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

Commit 68ad3d11 authored by Jerry Zhang's avatar Jerry Zhang Committed by Gerrit Code Review
Browse files

Merge "DO NOT MERGE: Add ScreenObserver"

parents 61fa3138 1b4b3c4e
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -268,4 +268,11 @@ public abstract class ActivityManagerInternal {
     * @param token The IApplicationToken for the activity
     */
    public abstract void setFocusedActivity(IBinder token);

    public interface ScreenObserver {
        public void onAwakeStateChanged(boolean isAwake);
        public void onKeyguardStateChanged(boolean isShowing);
    }

    public abstract void registerScreenObserver(ScreenObserver observer);
}
+25 −32
Original line number Diff line number Diff line
@@ -200,6 +200,7 @@ import android.app.ActivityManager.StackInfo;
import android.app.ActivityManager.TaskSnapshot;
import android.app.ActivityManager.TaskThumbnailInfo;
import android.app.ActivityManagerInternal;
import android.app.ActivityManagerInternal.ScreenObserver;
import android.app.ActivityManagerInternal.SleepToken;
import android.app.ActivityOptions;
import android.app.ActivityThread;
@@ -1548,6 +1549,8 @@ public class ActivityManagerService extends IActivityManager.Stub
        }
    }
    final List<ScreenObserver> mScreenObservers = new ArrayList<>();
    final RemoteCallbackList<IProcessObserver> mProcessObservers = new RemoteCallbackList<>();
    ProcessChangeItem[] mActiveProcessChanges = new ProcessChangeItem[5];
@@ -1689,6 +1692,8 @@ public class ActivityManagerService extends IActivityManager.Stub
    static final int PUSH_TEMP_WHITELIST_UI_MSG = 68;
    static final int SERVICE_FOREGROUND_CRASH_MSG = 69;
    static final int DISPATCH_OOM_ADJ_OBSERVER_MSG = 70;
    static final int DISPATCH_SCREEN_AWAKE_MSG = 71;
    static final int DISPATCH_SCREEN_KEYGUARD_MSG = 72;
    static final int START_USER_SWITCH_FG_MSG = 712;
    static final int NOTIFY_VR_KEYGUARD_MSG = 74;
@@ -2412,11 +2417,17 @@ public class ActivityManagerService extends IActivityManager.Stub
                    }
                }
            } break;
            case NOTIFY_VR_SLEEPING_MSG: {
                notifyVrManagerOfSleepState(msg.arg1 != 0);
            case DISPATCH_SCREEN_AWAKE_MSG: {
                final boolean isAwake = msg.arg1 != 0;
                for (int i = mScreenObservers.size() - 1; i >= 0; i--) {
                    mScreenObservers.get(i).onAwakeStateChanged(isAwake);
                }
            } break;
            case NOTIFY_VR_KEYGUARD_MSG: {
                notifyVrManagerOfKeyguardState(msg.arg1 != 0);
            case DISPATCH_SCREEN_KEYGUARD_MSG: {
                final boolean isShowing = msg.arg1 != 0;
                for (int i = mScreenObservers.size() - 1; i >= 0; i--) {
                    mScreenObservers.get(i).onKeyguardStateChanged(isShowing);
                }
            } break;
            case HANDLE_TRUST_STORAGE_UPDATE_MSG: {
                synchronized (ActivityManagerService.this) {
@@ -3260,32 +3271,6 @@ public class ActivityManagerService extends IActivityManager.Stub
                mHandler.obtainMessage(VR_MODE_CHANGE_MSG, 0, 0, r));
    }
    private void sendNotifyVrManagerOfSleepState(boolean isSleeping) {
        mHandler.sendMessage(
                mHandler.obtainMessage(NOTIFY_VR_SLEEPING_MSG, isSleeping ? 1 : 0, 0));
    }
    private void notifyVrManagerOfSleepState(boolean isSleeping) {
        final VrManagerInternal vrService = LocalServices.getService(VrManagerInternal.class);
        if (vrService == null) {
            return;
        }
        vrService.onSleepStateChanged(isSleeping);
    }
    private void sendNotifyVrManagerOfKeyguardState(boolean isShowing) {
        mHandler.sendMessage(
                mHandler.obtainMessage(NOTIFY_VR_KEYGUARD_MSG, isShowing ? 1 : 0, 0));
    }
    private void notifyVrManagerOfKeyguardState(boolean isShowing) {
        final VrManagerInternal vrService = LocalServices.getService(VrManagerInternal.class);
        if (vrService == null) {
            return;
        }
        vrService.onKeyguardStateChanged(isShowing);
    }
    final void showAskCompatModeDialogLocked(ActivityRecord r) {
        Message msg = Message.obtain();
        msg.what = SHOW_COMPAT_MODE_DIALOG_UI_MSG;
@@ -12497,7 +12482,8 @@ public class ActivityManagerService extends IActivityManager.Stub
            if (wasAwake != isAwake) {
                // Also update state in a special way for running foreground services UI.
                mServices.updateScreenStateLocked(isAwake);
                sendNotifyVrManagerOfSleepState(!isAwake);
                mHandler.obtainMessage(DISPATCH_SCREEN_AWAKE_MSG, isAwake ? 1 : 0, 0)
                        .sendToTarget();
            }
        }
    }
@@ -12650,7 +12636,9 @@ public class ActivityManagerService extends IActivityManager.Stub
                Binder.restoreCallingIdentity(ident);
            }
        }
        sendNotifyVrManagerOfKeyguardState(showing);
        mHandler.obtainMessage(DISPATCH_SCREEN_KEYGUARD_MSG, showing ? 1 : 0, 0)
                .sendToTarget();
    }
    @Override
@@ -24258,6 +24246,11 @@ public class ActivityManagerService extends IActivityManager.Stub
                }
            }
        }
        @Override
        public void registerScreenObserver(ScreenObserver observer) {
            mScreenObservers.add(observer);
        }
    }
    /**
+0 −14
Original line number Diff line number Diff line
@@ -58,13 +58,6 @@ public abstract class VrManagerInternal {
    public abstract void setVrMode(boolean enabled, @NonNull ComponentName packageName,
            int userId, int processId, @NonNull ComponentName calling);

    /**
     * Set whether the system has acquired a sleep token.
     *
     * @param isAsleep is {@code true} if the device is asleep, or {@code false} otherwise.
     */
    public abstract void onSleepStateChanged(boolean isAsleep);

    /**
     * Set whether the display used for VR output is on.
     *
@@ -73,13 +66,6 @@ public abstract class VrManagerInternal {
     */
    public abstract void onScreenStateChanged(boolean isScreenOn);

    /**
     * Set whether the keyguard is currently active/showing.
     *
     * @param isShowing is {@code true} if the keyguard is active/showing.
     */
    public abstract void onKeyguardStateChanged(boolean isShowing);

    /**
     * Return NO_ERROR if the given package is installed on the device and enabled as a
     * VrListenerService for the given current user, or a negative error code indicating a failure.
+13 −16
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ import static android.view.Display.INVALID_DISPLAY;

import android.Manifest;
import android.app.ActivityManagerInternal;
import android.app.ActivityManagerInternal.ScreenObserver;
import android.app.ActivityManager;
import android.app.AppOpsManager;
import android.app.INotificationManager;
@@ -104,7 +105,8 @@ import java.util.Objects;
 *
 * @hide
 */
public class VrManagerService extends SystemService implements EnabledComponentChangeListener{
public class VrManagerService extends SystemService
        implements EnabledComponentChangeListener, ScreenObserver {

    public static final String TAG = "VrManagerService";
    static final boolean DBG = false;
@@ -231,15 +233,17 @@ public class VrManagerService extends SystemService implements EnabledComponentC
        }
    }

    private void setSleepState(boolean isAsleep) {
        setSystemState(FLAG_AWAKE, !isAsleep);
    }

    private void setScreenOn(boolean isScreenOn) {
        setSystemState(FLAG_SCREEN_ON, isScreenOn);
    }

    private void setKeyguardShowing(boolean isShowing) {
    @Override
    public void onAwakeStateChanged(boolean isAwake) {
        setSystemState(FLAG_AWAKE, isAwake);
    }

    @Override
    public void onKeyguardStateChanged(boolean isShowing) {
        setSystemState(FLAG_KEYGUARD_UNLOCKED, !isShowing);
    }

@@ -674,21 +678,11 @@ public class VrManagerService extends SystemService implements EnabledComponentC
            VrManagerService.this.setVrMode(enabled, packageName, userId, processId, callingPackage);
        }

        @Override
        public void onSleepStateChanged(boolean isAsleep) {
            VrManagerService.this.setSleepState(isAsleep);
        }

        @Override
        public void onScreenStateChanged(boolean isScreenOn) {
            VrManagerService.this.setScreenOn(isScreenOn);
        }

        @Override
        public void onKeyguardStateChanged(boolean isShowing) {
            VrManagerService.this.setKeyguardShowing(isShowing);
        }

        @Override
        public boolean isCurrentVrListener(String packageName, int userId) {
            return VrManagerService.this.isCurrentVrListener(packageName, userId);
@@ -740,6 +734,9 @@ public class VrManagerService extends SystemService implements EnabledComponentC
    @Override
    public void onBootPhase(int phase) {
        if (phase == SystemService.PHASE_SYSTEM_SERVICES_READY) {
            LocalServices.getService(ActivityManagerInternal.class)
                    .registerScreenObserver(this);

            mNotificationManager = INotificationManager.Stub.asInterface(
                    ServiceManager.getService(Context.NOTIFICATION_SERVICE));
            synchronized (mLock) {