Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 67d41f4a authored by Ajay Panicker's avatar Ajay Panicker Committed by android-build-merger
Browse files

Merge "Track BLE Scanning statistics by UID instead of by package name" into oc-dev am: 4a3d30f4

am: ff455bfe

Change-Id: Ib8759d30348046e7ed8eecbedaf945c624841ce9
parents da6da8ca ff455bfe
Loading
Loading
Loading
Loading
+11 −12
Original line number Diff line number Diff line
@@ -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);
        }