switch SIM refactor to support MEP

To create new dialog for MEP. It is a simple UI for testing,
not the final version.

Bug: 199902896
Test: local build pass.
Change-Id: Ief4299e775c0758e4b886d5eff13bd482f8c8ab3
Merged-In: Ief4299e775c0758e4b886d5eff13bd482f8c8ab3
This commit is contained in:
SongFerngWang
2021-12-08 22:51:43 +08:00
committed by SongFerng Wang
parent 37358798bc
commit 59a6ecbde2
8 changed files with 181 additions and 23 deletions

View File

@@ -690,12 +690,12 @@
<activity android:name=".network.telephony.ToggleSubscriptionDialogActivity" <activity android:name=".network.telephony.ToggleSubscriptionDialogActivity"
android:exported="false" android:exported="false"
android:permission="android.permission.WRITE_EMBEDDED_SUBSCRIPTIONS" android:permission="android.permission.WRITE_EMBEDDED_SUBSCRIPTIONS"
android:theme="@*android:style/Theme.DeviceDefault.Dialog.Alert.DayNight" /> android:theme="@style/Theme.AlertDialog"/>
<activity android:name=".network.telephony.DeleteEuiccSubscriptionDialogActivity" <activity android:name=".network.telephony.DeleteEuiccSubscriptionDialogActivity"
android:exported="false" android:exported="false"
android:permission="android.permission.WRITE_EMBEDDED_SUBSCRIPTIONS" android:permission="android.permission.WRITE_EMBEDDED_SUBSCRIPTIONS"
android:theme="@*android:style/Theme.DeviceDefault.Dialog.Alert.DayNight" /> android:theme="@style/Theme.AlertDialog"/>
<activity <activity
android:name="Settings$TetherSettingsActivity" android:name="Settings$TetherSettingsActivity"
@@ -4202,14 +4202,14 @@
android:exported="false" android:exported="false"
android:permission="android.permission.WRITE_EMBEDDED_SUBSCRIPTIONS" android:permission="android.permission.WRITE_EMBEDDED_SUBSCRIPTIONS"
android:launchMode="singleInstance" android:launchMode="singleInstance"
android:theme="@*android:style/Theme.DeviceDefault.Dialog.Alert.DayNight" /> android:theme="@style/Theme.AlertDialog"/>
<activity <activity
android:name=".sim.DsdsDialogActivity" android:name=".sim.DsdsDialogActivity"
android:exported="false" android:exported="false"
android:permission="android.permission.WRITE_EMBEDDED_SUBSCRIPTIONS" android:permission="android.permission.WRITE_EMBEDDED_SUBSCRIPTIONS"
android:launchMode="singleInstance" android:launchMode="singleInstance"
android:theme="@*android:style/Theme.DeviceDefault.Dialog.Alert.DayNight" /> android:theme="@style/Theme.AlertDialog"/>
<service android:name=".sim.SimNotificationService" <service android:name=".sim.SimNotificationService"
android:permission="android.permission.BIND_JOB_SERVICE" /> android:permission="android.permission.BIND_JOB_SERVICE" />

View File

@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2021 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.
-->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
style="@style/Theme.Material3.DayNight.Dialog.Alert">
<TextView
android:id="@+id/msg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<ListView
android:id="@+id/carrier_list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="56dp"
android:gravity="start|top"
android:orientation="horizontal"
android:paddingEnd="12dp"
android:paddingTop="16dp"
android:paddingBottom="4dp"
android:baselineAligned="true">
<ImageView
android:src="@drawable/ic_info_outline_24dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:tint="?android:attr/textColorTertiary"/>
<TextView
android:id="@+id/info_outline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="16dp"
android:paddingBottom="8dp"
android:text="@string/sim_action_switch_sub_dialog_info_outline_for_turning_off"
android:textColor="?android:attr/textColorSecondary" />
</LinearLayout>
</LinearLayout>

View File

@@ -16,13 +16,14 @@
package com.android.settings.network.telephony; package com.android.settings.network.telephony;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog; import android.app.Dialog;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.os.Bundle; import android.os.Bundle;
import android.text.TextUtils; import android.text.TextUtils;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.FragmentActivity;
/** Fragment to show an alert dialog which only has the positive button. */ /** Fragment to show an alert dialog which only has the positive button. */
public class AlertDialogFragment extends BaseDialogFragment public class AlertDialogFragment extends BaseDialogFragment
implements DialogInterface.OnClickListener { implements DialogInterface.OnClickListener {
@@ -37,13 +38,13 @@ public class AlertDialogFragment extends BaseDialogFragment
* @param title * @param title
* @param msg * @param msg
*/ */
public static void show(Activity activity, String title, String msg) { public static void show(FragmentActivity activity, String title, String msg) {
AlertDialogFragment fragment = new AlertDialogFragment(); AlertDialogFragment fragment = new AlertDialogFragment();
Bundle arguments = new Bundle(); Bundle arguments = new Bundle();
arguments.putString(ARG_TITLE, title); arguments.putString(ARG_TITLE, title);
arguments.putString(ARG_MSG, msg); arguments.putString(ARG_MSG, msg);
fragment.setArguments(arguments); fragment.setArguments(arguments);
fragment.show(activity.getFragmentManager(), TAG); fragment.show(activity.getSupportFragmentManager(), TAG);
} }
@Override @Override
@@ -55,7 +56,7 @@ public class AlertDialogFragment extends BaseDialogFragment
if (!TextUtils.isEmpty(getArguments().getString(ARG_MSG))) { if (!TextUtils.isEmpty(getArguments().getString(ARG_MSG))) {
builder.setMessage(getArguments().getString(ARG_MSG)); builder.setMessage(getArguments().getString(ARG_MSG));
} }
return builder.show(); return builder.create();
} }
@Override @Override

View File

@@ -17,11 +17,11 @@
package com.android.settings.network.telephony; package com.android.settings.network.telephony;
import android.app.Activity; import android.app.Activity;
import android.app.DialogFragment;
import android.app.Fragment;
import android.os.Bundle; import android.os.Bundle;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.Fragment;
/** /**
* Base dialog fragment class with the functionality to make a fragment or an activity as a listener * Base dialog fragment class with the functionality to make a fragment or an activity as a listener

View File

@@ -16,13 +16,24 @@
package com.android.settings.network.telephony; package com.android.settings.network.telephony;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog; import android.app.Dialog;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.os.Bundle; import android.os.Bundle;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.FragmentActivity;
import com.android.settings.R;
import java.util.ArrayList;
/** Fragment to show a confirm dialog. The caller should implement onConfirmListener. */ /** Fragment to show a confirm dialog. The caller should implement onConfirmListener. */
public class ConfirmDialogFragment extends BaseDialogFragment public class ConfirmDialogFragment extends BaseDialogFragment
@@ -32,6 +43,7 @@ public class ConfirmDialogFragment extends BaseDialogFragment
private static final String ARG_MSG = "msg"; private static final String ARG_MSG = "msg";
private static final String ARG_POS_BUTTON_STRING = "pos_button_string"; private static final String ARG_POS_BUTTON_STRING = "pos_button_string";
private static final String ARG_NEG_BUTTON_STRING = "neg_button_string"; private static final String ARG_NEG_BUTTON_STRING = "neg_button_string";
private static final String ARG_LIST = "list";
/** /**
* Interface defining the method that will be invoked when the user has done with the dialog. * Interface defining the method that will be invoked when the user has done with the dialog.
@@ -51,7 +63,7 @@ public class ConfirmDialogFragment extends BaseDialogFragment
/** Displays a confirmation dialog which has confirm and cancel buttons. */ /** Displays a confirmation dialog which has confirm and cancel buttons. */
public static <T> void show( public static <T> void show(
Activity activity, FragmentActivity activity,
Class<T> callbackInterfaceClass, Class<T> callbackInterfaceClass,
int tagInCaller, int tagInCaller,
String title, String title,
@@ -66,7 +78,29 @@ public class ConfirmDialogFragment extends BaseDialogFragment
arguments.putString(ARG_NEG_BUTTON_STRING, negButtonString); arguments.putString(ARG_NEG_BUTTON_STRING, negButtonString);
setListener(activity, null, callbackInterfaceClass, tagInCaller, arguments); setListener(activity, null, callbackInterfaceClass, tagInCaller, arguments);
fragment.setArguments(arguments); fragment.setArguments(arguments);
fragment.show(activity.getFragmentManager(), TAG); fragment.show(activity.getSupportFragmentManager(), TAG);
}
/** Displays a confirmation dialog which has confirm and cancel buttons and carrier list.*/
public static <T> void show(
FragmentActivity activity,
Class<T> callbackInterfaceClass,
int tagInCaller,
String title,
String msg,
String posButtonString,
String negButtonString,
ArrayList<String> list) {
ConfirmDialogFragment fragment = new ConfirmDialogFragment();
Bundle arguments = new Bundle();
arguments.putString(ARG_TITLE, title);
arguments.putCharSequence(ARG_MSG, msg);
arguments.putString(ARG_POS_BUTTON_STRING, posButtonString);
arguments.putString(ARG_NEG_BUTTON_STRING, negButtonString);
arguments.putStringArrayList(ARG_LIST, list);
setListener(activity, null, callbackInterfaceClass, tagInCaller, arguments);
fragment.setArguments(arguments);
fragment.show(activity.getSupportFragmentManager(), TAG);
} }
@Override @Override
@@ -75,18 +109,56 @@ public class ConfirmDialogFragment extends BaseDialogFragment
String message = getArguments().getString(ARG_MSG); String message = getArguments().getString(ARG_MSG);
String posBtnString = getArguments().getString(ARG_POS_BUTTON_STRING); String posBtnString = getArguments().getString(ARG_POS_BUTTON_STRING);
String negBtnString = getArguments().getString(ARG_NEG_BUTTON_STRING); String negBtnString = getArguments().getString(ARG_NEG_BUTTON_STRING);
ArrayList<String> list = getArguments().getStringArrayList(ARG_LIST);
Log.i("Showing dialog with title = %s", title); Log.i(TAG, "Showing dialog with title =" + title);
AlertDialog.Builder builder = AlertDialog.Builder builder =
new AlertDialog.Builder(getContext()) new AlertDialog.Builder(getContext())
.setTitle(title) .setTitle(title)
.setPositiveButton(posBtnString, this) .setPositiveButton(posBtnString, this)
.setNegativeButton(negBtnString, this); .setNegativeButton(negBtnString, this);
if (list != null && !list.isEmpty()) {
Log.i(TAG, "list =" + list.toString());
View content = LayoutInflater.from(getContext()).inflate(
R.layout.sim_confirm_dialog_multiple_enabled_profiles_supported, null);
TextView dialogMessage = content.findViewById(R.id.msg);
if (!TextUtils.isEmpty(message) && dialogMessage != null) {
dialogMessage.setText(message);
}
final ArrayAdapter<String> arrayAdapterItems = new ArrayAdapter<String>(
getContext(), android.R.layout.select_dialog_item, list);
final ListView lvItems = content.findViewById(R.id.carrier_list);
if (lvItems != null) {
lvItems.setAdapter(arrayAdapterItems);
lvItems.setChoiceMode(ListView.CHOICE_MODE_NONE);
lvItems.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
Log.i(TAG, "list onClick =" + position);
Log.i(TAG, "list item =" + list.get(position));
if (position == list.size() - 1) {
// user select the "cancel" item;
informCaller(false, -1);
} else {
informCaller(true, position);
}
}
});
}
builder.setView(content);
} else {
if (!TextUtils.isEmpty(message)) { if (!TextUtils.isEmpty(message)) {
builder.setMessage(message); builder.setMessage(message);
} }
AlertDialog dialog = builder.show(); }
AlertDialog dialog = builder.create();
dialog.setCanceledOnTouchOutside(false); dialog.setCanceledOnTouchOutside(false);
return dialog; return dialog;
} }

View File

@@ -16,12 +16,13 @@
package com.android.settings.network.telephony; package com.android.settings.network.telephony;
import android.app.Activity;
import android.os.Bundle; import android.os.Bundle;
import android.telephony.SubscriptionManager; import android.telephony.SubscriptionManager;
import androidx.fragment.app.FragmentActivity;
/** The base class for subscription action dialogs */ /** The base class for subscription action dialogs */
public class SubscriptionActionDialogActivity extends Activity { public class SubscriptionActionDialogActivity extends FragmentActivity {
private static final String TAG = "SubscriptionActionDialogActivity"; private static final String TAG = "SubscriptionActionDialogActivity";
// Arguments // Arguments

View File

@@ -455,6 +455,31 @@ public class ToggleSubscriptionDialogActivity extends SubscriptionActionDialogAc
private void showMepSwitchSimConfirmDialog() { private void showMepSwitchSimConfirmDialog() {
Log.i(TAG, "showMepSwitchSimConfirmDialog"); Log.i(TAG, "showMepSwitchSimConfirmDialog");
final CharSequence displayName = SubscriptionUtil.getUniqueSubscriptionDisplayName(
mSubInfo, this);
String title = getString(R.string.sim_action_switch_sub_dialog_mep_title, displayName);
final StringBuilder switchDialogMsg = new StringBuilder();
switchDialogMsg.append(
getString(R.string.sim_action_switch_sub_dialog_mep_text, displayName));
if (isRtlMode) {
/* There are two lines of message in the dialog, and the RTL symbols must be added
* before and after each sentence, so use the line break symbol to find the position.
* (Each message are all with two line break symbols)
*/
switchDialogMsg.insert(0, RTL_MARK)
.insert(switchDialogMsg.indexOf(LINE_BREAK) - LINE_BREAK_OFFSET_ONE, RTL_MARK)
.insert(switchDialogMsg.indexOf(LINE_BREAK) + LINE_BREAK_OFFSET_TWO, RTL_MARK)
.insert(switchDialogMsg.length(), RTL_MARK);
}
ConfirmDialogFragment.show(
this,
ConfirmDialogFragment.OnConfirmListener.class,
DIALOG_TAG_ENABLE_SIM_CONFIRMATION_MEP,
title,
switchDialogMsg.toString(),
null,
null,
getSwitchDialogBodyList());
} }
private String getSwitchDialogPosBtnText() { private String getSwitchDialogPosBtnText() {

View File

@@ -160,9 +160,11 @@ public class SimDialogActivity extends FragmentActivity {
final TelephonyManager telephonyManager = getSystemService( final TelephonyManager telephonyManager = getSystemService(
TelephonyManager.class).createForSubscriptionId(subId); TelephonyManager.class).createForSubscriptionId(subId);
subscriptionManager.setDefaultDataSubId(subId); subscriptionManager.setDefaultDataSubId(subId);
if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
telephonyManager.setDataEnabled(true); telephonyManager.setDataEnabled(true);
Toast.makeText(this, R.string.data_switch_started, Toast.LENGTH_LONG).show(); Toast.makeText(this, R.string.data_switch_started, Toast.LENGTH_LONG).show();
} }
}
private void setDefaultCallsSubId(final int subId) { private void setDefaultCallsSubId(final int subId) {
final PhoneAccountHandle phoneAccount = subscriptionIdToPhoneAccountHandle(subId); final PhoneAccountHandle phoneAccount = subscriptionIdToPhoneAccountHandle(subId);