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

Commit e5dff82b authored by JW Wang's avatar JW Wang
Browse files

DSU enhancement (4/N)

* Support hiding notification
  This allows the client to provide customized UI
  to enter/exit DSU without using the notifications
  from the status bar.

Bug: 277691885
Test: adb shell am start-service --user 0 \
  -n com.android.dynsystem/com.android.dynsystem.DynamicSystemInstallationService \
  -a android.os.image.action.HIDE_NOTIFICATION
Change-Id: I3f51e6caf0d3b336a71b6154d644f89624cd9491
parent d4bf2448
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -202,6 +202,13 @@ public class DynamicSystemClient {
    public static final String ACTION_NOTIFY_IF_IN_USE =
            "android.os.image.action.NOTIFY_IF_IN_USE";

    /**
     * Intent action: hide notifications about the status of {@code DynamicSystem}.
     * @hide
     */
    public static final String ACTION_HIDE_NOTIFICATION =
            "android.os.image.action.HIDE_NOTIFICATION";

    /*
     * Intent Keys
     */
+22 −4
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.dynsystem;
import static android.os.AsyncTask.Status.FINISHED;
import static android.os.AsyncTask.Status.PENDING;
import static android.os.AsyncTask.Status.RUNNING;
import static android.os.image.DynamicSystemClient.ACTION_HIDE_NOTIFICATION;
import static android.os.image.DynamicSystemClient.ACTION_NOTIFY_IF_IN_USE;
import static android.os.image.DynamicSystemClient.ACTION_START_INSTALL;
import static android.os.image.DynamicSystemClient.CAUSE_ERROR_EXCEPTION;
@@ -173,6 +174,7 @@ public class DynamicSystemInstallationService extends Service
    // This is for testing only now
    private boolean mEnableWhenCompleted;
    private boolean mOneShot;
    private boolean mHideNotification;

    private InstallationAsyncTask.Progress mInstallTaskProgress;
    private InstallationAsyncTask mInstallTask;
@@ -230,6 +232,8 @@ public class DynamicSystemInstallationService extends Service
            executeRebootToNormalCommand();
        } else if (ACTION_NOTIFY_IF_IN_USE.equals(action)) {
            executeNotifyIfInUseCommand();
        } else if (ACTION_HIDE_NOTIFICATION.equals(action)) {
            executeHideNotificationCommand();
        }

        return Service.START_NOT_STICKY;
@@ -441,12 +445,16 @@ public class DynamicSystemInstallationService extends Service
    private void executeNotifyIfInUseCommand() {
        switch (getStatus()) {
            case STATUS_IN_USE:
                if (!mHideNotification) {
                    startForeground(NOTIFICATION_ID,
                            buildNotification(STATUS_IN_USE, CAUSE_NOT_SPECIFIED));
                }
                break;
            case STATUS_READY:
                if (!mHideNotification) {
                    startForeground(NOTIFICATION_ID,
                            buildNotification(STATUS_READY, CAUSE_NOT_SPECIFIED));
                }
                break;
            case STATUS_IN_PROGRESS:
                break;
@@ -456,6 +464,16 @@ public class DynamicSystemInstallationService extends Service
        }
    }

    private void executeHideNotificationCommand() {
        mHideNotification = true;
        switch (getStatus()) {
            case STATUS_IN_USE:
            case STATUS_READY:
                stopForeground(STOP_FOREGROUND_REMOVE);
                break;
        }
    }

    private void resetTaskAndStop() {
        resetTaskAndStop(/* removeNotification= */ false);
    }