Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c7d64c13 authored by Sami Tolvanen's avatar Sami Tolvanen
Browse files

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
parent 328653d7
Loading
Loading
Loading
Loading
+5 −0
Original line number Original line Diff line number Diff line
@@ -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.-->
    <!-- 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>
    <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>
</resources>
+2 −0
Original line number Original line Diff line number Diff line
@@ -1895,6 +1895,8 @@
  <java-symbol type="string" name="config_customVpnConfirmDialogComponent" />
  <java-symbol type="string" name="config_customVpnConfirmDialogComponent" />
  <java-symbol type="string" name="config_defaultNetworkScorerPackageName" />
  <java-symbol type="string" name="config_defaultNetworkScorerPackageName" />
  <java-symbol type="string" name="config_persistentDataPackageName" />
  <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="layout" name="resolver_list" />
  <java-symbol type="id" name="resolver_list" />
  <java-symbol type="id" name="resolver_list" />
+34 −0
Original line number Original line Diff line number Diff line
@@ -24,6 +24,9 @@ import android.app.ActivityManagerInternal;
import android.app.ActivityManagerNative;
import android.app.ActivityManagerNative;
import android.app.AppOpsManager;
import android.app.AppOpsManager;
import android.app.IActivityManager;
import android.app.IActivityManager;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.admin.DevicePolicyManager;
import android.app.admin.DevicePolicyManager;
import android.content.BroadcastReceiver;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.ContentResolver;
@@ -118,6 +121,7 @@ import android.view.animation.Animation;
import android.view.inputmethod.InputMethodManagerInternal;
import android.view.inputmethod.InputMethodManagerInternal;
import android.widget.Toast;
import android.widget.Toast;


import com.android.internal.R;
import com.android.internal.app.IAssistScreenshotReceiver;
import com.android.internal.app.IAssistScreenshotReceiver;
import com.android.internal.os.IResultReceiver;
import com.android.internal.os.IResultReceiver;
import com.android.internal.policy.IShortcutService;
import com.android.internal.policy.IShortcutService;
@@ -7468,6 +7472,35 @@ public class WindowManagerService extends IWindowManager.Stub
        return mCurrentFocus;
        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() {
    public boolean detectSafeMode() {
        if (!mInputMonitor.waitForInputDevicesReady(
        if (!mInputMonitor.waitForInputDevicesReady(
                INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS)) {
                INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS)) {
@@ -7500,6 +7533,7 @@ public class WindowManagerService extends IWindowManager.Stub


                    if (auditSafeMode >= buildDate) {
                    if (auditSafeMode >= buildDate) {
                        mSafeMode = true;
                        mSafeMode = true;
                        showAuditSafeModeNotification();
                    } else {
                    } else {
                        SystemProperties.set(ShutdownThread.REBOOT_SAFEMODE_PROPERTY, "");
                        SystemProperties.set(ShutdownThread.REBOOT_SAFEMODE_PROPERTY, "");
                        SystemProperties.set(ShutdownThread.AUDIT_SAFEMODE_PROPERTY, "");
                        SystemProperties.set(ShutdownThread.AUDIT_SAFEMODE_PROPERTY, "");