Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(android): switch to new callback-style permission requests #4033

Merged
merged 25 commits into from Jan 8, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
14e644c
Uses new permissions callbacks, work so far
carlpoole Dec 21, 2020
08ebc98
begun moving permission caching work to new system, reorganizing
carlpoole Dec 23, 2020
73526da
added PermissionState back after reconciling with reverted commit in …
carlpoole Dec 23, 2020
4fbc641
added PermissionState class to represent states instead of raw strings
carlpoole Dec 23, 2020
8bb79ec
updated requestPermissions call to handle aliases and pass through to…
carlpoole Dec 23, 2020
773ebec
undoing unintentional iOS format change
carlpoole Dec 23, 2020
a563f25
Update CAPBridgeViewController.swift
carlpoole Dec 23, 2020
d000384
Merge branch 'main' into perms-1.2
carlpoole Dec 29, 2020
1f8f848
protected for access, might change this. PluginMethod annotation went…
carlpoole Dec 30, 2020
e9b5ee2
check if perm result handled by plugin before OS handles callback
carlpoole Jan 4, 2021
a657476
Merge branch 'perms-1.2' of github.com:ionic-team/capacitor into perm…
carlpoole Jan 4, 2021
1927042
annotated permission response methods
carlpoole Jan 7, 2021
d894e3b
remove unused Permissionallback
carlpoole Jan 7, 2021
d6db63f
removed PermissionResponse annotation and merged into PluginMethod
carlpoole Jan 7, 2021
7e3e6dc
improved default behavior for overriden permissionRequest
carlpoole Jan 7, 2021
6b44c59
Merge branch 'main' into perms-1.2
carlpoole Jan 7, 2021
8b77ed1
Undoing iOS fmt change that happened
carlpoole Jan 7, 2021
419456b
removed permissionRequestCode from CapacitorPlugin annotiation for v3
carlpoole Jan 7, 2021
6b95ed2
removed unused annotation
carlpoole Jan 8, 2021
4624228
Comment improvements, cleanup
carlpoole Jan 8, 2021
5751e53
hard reject when permissions requested and no registered callback, co…
carlpoole Jan 8, 2021
d209086
refactor getPluginWithRequestCode
carlpoole Jan 8, 2021
7fbcf60
Merge branch 'main' into perms-1.2
carlpoole Jan 8, 2021
2011ed3
Merge branch 'main' into perms-1.2
carlpoole Jan 8, 2021
f2b86a7
Merge branch 'main' into perms-1.2
imhoffd Jan 8, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions android/capacitor/src/main/java/com/getcapacitor/Bridge.java
Expand Up @@ -758,8 +758,9 @@ public void startActivityForPluginWithResult(PluginCall call, Intent intent, int
}

/**
* Handle a request permission result by finding the that requested
* the permission and calling their permission handler
* Check for legacy Capacitor or Cordova plugins that may have registered to handle a permission
imhoffd marked this conversation as resolved.
Show resolved Hide resolved
* request, and handle them if so. If not handled, false is returned.
*
* @param requestCode the code that was requested
* @param permissions the permissions requested
* @param grantResults the set of granted/denied permissions
Expand Down
Expand Up @@ -164,6 +164,22 @@ public void onDetachedFromWindow() {
this.bridge.onDetachedFromWindow();
}

/**
* Handles permission request results.
*
* Capacitor is backwards compatible such that plugins using legacy permission request codes
* may coexist with plugins using the AndroidX Activity v1.2 permission callback flow introduced
* in Capacitor 3.0.
*
* In this method, plugins are checked first for ownership of the legacy permission request code.
* If the {@link Bridge#onRequestPermissionsResult(int, String[], int[])} method indicates it has
* handled the permission, then the permission callback will be considered complete. Otherwise,
* the permission will be handled using the AndroidX Activity flow.
*
* @param requestCode the request code associated with the permission request
* @param permissions the Android permission strings requested
* @param grantResults the status result of the permission request
*/
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
if (this.bridge == null) {
Expand Down
Expand Up @@ -67,7 +67,7 @@ public class Plugin {
/**
* Base activity result launcher used by the {@link #requestPermissions(PluginCall)} plugin call
*/
protected ActivityResultLauncher<String[]> basePermissionLauncher = null;
private ActivityResultLauncher<String[]> basePermissionLauncher = null;

/**
* Launchers used by the plugin to request permissions
Expand Down
Expand Up @@ -18,8 +18,8 @@ public CordovaPlugin getActivityResultCallback() {
}

/**
* Use in lieu of {@link CordovaInterfaceImpl#onRequestPermissionResult(int, String[], int[])} to return
* a boolean if Cordova is handling the permission request with a registered code.
* Checks Cordova permission callbacks to handle permissions defined by a Cordova plugin.
* Returns true if Cordova is handling the permission request with a registered code.
*
* @param requestCode
* @param permissions
Expand Down