You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cordova.apache.org by riknoll <gi...@git.apache.org> on 2016/03/25 20:09:14 UTC
[GitHub] cordova-android pull request: CB-10963: Handle overlapping permiss...
GitHub user riknoll opened a pull request:
https://github.com/apache/cordova-android/pull/285
CB-10963: Handle overlapping permission requests from plugins
Adds support for overlapping permission requests from plugins (i.e. requests that are made while another request is still pending). The old behavior was to just return the last permission request, which meant that plugins could inadvertently cancel requests made by other plugins.
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/MSOpenTech/cordova-android CB-10963
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/cordova-android/pull/285.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #285
----
commit 49112607c958fc5c623b10c3fa1b697b1f7f214e
Author: Richard Knoll <ri...@gmail.com>
Date: 2016-03-25T18:07:27Z
CB-10963: Handle overlapping permission requests from plugins
----
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org
[GitHub] cordova-android pull request: CB-10963: Handle overlapping permiss...
Posted by jasongin <gi...@git.apache.org>.
Github user jasongin commented on a diff in the pull request:
https://github.com/apache/cordova-android/pull/285#discussion_r57485883
--- Diff: framework/src/org/apache/cordova/CallbackMap.java ---
@@ -0,0 +1,65 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+*/
+package org.apache.cordova;
+
+import android.util.Pair;
+import android.util.SparseArray;
+
+/**
+ * Provides a collection that maps unique request codes to CordovaPlugins and Integers.
+ * Used to ensure that when plugins make requests for runtime permissions, those requests do not
+ * collide with requests from other plugins that use the same request code value.
+ */
+public class CallbackMap {
--- End diff --
Why public? It's only used in this package right?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org
[GitHub] cordova-android pull request: CB-10963: Handle overlapping permiss...
Posted by riknoll <gi...@git.apache.org>.
Github user riknoll commented on the pull request:
https://github.com/apache/cordova-android/pull/285#issuecomment-202506848
Perhaps we can mock the Activity's request permissions method? I don't have a lot of experience writing JUnit tests for Android.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org
[GitHub] cordova-android pull request: CB-10963: Handle overlapping permiss...
Posted by jasongin <gi...@git.apache.org>.
Github user jasongin commented on a diff in the pull request:
https://github.com/apache/cordova-android/pull/285#discussion_r57489412
--- Diff: framework/src/org/apache/cordova/CallbackMap.java ---
@@ -0,0 +1,65 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+*/
+package org.apache.cordova;
+
+import android.util.Pair;
+import android.util.SparseArray;
+
+/**
+ * Provides a collection that maps unique request codes to CordovaPlugins and Integers.
+ * Used to ensure that when plugins make requests for runtime permissions, those requests do not
+ * collide with requests from other plugins that use the same request code value.
+ */
+public class CallbackMap {
--- End diff --
Never mind, it looks like basically everything in this package is public/protected to allow for easy extensibility.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org
[GitHub] cordova-android pull request: CB-10963: Handle overlapping permiss...
Posted by riknoll <gi...@git.apache.org>.
Github user riknoll commented on the pull request:
https://github.com/apache/cordova-android/pull/285#issuecomment-201435318
@infil00p @jasongin please review when you have a moment.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org
[GitHub] cordova-android pull request: CB-10963: Handle overlapping permiss...
Posted by riknoll <gi...@git.apache.org>.
Github user riknoll commented on a diff in the pull request:
https://github.com/apache/cordova-android/pull/285#discussion_r57487068
--- Diff: framework/src/org/apache/cordova/CallbackMap.java ---
@@ -0,0 +1,65 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+*/
+package org.apache.cordova;
+
+import android.util.Pair;
+import android.util.SparseArray;
+
+/**
+ * Provides a collection that maps unique request codes to CordovaPlugins and Integers.
+ * Used to ensure that when plugins make requests for runtime permissions, those requests do not
+ * collide with requests from other plugins that use the same request code value.
+ */
+public class CallbackMap {
+ private int currentCallbackId = 0;
+ private SparseArray<Pair<CordovaPlugin, Integer>> callbacks;
+
+ public CallbackMap() {
+ this.callbacks = new SparseArray<Pair<CordovaPlugin, Integer>>();
+ }
+
+ /**
+ * Stores a CordovaPlugin and request code and returns a new unique request code to use
+ * in a permission request.
+ *
+ * @param receiver The plugin that is making the request
+ * @param requestCode The original request code used by the plugin
+ * @return A unique request code that can be used to retrieve this callback
+ * with getAndRemoveCallback()
+ */
+ public int registerCallback(CordovaPlugin receiver, int requestCode) {
+ int mappedId = this.currentCallbackId++;
--- End diff --
Updated to synchronize the methods themselves
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org
[GitHub] cordova-android pull request: CB-10963: Handle overlapping permiss...
Posted by jasongin <gi...@git.apache.org>.
Github user jasongin commented on a diff in the pull request:
https://github.com/apache/cordova-android/pull/285#discussion_r57485105
--- Diff: framework/src/org/apache/cordova/CallbackMap.java ---
@@ -0,0 +1,65 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+*/
+package org.apache.cordova;
+
+import android.util.Pair;
+import android.util.SparseArray;
+
+/**
+ * Provides a collection that maps unique request codes to CordovaPlugins and Integers.
+ * Used to ensure that when plugins make requests for runtime permissions, those requests do not
+ * collide with requests from other plugins that use the same request code value.
+ */
+public class CallbackMap {
+ private int currentCallbackId = 0;
+ private SparseArray<Pair<CordovaPlugin, Integer>> callbacks;
+
+ public CallbackMap() {
+ this.callbacks = new SparseArray<Pair<CordovaPlugin, Integer>>();
+ }
+
+ /**
+ * Stores a CordovaPlugin and request code and returns a new unique request code to use
+ * in a permission request.
+ *
+ * @param receiver The plugin that is making the request
+ * @param requestCode The original request code used by the plugin
+ * @return A unique request code that can be used to retrieve this callback
+ * with getAndRemoveCallback()
+ */
+ public int registerCallback(CordovaPlugin receiver, int requestCode) {
+ int mappedId = this.currentCallbackId++;
--- End diff --
Can this be called concurrently? If so, consider using java.util.concurrent.atomic.AtomicInteger.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org
[GitHub] cordova-android pull request: CB-10963: Handle overlapping permiss...
Posted by jasongin <gi...@git.apache.org>.
Github user jasongin commented on a diff in the pull request:
https://github.com/apache/cordova-android/pull/285#discussion_r57485286
--- Diff: framework/src/org/apache/cordova/CallbackMap.java ---
@@ -0,0 +1,65 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+*/
+package org.apache.cordova;
+
+import android.util.Pair;
+import android.util.SparseArray;
+
+/**
+ * Provides a collection that maps unique request codes to CordovaPlugins and Integers.
+ * Used to ensure that when plugins make requests for runtime permissions, those requests do not
+ * collide with requests from other plugins that use the same request code value.
+ */
+public class CallbackMap {
+ private int currentCallbackId = 0;
+ private SparseArray<Pair<CordovaPlugin, Integer>> callbacks;
+
+ public CallbackMap() {
+ this.callbacks = new SparseArray<Pair<CordovaPlugin, Integer>>();
+ }
+
+ /**
+ * Stores a CordovaPlugin and request code and returns a new unique request code to use
+ * in a permission request.
+ *
+ * @param receiver The plugin that is making the request
+ * @param requestCode The original request code used by the plugin
+ * @return A unique request code that can be used to retrieve this callback
+ * with getAndRemoveCallback()
+ */
+ public int registerCallback(CordovaPlugin receiver, int requestCode) {
+ int mappedId = this.currentCallbackId++;
--- End diff --
Also then you'd need a collection tolerant of concurrency instead of SparseArray.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org
[GitHub] cordova-android pull request: CB-10963: Handle overlapping permiss...
Posted by jasongin <gi...@git.apache.org>.
Github user jasongin commented on the pull request:
https://github.com/apache/cordova-android/pull/285#issuecomment-201493604
LGTM
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org
[GitHub] cordova-android pull request: CB-10963: Handle overlapping permiss...
Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:
https://github.com/apache/cordova-android/pull/285
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org
[GitHub] cordova-android pull request: CB-10963: Handle overlapping permiss...
Posted by infil00p <gi...@git.apache.org>.
Github user infil00p commented on the pull request:
https://github.com/apache/cordova-android/pull/285#issuecomment-201966761
Can we somehow create a test for this? I don't know how this is testable, since I still don't know exactly how to use JUnit to test onActivityResult.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org