Fix problem of multiple stacked copies of "Select SIM" dialog
The SimDialogActivity is used to ask the user questions about which SIM card to use for various services like calls, SMS, and data. In some cases of SIM changes (eg when a SIM is added or removed), the telephony stack sends a broadcast that SimSelectNotification listens for so it can pop up a general "SIM cards changed" notification, and we additionally want to bring up an interruptive dialog to ask the user a specific question. This might happen for instance when we want to ask the user's permission to turn on data on a SIM. Recent DSDS changes in the telephony stack have meant that we accidentally create several stacked copies of this dialog, because they send several broadcast updates as information about SIMs asynchronously changes. For instance, we might initially detect a SIM with a generic name of "CARD 1", and shortly after discover the actual carrier name. So what we really want is to put up the dialog, and update it as information changes. This CL makes SimDialogActivity use launchMode="singleTop" so that additional copies of the activity won't be launched. Then it internally enforces only showing one dialog per type of request (calls, SMS, data, or preferred sim). If we get a request for a dialog that already exists, we just update it instead of creating a new one for that type. So there can still be a stack of more than one dialog, but each one will be asking a different question. This also refactors the monolithic, somewhat confusing code for showing the various types of dialogs into a more clearly separated class hierarchy, and switches to using DialogFragment for the dialog. Fixes: 126596081 Test: manual (start with device in DSDS mode with 2 subs, remove SIM card and re-insert it) Change-Id: I0dbc41dc3b15015389823a24df10bbff08ec6615
This commit is contained in:
101
src/com/android/settings/sim/PreferredSimDialogFragment.java
Normal file
101
src/com/android/settings/sim/PreferredSimDialogFragment.java
Normal file
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* Copyright (C) 2019 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.settings.sim;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.telephony.SubscriptionInfo;
|
||||
import android.telephony.SubscriptionManager;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
/**
|
||||
* Presents a dialog asking the user if they want to update all services to use a given "preferred"
|
||||
* SIM. Typically this would be used in a case where a device goes from having multiple SIMs down to
|
||||
* only one.
|
||||
*/
|
||||
public class PreferredSimDialogFragment extends SimDialogFragment implements
|
||||
DialogInterface.OnClickListener {
|
||||
private static final String TAG = "PreferredSimDialogFrag";
|
||||
|
||||
public static PreferredSimDialogFragment newInstance() {
|
||||
final PreferredSimDialogFragment fragment = new PreferredSimDialogFragment();
|
||||
final Bundle args = initArguments(SimDialogActivity.PREFERRED_PICK,
|
||||
R.string.sim_preferred_title);
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
|
||||
final AlertDialog dialog = new AlertDialog.Builder(getContext())
|
||||
.setTitle(getTitleResId())
|
||||
.setPositiveButton(R.string.yes, this)
|
||||
.setNegativeButton(R.string.no, null)
|
||||
.create();
|
||||
updateDialog(dialog);
|
||||
return dialog;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int buttonClicked) {
|
||||
if (buttonClicked != DialogInterface.BUTTON_POSITIVE) {
|
||||
return;
|
||||
}
|
||||
final SimDialogActivity activity = (SimDialogActivity) getActivity();
|
||||
final SubscriptionInfo info = getPreferredSubscription();
|
||||
if (info != null) {
|
||||
activity.onSubscriptionSelected(getDialogType(), info.getSubscriptionId());
|
||||
}
|
||||
}
|
||||
|
||||
public SubscriptionInfo getPreferredSubscription() {
|
||||
final Activity activity = getActivity();
|
||||
final int slotId = activity.getIntent().getIntExtra(SimDialogActivity.PREFERRED_SIM,
|
||||
SubscriptionManager.INVALID_SUBSCRIPTION_ID);
|
||||
return getSubscriptionManager().getActiveSubscriptionInfoForSimSlotIndex(slotId);
|
||||
}
|
||||
|
||||
private void updateDialog(AlertDialog dialog) {
|
||||
final SubscriptionInfo info = getPreferredSubscription();
|
||||
if (info == null) {
|
||||
dismiss();
|
||||
return;
|
||||
}
|
||||
final String message =
|
||||
getContext().getString(R.string.sim_preferred_message, info.getDisplayName());
|
||||
dialog.setMessage(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDialog() {
|
||||
updateDialog((AlertDialog) getDialog());
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
protected SubscriptionManager getSubscriptionManager() {
|
||||
return getContext().getSystemService(SubscriptionManager.class);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user