Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

improvements for permission flow

Michael Rademakera28a9415a02c
diff --git a/console/android/src/main/java/org/openremote/android/MainActivity.java b/console/android/src/main/java/org/openremote/android/MainActivity.java
index d7187aa1e..935c616ec 100644
--- a/console/android/src/main/java/org/openremote/android/MainActivity.java
+++ b/console/android/src/main/java/org/openremote/android/MainActivity.java
@@ -67,6 +67,7 @@ public class MainActivity extends Activity {
protected Context context;
protected SharedPreferences sharedPreferences;
protected GeofenceProvider geofenceProvider;
+ protected String consoleId;
protected BroadcastReceiver onDownloadCompleteReciever = new BroadcastReceiver() {
public void onReceive(Context ctxt, Intent intent) {
@@ -400,8 +401,11 @@ public class MainActivity extends Activity {
} else if (requestCode == GeofenceProvider.Companion.getLocationReponseCode()) {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
try {
- Map<String, Object> initData = geofenceProvider.initialize();
- final String jsonString = new ObjectMapper().writeValueAsString(initData);
+ Map<String, Object> enableData = geofenceProvider.enable(String.format("%s/%s",
+ getString(R.string.OR_BASE_SERVER),
+ getString(R.string.OR_REALM)),
+ consoleId);
+ final String jsonString = new ObjectMapper().writeValueAsString(enableData);
this.runOnUiThread(new Runnable() {
@Override
public void run() {
@@ -476,16 +480,13 @@ public class MainActivity extends Activity {
protected void handleGeofenceProviderMessage(String action, JSONObject data) throws JSONException {
if (action.equalsIgnoreCase("PROVIDER_INIT")) {
geofenceProvider = new GeofenceProvider(activity);
- if (!geofenceProvider.checkPermission()) {
- geofenceProvider.registerPermissions();
- } else {
- Map<String, Object> initData = geofenceProvider.initialize();
- notifyClient(initData);
- }
+ Map<String, Object> initData = geofenceProvider.initialize();
+ notifyClient(initData);
} else if (action.equalsIgnoreCase("PROVIDER_ENABLE")) {
if (data != null) {
String consoleId = data.getString("consoleId");
if (consoleId != null) {
+ ((MainActivity) activity).consoleId = consoleId;
Map<String, Object> enableData = geofenceProvider.enable(String.format("%s/%s",
getString(R.string.OR_BASE_SERVER),
getString(R.string.OR_REALM)),
diff --git a/console/android/src/main/java/org/openremote/android/service/GeofenceProvider.kt b/console/android/src/main/java/org/openremote/android/service/GeofenceProvider.kt
index 279c5911e..cfc575bac 100644
--- a/console/android/src/main/java/org/openremote/android/service/GeofenceProvider.kt
+++ b/console/android/src/main/java/org/openremote/android/service/GeofenceProvider.kt
@@ -31,6 +31,7 @@ class GeofenceProvider(val activity: Activity) {
val geoPostUrlsKey = "geoPostUrls"
var geoPostUrls = hashMapOf<String, List<String>>()
var locationReponseCode = 101
+ lateinit var consoleId: String
}
val version = "ORConsole"
@@ -50,10 +51,7 @@ class GeofenceProvider(val activity: Activity) {
var baseURL: String? = null
var consoleId: String? = null
-
fun initialize(): Map<String, Any> {
- geofencingClient = LocationServices.getGeofencingClient(activity)
-
var inputStream: ObjectInputStream? = null
try {
val file = File(activity.getDir("data", MODE_PRIVATE), geoPostUrlsKey)
@@ -70,7 +68,7 @@ class GeofenceProvider(val activity: Activity) {
"provider" to "geofence",
"version" to version,
"requiresPermission" to true,
- "hasPermission" to true,
+ "hasPermission" to checkPermission(),
"success" to true
)
}
@@ -85,18 +83,24 @@ class GeofenceProvider(val activity: Activity) {
.putString(consoleIdKey, this.consoleId)
.apply()
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
- activity.startForegroundService(Intent(activity, LocationService::class.java))
+ if(!checkPermission()) {
+ registerPermissions()
} else {
- activity.startService(Intent(activity, LocationService::class.java))
- }
+ geofencingClient = LocationServices.getGeofencingClient(activity)
- fetchGeofences()
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ activity.startForegroundService(Intent(activity, LocationService::class.java))
+ } else {
+ activity.startService(Intent(activity, LocationService::class.java))
+ }
+
+ fetchGeofences()
+ }
return hashMapOf(
"action" to "PROVIDER_ENABLE",
"provider" to "geofence",
- "hasPermission" to true,
+ "hasPermission" to checkPermission(),
"success" to true
)
}
diff --git a/manager/src/main/java/org/openremote/manager/notification/FCMDeliveryService.java b/manager/src/main/java/org/openremote/manager/notification/FCMDeliveryService.java
index 592b922e8..b4f7acd7c 100644
--- a/manager/src/main/java/org/openremote/manager/notification/FCMDeliveryService.java
+++ b/manager/src/main/java/org/openremote/manager/notification/FCMDeliveryService.java
@@ -217,17 +217,17 @@ public class FCMDeliveryService {
LOG.log(Level.WARNING, "FCM send failed: " + e.getErrorCode(), e);
// TODO: Implement backoff and blacklisting
- switch (e.getErrorCode()) {
- // Errors we cannot recover from - stop FCM to avoid blacklisting our app
- case "invalid-argument":
- case "authentication-error":
- LOG.severe("FCM critical error so marking FCM as invalid no more messages will be sent");
- setValid(false);
- break;
- case "server-unavailable":
- case "internal-error":
- break;
- }
+// switch (e.getErrorCode()) {
+// // Errors we cannot recover from - stop FCM to avoid blacklisting our app
+// case "invalid-argument":
+// case "authentication-error":
+// LOG.severe("FCM critical error so marking FCM as invalid no more messages will be sent");
+// setValid(false);
+// break;
+// case "server-unavailable":
+// case "internal-error":
+// break;
+// }
}
return success;