Snap for 12502765 from 3ba451c4a3 to 25Q1-release

Change-Id: I75c0e934ab77923a4c0fc33372af989a004c3ab6
This commit is contained in:
Android Build Coastguard Worker
2024-10-15 23:23:30 +00:00
29 changed files with 607 additions and 31 deletions

View File

@@ -98,6 +98,7 @@ android_library {
"SettingsLibDataStore",
"SettingsLibMetadata",
"SettingsLibPreference",
"SettingsLibService",
"aconfig_settings_flags_lib",
"accessibility_settings_flags_lib",
"contextualcards",
@@ -107,7 +108,6 @@ android_library {
"fuelgauge-protos-lite",
"settings-logtags",
"statslog-settings",
"telephony_flags_core_java_lib",
"setupdesign-lottie-loading-layout",
"device_policy_aconfig_flags_lib",
"keyboard_flags_lib",

View File

@@ -5293,12 +5293,36 @@
android:value="com.android.settings.connecteddevice.audiosharing.audiostreams.AudioStreamConfirmDialog" />
</activity>
<activity
android:name="Settings$ContactsStorageSettingsActivity"
android:label="@string/contacts_storage_settings_title"
android:exported="true"
android:featureFlag="com.android.settings.flags.enable_contacts_default_account_in_settings">
<intent-filter>
<action android:name="android.provider.action.SET_DEFAULT_ACCOUNT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.applications.contacts.ContactsStorageSettings"/>
</activity>
<service
android:name="com.android.settings.connecteddevice.audiosharing.audiostreams.AudioStreamMediaService"
android:foregroundServiceType="mediaPlayback"
android:enabled="true"
android:exported="false" />
<!-- Once b/364771256 is fixed, add android:featureFlag="com.android.settings.flags.catalyst_service". -->
<!-- Permission is not yet finalized, use READ_BASIC_PHONE_STATE temporarily. -->
<service
android:name=".SettingsService"
android:exported="true"
android:permission="android.permission.READ_BASIC_PHONE_STATE">
<intent-filter>
<action android:name="com.android.settingslib.PREFERENCE_SERVICE" />
</intent-filter>
</service>
<receiver android:name="com.android.settings.connecteddevice.audiosharing.AudioSharingReceiver"
android:exported="false">
<intent-filter>

View File

@@ -0,0 +1,9 @@
package: "com.android.settings.flags"
container: "system"
flag {
name: "catalyst_battery_saver_screen"
namespace: "android_settings"
description: "Flag for Battery Saver"
bug: "323791114"
}

View File

@@ -0,0 +1,9 @@
package: "com.android.settings.flags"
container: "system"
flag {
name: "catalyst_network_provider_and_internet_screen"
namespace: "android_settings"
description: "Flag for Network & Internet"
bug: "323791114"
}

View File

@@ -63,3 +63,10 @@ flag {
description: "Flag for all screens"
bug: "323791114"
}
flag {
name: "catalyst_service"
namespace: "android_settings"
description: "Flag for catalyst service"
bug: "323791114"
}

View File

@@ -32,7 +32,7 @@
<item
android:width="24dp"
android:height="24dp"
android:left="57dp"
android:start="57dp"
android:top="57dp">
<vector
android:width="24dp"

View File

@@ -13708,7 +13708,6 @@
<!-- Learn more link for audio sharing qrcode [CHAR LIMIT=none]-->
<string name="audio_streams_qr_code_help_with_link"><annotation id="link">Need help?</annotation></string>
<!-- url for learning more about bluetooth audio sharing -->
<string name="help_url_audio_sharing" translatable="false"></string>
@@ -13729,4 +13728,11 @@
<string name="contacts_storage_no_account_set">No default set</string>
<!-- Text for add account selection message when no account has been added [CHAR LIMIT=100] -->
<string name="contacts_storage_first_time_add_account_message">Add an account to get started</string>
<!-- Circle to Search (shared between all entrypoints) -->
<!-- Name of Google's new feature to circle to search anything on your phone screen,
without switching apps. Also used as the setting title. [CHAR LIMIT=60] -->
<string name="search_gesture_feature_title">Circle to Search</string>
<!-- Summary text for press and hold nav handle OR home button to invoke Circle to Search. [CHAR LIMIT=NONE] -->
<string name="search_gesture_feature_summary">Touch and hold the Home button or the navigation handle to search using the content on your screen.</string>
</resources>

View File

@@ -20,6 +20,9 @@
android:persistent="false"
android:title="@string/accessibility_system_controls_title">
<!-- The item is not specific to Accessibility.
The same entry is under System, which is unlikely to be removed,
so this is not searchable. -->
<Preference
android:fragment="com.android.settings.gestures.SystemNavigationGestureSettings"
android:key="gesture_system_navigation_input_summary_accessibility"
@@ -28,6 +31,9 @@
settings:searchable="false"
settings:controller="com.android.settings.gestures.SystemNavigationPreferenceController"/>
<!-- The item is not specific to Accessibility.
The same entry is under System > Gesture, which is unlikely to be removed,
so this is not searchable. -->
<Preference
android:fragment="com.android.settings.gestures.OneHandedSettings"
android:key="gesture_system_navigation_one_handed_accessibility"
@@ -43,21 +49,28 @@
settings:controller="com.android.settings.accessibility.PowerButtonEndsCallPreferenceController"/>
<!-- Standard auto-rotation preference that will be shown when device state based auto-rotation
settings are NOT available. -->
settings are NOT available.
The item is not specific to Accessibility.
The same entry is under Display & touch, which is unlikely to be removed,
so this is not searchable.-->
<SwitchPreferenceCompat
android:key="toggle_lock_screen_rotation_preference"
android:persistent="false"
android:title="@string/accelerometer_title"
settings:searchable="false"
settings:controller="com.android.settings.accessibility.LockScreenRotationPreferenceController"/>
<!-- Auto-rotation preference that will be shown when device state based auto-rotation settings
are available. -->
are available.
The item is not specific to Accessibility.
The same entry is under Display & touch, which is unlikely to be removed,
so this is not searchable. -->
<Preference
android:key="device_state_auto_rotate_accessibility"
android:persistent="false"
android:title="@string/accelerometer_title"
android:fragment="com.android.settings.display.DeviceStateAutoRotateDetailsFragment"
settings:keywords="@string/keywords_auto_rotate"
settings:searchable="false"
settings:controller="com.android.settings.display.DeviceStateAutoRotateOverviewController"/>
</PreferenceScreen>

View File

@@ -28,7 +28,8 @@
settings:searchable="false"
settings:dynamicColor="true"
settings:lottie_imageAssetsFolder="button_nav_menu"
settings:lottie_rawRes="@raw/lottie_button_nav_menu"/>
settings:lottie_rawRes="@raw/lottie_button_nav_menu"
settings:controller="com.android.settings.gestures.ButtonNavigationSettingsAssistController"/>
<SwitchPreferenceCompat
android:key="assistant_long_press_home_gesture"

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2018 The Android Open Source Project
Copyright (C) 2024 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.
@@ -19,4 +19,15 @@
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:settings="http://schemas.android.com/apk/res-auto"
android:title="@string/system_navigation_title"
settings:keywords="@string/keywords_system_navigation"/>
settings:keywords="@string/keywords_system_navigation">
<SwitchPreferenceCompat
android:key="search_gesture_press_hold"
android:title="@string/search_gesture_feature_title"
android:summary="@string/search_gesture_feature_summary"
android:order="100"
settings:allowDividerAbove="true"
settings:controller="com.android.settings.gestures.NavigationSettingsContextualSearchController"
settings:highlightableMenuKey="@string/menu_key_system" />
</PreferenceScreen>

View File

@@ -47,7 +47,6 @@ import androidx.activity.result.contract.ActivityResultContracts;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import com.android.internal.telephony.flags.Flags;
import com.android.settings.core.InstrumentedFragment;
import com.android.settings.core.SubSettingLauncher;
import com.android.settings.network.ResetNetworkRestrictionViewBuilder;
@@ -142,13 +141,10 @@ public class ResetNetwork extends InstrumentedFragment {
Context context = getContext();
boolean resetSims = false;
// TODO(b/317276437) Simplify the logic once flag is released
int resetOptions = ResetNetworkRequest.RESET_CONNECTIVITY_MANAGER
| ResetNetworkRequest.RESET_VPN_MANAGER;
if (Flags.resetMobileNetworkSettings()) {
resetOptions |= ResetNetworkRequest.RESET_IMS_STACK;
resetOptions |= ResetNetworkRequest.RESET_PHONE_PROCESS;
}
| ResetNetworkRequest.RESET_VPN_MANAGER
| ResetNetworkRequest.RESET_IMS_STACK
| ResetNetworkRequest.RESET_PHONE_PROCESS;
ResetNetworkRequest request = new ResetNetworkRequest(resetOptions);
if (mSubscriptions != null && mSubscriptions.size() > 0) {
int selectedIndex = mSubscriptionSpinner.getSelectedItemPosition();
@@ -156,9 +152,7 @@ public class ResetNetwork extends InstrumentedFragment {
int subId = subscription.getSubscriptionId();
request.setResetTelephonyAndNetworkPolicyManager(subId)
.setResetApn(subId);
if (Flags.resetMobileNetworkSettings()) {
request.setResetImsSubId(subId);
}
request.setResetImsSubId(subId);
}
if (mEsimContainer.getVisibility() == View.VISIBLE && mEsimCheckbox.isChecked()) {
resetSims = true;

View File

@@ -514,4 +514,5 @@ public class Settings extends SettingsActivity {
public static class HearingDevicesActivity extends SettingsActivity { /* empty */ }
public static class HearingDevicesPairingActivity extends SettingsActivity { /* empty */ }
public static class ContactsStorageSettingsActivity extends SettingsActivity { /* empty */ }
}

View File

@@ -0,0 +1,30 @@
/*
* Copyright (C) 2024 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
import android.content.Intent
import android.os.IBinder
import com.android.settings.flags.Flags
import com.android.settingslib.service.PreferenceService
/** Service to expose settings APIs. */
class SettingsService : PreferenceService({ _, _, _ -> true }) {
override fun onBind(intent: Intent): IBinder? {
return if (!Flags.catalystService()) null else super.onBind(intent)
}
}

View File

@@ -58,6 +58,8 @@ class BluetoothDeviceDetailsViewModel(
deviceSettingRepository.getDeviceSettingsConfig(cachedDevice)
}
private val spatialAudioModel by lazy { spatialAudioInteractor.getDeviceSetting(cachedDevice) }
suspend fun getItems(fragment: FragmentTypeModel): List<DeviceSettingConfigItemModel>? =
when (fragment) {
is FragmentTypeModel.DeviceDetailsMainFragment -> items.await()?.mainItems
@@ -81,7 +83,7 @@ class BluetoothDeviceDetailsViewModel(
}
return when (settingId) {
DeviceSettingId.DEVICE_SETTING_ID_SPATIAL_AUDIO_MULTI_TOGGLE ->
spatialAudioInteractor.getDeviceSetting(cachedDevice)
spatialAudioModel
else -> deviceSettingRepository.getDeviceSetting(cachedDevice, settingId)
}.map { it?.toPreferenceModel() }
}

View File

@@ -60,6 +60,7 @@ import com.android.settings.applications.appinfo.TurnScreenOnDetails;
import com.android.settings.applications.appinfo.WriteSettingsDetails;
import com.android.settings.applications.appops.BackgroundCheckSummary;
import com.android.settings.applications.assist.ManageAssist;
import com.android.settings.applications.contacts.ContactsStorageSettings;
import com.android.settings.applications.manageapplications.ManageApplications;
import com.android.settings.applications.managedomainurls.ManageDomainUrls;
import com.android.settings.applications.specialaccess.deviceadmin.DeviceAdminSettings;
@@ -401,7 +402,8 @@ public class SettingsGateway {
AccessibilityHearingAidsFragment.class.getName(),
HearingDevicePairingFragment.class.getName(),
ZenModesListFragment.class.getName(),
ZenModeFragment.class.getName()
ZenModeFragment.class.getName(),
ContactsStorageSettings.class.getName()
};
public static final String[] SETTINGS_FOR_RESTRICTED = {

View File

@@ -0,0 +1,47 @@
/*
* Copyright (C) 2024 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.fuelgauge.batterysaver
import android.content.Context
import com.android.settings.R
import com.android.settings.flags.Flags
import com.android.settingslib.metadata.ProvidePreferenceScreen
import com.android.settingslib.metadata.preferenceHierarchy
import com.android.settingslib.preference.PreferenceScreenCreator
@ProvidePreferenceScreen
class BatterySaverScreen : PreferenceScreenCreator {
override val key: String
get() = KEY
override val title: Int
get() = R.string.battery_saver
override val keywords: Int
get() = R.string.keywords_battery_saver
override fun isFlagEnabled(context: Context) = Flags.catalystBatterySaverScreen()
override fun fragmentClass() = BatterySaverSettings::class.java
override fun hasCompleteHierarchy() = false
override fun getPreferenceHierarchy(context: Context) = preferenceHierarchy(this) {}
companion object {
const val KEY = "battery_saver_screen"
}
}

View File

@@ -17,8 +17,11 @@
package com.android.settings.fuelgauge.batterysaver;
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.text.TextUtils;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import com.android.settings.R;
@@ -93,4 +96,10 @@ public class BatterySaverSettings extends DashboardFragment {
pref.setLearnMoreText(getString(R.string.battery_saver_link_a11y));
}
}
@Nullable
@Override
public String getPreferenceScreenBindingKey(@NonNull Context context) {
return BatterySaverScreen.KEY;
}
}

View File

@@ -16,6 +16,7 @@
package com.android.settings.gestures;
import static android.app.contextualsearch.ContextualSearchManager.FEATURE_CONTEXTUAL_SEARCH;
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_2BUTTON_OVERLAY;
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_3BUTTON_OVERLAY;
@@ -50,6 +51,11 @@ public class ButtonNavigationSettingsAssistController extends TogglePreferenceCo
@Override
public int getAvailabilityStatus() {
// Hide the existing assistant UI elements when contextual search is available.
if (mContext.getPackageManager().hasSystemFeature(FEATURE_CONTEXTUAL_SEARCH)) {
return UNSUPPORTED_ON_DEVICE;
}
if (SystemNavigationPreferenceController.isOverlayPackageAvailable(mContext,
NAV_BAR_MODE_2BUTTON_OVERLAY)
|| SystemNavigationPreferenceController.isOverlayPackageAvailable(mContext,

View File

@@ -0,0 +1,70 @@
/*
* Copyright (C) 2024 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.gestures;
import static android.app.contextualsearch.ContextualSearchManager.FEATURE_CONTEXTUAL_SEARCH;
import android.content.Context;
import android.provider.Settings;
import androidx.annotation.NonNull;
import com.android.settings.core.TogglePreferenceController;
/**
* Configures behaviour of Contextual Search setting.
*/
public class NavigationSettingsContextualSearchController extends TogglePreferenceController {
public NavigationSettingsContextualSearchController(@NonNull Context context,
@NonNull String preferenceKey) {
super(context, preferenceKey);
}
@Override
public boolean isChecked() {
boolean onByDefault = mContext.getResources().getBoolean(
com.android.internal.R.bool.config_searchAllEntrypointsEnabledDefault);
return Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.SEARCH_ALL_ENTRYPOINTS_ENABLED, onByDefault ? 1 : 0)
== 1;
}
@Override
public boolean setChecked(boolean isChecked) {
return Settings.Secure.putInt(mContext.getContentResolver(),
Settings.Secure.SEARCH_ALL_ENTRYPOINTS_ENABLED, isChecked ? 1 : 0);
}
@Override
public int getAvailabilityStatus() {
if (mContext.getPackageManager().hasSystemFeature(FEATURE_CONTEXTUAL_SEARCH)) {
return AVAILABLE;
}
return UNSUPPORTED_ON_DEVICE;
}
@Override
public boolean isSliceable() {
return false;
}
@Override
public int getSliceHighlightMenuRes() {
return NO_RES;
}
}

View File

@@ -19,6 +19,7 @@ import android.app.settings.SettingsEnums;
import android.content.Context;
import android.content.Intent;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.android.settings.R;
@@ -115,4 +116,10 @@ public class NetworkDashboardFragment extends DashboardFragment implements
return buildPreferenceControllers(context, null /* lifecycle */);
}
};
@Nullable
@Override
public String getPreferenceScreenBindingKey(@NonNull Context context) {
return NetworkDashboardScreen.KEY;
}
}

View File

@@ -0,0 +1,47 @@
/*
* Copyright (C) 2024 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
import android.content.Context
import com.android.settings.R
import com.android.settings.flags.Flags
import com.android.settingslib.metadata.ProvidePreferenceScreen
import com.android.settingslib.metadata.preferenceHierarchy
import com.android.settingslib.preference.PreferenceScreenCreator
@ProvidePreferenceScreen
class NetworkDashboardScreen : PreferenceScreenCreator {
override val key: String
get() = KEY
override val title: Int
get() = R.string.network_dashboard_title
override val icon: Int
get() = R.drawable.ic_settings_wireless_filled
override fun isFlagEnabled(context: Context) = Flags.catalystNetworkProviderAndInternetScreen()
override fun hasCompleteHierarchy() = false
override fun fragmentClass() = NetworkDashboardFragment::class.java
override fun getPreferenceHierarchy(context: Context) = preferenceHierarchy(this) {}
companion object {
const val KEY = "network_provider_and_internet_screen"
}
}

View File

@@ -109,7 +109,10 @@ android_robolectric_test {
java_library {
name: "Settings-robo-testutils",
srcs: ["testutils/**/*.java"],
srcs: [
"testutils/**/*.java",
"testutils/**/*.kt",
],
libs: [
"Robolectric_all-target_upstream",
"Settings-core",

View File

@@ -63,12 +63,14 @@ import android.widget.TextView;
import com.android.settings.R;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.SystemProperty;
import com.android.settings.widget.RingProgressBar;
import com.airbnb.lottie.LottieAnimationView;
import com.airbnb.lottie.LottieTask;
import com.google.android.setupdesign.GlifLayout;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
@@ -111,15 +113,23 @@ public class FingerprintEnrollEnrollingTest {
private final int[] mSfpsStageThresholds = new int[]{0, 9, 13, 19, 25};
private final int[] mUdfpsStageThresholds = new int[]{0, 13, 17, 22};
private final SystemProperty mSystemProperty = new SystemProperty();
private FingerprintEnrollEnrolling mActivity;
private Context mContext;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mSystemProperty.override("robolectric.createActivityContexts", "true");
FakeFeatureFactory.setupForTest();
}
@After
public void tearDown() {
mSystemProperty.close();
}
@Test
public void fingerprintUdfpsEnrollSuccessProgress_shouldNotVibrate() {
initializeActivityFor(TYPE_UDFPS_OPTICAL);
@@ -645,7 +655,6 @@ public class FingerprintEnrollEnrollingTest {
}
private void createActivity() {
System.setProperty("robolectric.createActivityContexts", "true");
final Bundle savedInstanceState = new Bundle();
savedInstanceState.putInt(KEY_STATE_PREVIOUS_ROTATION, Surface.ROTATION_90);

View File

@@ -21,9 +21,9 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import com.android.internal.widget.LockPatternUtils
import com.android.settings.flags.Flags
import com.android.settings.testutils.FakeFeatureFactory
import com.android.settings.testutils.SystemProperty
import com.android.settingslib.preference.CatalystScreenTestCase
import com.google.common.truth.Truth.assertThat
import org.junit.Ignore
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.ArgumentMatchers.anyInt
@@ -66,16 +66,16 @@ class DisplayScreenTest : CatalystScreenTestCase() {
assertThat(preferenceScreenCreator.isAvailable(contextWrapper)).isFalse()
}
@Ignore("robolectric.createActivityContexts cause other test failure")
override fun migration() {
// avoid UnsupportedOperationException when getDisplay from context
System.setProperty("robolectric.createActivityContexts", "true")
SystemProperty("robolectric.createActivityContexts", "true").use {
val lockPatternUtils =
mock<LockPatternUtils> { on { isSecure(anyInt()) } doReturn true }
FakeFeatureFactory.setupForTest().securityFeatureProvider.stub {
on { getLockPatternUtils(any()) } doReturn lockPatternUtils
}
val lockPatternUtils = mock<LockPatternUtils> { on { isSecure(anyInt()) } doReturn true }
FakeFeatureFactory.setupForTest().securityFeatureProvider.stub {
on { getLockPatternUtils(any()) } doReturn lockPatternUtils
super.migration()
}
super.migration()
}
}

View File

@@ -0,0 +1,37 @@
/*
* Copyright (C) 2024 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.fuelgauge.batterysaver
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.android.settings.flags.Flags
import com.android.settingslib.preference.CatalystScreenTestCase
import com.google.common.truth.Truth.assertThat
import org.junit.Test
import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class BatterySaverScreenTest : CatalystScreenTestCase() {
override val preferenceScreenCreator = BatterySaverScreen()
override val flagName: String
get() = Flags.FLAG_CATALYST_BATTERY_SAVER_SCREEN
@Test
fun key() {
assertThat(preferenceScreenCreator.key).isEqualTo(BatterySaverScreen.KEY)
}
}

View File

@@ -16,6 +16,8 @@
package com.android.settings.gestures;
import static android.app.contextualsearch.ContextualSearchManager.FEATURE_CONTEXTUAL_SEARCH;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.mock;
@@ -23,6 +25,7 @@ import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.provider.Settings;
@@ -40,13 +43,16 @@ public class ButtonNavigationSettingsAssistControllerTest {
"assistant_long_press_home_gesture";
private Context mContext;
private PackageManager mPackageManager;
private Resources mResources;
private ButtonNavigationSettingsAssistController mController;
@Before
public void setUp() {
mContext = spy(ApplicationProvider.getApplicationContext());
mPackageManager = mock(PackageManager.class);
mResources = mock(Resources.class);
when(mContext.getPackageManager()).thenReturn(mPackageManager);
when(mContext.getResources()).thenReturn(mResources);
mController = new ButtonNavigationSettingsAssistController(
@@ -97,4 +103,23 @@ public class ButtonNavigationSettingsAssistControllerTest {
Settings.Secure.ASSIST_LONG_PRESS_HOME_ENABLED, -1)).isEqualTo(1);
}
@Test
public void onPreferenceChange_preferenceChecked_valueTrue() {
mController.onPreferenceChange(null, true);
assertThat(Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.ASSIST_LONG_PRESS_HOME_ENABLED, -1)).isEqualTo(1);
}
@Test
public void onPreferenceChange_preferenceUnchecked_valueFalse() {
mController.onPreferenceChange(null, false);
assertThat(Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.ASSIST_LONG_PRESS_HOME_ENABLED, -1)).isEqualTo(0);
}
@Test
public void isAvailable_hasContextualSearchSystemFeature_shouldReturnFalse() {
when(mPackageManager.hasSystemFeature(FEATURE_CONTEXTUAL_SEARCH)).thenReturn(true);
assertThat(mController.isAvailable()).isFalse();
}
}

View File

@@ -0,0 +1,104 @@
/*
* Copyright (C) 2024 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.gestures;
import static android.app.contextualsearch.ContextualSearchManager.FEATURE_CONTEXTUAL_SEARCH;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.content.pm.PackageManager;
import android.provider.Settings;
import androidx.test.core.app.ApplicationProvider;
import com.android.settings.testutils.shadow.ShadowDeviceConfig;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
@RunWith(RobolectricTestRunner.class)
@Config(shadows = ShadowDeviceConfig.class)
public class NavigationSettingsContextualSearchControllerTest {
private static final String KEY_PRESS_HOLD_FOR_SEARCH = "search_gesture_press_hold";
private NavigationSettingsContextualSearchController mController;
private Context mContext;
private PackageManager mPackageManager;
@Before
public void setUp() {
mContext = spy(ApplicationProvider.getApplicationContext());
mPackageManager = mock(PackageManager.class);
when(mContext.getPackageManager()).thenReturn(mPackageManager);
mController = new NavigationSettingsContextualSearchController(
mContext, KEY_PRESS_HOLD_FOR_SEARCH);
}
@Test
public void isAvailable_hasContextualSearchSystemFeature_shouldReturnTrue() {
when(mPackageManager.hasSystemFeature(FEATURE_CONTEXTUAL_SEARCH)).thenReturn(true);
assertThat(mController.isAvailable()).isTrue();
}
@Test
public void isAvailable_doesNotHaveContextualSearchSystemFeature_shouldReturnFalse() {
when(mPackageManager.hasSystemFeature(FEATURE_CONTEXTUAL_SEARCH)).thenReturn(false);
assertThat(mController.isAvailable()).isFalse();
}
@Test
public void isChecked_noDefault_true() {
assertThat(mController.isChecked()).isTrue();
}
@Test
public void isChecked_valueFalse_shouldReturnFalse() {
Settings.Secure.putInt(mContext.getContentResolver(),
Settings.Secure.SEARCH_ALL_ENTRYPOINTS_ENABLED, 0);
assertThat(mController.isChecked()).isFalse();
}
@Test
public void isChecked_valueTrue_shouldReturnTrue() {
Settings.Secure.putInt(mContext.getContentResolver(),
Settings.Secure.SEARCH_ALL_ENTRYPOINTS_ENABLED, 1);
assertThat(mController.isChecked()).isTrue();
}
@Test
public void onPreferenceChange_preferenceChecked_valueTrue() {
mController.onPreferenceChange(null, true);
assertThat(Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.SEARCH_ALL_ENTRYPOINTS_ENABLED, -1)).isEqualTo(1);
}
@Test
public void onPreferenceChange_preferenceUnchecked_valueFalse() {
mController.onPreferenceChange(null, false);
assertThat(Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.SEARCH_ALL_ENTRYPOINTS_ENABLED, -1)).isEqualTo(0);
}
}

View File

@@ -0,0 +1,39 @@
/*
* Copyright (C) 2024 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
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.android.settings.flags.Flags
import com.android.settingslib.preference.CatalystScreenTestCase
import com.google.common.truth.Truth.assertThat
import org.junit.Test
import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class NetworkDashboardScreenTest : CatalystScreenTestCase() {
override val preferenceScreenCreator = NetworkDashboardScreen()
override val flagName: String
get() = Flags.FLAG_CATALYST_NETWORK_PROVIDER_AND_INTERNET_SCREEN
@Test
fun key() {
assertThat(preferenceScreenCreator.key).isEqualTo(NetworkDashboardScreen.KEY)
}
override fun migration() {
}
}

View File

@@ -0,0 +1,64 @@
/*
* Copyright (C) 2024 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.testutils
/**
* Helper class to override system properties.
*
* [System.setProperty] changes the static state in the JVM, which is shared by all tests. Hence,
* there is chance that test cases are dependent/interfered due to system property unexpectedly.
* This helper class backs up the old properties when invoking [override] and restore the old
* properties in [close] to avoid flaky testing.
*/
class SystemProperty(overrides: Map<String, String?> = mapOf()) : AutoCloseable {
private val oldProperties = mutableMapOf<String, String?>()
constructor(key: String, value: String?) : this(mapOf(key to value))
init {
override(overrides)
}
fun override(key: String, value: String?) = override(mapOf(key to value))
fun override(overrides: Map<String, String?>) {
// back up system properties for the overrides
for (key in overrides.keys) {
// only back up the oldest property
if (!oldProperties.containsKey(key)) {
oldProperties[key] = System.getProperty(key)
}
}
overrides.overrideProperties()
}
override fun close() {
// restore the backed up properties
oldProperties.overrideProperties()
oldProperties.clear()
}
private fun Map<String, String?>.overrideProperties() {
for ((key, value) in this) {
if (value != null) {
System.setProperty(key, value)
} else {
System.clearProperty(key)
}
}
}
}