From 64d1fc040b7ac249bd5340102ab576d3a22da9e4 Mon Sep 17 00:00:00 2001 From: Pavel Grafov Date: Wed, 18 Mar 2020 16:09:38 +0000 Subject: [PATCH] Don't notify about explicit personal app suspension. Notification about personal apps suspension should only be shown in cases when apps are suspended because of maximum work profile time off policy violation, not via an explicit call to suspend. + updated strings. Note, some strings are not used yet. Test: manual, with TestDPC, suspended apps explicitly, checked that the notification is not shown. Test: manual, with TestDPC, set maximum work profile time off, adjusted the clock, checked that the notification is there.` Bug: 151918490 Bug: 149076989 Change-Id: Idd4c7ec11af416c303c9218495d55c73154c7a5f --- core/res/res/values/strings.xml | 22 ++++++-- core/res/res/values/symbols.xml | 5 +- .../DevicePolicyManagerService.java | 52 ++++++++++++------- 3 files changed, 52 insertions(+), 27 deletions(-) diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml index ec69874d68d69..6a0fd611ba9be 100644 --- a/core/res/res/values/strings.xml +++ b/core/res/res/values/strings.xml @@ -441,11 +441,23 @@ Printing disabled by %s. - - Personal apps have been suspended by an admin - - - Tap here to check policy compliance. + + Unblock your personal apps + + Apps will be blocked tomorrow + + Your IT admin doesn\u2019t allow your + work profile to be paused for more than %1$d + days + + Turn on work profile Me diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml index 6c598d6480e27..5a30e3f8faac1 100644 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -1194,8 +1194,9 @@ - - + + + diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java index 6ab5303b41e4f..a84086df6fa42 100644 --- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java @@ -15662,19 +15662,25 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!userData.mAppsSuspended) { return PERSONAL_APPS_NOT_SUSPENDED; } else { - int reasons = PERSONAL_APPS_NOT_SUSPENDED; - if (admin.mSuspendPersonalApps) { - reasons |= PERSONAL_APPS_SUSPENDED_EXPLICITLY; - } final long deadline = admin.mProfileOffDeadline; - if (deadline != 0 && System.currentTimeMillis() > deadline) { - reasons |= PERSONAL_APPS_SUSPENDED_PROFILE_TIMEOUT; - } - return reasons; + return makeSuspensionReasons(admin.mSuspendPersonalApps, + deadline != 0 && System.currentTimeMillis() > deadline); } } } + private @PersonalAppSuspensionReason int makeSuspensionReasons( + boolean explicit, boolean timeout) { + int result = PERSONAL_APPS_NOT_SUSPENDED; + if (explicit) { + result |= PERSONAL_APPS_SUSPENDED_EXPLICITLY; + } + if (timeout) { + result |= PERSONAL_APPS_SUSPENDED_PROFILE_TIMEOUT; + } + return result; + } + @Override public void setPersonalAppsSuspended(ComponentName who, boolean suspended) { final int callingUserId = mInjector.userHandleGetCallingUserId(); @@ -15700,7 +15706,8 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { } mInjector.binderWithCleanCallingIdentity( - () -> applyPersonalAppsSuspension(callingUserId, suspended)); + () -> applyPersonalAppsSuspension( + callingUserId, PERSONAL_APPS_SUSPENDED_EXPLICITLY)); DevicePolicyEventLogger .createEvent(DevicePolicyEnums.SET_PERSONAL_APPS_SUSPENDED) @@ -15715,22 +15722,22 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { * @param running whether the profile is currently considered running. */ private void updatePersonalAppSuspension(int profileUserId, boolean running) { - final boolean shouldSuspend; + final int suspensionState; synchronized (getLockObject()) { final ActiveAdmin profileOwner = getProfileOwnerAdminLocked(profileUserId); if (profileOwner != null) { final boolean deadlineReached = updateProfileOffDeadlineLocked(profileUserId, profileOwner, running); - shouldSuspend = deadlineReached || profileOwner.mSuspendPersonalApps; - Slog.d(LOG_TAG, String.format( - "Should personal use be suspended: %b; explicit: %b; timeout: %b", - shouldSuspend, profileOwner.mSuspendPersonalApps, deadlineReached)); + suspensionState = makeSuspensionReasons( + profileOwner.mSuspendPersonalApps, deadlineReached); + Slog.d(LOG_TAG, + String.format("New personal apps suspension state: %d", suspensionState)); } else { - shouldSuspend = false; + suspensionState = PERSONAL_APPS_NOT_SUSPENDED; } } - applyPersonalAppsSuspension(profileUserId, shouldSuspend); + applyPersonalAppsSuspension(profileUserId, suspensionState); } /** @@ -15785,13 +15792,15 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { } } - private void applyPersonalAppsSuspension(int profileUserId, boolean shouldSuspend) { + private void applyPersonalAppsSuspension( + int profileUserId, @PersonalAppSuspensionReason int suspensionState) { final boolean suspended = getUserData(UserHandle.USER_SYSTEM).mAppsSuspended; + final boolean shouldSuspend = suspensionState != PERSONAL_APPS_NOT_SUSPENDED; if (suspended != shouldSuspend) { suspendPersonalAppsInternal(shouldSuspend, UserHandle.USER_SYSTEM); } - if (shouldSuspend) { + if (suspensionState == PERSONAL_APPS_SUSPENDED_PROFILE_TIMEOUT) { sendPersonalAppsSuspendedNotification(profileUserId); } else { clearPersonalAppsSuspendedNotification(); @@ -15832,8 +15841,11 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { private void sendPersonalAppsSuspendedNotification(int userId) { final String profileOwnerPackageName; + final long maxTimeOffDays; synchronized (getLockObject()) { profileOwnerPackageName = mOwners.getProfileOwnerComponent(userId).getPackageName(); + final ActiveAdmin poAdmin = getProfileOwnerAdminLocked(userId); + maxTimeOffDays = TimeUnit.MILLISECONDS.toDays(poAdmin.mProfileMaximumTimeOffMillis); } final Intent intent = new Intent(DevicePolicyManager.ACTION_CHECK_POLICY_COMPLIANCE); @@ -15849,9 +15861,9 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { .setOngoing(true) .setContentTitle( mContext.getString( - R.string.personal_apps_suspended_notification_title)) + R.string.personal_apps_suspended_title)) .setContentText(mContext.getString( - R.string.personal_apps_suspended_notification_text)) + R.string.personal_apps_suspended_text, maxTimeOffDays)) .setColor(mContext.getColor(R.color.system_notification_accent_color)) .setContentIntent(pendingIntent) .build();