Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f5c0da3d authored by fionaxu's avatar fionaxu
Browse files

Remove RuntimeException throws from TelephonyManager

scrub exceptions from remote or due to phone service not ready.
This is in consistent with other APIs in TelephonyManager.

TODO: investigate appropriate way to handle exceptions in synchronous
APIs e.g. checked exception for those internal service failure.
tracked by b/74401420

Bug: 74016743
Test: Build
Change-Id: Ie1a07f57c2e3a70e5ac6c3ffa238c2209b34f2b8
parent 641eb554
Loading
Loading
Loading
Loading
+12 −23
Original line number Diff line number Diff line
@@ -2754,18 +2754,17 @@ public class TelephonyManager {
     * @return ImsiEncryptionInfo Carrier specific information that will be used to encrypt the
     *         IMSI and IMPI. This includes the public key and the key identifier. This information
     *         will be stored in the device keystore. The system will return a null when no key was
     *         found, and the carrier does not require a key. The system will throw the following
     *         exceptions:
     *         1. IllegalArgumentException when an invalid key is sent.
     *         2. RuntimeException if the key is required but not found; and also if there was an
     *         internal exception.
     *         found, and the carrier does not require a key. The system will throw
     *         IllegalArgumentException when an invalid key is sent or when key is required but
     *         not found.
     * @hide
     */
    public ImsiEncryptionInfo getCarrierInfoForImsiEncryption(int keyType) {
        try {
            IPhoneSubInfo info = getSubscriberInfo();
            if (info == null) {
                throw new RuntimeException("IMSI error: Subscriber Info is null");
                Rlog.e(TAG,"IMSI error: Subscriber Info is null");
                return null;
            }
            int subId = getSubId(SubscriptionManager.getDefaultDataSubscriptionId());
            if (keyType != KEY_TYPE_EPDG && keyType != KEY_TYPE_WLAN) {
@@ -2773,20 +2772,18 @@ public class TelephonyManager {
            }
            ImsiEncryptionInfo imsiEncryptionInfo = info.getCarrierInfoForImsiEncryption(
                    subId, keyType, mContext.getOpPackageName());
            if (imsiEncryptionInfo  == null
                    && isImsiEncryptionRequired(subId, keyType)) {
            if (imsiEncryptionInfo == null && isImsiEncryptionRequired(subId, keyType)) {
                Rlog.e(TAG, "IMSI error: key is required but not found");
                throw new RuntimeException("IMSI error: key is required but not found");
                throw new IllegalArgumentException("IMSI error: key is required but not found");
            }
            return imsiEncryptionInfo;
        } catch (RemoteException ex) {
            Rlog.e(TAG, "getCarrierInfoForImsiEncryption RemoteException" + ex);
            throw new RuntimeException("IMSI error: Remote Exception");
        } catch (NullPointerException ex) {
            // This could happen before phone restarts due to crashing
            Rlog.e(TAG, "getCarrierInfoForImsiEncryption NullPointerException" + ex);
            throw new RuntimeException("IMSI error: Null Pointer exception");
        }
        return null;
    }

    /**
@@ -2802,17 +2799,16 @@ public class TelephonyManager {
        try {
            IPhoneSubInfo info = getSubscriberInfo();
            if (info == null) {
                throw new RuntimeException("IMSI error: Subscriber Info is null");
                Rlog.e(TAG, "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);
            throw new RuntimeException("IMSI error: Remote Exception");
        } catch (NullPointerException ex) {
            // This could happen before phone restarts due to crashing
            Rlog.e(TAG, "getCarrierInfoForImsiEncryption NullPointerException" + ex);
            throw new RuntimeException("IMSI error: Null Pointer exception");
        }
    }

@@ -3788,8 +3784,6 @@ public class TelephonyManager {
     *
     * @throws SecurityException if the caller does not have carrier privileges or is not the
     *         current default dialer
     *
     * @throws IllegalStateException if telephony service is unavailable.
     */
    public void sendDialerSpecialCode(String inputCode) {
        try {
@@ -3797,10 +3791,8 @@ public class TelephonyManager {
            telephony.sendDialerSpecialCode(mContext.getOpPackageName(), inputCode);
        } catch (RemoteException ex) {
            // This could happen if binder process crashes.
            ex.rethrowFromSystemServer();
        } catch (NullPointerException ex) {
            // This could happen before phone restarts due to crashing
            throw new IllegalStateException("Telephony service unavailable");
        }
    }

@@ -4925,10 +4917,10 @@ public class TelephonyManager {
        String v = android.provider.Settings.Global.getString(cr, name);

        if (index == Integer.MAX_VALUE) {
            throw new RuntimeException("putIntAtIndex index == MAX_VALUE index=" + index);
            throw new IllegalArgumentException("putIntAtIndex index == MAX_VALUE index=" + index);
        }
        if (index < 0) {
            throw new RuntimeException("putIntAtIndex index < 0 index=" + index);
            throw new IllegalArgumentException("putIntAtIndex index < 0 index=" + index);
        }
        if (v != null) {
            valArray = v.split(",");
@@ -7210,7 +7202,6 @@ public class TelephonyManager {
            }
        } catch (RemoteException ex) {
            // This could happen if binder process crashes.
            ex.rethrowAsRuntimeException();
        }
        return UNKNOWN_CARRIER_ID;
    }
@@ -7235,7 +7226,6 @@ public class TelephonyManager {
            }
        } catch (RemoteException ex) {
            // This could happen if binder process crashes.
            ex.rethrowAsRuntimeException();
        }
        return null;
    }
@@ -7759,7 +7749,6 @@ public class TelephonyManager {
            }
        } catch (RemoteException ex) {
            // This could happen if binder process crashes.
            ex.rethrowAsRuntimeException();
        }
    }
}