* Highly inspired by iOS raise to wake - Adapted to OnePlus sm8250 doze sm8250-common: doze: Add min interval for raise2wake * avoid having early wakeup * also fix typo in acquire timeout sm8250-common: doze: Enable pickup when raise to wake is toggled - This is needed in order for raise to wake to function properly. sm8250-common: doze: Fix pickup status for raise to wake Co-authored-by: AnierinB <anierinb@evolution-x.org> Co-authored-by: AshutoshSundresh <ashutoshsundresh@gmail.com> Co-authored-by: LuK1337 <priv.luk@gmail.com> Signed-off-by: AnierinB <anierinb@evolution-x.org> Signed-off-by: Omkar Chandorkar <gotenksIN@aosip.dev> Signed-off-by: LuK1337 <priv.luk@gmail.com> Change-Id: I5df0c4f11f1b24ab813abc393960c5f03f5fab1f
129 lines
4.7 KiB
Java
129 lines
4.7 KiB
Java
/*
|
|
* 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.
|
|
* 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 org.lineageos.settings.doze;
|
|
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.hardware.display.AmbientDisplayConfiguration;
|
|
import android.hardware.Sensor;
|
|
import android.hardware.SensorManager;
|
|
import android.os.UserHandle;
|
|
import android.provider.Settings;
|
|
import android.util.Log;
|
|
import androidx.preference.PreferenceManager;
|
|
|
|
import static android.provider.Settings.Secure.DOZE_ALWAYS_ON;
|
|
import static android.provider.Settings.Secure.DOZE_ENABLED;
|
|
|
|
public final class Utils {
|
|
|
|
private static final String TAG = "DozeUtils";
|
|
private static final boolean DEBUG = false;
|
|
|
|
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_type";
|
|
protected static final String GESTURE_POCKET_KEY = "gesture_pocket";
|
|
|
|
protected static void startService(Context context) {
|
|
if (DEBUG) Log.d(TAG, "Starting service");
|
|
context.startServiceAsUser(new Intent(context, DozeService.class),
|
|
UserHandle.CURRENT);
|
|
}
|
|
|
|
protected static void stopService(Context context) {
|
|
if (DEBUG) Log.d(TAG, "Stopping service");
|
|
context.stopServiceAsUser(new Intent(context, DozeService.class),
|
|
UserHandle.CURRENT);
|
|
}
|
|
|
|
protected static void checkDozeService(Context context) {
|
|
if (isDozeEnabled(context) && !isAlwaysOnEnabled(context) && areGesturesEnabled(context)) {
|
|
startService(context);
|
|
} else {
|
|
stopService(context);
|
|
}
|
|
}
|
|
|
|
protected static boolean isDozeEnabled(Context context) {
|
|
return Settings.Secure.getInt(context.getContentResolver(),
|
|
DOZE_ENABLED, 1) != 0;
|
|
}
|
|
|
|
protected static boolean enableDoze(Context context, boolean enable) {
|
|
return Settings.Secure.putInt(context.getContentResolver(),
|
|
DOZE_ENABLED, enable ? 1 : 0);
|
|
}
|
|
|
|
protected static void launchDozePulse(Context context) {
|
|
if (DEBUG) Log.d(TAG, "Launch doze pulse");
|
|
context.sendBroadcastAsUser(new Intent(DOZE_INTENT),
|
|
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, 0, UserHandle.USER_CURRENT) != 0;
|
|
}
|
|
|
|
protected static boolean alwaysOnDisplayAvailable(Context context) {
|
|
return new AmbientDisplayConfiguration(context).alwaysOnAvailable();
|
|
}
|
|
|
|
protected static boolean isGestureEnabled(Context context, String gesture) {
|
|
return PreferenceManager.getDefaultSharedPreferences(context)
|
|
.getBoolean(gesture, false);
|
|
}
|
|
|
|
protected static boolean isPickUpEnabled(Context context) {
|
|
return !PreferenceManager.getDefaultSharedPreferences(context)
|
|
.getString(GESTURE_PICK_UP_KEY, "0").equals("0");
|
|
}
|
|
|
|
protected static boolean isPickUpSetToWake(Context context) {
|
|
return PreferenceManager.getDefaultSharedPreferences(context)
|
|
.getString(GESTURE_PICK_UP_KEY, "0").equals("2");
|
|
}
|
|
|
|
protected static boolean isPocketEnabled(Context context) {
|
|
return isGestureEnabled(context, GESTURE_POCKET_KEY);
|
|
}
|
|
|
|
public static boolean areGesturesEnabled(Context context) {
|
|
return isPickUpEnabled(context) || isPocketEnabled(context);
|
|
}
|
|
|
|
protected static Sensor getSensor(SensorManager sm, String type) {
|
|
for (Sensor sensor : sm.getSensorList(Sensor.TYPE_ALL)) {
|
|
if (type.equals(sensor.getStringType())) {
|
|
return sensor;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
}
|