From 1e486d9b4af3dac27b03044ba84aa771b1e670de Mon Sep 17 00:00:00 2001 From: Meng Wang Date: Mon, 30 Sep 2019 16:29:37 -0700 Subject: [PATCH] Do not use hidden API ParcelableException ParcelableException, when written into Parcel, just keeps the excaption class name and its string representation. So we pass the same across AIDL and compose the Exception class on the other side, following how a ParcelableException is read from Parcel. Bug: 141315988 Test: make Change-Id: I92083c8a22e58c07a3537d11b1e1c143ece99031 Merged-In: I92dd527aad1e174871c330d1c043189407e136cb --- .../android/telephony/ICellInfoCallback.aidl | 3 +-- .../android/telephony/TelephonyManager.java | 26 ++++++++++++++----- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/telephony/java/android/telephony/ICellInfoCallback.aidl b/telephony/java/android/telephony/ICellInfoCallback.aidl index ee3c1b1be6d97..60732a3db59ad 100644 --- a/telephony/java/android/telephony/ICellInfoCallback.aidl +++ b/telephony/java/android/telephony/ICellInfoCallback.aidl @@ -16,7 +16,6 @@ package android.telephony; -import android.os.ParcelableException; import android.telephony.CellInfo; import java.util.List; @@ -28,5 +27,5 @@ import java.util.List; oneway interface ICellInfoCallback { void onCellInfo(in List state); - void onError(in int errorCode, in ParcelableException detail); + void onError(in int errorCode, in String exceptionName, in String message); } diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java index 2c26f1625d672..8dfc944c05b44 100644 --- a/telephony/java/android/telephony/TelephonyManager.java +++ b/telephony/java/android/telephony/TelephonyManager.java @@ -70,7 +70,6 @@ import android.telephony.Annotation.NetworkType; import android.telephony.Annotation.RadioPowerState; import android.telephony.Annotation.SimActivationState; import android.telephony.VisualVoicemailService.VisualVoicemailTask; -import android.telephony.data.ApnSetting; import android.telephony.emergency.EmergencyNumber; import android.telephony.emergency.EmergencyNumber.EmergencyServiceCategories; import android.telephony.ims.ImsMmTelManager; @@ -5490,19 +5489,20 @@ public class TelephonyManager { telephony.requestCellInfoUpdate( getSubId(), new ICellInfoCallback.Stub() { + @Override public void onCellInfo(List cellInfo) { Binder.withCleanCallingIdentity(() -> executor.execute(() -> callback.onCellInfo(cellInfo))); } - public void onError(int errorCode, android.os.ParcelableException detail) { + @Override + public void onError(int errorCode, String exceptionName, String message) { Binder.withCleanCallingIdentity(() -> executor.execute(() -> callback.onError( errorCode, - detail == null ? null : detail.getCause()))); + createThrowableByClassName(exceptionName, message)))); } }, getOpPackageName()); - } catch (RemoteException ex) { } } @@ -5531,22 +5531,36 @@ public class TelephonyManager { telephony.requestCellInfoUpdateWithWorkSource( getSubId(), new ICellInfoCallback.Stub() { + @Override public void onCellInfo(List cellInfo) { Binder.withCleanCallingIdentity(() -> executor.execute(() -> callback.onCellInfo(cellInfo))); } - public void onError(int errorCode, android.os.ParcelableException detail) { + @Override + public void onError(int errorCode, String exceptionName, String message) { Binder.withCleanCallingIdentity(() -> executor.execute(() -> callback.onError( errorCode, - detail == null ? null : detail.getCause()))); + createThrowableByClassName(exceptionName, message)))); } }, getOpPackageName(), workSource); } catch (RemoteException ex) { } } + private static Throwable createThrowableByClassName(String className, String message) { + if (className == null) { + return null; + } + try { + Class c = Class.forName(className); + return (Throwable) c.getConstructor(String.class).newInstance(message); + } catch (ReflectiveOperationException | ClassCastException e) { + } + return new RuntimeException(className + ": " + message); + } + /** * Sets the minimum time in milli-seconds between {@link PhoneStateListener#onCellInfoChanged * PhoneStateListener.onCellInfoChanged} will be invoked.