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

Commit a4b3205c authored by kaiyiz's avatar kaiyiz Committed by Brint E. Kriebel
Browse files

DeskClock: Request user to confirm power-on device on power-off alarm event

Show a dialog to request user confirmation to power on the
phone when power-off alarm pops up and user dismisses it.
On user confirmation power-on the phone.Otherwise,keep the
phone switched off.

CRs-fixed: 637275

Change-Id: I20250fa3a86bc51cfaa3bd8b26906755f2726556
parent 187d05e0
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -29,4 +29,5 @@
    <item type="integer" name="world_clocks_per_row">2</item>
    <!-- Total clocks per row is 2 + world_clocks_per_row. -->
    <item type="integer" name="clocks_per_row">4</item>
    <bool name="config_poweron_alert">false</bool>
</resources>
+9 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.PowerManager.WakeLock;
import android.os.SystemProperties;
import android.preference.PreferenceManager;

import com.android.deskclock.alarms.AlarmStateManager;
@@ -34,6 +35,7 @@ public class AlarmInitReceiver extends BroadcastReceiver {

    // A flag that indicates that switching the volume button default was done
    private static final String PREF_VOLUME_DEF_DONE = "vol_def_done";
    private static final String PROP_BOOT_MODE = "ro.alarm_boot";

    /**
     * Sets alarm on ACTION_BOOT_COMPLETED.  Resets alarm on
@@ -67,6 +69,13 @@ public class AlarmInitReceiver extends BroadcastReceiver {
                        Log.v("AlarmInitReceiver - resetting volume button default");
                        switchVolumeButtonDefault(prefs);
                    }
                    boolean poweronAlert = context.getResources()
                            .getBoolean(R.bool.config_poweron_alert);
                    if (poweronAlert) {
                        if(SystemProperties.getBoolean(PROP_BOOT_MODE, false)) {
                            AlarmStateManager.setRtcPowerUp(context, true);
                        }
                    }
                }

                // Update all the alarm instances on time change event
+36 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ import android.app.AlarmManager;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.ActivityNotFoundException;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.Context;
@@ -117,6 +118,13 @@ public final class AlarmStateManager extends BroadcastReceiver {
    // Buffer time in seconds to fire alarm instead of marking it missed.
    public static final int ALARM_FIRE_BUFFER = 15;

    private static boolean sRtcPowerUp = false;
    private static final String ACTION_POWER_ON_ALERT =
            "org.codeaurora.poweronalert.action.POWER_ON_ALERT";
    private static final String ALARM_POWER_OFF_ACTION =
            "org.codeaurora.poweronalert.action.ALARM_POWER_OFF";
    private static final String FIRST_ALARM_FLAG = "first_alarm";

    public static int getGlobalIntentId(Context context) {
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
        return prefs.getInt(ALARM_GLOBAL_ID_EXTRA, -1);
@@ -508,6 +516,13 @@ public final class AlarmStateManager extends BroadcastReceiver {

        // Instance is not valid anymore, so find next alarm that will fire and notify system
        updateNextAlarm(context);
        if (isPowerOffAlarm(context)) {
            try {
                context.startActivity(new Intent(ACTION_POWER_ON_ALERT));
            } catch (ActivityNotFoundException ex) {
                // do nothing, the powerOnAlert app couldn't be found.
            }
        }
    }

    /**
@@ -694,6 +709,9 @@ public final class AlarmStateManager extends BroadcastReceiver {
                break;
            case AlarmInstance.MISSED_STATE:
                setMissedState(context, instance);
                if (isPowerOffAlarm(context)) {
                    context.sendBroadcast(new Intent(ALARM_POWER_OFF_ACTION));
                }
                break;
            case AlarmInstance.DISMISSED_STATE:
                setDismissState(context, instance);
@@ -825,4 +843,22 @@ public final class AlarmStateManager extends BroadcastReceiver {
            setOneminutelate(context, instance);
        }
    }

    public static void setRtcPowerUp(Context context, boolean isRtcPowerUp) {
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
        prefs.edit().putBoolean(FIRST_ALARM_FLAG, isRtcPowerUp).commit();
    }

    /**
     * @return true if the alarm is a power off alarm
     */
    public static boolean isPowerOffAlarm(Context context) {
        boolean isPoAlarm = false;
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
        if (prefs.getBoolean(FIRST_ALARM_FLAG, false)) {
            isPoAlarm = true;
            setRtcPowerUp(context,false);
        }
        return isPoAlarm;
    }
}