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

Commit ddcc3cd0 authored by Grace Jia's avatar Grace Jia
Browse files

Throw RuntimeException/ImsException when binder is null.

Bug: 149227341
Test: atest CtsTelephonyTestCases:ImsMmTelManagerTest
Change-Id: Ida19a2f5e0bbb64facd7f08eb4ab68d120134a0e
Merged-In: Ida19a2f5e0bbb64facd7f08eb4ab68d120134a0e
parent 4cfcf003
Loading
Loading
Loading
Loading
+176 −29
Original line number Diff line number Diff line
@@ -295,8 +295,15 @@ public class ImsMmTelManager implements RegistrationManager {
            throw new IllegalArgumentException("Must include a non-null Executor.");
        }
        c.setExecutor(executor);

        ITelephony iTelephony = getITelephony();
        if (iTelephony == null) {
            throw new ImsException("Could not find Telephony Service.",
                    ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
        }

        try {
            getITelephony().registerImsRegistrationCallback(mSubId, c.getBinder());
            iTelephony.registerImsRegistrationCallback(mSubId, c.getBinder());
        } catch (ServiceSpecificException e) {
            if (e.errorCode == ImsException.CODE_ERROR_INVALID_SUBSCRIPTION) {
                // Rethrow as runtime error to keep API compatible.
@@ -332,8 +339,15 @@ public class ImsMmTelManager implements RegistrationManager {
            throw new IllegalArgumentException("Must include a non-null Executor.");
        }
        c.setExecutor(executor);

        ITelephony iTelephony = getITelephony();
        if (iTelephony == null) {
            throw new ImsException("Could not find Telephony Service.",
                    ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
        }

        try {
            getITelephony().registerImsRegistrationCallback(mSubId, c.getBinder());
            iTelephony.registerImsRegistrationCallback(mSubId, c.getBinder());
        } catch (ServiceSpecificException e) {
            throw new ImsException(e.getMessage(), e.errorCode);
        } catch (RemoteException | IllegalStateException e) {
@@ -362,8 +376,14 @@ public class ImsMmTelManager implements RegistrationManager {
        if (c == null) {
            throw new IllegalArgumentException("Must include a non-null RegistrationCallback.");
        }

        ITelephony iTelephony = getITelephony();
        if (iTelephony == null) {
            throw new RuntimeException("Could not find Telephony Service.");
        }

        try {
            getITelephony().unregisterImsRegistrationCallback(mSubId, c.getBinder());
            iTelephony.unregisterImsRegistrationCallback(mSubId, c.getBinder());
        } catch (RemoteException e) {
            throw e.rethrowAsRuntimeException();
        }
@@ -388,8 +408,14 @@ public class ImsMmTelManager implements RegistrationManager {
        if (c == null) {
            throw new IllegalArgumentException("Must include a non-null RegistrationCallback.");
        }

        ITelephony iTelephony = getITelephony();
        if (iTelephony == null) {
            throw new RuntimeException("Could not find Telephony Service.");
        }

        try {
            getITelephony().unregisterImsRegistrationCallback(mSubId, c.getBinder());
            iTelephony.unregisterImsRegistrationCallback(mSubId, c.getBinder());
        } catch (RemoteException e) {
            throw e.rethrowAsRuntimeException();
        }
@@ -410,8 +436,14 @@ public class ImsMmTelManager implements RegistrationManager {
        if (executor == null) {
            throw new IllegalArgumentException("Must include a non-null Executor.");
        }

        ITelephony iTelephony = getITelephony();
        if (iTelephony == null) {
            throw new RuntimeException("Could not find Telephony Service.");
        }

        try {
            getITelephony().getImsMmTelRegistrationState(mSubId, new IIntegerConsumer.Stub() {
            iTelephony.getImsMmTelRegistrationState(mSubId, new IIntegerConsumer.Stub() {
                @Override
                public void accept(int result) {
                    executor.execute(() -> stateCallback.accept(result));
@@ -444,8 +476,14 @@ public class ImsMmTelManager implements RegistrationManager {
        if (executor == null) {
            throw new IllegalArgumentException("Must include a non-null Executor.");
        }

        ITelephony iTelephony = getITelephony();
        if (iTelephony == null) {
            throw new RuntimeException("Could not find Telephony Service.");
        }

        try {
            getITelephony().getImsMmTelRegistrationTransportType(mSubId,
            iTelephony.getImsMmTelRegistrationTransportType(mSubId,
                    new IIntegerConsumer.Stub() {
                        @Override
                        public void accept(int result) {
@@ -507,8 +545,15 @@ public class ImsMmTelManager implements RegistrationManager {
            throw new IllegalArgumentException("Must include a non-null Executor.");
        }
        c.setExecutor(executor);

        ITelephony iTelephony = getITelephony();
        if (iTelephony == null) {
            throw new ImsException("Could not find Telephony Service.",
                    ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
        }

        try {
            getITelephony().registerMmTelCapabilityCallback(mSubId, c.getBinder());
            iTelephony.registerMmTelCapabilityCallback(mSubId, c.getBinder());
        } catch (ServiceSpecificException e) {
            if (e.errorCode == ImsException.CODE_ERROR_INVALID_SUBSCRIPTION) {
                // Rethrow as runtime error to keep API compatible.
@@ -554,8 +599,14 @@ public class ImsMmTelManager implements RegistrationManager {
        if (c == null) {
            throw new IllegalArgumentException("Must include a non-null RegistrationCallback.");
        }

        ITelephony iTelephony = getITelephony();
        if (iTelephony == null) {
            throw new RuntimeException("Could not find Telephony Service.");
        }

        try {
            getITelephony().unregisterMmTelCapabilityCallback(mSubId, c.getBinder());
            iTelephony.unregisterMmTelCapabilityCallback(mSubId, c.getBinder());
        } catch (RemoteException e) {
            throw e.rethrowAsRuntimeException();
        }
@@ -600,8 +651,13 @@ public class ImsMmTelManager implements RegistrationManager {
            android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
            android.Manifest.permission.READ_PRECISE_PHONE_STATE})
    public boolean isAdvancedCallingSettingEnabled() {
        ITelephony iTelephony = getITelephony();
        if (iTelephony == null) {
            throw new RuntimeException("Could not find Telephony Service.");
        }

        try {
            return getITelephony().isAdvancedCallingSettingEnabled(mSubId);
            return iTelephony.isAdvancedCallingSettingEnabled(mSubId);
        } catch (ServiceSpecificException e) {
            if (e.errorCode == ImsException.CODE_ERROR_INVALID_SUBSCRIPTION) {
                // Rethrow as runtime error to keep API compatible.
@@ -641,8 +697,13 @@ public class ImsMmTelManager implements RegistrationManager {
    @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
    @SystemApi @TestApi
    public void setAdvancedCallingSettingEnabled(boolean isEnabled) {
        ITelephony iTelephony = getITelephony();
        if (iTelephony == null) {
            throw new RuntimeException("Could not find Telephony Service.");
        }

        try {
            getITelephony().setAdvancedCallingSettingEnabled(mSubId, isEnabled);
            iTelephony.setAdvancedCallingSettingEnabled(mSubId, isEnabled);
        } catch (ServiceSpecificException e) {
            if (e.errorCode == ImsException.CODE_ERROR_INVALID_SUBSCRIPTION) {
                // Rethrow as runtime error to keep API compatible.
@@ -681,8 +742,13 @@ public class ImsMmTelManager implements RegistrationManager {
    @SystemApi @TestApi
    public boolean isCapable(@MmTelFeature.MmTelCapabilities.MmTelCapability int capability,
            @ImsRegistrationImplBase.ImsRegistrationTech int imsRegTech) {
        ITelephony iTelephony = getITelephony();
        if (iTelephony == null) {
            throw new RuntimeException("Could not find Telephony Service.");
        }

        try {
            return getITelephony().isCapable(mSubId, capability, imsRegTech);
            return iTelephony.isCapable(mSubId, capability, imsRegTech);
        } catch (RemoteException e) {
            throw e.rethrowAsRuntimeException();
        }
@@ -710,8 +776,13 @@ public class ImsMmTelManager implements RegistrationManager {
    @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
    public boolean isAvailable(@MmTelFeature.MmTelCapabilities.MmTelCapability int capability,
            @ImsRegistrationImplBase.ImsRegistrationTech int imsRegTech) {
        ITelephony iTelephony = getITelephony();
        if (iTelephony == null) {
            throw new RuntimeException("Could not find Telephony Service.");
        }

        try {
            return getITelephony().isAvailable(mSubId, capability, imsRegTech);
            return iTelephony.isAvailable(mSubId, capability, imsRegTech);
        } catch (RemoteException e) {
            throw e.rethrowAsRuntimeException();
        }
@@ -745,6 +816,13 @@ public class ImsMmTelManager implements RegistrationManager {
        if (executor == null) {
            throw new IllegalArgumentException("Must include a non-null Executor.");
        }

        ITelephony iTelephony = getITelephony();
        if (iTelephony == null) {
            throw new ImsException("Could not find Telephony Service.",
                    ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
        }

        try {
            getITelephony().isMmTelCapabilitySupported(mSubId, new IIntegerConsumer.Stub() {
                @Override
@@ -789,8 +867,13 @@ public class ImsMmTelManager implements RegistrationManager {
            android.Manifest.permission.READ_PRECISE_PHONE_STATE})
    @SuppressAutoDoc // No support for device / profile owner or carrier privileges (b/72967236).
    public boolean isVtSettingEnabled() {
        ITelephony iTelephony = getITelephony();
        if (iTelephony == null) {
            throw new RuntimeException("Could not find Telephony Service.");
        }

        try {
            return getITelephony().isVtSettingEnabled(mSubId);
            return iTelephony.isVtSettingEnabled(mSubId);
        } catch (ServiceSpecificException e) {
            if (e.errorCode == ImsException.CODE_ERROR_INVALID_SUBSCRIPTION) {
                // Rethrow as runtime error to keep API compatible.
@@ -814,8 +897,13 @@ public class ImsMmTelManager implements RegistrationManager {
    @SystemApi @TestApi
    @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
    public void setVtSettingEnabled(boolean isEnabled) {
        ITelephony iTelephony = getITelephony();
        if (iTelephony == null) {
            throw new RuntimeException("Could not find Telephony Service.");
        }

        try {
            getITelephony().setVtSettingEnabled(mSubId, isEnabled);
            iTelephony.setVtSettingEnabled(mSubId, isEnabled);
        } catch (ServiceSpecificException e) {
            if (e.errorCode == ImsException.CODE_ERROR_INVALID_SUBSCRIPTION) {
                // Rethrow as runtime error to keep API compatible.
@@ -854,8 +942,13 @@ public class ImsMmTelManager implements RegistrationManager {
            android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
            android.Manifest.permission.READ_PRECISE_PHONE_STATE})
    public boolean isVoWiFiSettingEnabled() {
        ITelephony iTelephony = getITelephony();
        if (iTelephony == null) {
            throw new RuntimeException("Could not find Telephony Service.");
        }

        try {
            return getITelephony().isVoWiFiSettingEnabled(mSubId);
            return iTelephony.isVoWiFiSettingEnabled(mSubId);
        } catch (ServiceSpecificException e) {
            if (e.errorCode == ImsException.CODE_ERROR_INVALID_SUBSCRIPTION) {
                // Rethrow as runtime error to keep API compatible.
@@ -880,8 +973,13 @@ public class ImsMmTelManager implements RegistrationManager {
    @SystemApi @TestApi
    @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
    public void setVoWiFiSettingEnabled(boolean isEnabled) {
        ITelephony iTelephony = getITelephony();
        if (iTelephony == null) {
            throw new RuntimeException("Could not find Telephony Service.");
        }

        try {
            getITelephony().setVoWiFiSettingEnabled(mSubId, isEnabled);
            iTelephony.setVoWiFiSettingEnabled(mSubId, isEnabled);
        } catch (ServiceSpecificException e) {
            if (e.errorCode == ImsException.CODE_ERROR_INVALID_SUBSCRIPTION) {
                // Rethrow as runtime error to keep API compatible.
@@ -922,8 +1020,13 @@ public class ImsMmTelManager implements RegistrationManager {
            android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
            android.Manifest.permission.READ_PRECISE_PHONE_STATE})
    public boolean isVoWiFiRoamingSettingEnabled() {
        ITelephony iTelephony = getITelephony();
        if (iTelephony == null) {
            throw new RuntimeException("Could not find Telephony Service.");
        }

        try {
            return getITelephony().isVoWiFiRoamingSettingEnabled(mSubId);
            return iTelephony.isVoWiFiRoamingSettingEnabled(mSubId);
        } catch (ServiceSpecificException e) {
            if (e.errorCode == ImsException.CODE_ERROR_INVALID_SUBSCRIPTION) {
                // Rethrow as runtime error to keep API compatible.
@@ -949,8 +1052,13 @@ public class ImsMmTelManager implements RegistrationManager {
    @SystemApi @TestApi
    @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
    public void setVoWiFiRoamingSettingEnabled(boolean isEnabled) {
        ITelephony iTelephony = getITelephony();
        if (iTelephony == null) {
            throw new RuntimeException("Could not find Telephony Service.");
        }

        try {
            getITelephony().setVoWiFiRoamingSettingEnabled(mSubId, isEnabled);
            iTelephony.setVoWiFiRoamingSettingEnabled(mSubId, isEnabled);
        } catch (ServiceSpecificException e) {
            if (e.errorCode == ImsException.CODE_ERROR_INVALID_SUBSCRIPTION) {
                // Rethrow as runtime error to keep API compatible.
@@ -981,8 +1089,13 @@ public class ImsMmTelManager implements RegistrationManager {
    @SystemApi @TestApi
    @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
    public void setVoWiFiNonPersistent(boolean isCapable, int mode) {
        ITelephony iTelephony = getITelephony();
        if (iTelephony == null) {
            throw new RuntimeException("Could not find Telephony Service.");
        }

        try {
            getITelephony().setVoWiFiNonPersistent(mSubId, isCapable, mode);
            iTelephony.setVoWiFiNonPersistent(mSubId, isCapable, mode);
        } catch (ServiceSpecificException e) {
            if (e.errorCode == ImsException.CODE_ERROR_INVALID_SUBSCRIPTION) {
                // Rethrow as runtime error to keep API compatible.
@@ -1026,8 +1139,13 @@ public class ImsMmTelManager implements RegistrationManager {
            android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
            android.Manifest.permission.READ_PRECISE_PHONE_STATE})
    public @WiFiCallingMode int getVoWiFiModeSetting() {
        ITelephony iTelephony = getITelephony();
        if (iTelephony == null) {
            throw new RuntimeException("Could not find Telephony Service.");
        }

        try {
            return getITelephony().getVoWiFiModeSetting(mSubId);
            return iTelephony.getVoWiFiModeSetting(mSubId);
        } catch (ServiceSpecificException e) {
            if (e.errorCode == ImsException.CODE_ERROR_INVALID_SUBSCRIPTION) {
                // Rethrow as runtime error to keep API compatible.
@@ -1055,8 +1173,13 @@ public class ImsMmTelManager implements RegistrationManager {
    @SystemApi @TestApi
    @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
    public void setVoWiFiModeSetting(@WiFiCallingMode int mode) {
        ITelephony iTelephony = getITelephony();
        if (iTelephony == null) {
            throw new RuntimeException("Could not find Telephony Service.");
        }

        try {
            getITelephony().setVoWiFiModeSetting(mSubId, mode);
            iTelephony.setVoWiFiModeSetting(mSubId, mode);
        } catch (ServiceSpecificException e) {
            if (e.errorCode == ImsException.CODE_ERROR_INVALID_SUBSCRIPTION) {
                // Rethrow as runtime error to keep API compatible.
@@ -1086,8 +1209,13 @@ public class ImsMmTelManager implements RegistrationManager {
    @SystemApi @TestApi
    @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
    public @WiFiCallingMode int getVoWiFiRoamingModeSetting() {
        ITelephony iTelephony = getITelephony();
        if (iTelephony == null) {
            throw new RuntimeException("Could not find Telephony Service.");
        }

        try {
            return getITelephony().getVoWiFiRoamingModeSetting(mSubId);
            return iTelephony.getVoWiFiRoamingModeSetting(mSubId);
        } catch (ServiceSpecificException e) {
            if (e.errorCode == ImsException.CODE_ERROR_INVALID_SUBSCRIPTION) {
                // Rethrow as runtime error to keep API compatible.
@@ -1117,8 +1245,13 @@ public class ImsMmTelManager implements RegistrationManager {
    @SystemApi @TestApi
    @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
    public void setVoWiFiRoamingModeSetting(@WiFiCallingMode int mode) {
        ITelephony iTelephony = getITelephony();
        if (iTelephony == null) {
            throw new RuntimeException("Could not find Telephony Service.");
        }

        try {
            getITelephony().setVoWiFiRoamingModeSetting(mSubId, mode);
            iTelephony.setVoWiFiRoamingModeSetting(mSubId, mode);
        } catch (ServiceSpecificException e) {
            if (e.errorCode == ImsException.CODE_ERROR_INVALID_SUBSCRIPTION) {
                // Rethrow as runtime error to keep API compatible.
@@ -1146,8 +1279,13 @@ public class ImsMmTelManager implements RegistrationManager {
    @SystemApi @TestApi
    @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
    public void setRttCapabilitySetting(boolean isEnabled) {
        ITelephony iTelephony = getITelephony();
        if (iTelephony == null) {
            throw new RuntimeException("Could not find Telephony Service.");
        }

        try {
            getITelephony().setRttCapabilitySetting(mSubId, isEnabled);
            iTelephony.setRttCapabilitySetting(mSubId, isEnabled);
        } catch (ServiceSpecificException e) {
            if (e.errorCode == ImsException.CODE_ERROR_INVALID_SUBSCRIPTION) {
                // Rethrow as runtime error to keep API compatible.
@@ -1187,8 +1325,13 @@ public class ImsMmTelManager implements RegistrationManager {
            android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
            android.Manifest.permission.READ_PRECISE_PHONE_STATE})
    public boolean isTtyOverVolteEnabled() {
        ITelephony iTelephony = getITelephony();
        if (iTelephony == null) {
            throw new RuntimeException("Could not find Telephony Service.");
        }

        try {
            return getITelephony().isTtyOverVolteEnabled(mSubId);
            return iTelephony.isTtyOverVolteEnabled(mSubId);
        } catch (ServiceSpecificException e) {
            if (e.errorCode == ImsException.CODE_ERROR_INVALID_SUBSCRIPTION) {
                // Rethrow as runtime error to keep API compatible.
@@ -1224,8 +1367,15 @@ public class ImsMmTelManager implements RegistrationManager {
        if (callback == null) {
            throw new IllegalArgumentException("Must include a non-null Consumer.");
        }

        ITelephony iTelephony = getITelephony();
        if (iTelephony == null) {
            throw new ImsException("Could not find Telephony Service.",
                    ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
        }

        try {
            getITelephony().getImsMmTelFeatureState(mSubId, new IIntegerConsumer.Stub() {
            iTelephony.getImsMmTelFeatureState(mSubId, new IIntegerConsumer.Stub() {
                @Override
                public void accept(int result) {
                    executor.execute(() -> callback.accept(result));
@@ -1241,9 +1391,6 @@ public class ImsMmTelManager implements RegistrationManager {
    private static ITelephony getITelephony() {
        ITelephony binder = ITelephony.Stub.asInterface(
                ServiceManager.getService(Context.TELEPHONY_SERVICE));
        if (binder == null) {
            throw new RuntimeException("Could not find Telephony Service.");
        }
        return binder;
    }
}