From fd731321764579fad32674318565329f5c8402a3 Mon Sep 17 00:00:00 2001 From: Darshan Parajuli Date: Sat, 10 Dec 2022 15:58:56 -0800 Subject: [PATCH] Upgrade AGP, and dependencies. --- app/build.gradle | 8 +- app/src/main/AndroidManifest.xml | 122 +++++++++--------- .../fragments/filters/FiltersFragment.kt | 1 + .../fragments/settings/SettingsFragment.kt | 24 ++-- .../dialogs/FilterExclusionDialogFragment.kt | 3 +- .../dp/logcatapp/services/LogcatService.kt | 63 ++++++--- .../com/dp/logcatapp/util/MyExtensions.kt | 24 +++- build.gradle | 31 +++-- collections/build.gradle | 2 - gradle/wrapper/gradle-wrapper.properties | 2 +- logcat/build.gradle | 2 - logger/build.gradle | 2 - 12 files changed, 164 insertions(+), 120 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index e1919c6..10b54b8 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -6,17 +6,18 @@ apply plugin: 'kotlin-kapt' def fileProvider = "file_provider" android { - compileSdkVersion 30 - buildToolsVersion "30.0.3" + compileSdkVersion 33 + buildToolsVersion "33.0.1" defaultConfig { applicationId "com.dp.logcatapp" minSdkVersion 16 - targetSdkVersion 30 + targetSdkVersion 33 versionCode 33 versionName "1.7.2" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true + multiDexEnabled true } signingConfigs { @@ -90,6 +91,7 @@ dependencies { kapt "androidx.room:room-compiler:$room_version" implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlin_coroutines_core_version" implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$kotlin_coroutines_android_version" + implementation "androidx.multidex:multidex:$multidex_version" testImplementation "junit:junit:$junit_version" androidTestImplementation "androidx.test:runner:$runner_version" diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 3d4a86a..363da4a 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,101 +1,103 @@ + xmlns:tools="http://schemas.android.com/tools" + package="com.dp.logcatapp"> - + - - - + + + + android:name=".LogcatApp" + android:allowBackup="true" + android:fullBackupContent="true" + android:icon="@mipmap/ic_launcher" + android:label="@string/app_name" + android:largeHeap="true" + android:supportsRtl="true" + android:theme="@style/LightTheme" + tools:ignore="GoogleAppIndexingWarning"> + android:exported="true" + android:name=".activities.SplashActivity" + android:theme="@style/SplashScreenTheme"> - + - + + android:name=".activities.MainActivity" + android:launchMode="singleTask"/> + android:name=".activities.SettingsActivity" + android:launchMode="singleTask" + android:parentActivityName=".activities.MainActivity" + android:windowSoftInputMode="adjustResize"> + android:name="android.support.PARENT_ACTIVITY" + android:value=".activities.MainActivity"/> + android:name=".activities.FiltersActivity" + android:launchMode="singleTask" + android:parentActivityName=".activities.MainActivity" + android:windowSoftInputMode="adjustResize"> + android:name="android.support.PARENT_ACTIVITY" + android:value=".activities.MainActivity"/> + android:name=".activities.SavedLogsActivity" + android:launchMode="singleTask" + android:parentActivityName=".activities.MainActivity" + android:windowSoftInputMode="adjustResize"> + android:name="android.support.PARENT_ACTIVITY" + android:value=".activities.MainActivity"/> + android:name=".activities.SavedLogsViewerActivity" + android:launchMode="singleTask" + android:parentActivityName=".activities.SavedLogsActivity" + android:windowSoftInputMode="adjustResize" + android:exported="true"> + android:name="android.support.PARENT_ACTIVITY" + android:value=".activities.SavedLogsActivity"/> - - + + + android:mimeType="text/plain" + android:scheme="file"/> + android:mimeType="text/plain" + android:scheme="content"/> + android:name=".services.LogcatService" + android:exported="false" + android:stopWithTask="false"/> + android:name="androidx.core.content.FileProvider" + android:authorities="${applicationId}.${fileProvider}" + android:exported="false" + android:grantUriPermissions="true"> + android:name="android.support.FILE_PROVIDER_PATHS" + android:resource="@xml/file_provider_paths"/> diff --git a/app/src/main/java/com/dp/logcatapp/fragments/filters/FiltersFragment.kt b/app/src/main/java/com/dp/logcatapp/fragments/filters/FiltersFragment.kt index 18d951d..0f5270d 100644 --- a/app/src/main/java/com/dp/logcatapp/fragments/filters/FiltersFragment.kt +++ b/app/src/main/java/com/dp/logcatapp/fragments/filters/FiltersFragment.kt @@ -10,6 +10,7 @@ import android.view.View import android.view.ViewGroup import android.widget.ImageButton import android.widget.TextView +import androidx.fragment.app.setFragmentResultListener import androidx.lifecycle.Observer import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.DividerItemDecoration diff --git a/app/src/main/java/com/dp/logcatapp/fragments/settings/SettingsFragment.kt b/app/src/main/java/com/dp/logcatapp/fragments/settings/SettingsFragment.kt index e996262..d0638f0 100644 --- a/app/src/main/java/com/dp/logcatapp/fragments/settings/SettingsFragment.kt +++ b/app/src/main/java/com/dp/logcatapp/fragments/settings/SettingsFragment.kt @@ -50,7 +50,7 @@ class SettingsFragment : PreferenceFragmentCompat() { } private fun setupAppearanceCategory() { - val sharedPrefs = preferenceScreen.sharedPreferences + val sharedPrefs = preferenceScreen.sharedPreferences!! val themePref = findPreference(PreferenceKeys.Appearance.KEY_THEME)!! val useBlackThemePref = findPreference(PreferenceKeys.Appearance.KEY_USE_BLACK_THEME)!! @@ -91,7 +91,7 @@ class SettingsFragment : PreferenceFragmentCompat() { val prefBuffers = findPreference(PreferenceKeys.Logcat.KEY_BUFFERS)!! val prefMaxLogs = findPreference(PreferenceKeys.Logcat.KEY_MAX_LOGS)!! - prefPollInterval.summary = preferenceScreen.sharedPreferences + prefPollInterval.summary = preferenceScreen.sharedPreferences!! .getString( PreferenceKeys.Logcat.KEY_POLL_INTERVAL, PreferenceKeys.Logcat.Default.POLL_INTERVAL @@ -119,7 +119,7 @@ class SettingsFragment : PreferenceFragmentCompat() { val availableBuffers = Logcat.AVAILABLE_BUFFERS val defaultBuffers = PreferenceKeys.Logcat.Default.BUFFERS if (availableBuffers.isNotEmpty() && defaultBuffers.isNotEmpty()) { - val bufferValues = preferenceScreen.sharedPreferences + val bufferValues = preferenceScreen.sharedPreferences!! .getStringSet(PreferenceKeys.Logcat.KEY_BUFFERS, defaultBuffers)!! val toSummary = { values: Set -> @@ -153,7 +153,7 @@ class SettingsFragment : PreferenceFragmentCompat() { prefBuffers.isVisible = false } - val maxLogs = preferenceScreen.sharedPreferences.getString( + val maxLogs = preferenceScreen.sharedPreferences!!.getString( PreferenceKeys.Logcat.KEY_MAX_LOGS, PreferenceKeys.Logcat.Default.MAX_LOGS )!!.trim().toInt() @@ -163,7 +163,7 @@ class SettingsFragment : PreferenceFragmentCompat() { .OnPreferenceChangeListener callback@{ preference, newValue -> val activity = requireActivity() try { - val oldValue = preferenceScreen.sharedPreferences.getString( + val oldValue = preferenceScreen.sharedPreferences!!.getString( PreferenceKeys.Logcat.KEY_MAX_LOGS, PreferenceKeys.Logcat.Default.MAX_LOGS )!!.trim().toInt() @@ -190,8 +190,8 @@ class SettingsFragment : PreferenceFragmentCompat() { } private fun setupSaveLocationOption() { - prefSaveLocation = findPreference(PreferenceKeys.Logcat.KEY_SAVE_LOCATION)!! - val saveLocation = preferenceScreen.sharedPreferences.getString( + prefSaveLocation = findPreference(PreferenceKeys.Logcat.KEY_SAVE_LOCATION)!! + val saveLocation = preferenceScreen.sharedPreferences!!.getString( PreferenceKeys.Logcat.KEY_SAVE_LOCATION, PreferenceKeys.Logcat.Default.SAVE_LOCATION )!!.trim() @@ -250,7 +250,7 @@ class SettingsFragment : PreferenceFragmentCompat() { return } - preferenceScreen.sharedPreferences.edit { + preferenceScreen.sharedPreferences!!.edit { putString(PreferenceKeys.Logcat.KEY_SAVE_LOCATION, file.absolutePath) } prefSaveLocation.summary = "%s/%s".format( @@ -311,12 +311,12 @@ class SettingsFragment : PreferenceFragmentCompat() { SAVE_LOCATION_REQ -> { val uri = data?.data if (uri != null) { - activity!!.contentResolver.takePersistableUriPermission( + requireActivity().contentResolver.takePersistableUriPermission( uri, Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION ) - preferenceScreen.sharedPreferences.edit { + preferenceScreen.sharedPreferences!!.edit { putString( PreferenceKeys.Logcat.KEY_SAVE_LOCATION, uri.toString() @@ -329,7 +329,7 @@ class SettingsFragment : PreferenceFragmentCompat() { } private fun setupDefaultSaveLocation() { - preferenceScreen.sharedPreferences.edit { + preferenceScreen.sharedPreferences!!.edit { putString(PreferenceKeys.Logcat.KEY_SAVE_LOCATION, "") } prefSaveLocation.summary = getString(R.string.save_location_internal) @@ -359,7 +359,7 @@ class SettingsFragment : PreferenceFragmentCompat() { } override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { - return AlertDialog.Builder(activity!!) + return AlertDialog.Builder(requireActivity()) .setTitle(R.string.save_location) .setItems(R.array.save_location_options) { _, which -> if (which == 0) { diff --git a/app/src/main/java/com/dp/logcatapp/fragments/shared/dialogs/FilterExclusionDialogFragment.kt b/app/src/main/java/com/dp/logcatapp/fragments/shared/dialogs/FilterExclusionDialogFragment.kt index d464b96..98491f8 100644 --- a/app/src/main/java/com/dp/logcatapp/fragments/shared/dialogs/FilterExclusionDialogFragment.kt +++ b/app/src/main/java/com/dp/logcatapp/fragments/shared/dialogs/FilterExclusionDialogFragment.kt @@ -9,6 +9,7 @@ import com.dp.logcat.Log import com.dp.logcatapp.R import com.dp.logcatapp.activities.FiltersActivity import com.dp.logcatapp.fragments.base.BaseDialogFragment +import com.dp.logcatapp.util.getParcelableCompat class FilterExclusionDialogFragment : BaseDialogFragment(), DialogInterface.OnClickListener { @@ -42,7 +43,7 @@ class FilterExclusionDialogFragment : BaseDialogFragment(), DialogInterface.OnCl dialog: DialogInterface, which: Int ) { - val log = requireArguments().getParcelable(KEY_LOG)!! + val log = requireArguments().getParcelableCompat(KEY_LOG)!! when (which) { LogContentType.FILTER.ordinal -> moveToFilterActivity(log, false) LogContentType.EXCLUDE.ordinal -> moveToFilterActivity(log, true) diff --git a/app/src/main/java/com/dp/logcatapp/services/LogcatService.kt b/app/src/main/java/com/dp/logcatapp/services/LogcatService.kt index 069d0ba..f8becbe 100644 --- a/app/src/main/java/com/dp/logcatapp/services/LogcatService.kt +++ b/app/src/main/java/com/dp/logcatapp/services/LogcatService.kt @@ -5,11 +5,14 @@ import android.app.Notification import android.app.NotificationChannel import android.app.NotificationManager import android.app.PendingIntent +import android.app.PendingIntent.FLAG_IMMUTABLE +import android.app.PendingIntent.FLAG_UPDATE_CURRENT import android.content.Context import android.content.Intent import android.content.SharedPreferences import android.graphics.BitmapFactory -import android.os.Build +import android.os.Build.VERSION +import android.os.Build.VERSION_CODES import androidx.core.app.NotificationCompat import androidx.core.content.ContextCompat import androidx.core.content.edit @@ -38,7 +41,7 @@ class LogcatService : BaseService() { override fun onCreate() { super.onCreate() - if (Build.VERSION.SDK_INT >= 26) { + if (VERSION.SDK_INT >= 26) { createNotificationChannel() } @@ -76,18 +79,32 @@ class LogcatService : BaseService() { private fun createNotification(addStopRecordingAction: Boolean): Notification { val startIntent = Intent(this, MainActivity::class.java) startIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT) - val contentIntent = PendingIntent.getActivity( - this, 0, startIntent, - PendingIntent.FLAG_UPDATE_CURRENT - ) + val contentIntent = if (VERSION.SDK_INT >= VERSION_CODES.M) { + PendingIntent.getActivity( + this, 0, startIntent, + FLAG_UPDATE_CURRENT or FLAG_IMMUTABLE, + ) + } else { + PendingIntent.getActivity( + this, 0, startIntent, + FLAG_UPDATE_CURRENT, + ) + } val exitIntent = Intent(this, MainActivity::class.java) exitIntent.putExtra(MainActivity.EXIT_EXTRA, true) exitIntent.action = "exit" - val exitPendingIntent = PendingIntent.getActivity( - this, 1, exitIntent, - PendingIntent.FLAG_UPDATE_CURRENT - ) + val exitPendingIntent = if (VERSION.SDK_INT >= VERSION_CODES.M) { + PendingIntent.getActivity( + this, 1, exitIntent, + FLAG_UPDATE_CURRENT or FLAG_IMMUTABLE + ) + } else { + PendingIntent.getActivity( + this, 1, exitIntent, + FLAG_UPDATE_CURRENT + ) + } val exitAction = NotificationCompat.Action.Builder( R.drawable.ic_clear_white_24dp, @@ -112,10 +129,19 @@ class LogcatService : BaseService() { val stopRecordingIntent = Intent(this, MainActivity::class.java) stopRecordingIntent.putExtra(MainActivity.STOP_RECORDING_EXTRA, true) stopRecordingIntent.action = "stop recording" - val stopRecordingPendingIntent = PendingIntent.getActivity( - this, 2, - stopRecordingIntent, PendingIntent.FLAG_UPDATE_CURRENT - ) + val stopRecordingPendingIntent = if (VERSION.SDK_INT >= VERSION_CODES.M) { + PendingIntent.getActivity( + this, 2, + stopRecordingIntent, + FLAG_UPDATE_CURRENT or FLAG_IMMUTABLE + ) + } else { + PendingIntent.getActivity( + this, 2, + stopRecordingIntent, + FLAG_UPDATE_CURRENT, + ) + } val stopRecordingAction = NotificationCompat.Action.Builder( R.drawable.ic_stop_white_24dp, getString(R.string.stop_recording), stopRecordingPendingIntent @@ -125,7 +151,7 @@ class LogcatService : BaseService() { builder.addAction(stopRecordingAction) } - if (Build.VERSION.SDK_INT < 21) { + if (VERSION.SDK_INT < 21) { builder.setLargeIcon(BitmapFactory.decodeResource(resources, R.mipmap.ic_launcher)) } @@ -154,7 +180,7 @@ class LogcatService : BaseService() { super.onDestroy() logcat.close() - if (Build.VERSION.SDK_INT >= 26) { + if (VERSION.SDK_INT >= 26) { deleteNotificationChannel() } } @@ -199,7 +225,8 @@ class LogcatService : BaseService() { showToast(getString(R.string.restarting_logcat)) restartedLogcat = true - logcat.logcatBuffers = bufferValues.map { e -> buffers[e.toInt()].toLowerCase() }.toSet() + logcat.logcatBuffers = + bufferValues.map { e -> buffers[e.toInt()].lowercase(Locale.getDefault()) }.toSet() logcat.restart() } @@ -224,7 +251,7 @@ class LogcatService : BaseService() { val buffers = Logcat.AVAILABLE_BUFFERS logcat.logcatBuffers = bufferValues.mapNotNull { e -> buffers.getOrNull(e.toInt()) - ?.toLowerCase(Locale.getDefault()) + ?.lowercase(Locale.getDefault()) }.toSet().ifEmpty { sharedPreferences.edit { putStringSet( diff --git a/app/src/main/java/com/dp/logcatapp/util/MyExtensions.kt b/app/src/main/java/com/dp/logcatapp/util/MyExtensions.kt index 32704b3..3f5a535 100644 --- a/app/src/main/java/com/dp/logcatapp/util/MyExtensions.kt +++ b/app/src/main/java/com/dp/logcatapp/util/MyExtensions.kt @@ -10,8 +10,10 @@ import android.content.SharedPreferences import android.graphics.Typeface import android.graphics.drawable.Drawable import android.net.Uri -import android.os.Build import android.os.Build.VERSION.SDK_INT +import android.os.Build.VERSION_CODES.TIRAMISU +import android.os.Bundle +import android.os.Parcelable import android.provider.OpenableColumns import android.util.TypedValue import android.view.Display @@ -34,6 +36,7 @@ import java.io.IOException import java.io.InputStream import java.io.OutputStream import java.util.Calendar +import java.util.Locale //// BEGIN Activity @@ -227,7 +230,12 @@ fun Context.getFileNameFromUri(uri: Uri): String { val cursor = contentResolver.query(uri, null, null, null, null) name = cursor?.use { if (it.moveToFirst()) { - it.getString(it.getColumnIndex(OpenableColumns.DISPLAY_NAME)) + val index = it.getColumnIndex(OpenableColumns.DISPLAY_NAME) + if (index != -1) { + it.getString(index) + } else { + null + } } else { null } @@ -257,7 +265,8 @@ fun Context.inflateLayout( //// BEGIN String @SuppressLint("DefaultLocale") -fun String.containsIgnoreCase(other: String) = toLowerCase().contains(other.toLowerCase()) +fun String.containsIgnoreCase(other: String) = + lowercase(Locale.getDefault()).contains(other.lowercase(Locale.getDefault())) //// END String @@ -277,4 +286,13 @@ fun OutputStream.closeQuietly() { } } +inline fun Bundle.getParcelableCompat(key: String): T? { + if (SDK_INT >= TIRAMISU) { + return getParcelable(key, T::class.java) + } else { + @Suppress("DEPRECATION") + return getParcelable(key) + } +} + //// END Misc \ No newline at end of file diff --git a/build.gradle b/build.gradle index 794d6df..b24f0ee 100644 --- a/build.gradle +++ b/build.gradle @@ -1,14 +1,13 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.4.31' + ext.kotlin_version = '1.7.20' repositories { google() mavenCentral() - jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:4.1.2' + classpath 'com.android.tools.build:gradle:7.3.1' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // NOTE: Do not place your application dependencies here; they belong @@ -20,29 +19,29 @@ allprojects { repositories { google() mavenCentral() - jcenter() } } ext { - appcompat_version = "1.2.0" - constraint_layout_version = "2.0.4" - core_ktx_version = "1.3.2" + appcompat_version = "1.5.1" + constraint_layout_version = "2.1.4" + core_ktx_version = "1.9.0" documentfile_version = "1.0.1" - fragment_ktx_version = "1.3.0" - kotlin_coroutines_android_version = "1.3.7" - kotlin_coroutines_core_version = "1.3.7" + fragment_ktx_version = "1.5.5" + kotlin_coroutines_android_version = "1.5.2" + kotlin_coroutines_core_version = "1.5.2" legacy_preference_v14_version = "1.0.0" lifecycle_ext = "2.2.0" - lifecycle_version = "2.3.0" - material_version = "1.3.0" - preference_version = "1.1.1" - room_version = "2.2.6" + lifecycle_version = "2.5.1" + material_version = "1.7.0" + multidex_version = "2.0.1" + preference_version = "1.2.0" + room_version = "2.4.3" // test dependencies junit_version = "4.13.2" - runner_version = "1.3.0" - espresso_core_version = "3.3.0" + runner_version = "1.5.1" + espresso_core_version = "3.5.0" } task clean(type: Delete) { diff --git a/collections/build.gradle b/collections/build.gradle index 86e6105..c7a5590 100644 --- a/collections/build.gradle +++ b/collections/build.gradle @@ -9,8 +9,6 @@ android { defaultConfig { minSdkVersion 16 - versionCode 1 - versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 9d88f67..b3e9a70 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip diff --git a/logcat/build.gradle b/logcat/build.gradle index e94eb35..73416d2 100644 --- a/logcat/build.gradle +++ b/logcat/build.gradle @@ -8,8 +8,6 @@ android { defaultConfig { minSdkVersion 16 - versionCode 1 - versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } diff --git a/logger/build.gradle b/logger/build.gradle index 4c37175..46e59e7 100644 --- a/logger/build.gradle +++ b/logger/build.gradle @@ -7,8 +7,6 @@ android { defaultConfig { minSdkVersion 16 - versionCode 1 - versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" }