From 931541c59a393a4ea62acf474de28ddb3a582df8 Mon Sep 17 00:00:00 2001 From: wangmingjun Date: Fri, 28 Jan 2022 14:11:30 +0800 Subject: [PATCH] =?UTF-8?q?[taxi/bus=202.5.1]=20taxi/bus=20=E5=A4=84?= =?UTF-8?q?=E7=90=86Rxjava=E8=B0=83=E5=BA=A6=E5=99=A8=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../och/bus/presenter/OchBusOrderModel.java | 40 ++++++++++++++++++ .../och/taxi/model/MogoOCHTaxiModelNew.java | 42 +++++++++++++++++++ 2 files changed, 82 insertions(+) diff --git a/OCH/mogo-och-bus/src/main/java/com/mogo/och/bus/presenter/OchBusOrderModel.java b/OCH/mogo-och-bus/src/main/java/com/mogo/och/bus/presenter/OchBusOrderModel.java index 3131f69923..60e6cc4475 100644 --- a/OCH/mogo-och-bus/src/main/java/com/mogo/och/bus/presenter/OchBusOrderModel.java +++ b/OCH/mogo-och-bus/src/main/java/com/mogo/och/bus/presenter/OchBusOrderModel.java @@ -43,6 +43,7 @@ import com.mogo.service.IMogoServiceApis; import com.mogo.service.statusmanager.IMogoStatusChangedListener; import com.mogo.service.statusmanager.StatusDescriptor; +import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.concurrent.TimeUnit; @@ -50,6 +51,9 @@ import java.util.concurrent.TimeUnit; import io.reactivex.Observable; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable; +import io.reactivex.exceptions.UndeliverableException; +import io.reactivex.functions.Consumer; +import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.schedulers.Schedulers; import static com.mogo.och.bus.constant.OchBusConst.STATION_STATUS_STOPPED; @@ -131,6 +135,42 @@ public class OchBusOrderModel { .registerStatusChangedListener( TAG, StatusDescriptor.VR_MODE, mMogoStatusChangedListener ); } + //2022.1.28 + // 调用Disposable.dispose() 时候会出现InterruptedException 导致出现崩溃 + // The exception could not be delivered to the consumer because it has already canceled/disposed the flow or the excTeption has nowhere to go to begin with + RxJavaPlugins.setErrorHandler(new Consumer() { + @Override + public void accept(Throwable e) { + if (e instanceof UndeliverableException) { + e = e.getCause(); + Log.d(TAG,"UndeliverableException"); + } + if ((e instanceof IOException)) {// + // fine, irrelevant network problem or API that throws on cancellation + Log.d(TAG,"IOException"); + return; + } + if (e instanceof InterruptedException) { + // fine, some blocking code was interrupted by a dispose call + Log.d(TAG,"InterruptedException"); + return; + } + if ((e instanceof NullPointerException) || (e instanceof IllegalArgumentException)) { + // that's likely a bug in the application + Log.d(TAG,"NullPointerException or IllegalArgumentException"); + Thread.currentThread().getUncaughtExceptionHandler().uncaughtException(Thread.currentThread(), e); + return; + } + if (e instanceof IllegalStateException) { + // that's a bug in RxJava or in a custom operator + Log.d(TAG,"IllegalStateException"); + Thread.currentThread().getUncaughtExceptionHandler().uncaughtException(Thread.currentThread(), e); + return; + } + Log.d(TAG,"Undeliverable exception"); + } + }); + //2021/10/20 轮询小巴车订单,暂时用来播报 startLoopBusOrders(); } diff --git a/OCH/mogo-och-taxi/src/main/java/com/mogo/och/taxi/model/MogoOCHTaxiModelNew.java b/OCH/mogo-och-taxi/src/main/java/com/mogo/och/taxi/model/MogoOCHTaxiModelNew.java index 40d7277887..58d22abc4a 100644 --- a/OCH/mogo-och-taxi/src/main/java/com/mogo/och/taxi/model/MogoOCHTaxiModelNew.java +++ b/OCH/mogo-och-taxi/src/main/java/com/mogo/och/taxi/model/MogoOCHTaxiModelNew.java @@ -4,6 +4,7 @@ import android.content.Context; import android.content.Intent; import android.location.Location; import android.net.ConnectivityManager; +import android.util.Log; import androidx.annotation.Nullable; @@ -60,10 +61,15 @@ import com.mogo.service.statusmanager.StatusDescriptor; import org.jetbrains.annotations.NotNull; +import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import io.reactivex.exceptions.UndeliverableException; +import io.reactivex.functions.Consumer; +import io.reactivex.plugins.RxJavaPlugins; + /** * Created by pangfan on 2021/8/19 * @@ -133,6 +139,42 @@ public class MogoOCHTaxiModelNew { apis.getLocationInfoApi().start(); } + //2022.1.28 + // 调用Disposable.dispose() 时候会出现InterruptedException 导致出现崩溃 + // The exception could not be delivered to the consumer because it has already canceled/disposed the flow or the excTeption has nowhere to go to begin with + RxJavaPlugins.setErrorHandler(new Consumer() { + @Override + public void accept(Throwable e) { + if (e instanceof UndeliverableException) { + e = e.getCause(); + Log.d(TAG,"UndeliverableException"); + } + if ((e instanceof IOException)) {// + // fine, irrelevant network problem or API that throws on cancellation + Log.d(TAG,"IOException"); + return; + } + if (e instanceof InterruptedException) { + // fine, some blocking code was interrupted by a dispose call + Log.d(TAG,"InterruptedException"); + return; + } + if ((e instanceof NullPointerException) || (e instanceof IllegalArgumentException)) { + // that's likely a bug in the application + Log.d(TAG,"NullPointerException or IllegalArgumentException"); + Thread.currentThread().getUncaughtExceptionHandler().uncaughtException(Thread.currentThread(), e); + return; + } + if (e instanceof IllegalStateException) { + // that's a bug in RxJava or in a custom operator + Log.d(TAG,"IllegalStateException"); + Thread.currentThread().getUncaughtExceptionHandler().uncaughtException(Thread.currentThread(), e); + return; + } + Log.d(TAG,"Undeliverable exception"); + } + }); + if (NetworkUtils.isConnected(mContext)) { // startOrStopOrderLoop(mOCHCarStatus == 1); queryCarStatus();