在果冻豆READ_LOGS许可(API 16) [英] READ_LOGS permission on Jelly Bean (api 16)

查看:146
本文介绍了在果冻豆READ_LOGS许可(API 16)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于机器人糖豆不支持日志读取权限的(根据这个谷歌IO 2012视频和的这一个了),我想知道这是否是可能的根设备(或无根的设备)能够绕过这个限制,并且能够读取日志。

Since Android Jelly Bean doesn't support the logs reading permission (according to this google io 2012 video and this one too ) , i would like to know if it's possible for rooted devices (or non-rooted devices) to be able to bypass this restriction and be able to read the logs.

我该怎么办呢?我真的需要使应用系统的应用程序,或者是发根就够了吗?

How do i do that? Do i really need to make the app a system app, or is rooting enough?

推荐答案

您可以从您的应用程序执行时grant命令获取root权限的设备上的权限。也许你将不得不后重新启动应用程序以使更改生效,但:

You can obtain the permission on a rooted device by executing the pm grant command from your app. Probably you will have to restart the app after that for the change to take effect, though:

String pname = getPackageName();
String[] CMDLINE_GRANTPERMS = { "su", "-c", null };
if (getPackageManager().checkPermission(android.Manifest.permission.READ_LOGS, pname) != 0) {
    Log.d(TAG, "we do not have the READ_LOGS permission!");
    if (android.os.Build.VERSION.SDK_INT >= 16) {
        Log.d(TAG, "Working around JellyBeans 'feature'...");
        try {
            // format the commandline parameter
            CMDLINE_GRANTPERMS[2] = String.format("pm grant %s android.permission.READ_LOGS", pname);
            java.lang.Process p = Runtime.getRuntime().exec(CMDLINE_GRANTPERMS);
            int res = p.waitFor();
            Log.d(TAG, "exec returned: " + res);
            if (res != 0)
                throw new Exception("failed to become root");
        } catch (Exception e) {
            Log.d(TAG, "exec(): " + e);
            Toast.makeText(context, "Failed to obtain READ_LOGS permission", Toast.LENGTH_LONG).show();
        }
    }
} else
    Log.d(TAG, "we have the READ_LOGS permission already!");

这code应该从你的onCreate称为()。一旦授予权限,没有更多的root权限是必需的。

This code should be called from your onCreate(). Once the permission is granted, no more root powers are required.

PS:本p.waitFor()上的超级用户的应用程序块,拖延你的应用程序启动并有可能导致ANR

P.S: The p.waitFor() blocks on the Superuser app, delaying your app start and potentially cause an ANR.

这篇关于在果冻豆READ_LOGS许可(API 16)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆