This demo uses the same sample as Sensitive Views Without Accessibility Data Sensitivity. The app creates a login and payment form with views that handle sensitive data, each using a different accessibility data sensitivity configuration:
Username field: isn't marked as accessibility data sensitive.
Password field: is explicitly marked as accessibility data sensitive.
One-time code field: sets filterTouchesWhenObscured, which implies accessibility data sensitivity.
Payment container: a LinearLayout that is explicitly marked as accessibility data sensitive using setAccessibilityDataSensitive(View.ACCESSIBILITY_DATA_SENSITIVE_YES). It contains two views:
Card number field: keeps the default value, ACCESSIBILITY_DATA_SENSITIVE_AUTO, so it inherits the protection from the payment container.
Confirm Payment button: explicitly disables the protection using setAccessibilityDataSensitive(View.ACCESSIBILITY_DATA_SENSITIVE_NO), which overrides the value inherited from the payment container.
Cancel button: is outside the payment container and keeps the default value, ACCESSIBILITY_DATA_SENSITIVE_AUTO. It doesn't handle sensitive data, so it isn't protected.
Marking a view as accessibility data sensitive only restricts accessibility services that aren't declared as accessibility tools. Accessibility tools, such as screen readers, can still read and interact with all of these views (see "Accessibility Tools" in Accessibility Data Sensitivity).
Install the app on a device running Android 14 (API level 34) or higher ( Installing Apps).
Make sure you have Frida (Android) installed on your machine and the frida-server running on the device.
Run run.sh to spawn the app with Frida. The script uses Method Hooking to hook the relevant API calls.
Tap the Start button.
Use Inspecting the UI Hierarchy to obtain the view hierarchy of the screen. The script does this automatically shortly after the app changes the hooked settings. On other screens, call dumpViews() from the Frida REPL.
Stop the script by pressing Ctrl+C and/or q to quit the Frida CLI.
1234
#!/bin/bash# Spawn the app with Frida, hook the accessibility data sensitivity setters, and dump the view hierarchy
frida-U-forg.owasp.mastestapp-l./script.js-ooutput.txt
// Hooks the View setters that configure accessibility data sensitivity and dumps the view hierarchy of the// foreground activity with the effective isAccessibilityDataSensitive() value of each view.// The dump runs automatically shortly after the app changes these settings. You can also call dumpViews()// from the Frida REPL at any time, for example, after navigating to another screen that handles sensitive data.constSENSITIVITY_MODES={0:"AUTO",1:"YES",2:"NO"};constBACKTRACE_LINES=6;constDUMP_DELAY_MS=1500;letpendingDump=null;functionbacktrace(){constLog=Java.use("android.util.Log");constException=Java.use("java.lang.Exception");constlines=Log.getStackTraceString(Exception.$new()).split("\n").slice(1,1+BACKTRACE_LINES);returnlines.map(line=>" "+line.trim()).join("\n");}functiondescribe(view){constTextView=Java.use("android.widget.TextView");constEditText=Java.use("android.widget.EditText");letdescription=view.getClass().getName();constid=view.getId();if(id!==-1){try{description+=` id=${view.getResources().getResourceEntryName(id)}`;}catch(e){// The view uses a generated ID without a resource entry.}}if(TextView.class.isInstance(view)){consttextView=Java.cast(view,TextView);consthint=textView.getHint();if(hint!==null){description+=` hint="${hint.toString()}"`;}// Don't print the content of input fields to avoid logging sensitive data.if(!EditText.class.isInstance(view)){consttext=textView.getText();if(text!==null&&text.length()>0){description+=` text="${text.toString()}"`;}}}returndescription;}functionwalk(view,depth,lines){constViewGroup=Java.use("android.view.ViewGroup");lines.push(`${" ".repeat(depth)}${describe(view)}`+` isAccessibilityDataSensitive=${view.isAccessibilityDataSensitive()}`+` filterTouchesWhenObscured=${view.getFilterTouchesWhenObscured()}`);if(ViewGroup.class.isInstance(view)){constgroup=Java.cast(view,ViewGroup);for(leti=0;i<group.getChildCount();i++){walk(group.getChildAt(i),depth+1,lines);}}}functiondumpViews(){Java.perform(()=>{Java.scheduleOnMainThread(()=>{Java.choose("android.app.Activity",{onMatch(activity){if(activity.isFinishing()||activity.isDestroyed()||!activity.hasWindowFocus()){return;}constlines=[];walk(activity.getWindow().getDecorView(),0,lines);console.log(`\n[*] View hierarchy of ${activity.getClass().getName()}:`);console.log(lines.join("\n"));},onComplete(){console.log("\n[*] Finished dumping the view hierarchy.");}});});});}functionscheduleDump(){if(pendingDump!==null){clearTimeout(pendingDump);}pendingDump=setTimeout(()=>{pendingDump=null;dumpViews();},DUMP_DELAY_MS);}globalThis.dumpViews=dumpViews;Java.perform(()=>{constView=Java.use("android.view.View");if(View.setAccessibilityDataSensitive===undefined||View.isAccessibilityDataSensitive===undefined){console.log("[-] Accessibility data sensitivity APIs aren't available. Use a device running Android 14 (API level 34) or higher.");return;}View.setAccessibilityDataSensitive.implementation=function(mode){console.log(`\n[setAccessibilityDataSensitive] ${describe(this)} mode=${SENSITIVITY_MODES[mode]??mode}`);console.log(backtrace());this.setAccessibilityDataSensitive(mode);scheduleDump();};View.setFilterTouchesWhenObscured.implementation=function(enabled){console.log(`\n[setFilterTouchesWhenObscured] ${describe(this)} enabled=${enabled}`);console.log(backtrace());this.setFilterTouchesWhenObscured(enabled);scheduleDump();};console.log("[*] Hooks installed. Tap Start, or call dumpViews() to dump the current screen.");});
The Frida script covers both techniques:
Hooks ( Method Hooking): it hooks setAccessibilityDataSensitive and setFilterTouchesWhenObscured and prints the arguments and a backtrace for each call.
View hierarchy ( Inspecting the UI Hierarchy): its dumpViews() function enumerates the views of the foreground activity and prints the effective value returned by isAccessibilityDataSensitive for each view, which includes the protection inherited from parent views and implied by filterTouchesWhenObscured.
The output shows the calls to the hooked setters, including their arguments and backtraces, followed by the view hierarchy of the screen with the effective accessibility data sensitivity of each view.
The hooks capture four calls from MastgTest.mastgTest: setAccessibilityDataSensitive with the YES mode on the Password field (MastgTest.kt:53) and on the payment container, a LinearLayout (MastgTest.kt:65), setFilterTouchesWhenObscured(true) on the One-time code field (MastgTest.kt:58), and setAccessibilityDataSensitive with the NO mode on the Confirm Payment button (MastgTest.kt:75).
The view hierarchy shows the form at the end of the content frame. The Username field and the Confirm Payment button return isAccessibilityDataSensitive=false, while the Password, One-time code, and Card number fields return true.
The screenshot shows the screen with the form at the bottom:
It also shows which views display or accept sensitive data: the Username, Password, One-time code, and Card number fields, and the Confirm Payment button. The Cancel button doesn't handle sensitive data.
The test case fails because two views that handle sensitive data return false from isAccessibilityDataSensitive:
The Username field doesn't call any of the hooked setters, and the view hierarchy confirms it isn't protected.
The Confirm Payment button explicitly disables the protection with setAccessibilityDataSensitive and the NO mode, as shown in the hook output and its backtrace (MastgTest.kt:75), even though the payment container is marked as accessibility data sensitive.
The Password, One-time code, and Card number fields return true. The card number field doesn't call any of the hooked setters, but the view hierarchy shows that it inherits the protection from the payment container. Only the enumeration of the view hierarchy reveals this inherited protection, and the unprotected username field, because neither involves a call to the hooked setters.