OSDN Git Service

Track BLE Scanning statistics by UID instead of by package name
authorAjay Panicker <apanicke@google.com>
Mon, 15 May 2017 20:33:41 +0000 (13:33 -0700)
committerAjay Panicker <apanicke@google.com>
Wed, 17 May 2017 17:42:31 +0000 (17:42 +0000)
Bug: 38315257
Test: cts-tradefed run cts-dev -m CtsIncidentHostTestCases -t com.android.server.cts.BatteryStatsValidationTest
Change-Id: I8a705f6f8169bf074a0eacc39c015bb1af04207d

src/com/android/bluetooth/gatt/ContextMap.java

index a46be3b..a9965db 100644 (file)
@@ -143,7 +143,7 @@ import com.android.bluetooth.btservice.BluetoothProto;
     private List<App> mApps = new ArrayList<App>();
 
     /** Internal map to keep track of logging information by app name */
-    HashMap<String, AppScanStats> mAppScanStats = new HashMap<String, AppScanStats>();
+    HashMap<Integer, AppScanStats> mAppScanStats = new HashMap<Integer, AppScanStats>();
 
     /** Internal list of connected devices **/
     Set<Connection> mConnections = new HashSet<Connection>();
@@ -152,17 +152,17 @@ import com.android.bluetooth.btservice.BluetoothProto;
      * Add an entry to the application context list.
      */
     void add(UUID uuid, WorkSource workSource, C callback, T info, GattService service) {
-        String appName = service.getPackageManager().getNameForUid(
-                             Binder.getCallingUid());
+        int appUid = Binder.getCallingUid();
+        String appName = service.getPackageManager().getNameForUid(appUid);
         if (appName == null) {
             // Assign an app name if one isn't found
-            appName = "Unknown App (UID: " + Binder.getCallingUid() + ")";
+            appName = "Unknown App (UID: " + appUid + ")";
         }
         synchronized (mApps) {
-            AppScanStats appScanStats = mAppScanStats.get(appName);
+            AppScanStats appScanStats = mAppScanStats.get(appUid);
             if (appScanStats == null) {
                 appScanStats = new AppScanStats(appName, workSource, this, service);
-                mAppScanStats.put(appName, appScanStats);
+                mAppScanStats.put(appUid, appScanStats);
             }
             mApps.add(new App(uuid, callback, info, appName, appScanStats));
             appScanStats.isRegistered = true;
@@ -333,10 +333,10 @@ import com.android.bluetooth.btservice.BluetoothProto;
     }
 
     /**
-     * Get Logging info by application name
+     * Get Logging info by application UID
      */
-    AppScanStats getAppScanStatsByName(String name) {
-        return mAppScanStats.get(name);
+    AppScanStats getAppScanStatsByUid(int uid) {
+        return mAppScanStats.get(uid);
     }
 
     /**
@@ -441,11 +441,10 @@ import com.android.bluetooth.btservice.BluetoothProto;
     void dump(StringBuilder sb) {
         sb.append("  Entries: " + mAppScanStats.size() + "\n\n");
 
-        Iterator<Map.Entry<String, AppScanStats>> it = mAppScanStats.entrySet().iterator();
+        Iterator<Map.Entry<Integer, AppScanStats>> it = mAppScanStats.entrySet().iterator();
         while (it.hasNext()) {
-            Map.Entry<String, AppScanStats> entry = it.next();
+            Map.Entry<Integer, AppScanStats> entry = it.next();
 
-            String name = entry.getKey();
             AppScanStats appScanStats = entry.getValue();
             appScanStats.dumpToString(sb);
         }