sdm845-common: 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
This commit is contained in:
parent
8e87bbae81
commit
ea2cc87e51
3 changed files with 67 additions and 5 deletions
|
@ -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:disableDependentsState="true"
|
||||||
|
android:title="@string/ambient_display_always_on_title"
|
||||||
|
android:summary="@string/ambient_display_always_on_summary"
|
||||||
|
android:persistent="false" />
|
||||||
|
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
android:key="pickup_sensor"
|
android:key="pickup_sensor"
|
||||||
android:title="@string/pickup_sensor_title">
|
android:title="@string/pickup_sensor_title">
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2015 The CyanogenMod Project
|
* Copyright (C) 2015 The CyanogenMod Project
|
||||||
* 2017-2018 The LineageOS 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.
|
||||||
|
@ -29,6 +29,7 @@ import android.os.Bundle;
|
||||||
import android.support.v14.preference.PreferenceFragment;
|
import android.support.v14.preference.PreferenceFragment;
|
||||||
import android.support.v14.preference.SwitchPreference;
|
import android.support.v14.preference.SwitchPreference;
|
||||||
import android.support.v7.preference.Preference;
|
import android.support.v7.preference.Preference;
|
||||||
|
import android.support.v7.preference.PreferenceCategory;
|
||||||
import android.support.v7.preference.Preference.OnPreferenceChangeListener;
|
import android.support.v7.preference.Preference.OnPreferenceChangeListener;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
@ -44,6 +45,8 @@ public class DozeSettingsFragment extends PreferenceFragment implements OnPrefer
|
||||||
private TextView mTextView;
|
private TextView mTextView;
|
||||||
private View mSwitchBar;
|
private View mSwitchBar;
|
||||||
|
|
||||||
|
private SwitchPreference mAlwaysOnDisplayPreference;
|
||||||
|
|
||||||
private SwitchPreference mPickUpPreference;
|
private SwitchPreference mPickUpPreference;
|
||||||
private SwitchPreference mPocketPreference;
|
private SwitchPreference mPocketPreference;
|
||||||
|
|
||||||
|
@ -61,6 +64,16 @@ public class DozeSettingsFragment extends PreferenceFragment implements OnPrefer
|
||||||
|
|
||||||
boolean dozeEnabled = Utils.isDozeEnabled(getActivity());
|
boolean dozeEnabled = Utils.isDozeEnabled(getActivity());
|
||||||
|
|
||||||
|
mAlwaysOnDisplayPreference = (SwitchPreference) findPreference(Utils.ALWAYS_ON_DISPLAY);
|
||||||
|
mAlwaysOnDisplayPreference.setEnabled(dozeEnabled);
|
||||||
|
mAlwaysOnDisplayPreference.setChecked(Utils.isAlwaysOnEnabled(getActivity()));
|
||||||
|
mAlwaysOnDisplayPreference.setOnPreferenceChangeListener(this);
|
||||||
|
|
||||||
|
PreferenceCategory pickupSensorCategory = (PreferenceCategory) getPreferenceScreen().
|
||||||
|
findPreference(Utils.CATEG_PICKUP_SENSOR);
|
||||||
|
PreferenceCategory proximitySensorCategory = (PreferenceCategory) getPreferenceScreen().
|
||||||
|
findPreference(Utils.CATEG_PROX_SENSOR);
|
||||||
|
|
||||||
mPickUpPreference = (SwitchPreference) findPreference(Utils.GESTURE_PICK_UP_KEY);
|
mPickUpPreference = (SwitchPreference) findPreference(Utils.GESTURE_PICK_UP_KEY);
|
||||||
mPickUpPreference.setEnabled(dozeEnabled);
|
mPickUpPreference.setEnabled(dozeEnabled);
|
||||||
mPickUpPreference.setOnPreferenceChangeListener(this);
|
mPickUpPreference.setOnPreferenceChangeListener(this);
|
||||||
|
@ -68,6 +81,14 @@ public class DozeSettingsFragment extends PreferenceFragment implements OnPrefer
|
||||||
mPocketPreference = (SwitchPreference) findPreference(Utils.GESTURE_POCKET_KEY);
|
mPocketPreference = (SwitchPreference) 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 {
|
||||||
|
pickupSensorCategory.setDependency(Utils.ALWAYS_ON_DISPLAY);
|
||||||
|
proximitySensorCategory.setDependency(Utils.ALWAYS_ON_DISPLAY);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -101,8 +122,13 @@ public class DozeSettingsFragment extends PreferenceFragment implements OnPrefer
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
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());
|
Utils.checkDozeService(getActivity());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,6 +140,12 @@ public class DozeSettingsFragment extends PreferenceFragment implements OnPrefer
|
||||||
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);
|
||||||
|
|
||||||
mPickUpPreference.setEnabled(isChecked);
|
mPickUpPreference.setEnabled(isChecked);
|
||||||
mPocketPreference.setEnabled(isChecked);
|
mPocketPreference.setEnabled(isChecked);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2015 The CyanogenMod Project
|
* Copyright (C) 2015 The CyanogenMod Project
|
||||||
* 2017-2018 The LineageOS 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.
|
||||||
|
@ -26,6 +26,9 @@ import android.support.v7.preference.PreferenceManager;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.android.internal.hardware.AmbientDisplayConfiguration;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
public final class Utils {
|
public final class Utils {
|
||||||
|
@ -35,6 +38,11 @@ public final class Utils {
|
||||||
|
|
||||||
private static final String DOZE_INTENT = "com.android.systemui.doze.pulse";
|
private static final String DOZE_INTENT = "com.android.systemui.doze.pulse";
|
||||||
|
|
||||||
|
protected static final String ALWAYS_ON_DISPLAY = "always_on_display";
|
||||||
|
|
||||||
|
protected static final String CATEG_PICKUP_SENSOR = "pickup_sensor";
|
||||||
|
protected static final String CATEG_PROX_SENSOR = "proximity_sensor";
|
||||||
|
|
||||||
protected static final String GESTURE_PICK_UP_KEY = "gesture_pick_up";
|
protected static final String GESTURE_PICK_UP_KEY = "gesture_pick_up";
|
||||||
protected static final String GESTURE_POCKET_KEY = "gesture_pocket";
|
protected static final String GESTURE_POCKET_KEY = "gesture_pocket";
|
||||||
|
|
||||||
|
@ -51,7 +59,7 @@ public final class Utils {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static void checkDozeService(Context context) {
|
protected static void checkDozeService(Context context) {
|
||||||
if (isDozeEnabled(context) && areGesturesEnabled(context)) {
|
if (isDozeEnabled(context) && !isAlwaysOnEnabled(context) && areGesturesEnabled(context)) {
|
||||||
startService(context);
|
startService(context);
|
||||||
} else {
|
} else {
|
||||||
stopService(context);
|
stopService(context);
|
||||||
|
@ -74,6 +82,20 @@ public final class Utils {
|
||||||
new UserHandle(UserHandle.USER_CURRENT));
|
new UserHandle(UserHandle.USER_CURRENT));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 isAlwaysOnEnabled(Context context) {
|
||||||
|
return Settings.Secure.getIntForUser(context.getContentResolver(),
|
||||||
|
DOZE_ALWAYS_ON, 1, UserHandle.USER_CURRENT) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static boolean alwaysOnDisplayAvailable(Context context) {
|
||||||
|
return new AmbientDisplayConfiguration(context).alwaysOnAvailable();
|
||||||
|
}
|
||||||
|
|
||||||
protected static void enableGesture(Context context, String gesture, boolean enable) {
|
protected static void enableGesture(Context context, String gesture, boolean enable) {
|
||||||
PreferenceManager.getDefaultSharedPreferences(context).edit()
|
PreferenceManager.getDefaultSharedPreferences(context).edit()
|
||||||
.putBoolean(gesture, enable).apply();
|
.putBoolean(gesture, enable).apply();
|
||||||
|
|
Loading…
Reference in a new issue