diff --git a/core/java/android/app/admin/DevicePolicyManagerInternal.java b/core/java/android/app/admin/DevicePolicyManagerInternal.java index b6f09167580f9..537b8d42e123a 100644 --- a/core/java/android/app/admin/DevicePolicyManagerInternal.java +++ b/core/java/android/app/admin/DevicePolicyManagerInternal.java @@ -269,4 +269,9 @@ public abstract class DevicePolicyManagerInternal { * {@link #supportsResetOp(int)} is true. */ public abstract void resetOp(int op, String packageName, @UserIdInt int userId); + + /** + * Returns whether new "turn off work" behavior is enabled via feature flag. + */ + public abstract boolean isKeepProfilesRunningEnabled(); } diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java index 775e3d8334039..1ec2438613d28 100644 --- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java @@ -718,6 +718,16 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { private static final String ENABLE_COEXISTENCE_FLAG = "enable_coexistence"; private static final boolean DEFAULT_ENABLE_COEXISTENCE_FLAG = false; + // TODO(b/258425381) remove the flag after rollout. + private static final String KEEP_PROFILES_RUNNING_FLAG = "enable_keep_profiles_running"; + private static final boolean DEFAULT_KEEP_PROFILES_RUNNING_FLAG = false; + + /** + * This feature flag is checked once after boot and this value us used until the next reboot to + * avoid needing to handle the flag changing on the fly. + */ + private final boolean mKeepProfilesRunning = isKeepProfilesRunningFlagEnabled(); + /** * For apps targeting U+ * Enable multiple admins to coexist on the same device. @@ -9892,6 +9902,8 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { (size == 1 ? "" : "s")); } pw.println(); + pw.println("Keep profiles running: " + mKeepProfilesRunning); + pw.println(); mPolicyCache.dump(pw); pw.println(); @@ -13533,6 +13545,11 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { } } + @Override + public boolean isKeepProfilesRunningEnabled() { + return mKeepProfilesRunning; + } + private @Mode int findInteractAcrossProfilesResetMode(String packageName) { return getDefaultCrossProfilePackages().contains(packageName) ? AppOpsManager.MODE_ALLOWED @@ -19167,4 +19184,11 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { ENABLE_COEXISTENCE_FLAG, DEFAULT_ENABLE_COEXISTENCE_FLAG); } + + private static boolean isKeepProfilesRunningFlagEnabled() { + return DeviceConfig.getBoolean( + NAMESPACE_DEVICE_POLICY_MANAGER, + KEEP_PROFILES_RUNNING_FLAG, + DEFAULT_KEEP_PROFILES_RUNNING_FLAG); + } }