Skip to content

Commit 5ae6743

Browse files
committed
patch expiry warning: handle System UI force stops
The JobScheduler service will cancel jobs from apps that have been force stopped. In SystemUI's case, the app seems to still run when the main user force stops the app, but the intent that is broadcast on app force stopped is still fired off. JobSchedulerService log output beforehand: Got android.intent.action.PACKAGE_RESTARTED for 10125/com.android.systemui Pulled stopped state of com.android.systemui (10125): false Removing jobs for pkg com.android.systemui at uid 10125 CANCEL: b9480f5 #u0a125/450000 com.android.systemui/.patchlevelwarning.PeriodicPatchLevelExpiryCheck Got android.intent.action.PACKAGE_UNSTOPPED for 10125/com.android.systemui
1 parent 3060dd4 commit 5ae6743

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,6 +1448,12 @@ public void onPrimaryBouncerShowingChanged() {
14481448

14491449
private final Lazy<PatchLevelWarningDialogDelegate> mPatchLevelWarningDialogDelegate;
14501450

1451+
private boolean mIsPatchLevelWarningEnabled = true;
1452+
1453+
private long mPatchLevelJobScheduleKeyguardCheckLastTimeRun = 0;
1454+
1455+
private final long PATCH_LEVEL_JOB_SCHEDULE_KG_CHECK_INTERVAL = 24 * 60 * 60 * 1000; // 1 day
1456+
14511457
private final Handler mBgHandler;
14521458

14531459
private final GlobalSettings mGlobalSettings;
@@ -1694,7 +1700,8 @@ private void setupLocked() {
16941700
final ContentObserver observer = new ContentObserver(mBgHandler) {
16951701
@Override
16961702
public void onChange(boolean selfChange) {
1697-
if (PeriodicPatchLevelExpiryCheck.isPatchLevelWarningEnabled(mContext)) {
1703+
mIsPatchLevelWarningEnabled = PeriodicPatchLevelExpiryCheck.isPatchLevelWarningEnabled(mContext);
1704+
if (mIsPatchLevelWarningEnabled) {
16981705
PeriodicPatchLevelExpiryCheck.schedule(mContext, false);
16991706
} else {
17001707
mPatchLevelWarningDialogDelegate.get().markDontShowOnKeyguard();
@@ -2855,9 +2862,28 @@ private void sendUserPresentBroadcast() {
28552862
}
28562863
mLockPatternUtils.userPresent(currentUserId);
28572864

2865+
// Ensure expiry warning job is always scheduled if warning enabled.
2866+
// Job might be cancelled if the main user of device force stops SystemUI
2867+
// (force stopping System UI will still cause System UI to function)
2868+
if (mIsPatchLevelWarningEnabled) {
2869+
// limit number of calls to JobScheduler.getPendingJob
2870+
final long now = System.currentTimeMillis();
2871+
final long timeBetween = now - mPatchLevelJobScheduleKeyguardCheckLastTimeRun;
2872+
if (timeBetween > PATCH_LEVEL_JOB_SCHEDULE_KG_CHECK_INTERVAL) {
2873+
mPatchLevelJobScheduleKeyguardCheckLastTimeRun = now;
2874+
if (!PeriodicPatchLevelExpiryCheck.isJobScheduled(mContext)) {
2875+
Log.w(TAG, "expected PeriodicPatchLevelExpiryCheck to be scheduled; rescheduling");
2876+
PeriodicPatchLevelExpiryCheck.schedule(mContext, false);
2877+
}
2878+
}
2879+
}
2880+
28582881
// Show expiry warning popup
28592882
// This *could* be done as a separate app, but an implicit broadcast receiver
28602883
// in a manifest wouldn't receive this broadcast.
2884+
//
2885+
// The periodic service marks the local variables in the delegate to avoid
2886+
// having to do calculations on every keyguard unlock.
28612887
if (mPatchLevelWarningDialogDelegate.get().shouldShowOnThisKeyguardUnlock()) {
28622888
maybeShowPatchLevelExpiredDialog();
28632889
}
@@ -2876,8 +2902,9 @@ private void maybeShowPatchLevelExpiredDialog() {
28762902
mPatchLevelWarningDialogDelegate.get().beforeDialogShown();
28772903
// Although the periodic service will mark us to show the dialog on keyguard unlock,
28782904
// need to sanity check this against the actual expiry state and setting
2905+
mIsPatchLevelWarningEnabled = PeriodicPatchLevelExpiryCheck.isPatchLevelWarningEnabled(mContext);
28792906
if (PeriodicPatchLevelExpiryCheck.isPatchLevelExpiredOrUnparseable() &&
2880-
PeriodicPatchLevelExpiryCheck.isPatchLevelWarningEnabled(mContext)) {
2907+
mIsPatchLevelWarningEnabled) {
28812908
// post to UI thread of keyguard because possibly still holding a lock here, and
28822909
// should finish rest of keyguard animations
28832910
mHandler.post(() -> mPatchLevelWarningDialogDelegate.get().createDialog().show());

packages/SystemUI/src/com/android/systemui/patchlevelwarning/PeriodicPatchLevelExpiryCheck.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,13 @@ class PeriodicPatchLevelExpiryCheck : JobService() {
146146
return LocalDate.now() >= getWarningStartDate(securityPatchLocalDate)
147147
}
148148

149+
@JvmStatic
150+
fun isJobScheduled(context: Context): Boolean {
151+
val jobScheduler = context.getSystemService(JobScheduler::class.java)
152+
return (jobScheduler.getPendingJob(JOB_ID) != null)
153+
.also { scheduled -> Log.d(TAG, "isJobScheduled = $scheduled") }
154+
}
155+
149156
@JvmStatic
150157
fun schedule(context: Context, isFromBoot: Boolean = false) {
151158
// SystemUI should only be from system user

0 commit comments

Comments
 (0)