diff options
| author | Junyu Lai <junyulai@google.com> | 2021-12-28 09:03:07 +0000 |
|---|---|---|
| committer | Junyu Lai <junyulai@google.com> | 2021-12-29 01:43:54 +0000 |
| commit | 4f84ff37091d05733eceb7867bdfb619aca65052 (patch) | |
| tree | 0948c701c9cd44edb6fcae92c0872e2827f663d4 /framework-t/src/android/net/NetworkStatsAccess.java | |
| parent | 989b2128db294a79986860c91576e4e239985782 (diff) | |
[MS26.1] Remove Process.NETWORK_STACK_UID dependency
Check NetworkStack permission instead.
Test: NetworkStatsAccessTest
Bug: 204830222
Change-Id: I052a1422d145af533b036b0f017ace485b67cbfe
Diffstat (limited to 'framework-t/src/android/net/NetworkStatsAccess.java')
| -rw-r--r-- | framework-t/src/android/net/NetworkStatsAccess.java | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/framework-t/src/android/net/NetworkStatsAccess.java b/framework-t/src/android/net/NetworkStatsAccess.java index 591605d952..779fdf94a0 100644 --- a/framework-t/src/android/net/NetworkStatsAccess.java +++ b/framework-t/src/android/net/NetworkStatsAccess.java @@ -17,6 +17,7 @@ package android.net; import static android.Manifest.permission.READ_NETWORK_USAGE_HISTORY; +import static android.content.pm.PackageManager.PERMISSION_GRANTED; import static android.net.NetworkStats.UID_ALL; import static android.net.TrafficStats.UID_REMOVED; import static android.net.TrafficStats.UID_TETHERING; @@ -106,7 +107,7 @@ public final class NetworkStatsAccess { /** Returns the {@link NetworkStatsAccess.Level} for the given caller. */ public static @NetworkStatsAccess.Level int checkAccessLevel( - Context context, int callingUid, String callingPackage) { + Context context, int callingPid, int callingUid, String callingPackage) { final DevicePolicyManager mDpm = context.getSystemService(DevicePolicyManager.class); final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); @@ -123,8 +124,12 @@ public final class NetworkStatsAccess { final boolean isDeviceOwner = mDpm != null && mDpm.isDeviceOwnerApp(callingPackage); final int appId = UserHandle.getAppId(callingUid); + final boolean isNetworkStack = context.checkPermission( + android.Manifest.permission.NETWORK_STACK, callingPid, callingUid) + == PERMISSION_GRANTED; + if (hasCarrierPrivileges || isDeviceOwner - || appId == Process.SYSTEM_UID || appId == Process.NETWORK_STACK_UID) { + || appId == Process.SYSTEM_UID || isNetworkStack) { // Carrier-privileged apps and device owners, and the system (including the // network stack) can access data usage for all apps on the device. return NetworkStatsAccess.Level.DEVICE; |
