MotoActions: General cleanup
authorMichael W <baddaemon87@gmail.com>
Fri, 11 Feb 2022 14:38:28 +0000 (15:38 +0100)
committerdianlujitao <dianlujitao@lineageos.org>
Sun, 13 Feb 2022 03:36:30 +0000 (11:36 +0800)
* Remove unused classes, methods, interfaces, imports
* Reorder imports
* Add final where applicable
* Fix line lengths
* Use local variables where possible
* Replace deprecated Vibrator.vibrate(long) with the successor
* Simplify conditions where they are always met
* Rearrange tags and remove unused schemas in resources
* Merge ScreenReceiver into the service
  -> a separate, instantiated but never called-into class makes
     one think it's unused

Change-Id: I05cff7ecaf424c166fedceb1f4f8963164c6085a

35 files changed:
MotoActions/AndroidManifest.xml
MotoActions/res/color/chop.xml
MotoActions/res/color/flip.xml
MotoActions/res/color/pick.xml
MotoActions/res/color/pick2.xml
MotoActions/res/color/pick3.xml
MotoActions/res/color/quick.xml
MotoActions/res/drawable/ic_hand.xml
MotoActions/res/drawable/ic_pickup.xml
MotoActions/res/drawable/ic_pocket.xml
MotoActions/res/drawable/ic_settings_chop.xml
MotoActions/res/drawable/ic_settings_flip.xml
MotoActions/res/drawable/ic_settings_pick.xml
MotoActions/res/drawable/ic_settings_twist.xml
MotoActions/res/drawable/ic_settings_wave.xml
MotoActions/src/org/lineageos/settings/device/ActionsPreferenceActivity.java
MotoActions/src/org/lineageos/settings/device/ActionsPreferenceFragment.java
MotoActions/src/org/lineageos/settings/device/BootCompletedReceiver.java
MotoActions/src/org/lineageos/settings/device/MotoActionsService.java
MotoActions/src/org/lineageos/settings/device/MotoActionsSettings.java
MotoActions/src/org/lineageos/settings/device/SensorAction.java
MotoActions/src/org/lineageos/settings/device/SensorHelper.java
MotoActions/src/org/lineageos/settings/device/ServiceWrapper.java [deleted file]
MotoActions/src/org/lineageos/settings/device/actions/CameraActivationAction.java
MotoActions/src/org/lineageos/settings/device/actions/CameraActivationSensor.java
MotoActions/src/org/lineageos/settings/device/actions/ChopChopSensor.java
MotoActions/src/org/lineageos/settings/device/actions/FlipToMute.java
MotoActions/src/org/lineageos/settings/device/actions/LiftToSilence.java
MotoActions/src/org/lineageos/settings/device/actions/ProximitySilencer.java
MotoActions/src/org/lineageos/settings/device/actions/TorchAction.java
MotoActions/src/org/lineageos/settings/device/actions/UpdatedStateNotifier.java
MotoActions/src/org/lineageos/settings/device/doze/DozePulseAction.java
MotoActions/src/org/lineageos/settings/device/doze/FlatUpSensor.java
MotoActions/src/org/lineageos/settings/device/doze/ScreenReceiver.java [deleted file]
MotoActions/src/org/lineageos/settings/device/doze/ScreenStateNotifier.java

index b7c34103eb8bd6c0e0766358e07e45a8dfea089d..4daf7d212c8061f3a5519d72d823bde0e7250136 100644 (file)
@@ -7,6 +7,7 @@
     <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">
-            <intent-filter>
-                <action android:name="ServiceWrapper"/>
-            </intent-filter>
+        <service android:name="org.lineageos.settings.device.MotoActionsService"
+            android:permission="MotoActionsService">
         </service>
 
         <activity
index dbc4b313f207172b4bd43052c6c41dbdb212d91d..20451d88c0e8387814f4908e1e015b761e3f6d62 100644 (file)
@@ -1,6 +1,11 @@
 <?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>
index 2c494b3616aa07733a5d6d07b3f19977320df65e..8b94f5db8cfc1d3234de1f461d5d3c604cefd186 100644 (file)
@@ -1,6 +1,11 @@
 <?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>
index 07fd2a522ba790c5e2c83b29591c3ebdc83fd63c..09f4d0284dbe4365e441c9371e6ddb39bdf52116 100644 (file)
@@ -1,6 +1,11 @@
 <?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>
index 97b189fc4fd32f4aef0c4c6800275c87517bc8d0..f02c511aed4101a95f771ed7fc520ef0003f8318 100644 (file)
@@ -1,6 +1,11 @@
 <?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>
index aa00b3987b9ac681784487a9dfb31f40c0fc8c9a..5ac80a62b84c03b6b37e2e0e72d3426a965b207e 100644 (file)
@@ -1,6 +1,11 @@
 <?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>
index 215cf11c903abc9e0b96dc2ce44771d0a2c72eef..f5944c450d8430ddba9e1f0ba525ba722df7e728 100644 (file)
@@ -1,6 +1,11 @@
 <?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>
index 6d379fc62d87067731562e02f8f510ee497f67cf..1e79721011b638175ddff9456cdffa19b62dc90b 100644 (file)
@@ -1,9 +1,8 @@
-<!-- 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>
index 9a126652e101d3c8b85c166f93ee4e808ec4c5f3..0f68d5b6d55cd2baaa98de99fafef5e4d8449a16 100644 (file)
@@ -1,9 +1,8 @@
-<!-- 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>
index 44ae6e2a873785e986bbf25de5878647431502bd..b65d441527d42722926b4fa805a22b54fe24c887 100644 (file)
@@ -1,9 +1,8 @@
-<!-- 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>
index 8e2926bf876c916ac29b2a701be3fd58fb2697db..f2df1c1216f9dda239cbfcf566f097f39284ab84 100644 (file)
@@ -1,6 +1,10 @@
 <?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" />
index 7b07736efe500f36138a50774da31e072edad03f..360fe7c88db7fc58512222644a94ae084e03cc45 100644 (file)
@@ -1,6 +1,10 @@
 <?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" />
index adfdece45fa0930871c8344c133dcdd6c7cf687f..df299d3f34e58e97127dcbc89b4d84e332816161 100644 (file)
@@ -1,6 +1,10 @@
 <?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" />
index 50675ca8d0c503ede5d5c00eb6fa2da5e962cab1..f04e77fd982007d48e51c39c2f62a053e8604668 100644 (file)
@@ -1,6 +1,10 @@
 <?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" />
index 5c559a499f213b1ca87d067e6a9c5556cda70b24..8cee58fb4e3b58a2e8fb2bf82211325097fc2d36 100644 (file)
@@ -1,6 +1,10 @@
 <?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" />
index d53cda930f26cf9e241aa018cf8455b3f67e67b6..2bb86efdd7118302b5e91c0522cc54340cb264c7 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * 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.
@@ -25,7 +25,9 @@ public class ActionsPreferenceActivity extends PreferenceActivity {
     @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();
     }
 }
index 38cf260557909d035e790485609699fbb530bf95..7ee570c3a3c4b05d3fe3755f024aa1a3126ed689 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * 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.
@@ -19,21 +19,17 @@ package org.lineageos.settings.device;
 
 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) {
index 198bdbaf1c8a386d0d71b0e6fea946b67da9ea48..dc8610f469ab598bee7ed6147ffe38b8b7aa7bd2 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * 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;
-        }
-    };
 }
index e6e3ec4800a015f783e7cd380ed0ac842e03c448..95073877cf1e09c9babb3d2e7bbefa887ff187e7 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * 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();
         }
@@ -101,9 +102,9 @@ public class MotoActionsService extends IntentService implements ScreenStateNoti
 
     @Override
     public void screenTurnedOff() {
-            if (mWakeLock.isHeld()) {
-                mWakeLock.release();
-            }
+        if (mWakeLock.isHeld()) {
+            mWakeLock.release();
+        }
         for (ScreenStateNotifier screenStateNotifier : mScreenStateNotifiers) {
             screenStateNotifier.screenTurnedOff();
         }
@@ -119,4 +120,15 @@ public class MotoActionsService extends IntentService implements ScreenStateNoti
             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();
+            }
+        }
+    };
 }
index 50ceb613f07581e827660884de6546b45b378722..d1e2e50076b126ffa97d1aa6b34392043acf927a 100644 (file)
 
 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";
@@ -149,35 +148,35 @@ public class MotoActionsSettings {
         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();
+                    }
+                }
+            };
 }
index 4bc72c4fca1ddcfd02bb74c7c6ddda5f36beb2eb..ed57c95c6e7f7a5c733eee190d60a3b8d3327819 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * 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.
@@ -18,5 +18,5 @@
 package org.lineageos.settings.device;
 
 public interface SensorAction {
-    public void action();
+    void action();
 }
index 9ba0d993ef29cb5f65c37ce08864af95aa0d258b..a4d2a3322f32f7b9e0a4749360fd3324aa2eec06 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * 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";
 
@@ -45,7 +44,7 @@ public class SensorHelper {
 
     public SensorHelper(Context context) {
         mContext = context;
-        mSensorManager = (SensorManager) mContext .getSystemService(Context.SENSOR_SERVICE);
+        mSensorManager = (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE);
         dumpSensorsList();
     }
 
@@ -57,7 +56,8 @@ public class SensorHelper {
             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) {
@@ -99,15 +99,4 @@ public class SensorHelper {
     public void unregisterListener(SensorEventListener listener) {
         mSensorManager.unregisterListener(listener);
     }
-
-    /* TriggerSensor */
-    public void requestTriggerSensor(Sensor sensor, TriggerEventListener listener) {
-        if (!mSensorManager.requestTriggerSensor(listener, sensor)) {
-            Log.e(TAG, "Failed to requestTriggerSensor for sensor " + sensor);
-        }
-    }
-
-    public void cancelTriggerSensor(Sensor sensor, TriggerEventListener listener) {
-        mSensorManager.cancelTriggerSensor(listener, sensor);
-    }
 }
diff --git a/MotoActions/src/org/lineageos/settings/device/ServiceWrapper.java b/MotoActions/src/org/lineageos/settings/device/ServiceWrapper.java
deleted file mode 100644 (file)
index 6deb8bf..0000000
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Copyright (c) 2015 The CyanogenMod Project
- * Copyright (c) 2017 The LineageOS Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package 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() {
-    }
-}
index 3bd276c1b0ba9b59f9830f93659c2ac5325a4b86..60a943a392f41bf87f26cc3ffec69a092397a2e4 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * 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.
@@ -17,8 +17,6 @@
 
 package org.lineageos.settings.device.actions;
 
-import java.util.List;
-
 import android.app.KeyguardManager;
 import android.content.ComponentName;
 import android.content.Context;
@@ -27,15 +25,16 @@ 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.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;
 
@@ -43,12 +42,16 @@ public class CameraActivationAction implements SensorAction {
     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
@@ -64,13 +67,11 @@ public class CameraActivationAction implements SensorAction {
 
     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() {
@@ -112,13 +113,13 @@ public class CameraActivationAction implements SensorAction {
     }
 
     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;
index 2d8062b98739f511dc4f8c77e5d45a879e3d3191..847777c949153b485ac096d6b970175261ff24f8 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * 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;
@@ -32,20 +29,15 @@ import org.lineageos.settings.device.SensorHelper;
 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
@@ -53,7 +45,7 @@ public class CameraActivationSensor implements SensorEventListener, UpdatedState
         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;
         }
@@ -62,7 +54,9 @@ public class CameraActivationSensor implements SensorEventListener, UpdatedState
     @Override
     public void onSensorChanged(SensorEvent event) {
         Log.d(TAG, "activate camera");
-        if (mIsEnabled) mMotoActionsSettings.cameraAction();
+        if (mIsEnabled) {
+            mMotoActionsSettings.cameraAction();
+        }
     }
 
     @Override
index e67eeda5ec8dbb4214a69ee5172e1691a26fbbf6..e309905c658ad6fd37c373920a7041b69044c327 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * 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;
@@ -31,8 +28,6 @@ import org.lineageos.settings.device.SensorHelper;
 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;
@@ -41,8 +36,8 @@ public class ChopChopSensor implements SensorEventListener, UpdatedStateNotifier
     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();
@@ -55,7 +50,7 @@ public class ChopChopSensor implements SensorEventListener, UpdatedStateNotifier
             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);
@@ -77,7 +72,7 @@ public class ChopChopSensor implements SensorEventListener, UpdatedStateNotifier
     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();
@@ -87,5 +82,4 @@ public class ChopChopSensor implements SensorEventListener, UpdatedStateNotifier
         public void onAccuracyChanged(Sensor mSensor, int accuracy) {
         }
     };
-
 }
index 3cfd9944ba6d3c4b7f55c0802c1a08392ea52ad9..e1cda5a39dd7ce47a0e777d2f5b4c8a1e5277ab2 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * 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.
@@ -38,23 +38,22 @@ public class FlipToMute implements UpdatedStateNotifier {
     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();
     }
@@ -66,7 +65,7 @@ public class FlipToMute implements UpdatedStateNotifier {
             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");
@@ -77,7 +76,7 @@ public class FlipToMute implements UpdatedStateNotifier {
         }
     }
 
-    private SensorEventListener mFlatDownListener = new SensorEventListener() {
+    private final SensorEventListener mFlatDownListener = new SensorEventListener() {
         @Override
         public synchronized void onSensorChanged(SensorEvent event) {
             mIsFlatDown = (event.values[0] != 0);
@@ -89,7 +88,7 @@ public class FlipToMute implements UpdatedStateNotifier {
         }
     };
 
-    private SensorEventListener mStowListener = new SensorEventListener() {
+    private final SensorEventListener mStowListener = new SensorEventListener() {
         @Override
         public synchronized void onSensorChanged(SensorEvent event) {
             mIsStowed = (event.values[0] != 0);
@@ -102,11 +101,11 @@ public class FlipToMute implements UpdatedStateNotifier {
     };
 
     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);
@@ -115,7 +114,6 @@ public class FlipToMute implements UpdatedStateNotifier {
     }
 
     public class Receiver extends BroadcastReceiver {
-
         @Override
         public void onReceive(Context context, Intent intent) {
             if (!mIsFlatDown && !mIsStowed) {
index 5175489b620d9dd696c73d531bb9462e0ea48cd1..d1e020fb80d5ce87eac0dd5dedce7272a089f6f6 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * 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.
@@ -21,15 +21,16 @@ 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;
 
-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;
@@ -44,14 +45,14 @@ public class LiftToSilence extends PhoneStateListener implements SensorEventList
     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
@@ -84,7 +85,7 @@ public class LiftToSilence extends PhoneStateListener implements SensorEventList
         boolean thisFlatUp = (event.values[0] != 0);
 
         Log.d(TAG, "event: " + thisFlatUp + " mLastFlatUp=" + mLastFlatUp + " mIsStowed=" +
-            mIsStowed);
+                mIsStowed);
 
         if (mLastFlatUp && !thisFlatUp && !mIsStowed) {
             mTelecomManager.silenceRinger();
@@ -96,7 +97,7 @@ public class LiftToSilence extends PhoneStateListener implements SensorEventList
     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);
index d97016e420d8c66ac0774e331011b2e5a1938390..ce6f6f8d4af1c3dc996a0175dee82b2f5c4eb715 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * 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;
@@ -45,12 +46,12 @@ public class ProximitySilencer extends PhoneStateListener implements SensorEvent
     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;
@@ -71,23 +72,19 @@ public class ProximitySilencer extends PhoneStateListener implements SensorEvent
         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;
         }
index d1d824a3233a0013af7de07f0724679007fbdffe..0c221f0a4d86cd996d65ad23fede788af1c48359 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * 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);
@@ -50,18 +48,18 @@ public class TorchAction implements SensorAction {
                     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) {
             }
         }
     }
@@ -70,15 +68,17 @@ public class TorchAction implements SensorAction {
 
         @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;
         }
     }
index 224a57b5ac83a337ab58e9da75b6e32c6ec5c737..ac7e5c854b9c311b95b0258d58b166670644ae4a 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * 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.
@@ -18,5 +18,5 @@
 package org.lineageos.settings.device.actions;
 
 public interface UpdatedStateNotifier {
-    public void updateState();
+    void updateState();
 }
index 267ebce1c0780fa94ab495ebc2b4e46d23a16dfc..319b6cd4654e56a836e67f4f4949fcf75ff1abd0 100644 (file)
@@ -47,7 +47,7 @@ public class DozePulseAction implements SensorAction, ScreenStateNotifier {
     }
 
     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);
index 2a50cc32a6885eca6cf0de780a5d60760094976a..70300f25488a1f81b576bced51e599ebecd8c35a 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * 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.
@@ -40,7 +40,7 @@ public class FlatUpSensor implements ScreenStateNotifier {
     private boolean mLastFlatUp;
 
     public FlatUpSensor(MotoActionsSettings MotoActionsSettings, SensorHelper sensorHelper,
-                SensorAction action) {
+                        SensorAction action) {
         mMotoActionsSettings = MotoActionsSettings;
         mSensorHelper = sensorHelper;
         mSensorAction = action;
@@ -69,15 +69,15 @@ public class FlatUpSensor implements ScreenStateNotifier {
         }
     }
 
-    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;
@@ -88,7 +88,7 @@ public class FlatUpSensor implements ScreenStateNotifier {
         }
     };
 
-    private SensorEventListener mStowListener = new SensorEventListener() {
+    private final SensorEventListener mStowListener = new SensorEventListener() {
         @Override
         public synchronized void onSensorChanged(SensorEvent event) {
             mIsStowed = (event.values[0] != 0);
diff --git a/MotoActions/src/org/lineageos/settings/device/doze/ScreenReceiver.java b/MotoActions/src/org/lineageos/settings/device/doze/ScreenReceiver.java
deleted file mode 100644 (file)
index e8d8024..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright (c) 2015 The CyanogenMod Project
- * Copyright (c) 2017 The LineageOS Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package 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();
-        }
-    }
-}
index 7b9ab5916ef34b270470829b607e7cf38a835584..4d1e511dbab6492343a56880d8196eeed309246e 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * 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.
@@ -18,6 +18,7 @@
 package org.lineageos.settings.device.doze;
 
 public interface ScreenStateNotifier {
-    public void screenTurnedOn();
-    public void screenTurnedOff();
+    void screenTurnedOn();
+
+    void screenTurnedOff();
 }