diff --git a/framework-t/src/android/net/NetworkStatsAccess.java b/framework-t/src/android/net/NetworkStatsAccess.java index 7c9b3ecbf5..449588af00 100644 --- a/framework-t/src/android/net/NetworkStatsAccess.java +++ b/framework-t/src/android/net/NetworkStatsAccess.java @@ -111,6 +111,12 @@ public final class NetworkStatsAccess { /** Returns the {@link NetworkStatsAccess.Level} for the given caller. */ public static @NetworkStatsAccess.Level int checkAccessLevel( Context context, int callingPid, int callingUid, @Nullable String callingPackage) { + final int appId = UserHandle.getAppId(callingUid); + if (appId == Process.SYSTEM_UID) { + // the system can access data usage for all apps on the device. + // check system uid first, to avoid possible dead lock from other APIs + return NetworkStatsAccess.Level.DEVICE; + } final DevicePolicyManager mDpm = context.getSystemService(DevicePolicyManager.class); final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); @@ -126,16 +132,13 @@ public final class NetworkStatsAccess { Binder.restoreCallingIdentity(token); } - final int appId = UserHandle.getAppId(callingUid); - final boolean isNetworkStack = PermissionUtils.hasAnyPermissionOf( context, callingPid, callingUid, android.Manifest.permission.NETWORK_STACK, NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK); - if (hasCarrierPrivileges || isDeviceOwner - || 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. + if (hasCarrierPrivileges || isDeviceOwner || isNetworkStack) { + // Carrier-privileged apps and device owners, and the network stack + // can access data usage for all apps on the device. return NetworkStatsAccess.Level.DEVICE; }