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

Commit fd45e5fe authored by Nathan Harold's avatar Nathan Harold
Browse files

Count and Report Bandwidth Requests by UID

To debug power drain due to modem wakeups,
one of the signals we'd like to track is
requests for bandwidth estimate to see which
apps are making requests and how often. This
patch keeps a simple count per-UID when an
app requests a bandwidth update, and that
count is made available in dumpsys.

Bug: 77498849
Test: runtest frameworks-net
Change-Id: I30d2ce85f9fa6747030cf4039d1080113a32e386
parent c14a4be7
Loading
Loading
Loading
Loading
+24 −1
Original line number Diff line number Diff line
@@ -497,6 +497,9 @@ public class ConnectivityService extends IConnectivityManager.Stub

    private final IpConnectivityLog mMetricsLog;

    @GuardedBy("mBandwidthRequests")
    private final SparseArray<Integer> mBandwidthRequests = new SparseArray(10);

    @VisibleForTesting
    final MultinetworkPolicyTracker mMultinetworkPolicyTracker;

@@ -2069,6 +2072,18 @@ public class ConnectivityService extends IConnectivityManager.Stub
                pw.println("currently holding WakeLock for: " + (duration / 1000) + "s");
            }
            mWakelockLogs.reverseDump(fd, pw, args);

            pw.println();
            pw.println("bandwidth update requests (by uid):");
            pw.increaseIndent();
            synchronized (mBandwidthRequests) {
                for (int i = 0; i < mBandwidthRequests.size(); i++) {
                    pw.println("[" + mBandwidthRequests.keyAt(i)
                            + "]: " + mBandwidthRequests.valueAt(i));
                }
            }
            pw.decreaseIndent();

            pw.decreaseIndent();
        }
    }
@@ -4223,6 +4238,14 @@ public class ConnectivityService extends IConnectivityManager.Stub
        }
        if (nai != null) {
            nai.asyncChannel.sendMessage(android.net.NetworkAgent.CMD_REQUEST_BANDWIDTH_UPDATE);
            synchronized (mBandwidthRequests) {
                final int uid = Binder.getCallingUid();
                Integer uidReqs = mBandwidthRequests.get(uid);
                if (uidReqs == null) {
                    uidReqs = new Integer(0);
                }
                mBandwidthRequests.put(uid, ++uidReqs);
            }
            return true;
        }
        return false;