code cleanup

Signed-off-by: tobiaskaminsky <tobias@kaminsky.me>
This commit is contained in:
tobiaskaminsky 2018-03-20 14:12:32 +01:00 committed by AndyScherzinger
parent 5f89a1f626
commit f85e8e3389
No known key found for this signature in database
GPG key ID: 6CADC7E3523C308B
5 changed files with 15 additions and 19 deletions

View file

@ -84,9 +84,8 @@ public class PassCodeManager {
activity.startActivityForResult(i, PASSCODE_ACTIVITY);
}
if (!sExemptOfPasscodeActivites.contains(activity.getClass()) && Build.VERSION.SDK_INT >=
Build.VERSION_CODES.M && deviceCredentialsShouldBeRequested(activity) &&
if (!sExemptOfPasscodeActivites.contains(activity.getClass()) &&
Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && deviceCredentialsShouldBeRequested(activity) &&
!DeviceCredentialUtils.tryEncrypt(activity)) {
Intent i = new Intent(MainApp.getAppContext(), RequestCredentialsActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
@ -102,7 +101,8 @@ public class PassCodeManager {
}
setUnlockTimestamp();
PowerManager powerMgr = (PowerManager) activity.getSystemService(Context.POWER_SERVICE);
if ((passCodeIsEnabled() || deviceCredentialsAreEnabled(activity)) && powerMgr != null && !powerMgr.isScreenOn()) {
if ((passCodeIsEnabled() || deviceCredentialsAreEnabled(activity)) && powerMgr != null
&& !powerMgr.isScreenOn()) {
activity.moveTaskToBack(true);
}
}

View file

@ -52,10 +52,10 @@ public class ManageSpaceActivity extends AppCompatActivity {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setTitle(R.string.manage_space_title);
TextView descriptionTextView = (TextView) findViewById(R.id.general_description);
TextView descriptionTextView = findViewById(R.id.general_description);
descriptionTextView.setText(getString(R.string.manage_space_description, getString(R.string.app_name)));
Button clearDataButton = (Button) findViewById(R.id.clearDataButton);
Button clearDataButton = findViewById(R.id.clearDataButton);
clearDataButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

View file

@ -376,7 +376,6 @@ public class Preferences extends PreferenceActivity
if (pFeedback != null) {
if (feedbackEnabled) {
pFeedback.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
String feedbackMail = getString(R.string.mail_feedback);
@ -883,7 +882,7 @@ public class Preferences extends PreferenceActivity
} else if (requestCode == ACTION_CONFIRM_DEVICE_CREDENTIALS && resultCode == RESULT_OK &&
Build.VERSION.SDK_INT >= Build.VERSION_CODES.M &&
data.getIntExtra(RequestCredentialsActivity.KEY_CHECK_RESULT,
RequestCredentialsActivity.KEY_CHECK_RESULT_FALSE) ==
RequestCredentialsActivity.KEY_CHECK_RESULT_FALSE) ==
RequestCredentialsActivity.KEY_CHECK_RESULT_TRUE) {
mLock.setValue(LOCK_NONE);
mLock.setSummary(mLock.getEntry());

View file

@ -52,8 +52,7 @@ public class RequestCredentialsActivity extends Activity {
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_CODE_CONFIRM_DEVICE_CREDENTIALS) {
if (resultCode == Activity.RESULT_OK && DeviceCredentialUtils
.tryEncrypt(getApplicationContext())) {
if (resultCode == Activity.RESULT_OK && DeviceCredentialUtils.tryEncrypt(getApplicationContext())) {
finishWithResult(KEY_CHECK_RESULT_TRUE);
} else if (resultCode == Activity.RESULT_CANCELED) {
finishWithResult(KEY_CHECK_RESULT_CANCEL);

View file

@ -62,8 +62,8 @@ public class DeviceCredentialUtils {
private static final String ANDROID_KEY_STORE = "AndroidKeyStore";
public static boolean areCredentialsAvailable(Context context) {
KeyguardManager keyguardManager = (KeyguardManager) context.getSystemService(
Context.KEYGUARD_SERVICE);
KeyguardManager keyguardManager = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
if (keyguardManager != null) {
return keyguardManager.isKeyguardSecure();
} else {
@ -82,13 +82,12 @@ public class DeviceCredentialUtils {
try {
KeyStore keyStore = KeyStore.getInstance(ANDROID_KEY_STORE);
keyStore.load(null);
KeyGenerator keyGenerator = KeyGenerator.getInstance(
KeyProperties.KEY_ALGORITHM_AES, ANDROID_KEY_STORE);
KeyGenerator keyGenerator = KeyGenerator.getInstance(KeyProperties.KEY_ALGORITHM_AES, ANDROID_KEY_STORE);
// Set the alias of the entry in Android KeyStore where the key will appear
// and the constrains (purposes) in the constructor of the Builder
keyGenerator.init(new KeyGenParameterSpec.Builder(keyName,
KeyProperties.PURPOSE_ENCRYPT | KeyProperties.PURPOSE_DECRYPT)
keyGenerator.init(new KeyGenParameterSpec.Builder(keyName, KeyProperties.PURPOSE_ENCRYPT |
KeyProperties.PURPOSE_DECRYPT)
.setBlockModes(KeyProperties.BLOCK_MODE_CBC)
.setUserAuthenticationRequired(true)
// Require that the user has unlocked in the last 30 seconds
@ -118,9 +117,8 @@ public class DeviceCredentialUtils {
KeyStore keyStore = KeyStore.getInstance(ANDROID_KEY_STORE);
keyStore.load(null);
SecretKey secretKey = (SecretKey) keyStore.getKey(keyName, null);
Cipher cipher = Cipher.getInstance(
KeyProperties.KEY_ALGORITHM_AES + "/" + KeyProperties.BLOCK_MODE_CBC + "/"
+ KeyProperties.ENCRYPTION_PADDING_PKCS7);
Cipher cipher = Cipher.getInstance(KeyProperties.KEY_ALGORITHM_AES + "/" +
KeyProperties.BLOCK_MODE_CBC + "/" + KeyProperties.ENCRYPTION_PADDING_PKCS7);
// Try encrypting something, it will only work if the user authenticated within
// the last AUTHENTICATION_DURATION_SECONDS seconds.