AOD: Add temporary always-on setting
Adds a setting for controlling always-on ambient display until the new ambient display settings screen is implemented. Also updates DozePreferenceController to use the the AmbientDisplayConfiguration helper instead of recreating that logic. Also adds tests for both doze preference controllers. Bug: 33279975 Test: Toggle "Settings > Display > Always on", verify ambient display is on / off Test: make RunSettingsRoboTests Change-Id: If36356bc29329a4e0732e79db662ffb02c9fc189
This commit is contained in:
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.provider.Settings;
|
||||
import android.support.v14.preference.SwitchPreference;
|
||||
|
||||
import com.android.internal.hardware.AmbientDisplayConfiguration;
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.shadow.ShadowSecureSettings;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
|
||||
shadows = {ShadowSecureSettings.class})
|
||||
public class DozeAlwaysOnPreferenceControllerTest {
|
||||
|
||||
@Mock Context mContext;
|
||||
@Mock AmbientDisplayConfiguration mConfig;
|
||||
@Mock SwitchPreference mSwitchPreference;
|
||||
|
||||
DozeAlwaysOnPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mController = new DozeAlwaysOnPreferenceController(mContext, mConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_enabled() throws Exception {
|
||||
when(mConfig.alwaysOnEnabled(anyInt()))
|
||||
.thenReturn(true);
|
||||
|
||||
mController.updateState(mSwitchPreference);
|
||||
|
||||
verify(mSwitchPreference).setChecked(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_disabled() throws Exception {
|
||||
when(mConfig.alwaysOnEnabled(anyInt()))
|
||||
.thenReturn(false);
|
||||
|
||||
mController.updateState(mSwitchPreference);
|
||||
|
||||
verify(mSwitchPreference).setChecked(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPreferenceChange_enable() throws Exception {
|
||||
mController.onPreferenceChange(mSwitchPreference, true);
|
||||
|
||||
assertThat(Settings.Secure.getInt(null, Settings.Secure.DOZE_ALWAYS_ON, -1))
|
||||
.isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPreferenceChange_disable() throws Exception {
|
||||
mController.onPreferenceChange(mSwitchPreference, false);
|
||||
|
||||
assertThat(Settings.Secure.getInt(null, Settings.Secure.DOZE_ALWAYS_ON, -1))
|
||||
.isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_available() throws Exception {
|
||||
when(mConfig.alwaysOnAvailable())
|
||||
.thenReturn(true);
|
||||
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_unavailable() throws Exception {
|
||||
when(mConfig.alwaysOnAvailable())
|
||||
.thenReturn(false);
|
||||
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
}
|
@@ -0,0 +1,134 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.internal.logging.nano.MetricsProto.MetricsEvent.ACTION_AMBIENT_DISPLAY;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.provider.Settings;
|
||||
import android.support.v14.preference.SwitchPreference;
|
||||
|
||||
import com.android.internal.hardware.AmbientDisplayConfiguration;
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
|
||||
import com.android.settings.testutils.shadow.ShadowSecureSettings;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
|
||||
shadows = {ShadowSecureSettings.class})
|
||||
public class DozePreferenceControllerTest {
|
||||
|
||||
@Mock Context mContext;
|
||||
@Mock AmbientDisplayConfiguration mConfig;
|
||||
@Mock SwitchPreference mSwitchPreference;
|
||||
@Mock MetricsFeatureProvider mMetricsFeatureProvider;
|
||||
|
||||
DozePreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mController = new DozePreferenceController(mContext, mConfig, mMetricsFeatureProvider);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_enabled() throws Exception {
|
||||
when(mConfig.pulseOnNotificationEnabled(anyInt()))
|
||||
.thenReturn(true);
|
||||
|
||||
mController.updateState(mSwitchPreference);
|
||||
|
||||
verify(mSwitchPreference).setChecked(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_disabled() throws Exception {
|
||||
when(mConfig.pulseOnNotificationEnabled(anyInt()))
|
||||
.thenReturn(false);
|
||||
|
||||
mController.updateState(mSwitchPreference);
|
||||
|
||||
verify(mSwitchPreference).setChecked(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPreferenceChange_enable() throws Exception {
|
||||
mController.onPreferenceChange(mSwitchPreference, true);
|
||||
|
||||
assertThat(Settings.Secure.getInt(null, Settings.Secure.DOZE_ENABLED, -1))
|
||||
.isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPreferenceChange_disable() throws Exception {
|
||||
mController.onPreferenceChange(mSwitchPreference, false);
|
||||
|
||||
assertThat(Settings.Secure.getInt(null, Settings.Secure.DOZE_ENABLED, -1))
|
||||
.isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_available() throws Exception {
|
||||
when(mConfig.pulseOnNotificationAvailable())
|
||||
.thenReturn(true);
|
||||
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_unavailable() throws Exception {
|
||||
when(mConfig.pulseOnNotificationAvailable())
|
||||
.thenReturn(false);
|
||||
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handlePreferenceTreeClick_reportsEventForItsPreference() throws Exception {
|
||||
when(mSwitchPreference.getKey()).thenReturn(DozePreferenceController.KEY_DOZE);
|
||||
|
||||
mController.handlePreferenceTreeClick(mSwitchPreference);
|
||||
|
||||
verify(mMetricsFeatureProvider).action(any(), eq(ACTION_AMBIENT_DISPLAY));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handlePreferenceTreeClick_doesntReportEventForOtherPreferences() throws Exception {
|
||||
when(mSwitchPreference.getKey()).thenReturn("some_other_key");
|
||||
|
||||
mController.handlePreferenceTreeClick(mSwitchPreference);
|
||||
|
||||
verifyNoMoreInteractions(mMetricsFeatureProvider);
|
||||
}
|
||||
}
|
@@ -258,7 +258,7 @@ public class DatabaseIndexingManagerTest {
|
||||
SearchIndexableResource resource = getFakeResource(R.xml.display_settings);
|
||||
mManager.indexOneSearchIndexableData(mDb, localeStr, resource, new HashMap<>());
|
||||
Cursor cursor = mDb.rawQuery("SELECT * FROM prefs_index", null);
|
||||
assertThat(cursor.getCount()).isEqualTo(18);
|
||||
assertThat(cursor.getCount()).isEqualTo(19);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -273,7 +273,7 @@ public class DatabaseIndexingManagerTest {
|
||||
Cursor cursor = mDb.rawQuery("SELECT * FROM prefs_index WHERE enabled = 0", null);
|
||||
assertThat(cursor.getCount()).isEqualTo(2);
|
||||
cursor = mDb.rawQuery("SELECT * FROM prefs_index WHERE enabled = 1", null);
|
||||
assertThat(cursor.getCount()).isEqualTo(16);
|
||||
assertThat(cursor.getCount()).isEqualTo(17);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Reference in New Issue
Block a user