Add ResultPayload for always-on ambient display.
am: eb1a45b95b
Change-Id: Ie00201adc19b7da516e3bb64fe857a17f8282d28
This commit is contained in:
@@ -15,21 +15,26 @@
|
||||
*/
|
||||
package com.android.settings.display;
|
||||
|
||||
import static android.provider.Settings.Secure.DOZE_ALWAYS_ON;
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.Settings;
|
||||
import android.support.v14.preference.SwitchPreference;
|
||||
import android.support.v7.preference.Preference;
|
||||
|
||||
import com.android.internal.hardware.AmbientDisplayConfiguration;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.PreferenceController;
|
||||
import com.android.settings.search.DatabaseIndexingUtils;
|
||||
import com.android.settings.search.InlineSwitchPayload;
|
||||
import com.android.settings.search.ResultPayload;
|
||||
|
||||
public class AmbientDisplayAlwaysOnPreferenceController extends PreferenceController
|
||||
implements Preference.OnPreferenceChangeListener {
|
||||
|
||||
private final int ON = 1;
|
||||
private final int OFF = 0;
|
||||
|
||||
private static final String KEY_ALWAYS_ON = "ambient_display_always_on";
|
||||
private static final int MY_USER = UserHandle.myUserId();
|
||||
|
||||
@@ -59,8 +64,9 @@ public class AmbientDisplayAlwaysOnPreferenceController extends PreferenceContro
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
int enabled = (boolean) newValue ? 1 : 0;
|
||||
Settings.Secure.putInt(mContext.getContentResolver(), DOZE_ALWAYS_ON, enabled);
|
||||
int enabled = (boolean) newValue ? ON : OFF;
|
||||
Settings.Secure.putInt(
|
||||
mContext.getContentResolver(), Settings.Secure.DOZE_ALWAYS_ON, enabled);
|
||||
if (mCallback != null) {
|
||||
mCallback.onPreferenceChanged();
|
||||
}
|
||||
@@ -71,4 +77,14 @@ public class AmbientDisplayAlwaysOnPreferenceController extends PreferenceContro
|
||||
public boolean isAvailable() {
|
||||
return mConfig.alwaysOnAvailable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultPayload getResultPayload() {
|
||||
final Intent intent = DatabaseIndexingUtils.buildSubsettingIntent(mContext,
|
||||
AmbientDisplaySettings.class.getName(), KEY_ALWAYS_ON,
|
||||
mContext.getString(R.string.ambient_display_screen_title));
|
||||
|
||||
return new InlineSwitchPayload(Settings.Secure.DOZE_ALWAYS_ON,
|
||||
ResultPayload.SettingsSource.SECURE, ON, intent, isAvailable());
|
||||
}
|
||||
}
|
||||
|
@@ -22,13 +22,16 @@ import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.provider.Settings;
|
||||
import android.support.v14.preference.SwitchPreference;
|
||||
|
||||
import com.android.internal.hardware.AmbientDisplayConfiguration;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.search.InlinePayload;
|
||||
import com.android.settings.search.InlineSwitchPayload;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.ShadowSecureSettings;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -115,4 +118,34 @@ public class AmbientDisplayAlwaysOnPreferenceControllerTest {
|
||||
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPreferenceController_ProperResultPayloadType() {
|
||||
assertThat(mController.getResultPayload()).isInstanceOf(InlineSwitchPayload.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = ShadowSecureSettings.class)
|
||||
public void testSetValue_updatesCorrectly() {
|
||||
int newValue = 1;
|
||||
ContentResolver resolver = mContext.getContentResolver();
|
||||
Settings.Secure.putInt(resolver, Settings.Secure.DOZE_ALWAYS_ON, 0);
|
||||
|
||||
((InlinePayload) mController.getResultPayload()).setValue(mContext, newValue);
|
||||
int updatedValue = Settings.Secure.getInt(resolver, Settings.Secure.DOZE_ALWAYS_ON, -1);
|
||||
|
||||
assertThat(updatedValue).isEqualTo(newValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = ShadowSecureSettings.class)
|
||||
public void testGetValue_correctValueReturned() {
|
||||
int currentValue = 1;
|
||||
ContentResolver resolver = mContext.getContentResolver();
|
||||
Settings.Secure.putInt(resolver, Settings.Secure.DOZE_ALWAYS_ON, currentValue);
|
||||
|
||||
int newValue = ((InlinePayload) mController.getResultPayload()).getValue(mContext);
|
||||
|
||||
assertThat(newValue).isEqualTo(currentValue);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user