2022-04-04 21:48:14 -04:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: anupritaisno1 <www.anuprita804@gmail.com>
|
|
|
|
Date: Mon, 18 Oct 2021 04:05:40 +0530
|
|
|
|
Subject: [PATCH] automatically reboot device after timeout if set
|
|
|
|
|
|
|
|
Signed-off-by: anupritaisno1 <www.anuprita804@gmail.com>
|
|
|
|
Change-Id: If891bfbcc144c9336ba013260bad2b7c7a59c054
|
|
|
|
---
|
|
|
|
core/java/android/provider/Settings.java | 7 ++++
|
|
|
|
data/etc/com.android.systemui.xml | 1 +
|
|
|
|
packages/SystemUI/AndroidManifest.xml | 3 ++
|
|
|
|
.../keyguard/KeyguardViewMediator.java | 35 +++++++++++++++++++
|
|
|
|
4 files changed, 46 insertions(+)
|
|
|
|
|
|
|
|
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java
|
2024-02-07 17:17:55 -05:00
|
|
|
index 62805ae63b43..5c7851d3fb41 100644
|
2022-04-04 21:48:14 -04:00
|
|
|
--- a/core/java/android/provider/Settings.java
|
|
|
|
+++ b/core/java/android/provider/Settings.java
|
2024-02-07 17:17:55 -05:00
|
|
|
@@ -16402,6 +16402,13 @@ public final class Settings {
|
2022-04-04 21:48:14 -04:00
|
|
|
* @hide
|
|
|
|
*/
|
|
|
|
public static final String RESTRICTED_NETWORKING_MODE = "restricted_networking_mode";
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Whether to automatically reboot the device after a user defined timeout
|
|
|
|
+ *
|
|
|
|
+ * @hide
|
|
|
|
+ */
|
|
|
|
+ public static final String SETTINGS_REBOOT_AFTER_TIMEOUT = "settings_reboot_after_timeout";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
diff --git a/data/etc/com.android.systemui.xml b/data/etc/com.android.systemui.xml
|
|
|
|
index f2a33de008d6..354fd82f3a0d 100644
|
|
|
|
--- a/data/etc/com.android.systemui.xml
|
|
|
|
+++ b/data/etc/com.android.systemui.xml
|
|
|
|
@@ -48,6 +48,7 @@
|
|
|
|
<permission name="android.permission.READ_NETWORK_USAGE_HISTORY"/>
|
|
|
|
<permission name="android.permission.READ_PRIVILEGED_PHONE_STATE"/>
|
|
|
|
<permission name="android.permission.REAL_GET_TASKS"/>
|
|
|
|
+ <permission name="android.permission.REBOOT"/>
|
|
|
|
<permission name="android.permission.REQUEST_NETWORK_SCORES"/>
|
|
|
|
<permission name="android.permission.RECEIVE_MEDIA_RESOURCE_USAGE"/>
|
|
|
|
<permission name="android.permission.START_ACTIVITIES_FROM_BACKGROUND" />
|
|
|
|
diff --git a/packages/SystemUI/AndroidManifest.xml b/packages/SystemUI/AndroidManifest.xml
|
2022-05-14 23:17:50 -04:00
|
|
|
index cdec5a47b240..3210af7bdebc 100644
|
2022-04-04 21:48:14 -04:00
|
|
|
--- a/packages/SystemUI/AndroidManifest.xml
|
|
|
|
+++ b/packages/SystemUI/AndroidManifest.xml
|
|
|
|
@@ -292,6 +292,9 @@
|
|
|
|
|
|
|
|
<uses-permission android:name="android.permission.READ_PEOPLE_DATA" />
|
|
|
|
|
|
|
|
+ <!-- Permission to allow rebooting the device after a user configurable amount of time -->
|
|
|
|
+ <uses-permission android:name="android.permission.REBOOT" />
|
|
|
|
+
|
2022-05-14 23:17:50 -04:00
|
|
|
<uses-permission android:name="lineageos.permission.WRITE_SETTINGS"/>
|
|
|
|
|
2022-04-04 21:48:14 -04:00
|
|
|
<protected-broadcast android:name="com.android.settingslib.action.REGISTER_SLICE_RECEIVER" />
|
|
|
|
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java
|
2023-12-09 21:22:33 -05:00
|
|
|
index e5e98284c1de..c8c9116ec00a 100644
|
2022-04-04 21:48:14 -04:00
|
|
|
--- a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java
|
|
|
|
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java
|
2022-06-13 11:04:06 -04:00
|
|
|
@@ -187,6 +187,8 @@ public class KeyguardViewMediator extends SystemUI implements Dumpable,
|
2022-04-04 21:48:14 -04:00
|
|
|
|
|
|
|
private final static String TAG = "KeyguardViewMediator";
|
|
|
|
|
|
|
|
+ private static final String DELAYED_REBOOT_ACTION =
|
|
|
|
+ "com.android.internal.policy.impl.PhoneWindowManager.DELAYED_REBOOT";
|
|
|
|
private static final String DELAYED_KEYGUARD_ACTION =
|
|
|
|
"com.android.internal.policy.impl.PhoneWindowManager.DELAYED_KEYGUARD";
|
|
|
|
private static final String DELAYED_LOCK_PROFILE_ACTION =
|
|
|
|
@@ -313,6 +315,11 @@ public class KeyguardViewMediator extends SystemUI implements Dumpable,
|
|
|
|
*/
|
|
|
|
private int mDelayedProfileShowingSequence;
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Same as {@link #mDelayedProfileShowingSequence}, but used for our reboot implementation
|
|
|
|
+ */
|
|
|
|
+ private int mDelayedRebootSequence;
|
|
|
|
+
|
|
|
|
/**
|
|
|
|
* If the user has disabled the keyguard, then requests to exit, this is
|
|
|
|
* how we'll ultimately let them know whether it was successful. We use this
|
2023-08-10 12:40:34 -04:00
|
|
|
@@ -914,6 +921,7 @@ public class KeyguardViewMediator extends SystemUI implements Dumpable,
|
2022-04-04 21:48:14 -04:00
|
|
|
final IntentFilter delayedActionFilter = new IntentFilter();
|
|
|
|
delayedActionFilter.addAction(DELAYED_KEYGUARD_ACTION);
|
|
|
|
delayedActionFilter.addAction(DELAYED_LOCK_PROFILE_ACTION);
|
|
|
|
+ delayedActionFilter.addAction(DELAYED_REBOOT_ACTION);
|
|
|
|
mContext.registerReceiver(mDelayedLockBroadcastReceiver, delayedActionFilter,
|
|
|
|
SYSTEMUI_PERMISSION, null /* scheduler */);
|
|
|
|
|
2023-08-10 12:40:34 -04:00
|
|
|
@@ -1215,6 +1223,18 @@ public class KeyguardViewMediator extends SystemUI implements Dumpable,
|
2022-04-04 21:48:14 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
+ private void doRebootForOwnerAfterTimeoutIfEnabled(long rebootAfterTimeout) {
|
|
|
|
+ long when = SystemClock.elapsedRealtime() + rebootAfterTimeout;
|
|
|
|
+ Intent rebootIntent = new Intent(DELAYED_REBOOT_ACTION);
|
|
|
|
+ rebootIntent.putExtra("seq", mDelayedRebootSequence);
|
|
|
|
+ rebootIntent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
|
|
|
|
+ PendingIntent sender = PendingIntent.getBroadcast(mContext,
|
|
|
|
+ 0, rebootIntent, PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_IMMUTABLE);
|
|
|
|
+ mAlarmManager.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP, when, sender);
|
|
|
|
+ if (DEBUG) Log.d(TAG, "setting alarm to reboot device, timeout = "
|
|
|
|
+ + String.valueOf(rebootAfterTimeout));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
private void doKeyguardForChildProfilesLocked() {
|
|
|
|
UserManager um = UserManager.get(mContext);
|
|
|
|
for (int profileId : um.getEnabledProfileIds(UserHandle.myUserId())) {
|
2023-08-10 12:40:34 -04:00
|
|
|
@@ -1232,6 +1252,10 @@ public class KeyguardViewMediator extends SystemUI implements Dumpable,
|
2022-04-04 21:48:14 -04:00
|
|
|
mDelayedProfileShowingSequence++;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ private void cancelDoRebootForOwnerAfterTimeoutIfEnabled() {
|
|
|
|
+ mDelayedRebootSequence++;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
/**
|
|
|
|
* Let's us know when the device is waking up.
|
|
|
|
*/
|
2023-12-09 21:22:33 -05:00
|
|
|
@@ -1602,6 +1626,10 @@ public class KeyguardViewMediator extends SystemUI implements Dumpable,
|
2022-04-04 21:48:14 -04:00
|
|
|
|
|
|
|
if (DEBUG) Log.d(TAG, "doKeyguard: showing the lock screen");
|
|
|
|
showLocked(options);
|
|
|
|
+ final long rebootAfterTimeout = Settings.Global.getLong(mContext.getContentResolver(), Settings.Global.SETTINGS_REBOOT_AFTER_TIMEOUT, 0);
|
|
|
|
+ if (rebootAfterTimeout >= 1) {
|
|
|
|
+ doRebootForOwnerAfterTimeoutIfEnabled(rebootAfterTimeout);
|
|
|
|
+ }
|
|
|
|
}
|
|
|
|
|
|
|
|
private void lockProfile(int userId) {
|
2023-12-09 21:22:33 -05:00
|
|
|
@@ -1798,6 +1826,12 @@ public class KeyguardViewMediator extends SystemUI implements Dumpable,
|
2022-04-04 21:48:14 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
+ } else if (DELAYED_REBOOT_ACTION.equals(intent.getAction())) {
|
|
|
|
+ final int sequence = intent.getIntExtra("seq", 0);
|
|
|
|
+ if (sequence == mDelayedRebootSequence) {
|
|
|
|
+ PowerManager pm = mContext.getSystemService(PowerManager.class);
|
|
|
|
+ pm.reboot(null);
|
|
|
|
+ }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2023-12-09 21:22:33 -05:00
|
|
|
@@ -2375,6 +2409,7 @@ public class KeyguardViewMediator extends SystemUI implements Dumpable,
|
2022-04-04 21:48:14 -04:00
|
|
|
mHideAnimationRun = false;
|
|
|
|
adjustStatusBarLocked();
|
|
|
|
sendUserPresentBroadcast();
|
|
|
|
+ cancelDoRebootForOwnerAfterTimeoutIfEnabled();
|
|
|
|
}
|
|
|
|
|
|
|
|
private Configuration.Builder createInteractionJankMonitorConf(String tag) {
|