diff options
author | LuK1337 <priv.luk@gmail.com> | 2015-12-17 21:32:46 +0800 |
---|---|---|
committer | Umair Khan <omerjerk@gmail.com> | 2016-01-04 14:25:36 +0530 |
commit | 852bcd16b075d74f3c24373d8321f9b193200c2e (patch) | |
tree | 6f0a4c80f38caf2d22003d0757c24ca29969a0b6 /src/com/android/browser/PermissionsPrompt.java | |
parent | ad614da6fd8a6c85ac98bd27d92e2801098e2bf6 (diff) | |
download | packages_apps_Browser-852bcd16b075d74f3c24373d8321f9b193200c2e.zip packages_apps_Browser-852bcd16b075d74f3c24373d8321f9b193200c2e.tar.gz packages_apps_Browser-852bcd16b075d74f3c24373d8321f9b193200c2e.tar.bz2 |
Browser: runtime permissions
Change-Id: I19caa970421898196c005aa9ad7cc651cd574c0a
Signed-off-by: jrizzoli <joey@cyanogenmoditalia.it>
Diffstat (limited to 'src/com/android/browser/PermissionsPrompt.java')
-rw-r--r-- | src/com/android/browser/PermissionsPrompt.java | 39 |
1 files changed, 36 insertions, 3 deletions
diff --git a/src/com/android/browser/PermissionsPrompt.java b/src/com/android/browser/PermissionsPrompt.java index 29412d9..47c6c4e 100644 --- a/src/com/android/browser/PermissionsPrompt.java +++ b/src/com/android/browser/PermissionsPrompt.java @@ -16,7 +16,11 @@ package com.android.browser; +import android.Manifest; +import android.app.Activity; import android.content.Context; +import android.content.Intent; +import android.content.pm.PackageManager; import android.net.Uri; import android.util.AttributeSet; import android.view.Gravity; @@ -29,7 +33,9 @@ import android.widget.RelativeLayout; import android.widget.TextView; import android.widget.Toast; +import java.util.ArrayList; import java.util.Enumeration; +import java.util.List; import java.util.Vector; public class PermissionsPrompt extends RelativeLayout { @@ -37,14 +43,17 @@ public class PermissionsPrompt extends RelativeLayout { private Button mAllowButton; private Button mDenyButton; private CheckBox mRemember; + private Context mContext; private PermissionRequest mRequest; public PermissionsPrompt(Context context) { this(context, null); + mContext = context; } public PermissionsPrompt(Context context, AttributeSet attrs) { super(context, attrs); + mContext = context; } @Override @@ -117,9 +126,33 @@ public class PermissionsPrompt extends RelativeLayout { */ private void handleButtonClick(boolean allow) { hide(); - if (allow) - mRequest.grant(mRequest.getResources()); - else + if (allow) { + String[] resources = mRequest.getResources(); + List<String> permissionsToRequest = new ArrayList<String>(); + + for (String resource : resources) { + if (resource.equals(PermissionRequest.RESOURCE_VIDEO_CAPTURE) && + mContext.checkSelfPermission(Manifest.permission.CAMERA) != + PackageManager.PERMISSION_GRANTED) { + permissionsToRequest.add(Manifest.permission.CAMERA); + } else if (resource.equals(PermissionRequest.RESOURCE_AUDIO_CAPTURE) && + mContext.checkSelfPermission(Manifest.permission.RECORD_AUDIO) != + PackageManager.PERMISSION_GRANTED) { + permissionsToRequest.add(Manifest.permission.RECORD_AUDIO); + } + } + + if (permissionsToRequest.size() > 0) { + String[] permissions = permissionsToRequest.toArray( + new String[permissionsToRequest.size()]); + ((Activity) mContext).requestPermissions(permissions, 1); + Intent intent = new Intent(mContext, PermissionsActivity.class); + mContext.startActivity(intent); + } else { + mRequest.grant(mRequest.getResources()); + } + } else { mRequest.deny(); + } } } |