简体   繁体   中英

How to grant more permissions to android shell user?

I build some command line tool with ndk and execute it in /data/local/tmp. Now it prompts me "requires android.permission.RECORD_AUDIO" when I call some OpenSLES API in my command line tool:

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 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.

Can I just debug my OpenSLES demo in the android shell ? How can I get more permisson just in shell .

Must I create a jni and java project for every experimental code snippet and modify them together when I change some C++ interfaces ?

Can I access RECORD_AUDIO, CAMERA directly in a command tool from shell ?

This is the new permissions model in Android Marshmallow in action. 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:

     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 } 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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