Loading src/java/com/android/internal/telephony/IntentBroadcaster.java 0 → 100644 +102 −0 Original line number Diff line number Diff line /* * Copyright (C) 2017 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.internal.telephony; import android.app.ActivityManager; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.os.UserHandle; import android.util.Log; import java.util.HashMap; import java.util.Iterator; import java.util.Map; /** * This class is used to broadcast intents that need to be rebroadcast after the device is unlocked. * NOTE: Currently this is used only for SIM_STATE_CHANGED so logic is hardcoded for that; * for example broadcasts are always sticky, only the last intent for the slotId is rebroadcast, * etc. */ public class IntentBroadcaster { private static final String TAG = "IntentBroadcaster"; private Map<Integer, Intent> mRebroadcastIntents = new HashMap<>(); private static IntentBroadcaster sIntentBroadcaster; private final BroadcastReceiver mReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (action.equals(Intent.ACTION_USER_UNLOCKED)) { synchronized (mRebroadcastIntents) { // rebroadcast intents Iterator iterator = mRebroadcastIntents.entrySet().iterator(); while (iterator.hasNext()) { Map.Entry pair = (Map.Entry) iterator.next(); Intent i = (Intent) pair.getValue(); i.putExtra(TelephonyIntents.EXTRA_REBROADCAST_ON_UNLOCK, true); iterator.remove(); logd("Rebroadcasting intent " + i.getAction() + " " + i.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE) + " for slotId " + pair.getKey()); ActivityManager.broadcastStickyIntent(i, UserHandle.USER_ALL); } } } } }; private IntentBroadcaster(Context context) { context.registerReceiver(mReceiver, new IntentFilter(Intent.ACTION_USER_UNLOCKED)); } /** * Method to get an instance of IntentBroadcaster after creating one if needed. * @return IntentBroadcaster instance */ public static IntentBroadcaster getInstance(Context context) { if (sIntentBroadcaster == null) { sIntentBroadcaster = new IntentBroadcaster(context); } return sIntentBroadcaster; } public static IntentBroadcaster getInstance() { return sIntentBroadcaster; } /** * Wrapper for ActivityManager.broadcastStickyIntent() that also stores intent to be rebroadcast * on USER_UNLOCKED */ public void broadcastStickyIntent(Intent intent, int slotId) { logd("Broadcasting and adding intent for rebroadcast: " + intent.getAction() + " " + intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE) + " for slotId " + slotId); synchronized (mRebroadcastIntents) { ActivityManager.broadcastStickyIntent(intent, UserHandle.USER_ALL); mRebroadcastIntents.put(slotId, intent); } } private void logd(String s) { Log.d(TAG, s); } } src/java/com/android/internal/telephony/PhoneFactory.java +3 −0 Original line number Diff line number Diff line Loading @@ -74,6 +74,7 @@ public class PhoneFactory { static private ProxyController sProxyController; static private UiccController sUiccController; private static IntentBroadcaster sIntentBroadcaster; static private CommandsInterface sCommandsInterface = null; static private SubscriptionInfoUpdater sSubInfoRecordUpdater = null; Loading Loading @@ -238,6 +239,8 @@ public class PhoneFactory { sProxyController = ProxyController.getInstance(context, sPhones, sUiccController, sCommandsInterfaces, sPhoneSwitcher); sIntentBroadcaster = IntentBroadcaster.getInstance(context); sNotificationChannelController = new NotificationChannelController(context); sTelephonyNetworkFactories = new TelephonyNetworkFactory[numPhones]; Loading src/java/com/android/internal/telephony/SubscriptionInfoUpdater.java +1 −28 Original line number Diff line number Diff line Loading @@ -32,8 +32,6 @@ import android.os.IRemoteCallback; import android.os.Message; import android.os.RemoteException; import android.os.ServiceManager; import android.os.UserHandle; import android.os.UserManager; import android.preference.PreferenceManager; import android.provider.Settings; import android.telephony.CarrierConfigManager; Loading @@ -51,10 +49,7 @@ import com.android.internal.telephony.uicc.IccUtils; import java.io.FileDescriptor; import java.io.PrintWriter; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; /** *@hide Loading Loading @@ -105,8 +100,6 @@ public class SubscriptionInfoUpdater extends Handler { private static int[] mInsertSimState = new int[PROJECT_SIM_NUM]; private SubscriptionManager mSubscriptionManager = null; private IPackageManager mPackageManager; private UserManager mUserManager; private Map<Integer, Intent> rebroadcastIntentsOnUnlock = new HashMap<>(); // The current foreground user ID. private int mCurrentlyActiveUserId; Loading @@ -119,11 +112,9 @@ public class SubscriptionInfoUpdater extends Handler { mPhone = phone; mSubscriptionManager = SubscriptionManager.from(mContext); mPackageManager = IPackageManager.Stub.asInterface(ServiceManager.getService("package")); mUserManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE); IntentFilter intentFilter = new IntentFilter(TelephonyIntents.ACTION_SIM_STATE_CHANGED); intentFilter.addAction(IccCardProxy.ACTION_INTERNAL_SIM_STATE_CHANGED); intentFilter.addAction(Intent.ACTION_USER_UNLOCKED); mContext.registerReceiver(sReceiver, intentFilter); mCarrierServiceBindHelper = new CarrierServiceBindHelper(mContext); Loading Loading @@ -170,22 +161,6 @@ public class SubscriptionInfoUpdater extends Handler { String action = intent.getAction(); logd("Action: " + action); if (action.equals(Intent.ACTION_USER_UNLOCKED)) { // broadcast pending intents Iterator iterator = rebroadcastIntentsOnUnlock.entrySet().iterator(); while (iterator.hasNext()) { Map.Entry pair = (Map.Entry) iterator.next(); Intent i = (Intent)pair.getValue(); i.putExtra(TelephonyIntents.EXTRA_REBROADCAST_ON_UNLOCK, true); iterator.remove(); logd("Broadcasting intent ACTION_SIM_STATE_CHANGED for mCardIndex: " + pair.getKey()); ActivityManager.broadcastStickyIntent(i, UserHandle.USER_ALL); } logd("[Receiver]-"); return; } if (!action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED) && !action.equals(IccCardProxy.ACTION_INTERNAL_SIM_STATE_CHANGED)) { return; Loading @@ -203,7 +178,6 @@ public class SubscriptionInfoUpdater extends Handler { logd("simStatus: " + simStatus); if (action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) { rebroadcastIntentsOnUnlock.put(slotIndex, intent); if (IccCardConstants.INTENT_VALUE_ICC_ABSENT.equals(simStatus)) { sendMessage(obtainMessage(EVENT_SIM_ABSENT, slotIndex, -1)); } else if (IccCardConstants.INTENT_VALUE_ICC_UNKNOWN.equals(simStatus)) { Loading Loading @@ -685,8 +659,7 @@ public class SubscriptionInfoUpdater extends Handler { SubscriptionManager.putPhoneIdAndSubIdExtra(i, slotId); logd("Broadcasting intent ACTION_SIM_STATE_CHANGED " + state + " reason " + reason + " for mCardIndex: " + slotId); ActivityManager.broadcastStickyIntent(i, UserHandle.USER_ALL); rebroadcastIntentsOnUnlock.put(slotId, i); IntentBroadcaster.getInstance().broadcastStickyIntent(i, slotId); } public void dispose() { Loading src/java/com/android/internal/telephony/uicc/IccCardProxy.java +2 −1 Original line number Diff line number Diff line Loading @@ -36,6 +36,7 @@ import com.android.internal.telephony.CommandsInterface.RadioState; import com.android.internal.telephony.IccCard; import com.android.internal.telephony.IccCardConstants; import com.android.internal.telephony.IccCardConstants.State; import com.android.internal.telephony.IntentBroadcaster; import com.android.internal.telephony.MccTable; import com.android.internal.telephony.Phone; import com.android.internal.telephony.PhoneConstants; Loading Loading @@ -506,7 +507,7 @@ public class IccCardProxy extends Handler implements IccCard { SubscriptionManager.putPhoneIdAndSubIdExtra(intent, mPhoneId); log("broadcastIccStateChangedIntent intent ACTION_SIM_STATE_CHANGED value=" + value + " reason=" + reason + " for mPhoneId=" + mPhoneId); ActivityManager.broadcastStickyIntent(intent, UserHandle.USER_ALL); IntentBroadcaster.getInstance().broadcastStickyIntent(intent, mPhoneId); } } Loading tests/telephonytests/src/com/android/internal/telephony/SubscriptionInfoUpdaterTest.java +1 −1 Original line number Diff line number Diff line Loading @@ -410,7 +410,7 @@ public class SubscriptionInfoUpdaterTest extends TelephonyTest { @Test @SmallTest public void testSimLockWIthIccId() throws Exception { public void testSimLockWithIccId() throws Exception { /* no need for IccId query */ replaceInstance(SubscriptionInfoUpdater.class, "mIccId", null, Loading Loading
src/java/com/android/internal/telephony/IntentBroadcaster.java 0 → 100644 +102 −0 Original line number Diff line number Diff line /* * Copyright (C) 2017 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.internal.telephony; import android.app.ActivityManager; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.os.UserHandle; import android.util.Log; import java.util.HashMap; import java.util.Iterator; import java.util.Map; /** * This class is used to broadcast intents that need to be rebroadcast after the device is unlocked. * NOTE: Currently this is used only for SIM_STATE_CHANGED so logic is hardcoded for that; * for example broadcasts are always sticky, only the last intent for the slotId is rebroadcast, * etc. */ public class IntentBroadcaster { private static final String TAG = "IntentBroadcaster"; private Map<Integer, Intent> mRebroadcastIntents = new HashMap<>(); private static IntentBroadcaster sIntentBroadcaster; private final BroadcastReceiver mReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (action.equals(Intent.ACTION_USER_UNLOCKED)) { synchronized (mRebroadcastIntents) { // rebroadcast intents Iterator iterator = mRebroadcastIntents.entrySet().iterator(); while (iterator.hasNext()) { Map.Entry pair = (Map.Entry) iterator.next(); Intent i = (Intent) pair.getValue(); i.putExtra(TelephonyIntents.EXTRA_REBROADCAST_ON_UNLOCK, true); iterator.remove(); logd("Rebroadcasting intent " + i.getAction() + " " + i.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE) + " for slotId " + pair.getKey()); ActivityManager.broadcastStickyIntent(i, UserHandle.USER_ALL); } } } } }; private IntentBroadcaster(Context context) { context.registerReceiver(mReceiver, new IntentFilter(Intent.ACTION_USER_UNLOCKED)); } /** * Method to get an instance of IntentBroadcaster after creating one if needed. * @return IntentBroadcaster instance */ public static IntentBroadcaster getInstance(Context context) { if (sIntentBroadcaster == null) { sIntentBroadcaster = new IntentBroadcaster(context); } return sIntentBroadcaster; } public static IntentBroadcaster getInstance() { return sIntentBroadcaster; } /** * Wrapper for ActivityManager.broadcastStickyIntent() that also stores intent to be rebroadcast * on USER_UNLOCKED */ public void broadcastStickyIntent(Intent intent, int slotId) { logd("Broadcasting and adding intent for rebroadcast: " + intent.getAction() + " " + intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE) + " for slotId " + slotId); synchronized (mRebroadcastIntents) { ActivityManager.broadcastStickyIntent(intent, UserHandle.USER_ALL); mRebroadcastIntents.put(slotId, intent); } } private void logd(String s) { Log.d(TAG, s); } }
src/java/com/android/internal/telephony/PhoneFactory.java +3 −0 Original line number Diff line number Diff line Loading @@ -74,6 +74,7 @@ public class PhoneFactory { static private ProxyController sProxyController; static private UiccController sUiccController; private static IntentBroadcaster sIntentBroadcaster; static private CommandsInterface sCommandsInterface = null; static private SubscriptionInfoUpdater sSubInfoRecordUpdater = null; Loading Loading @@ -238,6 +239,8 @@ public class PhoneFactory { sProxyController = ProxyController.getInstance(context, sPhones, sUiccController, sCommandsInterfaces, sPhoneSwitcher); sIntentBroadcaster = IntentBroadcaster.getInstance(context); sNotificationChannelController = new NotificationChannelController(context); sTelephonyNetworkFactories = new TelephonyNetworkFactory[numPhones]; Loading
src/java/com/android/internal/telephony/SubscriptionInfoUpdater.java +1 −28 Original line number Diff line number Diff line Loading @@ -32,8 +32,6 @@ import android.os.IRemoteCallback; import android.os.Message; import android.os.RemoteException; import android.os.ServiceManager; import android.os.UserHandle; import android.os.UserManager; import android.preference.PreferenceManager; import android.provider.Settings; import android.telephony.CarrierConfigManager; Loading @@ -51,10 +49,7 @@ import com.android.internal.telephony.uicc.IccUtils; import java.io.FileDescriptor; import java.io.PrintWriter; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; /** *@hide Loading Loading @@ -105,8 +100,6 @@ public class SubscriptionInfoUpdater extends Handler { private static int[] mInsertSimState = new int[PROJECT_SIM_NUM]; private SubscriptionManager mSubscriptionManager = null; private IPackageManager mPackageManager; private UserManager mUserManager; private Map<Integer, Intent> rebroadcastIntentsOnUnlock = new HashMap<>(); // The current foreground user ID. private int mCurrentlyActiveUserId; Loading @@ -119,11 +112,9 @@ public class SubscriptionInfoUpdater extends Handler { mPhone = phone; mSubscriptionManager = SubscriptionManager.from(mContext); mPackageManager = IPackageManager.Stub.asInterface(ServiceManager.getService("package")); mUserManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE); IntentFilter intentFilter = new IntentFilter(TelephonyIntents.ACTION_SIM_STATE_CHANGED); intentFilter.addAction(IccCardProxy.ACTION_INTERNAL_SIM_STATE_CHANGED); intentFilter.addAction(Intent.ACTION_USER_UNLOCKED); mContext.registerReceiver(sReceiver, intentFilter); mCarrierServiceBindHelper = new CarrierServiceBindHelper(mContext); Loading Loading @@ -170,22 +161,6 @@ public class SubscriptionInfoUpdater extends Handler { String action = intent.getAction(); logd("Action: " + action); if (action.equals(Intent.ACTION_USER_UNLOCKED)) { // broadcast pending intents Iterator iterator = rebroadcastIntentsOnUnlock.entrySet().iterator(); while (iterator.hasNext()) { Map.Entry pair = (Map.Entry) iterator.next(); Intent i = (Intent)pair.getValue(); i.putExtra(TelephonyIntents.EXTRA_REBROADCAST_ON_UNLOCK, true); iterator.remove(); logd("Broadcasting intent ACTION_SIM_STATE_CHANGED for mCardIndex: " + pair.getKey()); ActivityManager.broadcastStickyIntent(i, UserHandle.USER_ALL); } logd("[Receiver]-"); return; } if (!action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED) && !action.equals(IccCardProxy.ACTION_INTERNAL_SIM_STATE_CHANGED)) { return; Loading @@ -203,7 +178,6 @@ public class SubscriptionInfoUpdater extends Handler { logd("simStatus: " + simStatus); if (action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) { rebroadcastIntentsOnUnlock.put(slotIndex, intent); if (IccCardConstants.INTENT_VALUE_ICC_ABSENT.equals(simStatus)) { sendMessage(obtainMessage(EVENT_SIM_ABSENT, slotIndex, -1)); } else if (IccCardConstants.INTENT_VALUE_ICC_UNKNOWN.equals(simStatus)) { Loading Loading @@ -685,8 +659,7 @@ public class SubscriptionInfoUpdater extends Handler { SubscriptionManager.putPhoneIdAndSubIdExtra(i, slotId); logd("Broadcasting intent ACTION_SIM_STATE_CHANGED " + state + " reason " + reason + " for mCardIndex: " + slotId); ActivityManager.broadcastStickyIntent(i, UserHandle.USER_ALL); rebroadcastIntentsOnUnlock.put(slotId, i); IntentBroadcaster.getInstance().broadcastStickyIntent(i, slotId); } public void dispose() { Loading
src/java/com/android/internal/telephony/uicc/IccCardProxy.java +2 −1 Original line number Diff line number Diff line Loading @@ -36,6 +36,7 @@ import com.android.internal.telephony.CommandsInterface.RadioState; import com.android.internal.telephony.IccCard; import com.android.internal.telephony.IccCardConstants; import com.android.internal.telephony.IccCardConstants.State; import com.android.internal.telephony.IntentBroadcaster; import com.android.internal.telephony.MccTable; import com.android.internal.telephony.Phone; import com.android.internal.telephony.PhoneConstants; Loading Loading @@ -506,7 +507,7 @@ public class IccCardProxy extends Handler implements IccCard { SubscriptionManager.putPhoneIdAndSubIdExtra(intent, mPhoneId); log("broadcastIccStateChangedIntent intent ACTION_SIM_STATE_CHANGED value=" + value + " reason=" + reason + " for mPhoneId=" + mPhoneId); ActivityManager.broadcastStickyIntent(intent, UserHandle.USER_ALL); IntentBroadcaster.getInstance().broadcastStickyIntent(intent, mPhoneId); } } Loading
tests/telephonytests/src/com/android/internal/telephony/SubscriptionInfoUpdaterTest.java +1 −1 Original line number Diff line number Diff line Loading @@ -410,7 +410,7 @@ public class SubscriptionInfoUpdaterTest extends TelephonyTest { @Test @SmallTest public void testSimLockWIthIccId() throws Exception { public void testSimLockWithIccId() throws Exception { /* no need for IccId query */ replaceInstance(SubscriptionInfoUpdater.class, "mIccId", null, Loading