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

Commit 60179584 authored by huiwan's avatar huiwan
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 3dfb5ec9
Loading
Loading
Loading
Loading
+55 −0
Original line number Original line Diff line number Diff line
@@ -118,6 +118,7 @@ import java.io.FileReader;
import java.io.IOException;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.HashSet;
import java.util.List;


import static android.view.WindowManager.LayoutParams.*;
import static android.view.WindowManager.LayoutParams.*;
import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT;
import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT;
@@ -227,6 +228,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
     */
     */
@@ -2405,6 +2416,25 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            }
            }
        }
        }


        // 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.
@@ -6531,4 +6561,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
@@ -3339,6 +3339,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();
@@ -11387,6 +11402,15 @@ public final class ActivityManagerService extends ActivityManagerNative
            mBooting = true;
            mBooting = true;
            startHomeActivityLocked(mCurrentUserId);
            startHomeActivityLocked(mCurrentUserId);
            // 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()) {
                    Message msg = Message.obtain();
                    Message msg = Message.obtain();