Merge pull request #657 from mchllngr/auto-unlock-after-autofill
added option to automatically unlock after the password has been filled in by autofill
This commit is contained in:
commit
2abe414aa4
8 changed files with 96 additions and 6 deletions
|
@ -27,7 +27,6 @@ import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import com.google.android.material.textfield.TextInputEditText;
|
|
||||||
import com.google.android.material.textfield.TextInputLayout;
|
import com.google.android.material.textfield.TextInputLayout;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
@ -57,11 +56,13 @@ import org.shadowice.flocke.andotp.Tasks.AuthenticationTask;
|
||||||
import org.shadowice.flocke.andotp.Tasks.AuthenticationTask.Result;
|
import org.shadowice.flocke.andotp.Tasks.AuthenticationTask.Result;
|
||||||
import org.shadowice.flocke.andotp.Utilities.Constants;
|
import org.shadowice.flocke.andotp.Utilities.Constants;
|
||||||
import org.shadowice.flocke.andotp.Utilities.EditorActionHelper;
|
import org.shadowice.flocke.andotp.Utilities.EditorActionHelper;
|
||||||
|
import org.shadowice.flocke.andotp.View.AutoFillable.AutoFillableTextInputEditText;
|
||||||
|
|
||||||
import static org.shadowice.flocke.andotp.Utilities.Constants.AuthMethod;
|
import static org.shadowice.flocke.andotp.Utilities.Constants.AuthMethod;
|
||||||
|
|
||||||
public class AuthenticateActivity extends BaseActivity
|
public class AuthenticateActivity extends BaseActivity
|
||||||
implements EditText.OnEditorActionListener, View.OnClickListener {
|
implements EditText.OnEditorActionListener, View.OnClickListener {
|
||||||
|
private final AutoFillableTextInputEditText.AutoFillTextListener autoFillTextListener = text -> startAuthTask(text.toString());
|
||||||
|
|
||||||
private static final String TAG_TASK_FRAGMENT = "AuthenticateActivity.TaskFragmentTag";
|
private static final String TAG_TASK_FRAGMENT = "AuthenticateActivity.TaskFragmentTag";
|
||||||
|
|
||||||
|
@ -72,7 +73,7 @@ public class AuthenticateActivity extends BaseActivity
|
||||||
private ProcessLifecycleObserver observer;
|
private ProcessLifecycleObserver observer;
|
||||||
|
|
||||||
private TextInputLayout passwordLayout;
|
private TextInputLayout passwordLayout;
|
||||||
private TextInputEditText passwordInput;
|
AutoFillableTextInputEditText passwordInput;
|
||||||
private Button unlockButton;
|
private Button unlockButton;
|
||||||
private ProgressBar unlockProgress;
|
private ProgressBar unlockProgress;
|
||||||
|
|
||||||
|
@ -288,6 +289,14 @@ public class AuthenticateActivity extends BaseActivity
|
||||||
super.onBackPressed();
|
super.onBackPressed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onStart() {
|
||||||
|
super.onStart();
|
||||||
|
if (settings.getAutoUnlockAfterAutofill()) {
|
||||||
|
passwordInput.setAutoFillTextListener(autoFillTextListener);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPause() {
|
protected void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
|
@ -298,6 +307,12 @@ public class AuthenticateActivity extends BaseActivity
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onStop() {
|
||||||
|
passwordInput.setAutoFillTextListener(null);
|
||||||
|
super.onStop();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDestroy() {
|
protected void onDestroy() {
|
||||||
ProcessLifecycleOwner.get().getLifecycle()
|
ProcessLifecycleOwner.get().getLifecycle()
|
||||||
|
|
|
@ -363,12 +363,17 @@ public class SettingsActivity extends BaseActivity
|
||||||
});
|
});
|
||||||
|
|
||||||
CheckBoxPreference blockAutofill = (CheckBoxPreference) findPreference(getString(R.string.settings_key_block_autofill));
|
CheckBoxPreference blockAutofill = (CheckBoxPreference) findPreference(getString(R.string.settings_key_block_autofill));
|
||||||
|
CheckBoxPreference autoUnlockAfterAutofill = (CheckBoxPreference) findPreference(getString(R.string.settings_key_auto_unlock_after_autofill));
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
blockAutofill.setEnabled(true);
|
blockAutofill.setEnabled(true);
|
||||||
blockAutofill.setSummary(R.string.settings_desc_block_autofill);
|
blockAutofill.setSummary(R.string.settings_desc_block_autofill);
|
||||||
|
autoUnlockAfterAutofill.setEnabled(true);
|
||||||
|
autoUnlockAfterAutofill.setSummary(R.string.settings_desc_auto_unlock_after_autofill);
|
||||||
} else {
|
} else {
|
||||||
blockAutofill.setEnabled(false);
|
blockAutofill.setEnabled(false);
|
||||||
blockAutofill.setSummary(R.string.settings_desc_block_autofill_android);
|
blockAutofill.setSummary(R.string.settings_desc_autofill_requires_android_o);
|
||||||
|
autoUnlockAfterAutofill.setEnabled(false);
|
||||||
|
autoUnlockAfterAutofill.setSummary(R.string.settings_desc_autofill_requires_android_o);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Authentication
|
// Authentication
|
||||||
|
|
|
@ -606,6 +606,10 @@ public class Settings {
|
||||||
return getBoolean(R.string.settings_key_block_autofill, false);
|
return getBoolean(R.string.settings_key_block_autofill, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean getAutoUnlockAfterAutofill() {
|
||||||
|
return getBoolean(R.string.settings_key_auto_unlock_after_autofill, false);
|
||||||
|
}
|
||||||
|
|
||||||
public void setDefaultBackupType(Constants.BackupType type) {
|
public void setDefaultBackupType(Constants.BackupType type) {
|
||||||
setString(R.string.settings_key_backup_default_type, type.name().toLowerCase(Locale.ENGLISH));
|
setString(R.string.settings_key_backup_default_type, type.name().toLowerCase(Locale.ENGLISH));
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,56 @@
|
||||||
|
package org.shadowice.flocke.andotp.View.AutoFillable;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.Build;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
import android.view.autofill.AutofillValue;
|
||||||
|
|
||||||
|
import com.google.android.material.textfield.TextInputEditText;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link TextInputEditText} that allows setting a {@link AutoFillTextListener} for getting notified when
|
||||||
|
* this field was filled in by autofill.
|
||||||
|
*
|
||||||
|
* On devices running Android 7.1 (API 25) and below the listener will never be called, because
|
||||||
|
* autofill is not supported.
|
||||||
|
*/
|
||||||
|
public class AutoFillableTextInputEditText extends TextInputEditText {
|
||||||
|
|
||||||
|
@Nullable private AutoFillTextListener listener = null;
|
||||||
|
|
||||||
|
public AutoFillableTextInputEditText(@NonNull Context context) {
|
||||||
|
super(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
public AutoFillableTextInputEditText(@NonNull Context context, @Nullable AttributeSet attrs) {
|
||||||
|
super(context, attrs);
|
||||||
|
}
|
||||||
|
|
||||||
|
public AutoFillableTextInputEditText(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
|
||||||
|
super(context, attrs, defStyleAttr);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void autofill(AutofillValue value) {
|
||||||
|
super.autofill(value);
|
||||||
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O || listener == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value != null && value.isText()) {
|
||||||
|
listener.onTextAutoFilled(value.getTextValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAutoFillTextListener(@Nullable AutoFillTextListener listener) {
|
||||||
|
this.listener = listener;
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface AutoFillTextListener {
|
||||||
|
|
||||||
|
void onTextAutoFilled(@NonNull CharSequence text);
|
||||||
|
}
|
||||||
|
}
|
|
@ -24,7 +24,7 @@
|
||||||
android:hint="@string/auth_hint_password"
|
android:hint="@string/auth_hint_password"
|
||||||
app:endIconMode="password_toggle" >
|
app:endIconMode="password_toggle" >
|
||||||
|
|
||||||
<com.google.android.material.textfield.TextInputEditText
|
<org.shadowice.flocke.andotp.View.AutoFillable.AutoFillableTextInputEditText
|
||||||
android:id="@+id/passwordEdit"
|
android:id="@+id/passwordEdit"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
<string name="settings_key_auth_inactivity_delay" translatable="false">pref_auth_inactivity_timeout</string>
|
<string name="settings_key_auth_inactivity_delay" translatable="false">pref_auth_inactivity_timeout</string>
|
||||||
<string name="settings_key_block_accessibility" translatable="false">pref_block_accessibility</string>
|
<string name="settings_key_block_accessibility" translatable="false">pref_block_accessibility</string>
|
||||||
<string name="settings_key_block_autofill" translatable="false">pref_block_autofill</string>
|
<string name="settings_key_block_autofill" translatable="false">pref_block_autofill</string>
|
||||||
|
<string name="settings_key_auto_unlock_after_autofill" translatable="false">pref_auto_unlock_after_autofill</string>
|
||||||
|
|
||||||
<string name="settings_key_lang" translatable="false">pref_lang</string>
|
<string name="settings_key_lang" translatable="false">pref_lang</string>
|
||||||
<string name="settings_key_locale" translatable="false">pref_locale</string> <!-- Deprecated -->
|
<string name="settings_key_locale" translatable="false">pref_locale</string> <!-- Deprecated -->
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
<string name="settings_title_auth_inactivity_delay">Delay for inactivity re-lock</string>
|
<string name="settings_title_auth_inactivity_delay">Delay for inactivity re-lock</string>
|
||||||
<string name="settings_title_block_accessibility">Block accessibility services</string>
|
<string name="settings_title_block_accessibility">Block accessibility services</string>
|
||||||
<string name="settings_title_block_autofill">Block autofill</string>
|
<string name="settings_title_block_autofill">Block autofill</string>
|
||||||
|
<string name="settings_title_auto_unlock_after_autofill">Unlock automatically after autofill</string>
|
||||||
|
|
||||||
<string name="settings_title_lang">Language</string>
|
<string name="settings_title_lang">Language</string>
|
||||||
<string name="settings_title_theme">Theme</string>
|
<string name="settings_title_theme">Theme</string>
|
||||||
|
@ -74,7 +75,9 @@
|
||||||
services. <b>DO NOT enable this if you rely on the accessibility services!</b></string>
|
services. <b>DO NOT enable this if you rely on the accessibility services!</b></string>
|
||||||
<string name="settings_desc_block_autofill">Block autofill services from accessing password
|
<string name="settings_desc_block_autofill">Block autofill services from accessing password
|
||||||
fields inside the app</string>
|
fields inside the app</string>
|
||||||
<string name="settings_desc_block_autofill_android">This feature requires an Android version
|
<string name="settings_desc_auto_unlock_after_autofill">Unlock if the password has been filled
|
||||||
|
in by autofill</string>
|
||||||
|
<string name="settings_desc_autofill_requires_android_o">This feature requires an Android version
|
||||||
above 8.0 (Oreo)</string>
|
above 8.0 (Oreo)</string>
|
||||||
|
|
||||||
<string name="settings_desc_label_scroll">Scroll overlong labels instead of truncating them</string>
|
<string name="settings_desc_label_scroll">Scroll overlong labels instead of truncating them</string>
|
||||||
|
|
|
@ -74,6 +74,12 @@
|
||||||
android:summary="@string/settings_desc_block_autofill"
|
android:summary="@string/settings_desc_block_autofill"
|
||||||
android:defaultValue="false" />
|
android:defaultValue="false" />
|
||||||
|
|
||||||
|
<CheckBoxPreference
|
||||||
|
android:key="@string/settings_key_auto_unlock_after_autofill"
|
||||||
|
android:title="@string/settings_title_auto_unlock_after_autofill"
|
||||||
|
android:summary="@string/settings_desc_auto_unlock_after_autofill"
|
||||||
|
android:defaultValue="false" />
|
||||||
|
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
|
|
Loading…
Reference in a new issue