Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(354)

Side by Side Diff: ui/android/java/src/org/chromium/ui/base/ActivityWindowAndroid.java

Issue 2682863002: [Android] Explicitly request all needed runtime permissions. (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.ui.base; 5 package org.chromium.ui.base;
6 6
7 import android.app.Activity; 7 import android.app.Activity;
8 import android.app.PendingIntent; 8 import android.app.PendingIntent;
9 import android.content.ActivityNotFoundException; 9 import android.content.ActivityNotFoundException;
10 import android.content.Context; 10 import android.content.Context;
11 import android.content.Intent; 11 import android.content.Intent;
12 import android.content.IntentSender.SendIntentException; 12 import android.content.IntentSender.SendIntentException;
13 import android.content.SharedPreferences; 13 import android.content.SharedPreferences;
14 import android.content.pm.PackageManager; 14 import android.content.pm.PackageManager;
15 import android.content.pm.PackageManager.NameNotFoundException; 15 import android.content.pm.PackageManager.NameNotFoundException;
16 import android.content.pm.PermissionInfo; 16 import android.content.pm.PermissionInfo;
17 import android.os.Build; 17 import android.os.Build;
18 import android.os.Handler; 18 import android.os.Handler;
19 import android.os.Process; 19 import android.os.Process;
20 import android.text.TextUtils; 20 import android.text.TextUtils;
21 import android.util.SparseArray; 21 import android.util.SparseArray;
22 import android.view.View; 22 import android.view.View;
23 23
24 import org.chromium.base.ActivityState; 24 import org.chromium.base.ActivityState;
25 import org.chromium.base.ApiCompatibilityUtils; 25 import org.chromium.base.ApiCompatibilityUtils;
26 import org.chromium.base.ApplicationStatus; 26 import org.chromium.base.ApplicationStatus;
27 import org.chromium.base.BuildInfo;
27 import org.chromium.base.Callback; 28 import org.chromium.base.Callback;
28 import org.chromium.base.ContextUtils; 29 import org.chromium.base.ContextUtils;
29 import org.chromium.ui.UiUtils; 30 import org.chromium.ui.UiUtils;
30 31
31 import java.lang.ref.WeakReference; 32 import java.lang.ref.WeakReference;
32 33
33 /** 34 /**
34 * The class provides the WindowAndroid's implementation which requires 35 * The class provides the WindowAndroid's implementation which requires
35 * Activity Instance. 36 * Activity Instance.
36 * Only instantiate this class when you need the implemented features. 37 * Only instantiate this class when you need the implemented features.
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 if (errorMessage != null) { 172 if (errorMessage != null) {
172 showCallbackNonExistentError(errorMessage); 173 showCallbackNonExistentError(errorMessage);
173 return true; 174 return true;
174 } 175 }
175 } 176 }
176 return false; 177 return false;
177 } 178 }
178 179
179 private String getHasRequestedPermissionKey(String permission) { 180 private String getHasRequestedPermissionKey(String permission) {
180 String permissionQueriedKey = permission; 181 String permissionQueriedKey = permission;
181 try { 182 // Prior to O, permissions were granted at the group level. Post O, eac h permission is
182 // Runtime permissions are controlled at the group level. So when d etermining whether 183 // granted individually.
183 // we have requested a particular permission before, we should check whether we 184 if (!BuildInfo.isAtLeastO()) {
184 // have requested any permission in that group as that mimics the lo gic in the Android 185 try {
185 // framework. 186 // Runtime permissions are controlled at the group level. So wh en determining
186 // 187 // whether we have requested a particular permission before, we should check whether
187 // e.g. Requesting first the permission ACCESS_FINE_LOCATION will re sult in Chrome 188 // we have requested any permission in that group as that mimics the logic in the
188 // treating ACCESS_COARSE_LOCATION as if it had already been re quested as well. 189 // Android framework.
189 PermissionInfo permissionInfo = getApplicationContext().getPackageMa nager() 190 //
190 .getPermissionInfo(permission, PackageManager.GET_META_DATA) ; 191 // e.g. Requesting first the permission ACCESS_FINE_LOCATION wil l result in Chrome
192 // treating ACCESS_COARSE_LOCATION as if it had already bee n requested as well.
193 PermissionInfo permissionInfo = getApplicationContext().getPacka geManager()
194 .getPermissionInfo(permission, PackageManager.GET_META_D ATA);
191 195
192 if (!TextUtils.isEmpty(permissionInfo.group)) { 196 if (!TextUtils.isEmpty(permissionInfo.group)) {
193 permissionQueriedKey = permissionInfo.group; 197 permissionQueriedKey = permissionInfo.group;
198 }
199 } catch (NameNotFoundException e) {
200 // Unknown permission. Default back to the permission name inst ead of the group.
194 } 201 }
195 } catch (NameNotFoundException e) {
196 // Unknown permission. Default back to the permission name instead of the group.
197 } 202 }
198 203
199 return PERMISSION_QUERIED_KEY_PREFIX + permissionQueriedKey; 204 return PERMISSION_QUERIED_KEY_PREFIX + permissionQueriedKey;
200 } 205 }
201 206
202 /** 207 /**
203 * Responds to a pending permission result. 208 * Responds to a pending permission result.
204 * @param requestCode The unique code for the permission request. 209 * @param requestCode The unique code for the permission request.
205 * @param permissions The list of permissions in the result. 210 * @param permissions The list of permissions in the result.
206 * @param grantResults Whether the permissions were granted. 211 * @param grantResults Whether the permissions were granted.
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 Activity activity = getActivity().get(); 336 Activity activity = getActivity().get();
332 if (activity == null) return false; 337 if (activity == null) return false;
333 338
334 int requestCode = generateNextRequestCode(); 339 int requestCode = generateNextRequestCode();
335 mOutstandingPermissionRequests.put(requestCode, callback); 340 mOutstandingPermissionRequests.put(requestCode, callback);
336 activity.requestPermissions(permissions, requestCode); 341 activity.requestPermissions(permissions, requestCode);
337 return true; 342 return true;
338 } 343 }
339 } 344 }
340 } 345 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698