mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
Remove screenlock (#1942)
* Remove screen lock feature, move the two remaining "App access" options into "Advanced" Locking the app was removed a long time ago, so in "App access" in the settings, the only two remaining items were "Screen security" and "Incognito keyboard". * Remove the now-unused strings * remove app-access-category from main settings screen Co-authored-by: B. Petersen <r10s@b44t.com>
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 428 B |
Binary file not shown.
|
Before Width: | Height: | Size: 288 B |
Binary file not shown.
|
Before Width: | Height: | Size: 507 B |
Binary file not shown.
|
Before Width: | Height: | Size: 702 B |
Binary file not shown.
|
Before Width: | Height: | Size: 913 B |
@@ -1,4 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:src="@drawable/ic_security_white_24dp"
|
||||
android:tint="?attr/pref_icon_tint"/>
|
||||
@@ -492,8 +492,6 @@
|
||||
<string name="pref_outgoing_balanced">Balanced</string>
|
||||
<string name="pref_outgoing_worse">Worse quality, small size</string>
|
||||
<string name="pref_vibrate">Vibrate</string>
|
||||
<string name="pref_change_secret">Change secret</string>
|
||||
<string name="pref_change_secret_explain">Change your PIN / pattern / fingerprint via system settings</string>
|
||||
<string name="pref_screen_security">Screen security</string>
|
||||
<!-- Translators: The wording must indicate that we can't guarantee that, its a System flag that we set. But the System in question must honor it. -->
|
||||
<string name="pref_screen_security_explain">Request to block screenshots in the recents list and inside the app</string>
|
||||
@@ -666,15 +664,9 @@
|
||||
<string name="systemmsg_chat_protection_enabled">Chat protection enabled.</string>
|
||||
|
||||
<!-- screen lock -->
|
||||
<string name="screenlock_title">Screen lock</string>
|
||||
<string name="screenlock_explain">Lock access with Android screen lock or fingerprint; to avoid showing the prior content, please also enable \"Screen security\".</string>
|
||||
<string name="screenlock_authentication_failed">Authentication failed.</string>
|
||||
<string name="screenlock_unlock_title">Unlock Delta Chat</string>
|
||||
<string name="screenlock_unlock_description">Please enter your system defined secret to unlock Delta Chat.</string>
|
||||
<string name="screenlock_inactivity_timeout">Inactivity timeout lock</string>
|
||||
<string name="screenlock_inactivity_timeout_explain">Auto-lock Delta Chat after a specified time period of inactivity</string>
|
||||
<string name="screenlock_inactivity_timeout_interval">Time to remain active</string>
|
||||
|
||||
<string name="screenlock_authentication_failed">Authentication failed.</string>
|
||||
|
||||
<!-- qr code stuff -->
|
||||
<string name="qr_code">QR code</string>
|
||||
|
||||
@@ -20,11 +20,6 @@
|
||||
android:icon="@drawable/ic_brightness_6_24dp"
|
||||
android:layout="@layout/preference_item" />
|
||||
|
||||
<Preference android:key="preference_category_app_protection"
|
||||
android:title="@string/pref_app_access"
|
||||
android:icon="@drawable/ic_security_24dp"
|
||||
android:layout="@layout/preference_item" />
|
||||
|
||||
<Preference android:key="preference_category_advanced"
|
||||
android:title="@string/menu_advanced"
|
||||
android:icon="@drawable/ic_advanced_24dp"
|
||||
|
||||
@@ -49,6 +49,21 @@
|
||||
</PreferenceCategory>
|
||||
|
||||
|
||||
<PreferenceCategory android:title="@string/pref_app_access">
|
||||
<org.thoughtcrime.securesms.components.SwitchPreferenceCompat
|
||||
android:defaultValue="false"
|
||||
android:key="pref_screen_security"
|
||||
android:summary="@string/pref_screen_security_explain"
|
||||
android:title="@string/pref_screen_security" />
|
||||
|
||||
<org.thoughtcrime.securesms.components.SwitchPreferenceCompat
|
||||
android:defaultValue="false"
|
||||
android:key="pref_incognito_keyboard"
|
||||
android:summary="@string/pref_incognito_keyboard_explain"
|
||||
android:title="@string/pref_incognito_keyboard" />
|
||||
</PreferenceCategory>
|
||||
|
||||
|
||||
<PreferenceCategory android:title="@string/pref_experimental_features">
|
||||
|
||||
<org.thoughtcrime.securesms.components.SwitchPreferenceCompat
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<org.thoughtcrime.securesms.components.SwitchPreferenceCompat
|
||||
android:defaultValue="false"
|
||||
android:key="pref_screen_security"
|
||||
android:summary="@string/pref_screen_security_explain"
|
||||
android:title="@string/pref_screen_security" />
|
||||
|
||||
<org.thoughtcrime.securesms.components.SwitchPreferenceCompat
|
||||
android:defaultValue="false"
|
||||
android:key="pref_incognito_keyboard"
|
||||
android:summary="@string/pref_incognito_keyboard_explain"
|
||||
android:title="@string/pref_incognito_keyboard" />
|
||||
|
||||
<PreferenceCategory android:key="pref_android_screen_lock_category" android:title="@string/screenlock_title">
|
||||
|
||||
<org.thoughtcrime.securesms.components.SwitchPreferenceCompat
|
||||
android:defaultValue="false"
|
||||
android:key="pref_android_screen_lock"
|
||||
android:summary="@string/screenlock_explain"
|
||||
android:title="@string/screenlock_title" />
|
||||
|
||||
<org.thoughtcrime.securesms.components.SwitchPreferenceCompat
|
||||
android:defaultValue="false"
|
||||
android:key="pref_timeout_passphrase"
|
||||
android:summary="@string/screenlock_inactivity_timeout_explain"
|
||||
android:title="@string/screenlock_inactivity_timeout" />
|
||||
|
||||
<Preference
|
||||
android:dependency="pref_timeout_passphrase"
|
||||
android:key="pref_timeout_interval"
|
||||
android:title="@string/screenlock_inactivity_timeout_interval" />
|
||||
|
||||
<Preference
|
||||
android:key="pref_change_passphrase"
|
||||
android:summary="@string/pref_change_secret_explain"
|
||||
android:title="@string/pref_change_secret" />
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
</PreferenceScreen>
|
||||
@@ -1,26 +1,18 @@
|
||||
package org.thoughtcrime.securesms;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
|
||||
import androidx.appcompat.app.AppCompatDelegate;
|
||||
import androidx.lifecycle.DefaultLifecycleObserver;
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
import androidx.lifecycle.ProcessLifecycleOwner;
|
||||
import androidx.work.Constraints;
|
||||
import androidx.work.ExistingPeriodicWorkPolicy;
|
||||
import androidx.work.NetworkType;
|
||||
import androidx.work.PeriodicWorkRequest;
|
||||
import androidx.work.WorkManager;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AppCompatDelegate;
|
||||
import androidx.multidex.MultiDexApplication;
|
||||
|
||||
import com.b44t.messenger.DcContext;
|
||||
import androidx.work.Constraints;
|
||||
import androidx.work.ExistingPeriodicWorkPolicy;
|
||||
import androidx.work.NetworkType;
|
||||
import androidx.work.PeriodicWorkRequest;
|
||||
import androidx.work.WorkManager;
|
||||
|
||||
import org.thoughtcrime.securesms.connect.ApplicationDcContext;
|
||||
import org.thoughtcrime.securesms.connect.FetchWorker;
|
||||
@@ -33,18 +25,16 @@ import org.thoughtcrime.securesms.jobmanager.JobManager;
|
||||
import org.thoughtcrime.securesms.notifications.InChatSounds;
|
||||
import org.thoughtcrime.securesms.util.AndroidSignalProtocolLogger;
|
||||
import org.thoughtcrime.securesms.util.DynamicLanguage;
|
||||
import org.thoughtcrime.securesms.util.ScreenLockUtil;
|
||||
import org.thoughtcrime.securesms.util.SignalProtocolLoggerProvider;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
//import com.squareup.leakcanary.LeakCanary;
|
||||
|
||||
public class ApplicationContext extends MultiDexApplication implements DefaultLifecycleObserver {
|
||||
public class ApplicationContext extends MultiDexApplication {
|
||||
|
||||
public ApplicationDcContext dcContext;
|
||||
public DcLocationManager dcLocationManager;
|
||||
private JobManager jobManager;
|
||||
private volatile boolean isAppVisible;
|
||||
|
||||
public static ApplicationContext getInstance(Context context) {
|
||||
return (ApplicationContext)context.getApplicationContext();
|
||||
@@ -76,7 +66,6 @@ public class ApplicationContext extends MultiDexApplication implements DefaultLi
|
||||
initializeRandomNumberFix();
|
||||
initializeLogging();
|
||||
initializeJobManager();
|
||||
ProcessLifecycleOwner.get().getLifecycle().addObserver(this);
|
||||
InChatSounds.getInstance(this);
|
||||
|
||||
dcLocationManager = new DcLocationManager(this);
|
||||
@@ -118,25 +107,10 @@ public class ApplicationContext extends MultiDexApplication implements DefaultLi
|
||||
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart(@NonNull LifecycleOwner owner) {
|
||||
isAppVisible = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop(@NonNull LifecycleOwner owner) {
|
||||
isAppVisible = false;
|
||||
ScreenLockUtil.setShouldLockApp(true);
|
||||
}
|
||||
|
||||
public JobManager getJobManager() {
|
||||
return jobManager;
|
||||
}
|
||||
|
||||
public boolean isAppVisible() {
|
||||
return isAppVisible;
|
||||
}
|
||||
|
||||
private void initializeRandomNumberFix() {
|
||||
PRNGFixes.apply();
|
||||
}
|
||||
|
||||
@@ -18,13 +18,11 @@
|
||||
package org.thoughtcrime.securesms;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Build.VERSION;
|
||||
import android.os.Bundle;
|
||||
@@ -37,11 +35,9 @@ import androidx.fragment.app.FragmentTransaction;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.core.graphics.drawable.DrawableCompat;
|
||||
import androidx.preference.Preference;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.thoughtcrime.securesms.permissions.Permissions;
|
||||
import org.thoughtcrime.securesms.preferences.AdvancedPreferenceFragment;
|
||||
import org.thoughtcrime.securesms.preferences.AppProtectionPreferenceFragment;
|
||||
import org.thoughtcrime.securesms.preferences.AppearancePreferenceFragment;
|
||||
import org.thoughtcrime.securesms.preferences.ChatsPreferenceFragment;
|
||||
import org.thoughtcrime.securesms.preferences.CorrectedPreferenceFragment;
|
||||
@@ -66,7 +62,6 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredActionBarA
|
||||
|
||||
private static final String PREFERENCE_CATEGORY_PROFILE = "preference_category_profile";
|
||||
private static final String PREFERENCE_CATEGORY_NOTIFICATIONS = "preference_category_notifications";
|
||||
private static final String PREFERENCE_CATEGORY_APP_PROTECTION = "preference_category_app_protection";
|
||||
private static final String PREFERENCE_CATEGORY_APPEARANCE = "preference_category_appearance";
|
||||
private static final String PREFERENCE_CATEGORY_CHATS = "preference_category_chats";
|
||||
private static final String PREFERENCE_CATEGORY_ADVANCED = "preference_category_advanced";
|
||||
@@ -141,8 +136,6 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredActionBarA
|
||||
.setOnPreferenceClickListener(new ProfileClickListener());
|
||||
this.findPreference(PREFERENCE_CATEGORY_NOTIFICATIONS)
|
||||
.setOnPreferenceClickListener(new CategoryClickListener(PREFERENCE_CATEGORY_NOTIFICATIONS));
|
||||
this.findPreference(PREFERENCE_CATEGORY_APP_PROTECTION)
|
||||
.setOnPreferenceClickListener(new CategoryClickListener(PREFERENCE_CATEGORY_APP_PROTECTION));
|
||||
this.findPreference(PREFERENCE_CATEGORY_APPEARANCE)
|
||||
.setOnPreferenceClickListener(new CategoryClickListener(PREFERENCE_CATEGORY_APPEARANCE));
|
||||
this.findPreference(PREFERENCE_CATEGORY_CHATS)
|
||||
@@ -187,7 +180,6 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredActionBarA
|
||||
@TargetApi(11)
|
||||
private void tintIcons(Context context) {
|
||||
Drawable notifications = DrawableCompat.wrap(ContextCompat.getDrawable(context, R.drawable.ic_notifications_white_24dp));
|
||||
Drawable privacy = DrawableCompat.wrap(ContextCompat.getDrawable(context, R.drawable.ic_security_white_24dp));
|
||||
Drawable appearance = DrawableCompat.wrap(ContextCompat.getDrawable(context, R.drawable.ic_brightness_6_white_24dp));
|
||||
Drawable chats = DrawableCompat.wrap(ContextCompat.getDrawable(context, R.drawable.ic_forum_white_24dp));
|
||||
Drawable advanced = DrawableCompat.wrap(ContextCompat.getDrawable(context, R.drawable.ic_advanced_white_24dp));
|
||||
@@ -199,14 +191,12 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredActionBarA
|
||||
typedArray.recycle();
|
||||
|
||||
DrawableCompat.setTint(notifications, color);
|
||||
DrawableCompat.setTint(privacy, color);
|
||||
DrawableCompat.setTint(appearance, color);
|
||||
DrawableCompat.setTint(chats, color);
|
||||
DrawableCompat.setTint(advanced, color);
|
||||
DrawableCompat.setTint(help, color);
|
||||
|
||||
this.findPreference(PREFERENCE_CATEGORY_NOTIFICATIONS).setIcon(notifications);
|
||||
this.findPreference(PREFERENCE_CATEGORY_APP_PROTECTION).setIcon(privacy);
|
||||
this.findPreference(PREFERENCE_CATEGORY_APPEARANCE).setIcon(appearance);
|
||||
this.findPreference(PREFERENCE_CATEGORY_CHATS).setIcon(chats);
|
||||
this.findPreference(PREFERENCE_CATEGORY_ADVANCED).setIcon(advanced);
|
||||
@@ -228,9 +218,6 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredActionBarA
|
||||
case PREFERENCE_CATEGORY_NOTIFICATIONS:
|
||||
fragment = new NotificationsPreferenceFragment();
|
||||
break;
|
||||
case PREFERENCE_CATEGORY_APP_PROTECTION:
|
||||
fragment = new AppProtectionPreferenceFragment();
|
||||
break;
|
||||
case PREFERENCE_CATEGORY_APPEARANCE:
|
||||
fragment = new AppearancePreferenceFragment();
|
||||
break;
|
||||
|
||||
@@ -1,37 +1,26 @@
|
||||
package org.thoughtcrime.securesms;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.core.app.ActivityOptionsCompat;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewConfiguration;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import org.thoughtcrime.securesms.util.Prefs;
|
||||
import org.thoughtcrime.securesms.util.ScreenLockUtil;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Timer;
|
||||
|
||||
|
||||
public abstract class BaseActionBarActivity extends AppCompatActivity {
|
||||
|
||||
private static final String TAG = BaseActionBarActivity.class.getSimpleName();
|
||||
|
||||
private Timer timer;
|
||||
|
||||
private boolean isWaitingForResult;
|
||||
private boolean isHiddenByScreenLock;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
if (BaseActivity.isMenuWorkaroundRequired()) {
|
||||
@@ -40,67 +29,10 @@ public abstract class BaseActionBarActivity extends AppCompatActivity {
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
if (ScreenLockUtil.isScreenLockEnabled(this) && ScreenLockUtil.getShouldLockApp() && !isWaitingForResult) {
|
||||
ScreenLockUtil.applyScreenLock(this);
|
||||
} else if (isHiddenByScreenLock) {
|
||||
findViewById(android.R.id.content).setVisibility(View.VISIBLE);
|
||||
isHiddenByScreenLock = false;
|
||||
}
|
||||
super.onStart();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
if (ScreenLockUtil.isScreenLockEnabled(this)) {
|
||||
findViewById(android.R.id.content).setVisibility(View.GONE);
|
||||
isHiddenByScreenLock = true;
|
||||
}
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
isWaitingForResult = false;
|
||||
if (requestCode == ScreenLockUtil.REQUEST_CODE_CONFIRM_CREDENTIALS) {
|
||||
if (resultCode == RESULT_OK) {
|
||||
ScreenLockUtil.setShouldLockApp(false);
|
||||
} else {
|
||||
Toast.makeText(this, R.string.screenlock_authentication_failed, Toast.LENGTH_SHORT).show();
|
||||
ScreenLockUtil.applyScreenLock(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
initializeScreenshotSecurity();
|
||||
initializeScreenLockTimeout();
|
||||
}
|
||||
|
||||
private void initializeScreenLockTimeout() {
|
||||
if (ScreenLockUtil.isScreenLockTimeoutEnabled(this)) {
|
||||
timer = ScreenLockUtil.scheduleScreenLockTimer(timer, this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
tearDownScreenLockTimeout();
|
||||
}
|
||||
|
||||
private void tearDownScreenLockTimeout() {
|
||||
ScreenLockUtil.cancelScreenLockTimer(timer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUserInteraction() {
|
||||
super.onUserInteraction();
|
||||
initializeScreenLockTimeout();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -145,14 +77,6 @@ public abstract class BaseActionBarActivity extends AppCompatActivity {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startActivityForResult(Intent intent, int requestCode) {
|
||||
super.startActivityForResult(intent, requestCode);
|
||||
if (requestCode != -1) {
|
||||
isWaitingForResult = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void makeSearchMenuVisible(final Menu menu, final MenuItem searchItem, boolean visible) {
|
||||
for (int i = 0; i < menu.size(); ++i) {
|
||||
MenuItem item = menu.getItem(i);
|
||||
|
||||
@@ -60,17 +60,17 @@ public class ApplicationDcContext extends DcContext {
|
||||
|
||||
// screen-lock is deprecated, inform users still using it
|
||||
try {
|
||||
if (!Prefs.getBooleanPreference(context, "pref_android_screen_lock_checked", false)) {
|
||||
Prefs.setBooleanPreference(context, "pref_android_screen_lock_checked", true);
|
||||
if (!Prefs.getBooleanPreference(context, "pref_android_screen_lock_checked_1", false)) {
|
||||
Prefs.setBooleanPreference(context, "pref_android_screen_lock_checked_1", true);
|
||||
if (Prefs.isScreenLockEnabled(context)) {
|
||||
Prefs.setBooleanPreference(context, "pref_android_screen_lock_keep_for_now", true);
|
||||
Prefs.setScreenLockEnabled(context, false);
|
||||
DcMsg msg = new DcMsg(this, DcMsg.DC_MSG_TEXT);
|
||||
msg.setText("⚠️ You are using the function \"Screen lock\" " +
|
||||
"that will be removed in one of the next versions for the following reasons:\n" +
|
||||
msg.setText("⚠️ You were using the function \"Screen lock\" " +
|
||||
"that was removed for the following reasons:\n" +
|
||||
"\n" +
|
||||
"• It does not add much protection as one just has to repeat the system secret.\n" +
|
||||
"• It did not add much protection as one just has to repeat the system secret.\n" +
|
||||
"\n" +
|
||||
"• It is hard to maintain across different Android versions and is not even doable on some." +
|
||||
"• It was hard to maintain across different Android versions and is not even doable on some." +
|
||||
" We like to put the resources to other things.\n" +
|
||||
"\n" +
|
||||
"• It is not planned/possible on iOS or Desktop this way" +
|
||||
@@ -80,7 +80,7 @@ public class ApplicationDcContext extends DcContext {
|
||||
"\n" +
|
||||
"\uD83D\uDC49 For the future, we suggest to keep your phone locked " +
|
||||
"or use an appropriate app or check the device settings.");
|
||||
addDeviceMsg("android-screen-lock-deprecated14", msg);
|
||||
addDeviceMsg("android-screen-lock-deprecated17", msg);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -6,15 +6,16 @@ import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.preference.CheckBoxPreference;
|
||||
import androidx.preference.Preference;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.b44t.messenger.DcContext;
|
||||
|
||||
@@ -24,6 +25,7 @@ import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.connect.DcEventCenter;
|
||||
import org.thoughtcrime.securesms.connect.DcHelper;
|
||||
import org.thoughtcrime.securesms.permissions.Permissions;
|
||||
import org.thoughtcrime.securesms.util.Prefs;
|
||||
import org.thoughtcrime.securesms.util.ScreenLockUtil;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.thoughtcrime.securesms.util.views.ProgressDialog;
|
||||
@@ -95,6 +97,9 @@ public class AdvancedPreferenceFragment extends ListSummaryPreferenceFragment
|
||||
Preference manageKeys = this.findPreference("pref_manage_keys");
|
||||
manageKeys.setOnPreferenceClickListener(new ManageKeysListener());
|
||||
|
||||
Preference screenSecurity = this.findPreference(Prefs.SCREEN_SECURITY_PREF);
|
||||
screenSecurity.setOnPreferenceChangeListener(new ScreenShotSecurityListener());
|
||||
|
||||
Preference submitDebugLog = this.findPreference("pref_view_log");
|
||||
submitDebugLog.setOnPreferenceClickListener(new ViewLogListener());
|
||||
|
||||
@@ -169,6 +174,16 @@ public class AdvancedPreferenceFragment extends ListSummaryPreferenceFragment
|
||||
}
|
||||
}
|
||||
|
||||
private class ScreenShotSecurityListener implements Preference.OnPreferenceChangeListener {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
boolean enabled = (Boolean) newValue;
|
||||
Prefs.setScreenSecurityEnabled(getContext(), enabled);
|
||||
Toast.makeText(getContext(), R.string.pref_screen_security_please_restart_hint, Toast.LENGTH_LONG).show();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private class ViewLogListener implements Preference.OnPreferenceClickListener {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
|
||||
@@ -1,140 +0,0 @@
|
||||
package org.thoughtcrime.securesms.preferences;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.KeyguardManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.provider.Settings;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceCategory;
|
||||
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.thoughtcrime.securesms.ApplicationPreferencesActivity;
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.components.SwitchPreferenceCompat;
|
||||
import org.thoughtcrime.securesms.util.Prefs;
|
||||
import org.thoughtcrime.securesms.util.ScreenLockUtil;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import mobi.upod.timedurationpicker.TimeDurationPickerDialog;
|
||||
|
||||
public class AppProtectionPreferenceFragment extends CorrectedPreferenceFragment {
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle paramBundle) {
|
||||
super.onCreate(paramBundle);
|
||||
|
||||
this.findPreference(Prefs.SCREEN_LOCK).setOnPreferenceChangeListener(new ScreenLockListener());
|
||||
this.findPreference(Prefs.CHANGE_PASSPHRASE_PREF).setOnPreferenceClickListener(new ChangePassphraseClickListener());
|
||||
this.findPreference(Prefs.SCREEN_LOCK_TIMEOUT_INTERVAL_PREF).setOnPreferenceClickListener(new LockIntervalClickListener());
|
||||
this.findPreference(Prefs.SCREEN_SECURITY_PREF).setOnPreferenceChangeListener(new ScreenShotSecurityListener());
|
||||
|
||||
initializeVisibility();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreatePreferences(@Nullable Bundle savedInstanceState, String rootKey) {
|
||||
addPreferencesFromResource(R.xml.preferences_app_protection);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
((ApplicationPreferencesActivity) getActivity()).getSupportActionBar().setTitle(R.string.pref_app_access);
|
||||
initializePassphraseTimeoutSummary();
|
||||
}
|
||||
|
||||
private void initializePassphraseTimeoutSummary() {
|
||||
int timeoutSeconds = Prefs.getScreenLockTimeoutInterval(getActivity());
|
||||
this.findPreference(Prefs.SCREEN_LOCK_TIMEOUT_INTERVAL_PREF)
|
||||
.setSummary(getResources().getQuantityString(R.plurals.n_minutes, timeoutSeconds, timeoutSeconds / 60));
|
||||
}
|
||||
|
||||
private void initializeVisibility() {
|
||||
KeyguardManager keyguardManager = (KeyguardManager) getContext().getSystemService(Context.KEYGUARD_SERVICE);
|
||||
SwitchPreferenceCompat screenLockPreference = (SwitchPreferenceCompat) findPreference(Prefs.SCREEN_LOCK);
|
||||
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.LOLLIPOP || keyguardManager == null || !keyguardManager.isKeyguardSecure()) {
|
||||
screenLockPreference.setChecked(false);
|
||||
screenLockPreference.setEnabled(false);
|
||||
}
|
||||
if (!screenLockPreference.isChecked()) {
|
||||
manageScreenLockChildren(false);
|
||||
}
|
||||
|
||||
// screen-lock is deprecated
|
||||
try {
|
||||
if (!Prefs.getBooleanPreference(getContext(), "pref_android_screen_lock_keep_for_now", false)) {
|
||||
PreferenceCategory screenLockCategory = findPreference("pref_android_screen_lock_category");
|
||||
screenLockCategory.setVisible(false);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void manageScreenLockChildren(boolean enable) {
|
||||
SwitchPreferenceCompat timeoutPreference = (SwitchPreferenceCompat) findPreference(Prefs.SCREEN_LOCK_TIMEOUT_PREF);
|
||||
timeoutPreference.setEnabled(enable);
|
||||
findPreference(Prefs.SCREEN_LOCK_TIMEOUT_INTERVAL_PREF).setEnabled(enable);
|
||||
if (!enable) {
|
||||
timeoutPreference.setChecked(false);
|
||||
}
|
||||
}
|
||||
|
||||
private class ScreenShotSecurityListener implements Preference.OnPreferenceChangeListener {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
boolean enabled = (Boolean) newValue;
|
||||
Prefs.setScreenSecurityEnabled(getContext(), enabled);
|
||||
Toast.makeText(getContext(), R.string.pref_screen_security_please_restart_hint, Toast.LENGTH_LONG).show();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private class ScreenLockListener implements Preference.OnPreferenceChangeListener {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
boolean enabled = (Boolean) newValue;
|
||||
manageScreenLockChildren(enabled);
|
||||
Prefs.setScreenLockEnabled(getContext(), enabled);
|
||||
ScreenLockUtil.setShouldLockApp(false);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private class ChangePassphraseClickListener implements Preference.OnPreferenceClickListener {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
Intent intent = new Intent(Settings.ACTION_SECURITY_SETTINGS);
|
||||
startActivity(intent);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private class LockIntervalClickListener implements Preference.OnPreferenceClickListener {
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
new TimeDurationPickerDialog(getContext(), (view, duration) -> {
|
||||
int timeoutSeconds = (int) Math.max(TimeUnit.MILLISECONDS.toSeconds(duration), 60);
|
||||
|
||||
Prefs.setScreenLockTimeoutInterval(getActivity(), timeoutSeconds);
|
||||
|
||||
initializePassphraseTimeoutSummary();
|
||||
|
||||
}, 0).show();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -31,7 +31,6 @@ public class Prefs {
|
||||
|
||||
private static final String TAG = Prefs.class.getSimpleName();
|
||||
|
||||
public static final String CHANGE_PASSPHRASE_PREF = "pref_change_passphrase";
|
||||
public static final String DISABLE_PASSPHRASE_PREF = "pref_disable_passphrase";
|
||||
public static final String THEME_PREF = "pref_theme";
|
||||
public static final String LANGUAGE_PREF = "pref_language";
|
||||
@@ -43,8 +42,6 @@ public class Prefs {
|
||||
private static final String NOTIFICATION_PREF = "pref_key_enable_notifications";
|
||||
public static final String LED_COLOR_PREF = "pref_led_color";
|
||||
private static final String CHAT_RINGTONE = "pref_chat_ringtone_"; // followed by chat-id
|
||||
public static final String SCREEN_LOCK_TIMEOUT_INTERVAL_PREF = "pref_timeout_interval";
|
||||
public static final String SCREEN_LOCK_TIMEOUT_PREF = "pref_timeout_passphrase";
|
||||
public static final String SCREEN_SECURITY_PREF = "pref_screen_security";
|
||||
private static final String ENTER_SENDS_PREF = "pref_enter_sends";
|
||||
private static final String PROMPTED_DOZE_MSG_ID_PREF = "pref_prompted_doze_msg_id";
|
||||
@@ -144,18 +141,6 @@ public class Prefs {
|
||||
return getStringPreference(context, THEME_PREF, DynamicTheme.systemThemeAvailable() ? DynamicTheme.SYSTEM : DynamicTheme.LIGHT);
|
||||
}
|
||||
|
||||
public static boolean isScreenLockTimeoutEnabled(Context context) {
|
||||
return getBooleanPreference(context, SCREEN_LOCK_TIMEOUT_PREF, false);
|
||||
}
|
||||
|
||||
public static int getScreenLockTimeoutInterval(Context context) {
|
||||
return getIntegerPreference(context, SCREEN_LOCK_TIMEOUT_INTERVAL_PREF, 5 * 60);
|
||||
}
|
||||
|
||||
public static void setScreenLockTimeoutInterval(Context context, int interval) {
|
||||
setIntegerPrefrence(context, SCREEN_LOCK_TIMEOUT_INTERVAL_PREF, interval);
|
||||
}
|
||||
|
||||
public static String getLanguage(Context context) {
|
||||
return getStringPreference(context, LANGUAGE_PREF, "zz");
|
||||
}
|
||||
|
||||
@@ -7,19 +7,10 @@ import android.content.Intent;
|
||||
|
||||
import org.thoughtcrime.securesms.R;
|
||||
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
public class ScreenLockUtil {
|
||||
|
||||
public static final int REQUEST_CODE_CONFIRM_CREDENTIALS = 1001;
|
||||
|
||||
private static boolean shouldLockApp = true;
|
||||
|
||||
public static void applyScreenLock(Activity activity) {
|
||||
applyScreenLock(activity, REQUEST_CODE_CONFIRM_CREDENTIALS);
|
||||
}
|
||||
|
||||
public static boolean applyScreenLock(Activity activity, int requestCode) {
|
||||
KeyguardManager keyguardManager = (KeyguardManager) activity.getSystemService(Context.KEYGUARD_SERVICE);
|
||||
Intent intent;
|
||||
@@ -33,44 +24,7 @@ public class ScreenLockUtil {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isScreenLockEnabled(Context context) {
|
||||
return isScreenLockAvailable() && Prefs.isScreenLockEnabled(context);
|
||||
}
|
||||
|
||||
private static boolean isScreenLockAvailable() {
|
||||
return android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP;
|
||||
}
|
||||
|
||||
public static boolean isScreenLockTimeoutEnabled(Context context) {
|
||||
return isScreenLockAvailable() && Prefs.isScreenLockTimeoutEnabled(context);
|
||||
}
|
||||
|
||||
public static Timer scheduleScreenLockTimer(Timer timer, Activity activity) {
|
||||
cancelScreenLockTimer(timer);
|
||||
Timer newTimer = new Timer();
|
||||
newTimer.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (isScreenLockTimeoutEnabled(activity)) {
|
||||
ScreenLockUtil.applyScreenLock(activity);
|
||||
}
|
||||
}
|
||||
}, Prefs.getScreenLockTimeoutInterval(activity) * 1000);
|
||||
return newTimer;
|
||||
}
|
||||
|
||||
public static void cancelScreenLockTimer(Timer timer) {
|
||||
if (timer != null) {
|
||||
timer.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean getShouldLockApp() {
|
||||
return shouldLockApp;
|
||||
}
|
||||
|
||||
public static void setShouldLockApp(boolean newShouldLockApp) {
|
||||
shouldLockApp = newShouldLockApp;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user