我想测试一个应用程序是否可以获得ignore其他应用程序的READ_SMS许可,主要活动的源代码是
...
ShellExecuter se = new ShellExecuter();
...
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_applist);
ignPermission("com.vrs.smsapp", "READ_SMS");
}
private void ignPermission(String pkg, String perm) {
String cmd = "appops set " + pkg + " " + perm + " ignore";
String res = se.Execute(cmd);
Log.d(LOGTAG, "cmd: " + cmd + ", res: " + res);
}
Run Code Online (Sandbox Code Playgroud)
和类的代码ShellExecuter:
public class ShellExecuter {
public String Execute(String cmd) {
StringBuffer output = new StringBuffer();
Process p;
try {
p = Runtime.getRuntime().exec(cmd);
p.waitFor();
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = "";
while ((line = reader.readLine()) != null) {
output.append(line + "\n");
}
} catch (Exception e){
e.printStackTrace();
}
String response = output.toString();
return response;
}
}
Run Code Online (Sandbox Code Playgroud)
日志文件将是
cmd:appops设置com.vrs.smsapp READ_SMS忽略,资源:
但是,运行此应用程序后,权限仍然存在:
$ adb shell appops get com.vrs.smsapp
READ_SMS: allow; time=+30s557ms ago
READ_ICC_SMS: allow; time=+30s557ms ago
READ_EXTERNAL_STORAGE: allow; time=+1m9s309ms ago
WRITE_EXTERNAL_STORAGE: allow; time=+1m9s309ms ago
Run Code Online (Sandbox Code Playgroud)
如果我在 macbook 的终端中运行命令,它会成功:
$ adb shell appops set com.vrs.smsapp READ_SMS ignore
$ adb shell appops get com.vrs.smsapp
READ_SMS: ignore; time=+20m38s355ms ago
READ_ICC_SMS: allow; time=+20m38s355ms ago; rejectTime=+13m11s708ms ago
READ_EXTERNAL_STORAGE: allow; time=+13m14s688ms ago
WRITE_EXTERNAL_STORAGE: allow; time=+13m14s688ms ago
Run Code Online (Sandbox Code Playgroud)
我想知道如何更改我的程序来控制其他应用程序的权限。
| 归档时间: |
|
| 查看次数: |
4769 次 |
| 最近记录: |