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

Commit 5b04546a authored by Mao Jinlong's avatar Mao Jinlong 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 54face31
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -104,8 +104,9 @@ public class AlarmManager {
     * Alarm time in {@link System#currentTimeMillis System.currentTimeMillis()}
     * (wall clock time in UTC), which will wake up the device when
     * it goes off. And it will power on the devices when it shuts down.
     * Set as 5 to make it be compatible with android_alarm_type.
     */
    public static final int RTC_POWEROFF_WAKEUP = 4;
    public static final int RTC_POWEROFF_WAKEUP = 5;

    /**
     * Broadcast Action: Sent after the value returned by
+11 −0
Original line number Diff line number Diff line
@@ -2864,6 +2864,15 @@ public final class Settings {

        private static final Validator TEXT_AUTO_CAPS_VALIDATOR = sBooleanValidator;

        /**
         * Setting to show if system is in power off alarm mode. 1 = true, 0 = false
         * @hide
         */
        public static final String POWER_OFF_ALARM_MODE = "power_off_alarm_mode";

        /** Validator for POWER_OFF_ALARM_MODE */
        private static final Validator POWER_OFF_ALARM_MODE_VALIDATOR = sBooleanValidator;

        /**
         * Setting to enable Auto Punctuate in text editors. 1 = On, 0 = Off. This
         * feature converts two spaces to a "." and space.
@@ -3579,6 +3588,7 @@ public final class Settings {
            PUBLIC_SETTINGS.add(SOUND_EFFECTS_ENABLED);
            PUBLIC_SETTINGS.add(HAPTIC_FEEDBACK_ENABLED);
            PUBLIC_SETTINGS.add(SHOW_WEB_SUGGESTIONS);
            PUBLIC_SETTINGS.add(POWER_OFF_ALARM_MODE);
        }

        /**
@@ -3704,6 +3714,7 @@ public final class Settings {
            VALIDATORS.put(WIFI_STATIC_NETMASK, WIFI_STATIC_NETMASK_VALIDATOR);
            VALIDATORS.put(WIFI_STATIC_DNS1, WIFI_STATIC_DNS1_VALIDATOR);
            VALIDATORS.put(WIFI_STATIC_DNS2, WIFI_STATIC_DNS2_VALIDATOR);
            VALIDATORS.put(POWER_OFF_ALARM_MODE, POWER_OFF_ALARM_MODE_VALIDATOR);
        }

        /**
+20 −0
Original line number Diff line number Diff line
@@ -300,6 +300,11 @@ public final class ActivityManagerService extends ActivityManagerNative
    private static final String TAG_VISIBILITY = TAG + POSTFIX_VISIBILITY;
    private static final String TAG_VISIBLE_BEHIND = TAG + POSTFIX_VISIBLE_BEHIND;
    private static final String ACTION_POWER_OFF_ALARM =
            "org.codeaurora.alarm.action.POWER_OFF_ALARM";
    private static final String POWER_OFF_ALARM = "powerOffAlarm";
    /** Control over CPU and battery monitoring */
    // write battery stats every 30 minutes.
    static final long BATTERY_STATS_TIME = 30 * 60 * 1000;
@@ -3608,6 +3613,15 @@ public final class ActivityManagerService extends ActivityManagerNative
        return true;
    }
    /**
     * If system is power off alarm boot mode, we need to start alarm UI.
     */
    void startAlarmActivityLocked() {
        Intent intent = new Intent(ACTION_POWER_OFF_ALARM);
        intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
        mContext.startActivityAsUser(intent, UserHandle.CURRENT);
    }
    private ActivityInfo resolveActivityInfo(Intent intent, int flags, int userId) {
        ActivityInfo ai = null;
        ComponentName comp = intent.getComponent();
@@ -12062,6 +12076,12 @@ public final class ActivityManagerService extends ActivityManagerNative
            mBooting = true;
            startHomeActivityLocked(mCurrentUserId, "systemReady");
            // start the power off alarm by boot mode
            boolean isAlarmBoot = SystemProperties.getBoolean("ro.alarm_boot", false);
            if (isAlarmBoot) {
                startAlarmActivityLocked();
            }
            try {
                if (AppGlobals.getPackageManager().hasSystemUidErrors()) {
                    Slog.e(TAG, "UIDs on the system are inconsistent, you need to wipe your"
+13 −0
Original line number Diff line number Diff line
@@ -3137,6 +3137,19 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                    + " canceled=" + canceled);
        }

        // If the boot mode is power off alarm, we should not dispatch the several physical keys
        // in power off alarm UI to avoid pausing power off alarm UI.
        int isPowerOffAlarmMode = Settings.System.getInt(mContext.getContentResolver(),
                Settings.System.POWER_OFF_ALARM_MODE, 0);
        if (DEBUG_INPUT) { Log.d(TAG, "intercept Dispatching isPowerOffAlarmMode = " +
                isPowerOffAlarmMode); }

        if (isPowerOffAlarmMode == 1 && (keyCode == KeyEvent.KEYCODE_HOME
                || keyCode == KeyEvent.KEYCODE_SEARCH
                || keyCode == KeyEvent.KEYCODE_MENU)) {
            return -1;  // ignore the physical key here
        }

        // 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
        // try again later before dispatching.
+1 −0
Original line number Diff line number Diff line
@@ -55,6 +55,7 @@ static const clockid_t android_alarm_to_clockid[N_ANDROID_TIMERFDS] = {
    CLOCK_BOOTTIME_ALARM,
    CLOCK_BOOTTIME,
    CLOCK_MONOTONIC,
    CLOCK_POWEROFF_ALARM,
    CLOCK_REALTIME,
};
/* to match the legacy alarm driver implementation, we need an extra