From 34335379c47fae91c0e9b33fb04264f200635520 Mon Sep 17 00:00:00 2001 From: Soonil Nagarkar Date: Tue, 25 Jan 2022 16:06:25 -0800 Subject: [PATCH] Propagate exception information through BinderRunner Use exceptions to provide better error messages for Geocoder APIs. Test: presubmits Change-Id: Idd8a02d5ff8ec211d4855aefeae55d28943a3e5e --- .../java/com/android/server/location/GeocoderProxy.java | 8 ++++---- .../location/provider/proxy/ProxyLocationProvider.java | 2 +- .../com/android/server/servicewatcher/ServiceWatcher.java | 2 +- .../android/server/servicewatcher/ServiceWatcherImpl.java | 5 +++-- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/services/core/java/com/android/server/location/GeocoderProxy.java b/services/core/java/com/android/server/location/GeocoderProxy.java index 57a7620a3b322..ac42646499a3f 100644 --- a/services/core/java/com/android/server/location/GeocoderProxy.java +++ b/services/core/java/com/android/server/location/GeocoderProxy.java @@ -83,9 +83,9 @@ public class GeocoderProxy { } @Override - public void onError() { + public void onError(Throwable t) { try { - listener.onResults("Service not Available", Collections.emptyList()); + listener.onResults(t.toString(), Collections.emptyList()); } catch (RemoteException e) { // ignore } @@ -110,9 +110,9 @@ public class GeocoderProxy { } @Override - public void onError() { + public void onError(Throwable t) { try { - listener.onResults("Service not Available", Collections.emptyList()); + listener.onResults(t.toString(), Collections.emptyList()); } catch (RemoteException e) { // ignore } diff --git a/services/core/java/com/android/server/location/provider/proxy/ProxyLocationProvider.java b/services/core/java/com/android/server/location/provider/proxy/ProxyLocationProvider.java index 2b3f420749918..05966da282179 100644 --- a/services/core/java/com/android/server/location/provider/proxy/ProxyLocationProvider.java +++ b/services/core/java/com/android/server/location/provider/proxy/ProxyLocationProvider.java @@ -208,7 +208,7 @@ public class ProxyLocationProvider extends AbstractLocationProvider implements } @Override - public void onError() { + public void onError(Throwable t) { synchronized (mLock) { mFlushListeners.remove(callback); } diff --git a/services/core/java/com/android/server/servicewatcher/ServiceWatcher.java b/services/core/java/com/android/server/servicewatcher/ServiceWatcher.java index 030bbd2bc652d..56367180ec15e 100644 --- a/services/core/java/com/android/server/servicewatcher/ServiceWatcher.java +++ b/services/core/java/com/android/server/servicewatcher/ServiceWatcher.java @@ -70,7 +70,7 @@ public interface ServiceWatcher { * cleanup in response to a single binder operation, it should not be used to propagate * errors further. Run on the ServiceWatcher thread. */ - default void onError() {} + default void onError(Throwable t) {} } /** diff --git a/services/core/java/com/android/server/servicewatcher/ServiceWatcherImpl.java b/services/core/java/com/android/server/servicewatcher/ServiceWatcherImpl.java index 631be380e2ebc..94ea463e8bf7b 100644 --- a/services/core/java/com/android/server/servicewatcher/ServiceWatcherImpl.java +++ b/services/core/java/com/android/server/servicewatcher/ServiceWatcherImpl.java @@ -25,6 +25,7 @@ import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; +import android.os.DeadObjectException; import android.os.Handler; import android.os.IBinder; import android.os.Looper; @@ -239,7 +240,7 @@ class ServiceWatcherImpl implements Preconditions.checkState(Looper.myLooper() == mHandler.getLooper()); if (mBinder == null) { - operation.onError(); + operation.onError(new DeadObjectException()); return; } @@ -249,7 +250,7 @@ class ServiceWatcherImpl implements // binders may propagate some specific non-RemoteExceptions from the other side // through the binder as well - we cannot allow those to crash the system server Log.e(TAG, "[" + mTag + "] error running operation on " + mBoundServiceInfo, e); - operation.onError(); + operation.onError(e); } }