diff options
| author | 2018-03-22 14:39:43 +0800 | |
|---|---|---|
| committer | 2018-03-26 10:17:23 +0000 | |
| commit | b1b24e71f55de2bfa2cc8d0ff96ec0ac021e663d (patch) | |
| tree | d39c02c817307ac05df0b2c818ad76770b27c9af | |
| parent | 01cee8e6862cabe5dd1d7bfebaa82fc5bb255ee6 (diff) | |
Reset SIM state if the subscription is no longer active.
Bug: 75499020
Fixes: 76400559
Test: manual.
Change-Id: I6774e8db4302c2367c7bf7b5db73d25657ef9bd7
| -rw-r--r-- | packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java | 75 |
1 files changed, 45 insertions, 30 deletions
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java b/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java index d24675c67188..1bab36be8cd8 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java @@ -68,7 +68,6 @@ import android.telephony.SubscriptionManager; import android.telephony.SubscriptionManager.OnSubscriptionsChangedListener; import android.telephony.TelephonyManager; import android.util.Log; -import android.util.Slog; import android.util.SparseBooleanArray; import android.util.SparseIntArray; @@ -88,6 +87,7 @@ import java.io.PrintWriter; import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map.Entry; @@ -400,16 +400,9 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener { // Hack level over 9000: Because the subscription id is not yet valid when we see the // first update in handleSimStateChange, we need to force refresh all all SIM states // so the subscription id for them is consistent. - ArrayList<SubscriptionInfo> changedSubscriptions = new ArrayList<>(); - for (int i = 0; i < subscriptionInfos.size(); i++) { - SubscriptionInfo info = subscriptionInfos.get(i); - boolean changed = refreshSimState(info.getSubscriptionId(), info.getSimSlotIndex()); - if (changed) { - changedSubscriptions.add(info); - } - } - for (int i = 0; i < changedSubscriptions.size(); i++) { - SimData data = mSimDatas.get(changedSubscriptions.get(i).getSubscriptionId()); + List<Integer> changedSubscriptionIds = refreshSimState(subscriptionInfos); + for (int i = 0; i < changedSubscriptionIds.size(); i++) { + SimData data = mSimDatas.get(changedSubscriptionIds.get(i)); for (int j = 0; j < mCallbacks.size(); j++) { KeyguardUpdateMonitorCallback cb = mCallbacks.get(j).get(); if (cb != null) { @@ -1846,34 +1839,56 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener { }; /** - * @return true if and only if the state has changed for the specified {@code slotId} + * @return A list of changed subscriptions, maybe empty but never null */ - private boolean refreshSimState(int subId, int slotId) { + private List<Integer> refreshSimState(final List<SubscriptionInfo> activeSubscriptionInfos) { // This is awful. It exists because there are two APIs for getting the SIM status // that don't return the complete set of values and have different types. In Keyguard we // need IccCardConstants, but TelephonyManager would only give us // TelephonyManager.SIM_STATE*, so we retrieve it manually. final TelephonyManager tele = TelephonyManager.from(mContext); - int simState = tele.getSimState(slotId); - State state; - try { - state = State.intToState(simState); - } catch(IllegalArgumentException ex) { - Log.w(TAG, "Unknown sim state: " + simState); - state = State.UNKNOWN; + ArrayList<Integer> changedSubscriptionIds = new ArrayList<>(); + HashSet<Integer> activeSubIds = new HashSet<>(); + + for (SubscriptionInfo info : activeSubscriptionInfos) { + int subId = info.getSubscriptionId(); + int slotId = info.getSimSlotIndex(); + int simState = tele.getSimState(slotId); + State state; + try { + state = State.intToState(simState); + } catch(IllegalArgumentException ex) { + Log.w(TAG, "Unknown sim state: " + simState); + state = State.UNKNOWN; + } + + SimData data = mSimDatas.get(subId); + final boolean changed; + if (data == null) { + data = new SimData(state, slotId, subId); + mSimDatas.put(subId, data); + changed = true; // no data yet; force update + } else { + changed = data.simState != state; + data.simState = state; + } + if (changed) { + changedSubscriptionIds.add(subId); + } + + activeSubIds.add(subId); } - SimData data = mSimDatas.get(subId); - final boolean changed; - if (data == null) { - data = new SimData(state, slotId, subId); - mSimDatas.put(subId, data); - changed = true; // no data yet; force update - } else { - changed = data.simState != state; - data.simState = state; + + for (SimData data : mSimDatas.values()) { + if (!activeSubIds.contains(data.subId) && data.simState != State.ABSENT) { + // for the inactive subscriptions, reset state to ABSENT + data.simState = State.ABSENT; + changedSubscriptionIds.add(data.subId); + } } - return changed; + + return changedSubscriptionIds; } public static boolean isSimPinSecure(IccCardConstants.State state) { |