mirror of
https://github.com/mollyim/mollyim-android.git
synced 2025-05-12 21:30:39 +01:00
Add experimental softlock
This commit is contained in:
parent
d4440cf380
commit
b09a0f526e
3 changed files with 26 additions and 19 deletions
|
@ -281,18 +281,6 @@ public class ApplicationContext extends MultiDexApplication implements AppForegr
|
|||
@MainThread
|
||||
public void onLock() {
|
||||
Log.i(TAG, "onLock()");
|
||||
|
||||
stopService(new Intent(this, WebRtcCallService.class));
|
||||
|
||||
finalizeExpiringMessageManager();
|
||||
finalizeMessageRetrieval();
|
||||
unregisterKeyEventReceiver();
|
||||
|
||||
ThreadUtil.runOnMainDelayed(() -> {
|
||||
ApplicationDependencies.getJobManager().shutdown(TimeUnit.SECONDS.toMillis(10));
|
||||
KeyCachingService.clearMasterSecret();
|
||||
WipeMemoryService.run(this, true);
|
||||
}, TimeUnit.SECONDS.toMillis(1));
|
||||
}
|
||||
|
||||
public void checkBuildExpiration() {
|
||||
|
|
|
@ -62,7 +62,7 @@ public abstract class PassphraseRequiredActivity extends PassphraseActivity impl
|
|||
AppStartup.getInstance().onCriticalRenderEventStart();
|
||||
onPreCreate();
|
||||
|
||||
final boolean locked = KeyCachingService.isLocked();
|
||||
final boolean locked = KeyCachingService.isSoftLocked();
|
||||
routeApplicationState(locked);
|
||||
|
||||
if (!locked) {
|
||||
|
|
|
@ -76,12 +76,18 @@ public class KeyCachingService extends Service {
|
|||
|
||||
private static volatile boolean locking;
|
||||
|
||||
private static volatile boolean softLocked = true;
|
||||
|
||||
public KeyCachingService() {}
|
||||
|
||||
public static synchronized boolean isLocked() {
|
||||
return masterSecret == null || locking;
|
||||
}
|
||||
|
||||
public static synchronized boolean isSoftLocked() {
|
||||
return softLocked;
|
||||
}
|
||||
|
||||
public static synchronized MasterSecret getMasterSecret() {
|
||||
if (masterSecret == null) {
|
||||
throw new IllegalStateException();
|
||||
|
@ -91,6 +97,7 @@ public class KeyCachingService extends Service {
|
|||
|
||||
public static synchronized void setMasterSecret(final MasterSecret newMasterSecret) {
|
||||
masterSecret = newMasterSecret;
|
||||
softLocked = false;
|
||||
}
|
||||
|
||||
public static synchronized void clearMasterSecret() {
|
||||
|
@ -176,15 +183,11 @@ public class KeyCachingService extends Service {
|
|||
return;
|
||||
}
|
||||
|
||||
KeyCachingService.locking = true;
|
||||
KeyCachingService.softLocked = true;
|
||||
|
||||
sendPackageBroadcast(CLEAR_KEY_EVENT);
|
||||
|
||||
SignalExecutors.BOUNDED.execute(() -> {
|
||||
MessageNotifier messageNotifier = ApplicationDependencies.getMessageNotifier();
|
||||
messageNotifier.cancelDelayedNotifications();
|
||||
messageNotifier.clearNotifications(KeyCachingService.this);
|
||||
});
|
||||
foregroundServiceSoftLock();
|
||||
}
|
||||
|
||||
private void handleLocaleChanged() {
|
||||
|
@ -252,6 +255,22 @@ public class KeyCachingService extends Service {
|
|||
startForeground(SERVICE_RUNNING_ID, builder.build());
|
||||
}
|
||||
|
||||
private void foregroundServiceSoftLock() {
|
||||
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, NotificationChannels.LOCKED_STATUS);
|
||||
|
||||
builder.setContentTitle(getString(R.string.prompt_passphrase_activity__signal_is_locked));
|
||||
builder.setContentText(getString(R.string.KeyCachingService_signal_passphrase_cached));
|
||||
builder.setSmallIcon(R.drawable.ic_lock_white_48dp);
|
||||
builder.setColor(getResources().getColor(R.color.core_ultramarine));
|
||||
builder.setWhen(0);
|
||||
builder.setPriority(NotificationCompat.PRIORITY_LOW);
|
||||
builder.setPriority(NotificationCompat.PRIORITY_MIN);
|
||||
|
||||
builder.setContentIntent(buildLaunchIntent());
|
||||
|
||||
startForeground(SERVICE_RUNNING_ID, builder.build());
|
||||
}
|
||||
|
||||
private void sendPackageBroadcast(String action) {
|
||||
Log.i(TAG, "Broadcasting " + action);
|
||||
|
||||
|
|
Loading…
Reference in a new issue