sanders: LineageActions: Re-add/fix Glance Sensor

Signed-off-by: ronaxdevil <pratabidya.007@gmail.com>
This commit is contained in:
therootlord
2018-02-08 01:16:19 -02:00
committed by ronaxdevil
parent 9910e9f435
commit f33f6494bd
3 changed files with 83 additions and 12 deletions

View File

@@ -35,6 +35,7 @@ import org.lineageos.settings.device.actions.LiftToSilence;
import org.lineageos.settings.device.actions.ProximitySilencer;
import org.lineageos.settings.device.doze.DozePulseAction;
import org.lineageos.settings.device.doze.GlanceSensor;
import org.lineageos.settings.device.doze.ProximitySensor;
import org.lineageos.settings.device.doze.ScreenReceiver;
import org.lineageos.settings.device.doze.ScreenStateNotifier;
@@ -70,6 +71,7 @@ public class LineageActionsService extends IntentService implements ScreenStateN
mScreenStateNotifiers.add(mDozePulseAction);
// Actionable sensors get screen on/off notifications
mScreenStateNotifiers.add(new GlanceSensor(lineageActionsSettings, mSensorHelper, mDozePulseAction));
mScreenStateNotifiers.add(new ProximitySensor(lineageActionsSettings, mSensorHelper, mDozePulseAction));
mScreenStateNotifiers.add(new StowSensor(lineageActionsSettings, mSensorHelper, mDozePulseAction));

View File

@@ -26,7 +26,6 @@ import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.hardware.TriggerEventListener;
import android.util.Log;
public class SensorHelper {
@@ -37,6 +36,7 @@ public class SensorHelper {
private static final int SENSOR_TYPE_MMI_FLAT_UP = 65537;
private static final int SENSOR_TYPE_MMI_FLAT_DOWN = 65538;
private static final int SENSOR_TYPE_MMI_STOW = 65539;
private static final int SENSOR_TYPE_MMI_GLANCE = 65548;
private static final int BATCH_LATENCY_IN_MS = 100;
@@ -81,6 +81,10 @@ public class SensorHelper {
return mSensorManager.getDefaultSensor(SENSOR_TYPE_MMI_FLAT_DOWN, true);
}
public Sensor getGlanceSensor() {
return mSensorManager.getDefaultSensor(SENSOR_TYPE_MMI_GLANCE, true);
}
public Sensor getProximitySensor() {
return mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY, true);
}
@@ -99,15 +103,4 @@ public class SensorHelper {
public void unregisterListener(SensorEventListener listener) {
mSensorManager.unregisterListener(listener);
}
/* TriggerSensor */
public void requestTriggerSensor(Sensor sensor, TriggerEventListener listener) {
if (!mSensorManager.requestTriggerSensor(listener, sensor)) {
throw new RuntimeException("Failed to requestTriggerSensor for sensor " + sensor);
}
}
public void cancelTriggerSensor(Sensor sensor, TriggerEventListener listener) {
mSensorManager.cancelTriggerSensor(listener, sensor);
}
}

View File

@@ -0,0 +1,76 @@
/*
* Copyright (c) 2017 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.device.doze;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.util.Log;
import org.lineageos.settings.device.LineageActionsSettings;
import org.lineageos.settings.device.SensorAction;
import org.lineageos.settings.device.SensorHelper;
public class GlanceSensor implements ScreenStateNotifier {
private static final String TAG = "LineageActions-GlanceSensor";
private final LineageActionsSettings mLineageActionsSettings;
private final SensorHelper mSensorHelper;
private final SensorAction mSensorAction;
private final Sensor mSensor;
private boolean mEnabled;
public GlanceSensor(LineageActionsSettings lineageActionsSettings, SensorHelper sensorHelper,
SensorAction action) {
mLineageActionsSettings = lineageActionsSettings;
mSensorHelper = sensorHelper;
mSensorAction = action;
mSensor = sensorHelper.getGlanceSensor();
}
@Override
public void screenTurnedOn() {
if (mEnabled) {
Log.d(TAG, "Disabling");
mSensorHelper.unregisterListener(mGlanceListener);
mEnabled = false;
}
}
@Override
public void screenTurnedOff() {
if (mLineageActionsSettings.isPickUpEnabled() && !mEnabled) {
Log.d(TAG, "Enabling");
mSensorHelper.registerListener(mSensor, mGlanceListener);
mEnabled = true;
}
}
private SensorEventListener mGlanceListener = new SensorEventListener() {
@Override
public void onSensorChanged(SensorEvent event) {
Log.d(TAG, "triggered");
mSensorAction.action();
}
@Override
public void onAccuracyChanged(Sensor mSensor, int accuracy) {
}
};
}