Merge "Hide the stop button for the device admin app in the task manager" into tm-dev

This commit is contained in:
Jing Ji
2022-05-24 18:55:36 +00:00
committed by Android (Google) Code Review
6 changed files with 23 additions and 1 deletions

View File

@@ -379,6 +379,11 @@ public class PowerExemptionManager {
* @hide * @hide
*/ */
public static final int REASON_DISALLOW_APPS_CONTROL = 323; public static final int REASON_DISALLOW_APPS_CONTROL = 323;
/**
* Active device admin package.
* @hide
*/
public static final int REASON_ACTIVE_DEVICE_ADMIN = 324;
/** @hide The app requests out-out. */ /** @hide The app requests out-out. */
public static final int REASON_OPT_OUT_REQUESTED = 1000; public static final int REASON_OPT_OUT_REQUESTED = 1000;
@@ -459,6 +464,7 @@ public class PowerExemptionManager {
REASON_OPT_OUT_REQUESTED, REASON_OPT_OUT_REQUESTED,
REASON_DPO_PROTECTED_APP, REASON_DPO_PROTECTED_APP,
REASON_DISALLOW_APPS_CONTROL, REASON_DISALLOW_APPS_CONTROL,
REASON_ACTIVE_DEVICE_ADMIN,
}) })
@Retention(RetentionPolicy.SOURCE) @Retention(RetentionPolicy.SOURCE)
public @interface ReasonCode {} public @interface ReasonCode {}
@@ -669,6 +675,8 @@ public class PowerExemptionManager {
return AppBackgroundRestrictionsInfo.REASON_DPO_PROTECTED_APP; return AppBackgroundRestrictionsInfo.REASON_DPO_PROTECTED_APP;
case REASON_DISALLOW_APPS_CONTROL: case REASON_DISALLOW_APPS_CONTROL:
return AppBackgroundRestrictionsInfo.REASON_DISALLOW_APPS_CONTROL; return AppBackgroundRestrictionsInfo.REASON_DISALLOW_APPS_CONTROL;
case REASON_ACTIVE_DEVICE_ADMIN:
return AppBackgroundRestrictionsInfo.REASON_ACTIVE_DEVICE_ADMIN;
default: default:
return AppBackgroundRestrictionsInfo.REASON_DENIED; return AppBackgroundRestrictionsInfo.REASON_DENIED;
} }
@@ -818,6 +826,8 @@ public class PowerExemptionManager {
return "DPO_PROTECTED_APP"; return "DPO_PROTECTED_APP";
case REASON_DISALLOW_APPS_CONTROL: case REASON_DISALLOW_APPS_CONTROL:
return "DISALLOW_APPS_CONTROL"; return "DISALLOW_APPS_CONTROL";
case REASON_ACTIVE_DEVICE_ADMIN:
return "ACTIVE_DEVICE_ADMIN";
case REASON_OPT_OUT_REQUESTED: case REASON_OPT_OUT_REQUESTED:
return "REASON_OPT_OUT_REQUESTED"; return "REASON_OPT_OUT_REQUESTED";
default: default:

View File

@@ -218,6 +218,11 @@ public interface AppStandbyInternal {
void setActiveAdminApps(Set<String> adminPkgs, int userId); void setActiveAdminApps(Set<String> adminPkgs, int userId);
/**
* @return {@code true} if the given package is an active device admin app.
*/
boolean isActiveDeviceAdmin(String packageName, int userId);
void onAdminDataAvailable(); void onAdminDataAvailable();
void clearCarrierPrivilegedApps(); void clearCarrierPrivilegedApps();

View File

@@ -1799,7 +1799,8 @@ public class AppStandbyController
} }
@VisibleForTesting @VisibleForTesting
boolean isActiveDeviceAdmin(String packageName, int userId) { @Override
public boolean isActiveDeviceAdmin(String packageName, int userId) {
synchronized (mActiveAdminApps) { synchronized (mActiveAdminApps) {
final Set<String> adminPkgs = mActiveAdminApps.get(userId); final Set<String> adminPkgs = mActiveAdminApps.get(userId);
return adminPkgs != null && adminPkgs.contains(packageName); return adminPkgs != null && adminPkgs.contains(packageName);

View File

@@ -176,6 +176,7 @@ message AppBackgroundRestrictionsInfo {
REASON_CARRIER_PRIVILEGED_APP = 321; REASON_CARRIER_PRIVILEGED_APP = 321;
REASON_DPO_PROTECTED_APP = 322; REASON_DPO_PROTECTED_APP = 322;
REASON_DISALLOW_APPS_CONTROL = 323; REASON_DISALLOW_APPS_CONTROL = 323;
REASON_ACTIVE_DEVICE_ADMIN = 324;
// app requested to be exempt // app requested to be exempt
REASON_OPT_OUT_REQUESTED = 1000; REASON_OPT_OUT_REQUESTED = 1000;
} }

View File

@@ -462,6 +462,7 @@ class FgsManagerController @Inject constructor(
PowerExemptionManager.REASON_DISALLOW_APPS_CONTROL, PowerExemptionManager.REASON_DISALLOW_APPS_CONTROL,
PowerExemptionManager.REASON_DPO_PROTECTED_APP, PowerExemptionManager.REASON_DPO_PROTECTED_APP,
PowerExemptionManager.REASON_PROFILE_OWNER, PowerExemptionManager.REASON_PROFILE_OWNER,
PowerExemptionManager.REASON_ACTIVE_DEVICE_ADMIN,
PowerExemptionManager.REASON_PROC_STATE_PERSISTENT, PowerExemptionManager.REASON_PROC_STATE_PERSISTENT,
PowerExemptionManager.REASON_PROC_STATE_PERSISTENT_UI, PowerExemptionManager.REASON_PROC_STATE_PERSISTENT_UI,
PowerExemptionManager.REASON_ROLE_DIALER, PowerExemptionManager.REASON_ROLE_DIALER,

View File

@@ -55,6 +55,7 @@ import static android.content.Intent.ACTION_SHOW_FOREGROUND_SERVICE_MANAGER;
import static android.content.pm.PackageManager.MATCH_DIRECT_BOOT_AWARE; import static android.content.pm.PackageManager.MATCH_DIRECT_BOOT_AWARE;
import static android.content.pm.PackageManager.MATCH_DIRECT_BOOT_UNAWARE; import static android.content.pm.PackageManager.MATCH_DIRECT_BOOT_UNAWARE;
import static android.content.pm.PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS; import static android.content.pm.PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS;
import static android.os.PowerExemptionManager.REASON_ACTIVE_DEVICE_ADMIN;
import static android.os.PowerExemptionManager.REASON_ALLOWLISTED_PACKAGE; import static android.os.PowerExemptionManager.REASON_ALLOWLISTED_PACKAGE;
import static android.os.PowerExemptionManager.REASON_CARRIER_PRIVILEGED_APP; import static android.os.PowerExemptionManager.REASON_CARRIER_PRIVILEGED_APP;
import static android.os.PowerExemptionManager.REASON_COMPANION_DEVICE_MANAGER; import static android.os.PowerExemptionManager.REASON_COMPANION_DEVICE_MANAGER;
@@ -2777,6 +2778,7 @@ public final class AppRestrictionController {
if (packages != null) { if (packages != null) {
final AppOpsManager appOpsManager = mInjector.getAppOpsManager(); final AppOpsManager appOpsManager = mInjector.getAppOpsManager();
final PackageManagerInternal pm = mInjector.getPackageManagerInternal(); final PackageManagerInternal pm = mInjector.getPackageManagerInternal();
final AppStandbyInternal appStandbyInternal = mInjector.getAppStandbyInternal();
for (String pkg : packages) { for (String pkg : packages) {
if (appOpsManager.checkOpNoThrow(AppOpsManager.OP_ACTIVATE_VPN, if (appOpsManager.checkOpNoThrow(AppOpsManager.OP_ACTIVATE_VPN,
uid, pkg) == AppOpsManager.MODE_ALLOWED) { uid, pkg) == AppOpsManager.MODE_ALLOWED) {
@@ -2794,6 +2796,8 @@ public final class AppRestrictionController {
return REASON_SYSTEM_ALLOW_LISTED; return REASON_SYSTEM_ALLOW_LISTED;
} else if (pm.isPackageStateProtected(pkg, userId)) { } else if (pm.isPackageStateProtected(pkg, userId)) {
return REASON_DPO_PROTECTED_APP; return REASON_DPO_PROTECTED_APP;
} else if (appStandbyInternal.isActiveDeviceAdmin(pkg, userId)) {
return REASON_ACTIVE_DEVICE_ADMIN;
} }
} }
} }