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

Commit b7f24523 authored by huiwan's avatar huiwan Committed by Steve Kondik
Browse files

Alarm: add support for power off alarm

When phone is in Power-Off Alarm boot mode:

    1. At the correct booting place to trigger the Power-Off Alarm UI
    2. At the Power-Off Alarm alert UI, don't dispatch related physical
           key, such as home, search, etc

Change-Id: I60ede3bde21d26eafb0610946f6d8bf884c85ddb
parent beaabbd8
Loading
Loading
Loading
Loading
+54 −0
Original line number Original line Diff line number Diff line
@@ -245,6 +245,16 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    private static final String ACTION_WIFI_DISPLAY_VIDEO =
    private static final String ACTION_WIFI_DISPLAY_VIDEO =
            "org.codeaurora.intent.action.WIFI_DISPLAY_VIDEO";
            "org.codeaurora.intent.action.WIFI_DISPLAY_VIDEO";


    /**
     * The key indicate whether this is in power off alarm mode.
     */
    private static final String POWER_OFF_ALARM_MODE = "POWER_OFF_ALARM_MODE";

    /**
     * The full power off alarm class name.
     */
    private static final String ALARM_CLASS_NAME = "com.android.deskclock.alarms.AlarmActivity";

    /**
    /**
     * Keyguard stuff
     * Keyguard stuff
     */
     */
@@ -2906,6 +2916,25 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                    + " canceled=" + canceled);
                    + " canceled=" + canceled);
        }
        }


        // If the boot mode is power off alarm, we should not dispatch the several physical key
        // in power off alarm UI.
        String isAlarmBoot = Settings.System.getString(mContext.getContentResolver(),
                POWER_OFF_ALARM_MODE);
        if (DEBUG_INPUT) { Log.d(TAG, "intercept Dispatching isAlarmBoot = " + isAlarmBoot); }

        if (isAlarmBoot!= null && isAlarmBoot.equals("true") && (keyCode == KeyEvent.KEYCODE_HOME
                || keyCode == KeyEvent.KEYCODE_SEARCH
                || keyCode == KeyEvent.KEYCODE_MENU)) {
            if (isAlarmViewTopActivity()) {
                return -1;  // ignore the physical key here
            } else {
                // Since power off alarm UI is not top activity, we should not ignore physical key
                // dispatch, even it is still power off alarm mode.
                Settings.System.putString(mContext.getContentResolver(), POWER_OFF_ALARM_MODE,
                        "false");
            }
        }

        // If we think we might have a volume down & power key chord on the way
        // If we think we might have a volume down & power key chord on the way
        // but we're not sure, then tell the dispatcher to wait a little while and
        // but we're not sure, then tell the dispatcher to wait a little while and
        // try again later before dispatching.
        // try again later before dispatching.
@@ -7339,4 +7368,29 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            mOrientationListener.dump(pw, prefix);
            mOrientationListener.dump(pw, prefix);
        }
        }
    }
    }

    /**
     * Check whether power off alarm view is on top of the activity stack.
     */
    private boolean isAlarmViewTopActivity() {
        List<ActivityManager.RunningTaskInfo> taskList;

        try {
            taskList = ActivityManagerNative.getDefault().getTasks(1, 0);
        } catch (RemoteException e) {
            Log.e(TAG, "isAlarmViewTopActivity get the activity stack failed");
            return false;
        }

        if ((taskList != null)
                && (taskList.get(0) != null)
                && (taskList.get(0).topActivity != null)
                && (taskList.get(0).topActivity.getClassName() != null)
                && (taskList.get(0).topActivity.getClassName().equals(ALARM_CLASS_NAME))) {

            return true;
        }

        return false;
    }
}
}
+24 −0
Original line number Original line Diff line number Diff line
@@ -3226,6 +3226,21 @@ public final class ActivityManagerService extends ActivityManagerNative
        return true;
        return true;
    }
    }
    /**
     * If system is power off alarm boot mode, we need to start the alarm alert
     * view here, to trigger the power off alarm UI.
     */
    void startAlarmActivityLocked() {
        ComponentName compenentName = new ComponentName("com.android.deskclock",
                "com.android.deskclock.alarms.AlarmActivity");
        Intent intent = new Intent();
        intent.setComponent(compenentName);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.putExtra("ro.alarm_boot", true);
        mContext.startActivityAsUser(intent, UserHandle.CURRENT);
    }
    private ActivityInfo resolveActivityInfo(Intent intent, int flags, int userId) {
    private ActivityInfo resolveActivityInfo(Intent intent, int flags, int userId) {
        ActivityInfo ai = null;
        ActivityInfo ai = null;
        ComponentName comp = intent.getComponent();
        ComponentName comp = intent.getComponent();
@@ -11472,6 +11487,15 @@ public final class ActivityManagerService extends ActivityManagerNative
            mBooting = true;
            mBooting = true;
            startHomeActivityLocked(mCurrentUserId, "systemReady");
            startHomeActivityLocked(mCurrentUserId, "systemReady");
            // start the power off alarm by boot mode
            boolean isAlarmBoot = SystemProperties.getBoolean("ro.alarm_boot", false);
            if (isAlarmBoot) {
                if (DEBUG) {
                    Slog.i(TAG, "ActivityManagerService systemReady isAlarmBoot = " + isAlarmBoot);
                }
                startAlarmActivityLocked();
            }
            try {
            try {
                if (AppGlobals.getPackageManager().hasSystemUidErrors()) {
                if (AppGlobals.getPackageManager().hasSystemUidErrors()) {
                    Slog.e(TAG, "UIDs on the system are inconsistent, you need to wipe your"
                    Slog.e(TAG, "UIDs on the system are inconsistent, you need to wipe your"