|
28 | 28 | import android.os.Handler;
|
29 | 29 | import android.os.PowerManager;
|
30 | 30 | import android.os.SystemProperties;
|
31 |
| - |
32 | 31 | import android.preference.PreferenceManager;
|
33 | 32 | import android.provider.Settings;
|
34 | 33 | import android.support.v4.app.NotificationManagerCompat;
|
@@ -150,11 +149,6 @@ public final class AlarmStateManager extends BroadcastReceiver {
|
150 | 149 | private static StateChangeScheduler sStateChangeScheduler =
|
151 | 150 | new AlarmManagerStateChangeScheduler();
|
152 | 151 |
|
153 |
| - private static final String ACTION_POWER_ON_ALERT = |
154 |
| - "org.codeaurora.poweronalert.action.POWER_ON_ALERT"; |
155 |
| - private static final String ACTION_POWER_OFF = |
156 |
| - "org.codeaurora.poweronalert.action.ALARM_POWER_OFF"; |
157 |
| - |
158 | 152 | private static Calendar getCurrentTime() {
|
159 | 153 | return sCurrentTimeFactory == null ?
|
160 | 154 | Calendar.getInstance() : sCurrentTimeFactory.getCurrentTime();
|
@@ -547,7 +541,7 @@ public void run() {
|
547 | 541 | updateNextAlarm(context);
|
548 | 542 |
|
549 | 543 | if (isAlarmBoot()) {
|
550 |
| - context.sendBroadcast(new Intent(ACTION_POWER_OFF)); |
| 544 | + powerOff(context); |
551 | 545 | }
|
552 | 546 | }
|
553 | 547 |
|
@@ -630,8 +624,7 @@ public static void setDismissState(Context context, AlarmInstance instance) {
|
630 | 624 | AlarmInstance.updateInstance(contentResolver, instance);
|
631 | 625 |
|
632 | 626 | if (isAlarmBoot()) {
|
633 |
| - context.startActivity(new Intent(ACTION_POWER_ON_ALERT) |
634 |
| - .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); |
| 627 | + reboot(context); |
635 | 628 | }
|
636 | 629 | }
|
637 | 630 |
|
@@ -901,7 +894,7 @@ private static void setAlarmState(Context context, AlarmInstance instance, int s
|
901 | 894 | case AlarmInstance.MISSED_STATE:
|
902 | 895 | setMissedState(context, instance);
|
903 | 896 | if (isAlarmBoot()) {
|
904 |
| - context.sendBroadcast(new Intent(ACTION_POWER_OFF)); |
| 897 | + powerOff(context); |
905 | 898 | }
|
906 | 899 | break;
|
907 | 900 | case AlarmInstance.PREDISMISSED_STATE:
|
@@ -1141,10 +1134,28 @@ public static void setChangeAlarmState(Context context, AlarmInstance instance,
|
1141 | 1134 | }
|
1142 | 1135 | }
|
1143 | 1136 |
|
1144 |
| - /* |
1145 |
| - * Check if it is alarm boot |
| 1137 | + /** |
| 1138 | + * Check if the device booted because of an alarm |
| 1139 | + */ |
| 1140 | + public static boolean isAlarmBoot() { |
| 1141 | + return SystemProperties.getBoolean("ro.alarm_boot", false); |
| 1142 | + } |
| 1143 | + |
| 1144 | + /** |
| 1145 | + * Power off immediately |
| 1146 | + */ |
| 1147 | + private static void powerOff(Context context) { |
| 1148 | + Intent requestShutdown = new Intent(Intent.ACTION_REQUEST_SHUTDOWN); |
| 1149 | + requestShutdown.putExtra(Intent.EXTRA_KEY_CONFIRM, false); |
| 1150 | + requestShutdown.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1151 | + context.startActivity(requestShutdown); |
| 1152 | + } |
| 1153 | + |
| 1154 | + /** |
| 1155 | + * Reboot immediately |
1146 | 1156 | */
|
1147 |
| - public static boolean isAlarmBoot () { |
1148 |
| - return SystemProperties.getBoolean("ro.alarm_boot", false); |
| 1157 | + private static void reboot(Context context) { |
| 1158 | + PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); |
| 1159 | + pm.reboot(null); |
1149 | 1160 | }
|
1150 | 1161 | }
|
0 commit comments