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

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

Issue 1965093002: 🎾 Migrate more shared preferences to ContextUtils. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 7 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
« no previous file with comments | « sync/android/javatests/src/org/chromium/sync/notifier/InvalidationPreferencesTest.java ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.preference.PreferenceManager;
21 import android.text.TextUtils; 20 import android.text.TextUtils;
22 import android.util.SparseArray; 21 import android.util.SparseArray;
23 import android.view.View; 22 import android.view.View;
24 23
25 import org.chromium.base.ActivityState; 24 import org.chromium.base.ActivityState;
26 import org.chromium.base.ApplicationStatus; 25 import org.chromium.base.ApplicationStatus;
27 import org.chromium.base.Callback; 26 import org.chromium.base.Callback;
27 import org.chromium.base.ContextUtils;
28 import org.chromium.ui.UiUtils; 28 import org.chromium.ui.UiUtils;
29 29
30 import java.lang.ref.WeakReference; 30 import java.lang.ref.WeakReference;
31 31
32 /** 32 /**
33 * The class provides the WindowAndroid's implementation which requires 33 * The class provides the WindowAndroid's implementation which requires
34 * Activity Instance. 34 * Activity Instance.
35 * Only instantiate this class when you need the implemented features. 35 * Only instantiate this class when you need the implemented features.
36 */ 36 */
37 public class ActivityWindowAndroid 37 public class ActivityWindowAndroid
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 * @param requestCode The unique code for the permission request. 204 * @param requestCode The unique code for the permission request.
205 * @param permissions The list of permissions in the result. 205 * @param permissions The list of permissions in the result.
206 * @param grantResults Whether the permissions were granted. 206 * @param grantResults Whether the permissions were granted.
207 * @return Whether the permission request corresponding to a pending permiss ion request. 207 * @return Whether the permission request corresponding to a pending permiss ion request.
208 */ 208 */
209 public boolean onRequestPermissionsResult(int requestCode, String[] permissi ons, 209 public boolean onRequestPermissionsResult(int requestCode, String[] permissi ons,
210 int[] grantResults) { 210 int[] grantResults) {
211 Activity activity = getActivity().get(); 211 Activity activity = getActivity().get();
212 assert activity != null; 212 assert activity != null;
213 213
214 SharedPreferences.Editor editor = 214 SharedPreferences.Editor editor = ContextUtils.getAppSharedPreferences() .edit();
215 PreferenceManager.getDefaultSharedPreferences(activity).edit();
216 for (int i = 0; i < permissions.length; i++) { 215 for (int i = 0; i < permissions.length; i++) {
217 editor.putBoolean(getHasRequestedPermissionKey(permissions[i]), true ); 216 editor.putBoolean(getHasRequestedPermissionKey(permissions[i]), true );
218 } 217 }
219 editor.apply(); 218 editor.apply();
220 219
221 PermissionCallback callback = mOutstandingPermissionRequests.get(request Code); 220 PermissionCallback callback = mOutstandingPermissionRequests.get(request Code);
222 mOutstandingPermissionRequests.delete(requestCode); 221 mOutstandingPermissionRequests.delete(requestCode);
223 if (callback == null) return false; 222 if (callback == null) return false;
224 callback.onRequestPermissionsResult(permissions, grantResults); 223 callback.onRequestPermissionsResult(permissions, grantResults);
225 return true; 224 return true;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 return false; 274 return false;
276 } 275 }
277 276
278 if (activity.shouldShowRequestPermissionRationale(permission)) { 277 if (activity.shouldShowRequestPermissionRationale(permission)) {
279 return true; 278 return true;
280 } 279 }
281 280
282 // Check whether we have ever asked for this permission by checking whether we saved 281 // Check whether we have ever asked for this permission by checking whether we saved
283 // a preference associated with it before. 282 // a preference associated with it before.
284 String permissionQueriedKey = getHasRequestedPermissionKey(permissio n); 283 String permissionQueriedKey = getHasRequestedPermissionKey(permissio n);
285 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferen ces(activity); 284 SharedPreferences prefs = ContextUtils.getAppSharedPreferences();
286 if (!prefs.getBoolean(permissionQueriedKey, false)) return true; 285 if (!prefs.getBoolean(permissionQueriedKey, false)) return true;
287 286
288 return false; 287 return false;
289 } 288 }
290 289
291 @Override 290 @Override
292 public boolean isPermissionRevokedByPolicy(String permission) { 291 public boolean isPermissionRevokedByPolicy(String permission) {
293 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return false; 292 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return false;
294 293
295 Activity activity = getActivity().get(); 294 Activity activity = getActivity().get();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 Activity activity = getActivity().get(); 330 Activity activity = getActivity().get();
332 if (activity == null) return false; 331 if (activity == null) return false;
333 332
334 int requestCode = generateNextRequestCode(); 333 int requestCode = generateNextRequestCode();
335 mOutstandingPermissionRequests.put(requestCode, callback); 334 mOutstandingPermissionRequests.put(requestCode, callback);
336 activity.requestPermissions(permissions, requestCode); 335 activity.requestPermissions(permissions, requestCode);
337 return true; 336 return true;
338 } 337 }
339 } 338 }
340 } 339 }
OLDNEW
« no previous file with comments | « sync/android/javatests/src/org/chromium/sync/notifier/InvalidationPreferencesTest.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698