Merge changes I0ea498d2,I2d650eb3,I8adcf27e
* changes:
Grey out LE audio offload switcher as LE audio isn't enabled/supported
Unify the LE audio string and refine the layout to put LE audio switch together
Add LE Audio feature switcher in the developer option menu
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index a2d8049..bc491e2 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -3958,6 +3958,38 @@
android:value="true" />
</activity>
+ <activity
+ android:name="Settings$BluetoothBroadcastActivity"
+ android:exported="true"
+ android:theme="@style/Theme.AlertDialog.SimConfirmDialog"
+ android:permission="android.permission.BLUETOOTH_CONNECT"
+ android:configChanges="orientation|keyboardHidden|screenSize">
+ <intent-filter android:priority="1">
+ <action android:name="android.settings.MEDIA_BROADCAST_DIALOG" />
+ <category android:name="android.intent.category.DEFAULT" />
+ </intent-filter>
+ <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
+ android:value="com.android.settings.bluetooth.BluetoothBroadcastsDialog" />
+ <meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
+ android:value="true" />
+ </activity>
+
+ <activity
+ android:name="Settings$BluetoothFindBroadcastsActivity"
+ android:label="@string/bluetooth_find_broadcast_title"
+ android:exported="true"
+ android:permission="android.permission.BLUETOOTH_CONNECT"
+ android:configChanges="orientation|keyboardHidden|screenSize">
+ <intent-filter android:priority="1">
+ <action android:name="android.settings.BLUTOOTH_FIND_BROADCASTS_ACTIVITY" />
+ <category android:name="android.intent.category.DEFAULT" />
+ </intent-filter>
+ <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
+ android:value="com.android.settings.bluetooth.BluetoothFindBroadcastsFragment" />
+ <meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
+ android:value="true" />
+ </activity>
+
<activity android:name=".panel.SettingsPanelActivity"
android:label="@string/settings_panel_title"
android:theme="@style/Theme.Panel"
diff --git a/res/drawable/broadcast_button_outline.xml b/res/drawable/broadcast_button_outline.xml
new file mode 100644
index 0000000..6609915
--- /dev/null
+++ b/res/drawable/broadcast_button_outline.xml
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2022 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.
+-->
+<inset xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:androidprv="http://schemas.android.com/apk/prv/res/android"
+ android:insetTop="6dp"
+ android:insetBottom="6dp">
+ <ripple android:color="?android:attr/colorControlHighlight">
+ <item android:id="@android:id/mask">
+ <shape android:shape="rectangle">
+ <solid android:color="@android:color/white"/>
+ <corners android:radius="24dp"/>
+ </shape>
+ </item>
+ <item>
+ <shape android:shape="rectangle">
+ <corners android:radius="24dp"/>
+ <solid android:color="@android:color/transparent"/>
+ <stroke android:color="?androidprv:attr/colorAccentPrimaryVariant"
+ android:width="1dp"
+ />
+ <padding android:left="16dp"
+ android:top="8dp"
+ android:right="16dp"
+ android:bottom="8dp"/>
+ </shape>
+ </item>
+ </ripple>
+</inset>
diff --git a/res/layout-land/adb_qrcode_scanner_fragment.xml b/res/layout-land/adb_qrcode_scanner_fragment.xml
index 6451551..a2c0110 100644
--- a/res/layout-land/adb_qrcode_scanner_fragment.xml
+++ b/res/layout-land/adb_qrcode_scanner_fragment.xml
@@ -45,7 +45,7 @@
android:id="@+id/preview_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"/>
- <com.android.settings.wifi.qrcode.QrDecorateView
+ <com.android.settingslib.qrcode.QrDecorateView
android:id="@+id/decorate_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"/>
diff --git a/res/layout-land/wifi_dpp_qrcode_scanner_fragment.xml b/res/layout-land/wifi_dpp_qrcode_scanner_fragment.xml
index 7428749..11bb0ae 100644
--- a/res/layout-land/wifi_dpp_qrcode_scanner_fragment.xml
+++ b/res/layout-land/wifi_dpp_qrcode_scanner_fragment.xml
@@ -44,7 +44,7 @@
android:id="@+id/preview_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"/>
- <com.android.settings.wifi.qrcode.QrDecorateView
+ <com.android.settingslib.qrcode.QrDecorateView
android:id="@+id/decorate_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"/>
diff --git a/res/layout/adb_qrcode_scanner_fragment.xml b/res/layout/adb_qrcode_scanner_fragment.xml
index 7823155..98c2122 100644
--- a/res/layout/adb_qrcode_scanner_fragment.xml
+++ b/res/layout/adb_qrcode_scanner_fragment.xml
@@ -45,7 +45,7 @@
android:id="@+id/preview_view"
android:layout_width="match_parent"
android:layout_height="@dimen/qrcode_preview_size"/>
- <com.android.settings.wifi.qrcode.QrDecorateView
+ <com.android.settingslib.qrcode.QrDecorateView
android:id="@+id/decorate_view"
android:layout_width="match_parent"
android:layout_height="@dimen/qrcode_preview_size"/>
diff --git a/res/layout/bluetooth_broadcast_entity_header.xml b/res/layout/bluetooth_broadcast_entity_header.xml
new file mode 100644
index 0000000..cc18d94
--- /dev/null
+++ b/res/layout/bluetooth_broadcast_entity_header.xml
@@ -0,0 +1,99 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2022 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:id="@+id/entity_header"
+ style="@style/EntityHeader"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:gravity="center"
+ android:paddingStart="?android:attr/listPreferredItemPaddingStart"
+ android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
+ android:orientation="vertical">
+
+ <TextView
+ android:id="@+id/entity_header_title"
+ style="@style/TextAppearance.EntityHeaderTitle"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:singleLine="false"
+ android:ellipsize="marquee"
+ android:textDirection="locale"/>
+
+ <TextView
+ android:id="@+id/entity_header_summary"
+ style="@style/TextAppearance.EntityHeaderSummary"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="@dimen/bluetooth_find_broadcast_header_top_margin"
+ android:singleLine="false"
+ android:ellipsize="marquee"
+ android:textDirection="locale"/>
+
+ <Button
+ android:id="@+id/button_find_broadcast"
+ android:layout_width="@dimen/bluetooth_find_broadcast_button_one_size"
+ android:layout_height="wrap_content"
+ android:text="@string/bluetooth_find_broadcast"
+ android:clickable="true"
+ style="@style/BroadcastActionButton" />
+
+ <LinearLayout
+ android:id="@+id/button_broadcast_layout"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:gravity="center"
+ android:orientation="horizontal" >
+
+ <LinearLayout
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content">
+ <Button
+ android:id="@+id/button_leave_broadcast"
+ android:layout_width="@dimen/bluetooth_find_broadcast_button_two_size"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:text="@string/bluetooth_find_broadcast_button_leave"
+ android:clickable="true"
+ style="@style/BroadcastActionButton" />
+ </LinearLayout>
+
+ <LinearLayout
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginStart="@dimen/bluetooth_find_broadcast_button_start_margin">
+ <Button
+ android:id="@+id/button_scan_qr_code"
+ android:layout_width="@dimen/bluetooth_find_broadcast_button_two_size"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:text="@string/bluetooth_find_broadcast_button_scan"
+ android:clickable="true"
+ style="@style/BroadcastActionButton" />
+ </LinearLayout>
+
+ </LinearLayout>
+
+ <android.widget.ProgressBar
+ android:id="@+id/progressBar"
+ style="?android:attr/progressBarStyleHorizontal"
+ android:layout_width="@dimen/bluetooth_find_broadcast_progress_width"
+ android:layout_height="@dimen/bluetooth_find_broadcast_progress_height"
+ android:layout_marginTop="@dimen/bluetooth_find_broadcast_progress_margin_top"
+ android:progressDrawable="@drawable/color_bar_progress"/>
+</LinearLayout>
diff --git a/res/layout/wifi_dpp_qrcode_scanner_fragment.xml b/res/layout/wifi_dpp_qrcode_scanner_fragment.xml
index 380fc8a..dd96d7e 100644
--- a/res/layout/wifi_dpp_qrcode_scanner_fragment.xml
+++ b/res/layout/wifi_dpp_qrcode_scanner_fragment.xml
@@ -44,7 +44,7 @@
android:id="@+id/preview_view"
android:layout_width="match_parent"
android:layout_height="@dimen/qrcode_preview_size"/>
- <com.android.settings.wifi.qrcode.QrDecorateView
+ <com.android.settingslib.qrcode.QrDecorateView
android:id="@+id/decorate_view"
android:layout_width="match_parent"
android:layout_height="@dimen/qrcode_preview_size"/>
diff --git a/res/values/arrays.xml b/res/values/arrays.xml
index 0fe13fe..9f0af97 100644
--- a/res/values/arrays.xml
+++ b/res/values/arrays.xml
@@ -1180,14 +1180,14 @@
</string-array>
<!-- Array of color for sim color for multi-sim in light mode -->
- <string-array name="sim_color_light">
+ <integer-array name="sim_color_light">
<item>@color/SIM_color_cyan</item>
<item>@color/SIM_color_blue800</item>
<item>@color/SIM_color_green800</item>
<item>@color/SIM_color_purple800</item>
<item>@color/SIM_color_pink800</item>
<item>@color/SIM_color_orange</item>
- </string-array>
+ </integer-array>
<!-- Array of titles for sim color for multi-sim -->
<string-array name="color_picker">
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index 8b73585..b160900 100755
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -399,6 +399,15 @@
<dimen name="le_bluetooth_summary_start_margin">20dp</dimen>
<dimen name="le_bluetooth_summary_padding">1.5dp</dimen>
+ <!-- Header layout of bluetooth find broadcast page -->
+ <dimen name="bluetooth_find_broadcast_button_one_size">220dp</dimen>
+ <dimen name="bluetooth_find_broadcast_button_two_size">150dp</dimen>
+ <dimen name="bluetooth_find_broadcast_button_start_margin">16dp</dimen>
+ <dimen name="bluetooth_find_broadcast_header_top_margin">4dp</dimen>
+ <dimen name="bluetooth_find_broadcast_progress_width">155dp</dimen>
+ <dimen name="bluetooth_find_broadcast_progress_height">4dp</dimen>
+ <dimen name="bluetooth_find_broadcast_progress_margin_top">8dp</dimen>
+
<!-- Developer option bluetooth settings dialog -->
<dimen name="developer_option_dialog_margin_start">8dp</dimen>
<dimen name="developer_option_dialog_margin_top">8dp</dimen>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index ecee16e..c540c1f 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -13501,4 +13501,22 @@
<string name="bluetooth_connect_access_dialog_negative">Don\u2019t connect</string>
<!-- Strings for Dialog connect button -->
<string name="bluetooth_connect_access_dialog_positive">Connect</string>
+
+ <!-- BT LE Audio Device: Media Broadcast -->
+ <!-- The title of the Media Broadcast Dialog [CHAR LIMIT=none] -->
+ <string name="bluetooth_broadcast_dialog_title">Broadcast</string>
+ <!-- The message of the Media Broadcast Dialog for finding broadcast [CHAR LIMIT=none] -->
+ <string name="bluetooth_broadcast_dialog_find_message">Listen to broadcasts that are playing near you</string>
+ <!-- The message of the Media Broadcast Dialog for broadcast [CHAR LIMIT=none] -->
+ <string name="bluetooth_broadcast_dialog_broadcast_message">Broadcast media to devices near you, or listen to someone else’s broadcast</string>
+ <!-- The title of the Media Find Broadcast activity [CHAR LIMIT=none] -->
+ <string name="bluetooth_find_broadcast_title">Broadcasts</string>
+ <!-- The summary of the Media Find Broadcast activity [CHAR LIMIT=none] -->
+ <string name="bluetooth_find_broadcast_summary">Listening to</string>
+ <!-- The Button of the action to find broadcasts [CHAR LIMIT=none] -->
+ <string name="bluetooth_find_broadcast">Find broadcasts</string>
+ <!-- The Button of the action to leave the broadcast [CHAR LIMIT=none] -->
+ <string name="bluetooth_find_broadcast_button_leave">Leave broadcast</string>
+ <!-- The Button of the action to scan QR code [CHAR LIMIT=none] -->
+ <string name="bluetooth_find_broadcast_button_scan">Scan QR code</string>
</resources>
diff --git a/res/values/styles.xml b/res/values/styles.xml
index 838d63b..1a6f88f 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -936,4 +936,15 @@
<style name="SimConfirmDialog.ButtonBarStyle" parent="@android:style/Widget.Material.ButtonBar">
<item name="android:paddingEnd">8dp</item>
</style>
+
+ <style name="BroadcastActionButton" parent="@android:style/Widget.Material.Button">
+ <item name="android:background">@drawable/broadcast_button_outline</item>
+ <item name="android:textColor">?android:attr/textColorPrimary</item>
+ <item name="android:textSize">14sp</item>
+ <item name="android:lineHeight">20sp</item>
+ <item name="android:fontFamily">@*android:string/config_bodyFontFamilyMedium</item>
+ <item name="android:stateListAnimator">@null</item>
+ <item name="android:minWidth">0dp</item>
+ <item name="android:textAllCaps">false</item>
+ </style>
</resources>
diff --git a/res/xml/bluetooth_find_broadcasts_fragment.xml b/res/xml/bluetooth_find_broadcasts_fragment.xml
new file mode 100644
index 0000000..a564ac9
--- /dev/null
+++ b/res/xml/bluetooth_find_broadcasts_fragment.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2022 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.
+ -->
+<PreferenceScreen
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:settings="http://schemas.android.com/apk/res-auto"
+ android:title="@string/bluetooth_find_broadcast_title">
+
+ <com.android.settingslib.widget.LayoutPreference
+ android:key="bluetooth_find_broadcast_header"
+ android:layout="@layout/bluetooth_broadcast_entity_header"
+ android:selectable="false"
+ settings:allowDividerBelow="true"
+ settings:searchable="false" />
+
+ <PreferenceCategory
+ android:key="broadcast_source_list"
+ android:layout="@layout/preference_category_no_label"/>
+
+</PreferenceScreen>
+
+
diff --git a/src/com/android/settings/Settings.java b/src/com/android/settings/Settings.java
index 287ac85..0e0115e 100644
--- a/src/com/android/settings/Settings.java
+++ b/src/com/android/settings/Settings.java
@@ -298,6 +298,8 @@
public static class WebViewAppPickerActivity extends SettingsActivity { /* empty */ }
public static class AdvancedConnectedDeviceActivity extends SettingsActivity { /* empty */ }
public static class BluetoothDeviceDetailActivity extends SettingsActivity { /* empty */ }
+ public static class BluetoothBroadcastActivity extends SettingsActivity { /* empty */ }
+ public static class BluetoothFindBroadcastsActivity extends SettingsActivity { /* empty */ }
public static class WifiCallingDisclaimerActivity extends SettingsActivity { /* empty */ }
public static class MobileNetworkListActivity extends SettingsActivity {}
public static class PowerMenuSettingsActivity extends SettingsActivity {}
diff --git a/src/com/android/settings/bluetooth/BluetoothBroadcastDialog.java b/src/com/android/settings/bluetooth/BluetoothBroadcastDialog.java
new file mode 100644
index 0000000..c743653
--- /dev/null
+++ b/src/com/android/settings/bluetooth/BluetoothBroadcastDialog.java
@@ -0,0 +1,139 @@
+/*
+ * Copyright (C) 2022 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.bluetooth;
+
+import android.app.Dialog;
+import android.app.settings.SettingsEnums;
+import android.content.Context;
+import android.os.Bundle;
+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 androidx.appcompat.app.AlertDialog;
+
+import com.android.settings.R;
+import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
+
+import java.util.ArrayList;
+
+/**
+ * This Dialog allowed users to do some actions for broadcast media or find the
+ * nearby broadcast sources.
+ */
+public class BluetoothBroadcastDialog extends InstrumentedDialogFragment {
+
+ private static final String TAG = "BTBroadcastsDialog";
+
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setShowsDialog(true);
+ }
+
+ @Override
+ public Dialog onCreateDialog(Bundle savedInstanceState) {
+ final Context context = getActivity();
+ final boolean isMediaPlaying = isMediaPlaying();
+
+ final AlertDialog.Builder builder = new AlertDialog.Builder(context);
+ builder.setTitle(isMediaPlaying ? R.string.bluetooth_find_broadcast
+ : R.string.bluetooth_broadcast_dialog_title);
+ builder.setMessage(isMediaPlaying ? R.string.bluetooth_broadcast_dialog_find_message
+ : R.string.bluetooth_broadcast_dialog_broadcast_message);
+
+ ArrayList<String> optionList = new ArrayList<String>();
+ if (!isMediaPlaying) {
+ optionList.add(context.getString(R.string.bluetooth_broadcast_dialog_title));
+ }
+ optionList.add(context.getString(R.string.bluetooth_find_broadcast));
+ optionList.add(context.getString(android.R.string.cancel));
+
+ View content = LayoutInflater.from(context).inflate(
+ R.layout.sim_confirm_dialog_multiple_enabled_profiles_supported, null);
+
+ if (content != null) {
+ Log.i(TAG, "list =" + optionList.toString());
+
+ final ArrayAdapter<String> arrayAdapterItems = new ArrayAdapter<String>(
+ context,
+ R.layout.sim_confirm_dialog_item_multiple_enabled_profiles_supported,
+ optionList);
+ final ListView lvItems = content.findViewById(R.id.carrier_list);
+ if (lvItems != null) {
+ lvItems.setVisibility(View.VISIBLE);
+ lvItems.setAdapter(arrayAdapterItems);
+ 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 =" + optionList.get(position));
+
+ if (position == optionList.size() - 1) {
+ // The last position in the options is the Cancel button. So when
+ // the user clicks the button, we do nothing but dismiss the dialog.
+ dismiss();
+ } else {
+ if (optionList.get(position).equals(
+ context.getString(R.string.bluetooth_find_broadcast))) {
+ launchFindBroadcastsActivity();
+ } else {
+ launchMediaOutputBroadcastDialog();
+ }
+ }
+ }
+ });
+ }
+ builder.setView(content);
+ } else {
+ Log.i(TAG, "optionList is empty");
+ }
+
+ AlertDialog dialog = builder.create();
+ dialog.setCanceledOnTouchOutside(false);
+ return dialog;
+ }
+
+ private boolean isMediaPlaying() {
+ return true;
+ }
+
+
+ @Override
+ public void onStart() {
+ super.onStart();
+ }
+
+ @Override
+ public int getMetricsCategory() {
+ //TODO(b/228255796) : add new enum for find broadcast fragment
+ return SettingsEnums.PAGE_UNKNOWN;
+ }
+
+ private void launchFindBroadcastsActivity() {
+
+ }
+
+ private void launchMediaOutputBroadcastDialog() {
+
+ }
+}
diff --git a/src/com/android/settings/bluetooth/BluetoothFindBroadcastsFragment.java b/src/com/android/settings/bluetooth/BluetoothFindBroadcastsFragment.java
new file mode 100644
index 0000000..f251db5
--- /dev/null
+++ b/src/com/android/settings/bluetooth/BluetoothFindBroadcastsFragment.java
@@ -0,0 +1,128 @@
+/*
+ * Copyright (C) 2022 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.bluetooth;
+
+import static android.bluetooth.BluetoothDevice.BOND_NONE;
+import static android.os.UserManager.DISALLOW_CONFIG_BLUETOOTH;
+
+import android.app.settings.SettingsEnums;
+import android.bluetooth.BluetoothDevice;
+import android.content.Context;
+import android.util.Log;
+
+import androidx.annotation.VisibleForTesting;
+
+import com.android.settings.R;
+import com.android.settings.dashboard.RestrictedDashboardFragment;
+import com.android.settingslib.bluetooth.CachedBluetoothDevice;
+import com.android.settingslib.bluetooth.LocalBluetoothManager;
+import com.android.settingslib.core.AbstractPreferenceController;
+import com.android.settingslib.core.lifecycle.Lifecycle;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * This fragment allowed users to find the nearby broadcast sources.
+ */
+public class BluetoothFindBroadcastsFragment extends RestrictedDashboardFragment {
+
+ private static final String TAG = "BTFindBroadcastsFrg";
+
+ public static final String KEY_DEVICE_ADDRESS = "device_address";
+
+ public static final String PREF_KEY_BROADCAST_SOURCE = "broadcast_source";
+
+ @VisibleForTesting
+ String mDeviceAddress;
+ @VisibleForTesting
+ LocalBluetoothManager mManager;
+ @VisibleForTesting
+ CachedBluetoothDevice mCachedDevice;
+
+ public BluetoothFindBroadcastsFragment() {
+ super(DISALLOW_CONFIG_BLUETOOTH);
+ }
+
+ @VisibleForTesting
+ LocalBluetoothManager getLocalBluetoothManager(Context context) {
+ return Utils.getLocalBtManager(context);
+ }
+
+ @VisibleForTesting
+ CachedBluetoothDevice getCachedDevice(String deviceAddress) {
+ BluetoothDevice remoteDevice =
+ mManager.getBluetoothAdapter().getRemoteDevice(deviceAddress);
+ return mManager.getCachedDeviceManager().findDevice(remoteDevice);
+ }
+
+ @Override
+ public void onAttach(Context context) {
+ mDeviceAddress = getArguments().getString(KEY_DEVICE_ADDRESS);
+ mManager = getLocalBluetoothManager(context);
+ mCachedDevice = getCachedDevice(mDeviceAddress);
+ super.onAttach(context);
+ if (mCachedDevice == null) {
+ //Close this page if device is null with invalid device mac address
+ Log.w(TAG, "onAttach() CachedDevice is null!");
+ finish();
+ return;
+ }
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+ finishFragmentIfNecessary();
+ }
+
+ @VisibleForTesting
+ void finishFragmentIfNecessary() {
+ if (mCachedDevice.getBondState() == BOND_NONE) {
+ finish();
+ return;
+ }
+ }
+
+ @Override
+ public int getMetricsCategory() {
+ //TODO(b/228255796) : add new enum for find broadcast fragment
+ return SettingsEnums.PAGE_UNKNOWN;
+ }
+
+ @Override
+ protected String getLogTag() {
+ return TAG;
+ }
+
+ @Override
+ protected int getPreferenceScreenResId() {
+ return R.xml.bluetooth_find_broadcasts_fragment;
+ }
+
+ @Override
+ protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
+ ArrayList<AbstractPreferenceController> controllers = new ArrayList<>();
+
+ if (mCachedDevice != null) {
+ Lifecycle lifecycle = getSettingsLifecycle();
+ controllers.add(new BluetoothFindBroadcastsHeaderController(context, this,
+ mCachedDevice, lifecycle, mManager));
+ }
+ return controllers;
+ }
+}
diff --git a/src/com/android/settings/bluetooth/BluetoothFindBroadcastsHeaderController.java b/src/com/android/settings/bluetooth/BluetoothFindBroadcastsHeaderController.java
new file mode 100644
index 0000000..dfdcae0
--- /dev/null
+++ b/src/com/android/settings/bluetooth/BluetoothFindBroadcastsHeaderController.java
@@ -0,0 +1,131 @@
+/*
+ * Copyright (C) 2022 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.bluetooth;
+
+import android.content.Context;
+import android.util.Log;
+import android.view.View;
+import android.widget.Button;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+import androidx.preference.PreferenceCategory;
+import androidx.preference.PreferenceFragmentCompat;
+import androidx.preference.PreferenceScreen;
+
+import com.android.settings.R;
+import com.android.settingslib.bluetooth.CachedBluetoothDevice;
+import com.android.settingslib.bluetooth.LocalBluetoothManager;
+import com.android.settingslib.bluetooth.LocalBluetoothProfileManager;
+import com.android.settingslib.core.lifecycle.Lifecycle;
+import com.android.settingslib.widget.LayoutPreference;
+
+/**
+ * This class adds a header to display the action button for joining the broadcast session
+ * by scanning QR code and leaving the broadcast session
+ */
+public class BluetoothFindBroadcastsHeaderController extends BluetoothDetailsController {
+ private static final String TAG = "BtFindBroadcastCtrl";
+
+ private static final String KEY_BROADCAST_HEADER = "bluetooth_find_broadcast_header";
+ private static final String KEY_BROADCAST_SOURCE_LIST = "broadcast_source_list";
+
+ LayoutPreference mLayoutPreference;
+ PreferenceCategory mBroadcastSourceList;
+ TextView mTitle;
+ TextView mSummary;
+ Button mBtnFindBroadcast;
+ LinearLayout mBtnBroadcastLayout;
+ Button mBtnLeaveBroadcast;
+ Button mBtnScanQrCode;
+
+ public BluetoothFindBroadcastsHeaderController(Context context,
+ PreferenceFragmentCompat fragment, CachedBluetoothDevice device, Lifecycle lifecycle,
+ LocalBluetoothManager bluetoothManager) {
+ super(context, fragment, device, lifecycle);
+ }
+
+ @Override
+ protected void init(PreferenceScreen screen) {
+ mLayoutPreference = screen.findPreference(KEY_BROADCAST_HEADER);
+ mBroadcastSourceList = screen.findPreference(KEY_BROADCAST_SOURCE_LIST);
+
+ refresh();
+ }
+
+ @Override
+ protected void refresh() {
+ if (mLayoutPreference == null || mCachedDevice == null) {
+ return;
+ }
+
+ mTitle = mLayoutPreference.findViewById(R.id.entity_header_title);
+ mTitle.setText(mCachedDevice.getName());
+ mSummary = mLayoutPreference.findViewById(R.id.entity_header_summary);
+ mSummary.setText("");
+
+ mBtnFindBroadcast = mLayoutPreference.findViewById(R.id.button_find_broadcast);
+ mBtnFindBroadcast.setOnClickListener(v -> scanBroadcastSource());
+ mBtnBroadcastLayout = mLayoutPreference.findViewById(R.id.button_broadcast_layout);
+ mBtnLeaveBroadcast = mLayoutPreference.findViewById(R.id.button_leave_broadcast);
+ mBtnLeaveBroadcast.setOnClickListener(v -> leaveBroadcastSession());
+ mBtnScanQrCode = mLayoutPreference.findViewById(R.id.button_scan_qr_code);
+ mBtnScanQrCode.setOnClickListener(v -> launchQrCodeScanner());
+
+ updateHeaderLayout();
+ }
+
+ private boolean isBroadcastSourceExist() {
+ return mBroadcastSourceList.getPreferenceCount() > 0;
+ }
+
+ private void updateHeaderLayout() {
+ if (isBroadcastSourceExist()) {
+ mBtnFindBroadcast.setVisibility(View.GONE);
+ mBtnBroadcastLayout.setVisibility(View.VISIBLE);
+ } else {
+ mBtnFindBroadcast.setVisibility(View.VISIBLE);
+ mBtnBroadcastLayout.setVisibility(View.GONE);
+ }
+ }
+
+ private void scanBroadcastSource() {
+ // TODO(b/228258236) : Call the LocalBluetoothLeBroadcastAssistant
+ // to start searching for source
+ }
+
+ private void leaveBroadcastSession() {
+ // TODO(b/228258236) : Call the LocalBluetoothLeBroadcastAssistant
+ // to leave the broadcast session
+ }
+
+ private void launchQrCodeScanner() {
+ // TODO(b/228259065) : Launch the QR code scanner page by intent
+ }
+
+ @Override
+ public void onDeviceAttributesChanged() {
+ if (mCachedDevice != null) {
+ refresh();
+ }
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return KEY_BROADCAST_HEADER;
+ }
+}
diff --git a/src/com/android/settings/core/gateway/SettingsGateway.java b/src/com/android/settings/core/gateway/SettingsGateway.java
index 2cf9255..3451670 100644
--- a/src/com/android/settings/core/gateway/SettingsGateway.java
+++ b/src/com/android/settings/core/gateway/SettingsGateway.java
@@ -67,7 +67,9 @@
import com.android.settings.biometrics.combination.CombinedBiometricSettings;
import com.android.settings.biometrics.face.FaceSettings;
import com.android.settings.biometrics.fingerprint.FingerprintSettings;
+import com.android.settings.bluetooth.BluetoothBroadcastDialog;
import com.android.settings.bluetooth.BluetoothDeviceDetailsFragment;
+import com.android.settings.bluetooth.BluetoothFindBroadcastsFragment;
import com.android.settings.bluetooth.BluetoothPairingDetail;
import com.android.settings.bugreporthandler.BugReportHandlerPicker;
import com.android.settings.connecteddevice.AdvancedConnectedDeviceDashboardFragment;
@@ -307,6 +309,8 @@
WebViewAppPicker.class.getName(),
LockscreenDashboardFragment.class.getName(),
BluetoothDeviceDetailsFragment.class.getName(),
+ BluetoothBroadcastDialog.class.getName(),
+ BluetoothFindBroadcastsFragment.class.getName(),
DataUsageList.class.getName(),
ToggleBackupSettingFragment.class.getName(),
PreviouslyConnectedDeviceDashboardFragment.class.getName(),
diff --git a/src/com/android/settings/development/AdbQrcodeScannerFragment.java b/src/com/android/settings/development/AdbQrcodeScannerFragment.java
index 1035fbe..664c729 100644
--- a/src/com/android/settings/development/AdbQrcodeScannerFragment.java
+++ b/src/com/android/settings/development/AdbQrcodeScannerFragment.java
@@ -48,8 +48,8 @@
import com.android.settings.wifi.dpp.AdbQrCode;
import com.android.settings.wifi.dpp.WifiDppQrCodeBaseFragment;
import com.android.settings.wifi.dpp.WifiNetworkConfig;
-import com.android.settings.wifi.qrcode.QrCamera;
-import com.android.settings.wifi.qrcode.QrDecorateView;
+import com.android.settingslib.qrcode.QrCamera;
+import com.android.settingslib.qrcode.QrDecorateView;
import com.google.android.setupdesign.util.ThemeHelper;
diff --git a/src/com/android/settings/deviceinfo/StorageDashboardFragment.java b/src/com/android/settings/deviceinfo/StorageDashboardFragment.java
index 4903948..3760ab5 100644
--- a/src/com/android/settings/deviceinfo/StorageDashboardFragment.java
+++ b/src/com/android/settings/deviceinfo/StorageDashboardFragment.java
@@ -361,9 +361,7 @@
return;
}
- if (getView().findViewById(R.id.loading_container).getVisibility() == View.VISIBLE) {
- setLoading(false /* loading */, true /* animate */);
- }
+ setLoading(false /* loading */, true /* animate */);
final long privateUsedBytes = mStorageInfo.totalBytes - mStorageInfo.freeBytes;
mPreferenceController.setVolume(mSelectedStorageEntry.getVolumeInfo());
diff --git a/src/com/android/settings/network/UiccSlotUtil.java b/src/com/android/settings/network/UiccSlotUtil.java
index 8fdc370..c27621a 100644
--- a/src/com/android/settings/network/UiccSlotUtil.java
+++ b/src/com/android/settings/network/UiccSlotUtil.java
@@ -193,7 +193,7 @@
if (slotInfo == null) {
return false;
}
- return !slotInfo.isRemovable();
+ return slotInfo.getIsEuicc();
})
.findFirst().orElse(-1);
diff --git a/src/com/android/settings/wifi/dpp/WifiDppQrCodeGeneratorFragment.java b/src/com/android/settings/wifi/dpp/WifiDppQrCodeGeneratorFragment.java
index 2ec960e..d3a4be7 100644
--- a/src/com/android/settings/wifi/dpp/WifiDppQrCodeGeneratorFragment.java
+++ b/src/com/android/settings/wifi/dpp/WifiDppQrCodeGeneratorFragment.java
@@ -43,7 +43,7 @@
import com.android.internal.app.chooser.DisplayResolveInfo;
import com.android.internal.app.chooser.TargetInfo;
import com.android.settings.R;
-import com.android.settings.wifi.qrcode.QrCodeGenerator;
+import com.android.settingslib.qrcode.QrCodeGenerator;
import com.google.zxing.WriterException;
diff --git a/src/com/android/settings/wifi/dpp/WifiDppQrCodeScannerFragment.java b/src/com/android/settings/wifi/dpp/WifiDppQrCodeScannerFragment.java
index 528fbc3..f313f6b 100644
--- a/src/com/android/settings/wifi/dpp/WifiDppQrCodeScannerFragment.java
+++ b/src/com/android/settings/wifi/dpp/WifiDppQrCodeScannerFragment.java
@@ -56,8 +56,8 @@
import com.android.settings.R;
import com.android.settings.overlay.FeatureFactory;
-import com.android.settings.wifi.qrcode.QrCamera;
-import com.android.settings.wifi.qrcode.QrDecorateView;
+import com.android.settingslib.qrcode.QrCamera;
+import com.android.settingslib.qrcode.QrDecorateView;
import com.android.wifitrackerlib.WifiEntry;
import com.android.wifitrackerlib.WifiPickerTracker;
diff --git a/src/com/android/settings/wifi/qrcode/QrCamera.java b/src/com/android/settings/wifi/qrcode/QrCamera.java
deleted file mode 100644
index d07c543..0000000
--- a/src/com/android/settings/wifi/qrcode/QrCamera.java
+++ /dev/null
@@ -1,482 +0,0 @@
-/*
- * Copyright (C) 2018 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.wifi.qrcode;
-
-import android.content.Context;
-import android.content.res.Configuration;
-import android.graphics.Matrix;
-import android.graphics.Rect;
-import android.graphics.SurfaceTexture;
-import android.hardware.Camera;
-import android.hardware.Camera.CameraInfo;
-import android.hardware.Camera.Parameters;
-import android.os.AsyncTask;
-import android.os.Handler;
-import android.os.Message;
-import android.util.ArrayMap;
-import android.util.Log;
-import android.util.Size;
-import android.view.Surface;
-import android.view.WindowManager;
-
-import androidx.annotation.VisibleForTesting;
-
-import com.google.zxing.BarcodeFormat;
-import com.google.zxing.BinaryBitmap;
-import com.google.zxing.DecodeHintType;
-import com.google.zxing.MultiFormatReader;
-import com.google.zxing.ReaderException;
-import com.google.zxing.Result;
-import com.google.zxing.common.HybridBinarizer;
-
-import java.io.IOException;
-import java.lang.ref.WeakReference;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Semaphore;
-
-/**
- * Manage the camera for the QR scanner and help the decoder to get the image inside the scanning
- * frame. Caller prepares a {@link SurfaceTexture} then call {@link #start(SurfaceTexture)} to
- * start QR Code scanning. The scanning result will return by ScannerCallback interface. Caller
- * can also call {@link #stop()} to halt QR Code scanning before the result returned.
- */
-public class QrCamera extends Handler {
- private static final String TAG = "QrCamera";
-
- private static final int MSG_AUTO_FOCUS = 1;
-
- /**
- * The max allowed difference between picture size ratio and preview size ratio.
- * Uses to filter the picture sizes of similar preview size ratio, for example, if a preview
- * size is 1920x1440, MAX_RATIO_DIFF 0.1 could allow picture size of 720x480 or 352x288 or
- * 176x44 but not 1920x1080.
- */
- private static final double MAX_RATIO_DIFF = 0.1;
-
- private static final long AUTOFOCUS_INTERVAL_MS = 1500L;
-
- private static Map<DecodeHintType, List<BarcodeFormat>> HINTS = new ArrayMap<>();
- private static List<BarcodeFormat> FORMATS = new ArrayList<>();
-
- static {
- FORMATS.add(BarcodeFormat.QR_CODE);
- HINTS.put(DecodeHintType.POSSIBLE_FORMATS, FORMATS);
- }
-
- @VisibleForTesting
- Camera mCamera;
- private Size mPreviewSize;
- private WeakReference<Context> mContext;
- private ScannerCallback mScannerCallback;
- private MultiFormatReader mReader;
- private DecodingTask mDecodeTask;
- private int mCameraOrientation;
- @VisibleForTesting
- Camera.Parameters mParameters;
-
- public QrCamera(Context context, ScannerCallback callback) {
- mContext = new WeakReference<Context>(context);
- mScannerCallback = callback;
- mReader = new MultiFormatReader();
- mReader.setHints(HINTS);
- }
-
- /**
- * The function start camera preview and capture pictures to decode QR code continuously in a
- * background task.
- *
- * @param surface The surface to be used for live preview.
- */
- public void start(SurfaceTexture surface) {
- if (mDecodeTask == null) {
- mDecodeTask = new DecodingTask(surface);
- // Execute in the separate thread pool to prevent block other AsyncTask.
- mDecodeTask.executeOnExecutor(Executors.newSingleThreadExecutor());
- }
- }
-
- /**
- * The function stop camera preview and background decode task. Caller call this function when
- * the surface is being destroyed.
- */
- public void stop() {
- removeMessages(MSG_AUTO_FOCUS);
- if (mDecodeTask != null) {
- mDecodeTask.cancel(true);
- mDecodeTask = null;
- }
- if (mCamera != null) {
- mCamera.stopPreview();
- releaseCamera();
- }
- }
-
- /** The scanner which includes this QrCamera class should implement this */
- public interface ScannerCallback {
-
- /**
- * The function used to handle the decoding result of the QR code.
- *
- * @param result the result QR code after decoding.
- */
- void handleSuccessfulResult(String result);
-
- /** Request the QR code scanner to handle the failure happened. */
- void handleCameraFailure();
-
- /**
- * The function used to get the background View size.
- *
- * @return Includes the background view size.
- */
- Size getViewSize();
-
- /**
- * The function used to get the frame position inside the view
- *
- * @param previewSize Is the preview size set by camera
- * @param cameraOrientation Is the orientation of current Camera
- * @return The rectangle would like to crop from the camera preview shot.
- */
- Rect getFramePosition(Size previewSize, int cameraOrientation);
-
- /**
- * Sets the transform to associate with preview area.
- *
- * @param transform The transform to apply to the content of preview
- */
- void setTransform(Matrix transform);
-
- /**
- * Verify QR code is valid or not. The camera will stop scanning if this callback returns
- * true.
- *
- * @param qrCode The result QR code after decoding.
- * @return Returns true if qrCode hold valid information.
- */
- boolean isValid(String qrCode);
- }
-
- @VisibleForTesting
- void setCameraParameter() {
- mParameters = mCamera.getParameters();
- mPreviewSize = getBestPreviewSize(mParameters);
- mParameters.setPreviewSize(mPreviewSize.getWidth(), mPreviewSize.getHeight());
- Size pictureSize = getBestPictureSize(mParameters);
- mParameters.setPictureSize(pictureSize.getWidth(), pictureSize.getHeight());
-
- final List<String> supportedFlashModes = mParameters.getSupportedFlashModes();
- if (supportedFlashModes != null &&
- supportedFlashModes.contains(Parameters.FLASH_MODE_OFF)) {
- mParameters.setFlashMode(Parameters.FLASH_MODE_OFF);
- }
-
- final List<String> supportedFocusModes = mParameters.getSupportedFocusModes();
- if (supportedFocusModes.contains(Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)) {
- mParameters.setFocusMode(Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
- } else if (supportedFocusModes.contains(Parameters.FOCUS_MODE_AUTO)) {
- mParameters.setFocusMode(Parameters.FOCUS_MODE_AUTO);
- }
- mCamera.setParameters(mParameters);
- }
-
- private boolean startPreview() {
- if (mContext.get() == null) {
- return false;
- }
-
- final WindowManager winManager =
- (WindowManager) mContext.get().getSystemService(Context.WINDOW_SERVICE);
- final int rotation = winManager.getDefaultDisplay().getRotation();
- int degrees = 0;
- switch (rotation) {
- case Surface.ROTATION_0:
- degrees = 0;
- break;
- case Surface.ROTATION_90:
- degrees = 90;
- break;
- case Surface.ROTATION_180:
- degrees = 180;
- break;
- case Surface.ROTATION_270:
- degrees = 270;
- break;
- }
- final int rotateDegrees = (mCameraOrientation - degrees + 360) % 360;
- mCamera.setDisplayOrientation(rotateDegrees);
- mCamera.startPreview();
- if (Parameters.FOCUS_MODE_AUTO.equals(mParameters.getFocusMode())) {
- mCamera.autoFocus(/* Camera.AutoFocusCallback */ null);
- sendMessageDelayed(obtainMessage(MSG_AUTO_FOCUS), AUTOFOCUS_INTERVAL_MS);
- }
- return true;
- }
-
- private class DecodingTask extends AsyncTask<Void, Void, String> {
- private QrYuvLuminanceSource mImage;
- private SurfaceTexture mSurface;
-
- private DecodingTask(SurfaceTexture surface) {
- mSurface = surface;
- }
-
- @Override
- protected String doInBackground(Void... tmp) {
- if (!initCamera(mSurface)) {
- return null;
- }
-
- final Semaphore imageGot = new Semaphore(0);
- while (true) {
- // This loop will try to capture preview image continuously until a valid QR Code
- // decoded. The caller can also call {@link #stop()} to interrupts scanning loop.
- mCamera.setOneShotPreviewCallback(
- (imageData, camera) -> {
- mImage = getFrameImage(imageData);
- imageGot.release();
- });
- try {
- // Semaphore.acquire() blocking until permit is available, or the thread is
- // interrupted.
- imageGot.acquire();
- Result qrCode = null;
- try {
- qrCode =
- mReader.decodeWithState(
- new BinaryBitmap(new HybridBinarizer(mImage)));
- } catch (ReaderException e) {
- // No logging since every time the reader cannot decode the
- // image, this ReaderException will be thrown.
- } finally {
- mReader.reset();
- }
- if (qrCode != null) {
- if (mScannerCallback.isValid(qrCode.getText())) {
- return qrCode.getText();
- }
- }
- } catch (InterruptedException e) {
- Thread.currentThread().interrupt();
- return null;
- }
- }
- }
-
- @Override
- protected void onPostExecute(String qrCode) {
- if (qrCode != null) {
- mScannerCallback.handleSuccessfulResult(qrCode);
- }
- }
-
- private boolean initCamera(SurfaceTexture surface) {
- final int numberOfCameras = Camera.getNumberOfCameras();
- Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
- try {
- for (int i = 0; i < numberOfCameras; ++i) {
- Camera.getCameraInfo(i, cameraInfo);
- if (cameraInfo.facing == CameraInfo.CAMERA_FACING_BACK) {
- releaseCamera();
- mCamera = Camera.open(i);
- mCameraOrientation = cameraInfo.orientation;
- break;
- }
- }
- if (mCamera == null && numberOfCameras > 0) {
- Log.i(TAG, "Can't find back camera. Opening a different camera");
- Camera.getCameraInfo(0, cameraInfo);
- releaseCamera();
- mCamera = Camera.open(0);
- mCameraOrientation = cameraInfo.orientation;
- }
- } catch (RuntimeException e) {
- Log.e(TAG, "Fail to open camera: " + e);
- mCamera = null;
- mScannerCallback.handleCameraFailure();
- return false;
- }
-
- try {
- if (mCamera == null) {
- throw new IOException("Cannot find available camera");
- }
- mCamera.setPreviewTexture(surface);
- setCameraParameter();
- setTransformationMatrix();
- if (!startPreview()) {
- throw new IOException("Lost contex");
- }
- } catch (IOException ioe) {
- Log.e(TAG, "Fail to startPreview camera: " + ioe);
- mCamera = null;
- mScannerCallback.handleCameraFailure();
- return false;
- }
- return true;
- }
- }
-
- private void releaseCamera() {
- if (mCamera != null) {
- mCamera.release();
- mCamera = null;
- }
- }
-
- /** Set transform matrix to crop and center the preview picture */
- private void setTransformationMatrix() {
- final boolean isPortrait = mContext.get().getResources().getConfiguration().orientation
- == Configuration.ORIENTATION_PORTRAIT;
-
- final int previewWidth = isPortrait ? mPreviewSize.getWidth() : mPreviewSize.getHeight();
- final int previewHeight = isPortrait ? mPreviewSize.getHeight() : mPreviewSize.getWidth();
- final float ratioPreview = (float) getRatio(previewWidth, previewHeight);
-
- // Calculate transformation matrix.
- float scaleX = 1.0f;
- float scaleY = 1.0f;
- if (previewWidth > previewHeight) {
- scaleY = scaleX / ratioPreview;
- } else {
- scaleX = scaleY / ratioPreview;
- }
-
- // Set the transform matrix.
- final Matrix matrix = new Matrix();
- matrix.setScale(scaleX, scaleY);
- mScannerCallback.setTransform(matrix);
- }
-
- private QrYuvLuminanceSource getFrameImage(byte[] imageData) {
- final Rect frame = mScannerCallback.getFramePosition(mPreviewSize, mCameraOrientation);
- final QrYuvLuminanceSource image = new QrYuvLuminanceSource(imageData,
- mPreviewSize.getWidth(), mPreviewSize.getHeight());
- return (QrYuvLuminanceSource)
- image.crop(frame.left, frame.top, frame.width(), frame.height());
- }
-
- @Override
- public void handleMessage(Message msg) {
- switch (msg.what) {
- case MSG_AUTO_FOCUS:
- // Calling autoFocus(null) will only trigger the camera to focus once. In order
- // to make the camera continuously auto focus during scanning, need to periodically
- // trigger it.
- mCamera.autoFocus(/* Camera.AutoFocusCallback */ null);
- sendMessageDelayed(obtainMessage(MSG_AUTO_FOCUS), AUTOFOCUS_INTERVAL_MS);
- break;
- default:
- Log.d(TAG, "Unexpected Message: " + msg.what);
- }
- }
-
- /** Get best preview size from the list of camera supported preview sizes. Compares the
- * preview size and aspect ratio to choose the best one. */
- private Size getBestPreviewSize(Camera.Parameters parameters) {
- final double minRatioDiffPercent = 0.1;
- final Size windowSize = mScannerCallback.getViewSize();
- final double winRatio = getRatio(windowSize.getWidth(), windowSize.getHeight());
- double bestChoiceRatio = 0;
- Size bestChoice = new Size(0, 0);
- for (Camera.Size size : parameters.getSupportedPreviewSizes()) {
- double ratio = getRatio(size.width, size.height);
- if (size.height * size.width > bestChoice.getWidth() * bestChoice.getHeight()
- && (Math.abs(bestChoiceRatio - winRatio) / winRatio > minRatioDiffPercent
- || Math.abs(ratio - winRatio) / winRatio <= minRatioDiffPercent)) {
- bestChoice = new Size(size.width, size.height);
- bestChoiceRatio = getRatio(size.width, size.height);
- }
- }
- return bestChoice;
- }
-
- /** Get best picture size from the list of camera supported picture sizes. Compares the
- * picture size and aspect ratio to choose the best one. */
- private Size getBestPictureSize(Camera.Parameters parameters) {
- final Camera.Size previewSize = parameters.getPreviewSize();
- final double previewRatio = getRatio(previewSize.width, previewSize.height);
- List<Size> bestChoices = new ArrayList<>();
- final List<Size> similarChoices = new ArrayList<>();
-
- // Filter by ratio
- for (Camera.Size size : parameters.getSupportedPictureSizes()) {
- double ratio = getRatio(size.width, size.height);
- if (ratio == previewRatio) {
- bestChoices.add(new Size(size.width, size.height));
- } else if (Math.abs(ratio - previewRatio) < MAX_RATIO_DIFF) {
- similarChoices.add(new Size(size.width, size.height));
- }
- }
-
- if (bestChoices.size() == 0 && similarChoices.size() == 0) {
- Log.d(TAG, "No proper picture size, return default picture size");
- Camera.Size defaultPictureSize = parameters.getPictureSize();
- return new Size(defaultPictureSize.width, defaultPictureSize.height);
- }
-
- if (bestChoices.size() == 0) {
- bestChoices = similarChoices;
- }
-
- // Get the best by area
- int bestAreaDifference = Integer.MAX_VALUE;
- Size bestChoice = null;
- final int previewArea = previewSize.width * previewSize.height;
- for (Size size : bestChoices) {
- int areaDifference = Math.abs(size.getWidth() * size.getHeight() - previewArea);
- if (areaDifference < bestAreaDifference) {
- bestAreaDifference = areaDifference;
- bestChoice = size;
- }
- }
- return bestChoice;
- }
-
- private double getRatio(double x, double y) {
- return (x < y) ? x / y : y / x;
- }
-
- @VisibleForTesting
- protected void decodeImage(BinaryBitmap image) {
- Result qrCode = null;
-
- try {
- qrCode = mReader.decodeWithState(image);
- } catch (ReaderException e) {
- } finally {
- mReader.reset();
- }
-
- if (qrCode != null) {
- mScannerCallback.handleSuccessfulResult(qrCode.getText());
- }
- }
-
- /**
- * After {@link #start(SurfaceTexture)}, DecodingTask runs continuously to capture images and
- * decode QR code. DecodingTask become null After {@link #stop()}.
- *
- * Uses this method in test case to prevent power consumption problem.
- */
- public boolean isDecodeTaskAlive() {
- return mDecodeTask != null;
- }
-}
diff --git a/src/com/android/settings/wifi/qrcode/QrCodeGenerator.java b/src/com/android/settings/wifi/qrcode/QrCodeGenerator.java
deleted file mode 100644
index d9682d2..0000000
--- a/src/com/android/settings/wifi/qrcode/QrCodeGenerator.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Copyright (C) 2018 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.wifi.qrcode;
-
-import android.graphics.Bitmap;
-import android.graphics.Color;
-
-import com.google.zxing.BarcodeFormat;
-import com.google.zxing.EncodeHintType;
-import com.google.zxing.MultiFormatWriter;
-import com.google.zxing.WriterException;
-import com.google.zxing.common.BitMatrix;
-
-import java.nio.charset.CharsetEncoder;
-import java.nio.charset.StandardCharsets;
-import java.util.HashMap;
-import java.util.Map;
-
-public final class QrCodeGenerator {
- /**
- * Generates a barcode image with {@code contents}.
- *
- * @param contents The contents to encode in the barcode
- * @param size The preferred image size in pixels
- * @return Barcode bitmap
- */
- public static Bitmap encodeQrCode(String contents, int size)
- throws WriterException, IllegalArgumentException {
- final Map<EncodeHintType, Object> hints = new HashMap<>();
- if (!isIso88591(contents)) {
- hints.put(EncodeHintType.CHARACTER_SET, StandardCharsets.UTF_8.name());
- }
-
- final BitMatrix qrBits = new MultiFormatWriter().encode(contents, BarcodeFormat.QR_CODE,
- size, size, hints);
- final Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.RGB_565);
- for (int x = 0; x < size; x++) {
- for (int y = 0; y < size; y++) {
- bitmap.setPixel(x, y, qrBits.get(x, y) ? Color.BLACK : Color.WHITE);
- }
- }
- return bitmap;
- }
-
- private static boolean isIso88591(String contents) {
- CharsetEncoder encoder = StandardCharsets.ISO_8859_1.newEncoder();
- return encoder.canEncode(contents);
- }
-}
diff --git a/src/com/android/settings/wifi/qrcode/QrDecorateView.java b/src/com/android/settings/wifi/qrcode/QrDecorateView.java
deleted file mode 100644
index 5df0cd0..0000000
--- a/src/com/android/settings/wifi/qrcode/QrDecorateView.java
+++ /dev/null
@@ -1,143 +0,0 @@
-/*
- * Copyright (C) 2018 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.wifi.qrcode;
-
-import android.content.Context;
-import android.graphics.Bitmap;
-import android.graphics.Canvas;
-import android.graphics.Paint;
-import android.graphics.PorterDuff;
-import android.graphics.PorterDuffXfermode;
-import android.graphics.RectF;
-import android.util.AttributeSet;
-import android.util.TypedValue;
-import android.view.View;
-
-import com.android.settings.R;
-
-/**
- * Draws the lines at the corner of the inner frame.
- */
-public class QrDecorateView extends View {
- private static final float CORNER_STROKE_WIDTH = 4f; // 4dp
- private static final float CORNER_LINE_LENGTH = 264f; // 264dp
- private static final float CORNER_RADIUS = 16f; // 16dp
-
- final private int mCornerColor;
- final private int mFocusedCornerColor;
- final private int mBackgroundColor;
-
- final private Paint mStrokePaint;
- final private Paint mTransparentPaint;
- final private Paint mBackgroundPaint;
-
- final private float mRadius;
- final private float mInnerRidus;
-
- private Bitmap mMaskBitmap;
- private Canvas mMaskCanvas;
-
- private RectF mOuterFrame;
- private RectF mInnerFrame;
-
- private boolean mFocused;
-
- public QrDecorateView(Context context) {
- this(context, null);
- }
-
- public QrDecorateView(Context context, AttributeSet attrs) {
- this(context, attrs, 0);
- }
-
- public QrDecorateView(Context context, AttributeSet attrs, int defStyleAttr) {
- this(context, attrs, defStyleAttr, 0);
- }
-
- public QrDecorateView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
- super(context, attrs, defStyleAttr, defStyleRes);
-
- mFocused = false;
- mRadius = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, CORNER_RADIUS,
- getResources().getDisplayMetrics());
- // Inner radius needs to minus stroke width for keeping the width of border consistent.
- mInnerRidus = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
- CORNER_RADIUS - CORNER_STROKE_WIDTH, getResources().getDisplayMetrics());
-
- mCornerColor = context.getResources().getColor(R.color.qr_corner_line_color);
- mFocusedCornerColor = context.getResources().getColor(R.color.qr_focused_corner_line_color);
- mBackgroundColor = context.getResources().getColor(R.color.qr_background_color);
-
- mStrokePaint = new Paint();
- mStrokePaint.setAntiAlias(true);
-
- mTransparentPaint = new Paint();
- mTransparentPaint.setAntiAlias(true);
- mTransparentPaint.setColor(getResources().getColor(android.R.color.transparent));
- mTransparentPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
-
- mBackgroundPaint = new Paint();
- mBackgroundPaint.setColor(mBackgroundColor);
- }
-
- @Override
- protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
- super.onLayout(changed, left, top, right, bottom);
-
- if(mMaskBitmap == null) {
- mMaskBitmap = Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.ARGB_8888);
- mMaskCanvas = new Canvas(mMaskBitmap);
- }
-
- calculateFramePos();
- }
-
- @Override
- protected void onDraw(Canvas canvas) {
- // Set frame line color.
- mStrokePaint.setColor(mFocused ? mFocusedCornerColor : mCornerColor);
- // Draw background color.
- mMaskCanvas.drawColor(mBackgroundColor);
- // Draw outer corner.
- mMaskCanvas.drawRoundRect(mOuterFrame, mRadius, mRadius, mStrokePaint);
- // Draw inner transparent corner.
- mMaskCanvas.drawRoundRect(mInnerFrame, mInnerRidus, mInnerRidus, mTransparentPaint);
-
- canvas.drawBitmap(mMaskBitmap, 0, 0, mBackgroundPaint);
- super.onDraw(canvas);
- }
-
- private void calculateFramePos() {
- final int centralX = getWidth() / 2;
- final int centralY = getHeight() / 2;
- final float cornerLineLength = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
- CORNER_LINE_LENGTH, getResources().getDisplayMetrics()) / 2;
- final float strokeWidth = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
- CORNER_STROKE_WIDTH, getResources().getDisplayMetrics());
-
- mOuterFrame = new RectF(centralX - cornerLineLength, centralY - cornerLineLength,
- centralX + cornerLineLength, centralY + cornerLineLength);
- mInnerFrame = new RectF(mOuterFrame.left + strokeWidth, mOuterFrame.top + strokeWidth,
- mOuterFrame.right - strokeWidth, mOuterFrame.bottom - strokeWidth);
- }
-
- // Draws green lines if focused. Otherwise, draws white lines.
- public void setFocused(boolean focused) {
- mFocused = focused;
- invalidate();
- }
-}
diff --git a/src/com/android/settings/wifi/qrcode/QrYuvLuminanceSource.java b/src/com/android/settings/wifi/qrcode/QrYuvLuminanceSource.java
deleted file mode 100644
index 874a758..0000000
--- a/src/com/android/settings/wifi/qrcode/QrYuvLuminanceSource.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Copyright (C) 2018 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.wifi.qrcode;
-
-import com.google.zxing.LuminanceSource;
-
-/**
- * This helper class implements crop method to crop preview picture.
- */
-public class QrYuvLuminanceSource extends LuminanceSource {
-
- private byte[] mYuvData;
- private int mWidth;
- private int mHeight;
-
- public QrYuvLuminanceSource(byte[] yuvData, int width, int height) {
- super(width, height);
-
- mWidth = width;
- mHeight = height;
- mYuvData = yuvData;
- }
-
- @Override
- public boolean isCropSupported() {
- return true;
- }
-
- @Override
- public LuminanceSource crop(int left, int top, int crop_width, int crop_height) {
- final byte[] newImage = new byte[crop_width * crop_height];
- int inputOffset = top * mWidth + left;
-
- if (left + crop_width > mWidth || top + crop_height > mHeight) {
- throw new IllegalArgumentException("cropped rectangle does not fit within image data.");
- }
-
- for (int y = 0; y < crop_height; y++) {
- System.arraycopy(mYuvData, inputOffset, newImage, y * crop_width, crop_width);
- inputOffset += mWidth;
- }
- return new QrYuvLuminanceSource(newImage, crop_width, crop_height);
- }
-
- @Override
- public byte[] getRow(int y, byte[] row) {
- if (y < 0 || y >= mHeight) {
- throw new IllegalArgumentException("Requested row is outside the image: " + y);
- }
- if (row == null || row.length < mWidth) {
- row = new byte[mWidth];
- }
- System.arraycopy(mYuvData, y * mWidth, row, 0, mWidth);
- return row;
- }
-
- @Override
- public byte[] getMatrix() {
- return mYuvData;
- }
-}
diff --git a/tests/robotests/src/com/android/settings/wifi/qrcode/QrCameraTest.java b/tests/robotests/src/com/android/settings/wifi/qrcode/QrCameraTest.java
deleted file mode 100644
index de0df73..0000000
--- a/tests/robotests/src/com/android/settings/wifi/qrcode/QrCameraTest.java
+++ /dev/null
@@ -1,176 +0,0 @@
-/*
- * Copyright (C) 2018 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.wifi.qrcode;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import static org.mockito.ArgumentMatchers.anyInt;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import android.content.Context;
-import android.graphics.Bitmap;
-import android.graphics.Matrix;
-import android.graphics.Rect;
-import android.graphics.SurfaceTexture;
-import android.hardware.Camera;
-import android.hardware.Camera.Parameters;
-import android.hardware.Camera.Size;
-
-import com.google.zxing.BinaryBitmap;
-import com.google.zxing.LuminanceSource;
-import com.google.zxing.RGBLuminanceSource;
-import com.google.zxing.WriterException;
-import com.google.zxing.common.HybridBinarizer;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.robolectric.RobolectricTestRunner;
-import org.robolectric.RuntimeEnvironment;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
-
-@RunWith(RobolectricTestRunner.class)
-public class QrCameraTest {
-
- @Mock
- private SurfaceTexture mSurfaceTexture;
-
- private QrCamera mCamera;
- private Context mContext;
-
- private String mQrCode;
- CountDownLatch mCallbackSignal;
- private boolean mCameraCallbacked;
-
- private class ScannerTestCallback implements QrCamera.ScannerCallback {
- @Override
- public android.util.Size getViewSize() {
- return new android.util.Size(0, 0);
- }
-
- @Override
- public Rect getFramePosition(android.util.Size previewSize, int cameraOrientation) {
- return new Rect(0,0,0,0);
- }
-
- @Override
- public void handleSuccessfulResult(String qrCode) {
- mQrCode = qrCode;
- }
-
- @Override
- public void handleCameraFailure() {
- mCameraCallbacked = true;
- mCallbackSignal.countDown();
- }
-
- @Override
- public void setTransform(Matrix transform) {
- // Do nothing
- }
-
- @Override
- public boolean isValid(String qrCode) {
- return true;
- }
- }
-
- private ScannerTestCallback mScannerCallback;
-
- @Before
- public void setUp() {
- mContext = RuntimeEnvironment.application;
- mScannerCallback = new ScannerTestCallback();
- mCamera = new QrCamera(mContext, mScannerCallback);
- mSurfaceTexture = mock(SurfaceTexture.class);
- mQrCode = "";
- mCameraCallbacked = false;
- mCallbackSignal = null;
- }
-
- @Test
- public void testCamera_Init_Callback() throws InterruptedException {
- mCallbackSignal = new CountDownLatch(1);
- mCamera.start(mSurfaceTexture);
- mCallbackSignal.await(5000, TimeUnit.MILLISECONDS);
- assertThat(mCameraCallbacked).isTrue();
- }
-
- @Test
- public void testDecode_PictureCaptured_QrCodeCorrectValue() {
- final String googleUrl = "http://www.google.com";
-
- try {
- final Bitmap bmp = QrCodeGenerator.encodeQrCode(googleUrl, 320);
- final int[] intArray = new int[bmp.getWidth() * bmp.getHeight()];
- bmp.getPixels(intArray, 0, bmp.getWidth(), 0, 0, bmp.getWidth(), bmp.getHeight());
- LuminanceSource source = new RGBLuminanceSource(bmp.getWidth(), bmp.getHeight(),
- intArray);
- final BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
- mCamera.decodeImage(bitmap);
- bmp.recycle();
- } catch (WriterException e) {
- }
-
- assertThat(mQrCode).isEqualTo(googleUrl);
- }
-
- @Test
- public void testDecode_unicodePictureCaptured_QrCodeCorrectValue() {
- final String unicodeTest = "中文測試";
-
- try {
- final Bitmap bmp = QrCodeGenerator.encodeQrCode(unicodeTest, 320);
- final int[] intArray = new int[bmp.getWidth() * bmp.getHeight()];
- bmp.getPixels(intArray, 0, bmp.getWidth(), 0, 0, bmp.getWidth(), bmp.getHeight());
- LuminanceSource source = new RGBLuminanceSource(bmp.getWidth(), bmp.getHeight(),
- intArray);
- final BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
- mCamera.decodeImage(bitmap);
- bmp.recycle();
- } catch (WriterException e) {
- }
-
- assertThat(mQrCode).isEqualTo(unicodeTest);
- }
-
- @Test
- public void setCameraParameter_shouldSetParameters() {
- mCamera.mCamera = mock(Camera.class);
- Parameters parameters = mock(Camera.Parameters.class);
- Size size = mCamera.mCamera.new Size(1920, 1440);
- List<Camera.Size> sizes = new ArrayList<>(Arrays.asList(size));
- when(parameters.getPreviewSize()).thenReturn(size);
- when(parameters.getSupportedPreviewSizes()).thenReturn(sizes);
- when(parameters.getSupportedPictureSizes()).thenReturn(sizes);
- when(mCamera.mCamera.getParameters()).thenReturn(parameters);
-
- mCamera.setCameraParameter();
-
- verify(mCamera.mParameters).setPreviewSize(anyInt(), anyInt());
- verify(mCamera.mParameters).setPictureSize(anyInt(), anyInt());
- verify(mCamera.mCamera).setParameters(mCamera.mParameters);
- }
-}
diff --git a/tests/unit/src/com/android/settings/network/UiccSlotUtilTest.java b/tests/unit/src/com/android/settings/network/UiccSlotUtilTest.java
index 2cf9845..5aa73ea 100644
--- a/tests/unit/src/com/android/settings/network/UiccSlotUtilTest.java
+++ b/tests/unit/src/com/android/settings/network/UiccSlotUtilTest.java
@@ -92,6 +92,14 @@
assertThat(testSlot).isEqualTo(0);
}
+ @Test
+ public void getEsimSlotId_twoSimSlotsDeviceAndRemovableEsimIsSlot1_returnTheCorrectEsimSlot() {
+ when(mTelephonyManager.getUiccSlotsInfo()).thenReturn(
+ twoSimSlotsDeviceActivePsimActiveRemovableEsim());
+ int testSlot = UiccSlotUtil.getEsimSlotId(mContext);
+
+ assertThat(testSlot).isEqualTo(1);
+ }
@Test
public void getEsimSlotId_twoSimSlotsDeviceAndEsimIsSlot1_returnTheCorrectEsimSlot() {
@@ -729,6 +737,12 @@
createUiccSlotInfo(true, false, 1, true)};
}
+ private UiccSlotInfo[] twoSimSlotsDeviceActivePsimActiveRemovableEsim() {
+ return new UiccSlotInfo[]{
+ createUiccSlotInfo(false, true, 0, true),
+ createUiccSlotInfo(true, true, 1, true)};
+ }
+
private UiccSlotInfo[] twoSimSlotsDeviceActiveEsimActivePsim() {
return new UiccSlotInfo[]{
createUiccSlotInfo(true, false, 0, true),