exynos9610: kang LineageActions from nash
authorJan Altensen <info@stricted.net>
Fri, 4 Sep 2020 21:17:43 +0000 (23:17 +0200)
committerJan Altensen <info@stricted.net>
Sun, 1 Nov 2020 02:06:36 +0000 (03:06 +0100)
Change-Id: Iaad009cb167850e39b324edcea302eccb5b0fccf

33 files changed:
LineageActions/Android.mk [new file with mode: 0644]
LineageActions/AndroidManifest.xml [new file with mode: 0644]
LineageActions/proguard.flags [new file with mode: 0644]
LineageActions/res/drawable/ic_settings_gestures.xml [new file with mode: 0644]
LineageActions/res/values/strings.xml [new file with mode: 0644]
LineageActions/res/values/styles.xml [new file with mode: 0644]
LineageActions/res/xml/actions_panel.xml [new file with mode: 0644]
LineageActions/res/xml/doze_panel.xml [new file with mode: 0644]
LineageActions/src/org/lineageos/settings/device/ActionsPreferenceActivity.java [new file with mode: 0644]
LineageActions/src/org/lineageos/settings/device/ActionsPreferenceFragment.java [new file with mode: 0644]
LineageActions/src/org/lineageos/settings/device/BootCompletedReceiver.java [new file with mode: 0644]
LineageActions/src/org/lineageos/settings/device/DozePreferenceActivity.java [new file with mode: 0644]
LineageActions/src/org/lineageos/settings/device/LineageActionsService.java [new file with mode: 0644]
LineageActions/src/org/lineageos/settings/device/LineageActionsSettings.java [new file with mode: 0644]
LineageActions/src/org/lineageos/settings/device/SensorAction.java [new file with mode: 0644]
LineageActions/src/org/lineageos/settings/device/SensorHelper.java [new file with mode: 0644]
LineageActions/src/org/lineageos/settings/device/ServiceWrapper.java [new file with mode: 0644]
LineageActions/src/org/lineageos/settings/device/actions/CameraActivationAction.java [new file with mode: 0644]
LineageActions/src/org/lineageos/settings/device/actions/CameraActivationSensor.java [new file with mode: 0644]
LineageActions/src/org/lineageos/settings/device/actions/ChopChopSensor.java [new file with mode: 0644]
LineageActions/src/org/lineageos/settings/device/actions/FlipToMute.java [new file with mode: 0644]
LineageActions/src/org/lineageos/settings/device/actions/LiftToSilence.java [new file with mode: 0644]
LineageActions/src/org/lineageos/settings/device/actions/ProximitySilencer.java [new file with mode: 0644]
LineageActions/src/org/lineageos/settings/device/actions/TorchAction.java [new file with mode: 0644]
LineageActions/src/org/lineageos/settings/device/actions/UpdatedStateNotifier.java [new file with mode: 0644]
LineageActions/src/org/lineageos/settings/device/doze/DozePulseAction.java [new file with mode: 0644]
LineageActions/src/org/lineageos/settings/device/doze/FlatUpSensor.java [new file with mode: 0644]
LineageActions/src/org/lineageos/settings/device/doze/GlanceSensor.java [new file with mode: 0644]
LineageActions/src/org/lineageos/settings/device/doze/ProximitySensor.java [new file with mode: 0644]
LineageActions/src/org/lineageos/settings/device/doze/ScreenReceiver.java [new file with mode: 0644]
LineageActions/src/org/lineageos/settings/device/doze/ScreenStateNotifier.java [new file with mode: 0644]
LineageActions/src/org/lineageos/settings/device/doze/StowSensor.java [new file with mode: 0644]
common.mk

diff --git a/LineageActions/Android.mk b/LineageActions/Android.mk
new file mode 100644 (file)
index 0000000..defb46e
--- /dev/null
@@ -0,0 +1,31 @@
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_MODULE_TAGS := optional
+
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+LOCAL_PACKAGE_NAME := LineageActions
+LOCAL_CERTIFICATE := platform
+LOCAL_PRIVATE_PLATFORM_APIS := true
+LOCAL_PROPRIETARY_MODULE := true
+LOCAL_USE_AAPT2 := true
+
+LOCAL_STATIC_ANDROID_LIBRARIES := \
+    androidx.core_core \
+    androidx.preference_preference
+
+LOCAL_PROGUARD_FLAG_FILES := proguard.flags
+
+LOCAL_RESOURCE_DIR := \
+    $(LOCAL_PATH)/res \
+    $(TOP)/packages/resources/devicesettings/res
+
+ifneq ($(INCREMENTAL_BUILDS),)
+    LOCAL_PROGUARD_ENABLED := disabled
+    LOCAL_JACK_ENABLED := incremental
+endif
+
+include frameworks/base/packages/SettingsLib/common.mk
+
+include $(BUILD_PACKAGE)
diff --git a/LineageActions/AndroidManifest.xml b/LineageActions/AndroidManifest.xml
new file mode 100644 (file)
index 0000000..037bf01
--- /dev/null
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    package="org.lineageos.settings.device"
+    android:sharedUserId="android.uid.system"
+    >
+
+    <original-package android:name="com.cyanogenmod.settings.device" />
+
+    <uses-permission android:name="android.permission.ACCESS_NOTIFICATION_POLICY" />
+    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
+    <uses-permission android:name="android.permission.VIBRATE"/>
+    <uses-permission android:name="android.permission.WAKE_LOCK" />
+
+    <protected-broadcast android:name="com.android.systemui.doze.pulse" />
+
+    <application
+        android:allowBackup="true"
+        android:label="@string/device_settings_app_name"
+        android:persistent="true">
+
+        <receiver android:name="org.lineageos.settings.device.BootCompletedReceiver">
+            <intent-filter>
+                <action android:name="android.intent.action.BOOT_COMPLETED" />
+                <category android:name="android.intent.category.DEFAULT" />
+            </intent-filter>
+        </receiver>
+
+        <service android:name="ServiceWrapper" android:permission="ServiceWrapper">
+            <intent-filter>
+                <action android:name="ServiceWrapper"/>
+            </intent-filter>
+        </service>
+
+        <activity
+            android:name=".DozePreferenceActivity"
+            android:label="@string/ambient_display_gestures_title"
+            android:theme="@style/LineageActions">
+            <intent-filter>
+                <action android:name="com.android.settings.action.IA_SETTINGS" />
+            </intent-filter>
+            <meta-data
+                android:name="com.android.settings.category"
+                android:value="com.android.settings.category.ia.display" />
+            <meta-data
+                android:name="com.android.settings.summary"
+                android:resource="@string/ambient_display_gestures_summary" />
+        </activity>
+
+        <activity
+            android:name=".ActionsPreferenceActivity"
+            android:label="@string/moto_gestures_panel_title"
+            android:theme="@style/LineageActions">
+            <intent-filter>
+                <action android:name="com.android.settings.action.IA_SETTINGS" />
+            </intent-filter>
+            <meta-data
+                android:name="com.android.settings.category"
+                android:value="com.android.settings.category.ia.system" />
+            <meta-data
+                android:name="com.android.settings.icon"
+                android:resource="@drawable/ic_settings_gestures" />
+            <meta-data
+                android:name="com.android.settings.summary"
+                android:resource="@string/screen_gestures_panel_summary" />
+        </activity>
+
+    </application>
+
+</manifest>
diff --git a/LineageActions/proguard.flags b/LineageActions/proguard.flags
new file mode 100644 (file)
index 0000000..ab22f4b
--- /dev/null
@@ -0,0 +1,9 @@
+-keep class org.lineageos.LineageActions.* {
+  *;
+}
+
+-keepclasseswithmembers class * {
+    public <init>(android.content.Context, android.util.AttributeSet);
+}
+
+-keep class ** extends android.support.v14.preference.PreferenceFragment
diff --git a/LineageActions/res/drawable/ic_settings_gestures.xml b/LineageActions/res/drawable/ic_settings_gestures.xml
new file mode 100644 (file)
index 0000000..341d42f
--- /dev/null
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+    Copyright (c) 2015 The CyanogenMod 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.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+        android:width="24dp"
+        android:height="24dp"
+        android:viewportWidth="24"
+        android:viewportHeight="24"
+        android:tint="?android:attr/colorControlNormal">
+
+    <path
+        android:pathData="M4.7,6.9c0.7-0.7,1.4-1.4,1.7-1.2c0.5,0.2,0,1-0.3,1.5c-0.2,0.4-2.8,3.9-2.8,6.3c0,1.3,0.5,2.3,1.3,3
+c0.7,0.6,1.7,0.7,2.6,0.5c1.1-0.3,1.9-1.4,3-2.8c1.2-1.5,2.8-3.4,4-3.4c1.6,0,1.6,1,1.7,1.8c-3.7,0.6-5.3,3.7-5.3,5.4
+s1.4,3.1,3.2,3.1c1.6,0,4.3-1.3,4.6-6.1H21v-2.5h-2.4c-0.1-1.7-1.1-4.2-4-4.2c-2.2,0-4.1,1.9-4.9,2.8c-0.6,0.7-2,2.5-2.3,2.7
+c-0.2,0.3-0.7,0.8-1.1,0.8c-0.4,0-0.7-0.8-0.4-1.9c0.3-1.1,1.4-2.9,1.8-3.5C8.5,8,9.1,7.2,9.1,5.9C9.1,3.7,7.4,3,6.6,3
+C5.3,3,4.1,4,3.9,4.3C3.5,4.6,3.2,4.9,3,5.2L4.7,6.9z
+M13.9,18.6c-0.3,0-0.7-0.3-0.7-0.7c0-0.6,0.7-2.2,2.8-2.8
+C15.8,17.8,14.6,18.6,13.9,18.6z"
+        android:strokeColor="#00000000"
+        android:fillType="nonZero"
+        android:fillColor="#000000"
+        android:strokeWidth="1"/>
+</vector>
diff --git a/LineageActions/res/values/strings.xml b/LineageActions/res/values/strings.xml
new file mode 100644 (file)
index 0000000..ebb5b7b
--- /dev/null
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+    <string name="screen_gestures_panel_summary" translatable="false">Special Device Gestures</string>
+    <string name="moto_gestures_panel_title">Moto Gestures</string>
+</resources>
diff --git a/LineageActions/res/values/styles.xml b/LineageActions/res/values/styles.xml
new file mode 100644 (file)
index 0000000..76c7ffb
--- /dev/null
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+     Copyright (C) 2016 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.
+-->
+<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+    <style name="LineageActions" parent="@android:style/Theme.DeviceDefault.Settings">
+        <item name="preferenceCategoryStyle">@style/SettingsTheme.PreferenceCategoryStyle</item>
+        <item name="preferenceTheme">@style/SettingsTheme.Preference</item>
+        <item name="switchPreferenceStyle">@style/SettingsTheme.SwitchPreferenceStyle</item>
+    </style>
+
+    <style name="SettingsTheme.PreferenceCategoryStyle" parent="@*android:style/Preference.DeviceDefault.Category">
+        <item name="allowDividerAbove">true</item>
+        <item name="allowDividerBelow">true</item>
+        <item name="android:layout">@layout/preference_category_material_settings</item>
+    </style>
+
+    <style name="SettingsTheme.Preference" parent="@android:style/Theme.DeviceDefault.Settings">
+        <item name="allowDividerAbove">false</item>
+        <item name="allowDividerBelow">true</item>
+        <item name="singleLineTitle">false</item>
+    </style>
+
+    <style name="SettingsTheme.SwitchPreferenceStyle" parent="@*android:style/Preference.DeviceDefault">
+        <item name="allowDividerAbove">false</item>
+        <item name="allowDividerBelow">false</item>
+        <item name="singleLineTitle">false</item>
+        <item name="widgetLayout">@*android:layout/preference_widget_switch</item>
+        <item name="android:layout">@layout/preference_material_settings</item>
+    </style>
+</resources>
diff --git a/LineageActions/res/xml/actions_panel.xml b/LineageActions/res/xml/actions_panel.xml
new file mode 100644 (file)
index 0000000..7bb0784
--- /dev/null
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+     Copyright (C) 2015-2016 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.
+-->
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
+        xmlns:settings="http://schemas.android.com/apk/res/com.android.settings">
+
+    <PreferenceCategory
+        android:key="actions_key"
+        android:title="@string/actions_title">
+
+        <SwitchPreference
+            android:key="gesture_camera_action"
+            android:defaultValue="true"
+            android:title="@string/camera_gesture_title"
+            android:summary="@string/camera_gesture_summary" />
+
+        <SwitchPreference
+            android:key="gesture_chop_chop"
+            android:defaultValue="true"
+            android:title="@string/chop_chop_gesture_title"
+            android:summary="@string/chop_chop_gesture_summary" />
+
+        <SwitchPreference
+            android:key="gesture_ir_silencer"
+            android:defaultValue="false"
+            android:title="@string/hand_wave_silencer_title"
+            android:summary="@string/hand_wave_silencer_summary" />
+
+        <SwitchPreference
+            android:key="gesture_flip_to_mute"
+            android:defaultValue="false"
+            android:title="@string/flip_to_mute_title"
+            android:summary="@string/flip_to_mute_summary" />
+
+        <SwitchPreference
+            android:key="gesture_lift_to_silence"
+            android:defaultValue="false"
+            android:title="@string/lift_to_silence_title"
+            android:summary="@string/lift_to_silence_summary" />
+
+    </PreferenceCategory>
+
+</PreferenceScreen>
diff --git a/LineageActions/res/xml/doze_panel.xml b/LineageActions/res/xml/doze_panel.xml
new file mode 100644 (file)
index 0000000..8b21198
--- /dev/null
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+     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.
+-->
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
+        xmlns:settings="http://schemas.android.com/apk/res/com.android.settings">
+
+    <PreferenceCategory
+        android:key="ambient_display_key"
+        android:title="@string/ambient_display_title">
+
+        <SwitchPreference
+            android:key="gesture_pick_up"
+            android:defaultValue="true"
+            android:title="@string/pick_up_gesture_title"
+            android:summary="@string/pick_up_gesture_summary" />
+
+        <SwitchPreference
+            android:key="gesture_hand_wave"
+            android:defaultValue="true"
+            android:title="@string/hand_wave_gesture_title"
+            android:summary="@string/hand_wave_gesture_summary" />
+    </PreferenceCategory>
+
+</PreferenceScreen>
diff --git a/LineageActions/src/org/lineageos/settings/device/ActionsPreferenceActivity.java b/LineageActions/src/org/lineageos/settings/device/ActionsPreferenceActivity.java
new file mode 100644 (file)
index 0000000..d53cda9
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2016 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 org.lineageos.settings.device;
+
+import android.os.Bundle;
+import android.preference.PreferenceActivity;
+
+public class ActionsPreferenceActivity extends PreferenceActivity {
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        getFragmentManager().beginTransaction()
+            .replace(android.R.id.content, new ActionsPreferenceFragment()).commit();
+    }
+}
diff --git a/LineageActions/src/org/lineageos/settings/device/ActionsPreferenceFragment.java b/LineageActions/src/org/lineageos/settings/device/ActionsPreferenceFragment.java
new file mode 100644 (file)
index 0000000..8a75fc2
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2015-2016 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 org.lineageos.settings.device;
+
+import android.app.ActionBar;
+import android.os.Bundle;
+import androidx.preference.Preference;
+import androidx.preference.PreferenceFragment;
+import androidx.preference.SwitchPreference;
+import android.text.TextUtils;
+import android.view.MenuItem;
+
+import java.io.File;
+
+public class ActionsPreferenceFragment extends PreferenceFragment {
+
+    @Override
+    public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
+        addPreferencesFromResource(R.xml.actions_panel);
+        final ActionBar actionBar = getActivity().getActionBar();
+        actionBar.setDisplayHomeAsUpEnabled(true);
+    }
+
+    @Override
+    public boolean onOptionsItemSelected(MenuItem item) {
+        if (item.getItemId() == android.R.id.home) {
+            getActivity().onBackPressed();
+            return true;
+        }
+        return false;
+    }
+}
diff --git a/LineageActions/src/org/lineageos/settings/device/BootCompletedReceiver.java b/LineageActions/src/org/lineageos/settings/device/BootCompletedReceiver.java
new file mode 100644 (file)
index 0000000..27d42d7
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * 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 org.lineageos.settings.device;
+
+import android.content.BroadcastReceiver;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.ServiceConnection;
+import android.os.IBinder;
+import android.util.Log;
+
+import org.lineageos.settings.device.ServiceWrapper.LocalBinder;
+
+public class BootCompletedReceiver extends BroadcastReceiver {
+    static final String TAG = "LineageActions";
+    private ServiceWrapper mServiceWrapper;
+
+    @Override
+    public void onReceive(final Context context, Intent intent) {
+        Log.i(TAG, "Booting");
+        context.startService(new Intent(context, ServiceWrapper.class));
+    }
+
+    private ServiceConnection serviceConnection = new ServiceConnection() {
+        @Override
+        public void onServiceConnected(ComponentName className, IBinder service) {
+            LocalBinder binder = (LocalBinder) service;
+            mServiceWrapper = binder.getService();
+            mServiceWrapper.start();
+        }
+
+        @Override
+        public void onServiceDisconnected(ComponentName className) {
+            mServiceWrapper = null;
+        }
+    };
+}
diff --git a/LineageActions/src/org/lineageos/settings/device/DozePreferenceActivity.java b/LineageActions/src/org/lineageos/settings/device/DozePreferenceActivity.java
new file mode 100644 (file)
index 0000000..c8e7cc6
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * 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;
+
+import android.os.Bundle;
+import android.preference.PreferenceActivity;
+import androidx.preference.PreferenceCategory;
+import androidx.preference.PreferenceFragment;
+import android.view.MenuItem;
+
+public class DozePreferenceActivity extends PreferenceActivity {
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        getActionBar().setDisplayHomeAsUpEnabled(true);
+        getFragmentManager().beginTransaction()
+                .replace(android.R.id.content, new DozePreferenceFragment()).commit();
+    }
+
+    public static class DozePreferenceFragment extends PreferenceFragment {
+        private static final String CATEGORY_AMBIENT_DISPLAY = "ambient_display_key";
+
+        @Override
+        public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
+            addPreferencesFromResource(R.xml.doze_panel);
+            boolean dozeEnabled = LineageActionsSettings.isDozeEnabled(getActivity());
+            boolean aodEnabled = LineageActionsSettings.isAODEnabled(getActivity());
+            PreferenceCategory ambientDisplayCat = (PreferenceCategory)
+                    findPreference(CATEGORY_AMBIENT_DISPLAY);
+            if (ambientDisplayCat != null) {
+                ambientDisplayCat.setEnabled(dozeEnabled && !aodEnabled);
+            }
+        }
+    }
+
+    @Override
+    public boolean onOptionsItemSelected(MenuItem item) {
+        if (item.getItemId() == android.R.id.home) {
+            onBackPressed();
+            return true;
+        }
+        return super.onOptionsItemSelected(item);
+    }
+}
diff --git a/LineageActions/src/org/lineageos/settings/device/LineageActionsService.java b/LineageActions/src/org/lineageos/settings/device/LineageActionsService.java
new file mode 100644 (file)
index 0000000..0a883aa
--- /dev/null
@@ -0,0 +1,126 @@
+/*
+ * 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 org.lineageos.settings.device;
+
+import android.app.IntentService;
+import android.content.Context;
+import android.content.Intent;
+import android.os.PowerManager;
+import android.provider.Settings;
+import android.util.Log;
+
+import java.util.List;
+import java.util.LinkedList;
+
+import org.lineageos.settings.device.actions.UpdatedStateNotifier;
+import org.lineageos.settings.device.actions.CameraActivationSensor;
+import org.lineageos.settings.device.actions.ChopChopSensor;
+import org.lineageos.settings.device.actions.FlipToMute;
+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.FlatUpSensor;
+import org.lineageos.settings.device.doze.ScreenReceiver;
+import org.lineageos.settings.device.doze.ScreenStateNotifier;
+import org.lineageos.settings.device.doze.StowSensor;
+
+public class LineageActionsService extends IntentService implements ScreenStateNotifier,
+        UpdatedStateNotifier {
+    private static final String TAG = "LineageActions";
+
+    private final Context mContext;
+
+    private final DozePulseAction mDozePulseAction;
+    private final PowerManager mPowerManager;
+    private final PowerManager.WakeLock mWakeLock;
+    private final ScreenReceiver mScreenReceiver;
+    private final SensorHelper mSensorHelper;
+
+    private final List<ScreenStateNotifier> mScreenStateNotifiers = new LinkedList<ScreenStateNotifier>();
+    private final List<UpdatedStateNotifier> mUpdatedStateNotifiers =
+                        new LinkedList<UpdatedStateNotifier>();
+
+    public LineageActionsService(Context context) {
+        super("LineageActionService");
+        mContext = context;
+
+        Log.d(TAG, "Starting");
+
+        LineageActionsSettings lineageActionsSettings = new LineageActionsSettings(context, this);
+        mSensorHelper = new SensorHelper(context);
+        mScreenReceiver = new ScreenReceiver(context, this);
+
+        mDozePulseAction = new DozePulseAction(context);
+        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));
+        mScreenStateNotifiers.add(new FlatUpSensor(lineageActionsSettings, mSensorHelper, mDozePulseAction));
+
+        // Other actions that are always enabled
+        mUpdatedStateNotifiers.add(new CameraActivationSensor(lineageActionsSettings, mSensorHelper));
+        mUpdatedStateNotifiers.add(new ChopChopSensor(lineageActionsSettings, mSensorHelper));
+        mUpdatedStateNotifiers.add(new ProximitySilencer(lineageActionsSettings, context, mSensorHelper));
+        mUpdatedStateNotifiers.add(new FlipToMute(lineageActionsSettings, context, mSensorHelper));
+        mUpdatedStateNotifiers.add(new LiftToSilence(lineageActionsSettings, context, mSensorHelper));
+
+        mPowerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
+        mWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "LineageActionsWakeLock");
+        updateState();
+    }
+
+    @Override
+    protected void onHandleIntent(Intent intent) {
+    }
+
+    @Override
+    public void screenTurnedOn() {
+            if (!mWakeLock.isHeld()) {
+                mWakeLock.acquire();
+            }
+        for (ScreenStateNotifier screenStateNotifier : mScreenStateNotifiers) {
+            screenStateNotifier.screenTurnedOn();
+        }
+    }
+
+    @Override
+    public void screenTurnedOff() {
+            if (mWakeLock.isHeld()) {
+                mWakeLock.release();
+            }
+        for (ScreenStateNotifier screenStateNotifier : mScreenStateNotifiers) {
+            screenStateNotifier.screenTurnedOff();
+        }
+    }
+
+    public void updateState() {
+        if (mPowerManager.isInteractive()) {
+            screenTurnedOn();
+        } else {
+            screenTurnedOff();
+        }
+        for (UpdatedStateNotifier notifier : mUpdatedStateNotifiers) {
+            notifier.updateState();
+        }
+    }
+}
diff --git a/LineageActions/src/org/lineageos/settings/device/LineageActionsSettings.java b/LineageActions/src/org/lineageos/settings/device/LineageActionsSettings.java
new file mode 100644 (file)
index 0000000..c0a408c
--- /dev/null
@@ -0,0 +1,151 @@
+/*
+ * 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 org.lineageos.settings.device;
+
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.hardware.display.AmbientDisplayConfiguration;
+import android.os.UserHandle;
+import android.preference.PreferenceManager;
+
+import org.lineageos.settings.device.actions.UpdatedStateNotifier;
+import org.lineageos.settings.device.actions.CameraActivationAction;
+import org.lineageos.settings.device.actions.TorchAction;
+
+public class LineageActionsSettings {
+    private static final String TAG = "LineageActions";
+
+    private static final String GESTURE_CAMERA_ACTION_KEY = "gesture_camera_action";
+    private static final String GESTURE_CHOP_CHOP_KEY = "gesture_chop_chop";
+    private static final String GESTURE_PICK_UP_KEY = "gesture_pick_up";
+    private static final String GESTURE_IR_WAKEUP_KEY = "gesture_hand_wave";
+    private static final String GESTURE_IR_SILENCER_KEY = "gesture_ir_silencer";
+    private static final String GESTURE_FLIP_TO_MUTE_KEY = "gesture_flip_to_mute";
+    private static final String GESTURE_LIFT_TO_SILENCE_KEY = "gesture_lift_to_silence";
+
+    private final Context mContext;
+    private final UpdatedStateNotifier mUpdatedStateNotifier;
+
+    private boolean mCameraGestureEnabled;
+    private boolean mChopChopEnabled;
+    private boolean mPickUpGestureEnabled;
+    private boolean mIrWakeUpEnabled;
+    private boolean mIrSilencerEnabled;
+    private boolean mFlipToMuteEnabled;
+    private boolean mLiftToSilenceEnabled;
+
+    public LineageActionsSettings(Context context, UpdatedStateNotifier updatedStateNotifier) {
+        SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
+        loadPreferences(sharedPrefs);
+        sharedPrefs.registerOnSharedPreferenceChangeListener(mPrefListener);
+        mContext = context;
+        mUpdatedStateNotifier = updatedStateNotifier;
+    }
+
+    public boolean isCameraGestureEnabled() {
+        return mCameraGestureEnabled;
+    }
+
+    public boolean isChopChopGestureEnabled() {
+        return mChopChopEnabled;
+    }
+
+    public static boolean isAODEnabled(Context context) {
+        return new AmbientDisplayConfiguration(context).alwaysOnEnabled(UserHandle.USER_CURRENT);
+    }
+
+    public static boolean isDozeEnabled(Context context) {
+        return new AmbientDisplayConfiguration(context).pulseOnNotificationEnabled(UserHandle.USER_CURRENT);
+    }
+
+    public boolean isAODEnabled() {
+        return isAODEnabled(mContext);
+    }
+
+    public boolean isDozeEnabled() {
+        return isDozeEnabled(mContext);
+    }
+
+    public boolean isIrWakeupEnabled() {
+        return isDozeEnabled() && !isAODEnabled() && mIrWakeUpEnabled;
+    }
+
+    public boolean isPickUpEnabled() {
+        return isDozeEnabled() && !isAODEnabled() && mPickUpGestureEnabled;
+    }
+
+    public boolean isIrSilencerEnabled() {
+        return mIrSilencerEnabled;
+    }
+
+    public boolean isFlipToMuteEnabled() {
+        return mFlipToMuteEnabled;
+    }
+
+    public boolean isLiftToSilenceEnabled() {
+        return mLiftToSilenceEnabled;
+    }
+
+    public void cameraAction() {
+        new CameraActivationAction(mContext).action();
+    }
+
+    public void chopChopAction() {
+        new TorchAction(mContext).action();
+    }
+
+    private void loadPreferences(SharedPreferences sharedPreferences) {
+        mCameraGestureEnabled = sharedPreferences.getBoolean(GESTURE_CAMERA_ACTION_KEY, true);
+        mChopChopEnabled = sharedPreferences.getBoolean(GESTURE_CHOP_CHOP_KEY, true);
+        mIrWakeUpEnabled = sharedPreferences.getBoolean(GESTURE_IR_WAKEUP_KEY, true);
+        mPickUpGestureEnabled = sharedPreferences.getBoolean(GESTURE_PICK_UP_KEY, true);
+        mIrSilencerEnabled = sharedPreferences.getBoolean(GESTURE_IR_SILENCER_KEY, false);
+        mFlipToMuteEnabled = sharedPreferences.getBoolean(GESTURE_FLIP_TO_MUTE_KEY, false);
+        mLiftToSilenceEnabled = sharedPreferences.getBoolean(GESTURE_LIFT_TO_SILENCE_KEY, false);
+    }
+
+    private SharedPreferences.OnSharedPreferenceChangeListener mPrefListener =
+            new SharedPreferences.OnSharedPreferenceChangeListener() {
+        @Override
+        public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
+            boolean updated = true;
+
+            if (GESTURE_CAMERA_ACTION_KEY.equals(key)) {
+                mCameraGestureEnabled = sharedPreferences.getBoolean(GESTURE_CAMERA_ACTION_KEY, true);
+            } else if (GESTURE_CHOP_CHOP_KEY.equals(key)) {
+                mChopChopEnabled = sharedPreferences.getBoolean(GESTURE_CHOP_CHOP_KEY, true);
+            } else if (GESTURE_IR_WAKEUP_KEY.equals(key)) {
+                mIrWakeUpEnabled = sharedPreferences.getBoolean(GESTURE_IR_WAKEUP_KEY, true);
+            } else if (GESTURE_PICK_UP_KEY.equals(key)) {
+                mPickUpGestureEnabled = sharedPreferences.getBoolean(GESTURE_PICK_UP_KEY, true);
+            } else if (GESTURE_IR_SILENCER_KEY.equals(key)) {
+                mIrSilencerEnabled = sharedPreferences.getBoolean(GESTURE_IR_SILENCER_KEY, false);
+            } else if (GESTURE_FLIP_TO_MUTE_KEY.equals(key)) {
+                mFlipToMuteEnabled = sharedPreferences.getBoolean(GESTURE_FLIP_TO_MUTE_KEY, false);
+            } else if (GESTURE_LIFT_TO_SILENCE_KEY.equals(key)) {
+                mLiftToSilenceEnabled = sharedPreferences.getBoolean(GESTURE_LIFT_TO_SILENCE_KEY, false);
+            } else {
+                updated = false;
+            }
+
+            if (updated) {
+                mUpdatedStateNotifier.updateState();
+            }
+        }
+    };
+}
diff --git a/LineageActions/src/org/lineageos/settings/device/SensorAction.java b/LineageActions/src/org/lineageos/settings/device/SensorAction.java
new file mode 100644 (file)
index 0000000..4bc72c4
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+ * 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 org.lineageos.settings.device;
+
+public interface SensorAction {
+    public void action();
+}
diff --git a/LineageActions/src/org/lineageos/settings/device/SensorHelper.java b/LineageActions/src/org/lineageos/settings/device/SensorHelper.java
new file mode 100644 (file)
index 0000000..5d3776c
--- /dev/null
@@ -0,0 +1,123 @@
+/*
+ * 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 org.lineageos.settings.device;
+
+import java.util.List;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+
+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 {
+    private static final String TAG = "LineageActions";
+
+    private static final int SENSOR_TYPE_MMI_CAMERA_ACTIVATION = 65540;
+    private static final int SENSOR_TYPE_MMI_CHOP_CHOP = 65546;
+    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 SENSOR_TYPE_MMI_GLANCE_APPROACH = 65555;
+
+    private static final int BATCH_LATENCY_IN_MS = 100;
+
+    private final Context mContext;
+    private final SensorManager mSensorManager;
+
+    public SensorHelper(Context context) {
+        mContext = context;
+        mSensorManager = (SensorManager) mContext .getSystemService(Context.SENSOR_SERVICE);
+        dumpSensorsList();
+    }
+
+    private void dumpSensorsList() {
+        try {
+            FileOutputStream out = mContext.openFileOutput("sensors.txt", Context.MODE_PRIVATE);
+            OutputStreamWriter writer = new OutputStreamWriter(out);
+
+            List<Sensor> sensorList = mSensorManager.getSensorList(Sensor.TYPE_ALL);
+            for (Sensor sensor : sensorList) {
+                writer.write("sensor " + sensor.getType() + " = " + sensor.getName()
+                    + " max batch: " + sensor.getFifoMaxEventCount() + " isWakeUp: " + sensor.isWakeUpSensor() + "\n");
+            }
+            writer.close();
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    public Sensor getCameraActivationSensor() {
+        return mSensorManager.getDefaultSensor(SENSOR_TYPE_MMI_CAMERA_ACTIVATION, true);
+    }
+
+    public Sensor getChopChopSensor() {
+        return mSensorManager.getDefaultSensor(SENSOR_TYPE_MMI_CHOP_CHOP, true);
+    }
+
+    public Sensor getFlatUpSensor() {
+        return mSensorManager.getDefaultSensor(SENSOR_TYPE_MMI_FLAT_UP, true);
+    }
+
+    public Sensor getFlatDownSensor() {
+        return mSensorManager.getDefaultSensor(SENSOR_TYPE_MMI_FLAT_DOWN, true);
+    }
+
+    public Sensor getGlanceSensor() {
+        return mSensorManager.getDefaultSensor(SENSOR_TYPE_MMI_GLANCE, true);
+    }
+    
+    public Sensor getApproachGlanceSensor() {
+        return mSensorManager.getDefaultSensor(SENSOR_TYPE_MMI_GLANCE_APPROACH, true);
+    }
+
+    public Sensor getProximitySensor() {
+        return mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY, true);
+    }
+
+    public Sensor getStowSensor() {
+        return mSensorManager.getDefaultSensor(SENSOR_TYPE_MMI_STOW, true);
+    }
+
+    public void registerListener(Sensor sensor, SensorEventListener listener) {
+        if (!mSensorManager.registerListener(listener, sensor,
+            SensorManager.SENSOR_DELAY_NORMAL, BATCH_LATENCY_IN_MS * 1000)) {
+            throw new RuntimeException("Failed to registerListener for sensor " + sensor);
+        }
+    }
+
+    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);
+    }
+}
diff --git a/LineageActions/src/org/lineageos/settings/device/ServiceWrapper.java b/LineageActions/src/org/lineageos/settings/device/ServiceWrapper.java
new file mode 100644 (file)
index 0000000..de3609a
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * 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 org.lineageos.settings.device;
+
+import android.content.Intent;
+import android.os.Binder;
+import android.os.Bundle;
+import android.os.IBinder;
+import android.util.Log;
+
+public class ServiceWrapper extends android.app.Service {
+    static final String TAG = "LineageActions-ServiceWrapper";
+
+    private final IBinder mBinder = new LocalBinder();
+    private LineageActionsService mLineageActionsService;
+
+    public interface ServiceCallback {
+        void sendResults(int resultCode, Bundle b);
+    }
+
+    public class LocalBinder extends Binder {
+        ServiceWrapper getService() {
+            // Return this instance of the service so clients can call public
+            // methods
+            return ServiceWrapper.this;
+        }
+    }
+
+    @Override
+    public void onCreate() {
+        Log.i(TAG, "onCreate");
+        super.onCreate();
+        mLineageActionsService = new LineageActionsService(this);
+    }
+
+    @Override
+    public IBinder onBind(Intent intent) {
+        Log.i(TAG, "onBind");
+        return null;
+    }
+
+    public void setCallback(ServiceCallback callback) {
+    }
+
+    public void start() {
+        Log.i(TAG, "start");
+    }
+
+    public void stop() {
+    }
+}
diff --git a/LineageActions/src/org/lineageos/settings/device/actions/CameraActivationAction.java b/LineageActions/src/org/lineageos/settings/device/actions/CameraActivationAction.java
new file mode 100644 (file)
index 0000000..3d58992
--- /dev/null
@@ -0,0 +1,135 @@
+/*
+ * 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 org.lineageos.settings.device.actions;
+
+import java.util.List;
+
+import android.app.KeyguardManager;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.ActivityInfo;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+import android.os.PowerManager;
+import android.os.PowerManager.WakeLock;
+import android.os.Vibrator;
+import android.provider.MediaStore;
+import android.util.Log;
+
+import org.lineageos.settings.device.SensorAction;
+
+public class CameraActivationAction implements SensorAction {
+    private static final String TAG = "LineageActions";
+
+    private static final int TURN_SCREEN_ON_WAKE_LOCK_MS = 500;
+
+    private final Context mContext;
+    private final KeyguardManager mKeyguardManager;
+    private final PackageManager mPackageManager;
+    private final PowerManager mPowerManager;
+
+    public CameraActivationAction(Context context) {
+        mContext = context;
+        mKeyguardManager = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
+        mPowerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
+        mPackageManager = context.getPackageManager();
+    }
+
+    @Override
+    public void action() {
+        vibrate();
+        turnScreenOn();
+        if (mKeyguardManager.inKeyguardRestrictedInputMode()) {
+            launchSecureCamera();
+        } else {
+            launchCamera();
+        }
+    }
+
+    private void vibrate() {
+        Vibrator v = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE);
+        v.vibrate(500);
+    }
+
+    private void turnScreenOn() {
+        PowerManager.WakeLock wl = mPowerManager.newWakeLock(
+            PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, TAG);
+        wl.acquire(TURN_SCREEN_ON_WAKE_LOCK_MS);
+    }
+
+    private void launchCamera() {
+        Intent intent = createIntent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
+        if (getBestActivityInfo(intent) != null) {
+            // Only launch if we can succeed, but let the user pick the action
+            mContext.startActivity(intent);
+        }
+    }
+
+    private void launchSecureCamera() {
+        // Keyguard won't allow a picker, try to pick the secure intent in the package
+        // that would be the one used for a default action of launching the camera
+        Intent normalIntent = createIntent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
+        Intent secureIntent = createIntent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
+        ActivityInfo normalActivity = getBestActivityInfo(normalIntent);
+        ActivityInfo secureActivity = getBestActivityInfo(secureIntent, normalActivity);
+        if (secureActivity != null) {
+            secureIntent.setComponent(componentName(secureActivity));
+            mContext.startActivity(secureIntent);
+        }
+    }
+
+    private Intent createIntent(String intentName) {
+        Intent intent = new Intent(intentName);
+        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+        intent.addFlags(Intent.FLAG_FROM_BACKGROUND);
+        return intent;
+    }
+
+    private ActivityInfo getBestActivityInfo(Intent intent) {
+        ResolveInfo resolveInfo = mPackageManager.resolveActivity(intent, 0);
+        if (resolveInfo != null) {
+            return resolveInfo.activityInfo;
+        } else {
+            // If the resolving failed, just find our own best match
+            return getBestActivityInfo(intent, null);
+        }
+    }
+
+    private ActivityInfo getBestActivityInfo(Intent intent, ActivityInfo match) {
+        List <ResolveInfo> activities = mPackageManager.queryIntentActivities(intent, 0);
+        ActivityInfo best = null;
+        if (activities.size() > 0) {
+            best = activities.get(0).activityInfo;
+            if (match != null) {
+                String packageName = match.applicationInfo.packageName;
+                for (int i = activities.size()-1; i >= 0; i--) {
+                    ActivityInfo activityInfo = activities.get(i).activityInfo;
+                    if (packageName.equals(activityInfo.applicationInfo.packageName)) {
+                        best = activityInfo;
+                    }
+                }
+            }
+        }
+        return best;
+    }
+
+    private ComponentName componentName(ActivityInfo activity) {
+        return new ComponentName(activity.applicationInfo.packageName, activity.name);
+    }
+}
diff --git a/LineageActions/src/org/lineageos/settings/device/actions/CameraActivationSensor.java b/LineageActions/src/org/lineageos/settings/device/actions/CameraActivationSensor.java
new file mode 100644 (file)
index 0000000..c83eb6c
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * 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 org.lineageos.settings.device.actions;
+
+import java.util.List;
+
+import android.hardware.Sensor;
+import android.hardware.SensorEvent;
+import android.hardware.SensorEventListener;
+import android.hardware.SensorManager;
+import android.util.Log;
+
+import org.lineageos.settings.device.LineageActionsSettings;
+import org.lineageos.settings.device.SensorHelper;
+
+public class CameraActivationSensor implements SensorEventListener, UpdatedStateNotifier {
+    private static final String TAG = "LineageActions-CameraSensor";
+
+    private static final int TURN_SCREEN_ON_WAKE_LOCK_MS = 500;
+
+    private final LineageActionsSettings mLineageActionsSettings;
+    private final SensorHelper mSensorHelper;
+
+    private final Sensor mSensor;
+
+    private boolean mIsEnabled;
+
+    public CameraActivationSensor(LineageActionsSettings lineageActionsSettings, SensorHelper sensorHelper) {
+        mLineageActionsSettings = lineageActionsSettings;
+        mSensorHelper = sensorHelper;
+        mSensor = sensorHelper.getCameraActivationSensor();
+        mSensorHelper.registerListener(mSensor, this);
+    }
+
+    @Override
+    public synchronized void updateState() {
+        if (mLineageActionsSettings.isCameraGestureEnabled() && !mIsEnabled) {
+            Log.d(TAG, "Enabling");
+            mIsEnabled = true;
+        } else if (! mLineageActionsSettings.isCameraGestureEnabled() && mIsEnabled) {
+            Log.d(TAG, "Disabling");
+            mIsEnabled = false;
+        }
+    }
+
+    @Override
+    public void onSensorChanged(SensorEvent event) {
+        Log.d(TAG, "activate camera");
+        if (mIsEnabled) mLineageActionsSettings.cameraAction();
+    }
+
+    @Override
+    public void onAccuracyChanged(Sensor sensor, int accuracy) {
+    }
+}
diff --git a/LineageActions/src/org/lineageos/settings/device/actions/ChopChopSensor.java b/LineageActions/src/org/lineageos/settings/device/actions/ChopChopSensor.java
new file mode 100644 (file)
index 0000000..0ccd641
--- /dev/null
@@ -0,0 +1,91 @@
+/*
+ * Copyright (c) 2015-2016 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 org.lineageos.settings.device.actions;
+
+import java.util.List;
+
+import android.hardware.Sensor;
+import android.hardware.SensorEvent;
+import android.hardware.SensorEventListener;
+import android.hardware.SensorManager;
+import android.util.Log;
+
+import org.lineageos.settings.device.LineageActionsSettings;
+import org.lineageos.settings.device.SensorHelper;
+
+public class ChopChopSensor implements SensorEventListener, UpdatedStateNotifier {
+    private static final String TAG = "LineageActions-ChopChopSensor";
+
+    private static final int TURN_SCREEN_ON_WAKE_LOCK_MS = 500;
+
+    private final LineageActionsSettings mLineageActionsSettings;
+    private final SensorHelper mSensorHelper;
+    private final Sensor mSensor;
+    private final Sensor mProx;
+
+    private boolean mIsEnabled;
+    private boolean mProxIsCovered;
+
+    public ChopChopSensor(LineageActionsSettings lineageActionsSettings, SensorHelper sensorHelper) {
+        mLineageActionsSettings = lineageActionsSettings;
+        mSensorHelper = sensorHelper;
+        mSensor = sensorHelper.getChopChopSensor();
+        mProx = sensorHelper.getProximitySensor();
+    }
+
+    @Override
+    public synchronized void updateState() {
+        if (mLineageActionsSettings.isChopChopGestureEnabled() && !mIsEnabled) {
+            Log.d(TAG, "Enabling");
+            mSensorHelper.registerListener(mSensor, this);
+            mSensorHelper.registerListener(mProx, mProxListener);
+            mIsEnabled = true;
+        } else if (! mLineageActionsSettings.isChopChopGestureEnabled() && mIsEnabled) {
+            Log.d(TAG, "Disabling");
+            mSensorHelper.unregisterListener(this);
+            mSensorHelper.unregisterListener(mProxListener);
+            mIsEnabled = false;
+        }
+    }
+
+    @Override
+    public void onSensorChanged(SensorEvent event) {
+        Log.d(TAG, "chop chop triggered");
+        if (mProxIsCovered) {
+            Log.d(TAG, "proximity sensor covered, ignoring chop-chop");
+            return;
+        }
+        mLineageActionsSettings.chopChopAction();
+    }
+
+    @Override
+    public void onAccuracyChanged(Sensor sensor, int accuracy) {
+    }
+
+    private SensorEventListener mProxListener = new SensorEventListener() {
+        @Override
+        public synchronized void onSensorChanged(SensorEvent event) {
+            mProxIsCovered = event.values[0] < mProx.getMaximumRange();
+        }
+
+        @Override
+        public void onAccuracyChanged(Sensor mSensor, int accuracy) {
+        }
+    };
+
+}
diff --git a/LineageActions/src/org/lineageos/settings/device/actions/FlipToMute.java b/LineageActions/src/org/lineageos/settings/device/actions/FlipToMute.java
new file mode 100644 (file)
index 0000000..7db8154
--- /dev/null
@@ -0,0 +1,127 @@
+/*
+ * Copyright (c) 2016 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 org.lineageos.settings.device.actions;
+
+import android.app.NotificationManager;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+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.SensorHelper;
+
+public class FlipToMute implements UpdatedStateNotifier {
+    private static final String TAG = "LineageActions-FlipToMute";
+
+    private final NotificationManager mNotificationManager;
+    private final LineageActionsSettings mLineageActionsSettings;
+    private final SensorHelper mSensorHelper;
+    private final Sensor mFlatDown;
+    private final Sensor mStow;
+
+    private boolean mIsEnabled;
+    private boolean mIsFlatDown;
+    private boolean mIsStowed;
+    private int mFilter;
+    private Context mContext;
+    private Receiver mReceiver;
+
+    public FlipToMute(LineageActionsSettings lineageActionsSettings, Context context,
+                SensorHelper sensorHelper) {
+        mLineageActionsSettings = lineageActionsSettings;
+        mContext = context;
+        mSensorHelper = sensorHelper;
+        mFlatDown = sensorHelper.getFlatDownSensor();
+        mStow = sensorHelper.getStowSensor();
+        mNotificationManager =
+            (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
+        mFilter = mNotificationManager.getCurrentInterruptionFilter();
+        mReceiver = new Receiver();
+    }
+
+    @Override
+    public void updateState() {
+        if (mLineageActionsSettings.isFlipToMuteEnabled() && !mIsEnabled) {
+            Log.d(TAG, "Enabling");
+            mSensorHelper.registerListener(mFlatDown, mFlatDownListener);
+            mSensorHelper.registerListener(mStow, mStowListener);
+            mContext.registerReceiver(mReceiver,
+                new IntentFilter(NotificationManager.ACTION_INTERRUPTION_FILTER_CHANGED));
+            mIsEnabled = true;
+        } else if (!mLineageActionsSettings.isFlipToMuteEnabled() && mIsEnabled) {
+            Log.d(TAG, "Disabling");
+            mSensorHelper.unregisterListener(mFlatDownListener);
+            mSensorHelper.unregisterListener(mStowListener);
+            mContext.unregisterReceiver(mReceiver);
+            mIsEnabled = false;
+        }
+    }
+
+    private SensorEventListener mFlatDownListener = new SensorEventListener() {
+        @Override
+        public synchronized void onSensorChanged(SensorEvent event) {
+            mIsFlatDown = (event.values[0] != 0);
+            sensorChange();
+        }
+
+        @Override
+        public void onAccuracyChanged(Sensor mSensor, int accuracy) {
+        }
+    };
+
+    private SensorEventListener mStowListener = new SensorEventListener() {
+        @Override
+        public synchronized void onSensorChanged(SensorEvent event) {
+            mIsStowed = (event.values[0] != 0);
+            sensorChange();
+        }
+
+        @Override
+        public void onAccuracyChanged(Sensor mSensor, int accuracy) {
+        }
+    };
+
+    private void sensorChange() {
+
+        Log.d(TAG, "event: " + mIsFlatDown + " mIsStowed=" + mIsStowed);
+
+        if (mIsFlatDown && mIsStowed) {
+            mNotificationManager.setInterruptionFilter(NotificationManager.INTERRUPTION_FILTER_PRIORITY);
+            Log.d(TAG, "Interrupt filter: Allow priority");
+        } else if (!mIsFlatDown) {
+            mNotificationManager.setInterruptionFilter(mFilter);
+            Log.d(TAG, "Interrupt filter: Restore");
+        }
+    }
+
+    public class Receiver extends BroadcastReceiver {
+
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            if (!mIsFlatDown && !mIsStowed) {
+                mFilter = mNotificationManager.getCurrentInterruptionFilter();
+                Log.d(TAG, "Interrupt filter: Backup");
+            }
+        }
+    }
+}
diff --git a/LineageActions/src/org/lineageos/settings/device/actions/LiftToSilence.java b/LineageActions/src/org/lineageos/settings/device/actions/LiftToSilence.java
new file mode 100644 (file)
index 0000000..4fe671f
--- /dev/null
@@ -0,0 +1,109 @@
+/*
+ * Copyright (c) 2016 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 org.lineageos.settings.device.actions;
+
+import android.content.Context;
+import android.hardware.Sensor;
+import android.hardware.SensorEvent;
+import android.hardware.SensorEventListener;
+import android.telephony.PhoneStateListener;
+import android.telecom.TelecomManager;
+import android.telephony.TelephonyManager;
+import android.util.Log;
+
+import org.lineageos.settings.device.LineageActionsSettings;
+import org.lineageos.settings.device.SensorHelper;
+
+public class LiftToSilence extends PhoneStateListener implements SensorEventListener, UpdatedStateNotifier {
+    private static final String TAG = "LineageActions-LiftToSilence";
+
+    private final LineageActionsSettings mLineageActionsSettings;
+    private final SensorHelper mSensorHelper;
+    private final Sensor mFlatUpSensor;
+    private final Sensor mStowSensor;
+
+    private final TelecomManager mTelecomManager;
+    private final TelephonyManager mTelephonyManager;
+
+    private boolean mIsRinging;
+    private boolean mIsStowed;
+    private boolean mLastFlatUp;
+
+    public LiftToSilence(LineageActionsSettings lineageActionsSettings, Context context,
+                SensorHelper sensorHelper) {
+        mLineageActionsSettings = lineageActionsSettings;
+        mSensorHelper = sensorHelper;
+        mFlatUpSensor = sensorHelper.getFlatUpSensor();
+        mStowSensor = sensorHelper.getStowSensor();
+        mTelecomManager = (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE);
+        mTelephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
+    }
+
+    @Override
+    public void updateState() {
+        if (mLineageActionsSettings.isLiftToSilenceEnabled()) {
+            mTelephonyManager.listen(this, LISTEN_CALL_STATE);
+        } else {
+            mTelephonyManager.listen(this, 0);
+        }
+    }
+
+    @Override
+    public synchronized void onCallStateChanged(int state, String incomingNumber) {
+        if (state == TelephonyManager.CALL_STATE_RINGING && !mIsRinging) {
+            Log.d(TAG, "Ringing started");
+            mSensorHelper.registerListener(mFlatUpSensor, this);
+            mSensorHelper.registerListener(mStowSensor, mStowListener);
+            mIsRinging = true;
+        } else if (state != TelephonyManager.CALL_STATE_RINGING && mIsRinging) {
+            Log.d(TAG, "Ringing stopped");
+            mSensorHelper.unregisterListener(this);
+            mSensorHelper.unregisterListener(mStowListener);
+            mIsRinging = false;
+        }
+    }
+
+
+    @Override
+    public synchronized void onSensorChanged(SensorEvent event) {
+        boolean thisFlatUp = (event.values[0] != 0);
+
+        Log.d(TAG, "event: " + thisFlatUp + " mLastFlatUp=" + mLastFlatUp + " mIsStowed=" +
+            mIsStowed);
+
+        if (mLastFlatUp && !thisFlatUp && !mIsStowed) {
+            mTelecomManager.silenceRinger();
+        }
+        mLastFlatUp = thisFlatUp;
+    }
+
+    @Override
+    public void onAccuracyChanged(Sensor mSensor, int accuracy) {
+    }
+
+    private SensorEventListener mStowListener = new SensorEventListener() {
+        @Override
+        public synchronized void onSensorChanged(SensorEvent event) {
+            mIsStowed = (event.values[0] != 0);
+        }
+
+        @Override
+        public void onAccuracyChanged(Sensor mSensor, int accuracy) {
+        }
+    };
+}
diff --git a/LineageActions/src/org/lineageos/settings/device/actions/ProximitySilencer.java b/LineageActions/src/org/lineageos/settings/device/actions/ProximitySilencer.java
new file mode 100644 (file)
index 0000000..605aaf5
--- /dev/null
@@ -0,0 +1,113 @@
+/*
+ * 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 org.lineageos.settings.device.actions;
+
+import android.content.Context;
+import android.hardware.Sensor;
+import android.hardware.SensorEvent;
+import android.hardware.SensorEventListener;
+import android.telephony.PhoneStateListener;
+import android.telecom.TelecomManager;
+import android.telephony.TelephonyManager;
+import android.util.Log;
+
+import org.lineageos.settings.device.LineageActionsSettings;
+import org.lineageos.settings.device.SensorHelper;
+
+import static android.telephony.TelephonyManager.*;
+
+public class ProximitySilencer extends PhoneStateListener implements SensorEventListener, UpdatedStateNotifier {
+    private static final String TAG = "LineageActions-ProximitySilencer";
+
+    private static final int SILENCE_DELAY_MS = 500;
+
+    private final TelecomManager mTelecomManager;
+    private final TelephonyManager mTelephonyManager;
+    private final LineageActionsSettings mLineageActionsSettings;
+    private final SensorHelper mSensorHelper;
+    private final Sensor mSensor;
+    private boolean mIsRinging;
+    private long mRingStartedMs;
+    private boolean mCoveredRinging;
+
+    public ProximitySilencer(LineageActionsSettings lineageActionsSettings, Context context,
+                SensorHelper sensorHelper) {
+        mTelecomManager = (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE);
+        mTelephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
+
+        mLineageActionsSettings = lineageActionsSettings;
+        mSensorHelper = sensorHelper;
+        mSensor = sensorHelper.getProximitySensor();
+        mCoveredRinging = false;
+        mIsRinging = false;
+    }
+
+    @Override
+    public void updateState() {
+        if (mLineageActionsSettings.isIrSilencerEnabled()) {
+            mTelephonyManager.listen(this, LISTEN_CALL_STATE);
+        } else {
+            mTelephonyManager.listen(this, 0);
+        }
+    }
+
+    @Override
+    public synchronized void onSensorChanged(SensorEvent event) {
+        boolean isNear = event.values[0] < mSensor.getMaximumRange();
+        long now = System.currentTimeMillis();
+
+        if (isNear){
+            if (mIsRinging && (now - mRingStartedMs >= SILENCE_DELAY_MS)){
+                mCoveredRinging = true;
+            } else {
+                mCoveredRinging = false;
+            }
+            return;
+        }
+
+        if (!isNear && mIsRinging) {
+            Log.d(TAG, "event: " + event.values[0] + ", " + " covered " + Boolean.toString(mCoveredRinging));
+            if (mCoveredRinging) {
+                Log.d(TAG, "Silencing ringer");
+                mTelecomManager.silenceRinger();
+            } else {
+                Log.d(TAG, "Ignoring silence gesture: " + now + " is too close to " +
+                        mRingStartedMs + ", delay=" + SILENCE_DELAY_MS + " or covered " + Boolean.toString(mCoveredRinging));
+            }
+            mCoveredRinging = false;
+        }
+    }
+
+    @Override
+    public synchronized void onCallStateChanged(int state, String incomingNumber) {
+        if (state == CALL_STATE_RINGING && !mIsRinging) {
+            Log.d(TAG, "Ringing started");
+            mSensorHelper.registerListener(mSensor, this);
+            mIsRinging = true;
+            mRingStartedMs = System.currentTimeMillis();
+        } else if (state != CALL_STATE_RINGING && mIsRinging) {
+            Log.d(TAG, "Ringing stopped");
+            mSensorHelper.unregisterListener(this);
+            mIsRinging = false;
+        }
+    }
+
+    @Override
+    public void onAccuracyChanged(Sensor mSensor, int accuracy) {
+    }
+}
diff --git a/LineageActions/src/org/lineageos/settings/device/actions/TorchAction.java b/LineageActions/src/org/lineageos/settings/device/actions/TorchAction.java
new file mode 100644 (file)
index 0000000..22ff1f5
--- /dev/null
@@ -0,0 +1,84 @@
+/*
+ * 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 org.lineageos.settings.device.actions;
+
+import android.content.Context;
+import android.hardware.camera2.CameraManager;
+import android.hardware.camera2.CameraCharacteristics;
+import android.hardware.camera2.CameraAccessException;
+import android.os.Vibrator;
+import android.util.Log;
+
+import org.lineageos.settings.device.SensorAction;
+
+public class TorchAction implements SensorAction {
+    private static final String TAG = "LineageActions";
+
+    private static final int TURN_SCREEN_ON_WAKE_LOCK_MS = 500;
+
+    private CameraManager mCameraManager;
+    private final Vibrator mVibrator;
+    private String mRearCameraId;
+    private static boolean mTorchEnabled;
+
+    public TorchAction(Context mContext) {
+        mCameraManager = (CameraManager) mContext.getSystemService(Context.CAMERA_SERVICE);
+        mVibrator = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE);
+        try {
+            for (final String cameraId : mCameraManager.getCameraIdList()) {
+                CameraCharacteristics characteristics =
+                        mCameraManager.getCameraCharacteristics(cameraId);
+                int cOrientation = characteristics.get(CameraCharacteristics.LENS_FACING);
+                if (cOrientation == CameraCharacteristics.LENS_FACING_BACK) {
+                    mRearCameraId = cameraId;
+                    break;
+                }
+            }
+        } catch (CameraAccessException e) {
+        }
+    }
+
+    @Override
+    public void action() {
+        mVibrator.vibrate(250);
+        if (mRearCameraId != null) {
+            try {
+                mCameraManager.setTorchMode(mRearCameraId, !mTorchEnabled);
+                mTorchEnabled = !mTorchEnabled;
+            } catch (CameraAccessException e) {
+            }
+        }
+    }
+
+    private class MyTorchCallback extends CameraManager.TorchCallback {
+
+        @Override
+        public void onTorchModeChanged(String cameraId, boolean enabled) {
+            if (!cameraId.equals(mRearCameraId))
+                return;
+            mTorchEnabled = enabled;
+        }
+
+        @Override
+        public void onTorchModeUnavailable(String cameraId) {
+            if (!cameraId.equals(mRearCameraId))
+                return;
+            mTorchEnabled = false;
+        }
+    }
+}
diff --git a/LineageActions/src/org/lineageos/settings/device/actions/UpdatedStateNotifier.java b/LineageActions/src/org/lineageos/settings/device/actions/UpdatedStateNotifier.java
new file mode 100644 (file)
index 0000000..224a57b
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+ * 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 org.lineageos.settings.device.actions;
+
+public interface UpdatedStateNotifier {
+    public void updateState();
+}
diff --git a/LineageActions/src/org/lineageos/settings/device/doze/DozePulseAction.java b/LineageActions/src/org/lineageos/settings/device/doze/DozePulseAction.java
new file mode 100644 (file)
index 0000000..4445b28
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * 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 org.lineageos.settings.device.doze;
+
+import android.content.Context;
+import android.content.Intent;
+import android.util.Log;
+
+import org.lineageos.settings.device.SensorAction;
+
+public class DozePulseAction implements SensorAction, ScreenStateNotifier {
+    private static final String TAG = "LineageActions";
+
+    private static final int DELAY_BETWEEN_DOZES_IN_MS = 1500;
+
+    private final Context mContext;
+
+    private long mLastDoze;
+
+    public DozePulseAction(Context context) {
+        mContext = context;
+    }
+
+    @Override
+    public void screenTurnedOn() {
+    }
+
+    @Override
+    public void screenTurnedOff() {
+        mLastDoze = System.currentTimeMillis();
+    }
+
+    public void action() {
+         if (mayDoze()) {
+            Log.d(TAG, "Sending doze.pulse intent");
+            mContext.sendBroadcast(new Intent("com.android.systemui.doze.pulse"));
+        }
+    }
+
+    public synchronized boolean mayDoze() {
+        long now = System.currentTimeMillis();
+        if (now - mLastDoze > DELAY_BETWEEN_DOZES_IN_MS) {
+            Log.d(TAG, "Allowing doze");
+            mLastDoze = now;
+            return true;
+        } else {
+            Log.d(TAG, "Denying doze");
+            return false;
+        }
+    }
+}
diff --git a/LineageActions/src/org/lineageos/settings/device/doze/FlatUpSensor.java b/LineageActions/src/org/lineageos/settings/device/doze/FlatUpSensor.java
new file mode 100644 (file)
index 0000000..24255c3
--- /dev/null
@@ -0,0 +1,101 @@
+/*
+ * 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 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 FlatUpSensor implements ScreenStateNotifier {
+    private static final String TAG = "LineageActions-FlatUpSensor";
+
+    private final LineageActionsSettings mLineageActionsSettings;
+    private final SensorHelper mSensorHelper;
+    private final SensorAction mSensorAction;
+    private final Sensor mFlatUpSensor;
+    private final Sensor mStowSensor;
+
+    private boolean mEnabled;
+    private boolean mIsStowed;
+    private boolean mLastFlatUp;
+
+    public FlatUpSensor(LineageActionsSettings LineageActionsSettings, SensorHelper sensorHelper,
+                SensorAction action) {
+        mLineageActionsSettings = LineageActionsSettings;
+        mSensorHelper = sensorHelper;
+        mSensorAction = action;
+
+        mFlatUpSensor = sensorHelper.getFlatUpSensor();
+        mStowSensor = sensorHelper.getStowSensor();
+    }
+
+    @Override
+    public void screenTurnedOn() {
+        if (mEnabled) {
+            Log.d(TAG, "Disabling");
+            mSensorHelper.unregisterListener(mFlatUpListener);
+            mSensorHelper.unregisterListener(mStowListener);
+            mEnabled = false;
+        }
+    }
+
+    @Override
+    public void screenTurnedOff() {
+        if (mLineageActionsSettings.isPickUpEnabled() && !mEnabled) {
+            Log.d(TAG, "Enabling");
+            mSensorHelper.registerListener(mFlatUpSensor, mFlatUpListener);
+            mSensorHelper.registerListener(mStowSensor, mStowListener);
+            mEnabled = true;
+        }
+    }
+
+    private SensorEventListener mFlatUpListener = new SensorEventListener() {
+        @Override
+        public synchronized void onSensorChanged(SensorEvent event) {
+            boolean thisFlatUp = (event.values[0] != 0);
+
+            Log.d(TAG, "event: " + thisFlatUp + " mLastFlatUp=" + mLastFlatUp + " mIsStowed=" +
+                mIsStowed);
+
+            if (mLastFlatUp && ! thisFlatUp && ! mIsStowed) {
+                mSensorAction.action();
+            }
+            mLastFlatUp = thisFlatUp;
+        }
+
+        @Override
+        public void onAccuracyChanged(Sensor mSensor, int accuracy) {
+        }
+    };
+
+    private SensorEventListener mStowListener = new SensorEventListener() {
+        @Override
+        public synchronized void onSensorChanged(SensorEvent event) {
+            mIsStowed = (event.values[0] != 0);
+        }
+
+        @Override
+        public void onAccuracyChanged(Sensor mSensor, int accuracy) {
+        }
+    };
+}
diff --git a/LineageActions/src/org/lineageos/settings/device/doze/GlanceSensor.java b/LineageActions/src/org/lineageos/settings/device/doze/GlanceSensor.java
new file mode 100644 (file)
index 0000000..b557449
--- /dev/null
@@ -0,0 +1,93 @@
+/*
+ * 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 final Sensor mApproachSensor;
+
+    private boolean mEnabled;
+
+    public GlanceSensor(LineageActionsSettings lineageActionsSettings, SensorHelper sensorHelper,
+                SensorAction action) {
+        mLineageActionsSettings = lineageActionsSettings;
+        mSensorHelper = sensorHelper;
+        mSensorAction = action;
+
+        mSensor = sensorHelper.getGlanceSensor();
+        mApproachSensor = sensorHelper.getApproachGlanceSensor();
+    }
+
+    @Override
+    public void screenTurnedOn() {
+        if (mEnabled) {
+            Log.d(TAG, "Disabling");
+            mSensorHelper.unregisterListener(mGlanceListener);
+            mSensorHelper.unregisterListener(mApproachGlanceListener);
+            mEnabled = false;
+        }
+    }
+
+    @Override
+    public void screenTurnedOff() {
+        if (mLineageActionsSettings.isPickUpEnabled() && !mEnabled) {
+            Log.d(TAG, "Enabling");
+            mSensorHelper.registerListener(mSensor, mGlanceListener);
+            mSensorHelper.registerListener(mSensor, mApproachGlanceListener);
+            mEnabled = true;
+        }
+    }
+
+    private SensorEventListener mGlanceListener = new SensorEventListener() {
+        @Override
+        public synchronized void onSensorChanged(SensorEvent event) {
+            Log.d(TAG, "Changed");
+            mSensorAction.action();
+        }
+
+        @Override
+        public void onAccuracyChanged(Sensor mSensor, int accuracy) {
+        }
+    };
+
+    private SensorEventListener mApproachGlanceListener = new SensorEventListener() {
+        @Override
+        public synchronized void onSensorChanged(SensorEvent event) {
+            Log.d(TAG, "Approach: Changed");
+            mSensorAction.action();
+        }
+
+        @Override
+        public void onAccuracyChanged(Sensor mSensor, int accuracy) {
+        }
+    };
+}
diff --git a/LineageActions/src/org/lineageos/settings/device/doze/ProximitySensor.java b/LineageActions/src/org/lineageos/settings/device/doze/ProximitySensor.java
new file mode 100644 (file)
index 0000000..dca3c41
--- /dev/null
@@ -0,0 +1,81 @@
+/*
+ * 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 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 ProximitySensor implements ScreenStateNotifier, SensorEventListener {
+    private static final String TAG = "LineageActions-ProximitySensor";
+
+    private final LineageActionsSettings mLineageActionsSettings;
+    private final SensorHelper mSensorHelper;
+    private final SensorAction mSensorAction;
+    private final Sensor mSensor;
+
+    private boolean mEnabled;
+
+    private boolean mSawNear = false;
+
+    public ProximitySensor(LineageActionsSettings lineageActionsSettings, SensorHelper sensorHelper,
+                SensorAction action) {
+        mLineageActionsSettings = lineageActionsSettings;
+        mSensorHelper = sensorHelper;
+        mSensorAction = action;
+
+        mSensor = sensorHelper.getProximitySensor();
+    }
+
+    @Override
+    public void screenTurnedOn() {
+        if (mEnabled) {
+            Log.d(TAG, "Disabling");
+            mSensorHelper.unregisterListener(this);
+            mEnabled = false;
+        }
+    }
+
+    @Override
+    public void screenTurnedOff() {
+        if (mLineageActionsSettings.isIrWakeupEnabled() && !mEnabled) {
+            Log.d(TAG, "Enabling");
+            mSensorHelper.registerListener(mSensor, this);
+            mEnabled = true;
+        }
+    }
+
+    @Override
+    public void onSensorChanged(SensorEvent event) {
+        boolean isNear = event.values[0] < mSensor.getMaximumRange();
+        if (mSawNear && !isNear) {
+            Log.d(TAG, "wave triggered");
+            mSensorAction.action();
+        }
+        mSawNear = isNear;
+    }
+
+    @Override
+    public void onAccuracyChanged(Sensor mSensor, int accuracy) {
+    }
+}
diff --git a/LineageActions/src/org/lineageos/settings/device/doze/ScreenReceiver.java b/LineageActions/src/org/lineageos/settings/device/doze/ScreenReceiver.java
new file mode 100644 (file)
index 0000000..e8d8024
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * 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 org.lineageos.settings.device.doze;
+
+import java.util.List;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+
+public class ScreenReceiver extends BroadcastReceiver {
+    private final ScreenStateNotifier mNotifier;
+
+    public ScreenReceiver(Context context, ScreenStateNotifier notifier) {
+        mNotifier = notifier;
+
+        IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
+        filter.addAction(Intent.ACTION_SCREEN_OFF);
+        context.registerReceiver(this, filter);
+    }
+
+    @Override
+    public void onReceive(Context context, Intent intent) {
+        if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
+            mNotifier.screenTurnedOff();
+        } else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
+            mNotifier.screenTurnedOn();
+        }
+    }
+}
diff --git a/LineageActions/src/org/lineageos/settings/device/doze/ScreenStateNotifier.java b/LineageActions/src/org/lineageos/settings/device/doze/ScreenStateNotifier.java
new file mode 100644 (file)
index 0000000..7b9ab59
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * 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 org.lineageos.settings.device.doze;
+
+public interface ScreenStateNotifier {
+    public void screenTurnedOn();
+    public void screenTurnedOff();
+}
diff --git a/LineageActions/src/org/lineageos/settings/device/doze/StowSensor.java b/LineageActions/src/org/lineageos/settings/device/doze/StowSensor.java
new file mode 100644 (file)
index 0000000..74c22fe
--- /dev/null
@@ -0,0 +1,91 @@
+/*
+ * 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 org.lineageos.settings.device.doze;
+
+import android.hardware.Sensor;
+import android.hardware.SensorEvent;
+import android.hardware.SensorEventListener;
+import android.util.Log;
+
+import java.lang.System;
+
+import org.lineageos.settings.device.LineageActionsSettings;
+import org.lineageos.settings.device.SensorAction;
+import org.lineageos.settings.device.SensorHelper;
+
+public class StowSensor implements ScreenStateNotifier, SensorEventListener {
+    private static final String TAG = "LineageActions-StowSensor";
+    private static final int IN_POCKET_MIN_TIME = 5000;
+
+    private final LineageActionsSettings mLineageActionsSettings;
+    private final SensorHelper mSensorHelper;
+    private final SensorAction mSensorAction;
+    private final Sensor mSensor;
+
+    private boolean mEnabled;
+    private boolean mLastStowed;
+    private long isStowedTime;
+
+    public StowSensor(LineageActionsSettings lineageActionsSettings, SensorHelper sensorHelper,
+                SensorAction action) {
+        mLineageActionsSettings = lineageActionsSettings;
+        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 (!mLineageActionsSettings.isIrWakeupEnabled() &&
+            mLineageActionsSettings.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) {
+    }
+}
index 4e92917eb3d67aea8c263bf27280511a10a01c5b..d19d8ef103ccd3690bbac8b25d730f0d3d2fd906 100644 (file)
--- a/common.mk
+++ b/common.mk
@@ -178,6 +178,10 @@ PRODUCT_PACKAGES += \
 PRODUCT_PACKAGES += \
     android.hardware.light@2.0-service.exynos9610
 
+# LineageActions
+PRODUCT_PACKAGES += \
+    LineageActions
+
 # Media
 PRODUCT_COPY_FILES += \
     $(COMMON_PATH)/configs/media/media_codecs.xml:$(TARGET_COPY_OUT_VENDOR)/etc/media_codecs.xml \