简体   繁体   English

如何为android shell用户授予更多权限?

[英]How to grant more permissions to android shell user?

I build some command line tool with ndk and execute it in /data/local/tmp. 我用ndk构建了一些命令行工具,并在/ data / local / tmp中执行它。 Now it prompts me "requires android.permission.RECORD_AUDIO" when I call some OpenSLES API in my command line tool: 现在,当我在命令行工具中调用一些OpenSLES API时,它会提示我“需要android.permission.RECORD_AUDIO”:

W/AudioRecord( 4226): AUDIO_INPUT_FLAG_FAST denied by client
W/ServiceManager(  207): Permission failure: android.permission.RECORD_AUDIO from uid=2000 pid=4226
E/        (  207): Request requires android.permission.RECORD_AUDIO
D/PowerManagerService(  964): handleSandman: canDream=false, mWakefulness=Asleep
E/AudioFlinger(  207): openRecord() permission denied: recording not allowed
E/AudioRecord( 4226): AudioFlinger could not create record track, status: -1
E/libOpenSLES( 4226): android_audioRecorder_realize(0x453430) error creating AudioRecord object
W/libOpenSLES( 4226): Leaving Object::Realize (SL_RESULT_CONTENT_UNSUPPORTED)

I have also tried to grant shell with pm grant: 我也尝试用pm授予shell:

pm grant "com.android.shell" android.permission.RECORD_AUDIO
pm grant "com.android.shell" android.permission.RECORD_AUDIO
pm grant "com.android.shell" android.permission.RECORD_AUDIO
Operation not allowed: java.lang.SecurityException: Package com.android.shell has not requested permission android.permission.RECORD_AUDIO

changing /system/etc/permissions/platform.xml has no effect too. 更改/system/etc/permissions/platform.xml也没有效果。

Can I just debug my OpenSLES demo in the android shell ? 我可以在android shell中调试我的OpenSLES演示吗? How can I get more permisson just in shell . 如何在shell中获得更多权限。

Must I create a jni and java project for every experimental code snippet and modify them together when I change some C++ interfaces ? 我必须为每个实验代码片段创建一个jni和java项目,并在更改某些C ++接口时将它们一起修改吗?

Can I access RECORD_AUDIO, CAMERA directly in a command tool from shell ? 我可以直接在shell的命令工具中访问RECORD_AUDIO,CAMERA吗?

This is the new permissions model in Android Marshmallow in action. 这是Android Marshmallow中的新权限模型 To get this permission you'll need to prompt the user to grant it. 要获得此权限,您需要提示用户授予权限。 Here's what I do: 这是我做的:

  1. Whenever I need RECORD_AUDIO permission I run a check to see if I have it: 每当我需要RECORD_AUDIO权限时,我都会检查是否有它:

     private boolean hasRecordAudioPermission(){ boolean hasPermission = (ContextCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO) == PackageManager.PERMISSION_GRANTED); log("Has RECORD_AUDIO permission? " + hasPermission); return hasPermission; } 
  2. If I don't have it then request it 如果我没有它,那么请求它

     private void requestRecordAudioPermission(){ String requiredPermission = Manifest.permission.RECORD_AUDIO; // If the user previously denied this permission then show a message explaining why // this permission is needed if (ActivityCompat.shouldShowRequestPermissionRationale(this, requiredPermission)) { showToast("This app needs to record audio through the microphone...."); } // request the permission. ActivityCompat.requestPermissions(this, new String[]{requiredPermission}, PERMISSIONS_REQUEST_RECORD_AUDIO); } @Override public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) { // This method is called when the user responds to the permissions dialog } 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM