throw runtimeException for applicable TM APIs
1. This CL revert some API change from ag/3710629.
2. throw runtime exception when running in a non-1000 UID.
3. throw for methods that persist some sort of state and readers could continue to
return placeholder values.
4. for rest of TelephonyManager API cleanup b/74401420.
Bug: 74016743
Test: Build
Change-Id: I2846efc11eebce4a923762f56f09daaf37c44763
diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java
index c5386ef..a12a7a0 100644
--- a/telephony/java/android/telephony/TelephonyManager.java
+++ b/telephony/java/android/telephony/TelephonyManager.java
@@ -40,6 +40,7 @@
import android.os.Bundle;
import android.os.Handler;
import android.os.PersistableBundle;
+import android.os.Process;
import android.os.RemoteException;
import android.os.ResultReceiver;
import android.os.ServiceManager;
@@ -214,6 +215,10 @@
return ActivityThread.currentOpPackageName();
}
+ private boolean isSystemProcess() {
+ return Process.myUid() == Process.SYSTEM_UID;
+ }
+
/**
* Returns the multi SIM variant
* Returns DSDS for Dual SIM Dual Standby
@@ -2866,15 +2871,18 @@
IPhoneSubInfo info = getSubscriberInfo();
if (info == null) {
Rlog.e(TAG, "IMSI error: Subscriber Info is null");
+ if (!isSystemProcess()) {
+ throw new RuntimeException("IMSI error: Subscriber Info is null");
+ }
return;
}
int subId = getSubId(SubscriptionManager.getDefaultDataSubscriptionId());
info.resetCarrierKeysForImsiEncryption(subId, mContext.getOpPackageName());
} catch (RemoteException ex) {
Rlog.e(TAG, "getCarrierInfoForImsiEncryption RemoteException" + ex);
- } catch (NullPointerException ex) {
- // This could happen before phone restarts due to crashing
- Rlog.e(TAG, "getCarrierInfoForImsiEncryption NullPointerException" + ex);
+ if (!isSystemProcess()) {
+ ex.rethrowAsRuntimeException();
+ }
}
}
@@ -3863,11 +3871,18 @@
public void sendDialerSpecialCode(String inputCode) {
try {
final ITelephony telephony = getITelephony();
+ if (telephony == null) {
+ if (!isSystemProcess()) {
+ throw new RuntimeException("Telephony service unavailable");
+ }
+ return;
+ }
telephony.sendDialerSpecialCode(mContext.getOpPackageName(), inputCode);
} catch (RemoteException ex) {
// This could happen if binder process crashes.
- } catch (NullPointerException ex) {
- // This could happen before phone restarts due to crashing
+ if (!isSystemProcess()) {
+ ex.rethrowAsRuntimeException();
+ }
}
}
@@ -7836,6 +7851,9 @@
}
} catch (RemoteException ex) {
// This could happen if binder process crashes.
+ if (!isSystemProcess()) {
+ ex.rethrowAsRuntimeException();
+ }
}
}
}