From fa578b175d64c93258eb1bb94059e3d369693921 Mon Sep 17 00:00:00 2001 From: Jens Date: Wed, 8 Dec 2021 23:08:05 +0100 Subject: [PATCH] Refactoring --- .../java/com/jens/automation2/Actions.java | 36 +++++++++++++++++-- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/jens/automation2/Actions.java b/app/src/main/java/com/jens/automation2/Actions.java index cee7f6d..2e4f1ed 100644 --- a/app/src/main/java/com/jens/automation2/Actions.java +++ b/app/src/main/java/com/jens/automation2/Actions.java @@ -5,6 +5,7 @@ import android.annotation.SuppressLint; import android.annotation.TargetApi; import android.app.NotificationManager; import android.app.PendingIntent; +import android.app.admin.DevicePolicyManager; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothManager; @@ -1131,12 +1132,41 @@ public class Actions public static void turnOffScreen() { Miscellaneous.logEvent("i", "Actions", "Turning screen off.", 3); + + DevicePolicyManager deviceManger = (DevicePolicyManager)Miscellaneous.getAnyContext().getSystemService(Context. DEVICE_POLICY_SERVICE); + deviceManger.lockNow(); + + /*params.flags |= LayoutParams.FLAG_KEEP_SCREEN_ON; + params.screenBrightness = 0; + getWindow().setAttributes(params); + PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); -// WakeLock wakeLock = pm.newWakeLock(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK, "tag"); - WakeLock wakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK , "tag"); - wakeLock.acquire(); + WakeLock wakeLock = pm.newWakeLock(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK, "tag"); +// WakeLock wakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK , "tag"); + wakeLock.acquire();*/ } + // using root + /*private void turnOffScreen() + { + try + { + Class c = Class.forName("android.os.PowerManager"); + PowerManager mPowerManager = (PowerManager) this.getSystemService(Context.POWER_SERVICE); + for(Method m : c.getDeclaredMethods()){ + if(m.getName().equals("goToSleep")){ + m.setAccessible(true); + if(m.getParameterTypes().length == 1){ + m.invoke(mPowerManager,SystemClock.uptimeMillis()-2); + } + } + } + } + catch (Exception e) + { + } + }*/ + @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) @SuppressLint("NewApi") public static boolean setAirplaneMode(boolean desiredState, boolean toggleActionIfPossible)