1 package com.android.car; 2 3 import android.bluetooth.BluetoothDevice; 4 import android.bluetooth.BluetoothProfile; 5 6 /** 7 * Some potentially useful static methods. 8 */ 9 public class Utils { 10 static final Boolean DBG = false; 11 12 static String getDeviceDebugInfo(BluetoothDevice device) { 13 return "(name = " + device.getName() + ", addr = " + device.getAddress() + ")"; 14 } 15 16 static String getProfileName(int profile) { 17 switch(profile) { 18 case BluetoothProfile.A2DP_SINK: 19 return "A2DP_SINK"; 20 case BluetoothProfile.HEADSET_CLIENT: 21 return "HFP"; 22 case BluetoothProfile.PBAP_CLIENT: 23 return "PBAP"; 24 case BluetoothProfile.MAP_CLIENT: 25 return "MAP"; 26 case BluetoothProfile.AVRCP_CONTROLLER: 27 return "AVRCP"; 28 case BluetoothProfile.PAN: 29 return "PAN"; 30 default: 31 return profile + ""; 32 33 } 34 } 35 36 /** 37 * An utility class to dump transition events across different car service components. 38 * The output will be of the form 39 * <p> 40 * "Time <svc name>: [optional context information] changed from <from state> to <to state>" 41 * This can be used in conjunction with the dump() method to dump this information through 42 * adb shell dumpsys activity service com.android.car 43 * <p> 44 * A specific service in CarService can choose to use a circular buffer of N records to keep 45 * track of the last N transitions. 46 * 47 */ 48 public static class TransitionLog { 49 private String mServiceName; // name of the service or tag 50 private int mFromState; // old state 51 private int mToState; // new state 52 private long mTimestampMs; // System.currentTimeMillis() 53 private String mExtra; // Additional information as a String 54 55 public TransitionLog(String name, int fromState, int toState, long timestamp, 56 String extra) { 57 this(name, fromState, toState, timestamp); 58 mExtra = extra; 59 } 60 61 public TransitionLog(String name, int fromState, int toState, long timeStamp) { 62 mServiceName = name; 63 mFromState = fromState; 64 mToState = toState; 65 mTimestampMs = timeStamp; 66 } 67 68 private CharSequence timeToLog(long timestamp) { 69 return android.text.format.DateFormat.format("MM-dd HH:mm:ss", timestamp); 70 } 71 72 @Override 73 public String toString() { 74 return timeToLog(mTimestampMs) + " " + mServiceName + ": " + (mExtra != null ? mExtra 75 : "") + " changed from " + mFromState + " to " + mToState; 76 } 77 } 78 } 79