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

Commit 7d8e293b authored by Adam Bookatz's avatar Adam Bookatz
Browse files

Notification for wrong HSUM state

It is theoretically possible to flash (without wiping) an HSUM build
onto a device that was hitherto non-HSUM (or vice versa).
In that case, we purposefully leave
the device in the previous mode, since there is no way to safely change
the HSUM state. However, that situation may be confusing to the user,
who may flash the device (or receive an OTA) without realising that a
wipe was required in order to change their HSUM state.

We therefore now show a notification when this happens, instructing the
user to factory reset the device, so that it can get into the correct
HSUM state.

This is only expected to affect experiments/dogfooding. Normally, we do
not expect organizations to OTA between HSUM-non-HSUM builds without
wiping. If an OEM wishes to do this inadvisable activity, they would be
advised to similarly disable this notification.

Test: manual
Bug: 341963779
Flag: EXEMPT bugfix
Change-Id: I620afa7db941c117e93529f408c728b8c1d411c1
parent 34053329
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -3833,6 +3833,11 @@
    <!-- Message of notification shown when Test Harness Mode is enabled. [CHAR LIMIT=NONE] -->
    <string name="test_harness_mode_notification_message">Perform a factory reset to disable Test Harness Mode.</string>

    <!-- Title of notification shown when device is in the wrong Headless System User Mode configuration. [CHAR LIMIT=NONE] -->
    <string name="wrong_hsum_configuration_notification_title">Wrong HSUM build configuration</string>
    <!-- Message of notification shown when device is in the wrong Headless System User Mode configuration. [CHAR LIMIT=NONE] -->
    <string name="wrong_hsum_configuration_notification_message">The Headless System User Mode state of this device differs from its build configuration. Please factory reset the device.</string>

    <!-- Title of notification shown when serial console is enabled. [CHAR LIMIT=NONE] -->
    <string name="console_running_notification_title">Serial console enabled</string>
    <!-- Message of notification shown when serial console is enabled. [CHAR LIMIT=NONE] -->
+2 −0
Original line number Diff line number Diff line
@@ -2153,6 +2153,8 @@
  <java-symbol type="string" name="adbwifi_active_notification_title" />
  <java-symbol type="string" name="test_harness_mode_notification_title" />
  <java-symbol type="string" name="test_harness_mode_notification_message" />
  <java-symbol type="string" name="wrong_hsum_configuration_notification_title" />
  <java-symbol type="string" name="wrong_hsum_configuration_notification_message" />
  <java-symbol type="string" name="console_running_notification_title" />
  <java-symbol type="string" name="console_running_notification_message" />
  <java-symbol type="string" name="mte_override_notification_title" />
+4 −0
Original line number Diff line number Diff line
@@ -314,6 +314,10 @@ message SystemMessage {
    // Package: com.android.systemui
    NOTE_ADAPTIVE_NOTIFICATIONS = 76;

    // Warn the user that the device's Headless System User Mode status doesn't match the build's.
    // Package: android
    NOTE_WRONG_HSUM_STATUS = 77;

    // ADD_NEW_IDS_ABOVE_THIS_LINE
    // Legacy IDs with arbitrary values appear below
    // Legacy IDs existed as stable non-conflicting constants prior to the O release
+48 −0
Original line number Diff line number Diff line
@@ -62,6 +62,8 @@ import android.app.BroadcastOptions;
import android.app.IActivityManager;
import android.app.IStopUserCallback;
import android.app.KeyguardManager;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.StatsManager;
import android.app.admin.DevicePolicyEventLogger;
@@ -147,6 +149,8 @@ import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.app.IAppOpsService;
import com.android.internal.app.SetScreenLockDialogActivity;
import com.android.internal.logging.MetricsLogger;
import com.android.internal.messages.nano.SystemMessageProto.SystemMessage;
import com.android.internal.notification.SystemNotificationChannels;
import com.android.internal.os.BackgroundThread;
import com.android.internal.os.RoSystemProperties;
import com.android.internal.util.DumpUtils;
@@ -1070,6 +1074,8 @@ public class UserManagerService extends IUserManager.Stub {
        if (isAutoLockingPrivateSpaceOnRestartsEnabled()) {
            autoLockPrivateSpace();
        }

        showHsumNotificationIfNeeded();
    }

    private boolean isAutoLockingPrivateSpaceOnRestartsEnabled() {
@@ -4163,6 +4169,48 @@ public class UserManagerService extends IUserManager.Stub {
        mUpdatingSystemUserMode = true;
    }

    /**
     * If the device's actual HSUM status differs from that which is defined by its build
     * configuration, warn the user. Ignores HSUM emulated status, since that isn't relevant.
     *
     * The goal is to inform dogfooders that they need to factory reset the device to align their
     * device with its build configuration.
     */
    private void showHsumNotificationIfNeeded() {
        if (RoSystemProperties.MULTIUSER_HEADLESS_SYSTEM_USER == isHeadlessSystemUserMode()) {
            // Actual state does match the configuration. Great!
            return;
        }
        if (Build.isDebuggable()
                && !TextUtils.isEmpty(SystemProperties.get(SYSTEM_USER_MODE_EMULATION_PROPERTY))) {
            // Ignore any device that has been playing around with HSUM emulation.
            return;
        }
        Slogf.w(LOG_TAG, "Posting warning that device's HSUM status doesn't match the build's.");

        final String title = mContext
                .getString(R.string.wrong_hsum_configuration_notification_title);
        final String message = mContext
                .getString(R.string.wrong_hsum_configuration_notification_message);

        final Notification notification =
                new Notification.Builder(mContext, SystemNotificationChannels.DEVELOPER)
                        .setSmallIcon(R.drawable.stat_sys_adb)
                        .setWhen(0)
                        .setOngoing(true)
                        .setTicker(title)
                        .setDefaults(0)
                        .setColor(mContext.getColor(R.color.system_notification_accent_color))
                        .setContentTitle(title)
                        .setContentText(message)
                        .setVisibility(Notification.VISIBILITY_PUBLIC)
                        .build();

        final NotificationManager notificationManager =
                mContext.getSystemService(NotificationManager.class);
        notificationManager.notifyAsUser(
                null, SystemMessage.NOTE_WRONG_HSUM_STATUS, notification, UserHandle.ALL);
    }

    private ResilientAtomicFile getUserListFile() {
        File tempBackup = new File(mUserListFile.getParent(), mUserListFile.getName() + ".backup");