12
12
13
13
import org .sorz .lab .tinykeepass .auth .FingerprintDialogFragment ;
14
14
import org .sorz .lab .tinykeepass .auth .SecureStringStorage ;
15
- import org .sorz .lab .tinykeepass .keepass .KeePassStorage ;
16
15
import org .sorz .lab .tinykeepass .keepass .OpenKeePassTask ;
17
16
17
+ import java .security .KeyException ;
18
18
import java .util .List ;
19
19
import java .util .function .Consumer ;
20
20
28
28
public abstract class BaseActivity extends AppCompatActivity
29
29
implements FingerprintDialogFragment .OnFragmentInteractionListener {
30
30
private final static String TAG = MainActivity .class .getName ();
31
- private final static int REQUEST_CONFIRM_DEVICE_CREDENTIAL = 0 ;
31
+ private final static int REQUEST_CONFIRM_DEVICE_CREDENTIAL = 100 ;
32
+ private final static int REQUEST_SETUP_DATABASE = 101 ;
32
33
33
34
private SharedPreferences preferences ;
34
35
private KeyguardManager keyguardManager ;
@@ -57,6 +58,12 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
57
58
else
58
59
onKeyAuthFailed .accept (getString (R .string .fail_to_auth ));
59
60
break ;
61
+ case REQUEST_SETUP_DATABASE :
62
+ if (resultCode == RESULT_OK )
63
+ getKey ();
64
+ else
65
+ onKeyAuthFailed .accept (getString (R .string .fail_to_decrypt ));
66
+ break ;
60
67
default :
61
68
super .onActivityResult (requestCode , resultCode , data );
62
69
}
@@ -79,6 +86,13 @@ protected void getDatabaseKeys(Consumer<List<String>> onKeyRetrieved,
79
86
getKey ();
80
87
}
81
88
89
+ @ Override
90
+ public void onKeyException (KeyException e ) {
91
+ // Key is invalided, have to reconfigure passwords.
92
+ Intent intent = new Intent (this , DatabaseSetupActivity .class );
93
+ startActivityForResult (intent , REQUEST_SETUP_DATABASE );
94
+ }
95
+
82
96
private void getKey () {
83
97
int authMethod = preferences .getInt ("key-auth-method" , 0 );
84
98
switch (authMethod ) {
@@ -93,6 +107,8 @@ private void getKey() {
93
107
getString (R .string .auth_key_title ),
94
108
getString (R .string .auth_key_description ));
95
109
startActivityForResult (intent , REQUEST_CONFIRM_DEVICE_CREDENTIAL );
110
+ } catch (KeyException e ) {
111
+ onKeyException (e );
96
112
} catch (SecureStringStorage .SystemException e ) {
97
113
throw new RuntimeException (e );
98
114
}
0 commit comments