diff options
Diffstat (limited to 'src/com/android/cellbroadcastreceiver/CellBroadcastReceiver.java')
-rw-r--r-- | src/com/android/cellbroadcastreceiver/CellBroadcastReceiver.java | 80 |
1 files changed, 55 insertions, 25 deletions
diff --git a/src/com/android/cellbroadcastreceiver/CellBroadcastReceiver.java b/src/com/android/cellbroadcastreceiver/CellBroadcastReceiver.java index 8c747637..42cf053b 100644 --- a/src/com/android/cellbroadcastreceiver/CellBroadcastReceiver.java +++ b/src/com/android/cellbroadcastreceiver/CellBroadcastReceiver.java @@ -21,6 +21,7 @@ import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.PackageManager; +import android.os.Bundle; import android.os.RemoteException; import android.os.ServiceManager; import android.os.UserHandle; @@ -28,13 +29,20 @@ import android.preference.PreferenceManager; import android.provider.Telephony; import android.telephony.CellBroadcastMessage; import android.telephony.ServiceState; +import android.telephony.SubscriptionInfo; +import android.telephony.SubscriptionManager; import android.telephony.TelephonyManager; import android.telephony.cdma.CdmaSmsCbProgramData; import android.util.Log; +import com.android.internal.telephony.PhoneConstants; import com.android.internal.telephony.ITelephony; +import com.android.internal.telephony.IccCardConstants; import com.android.internal.telephony.cdma.sms.SmsEnvelope; import com.android.internal.telephony.TelephonyIntents; +import com.android.internal.telephony.uicc.IccCardProxy; + +import java.util.List; public class CellBroadcastReceiver extends BroadcastReceiver { private static final String TAG = "CellBroadcastReceiver"; @@ -55,16 +63,33 @@ public class CellBroadcastReceiver extends BroadcastReceiver { if (TelephonyIntents.ACTION_SERVICE_STATE_CHANGED.equals(action)) { if (DBG) log("Intent ACTION_SERVICE_STATE_CHANGED"); + int subId = intent.getExtras().getInt(PhoneConstants.SUBSCRIPTION_KEY); + Log.d(TAG, "subscriptionId = " + subId); + if (!SubscriptionManager.isValidSubscriptionId(subId)) { + return; + } 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)) && (UserHandle.myUserId() == UserHandle.USER_OWNER)) { - startConfigService(context.getApplicationContext()); + startConfigService(context.getApplicationContext(), subId); + } + } + } else if (IccCardProxy.ACTION_INTERNAL_SIM_STATE_CHANGED.equals(action)){ + String simStatus = intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE); + if (IccCardConstants.INTENT_VALUE_ICC_LOADED.equals(simStatus)) { + List<SubscriptionInfo> subscriptionInfoList = SubscriptionManager.from( + context).getActiveSubscriptionInfoList(); + if (subscriptionInfoList != null) { + for (SubscriptionInfo subInfo : subscriptionInfoList) { + startConfigService(context, subInfo.getSubscriptionId()); + } } } } else if (Telephony.Sms.Intents.SMS_EMERGENCY_CB_RECEIVED_ACTION.equals(action) || @@ -85,7 +110,9 @@ public class CellBroadcastReceiver extends BroadcastReceiver { CdmaSmsCbProgramData[] programDataList = (CdmaSmsCbProgramData[]) intent.getParcelableArrayExtra("program_data_list"); if (programDataList != null) { - handleCdmaSmsCbProgramData(context, programDataList); + int subId = intent.getExtras().getInt(PhoneConstants.SUBSCRIPTION_KEY); + Log.d(TAG, "subscriptionId = " + subId); + handleCdmaSmsCbProgramData(context, programDataList, subId); } else { loge("SCPD intent received with no program_data_list"); } @@ -122,26 +149,27 @@ public class CellBroadcastReceiver extends BroadcastReceiver { * @param programDataList */ private void handleCdmaSmsCbProgramData(Context context, - CdmaSmsCbProgramData[] programDataList) { + CdmaSmsCbProgramData[] programDataList, int subId) { for (CdmaSmsCbProgramData programData : programDataList) { switch (programData.getOperation()) { case CdmaSmsCbProgramData.OPERATION_ADD_CATEGORY: - tryCdmaSetCategory(context, programData.getCategory(), true); + tryCdmaSetCategory(context, programData.getCategory(), true, subId); break; case CdmaSmsCbProgramData.OPERATION_DELETE_CATEGORY: - tryCdmaSetCategory(context, programData.getCategory(), false); + tryCdmaSetCategory(context, programData.getCategory(), false, subId); break; case CdmaSmsCbProgramData.OPERATION_CLEAR_CATEGORIES: tryCdmaSetCategory(context, - SmsEnvelope.SERVICE_CATEGORY_CMAS_EXTREME_THREAT, false); + SmsEnvelope.SERVICE_CATEGORY_CMAS_EXTREME_THREAT, false, subId); tryCdmaSetCategory(context, - SmsEnvelope.SERVICE_CATEGORY_CMAS_SEVERE_THREAT, false); + SmsEnvelope.SERVICE_CATEGORY_CMAS_SEVERE_THREAT, false, subId); tryCdmaSetCategory(context, - SmsEnvelope.SERVICE_CATEGORY_CMAS_CHILD_ABDUCTION_EMERGENCY, false); + SmsEnvelope.SERVICE_CATEGORY_CMAS_CHILD_ABDUCTION_EMERGENCY, false, + subId); tryCdmaSetCategory(context, - SmsEnvelope.SERVICE_CATEGORY_CMAS_TEST_MESSAGE, false); + SmsEnvelope.SERVICE_CATEGORY_CMAS_TEST_MESSAGE, false, subId); break; default: @@ -150,30 +178,30 @@ public class CellBroadcastReceiver extends BroadcastReceiver { } } - private void tryCdmaSetCategory(Context context, int category, boolean enable) { - SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); - + private void tryCdmaSetCategory(Context context, int category, boolean enable, int subId) { switch (category) { case SmsEnvelope.SERVICE_CATEGORY_CMAS_EXTREME_THREAT: - sharedPrefs.edit().putBoolean( - CellBroadcastSettings.KEY_ENABLE_CMAS_EXTREME_THREAT_ALERTS, enable) - .apply(); + SubscriptionManager.setSubscriptionProperty(subId, + SubscriptionManager.CB_EXTREME_THREAT_ALERT, + (enable ? "1" : "0")); break; case SmsEnvelope.SERVICE_CATEGORY_CMAS_SEVERE_THREAT: - sharedPrefs.edit().putBoolean( - CellBroadcastSettings.KEY_ENABLE_CMAS_SEVERE_THREAT_ALERTS, enable) - .apply(); + SubscriptionManager.setSubscriptionProperty(subId, + SubscriptionManager.CB_SEVERE_THREAT_ALERT, + (enable ? "1" : "0")); break; case SmsEnvelope.SERVICE_CATEGORY_CMAS_CHILD_ABDUCTION_EMERGENCY: - sharedPrefs.edit().putBoolean( - CellBroadcastSettings.KEY_ENABLE_CMAS_AMBER_ALERTS, enable).apply(); + SubscriptionManager.setSubscriptionProperty(subId, + SubscriptionManager.CB_AMBER_ALERT, + (enable ? "1" : "0")); break; case SmsEnvelope.SERVICE_CATEGORY_CMAS_TEST_MESSAGE: - sharedPrefs.edit().putBoolean( - CellBroadcastSettings.KEY_ENABLE_CMAS_TEST_ALERTS, enable).apply(); + SubscriptionManager.setSubscriptionProperty(subId, + SubscriptionManager.CB_CMAS_TEST_ALERT, + (enable ? "1" : "0")); break; default: @@ -186,21 +214,23 @@ public class CellBroadcastReceiver extends BroadcastReceiver { * Tell {@link CellBroadcastConfigService} to enable the CB channels. * @param context the broadcast receiver context */ - static void startConfigService(Context context) { + static void startConfigService(Context context, int subId) { Intent serviceIntent = new Intent(CellBroadcastConfigService.ACTION_ENABLE_CHANNELS, null, context, CellBroadcastConfigService.class); + serviceIntent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId); context.startService(serviceIntent); } /** * @return true if the phone is a CDMA phone type */ - static boolean phoneIsCdma() { + static boolean phoneIsCdma(int subId) { boolean isCdma = false; try { ITelephony phone = ITelephony.Stub.asInterface(ServiceManager.checkService("phone")); if (phone != null) { - isCdma = (phone.getActivePhoneType() == TelephonyManager.PHONE_TYPE_CDMA); + isCdma = (phone.getActivePhoneTypeForSubscriber(subId) == + TelephonyManager.PHONE_TYPE_CDMA); } } catch (RemoteException e) { Log.w(TAG, "phone.getActivePhoneType() failed", e); |