OLD | NEW |
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 Loading... |
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 = |
| 194 getApplicationContext().getPackageManager().getPermissio
nInfo( |
| 195 permission, PackageManager.GET_META_DATA); |
191 | 196 |
192 if (!TextUtils.isEmpty(permissionInfo.group)) { | 197 if (!TextUtils.isEmpty(permissionInfo.group)) { |
193 permissionQueriedKey = permissionInfo.group; | 198 permissionQueriedKey = permissionInfo.group; |
| 199 } |
| 200 } catch (NameNotFoundException e) { |
| 201 // Unknown permission. Default back to the permission name inst
ead of the group. |
194 } | 202 } |
195 } catch (NameNotFoundException e) { | |
196 // Unknown permission. Default back to the permission name instead
of the group. | |
197 } | 203 } |
198 | 204 |
199 return PERMISSION_QUERIED_KEY_PREFIX + permissionQueriedKey; | 205 return PERMISSION_QUERIED_KEY_PREFIX + permissionQueriedKey; |
200 } | 206 } |
201 | 207 |
202 /** | 208 /** |
203 * Responds to a pending permission result. | 209 * Responds to a pending permission result. |
204 * @param requestCode The unique code for the permission request. | 210 * @param requestCode The unique code for the permission request. |
205 * @param permissions The list of permissions in the result. | 211 * @param permissions The list of permissions in the result. |
206 * @param grantResults Whether the permissions were granted. | 212 * @param grantResults Whether the permissions were granted. |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 Activity activity = getActivity().get(); | 337 Activity activity = getActivity().get(); |
332 if (activity == null) return false; | 338 if (activity == null) return false; |
333 | 339 |
334 int requestCode = generateNextRequestCode(); | 340 int requestCode = generateNextRequestCode(); |
335 mOutstandingPermissionRequests.put(requestCode, callback); | 341 mOutstandingPermissionRequests.put(requestCode, callback); |
336 activity.requestPermissions(permissions, requestCode); | 342 activity.requestPermissions(permissions, requestCode); |
337 return true; | 343 return true; |
338 } | 344 } |
339 } | 345 } |
340 } | 346 } |
OLD | NEW |