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
This commit is contained in:
Sami Tolvanen
2016-02-25 10:03:47 -08:00
parent 328653d74c
commit c7d64c134a
3 changed files with 41 additions and 0 deletions

View File

@@ -4228,4 +4228,9 @@
<!-- The representation of a time duration when negative. An example is -1:14. This can be used with a countdown timer for example.-->
<string name="negative_duration">\u2212<xliff:g id="time" example="1:14">%1$s</xliff:g></string>
<!-- Title of notification shown when device has been forced to safe mode after a security compromise. -->
<string name="audit_safemode_notification">Factory reset to use this device normally</string>
<!-- Description of notification shown when device has been forced to safe mode after a security compromise. -->
<string name="audit_safemode_notification_details">Touch to learn more.</string>
</resources>

View File

@@ -1895,6 +1895,8 @@
<java-symbol type="string" name="config_customVpnConfirmDialogComponent" />
<java-symbol type="string" name="config_defaultNetworkScorerPackageName" />
<java-symbol type="string" name="config_persistentDataPackageName" />
<java-symbol type="string" name="audit_safemode_notification" />
<java-symbol type="string" name="audit_safemode_notification_details" />
<java-symbol type="layout" name="resolver_list" />
<java-symbol type="id" name="resolver_list" />

View File

@@ -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, "");