packages/apps/Settings
修訂 | abd767ab1d7038a121b542027f0f34b519e38992 (tree) |
---|---|
時間 | 2020-12-16 07:11:55 |
作者 | Malcolm Chen <refuhoo@goog...> |
Commiter | Xiangyu/Malcolm Chen |
Automatically dismiss SIM combination warnings and selection dialogs.
When configuring CBRS profiles this dialog / notification will be
dismissed after configuration is done, to avoid confusion.
Bug: 142092510
Test: manual and unittest
Change-Id: Iaf30062f555ec2c119c4aafd6aa013e73b5253f0
Merged-In: Iaf30062f555ec2c119c4aafd6aa013e73b5253f0
@@ -19,7 +19,6 @@ package com.android.settings.sim; | ||
19 | 19 | import android.app.Activity; |
20 | 20 | import android.content.Intent; |
21 | 21 | import android.os.Bundle; |
22 | -import android.telecom.PhoneAccount; | |
23 | 22 | import android.telecom.PhoneAccountHandle; |
24 | 23 | import android.telecom.TelecomManager; |
25 | 24 | import android.telephony.SubscriptionManager; |
@@ -54,6 +53,8 @@ public class SimDialogActivity extends FragmentActivity { | ||
54 | 53 | public static final int PREFERRED_PICK = 3; |
55 | 54 | // Show the "select SMS subscription" dialog, but don't save as default, just return a result |
56 | 55 | public static final int SMS_PICK_FOR_MESSAGE = 4; |
56 | + // Dismiss the current dialog and finish the activity. | |
57 | + public static final int PICK_DISMISS = 5; | |
57 | 58 | |
58 | 59 | @Override |
59 | 60 | protected void onCreate(Bundle savedInstanceState) { |
@@ -70,6 +71,12 @@ public class SimDialogActivity extends FragmentActivity { | ||
70 | 71 | |
71 | 72 | private void showOrUpdateDialog() { |
72 | 73 | final int dialogType = getIntent().getIntExtra(DIALOG_TYPE_KEY, INVALID_PICK); |
74 | + | |
75 | + if (dialogType == PICK_DISMISS) { | |
76 | + finishAndRemoveTask(); | |
77 | + return; | |
78 | + } | |
79 | + | |
73 | 80 | final String tag = Integer.toString(dialogType); |
74 | 81 | final FragmentManager fragmentManager = getSupportFragmentManager(); |
75 | 82 | SimDialogFragment fragment = (SimDialogFragment) fragmentManager.findFragmentByTag(tag); |
@@ -20,10 +20,10 @@ import static android.provider.Settings.ENABLE_MMS_DATA_REQUEST_REASON_INCOMING_ | ||
20 | 20 | import static android.provider.Settings.ENABLE_MMS_DATA_REQUEST_REASON_OUTGOING_MMS; |
21 | 21 | import static android.provider.Settings.EXTRA_ENABLE_MMS_DATA_REQUEST_REASON; |
22 | 22 | import static android.provider.Settings.EXTRA_SUB_ID; |
23 | -import static com.android.settings.Utils.SETTINGS_PACKAGE_NAME; | |
24 | 23 | import static android.telephony.TelephonyManager.EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE; |
25 | 24 | import static android.telephony.TelephonyManager.EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE_ALL; |
26 | 25 | import static android.telephony.TelephonyManager.EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE_DATA; |
26 | +import static android.telephony.TelephonyManager.EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE_DISMISS; | |
27 | 27 | import static android.telephony.TelephonyManager.EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE_NONE; |
28 | 28 | import static android.telephony.TelephonyManager.EXTRA_SIM_COMBINATION_NAMES; |
29 | 29 | import static android.telephony.TelephonyManager.EXTRA_SIM_COMBINATION_WARNING_TYPE; |
@@ -32,6 +32,9 @@ import static android.telephony.TelephonyManager.EXTRA_SIM_COMBINATION_WARNING_T | ||
32 | 32 | import static android.telephony.TelephonyManager.EXTRA_SUBSCRIPTION_ID; |
33 | 33 | import static android.telephony.data.ApnSetting.TYPE_MMS; |
34 | 34 | |
35 | +import static com.android.settings.Utils.SETTINGS_PACKAGE_NAME; | |
36 | +import static com.android.settings.sim.SimDialogActivity.PICK_DISMISS; | |
37 | + | |
35 | 38 | import android.app.Notification; |
36 | 39 | import android.app.NotificationChannel; |
37 | 40 | import android.app.NotificationManager; |
@@ -51,7 +54,6 @@ import com.android.settings.HelpTrampoline; | ||
51 | 54 | import com.android.settings.R; |
52 | 55 | import com.android.settings.network.SubscriptionUtil; |
53 | 56 | import com.android.settings.network.telephony.MobileNetworkActivity; |
54 | -import com.android.settingslib.HelpUtils; | |
55 | 57 | |
56 | 58 | public class SimSelectNotification extends BroadcastReceiver { |
57 | 59 | private static final String TAG = "SimSelectNotification"; |
@@ -159,6 +161,16 @@ public class SimSelectNotification extends BroadcastReceiver { | ||
159 | 161 | |
160 | 162 | // Cancel any previous notifications |
161 | 163 | cancelSimSelectNotification(context); |
164 | + | |
165 | + // If the dialog type is to dismiss. | |
166 | + if (dialogType == EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE_DISMISS) { | |
167 | + Intent newIntent = new Intent(context, SimDialogActivity.class); | |
168 | + newIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | |
169 | + newIntent.putExtra(SimDialogActivity.DIALOG_TYPE_KEY, PICK_DISMISS); | |
170 | + context.startActivity(newIntent); | |
171 | + return; | |
172 | + } | |
173 | + | |
162 | 174 | // Create a notification to tell the user that some defaults are missing |
163 | 175 | createSimSelectNotification(context); |
164 | 176 |
@@ -186,10 +198,11 @@ public class SimSelectNotification extends BroadcastReceiver { | ||
186 | 198 | final int warningType = intent.getIntExtra(EXTRA_SIM_COMBINATION_WARNING_TYPE, |
187 | 199 | EXTRA_SIM_COMBINATION_WARNING_TYPE_NONE); |
188 | 200 | |
201 | + // Cancel any previous notifications | |
202 | + cancelSimCombinationWarningNotification(context); | |
203 | + | |
189 | 204 | if (warningType == EXTRA_SIM_COMBINATION_WARNING_TYPE_DUAL_CDMA) { |
190 | - // Cancel any previous notifications | |
191 | - cancelSimCombinationWarningNotification(context); | |
192 | - // Create a notification to tell the user that some defaults are missing | |
205 | + // Create a notification to tell the user that there's a sim combination warning. | |
193 | 206 | createSimCombinationWarningNotification(context, intent); |
194 | 207 | } |
195 | 208 | } |
@@ -21,11 +21,17 @@ import static android.provider.Settings.ENABLE_MMS_DATA_REQUEST_REASON_INCOMING_ | ||
21 | 21 | import static android.provider.Settings.ENABLE_MMS_DATA_REQUEST_REASON_OUTGOING_MMS; |
22 | 22 | import static android.provider.Settings.EXTRA_ENABLE_MMS_DATA_REQUEST_REASON; |
23 | 23 | import static android.provider.Settings.EXTRA_SUB_ID; |
24 | +import static android.telephony.TelephonyManager.EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE; | |
25 | +import static android.telephony.TelephonyManager.EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE_DATA; | |
26 | +import static android.telephony.TelephonyManager.EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE_DISMISS; | |
24 | 27 | import static android.telephony.TelephonyManager.EXTRA_SIM_COMBINATION_NAMES; |
25 | 28 | import static android.telephony.TelephonyManager.EXTRA_SIM_COMBINATION_WARNING_TYPE; |
26 | 29 | import static android.telephony.TelephonyManager.EXTRA_SIM_COMBINATION_WARNING_TYPE_DUAL_CDMA; |
27 | 30 | import static android.telephony.data.ApnSetting.TYPE_MMS; |
28 | 31 | |
32 | +import static com.android.settings.sim.SimDialogActivity.DATA_PICK; | |
33 | +import static com.android.settings.sim.SimDialogActivity.INVALID_PICK; | |
34 | +import static com.android.settings.sim.SimDialogActivity.PICK_DISMISS; | |
29 | 35 | import static com.android.settings.sim.SimSelectNotification.ENABLE_MMS_NOTIFICATION_CHANNEL; |
30 | 36 | import static com.android.settings.sim.SimSelectNotification.ENABLE_MMS_NOTIFICATION_ID; |
31 | 37 | import static com.android.settings.sim.SimSelectNotification.SIM_WARNING_NOTIFICATION_CHANNEL; |
@@ -36,6 +42,7 @@ import static com.google.common.truth.Truth.assertThat; | ||
36 | 42 | import static org.mockito.ArgumentMatchers.any; |
37 | 43 | import static org.mockito.ArgumentMatchers.anyInt; |
38 | 44 | import static org.mockito.ArgumentMatchers.eq; |
45 | +import static org.mockito.Mockito.clearInvocations; | |
39 | 46 | import static org.mockito.Mockito.never; |
40 | 47 | import static org.mockito.Mockito.verify; |
41 | 48 | import static org.mockito.Mockito.when; |
@@ -54,7 +61,6 @@ import android.telephony.SubscriptionManager; | ||
54 | 61 | import android.telephony.TelephonyManager; |
55 | 62 | |
56 | 63 | import com.android.settings.R; |
57 | - | |
58 | 64 | import com.android.settings.testutils.shadow.ShadowAlertDialogCompat; |
59 | 65 | |
60 | 66 | import org.junit.Before; |
@@ -197,6 +203,50 @@ public class SimSelectNotificationTest { | ||
197 | 203 | } |
198 | 204 | |
199 | 205 | @Test |
206 | + public void onReceivePrimarySubListChange_WithDataPickExtra_shouldStartActivity() { | |
207 | + Intent intent = new Intent(TelephonyManager.ACTION_PRIMARY_SUBSCRIPTION_LIST_CHANGED); | |
208 | + intent.putExtra(EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE, | |
209 | + EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE_DATA); | |
210 | + | |
211 | + mSimSelectNotification.onReceive(mContext, intent); | |
212 | + | |
213 | + ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class); | |
214 | + verify(mContext).startActivity(intentCaptor.capture()); | |
215 | + Intent capturedIntent = intentCaptor.getValue(); | |
216 | + assertThat(capturedIntent).isNotNull(); | |
217 | + assertThat(capturedIntent.getComponent().getClassName()).isEqualTo( | |
218 | + SimDialogActivity.class.getName()); | |
219 | + assertThat(capturedIntent.getFlags() & Intent.FLAG_ACTIVITY_NEW_TASK) | |
220 | + .isNotEqualTo(0); | |
221 | + assertThat(capturedIntent.getIntExtra(SimDialogActivity.DIALOG_TYPE_KEY, INVALID_PICK)) | |
222 | + .isEqualTo(DATA_PICK); | |
223 | + } | |
224 | + | |
225 | + @Test | |
226 | + public void onReceivePrimarySubListChange_WithDismissExtra_shouldDismiss() { | |
227 | + Intent intent = new Intent(TelephonyManager.ACTION_PRIMARY_SUBSCRIPTION_LIST_CHANGED); | |
228 | + intent.putExtra(EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE, | |
229 | + EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE_DATA); | |
230 | + | |
231 | + mSimSelectNotification.onReceive(mContext, intent); | |
232 | + clearInvocations(mContext); | |
233 | + | |
234 | + // Dismiss. | |
235 | + intent.putExtra(EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE, | |
236 | + EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE_DISMISS); | |
237 | + mSimSelectNotification.onReceive(mContext, intent); | |
238 | + ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class); | |
239 | + verify(mContext).startActivity(intentCaptor.capture()); | |
240 | + Intent capturedIntent = intentCaptor.getValue(); | |
241 | + assertThat(capturedIntent).isNotNull(); | |
242 | + assertThat(capturedIntent.getComponent().getClassName()).isEqualTo( | |
243 | + SimDialogActivity.class.getName()); | |
244 | + assertThat(capturedIntent.getFlags() & Intent.FLAG_ACTIVITY_NEW_TASK) | |
245 | + .isNotEqualTo(0); | |
246 | + assertThat(capturedIntent.getIntExtra(SimDialogActivity.DIALOG_TYPE_KEY, INVALID_PICK)) | |
247 | + .isEqualTo(PICK_DISMISS); | |
248 | + } | |
249 | + @Test | |
200 | 250 | public void onReceivePrimarySubListChange_DualCdmaWarning_notificationShouldSend() { |
201 | 251 | Intent intent = new Intent(TelephonyManager.ACTION_PRIMARY_SUBSCRIPTION_LIST_CHANGED); |
202 | 252 |