Merge Android 24Q2 Release (ab/11526283) to aosp-main-future

Bug: 337098550
Merged-In: I96574a79eba581db95d387f0d9c9fde2e004c41c
Change-Id: Ib9f2c742f8aa72651ef9eca80a716dd94b9041ea
This commit is contained in:
Xin Li
2024-05-23 14:12:07 -07:00
1413 changed files with 69959 additions and 31812 deletions

View File

@@ -0,0 +1,108 @@
/*
* Copyright (C) 2022 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.development;
import static com.android.settings.development.BluetoothLeAudioModePreferenceController
.LE_AUDIO_DYNAMIC_SWITCHER_MODE_PROPERTY;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import android.bluetooth.BluetoothAdapter;
import android.content.Context;
import android.os.SystemProperties;
import androidx.preference.ListPreference;
import androidx.preference.PreferenceScreen;
import com.android.settings.R;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
@RunWith(RobolectricTestRunner.class)
public class BluetoothLeAudioModePreferenceControllerTest {
@Mock
private PreferenceScreen mPreferenceScreen;
@Mock
private DevelopmentSettingsDashboardFragment mFragment;
@Mock
private BluetoothAdapter mBluetoothAdapter;
@Mock
private ListPreference mPreference;
private Context mContext;
private BluetoothLeAudioModePreferenceController mController;
private String[] mListValues;
private String[] mListSummaries;
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
mListValues = mContext.getResources().getStringArray(
R.array.bluetooth_leaudio_mode_values);
mListSummaries = mContext.getResources().getStringArray(
R.array.bluetooth_leaudio_mode);
mController = spy(new BluetoothLeAudioModePreferenceController(mContext, mFragment));
when(mPreferenceScreen.findPreference(mController.getPreferenceKey()))
.thenReturn(mPreference);
mController.mBluetoothAdapter = mBluetoothAdapter;
mController.displayPreference(mPreferenceScreen);
}
@Test
public void onRebootDialogConfirmed_changeLeAudioMode_shouldSetLeAudioMode() {
mController.mChanged = true;
SystemProperties.set(LE_AUDIO_DYNAMIC_SWITCHER_MODE_PROPERTY, mListValues[0]);
mController.mNewMode = mListValues[1];
mController.onRebootDialogConfirmed();
assertThat(SystemProperties.get(LE_AUDIO_DYNAMIC_SWITCHER_MODE_PROPERTY, mListValues[0])
.equals(mController.mNewMode)).isTrue();
}
@Test
public void onRebootDialogConfirmed_notChangeLeAudioMode_shouldNotSetLeAudioMode() {
mController.mChanged = false;
SystemProperties.set(LE_AUDIO_DYNAMIC_SWITCHER_MODE_PROPERTY, mListValues[0]);
mController.mNewMode = mListValues[1];
mController.onRebootDialogConfirmed();
assertThat(SystemProperties.get(LE_AUDIO_DYNAMIC_SWITCHER_MODE_PROPERTY, mListValues[0])
.equals(mController.mNewMode)).isFalse();
}
@Test
public void onRebootDialogCanceled_shouldNotSetLeAudioMode() {
mController.mChanged = true;
SystemProperties.set(LE_AUDIO_DYNAMIC_SWITCHER_MODE_PROPERTY, mListValues[0]);
mController.mNewMode = mListValues[1];
mController.onRebootDialogCanceled();
assertThat(SystemProperties.get(LE_AUDIO_DYNAMIC_SWITCHER_MODE_PROPERTY, mListValues[0])
.equals(mController.mNewMode)).isFalse();
}
}

View File

@@ -16,6 +16,8 @@
package com.android.settings.development;
import static android.hardware.display.DisplayManager.DISPLAY_CATEGORY_ALL_INCLUDING_DISABLED;
import static com.android.internal.display.RefreshRateSettingsUtils.DEFAULT_REFRESH_RATE;
import static com.android.settings.development.ForcePeakRefreshRatePreferenceController.NO_CONFIG;
@@ -24,19 +26,28 @@ import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.hardware.display.DisplayManager;
import android.platform.test.annotations.RequiresFlagsDisabled;
import android.platform.test.annotations.RequiresFlagsEnabled;
import android.platform.test.flag.junit.CheckFlagsRule;
import android.platform.test.flag.junit.DeviceFlagsValueProvider;
import android.provider.Settings;
import android.testing.TestableContext;
import android.view.Display;
import androidx.preference.PreferenceScreen;
import androidx.preference.SwitchPreference;
import androidx.test.platform.app.InstrumentationRegistry;
import com.android.server.display.feature.flags.Flags;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
@RunWith(RobolectricTestRunner.class)
@@ -46,14 +57,51 @@ public class ForcePeakRefreshRatePreferenceControllerTest {
private SwitchPreference mPreference;
@Mock
private PreferenceScreen mScreen;
@Mock
private DisplayManager mDisplayManagerMock;
@Mock
private Display mDisplayMock;
@Mock
private Display mDisplayMock2;
private Context mContext;
private ForcePeakRefreshRatePreferenceController mController;
@Rule
public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule();
@Rule
public final TestableContext mContext = new TestableContext(
InstrumentationRegistry.getInstrumentation().getContext());
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
mContext.addMockSystemService(DisplayManager.class, mDisplayManagerMock);
Display.Mode[] modes = new Display.Mode[]{
new Display.Mode(/* modeId= */ 0, /* width= */ 800, /* height= */ 600,
/* refreshRate= */ 60),
new Display.Mode(/* modeId= */ 0, /* width= */ 800, /* height= */ 600,
/* refreshRate= */ 120),
new Display.Mode(/* modeId= */ 0, /* width= */ 800, /* height= */ 600,
/* refreshRate= */ 90)
};
when(mDisplayManagerMock.getDisplay(Display.DEFAULT_DISPLAY)).thenReturn(mDisplayMock);
when(mDisplayMock.getSupportedModes()).thenReturn(modes);
Display.Mode[] modes2 = new Display.Mode[]{
new Display.Mode(/* modeId= */ 0, /* width= */ 800, /* height= */ 600,
/* refreshRate= */ 70),
new Display.Mode(/* modeId= */ 0, /* width= */ 800, /* height= */ 600,
/* refreshRate= */ 130),
new Display.Mode(/* modeId= */ 0, /* width= */ 800, /* height= */ 600,
/* refreshRate= */ 80)
};
when(mDisplayManagerMock.getDisplay(Display.DEFAULT_DISPLAY + 1)).thenReturn(mDisplayMock2);
when(mDisplayMock2.getSupportedModes()).thenReturn(modes2);
when(mDisplayManagerMock.getDisplays(DISPLAY_CATEGORY_ALL_INCLUDING_DISABLED))
.thenReturn(new Display[]{ mDisplayMock, mDisplayMock2 });
mController = new ForcePeakRefreshRatePreferenceController(mContext);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
when(mPreference.getKey()).thenReturn(mController.getPreferenceKey());
@@ -61,7 +109,19 @@ public class ForcePeakRefreshRatePreferenceControllerTest {
}
@Test
public void onPreferenceChange_preferenceChecked_shouldEnableForcePeak() {
@RequiresFlagsDisabled(Flags.FLAG_BACK_UP_SMOOTH_DISPLAY_AND_FORCE_PEAK_REFRESH_RATE)
public void onPreferenceChange_preferenceChecked_shouldEnableForcePeak_featureFlagOff() {
mController.mPeakRefreshRate = 88f;
mController.onPreferenceChange(mPreference, true);
assertThat(Settings.System.getFloat(mContext.getContentResolver(),
Settings.System.MIN_REFRESH_RATE, NO_CONFIG)).isEqualTo(88f);
}
@Test
@RequiresFlagsEnabled(Flags.FLAG_BACK_UP_SMOOTH_DISPLAY_AND_FORCE_PEAK_REFRESH_RATE)
public void onPreferenceChange_preferenceChecked_shouldEnableForcePeak_featureFlagOn() {
mController.mPeakRefreshRate = 88f;
mController.onPreferenceChange(mPreference, true);
@@ -88,6 +148,7 @@ public class ForcePeakRefreshRatePreferenceControllerTest {
mController.updateState(mPreference);
verify(mPreference).setChecked(true);
assertThat(mController.isForcePeakRefreshRateEnabled()).isTrue();
}
@Test
@@ -98,6 +159,7 @@ public class ForcePeakRefreshRatePreferenceControllerTest {
mController.updateState(mPreference);
verify(mPreference).setChecked(false);
assertThat(mController.isForcePeakRefreshRateEnabled()).isFalse();
}
@Test
@@ -129,4 +191,16 @@ public class ForcePeakRefreshRatePreferenceControllerTest {
assertThat(mPreference.isChecked()).isFalse();
assertThat(mPreference.isEnabled()).isFalse();
}
@Test
@RequiresFlagsDisabled(Flags.FLAG_BACK_UP_SMOOTH_DISPLAY_AND_FORCE_PEAK_REFRESH_RATE)
public void peakRefreshRate_highestOfDefaultDisplay_featureFlagOff() {
assertThat(mController.mPeakRefreshRate).isEqualTo(120);
}
@Test
@RequiresFlagsEnabled(Flags.FLAG_BACK_UP_SMOOTH_DISPLAY_AND_FORCE_PEAK_REFRESH_RATE)
public void peakRefreshRate_highestOfAllDisplays_featureFlagOn() {
assertThat(mController.mPeakRefreshRate).isEqualTo(130);
}
}

View File

@@ -0,0 +1,177 @@
/*
* 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.development;
import static com.android.settings.development.GameDefaultFrameRatePreferenceController.Injector;
import static com.android.settings.development.GameDefaultFrameRatePreferenceController.PROPERTY_DEBUG_GFX_GAME_DEFAULT_FRAME_RATE_DISABLED;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.app.IGameManagerService;
import android.content.Context;
import android.os.RemoteException;
import android.platform.test.flag.junit.SetFlagsRule;
import androidx.preference.PreferenceScreen;
import androidx.preference.TwoStatePreference;
import com.android.settings.flags.Flags;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentMatchers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
@RunWith(RobolectricTestRunner.class)
public class GameDefaultFrameRatePreferenceControllerTest {
@Mock
private Context mContext;
@Mock
private PreferenceScreen mScreen;
@Mock
private TwoStatePreference mPreference;
@Mock
private IGameManagerService mGameManagerService;
@Mock
private DevelopmentSystemPropertiesWrapper mSysPropsMock;
private GameDefaultFrameRatePreferenceController mController;
@Rule
public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
mController = new GameDefaultFrameRatePreferenceController(mContext, mGameManagerService,
new Injector(){
@Override
public DevelopmentSystemPropertiesWrapper createSystemPropertiesWrapper() {
return mSysPropsMock;
}
});
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
mController.displayPreference(mScreen);
}
@Test
public void onPreferenceChange_settingEnabled_shouldChecked() throws RemoteException {
mSetFlagsRule.enableFlags(Flags.FLAG_DEVELOPMENT_GAME_DEFAULT_FRAME_RATE);
assertTrue(mController.isAvailable());
when(mSysPropsMock.getBoolean(
ArgumentMatchers.eq(PROPERTY_DEBUG_GFX_GAME_DEFAULT_FRAME_RATE_DISABLED),
ArgumentMatchers.eq(false)))
.thenReturn(true);
mController.onPreferenceChange(mPreference, true /* new value */);
verify(mPreference).setChecked(true);
}
@Test
public void onPreferenceChange_settingDisabled_shouldUnchecked() throws RemoteException {
mSetFlagsRule.enableFlags(Flags.FLAG_DEVELOPMENT_GAME_DEFAULT_FRAME_RATE);
assertTrue(mController.isAvailable());
when(mSysPropsMock.getBoolean(
ArgumentMatchers.eq(PROPERTY_DEBUG_GFX_GAME_DEFAULT_FRAME_RATE_DISABLED),
ArgumentMatchers.eq(false)))
.thenReturn(false);
mController.onPreferenceChange(mPreference, false /* new value */);
verify(mPreference).setChecked(false);
}
@Test
public void updateState_settingEnabled_shouldChecked() throws RemoteException {
mSetFlagsRule.enableFlags(Flags.FLAG_DEVELOPMENT_GAME_DEFAULT_FRAME_RATE);
assertTrue(mController.isAvailable());
when(mSysPropsMock.getBoolean(
ArgumentMatchers.eq(PROPERTY_DEBUG_GFX_GAME_DEFAULT_FRAME_RATE_DISABLED),
ArgumentMatchers.eq(false)))
.thenReturn(true);
mController.updateState(mPreference);
verify(mPreference).setChecked(true);
}
@Test
public void updateState_settingDisabled_shouldUnchecked() throws RemoteException {
mSetFlagsRule.enableFlags(Flags.FLAG_DEVELOPMENT_GAME_DEFAULT_FRAME_RATE);
assertTrue(mController.isAvailable());
when(mSysPropsMock.getBoolean(
ArgumentMatchers.eq(PROPERTY_DEBUG_GFX_GAME_DEFAULT_FRAME_RATE_DISABLED),
ArgumentMatchers.eq(false)))
.thenReturn(false);
mController.updateState(mPreference);
verify(mPreference).setChecked(false);
}
@Test
public void settingNotAvailable_flagsOff() {
mSetFlagsRule.disableFlags(Flags.FLAG_DEVELOPMENT_GAME_DEFAULT_FRAME_RATE);
mController = new GameDefaultFrameRatePreferenceController(
mContext, mGameManagerService, new Injector());
assertFalse(mController.isAvailable());
}
@Test
public void settingAvailable_flagsOn() {
mSetFlagsRule.enableFlags(Flags.FLAG_DEVELOPMENT_GAME_DEFAULT_FRAME_RATE);
mController = new GameDefaultFrameRatePreferenceController(
mContext, mGameManagerService, new Injector());
assertTrue(mController.isAvailable());
}
@Test
public void onDeveloperOptionsSwitchDisabled_preferenceUnchecked_shouldNotTurnOffPreference()
throws RemoteException {
mSetFlagsRule.enableFlags(Flags.FLAG_DEVELOPMENT_GAME_DEFAULT_FRAME_RATE);
when(mSysPropsMock.getBoolean(
ArgumentMatchers.eq(PROPERTY_DEBUG_GFX_GAME_DEFAULT_FRAME_RATE_DISABLED),
ArgumentMatchers.eq(false)))
.thenReturn(false);
assertTrue(mController.isAvailable());
when(mPreference.isChecked()).thenReturn(false);
mController.onDeveloperOptionsSwitchDisabled();
verify(mPreference).setChecked(false);
verify(mPreference).setEnabled(false);
}
@Test
public void onDeveloperOptionsSwitchDisabled_preferenceChecked_shouldTurnOffPreference()
throws RemoteException {
mSetFlagsRule.enableFlags(Flags.FLAG_DEVELOPMENT_GAME_DEFAULT_FRAME_RATE);
when(mSysPropsMock.getBoolean(
ArgumentMatchers.eq(PROPERTY_DEBUG_GFX_GAME_DEFAULT_FRAME_RATE_DISABLED),
ArgumentMatchers.eq(false)))
.thenReturn(true);
assertTrue(mController.isAvailable());
when(mPreference.isChecked()).thenReturn(true);
mController.onDeveloperOptionsSwitchDisabled();
verify(mPreference).setChecked(false);
verify(mPreference).setEnabled(false);
}
}

View File

@@ -41,7 +41,8 @@ import androidx.preference.Preference;
import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceManager;
import androidx.preference.PreferenceScreen;
import androidx.preference.SwitchPreference;
import androidx.preference.SwitchPreferenceCompat;
import androidx.test.core.app.ApplicationProvider;
import com.android.internal.compat.CompatibilityChangeConfig;
import com.android.internal.compat.CompatibilityChangeInfo;
@@ -51,13 +52,13 @@ import com.android.internal.compat.OverrideAllowedState;
import com.android.settings.R;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import java.util.ArrayList;
import java.util.Arrays;
@@ -67,6 +68,8 @@ import java.util.Set;
@RunWith(RobolectricTestRunner.class)
public class PlatformCompatDashboardTest {
@Rule
public final MockitoRule mMockitoRule = MockitoJUnit.rule();
private PlatformCompatDashboard mDashboard;
@Mock
@@ -87,7 +90,6 @@ public class PlatformCompatDashboardTest {
@Before
public void setUp() throws RemoteException, NameNotFoundException {
MockitoAnnotations.initMocks(this);
mChanges = new CompatibilityChangeInfo[5];
mChanges[0] = new CompatibilityChangeInfo(
1L, "Default_Enabled", 0, 0, false, false, "", false);
@@ -104,7 +106,7 @@ public class PlatformCompatDashboardTest {
// By default, allow any change
when(mOverrideValidator.getOverrideAllowedState(anyLong(),anyString()))
.thenReturn(new OverrideAllowedState(ALLOWED, -1, -1));
mContext = spy(RuntimeEnvironment.application);
mContext = spy(ApplicationProvider.getApplicationContext());
mPreferenceManager = new PreferenceManager(mContext);
mPreferenceScreen = mPreferenceManager.createPreferenceScreen(mContext);
mApplicationInfo.packageName = APP_NAME;
@@ -141,7 +143,6 @@ public class PlatformCompatDashboardTest {
R.string.platform_compat_selected_app_summary, APP_NAME, 1));
}
@Ignore("b/313591873")
@Test
public void createPreferenceForChange_defaultEnabledChange_createCheckedEntry() {
CompatibilityChangeInfo enabledChange = mChanges[0];
@@ -152,15 +153,14 @@ public class PlatformCompatDashboardTest {
Preference enabledPreference = mDashboard.createPreferenceForChange(mContext, enabledChange,
config);
SwitchPreference enabledSwitchPreference = (SwitchPreference) enabledPreference;
SwitchPreferenceCompat enabledSwitchPreference = (SwitchPreferenceCompat) enabledPreference;
assertThat(enabledPreference.getSummary()).isEqualTo(mChanges[0].getName());
assertThat(enabledPreference instanceof SwitchPreference).isTrue();
assertThat(enabledPreference instanceof SwitchPreferenceCompat).isTrue();
assertThat(enabledSwitchPreference.isChecked()).isTrue();
assertThat(enabledSwitchPreference.isEnabled()).isTrue();
}
@Ignore("b/313591873")
@Test
public void createPreferenceForChange_defaultDisabledChange_createUncheckedEntry() {
CompatibilityChangeInfo disabledChange = mChanges[1];
@@ -172,12 +172,12 @@ public class PlatformCompatDashboardTest {
disabledChange, config);
assertThat(disabledPreference.getSummary()).isEqualTo(mChanges[1].getName());
SwitchPreference disabledSwitchPreference = (SwitchPreference) disabledPreference;
SwitchPreferenceCompat disabledSwitchPreference =
(SwitchPreferenceCompat) disabledPreference;
assertThat(disabledSwitchPreference.isChecked()).isFalse();
assertThat(disabledSwitchPreference.isEnabled()).isTrue();
}
@Ignore("b/313591873")
@Test
public void createPreferenceForChange_cannotOverride_createDisabledEntry()
throws RemoteException {
@@ -191,15 +191,14 @@ public class PlatformCompatDashboardTest {
Preference preference = mDashboard.createPreferenceForChange(mContext, enabledChange,
config);
SwitchPreference switchPreference = (SwitchPreference) preference;
SwitchPreferenceCompat switchPreference = (SwitchPreferenceCompat) preference;
assertThat(preference.getSummary()).isEqualTo(mChanges[0].getName());
assertThat(preference instanceof SwitchPreference).isTrue();
assertThat(preference instanceof SwitchPreferenceCompat).isTrue();
assertThat(switchPreference.isChecked()).isTrue();
assertThat(switchPreference.isEnabled()).isFalse();
}
@Ignore("b/313591873")
@Test
public void createChangeCategoryPreference_enabledAndDisabled_hasTitleAndEntries() {
Set<Long> enabledChanges = new HashSet<>();
@@ -226,7 +225,7 @@ public class PlatformCompatDashboardTest {
assertThat(category.getPreferenceCount()).isEqualTo(mChanges.length);
for (int i = 0; i < mChanges.length; ++i) {
Preference childPreference = category.getPreference(i);
assertThat(childPreference instanceof SwitchPreference).isTrue();
assertThat(childPreference instanceof SwitchPreferenceCompat).isTrue();
}
}
}

View File

@@ -43,6 +43,7 @@ import androidx.preference.PreferenceScreen;
import com.android.settings.R;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -52,6 +53,7 @@ import org.robolectric.RuntimeEnvironment;
import java.util.Arrays;
@Ignore("b/317934814")
@RunWith(RobolectricTestRunner.class)
public class GraphicsDriverAppPreferenceControllerTest {