summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorSvetoslav <svetoslavganov@google.com>2015-10-15 16:54:00 -0700
committerSvetoslav <svetoslavganov@google.com>2015-10-16 13:42:32 -0700
commitffb32b1f243e691f67c4d373050563d9028177cd (patch)
treeb43a9d3032854acfd7fe2e7148ec69c9db49cd8d /core
parente39def480fd2d1bcc3a89751dd492d4634c38194 (diff)
downloadframeworks_base-ffb32b1f243e691f67c4d373050563d9028177cd.zip
frameworks_base-ffb32b1f243e691f67c4d373050563d9028177cd.tar.gz
frameworks_base-ffb32b1f243e691f67c4d373050563d9028177cd.tar.bz2
Don't allow concurrent permission requests.
bug:24690277 Change-Id: Ie8c6eae230cd20e40d32cf688d30f6d40f9a9acd
Diffstat (limited to 'core')
-rw-r--r--core/java/android/app/Activity.java29
1 files changed, 29 insertions, 0 deletions
diff --git a/core/java/android/app/Activity.java b/core/java/android/app/Activity.java
index 2cb3f39..ecd0050 100644
--- a/core/java/android/app/Activity.java
+++ b/core/java/android/app/Activity.java
@@ -689,6 +689,8 @@ public class Activity extends ContextThemeWrapper
private static final String SAVED_DIALOGS_TAG = "android:savedDialogs";
private static final String SAVED_DIALOG_KEY_PREFIX = "android:dialog_";
private static final String SAVED_DIALOG_ARGS_KEY_PREFIX = "android:dialog_args_";
+ private static final String HAS_CURENT_PERMISSIONS_REQUEST_KEY =
+ "android:hasCurrentPermissionsRequest";
private static final String REQUEST_PERMISSIONS_WHO_PREFIX = "@android:requestPermissions:";
@@ -797,6 +799,8 @@ public class Activity extends ContextThemeWrapper
SharedElementCallback mEnterTransitionListener = SharedElementCallback.NULL_CALLBACK;
SharedElementCallback mExitTransitionListener = SharedElementCallback.NULL_CALLBACK;
+ private boolean mHasCurrentPermissionsRequest;
+
/** Return the intent that started this activity. */
public Intent getIntent() {
return mIntent;
@@ -1298,6 +1302,7 @@ public class Activity extends ContextThemeWrapper
onSaveInstanceState(outState);
saveManagedDialogs(outState);
mActivityTransitionState.saveState(outState);
+ storeHasCurrentPermissionRequest(outState);
if (DEBUG_LIFECYCLE) Slog.v(TAG, "onSaveInstanceState " + this + ": " + outState);
}
@@ -1313,6 +1318,7 @@ public class Activity extends ContextThemeWrapper
final void performSaveInstanceState(Bundle outState, PersistableBundle outPersistentState) {
onSaveInstanceState(outState, outPersistentState);
saveManagedDialogs(outState);
+ storeHasCurrentPermissionRequest(outState);
if (DEBUG_LIFECYCLE) Slog.v(TAG, "onSaveInstanceState " + this + ": " + outState +
", " + outPersistentState);
}
@@ -3811,8 +3817,15 @@ public class Activity extends ContextThemeWrapper
* @see #shouldShowRequestPermissionRationale(String)
*/
public final void requestPermissions(@NonNull String[] permissions, int requestCode) {
+ if (mHasCurrentPermissionsRequest) {
+ Log.w(TAG, "Can reqeust only one set of permissions at a time");
+ // Dispatch the callback with empty arrays which means a cancellation.
+ onRequestPermissionsResult(requestCode, new String[0], new int[0]);
+ return;
+ }
Intent intent = getPackageManager().buildRequestPermissionsIntent(permissions);
startActivityForResult(REQUEST_PERMISSIONS_WHO_PREFIX, intent, requestCode, null);
+ mHasCurrentPermissionsRequest = true;
}
/**
@@ -6234,12 +6247,14 @@ public class Activity extends ContextThemeWrapper
}
final void performCreate(Bundle icicle) {
+ restoreHasCurrentPermissionRequest(icicle);
onCreate(icicle);
mActivityTransitionState.readState(icicle);
performCreateCommon();
}
final void performCreate(Bundle icicle, PersistableBundle persistentState) {
+ restoreHasCurrentPermissionRequest(icicle);
onCreate(icicle, persistentState);
mActivityTransitionState.readState(icicle);
performCreateCommon();
@@ -6418,6 +6433,19 @@ public class Activity extends ContextThemeWrapper
return mResumed;
}
+ private void storeHasCurrentPermissionRequest(Bundle bundle) {
+ if (bundle != null && mHasCurrentPermissionsRequest) {
+ bundle.putBoolean(HAS_CURENT_PERMISSIONS_REQUEST_KEY, true);
+ }
+ }
+
+ private void restoreHasCurrentPermissionRequest(Bundle bundle) {
+ if (bundle != null) {
+ mHasCurrentPermissionsRequest = bundle.getBoolean(
+ HAS_CURENT_PERMISSIONS_REQUEST_KEY, false);
+ }
+ }
+
void dispatchActivityResult(String who, int requestCode,
int resultCode, Intent data) {
if (false) Log.v(
@@ -6545,6 +6573,7 @@ public class Activity extends ContextThemeWrapper
}
private void dispatchRequestPermissionsResult(int requestCode, Intent data) {
+ mHasCurrentPermissionsRequest = false;
// If the package installer crashed we may have not data - best effort.
String[] permissions = (data != null) ? data.getStringArrayExtra(
PackageManager.EXTRA_REQUEST_PERMISSIONS_NAMES) : new String[0];