<original-package android:name="com.cyanogenmod.settings.device" />
<uses-permission android:name="android.permission.ACCESS_NOTIFICATION_POLICY" />
+ <uses-permission android:name="android.permission.MODIFY_PHONE_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.WAKE_LOCK" />
</intent-filter>
</receiver>
- <service
- android:name="ServiceWrapper"
- android:permission="ServiceWrapper"
+ <service android:name="org.lineageos.settings.device.MotoActionsService"
+ android:permission="MotoActionsService"
android:exported="false">
- <intent-filter>
- <action android:name="ServiceWrapper"/>
- </intent-filter>
</service>
<activity
<?xml version="1.0" encoding="utf-8"?>
-<gradient android:angle="0.0" android:type="linear" android:startX="17.406042" android:startY="8.589777" android:endX="5.316899" android:endY="16.000916" xmlns:aapt="http://schemas.android.com/aapt"
- xmlns:android="http://schemas.android.com/apk/res/android">
+<gradient xmlns:android="http://schemas.android.com/apk/res/android"
+ android:angle="0.0"
+ android:endX="5.316899"
+ android:endY="16.000916"
+ android:startX="17.406042"
+ android:startY="8.589777"
+ android:type="linear">
<item android:color="#33939ba3" android:offset="0.01" />
<item android:color="#ffffffff" android:offset="1.0" />
-</gradient>
\ No newline at end of file
+</gradient>
<?xml version="1.0" encoding="utf-8"?>
-<gradient android:angle="0.0" android:type="linear" android:startX="22.63" android:startY="17.89" android:endX="32.77" android:endY="17.89" xmlns:aapt="http://schemas.android.com/aapt"
- xmlns:android="http://schemas.android.com/apk/res/android">
+<gradient xmlns:android="http://schemas.android.com/apk/res/android"
+ android:angle="0.0"
+ android:endX="32.77"
+ android:endY="17.89"
+ android:startX="22.63"
+ android:startY="17.89"
+ android:type="linear">
<item android:color="#33939ba3" android:offset="0.01" />
<item android:color="#ffffffff" android:offset="1.0" />
</gradient>
<?xml version="1.0" encoding="utf-8"?>
-<gradient android:angle="0.0" android:type="linear" android:startX="13.485006" android:startY="33.3201" android:endX="13.485006" android:endY="24.3" xmlns:aapt="http://schemas.android.com/aapt"
- xmlns:android="http://schemas.android.com/apk/res/android">
+<gradient xmlns:android="http://schemas.android.com/apk/res/android"
+ android:angle="0.0"
+ android:endX="13.485006"
+ android:endY="24.3"
+ android:startX="13.485006"
+ android:startY="33.3201"
+ android:type="linear">
<item android:color="#33ffffff" android:offset="0.0" />
<item android:color="#ffffffff" android:offset="1.0" />
</gradient>
<?xml version="1.0" encoding="utf-8"?>
-<gradient android:angle="0.0" android:type="linear" android:startX="16.265007" android:startY="33.38" android:endX="16.265007" android:endY="26.83" xmlns:aapt="http://schemas.android.com/aapt"
- xmlns:android="http://schemas.android.com/apk/res/android">
+<gradient xmlns:android="http://schemas.android.com/apk/res/android"
+ android:angle="0.0"
+ android:endX="16.265007"
+ android:endY="26.83"
+ android:startX="16.265007"
+ android:startY="33.38"
+ android:type="linear">
<item android:color="#33ffffff" android:offset="0.0" />
<item android:color="#ffffffff" android:offset="1.0" />
</gradient>
<?xml version="1.0" encoding="utf-8"?>
-<gradient android:angle="0.0" android:type="linear" android:startX="18.995007" android:startY="33.38" android:endX="18.995007" android:endY="29.55" xmlns:aapt="http://schemas.android.com/aapt"
- xmlns:android="http://schemas.android.com/apk/res/android">
+<gradient xmlns:android="http://schemas.android.com/apk/res/android"
+ android:angle="0.0"
+ android:endX="18.995007"
+ android:endY="29.55"
+ android:startX="18.995007"
+ android:startY="33.38"
+ android:type="linear">
<item android:color="#33ffffff" android:offset="0.0" />
<item android:color="#ffffffff" android:offset="1.0" />
</gradient>
<?xml version="1.0" encoding="utf-8"?>
-<gradient android:angle="0.0" android:type="linear" android:startX="35.431374" android:startY="5.6165676" android:endX="35.524372" android:endY="17.735468" xmlns:aapt="http://schemas.android.com/aapt"
- xmlns:android="http://schemas.android.com/apk/res/android">
+<gradient xmlns:android="http://schemas.android.com/apk/res/android"
+ android:angle="0.0"
+ android:endX="35.524372"
+ android:endY="17.735468"
+ android:startX="35.431374"
+ android:startY="5.6165676"
+ android:type="linear">
<item android:color="#33939ba3" android:offset="0.01" />
<item android:color="#ffffffff" android:offset="1.0" />
</gradient>
-<!-- drawable/ic_hand.xml -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
- android:height="24dp"
- android:width="24dp"
- android:viewportWidth="24"
- android:viewportHeight="24"
- android:tint="?android:attr/colorControlNormal" >
+ android:width="24dp"
+ android:height="24dp"
+ android:tint="?android:attr/colorControlNormal"
+ android:viewportWidth="24"
+ android:viewportHeight="24">
<path android:fillColor="#000" android:pathData="M6.58,19H14.58V22H6.58V19M19.74,11.6C19.55,11.4 19.29,11.28 19,11.28L18.78,11.31L15.58,13V11.83L16.09,2.9C16.12,2.35 15.7,1.87 15.15,1.84C14.6,1.81 14.12,2.23 14.09,2.78L13.82,7.47H13.58L12.54,7.58V2A1,1 0 0,0 11.54,1C11,1 10.54,1.45 10.54,2V8.41L9.72,8.78L9.03,3.32C8.96,2.77 8.46,2.38 7.91,2.45C7.36,2.5 6.97,3 7.04,3.57L7.81,9.63L7.43,9.8C7.3,9.85 7.18,9.93 7.07,10L5.97,6.11C5.81,5.54 5.25,5.2 4.71,5.34C4.18,5.5 3.88,6.08 4.04,6.65L6.61,15.77C6.61,15.8 6.63,15.84 6.64,15.87L6.67,16H6.68C6.9,16.57 7.47,17 8.08,17H14.58C14.97,17 15.32,16.84 15.58,16.57L20.5,12.37L19.74,11.6Z" />
</vector>
-<!-- drawable/ic_pickup.xml -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
- android:height="24dp"
- android:width="24dp"
- android:viewportWidth="24"
- android:viewportHeight="24"
- android:tint="?android:attr/colorControlNormal" >
+ android:width="24dp"
+ android:height="24dp"
+ android:tint="?android:attr/colorControlNormal"
+ android:viewportWidth="24"
+ android:viewportHeight="24">
<path android:fillColor="#000" android:pathData="M9.64,13.4C8.63,12.5 7.34,12.03 6,12V15L2,11L6,7V10C7.67,10 9.3,10.57 10.63,11.59C10.22,12.15 9.89,12.76 9.64,13.4M18,15V12C17.5,12 13.5,12.16 13.05,16.2C14.61,16.75 15.43,18.47 14.88,20.03C14.33,21.59 12.61,22.41 11.05,21.86C9.5,21.3 8.67,19.59 9.22,18.03C9.5,17.17 10.2,16.5 11.05,16.2C11.34,12.61 14.4,9.88 18,10V7L22,11L18,15M13,19A1,1 0 0,0 12,18A1,1 0 0,0 11,19A1,1 0 0,0 12,20A1,1 0 0,0 13,19M11,11.12C11.58,10.46 12.25,9.89 13,9.43V5H16L12,1L8,5H11V11.12Z" />
</vector>
-<!-- drawable/pocket.xml -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
- android:height="24dp"
android:width="24dp"
+ android:height="24dp"
+ android:tint="?android:attr/colorControlNormal"
android:viewportWidth="24"
- android:viewportHeight="24"
- android:tint="?android:attr/colorControlNormal" >
+ android:viewportHeight="24">
<path android:fillColor="#000" android:pathData="M21.9,4.26C21.64,3.55 20.96,3.07 20.2,3.07H20.19L18.46,3.07H3.81C3.07,3.07 2.39,3.54 2.12,4.24C2.04,4.45 2,4.66 2,4.88V10.92L2.07,12.12C2.36,14.85 3.78,17.23 5.97,18.9C6,18.93 6.05,18.96 6.09,19H6.11C7.29,19.86 8.6,20.44 10,20.73C10.68,20.86 11.35,20.93 12,20.93C12.63,20.93 13.25,20.87 13.85,20.76C13.93,20.75 14,20.73 14.07,20.72C14.09,20.71 14.11,20.7 14.14,20.69C15.5,20.4 16.76,19.83 17.89,19H17.91C17.95,18.96 18,18.93 18.03,18.9C20.22,17.23 21.64,14.85 21.93,12.12L22,10.92V4.88C22,4.68 21.97,4.47 21.9,4.26M17.67,10.55L12.96,15.06C12.7,15.32 12.35,15.44 12,15.44C11.67,15.44 11.33,15.32 11.06,15.06L6.36,10.55C5.81,10.03 5.79,9.16 6.32,8.61C6.84,8.06 7.71,8.05 8.26,8.57L12,12.17L15.77,8.57C16.31,8.05 17.18,8.07 17.71,8.61C18.23,9.16 18.21,10.03 17.67,10.55Z" />
</vector>
<?xml version="1.0" encoding="utf-8"?>
-<vector android:height="46.0dip" android:width="46.0dip" android:autoMirrored="true" android:viewportWidth="46.0" android:viewportHeight="46.0" xmlns:aapt="http://schemas.android.com/aapt"
- xmlns:android="http://schemas.android.com/apk/res/android">
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="46.0dip"
+ android:height="46.0dip"
+ android:autoMirrored="true"
+ android:viewportWidth="46.0"
+ android:viewportHeight="46.0">
<path android:fillColor="?android:attr/colorAccent" android:pathData="M20,20m-19.5,0a19.5,19.5 0,1 1,39 0a19.5,19.5 0,1 1,-39 0" />
<path android:fillColor="#00000000" android:pathData="M20.0003,20.0038m-16.3277,6.4349a17.55,17.55 113.49,1 1,32.6554 -12.8699a17.55,17.55 113.49,1 1,-32.6554 12.8699" android:strokeColor="#ff0bbbef" android:strokeWidth="0.28" android:strokeAlpha="0.0" android:fillAlpha="0.0" />
<path android:fillColor="#ffffffff" android:pathData="M10.7614,17.0817L16.1565,11.2698A2,2 64.8053,0 1,18.983 11.1647L32.7688,23.9618A2,2 93.8141,0 1,32.874 26.7883L27.4789,32.6002A2,2 85.2688,0 1,24.6524 32.7053L10.8666,19.9082A2,2 68.6013,0 1,10.7614 17.0817z" />
<?xml version="1.0" encoding="utf-8"?>
-<vector android:height="46.0dip" android:width="46.0dip" android:autoMirrored="true" android:viewportWidth="46.0" android:viewportHeight="46.0" xmlns:aapt="http://schemas.android.com/aapt"
- xmlns:android="http://schemas.android.com/apk/res/android">
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="46.0dip"
+ android:height="46.0dip"
+ android:autoMirrored="true"
+ android:viewportWidth="46.0"
+ android:viewportHeight="46.0">
<path android:fillColor="?android:attr/colorAccent" android:pathData="M20,20m-19.5,0a19.5,19.5 0,1 1,39 0a19.5,19.5 0,1 1,-39 0" />
<path android:fillColor="#00000000" android:pathData="M20.0003,20.0038m-16.3277,6.4349a17.55,17.55 113.49,1 1,32.6554 -12.8699a17.55,17.55 113.49,1 1,-32.6554 12.8699" android:strokeColor="#ff0bbbef" android:strokeWidth="0.28" android:strokeAlpha="0.0" android:fillAlpha="0.0" />
<path android:fillColor="#ffffffff" android:pathData="M31.45,30v0.7H8.63V30A1.41,1.41 0,0 1,10 28.57h20A1.41,1.41 0,0 1,31.45 30Z" />
<?xml version="1.0" encoding="utf-8"?>
-<vector android:height="46.0dip" android:width="46.0dip" android:autoMirrored="true" android:viewportWidth="46.0" android:viewportHeight="46.0" xmlns:aapt="http://schemas.android.com/aapt"
- xmlns:android="http://schemas.android.com/apk/res/android">
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="46.0dip"
+ android:height="46.0dip"
+ android:autoMirrored="true"
+ android:viewportWidth="46.0"
+ android:viewportHeight="46.0">
<path android:fillColor="?android:attr/colorAccent" android:pathData="M20,20m-19.5,0a19.5,19.5 0,1 1,39 0a19.5,19.5 0,1 1,-39 0" />
<path android:fillColor="#ffffffff" android:pathData="M13.6,18l4.9,-4.9c0.8,-0.8 2,-0.8 2.8,0L33.2,25c0.8,0.8 0.8,2 0,2.8l-4.9,4.9c-0.8,0.8 -2,0.8 -2.8,0L13.6,20.8C12.8,20 12.8,18.7 13.6,18z" />
<path android:fillColor="?android:attr/colorAccent" android:pathData="M28.3,31.2c-2,0 -5.5,-0.2 -6.1,-0.2c-0.7,0 -1.3,-0.6 -1.3,-1.3c0,-0.7 0.5,-1.2 1.2,-1.3l-2.4,-0.1c-0.4,0 -0.7,-0.2 -0.9,-0.4c-0.3,-0.3 -0.4,-0.6 -0.4,-1c0,-0.7 0.5,-1.2 1.2,-1.3l-2.5,-0.1c-0.7,-0.1 -1.2,-0.8 -1.1,-1.5c0.1,-0.5 0.5,-1 1,-1.1l-2.6,-0.1c-0.4,0 -0.7,-0.2 -0.9,-0.4c-0.2,-0.3 -0.4,-0.6 -0.4,-1c0.1,-0.7 0.6,-1.2 1.3,-1.2h0.1l10.6,0.5h0.1c0.3,0 0.6,-0.1 0.7,-0.4c0.1,-0.1 0.1,-0.2 0.1,-0.3c0,-0.2 -0.1,-0.4 -0.2,-0.6c-0.6,-0.9 -1,-1.7 -1.4,-2.4c-0.2,-0.3 -0.3,-0.7 -0.3,-1.1c0,-0.6 0.3,-1.1 0.8,-1.4c0.2,-0.1 0.3,-0.2 0.5,-0.2c0.2,0 0.4,0.1 0.6,0.3l1.2,1.1l5.3,5.3c0.7,0.7 1.1,1.8 1.1,2.8v0.1c0,0.2 0,0.4 0,0.7v0.1c0,0.2 0,0.3 0,0.5c0,0.6 -0.1,1.2 -0.2,1.9C32.9,29.3 30.9,31.1 28.3,31.2L28.3,31.2z" />
<?xml version="1.0" encoding="utf-8"?>
-<vector android:height="46.0dip" android:width="46.0dip" android:autoMirrored="true" android:viewportWidth="46.0" android:viewportHeight="46.0" xmlns:aapt="http://schemas.android.com/aapt"
- xmlns:android="http://schemas.android.com/apk/res/android">
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="46.0dip"
+ android:height="46.0dip"
+ android:autoMirrored="true"
+ android:viewportWidth="46.0"
+ android:viewportHeight="46.0">
<path android:fillColor="?android:attr/colorAccent" android:pathData="M20,20m-19.5,0a19.5,19.5 0,1 1,39 0a19.5,19.5 0,1 1,-39 0" />
<path android:fillColor="#00000000" android:pathData="M20.0003,20.0038m-16.3277,6.4349a17.55,17.55 113.49,1 1,32.6554 -12.8699a17.55,17.55 113.49,1 1,-32.6554 12.8699" android:strokeColor="#ff0bbbef" android:strokeWidth="0.28" android:strokeAlpha="0.0" android:fillAlpha="0.0" />
<path android:fillColor="#00000000" android:pathData="M20.0003,20.0062m-6.4349,16.3277a17.55,17.55 66.51,1 1,12.8699 -32.6554a17.55,17.55 66.51,1 1,-12.8699 32.6554" android:strokeColor="#ff0bbbef" android:strokeWidth="0.28" android:strokeAlpha="0.0" android:fillAlpha="0.0" />
<?xml version="1.0" encoding="utf-8"?>
-<vector android:height="46.0dip" android:width="46.0dip" android:autoMirrored="true" android:viewportWidth="46.0" android:viewportHeight="46.0"
- xmlns:android="http://schemas.android.com/apk/res/android">
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="46.0dip"
+ android:height="46.0dip"
+ android:autoMirrored="true"
+ android:viewportWidth="46.0"
+ android:viewportHeight="46.0">
<path android:fillColor="?android:attr/colorAccent" android:pathData="M20,20m-19.5,0a19.5,19.5 0,1 1,39 0a19.5,19.5 0,1 1,-39 0" />
<path android:fillColor="#00000000" android:pathData="M20.0003,20.0038m-16.3277,6.4349a17.55,17.55 113.49,1 1,32.6554 -12.8699a17.55,17.55 113.49,1 1,-32.6554 12.8699" android:strokeColor="#ff0bbbef" android:strokeWidth="0.28" android:strokeAlpha="0.0" android:fillAlpha="0.0" />
<path android:fillColor="#ffffffff" android:pathData="M15.81,26.74l8.38,0a2.11,2.11 0,0 0,2.11 -2.1V6.06A2.11,2.11 0,0 0,24.19 4l-8.38,0A2.12,2.12 0,0 0,13.7 6v18.6A2.12,2.12 0,0 0,15.81 26.74Z" />
/*
* Copyright (c) 2016 The CyanogenMod Project
- * Copyright (c) 2017 The LineageOS Project
+ * Copyright (c) 2017-2022 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.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- getFragmentManager().beginTransaction()
- .replace(android.R.id.content, new ActionsPreferenceFragment()).commit();
+ getFragmentManager()
+ .beginTransaction()
+ .replace(android.R.id.content, new ActionsPreferenceFragment())
+ .commit();
}
}
/*
* Copyright (C) 2015-2016 The CyanogenMod Project
- * Copyright (C) 2017 The LineageOS Project
+ * Copyright (C) 2017-2022 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.
import android.app.ActionBar;
import android.os.Bundle;
-import androidx.preference.Preference;
+import android.view.MenuItem;
+
import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceFragment;
-import androidx.preference.SwitchPreference;
-import android.text.TextUtils;
-import android.view.MenuItem;
import org.lineageos.settings.device.actions.CameraActivationSensor;
-import java.io.File;
-
public class ActionsPreferenceFragment extends PreferenceFragment {
- private final String KEY_ACTIONS_CATEGORY = "actions_key";
- private final String KEY_GESTURE_CAMERA_ACTION = "gesture_camera_action";
+ private static final String KEY_ACTIONS_CATEGORY = "actions_key";
+ private static final String KEY_GESTURE_CAMERA_ACTION = "gesture_camera_action";
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
/*
* Copyright (c) 2015 The CyanogenMod Project
- * Copyright (c) 2017 The LineageOS Project
+ * Copyright (c) 2017-2022 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.
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.os.UserHandle;
import android.util.Log;
-import org.lineageos.settings.device.ServiceWrapper.LocalBinder;
-
public class BootCompletedReceiver extends BroadcastReceiver {
- static final String TAG = "MotoActions";
- private ServiceWrapper mServiceWrapper;
+ private static final String TAG = "MotoActions";
@Override
public void onReceive(final Context context, Intent intent) {
Log.i(TAG, "Booting");
- context.startService(new Intent(context, ServiceWrapper.class));
+ context.startServiceAsUser(new Intent(context, MotoActionsService.class),
+ UserHandle.CURRENT);
}
-
- 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;
- }
- };
}
/*
* Copyright (c) 2015 The CyanogenMod Project
- * Copyright (c) 2017 The LineageOS Project
+ * Copyright (c) 2017-2022 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.
package org.lineageos.settings.device;
-import android.app.IntentService;
+import android.app.Service;
+import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
+import android.content.IntentFilter;
+import android.os.IBinder;
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.actions.UpdatedStateNotifier;
import org.lineageos.settings.device.doze.DozePulseAction;
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 MotoActionsService extends IntentService implements ScreenStateNotifier,
+import java.util.LinkedList;
+import java.util.List;
+
+public class MotoActionsService extends Service implements ScreenStateNotifier,
UpdatedStateNotifier {
private static final String TAG = "MotoActions";
- private final Context mContext;
+ private final List<ScreenStateNotifier> mScreenStateNotifiers = new LinkedList<>();
+ private final List<UpdatedStateNotifier> mUpdatedStateNotifiers = new LinkedList<>();
- 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 MotoActionsService(Context context) {
- super("MotoActionservice");
- mContext = context;
+ private PowerManager mPowerManager;
+ private PowerManager.WakeLock mWakeLock;
+ public void onCreate() {
Log.d(TAG, "Starting");
- MotoActionsSettings MotoActionsSettings = new MotoActionsSettings(context, this);
- mSensorHelper = new SensorHelper(context);
- mScreenReceiver = new ScreenReceiver(context, this);
+ MotoActionsSettings actionsSettings = new MotoActionsSettings(this, this);
+ SensorHelper sensorHelper = new SensorHelper(this);
+ DozePulseAction dozePulseAction = new DozePulseAction(this);
- mDozePulseAction = new DozePulseAction(context);
- mScreenStateNotifiers.add(mDozePulseAction);
+ mScreenStateNotifiers.add(dozePulseAction);
// Actionable sensors get screen on/off notifications
- mScreenStateNotifiers.add(new StowSensor(MotoActionsSettings, mSensorHelper, mDozePulseAction));
- mScreenStateNotifiers.add(new FlatUpSensor(MotoActionsSettings, mSensorHelper, mDozePulseAction));
+ mScreenStateNotifiers.add(new StowSensor(actionsSettings, sensorHelper, dozePulseAction));
+ mScreenStateNotifiers.add(new FlatUpSensor(actionsSettings, sensorHelper, dozePulseAction));
// Other actions that are always enabled
- mUpdatedStateNotifiers.add(new CameraActivationSensor(MotoActionsSettings, mSensorHelper));
- mUpdatedStateNotifiers.add(new ChopChopSensor(MotoActionsSettings, mSensorHelper));
- mUpdatedStateNotifiers.add(new ProximitySilencer(MotoActionsSettings, context, mSensorHelper));
- mUpdatedStateNotifiers.add(new FlipToMute(MotoActionsSettings, context, mSensorHelper));
- mUpdatedStateNotifiers.add(new LiftToSilence(MotoActionsSettings, context, mSensorHelper));
-
- mPowerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
- mWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MotoActionsWakeLock");
+ mUpdatedStateNotifiers.add(new CameraActivationSensor(actionsSettings, sensorHelper));
+ mUpdatedStateNotifiers.add(new ChopChopSensor(actionsSettings, sensorHelper));
+ mUpdatedStateNotifiers.add(new ProximitySilencer(actionsSettings, this, sensorHelper));
+ mUpdatedStateNotifiers.add(new FlipToMute(actionsSettings, this, sensorHelper));
+ mUpdatedStateNotifiers.add(new LiftToSilence(actionsSettings, this, sensorHelper));
+
+ mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
+ mWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
+ TAG + ":WakeLock");
+
+ IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
+ filter.addAction(Intent.ACTION_SCREEN_OFF);
+ registerReceiver(mScreenStateReceiver, filter);
+
updateState();
}
+ public int onStartCommand(Intent intent, int flags, int startId) {
+ return START_STICKY;
+ }
+
@Override
- protected void onHandleIntent(Intent intent) {
+ public IBinder onBind(Intent intent) {
+ return null;
}
@Override
public void screenTurnedOn() {
- if (!mWakeLock.isHeld()) {
- mWakeLock.acquire();
- }
+ if (!mWakeLock.isHeld()) {
+ mWakeLock.acquire();
+ }
for (ScreenStateNotifier screenStateNotifier : mScreenStateNotifiers) {
screenStateNotifier.screenTurnedOn();
}
@Override
public void screenTurnedOff() {
- if (mWakeLock.isHeld()) {
- mWakeLock.release();
- }
+ if (mWakeLock.isHeld()) {
+ mWakeLock.release();
+ }
for (ScreenStateNotifier screenStateNotifier : mScreenStateNotifiers) {
screenStateNotifier.screenTurnedOff();
}
notifier.updateState();
}
}
+
+ private final BroadcastReceiver mScreenStateReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
+ screenTurnedOff();
+ } else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
+ screenTurnedOn();
+ }
+ }
+ };
}
package org.lineageos.settings.device;
+import static android.provider.Settings.Secure.DOZE_ALWAYS_ON;
+import static android.provider.Settings.Secure.DOZE_ENABLED;
+
import android.content.Context;
import android.content.SharedPreferences;
import android.hardware.display.AmbientDisplayConfiguration;
import android.os.UserHandle;
-import android.preference.PreferenceManager;
import android.provider.Settings;
-import org.lineageos.settings.device.actions.UpdatedStateNotifier;
+import androidx.preference.PreferenceManager;
+
import org.lineageos.settings.device.actions.CameraActivationAction;
import org.lineageos.settings.device.actions.TorchAction;
-
-import static android.provider.Settings.Secure.DOZE_ALWAYS_ON;
-import static android.provider.Settings.Secure.DOZE_ENABLED;
+import org.lineageos.settings.device.actions.UpdatedStateNotifier;
public class MotoActionsSettings {
- private static final String TAG = "MotoActions";
-
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_IR_SILENCER_KEY = "gesture_ir_silencer";
mLiftToSilenceEnabled = sharedPreferences.getBoolean(GESTURE_LIFT_TO_SILENCE_KEY, false);
}
- private SharedPreferences.OnSharedPreferenceChangeListener mPrefListener =
+ private final 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_POCKET_KEY.equals(key)) {
- mPocketGestureEnabled = sharedPreferences.getBoolean(GESTURE_POCKET_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();
- }
- }
- };
+ @Override
+ public void onSharedPreferenceChanged(SharedPreferences sharedPrefs, String key) {
+ boolean updated = true;
+
+ if (GESTURE_CAMERA_ACTION_KEY.equals(key)) {
+ mCameraGestureEnabled = sharedPrefs.getBoolean(GESTURE_CAMERA_ACTION_KEY, true);
+ } else if (GESTURE_CHOP_CHOP_KEY.equals(key)) {
+ mChopChopEnabled = sharedPrefs.getBoolean(GESTURE_CHOP_CHOP_KEY, true);
+ } else if (GESTURE_IR_WAKEUP_KEY.equals(key)) {
+ mIrWakeUpEnabled = sharedPrefs.getBoolean(GESTURE_IR_WAKEUP_KEY, true);
+ } else if (GESTURE_PICK_UP_KEY.equals(key)) {
+ mPickUpGestureEnabled = sharedPrefs.getBoolean(GESTURE_PICK_UP_KEY, true);
+ } else if (GESTURE_POCKET_KEY.equals(key)) {
+ mPocketGestureEnabled = sharedPrefs.getBoolean(GESTURE_POCKET_KEY, true);
+ } else if (GESTURE_IR_SILENCER_KEY.equals(key)) {
+ mIrSilencerEnabled = sharedPrefs.getBoolean(GESTURE_IR_SILENCER_KEY, false);
+ } else if (GESTURE_FLIP_TO_MUTE_KEY.equals(key)) {
+ mFlipToMuteEnabled = sharedPrefs.getBoolean(GESTURE_FLIP_TO_MUTE_KEY, false);
+ } else if (GESTURE_LIFT_TO_SILENCE_KEY.equals(key)) {
+ mLiftToSilenceEnabled = sharedPrefs.getBoolean(GESTURE_LIFT_TO_SILENCE_KEY, false);
+ } else {
+ updated = false;
+ }
+
+ if (updated) {
+ mUpdatedStateNotifier.updateState();
+ }
+ }
+ };
}
/*
* Copyright (c) 2015 The CyanogenMod Project
- * Copyright (c) 2017 The LineageOS Project
+ * Copyright (c) 2017-2022 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.
package org.lineageos.settings.device;
public interface SensorAction {
- public void action();
+ void action();
}
/*
* Copyright (c) 2015 The CyanogenMod Project
- * Copyright (c) 2017-2020 The LineageOS Project
+ * Copyright (c) 2017-2022 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.
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;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.util.List;
+
public class SensorHelper {
private static final String TAG = "MotoActions";
public SensorHelper(Context context) {
mContext = context;
- mSensorManager = (SensorManager) mContext .getSystemService(Context.SENSOR_SERVICE);
+ mSensorManager = (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE);
dumpSensorsList();
}
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");
+ + " max batch: " + sensor.getFifoMaxEventCount() + " isWakeUp: "
+ + sensor.isWakeUpSensor() + "\n");
}
writer.close();
} catch (IOException e) {
public void unregisterListener(SensorEventListener listener) {
mSensorManager.unregisterListener(listener);
}
-
- /* TriggerSensor */
- public void requestTriggerSensor(Sensor sensor, TriggerEventListener listener) {
- if (!mSensorManager.requestTriggerSensor(listener, sensor)) {
- Log.e(TAG, "Failed to requestTriggerSensor for sensor " + sensor);
- }
- }
-
- public void cancelTriggerSensor(Sensor sensor, TriggerEventListener listener) {
- mSensorManager.cancelTriggerSensor(listener, sensor);
- }
}
+++ /dev/null
-/*
- * 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 = "MotoActions-ServiceWrapper";
-
- private final IBinder mBinder = new LocalBinder();
- private MotoActionsService mMotoActionsService;
-
- 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();
- mMotoActionsService = new MotoActionsService(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() {
- }
-}
/*
* Copyright (c) 2015 The CyanogenMod Project
- * Copyright (c) 2017 The LineageOS Project
+ * Copyright (c) 2017-2022 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.
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.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.PowerManager;
-import android.os.PowerManager.WakeLock;
+import android.os.VibrationEffect;
import android.os.Vibrator;
import android.provider.MediaStore;
-import android.util.Log;
import org.lineageos.settings.device.SensorAction;
+import java.util.List;
+
public class CameraActivationAction implements SensorAction {
- private static final String TAG = "MotoActions";
+ private static final String TAG = "CameraActivationAction";
private static final int TURN_SCREEN_ON_WAKE_LOCK_MS = 500;
private final KeyguardManager mKeyguardManager;
private final PackageManager mPackageManager;
private final PowerManager mPowerManager;
+ private final PowerManager.WakeLock mScreenWakelock;
public CameraActivationAction(Context context) {
mContext = context;
mKeyguardManager = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
mPowerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
mPackageManager = context.getPackageManager();
+ mScreenWakelock = mPowerManager.newWakeLock(
+ PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP,
+ TAG + ":Wakelock");
}
@Override
private void vibrate() {
Vibrator v = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE);
- v.vibrate(500);
+ v.vibrate(VibrationEffect.createOneShot(500, VibrationEffect.DEFAULT_AMPLITUDE));
}
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);
+ mScreenWakelock.acquire(TURN_SCREEN_ON_WAKE_LOCK_MS);
}
private void launchCamera() {
}
private ActivityInfo getBestActivityInfo(Intent intent, ActivityInfo match) {
- List <ResolveInfo> activities = mPackageManager.queryIntentActivities(intent, 0);
+ 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--) {
+ for (int i = activities.size() - 1; i >= 0; i--) {
ActivityInfo activityInfo = activities.get(i).activityInfo;
if (packageName.equals(activityInfo.applicationInfo.packageName)) {
best = activityInfo;
/*
* Copyright (c) 2015 The CyanogenMod Project
- * Copyright (c) 2017-2020 The LineageOS Project
+ * Copyright (c) 2017-2022 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.
package org.lineageos.settings.device.actions;
-import java.util.List;
-
import android.content.Context;
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.MotoActionsSettings;
public class CameraActivationSensor implements SensorEventListener, UpdatedStateNotifier {
private static final String TAG = "MotoActions-CameraSensor";
- private static final int TURN_SCREEN_ON_WAKE_LOCK_MS = 500;
-
private final MotoActionsSettings mMotoActionsSettings;
- private final SensorHelper mSensorHelper;
-
- private final Sensor mSensor;
private boolean mIsEnabled;
- public CameraActivationSensor(MotoActionsSettings MotoActionsSettings, SensorHelper sensorHelper) {
- mMotoActionsSettings = MotoActionsSettings;
- mSensorHelper = sensorHelper;
- mSensor = sensorHelper.getCameraActivationSensor();
- mSensorHelper.registerListener(mSensor, this);
+ public CameraActivationSensor(MotoActionsSettings motoActionsSettings,
+ SensorHelper sensorHelper) {
+ mMotoActionsSettings = motoActionsSettings;
+ Sensor sensor = sensorHelper.getCameraActivationSensor();
+ sensorHelper.registerListener(sensor, this);
}
@Override
if (mMotoActionsSettings.isCameraGestureEnabled() && !mIsEnabled) {
Log.d(TAG, "Enabling");
mIsEnabled = true;
- } else if (! mMotoActionsSettings.isCameraGestureEnabled() && mIsEnabled) {
+ } else if (!mMotoActionsSettings.isCameraGestureEnabled() && mIsEnabled) {
Log.d(TAG, "Disabling");
mIsEnabled = false;
}
@Override
public void onSensorChanged(SensorEvent event) {
Log.d(TAG, "activate camera");
- if (mIsEnabled) mMotoActionsSettings.cameraAction();
+ if (mIsEnabled) {
+ mMotoActionsSettings.cameraAction();
+ }
}
@Override
/*
* Copyright (c) 2015-2016 The CyanogenMod Project
- * Copyright (c) 2017 The LineageOS Project
+ * Copyright (c) 2017-2022 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.
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.MotoActionsSettings;
public class ChopChopSensor implements SensorEventListener, UpdatedStateNotifier {
private static final String TAG = "MotoActions-ChopChopSensor";
- private static final int TURN_SCREEN_ON_WAKE_LOCK_MS = 500;
-
private final MotoActionsSettings mMotoActionsSettings;
private final SensorHelper mSensorHelper;
private final Sensor mSensor;
private boolean mIsEnabled;
private boolean mProxIsCovered;
- public ChopChopSensor(MotoActionsSettings MotoActionsSettings, SensorHelper sensorHelper) {
- mMotoActionsSettings = MotoActionsSettings;
+ public ChopChopSensor(MotoActionsSettings motoActionsSettings, SensorHelper sensorHelper) {
+ mMotoActionsSettings = motoActionsSettings;
mSensorHelper = sensorHelper;
mSensor = sensorHelper.getChopChopSensor();
mProx = sensorHelper.getProximitySensor();
mSensorHelper.registerListener(mSensor, this);
mSensorHelper.registerListener(mProx, mProxListener);
mIsEnabled = true;
- } else if (! mMotoActionsSettings.isChopChopGestureEnabled() && mIsEnabled) {
+ } else if (!mMotoActionsSettings.isChopChopGestureEnabled() && mIsEnabled) {
Log.d(TAG, "Disabling");
mSensorHelper.unregisterListener(this);
mSensorHelper.unregisterListener(mProxListener);
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
- private SensorEventListener mProxListener = new SensorEventListener() {
+ private final SensorEventListener mProxListener = new SensorEventListener() {
@Override
public synchronized void onSensorChanged(SensorEvent event) {
mProxIsCovered = event.values[0] < mProx.getMaximumRange();
public void onAccuracyChanged(Sensor mSensor, int accuracy) {
}
};
-
}
/*
* Copyright (c) 2016 The CyanogenMod Project
- * Copyright (c) 2017 The LineageOS Project
+ * Copyright (c) 2017-2022 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.
private final SensorHelper mSensorHelper;
private final Sensor mFlatDown;
private final Sensor mStow;
+ private final Receiver mReceiver;
private boolean mIsEnabled;
private boolean mIsFlatDown;
private boolean mIsStowed;
private int mFilter;
- private Context mContext;
- private Receiver mReceiver;
+ private final Context mContext;
- public FlipToMute(MotoActionsSettings MotoActionsSettings, Context context,
- SensorHelper sensorHelper) {
- mMotoActionsSettings = MotoActionsSettings;
+ public FlipToMute(MotoActionsSettings motoActionsSettings, Context context,
+ SensorHelper sensorHelper) {
+ mMotoActionsSettings = motoActionsSettings;
mContext = context;
mSensorHelper = sensorHelper;
mFlatDown = sensorHelper.getFlatDownSensor();
mStow = sensorHelper.getStowSensor();
- mNotificationManager =
- (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
+ mNotificationManager = context.getSystemService(NotificationManager.class);
mFilter = mNotificationManager.getCurrentInterruptionFilter();
mReceiver = new Receiver();
}
mSensorHelper.registerListener(mFlatDown, mFlatDownListener);
mSensorHelper.registerListener(mStow, mStowListener);
mContext.registerReceiver(mReceiver,
- new IntentFilter(NotificationManager.ACTION_INTERRUPTION_FILTER_CHANGED));
+ new IntentFilter(NotificationManager.ACTION_INTERRUPTION_FILTER_CHANGED));
mIsEnabled = true;
} else if (!mMotoActionsSettings.isFlipToMuteEnabled() && mIsEnabled) {
Log.d(TAG, "Disabling");
}
}
- private SensorEventListener mFlatDownListener = new SensorEventListener() {
+ private final SensorEventListener mFlatDownListener = new SensorEventListener() {
@Override
public synchronized void onSensorChanged(SensorEvent event) {
mIsFlatDown = (event.values[0] != 0);
}
};
- private SensorEventListener mStowListener = new SensorEventListener() {
+ private final SensorEventListener mStowListener = new SensorEventListener() {
@Override
public synchronized void onSensorChanged(SensorEvent event) {
mIsStowed = (event.values[0] != 0);
};
private void sensorChange() {
-
Log.d(TAG, "event: " + mIsFlatDown + " mIsStowed=" + mIsStowed);
if (mIsFlatDown && mIsStowed) {
- mNotificationManager.setInterruptionFilter(NotificationManager.INTERRUPTION_FILTER_PRIORITY);
+ mNotificationManager.setInterruptionFilter(
+ NotificationManager.INTERRUPTION_FILTER_PRIORITY);
Log.d(TAG, "Interrupt filter: Allow priority");
} else if (!mIsFlatDown) {
mNotificationManager.setInterruptionFilter(mFilter);
}
public class Receiver extends BroadcastReceiver {
-
@Override
public void onReceive(Context context, Intent intent) {
if (!mIsFlatDown && !mIsStowed) {
/*
* Copyright (c) 2016 The CyanogenMod Project
- * Copyright (c) 2017 The LineageOS Project
+ * Copyright (c) 2017-2022 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.
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
-import android.telephony.PhoneStateListener;
import android.telecom.TelecomManager;
+import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.util.Log;
import org.lineageos.settings.device.MotoActionsSettings;
import org.lineageos.settings.device.SensorHelper;
-public class LiftToSilence extends PhoneStateListener implements SensorEventListener, UpdatedStateNotifier {
+public class LiftToSilence extends PhoneStateListener implements SensorEventListener,
+ UpdatedStateNotifier {
private static final String TAG = "MotoActions-LiftToSilence";
private final MotoActionsSettings mMotoActionsSettings;
private boolean mIsStowed;
private boolean mLastFlatUp;
- public LiftToSilence(MotoActionsSettings MotoActionsSettings, Context context,
- SensorHelper sensorHelper) {
- mMotoActionsSettings = MotoActionsSettings;
+ public LiftToSilence(MotoActionsSettings motoActionsSettings, Context context,
+ SensorHelper sensorHelper) {
+ mMotoActionsSettings = motoActionsSettings;
mSensorHelper = sensorHelper;
mFlatUpSensor = sensorHelper.getFlatUpSensor();
mStowSensor = sensorHelper.getStowSensor();
mTelecomManager = (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE);
- mTelephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
+ mTelephonyManager = context.getSystemService(TelephonyManager.class);
}
@Override
boolean thisFlatUp = (event.values[0] != 0);
Log.d(TAG, "event: " + thisFlatUp + " mLastFlatUp=" + mLastFlatUp + " mIsStowed=" +
- mIsStowed);
+ mIsStowed);
if (mLastFlatUp && !thisFlatUp && !mIsStowed) {
mTelecomManager.silenceRinger();
public void onAccuracyChanged(Sensor mSensor, int accuracy) {
}
- private SensorEventListener mStowListener = new SensorEventListener() {
+ private final SensorEventListener mStowListener = new SensorEventListener() {
@Override
public synchronized void onSensorChanged(SensorEvent event) {
mIsStowed = (event.values[0] != 0);
/*
* Copyright (c) 2015 The CyanogenMod Project
- * Copyright (c) 2017 The LineageOS Project
+ * Copyright (c) 2017-2022 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.
package org.lineageos.settings.device.actions;
+import static android.telephony.TelephonyManager.CALL_STATE_RINGING;
+
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.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.util.Log;
import org.lineageos.settings.device.MotoActionsSettings;
import org.lineageos.settings.device.SensorHelper;
-import static android.telephony.TelephonyManager.*;
-
-public class ProximitySilencer extends PhoneStateListener implements SensorEventListener, UpdatedStateNotifier {
+public class ProximitySilencer extends PhoneStateListener implements SensorEventListener,
+ UpdatedStateNotifier {
private static final String TAG = "MotoActions-ProximitySilencer";
private static final int SILENCE_DELAY_MS = 500;
private long mRingStartedMs;
private boolean mCoveredRinging;
- public ProximitySilencer(MotoActionsSettings MotoActionsSettings, Context context,
- SensorHelper sensorHelper) {
+ public ProximitySilencer(MotoActionsSettings motoActionsSettings, Context context,
+ SensorHelper sensorHelper) {
mTelecomManager = (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE);
- mTelephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
+ mTelephonyManager = context.getSystemService(TelephonyManager.class);
- mMotoActionsSettings = MotoActionsSettings;
+ mMotoActionsSettings = motoActionsSettings;
mSensorHelper = sensorHelper;
mSensor = sensorHelper.getProximitySensor();
mCoveredRinging = false;
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;
- }
+ if (isNear) {
+ mCoveredRinging = mIsRinging && (now - mRingStartedMs >= SILENCE_DELAY_MS);
return;
}
- if (!isNear && mIsRinging) {
- Log.d(TAG, "event: " + event.values[0] + ", " + " covered " + Boolean.toString(mCoveredRinging));
+ if (mIsRinging) {
+ Log.d(TAG, "event: " + event.values[0] + ", " + " covered " + 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));
+ mRingStartedMs + ", delay=" + SILENCE_DELAY_MS);
}
mCoveredRinging = false;
}
/*
* Copyright (c) 2015 The CyanogenMod Project
- * Copyright (c) 2017 The LineageOS Project
+ * Copyright (c) 2017-2022 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.
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.hardware.camera2.CameraCharacteristics;
+import android.hardware.camera2.CameraManager;
+import android.os.VibrationEffect;
import android.os.Vibrator;
-import android.util.Log;
import org.lineageos.settings.device.SensorAction;
public class TorchAction implements SensorAction {
- private static final String TAG = "MotoActions";
-
- private static final int TURN_SCREEN_ON_WAKE_LOCK_MS = 500;
+ private static boolean mTorchEnabled;
- private CameraManager mCameraManager;
+ private final CameraManager mCameraManager;
private final Vibrator mVibrator;
+
private String mRearCameraId;
- private static boolean mTorchEnabled;
public TorchAction(Context mContext) {
mCameraManager = (CameraManager) mContext.getSystemService(Context.CAMERA_SERVICE);
break;
}
}
- } catch (CameraAccessException e) {
+ } catch (CameraAccessException ignored) {
}
}
@Override
public void action() {
- mVibrator.vibrate(250);
+ mVibrator.vibrate(VibrationEffect.createOneShot(250, VibrationEffect.DEFAULT_AMPLITUDE));
if (mRearCameraId != null) {
try {
mCameraManager.setTorchMode(mRearCameraId, !mTorchEnabled);
mTorchEnabled = !mTorchEnabled;
- } catch (CameraAccessException e) {
+ } catch (CameraAccessException ignored) {
}
}
}
@Override
public void onTorchModeChanged(String cameraId, boolean enabled) {
- if (!cameraId.equals(mRearCameraId))
+ if (!cameraId.equals(mRearCameraId)) {
return;
+ }
mTorchEnabled = enabled;
}
@Override
public void onTorchModeUnavailable(String cameraId) {
- if (!cameraId.equals(mRearCameraId))
+ if (!cameraId.equals(mRearCameraId)) {
return;
+ }
mTorchEnabled = false;
}
}
/*
* Copyright (c) 2015 The CyanogenMod Project
- * Copyright (c) 2017 The LineageOS Project
+ * Copyright (c) 2017-2022 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.
package org.lineageos.settings.device.actions;
public interface UpdatedStateNotifier {
- public void updateState();
+ void updateState();
}
}
public void action() {
- if (mayDoze()) {
+ if (mayDoze()) {
Log.d(TAG, "Sending doze.pulse intent");
Intent pulseIntent = new Intent("com.android.systemui.doze.pulse");
mContext.sendBroadcastAsUser(pulseIntent, UserHandle.CURRENT);
/*
* Copyright (c) 2015 The CyanogenMod Project
- * Copyright (C) 2017 The LineageOS Project
+ * Copyright (C) 2017-2022 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.
private boolean mLastFlatUp;
public FlatUpSensor(MotoActionsSettings MotoActionsSettings, SensorHelper sensorHelper,
- SensorAction action) {
+ SensorAction action) {
mMotoActionsSettings = MotoActionsSettings;
mSensorHelper = sensorHelper;
mSensorAction = action;
}
}
- private SensorEventListener mFlatUpListener = new SensorEventListener() {
+ private final 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);
+ mIsStowed);
- if (mLastFlatUp && ! thisFlatUp && ! mIsStowed) {
+ if (mLastFlatUp && !thisFlatUp && !mIsStowed) {
mSensorAction.action();
}
mLastFlatUp = thisFlatUp;
}
};
- private SensorEventListener mStowListener = new SensorEventListener() {
+ private final SensorEventListener mStowListener = new SensorEventListener() {
@Override
public synchronized void onSensorChanged(SensorEvent event) {
mIsStowed = (event.values[0] != 0);
+++ /dev/null
-/*
- * 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();
- }
- }
-}
/*
* Copyright (c) 2015 The CyanogenMod Project
- * Copyright (c) 2017 The LineageOS Project
+ * Copyright (c) 2017-2022 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.
package org.lineageos.settings.device.doze;
public interface ScreenStateNotifier {
- public void screenTurnedOn();
- public void screenTurnedOff();
+ void screenTurnedOn();
+
+ void screenTurnedOff();
}