Remove checks for system_process in TelephonyManager

Instead of throwing exceptions, return the default null/empty/void
behavior.

Test: atest TelephonyManagerTest
Fix: 175881713
Change-Id: Ia15c8183212bc67e74b45fc119b5ef9d4c295c94
This commit is contained in:
Sarah Chin
2021-03-13 00:07:40 -08:00
parent ac6f5ee927
commit eecdf254e9

View File

@@ -64,7 +64,6 @@ import android.os.ParcelFileDescriptor;
import android.os.ParcelUuid; import android.os.ParcelUuid;
import android.os.Parcelable; import android.os.Parcelable;
import android.os.PersistableBundle; import android.os.PersistableBundle;
import android.os.Process;
import android.os.RemoteException; import android.os.RemoteException;
import android.os.ResultReceiver; import android.os.ResultReceiver;
import android.os.SystemProperties; import android.os.SystemProperties;
@@ -428,10 +427,6 @@ public class TelephonyManager {
return null; return null;
} }
private boolean isSystemProcess() {
return Process.myUid() == Process.SYSTEM_UID;
}
/** /**
* Post a runnable to the BackgroundThread. * Post a runnable to the BackgroundThread.
* *
@@ -4205,19 +4200,12 @@ public class TelephonyManager {
try { try {
IPhoneSubInfo info = getSubscriberInfoService(); IPhoneSubInfo info = getSubscriberInfoService();
if (info == null) { if (info == null) {
Rlog.e(TAG, "IMSI error: Subscriber Info is null"); throw new RuntimeException("IMSI error: Subscriber Info is null");
if (!isSystemProcess()) {
throw new RuntimeException("IMSI error: Subscriber Info is null");
}
return;
} }
int subId = getSubId(SubscriptionManager.getDefaultDataSubscriptionId()); int subId = getSubId(SubscriptionManager.getDefaultDataSubscriptionId());
info.resetCarrierKeysForImsiEncryption(subId, mContext.getOpPackageName()); info.resetCarrierKeysForImsiEncryption(subId, mContext.getOpPackageName());
} catch (RemoteException ex) { } catch (RemoteException ex) {
Rlog.e(TAG, "getCarrierInfoForImsiEncryption RemoteException" + ex); Rlog.e(TAG, "Telephony#getCarrierInfoForImsiEncryption RemoteException" + ex);
if (!isSystemProcess()) {
ex.rethrowAsRuntimeException();
}
} }
} }
@@ -5611,17 +5599,11 @@ public class TelephonyManager {
try { try {
final ITelephony telephony = getITelephony(); final ITelephony telephony = getITelephony();
if (telephony == null) { if (telephony == null) {
if (!isSystemProcess()) {
throw new RuntimeException("Telephony service unavailable");
}
return; return;
} }
telephony.sendDialerSpecialCode(mContext.getOpPackageName(), inputCode); telephony.sendDialerSpecialCode(mContext.getOpPackageName(), inputCode);
} catch (RemoteException ex) { } catch (RemoteException ex) {
// This could happen if binder process crashes. Rlog.e(TAG, "Telephony#sendDialerSpecialCode RemoteException" + ex);
if (!isSystemProcess()) {
ex.rethrowAsRuntimeException();
}
} }
} }
@@ -9940,9 +9922,7 @@ public class TelephonyManager {
throw new IllegalStateException("telephony service is null."); throw new IllegalStateException("telephony service is null.");
} }
} catch (RemoteException ex) { } catch (RemoteException ex) {
if (!isSystemProcess()) { Rlog.e(TAG, "Telephony#getMobileProvisioningUrl RemoteException" + ex);
ex.rethrowAsRuntimeException();
}
} }
return null; return null;
} }
@@ -13926,9 +13906,7 @@ public class TelephonyManager {
return service.isDataEnabledForApn(apnType, getSubId(), pkgForDebug); return service.isDataEnabledForApn(apnType, getSubId(), pkgForDebug);
} }
} catch (RemoteException ex) { } catch (RemoteException ex) {
if (!isSystemProcess()) { Rlog.e(TAG, "Telephony#isDataEnabledForApn RemoteException" + ex);
ex.rethrowAsRuntimeException();
}
} }
return false; return false;
} }
@@ -13948,9 +13926,7 @@ public class TelephonyManager {
return service.isApnMetered(apnType, getSubId()); return service.isApnMetered(apnType, getSubId());
} }
} catch (RemoteException ex) { } catch (RemoteException ex) {
if (!isSystemProcess()) { Rlog.e(TAG, "Telephony#isApnMetered RemoteException" + ex);
ex.rethrowAsRuntimeException();
}
} }
return true; return true;
} }
@@ -14010,9 +13986,7 @@ public class TelephonyManager {
service.setSystemSelectionChannels(specifiers, getSubId(), aidlConsumer); service.setSystemSelectionChannels(specifiers, getSubId(), aidlConsumer);
} }
} catch (RemoteException ex) { } catch (RemoteException ex) {
if (!isSystemProcess()) { Rlog.e(TAG, "Telephony#setSystemSelectionChannels RemoteException" + ex);
ex.rethrowAsRuntimeException();
}
} }
} }
@@ -14040,9 +14014,7 @@ public class TelephonyManager {
throw new IllegalStateException("telephony service is null."); throw new IllegalStateException("telephony service is null.");
} }
} catch (RemoteException ex) { } catch (RemoteException ex) {
if (!isSystemProcess()) { Rlog.e(TAG, "Telephony#getSystemSelectionChannels RemoteException" + ex);
ex.rethrowAsRuntimeException();
}
} }
return new ArrayList<>(); return new ArrayList<>();
} }
@@ -14071,9 +14043,7 @@ public class TelephonyManager {
return service.isMvnoMatched(getSubId(), mvnoType, mvnoMatchData); return service.isMvnoMatched(getSubId(), mvnoType, mvnoMatchData);
} }
} catch (RemoteException ex) { } catch (RemoteException ex) {
if (!isSystemProcess()) { Rlog.e(TAG, "Telephony#matchesCurrentSimOperator RemoteException" + ex);
ex.rethrowAsRuntimeException();
}
} }
return false; return false;
} }
@@ -14474,10 +14444,7 @@ public class TelephonyManager {
service.setMobileDataPolicyEnabled(getSubId(), policy, enabled); service.setMobileDataPolicyEnabled(getSubId(), policy, enabled);
} }
} catch (RemoteException ex) { } catch (RemoteException ex) {
// This could happen if binder process crashes. Rlog.e(TAG, "Telephony#setMobileDataPolicyEnabled RemoteException" + ex);
if (!isSystemProcess()) {
ex.rethrowAsRuntimeException();
}
} }
} }
@@ -14497,10 +14464,7 @@ public class TelephonyManager {
return service.isMobileDataPolicyEnabled(getSubId(), policy); return service.isMobileDataPolicyEnabled(getSubId(), policy);
} }
} catch (RemoteException ex) { } catch (RemoteException ex) {
// This could happen if binder process crashes. Rlog.e(TAG, "Telephony#isMobileDataPolicyEnabled RemoteException" + ex);
if (!isSystemProcess()) {
ex.rethrowAsRuntimeException();
}
} }
return false; return false;
} }
@@ -15004,9 +14968,7 @@ public class TelephonyManager {
throw new IllegalStateException("telephony service is null."); throw new IllegalStateException("telephony service is null.");
} }
} catch (RemoteException ex) { } catch (RemoteException ex) {
if (!isSystemProcess()) { Rlog.e(TAG, "Telephony#getEquivalentHomePlmns RemoteException" + ex);
ex.rethrowAsRuntimeException();
}
} }
return Collections.emptyList(); return Collections.emptyList();
@@ -15098,9 +15060,7 @@ public class TelephonyManager {
throw new IllegalStateException("telephony service is null."); throw new IllegalStateException("telephony service is null.");
} }
} catch (RemoteException ex) { } catch (RemoteException ex) {
if (!isSystemProcess()) { Rlog.e(TAG, "Telephony#isRadioInterfaceCapabilitySupported RemoteException" + ex);
ex.rethrowAsRuntimeException();
}
} }
return false; return false;
} }