Skip to content

armgit / core

Public Imported from GitHub
0

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

Updated Android console providers

Rich Turnerf6a645fadac3
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 a19f57a63..1f78cfa0d 100644
--- a/console/android/src/main/java/org/openremote/android/MainActivity.java
+++ b/console/android/src/main/java/org/openremote/android/MainActivity.java
@@ -50,6 +50,8 @@ public class MainActivity extends Activity {
private static final int WEBVIEW_LOAD_TIMEOUT_DEFAULT = 5000;
public static final String ACTION_BROADCAST = "ACTION_BROADCAST";
+ public static final String PUSH_PROVIDER_DISABLED_KEY = "PushProviderDisabled";
+ public static final String CONSOLE_ID_KEY = "consoleId";
protected final ConnectivityChangeReceiver connectivityChangeReceiver = new ConnectivityChangeReceiver();
protected WebView webView;
@@ -556,6 +558,7 @@ public class MainActivity extends Activity {
response.put("provider", "push");
response.put("version", "fcm");
response.put("enabled", false);
+ response.put("disabled", sharedPreferences.contains(PUSH_PROVIDER_DISABLED_KEY));
response.put("requiresPermission", false);
response.put("hasPermission", true);
response.put("success", true);
@@ -564,7 +567,10 @@ public class MainActivity extends Activity {
String consoleId = data.getString("consoleId");
if (consoleId != null) {
- sharedPreferences.edit().putString(GeofenceProvider.Companion.getConsoleIdKey(), consoleId).apply();
+ sharedPreferences.edit()
+ .putString(GeofenceProvider.Companion.getConsoleIdKey(), consoleId)
+ .remove(PUSH_PROVIDER_DISABLED_KEY)
+ .apply();
}
// TODO: Implement topic support
String fcmToken = FirebaseInstanceId.getInstance().getToken();
@@ -582,6 +588,7 @@ public class MainActivity extends Activity {
Map<String, Object> response = new HashMap<>();
response.put("action", "PROVIDER_DISABLE");
response.put("provider", "push");
+ sharedPreferences.edit().putBoolean(PUSH_PROVIDER_DISABLED_KEY, true).apply();
notifyClient(response);
}
}
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 63c2136d8..f70b04a71 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
@@ -14,6 +14,7 @@ import com.google.android.gms.location.Geofence
import com.google.android.gms.location.GeofencingClient
import com.google.android.gms.location.GeofencingRequest
import com.google.android.gms.location.LocationServices
+import org.openremote.android.MainActivity
import org.openremote.android.R
import java.net.URL
import java.util.*
@@ -42,8 +43,9 @@ class GeofenceProvider(val context: Context) : ActivityCompat.OnRequestPermissio
companion object {
val baseUrlKey = "baseUrl"
- val consoleIdKey = "consoleId"
+ val consoleIdKey = MainActivity.CONSOLE_ID_KEY
val geofencesKey = "geofences"
+ val geofenceDisabledKey = "geofenceDisabled"
var locationReponseCode = 101
var JSON = ObjectMapper()
val LOG = Logger.getLogger(GeofenceProvider::class.java.name)
@@ -137,6 +139,8 @@ class GeofenceProvider(val context: Context) : ActivityCompat.OnRequestPermissio
var enableCallback: EnableCallback? = null
fun initialize(): Map<String, Any> {
+ val sharedPreferences = context.getSharedPreferences(context.getString(R.string.OR_CONSOLE_NAME), Context.MODE_PRIVATE)
+
return hashMapOf(
"action" to "PROVIDER_INIT",
"provider" to "geofence",
@@ -144,7 +148,8 @@ class GeofenceProvider(val context: Context) : ActivityCompat.OnRequestPermissio
"requiresPermission" to true,
"hasPermission" to (ContextCompat.checkSelfPermission(context, ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED),
"success" to true,
- "enabled" to false
+ "enabled" to false, // Always require enabling to ensure geofences are refresh at startup
+ "disabled" to sharedPreferences.contains(geofenceDisabledKey)
)
}
@@ -155,6 +160,7 @@ class GeofenceProvider(val context: Context) : ActivityCompat.OnRequestPermissio
sharedPreferences.edit()
.putString(baseUrlKey, baseUrl)
.putString(consoleIdKey, consoleId)
+ .remove(geofenceDisabledKey)
.apply()
if(ContextCompat.checkSelfPermission(context, ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
@@ -175,6 +181,7 @@ class GeofenceProvider(val context: Context) : ActivityCompat.OnRequestPermissio
.remove(baseUrlKey)
.remove(consoleIdKey)
.remove(geofencesKey)
+ .putBoolean(geofenceDisabledKey, true)
.apply()
//context.stopService(Intent(context, LocationService::class.java))