From edd20a44e88a489b1fa401091c2948ff43575edd Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Mon, 25 Dec 2023 12:30:54 -0800 Subject: [PATCH 1/4] feat: bump targetSdkVersion to 31 --- app/build.gradle | 4 ++-- app/src/main/AndroidManifest.xml | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 3aa5e4c71..c832a41e8 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -14,11 +14,11 @@ apply plugin: 'com.android.application' apply plugin: 'de.mobilej.unmock' android { - compileSdk 30 + compileSdk 31 defaultConfig { applicationId 'io.appium.uiautomator2' minSdkVersion 21 - targetSdkVersion 30 + targetSdkVersion 31 versionCode 145 archivesBaseName = 'appium-uiautomator2' /** diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 7587d5c77..e08d7618d 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -13,7 +13,9 @@ - + + From fa873ad9dc8806724cf6180b3a84fad61d880f3a Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Mon, 25 Dec 2023 13:18:34 -0800 Subject: [PATCH 2/4] bump to 32 as no diffs --- app/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index c832a41e8..46e39eb07 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -14,11 +14,11 @@ apply plugin: 'com.android.application' apply plugin: 'de.mobilej.unmock' android { - compileSdk 31 + compileSdk 32 defaultConfig { applicationId 'io.appium.uiautomator2' minSdkVersion 21 - targetSdkVersion 31 + targetSdkVersion 32 versionCode 145 archivesBaseName = 'appium-uiautomator2' /** From 432516d62464ba93087005fdef876686a282e9eb Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Mon, 25 Dec 2023 21:11:57 -0800 Subject: [PATCH 3/4] feat: use targetSdkVersion 33 --- app/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 46e39eb07..60393c609 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -14,11 +14,11 @@ apply plugin: 'com.android.application' apply plugin: 'de.mobilej.unmock' android { - compileSdk 32 + compileSdk 33 defaultConfig { applicationId 'io.appium.uiautomator2' minSdkVersion 21 - targetSdkVersion 32 + targetSdkVersion 33 versionCode 145 archivesBaseName = 'appium-uiautomator2' /** From be1d5e7f9918170db6a11e280d4d891ed41208ab Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Fri, 29 Dec 2023 01:29:50 -0800 Subject: [PATCH 4/4] Use accessibilityService.clearCache() --- .../appium/uiautomator2/utils/AXWindowHelpers.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/appium/uiautomator2/utils/AXWindowHelpers.java b/app/src/main/java/io/appium/uiautomator2/utils/AXWindowHelpers.java index a5fff017a..04b7168a5 100644 --- a/app/src/main/java/io/appium/uiautomator2/utils/AXWindowHelpers.java +++ b/app/src/main/java/io/appium/uiautomator2/utils/AXWindowHelpers.java @@ -16,6 +16,7 @@ package io.appium.uiautomator2.utils; +import android.accessibilityservice.AccessibilityService; import android.os.Build; import android.os.SystemClock; import android.view.accessibility.AccessibilityNodeInfo; @@ -28,6 +29,9 @@ import java.util.Objects; import static androidx.test.internal.util.Checks.checkNotNull; + +import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation; + import io.appium.uiautomator2.common.exceptions.UiAutomator2Exception; import io.appium.uiautomator2.core.UiAutomatorBridge; import io.appium.uiautomator2.model.internal.CustomUiDevice; @@ -47,8 +51,13 @@ public class AXWindowHelpers { */ private static void clearAccessibilityCache() { try { - // This call invokes `AccessibilityInteractionClient.getInstance().clearCache();` method - UiAutomatorBridge.getInstance().getUiAutomation().setServiceInfo(null); + if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + AccessibilityService accessibilityService = getInstrumentation().getContext().getSystemService(AccessibilityService.class); + accessibilityService.clearCache(); + } else { + // This call invokes `AccessibilityInteractionClient.getInstance().clearCache();` method + UiAutomatorBridge.getInstance().getUiAutomation().setServiceInfo(null); + } } catch (NullPointerException npe) { // it is fine // ignore