Snap for 10255078 from 4834abe241 to udc-qpr1-release

Change-Id: Ia4f2539b0b2f958d592945de991052f0b3ef487f
This commit is contained in:
Android Build Coastguard Worker
2023-06-03 05:23:28 +00:00
15 changed files with 199 additions and 74 deletions

View File

@@ -23,59 +23,46 @@
android:icon="@drawable/ic_scan_32dp" android:icon="@drawable/ic_scan_32dp"
app:sudDescriptionText="@string/wifi_dpp_scan_qr_code_join_unknown_network"> app:sudDescriptionText="@string/wifi_dpp_scan_qr_code_join_unknown_network">
<LinearLayout <androidx.constraintlayout.widget.ConstraintLayout
style="@style/SudContentFrame" style="@style/SudContentFrame"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent">
android:orientation="vertical"
android:gravity="center_horizontal">
<LinearLayout <FrameLayout
android:layout_width="match_parent" android:id="@+id/frame_layout"
android:layout_height="match_parent" android:layout_width="0dp"
android:gravity="center" android:layout_height="0dp"
android:orientation="vertical"> app:layout_constraintBottom_toTopOf="@id/error_message"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHeight_max="@dimen/qrcode_preview_size"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_max="@dimen/qrcode_preview_size">
<androidx.constraintlayout.widget.ConstraintLayout <TextureView
android:id="@+id/preview_view"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent" />
android:maxWidth="@dimen/qrcode_preview_size"
android:maxHeight="@dimen/qrcode_preview_size">
<FrameLayout <com.android.settingslib.qrcode.QrDecorateView
android:layout_width="0dp" android:id="@+id/decorate_view"
android:layout_height="0dp" android:layout_width="match_parent"
app:layout_constraintDimensionRatio="1:1" android:layout_height="match_parent" />
app:layout_constraintTop_toTopOf="parent" </FrameLayout>
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:clipChildren="true">
<TextureView
android:id="@+id/preview_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<com.android.settingslib.qrcode.QrDecorateView
android:id="@+id/decorate_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</FrameLayout>
</androidx.constraintlayout.widget.ConstraintLayout> <TextView
android:id="@+id/error_message"
<TextView style="@style/TextAppearance.ErrorText"
android:id="@+id/error_message" android:layout_width="wrap_content"
style="@style/TextAppearance.ErrorText" android:layout_height="wrap_content"
android:layout_width="wrap_content" android:layout_marginVertical="16dp"
android:layout_height="wrap_content" android:visibility="invisible"
android:layout_marginTop="16dp" app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginStart="?attr/sudMarginStart" app:layout_constraintEnd_toEndOf="parent"
android:layout_marginEnd="?attr/sudMarginEnd" app:layout_constraintStart_toStartOf="parent"
android:textAlignment="center" app:layout_constraintTop_toBottomOf="@id/frame_layout" />
android:visibility="invisible"/> </androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
</LinearLayout>
</com.google.android.setupdesign.GlifLayout> </com.google.android.setupdesign.GlifLayout>

View File

@@ -3020,8 +3020,6 @@
<string name="reset_bluetooth_wifi_complete_toast">Bluetooth &amp; Wi\u2011Fi have been reset</string> <string name="reset_bluetooth_wifi_complete_toast">Bluetooth &amp; Wi\u2011Fi have been reset</string>
<!-- Erase Euicc --> <!-- Erase Euicc -->
<!-- Confirmation button of dialog to confirm resetting user's app preferences [CHAR LIMIT=NONE] -->
<string name="erase_euicc_data_button">Erase</string>
<!-- Erase Euicc dialog and SD card & phone storage settings screen, title for the menu option and checkbox to let user decide whether erase eSIM data together [CHAR LIMIT=50] --> <!-- Erase Euicc dialog and SD card & phone storage settings screen, title for the menu option and checkbox to let user decide whether erase eSIM data together [CHAR LIMIT=50] -->
<string name="reset_esim_title">Erase eSIMs</string> <string name="reset_esim_title">Erase eSIMs</string>
<!-- Erase Euicc dialog and SD card & phone storage settings screen, message for the checkbox to let user decide whether erase eSIM data together [CHAR LIMIT=NONE] --> <!-- Erase Euicc dialog and SD card & phone storage settings screen, message for the checkbox to let user decide whether erase eSIM data together [CHAR LIMIT=NONE] -->
@@ -10189,8 +10187,7 @@
<!-- Label explaining that the app installed by credit provider can be uninstalled. [CHAR LIMIT=60]--> <!-- Label explaining that the app installed by credit provider can be uninstalled. [CHAR LIMIT=60]-->
<string name="financed_privacy_uninstall_creditor_app">You can uninstall the creditor app</string> <string name="financed_privacy_uninstall_creditor_app">You can uninstall the creditor app</string>
<!-- Title of setting on security settings screen on a device provisioned by Device Lock. This will take the user to a screen in Device Lock with information about what a device provider can control and their impact on the user's privacy. Shown on Device Lock provisioned devices only. [CHAR LIMIT=NONE] --> <!-- Title of setting on security settings screen on a device provisioned by Device Lock. This will take the user to a screen in Device Lock with information about what a device provider can control and their impact on the user's privacy. Shown on Device Lock provisioned devices only. [CHAR LIMIT=NONE] -->
<!-- TODO(b/282040794): Update the title --> <string name="financed_device_info">Financed device info</string>
<string name="device_lock_info">Device Lock</string>
<!-- Strings for displaying which applications were set as default for specific actions. --> <!-- Strings for displaying which applications were set as default for specific actions. -->
<!-- Title for the apps that have been set as default handlers of camera-related intents. [CHAR LIMIT=30] --> <!-- Title for the apps that have been set as default handlers of camera-related intents. [CHAR LIMIT=30] -->
<string name="default_camera_app_title">{count, plural, <string name="default_camera_app_title">{count, plural,

View File

@@ -132,6 +132,8 @@
<item name="android:windowSoftInputMode">adjustResize</item> <item name="android:windowSoftInputMode">adjustResize</item>
<item name="android:clipToPadding">true</item> <item name="android:clipToPadding">true</item>
<item name="android:clipChildren">true</item> <item name="android:clipChildren">true</item>
<item name="android:textDirection">locale</item>
<item name="android:layoutDirection">locale</item>
<!-- Redefine the ActionBar style for contentInsetStart --> <!-- Redefine the ActionBar style for contentInsetStart -->
<item name="android:actionBarStyle">@style/Widget.ActionBar</item> <item name="android:actionBarStyle">@style/Widget.ActionBar</item>

View File

@@ -147,8 +147,8 @@
settings:controller="com.android.settings.enterprise.FinancedPrivacyPreferenceController"/> settings:controller="com.android.settings.enterprise.FinancedPrivacyPreferenceController"/>
<Preference <Preference
android:key="device_lock_info" android:key="financed_device_info"
android:title="@string/device_lock_info" android:title="@string/financed_device_info"
android:summary="@string/summary_placeholder" android:summary="@string/summary_placeholder"
settings:controller="com.android.settings.devicelock.DeviceLockPreferenceController"> settings:controller="com.android.settings.devicelock.DeviceLockPreferenceController">
<intent android:action="com.android.devicelockcontroller.action.DEVICE_INFO_SETTINGS"/> <intent android:action="com.android.devicelockcontroller.action.DEVICE_INFO_SETTINGS"/>

View File

@@ -59,8 +59,8 @@
settings:controller="com.android.settings.enterprise.FinancedPrivacyPreferenceController"/> settings:controller="com.android.settings.enterprise.FinancedPrivacyPreferenceController"/>
<Preference <Preference
android:key="device_lock_info" android:key="financed_device_info"
android:title="@string/device_lock_info" android:title="@string/financed_device_info"
android:summary="@string/summary_placeholder" android:summary="@string/summary_placeholder"
settings:controller="com.android.settings.devicelock.DeviceLockPreferenceController"> settings:controller="com.android.settings.devicelock.DeviceLockPreferenceController">
<intent android:action="com.android.devicelockcontroller.action.DEVICE_INFO_SETTINGS"/> <intent android:action="com.android.devicelockcontroller.action.DEVICE_INFO_SETTINGS"/>

View File

@@ -99,7 +99,7 @@ public class BluetoothDetailsProfilesController extends BluetoothDetailsControll
mIsLeContactSharingEnabled = DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_SETTINGS_UI, mIsLeContactSharingEnabled = DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_SETTINGS_UI,
SettingsUIDeviceConfig.BT_LE_AUDIO_CONTACT_SHARING_ENABLED, true); SettingsUIDeviceConfig.BT_LE_AUDIO_CONTACT_SHARING_ENABLED, true);
mIsLeAudioToggleEnabled = DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_SETTINGS_UI, mIsLeAudioToggleEnabled = DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_SETTINGS_UI,
SettingsUIDeviceConfig.BT_LE_AUDIO_DEVICE_DETAIL_ENABLED, false) SettingsUIDeviceConfig.BT_LE_AUDIO_DEVICE_DETAIL_ENABLED, true)
|| DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_BLUETOOTH, || DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_BLUETOOTH,
CONFIG_LE_AUDIO_ENABLED_BY_DEFAULT, false); CONFIG_LE_AUDIO_ENABLED_BY_DEFAULT, false);
// Call refresh here even though it will get called later in onResume, to avoid the // Call refresh here even though it will get called later in onResume, to avoid the

View File

@@ -34,6 +34,8 @@ import com.android.settingslib.drawer.ProviderTile;
import com.android.settingslib.drawer.Tile; import com.android.settingslib.drawer.Tile;
import com.android.settingslib.drawer.TileUtils; import com.android.settingslib.drawer.TileUtils;
import com.google.android.setupcompat.util.WizardManagerHelper;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@@ -79,6 +81,9 @@ public class CategoryManager {
} }
public synchronized List<DashboardCategory> getCategories(Context context) { public synchronized List<DashboardCategory> getCategories(Context context) {
if (!WizardManagerHelper.isUserSetupComplete(context)) {
return new ArrayList<>();
}
tryInitCategories(context); tryInitCategories(context);
return mCategories; return mCategories;
} }
@@ -142,6 +147,10 @@ public class CategoryManager {
} }
private synchronized void tryInitCategories(Context context, boolean forceClearCache) { private synchronized void tryInitCategories(Context context, boolean forceClearCache) {
if (!WizardManagerHelper.isUserSetupComplete(context)) {
// Don't init while setup wizard is still running.
return;
}
if (mCategories == null) { if (mCategories == null) {
final boolean firstLoading = mCategoryByKeyMap.isEmpty(); final boolean firstLoading = mCategoryByKeyMap.isEmpty();
if (forceClearCache) { if (forceClearCache) {

View File

@@ -40,6 +40,7 @@ public class BluetoothLeAudioDeviceDetailsPreferenceController
private static final String PREFERENCE_KEY = "bluetooth_show_leaudio_device_details"; private static final String PREFERENCE_KEY = "bluetooth_show_leaudio_device_details";
private static final String CONFIG_LE_AUDIO_ENABLED_BY_DEFAULT = "le_audio_enabled_by_default"; private static final String CONFIG_LE_AUDIO_ENABLED_BY_DEFAULT = "le_audio_enabled_by_default";
private static final boolean LE_AUDIO_DEVICE_DETAIL_DEFAULT_VALUE = true;
static int sLeAudioSupportedStateCache = BluetoothStatusCodes.ERROR_UNKNOWN; static int sLeAudioSupportedStateCache = BluetoothStatusCodes.ERROR_UNKNOWN;
@VisibleForTesting @VisibleForTesting
@@ -75,7 +76,7 @@ public class BluetoothLeAudioDeviceDetailsPreferenceController
DeviceConfig.setProperty( DeviceConfig.setProperty(
DeviceConfig.NAMESPACE_SETTINGS_UI, DeviceConfig.NAMESPACE_SETTINGS_UI,
SettingsUIDeviceConfig.BT_LE_AUDIO_DEVICE_DETAIL_ENABLED, SettingsUIDeviceConfig.BT_LE_AUDIO_DEVICE_DETAIL_ENABLED,
isEnabled ? "true" : "false", false); isEnabled ? "true" : "false", LE_AUDIO_DEVICE_DETAIL_DEFAULT_VALUE);
return true; return true;
} }
@@ -87,7 +88,8 @@ public class BluetoothLeAudioDeviceDetailsPreferenceController
final boolean leAudioDeviceDetailEnabled = DeviceConfig.getBoolean( final boolean leAudioDeviceDetailEnabled = DeviceConfig.getBoolean(
DeviceConfig.NAMESPACE_SETTINGS_UI, DeviceConfig.NAMESPACE_SETTINGS_UI,
SettingsUIDeviceConfig.BT_LE_AUDIO_DEVICE_DETAIL_ENABLED, false); SettingsUIDeviceConfig.BT_LE_AUDIO_DEVICE_DETAIL_ENABLED,
LE_AUDIO_DEVICE_DETAIL_DEFAULT_VALUE);
final boolean leAudioEnabledByDefault = DeviceConfig.getBoolean( final boolean leAudioEnabledByDefault = DeviceConfig.getBoolean(
DeviceConfig.NAMESPACE_BLUETOOTH, CONFIG_LE_AUDIO_ENABLED_BY_DEFAULT, false); DeviceConfig.NAMESPACE_BLUETOOTH, CONFIG_LE_AUDIO_ENABLED_BY_DEFAULT, false);
@@ -102,6 +104,7 @@ public class BluetoothLeAudioDeviceDetailsPreferenceController
// Reset the toggle to null when the developer option is disabled // Reset the toggle to null when the developer option is disabled
DeviceConfig.setProperty( DeviceConfig.setProperty(
DeviceConfig.NAMESPACE_SETTINGS_UI, DeviceConfig.NAMESPACE_SETTINGS_UI,
SettingsUIDeviceConfig.BT_LE_AUDIO_DEVICE_DETAIL_ENABLED, "null", false); SettingsUIDeviceConfig.BT_LE_AUDIO_DEVICE_DETAIL_ENABLED, "null",
LE_AUDIO_DEVICE_DETAIL_DEFAULT_VALUE);
} }
} }

View File

@@ -23,7 +23,6 @@ import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.os.RecoverySystem;
import android.util.Log; import android.util.Log;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
@@ -62,7 +61,7 @@ public class EraseEuiccDataDialogFragment extends InstrumentedDialogFragment imp
return new AlertDialog.Builder(getActivity()) return new AlertDialog.Builder(getActivity())
.setTitle(R.string.reset_esim_title) .setTitle(R.string.reset_esim_title)
.setMessage(R.string.reset_esim_desc) .setMessage(R.string.reset_esim_desc)
.setPositiveButton(R.string.erase_euicc_data_button, this) .setPositiveButton(R.string.erase_sim_confirm_button, this)
.setNegativeButton(R.string.cancel, null) .setNegativeButton(R.string.cancel, null)
.setOnDismissListener(this) .setOnDismissListener(this)
.create(); .create();

View File

@@ -46,10 +46,12 @@ import androidx.preference.PreferenceGroup;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.Settings; import com.android.settings.Settings;
import com.android.settings.Settings.TetherSettingsActivity; import com.android.settings.Settings.TetherSettingsActivity;
import com.android.settings.Settings.WifiTetherSettingsActivity;
import com.android.settings.activityembedding.ActivityEmbeddingUtils; import com.android.settings.activityembedding.ActivityEmbeddingUtils;
import com.android.settings.core.BasePreferenceController; import com.android.settings.core.BasePreferenceController;
import com.android.settings.gestures.OneHandedSettingsUtils; import com.android.settings.gestures.OneHandedSettingsUtils;
import com.android.settings.overlay.FeatureFactory; import com.android.settings.overlay.FeatureFactory;
import com.android.settings.wifi.WifiUtils;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider; import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
import java.util.ArrayList; import java.util.ArrayList;
@@ -192,6 +194,12 @@ public class CreateShortcutPreferenceController extends BasePreferenceController
continue; continue;
} }
} }
if (info.activityInfo.name.endsWith(WifiTetherSettingsActivity.class.getSimpleName())) {
if (!canShowWifiHotspot()) {
Log.d(TAG, "Skipping Wi-Fi hotspot settings:" + info.activityInfo);
continue;
}
}
if (!info.activityInfo.applicationInfo.isSystemApp()) { if (!info.activityInfo.applicationInfo.isSystemApp()) {
Log.d(TAG, "Skipping non-system app: " + info.activityInfo); Log.d(TAG, "Skipping non-system app: " + info.activityInfo);
continue; continue;
@@ -202,6 +210,11 @@ public class CreateShortcutPreferenceController extends BasePreferenceController
return shortcuts; return shortcuts;
} }
@VisibleForTesting
boolean canShowWifiHotspot() {
return WifiUtils.canShowWifiHotspot(mContext);
}
private void logCreateShortcut(ResolveInfo info) { private void logCreateShortcut(ResolveInfo info) {
if (info == null || info.activityInfo == null) { if (info == null || info.activityInfo == null) {
return; return;

View File

@@ -39,10 +39,12 @@ import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentManager;
import com.android.internal.annotations.VisibleForTesting;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.network.CarrierConfigCache; import com.android.settings.network.CarrierConfigCache;
import com.android.settings.network.SubscriptionUtil; import com.android.settings.network.SubscriptionUtil;
import com.android.settings.network.ims.WifiCallingQueryImsState; import com.android.settings.network.ims.WifiCallingQueryImsState;
import com.android.settings.network.telephony.MobileNetworkUtils;
import com.android.settings.network.telephony.SubscriptionActionDialogActivity; import com.android.settings.network.telephony.SubscriptionActionDialogActivity;
import com.android.settings.overlay.FeatureFactory; import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider; import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
@@ -77,7 +79,10 @@ public class SimDialogActivity extends FragmentActivity {
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
if (isUiRestricted()) {
finish();
return;
}
if (!SubscriptionUtil.isSimHardwareVisible(this)) { if (!SubscriptionUtil.isSimHardwareVisible(this)) {
Log.d(TAG, "Not support on device without SIM."); Log.d(TAG, "Not support on device without SIM.");
finish(); finish();
@@ -91,6 +96,15 @@ public class SimDialogActivity extends FragmentActivity {
showOrUpdateDialog(); showOrUpdateDialog();
} }
@VisibleForTesting
boolean isUiRestricted() {
if (MobileNetworkUtils.isMobileNetworkUserRestricted(getApplicationContext())) {
Log.e(TAG, "This setting isn't available due to user restriction.");
return true;
}
return false;
}
@Override @Override
protected void onNewIntent(Intent intent) { protected void onNewIntent(Intent intent) {
super.onNewIntent(intent); super.onNewIntent(intent);

View File

@@ -41,6 +41,7 @@ object AppLanguagesPageProvider : SettingsPageProvider {
AppListPage( AppListPage(
title = stringResource(R.string.app_locales_picker_menu_title), title = stringResource(R.string.app_locales_picker_menu_title),
listModel = rememberContext(::AppLanguagesListModel), listModel = rememberContext(::AppLanguagesListModel),
noMoreOptions = true,
header = { header = {
Box(Modifier.padding(SettingsDimension.itemPadding)) { Box(Modifier.padding(SettingsDimension.itemPadding)) {
SettingsBody(stringResource(R.string.desc_app_locale_selection_supported)) SettingsBody(stringResource(R.string.desc_app_locale_selection_supported))

View File

@@ -84,7 +84,7 @@ public class CreateShortcutPreferenceControllerTest {
mShadowConnectivityManager = ShadowConnectivityManager.getShadow(); mShadowConnectivityManager = ShadowConnectivityManager.getShadow();
mShadowConnectivityManager.setTetheringSupported(true); mShadowConnectivityManager.setTetheringSupported(true);
mController = new CreateShortcutPreferenceController(mContext, "key"); mController = spy(new CreateShortcutPreferenceController(mContext, "key"));
mController.setActivity(mHost); mController.setActivity(mHost);
} }
@@ -159,27 +159,39 @@ public class CreateShortcutPreferenceControllerTest {
@Test @Test
public void queryShortcuts_setSupportOneHandedMode_ShouldEnableShortcuts() { public void queryShortcuts_setSupportOneHandedMode_ShouldEnableShortcuts() {
SystemProperties.set(SUPPORT_ONE_HANDED_MODE, "true"); SystemProperties.set(SUPPORT_ONE_HANDED_MODE, "true");
setupActivityInfo(Settings.OneHandedSettingsActivity.class.getSimpleName());
setupOneHandedModeActivityInfo(); assertThat(mController.queryShortcuts()).hasSize(1);
final List<ResolveInfo> info = mController.queryShortcuts();
assertThat(info).hasSize(1);
} }
@Test @Test
public void queryShortcuts_setUnsupportOneHandedMode_ShouldDisableShortcuts() { public void queryShortcuts_setUnsupportOneHandedMode_ShouldDisableShortcuts() {
SystemProperties.set(SUPPORT_ONE_HANDED_MODE, "false"); SystemProperties.set(SUPPORT_ONE_HANDED_MODE, "false");
setupActivityInfo(Settings.OneHandedSettingsActivity.class.getSimpleName());
setupOneHandedModeActivityInfo(); assertThat(mController.queryShortcuts()).hasSize(0);
final List<ResolveInfo> info = mController.queryShortcuts();
assertThat(info).hasSize(0);
} }
private void setupOneHandedModeActivityInfo() { @Test
final ResolveInfo ri = new ResolveInfo(); public void queryShortcuts_configShowWifiHotspot_ShouldEnableShortcuts() {
when(mController.canShowWifiHotspot()).thenReturn(true);
setupActivityInfo(Settings.WifiTetherSettingsActivity.class.getSimpleName());
assertThat(mController.queryShortcuts()).hasSize(1);
}
@Test
public void queryShortcuts_configNotShowWifiHotspot_ShouldDisableShortcuts() {
when(mController.canShowWifiHotspot()).thenReturn(false);
setupActivityInfo(Settings.WifiTetherSettingsActivity.class.getSimpleName());
assertThat(mController.queryShortcuts()).hasSize(0);
}
private void setupActivityInfo(String name) {
ResolveInfo ri = new ResolveInfo();
ri.activityInfo = new ActivityInfo(); ri.activityInfo = new ActivityInfo();
ri.activityInfo.name = Settings.OneHandedSettingsActivity.class.getSimpleName(); ri.activityInfo.name = name;
ri.activityInfo.applicationInfo = new ApplicationInfo(); ri.activityInfo.applicationInfo = new ApplicationInfo();
ri.activityInfo.applicationInfo.flags = ApplicationInfo.FLAG_SYSTEM; ri.activityInfo.applicationInfo.flags = ApplicationInfo.FLAG_SYSTEM;

View File

@@ -190,6 +190,7 @@ public class BatteryTestUtils {
when(mockUsbPort.getStatus()).thenReturn(mockUsbPortStatus); when(mockUsbPort.getStatus()).thenReturn(mockUsbPortStatus);
when(mockUsbPort.supportsComplianceWarnings()).thenReturn(true); when(mockUsbPort.supportsComplianceWarnings()).thenReturn(true);
when(mockUsbPortStatus.isConnected()).thenReturn(true); when(mockUsbPortStatus.isConnected()).thenReturn(true);
when(mockUsbPortStatus.getComplianceWarnings()).thenReturn(new int[]{1}); when(mockUsbPortStatus.getComplianceWarnings())
.thenReturn(new int[]{UsbPortStatus.COMPLIANCE_WARNING_OTHER});
} }
} }

View File

@@ -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.sim;
import static android.os.UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.os.UserManager;
import androidx.test.annotation.UiThreadTest;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Spy;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
@RunWith(AndroidJUnit4.class)
@UiThreadTest
public class SimDialogActivityTest {
@Rule
public final MockitoRule mMockitoRule = MockitoJUnit.rule();
@Spy
private final Context mContext = ApplicationProvider.getApplicationContext();
@Mock
private UserManager mUserManager;
private MockSimDialogActivity mActivity;
@Before
public void setUp() {
when(mContext.getSystemService(UserManager.class)).thenReturn(mUserManager);
when(mUserManager.isGuestUser()).thenReturn(false);
when(mUserManager.hasUserRestriction(DISALLOW_CONFIG_MOBILE_NETWORKS)).thenReturn(false);
mActivity = new MockSimDialogActivity();
}
@Test
public void isUiRestricted_normally_returnFalse() {
assertThat(mActivity.isUiRestricted()).isFalse();
}
@Test
public void isUiRestricted_isGuestUser_returnTrue() {
when(mUserManager.isGuestUser()).thenReturn(true);
assertThat(mActivity.isUiRestricted()).isTrue();
}
@Test
public void isUiRestricted_hasUserRestriction_returnTrue() {
when(mUserManager.hasUserRestriction(DISALLOW_CONFIG_MOBILE_NETWORKS)).thenReturn(true);
assertThat(mActivity.isUiRestricted()).isTrue();
}
public class MockSimDialogActivity extends SimDialogActivity {
@Override
public Context getApplicationContext() {
return mContext;
}
}
}