Using uiautomator1.0 for Android Automation: Shell Context, PackageManager, Database, Activity & Process Monitoring, and Chinese Input Support
This article demonstrates how to leverage uiautomator1.0 for Android automation by creating a shell‑based Context, accessing PackageManager, managing SQLite databases, monitoring app activities and processes, and implementing Chinese text input through AccessibilityNodeInfo.
This article, based on uiautomator1.0 test scripts, introduces practical automation testing techniques for Android, covering how to obtain a Context, launch apps by package name, use databases, monitor app runtime, and enable Chinese input support.
Shell Process Context Applications started via shell cannot directly obtain a Context, but an Android service‑dependent Context can be created by invoking ActivityThread.systemMain() . The resulting Context allows use of services such as PackageManager, ActivityManager, and SQLite, although dynamic permissions and app‑specific permissions cannot be accessed.
PackageManager Usage With the obtained Context, PackageManager can retrieve information about installed applications and the launch Intent for each app.
Database Application Database operations follow the same pattern as regular apps: create a class extending SQLiteOpenHelper , implement creation and upgrade logic, and ensure the database name uses an absolute path while the Context is non‑null.
Monitoring Current App Activity To collect activity display information, duration, crashes, ANR, and system ANR, implement the IActivityController.Stub interface and register it via ActivityManager#setActivityController . The callback methods allow tracking of activity switches, crashes, and ANR events.
App Process Monitoring When an app spawns multiple PIDs, ProcessObserver can be used to track process lifecycles. By correlating UID with the app, one can monitor process changes for a specific application.
Chinese Input Support in uiautomator1.0 Although uiautomator2.0 natively supports Chinese input, uiautomator1.0 does not. The article provides a workaround using AccessibilityNodeInfo to input Chinese characters on lower‑version Android devices.
360 Quality & Efficiency
360 Quality & Efficiency focuses on seamlessly integrating quality and efficiency in R&D, sharing 360’s internal best practices with industry peers to foster collaboration among Chinese enterprises and drive greater efficiency value.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.