Make it possible to set a zero value for screen lock timeout

Fixes #7485
This commit is contained in:
Moxie Marlinspike 2018-03-09 15:27:20 -08:00
parent 11ce4ee807
commit c8dd62cecf
4 changed files with 22 additions and 52 deletions

View File

@ -93,7 +93,7 @@ dependencies {
compile 'com.google.zxing:android-integration:3.1.0' compile 'com.google.zxing:android-integration:3.1.0'
compile 'com.squareup.dagger:dagger:1.2.2' compile 'com.squareup.dagger:dagger:1.2.2'
annotationProcessor 'com.squareup.dagger:dagger-compiler:1.2.2' annotationProcessor 'com.squareup.dagger:dagger-compiler:1.2.2'
compile 'com.code-troopers.betterpickers:library:3.1.0' compile 'mobi.upod:time-duration-picker:1.1.3'
provided 'com.squareup.dagger:dagger-compiler:1.2.2' provided 'com.squareup.dagger:dagger-compiler:1.2.2'
compile 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1' compile 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'
compile 'com.google.zxing:core:3.2.1' compile 'com.google.zxing:core:3.2.1'
@ -147,7 +147,7 @@ dependencyVerification {
'com.android.support:preference-v7:d9f32ddc92f8d6a0bd86a18f4fcaff805fa021245e395b6e7dd382907443ee53', 'com.android.support:preference-v7:d9f32ddc92f8d6a0bd86a18f4fcaff805fa021245e395b6e7dd382907443ee53',
'com.pnikosis:materialish-progress:d71d80e00717a096784482aee21001a9d299fec3833e4ebd87739ed36cf77c54', 'com.pnikosis:materialish-progress:d71d80e00717a096784482aee21001a9d299fec3833e4ebd87739ed36cf77c54',
'pl.tajchert:waitingdots:2835d49e0787dbcb606c5a60021ced66578503b1e9fddcd7a5ef0cd5f095ba2c', 'pl.tajchert:waitingdots:2835d49e0787dbcb606c5a60021ced66578503b1e9fddcd7a5ef0cd5f095ba2c',
'com.code-troopers.betterpickers:library:ab5cb3f00bd9c575461300b38f31f5874d522524b10bbaf75f3f05a4b6dbf5fd', 'mobi.upod:time-duration-picker:db469ce0f48dd96b892eac424ed76870e54bf00fe0a28cdcddfbe5f2a226a0e1',
'com.codewaves.stickyheadergrid:stickyheadergrid:5b4aa6a52a957cfd55f60f4220c11c0c371385a3cb9786cae03c260dcdef5794', 'com.codewaves.stickyheadergrid:stickyheadergrid:5b4aa6a52a957cfd55f60f4220c11c0c371385a3cb9786cae03c260dcdef5794',
'com.android.support:appcompat-v7:b2825e8b47f665d3362d8481c8d147d1af9230d16f23a2b94f6ccbc53c68cec1', 'com.android.support:appcompat-v7:b2825e8b47f665d3362d8481c8d147d1af9230d16f23a2b94f6ccbc53c68cec1',
'com.melnykov:floatingactionbutton:15d58d4fac0f7a288d0e5301bbaf501a146f5b3f5921277811bf99bd3b397263', 'com.melnykov:floatingactionbutton:15d58d4fac0f7a288d0e5301bbaf501a146f5b3f5921277811bf99bd3b397263',
@ -226,7 +226,6 @@ dependencyVerification {
] ]
} }
android { android {
flavorDimensions "none" flavorDimensions "none"
compileSdkVersion 27 compileSdkVersion 27

View File

@ -111,8 +111,6 @@
<attr name="pref_divider" format="reference" /> <attr name="pref_divider" format="reference" />
<attr name="app_protect_timeout_picker_color" format="reference"/>
<declare-styleable name="CustomDefaultPreference"> <declare-styleable name="CustomDefaultPreference">
<attr name="custom_pref_toggle" format="string"/> <attr name="custom_pref_toggle" format="string"/>
</declare-styleable> </declare-styleable>

View File

@ -229,8 +229,6 @@
<item name="pref_divider">@drawable/preference_divider_light</item> <item name="pref_divider">@drawable/preference_divider_light</item>
<item name="app_protect_timeout_picker_color">@style/BetterPickersDialogFragment.Light</item>
<item name="group_members_dialog_icon">@drawable/ic_group_grey600_24dp</item> <item name="group_members_dialog_icon">@drawable/ic_group_grey600_24dp</item>
<item name="preferenceTheme">@style/PreferenceThemeOverlay.Fix</item> <item name="preferenceTheme">@style/PreferenceThemeOverlay.Fix</item>
@ -354,8 +352,6 @@
<item name="pref_divider">@drawable/preference_divider_dark</item> <item name="pref_divider">@drawable/preference_divider_dark</item>
<item name="app_protect_timeout_picker_color">@style/BetterPickersDialogFragment</item>
<item name="group_members_dialog_icon">@drawable/ic_group_white_24dp</item> <item name="group_members_dialog_icon">@drawable/ic_group_white_24dp</item>
<item name="preferenceTheme">@style/PreferenceThemeOverlay.Fix</item> <item name="preferenceTheme">@style/PreferenceThemeOverlay.Fix</item>
<item name="search_toolbar_background">@color/black</item> <item name="search_toolbar_background">@color/black</item>

View File

@ -1,10 +1,9 @@
package org.thoughtcrime.securesms.preferences; package org.thoughtcrime.securesms.preferences;
import android.app.KeyguardManager;
import android.app.Activity; import android.app.Activity;
import android.app.KeyguardManager;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.res.TypedArray;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
@ -13,9 +12,6 @@ import android.support.v7.preference.CheckBoxPreference;
import android.support.v7.preference.Preference; import android.support.v7.preference.Preference;
import android.widget.Toast; import android.widget.Toast;
import com.codetroopers.betterpickers.hmspicker.HmsPickerBuilder;
import com.codetroopers.betterpickers.hmspicker.HmsPickerDialogFragment;
import org.thoughtcrime.securesms.ApplicationContext; import org.thoughtcrime.securesms.ApplicationContext;
import org.thoughtcrime.securesms.ApplicationPreferencesActivity; import org.thoughtcrime.securesms.ApplicationPreferencesActivity;
import org.thoughtcrime.securesms.BlockedContactsActivity; import org.thoughtcrime.securesms.BlockedContactsActivity;
@ -34,6 +30,8 @@ import java.util.concurrent.TimeUnit;
import javax.inject.Inject; import javax.inject.Inject;
import mobi.upod.timedurationpicker.TimeDurationPickerDialog;
public class AppProtectionPreferenceFragment extends CorrectedPreferenceFragment implements InjectableType { public class AppProtectionPreferenceFragment extends CorrectedPreferenceFragment implements InjectableType {
private static final String PREFERENCE_CATEGORY_BLOCKED = "preference_category_blocked"; private static final String PREFERENCE_CATEGORY_BLOCKED = "preference_category_blocked";
@ -132,32 +130,23 @@ public class AppProtectionPreferenceFragment extends CorrectedPreferenceFragment
} }
} }
private class ScreenLockTimeoutListener implements Preference.OnPreferenceClickListener, HmsPickerDialogFragment.HmsPickerDialogHandlerV2 { private class ScreenLockTimeoutListener implements Preference.OnPreferenceClickListener {
@Override @Override
public boolean onPreferenceClick(Preference preference) { public boolean onPreferenceClick(Preference preference) {
int[] attributes = {R.attr.app_protect_timeout_picker_color}; new TimeDurationPickerDialog(getContext(), (view, duration) -> {
TypedArray hmsStyle = getActivity().obtainStyledAttributes(attributes); if (duration == 0) {
TextSecurePreferences.setScreenLockTimeout(getContext(), 0);
} else {
long timeoutSeconds = Math.max(TimeUnit.MILLISECONDS.toSeconds(duration), 60);
TextSecurePreferences.setScreenLockTimeout(getContext(), timeoutSeconds);
}
new HmsPickerBuilder().setFragmentManager(getFragmentManager()) initializeScreenLockTimeoutSummary();
.setStyleResId(hmsStyle.getResourceId(0, R.style.BetterPickersDialogFragment_Light)) }, 0).show();
.addHmsPickerDialogHandler(this)
.show();
hmsStyle.recycle();
return true; return true;
} }
@Override
public void onDialogHmsSet(int reference, boolean isNegative, int hours, int minutes, int seconds) {
long timeoutSeconds = Math.max(TimeUnit.HOURS.toSeconds(hours) +
TimeUnit.MINUTES.toSeconds(minutes) +
TimeUnit.SECONDS.toSeconds(seconds), 60);
TextSecurePreferences.setScreenLockTimeout(getContext(), timeoutSeconds);
initializeScreenLockTimeoutSummary();
}
} }
private class AccountLockClickListener implements Preference.OnPreferenceClickListener { private class AccountLockClickListener implements Preference.OnPreferenceClickListener {
@ -231,33 +220,21 @@ public class AppProtectionPreferenceFragment extends CorrectedPreferenceFragment
} }
} }
private class PassphraseIntervalClickListener implements Preference.OnPreferenceClickListener, HmsPickerDialogFragment.HmsPickerDialogHandlerV2 { private class PassphraseIntervalClickListener implements Preference.OnPreferenceClickListener {
@Override @Override
public boolean onPreferenceClick(Preference preference) { public boolean onPreferenceClick(Preference preference) {
int[] attributes = {R.attr.app_protect_timeout_picker_color}; new TimeDurationPickerDialog(getContext(), (view, duration) -> {
TypedArray hmsStyle = getActivity().obtainStyledAttributes(attributes); int timeoutMinutes = Math.max((int)TimeUnit.MILLISECONDS.toMinutes(duration), 1);
new HmsPickerBuilder().setFragmentManager(getFragmentManager()) TextSecurePreferences.setPassphraseTimeoutInterval(getActivity(), timeoutMinutes);
.setStyleResId(hmsStyle.getResourceId(0, R.style.BetterPickersDialogFragment_Light))
.addHmsPickerDialogHandler(this)
.show();
hmsStyle.recycle(); initializePassphraseTimeoutSummary();
}, 0).show();
return true; return true;
} }
@Override
public void onDialogHmsSet(int reference, boolean isNegative, int hours, int minutes, int seconds) {
int timeoutMinutes = Math.max((int)TimeUnit.HOURS.toMinutes(hours) +
minutes +
(int)TimeUnit.SECONDS.toMinutes(seconds), 1);
TextSecurePreferences.setPassphraseTimeoutInterval(getActivity(), timeoutMinutes);
initializePassphraseTimeoutSummary();
}
} }
private class DisablePassphraseClickListener implements Preference.OnPreferenceChangeListener { private class DisablePassphraseClickListener implements Preference.OnPreferenceChangeListener {