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

Commit 3ba048e2 authored by Wink Saville's avatar Wink Saville Committed by The Android Automerger
Browse files

When phone changes update InBoundSmsHandlers and CellBroadcastHandlers.

Without this change for devices where the phone can change, for instance
on N5 with Sprint the phone will change from a GSMPhone to a CDMALTEPhone
and messages will not be sent to the appropriate handler.

For Sprint this was most readily seen when the voice mail notification
wasn't sent to the notification manager.

Bug: 11254397
Change-Id: Ia0e764cf6fa04208a7e194a35435f251a177309f
parent 2a374a4a
Loading
Loading
Loading
Loading
+3 −5
Original line number Diff line number Diff line
@@ -30,15 +30,13 @@ import android.telephony.SmsCbMessage;
 * completes and our result receiver is called.
 */
public class CellBroadcastHandler extends WakeLockStateMachine {
    private final Context mContext;

    private CellBroadcastHandler(Context context) {
        this("CellBroadcastHandler", context);
        this("CellBroadcastHandler", context, null);
    }

    protected CellBroadcastHandler(String debugTag, Context context) {
        super(debugTag, context);
        mContext = context;
    protected CellBroadcastHandler(String debugTag, Context context, PhoneBase phone) {
        super(debugTag, context, phone);
    }

    /**
+2 −0
Original line number Diff line number Diff line
@@ -79,6 +79,8 @@ public final class ImsSMSDispatcher extends SMSDispatcher {
        super.updatePhoneObject(phone);
        mCdmaDispatcher.updatePhoneObject(phone);
        mGsmDispatcher.updatePhoneObject(phone);
        mGsmInboundSmsHandler.updatePhoneObject(phone);
        mCdmaInboundSmsHandler.updatePhoneObject(phone);
    }

    public void dispose() {
+49 −9
Original line number Diff line number Diff line
@@ -114,6 +114,9 @@ public abstract class InboundSmsHandler extends StateMachine {
    /** Sent by {@link SmsBroadcastUndelivered} after cleaning the raw table. */
    static final int EVENT_START_ACCEPTING_SMS = 6;

    /** Update phone object */
    static final int EVENT_UPDATE_PHONE_OBJECT = 7;

    /** Wakelock release delay when returning to idle state. */
    private static final int WAKELOCK_TIMEOUT = 3000;

@@ -145,21 +148,29 @@ public abstract class InboundSmsHandler extends StateMachine {
    final WaitingState mWaitingState = new WaitingState();

    /** Helper class to check whether storage is available for incoming messages. */
    protected final SmsStorageMonitor mStorageMonitor;
    protected SmsStorageMonitor mStorageMonitor;

    private final boolean mSmsReceiveDisabled;

    protected PhoneBase mPhone;

    protected CellBroadcastHandler mCellBroadcastHandler;


    /**
     * Create a new SMS broadcast helper.
     * @param name the class name for logging
     * @param context the context of the phone app
     * @param storageMonitor the SmsStorageMonitor to check for storage availability
     */
    protected InboundSmsHandler(String name, Context context, SmsStorageMonitor storageMonitor) {
    protected InboundSmsHandler(String name, Context context, SmsStorageMonitor storageMonitor,
            PhoneBase phone, CellBroadcastHandler cellBroadcastHandler) {
        super(name);

        mContext = context;
        mStorageMonitor = storageMonitor;
        mPhone = phone;
        mCellBroadcastHandler = cellBroadcastHandler;
        mResolver = context.getContentResolver();
        mWapPush = new WapPushOverSms(context);

@@ -189,6 +200,13 @@ public abstract class InboundSmsHandler extends StateMachine {
        quit();
    }

    /**
     * Update the phone object when it changes.
     */
    public void updatePhoneObject(PhoneBase phone) {
        sendMessage(EVENT_UPDATE_PHONE_OBJECT, phone);
    }

    /**
     * Dispose of the WAP push object and release the wakelock.
     */
@@ -208,14 +226,23 @@ public abstract class InboundSmsHandler extends StateMachine {
    class DefaultState extends State {
        @Override
        public boolean processMessage(Message msg) {
            switch (msg.what) {
                case EVENT_UPDATE_PHONE_OBJECT: {
                    onUpdatePhoneObject((PhoneBase) msg.obj);
                    break;
                }
                default: {
                    String errorText = "processMessage: unhandled message type " + msg.what;
                    if (Build.IS_DEBUGGABLE) {
                        throw new RuntimeException(errorText);
                    } else {
                        loge(errorText);
                return HANDLED;
                    }
                    break;
                }
            }
            return HANDLED;
        }
    }

    /**
@@ -454,6 +481,19 @@ public abstract class InboundSmsHandler extends StateMachine {
    protected abstract void acknowledgeLastIncomingSms(boolean success,
            int result, Message response);

    /**
     * Called when the phone changes the default method updates mPhone
     * mStorageMonitor and mCellBroadcastHandler.updatePhoneObject.
     * Override if different or other behavior is desired.
     *
     * @param phone
     */
    protected void onUpdatePhoneObject(PhoneBase phone) {
        mPhone = phone;
        mStorageMonitor = mPhone.mSmsStorageMonitor;
        log("onUpdatePhoneObject: phone=" + mPhone.getClass().getSimpleName());
    }

    /**
     * Notify interested apps if the framework has rejected an incoming SMS,
     * and send an acknowledge message to the network.
+31 −8
Original line number Diff line number Diff line
@@ -48,6 +48,12 @@ public abstract class WakeLockStateMachine extends StateMachine {
    /** Release wakelock after a short timeout when returning to idle state. */
    static final int EVENT_RELEASE_WAKE_LOCK = 3;

    static final int EVENT_UPDATE_PHONE_OBJECT = 4;

    protected PhoneBase mPhone;

    protected Context mContext;

    /** Wakelock release delay when returning to idle state. */
    private static final int WAKE_LOCK_TIMEOUT = 3000;

@@ -55,9 +61,12 @@ public abstract class WakeLockStateMachine extends StateMachine {
    private final IdleState mIdleState = new IdleState();
    private final WaitingState mWaitingState = new WaitingState();

    protected WakeLockStateMachine(String debugTag, Context context) {
    protected WakeLockStateMachine(String debugTag, Context context, PhoneBase phone) {
        super(debugTag);

        mContext = context;
        mPhone = phone;

        PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, debugTag);
        mWakeLock.acquire();    // wake lock released after we enter idle state
@@ -68,6 +77,10 @@ public abstract class WakeLockStateMachine extends StateMachine {
        setInitialState(mIdleState);
    }

    public void updatePhoneObject(PhoneBase phone) {
        sendMessage(EVENT_UPDATE_PHONE_OBJECT, phone);
    }

    /**
     * Tell the state machine to quit after processing all messages.
     */
@@ -98,13 +111,23 @@ public abstract class WakeLockStateMachine extends StateMachine {
    class DefaultState extends State {
        @Override
        public boolean processMessage(Message msg) {
            switch (msg.what) {
                case EVENT_UPDATE_PHONE_OBJECT: {
                    mPhone = (PhoneBase) msg.obj;
                    log("updatePhoneObject: phone=" + mPhone.getClass().getSimpleName());
                    break;
                }
                default: {
                    String errorText = "processMessage: unhandled message type " + msg.what;
                    if (Build.IS_DEBUGGABLE) {
                        throw new RuntimeException(errorText);
                    } else {
                        loge(errorText);
                return HANDLED;
                    }
                    break;
                }
            }
            return HANDLED;
        }
    }

+15 −5
Original line number Diff line number Diff line
@@ -45,9 +45,7 @@ import java.util.Arrays;
 */
public class CdmaInboundSmsHandler extends InboundSmsHandler {

    private final PhoneBase mPhone;
    private final CdmaSMSDispatcher mSmsDispatcher;
    private final CellBroadcastHandler mCellBroadcastHandler;
    private final CdmaServiceCategoryProgramHandler mServiceCategoryProgramHandler;

    private byte[] mLastDispatchedSmsFingerprint;
@@ -61,12 +59,11 @@ public class CdmaInboundSmsHandler extends InboundSmsHandler {
     */
    private CdmaInboundSmsHandler(Context context, SmsStorageMonitor storageMonitor,
            PhoneBase phone, CdmaSMSDispatcher smsDispatcher) {
        super("CdmaInboundSmsHandler", context, storageMonitor);
        super("CdmaInboundSmsHandler", context, storageMonitor, phone,
                CellBroadcastHandler.makeCellBroadcastHandler(context));
        mSmsDispatcher = smsDispatcher;
        mCellBroadcastHandler = CellBroadcastHandler.makeCellBroadcastHandler(context);
        mServiceCategoryProgramHandler = CdmaServiceCategoryProgramHandler.makeScpHandler(context,
                phone.mCi);
        mPhone = phone;
        phone.mCi.setOnNewCdmaSms(getHandler(), EVENT_NEW_SMS, null);
    }

@@ -213,6 +210,19 @@ public class CdmaInboundSmsHandler extends InboundSmsHandler {
        mLastDispatchedSmsFingerprint = null;
    }

    /**
     * Called when the phone changes the default method updates mPhone
     * mStorageMonitor and mCellBroadcastHandler.updatePhoneObject.
     * Override if different or other behavior is desired.
     *
     * @param phone
     */
    @Override
    protected void onUpdatePhoneObject(PhoneBase phone) {
        super.onUpdatePhoneObject(phone);
        mCellBroadcastHandler.updatePhoneObject(phone);
    }

    /**
     * Convert Android result code to CDMA SMS failure cause.
     * @param rc the Android SMS intent result value
Loading