mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 02:39:05 +01:00
Remove LOCK button from foreground notification
When the user removes the screen lock, the app does not get really locked. There is no way about getting notified about this. Before users lock the app without it getting actually locked, we rather remove the button that was collapsed and not easy to find anyway.
This commit is contained in:
@@ -35,7 +35,6 @@ import org.briarproject.briar.R;
|
||||
import org.briarproject.briar.android.contact.ConversationActivity;
|
||||
import org.briarproject.briar.android.forum.ForumActivity;
|
||||
import org.briarproject.briar.android.login.SignInReminderReceiver;
|
||||
import org.briarproject.briar.android.login.UnlockActivity;
|
||||
import org.briarproject.briar.android.navdrawer.NavDrawerActivity;
|
||||
import org.briarproject.briar.android.privategroup.conversation.GroupActivity;
|
||||
import org.briarproject.briar.android.splash.SplashScreenActivity;
|
||||
@@ -277,12 +276,11 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
||||
@UiThread
|
||||
@Override
|
||||
public Notification getForegroundNotification() {
|
||||
return getForegroundNotification(false, false);
|
||||
return getForegroundNotification(false);
|
||||
}
|
||||
|
||||
@UiThread
|
||||
private Notification getForegroundNotification(boolean lockable,
|
||||
boolean locked) {
|
||||
private Notification getForegroundNotification(boolean locked) {
|
||||
int title = locked ? R.string.lock_is_locked :
|
||||
R.string.ongoing_notification_title;
|
||||
int text = locked ? R.string.lock_tap_to_unlock :
|
||||
@@ -304,24 +302,13 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
||||
b.setVisibility(VISIBILITY_SECRET);
|
||||
}
|
||||
b.setPriority(PRIORITY_MIN);
|
||||
|
||||
// Add a 'Lock' action
|
||||
if (lockable && !locked) {
|
||||
String actionTitle = appContext.getString(R.string.lock_lock);
|
||||
Intent i1 = new Intent(appContext, UnlockActivity.class);
|
||||
i1.setAction(ACTION_LOCK);
|
||||
PendingIntent actionIntent =
|
||||
PendingIntent.getActivity(appContext, 0, i1, 0);
|
||||
b.addAction(R.drawable.startup_lock, actionTitle, actionIntent);
|
||||
}
|
||||
return b.build();
|
||||
}
|
||||
|
||||
@UiThread
|
||||
@Override
|
||||
public void updateForegroundNotification(boolean lockable,
|
||||
boolean locked) {
|
||||
Notification n = getForegroundNotification(lockable, locked);
|
||||
public void updateForegroundNotification(boolean locked) {
|
||||
Notification n = getForegroundNotification(locked);
|
||||
notificationManager.notify(ONGOING_NOTIFICATION_ID, n);
|
||||
}
|
||||
|
||||
|
||||
@@ -204,10 +204,7 @@ public class AppModule {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
LockManager provideLockManager(LifecycleManager lifecycleManager,
|
||||
EventBus eventBus, LockManagerImpl lockManager) {
|
||||
lifecycleManager.registerService(lockManager);
|
||||
eventBus.addListener(lockManager);
|
||||
LockManager provideLockManager(LockManagerImpl lockManager) {
|
||||
return lockManager;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,14 +8,10 @@ import android.support.annotation.UiThread;
|
||||
|
||||
import org.briarproject.bramble.api.db.DatabaseExecutor;
|
||||
import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.bramble.api.event.Event;
|
||||
import org.briarproject.bramble.api.event.EventListener;
|
||||
import org.briarproject.bramble.api.lifecycle.Service;
|
||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||
import org.briarproject.bramble.api.settings.Settings;
|
||||
import org.briarproject.bramble.api.settings.SettingsManager;
|
||||
import org.briarproject.bramble.api.settings.event.SettingsUpdatedEvent;
|
||||
import org.briarproject.briar.api.android.AndroidNotificationManager;
|
||||
import org.briarproject.briar.api.android.LockManager;
|
||||
|
||||
@@ -34,7 +30,7 @@ import static org.briarproject.briar.android.util.UiUtils.hasScreenLock;
|
||||
@ThreadSafe
|
||||
@MethodsNotNullByDefault
|
||||
@ParametersNotNullByDefault
|
||||
public class LockManagerImpl implements LockManager, Service, EventListener {
|
||||
public class LockManagerImpl implements LockManager {
|
||||
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(LockManagerImpl.class.getName());
|
||||
@@ -45,7 +41,7 @@ public class LockManagerImpl implements LockManager, Service, EventListener {
|
||||
@DatabaseExecutor
|
||||
private final Executor dbExecutor;
|
||||
|
||||
private final MutableLiveData<Boolean> locked = new MutableLiveData<>();
|
||||
private volatile boolean locked = false;
|
||||
private final MutableLiveData<Boolean> lockable = new MutableLiveData<>();
|
||||
|
||||
@Inject
|
||||
@@ -57,58 +53,10 @@ public class LockManagerImpl implements LockManager, Service, EventListener {
|
||||
this.notificationManager = notificationManager;
|
||||
this.dbExecutor = dbExecutor;
|
||||
|
||||
// setting these in the constructor makes #getValue() @NonNull
|
||||
this.locked.setValue(false);
|
||||
// setting this in the constructor makes #getValue() @NonNull
|
||||
this.lockable.setValue(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startService() {
|
||||
lockable.observeForever(this::onLockableChanged);
|
||||
if (hasScreenLock(appContext)) {
|
||||
loadLockableSetting();
|
||||
} else {
|
||||
lockable.postValue(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopService() {
|
||||
lockable.removeObserver(this::onLockableChanged);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void eventOccurred(Event event) {
|
||||
if (event instanceof SettingsUpdatedEvent) {
|
||||
SettingsUpdatedEvent e = (SettingsUpdatedEvent) event;
|
||||
String namespace = e.getNamespace();
|
||||
if (namespace.equals(SETTINGS_NAMESPACE)) {
|
||||
loadLockableSetting();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void loadLockableSetting() {
|
||||
dbExecutor.execute(() -> {
|
||||
try {
|
||||
Settings settings =
|
||||
settingsManager.getSettings(SETTINGS_NAMESPACE);
|
||||
boolean lockable =
|
||||
settings.getBoolean(PREF_SCREEN_LOCK, false);
|
||||
boolean newValue = hasScreenLock(appContext) && lockable;
|
||||
this.lockable.postValue(newValue);
|
||||
} catch (DbException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
this.lockable.postValue(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void onLockableChanged(boolean lockable) {
|
||||
notificationManager
|
||||
.updateForegroundNotification(lockable, locked.getValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public LiveData<Boolean> isLockable() {
|
||||
return lockable;
|
||||
@@ -116,23 +64,33 @@ public class LockManagerImpl implements LockManager, Service, EventListener {
|
||||
|
||||
@UiThread
|
||||
@Override
|
||||
public void recheckLockable() {
|
||||
boolean oldValue = this.lockable.getValue();
|
||||
boolean newValue = hasScreenLock(appContext) && lockable.getValue();
|
||||
if (oldValue != newValue) {
|
||||
this.lockable.setValue(newValue);
|
||||
}
|
||||
public void checkIfLockable() {
|
||||
boolean oldValue = lockable.getValue();
|
||||
dbExecutor.execute(() -> {
|
||||
try {
|
||||
Settings settings =
|
||||
settingsManager.getSettings(SETTINGS_NAMESPACE);
|
||||
boolean lockable =
|
||||
settings.getBoolean(PREF_SCREEN_LOCK, false);
|
||||
boolean newValue = hasScreenLock(appContext) && lockable;
|
||||
if (oldValue != newValue) {
|
||||
this.lockable.postValue(newValue);
|
||||
}
|
||||
} catch (DbException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
this.lockable.postValue(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public LiveData<Boolean> isLocked() {
|
||||
public boolean isLocked() {
|
||||
return locked;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLocked(boolean locked) {
|
||||
this.locked.setValue(locked);
|
||||
notificationManager
|
||||
.updateForegroundNotification(lockable.getValue(), locked);
|
||||
this.locked = locked;
|
||||
notificationManager.updateForegroundNotification(locked);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,35 +70,22 @@ public abstract class BriarActivity extends BaseActivity {
|
||||
if (!briarController.accountSignedIn() && !isFinishing()) {
|
||||
Intent i = new Intent(this, PasswordActivity.class);
|
||||
startActivityForResult(i, REQUEST_PASSWORD);
|
||||
} else if (lockManager.isLocked().getValue()) {
|
||||
} else if (lockManager.isLocked()) {
|
||||
Intent i = new Intent(this, UnlockActivity.class);
|
||||
startActivityForResult(i, REQUEST_UNLOCK);
|
||||
} else {
|
||||
lockManager.isLocked().observe(this, locked -> {
|
||||
if (locked != null && locked) moveTaskToBack(true);
|
||||
});
|
||||
lockManager.recheckLockable();
|
||||
if (SDK_INT >= 23) {
|
||||
briarController.hasDozed(new UiResultHandler<Boolean>(this) {
|
||||
@Override
|
||||
public void onResultUi(Boolean result) {
|
||||
if (result) {
|
||||
showDozeDialog(getString(R.string.warning_dozed,
|
||||
getString(R.string.app_name)));
|
||||
}
|
||||
} else if (SDK_INT >= 23) {
|
||||
briarController.hasDozed(new UiResultHandler<Boolean>(this) {
|
||||
@Override
|
||||
public void onResultUi(Boolean result) {
|
||||
if (result) {
|
||||
showDozeDialog(getString(R.string.warning_dozed,
|
||||
getString(R.string.app_name)));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
// only react to lock changes while in foreground
|
||||
lockManager.isLocked().removeObservers(this);
|
||||
}
|
||||
|
||||
public void setSceneTransitionAnimation() {
|
||||
if (SDK_INT < 21) return;
|
||||
// workaround for #1007
|
||||
|
||||
@@ -22,7 +22,6 @@ import java.util.logging.Logger;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_UNLOCK;
|
||||
import static org.briarproject.briar.api.android.AndroidNotificationManager.ACTION_LOCK;
|
||||
|
||||
@RequiresApi(21)
|
||||
@MethodsNotNullByDefault
|
||||
@@ -49,13 +48,7 @@ public class UnlockActivity extends BaseActivity {
|
||||
Button button = findViewById(R.id.unlock);
|
||||
button.setOnClickListener(view -> requestKeyguardUnlock());
|
||||
|
||||
Intent intent = getIntent();
|
||||
if (intent != null && ACTION_LOCK.equals(intent.getAction())) {
|
||||
lockManager.setLocked(true);
|
||||
finish();
|
||||
} else {
|
||||
requestKeyguardUnlock();
|
||||
}
|
||||
requestKeyguardUnlock();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -155,6 +155,7 @@ public class NavDrawerActivity extends BriarActivity implements
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
updateTransports();
|
||||
lockManager.checkIfLockable();
|
||||
controller.showExpiryWarning(new UiResultHandler<ExpiryWarning>(this) {
|
||||
@Override
|
||||
public void onResultUi(ExpiryWarning expiry) {
|
||||
|
||||
@@ -49,7 +49,7 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
|
||||
if (accountManager.hasDatabaseKey()) {
|
||||
Intent i;
|
||||
if (lockManager.isLocked().getValue()) {
|
||||
if (lockManager.isLocked()) {
|
||||
// The database needs to be opened for the app to be locked.
|
||||
// Start main activity right away. It will open UnlockActivity.
|
||||
// Otherwise, we would end up with two screen unlock inputs.
|
||||
|
||||
@@ -53,11 +53,10 @@ public interface AndroidNotificationManager {
|
||||
|
||||
// Actions for pending intents
|
||||
String ACTION_DISMISS_REMINDER = "dismissReminder";
|
||||
String ACTION_LOCK = "lock";
|
||||
|
||||
Notification getForegroundNotification();
|
||||
|
||||
void updateForegroundNotification(boolean lockable, boolean locked);
|
||||
void updateForegroundNotification(boolean locked);
|
||||
|
||||
void clearContactNotification(ContactId c);
|
||||
|
||||
|
||||
@@ -5,13 +5,27 @@ import android.support.annotation.UiThread;
|
||||
|
||||
public interface LockManager {
|
||||
|
||||
/**
|
||||
* Returns an observable LiveData to indicate whether the app can be locked.
|
||||
*/
|
||||
LiveData<Boolean> isLockable();
|
||||
|
||||
/**
|
||||
* Updates the LiveData returned by {@link #isLockable()}.
|
||||
* It checks whether a device screen lock is available and
|
||||
* whether the app setting is checked.
|
||||
*/
|
||||
@UiThread
|
||||
void recheckLockable();
|
||||
void checkIfLockable();
|
||||
|
||||
LiveData<Boolean> isLocked();
|
||||
/**
|
||||
* Returns true if app is currently locked, false otherwise.
|
||||
*/
|
||||
boolean isLocked();
|
||||
|
||||
/**
|
||||
* Locks the app if true is passed, otherwise unlocks the app.
|
||||
*/
|
||||
void setLocked(boolean locked);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user