Skip to content

Commit

Permalink
* Fix for crash on Android 9 devices and starting services
Browse files Browse the repository at this point in the history
* Fix for crash when no WebView component present on device
* Fix for crash on some older Android devices with waking the device
  • Loading branch information
thanksmister committed Aug 31, 2018
1 parent 1312d9d commit 6539f8f
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 15 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ repositories {
def versionMajor = 0
def versionMinor = 8
def versionPatch = 3
def versionBuild = 1 // bump for dog food builds, public betas, etc.
def versionBuild = 2 // bump for dog food builds, public betas, etc.

def ALARM_CODE() {
Properties properties = new Properties()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ class AlarmPanelService : LifecycleService(), MQTTModule.MQTTListener {
@SuppressLint("WakelockTimeout")
private fun configurePowerOptions() {
Timber.d("configurePowerOptions")
if (!partialWakeLock!!.isHeld) {
if (partialWakeLock != null && !partialWakeLock!!.isHeld) {
partialWakeLock!!.acquire(3000)
}
if (!wifiLock!!.isHeld) {
Expand Down Expand Up @@ -605,10 +605,10 @@ class AlarmPanelService : LifecycleService(), MQTTModule.MQTTListener {
@SuppressLint("WakelockTimeout")
private fun switchScreenOn(awakeTime: Long) {
Timber.d("switchScreenOn")
if (!partialWakeLock!!.isHeld) {
if (partialWakeLock != null && !partialWakeLock!!.isHeld) {
Timber.d("partialWakeLock")
partialWakeLock!!.acquire(awakeTime)
} else {
} else if (partialWakeLock != null && partialWakeLock!!.isHeld) {
Timber.d("new partialWakeLock")
partialWakeLock!!.release()
partialWakeLock!!.acquire(awakeTime)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,11 @@ class MainActivity : BaseActivity(), ViewPager.OnPageChangeListener, ControlsFra
super.onStart()
Timber.d("onStart")
alarmPanelService = Intent(this, AlarmPanelService::class.java)
startService(alarmPanelService)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
startForegroundService(alarmPanelService)
} else {
startService(alarmPanelService)
}
}

override fun onStop() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,21 @@ class PlatformFragment : BaseFragment() {
private var displayProgress = true
private var zoomLevel = 1.0f
private val mOnScrollChangedListener: ViewTreeObserver.OnScrollChangedListener? = null
private var hasWebView:Boolean = true;

interface OnPlatformFragmentListener {
fun navigateAlarmPanel()
fun setPagingEnabled(value: Boolean)
}

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.fragment_platform, container, false)
try {
return inflater.inflate(R.layout.fragment_platform, container, false)
} catch (e: Exception) {
Timber.e(e.message)
hasWebView = true;
return inflater.inflate(R.layout.fragment_platform_no_webview, container, false)
}
}

override fun onAttach(context: Context?) {
Expand Down Expand Up @@ -144,7 +151,8 @@ class PlatformFragment : BaseFragment() {

private fun loadWebPage() {
Timber.d("loadWebPage url ${configuration.webUrl}")
if (configuration.hasPlatformModule() && !TextUtils.isEmpty(configuration.webUrl) && webView != null) {
if (configuration.hasPlatformModule() && !TextUtils.isEmpty(configuration.webUrl)
&& webView != null && hasWebView) {
configureWebSettings(configuration.browserUserAgent)
webView.webChromeClient = object : WebChromeClient() {
override fun onProgressChanged(view: WebView, newProgress: Int) {
Expand Down Expand Up @@ -194,13 +202,15 @@ class PlatformFragment : BaseFragment() {
SslError.SSL_NOTYETVALID -> message = getString(R.string.dialog_message_ssl_not_yet_valid)
}
message += getString(R.string.dialog_message_ssl_continue)
dialogUtils.showAlertDialog(activity!!, getString(R.string.dialog_title_ssl_error), message,
DialogInterface.OnClickListener { _, _ ->
handler?.proceed()
},
DialogInterface.OnClickListener { _, _ ->
handler?.cancel()
})
if(isAdded && activity != null) {
dialogUtils.showAlertDialog(activity!!, getString(R.string.dialog_title_ssl_error), message,
DialogInterface.OnClickListener { _, _ ->
handler?.proceed()
},
DialogInterface.OnClickListener { _, _ ->
handler?.cancel()
})
}
}
}
if (zoomLevel.toDouble() != 1.0) {
Expand Down Expand Up @@ -237,7 +247,7 @@ class PlatformFragment : BaseFragment() {
webSettings.databaseEnabled = true
webSettings.setAppCacheEnabled(true)
webSettings.javaScriptCanOpenWindowsAutomatically = true
if(!TextUtils.isEmpty(userAgent)) {
if (!TextUtils.isEmpty(userAgent)) {
webSettings.userAgentString = userAgent
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Expand Down
57 changes: 57 additions & 0 deletions app/src/main/res/layout/fragment_platform_no_webview.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<!--
~ Copyright (c) 2018 ThanksMister LLC
~
~ Licensed 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.
-->

<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipeContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:scrollbars="none">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:windowSoftInputMode="adjustResize">

<TextView
android:padding="16dp"
android:layout_centerInParent="true"
style="@style/TextAppearance.TextMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/dialog_missing_webview_warning"/>

<include
layout="@layout/dialog_progress"
android:visibility="gone"
tools:visibility="visible"/>

</RelativeLayout>

</android.support.v4.widget.SwipeRefreshLayout>

<!-- include bottom sheet -->
<include layout="@layout/bottom_sheet"/>

</android.support.design.widget.CoordinatorLayout >
2 changes: 2 additions & 0 deletions app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,8 @@
<string name="dialog_message_ssl_expired">El certificado ha expirado.</string>
<string name="dialog_message_ssl_untrusted">La autoridad de certificación no es de confianza.</string>
<string name="dialog_message_ssl_generic">Error de certificado SSL.</string>
<string name="dialog_missing_webview_warning">Este dispositivo no tiene instalado el componente WebView. Instale el componente en Google Play Store.</string>


<string-array name="inactivity_times">
<item>15 segundos</item>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-nl/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,8 @@
<string name="dialog_message_ssl_expired">Het certificaat is verlopen.</string>
<string name="dialog_message_ssl_untrusted">De certificeringsinstantie wordt niet vertrouwd.</string>
<string name="dialog_message_ssl_generic">SSL-certificaatfout.</string>
<string name="dialog_missing_webview_warning">Op dit apparaat is de WebView-component niet geïnstalleerd. Installeer het onderdeel van de Google Play Store.</string>


<string-array name="inactivity_times">
<item>15 seconden</item>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-pt/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,8 @@
<string name="dialog_message_ssl_expired">O certificado expirou.</string>
<string name="dialog_message_ssl_untrusted">A autoridade de certificação não é confiável.</string>
<string name="dialog_message_ssl_generic">Erro de certificado SSL.</string>
<string name="dialog_missing_webview_warning">Este dispositivo não possui o componente WebView instalado. Instale o componente na loja do Google Play.</string>


<string-array name="inactivity_times">
<item>15 segundos</item>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@
<string name="dialog_message_ssl_expired">The certificate has expired.</string>
<string name="dialog_message_ssl_untrusted">The certificate authority is not trusted.</string>
<string name="dialog_message_ssl_generic">SSL certificate error.</string>
<string name="dialog_missing_webview_warning">This device does not have the WebView component installed, please install the component from the Google Play store.</string>

<string-array name="inactivity_times">
<item>15 seconds</item>
Expand Down

0 comments on commit 6539f8f

Please sign in to comment.