blob: 78f5a8e064a23c0b59666b9bd5f811c4e9d3682d [file] [log] [blame]
Vasu Norie5fb9112017-11-17 10:23:02 -08001package com.android.car;
2
3import android.bluetooth.BluetoothDevice;
4import android.bluetooth.BluetoothProfile;
5
6/**
7 * Some potentially useful static methods.
8 */
9public 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";
Joseph Pirozzo99aeba92018-02-05 14:48:49 -080028 case BluetoothProfile.PAN:
29 return "PAN";
Vasu Norie5fb9112017-11-17 10:23:02 -080030 default:
31 return profile + "";
32
33 }
34 }
Ram Periathiruvadi22c0d682018-05-10 17:50:48 -070035
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 }
Vasu Norie5fb9112017-11-17 10:23:02 -080078}