Skip to content

armgit / core

Public Imported from GitHub
0

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

Consoles: Relative URLs support and improved error handling (#670)

Michael Rademakerbcfc9a5836a9
diff --git a/console/android/GenericApp/app/build.gradle b/console/android/GenericApp/app/build.gradle
index b70cc079e..ee30d20a9 100644
--- a/console/android/GenericApp/app/build.gradle
+++ b/console/android/GenericApp/app/build.gradle
@@ -10,7 +10,7 @@ android {
applicationId "io.openremote.app"
minSdkVersion 25
targetSdkVersion 32
- versionCode 31
+ versionCode 32
versionName "1.0.10"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
@@ -48,4 +48,4 @@ dependencies {
implementation 'com.google.firebase:firebase-messaging-ktx'
implementation 'com.google.android.material:material:1.5.0'
implementation project(':ORLib')
-}
\ No newline at end of file
+}
diff --git a/console/android/GenericApp/app/src/main/java/io/openremote/app/ui/ProjectActivity.kt b/console/android/GenericApp/app/src/main/java/io/openremote/app/ui/ProjectActivity.kt
index 40abd6db9..b09ac1eba 100644
--- a/console/android/GenericApp/app/src/main/java/io/openremote/app/ui/ProjectActivity.kt
+++ b/console/android/GenericApp/app/src/main/java/io/openremote/app/ui/ProjectActivity.kt
@@ -11,14 +11,15 @@ import android.widget.Toast
import androidx.preference.PreferenceManager
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import io.openremote.app.databinding.ActivityProjectBinding
+import io.openremote.orlib.ORConstants
import io.openremote.orlib.network.ApiManager
import io.openremote.orlib.ui.OrMainActivity
class ProjectActivity : Activity() {
private lateinit var binding: ActivityProjectBinding
+ private lateinit var sharedPreferences: SharedPreferences
- var sharedPreferences: SharedPreferences? = null
var host: String? = null
override fun onCreate(savedInstanceState: Bundle?) {
@@ -49,17 +50,18 @@ class ProjectActivity : Activity() {
private fun requestAppConfig(project: String, realm: String) {
binding.progressBar.visibility = View.VISIBLE
- host = if (URLUtil.isValidUrl(project)) project else "https://${project}.openremote.io/"
- val url = if (URLUtil.isValidUrl(project)) project.plus("/api/${realm}") else "https://${project}.openremote.io/api/${realm}"
+ host = if (URLUtil.isValidUrl(project)) project else "https://${project}.openremote.app/"
+ val url = if (URLUtil.isValidUrl(project)) project.plus("/api/${realm}") else "https://${project}.openremote.app/api/${realm}"
val apiManager = ApiManager(url)
apiManager.getAppConfig(realm) { statusCode, appConfig, error ->
binding.progressBar.visibility = View.INVISIBLE
if (statusCode in 200..299) {
- sharedPreferences?.edit()?.putString("host", host)?.apply()
- sharedPreferences?.edit()?.putString("realm", realm)?.apply()
+ sharedPreferences.edit().putString(ORConstants.HOST_KEY, host)
+ .putString(ORConstants.REALM_KEY, realm)
+ .apply()
val intent = Intent(this@ProjectActivity, OrMainActivity::class.java)
- intent.putExtra(OrMainActivity.APP_CONFIG_KEY, jacksonObjectMapper().writeValueAsString(appConfig))
- intent.putExtra(OrMainActivity.BASE_URL_KEY, host)
+ intent.putExtra(ORConstants.APP_CONFIG_KEY, jacksonObjectMapper().writeValueAsString(appConfig))
+ intent.putExtra(ORConstants.BASE_URL_KEY, host)
startActivity(intent)
finish()
} else {
@@ -73,4 +75,4 @@ class ProjectActivity : Activity() {
}
}
}
-}
\ No newline at end of file
+}
diff --git a/console/android/GenericApp/app/src/main/java/io/openremote/app/ui/SplashActivity.kt b/console/android/GenericApp/app/src/main/java/io/openremote/app/ui/SplashActivity.kt
index 2cee8f953..5aa1e0853 100644
--- a/console/android/GenericApp/app/src/main/java/io/openremote/app/ui/SplashActivity.kt
+++ b/console/android/GenericApp/app/src/main/java/io/openremote/app/ui/SplashActivity.kt
@@ -7,18 +7,19 @@ import android.os.Bundle
import androidx.preference.PreferenceManager
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import io.openremote.app.databinding.ActivitySplashBinding
+import io.openremote.orlib.ORConstants
import io.openremote.orlib.network.ApiManager
import io.openremote.orlib.ui.OrMainActivity
import io.openremote.orlib.ui.OrPrivacyPolicyActivity
class SplashActivity : Activity() {
- private val SHOW_CONDITIONS_REQUEST = 34563
+ object SplashActivityConstants {
+ const val SHOW_CONDITIONS_REQUEST = 34563
+ }
private lateinit var binding: ActivitySplashBinding
-
- var sharedPreferences: SharedPreferences? = null
- var host: String? = null
+ private lateinit var sharedPreferences: SharedPreferences
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@@ -28,19 +29,19 @@ class SplashActivity : Activity() {
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this)
- val privacyPolicyAccepted = sharedPreferences!!.getBoolean("privacyPolicyAccepted", false)
+ val privacyPolicyAccepted = sharedPreferences.getBoolean("privacyPolicyAccepted", false)
if (!privacyPolicyAccepted) {
val intent = Intent(this@SplashActivity, OrPrivacyPolicyActivity::class.java)
- startActivityForResult(intent, SHOW_CONDITIONS_REQUEST)
+ startActivityForResult(intent, SplashActivityConstants.SHOW_CONDITIONS_REQUEST)
} else {
startNextActivity()
}
}
private fun startNextActivity() {
- val host = sharedPreferences!!.getString("host", null)
- val realm = sharedPreferences!!.getString("realm", null)
+ val host = sharedPreferences.getString(ORConstants.HOST_KEY, null)
+ val realm = sharedPreferences.getString(ORConstants.REALM_KEY, null)
if (!host.isNullOrBlank() && !realm.isNullOrBlank()) {
val url = host.plus("/api/${realm}")
@@ -48,8 +49,8 @@ class SplashActivity : Activity() {
apiManager.getAppConfig(realm) { statusCode, appConfig, error ->
if (statusCode in 200..299) {
val intent = Intent(this@SplashActivity, OrMainActivity::class.java)
- intent.putExtra(OrMainActivity.APP_CONFIG_KEY, jacksonObjectMapper().writeValueAsString(appConfig))
- intent.putExtra(OrMainActivity.BASE_URL_KEY, host)
+ intent.putExtra(ORConstants.APP_CONFIG_KEY, jacksonObjectMapper().writeValueAsString(appConfig))
+ intent.putExtra(ORConstants.BASE_URL_KEY, host)
startActivity(intent)
finish()
} else {
@@ -64,12 +65,12 @@ class SplashActivity : Activity() {
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
- if(requestCode == SHOW_CONDITIONS_REQUEST) {
+ if(requestCode == SplashActivityConstants.SHOW_CONDITIONS_REQUEST) {
if (resultCode == RESULT_OK) {
- sharedPreferences!!.edit().putBoolean("privacyPolicyAccepted", true).apply()
+ sharedPreferences.edit().putBoolean("privacyPolicyAccepted", true).apply()
startNextActivity()
}
}
super.onActivityResult(requestCode, resultCode, data)
}
-}
\ No newline at end of file
+}
diff --git a/console/android/GenericApp/app/src/main/res/layout/activity_project.xml b/console/android/GenericApp/app/src/main/res/layout/activity_project.xml
index 978782688..9f4c24931 100644
--- a/console/android/GenericApp/app/src/main/res/layout/activity_project.xml
+++ b/console/android/GenericApp/app/src/main/res/layout/activity_project.xml
@@ -109,4 +109,4 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
-</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
+</androidx.constraintlayout.widget.ConstraintLayout>
diff --git a/console/android/ORLib/src/main/AndroidManifest.xml b/console/android/ORLib/src/main/AndroidManifest.xml
index 4101d86f0..ff910fdb3 100644
--- a/console/android/ORLib/src/main/AndroidManifest.xml
+++ b/console/android/ORLib/src/main/AndroidManifest.xml
@@ -3,5 +3,6 @@
package="io.openremote.orlib">
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
+ <uses-permission android:name="android.permission.BROADCAST_CLOSE_SYSTEM_DIALOGS" />
<uses-permission android:name="android.permission.CAMERA" />
-</manifest>
\ No newline at end of file
+</manifest>
diff --git a/console/android/ORLib/src/main/java/io/openremote/orlib/ORConstants.kt b/console/android/ORLib/src/main/java/io/openremote/orlib/ORConstants.kt
new file mode 100644
index 000000000..dd288d297
--- /dev/null
+++ b/console/android/ORLib/src/main/java/io/openremote/orlib/ORConstants.kt
@@ -0,0 +1,14 @@
+package io.openremote.orlib
+
+object ORConstants {
+ const val WRITE_PERMISSION_FOR_DOWNLOAD = 999
+ const val WRITE_PERMISSION_FOR_LOGGING = 1000
+ const val WEBVIEW_LOAD_TIMEOUT_DEFAULT = 5000
+ const val ACTION_BROADCAST = "ACTION_BROADCAST"
+ const val PUSH_PROVIDER_DISABLED_KEY = "PushProviderDisabled"
+ const val CONSOLE_ID_KEY = "consoleId"
+ const val APP_CONFIG_KEY = "APP_CONFIG_KEY"
+ const val BASE_URL_KEY = "BASE_URL_KEY"
+ const val HOST_KEY = "host"
+ const val REALM_KEY = "realm"
+}
diff --git a/console/android/ORLib/src/main/java/io/openremote/orlib/service/GeofenceProvider.kt b/console/android/ORLib/src/main/java/io/openremote/orlib/service/GeofenceProvider.kt
index b3cbf5ffc..097d56bf8 100644
--- a/console/android/ORLib/src/main/java/io/openremote/orlib/service/GeofenceProvider.kt
+++ b/console/android/ORLib/src/main/java/io/openremote/orlib/service/GeofenceProvider.kt
@@ -12,8 +12,10 @@ import androidx.appcompat.app.AlertDialog
import androidx.core.app.ActivityCompat
import com.fasterxml.jackson.databind.ObjectMapper
import com.google.android.gms.location.*
+import io.openremote.orlib.ORConstants
import io.openremote.orlib.R
import io.openremote.orlib.ui.OrMainActivity
+import java.lang.invoke.ConstantCallSite
import java.net.URL
import java.util.*
import java.util.logging.Level
@@ -40,12 +42,10 @@ class GeofenceProvider(val context: Context) {
}
companion object {
- val locationPermissionAskedKey = "LocationPermissionAsked"
- val baseUrlKey = "baseUrl"
- val consoleIdKey = OrMainActivity.CONSOLE_ID_KEY
- val geofencesKey = "geofences"
- val geofenceDisabledKey = "geofenceDisabled"
- val locationResponseCode = 101
+ const val locationPermissionAskedKey = "LocationPermissionAsked"
+ const val geofencesKey = "geofences"
+ const val geofenceDisabledKey = "geofenceDisabled"
+ const val locationResponseCode = 101
val JSON = ObjectMapper()
val LOG = Logger.getLogger(GeofenceProvider::class.java.name)
@@ -128,7 +128,7 @@ class GeofenceProvider(val context: Context) {
private fun getGeofencePendingIntent(context: Context, baseURL: String): PendingIntent {
val intent = Intent(context, GeofenceTransitionsIntentService::class.java)
- intent.putExtra(baseUrlKey, baseURL)
+ intent.putExtra(ORConstants.BASE_URL_KEY, baseURL)
// We use FLAG_UPDATE_CURRENT so that we get the same pending intent back when calling
// addGeofences() and removeGeofences().
return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)
@@ -139,7 +139,7 @@ class GeofenceProvider(val context: Context) {
context.getString(R.string.app_name),
Context.MODE_PRIVATE
)
- return sharedPreferences.getString(baseUrlKey, null)
+ return sharedPreferences.getString(ORConstants.BASE_URL_KEY, null)
}
private fun getConsoleId(context: Context): String? {
@@ -147,7 +147,7 @@ class GeofenceProvider(val context: Context) {
context.getString(R.string.app_name),
Context.MODE_PRIVATE
)
- return sharedPreferences.getString(consoleIdKey, null)
+ return sharedPreferences.getString(ORConstants.CONSOLE_ID_KEY, null)
}
}
@@ -213,8 +213,8 @@ class GeofenceProvider(val context: Context) {
context.getSharedPreferences(context.getString(R.string.app_name), Context.MODE_PRIVATE)
sharedPreferences.edit()
- .putString(baseUrlKey, baseUrl)
- .putString(consoleIdKey, consoleId)
+ .putString(ORConstants.BASE_URL_KEY, baseUrl)
+ .putString(ORConstants.CONSOLE_ID_KEY, consoleId)
.remove(geofenceDisabledKey)
.apply()
@@ -251,8 +251,8 @@ class GeofenceProvider(val context: Context) {
removeGeofences(getGeofences(context))
sharedPreferences.edit()
- .remove(baseUrlKey)
- .remove(consoleIdKey)
+ .remove(ORConstants.BASE_URL_KEY)
+ .remove(ORConstants.CONSOLE_ID_KEY)
.remove(geofencesKey)
.putBoolean(geofenceDisabledKey, true)
.apply()
@@ -470,4 +470,4 @@ class GeofenceProvider(val context: Context) {
}
}
}
-}
\ No newline at end of file
+}
diff --git a/console/android/ORLib/src/main/java/io/openremote/orlib/service/GeofenceTransitionsIntentService.kt b/console/android/ORLib/src/main/java/io/openremote/orlib/service/GeofenceTransitionsIntentService.kt
index e1471f8f0..665c83e9d 100644
--- a/console/android/ORLib/src/main/java/io/openremote/orlib/service/GeofenceTransitionsIntentService.kt
+++ b/console/android/ORLib/src/main/java/io/openremote/orlib/service/GeofenceTransitionsIntentService.kt
@@ -7,6 +7,7 @@ import android.util.Pair
import com.fasterxml.jackson.databind.ObjectMapper
import com.google.android.gms.location.Geofence
import com.google.android.gms.location.GeofencingEvent
+import io.openremote.orlib.ORConstants
import java.net.HttpURLConnection
import java.net.URL
import java.util.*
@@ -38,7 +39,7 @@ class GeofenceTransitionsIntentService : BroadcastReceiver() {
return
}
- val baseUrl = intent.getStringExtra(GeofenceProvider.baseUrlKey)
+ val baseUrl = intent.getStringExtra(ORConstants.BASE_URL_KEY)
val geofenceTransition = geofencingEvent.geofenceTransition
val trans = if (geofenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER) "ENTER" else "EXIT"
@@ -168,4 +169,4 @@ class GeofenceTransitionsIntentService : BroadcastReceiver() {
return success
}
-}
\ No newline at end of file
+}
diff --git a/console/android/ORLib/src/main/java/io/openremote/orlib/service/NotificationResource.kt b/console/android/ORLib/src/main/java/io/openremote/orlib/service/NotificationResource.kt
index 98dfba805..e433a09bb 100644
--- a/console/android/ORLib/src/main/java/io/openremote/orlib/service/NotificationResource.kt
+++ b/console/android/ORLib/src/main/java/io/openremote/orlib/service/NotificationResource.kt
@@ -3,6 +3,7 @@ package io.openremote.orlib.service
import android.content.Context
import android.content.SharedPreferences
import androidx.preference.PreferenceManager
+import io.openremote.orlib.ORConstants
import java.net.HttpURLConnection
import java.net.URL
import java.util.concurrent.Executors
@@ -13,41 +14,37 @@ class NotificationResource(context: Context) {
PreferenceManager.getDefaultSharedPreferences(context)
fun executeRequest(httpMethod: String, appUrl: String, data: String?) {
- val project = sharedPreferences.getString("project", null)
- val realm = sharedPreferences.getString("realm", null)
-
- if (!project.isNullOrBlank() && !realm.isNullOrBlank()) {
- Executors.newCachedThreadPool().execute {
- URL(appUrl)
- .openConnection()
- .let {
- it as HttpURLConnection
- }.apply {
- requestMethod = httpMethod
- setRequestProperty("Accept", "application/json")
-
- if (!data.isNullOrBlank()) {
- setRequestProperty("Content-Type", "application/json")
- doOutput = true
+ Executors.newCachedThreadPool().execute {
+ URL(appUrl)
+ .openConnection()
+ .let {
+ it as HttpURLConnection
+ }.apply {
+ requestMethod = httpMethod
+ setRequestProperty("Accept", "application/json")
+
+ if (!data.isNullOrBlank()) {
+ setRequestProperty("Content-Type", "application/json")
+ doOutput = true
- val outputWriter = outputStream.bufferedWriter()
- outputWriter.write(data)
- outputWriter.flush()
- }
+ val outputWriter = outputStream.bufferedWriter()
+ outputWriter.write(data)
+ outputWriter.flush()
}
- }
+ }
}
}
fun notificationDelivered(notificationId: Long, fcmToken: String?) {
LOG.info("Notification status update 'delivered': $notificationId")
- val project = sharedPreferences.getString("project", null)
- val realm = sharedPreferences.getString("realm", null)
+ val host = sharedPreferences.getString(ORConstants.HOST_KEY, null)
+ val realm = sharedPreferences.getString(ORConstants.REALM_KEY, null)
- if (!project.isNullOrBlank() && !realm.isNullOrBlank()) {
+ if (!host.isNullOrBlank() && !realm.isNullOrBlank()) {
+ val url = host.plus("/api/${realm}")
Executors.newCachedThreadPool().execute {
- URL("https://${project}.openremote.io/api/$realm/notification/${notificationId}/delivered?targetId=$fcmToken")
+ URL("${url}/notification/${notificationId}/delivered?targetId=$fcmToken")
.openConnection()
.let {
it as HttpURLConnection
@@ -68,12 +65,13 @@ class NotificationResource(context: Context) {
fcmToken: String?,
acknowledgement: String?
) {
- val project = sharedPreferences.getString("project", null)
- val realm = sharedPreferences.getString("realm", null)
+ val host = sharedPreferences.getString(ORConstants.HOST_KEY, null)
+ val realm = sharedPreferences.getString(ORConstants.REALM_KEY, null)
- if (!project.isNullOrBlank() && !realm.isNullOrBlank()) {
+ if (!host.isNullOrBlank() && !realm.isNullOrBlank()) {
+ val url = host.plus("/api/${realm}")
Executors.newCachedThreadPool().execute {
- URL("https://${project}.openremote.io/api/$realm/notification/${notificationId}/acknowledged?targetId=$fcmToken")
+ URL("${url}/notification/${notificationId}/acknowledged?targetId=$fcmToken")
.openConnection()
.let {
it as HttpURLConnection
@@ -100,4 +98,4 @@ class NotificationResource(context: Context) {
NotificationResource::class.java.name
)
}
-}
\ No newline at end of file
+}
diff --git a/console/android/ORLib/src/main/java/io/openremote/orlib/service/ORFirebaseMessagingService.kt b/console/android/ORLib/src/main/java/io/openremote/orlib/service/ORFirebaseMessagingService.kt
index 585f005c4..044329995 100644
--- a/console/android/ORLib/src/main/java/io/openremote/orlib/service/ORFirebaseMessagingService.kt
+++ b/console/android/ORLib/src/main/java/io/openremote/orlib/service/ORFirebaseMessagingService.kt
@@ -13,6 +13,7 @@ import androidx.core.app.NotificationCompat
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.google.firebase.messaging.RemoteMessage
+import io.openremote.orlib.ORConstants
import io.openremote.orlib.R
import io.openremote.orlib.models.ORAlertAction
import io.openremote.orlib.models.ORAlertButton
@@ -90,7 +91,7 @@ class ORFirebaseMessagingService : com.google.firebase.messaging.FirebaseMessagi
geofenceProvider.refreshGeofences()
}
else -> {
- val broadCastIntent = Intent(OrMainActivity.ACTION_BROADCAST)
+ val broadCastIntent = Intent(ORConstants.ACTION_BROADCAST)
broadCastIntent.putExtra("action", action)
sendBroadcast(broadCastIntent)
}
diff --git a/console/android/ORLib/src/main/java/io/openremote/orlib/service/ORMessagingActionService.kt b/console/android/ORLib/src/main/java/io/openremote/orlib/service/ORMessagingActionService.kt
index 2e85eb9a2..8b03ab94a 100644
--- a/console/android/ORLib/src/main/java/io/openremote/orlib/service/ORMessagingActionService.kt
+++ b/console/android/ORLib/src/main/java/io/openremote/orlib/service/ORMessagingActionService.kt
@@ -6,6 +6,7 @@ import android.app.NotificationManager
import android.net.Uri
import io.openremote.orlib.R
import android.text.TextUtils
+import io.openremote.orlib.ORConstants
import io.openremote.orlib.ui.OrMainActivity
class ORMessagingActionService : IntentService("org.openremote.android.ORMessagingActionService") {
@@ -25,7 +26,7 @@ class ORMessagingActionService : IntentService("org.openremote.android.ORMessagi
val consoleId = getSharedPreferences(
applicationContext.getString(R.string.app_name),
MODE_PRIVATE
- ).getString("consoleId", "")
+ ).getString(ORConstants.CONSOLE_ID_KEY, "")
if (!TextUtils.isEmpty(consoleId)) {
notificationResource!!.notificationAcknowledged(
notificationId,
@@ -65,4 +66,4 @@ class ORMessagingActionService : IntentService("org.openremote.android.ORMessagi
}
}
}
-}
\ No newline at end of file
+}
diff --git a/console/android/ORLib/src/main/java/io/openremote/orlib/ui/OrMainActivity.kt b/console/android/ORLib/src/main/java/io/openremote/orlib/ui/OrMainActivity.kt
index 57a623719..dee0ccc76 100644
--- a/console/android/ORLib/src/main/java/io/openremote/orlib/ui/OrMainActivity.kt
+++ b/console/android/ORLib/src/main/java/io/openremote/orlib/ui/OrMainActivity.kt
@@ -13,7 +13,6 @@ import android.graphics.Color
import android.net.ConnectivityManager
import android.net.Uri
import android.os.*
-import android.text.TextUtils
import android.view.KeyEvent
import android.view.View
import android.view.ViewGroup
@@ -31,6 +30,7 @@ import com.fasterxml.jackson.core.JsonProcessingException
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.google.android.material.floatingactionbutton.FloatingActionButton
import com.google.firebase.messaging.FirebaseMessaging
+import io.openremote.orlib.ORConstants
import io.openremote.orlib.R
import io.openremote.orlib.databinding.ActivityOrMainBinding
import io.openremote.orlib.models.ORAppConfig
@@ -44,22 +44,29 @@ import java.util.logging.Logger
open class OrMainActivity : Activity() {
+ private val LOG = Logger.getLogger(
+ OrMainActivity::class.java.name
+ )
+
private lateinit var binding: ActivityOrMainBinding
+ private lateinit var sharedPreferences: SharedPreferences
+
+
private var mapper = jacksonObjectMapper()
private val connectivityChangeReceiver: ConnectivityChangeReceiver =
ConnectivityChangeReceiver()
private var timeOutHandler: Handler? = null
private var timeOutRunnable: Runnable? = null
private var progressBar: ProgressBar? = null
- private var webViewTimeout = WEBVIEW_LOAD_TIMEOUT_DEFAULT
+ private var webViewTimeout = ORConstants.WEBVIEW_LOAD_TIMEOUT_DEFAULT
private var webViewLoaded = false
- private var sharedPreferences: SharedPreferences? = null
private var geofenceProvider: GeofenceProvider? = null
private var qrScannerProvider: QrScannerProvider? = null
private var consoleId: String? = null
private var appConfig: ORAppConfig? = null
private var baseUrl: String? = null
- private var onDownloadCompleteReciever: BroadcastReceiver = object : BroadcastReceiver() {
+
+ private var onDownloadCompleteReceiver: BroadcastReceiver = object : BroadcastReceiver() {
override fun onReceive(ctxt: Context, intent: Intent) {
val action = intent.action
if (DownloadManager.ACTION_DOWNLOAD_COMPLETE == action) {
@@ -77,17 +84,18 @@ open class OrMainActivity : Activity() {
if (URLUtil.isValidUrl(appConfig!!.initialUrl)) {
return appConfig!!.initialUrl
} else {
- sharedPreferences?.let { pref ->
- pref.getString("host", null)?.let { host ->
+ sharedPreferences.let { pref ->
+ pref.getString(ORConstants.HOST_KEY, null)?.let { host ->
return host.plus(appConfig!!.initialUrl)
}
}
}
}
- sharedPreferences?.let { pref ->
- pref.getString("host", null)?.let { host ->
- pref.getString("realm", null)?.let { realm ->
+
+ sharedPreferences.let { pref ->
+ pref.getString(ORConstants.HOST_KEY, null)?.let { host ->
+ pref.getString(ORConstants.REALM_KEY, null)?.let { realm ->
returnValue = host.plus("/api/${realm}")
}
}
@@ -127,21 +135,22 @@ open class OrMainActivity : Activity() {
progressBar?.max = 100
progressBar?.progress = 1
- if (intent.hasExtra(APP_CONFIG_KEY)) {
+ if (intent.hasExtra(ORConstants.APP_CONFIG_KEY)) {
appConfig = mapper.readValue(
- intent.getStringExtra(APP_CONFIG_KEY),
+ intent.getStringExtra(ORConstants.APP_CONFIG_KEY),
ORAppConfig::class.java
)
}
- if (intent.hasExtra(BASE_URL_KEY)) {
- baseUrl = intent.getStringExtra(BASE_URL_KEY)
+
+ if (intent.hasExtra(ORConstants.BASE_URL_KEY)) {
+ baseUrl = intent.getStringExtra(ORConstants.BASE_URL_KEY)
}
if (appConfig == null) {
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this)
- val host = sharedPreferences!!.getString("host", null)
- val realm = sharedPreferences!!.getString("realm", null)
+ val host = sharedPreferences.getString(ORConstants.HOST_KEY, null)
+ val realm = sharedPreferences.getString(ORConstants.REALM_KEY, null)
if (!host.isNullOrBlank() && !realm.isNullOrBlank()) {
val url = host.plus("/api/${realm}")
@@ -279,7 +288,7 @@ open class OrMainActivity : Activity() {
IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)
)
registerReceiver(
- onDownloadCompleteReciever,
+ onDownloadCompleteReceiver,
IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)
)
}
@@ -287,7 +296,7 @@ open class OrMainActivity : Activity() {
override fun onPause() {
super.onPause()
unregisterReceiver(connectivityChangeReceiver)
- unregisterReceiver(onDownloadCompleteReciever)
+ unregisterReceiver(onDownloadCompleteReceiver)
}
override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean {
@@ -457,7 +466,7 @@ open class OrMainActivity : Activity() {
// Write permission has not been granted yet, request it.
requestPermissions(
arrayOf(writePermission),
- WRITE_PERMISSION_FOR_DOWNLOAD
+ ORConstants.WRITE_PERMISSION_FOR_DOWNLOAD
)
} else {
val request = DownloadManager.Request(Uri.parse(url))
@@ -497,10 +506,12 @@ open class OrMainActivity : Activity() {
failingUrl: String?
) {
LOG.warning("Error requesting '$failingUrl': $errorCode($description)")
- //TODO should we always ignore image errors?
+
+ //TODO should we always ignore image errors and locale json files?
if (failingUrl != null && (failingUrl.endsWith("png")
|| failingUrl.endsWith("jpg")
- || failingUrl.endsWith("ico"))
+ || failingUrl.endsWith("ico") ||
+ failingUrl.contains("locales"))
) {
LOG.info("Ignoring error loading image resource")
return
@@ -533,7 +544,7 @@ open class OrMainActivity : Activity() {
permissions: Array<String>,
grantResults: IntArray
) {
- if (requestCode == WRITE_PERMISSION_FOR_DOWNLOAD) {
+ if (requestCode == ORConstants.WRITE_PERMISSION_FOR_DOWNLOAD) {
if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Toast.makeText(applicationContext, R.string.downloading_file, Toast.LENGTH_LONG)
.show()
@@ -618,14 +629,7 @@ open class OrMainActivity : Activity() {
action.equals("PROVIDER_ENABLE", ignoreCase = true) -> {
val consoleId = data.getString("consoleId")
(activity as OrMainActivity).consoleId = consoleId
- val baseUrl = sharedPreferences?.let { pref ->
- pref.getString("project", null)?.let { projectName ->
- pref.getString("realm", null)?.let { realmName ->
- "https://${projectName}.openremote.io/api/$realmName"
- }
- }
- } ?: ""
- geofenceProvider?.enable(this@OrMainActivity, baseUrl,
+ geofenceProvider?.enable(this@OrMainActivity, clientUrl ?: "",
consoleId, object : GeofenceProvider.GeofenceCallback {
override fun accept(responseData: Map<String, Any>) {
notifyClient(responseData)
@@ -665,7 +669,7 @@ open class OrMainActivity : Activity() {
response["provider"] = "push"
response["version"] = "fcm"
response["enabled"] = false
- response["disabled"] = sharedPreferences!!.contains(PUSH_PROVIDER_DISABLED_KEY)
+ response["disabled"] = sharedPreferences.contains(ORConstants.PUSH_PROVIDER_DISABLED_KEY)
response["requiresPermission"] = false
response["hasPermission"] = true
response["success"] = true
@@ -673,9 +677,9 @@ open class OrMainActivity : Activity() {
}
action.equals("PROVIDER_ENABLE", ignoreCase = true) -> {
val consoleId = data.getString("consoleId")
- sharedPreferences!!.edit()
- .putString(GeofenceProvider.Companion.consoleIdKey, consoleId)
- .remove(PUSH_PROVIDER_DISABLED_KEY)
+ sharedPreferences.edit()
+ .putString(ORConstants.CONSOLE_ID_KEY, consoleId)
+ .remove(ORConstants.PUSH_PROVIDER_DISABLED_KEY)
.apply()
// TODO: Implement topic support
FirebaseMessaging.getInstance().token.addOnCompleteListener { task ->
@@ -699,7 +703,7 @@ open class OrMainActivity : Activity() {
val response: MutableMap<String, Any?> = HashMap()
response["action"] = "PROVIDER_DISABLE"
response["provider"] = "push"
- sharedPreferences!!.edit().putBoolean(PUSH_PROVIDER_DISABLED_KEY, true).apply()
+ sharedPreferences.edit().putBoolean(ORConstants.PUSH_PROVIDER_DISABLED_KEY, true).apply()
notifyClient(response)
}
}
@@ -807,7 +811,7 @@ open class OrMainActivity : Activity() {
}
private fun storeData(key: String?, data: String?) {
- val editor = sharedPreferences!!.edit()
+ val editor = sharedPreferences.edit()
if (data == null) {
editor.remove(key)
} else {
@@ -817,7 +821,7 @@ open class OrMainActivity : Activity() {
}
private fun retrieveData(key: String?): Any? {
- var str = sharedPreferences!!.getString(key, null) ?: return null
+ val str = sharedPreferences.getString(key, null) ?: return null
// Parse data JSON
return try {
mapper.readTree(str)
@@ -842,18 +846,4 @@ open class OrMainActivity : Activity() {
onConnectivityChanged(activeNetwork != null && activeNetwork.isConnectedOrConnecting)
}
}
-
- companion object {
- private val LOG = Logger.getLogger(
- OrMainActivity::class.java.name
- )
- private const val WRITE_PERMISSION_FOR_DOWNLOAD = 999
- private const val WRITE_PERMISSION_FOR_LOGGING = 1000
- private const val WEBVIEW_LOAD_TIMEOUT_DEFAULT = 5000
- const val ACTION_BROADCAST = "ACTION_BROADCAST"
- const val PUSH_PROVIDER_DISABLED_KEY = "PushProviderDisabled"
- const val CONSOLE_ID_KEY = "consoleId"
- const val APP_CONFIG_KEY = "APP_CONFIG_KEY"
- const val BASE_URL_KEY = "BASE_URL_KEY"
- }
}
diff --git a/console/iOS/GenericApp/GenericApp.xcodeproj/project.pbxproj b/console/iOS/GenericApp/GenericApp.xcodeproj/project.pbxproj
index 73fcb7370..09e8c0434 100644
--- a/console/iOS/GenericApp/GenericApp.xcodeproj/project.pbxproj
+++ b/console/iOS/GenericApp/GenericApp.xcodeproj/project.pbxproj
@@ -524,7 +524,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = GenericApp/OpenRemote.entitlements;
CODE_SIGN_STYLE = Automatic;
- CURRENT_PROJECT_VERSION = 30;
+ CURRENT_PROJECT_VERSION = 31;
DEVELOPMENT_ASSET_PATHS = "";
DEVELOPMENT_TEAM = 4AC88KZHJZ;
ENABLE_PREVIEWS = YES;
@@ -550,7 +550,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = GenericApp/OpenRemote.entitlements;
CODE_SIGN_STYLE = Automatic;
- CURRENT_PROJECT_VERSION = 30;
+ CURRENT_PROJECT_VERSION = 31;
DEVELOPMENT_ASSET_PATHS = "";
DEVELOPMENT_TEAM = 4AC88KZHJZ;
ENABLE_PREVIEWS = YES;
@@ -575,7 +575,7 @@
APPLICATION_EXTENSION_API_ONLY = YES;
CODE_SIGN_ENTITLEMENTS = NotificationService/NotificationService.entitlements;
CODE_SIGN_STYLE = Automatic;
- CURRENT_PROJECT_VERSION = 29;
+ CURRENT_PROJECT_VERSION = 31;
DEVELOPMENT_TEAM = 4AC88KZHJZ;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
@@ -619,7 +619,7 @@
APPLICATION_EXTENSION_API_ONLY = YES;
CODE_SIGN_ENTITLEMENTS = NotificationService/NotificationService.entitlements;
CODE_SIGN_STYLE = Automatic;
- CURRENT_PROJECT_VERSION = 29;
+ CURRENT_PROJECT_VERSION = 31;
DEVELOPMENT_TEAM = 4AC88KZHJZ;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
diff --git a/console/iOS/GenericApp/GenericApp/AppDelegate.swift b/console/iOS/GenericApp/GenericApp/AppDelegate.swift
index 24c63f893..3cecdf62a 100644
--- a/console/iOS/GenericApp/GenericApp/AppDelegate.swift
+++ b/console/iOS/GenericApp/GenericApp/AppDelegate.swift
@@ -233,17 +233,17 @@ extension AppDelegate : UNUserNotificationCenterDelegate {
let userInfo = response.notification.request.content.userInfo
var notificationId : Int64? = nil
var consoleId : String?
- var project: String?
- var realm: String?
+ var urlString: String?
if let notificationIdString = userInfo[ActionType.notificationId] as? String{
notificationId = Int64(notificationIdString)
}
- if let defaults = UserDefaults(suiteName: DefaultsKey.groupEntitlement) {
- consoleId = defaults.string(forKey: GeofenceProvider.consoleIdKey)
- project = defaults.string(forKey: DefaultsKey.projectKey)
- realm = defaults.string(forKey: DefaultsKey.realmKey)
+ if let userDefaults = UserDefaults(suiteName: DefaultsKey.groupEntitlement) {
+ consoleId = userDefaults.string(forKey: GeofenceProvider.consoleIdKey)
+ let host = userDefaults.string(forKey: DefaultsKey.hostKey)
+ let realm = userDefaults.string(forKey: DefaultsKey.realmKey)
+ urlString = host!.appending("/api/\(realm!)")
}
NSLog("%@", "Action chosen: \(response.actionIdentifier)")
@@ -255,8 +255,8 @@ extension AppDelegate : UNUserNotificationCenterDelegate {
if urlTo.hasPrefix("http") || urlTo.hasPrefix("https") {
urlRequest = URL(string:urlTo)
} else {
- if let projectName = project, let realmName = realm {
- urlRequest = URL(string: "https://\(projectName).remote.io/\(realmName)/console/\(urlTo)")
+ if let url = urlString {
+ urlRequest = URL(string: "\(url)/console/\(urlTo)")
}
}
if let url = urlRequest{
@@ -288,8 +288,8 @@ extension AppDelegate : UNUserNotificationCenterDelegate {
if action.url.hasPrefix("http") || action.url.hasPrefix("https") {
urlRequest = URL(string:action.url)
} else {
- if let projectName = project, let realmName = realm {
- urlRequest = URL(string: "https://\(projectName).remote.io/\(realmName)/console/\(action.url)")
+ if let url = urlString {
+ urlRequest = URL(string: "\(url)/console/\(action.url)")
}
}
if let url = urlRequest {
diff --git a/console/iOS/GenericApp/GenericApp/UI/ProjectViewController.swift b/console/iOS/GenericApp/GenericApp/UI/ProjectViewController.swift
index 6e1603a6f..18f558573 100644
--- a/console/iOS/GenericApp/GenericApp/UI/ProjectViewController.swift
+++ b/console/iOS/GenericApp/GenericApp/UI/ProjectViewController.swift
@@ -71,8 +71,8 @@ extension ProjectViewController: UITextFieldDelegate {
}
fileprivate func requestAppConfig(_ project: String, _ realm: String) {
- host = project.isUrl() ? project : "https://\(project).openremote.io/"
- let url = project.isUrl() ? project.appending("/api/\(realm)") : "https://\(project).openremote.io/api/\(realm)"
+ host = project.isUrl() ? project : "https://\(project).openremote.app/"
+ let url = project.isUrl() ? project.appending("/api/\(realm)") : "https://\(project).openremote.app/api/\(realm)"
let apiManager = ApiManager(baseUrl: url)
apiManager.getAppConfig(realm: realm, callback: { statusCode, orAppConfig, error in
diff --git a/console/iOS/ORLib/ORLib.xcodeproj/project.pbxproj b/console/iOS/ORLib/ORLib.xcodeproj/project.pbxproj
index 9bd274d87..4c4db5338 100644
--- a/console/iOS/ORLib/ORLib.xcodeproj/project.pbxproj
+++ b/console/iOS/ORLib/ORLib.xcodeproj/project.pbxproj
@@ -44,7 +44,7 @@
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
-
+ 37A59C1C5EEB5A3027F557D0 /* Pods-ORLib.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ORLib.release.xcconfig"; path = "../../../Users/michael/Documents/OR/Code/openremote/console/iOS/GenericApp/Pods/Target Support Files/Pods-ORLib/Pods-ORLib.release.xcconfig"; sourceTree = "<group>"; };
3F2140D7DCE68D42273B346B /* Pods-ORLib.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ORLib.debug.xcconfig"; path = "../../../Users/michael/Documents/OR/Code/openremote/console/iOS/GenericApp/Pods/Target Support Files/Pods-ORLib/Pods-ORLib.debug.xcconfig"; sourceTree = "<group>"; };
41E56A0D7E49334C15A35CB4 /* Pods_ORLib.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_ORLib.framework; sourceTree = BUILT_PRODUCTS_DIR; };
4C0E4A0F274BDCE0008CB352 /* ScannerOverlayPreviewLayer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScannerOverlayPreviewLayer.swift; sourceTree = "<group>"; };
@@ -70,10 +70,7 @@
4CF5D06527143F1F00D705BE /* ORPushNotificationAction.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ORPushNotificationAction.swift; sourceTree = "<group>"; };
4CF5D06727143F1F00D705BE /* ORNotificationResource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ORNotificationResource.swift; sourceTree = "<group>"; };
4CF5D06827143F1F00D705BE /* ApiManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ApiManager.swift; sourceTree = "<group>"; };
- 6622F2FF5F233FCAA9475FCC /* Pods-ORLib.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ORLib.release.xcconfig"; path = "../../../michael/Documents/OR/Code/k2/console/iOS/K2/Pods/Target Support Files/Pods-ORLib/Pods-ORLib.release.xcconfig"; sourceTree = "<group>"; };
- 9AE68221D73F2C0743A39184 /* Pods-ORLibrary.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ORLibrary.release.xcconfig"; path = "../../../michael/Documents/OR/Code/eindhoven/console/beatrixkanaal/iOS/Beatrixkanaal/Pods/Target Support Files/Pods-ORLibrary/Pods-ORLibrary.release.xcconfig"; sourceTree = "<group>"; };
- F721AAB633C4A25ACBDD59EE /* Pods_ORLib.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_ORLib.framework; sourceTree = BUILT_PRODUCTS_DIR; };
-
+
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
diff --git a/console/iOS/ORLib/ORLib/Network/ORNotificationResource.swift b/console/iOS/ORLib/ORLib/Network/ORNotificationResource.swift
index d81e9ec3e..cee1fd58d 100644
--- a/console/iOS/ORLib/ORLib/Network/ORNotificationResource.swift
+++ b/console/iOS/ORLib/ORLib/Network/ORNotificationResource.swift
@@ -17,9 +17,10 @@ public class ORNotificationResource: NSObject, URLSessionDelegate {
public func notificationDelivered(notificationId : Int64, targetId : String) {
if let userdefaults = UserDefaults(suiteName: DefaultsKey.groupEntitlement),
- let project = userdefaults.string(forKey: DefaultsKey.projectKey),
+ let host = userdefaults.string(forKey: DefaultsKey.hostKey),
let realm = userdefaults.string(forKey: DefaultsKey.realmKey) {
- guard let urlRequest = URL(string: "https://\(project).openremote.io/\(realm)/notification/\(notificationId)/delivered?targetId=\(targetId)") else { return }
+ let url = host.appending("/api/\(realm)")
+ guard let urlRequest = URL(string: "\(url)/notification/\(notificationId)/delivered?targetId=\(targetId)") else { return }
let request = NSMutableURLRequest(url: urlRequest)
request.httpMethod = "PUT"
let sessionConfiguration = URLSessionConfiguration.default
@@ -41,9 +42,10 @@ public class ORNotificationResource: NSObject, URLSessionDelegate {
public func notificationAcknowledged(notificationId : Int64, targetId : String, acknowledgement: String) {
if let userdefaults = UserDefaults(suiteName: DefaultsKey.groupEntitlement),
- let project = userdefaults.string(forKey: DefaultsKey.projectKey),
+ let host = userdefaults.string(forKey: DefaultsKey.hostKey),
let realm = userdefaults.string(forKey: DefaultsKey.realmKey) {
- guard let urlRequest = URL(string: "https://\(project).openremote.io/\(realm)/notification/\(notificationId)/acknowledged?targetId=\(targetId)") else { return }
+ let url = host.appending("/api/\(realm)")
+ guard let urlRequest = URL(string: "\(url)/notification/\(notificationId)/acknowledged?targetId=\(targetId)") else { return }
let request = NSMutableURLRequest(url: urlRequest)
request.httpMethod = "PUT"
diff --git a/console/iOS/ORLib/ORLib/UI/ORViewController.swift b/console/iOS/ORLib/ORLib/UI/ORViewController.swift
index e1c1b5a2f..17afb48c9 100644
--- a/console/iOS/ORLib/ORLib/UI/ORViewController.swift
+++ b/console/iOS/ORLib/ORLib/UI/ORViewController.swift
@@ -316,9 +316,10 @@ extension ORViewcontroller: WKScriptMessageHandler {
case Actions.providerEnable:
if let consoleId = postMessageDict[GeofenceProvider.consoleIdKey] as? String {
if let userdefaults = UserDefaults(suiteName: DefaultsKey.groupEntitlement),
- let project = userdefaults.string(forKey: DefaultsKey.projectKey),
+ let host = userdefaults.string(forKey: DefaultsKey.hostKey),
let realm = userdefaults.string(forKey: DefaultsKey.realmKey) {
- geofenceProvider?.enable(baseUrl: "https://\(project).openremote.io/api/\(realm)", consoleId: consoleId, callback: { enableData in
+ let baseUrl = host.appending("/api/\(realm)")
+ geofenceProvider?.enable(baseUrl: baseUrl, consoleId: consoleId, callback: { enableData in
self.sendData(data: enableData)
DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(5)) {
self.geofenceProvider?.fetchGeofences()