From 0a2aef9d9ece08c4821f3eaf8208314af4d77dd0 Mon Sep 17 00:00:00 2001 From: xinhe Date: Tue, 30 Sep 2014 15:14:39 -0700 Subject: Fix for CMAS is not turned on CMAS is not turned on for several reasons: (1) Exception happends when default SMS sub Id is not available. (2) Cellbroadcast thread can die before the servicestate change triggered Bug:17571958 Change-Id: I7b210226fa24f266896763ff80235c4ed4b936eb --- .../CellBroadcastReceiver.java | 45 ++++++++-------------- 1 file changed, 15 insertions(+), 30 deletions(-) (limited to 'src/com/android') diff --git a/src/com/android/cellbroadcastreceiver/CellBroadcastReceiver.java b/src/com/android/cellbroadcastreceiver/CellBroadcastReceiver.java index c1eeeab7..a04cc2c7 100644 --- a/src/com/android/cellbroadcastreceiver/CellBroadcastReceiver.java +++ b/src/com/android/cellbroadcastreceiver/CellBroadcastReceiver.java @@ -27,7 +27,6 @@ import android.os.UserHandle; import android.preference.PreferenceManager; import android.provider.Telephony; import android.telephony.CellBroadcastMessage; -import android.telephony.PhoneStateListener; import android.telephony.ServiceState; import android.telephony.TelephonyManager; import android.telephony.cdma.CdmaSmsCbProgramData; @@ -35,11 +34,12 @@ import android.util.Log; import com.android.internal.telephony.ITelephony; import com.android.internal.telephony.cdma.sms.SmsEnvelope; +import com.android.internal.telephony.TelephonyIntents; public class CellBroadcastReceiver extends BroadcastReceiver { private static final String TAG = "CellBroadcastReceiver"; static final boolean DBG = true; // STOPSHIP: change to false before ship - + private int mServiceState = -1; private static final String GET_LATEST_CB_AREA_INFO_ACTION = "android.cellbroadcastreceiver.GET_LATEST_CB_AREA_INFO"; @@ -53,12 +53,19 @@ public class CellBroadcastReceiver extends BroadcastReceiver { String action = intent.getAction(); - if (Intent.ACTION_BOOT_COMPLETED.equals(action)) { - if (DBG) log("Registering for ServiceState updates"); - TelephonyManager tm = (TelephonyManager) context.getSystemService( - Context.TELEPHONY_SERVICE); - tm.listen(new ServiceStateListener(context.getApplicationContext()), - PhoneStateListener.LISTEN_SERVICE_STATE); + if (TelephonyIntents.ACTION_SERVICE_STATE_CHANGED.equals(action)) { + if (DBG) log("Intent ACTION_SERVICE_STATE_CHANGED"); + ServiceState serviceState = ServiceState.newFromBundle(intent.getExtras()); + int newState = serviceState.getState(); + if (newState != mServiceState) { + Log.d(TAG, "Service state changed! " + newState + " Full: " + serviceState + + " Current state=" + mServiceState); + mServiceState = newState; + if (newState == ServiceState.STATE_IN_SERVICE || + newState == ServiceState.STATE_EMERGENCY_ONLY) { + startConfigService(context.getApplicationContext()); + } + } } else if (Intent.ACTION_AIRPLANE_MODE_CHANGED.equals(action)) { boolean airplaneModeOn = intent.getBooleanExtra("state", false); if (DBG) log("airplaneModeOn: " + airplaneModeOn); @@ -202,28 +209,6 @@ public class CellBroadcastReceiver extends BroadcastReceiver { return isCdma; } - private static class ServiceStateListener extends PhoneStateListener { - private final Context mContext; - private int mServiceState = -1; - - ServiceStateListener(Context context) { - mContext = context; - } - - @Override - public void onServiceStateChanged(ServiceState ss) { - int newState = ss.getState(); - if (newState != mServiceState) { - Log.d(TAG, "Service state changed! " + newState + " Full: " + ss); - mServiceState = newState; - if (newState == ServiceState.STATE_IN_SERVICE || - newState == ServiceState.STATE_EMERGENCY_ONLY) { - startConfigService(mContext); - } - } - } - } - private static void log(String msg) { Log.d(TAG, msg); } -- cgit v1.2.3