From 94fffa486118d423fcf8a748f081de97b8c57dbe Mon Sep 17 00:00:00 2001 From: Kieron Quinn Date: Tue, 14 Feb 2023 22:08:29 +0000 Subject: [PATCH] - Improved adaptive lock screen overlay - Fixed insets on 3 button devices - Allow install on x86_64 devices without libhoudini or libndk --- app/build.gradle | 6 +-- app/release/output-metadata.json | 4 +- app/src/main/AndroidManifest.xml | 1 + .../LockscreenOverlayAccessibilityService.kt | 50 ++++++++++++++----- .../ui/base/BaseContainerFragment.kt | 2 +- .../screens/nowplaying/NowPlayingFragment.kt | 2 +- .../SetupCountryPickerFragment.kt | 2 +- .../setup/datausage/SetupDataUsageFragment.kt | 2 +- .../permissions/SetupPermissionsFragment.kt | 2 +- .../utils/extensions/Extensions+Inset.kt | 16 ++++-- app/src/main/jniLibs/x86_64/libfakelibrary.so | 0 app/src/main/res/xml/accessibilityservice.xml | 2 +- build.gradle | 8 +-- gradle/wrapper/gradle-wrapper.properties | 6 +-- 14 files changed, 69 insertions(+), 34 deletions(-) create mode 100644 app/src/main/jniLibs/x86_64/libfakelibrary.so diff --git a/app/build.gradle b/app/build.gradle index 8ba94a8..322709a 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -11,10 +11,10 @@ plugins { apply plugin: 'com.google.android.gms.oss-licenses-plugin' -String DEFAULT_MANIFEST = "242:https://storage.googleapis.com/music-iq-db/updatable_ytm_db/20230129-030041/manifest.json" +String DEFAULT_MANIFEST = "243:https://storage.googleapis.com/music-iq-db/updatable_ytm_db/20230212-030106/manifest.json" -def tagName = '2.1' -def version = 210 +def tagName = '2.1.1' +def version = 211 def getKeystoreProperties() { def properties = new Properties() diff --git a/app/release/output-metadata.json b/app/release/output-metadata.json index 822e92c..b28b7bd 100644 --- a/app/release/output-metadata.json +++ b/app/release/output-metadata.json @@ -11,8 +11,8 @@ "type": "SINGLE", "filters": [], "attributes": [], - "versionCode": 210, - "versionName": "2.1", + "versionCode": 211, + "versionName": "2.1.1", "outputFile": "app-release.apk" } ], diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index e90a2e5..1aaf9fd 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,5 +1,6 @@ () private val accessibility by inject() - private val accessibilityWindow = MutableStateFlow(null) + private val accessibilityWindowName = MutableStateFlow(null) + private val accessibilityWindowPackage = MutableStateFlow(null) private val lockscreenOverlayState = MutableStateFlow(null) private var currentBinding: OverlayBinding? = null @@ -98,12 +100,13 @@ class LockscreenOverlayAccessibilityService : LifecycleAccessibilityService() { */ private val accessibilityWindowIsLockscreen = combine( settings.lockscreenOverlayEnhanced.asFlow(), - accessibilityWindow, + accessibilityWindowName, + accessibilityWindowPackage, systemUiPackage, lockScreenText - ) { enhanced, window, systemui, lockscreen -> + ) { enhanced, windowName, windowPackage, systemui, lockscreen -> if(!enhanced) return@combine true - window?.packageName == systemui && window.windowName == lockscreen + windowPackage == systemui && windowName == lockscreen } private val overlayState by lazy { @@ -191,14 +194,37 @@ class LockscreenOverlayAccessibilityService : LifecycleAccessibilityService() { } override fun onAccessibilityEvent(event: AccessibilityEvent) { - if(event.packageName == BuildConfig.APPLICATION_ID) return //Prevent self-triggers + //Prevent self-trigger when adding overlay + if(event == null || event.packageName == BuildConfig.APPLICATION_ID) return + when (event.eventType) { + AccessibilityEvent.TYPE_WINDOWS_CHANGED -> { + onWindowsChange(event) + } + AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED -> { + onWindowStateChange(event) + } + } + } + + private fun onWindowsChange(event: AccessibilityEvent) { + //Get the window responsible for this change + val window = windows.firstOrNull { it.id == event.windowId } ?: return + //Get the package of the app responsible for adding the window + val packageName = window.root?.packageName ?: return + if(packageName == BuildConfig.APPLICATION_ID) return //Prevent self-trigger + //We only care if a window is being added + if(event.windowChanges == AccessibilityEvent.WINDOWS_CHANGE_ADDED){ + lifecycleScope.launchWhenCreated { + accessibilityWindowPackage.emit(packageName.toString()) + } + } + } + + private fun onWindowStateChange(event: AccessibilityEvent) { + if(event.contentChangeTypes == AccessibilityEvent.CONTENT_CHANGE_TYPE_PANE_DISAPPEARED) + return //Prevent triggering for disappearing windows lifecycleScope.launchWhenCreated { - accessibilityWindow.emit( - AccessibilityWindow( - event.packageName?.toString() ?: return@launchWhenCreated, - event.text?.firstOrNull() ?: return@launchWhenCreated - ) - ) + accessibilityWindowName.emit(event.text?.firstOrNull() ?: return@launchWhenCreated) } } @@ -389,6 +415,4 @@ class LockscreenOverlayAccessibilityService : LifecycleAccessibilityService() { return System.currentTimeMillis() < endTime } - private data class AccessibilityWindow(val packageName: String, val windowName: CharSequence?) - } \ No newline at end of file diff --git a/app/src/main/java/com/kieronquinn/app/ambientmusicmod/ui/base/BaseContainerFragment.kt b/app/src/main/java/com/kieronquinn/app/ambientmusicmod/ui/base/BaseContainerFragment.kt index bbd4445..2ea7280 100644 --- a/app/src/main/java/com/kieronquinn/app/ambientmusicmod/ui/base/BaseContainerFragment.kt +++ b/app/src/main/java/com/kieronquinn/app/ambientmusicmod/ui/base/BaseContainerFragment.kt @@ -88,7 +88,7 @@ abstract class BaseContainerFragment(inflate: (LayoutInflater, V } private fun BottomNavigationView.setupBottomNavigation() { - val legacyWorkaround = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) { + val legacyWorkaround = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) { context.getLegacyWorkaroundNavBarHeight() } else 0 onApplyInsets { view, insets -> diff --git a/app/src/main/java/com/kieronquinn/app/ambientmusicmod/ui/screens/nowplaying/NowPlayingFragment.kt b/app/src/main/java/com/kieronquinn/app/ambientmusicmod/ui/screens/nowplaying/NowPlayingFragment.kt index f09e2f7..b57c236 100644 --- a/app/src/main/java/com/kieronquinn/app/ambientmusicmod/ui/screens/nowplaying/NowPlayingFragment.kt +++ b/app/src/main/java/com/kieronquinn/app/ambientmusicmod/ui/screens/nowplaying/NowPlayingFragment.kt @@ -78,7 +78,7 @@ class NowPlayingFragment: BoundFragment(FragmentNowPl private fun setupFab() = with(binding.fabNowplayingRecognise){ backgroundTintList = ColorStateList.valueOf(monet.getPrimaryColor(context)) - val legacyWorkaround = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) { + val legacyWorkaround = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) { context.getLegacyWorkaroundNavBarHeight() } else 0 onApplyInsets { _, insets -> diff --git a/app/src/main/java/com/kieronquinn/app/ambientmusicmod/ui/screens/setup/countrypicker/SetupCountryPickerFragment.kt b/app/src/main/java/com/kieronquinn/app/ambientmusicmod/ui/screens/setup/countrypicker/SetupCountryPickerFragment.kt index 5d5c4b9..a3fb3cd 100644 --- a/app/src/main/java/com/kieronquinn/app/ambientmusicmod/ui/screens/setup/countrypicker/SetupCountryPickerFragment.kt +++ b/app/src/main/java/com/kieronquinn/app/ambientmusicmod/ui/screens/setup/countrypicker/SetupCountryPickerFragment.kt @@ -60,7 +60,7 @@ class SetupCountryPickerFragment: BoundFragment diff --git a/app/src/main/java/com/kieronquinn/app/ambientmusicmod/ui/screens/setup/datausage/SetupDataUsageFragment.kt b/app/src/main/java/com/kieronquinn/app/ambientmusicmod/ui/screens/setup/datausage/SetupDataUsageFragment.kt index 92837d5..4c94912 100644 --- a/app/src/main/java/com/kieronquinn/app/ambientmusicmod/ui/screens/setup/datausage/SetupDataUsageFragment.kt +++ b/app/src/main/java/com/kieronquinn/app/ambientmusicmod/ui/screens/setup/datausage/SetupDataUsageFragment.kt @@ -113,7 +113,7 @@ class SetupDataUsageFragment: BoundFragment(Fragm private fun setupInsets() { val standardPadding = resources.getDimension(R.dimen.margin_16).toInt() - val legacyWorkaround = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) { + val legacyWorkaround = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) { requireContext().getLegacyWorkaroundNavBarHeight() } else 0 binding.setupDataUsageControls.onApplyInsets { view, insets -> diff --git a/app/src/main/java/com/kieronquinn/app/ambientmusicmod/ui/screens/setup/permissions/SetupPermissionsFragment.kt b/app/src/main/java/com/kieronquinn/app/ambientmusicmod/ui/screens/setup/permissions/SetupPermissionsFragment.kt index b036882..88ea4eb 100644 --- a/app/src/main/java/com/kieronquinn/app/ambientmusicmod/ui/screens/setup/permissions/SetupPermissionsFragment.kt +++ b/app/src/main/java/com/kieronquinn/app/ambientmusicmod/ui/screens/setup/permissions/SetupPermissionsFragment.kt @@ -50,7 +50,7 @@ class SetupPermissionsFragment: BoundFragment(F private fun setupInsets() { val standardPadding = resources.getDimension(R.dimen.margin_16).toInt() - val legacyWorkaround = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) { + val legacyWorkaround = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) { requireContext().getLegacyWorkaroundNavBarHeight() } else 0 binding.setupPermissionsControls.onApplyInsets { view, insets -> diff --git a/app/src/main/java/com/kieronquinn/app/ambientmusicmod/utils/extensions/Extensions+Inset.kt b/app/src/main/java/com/kieronquinn/app/ambientmusicmod/utils/extensions/Extensions+Inset.kt index fc90c91..e623f1e 100644 --- a/app/src/main/java/com/kieronquinn/app/ambientmusicmod/utils/extensions/Extensions+Inset.kt +++ b/app/src/main/java/com/kieronquinn/app/ambientmusicmod/utils/extensions/Extensions+Inset.kt @@ -1,6 +1,7 @@ package com.kieronquinn.app.ambientmusicmod.utils.extensions import android.content.Context +import android.os.Build import android.view.View import android.view.ViewGroup import androidx.core.view.* @@ -16,18 +17,24 @@ fun View.onApplyInsets(block: (view: View, insets: WindowInsetsCompat) -> Unit) fun View.applyBottomNavigationInset(extraPadding: Float = 0f) { val bottomNavHeight = resources.getDimension(R.dimen.bottom_nav_height).toInt() updatePadding(bottom = bottomNavHeight + extraPadding.toInt()) + val legacyWorkaround = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) { + context.getLegacyWorkaroundNavBarHeight() + } else 0 onApplyInsets { _, insets -> val bottomInsets = insets.getInsets(WindowInsetsCompat.Type.systemBars() - or WindowInsetsCompat.Type.ime()).bottom + context.getLegacyWorkaroundNavBarHeight() + or WindowInsetsCompat.Type.ime()).bottom + legacyWorkaround updatePadding(bottom = bottomInsets + bottomNavHeight + extraPadding.toInt()) } } fun View.applyBottomNavigationMargin(extraPadding: Float = 0f) { val bottomNavHeight = resources.getDimension(R.dimen.bottom_nav_height_margins).toInt() + val legacyWorkaround = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) { + context.getLegacyWorkaroundNavBarHeight() + } else 0 onApplyInsets { _, insets -> val bottomInsets = insets.getInsets(WindowInsetsCompat.Type.systemBars()).bottom + - context.getLegacyWorkaroundNavBarHeight() + legacyWorkaround updateLayoutParams { updateMargins(bottom = bottomInsets + bottomNavHeight + extraPadding.toInt()) } @@ -36,9 +43,12 @@ fun View.applyBottomNavigationMargin(extraPadding: Float = 0f) { fun View.applyBottomNavigationMarginShort(extraPadding: Float = 0f) { val bottomNavHeight = resources.getDimension(R.dimen.bottom_nav_height).toInt() + val legacyWorkaround = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) { + context.getLegacyWorkaroundNavBarHeight() + } else 0 onApplyInsets { _, insets -> val bottomInsets = insets.getInsets(WindowInsetsCompat.Type.systemBars()).bottom + - context.getLegacyWorkaroundNavBarHeight() + legacyWorkaround updateLayoutParams { updateMargins(bottom = bottomInsets + bottomNavHeight + extraPadding.toInt()) } diff --git a/app/src/main/jniLibs/x86_64/libfakelibrary.so b/app/src/main/jniLibs/x86_64/libfakelibrary.so new file mode 100644 index 0000000..e69de29 diff --git a/app/src/main/res/xml/accessibilityservice.xml b/app/src/main/res/xml/accessibilityservice.xml index 5260976..d6c9ca8 100644 --- a/app/src/main/res/xml/accessibilityservice.xml +++ b/app/src/main/res/xml/accessibilityservice.xml @@ -3,6 +3,6 @@ android:accessibilityFeedbackType="feedbackGeneric" android:accessibilityFlags="flagDefault|flagRetrieveInteractiveWindows" android:canRetrieveWindowContent="true" - android:accessibilityEventTypes="typeWindowStateChanged" + android:accessibilityEventTypes="typeWindowStateChanged|typeWindowsChanged" android:settingsActivity="com.kieronquinn.app.ambientmusicmod.app.activities.MainActivity" android:description="@string/accessibility_service_description" /> \ No newline at end of file diff --git a/build.gradle b/build.gradle index 7af14d9..12f06e9 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ buildscript { ext.nav_version = "2.5.3" ext.protobufVersion = '0.8.17' ext.shizuku_version = '12.1.0' - ext.refine_version = '3.1.1' + ext.refine_version = '4.1.0' repositories { google() } @@ -16,11 +16,11 @@ buildscript { } plugins { - id 'com.android.application' version '7.1.3' apply false - id 'com.android.library' version '7.1.3' apply false + id 'com.android.application' version '7.4.1' apply false + id 'com.android.library' version '7.4.1' apply false id 'org.jetbrains.kotlin.android' version '1.6.21' apply false id 'com.google.dagger.hilt.android' version '2.41' apply false - id 'dev.rikka.tools.refine' version '3.1.1' apply false + id 'dev.rikka.tools.refine' version '4.1.0' apply false } task clean(type: Delete) { diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 78685ec..178b200 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Sun May 01 18:14:37 BST 2022 +#Tue Feb 14 21:49:42 GMT 2023 distributionBase=GRADLE_USER_HOME -distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip distributionPath=wrapper/dists -zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists