Skip to content

Commit

Permalink
Use accessibilityService.clearCache()
Browse files Browse the repository at this point in the history
  • Loading branch information
KazuCocoa committed Dec 29, 2023
1 parent 1f82a42 commit be1d5e7
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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
Expand Down

0 comments on commit be1d5e7

Please sign in to comment.