samsung: doze: Add AOD support to Ambient Display

* This makes the always on display mode feature visible for those
   devices that explicitly set it as available via AOSP overlay.
   Should only be enabled on devices where the display has been tuned
   to be power efficient in DOZE and/or DOZE_SUSPEND states.

Change-Id: If543936f9421dd7a6c0be594f7cb76afb227e34b
tirimbino
Bruno Martins 6 years ago
parent cc3bed76b0
commit 42ed17551b
  1. 8
      doze/res/xml/gesture_panel.xml
  2. 25
      doze/src/org/lineageos/settings/doze/SamsungDozeSettings.java
  3. 21
      doze/src/org/lineageos/settings/doze/Utils.java

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<!-- <!--
Copyright (C) 2015 The CyanogenMod Project Copyright (C) 2015 The CyanogenMod Project
2018-2019 The LineageOS Project
Licensed under the Apache License, Version 2.0 (the "License" Licensed under the Apache License, Version 2.0 (the "License"
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -16,6 +17,13 @@
--> -->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> <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 <PreferenceCategory
android:key="proximity_sensor" android:key="proximity_sensor"
android:title="@string/proximity_sensor_title"> android:title="@string/proximity_sensor_title">

@ -1,5 +1,6 @@
/* /*
* Copyright (C) 2015 The CyanogenMod Project * Copyright (C) 2015 The CyanogenMod Project
* 2017-2019 The LineageOS Project
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -38,6 +39,7 @@ public class SamsungDozeSettings extends PreferenceFragment
private TextView mTextView; private TextView mTextView;
private View mSwitchBar; private View mSwitchBar;
private SwitchPreference mAlwaysOnDisplayPreference;
private SwitchPreference mHandwavePreference; private SwitchPreference mHandwavePreference;
private SwitchPreference mPocketPreference; private SwitchPreference mPocketPreference;
@ -49,6 +51,10 @@ public class SamsungDozeSettings extends PreferenceFragment
boolean dozeEnabled = Utils.isDozeEnabled(getActivity()); 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 = findPreference(Utils.GESTURE_HAND_WAVE_KEY);
mHandwavePreference.setEnabled(dozeEnabled); mHandwavePreference.setEnabled(dozeEnabled);
mHandwavePreference.setOnPreferenceChangeListener(this); mHandwavePreference.setOnPreferenceChangeListener(this);
@ -56,6 +62,14 @@ public class SamsungDozeSettings extends PreferenceFragment
mPocketPreference = findPreference(Utils.GESTURE_POCKET_KEY); mPocketPreference = findPreference(Utils.GESTURE_POCKET_KEY);
mPocketPreference.setEnabled(dozeEnabled); mPocketPreference.setEnabled(dozeEnabled);
mPocketPreference.setOnPreferenceChangeListener(this); 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
@ -100,7 +114,12 @@ public class SamsungDozeSettings extends PreferenceFragment
@Override @Override
public boolean onPreferenceChange(Preference preference, Object newValue) { public boolean onPreferenceChange(Preference preference, Object newValue) {
if (Utils.ALWAYS_ON_DISPLAY.equals(preference.getKey())) {
Utils.enableAlwaysOn(getActivity(), (Boolean) newValue);
} else {
Utils.enableGesture(getActivity(), preference.getKey(), (Boolean) newValue); Utils.enableGesture(getActivity(), preference.getKey(), (Boolean) newValue);
}
Utils.checkDozeService(getActivity()); Utils.checkDozeService(getActivity());
return true; return true;
@ -114,6 +133,12 @@ public class SamsungDozeSettings extends PreferenceFragment
mTextView.setText(getString(isChecked ? R.string.switch_bar_on : R.string.switch_bar_off)); mTextView.setText(getString(isChecked ? R.string.switch_bar_on : R.string.switch_bar_off));
mSwitchBar.setActivated(isChecked); mSwitchBar.setActivated(isChecked);
if (!isChecked) {
Utils.enableAlwaysOn(getActivity(), false);
mAlwaysOnDisplayPreference.setChecked(false);
}
mAlwaysOnDisplayPreference.setEnabled(isChecked);
mHandwavePreference.setEnabled(isChecked); mHandwavePreference.setEnabled(isChecked);
mPocketPreference.setEnabled(isChecked); mPocketPreference.setEnabled(isChecked);
} }

@ -17,10 +17,12 @@
package org.lineageos.settings.doze; package org.lineageos.settings.doze;
import static android.provider.Settings.Secure.DOZE_ALWAYS_ON;
import static android.provider.Settings.Secure.DOZE_ENABLED; import static android.provider.Settings.Secure.DOZE_ENABLED;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.hardware.display.AmbientDisplayConfiguration;
import android.os.UserHandle; import android.os.UserHandle;
import android.provider.Settings; import android.provider.Settings;
import android.util.Log; import android.util.Log;
@ -32,6 +34,8 @@ public final class Utils {
private static final String TAG = "DozeUtils"; private static final String TAG = "DozeUtils";
private static final boolean DEBUG = false; 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_HAND_WAVE_KEY = "gesture_hand_wave";
protected static final String GESTURE_POCKET_KEY = "gesture_pocket"; protected static final String GESTURE_POCKET_KEY = "gesture_pocket";
@ -48,18 +52,33 @@ public final class Utils {
} }
protected static void checkDozeService(Context context) { protected static void checkDozeService(Context context) {
if (isDozeEnabled(context) && isAnyGestureEnabled(context)) { if (!isAlwaysOnEnabled(context) &&
isDozeEnabled(context) && isAnyGestureEnabled(context)) {
startService(context); startService(context);
} else { } else {
stopService(context); 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) { protected static boolean isDozeEnabled(Context context) {
return Settings.Secure.getInt(context.getContentResolver(), return Settings.Secure.getInt(context.getContentResolver(),
DOZE_ENABLED, 1) != 0; 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) { protected static boolean enableDoze(Context context, boolean enable) {
return Settings.Secure.putInt(context.getContentResolver(), return Settings.Secure.putInt(context.getContentResolver(),
DOZE_ENABLED, enable ? 1 : 0); DOZE_ENABLED, enable ? 1 : 0);

Loading…
Cancel
Save