-
Notifications
You must be signed in to change notification settings - Fork 660
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Thanks to Marshmallow, we now have a bunch of new code to handle the …
…permissions. This is a major step backwards.
- Loading branch information
Showing
3 changed files
with
179 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/* | ||
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.geolocation; | ||
|
||
import android.content.pm.PackageManager; | ||
import android.Manifest; | ||
import android.os.Build; | ||
|
||
import org.apache.cordova.CallbackContext; | ||
import org.apache.cordova.CordovaArgs; | ||
import org.apache.cordova.CordovaPlugin; | ||
import org.apache.cordova.PluginResult; | ||
import org.apache.cordova.LOG; | ||
import org.json.JSONArray; | ||
import org.json.JSONException; | ||
|
||
import javax.security.auth.callback.Callback; | ||
|
||
public class Geolocation extends CordovaPlugin { | ||
|
||
String TAG = "GeolocationPlugin"; | ||
CallbackContext context; | ||
|
||
String [] permissions; | ||
|
||
public Geolocation() | ||
{ | ||
permissions = new String[2]; | ||
permissions[0] = Manifest.permission.ACCESS_COARSE_LOCATION; | ||
permissions[1] = Manifest.permission.ACCESS_FINE_LOCATION; | ||
} | ||
|
||
|
||
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { | ||
context = callbackContext; | ||
if(action.equals("getPermission")) | ||
{ | ||
if(hasPermisssion()) | ||
{ | ||
PluginResult r = new PluginResult(PluginResult.Status.OK); | ||
context.sendPluginResult(r); | ||
return true; | ||
} | ||
else { | ||
cordova.requestPermissions(this, 0); | ||
} | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
public String[] getPermissionRequest() { | ||
return permissions; | ||
} | ||
|
||
|
||
public void onRequestPermissionResult(int requestCode, String[] permissions, | ||
int[] grantResults) throws JSONException | ||
{ | ||
PluginResult result; | ||
for(int r:grantResults) | ||
{ | ||
if(r == PackageManager.PERMISSION_DENIED) | ||
{ | ||
LOG.d(TAG, "Permission Denied!"); | ||
result = new PluginResult(PluginResult.Status.ILLEGAL_ACCESS_EXCEPTION); | ||
context.sendPluginResult(result); | ||
return; | ||
} | ||
} | ||
result = new PluginResult(PluginResult.Status.OK); | ||
context.sendPluginResult(result); | ||
} | ||
|
||
public boolean hasPermisssion() { | ||
This comment has been minimized.
Sorry, something went wrong. |
||
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.M) | ||
{ | ||
return true; | ||
} | ||
for(String p : permissions) | ||
{ | ||
if(PackageManager.PERMISSION_DENIED == cordova.getActivity().checkSelfPermission(p)) | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* | ||
* 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. | ||
* | ||
*/ | ||
|
||
|
||
var exec = cordova.require('cordova/exec'); | ||
|
||
module.exports = { | ||
|
||
/*TODO: Fix scope issues with this cordova.require. I have no idea exec works, but geo doesn't work */ | ||
|
||
getCurrentPosition: function(success, error, args) { | ||
var win = function() { | ||
var geo = cordova.require('cordova/modulemapper').getOriginalSymbol(window, 'navigator.geolocation'); | ||
geo.getCurrentPosition(success, error, { | ||
enableHighAccuracy: args[0], | ||
maximumAge: args[1] | ||
}); | ||
}; | ||
exec(win, error, "Geolocation", "getPermission", []); | ||
}, | ||
|
||
addWatch: function(success, error, args) { | ||
var win = function() { | ||
var geo = cordova.require('cordova/modulemapper').getOriginalSymbol(window, 'navigator.geolocation'); | ||
geo.watchPosition(successCallback, error, { | ||
enableHighAccuracy: args[1] | ||
}); | ||
}; | ||
exec(win, error, "Geolocation", "getPermission", []); | ||
}, | ||
|
||
clearWatch: function(success, error, args) { | ||
var win = function() { | ||
var geo = cordova.require('cordova/modulemapper').getOriginalSymbol(window, 'navigator.geolocation'); | ||
geo.clearWatch(args[0]); | ||
} | ||
exec(win, error, "Geolocation", "getPermission", []); | ||
} | ||
}; | ||
|
typo. extra "s"