From c7d64c134ae786cc41af78a3e7dfbfeda8be4287 Mon Sep 17 00:00:00 2001 From: Sami Tolvanen Date: Thu, 25 Feb 2016 10:03:47 -0800 Subject: [PATCH] Notify user when forced to boot into safe mode When the device is forced into safe mode due to a security compromise (persist.sys.audit_safemode has been set), notify the user and provide access to a help article. Bug: 27308928 Bug: 26902605 Change-Id: Ief7451f2d741eb888e5b111061aab5dc29525ea5 --- core/res/res/values/strings.xml | 5 +++ core/res/res/values/symbols.xml | 2 ++ .../server/wm/WindowManagerService.java | 34 +++++++++++++++++++ 3 files changed, 41 insertions(+) diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml index 1d7034df9a579..17afd92b648a6 100644 --- a/core/res/res/values/strings.xml +++ b/core/res/res/values/strings.xml @@ -4228,4 +4228,9 @@ \u2212%1$s + + Factory reset to use this device normally + + Touch to learn more. + diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml index 0120128302111..cad0e7b4570e8 100644 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -1895,6 +1895,8 @@ + + diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java index b64aaa89475a4..b92ecc0996d99 100644 --- a/services/core/java/com/android/server/wm/WindowManagerService.java +++ b/services/core/java/com/android/server/wm/WindowManagerService.java @@ -24,6 +24,9 @@ import android.app.ActivityManagerInternal; import android.app.ActivityManagerNative; import android.app.AppOpsManager; import android.app.IActivityManager; +import android.app.Notification; +import android.app.NotificationManager; +import android.app.PendingIntent; import android.app.admin.DevicePolicyManager; import android.content.BroadcastReceiver; import android.content.ContentResolver; @@ -118,6 +121,7 @@ import android.view.animation.Animation; import android.view.inputmethod.InputMethodManagerInternal; import android.widget.Toast; +import com.android.internal.R; import com.android.internal.app.IAssistScreenshotReceiver; import com.android.internal.os.IResultReceiver; import com.android.internal.policy.IShortcutService; @@ -7468,6 +7472,35 @@ public class WindowManagerService extends IWindowManager.Stub return mCurrentFocus; } + private void showAuditSafeModeNotification() { + PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, + new Intent(Intent.ACTION_VIEW, + Uri.parse("https://support.google.com/nexus/answer/2852139")), 0); + + String title = mContext.getString(R.string.audit_safemode_notification); + + Notification notification = new Notification.Builder(mContext) + .setSmallIcon(com.android.internal.R.drawable.stat_sys_warning) + .setWhen(0) + .setOngoing(true) + .setTicker(title) + .setLocalOnly(true) + .setPriority(Notification.PRIORITY_HIGH) + .setVisibility(Notification.VISIBILITY_PUBLIC) + .setColor(mContext.getColor( + com.android.internal.R.color.system_notification_accent_color)) + .setContentTitle(title) + .setContentText(mContext.getString(R.string.audit_safemode_notification_details)) + .setContentIntent(pendingIntent) + .build(); + + NotificationManager notificationManager = (NotificationManager) mContext + .getSystemService(Context.NOTIFICATION_SERVICE); + + notificationManager.notifyAsUser(null, R.string.audit_safemode_notification, notification, + UserHandle.ALL); + } + public boolean detectSafeMode() { if (!mInputMonitor.waitForInputDevicesReady( INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS)) { @@ -7500,6 +7533,7 @@ public class WindowManagerService extends IWindowManager.Stub if (auditSafeMode >= buildDate) { mSafeMode = true; + showAuditSafeModeNotification(); } else { SystemProperties.set(ShutdownThread.REBOOT_SAFEMODE_PROPERTY, ""); SystemProperties.set(ShutdownThread.AUDIT_SAFEMODE_PROPERTY, "");