From 97cd61fd13055ef93c9c27b691b0b1e684c33e85 Mon Sep 17 00:00:00 2001 From: J-Jamet Date: Fri, 17 Dec 2021 17:57:09 +0100 Subject: [PATCH] First pass to update API 31 --- app/build.gradle | 10 +++---- app/src/main/AndroidManifest.xml | 2 ++ .../activities/AutofillLauncherActivity.kt | 10 +++---- .../keepass/activities/EntryActivity.kt | 4 +-- .../keepass/adapters/NodesAdapter.kt | 1 + .../keepass/timeout/TimeoutHelper.kt | 22 +++++++++++++-- .../keepass/utils/BroadcastAction.kt | 28 +++++++++++++++---- .../kunzisoft/keepass/view/ToolbarAction.kt | 3 +- build.gradle | 8 +++--- crypto/build.gradle | 6 ++-- icon-pack-classic/build.gradle | 6 ++-- icon-pack-material/build.gradle | 6 ++-- 12 files changed, 72 insertions(+), 34 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 78b9b567c..d331ecef3 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -3,14 +3,14 @@ apply plugin: 'kotlin-android' apply plugin: 'kotlin-kapt' android { - compileSdkVersion 30 - buildToolsVersion "30.0.3" + compileSdkVersion 31 + buildToolsVersion "31.0.0" ndkVersion "21.4.7075529" defaultConfig { applicationId "com.kunzisoft.keepass" minSdkVersion 15 - targetSdkVersion 30 + targetSdkVersion 31 versionCode = 92 versionName = "3.1.0" multiDexEnabled true @@ -99,7 +99,7 @@ android { } } -def room_version = "2.3.0" +def room_version = "2.4.0" dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" @@ -113,7 +113,7 @@ dependencies { implementation 'androidx.media:media:1.4.3' // Lifecycle - LiveData - ViewModel - Coroutines implementation "androidx.core:core-ktx:$android_core_version" - implementation 'androidx.fragment:fragment-ktx:1.3.6' + implementation 'androidx.fragment:fragment-ktx:1.4.0' implementation "com.google.android.material:material:$android_material_version" // Database implementation "androidx.room:room-runtime:$room_version" diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d1f458ed1..9a424cdb0 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -10,6 +10,8 @@ android:anyDensity="true" /> + = Build.VERSION_CODES.M) { - // TODO Mutable - PendingIntent.FLAG_CANCEL_CURRENT + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { + PendingIntent.FLAG_MUTABLE or PendingIntent.FLAG_CANCEL_CURRENT } else { PendingIntent.FLAG_CANCEL_CURRENT }) @@ -248,9 +247,8 @@ class AutofillLauncherActivity : DatabaseModeActivity() { EntrySelectionHelper.addSpecialModeInIntent(this, SpecialMode.REGISTRATION) putExtra(KEY_REGISTER_INFO, registerInfo) }, - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - // TODO Mutable - PendingIntent.FLAG_CANCEL_CURRENT + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { + PendingIntent.FLAG_MUTABLE or PendingIntent.FLAG_CANCEL_CURRENT } else { PendingIntent.FLAG_CANCEL_CURRENT }) diff --git a/app/src/main/java/com/kunzisoft/keepass/activities/EntryActivity.kt b/app/src/main/java/com/kunzisoft/keepass/activities/EntryActivity.kt index dbe15e9ab..d9ed8c2d8 100644 --- a/app/src/main/java/com/kunzisoft/keepass/activities/EntryActivity.kt +++ b/app/src/main/java/com/kunzisoft/keepass/activities/EntryActivity.kt @@ -204,9 +204,9 @@ class EntryActivity : DatabaseLockActivity() { } mEntryViewModel.onOtpElementUpdated.observe(this) { otpElement -> - if (otpElement == null) + if (otpElement == null) { entryProgress?.visibility = View.GONE - when (otpElement?.type) { + } else when (otpElement.type) { // Only add token if HOTP OtpType.HOTP -> { entryProgress?.visibility = View.GONE diff --git a/app/src/main/java/com/kunzisoft/keepass/adapters/NodesAdapter.kt b/app/src/main/java/com/kunzisoft/keepass/adapters/NodesAdapter.kt index 1ddcaec74..6018b49bd 100644 --- a/app/src/main/java/com/kunzisoft/keepass/adapters/NodesAdapter.kt +++ b/app/src/main/java/com/kunzisoft/keepass/adapters/NodesAdapter.kt @@ -454,6 +454,7 @@ class NodesAdapter (private val context: Context, progress = otpElement.secondsRemaining } } + null -> {} } holder?.otpToken?.apply { text = otpElement?.token diff --git a/app/src/main/java/com/kunzisoft/keepass/timeout/TimeoutHelper.kt b/app/src/main/java/com/kunzisoft/keepass/timeout/TimeoutHelper.kt index fddd95ca3..d6b7490ca 100644 --- a/app/src/main/java/com/kunzisoft/keepass/timeout/TimeoutHelper.kt +++ b/app/src/main/java/com/kunzisoft/keepass/timeout/TimeoutHelper.kt @@ -66,9 +66,27 @@ object TimeoutHelper { val triggerTime = System.currentTimeMillis() + timeout Log.d(TAG, "TimeoutHelper start") if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { - alarmManager.setExact(AlarmManager.RTC, triggerTime, getLockPendingIntent(context)) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S + && !alarmManager.canScheduleExactAlarms()) { + alarmManager.set( + AlarmManager.RTC, + triggerTime, + getLockPendingIntent(context) + ) + // TODO explain why exact alarm is needed for timeout + } else { + alarmManager.setExact( + AlarmManager.RTC, + triggerTime, + getLockPendingIntent(context) + ) + } } else { - alarmManager.set(AlarmManager.RTC, triggerTime, getLockPendingIntent(context)) + alarmManager.set( + AlarmManager.RTC, + triggerTime, + getLockPendingIntent(context) + ) } } } diff --git a/app/src/main/java/com/kunzisoft/keepass/utils/BroadcastAction.kt b/app/src/main/java/com/kunzisoft/keepass/utils/BroadcastAction.kt index d3b6a6d14..78e8c5edb 100644 --- a/app/src/main/java/com/kunzisoft/keepass/utils/BroadcastAction.kt +++ b/app/src/main/java/com/kunzisoft/keepass/utils/BroadcastAction.kt @@ -72,11 +72,29 @@ class LockReceiver(var lockAction: () -> Unit) : BroadcastReceiver() { ) // Launch the effective action after a small time val first: Long = System.currentTimeMillis() + context.getString(R.string.timeout_screen_off).toLong() - val alarmManager = context.getSystemService(ALARM_SERVICE) as AlarmManager? - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { - alarmManager?.setExact(AlarmManager.RTC_WAKEUP, first, mLockPendingIntent) - } else { - alarmManager?.set(AlarmManager.RTC_WAKEUP, first, mLockPendingIntent) + (context.getSystemService(ALARM_SERVICE) as AlarmManager?)?.let { alarmManager -> + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S + && !alarmManager.canScheduleExactAlarms()) { + alarmManager.set( + AlarmManager.RTC_WAKEUP, + first, + mLockPendingIntent + ) + } else { + alarmManager.setExact( + AlarmManager.RTC_WAKEUP, + first, + mLockPendingIntent + ) + } + } else { + alarmManager.set( + AlarmManager.RTC_WAKEUP, + first, + mLockPendingIntent + ) + } } } else { cancelLockPendingIntent(context) diff --git a/app/src/main/java/com/kunzisoft/keepass/view/ToolbarAction.kt b/app/src/main/java/com/kunzisoft/keepass/view/ToolbarAction.kt index 7c103a828..852bd9aa3 100644 --- a/app/src/main/java/com/kunzisoft/keepass/view/ToolbarAction.kt +++ b/app/src/main/java/com/kunzisoft/keepass/view/ToolbarAction.kt @@ -80,7 +80,8 @@ class ToolbarAction @JvmOverloads constructor(context: Context, mActionModeCallback = null } - fun invalidateMenu() { + override fun invalidateMenu() { + super.invalidateMenu() open() mActionModeCallback?.onPrepareActionMode(actionMode, menu) } diff --git a/build.gradle b/build.gradle index e49f02e35..5e7838165 100644 --- a/build.gradle +++ b/build.gradle @@ -1,8 +1,8 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.5.31' - ext.android_core_version = '1.6.0' - ext.android_appcompat_version = '1.3.1' + ext.kotlin_version = '1.6.10' + ext.android_core_version = '1.7.0' + ext.android_appcompat_version = '1.4.0' ext.android_material_version = '1.4.0' ext.android_test_version = '1.4.0' repositories { @@ -10,7 +10,7 @@ buildscript { google() } dependencies { - classpath 'com.android.tools.build:gradle:7.0.3' + classpath 'com.android.tools.build:gradle:7.0.4' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } diff --git a/crypto/build.gradle b/crypto/build.gradle index 07db3064f..9a41d3b9d 100644 --- a/crypto/build.gradle +++ b/crypto/build.gradle @@ -5,12 +5,12 @@ plugins { } android { - compileSdkVersion 30 - buildToolsVersion "30.0.3" + compileSdkVersion 31 + buildToolsVersion "31.0.0" defaultConfig { minSdkVersion 15 - targetSdkVersion 30 + targetSdkVersion 31 versionCode 1 versionName "1.0" multiDexEnabled true diff --git a/icon-pack-classic/build.gradle b/icon-pack-classic/build.gradle index db6d4cd13..0559baee7 100644 --- a/icon-pack-classic/build.gradle +++ b/icon-pack-classic/build.gradle @@ -1,12 +1,12 @@ apply plugin: 'com.android.library' android { - compileSdkVersion 30 - buildToolsVersion '30.0.3' + compileSdkVersion 31 + buildToolsVersion '31.0.0' defaultConfig { minSdkVersion 14 - targetSdkVersion 30 + targetSdkVersion 31 } resourcePrefix 'classic_' diff --git a/icon-pack-material/build.gradle b/icon-pack-material/build.gradle index 7c57d1a7c..a9667829b 100644 --- a/icon-pack-material/build.gradle +++ b/icon-pack-material/build.gradle @@ -1,12 +1,12 @@ apply plugin: 'com.android.library' android { - compileSdkVersion 30 - buildToolsVersion '30.0.3' + compileSdkVersion 31 + buildToolsVersion '31.0.0' defaultConfig { minSdkVersion 14 - targetSdkVersion 30 + targetSdkVersion 31 } resourcePrefix 'material_'