From ea57e9b6cb0c721bf102417b43f49cc5d374f936 Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Sun, 29 Nov 2020 20:44:57 +0100 Subject: [PATCH 1/4] use new permission system and fix a few compiler warnings --- .../activities/MyPreferenceFragment.kt | 2 +- .../general/maintenance/ImportExportPrefs.kt | 19 +++++++++---------- .../androidaps/utils/AndroidPermission.kt | 2 +- .../pump/omnipod/ui/PodManagementActivity.kt | 2 +- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/activities/MyPreferenceFragment.kt b/app/src/main/java/info/nightscout/androidaps/activities/MyPreferenceFragment.kt index 235447a2fd..b3f3024de6 100644 --- a/app/src/main/java/info/nightscout/androidaps/activities/MyPreferenceFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/activities/MyPreferenceFragment.kt @@ -151,7 +151,7 @@ class MyPreferenceFragment : PreferenceFragmentCompat(), OnSharedPreferenceChang override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { (savedInstanceState ?: arguments)?.let { bundle -> if (bundle.containsKey("id")) { - pluginId = bundle.getInt("id") ?: -1 + pluginId = bundle.getInt("id") } if (bundle.containsKey("filter")) { filter = bundle.getString("filter") ?: "" diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/ImportExportPrefs.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/ImportExportPrefs.kt index 661dc3a2bb..5394a581d5 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/ImportExportPrefs.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/ImportExportPrefs.kt @@ -1,13 +1,13 @@ package info.nightscout.androidaps.plugins.general.maintenance import android.Manifest -import androidx.appcompat.app.AppCompatActivity import android.bluetooth.BluetoothAdapter import android.content.Context import android.content.Intent import android.content.pm.PackageManager import android.provider.Settings import androidx.annotation.StringRes +import androidx.appcompat.app.AppCompatActivity import androidx.core.content.ContextCompat import androidx.fragment.app.Fragment import androidx.fragment.app.FragmentActivity @@ -21,6 +21,7 @@ import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.general.maintenance.formats.* +import info.nightscout.androidaps.utils.AndroidPermission import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.ToastUtils import info.nightscout.androidaps.utils.alertDialogs.OKDialog @@ -43,12 +44,6 @@ import javax.inject.Singleton * Created by mike on 03.07.2016. */ -private const val REQUEST_EXTERNAL_STORAGE = 1 -private val PERMISSIONS_STORAGE = arrayOf( - Manifest.permission.READ_EXTERNAL_STORAGE, - Manifest.permission.WRITE_EXTERNAL_STORAGE -) - @Singleton class ImportExportPrefs @Inject constructor( private var log: AAPSLogger, @@ -57,6 +52,7 @@ class ImportExportPrefs @Inject constructor( private val buildHelper: BuildHelper, private val rxBus: RxBusWrapper, private val passwordCheck: PasswordCheck, + private val androidPermission: AndroidPermission, private val classicPrefsFormat: ClassicPrefsFormat, private val encryptedPrefsFormat: EncryptedPrefsFormat, private val prefFileList: PrefFileListProvider @@ -73,12 +69,15 @@ class ImportExportPrefs @Inject constructor( } fun verifyStoragePermissions(fragment: Fragment, onGranted: Runnable) { - fragment.context?.let { - val permission = ContextCompat.checkSelfPermission(it, + fragment.context?.let { ctx -> + val permission = ContextCompat.checkSelfPermission(ctx, Manifest.permission.WRITE_EXTERNAL_STORAGE) if (permission != PackageManager.PERMISSION_GRANTED) { // We don't have permission so prompt the user - fragment.requestPermissions(PERMISSIONS_STORAGE, REQUEST_EXTERNAL_STORAGE) + fragment.activity?.let { + androidPermission.askForPermission(it, arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE, + Manifest.permission.WRITE_EXTERNAL_STORAGE), AndroidPermission.CASE_STORAGE) + } } else { onGranted.run() } diff --git a/app/src/main/java/info/nightscout/androidaps/utils/AndroidPermission.kt b/app/src/main/java/info/nightscout/androidaps/utils/AndroidPermission.kt index 3cf3addeeb..b2d294da1a 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/AndroidPermission.kt +++ b/app/src/main/java/info/nightscout/androidaps/utils/AndroidPermission.kt @@ -46,7 +46,7 @@ class AndroidPermission @Inject constructor( private var permission_battery_optimization_failed = false @SuppressLint("BatteryLife") - private fun askForPermission(activity: FragmentActivity, permission: Array, requestCode: Int) { + fun askForPermission(activity: FragmentActivity, permission: Array, requestCode: Int) { var test = false var testBattery = false for (s in permission) { diff --git a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/ui/PodManagementActivity.kt b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/ui/PodManagementActivity.kt index 058a033d85..392dcd0be2 100644 --- a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/ui/PodManagementActivity.kt +++ b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/ui/PodManagementActivity.kt @@ -209,7 +209,7 @@ class PodManagementActivity : NoSplashAppCompatActivity() { } private fun displayNotConfiguredDialog() { - context?.let { + context.let { UIRunnable(Runnable { OKDialog.show(it, resourceHelper.gs(R.string.omnipod_warning), resourceHelper.gs(R.string.omnipod_error_operation_not_possible_no_configuration), null) From b5078e91c764da70d887273e698a5c8a8acbfd2f Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Sun, 29 Nov 2020 20:55:35 +0100 Subject: [PATCH 2/4] firebase activity expects to have launchMode overridden --- app/src/main/AndroidManifest.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 96763d8274..e0e2a6b05b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,5 +1,6 @@ @@ -71,6 +72,10 @@ + Date: Sun, 29 Nov 2020 21:04:26 +0100 Subject: [PATCH 3/4] fix two compiler warnings --- .../androidaps/plugins/general/openhumans/OpenHumansAPI.kt | 4 ++-- .../plugins/general/openhumans/OpenHumansUploader.kt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/openhumans/OpenHumansAPI.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/openhumans/OpenHumansAPI.kt index 70dc24f533..91fa60ca25 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/openhumans/OpenHumansAPI.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/openhumans/OpenHumansAPI.kt @@ -43,8 +43,8 @@ class OpenHumansAPI( .toSingle() .map { response -> response.use { _ -> - val body = response.body - val jsonObject = body?.let { JSONObject(it.string()) } + val responseBody = response.body + val jsonObject = responseBody?.let { JSONObject(it.string()) } if (!response.isSuccessful) throw OHHttpException(response.code, response.message, jsonObject?.getString("error")) if (jsonObject == null) throw OHHttpException(response.code, response.message, "No body") if (!jsonObject.has("expires_in")) throw OHMissingFieldException("expires_in") diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/openhumans/OpenHumansUploader.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/openhumans/OpenHumansUploader.kt index 6aade7412d..b1c80f5b25 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/openhumans/OpenHumansUploader.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/openhumans/OpenHumansUploader.kt @@ -564,7 +564,7 @@ class OpenHumansUploader @Inject constructor( creationDate = uploadDate.time ), content = bytes, - highestQueueId = items.map { it.id }.max() + highestQueueId = items.map { it.id }.maxOrNull() )) } From 8e95296bf7783e939c4a84026974302ecb813c8b Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Sun, 29 Nov 2020 21:06:12 +0100 Subject: [PATCH 4/4] fix logging lambda --- .../main/java/info/nightscout/androidaps/MainActivity.kt | 4 ++-- .../androidaps/historyBrowser/HistoryBrowseActivity.kt | 8 ++++---- .../general/persistentNotification/DummyService.kt | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/MainActivity.kt b/app/src/main/java/info/nightscout/androidaps/MainActivity.kt index e62cd087d9..866a98b3e1 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainActivity.kt +++ b/app/src/main/java/info/nightscout/androidaps/MainActivity.kt @@ -136,12 +136,12 @@ class MainActivity : NoSplashAppCompatActivity() { if (it.recreate) recreate() else setupViews() setWakeLock() - }) { fabricPrivacy::logException } + }, fabricPrivacy::logException ) ) disposable.add(rxBus .toObservable(EventPreferenceChange::class.java) .observeOn(AndroidSchedulers.mainThread()) - .subscribe({ processPreferenceChange(it) }) { fabricPrivacy::logException } + .subscribe({ processPreferenceChange(it) }, fabricPrivacy::logException ) ) if (!sp.getBoolean(R.string.key_setupwizard_processed, false) && !isRunningRealPumpTest()) { val intent = Intent(this, SetupWizardActivity::class.java) diff --git a/app/src/main/java/info/nightscout/androidaps/historyBrowser/HistoryBrowseActivity.kt b/app/src/main/java/info/nightscout/androidaps/historyBrowser/HistoryBrowseActivity.kt index 074ac67988..e72154ab1c 100644 --- a/app/src/main/java/info/nightscout/androidaps/historyBrowser/HistoryBrowseActivity.kt +++ b/app/src/main/java/info/nightscout/androidaps/historyBrowser/HistoryBrowseActivity.kt @@ -168,7 +168,7 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() { if (it.cause is EventCustomCalculationFinished) { updateGUI("EventAutosensCalculationFinished", bgOnly = false) } - }) { fabricPrivacy::logException } + }, fabricPrivacy::logException ) ) disposable.add(rxBus .toObservable(EventAutosensBgLoaded::class.java) @@ -178,12 +178,12 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() { if (it.cause is EventCustomCalculationFinished) { updateGUI("EventAutosensCalculationFinished", bgOnly = true) } - }) { fabricPrivacy::logException } + }, fabricPrivacy::logException ) ) disposable.add(rxBus .toObservable(EventIobCalculationProgress::class.java) .observeOn(AndroidSchedulers.mainThread()) - .subscribe({ overview_iobcalculationprogess?.text = it.progress }) { fabricPrivacy::logException } + .subscribe({ overview_iobcalculationprogess?.text = it.progress }, fabricPrivacy::logException ) ) disposable.add(rxBus .toObservable(EventRefreshOverview::class.java) @@ -193,7 +193,7 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() { prepareGraphs() updateGUI("EventRefreshOverview", bgOnly = false) } - }) { fabricPrivacy::logException } + }, fabricPrivacy::logException ) ) if (start == 0L) { // set start of current day diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/DummyService.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/DummyService.kt index 5fcf9ee85b..ecca16c581 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/DummyService.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/DummyService.kt @@ -44,7 +44,7 @@ class DummyService : DaggerService() { .subscribe({ aapsLogger.debug(LTag.CORE, "EventAppExit received") stopSelf() - }) { fabricPrivacy::logException } + }, fabricPrivacy::logException ) ) }