summaryrefslogtreecommitdiff
path: root/framework-t/src
diff options
context:
space:
mode:
authorlifr <lifr@google.com>2021-12-21 11:07:02 +0800
committerlifr <lifr@google.com>2021-12-21 11:31:44 +0800
commit155cb5cced030f245f1b6602b72b49e18cdb91c7 (patch)
tree86514bfde3df5e5808a44e056d8f19221c8c5a42 /framework-t/src
parent24138d07edb6dceff7bd147e29e46a55376089db (diff)
[DU02]Remove DevicePolicyManagerInternal from NetworkStatsAccess
NetworkStatsAccess is using DevicePolicyManagerInternal APIs, which cannot be accessed after moving into the mainline module. So, replace and remove those hidden API usages. Bug: 207100745 Test: atest NetworkStatsAccessTest Change-Id: I0802148050869d92e1f09d1d657034380029f236
Diffstat (limited to 'framework-t/src')
-rw-r--r--framework-t/src/android/net/NetworkStatsAccess.java14
1 files changed, 6 insertions, 8 deletions
diff --git a/framework-t/src/android/net/NetworkStatsAccess.java b/framework-t/src/android/net/NetworkStatsAccess.java
index 3885a9e6d5..591605d952 100644
--- a/framework-t/src/android/net/NetworkStatsAccess.java
+++ b/framework-t/src/android/net/NetworkStatsAccess.java
@@ -24,7 +24,7 @@ import static android.net.TrafficStats.UID_TETHERING;
import android.Manifest;
import android.annotation.IntDef;
import android.app.AppOpsManager;
-import android.app.admin.DevicePolicyManagerInternal;
+import android.app.admin.DevicePolicyManager;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Binder;
@@ -32,8 +32,6 @@ import android.os.Process;
import android.os.UserHandle;
import android.telephony.TelephonyManager;
-import com.android.server.LocalServices;
-
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -109,8 +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) {
- final DevicePolicyManagerInternal dpmi = LocalServices.getService(
- DevicePolicyManagerInternal.class);
+ final DevicePolicyManager mDpm = context.getSystemService(DevicePolicyManager.class);
final TelephonyManager tm = (TelephonyManager)
context.getSystemService(Context.TELEPHONY_SERVICE);
boolean hasCarrierPrivileges;
@@ -123,8 +120,9 @@ public final class NetworkStatsAccess {
Binder.restoreCallingIdentity(token);
}
- final boolean isDeviceOwner = dpmi != null && dpmi.isActiveDeviceOwner(callingUid);
+ final boolean isDeviceOwner = mDpm != null && mDpm.isDeviceOwnerApp(callingPackage);
final int appId = UserHandle.getAppId(callingUid);
+
if (hasCarrierPrivileges || isDeviceOwner
|| appId == Process.SYSTEM_UID || appId == Process.NETWORK_STACK_UID) {
// Carrier-privileged apps and device owners, and the system (including the
@@ -139,8 +137,8 @@ public final class NetworkStatsAccess {
}
//TODO(b/169395065) Figure out if this flow makes sense in Device Owner mode.
- boolean isProfileOwner = dpmi != null && (dpmi.isActiveProfileOwner(callingUid)
- || dpmi.isActiveDeviceOwner(callingUid));
+ boolean isProfileOwner = mDpm != null && (mDpm.isProfileOwnerApp(callingPackage)
+ || mDpm.isDeviceOwnerApp(callingPackage));
if (isProfileOwner) {
// Apps with the AppOps permission, profile owners, and apps with the privileged
// permission can access data usage for all apps in this user/profile.