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

Commit 2d566c32 authored by Mao Jinlong's avatar Mao Jinlong
Browse files

Fix time and ringtone issue of power off alarm

Timezone property's value will be reset when system is in encryption
mode like trigger_restart_min_framework. Because only tempfs is mounted
on data partition. So store timezone value in persist alarm folder when
device reboot or shutdown and set the value to timezone when it is
encryption mode.

ExternalStorageProvider and DownloadProvider are necessary for power
off alarm. They are for external storage document content and download
document content. These contents can be set to power off alarm's ringtone.
The original purpose to send alarm action when activity manager service is
ready is that start alarm activity as quickly as possible. But there are
some resources like media contents for power off alarm will be ready only
after boot complete. Remove sending alarm action and start alarm activity
in AlarmInitReceiver when boot is complete. This will have little
effect(less than 2s) to the timestamp when starting alarm activity. The
effect is acceptable.

And add check of mIsPowerOffAlarmSet to avoid writing persist partition
frequently.

Change-Id: I6d662832f05393ddf65f1593ffea2f12da9c4eb8
CRs-Fixed: 1050321, 1046238
parent 43ff3982
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -137,6 +137,12 @@ public class AlarmManager {
     */
    public static final String POWER_OFF_ALARM_INSTANCE_FILE =
            "/persist/alarm/powerOffAlarmInstance";

    /**
     * @hide
     */
    public static final String POWER_OFF_ALARM_TIMEZONE_FILE =
            "/persist/alarm/timezone";
    /**
     * @hide
     */
+2 −0
Original line number Diff line number Diff line
@@ -250,6 +250,8 @@
        <item>com.android.providers.media</item>
        <item>com.android.inputdevices</item>
        <item>com.android.providers.settings</item>
        <item>com.android.externalstorage</item>
        <item>com.android.providers.downloads.ui</item>
    </string-array>

</resources>
+25 −11
Original line number Diff line number Diff line
@@ -933,14 +933,31 @@ class AlarmManagerService extends SystemService {
    long mTotalDelayTime = 0;
    long mMaxDelayTime = 0;

    boolean mIsEncryptStatus = false;
    boolean mIsPowerOffAlarmSet = false;
    @Override
    public void onStart() {
        mNativeData = init();
        mNextWakeup = mNextRtcWakeup = mNextNonWakeup = 0;

        AlarmManager.writePowerOffAlarmFile(AlarmManager.POWER_OFF_ALARM_SET_FILE,
                AlarmManager.POWER_OFF_ALARM_NOT_SET);

        // We have to set current TimeZone info to kernel
        // because kernel doesn't keep this after reboot

        String cryptState = SystemProperties.get("vold.decrypt");
        if (ENCRYPTING_STATE.equals(cryptState) || ENCRYPTED_STATE.equals(cryptState)) {
            mIsEncryptStatus = true;
        }

        if (mIsEncryptStatus) {
            String tz =  AlarmManager
                        .readPowerOffAlarmFile(AlarmManager.POWER_OFF_ALARM_TIMEZONE_FILE);
            setTimeZoneImpl(tz);
        } else {
            setTimeZoneImpl(SystemProperties.get(TIMEZONE_PROPERTY));
        }

        PowerManager pm = (PowerManager) getContext().getSystemService(Context.POWER_SERVICE);
        mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "*alarm*");
@@ -1026,7 +1043,7 @@ class AlarmManagerService extends SystemService {

        TimeZone.setDefault(null);

        if (timeZoneWasChanged) {
        if (timeZoneWasChanged && !mIsEncryptStatus) {
            Intent intent = new Intent(Intent.ACTION_TIMEZONE_CHANGED);
            intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
            intent.putExtra("time-zone", zone.getID());
@@ -1902,12 +1919,6 @@ class AlarmManagerService extends SystemService {
                setLocked(ELAPSED_REALTIME_WAKEUP, firstWakeup.start);
            }

            boolean isEncryptStatus = false;
            String cryptState = SystemProperties.get("vold.decrypt");
            if (ENCRYPTING_STATE.equals(cryptState) || ENCRYPTED_STATE.equals(cryptState)) {
                isEncryptStatus = true;
            }

            // Set RTC_POWEROFF type alarm to kernel
            if (firstRtcWakeup != null && mNextRtcWakeup != firstRtcWakeup.start) {
                mNextRtcWakeup = firstRtcWakeup.start;
@@ -1917,19 +1928,22 @@ class AlarmManagerService extends SystemService {
                    // (power off alarm)
                    String packageName = alarm.packageName;
                    if (DESKCLOCK_PACKAGE_NAME.equals(packageName)) {
                        mIsPowerOffAlarmSet = true;
                        AlarmManager.writePowerOffAlarmFile(AlarmManager.POWER_OFF_ALARM_SET_FILE,
                                AlarmManager.POWER_OFF_ALARM_SET);
                        if (!isEncryptStatus) {
                        if (!mIsEncryptStatus) {
                            AlarmManager.writePowerOffAlarmFile(
                                    AlarmManager.POWER_OFF_ALARM_INSTANCE_FILE, "" + alarm.when);
                        }
                    } else {
                    } else if (mIsPowerOffAlarmSet){
                        mIsPowerOffAlarmSet = false;
                        AlarmManager.writePowerOffAlarmFile(AlarmManager.POWER_OFF_ALARM_SET_FILE,
                                AlarmManager.POWER_OFF_ALARM_NOT_SET);
                    }
                    setLocked(RTC_POWEROFF_WAKEUP, alarm.when);
                }
            } else if (firstRtcWakeup == null){
            } else if (firstRtcWakeup == null && mIsPowerOffAlarmSet){
                mIsPowerOffAlarmSet = false;
                AlarmManager.writePowerOffAlarmFile(AlarmManager.POWER_OFF_ALARM_SET_FILE,
                        AlarmManager.POWER_OFF_ALARM_NOT_SET);
            }
+0 −15
Original line number Diff line number Diff line
@@ -3981,15 +3981,6 @@ public final class ActivityManagerService extends ActivityManagerNative
        return intent;
    }
    /**
     * If system is power off alarm boot mode, we need to start alarm UI.
     */
    void sendAlarmBroadcast() {
        Intent intent = new Intent(ACTION_POWER_OFF_ALARM);
        intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
        mContext.sendBroadcastAsUser(intent, UserHandle.CURRENT);
    }
    boolean startHomeActivityLocked(int userId, String reason) {
        if (mFactoryTest == FactoryTest.FACTORY_TEST_LOW_LEVEL
                && mTopAction == null) {
@@ -13308,12 +13299,6 @@ public final class ActivityManagerService extends ActivityManagerNative
            }
            startHomeActivityLocked(currentUserId, "systemReady");
            // start the power off alarm by boot mode
            boolean isAlarmBoot = SystemProperties.getBoolean("ro.alarm_boot", false);
            if (isAlarmBoot) {
                sendAlarmBroadcast();
            }
            try {
                if (AppGlobals.getPackageManager().hasSystemUidErrors()) {
                    Slog.e(TAG, "UIDs on the system are inconsistent, you need to wipe your"
+2 −0
Original line number Diff line number Diff line
@@ -524,6 +524,8 @@ public final class ShutdownThread extends Thread {
                    AlarmManager.POWER_OFF_ALARM_HANDLED);
        }

        AlarmManager.writePowerOffAlarmFile(AlarmManager.POWER_OFF_ALARM_TIMEZONE_FILE,
                SystemProperties.get("persist.sys.timezone"));
        rebootOrShutdown(mContext, mReboot, mReason);
    }