From 7bab8e86df0e7086683d77d4a7e81e201e903a51 Mon Sep 17 00:00:00 2001 From: Jeff Sharkey Date: Fri, 10 Apr 2020 13:54:43 -0600 Subject: [PATCH] Narrow access to getDataLayerSnapshotForUid(). This method is used in TrafficStats to obtain the snapshot for the calling UID, so narrow it to only return data for that specific case. We might be tempted to throw an exception or adjust the method signature, but apps are using the raw AIDL in the greylist, so we return them an empty NetworkStats if they ask about other UIDs. Bug: 119672472 Test: manual Change-Id: I3064630039f1d8473d6425dd663f17813a4ae3a1 --- .../core/java/com/android/server/net/NetworkStatsService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/core/java/com/android/server/net/NetworkStatsService.java b/services/core/java/com/android/server/net/NetworkStatsService.java index d8264b3625..c3a1a883e5 100644 --- a/services/core/java/com/android/server/net/NetworkStatsService.java +++ b/services/core/java/com/android/server/net/NetworkStatsService.java @@ -16,7 +16,6 @@ package com.android.server.net; -import static android.Manifest.permission.ACCESS_NETWORK_STATE; import static android.Manifest.permission.NETWORK_STATS_PROVIDER; import static android.Manifest.permission.READ_NETWORK_USAGE_HISTORY; import static android.Manifest.permission.UPDATE_DEVICE_STATS; @@ -845,7 +844,8 @@ public class NetworkStatsService extends INetworkStatsService.Stub { @Override public NetworkStats getDataLayerSnapshotForUid(int uid) throws RemoteException { if (Binder.getCallingUid() != uid) { - mContext.enforceCallingOrSelfPermission(ACCESS_NETWORK_STATE, TAG); + Log.w(TAG, "Snapshots only available for calling UID"); + return new NetworkStats(SystemClock.elapsedRealtime(), 0); } // TODO: switch to data layer stats once kernel exports