summaryrefslogtreecommitdiff
path: root/location/java
diff options
context:
space:
mode:
author Soonil Nagarkar <sooniln@google.com> 2022-01-11 00:17:40 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2022-01-11 00:17:40 +0000
commit471b107d52ecbee40744eb96a072ddbcfbbfb875 (patch)
treeda8f2369624e82f065c581dceafeb6abcea29437 /location/java
parent005ad9b21406c45ba57acfc100055d98dde22d16 (diff)
parenta25ac6d49b49a9208015ef805d305eb5cbbb8798 (diff)
Merge "Ensure location provider exceptions are visible"
Diffstat (limited to 'location/java')
-rw-r--r--location/java/android/location/provider/LocationProviderBase.java40
1 files changed, 31 insertions, 9 deletions
diff --git a/location/java/android/location/provider/LocationProviderBase.java b/location/java/android/location/provider/LocationProviderBase.java
index 88a24794411c..529edddf4cf0 100644
--- a/location/java/android/location/provider/LocationProviderBase.java
+++ b/location/java/android/location/provider/LocationProviderBase.java
@@ -26,7 +26,9 @@ import android.content.Context;
import android.content.Intent;
import android.location.Location;
import android.os.Bundle;
+import android.os.Handler;
import android.os.IBinder;
+import android.os.Looper;
import android.os.RemoteException;
import android.util.Log;
@@ -308,9 +310,7 @@ public abstract class LocationProviderBase {
synchronized (mBinder) {
try {
manager.onInitialize(mAllowed, mProperties, mAttributionTag);
- } catch (RemoteException e) {
- throw e.rethrowFromSystemServer();
- } catch (RuntimeException e) {
+ } catch (RemoteException | RuntimeException e) {
Log.w(mTag, e);
}
@@ -320,12 +320,28 @@ public abstract class LocationProviderBase {
@Override
public void setRequest(ProviderRequest request) {
- onSetRequest(request);
+ try {
+ onSetRequest(request);
+ } catch (RuntimeException e) {
+ // exceptions on one-way binder threads are dropped - move to a different thread
+ Log.w(mTag, e);
+ new Handler(Looper.getMainLooper()).post(() -> {
+ throw new AssertionError(e);
+ });
+ }
}
@Override
public void flush() {
- onFlush(this::onFlushComplete);
+ try {
+ onFlush(this::onFlushComplete);
+ } catch (RuntimeException e) {
+ // exceptions on one-way binder threads are dropped - move to a different thread
+ Log.w(mTag, e);
+ new Handler(Looper.getMainLooper()).post(() -> {
+ throw new AssertionError(e);
+ });
+ }
}
private void onFlushComplete() {
@@ -333,9 +349,7 @@ public abstract class LocationProviderBase {
if (manager != null) {
try {
manager.onFlushComplete();
- } catch (RemoteException e) {
- throw e.rethrowFromSystemServer();
- } catch (RuntimeException e) {
+ } catch (RemoteException | RuntimeException e) {
Log.w(mTag, e);
}
}
@@ -343,7 +357,15 @@ public abstract class LocationProviderBase {
@Override
public void sendExtraCommand(String command, Bundle extras) {
- onSendExtraCommand(command, extras);
+ try {
+ onSendExtraCommand(command, extras);
+ } catch (RuntimeException e) {
+ // exceptions on one-way binder threads are dropped - move to a different thread
+ Log.w(mTag, e);
+ new Handler(Looper.getMainLooper()).post(() -> {
+ throw new AssertionError(e);
+ });
+ }
}
}
}