Skip to content

Commit

Permalink
Crash fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jensck committed Sep 19, 2019
1 parent 47e0cf6 commit ff048b8
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import android.view.View
import android.view.animation.AccelerateInterpolator
import android.view.animation.AnimationUtils
import android.widget.CompoundButton
import android.widget.ImageButton
import android.widget.ImageView
import androidx.appcompat.app.AppCompatActivity
import androidx.constraintlayout.widget.ConstraintLayout
Expand Down Expand Up @@ -252,8 +251,8 @@ class DeviceInfoBottomSheetController(
val deviceId = device.id
scopes.onWorker {
val cloud = ParticleCloudSDK.getCloud()
val device = cloud.getDevice(deviceId)
try {
val device = cloud.getDevice(deviceId)
device.startStopSignaling(shouldSignal)
} catch (ex: Exception) {
log.error(ex) { "Error turning rainbows ${if (shouldSignal) "ON" else "OFF"}" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,13 @@ private <T> T readResponse(Socket socket, Class<T> responseType, int timeoutValu

String responseData = buffer.readUtf8();
log.d("Command response (raw): " + CommandClientUtils.escapeJava(responseData));
T tee = gson.fromJson(responseData, responseType);
T tee;
try {
tee = gson.fromJson(responseData, responseType);
} catch (Exception ex) {
throw new IOException(ex);
}

log.d("Command response: " + tee);
EZ.closeThisThingOrMaybeDont(buffer);
return tee;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ public Network getNetworkObjectForCurrentWifiConnection() {
Arrays.asList(connectivityManager.getAllNetworks()),
network -> {
NetworkCapabilities capabilities = connectivityManager.getNetworkCapabilities(network);
if (capabilities == null) {
return false;
}
// Don't try using the P2P Wi-Fi interfaces on recent Samsung devices
if (capabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_WIFI_P2P)) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ package io.particle.mesh.ui.controlpanel

import androidx.annotation.MainThread
import androidx.annotation.WorkerThread
import androidx.fragment.app.FragmentActivity
import io.particle.android.sdk.cloud.ParticleCloud
import io.particle.android.sdk.cloud.ParticleCloudSDK
import io.particle.android.sdk.cloud.ParticleDevice
import io.particle.mesh.setup.BarcodeData.CompleteBarcodeData
import io.particle.mesh.setup.SerialNumber
import io.particle.mesh.setup.fetchBarcodeData
import io.particle.mesh.setup.flow.FlowRunnerUiListener
import io.particle.mesh.setup.utils.safeToast
import io.particle.mesh.ui.BaseFlowFragment
import io.particle.mesh.ui.TitleBarOptions
import mu.KotlinLogging
Expand All @@ -36,9 +34,20 @@ open class BaseControlPanelFragment : BaseFlowFragment() {
) {
val cloud = ParticleCloudSDK.getCloud()
flowSystemInterface.showGlobalProgressSpinner(true)
val barcode = flowScopes.withWorker { cloud.fetchBarcodeData(device.id) }
val barcode = try {
flowScopes.withWorker {
cloud.fetchBarcodeData(device.id)
}
} catch (ex: Exception) {
null
}
flowSystemInterface.showGlobalProgressSpinner(false)

if (barcode == null) {
activity?.safeToast("Unable to communicate with the Particle Cloud. Please try again.")
return
}

flowStarter(device, barcode)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.annotation.StringRes
import androidx.appcompat.app.AlertDialog
import androidx.fragment.app.FragmentActivity
import androidx.navigation.fragment.findNavController
import io.particle.android.sdk.cloud.models.ParticleApiSimStatus
import io.particle.android.sdk.cloud.models.ParticleApiSimStatus.ACTIVE
import io.particle.android.sdk.cloud.models.ParticleApiSimStatus.INACTIVE_DATA_LIMIT_REACHED
import io.particle.android.sdk.cloud.models.ParticleApiSimStatus.INACTIVE_INVALID_PAYMENT_METHOD
import io.particle.android.sdk.cloud.models.ParticleApiSimStatus.INACTIVE_NEVER_ACTIVATED
import io.particle.android.sdk.cloud.models.ParticleApiSimStatus.INACTIVE_USER_DEACTIVATED
import io.particle.android.sdk.utils.pass
import io.particle.mesh.common.QATool
import io.particle.mesh.setup.flow.FlowRunnerUiListener
import io.particle.mesh.setup.flow.SimStatusChangeMode
import io.particle.mesh.ui.R
import io.particle.mesh.ui.TitleBarOptions
import io.particle.mesh.ui.inflateFragment
Expand Down Expand Up @@ -71,7 +71,7 @@ class ControlPanelCellularOptionsFragment : BaseControlPanelFragment() {
ACTIVE -> SimStatusSwitchConfig.ACTIVE
INACTIVE_USER_DEACTIVATED -> SimStatusSwitchConfig.INACTIVE
INACTIVE_DATA_LIMIT_REACHED -> SimStatusSwitchConfig.PAUSED
INACTIVE_INVALID_PAYMENT_METHOD -> TODO()
INACTIVE_INVALID_PAYMENT_METHOD -> SimStatusSwitchConfig.INACTIVE
INACTIVE_NEVER_ACTIVATED -> throw IllegalArgumentException(
"SIMs shown in this screen should always have been activated"
)
Expand All @@ -88,13 +88,24 @@ class ControlPanelCellularOptionsFragment : BaseControlPanelFragment() {
INACTIVE_USER_DEACTIVATED -> flowRunner.startSimReactivateFlow(device)
INACTIVE_DATA_LIMIT_REACHED -> flowRunner.startSimUnpauseFlow(device)
// FIXME: find out what we want here
INACTIVE_INVALID_PAYMENT_METHOD -> TODO()
INACTIVE_INVALID_PAYMENT_METHOD -> showInvalidPaymentDialog()
INACTIVE_NEVER_ACTIVATED -> throw IllegalArgumentException(
"SIMs shown in this screen should always have been activated"
)
}
}

private fun showInvalidPaymentDialog() {
val aktivity = activity ?: return

p_controlpanel_cellular_options_change_sim_status.isChecked = false

AlertDialog.Builder(aktivity, R.style.Theme_MaterialComponents_Light_Dialog_Alert)
.setTitle("Invalid payment method")
.setMessage("To continue, please update your payment method at https://console.particle.io/billing/edit-card")
.setPositiveButton("OK") { _, _ -> pass } /* just close. */
.show()
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.FragmentActivity
import com.squareup.phrase.Phrase
import io.particle.mesh.setup.flow.FlowRunnerUiListener
import io.particle.mesh.ui.R
import kotlinx.android.synthetic.main.fragment_cp_enter_wifi_password.*

Expand All @@ -18,10 +20,10 @@ class ControlPanelEnterWifiNetworkPasswordFragment : BaseControlPanelFragment()
return inflater.inflate(R.layout.fragment_cp_enter_wifi_password, container, false)
}

override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
override fun onFragmentReady(activity: FragmentActivity, flowUiListener: FlowRunnerUiListener) {
super.onFragmentReady(activity, flowUiListener)
val headerText = Phrase.from(view, io.particle.mesh.R.string.p_enterwifipassword_header)
.putOptional("wifi_ssid", flowUiListener?.wifi?.wifiNetworkToConfigure?.ssid)
.putOptional("wifi_ssid", flowUiListener.wifi.wifiNetworkToConfigure?.ssid)
.format()
setup_header_text.text = headerText

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import io.particle.mesh.ui.inflateRow
import kotlinx.android.synthetic.main.fragment_control_panel_wifi_manage_networks.*
import kotlinx.android.synthetic.main.p_mesh_row_wifi_scan.view.*
import kotlinx.coroutines.delay
import kotlinx.coroutines.yield


class ControlPanelWifiManageNetworksFragment : BaseControlPanelFragment() {
Expand All @@ -48,6 +49,7 @@ class ControlPanelWifiManageNetworksFragment : BaseControlPanelFragment() {

private var barcode: CompleteBarcodeData? = null
private var transceiver: ProtocolTransceiver? = null
private val scopes = Scopes()

override fun onCreateView(
inflater: LayoutInflater,
Expand All @@ -67,7 +69,7 @@ class ControlPanelWifiManageNetworksFragment : BaseControlPanelFragment() {
adapter = KnownWifiNetworksAdapter(::onWifiNetworkSelected)
recyclerView.adapter = adapter

Scopes().onMain {
scopes.onMain {
startFlowWithBarcode { _, barcode ->
this@ControlPanelWifiManageNetworksFragment.barcode = barcode
reloadNetworks()
Expand All @@ -80,6 +82,11 @@ class ControlPanelWifiManageNetworksFragment : BaseControlPanelFragment() {
barcode?.let { reloadNetworks() }
}

override fun onDestroyView() {
super.onDestroyView()
scopes.cancelChildren()
}

@MainThread
private fun reloadNetworks() {
runWithTransceiver("Error reloading known networks") { xceiver, scopes ->
Expand Down Expand Up @@ -141,7 +148,6 @@ class ControlPanelWifiManageNetworksFragment : BaseControlPanelFragment() {
) {
flowSystemInterface.showGlobalProgressSpinner(true)
var connected = false
val scopes = Scopes()
scopes.onMain {
val xceiver = transceiver
try {
Expand All @@ -156,8 +162,9 @@ class ControlPanelWifiManageNetworksFragment : BaseControlPanelFragment() {
QATool.log(ex.toString())
val error = if (connected) errorMsg else "Error connecting to device"
flowSystemInterface.dialogHack.newSnackbarRequest(error)
findNavController().popBackStack()

if (isAdded) {
findNavController().popBackStack()
}
} finally {
flowSystemInterface.showGlobalProgressSpinner(false)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import androidx.lifecycle.LifecycleOwner
import androidx.navigation.fragment.findNavController
import com.squareup.phrase.Phrase
import io.particle.android.common.buildRawResourceUri
import io.particle.mesh.common.QATool
import io.particle.mesh.setup.flow.FlowRunnerUiListener
import io.particle.mesh.ui.BaseFlowFragment
import io.particle.mesh.ui.R
Expand All @@ -38,9 +39,19 @@ class ManualCommissioningAddToNetworkFragment : BaseFlowFragment() {

action_next.setOnClickListener {
// FIXME: this flow logic should live outside the UI
findNavController().navigate(
R.id.action_manualCommissioningAddToNetworkFragment_to_scanCommissionerCodeFragment
)
try {
findNavController().navigate(
R.id.action_manualCommissioningAddToNetworkFragment_to_scanCommissionerCodeFragment
)
} catch (ex: Exception) {
// Workaround to avoid this seemingly impossible crash: http://bit.ly/2kTpnIb
val error = IllegalStateException(
"Navigation error, Activity=${activity.javaClass}, isFinishing=${activity.isFinishing}",
ex
)
QATool.report(error)
this@ManualCommissioningAddToNetworkFragment.activity?.finish()
}
}

setup_header_text.text = Phrase.from(view, R.string.add_xenon_to_mesh_network)
Expand Down

0 comments on commit ff048b8

Please sign in to comment.