Skip to content

Commit

Permalink
Fix unlocked app issue after CacheCleanerService stop
Browse files Browse the repository at this point in the history
  • Loading branch information
zHd4 committed Jan 4, 2025
1 parent 1cec9cf commit 02d9453
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
21 changes: 21 additions & 0 deletions app/src/main/java/app/notesr/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,25 @@ public boolean serviceRunning(Class<?> serviceClass) {

return foundName != null;
}

public boolean isAnyActivityVisible() {
ActivityManager activityManager = (ActivityManager)
context.getSystemService(Context.ACTIVITY_SERVICE);

if (activityManager != null) {
for (ActivityManager.AppTask task : activityManager.getAppTasks()) {
ActivityManager.RecentTaskInfo taskInfo = task.getTaskInfo();

if (taskInfo != null && taskInfo.topActivity != null) {
String packageName = taskInfo.topActivity.getPackageName();

if (context.getPackageName().equals(packageName)) {
return true;
}
}
}
}

return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,13 @@ public void run() {

stopForeground(STOP_FOREGROUND_REMOVE);
stopSelf();

if (!App.getContext().isAnyActivityVisible()) {
System.exit(0);
}
}
}

//noinspection BusyWait
Thread.sleep(DELAY);
}
} catch (InterruptedException e) {
Expand Down

0 comments on commit 02d9453

Please sign in to comment.