Merge "Async load eid in SimEidPreferenceController" into main
diff --git a/aconfig/settings_connecteddevice_flag_declarations.aconfig b/aconfig/settings_connecteddevice_flag_declarations.aconfig
index 450fc0d..07aaecc 100644
--- a/aconfig/settings_connecteddevice_flag_declarations.aconfig
+++ b/aconfig/settings_connecteddevice_flag_declarations.aconfig
@@ -13,3 +13,10 @@
description: "Gates whether to enable LE audio sharing"
bug: "305620450"
}
+
+flag {
+ name: "enable_le_audio_qr_code_private_broadcast_sharing"
+ namespace: "pixel_cross_device_control"
+ description: "Gates whether to enable LE audio private broadcast sharing via QR code"
+ bug: "308368124"
+}
diff --git a/res/layout/accessibility_shortcut_secondary_action.xml b/res/layout/accessibility_shortcut_secondary_action.xml
index b3b81fe..80defdb 100644
--- a/res/layout/accessibility_shortcut_secondary_action.xml
+++ b/res/layout/accessibility_shortcut_secondary_action.xml
@@ -93,7 +93,7 @@
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="end|center_vertical"
- android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
+ android:paddingHorizontal="?android:attr/listPreferredItemPaddingEnd"
android:minWidth="58dp"
android:orientation="vertical" />
diff --git a/res/layout/preference_widget_switch_compat.xml b/res/layout/preference_widget_switch_compat.xml
new file mode 100644
index 0000000..e833171
--- /dev/null
+++ b/res/layout/preference_widget_switch_compat.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ Copyright (C) 2023 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.
+ -->
+
+<com.google.android.material.materialswitch.MaterialSwitch
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/switchWidget"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:background="@null"
+ android:clickable="false"
+ android:focusable="false"
+ android:theme="@style/Theme.Material3.DynamicColors.DayNight" />
diff --git a/res/values/strings.xml b/res/values/strings.xml
index ca69efa..ba56c53 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -295,6 +295,15 @@
<!-- Title for calls and alarms device on audio sharing page [CHAR LIMIT=none]-->
<string name="calls_and_alarms_device_title">Calls and alarms</string>
+ <!-- Title for audio streams preference category [CHAR LIMIT=none]-->
+ <string name="audio_sharing_streams_category_title">Connect to a LE audio stream</string>
+ <!-- Title for audio streams preference [CHAR LIMIT=none]-->
+ <string name="audio_sharing_streams_pref_title">Nearby audio streams</string>
+ <!-- Title for audio streams page [CHAR LIMIT=none]-->
+ <string name="audio_sharing_streams_title">Audio streams</string>
+ <!-- Summary for QR code scanning in audio streams page [CHAR LIMIT=none]-->
+ <string name="audio_sharing_streams_qr_code_summary">Connect to an audio stream using QR code</string>
+
<!-- Date & time settings screen title -->
<string name="date_and_time">Date & time</string>
diff --git a/res/xml/bluetooth_audio_sharing.xml b/res/xml/bluetooth_audio_sharing.xml
index bf7593a..86bb062 100644
--- a/res/xml/bluetooth_audio_sharing.xml
+++ b/res/xml/bluetooth_audio_sharing.xml
@@ -25,4 +25,18 @@
android:icon="@drawable/ic_audio_calls_and_alarms"
settings:controller="com.android.settings.connecteddevice.audiosharing.CallsAndAlarmsPreferenceController"
android:summary=""/>
+
+ <PreferenceCategory
+ android:key="audio_streams_settings_category"
+ android:title="@string/audio_sharing_streams_category_title"
+ settings:controller="com.android.settings.connecteddevice.audiosharing.AudioStreamsCategoryController" >
+
+ <Preference
+ android:key="audio_streams_settings"
+ android:fragment="com.android.settings.connecteddevice.audiosharing.AudioStreamsDashboardFragment"
+ android:title="@string/audio_sharing_streams_pref_title"
+ android:icon="@drawable/ic_chevron_right_24dp" />
+
+ </PreferenceCategory>
+
</PreferenceScreen>
\ No newline at end of file
diff --git a/res/xml/bluetooth_audio_streams.xml b/res/xml/bluetooth_audio_streams.xml
new file mode 100644
index 0000000..9d05a06
--- /dev/null
+++ b/res/xml/bluetooth_audio_streams.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ Copyright (C) 2023 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"
+ android:title="@string/audio_sharing_streams_title">
+
+ <Preference
+ android:key="audio_streams_scan_qr_code"
+ android:title="@string/bluetooth_find_broadcast_button_scan"
+ android:icon="@drawable/ic_add_24dp"
+ android:summary="@string/audio_sharing_streams_qr_code_summary"/>
+
+</PreferenceScreen>
\ No newline at end of file
diff --git a/src/com/android/settings/accessibility/ShortcutPreference.java b/src/com/android/settings/accessibility/ShortcutPreference.java
index 4b6868e..a04f8f4 100644
--- a/src/com/android/settings/accessibility/ShortcutPreference.java
+++ b/src/com/android/settings/accessibility/ShortcutPreference.java
@@ -62,7 +62,7 @@
ShortcutPreference(Context context, AttributeSet attrs) {
super(context, attrs);
setLayoutResource(R.layout.accessibility_shortcut_secondary_action);
- setWidgetLayoutResource(com.android.settingslib.R.layout.preference_widget_primary_switch);
+ setWidgetLayoutResource(androidx.preference.R.layout.preference_widget_switch_compat);
setIconSpaceReserved(false);
// Treat onSettingsClicked as this preference's click.
setOnPreferenceClickListener(preference -> {
@@ -89,7 +89,7 @@
}
CompoundButton switchWidget =
- holder.itemView.findViewById(com.android.settingslib.R.id.switchWidget);
+ holder.itemView.findViewById(androidx.preference.R.id.switchWidget);
if (switchWidget != null) {
// Consumes move events to ignore drag actions.
switchWidget.setOnTouchListener((v, event) -> {
diff --git a/src/com/android/settings/connecteddevice/audiosharing/AudioStreamsCategoryController.java b/src/com/android/settings/connecteddevice/audiosharing/AudioStreamsCategoryController.java
new file mode 100644
index 0000000..e25a6ab
--- /dev/null
+++ b/src/com/android/settings/connecteddevice/audiosharing/AudioStreamsCategoryController.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2023 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.connecteddevice.audiosharing;
+
+import android.content.Context;
+
+import com.android.settings.flags.Flags;
+import com.android.settings.widget.PreferenceCategoryController;
+
+public class AudioStreamsCategoryController extends PreferenceCategoryController {
+
+ public AudioStreamsCategoryController(Context context, String key) {
+ super(context, key);
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ return Flags.enableLeAudioQrCodePrivateBroadcastSharing() ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
+ }
+}
diff --git a/src/com/android/settings/connecteddevice/audiosharing/AudioStreamsDashboardFragment.java b/src/com/android/settings/connecteddevice/audiosharing/AudioStreamsDashboardFragment.java
new file mode 100644
index 0000000..40a8b29
--- /dev/null
+++ b/src/com/android/settings/connecteddevice/audiosharing/AudioStreamsDashboardFragment.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2023 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.connecteddevice.audiosharing;
+
+import android.content.Context;
+import android.os.Bundle;
+
+import com.android.settings.R;
+import com.android.settings.dashboard.DashboardFragment;
+
+public class AudioStreamsDashboardFragment extends DashboardFragment {
+ private static final String TAG = "AudioStreamsDashboardFrag";
+
+ public AudioStreamsDashboardFragment() {
+ super();
+ }
+
+ @Override
+ public int getMetricsCategory() {
+ // TODO: update category id.
+ return 0;
+ }
+
+ @Override
+ protected String getLogTag() {
+ return TAG;
+ }
+
+ @Override
+ public int getHelpResource() {
+ return R.string.help_url_audio_sharing;
+ }
+
+ @Override
+ protected int getPreferenceScreenResId() {
+ return R.xml.bluetooth_audio_streams;
+ }
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ }
+
+ @Override
+ public void onAttach(Context context) {
+ super.onAttach(context);
+ }
+
+ @Override
+ public void onActivityCreated(Bundle savedInstanceState) {
+ super.onActivityCreated(savedInstanceState);
+ }
+}
diff --git a/src/com/android/settings/network/telephony/MmsMessagePreferenceController.java b/src/com/android/settings/network/telephony/MmsMessagePreferenceController.java
deleted file mode 100644
index 8f59f0e..0000000
--- a/src/com/android/settings/network/telephony/MmsMessagePreferenceController.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * 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.network.telephony;
-
-import android.content.Context;
-import android.os.Handler;
-import android.os.Looper;
-import android.telephony.SubscriptionManager;
-import android.telephony.TelephonyManager;
-import android.telephony.data.ApnSetting;
-
-import androidx.preference.Preference;
-import androidx.preference.PreferenceScreen;
-
-import com.android.settings.network.MobileDataContentObserver;
-import com.android.settingslib.core.lifecycle.LifecycleObserver;
-import com.android.settingslib.core.lifecycle.events.OnStart;
-import com.android.settingslib.core.lifecycle.events.OnStop;
-
-/**
- * Preference controller for "MMS messages"
- */
-public class MmsMessagePreferenceController extends TelephonyTogglePreferenceController implements
- LifecycleObserver, OnStart, OnStop {
- private TelephonyManager mTelephonyManager;
- private MobileDataContentObserver mMobileDataContentObserver;
- private PreferenceScreen mScreen;
- private Preference mPreference;
-
- public MmsMessagePreferenceController(Context context, String key) {
- super(context, key);
- mMobileDataContentObserver = new MobileDataContentObserver(
- new Handler(Looper.getMainLooper()));
- mMobileDataContentObserver.setOnMobileDataChangedListener(() -> refreshPreference());
- }
-
- @Override
- public int getAvailabilityStatus(int subId) {
- final TelephonyManager telephonyManager = mContext.getSystemService(TelephonyManager.class)
- .createForSubscriptionId(subId);
- return (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID
- && !telephonyManager.isDataEnabled()
- && telephonyManager.isApnMetered(ApnSetting.TYPE_MMS))
- ? AVAILABLE
- : CONDITIONALLY_UNAVAILABLE;
- }
-
- @Override
- public void onStart() {
- if (mSubId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
- mMobileDataContentObserver.register(mContext, mSubId);
- updateState(mPreference);
- }
- }
-
- @Override
- public void onStop() {
- if (mSubId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
- mMobileDataContentObserver.unRegister(mContext);
- }
- }
-
- @Override
- public void displayPreference(PreferenceScreen screen) {
- super.displayPreference(screen);
- mScreen = screen;
- mPreference = screen.findPreference(getPreferenceKey());
- }
-
-
- public void init(int subId) {
- mSubId = subId;
- mTelephonyManager = mContext.getSystemService(TelephonyManager.class)
- .createForSubscriptionId(mSubId);
- }
-
- @Override
- public boolean setChecked(boolean isChecked) {
- if (mTelephonyManager == null) {
- return false;
- }
- mTelephonyManager.setMobileDataPolicyEnabled(
- TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED, isChecked);
- return true;
- }
-
-
- @Override
- public boolean isChecked() {
- return mTelephonyManager != null && mTelephonyManager.isDataEnabledForApn(
- ApnSetting.TYPE_MMS);
- }
-
- private void refreshPreference() {
- if (mScreen != null) {
- super.displayPreference(mScreen);
- }
- }
-}
diff --git a/src/com/android/settings/network/telephony/MmsMessagePreferenceController.kt b/src/com/android/settings/network/telephony/MmsMessagePreferenceController.kt
new file mode 100644
index 0000000..23a9738
--- /dev/null
+++ b/src/com/android/settings/network/telephony/MmsMessagePreferenceController.kt
@@ -0,0 +1,87 @@
+/*
+ * Copyright (C) 2023 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.network.telephony
+
+import android.content.Context
+import android.os.Handler
+import android.os.Looper
+import android.telephony.SubscriptionManager
+import android.telephony.TelephonyManager
+import android.telephony.data.ApnSetting
+import androidx.lifecycle.DefaultLifecycleObserver
+import androidx.lifecycle.LifecycleOwner
+import androidx.preference.PreferenceScreen
+import com.android.settings.network.MobileDataContentObserver
+
+/**
+ * Preference controller for "MMS messages"
+ */
+class MmsMessagePreferenceController(context: Context, key: String) :
+ TelephonyTogglePreferenceController(context, key), DefaultLifecycleObserver {
+
+ private lateinit var telephonyManager: TelephonyManager
+
+ private var preferenceScreen: PreferenceScreen? = null
+
+ private val mobileDataContentObserver =
+ MobileDataContentObserver(Handler(Looper.getMainLooper())).apply {
+ setOnMobileDataChangedListener {
+ preferenceScreen?.let { super.displayPreference(it) }
+ }
+ }
+
+ fun init(subId: Int) {
+ mSubId = subId
+ telephonyManager = mContext.getSystemService(TelephonyManager::class.java)!!
+ .createForSubscriptionId(subId)
+ }
+
+ override fun getAvailabilityStatus(subId: Int) =
+ if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID &&
+ !telephonyManager.isDataEnabled &&
+ telephonyManager.isApnMetered(ApnSetting.TYPE_MMS)
+ ) AVAILABLE else CONDITIONALLY_UNAVAILABLE
+
+ override fun onStart(owner: LifecycleOwner) {
+ if (mSubId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
+ mobileDataContentObserver.register(mContext, mSubId)
+ }
+ }
+
+ override fun onStop(owner: LifecycleOwner) {
+ if (mSubId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
+ mobileDataContentObserver.unRegister(mContext)
+ }
+ }
+
+ override fun displayPreference(screen: PreferenceScreen) {
+ super.displayPreference(screen)
+ preferenceScreen = screen
+ }
+
+ override fun isChecked(): Boolean = telephonyManager.isMobileDataPolicyEnabled(
+ TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED
+ )
+
+ override fun setChecked(isChecked: Boolean): Boolean {
+ telephonyManager.setMobileDataPolicyEnabled(
+ TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED,
+ isChecked,
+ )
+ return true
+ }
+}
diff --git a/src/com/android/settings/password/ChooseLockGeneric.java b/src/com/android/settings/password/ChooseLockGeneric.java
index 714f3ee..0bf1255 100644
--- a/src/com/android/settings/password/ChooseLockGeneric.java
+++ b/src/com/android/settings/password/ChooseLockGeneric.java
@@ -201,14 +201,6 @@
}
@Override
- public void onPause() {
- super.onPause();
- if (!getActivity().isChangingConfigurations() && !mWaitingForConfirmation) {
- finish();
- }
- }
-
- @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final Activity activity = getActivity();
diff --git a/src/com/android/settings/password/ChooseLockPassword.java b/src/com/android/settings/password/ChooseLockPassword.java
index e74a2ff..800adb0 100644
--- a/src/com/android/settings/password/ChooseLockPassword.java
+++ b/src/com/android/settings/password/ChooseLockPassword.java
@@ -219,13 +219,6 @@
findViewById(R.id.content_parent).setFitsSystemWindows(false);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
}
- @Override
- public void onPause() {
- super.onPause();
- if (!isChangingConfigurations()) {
- finish();
- }
- }
public static class ChooseLockPasswordFragment extends InstrumentedFragment
implements OnEditorActionListener, TextWatcher, SaveAndFinishWorker.Listener {
diff --git a/src/com/android/settings/password/ChooseLockPattern.java b/src/com/android/settings/password/ChooseLockPattern.java
index f0c432e..20d1e7d 100644
--- a/src/com/android/settings/password/ChooseLockPattern.java
+++ b/src/com/android/settings/password/ChooseLockPattern.java
@@ -98,14 +98,6 @@
return modIntent;
}
- @Override
- public void onPause() {
- super.onPause();
- if (!isChangingConfigurations()) {
- finish();
- }
- }
-
public static class IntentBuilder {
private final Intent mIntent;
diff --git a/tests/robotests/src/com/android/settings/password/ChooseLockGenericTest.java b/tests/robotests/src/com/android/settings/password/ChooseLockGenericTest.java
index a099a39..e625827 100644
--- a/tests/robotests/src/com/android/settings/password/ChooseLockGenericTest.java
+++ b/tests/robotests/src/com/android/settings/password/ChooseLockGenericTest.java
@@ -54,9 +54,7 @@
import android.provider.Settings.Global;
import androidx.annotation.Nullable;
-import androidx.lifecycle.Lifecycle;
import androidx.preference.Preference;
-import androidx.test.core.app.ActivityScenario;
import com.android.internal.widget.LockPatternUtils;
import com.android.internal.widget.LockscreenCredential;
@@ -615,29 +613,15 @@
mFragment.getString(R.string.face_unlock_set_unlock_password));
}
- @Test
- public void activity_dismisses_InBackground() {
- ActivityScenario<ChooseLockPassword> scenario =
- ActivityScenario.launchActivityForResult(getChooseLockGenericIntent(null));
- scenario.moveToState(Lifecycle.State.RESUMED);
- scenario.moveToState(Lifecycle.State.CREATED);
- assertThat(scenario.getResult()).isNotNull();
- }
-
private void initActivity(@Nullable Intent intent) {
- final Intent theIntent = getChooseLockGenericIntent(intent);
- // TODO(b/275023433) This presents the activity from being made 'visible` is workaround
- mActivity = Robolectric.buildActivity(ChooseLockGeneric.InternalActivity.class, theIntent)
- .create().start().postCreate(null).resume().get();
- mActivity.getSupportFragmentManager().beginTransaction().add(mFragment, null).commitNow();
- }
-
- private Intent getChooseLockGenericIntent(@Nullable Intent intent) {
if (intent == null) {
intent = new Intent();
}
intent.putExtra(ChooseLockGeneric.CONFIRM_CREDENTIALS, false);
- return intent;
+ // TODO(b/275023433) This presents the activity from being made 'visible` is workaround
+ mActivity = Robolectric.buildActivity(ChooseLockGeneric.InternalActivity.class, intent)
+ .create().start().postCreate(null).resume().get();
+ mActivity.getSupportFragmentManager().beginTransaction().add(mFragment, null).commitNow();
}
private static String capitalize(final String input) {
diff --git a/tests/robotests/src/com/android/settings/password/ChooseLockPasswordTest.java b/tests/robotests/src/com/android/settings/password/ChooseLockPasswordTest.java
index ed8179b..dea936d 100644
--- a/tests/robotests/src/com/android/settings/password/ChooseLockPasswordTest.java
+++ b/tests/robotests/src/com/android/settings/password/ChooseLockPasswordTest.java
@@ -47,9 +47,6 @@
import android.widget.CheckBox;
import android.widget.TextView;
-import androidx.lifecycle.Lifecycle;
-import androidx.test.core.app.ActivityScenario;
-
import com.android.internal.widget.LockscreenCredential;
import com.android.settings.R;
import com.android.settings.password.ChooseLockPassword.ChooseLockPasswordFragment;
@@ -518,31 +515,16 @@
assertThat(pinAutoConfirmOption.isChecked()).isFalse();
}
- @Test
- public void activity_dismisses_InBackground() {
- ActivityScenario<ChooseLockPassword> scenario =
- ActivityScenario.launchActivityForResult(getLockPasswordIntent());
- scenario.moveToState(Lifecycle.State.RESUMED);
- scenario.moveToState(Lifecycle.State.CREATED);
- assertThat(scenario.getResult()).isNotNull();
- }
-
private ChooseLockPassword setupActivityWithPinTypeAndDefaultPolicy() {
PasswordPolicy policy = new PasswordPolicy();
policy.quality = PASSWORD_QUALITY_UNSPECIFIED;
return buildChooseLockPasswordActivity(
- getLockPasswordIntent());
- }
-
- private Intent getLockPasswordIntent() {
- PasswordPolicy policy = new PasswordPolicy();
- policy.quality = PASSWORD_QUALITY_UNSPECIFIED;
- return new IntentBuilder(application)
- .setUserId(UserHandle.myUserId())
- .setPasswordType(PASSWORD_QUALITY_NUMERIC)
- .setPasswordRequirement(PASSWORD_COMPLEXITY_NONE, policy.getMinMetrics())
- .build();
+ new IntentBuilder(application)
+ .setUserId(UserHandle.myUserId())
+ .setPasswordType(PASSWORD_QUALITY_NUMERIC)
+ .setPasswordRequirement(PASSWORD_COMPLEXITY_NONE, policy.getMinMetrics())
+ .build());
}
private ChooseLockPassword buildChooseLockPasswordActivity(Intent intent) {
diff --git a/tests/robotests/src/com/android/settings/password/ChooseLockPatternTest.java b/tests/robotests/src/com/android/settings/password/ChooseLockPatternTest.java
index da12ee4..7715c62 100644
--- a/tests/robotests/src/com/android/settings/password/ChooseLockPatternTest.java
+++ b/tests/robotests/src/com/android/settings/password/ChooseLockPatternTest.java
@@ -30,9 +30,6 @@
import android.os.UserHandle;
import android.view.View;
-import androidx.lifecycle.Lifecycle;
-import androidx.test.core.app.ActivityScenario;
-
import com.android.internal.widget.LockPatternUtils;
import com.android.internal.widget.LockscreenCredential;
import com.android.settings.R;
@@ -140,29 +137,16 @@
R.string.lockpassword_draw_your_pattern_again_header));
}
- @Test
- public void activity_dismisses_InBackground() {
- ActivityScenario<ChooseLockPattern> scenario =
- ActivityScenario.launchActivityForResult(getLockPatternIntent(false));
- scenario.moveToState(Lifecycle.State.RESUMED);
- scenario.moveToState(Lifecycle.State.CREATED);
- assertThat(scenario.getResult()).isNotNull();
- }
-
private ChooseLockPattern createActivity(boolean addFingerprintExtra) {
return Robolectric.buildActivity(
- ChooseLockPattern.class,
- getLockPatternIntent(addFingerprintExtra))
+ ChooseLockPattern.class,
+ new IntentBuilder(application)
+ .setUserId(UserHandle.myUserId())
+ .setForFingerprint(addFingerprintExtra)
+ .build())
.setup().get();
}
- private Intent getLockPatternIntent(boolean addFingerprintExtra) {
- return new IntentBuilder(application)
- .setUserId(UserHandle.myUserId())
- .setForFingerprint(addFingerprintExtra)
- .build();
- }
-
private LockscreenCredential createPattern(String patternString) {
return LockscreenCredential.createPattern(LockPatternUtils.byteArrayToPattern(
patternString.getBytes()));
diff --git a/tests/spa_unit/src/com/android/settings/network/telephony/MmsMessagePreferenceControllerTest.kt b/tests/spa_unit/src/com/android/settings/network/telephony/MmsMessagePreferenceControllerTest.kt
new file mode 100644
index 0000000..33a8575
--- /dev/null
+++ b/tests/spa_unit/src/com/android/settings/network/telephony/MmsMessagePreferenceControllerTest.kt
@@ -0,0 +1,142 @@
+/*
+ * Copyright (C) 2023 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.network.telephony
+
+import android.content.Context
+import android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID
+import android.telephony.TelephonyManager
+import android.telephony.data.ApnSetting
+import androidx.test.core.app.ApplicationProvider
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import com.android.settings.core.BasePreferenceController.AVAILABLE
+import com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE
+import com.google.common.truth.Truth.assertThat
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.mockito.kotlin.any
+import org.mockito.kotlin.doReturn
+import org.mockito.kotlin.mock
+import org.mockito.kotlin.spy
+import org.mockito.kotlin.stub
+import org.mockito.kotlin.verify
+
+@RunWith(AndroidJUnit4::class)
+class MmsMessagePreferenceControllerTest {
+ private val mockTelephonyManager: TelephonyManager = mock<TelephonyManager> {
+ on { createForSubscriptionId(any()) } doReturn mock
+ }
+
+ private var context: Context = spy(ApplicationProvider.getApplicationContext()) {
+ on { getSystemService(TelephonyManager::class.java) } doReturn mockTelephonyManager
+ }
+
+ private val controller = MmsMessagePreferenceController(context, KEY).apply {
+ init(SUB_ID)
+ }
+
+ @Test
+ fun getAvailabilityStatus_invalidSubscription_returnUnavailable() {
+ controller.init(INVALID_SUBSCRIPTION_ID)
+
+ val availabilityStatus = controller.getAvailabilityStatus(INVALID_SUBSCRIPTION_ID)
+
+ assertThat(availabilityStatus).isEqualTo(CONDITIONALLY_UNAVAILABLE)
+ }
+
+ @Test
+ fun getAvailabilityStatus_mobileDataOn_returnUnavailable() {
+ mockTelephonyManager.stub {
+ on { isDataEnabled } doReturn true
+ }
+
+ val availabilityStatus = controller.getAvailabilityStatus(SUB_ID)
+
+ assertThat(availabilityStatus).isEqualTo(CONDITIONALLY_UNAVAILABLE)
+ }
+
+ @Test
+ fun getAvailabilityStatus_meteredOff_returnUnavailable() {
+ mockTelephonyManager.stub {
+ on { isApnMetered(ApnSetting.TYPE_MMS) } doReturn false
+ }
+
+ val availabilityStatus = controller.getAvailabilityStatus(SUB_ID)
+
+ assertThat(availabilityStatus).isEqualTo(CONDITIONALLY_UNAVAILABLE)
+ }
+
+ @Test
+ fun getAvailabilityStatus_mobileDataOffWithValidSubId_returnAvailable() {
+ mockTelephonyManager.stub {
+ on { isDataEnabled } doReturn false
+ on { isApnMetered(ApnSetting.TYPE_MMS) } doReturn true
+ }
+
+ val availabilityStatus = controller.getAvailabilityStatus(SUB_ID)
+
+ assertThat(availabilityStatus).isEqualTo(AVAILABLE)
+ }
+
+ @Test
+ fun isChecked_whenMmsNotAlwaysAllowed_returnFalse() {
+ mockTelephonyManager.stub {
+ on {
+ isMobileDataPolicyEnabled(TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED)
+ } doReturn false
+ }
+
+ val isChecked = controller.isChecked()
+
+ assertThat(isChecked).isFalse()
+ }
+
+ @Test
+ fun isChecked_whenMmsAlwaysAllowed_returnTrue() {
+ mockTelephonyManager.stub {
+ on {
+ isMobileDataPolicyEnabled(TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED)
+ } doReturn true
+ }
+
+ val isChecked = controller.isChecked()
+
+ assertThat(isChecked).isTrue()
+ }
+
+ @Test
+ fun setChecked_setTrue_setDataIntoSubscriptionManager() {
+ controller.setChecked(true)
+
+ verify(mockTelephonyManager).setMobileDataPolicyEnabled(
+ TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED, true
+ )
+ }
+
+ @Test
+ fun setChecked_setFalse_setDataIntoSubscriptionManager() {
+ controller.setChecked(false)
+
+ verify(mockTelephonyManager).setMobileDataPolicyEnabled(
+ TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED, false
+ )
+ }
+
+ private companion object {
+ const val KEY = "mms_message"
+ const val SUB_ID = 2
+ }
+}
diff --git a/tests/unit/src/com/android/settings/network/telephony/MmsMessagePreferenceControllerTest.java b/tests/unit/src/com/android/settings/network/telephony/MmsMessagePreferenceControllerTest.java
deleted file mode 100644
index 127cdfd..0000000
--- a/tests/unit/src/com/android/settings/network/telephony/MmsMessagePreferenceControllerTest.java
+++ /dev/null
@@ -1,142 +0,0 @@
-/*
- * Copyright (C) 2020 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.network.telephony;
-
-import static com.android.settings.core.BasePreferenceController.AVAILABLE;
-import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import static org.mockito.ArgumentMatchers.anyBoolean;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import android.content.Context;
-import android.os.Looper;
-import android.telephony.SubscriptionManager;
-import android.telephony.TelephonyManager;
-import android.telephony.data.ApnSetting;
-
-import androidx.preference.PreferenceManager;
-import androidx.preference.PreferenceScreen;
-import androidx.preference.SwitchPreference;
-import androidx.test.core.app.ApplicationProvider;
-import androidx.test.ext.junit.runners.AndroidJUnit4;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-
-@RunWith(AndroidJUnit4.class)
-public class MmsMessagePreferenceControllerTest {
- private static final int SUB_ID = 2;
-
- @Mock
- private TelephonyManager mTelephonyManager;
- @Mock
- private SubscriptionManager mSubscriptionManager;
-
- private MmsMessagePreferenceController mController;
- private SwitchPreference mPreference;
- private Context mContext;
-
- @Before
- public void setUp() {
- MockitoAnnotations.initMocks(this);
-
- mContext = spy(ApplicationProvider.getApplicationContext());
- when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager);
- when(mContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mTelephonyManager);
- when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubscriptionManager);
- when(mTelephonyManager.createForSubscriptionId(SUB_ID)).thenReturn(mTelephonyManager);
-
- mPreference = spy(new SwitchPreference(mContext));
- mController = new MmsMessagePreferenceController(mContext, "mms_message");
- mController.init(SUB_ID);
- mPreference.setKey(mController.getPreferenceKey());
- }
-
- @Test
- public void getAvailabilityStatus_invalidSubscription_returnUnavailable() {
- mController.init(SubscriptionManager.INVALID_SUBSCRIPTION_ID);
-
- assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
- }
-
- @Test
- public void getAvailabilityStatus_mobileDataOn_returnUnavailable() {
- when(mTelephonyManager.isDataEnabled()).thenReturn(true);
-
- assertThat(mController.getAvailabilityStatus(SUB_ID)).isEqualTo(CONDITIONALLY_UNAVAILABLE);
- }
-
- @Test
- public void getAvailabilityStatus_meteredOff_returnUnavailable() {
- when(mTelephonyManager.isApnMetered(ApnSetting.TYPE_MMS)).thenReturn(false);
-
- assertThat(mController.getAvailabilityStatus(SUB_ID)).isEqualTo(CONDITIONALLY_UNAVAILABLE);
- }
-
- @Test
- public void getAvailabilityStatus_mobileDataOffWithValidSubId_returnAvailable() {
- mController.init(SUB_ID);
- when(mTelephonyManager.isDataEnabled()).thenReturn(false);
- when(mTelephonyManager.isApnMetered(ApnSetting.TYPE_MMS)).thenReturn(true);
-
- assertThat(mController.getAvailabilityStatus(SUB_ID)).isEqualTo(AVAILABLE);
- }
-
- @Test
- public void isChecked_returnDataFromTelephonyManager() {
- when(mTelephonyManager.isDataEnabledForApn(ApnSetting.TYPE_MMS)).thenReturn(false);
- assertThat(mController.isChecked()).isFalse();
-
- when(mTelephonyManager.isDataEnabledForApn(ApnSetting.TYPE_MMS)).thenReturn(true);
- assertThat(mController.isChecked()).isTrue();
- }
-
- @Test
- public void setChecked_setDataIntoSubscriptionManager() {
- mController.setChecked(true);
- verify(mTelephonyManager).setMobileDataPolicyEnabled(
- TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED, true);
-
- mController.setChecked(false);
- verify(mTelephonyManager).setMobileDataPolicyEnabled(
- TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED, false);
- }
-
- @Test
- public void onStart_updatePreferenceUiState() {
- if (Looper.myLooper() == null) {
- Looper.prepare();
- }
- PreferenceManager preferenceManager = new PreferenceManager(mContext);
- PreferenceScreen preferenceScreen = preferenceManager.createPreferenceScreen(mContext);
- preferenceScreen.addPreference(mPreference);
- mController.displayPreference(preferenceScreen);
-
- mController.onStart();
-
- // First is preference initialization, and second is in onStart();
- verify(mPreference, times(2)).setChecked(anyBoolean());
- }
-}