From a2c262dd165df88a86f1ec2de6940c67d504e9dc Mon Sep 17 00:00:00 2001 From: Alberto97 Date: Sat, 30 Jun 2018 16:45:15 +0200 Subject: [PATCH] Actions: Don't listen for stow events This was required in the past to trigger doze when pulling out the device from a pocket (we were handling the "pick up" action with Flat Up sensor). Currently Glance sensor is being used which gets triggered in the previously described case itself thus there's no need to keep stow implementation alive. --- .../com/moto/actions/MotoActionsService.java | 2 - .../src/com/moto/actions/doze/StowSensor.java | 91 ------------------- 2 files changed, 93 deletions(-) delete mode 100644 MotoActions/src/com/moto/actions/doze/StowSensor.java diff --git a/MotoActions/src/com/moto/actions/MotoActionsService.java b/MotoActions/src/com/moto/actions/MotoActionsService.java index 1def698..4333d47 100644 --- a/MotoActions/src/com/moto/actions/MotoActionsService.java +++ b/MotoActions/src/com/moto/actions/MotoActionsService.java @@ -39,7 +39,6 @@ import com.moto.actions.doze.GlanceSensor; import com.moto.actions.doze.ProximitySensor; import com.moto.actions.doze.ScreenReceiver; import com.moto.actions.doze.ScreenStateNotifier; -import com.moto.actions.doze.StowSensor; public class MotoActionsService extends IntentService implements ScreenStateNotifier, UpdatedStateNotifier { @@ -73,7 +72,6 @@ public class MotoActionsService extends IntentService implements ScreenStateNoti // Actionable sensors get screen on/off notifications mScreenStateNotifiers.add(new GlanceSensor(motoActionsSettings, mSensorHelper, mDozePulseAction)); mScreenStateNotifiers.add(new ProximitySensor(motoActionsSettings, mSensorHelper, mDozePulseAction)); - mScreenStateNotifiers.add(new StowSensor(motoActionsSettings, mSensorHelper, mDozePulseAction)); // Other actions that are always enabled mUpdatedStateNotifiers.add(new CameraActivationSensor(motoActionsSettings, mSensorHelper)); diff --git a/MotoActions/src/com/moto/actions/doze/StowSensor.java b/MotoActions/src/com/moto/actions/doze/StowSensor.java deleted file mode 100644 index 0d88b20..0000000 --- a/MotoActions/src/com/moto/actions/doze/StowSensor.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (c) 2015 The CyanogenMod Project - * 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 com.moto.actions.doze; - -import android.hardware.Sensor; -import android.hardware.SensorEvent; -import android.hardware.SensorEventListener; -import android.util.Log; - -import java.lang.System; - -import com.moto.actions.MotoActionsSettings; -import com.moto.actions.SensorAction; -import com.moto.actions.SensorHelper; - -public class StowSensor implements ScreenStateNotifier, SensorEventListener { - private static final String TAG = "MotoActions-StowSensor"; - private static final int IN_POCKET_MIN_TIME = 5000; - - private final MotoActionsSettings mMotoActionsSettings; - private final SensorHelper mSensorHelper; - private final SensorAction mSensorAction; - private final Sensor mSensor; - - private boolean mEnabled; - private boolean mLastStowed; - private long isStowedTime; - - public StowSensor(MotoActionsSettings motoActionsSettings, SensorHelper sensorHelper, - SensorAction action) { - mMotoActionsSettings = motoActionsSettings; - mSensorHelper = sensorHelper; - mSensorAction = action; - - mSensor = sensorHelper.getStowSensor(); - } - - @Override - public void screenTurnedOn() { - if (mEnabled) { - Log.d(TAG, "Disabling"); - mSensorHelper.unregisterListener(this); - mEnabled = false; - } - } - - @Override - public void screenTurnedOff() { - if (!mMotoActionsSettings.isIrWakeupEnabled() && - mMotoActionsSettings.isPickUpEnabled() && !mEnabled) { - Log.d(TAG, "Enabling"); - mSensorHelper.registerListener(mSensor, this); - mEnabled = true; - } - } - - @Override - public void onSensorChanged(SensorEvent event) { - boolean thisStowed = (event.values[0] != 0); - if(thisStowed){ - isStowedTime = System.currentTimeMillis(); - } else if (mLastStowed && !thisStowed) { - long inPocketTime = System.currentTimeMillis() - isStowedTime; - if(inPocketTime >= IN_POCKET_MIN_TIME){ - Log.d(TAG, "Triggered after " + inPocketTime / 1000 + " seconds"); - mSensorAction.action(); - } - } - mLastStowed = thisStowed; - Log.d(TAG, "event: " + thisStowed); - } - - @Override - public void onAccuracyChanged(Sensor sensor, int accuracy) { - } -}