Store whether the Dialog was previously dismissed
The dialog can be dismissed by either the framework automatically (i.e. when the screen is rotated) or when the subscriptions change. If both of these things happen while the class is not deleted, then dismiss() will be called twice and there will be a crash Bug: 184899699 Test: atest -c SettingsUnitTests Change-Id: Ibaef59696feb566664a424f65f806396f02497e8
This commit is contained in:
@@ -23,6 +23,7 @@ import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.telephony.SubscriptionInfo;
|
||||
import android.telephony.SubscriptionManager;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
@@ -81,7 +82,12 @@ public class PreferredSimDialogFragment extends SimDialogFragment implements
|
||||
}
|
||||
|
||||
private void updateDialog(AlertDialog dialog) {
|
||||
Log.d(TAG, "Dialog updated, dismiss status: " + mWasDismissed);
|
||||
|
||||
final SubscriptionInfo info = getPreferredSubscription();
|
||||
if (mWasDismissed) {
|
||||
return;
|
||||
}
|
||||
if (info == null) {
|
||||
dismiss();
|
||||
return;
|
||||
|
@@ -19,6 +19,7 @@ package com.android.settings.sim;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
@@ -34,6 +35,7 @@ public abstract class SimDialogFragment extends InstrumentedDialogFragment imple
|
||||
private static final String KEY_DIALOG_TYPE = "dialog_type";
|
||||
|
||||
private SubscriptionsChangeListener mChangeListener;
|
||||
protected boolean mWasDismissed = false;
|
||||
|
||||
protected static Bundle initArguments(int dialogType, int titleResId) {
|
||||
final Bundle args = new Bundle();
|
||||
@@ -53,6 +55,8 @@ public abstract class SimDialogFragment extends InstrumentedDialogFragment imple
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
Log.d(TAG, "Dialog Attached.");
|
||||
mWasDismissed = false;
|
||||
mChangeListener = new SubscriptionsChangeListener(context, this);
|
||||
}
|
||||
|
||||
@@ -70,6 +74,8 @@ public abstract class SimDialogFragment extends InstrumentedDialogFragment imple
|
||||
|
||||
@Override
|
||||
public void onDismiss(@NonNull DialogInterface dialog) {
|
||||
Log.d(TAG, "Dialog Dismissed.");
|
||||
mWasDismissed = true;
|
||||
super.onDismiss(dialog);
|
||||
final SimDialogActivity activity = (SimDialogActivity) getActivity();
|
||||
if (activity != null && !activity.isFinishing()) {
|
||||
|
@@ -24,6 +24,7 @@ import android.os.Bundle;
|
||||
import android.telephony.SubscriptionInfo;
|
||||
import android.telephony.SubscriptionManager;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@@ -49,6 +50,7 @@ import java.util.List;
|
||||
*/
|
||||
public class SimListDialogFragment extends SimDialogFragment implements
|
||||
DialogInterface.OnClickListener {
|
||||
private static final String TAG = "SimListDialogFragment";
|
||||
protected static final String KEY_INCLUDE_ASK_EVERY_TIME = "include_ask_every_time";
|
||||
|
||||
protected SelectSubscriptionAdapter mAdapter;
|
||||
@@ -101,9 +103,13 @@ public class SimListDialogFragment extends SimDialogFragment implements
|
||||
|
||||
@Override
|
||||
public void updateDialog() {
|
||||
Log.d(TAG, "Dialog updated, dismiss status: " + mWasDismissed);
|
||||
|
||||
List<SubscriptionInfo> currentSubscriptions = getCurrentSubscriptions();
|
||||
if (currentSubscriptions == null) {
|
||||
dismiss();
|
||||
if (!mWasDismissed) {
|
||||
dismiss();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (getArguments().getBoolean(KEY_INCLUDE_ASK_EVERY_TIME)) {
|
||||
|
Reference in New Issue
Block a user