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

Commit 7961ac2c authored by Adam Lesinski's avatar Adam Lesinski
Browse files

SmsManager responds gracefully to no backing service

Previously we would get an NPE if there was no isms service
running on the device. Now we return sensible defaults
and throw UnsupportedOperationException for methods
that are meant to invoke actions and have a void
return type.

Change-Id: I894809a0d6431b7c6472ec6f69d3b8e84a1418ea
parent d5adcb04
Loading
Loading
Loading
Loading
+37 −27
Original line number Diff line number Diff line
@@ -96,11 +96,9 @@ public final class SmsManager {
        }

        try {
            ISms iccISms = ISms.Stub.asInterface(ServiceManager.getService("isms"));
            if (iccISms != null) {
            ISms iccISms = getISmsServiceOrThrow();
            iccISms.sendText(ActivityThread.currentPackageName(), destinationAddress,
                    scAddress, text, sentIntent, deliveryIntent);
            }
        } catch (RemoteException ex) {
            // ignore it
        }
@@ -176,12 +174,10 @@ public final class SmsManager {

        if (parts.size() > 1) {
            try {
                ISms iccISms = ISms.Stub.asInterface(ServiceManager.getService("isms"));
                if (iccISms != null) {
                ISms iccISms = getISmsServiceOrThrow();
                iccISms.sendMultipartText(ActivityThread.currentPackageName(),
                        destinationAddress, scAddress, parts,
                        sentIntents, deliveryIntents);
                }
            } catch (RemoteException ex) {
                // ignore it
            }
@@ -241,12 +237,10 @@ public final class SmsManager {
        }

        try {
            ISms iccISms = ISms.Stub.asInterface(ServiceManager.getService("isms"));
            if (iccISms != null) {
            ISms iccISms = getISmsServiceOrThrow();
            iccISms.sendData(ActivityThread.currentPackageName(),
                    destinationAddress, scAddress, destinationPort & 0xFFFF,
                    data, sentIntent, deliveryIntent);
            }
        } catch (RemoteException ex) {
            // ignore it
        }
@@ -265,6 +259,22 @@ public final class SmsManager {
        //nothing
    }

    /**
     * Returns the ISms service, or throws an UnsupportedOperationException if
     * the service does not exist.
     */
    private static ISms getISmsServiceOrThrow() {
        ISms iccISms = getISmsService();
        if (iccISms == null) {
            throw new UnsupportedOperationException("Sms is not supported");
        }
        return iccISms;
    }

    private static ISms getISmsService() {
        return ISms.Stub.asInterface(ServiceManager.getService("isms"));
    }

    /**
     * Copy a raw SMS PDU to the ICC.
     * ICC (Integrated Circuit Card) is the card of the device.
@@ -286,7 +296,7 @@ public final class SmsManager {
            throw new IllegalArgumentException("pdu is NULL");
        }
        try {
            ISms iccISms = ISms.Stub.asInterface(ServiceManager.getService("isms"));
            ISms iccISms = getISmsService();
            if (iccISms != null) {
                success = iccISms.copyMessageToIccEf(ActivityThread.currentPackageName(),
                        status, pdu, smsc);
@@ -315,7 +325,7 @@ public final class SmsManager {
        Arrays.fill(pdu, (byte)0xff);

        try {
            ISms iccISms = ISms.Stub.asInterface(ServiceManager.getService("isms"));
            ISms iccISms = getISmsService();
            if (iccISms != null) {
                success = iccISms.updateMessageOnIccEf(ActivityThread.currentPackageName(),
                        messageIndex, STATUS_ON_ICC_FREE, pdu);
@@ -345,7 +355,7 @@ public final class SmsManager {
        boolean success = false;

        try {
            ISms iccISms = ISms.Stub.asInterface(ServiceManager.getService("isms"));
            ISms iccISms = getISmsService();
            if (iccISms != null) {
                success = iccISms.updateMessageOnIccEf(ActivityThread.currentPackageName(),
                        messageIndex, newStatus, pdu);
@@ -370,7 +380,7 @@ public final class SmsManager {
        List<SmsRawData> records = null;

        try {
            ISms iccISms = ISms.Stub.asInterface(ServiceManager.getService("isms"));
            ISms iccISms = getISmsService();
            if (iccISms != null) {
                records = iccISms.getAllMessagesFromIccEf(ActivityThread.currentPackageName());
            }
@@ -401,7 +411,7 @@ public final class SmsManager {
        boolean success = false;

        try {
            ISms iccISms = ISms.Stub.asInterface(ServiceManager.getService("isms"));
            ISms iccISms = getISmsService();
            if (iccISms != null) {
                success = iccISms.enableCellBroadcast(messageIdentifier);
            }
@@ -432,7 +442,7 @@ public final class SmsManager {
        boolean success = false;

        try {
            ISms iccISms = ISms.Stub.asInterface(ServiceManager.getService("isms"));
            ISms iccISms = getISmsService();
            if (iccISms != null) {
                success = iccISms.disableCellBroadcast(messageIdentifier);
            }
@@ -469,7 +479,7 @@ public final class SmsManager {
            throw new IllegalArgumentException("endMessageId < startMessageId");
        }
        try {
            ISms iccISms = ISms.Stub.asInterface(ServiceManager.getService("isms"));
            ISms iccISms = getISmsService();
            if (iccISms != null) {
                success = iccISms.enableCellBroadcastRange(startMessageId, endMessageId);
            }
@@ -506,7 +516,7 @@ public final class SmsManager {
            throw new IllegalArgumentException("endMessageId < startMessageId");
        }
        try {
            ISms iccISms = ISms.Stub.asInterface(ServiceManager.getService("isms"));
            ISms iccISms = getISmsService();
            if (iccISms != null) {
                success = iccISms.disableCellBroadcastRange(startMessageId, endMessageId);
            }
@@ -556,7 +566,7 @@ public final class SmsManager {
    boolean isImsSmsSupported() {
        boolean boSupported = false;
        try {
            ISms iccISms = ISms.Stub.asInterface(ServiceManager.getService("isms"));
            ISms iccISms = getISmsService();
            if (iccISms != null) {
                boSupported = iccISms.isImsSmsSupported();
            }
@@ -581,7 +591,7 @@ public final class SmsManager {
    String getImsSmsFormat() {
        String format = com.android.internal.telephony.SmsConstants.FORMAT_UNKNOWN;
        try {
            ISms iccISms = ISms.Stub.asInterface(ServiceManager.getService("isms"));
            ISms iccISms = getISmsService();
            if (iccISms != null) {
                format = iccISms.getImsSmsFormat();
            }
+42 −20
Original line number Diff line number Diff line
@@ -50,7 +50,9 @@ public class DefaultPhoneNotifier implements PhoneNotifier {
            incomingNumber = ringingCall.getEarliestConnection().getAddress();
        }
        try {
            if (mRegistry != null) {
                mRegistry.notifyCallState(convertCallState(sender.getState()), incomingNumber);
            }
        } catch (RemoteException ex) {
            // system process is dead
        }
@@ -64,7 +66,9 @@ public class DefaultPhoneNotifier implements PhoneNotifier {
            ss.setStateOutOfService();
        }
        try {
            if (mRegistry != null) {
                mRegistry.notifyServiceState(ss);
            }
        } catch (RemoteException ex) {
            // system process is dead
        }
@@ -73,7 +77,9 @@ public class DefaultPhoneNotifier implements PhoneNotifier {
    @Override
    public void notifySignalStrength(Phone sender) {
        try {
            if (mRegistry != null) {
                mRegistry.notifySignalStrength(sender.getSignalStrength());
            }
        } catch (RemoteException ex) {
            // system process is dead
        }
@@ -82,7 +88,9 @@ public class DefaultPhoneNotifier implements PhoneNotifier {
    @Override
    public void notifyMessageWaitingChanged(Phone sender) {
        try {
            if (mRegistry != null) {
                mRegistry.notifyMessageWaitingChanged(sender.getMessageWaitingIndicator());
            }
        } catch (RemoteException ex) {
            // system process is dead
        }
@@ -91,7 +99,9 @@ public class DefaultPhoneNotifier implements PhoneNotifier {
    @Override
    public void notifyCallForwardingChanged(Phone sender) {
        try {
            if (mRegistry != null) {
                mRegistry.notifyCallForwardingChanged(sender.getCallForwardingIndicator());
            }
        } catch (RemoteException ex) {
            // system process is dead
        }
@@ -100,7 +110,9 @@ public class DefaultPhoneNotifier implements PhoneNotifier {
    @Override
    public void notifyDataActivity(Phone sender) {
        try {
            if (mRegistry != null) {
                mRegistry.notifyDataActivity(convertDataActivityState(sender.getDataActivityState()));
            }
        } catch (RemoteException ex) {
            // system process is dead
        }
@@ -130,6 +142,7 @@ public class DefaultPhoneNotifier implements PhoneNotifier {
        if (ss != null) roaming = ss.getRoaming();

        try {
            if (mRegistry != null) {
                mRegistry.notifyDataConnection(
                        convertDataState(state),
                        sender.isDataConnectivityPossible(apnType), reason,
@@ -140,6 +153,7 @@ public class DefaultPhoneNotifier implements PhoneNotifier {
                        ((telephony!=null) ? telephony.getNetworkType() :
                                TelephonyManager.NETWORK_TYPE_UNKNOWN),
                        roaming);
            }
        } catch (RemoteException ex) {
            // system process is dead
        }
@@ -148,7 +162,9 @@ public class DefaultPhoneNotifier implements PhoneNotifier {
    @Override
    public void notifyDataConnectionFailed(Phone sender, String reason, String apnType) {
        try {
            if (mRegistry != null) {
                mRegistry.notifyDataConnectionFailed(reason, apnType);
            }
        } catch (RemoteException ex) {
            // system process is dead
        }
@@ -159,7 +175,9 @@ public class DefaultPhoneNotifier implements PhoneNotifier {
        Bundle data = new Bundle();
        sender.getCellLocation().fillInNotifierBundle(data);
        try {
            if (mRegistry != null) {
                mRegistry.notifyCellLocation(data);
            }
        } catch (RemoteException ex) {
            // system process is dead
        }
@@ -168,7 +186,9 @@ public class DefaultPhoneNotifier implements PhoneNotifier {
    @Override
    public void notifyCellInfo(Phone sender, List<CellInfo> cellInfo) {
        try {
            if (mRegistry != null) {
                mRegistry.notifyCellInfo(cellInfo);
            }
        } catch (RemoteException ex) {

        }
@@ -177,7 +197,9 @@ public class DefaultPhoneNotifier implements PhoneNotifier {
    @Override
    public void notifyOtaspChanged(Phone sender, int otaspMode) {
        try {
            if (mRegistry != null) {
                mRegistry.notifyOtaspChanged(otaspMode);
            }
        } catch (RemoteException ex) {
            // system process is dead
        }