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

Commit f20f0d91 authored by fionaxu's avatar fionaxu
Browse files

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
parent 6f2965af
Loading
Loading
Loading
Loading
+23 −5
Original line number Original line Diff line number Diff line
@@ -40,6 +40,7 @@ import android.os.BatteryStats;
import android.os.Bundle;
import android.os.Bundle;
import android.os.Handler;
import android.os.Handler;
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.ServiceManager;
import android.os.ServiceManager;
@@ -214,6 +215,10 @@ public class TelephonyManager {
        return ActivityThread.currentOpPackageName();
        return ActivityThread.currentOpPackageName();
    }
    }


    private boolean isSystemProcess() {
        return Process.myUid() == Process.SYSTEM_UID;
    }

    /**
    /**
     * Returns the multi SIM variant
     * Returns the multi SIM variant
     * Returns DSDS for Dual SIM Dual Standby
     * Returns DSDS for Dual SIM Dual Standby
@@ -2866,15 +2871,18 @@ public class TelephonyManager {
            IPhoneSubInfo info = getSubscriberInfo();
            IPhoneSubInfo info = getSubscriberInfo();
            if (info == null) {
            if (info == null) {
                Rlog.e(TAG, "IMSI error: Subscriber Info is null");
                Rlog.e(TAG, "IMSI error: Subscriber Info is null");
                if (!isSystemProcess()) {
                    throw new RuntimeException("IMSI error: Subscriber Info is null");
                }
                return;
                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, "getCarrierInfoForImsiEncryption RemoteException" + ex);
        } catch (NullPointerException ex) {
            if (!isSystemProcess()) {
            // This could happen before phone restarts due to crashing
                ex.rethrowAsRuntimeException();
            Rlog.e(TAG, "getCarrierInfoForImsiEncryption NullPointerException" + ex);
            }
        }
        }
    }
    }


@@ -3863,11 +3871,18 @@ public class TelephonyManager {
    public void sendDialerSpecialCode(String inputCode) {
    public void sendDialerSpecialCode(String inputCode) {
        try {
        try {
            final ITelephony telephony = getITelephony();
            final ITelephony telephony = getITelephony();
            if (telephony == null) {
                if (!isSystemProcess()) {
                    throw new RuntimeException("Telephony service unavailable");
                }
                return;
            }
            telephony.sendDialerSpecialCode(mContext.getOpPackageName(), inputCode);
            telephony.sendDialerSpecialCode(mContext.getOpPackageName(), inputCode);
        } catch (RemoteException ex) {
        } catch (RemoteException ex) {
            // This could happen if binder process crashes.
            // This could happen if binder process crashes.
        } catch (NullPointerException ex) {
            if (!isSystemProcess()) {
            // This could happen before phone restarts due to crashing
                ex.rethrowAsRuntimeException();
            }
        }
        }
    }
    }


@@ -7836,6 +7851,9 @@ public class TelephonyManager {
            }
            }
        } catch (RemoteException ex) {
        } catch (RemoteException ex) {
            // This could happen if binder process crashes.
            // This could happen if binder process crashes.
            if (!isSystemProcess()) {
                ex.rethrowAsRuntimeException();
            }
        }
        }
    }
    }
}
}