summaryrefslogtreecommitdiff
path: root/services/devicepolicy
diff options
context:
space:
mode:
authorPavel Grafov <pgrafov@google.com>2020-05-14 15:15:18 +0100
committerPavel Grafov <pgrafov@google.com>2020-05-14 17:42:01 +0100
commitde75560ab3dabdba91f04169d1700dbf4c802eb8 (patch)
treebd7179934d2490ec825c19d234c58a07951c4cc8 /services/devicepolicy
parentd09423450bd6713f6136c7ce48bfc2765e27a3e2 (diff)
Use exact date and time instead of "tomorrow" in notification
This helps avoid confusion if the user only sees the notification the next day. Bug: 155740352 Test: manual with TestDPC Test: atest com.android.server.devicepolicy.DevicePolicyManagerTest Change-Id: I6c95a6db2e8967eeffa373f96170cd610f13856a
Diffstat (limited to 'services/devicepolicy')
-rw-r--r--services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java55
1 files changed, 32 insertions, 23 deletions
diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
index 60d59b2a7558..de963a94051f 100644
--- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
+++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
@@ -247,6 +247,7 @@ import android.stats.devicepolicy.DevicePolicyEnums;
import android.telephony.TelephonyManager;
import android.telephony.data.ApnSetting;
import android.text.TextUtils;
+import android.text.format.DateUtils;
import android.util.ArrayMap;
import android.util.ArraySet;
import android.util.AtomicFile;
@@ -15994,31 +15995,27 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
private @PersonalAppsSuspensionReason int updatePersonalAppsSuspension(
int profileUserId, boolean unlocked) {
final boolean suspendedExplicitly;
- final int deadlineState;
- final String poPackage;
+ final boolean suspendedByTimeout;
synchronized (getLockObject()) {
final ActiveAdmin profileOwner = getProfileOwnerAdminLocked(profileUserId);
if (profileOwner != null) {
- deadlineState =
+ final int deadlineState =
updateProfileOffDeadlineLocked(profileUserId, profileOwner, unlocked);
suspendedExplicitly = profileOwner.mSuspendPersonalApps;
- poPackage = profileOwner.info.getPackageName();
+ suspendedByTimeout = deadlineState == PROFILE_OFF_DEADLINE_REACHED;
+ Slog.d(LOG_TAG, String.format(
+ "Personal apps suspended explicitly: %b, deadline state: %d",
+ suspendedExplicitly, deadlineState));
+ final int notificationState =
+ unlocked ? PROFILE_OFF_DEADLINE_DEFAULT : deadlineState;
+ updateProfileOffDeadlineNotificationLocked(
+ profileUserId, profileOwner, notificationState);
} else {
- poPackage = null;
suspendedExplicitly = false;
- deadlineState = PROFILE_OFF_DEADLINE_DEFAULT;
+ suspendedByTimeout = false;
}
}
- Slog.d(LOG_TAG, String.format("Personal apps suspended explicitly: %b, deadline state: %d",
- suspendedExplicitly, deadlineState));
-
- if (poPackage != null) {
- final int notificationState = unlocked ? PROFILE_OFF_DEADLINE_DEFAULT : deadlineState;
- updateProfileOffDeadlineNotification(profileUserId, poPackage, notificationState);
- }
-
- final boolean suspendedByTimeout = deadlineState == PROFILE_OFF_DEADLINE_REACHED;
final int parentUserId = getProfileParentId(profileUserId);
suspendPersonalAppsInternal(parentUserId, suspendedExplicitly || suspendedByTimeout);
@@ -16130,9 +16127,9 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
}
}
- private void updateProfileOffDeadlineNotification(
- int profileUserId, String profileOwnerPackage, int notificationState) {
-
+ @GuardedBy("getLockObject()")
+ private void updateProfileOffDeadlineNotificationLocked(
+ int profileUserId, ActiveAdmin profileOwner, int notificationState) {
if (notificationState == PROFILE_OFF_DEADLINE_DEFAULT) {
mInjector.getNotificationManager().cancel(SystemMessage.NOTE_PERSONAL_APPS_SUSPENDED);
return;
@@ -16150,11 +16147,23 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
final Notification.Action turnProfileOnButton =
new Notification.Action.Builder(null /* icon */, buttonText, pendingIntent).build();
- final String text = mContext.getString(
- notificationState == PROFILE_OFF_DEADLINE_WARNING
- ? R.string.personal_apps_suspension_tomorrow_text
- : R.string.personal_apps_suspension_text);
- final boolean ongoing = notificationState == PROFILE_OFF_DEADLINE_REACHED;
+ final String text;
+ final boolean ongoing;
+ if (notificationState == PROFILE_OFF_DEADLINE_WARNING) {
+ // Round to the closest integer number of days.
+ final int maxDays = (int)
+ ((profileOwner.mProfileMaximumTimeOffMillis + MS_PER_DAY / 2) / MS_PER_DAY);
+ final String date = DateUtils.formatDateTime(
+ mContext, profileOwner.mProfileOffDeadline, DateUtils.FORMAT_SHOW_DATE);
+ final String time = DateUtils.formatDateTime(
+ mContext, profileOwner.mProfileOffDeadline, DateUtils.FORMAT_SHOW_TIME);
+ text = mContext.getString(
+ R.string.personal_apps_suspension_soon_text, date, time, maxDays);
+ ongoing = false;
+ } else {
+ text = mContext.getString(R.string.personal_apps_suspension_text);
+ ongoing = true;
+ }
final int color = mContext.getColor(R.color.personal_apps_suspension_notification_color);
final Bundle extras = new Bundle();
// TODO: Create a separate string for this.