Merge "Refine fold setting" into udc-qpr-dev am: 26e14e09bf

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/24314953

Change-Id: Iaf6c0514a406267de5924672b1e879a4dce3ce4a
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Shivangi Dubey
2023-09-06 15:06:39 +00:00
committed by Automerger Merge Worker
10 changed files with 427 additions and 208 deletions

View File

@@ -0,0 +1,68 @@
/*
* 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.display;
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.content.res.Resources;
import com.android.internal.R;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
@RunWith(RobolectricTestRunner.class)
public class FoldLockBehaviorPreferenceControllerTest {
@Mock
private Resources mResources;
private Context mContext;
private FoldLockBehaviorPreferenceController mController;
@Before
public void setUp() {
mContext = RuntimeEnvironment.application;
mResources = Mockito.mock(Resources.class);
mController = new FoldLockBehaviorPreferenceController(mContext, "key", mResources);
}
@Test
public void getAvailabilityStatus_withConfigNoShow_returnUnsupported() {
when(mResources.getBoolean(R.bool.config_fold_lock_behavior)).thenReturn(false);
assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
}
@Test
public void getAvailabilityStatus_withConfigNoShow_returnAvailable() {
when(mResources.getBoolean(R.bool.config_fold_lock_behavior)).thenReturn(true);
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
}
}

View File

@@ -0,0 +1,82 @@
/*
* 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.display;
import static android.provider.Settings.System.FOLD_LOCK_BEHAVIOR;
import static com.google.common.truth.Truth.assertThat;
import android.content.Context;
import android.os.UserHandle;
import android.provider.Settings;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
@RunWith(RobolectricTestRunner.class)
public class FoldLockBehaviorSettingsTest {
private Context mContext;
private FoldLockBehaviorSettings mSetting;
@Before
public void setUp() {
mContext = RuntimeEnvironment.application;
mSetting = new FoldLockBehaviorSettings();
mSetting.onAttach(mContext);
}
@Test
public void getDefaultKey_returnFoldSetting() {
setFoldSetting("stay_awake_on_fold_key");
String key = mSetting.getDefaultKey();
assertThat(key).isEqualTo("stay_awake_on_fold_key");
}
@Test
public void setDefaultKey_returnFoldSetting() {
mSetting.setDefaultKey("stay_awake_on_fold_key");
String key = getFoldSettingValue();
assertThat(key).isEqualTo("stay_awake_on_fold_key");
}
@Test
public void setInvalidDefaultKey_returnDefaultFoldSetting() {
setFoldSetting("invalid_fold_lock_behavior_key");
String key = mSetting.getDefaultKey();
assertThat(key).isEqualTo("selective_stay_awake_key");
}
private void setFoldSetting(String selectedSetting) {
Settings.System.putStringForUser(mContext.getContentResolver(),
FOLD_LOCK_BEHAVIOR, selectedSetting, UserHandle.USER_CURRENT);
}
private String getFoldSettingValue() {
return Settings.System.getStringForUser(mContext.getContentResolver(),
FOLD_LOCK_BEHAVIOR, UserHandle.USER_CURRENT);
}
}

View File

@@ -1,119 +0,0 @@
/*
* 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.display;
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.content.res.Resources;
import android.provider.Settings;
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.Mockito;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
@RunWith(RobolectricTestRunner.class)
public class StayAwakeOnFoldPreferenceControllerTest {
@Mock
private Resources mResources;
private Context mContext;
private StayAwakeOnFoldPreferenceController mController;
@Before
public void setUp() {
mContext = RuntimeEnvironment.application;
mResources = Mockito.mock(Resources.class);
mController = new StayAwakeOnFoldPreferenceController(mContext, "key", mResources);
}
@Test
public void getAvailabilityStatus_withConfigNoShow_returnUnsupported() {
when(mResources.getBoolean(R.bool.config_stay_awake_on_fold)).thenReturn(false);
assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
}
@Test
public void getAvailabilityStatus_withConfigNoShow_returnAvailable() {
when(mResources.getBoolean(R.bool.config_stay_awake_on_fold)).thenReturn(true);
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
}
@Test
public void setChecked_enableStayAwakeOnFold_setChecked() {
mController.setChecked(true);
assertThat(isStayAwakeOnFoldEnabled())
.isTrue();
}
@Test
public void setChecked_disableStayAwakeOnFold_setUnchecked() {
mController.setChecked(false);
assertThat(isStayAwakeOnFoldEnabled())
.isFalse();
}
@Test
public void isChecked_enableStayAwakeOnFold_returnTrue() {
enableStayAwakeOnFoldPreference();
assertThat(mController.isChecked()).isTrue();
}
@Test
public void isChecked_disableStayAwakeOnFold_returnFalse() {
disableStayAwakeOnFoldPreference();
assertThat(mController.isChecked()).isFalse();
}
private void enableStayAwakeOnFoldPreference() {
Settings.System.putInt(
mContext.getContentResolver(),
Settings.System.STAY_AWAKE_ON_FOLD,
1);
}
private void disableStayAwakeOnFoldPreference() {
Settings.System.putInt(
mContext.getContentResolver(),
Settings.System.STAY_AWAKE_ON_FOLD,
0);
}
private boolean isStayAwakeOnFoldEnabled() {
return (Settings.System.getInt(
mContext.getContentResolver(),
Settings.System.STAY_AWAKE_ON_FOLD,
0) == 1);
}
}