diff --git a/app/src/main/java/org/shadowice/flocke/andotp/Activities/MainActivity.java b/app/src/main/java/org/shadowice/flocke/andotp/Activities/MainActivity.java index a1956a3b..477c649b 100644 --- a/app/src/main/java/org/shadowice/flocke/andotp/Activities/MainActivity.java +++ b/app/src/main/java/org/shadowice/flocke/andotp/Activities/MainActivity.java @@ -23,22 +23,17 @@ package org.shadowice.flocke.andotp.Activities; -import android.Manifest; import android.animation.ObjectAnimator; import android.app.AlertDialog; import android.app.KeyguardManager; import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; -import android.content.pm.PackageManager; import android.content.res.Configuration; import android.os.Bundle; import android.os.CountDownTimer; import android.os.Handler; import android.preference.PreferenceManager; -import androidx.annotation.NonNull; -import androidx.core.app.ActivityCompat; -import androidx.core.content.ContextCompat; import androidx.core.view.GravityCompat; import androidx.drawerlayout.widget.DrawerLayout; import androidx.appcompat.app.ActionBarDrawerToggle; @@ -154,7 +149,7 @@ public class MainActivity extends BaseActivity if (authMethod == AuthMethod.DEVICE) { KeyguardManager km = (KeyguardManager) getSystemService(KEYGUARD_SERVICE); - if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP && km.isKeyguardSecure()) { + if (km.isKeyguardSecure()) { Intent authIntent = km.createConfirmDeviceCredentialIntent(getString(R.string.dialog_title_auth), getString(R.string.dialog_msg_auth)); startActivityForResult(authIntent, Constants.INTENT_MAIN_AUTHENTICATE); } @@ -243,7 +238,7 @@ public class MainActivity extends BaseActivity ManualEntryDialog.show(MainActivity.this, settings, adapter); return false; case R.id.fabScanQRFromImage: - openFileWithPermissions(Constants.INTENT_MAIN_QR_OPEN_IMAGE); + showOpenFileSelector(Constants.INTENT_MAIN_QR_OPEN_IMAGE); return false; default: return false; @@ -336,7 +331,7 @@ public class MainActivity extends BaseActivity if (intentAction.equals(INTENT_SCAN_QR)) { scanQRCode(); } else if (intentAction.equals(INTENT_IMPORT_QR)) { - openFileWithPermissions(Constants.INTENT_MAIN_QR_OPEN_IMAGE); + showOpenFileSelector(Constants.INTENT_MAIN_QR_OPEN_IMAGE); } else if (intentAction.equals(INTENT_ENTER_DETAILS)) { ManualEntryDialog.show(MainActivity.this, settings, adapter); } else if (intentAction.equals(Intent.ACTION_VIEW)) { @@ -486,12 +481,7 @@ public class MainActivity extends BaseActivity } else if (requestCode == Constants.INTENT_MAIN_AUTHENTICATE) { if (resultCode != RESULT_OK) { Toast.makeText(getBaseContext(), R.string.toast_auth_failed_fatal, Toast.LENGTH_LONG).show(); - - if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) { - finishAndRemoveTask(); - } else { - finish(); - } + finishAndRemoveTask(); } else { requireAuthentication = false; @@ -852,33 +842,12 @@ public class MainActivity extends BaseActivity return true; } - private void openFileWithPermissions(int intentId){ - if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { - showOpenFileSelector(intentId); - } else { - ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, Constants.PERMISSIONS_MAIN_QR_READ_IMAGE); - } - } - private void showOpenFileSelector(int intentId){ Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); intent.addCategory(Intent.CATEGORY_OPENABLE); intent.setType("image/*"); startActivityForResult(intent, intentId); } - - @Override - public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { - if (requestCode == Constants.PERMISSIONS_MAIN_QR_READ_IMAGE) { - if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - showOpenFileSelector(Constants.INTENT_MAIN_QR_OPEN_IMAGE); - } else { - Toast.makeText(this, R.string.backup_toast_storage_permissions, Toast.LENGTH_LONG).show(); - } - } else { - super.onRequestPermissionsResult(requestCode, permissions, grantResults); - } - } private void addQRCode(String result){ if(!TextUtils.isEmpty(result)) { diff --git a/app/src/main/java/org/shadowice/flocke/andotp/Utilities/Constants.java b/app/src/main/java/org/shadowice/flocke/andotp/Utilities/Constants.java index 4f000a4f..3e73e6b3 100644 --- a/app/src/main/java/org/shadowice/flocke/andotp/Utilities/Constants.java +++ b/app/src/main/java/org/shadowice/flocke/andotp/Utilities/Constants.java @@ -87,9 +87,6 @@ public class Constants { public static final int INTENT_SETTINGS_AUTHENTICATE = 300; - // Permission requests (Format: A1x with A = parent Activity, x = number of the request) - public final static int PERMISSIONS_MAIN_QR_READ_IMAGE = 111; - // Intent extras public final static String EXTRA_AUTH_PASSWORD_KEY = "password_key"; public final static String EXTRA_AUTH_NEW_ENCRYPTION = "new_encryption";