Skip to content

Commit

Permalink
* Fix for Android Pie (9) and foreground services permissions
Browse files Browse the repository at this point in the history
* Updated method for displaying 12/24 hour clock
* Ensure url is not null when doing page load on WebView
* Remove restart MQTT service as its not needed
  • Loading branch information
thanksmister committed Nov 23, 2018
1 parent 18b7e81 commit a72160b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ import io.reactivex.Observable
import io.reactivex.ObservableEmitter
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.exceptions.UndeliverableException
import io.reactivex.schedulers.Schedulers

class AlarmPanelService : LifecycleService(), MQTTModule.MQTTListener {
Expand Down Expand Up @@ -152,12 +153,12 @@ class AlarmPanelService : LifecycleService(), MQTTModule.MQTTListener {

this.currentUrl = configuration.webUrl

startForeground()
configureMqtt()
configurePowerOptions()
startHttp()
configureCamera()
configureAudioPlayer()
startForeground()
configureTextToSpeech()
startSensors()

Expand Down Expand Up @@ -312,7 +313,6 @@ class AlarmPanelService : LifecycleService(), MQTTModule.MQTTListener {

private fun configureMqtt() {
if (mqttModule == null && mqttOptions.isValid) {
Timber.d("configureMqtt")
mqttModule = MQTTModule(this@AlarmPanelService.applicationContext, mqttOptions,this@AlarmPanelService)
lifecycle.addObserver(mqttModule!!)
publishState(COMMAND_STATE, state.toString())
Expand All @@ -336,7 +336,7 @@ class AlarmPanelService : LifecycleService(), MQTTModule.MQTTListener {
mqttAlertMessageShown = true
sendAlertMessage(getString(R.string.error_mqtt_connection))
}
reconnectHandler.postDelayed(restartMqttRunnable, 30000)
//reconnectHandler.postDelayed(restartMqttRunnable, 30000)
}
}

Expand All @@ -347,7 +347,7 @@ class AlarmPanelService : LifecycleService(), MQTTModule.MQTTListener {
mqttAlertMessageShown = true
sendAlertMessage(getString(R.string.error_mqtt_exception))
}
reconnectHandler.postDelayed(restartMqttRunnable, 30000)
//reconnectHandler.postDelayed(restartMqttRunnable, 30000)
}
}

Expand Down Expand Up @@ -887,7 +887,13 @@ class AlarmPanelService : LifecycleService(), MQTTModule.MQTTListener {
emitter.onNext(true) // Pass on the data to subscriber
}
override fun onException(message: String?) {
emitter.onError(Throwable(message))
if(message != null) {
try {
emitter.onError(Throwable(message))
} catch (e: UndeliverableException) {
Timber.e(e.message)
}
}
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import android.os.Bundle
import android.os.Handler
import android.os.Looper.getMainLooper
import android.support.v4.content.res.ResourcesCompat
import android.text.format.DateUtils
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
Expand Down Expand Up @@ -62,7 +63,8 @@ class InformationFragment : BaseFragment() {
private val timeRunnable = object : Runnable {
override fun run() {
val currentDateString = DateFormat.getDateInstance(DateFormat.LONG, Locale.getDefault()).format(Date())
val currentTimeString = DateFormat.getTimeInstance(DateFormat.DEFAULT, Locale.getDefault()).format(Date())
//val currentTimeString = DateFormat.getTimeInstance(DateFormat.DEFAULT, Locale.getDefault()).format(Date())
val currentTimeString = DateUtils.formatDateTime(context, Date().time, DateUtils.FORMAT_SHOW_TIME);
dateText.text = currentDateString
timeText.text = currentTimeString
if (timeHandler != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ class PlatformFragment : BaseFragment() {
if(progressDialog != null) {
progressDialog.visibility = View.GONE
}
pageLoadComplete(view.url)
if(view.url != null) {
pageLoadComplete(view.url)
}
return
}
if(displayProgress) {
Expand Down Expand Up @@ -199,6 +201,7 @@ class PlatformFragment : BaseFragment() {
Toast.makeText(activity, description, Toast.LENGTH_SHORT).show()
}
}
// TODO we need to load SSL certificates
override fun onReceivedSslError(view: WebView, handler: SslErrorHandler?, error: SslError?) {
super.onReceivedSslError(view, handler, error)
var message = getString(R.string.dialog_message_ssl_generic)
Expand Down Expand Up @@ -234,7 +237,7 @@ class PlatformFragment : BaseFragment() {
}
}

private fun pageLoadComplete(url: String) {
private fun pageLoadComplete(url: String?) {
Timber.d("pageLoadComplete currentUrl $url")
val intent = Intent(AlarmPanelService.BROADCAST_EVENT_URL_CHANGE)
intent.putExtra(AlarmPanelService.BROADCAST_EVENT_URL_CHANGE, url)
Expand Down

0 comments on commit a72160b

Please sign in to comment.