Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lock screen if last use is more than 24 hours ago #2685

Merged
merged 1 commit into from
Sep 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/main/java/de/blau/android/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,11 @@ public enum CursorPaddirection {
*/
private static final int MAX_RELATION_SELECTION_DEPTH = 5;

/**
* 24 hours in ms
*/
private static final long ONE_DAY_MS = 24 * 3600 * 1000L;

/**
* Stores the {@link Preferences} as soon as they are available.
*/
Expand Down Expand Up @@ -4028,6 +4033,11 @@ void loadEditingState(@NonNull Main main, boolean setViewBox) {
if (setViewBox) {
editState.setViewBox(this, main.getMap());
}
File editStateFile = main.getFileStreamPath(EDITSTATE_FILENAME);
if (System.currentTimeMillis() - editStateFile.lastModified() > ONE_DAY_MS) {
Log.w(DEBUG_TAG, "App hasn't been run in a long time, locking");
main.lock();
}
}
editingStateRead = true;
}
Expand Down
52 changes: 25 additions & 27 deletions src/main/java/de/blau/android/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -4538,45 +4538,43 @@ private void showFollowButton() {
}
}

/**
* Runnable for locking
*/
private Runnable autoLock = () -> lock();

/**
* Lock screen if we are in a mode in which that can reasonably be done
*/
private Runnable autoLock = new Runnable() { // NOSONAR
@Override
public void run() {
if (!App.getLogic().isLocked()) {
EasyEditManager manager = getEasyEditManager();
boolean elementSelected = manager.inElementSelectedMode() || manager.inNewNoteSelectedMode();
if (!manager.isProcessingAction() || elementSelected) {
View lock = getLock();
if (lock != null) {
lock.performClick();
}
if (elementSelected) {
App.getLogic().deselectAll();
map.deselectObjects();
manager.finish();
}
} else {
// can't lock now, reschedule
if (prefs != null) {
int delay = prefs.getAutolockDelay();
if (delay > 0) {
map.postDelayed(autoLock, delay);
}
}
}
public void lock() {
if (App.getLogic().isLocked()) {
return;
}
EasyEditManager manager = getEasyEditManager();
boolean elementSelected = manager.inElementSelectedMode() || manager.inNewNoteSelectedMode();
if (!manager.isProcessingAction() || elementSelected) {
View lock = getLock();
if (lock != null) {
lock.performClick();
}
if (elementSelected) {
App.getLogic().deselectAll();
map.deselectObjects();
manager.finish();
}
} else {
// can't lock now, reschedule
scheduleAutoLock();
}
};
}

/**
* Schedule automatic locking of the screen in a configurable time in the future
*/
public void scheduleAutoLock() {
map.removeCallbacks(autoLock);
if (prefs != null) {
int delay = prefs.getAutolockDelay();
long delay = prefs.getAutolockDelay();
if (delay > 0) {
map.postDelayed(autoLock, delay);
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/de/blau/android/prefs/Preferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -1173,12 +1173,12 @@ public int getNotificationCacheSize() {
}

/**
* Get the number of seconds we should wait before locking the display
* Get the number of milliseconds we should wait before locking the display
*
* @return delay in seconds till we auto-lock
* @return delay in milliseconds till we auto-lock
*/
public int getAutolockDelay() {
return 1000 * autoLockDelay;
public long getAutolockDelay() {
return 1000L * autoLockDelay;
}

/**
Expand Down
Loading