packages/apps/Settings
リビジョン | 5f1747a00dd655bcc1f461e5d1edf6c38a88a3ad (tree) |
---|---|
日時 | 2015-03-26 10:49:50 |
作者 | Stuart Scott <stuartscott@goog...> |
コミッター | The Android Automerger |
Fix sim notifications.
bug:19705366
Change-Id: I1d1f2dc5cf1d4580ab503c88853b089db0362242
@@ -24,8 +24,6 @@ import android.app.PendingIntent; | ||
24 | 24 | import android.content.BroadcastReceiver; |
25 | 25 | import android.content.Context; |
26 | 26 | import android.content.Intent; |
27 | -import android.content.SharedPreferences; | |
28 | -import android.content.SharedPreferences.Editor; | |
29 | 27 | import android.content.res.Resources; |
30 | 28 | import android.provider.Settings; |
31 | 29 | import android.support.v4.app.NotificationCompat; |
@@ -40,13 +38,8 @@ import java.util.List; | ||
40 | 38 | |
41 | 39 | public class SimBootReceiver extends BroadcastReceiver { |
42 | 40 | private static final String TAG = "SimBootReceiver"; |
43 | - private static final int SLOT_EMPTY = -1; | |
44 | 41 | private static final int NOTIFICATION_ID = 1; |
45 | - private static final String SHARED_PREFERENCES_NAME = "sim_state"; | |
46 | - private static final String SLOT_PREFIX = "sim_slot_"; | |
47 | - private static final int INVALID_SLOT = -2; // Used when upgrading from K to LMR1 | |
48 | 42 | |
49 | - private SharedPreferences mSharedPreferences = null; | |
50 | 43 | private TelephonyManager mTelephonyManager; |
51 | 44 | private Context mContext; |
52 | 45 | private SubscriptionManager mSubscriptionManager; |
@@ -56,9 +49,6 @@ public class SimBootReceiver extends BroadcastReceiver { | ||
56 | 49 | mTelephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); |
57 | 50 | mContext = context; |
58 | 51 | mSubscriptionManager = SubscriptionManager.from(mContext); |
59 | - mSharedPreferences = mContext.getSharedPreferences(SHARED_PREFERENCES_NAME, | |
60 | - Context.MODE_PRIVATE); | |
61 | - | |
62 | 52 | mSubscriptionManager.addOnSubscriptionsChangedListener(mSubscriptionListener); |
63 | 53 | } |
64 | 54 |
@@ -75,6 +65,22 @@ public class SimBootReceiver extends BroadcastReceiver { | ||
75 | 65 | return; |
76 | 66 | } |
77 | 67 | |
68 | + // Cancel any previous notifications | |
69 | + cancelNotification(mContext); | |
70 | + | |
71 | + // Clear defaults for any subscriptions which no longer exist | |
72 | + mSubscriptionManager.clearDefaultsForInactiveSubIds(); | |
73 | + | |
74 | + boolean dataSelected = SubscriptionManager.isUsableSubIdValue( | |
75 | + SubscriptionManager.getDefaultDataSubId()); | |
76 | + boolean smsSelected = SubscriptionManager.isUsableSubIdValue( | |
77 | + SubscriptionManager.getDefaultSmsSubId()); | |
78 | + | |
79 | + // If data and sms defaults are selected, dont show notification (Calls default is optional) | |
80 | + if (dataSelected && smsSelected) { | |
81 | + return; | |
82 | + } | |
83 | + | |
78 | 84 | // We wait until SubscriptionManager returns a valid list of Subscription informations |
79 | 85 | // by checking if the list is empty. |
80 | 86 | // This is not completely correct, but works for most cases. |
@@ -82,57 +88,34 @@ public class SimBootReceiver extends BroadcastReceiver { | ||
82 | 88 | List<SubscriptionInfo> sil = mSubscriptionManager.getActiveSubscriptionInfoList(); |
83 | 89 | if (sil == null || sil.size() < 1) { |
84 | 90 | return; |
85 | - } | |
86 | - | |
87 | - for (int i = 0; i < numSlots; i++) { | |
88 | - final SubscriptionInfo sir = Utils.findRecordBySlotId(mContext, i); | |
89 | - final String key = SLOT_PREFIX+i; | |
90 | - final int lastSubId = getLastSubId(key); | |
91 | - | |
92 | - if (sir != null) { | |
93 | - numSIMsDetected++; | |
94 | - final int currentSubId = sir.getSubscriptionId(); | |
95 | - if (lastSubId == INVALID_SLOT) { | |
96 | - setLastSubId(key, currentSubId); | |
97 | - } else if (lastSubId != currentSubId) { | |
98 | - createNotification(mContext); | |
99 | - setLastSubId(key, currentSubId); | |
100 | - notificationSent = true; | |
101 | - } | |
102 | - lastSIMSlotDetected = i; | |
103 | - } else if (lastSubId != SLOT_EMPTY) { | |
104 | - createNotification(mContext); | |
105 | - setLastSubId(key, SLOT_EMPTY); | |
106 | - notificationSent = true; | |
107 | - } | |
108 | - } | |
109 | - | |
110 | - if (notificationSent) { | |
111 | - Intent intent = new Intent(mContext, SimDialogActivity.class); | |
112 | - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | |
113 | - if (numSIMsDetected == 1) { | |
91 | + } else { | |
92 | + // Create a notification to tell the user that some defaults are missing | |
93 | + createNotification(mContext); | |
94 | + | |
95 | + if (sil.size() == 1) { | |
96 | + // If there is only one subscription, ask if user wants to use if for everything | |
97 | + Intent intent = new Intent(mContext, SimDialogActivity.class); | |
98 | + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | |
114 | 99 | intent.putExtra(SimDialogActivity.DIALOG_TYPE_KEY, SimDialogActivity.PREFERRED_PICK); |
115 | - intent.putExtra(SimDialogActivity.PREFERRED_SIM, lastSIMSlotDetected); | |
116 | - } else { | |
100 | + intent.putExtra(SimDialogActivity.PREFERRED_SIM, sil.get(0).getSimSlotIndex()); | |
101 | + mContext.startActivity(intent); | |
102 | + } else if (!dataSelected) { | |
103 | + // TODO(sanketpadawe): This should not be shown if the user is looking at the | |
104 | + // SimSettings page - its just annoying | |
105 | + // If there are mulitple, ensure they pick default data | |
106 | + Intent intent = new Intent(mContext, SimDialogActivity.class); | |
107 | + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | |
117 | 108 | intent.putExtra(SimDialogActivity.DIALOG_TYPE_KEY, SimDialogActivity.DATA_PICK); |
109 | + mContext.startActivity(intent); | |
118 | 110 | } |
119 | - mContext.startActivity(intent); | |
120 | 111 | } |
121 | - } | |
122 | - | |
123 | - private int getLastSubId(String strSlotId) { | |
124 | - return mSharedPreferences.getInt(strSlotId, INVALID_SLOT); | |
125 | - } | |
126 | 112 | |
127 | - private void setLastSubId(String strSlotId, int value) { | |
128 | - Editor editor = mSharedPreferences.edit(); | |
129 | - editor.putInt(strSlotId, value); | |
130 | - editor.commit(); | |
131 | 113 | } |
132 | 114 | |
133 | 115 | private void createNotification(Context context){ |
134 | 116 | final Resources resources = context.getResources(); |
135 | 117 | |
118 | + // TODO(sanketpadawe): This notification should not be dissmissable by the user | |
136 | 119 | NotificationCompat.Builder builder = |
137 | 120 | new NotificationCompat.Builder(context) |
138 | 121 | .setSmallIcon(R.drawable.ic_sim_card_alert_white_48dp) |