mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-20 22:59:54 +01:00
Screen Lock: Address first round of review comments
This commit is contained in:
@@ -35,6 +35,7 @@ import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_PASSW
|
|||||||
import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_UNLOCK;
|
import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_UNLOCK;
|
||||||
import static org.briarproject.briar.android.util.UiUtils.getDozeWhitelistingIntent;
|
import static org.briarproject.briar.android.util.UiUtils.getDozeWhitelistingIntent;
|
||||||
import static org.briarproject.briar.android.util.UiUtils.isSamsung7;
|
import static org.briarproject.briar.android.util.UiUtils.isSamsung7;
|
||||||
|
import static org.briarproject.briar.android.util.UiUtils.showAndroidHomeScreen;
|
||||||
|
|
||||||
@SuppressLint("Registered")
|
@SuppressLint("Registered")
|
||||||
public abstract class BriarActivity extends BaseActivity {
|
public abstract class BriarActivity extends BaseActivity {
|
||||||
@@ -73,18 +74,30 @@ public abstract class BriarActivity extends BaseActivity {
|
|||||||
} else if(lockManager.isLocked().getValue()) {
|
} else if(lockManager.isLocked().getValue()) {
|
||||||
Intent i = new Intent(this, UnlockActivity.class);
|
Intent i = new Intent(this, UnlockActivity.class);
|
||||||
startActivityForResult(i, REQUEST_UNLOCK);
|
startActivityForResult(i, REQUEST_UNLOCK);
|
||||||
} else if (SDK_INT >= 23) {
|
} else {
|
||||||
briarController.hasDozed(new UiResultHandler<Boolean>(this) {
|
lockManager.isLocked().observe(this, locked -> {
|
||||||
@Override
|
if (locked != null && locked) showAndroidHomeScreen(this);
|
||||||
public void onResultUi(Boolean result) {
|
|
||||||
if (result) {
|
|
||||||
showDozeDialog(getString(R.string.warning_dozed,
|
|
||||||
getString(R.string.app_name)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
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)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
lockManager.recheckLockable();
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onStop() {
|
||||||
|
super.onStop();
|
||||||
|
// only react to lock changes while in foreground
|
||||||
|
lockManager.isLocked().removeObservers(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSceneTransitionAnimation() {
|
public void setSceneTransitionAnimation() {
|
||||||
@@ -125,10 +138,6 @@ public abstract class BriarActivity extends BaseActivity {
|
|||||||
return toolbar;
|
return toolbar;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onLockableChanged(boolean lockable) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void showDozeDialog(String message) {
|
protected void showDozeDialog(String message) {
|
||||||
AlertDialog.Builder b =
|
AlertDialog.Builder b =
|
||||||
new AlertDialog.Builder(this, R.style.BriarDialogTheme);
|
new AlertDialog.Builder(this, R.style.BriarDialogTheme);
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import java.util.logging.Logger;
|
|||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_UNLOCK;
|
import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_UNLOCK;
|
||||||
|
import static org.briarproject.briar.android.util.UiUtils.showAndroidHomeScreen;
|
||||||
import static org.briarproject.briar.api.android.AndroidNotificationManager.ACTION_LOCK;
|
import static org.briarproject.briar.api.android.AndroidNotificationManager.ACTION_LOCK;
|
||||||
|
|
||||||
@RequiresApi(21)
|
@RequiresApi(21)
|
||||||
@@ -52,11 +53,17 @@ public class UnlockActivity extends BaseActivity {
|
|||||||
Intent intent = getIntent();
|
Intent intent = getIntent();
|
||||||
if (intent != null && ACTION_LOCK.equals(intent.getAction())) {
|
if (intent != null && ACTION_LOCK.equals(intent.getAction())) {
|
||||||
lockManager.setLocked(true);
|
lockManager.setLocked(true);
|
||||||
|
finish();
|
||||||
} else {
|
} else {
|
||||||
requestKeyguardUnlock();
|
requestKeyguardUnlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBackPressed() {
|
||||||
|
showAndroidHomeScreen(this);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onActivityResult(int requestCode, int resultCode,
|
protected void onActivityResult(int requestCode, int resultCode,
|
||||||
Intent data) {
|
Intent data) {
|
||||||
@@ -70,9 +77,9 @@ public class UnlockActivity extends BaseActivity {
|
|||||||
KeyguardManager keyguardManager = (KeyguardManager) getSystemService(
|
KeyguardManager keyguardManager = (KeyguardManager) getSystemService(
|
||||||
Context.KEYGUARD_SERVICE);
|
Context.KEYGUARD_SERVICE);
|
||||||
assert keyguardManager != null;
|
assert keyguardManager != null;
|
||||||
Intent intent = keyguardManager
|
Intent intent = keyguardManager.createConfirmDeviceCredentialIntent(
|
||||||
.createConfirmDeviceCredentialIntent(getString(R.string.lock_unlock),
|
getString(R.string.lock_unlock),
|
||||||
null);
|
getString(R.string.lock_unlock_description));
|
||||||
if (intent == null) {
|
if (intent == null) {
|
||||||
// the user must have removed the screen lock since locked
|
// the user must have removed the screen lock since locked
|
||||||
LOG.warning("Unlocking without keyguard");
|
LOG.warning("Unlocking without keyguard");
|
||||||
|
|||||||
@@ -256,6 +256,7 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
|||||||
public void onStart() {
|
public void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
eventBus.addListener(this);
|
eventBus.addListener(this);
|
||||||
|
updateScreenLockSetting(settings != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -350,10 +351,8 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
|||||||
PREF_TOR_NETWORK_ALWAYS);
|
PREF_TOR_NETWORK_ALWAYS);
|
||||||
boolean torBlockedSetting =
|
boolean torBlockedSetting =
|
||||||
torSettings.getBoolean(PREF_TOR_DISABLE_BLOCKED, true);
|
torSettings.getBoolean(PREF_TOR_DISABLE_BLOCKED, true);
|
||||||
boolean screenLockSetting =
|
displaySettings(btSetting, torNetworkSetting,
|
||||||
settings.getBoolean(PREF_SCREEN_LOCK, false);
|
torBlockedSetting);
|
||||||
displaySettings(btSetting, torNetworkSetting, torBlockedSetting,
|
|
||||||
screenLockSetting);
|
|
||||||
} catch (DbException e) {
|
} catch (DbException e) {
|
||||||
logException(LOG, WARNING, e);
|
logException(LOG, WARNING, e);
|
||||||
}
|
}
|
||||||
@@ -361,13 +360,18 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void displaySettings(boolean btSetting, int torNetworkSetting,
|
private void displaySettings(boolean btSetting, int torNetworkSetting,
|
||||||
boolean torBlockedSetting, boolean screenLockSetting) {
|
boolean torBlockedSetting) {
|
||||||
listener.runOnUiThreadUnlessDestroyed(() -> {
|
listener.runOnUiThreadUnlessDestroyed(() -> {
|
||||||
enableBluetooth.setValue(Boolean.toString(btSetting));
|
enableBluetooth.setValue(Boolean.toString(btSetting));
|
||||||
torNetwork.setValue(Integer.toString(torNetworkSetting));
|
torNetwork.setValue(Integer.toString(torNetworkSetting));
|
||||||
torBlocked.setChecked(torBlockedSetting);
|
torBlocked.setChecked(torBlockedSetting);
|
||||||
screenLock.setChecked(screenLockSetting);
|
|
||||||
|
|
||||||
|
if (SDK_INT >= 21) {
|
||||||
|
boolean screenLockable =
|
||||||
|
settings.getBoolean(PREF_SCREEN_LOCK, false);
|
||||||
|
screenLock.setChecked(
|
||||||
|
screenLockable && hasScreenLock(getActivity()));
|
||||||
|
}
|
||||||
if (SDK_INT < 26) {
|
if (SDK_INT < 26) {
|
||||||
notifyPrivateMessages.setChecked(settings.getBoolean(
|
notifyPrivateMessages.setChecked(settings.getBoolean(
|
||||||
PREF_NOTIFY_PRIVATE, true));
|
PREF_NOTIFY_PRIVATE, true));
|
||||||
@@ -427,12 +431,7 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
|||||||
enableBluetooth.setEnabled(enabled);
|
enableBluetooth.setEnabled(enabled);
|
||||||
torNetwork.setEnabled(enabled);
|
torNetwork.setEnabled(enabled);
|
||||||
torBlocked.setEnabled(enabled);
|
torBlocked.setEnabled(enabled);
|
||||||
if (enabled && getActivity() != null && hasScreenLock(getActivity())) {
|
updateScreenLockSetting(enabled);
|
||||||
screenLock.setEnabled(true);
|
|
||||||
} else {
|
|
||||||
screenLock.setEnabled(false);
|
|
||||||
screenLock.setSummary(getString(R.string.lock_disabled));
|
|
||||||
}
|
|
||||||
notifyPrivateMessages.setEnabled(enabled);
|
notifyPrivateMessages.setEnabled(enabled);
|
||||||
notifyGroupMessages.setEnabled(enabled);
|
notifyGroupMessages.setEnabled(enabled);
|
||||||
notifyForumPosts.setEnabled(enabled);
|
notifyForumPosts.setEnabled(enabled);
|
||||||
@@ -442,6 +441,18 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
|||||||
notifySound.setEnabled(enabled);
|
notifySound.setEnabled(enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateScreenLockSetting(boolean enabled) {
|
||||||
|
if (SDK_INT < 21) {
|
||||||
|
screenLock.setVisible(false);
|
||||||
|
} else if (enabled && hasScreenLock(getActivity())) {
|
||||||
|
screenLock.setEnabled(true);
|
||||||
|
} else {
|
||||||
|
screenLock.setEnabled(false);
|
||||||
|
screenLock.setChecked(false);
|
||||||
|
screenLock.setSummary(getString(R.string.lock_disabled));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@TargetApi(26)
|
@TargetApi(26)
|
||||||
private void setupNotificationPreference(CheckBoxPreference pref,
|
private void setupNotificationPreference(CheckBoxPreference pref,
|
||||||
String channelId, @StringRes int summary) {
|
String channelId, @StringRes int summary) {
|
||||||
|
|||||||
@@ -240,4 +240,11 @@ public class UiUtils {
|
|||||||
(SDK_INT >= 23 && keyguardManager.isDeviceSecure());
|
(SDK_INT >= 23 && keyguardManager.isDeviceSecure());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void showAndroidHomeScreen(Context ctx) {
|
||||||
|
Intent i = new Intent(Intent.ACTION_MAIN);
|
||||||
|
i.addCategory(Intent.CATEGORY_HOME);
|
||||||
|
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
ctx.startActivity(i);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -358,7 +358,7 @@
|
|||||||
<!-- Settings Security and Panic -->
|
<!-- Settings Security and Panic -->
|
||||||
<string name="security_settings_title">Security</string>
|
<string name="security_settings_title">Security</string>
|
||||||
<string name="pref_lock_title">Screen Lock</string>
|
<string name="pref_lock_title">Screen Lock</string>
|
||||||
<string name="pref_lock_summary">Lock app access with Android screen lock or fingerprint</string>
|
<string name="pref_lock_summary">Use the device\'s screen lock to protect Briar while signed in</string>
|
||||||
<string name="change_password">Change password</string>
|
<string name="change_password">Change password</string>
|
||||||
<string name="current_password">Current password</string>
|
<string name="current_password">Current password</string>
|
||||||
<string name="choose_new_password">New password</string>
|
<string name="choose_new_password">New password</string>
|
||||||
@@ -450,9 +450,10 @@
|
|||||||
|
|
||||||
<!-- App Locking -->
|
<!-- App Locking -->
|
||||||
<string name="lock_unlock">Unlock Briar</string>
|
<string name="lock_unlock">Unlock Briar</string>
|
||||||
|
<string name="lock_unlock_description">Enter your device PIN, pattern or password to continue</string>
|
||||||
<string name="lock_is_locked">Briar is locked</string>
|
<string name="lock_is_locked">Briar is locked</string>
|
||||||
<string name="lock_tap_to_unlock">Tap to unlock</string>
|
<string name="lock_tap_to_unlock">Tap to unlock</string>
|
||||||
<string name="lock_disabled">Only available on Android 5 or newer and when a system screen lock is set</string>
|
<string name="lock_disabled">Set up a screen lock for your device to protect Briar while signed in</string>
|
||||||
<!-- This is meant as an imperative, but should be shorter than: Lock the app! -->
|
<!-- This is meant as an imperative, but should be shorter than: Lock the app! -->
|
||||||
<string name="lock_lock">Lock</string>
|
<string name="lock_lock">Lock</string>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user