Merge "Don't notify about explicit personal app suspension." into rvc-dev am: e39a7b6a80 am: e68a57ee7c

Change-Id: Ic91033873e1b3aba4b13988fce40688873c64877
This commit is contained in:
TreeHugger Robot
2020-03-23 16:04:17 +00:00
committed by Automerger Merge Worker
3 changed files with 52 additions and 27 deletions

View File

@@ -441,11 +441,23 @@
<!-- A toast message displayed when printing is attempted but disabled by policy. -->
<string name="printing_disabled_by">Printing disabled by <xliff:g id="owner_app">%s</xliff:g>.</string>
<!-- Content title for a notification that personal apps are suspended [CHAR LIMIT=NONE] -->
<string name="personal_apps_suspended_notification_title">Personal apps have been suspended by an admin</string>
<!-- Message for a notification about personal apps suspension when work profile is off. [CHAR LIMIT=NONE] -->
<string name="personal_apps_suspended_notification_text">Tap here to check policy compliance.</string>
<!-- Notification title. This notification lets a user know that their personal apps are
blocked due to a work policy from their IT admin, and tells them what they need to do
to unblock their apps.[CHAR LIMIT=29] -->
<string name="personal_apps_suspended_title">Unblock your personal apps</string>
<!-- Notification title. This notification lets a user know that their apps will be blocked
tomorrow due to a work policy from their IT admin, and tells them what they need to do to
prevent the apps from being blocked. [CHAR LIMIT=29] -->
<string name="personal_apps_suspended_tomorrow_title">Apps will be blocked tomorrow</string>
<!-- Notification text. This notification lets a user know that they need to turn on their
work profile due to a work policy from their IT admin. The number of days is at least 3.
[CHAR LIMIT=NONE] -->
<string name="personal_apps_suspended_text">Your IT admin doesn\u2019t allow your
work profile to be paused for more than <xliff:g id="days" example="3">%1$d</xliff:g>
days</string>
<!-- Title for the button that turns work profile on. To be used in a notification
[CHAR LIMIT=NONE] -->
<string name="personal_apps_suspended_turn_profile_on">Turn on work profile</string>
<!-- Display name for any time a piece of data refers to the owner of the phone. For example, this could be used in place of the phone's phone number. -->
<string name="me">Me</string>

View File

@@ -1194,8 +1194,9 @@
<java-symbol type="string" name="network_logging_notification_text" />
<java-symbol type="string" name="location_changed_notification_title" />
<java-symbol type="string" name="location_changed_notification_text" />
<java-symbol type="string" name="personal_apps_suspended_notification_title" />
<java-symbol type="string" name="personal_apps_suspended_notification_text" />
<java-symbol type="string" name="personal_apps_suspended_title" />
<java-symbol type="string" name="personal_apps_suspended_tomorrow_title" />
<java-symbol type="string" name="personal_apps_suspended_text" />
<java-symbol type="string" name="factory_reset_warning" />
<java-symbol type="string" name="factory_reset_message" />
<java-symbol type="string" name="lockscreen_transport_play_description" />

View File

@@ -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();