<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2015 The CyanogenMod Project
+ 2018-2019 The LineageOS Project
Licensed under the Apache License, Version 2.0 (the "License"
you may not use this file except in compliance with the License.
-->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
+ <SwitchPreference
+ android:key="always_on_display"
+ android:defaultValue="false"
+ android:disableDependentsState="true"
+ android:title="@string/ambient_display_always_on_title"
+ android:summary="@string/ambient_display_always_on_summary" />
+
<PreferenceCategory
android:key="proximity_sensor"
android:title="@string/proximity_sensor_title">
/*
* Copyright (C) 2015 The CyanogenMod Project
+ * 2017-2019 The LineageOS Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
private TextView mTextView;
private View mSwitchBar;
+ private SwitchPreference mAlwaysOnDisplayPreference;
private SwitchPreference mHandwavePreference;
private SwitchPreference mPocketPreference;
boolean dozeEnabled = Utils.isDozeEnabled(getActivity());
+ mAlwaysOnDisplayPreference = findPreference(Utils.ALWAYS_ON_DISPLAY);
+ mAlwaysOnDisplayPreference.setEnabled(dozeEnabled);
+ mAlwaysOnDisplayPreference.setOnPreferenceChangeListener(this);
+
mHandwavePreference = findPreference(Utils.GESTURE_HAND_WAVE_KEY);
mHandwavePreference.setEnabled(dozeEnabled);
mHandwavePreference.setOnPreferenceChangeListener(this);
mPocketPreference = findPreference(Utils.GESTURE_POCKET_KEY);
mPocketPreference.setEnabled(dozeEnabled);
mPocketPreference.setOnPreferenceChangeListener(this);
+
+ // Hide AOD if not supported and set all its dependents otherwise
+ if (!Utils.alwaysOnDisplayAvailable(getActivity())) {
+ getPreferenceScreen().removePreference(mAlwaysOnDisplayPreference);
+ } else {
+ mHandwavePreference.setDependency(Utils.ALWAYS_ON_DISPLAY);
+ mPocketPreference.setDependency(Utils.ALWAYS_ON_DISPLAY);
+ }
}
@Override
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
- Utils.enableGesture(getActivity(), preference.getKey(), (Boolean) newValue);
+ if (Utils.ALWAYS_ON_DISPLAY.equals(preference.getKey())) {
+ Utils.enableAlwaysOn(getActivity(), (Boolean) newValue);
+ } else {
+ Utils.enableGesture(getActivity(), preference.getKey(), (Boolean) newValue);
+ }
+
Utils.checkDozeService(getActivity());
return true;
mTextView.setText(getString(isChecked ? R.string.switch_bar_on : R.string.switch_bar_off));
mSwitchBar.setActivated(isChecked);
+ if (!isChecked) {
+ Utils.enableAlwaysOn(getActivity(), false);
+ mAlwaysOnDisplayPreference.setChecked(false);
+ }
+ mAlwaysOnDisplayPreference.setEnabled(isChecked);
+
mHandwavePreference.setEnabled(isChecked);
mPocketPreference.setEnabled(isChecked);
}
package org.lineageos.settings.doze;
+import static android.provider.Settings.Secure.DOZE_ALWAYS_ON;
import static android.provider.Settings.Secure.DOZE_ENABLED;
import android.content.Context;
import android.content.Intent;
+import android.hardware.display.AmbientDisplayConfiguration;
import android.os.UserHandle;
import android.provider.Settings;
import android.util.Log;
private static final String TAG = "DozeUtils";
private static final boolean DEBUG = false;
+ protected static final String ALWAYS_ON_DISPLAY = "always_on_display";
+
protected static final String GESTURE_HAND_WAVE_KEY = "gesture_hand_wave";
protected static final String GESTURE_POCKET_KEY = "gesture_pocket";
}
protected static void checkDozeService(Context context) {
- if (isDozeEnabled(context) && isAnyGestureEnabled(context)) {
+ if (!isAlwaysOnEnabled(context) &&
+ isDozeEnabled(context) && isAnyGestureEnabled(context)) {
startService(context);
} else {
stopService(context);
}
}
+ protected static boolean alwaysOnDisplayAvailable(Context context) {
+ return new AmbientDisplayConfiguration(context).alwaysOnAvailable();
+ }
+
+ private static boolean isAlwaysOnEnabled(Context context) {
+ return Settings.Secure.getIntForUser(context.getContentResolver(),
+ DOZE_ALWAYS_ON, 1, UserHandle.USER_CURRENT) != 0;
+ }
+
protected static boolean isDozeEnabled(Context context) {
return Settings.Secure.getInt(context.getContentResolver(),
DOZE_ENABLED, 1) != 0;
}
+ protected static boolean enableAlwaysOn(Context context, boolean enable) {
+ return Settings.Secure.putIntForUser(context.getContentResolver(),
+ DOZE_ALWAYS_ON, enable ? 1 : 0, UserHandle.USER_CURRENT);
+ }
+
protected static boolean enableDoze(Context context, boolean enable) {
return Settings.Secure.putInt(context.getContentResolver(),
DOZE_ENABLED, enable ? 1 : 0);