Uiautomator

来源:互联网 发布:特种兵知乎 编辑:程序博客网 时间:2024/05/16 14:35

Uiautomator - settings


settings 是Android 4.2 之后引进的一个系统工具,其具体作用是可以方便的获取设置设备变量,不需要Root权限,堪比一个比较BUG的存在,许多手机助手或者管家都利用它来获取额外的权限对设备进行操作,对于测试人员来说非常便利。

Settings中的值,大体有以下几种,也非常容易使用。

enable or disable: 使用1. 0 来区分 enable, disble.

mode: 使用int 值来表示不同的模式,具体模式可以在常量定义中找到。

String:使用String来记录串值及URI.


如下代码所示:

adb shell settings put global airplane_mode_on 1

adb shell settings put global airplane_mode_on 0

adb shell settings get global auto_time // 是否自动同步网络时间

adb shell settings get global wifi_on // wifi是否打开

adb shell settings get system next_alarm_formatted //获取下一次闹钟


Android 4.2之后的源码android-19\com\android\commands\ 目录下SettingsCmd.java文件,

 private static void printUsage() {        System.err.println("usage:  settings [--user NUM] get namespace key");        System.err.println("        settings [--user NUM] put namespace key value");        System.err.println("\n'namespace' is one of {system, secure, global}, case-insensitive");        System.err.println("If '--user NUM' is not given, the operations are performed on the owner user.");    }

Key 的查询可以从网页

http://developer.android.com/reference/android/provider/Settings.System.html

https://developer.android.com/reference/android/provider/Settings.Global.html

https://developer.android.com/reference/android/provider/Settings.Secure.html


 
原创粉丝点击