forked from jens/Automation
delayed lock screen
This commit is contained in:
@ -403,4 +403,26 @@ public class DateTimeListener extends BroadcastReceiver implements AutomationLis
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public class TimeObject
|
||||
{
|
||||
int hours, minutes, seconds;
|
||||
|
||||
public int getHours()
|
||||
{
|
||||
return hours;
|
||||
}
|
||||
|
||||
public void setHours(int hours)
|
||||
{
|
||||
this.hours = hours;
|
||||
}
|
||||
|
||||
public TimeObject(int hours, int minutes, int seconds)
|
||||
{
|
||||
this.hours = hours;
|
||||
this.minutes = minutes;
|
||||
this.seconds = seconds;
|
||||
}
|
||||
}
|
||||
}
|
@ -7,12 +7,8 @@ import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.os.BatteryManager;
|
||||
import android.os.Build;
|
||||
import android.os.PowerManager;
|
||||
import android.provider.Settings;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.RequiresApi;
|
||||
|
||||
@ -23,13 +19,13 @@ import com.jens.automation2.Rule;
|
||||
import com.jens.automation2.Trigger.Trigger_Enum;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
public class ScreenStateReceiver extends BroadcastReceiver implements AutomationListenerInterface
|
||||
{
|
||||
static int screenState = -1; // initialize with a better value than this
|
||||
static int screenPowerState = -1; // initialize with a better value than this
|
||||
static int screenLockState = -1; // initialize with a better value than this
|
||||
public static AutomationService automationServiceRef = null;
|
||||
|
||||
private static boolean screenStateReceiverActive = false;
|
||||
@ -37,7 +33,14 @@ public class ScreenStateReceiver extends BroadcastReceiver implements Automation
|
||||
private static Intent screenStatusIntent = null;
|
||||
private static BroadcastReceiver screenStateReceiverInstance = null;
|
||||
|
||||
public final static String broadcastScreenLocked = "automation.system.screen_locked";
|
||||
public final static String broadcastScreenLockedWithoutSecurity = "automation.system.screen_locked_without_security";
|
||||
public final static String broadcastScreenLockedWithSecurity = "automation.system.screen_locked_with_security";
|
||||
|
||||
public final static int SCREEN_STATE_OFF = 0;
|
||||
public final static int SCREEN_STATE_ON = 1;
|
||||
public final static int SCREEN_STATE_UNLOCKED = 2;
|
||||
public final static int SCREEN_STATE_LOCKED_WITHOUT_SECURITY = 3;
|
||||
public final static int SCREEN_STATE_LOCKED_WITH_SECURITY = 4;
|
||||
|
||||
public static BroadcastReceiver getScreenStateReceiverInstance()
|
||||
{
|
||||
@ -62,7 +65,7 @@ public class ScreenStateReceiver extends BroadcastReceiver implements Automation
|
||||
screenStateIntentFilter.addAction(Intent.ACTION_SCREEN_OFF);
|
||||
screenStateIntentFilter.addAction(Intent.ACTION_SCREEN_ON);
|
||||
screenStateIntentFilter.addAction(Intent.ACTION_USER_PRESENT); // also fired when device is unlocked
|
||||
screenStateIntentFilter.addAction(broadcastScreenLocked);
|
||||
screenStateIntentFilter.addAction(broadcastScreenLockedWithSecurity);
|
||||
// Intent.ACTION_USER_UNLOCKED
|
||||
}
|
||||
|
||||
@ -91,16 +94,14 @@ public class ScreenStateReceiver extends BroadcastReceiver implements Automation
|
||||
return screenStateReceiverActive;
|
||||
}
|
||||
|
||||
public static int getScreenState()
|
||||
public static int getScreenPowerState()
|
||||
{
|
||||
return screenState;
|
||||
return screenPowerState;
|
||||
}
|
||||
|
||||
private static int currentChargingState = 0; //0=unknown, 1=no, 2=yes
|
||||
|
||||
public static int getCurrentChargingState()
|
||||
public static int getScreenLockState()
|
||||
{
|
||||
return currentChargingState;
|
||||
return screenLockState;
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP_MR1)
|
||||
@ -118,7 +119,7 @@ public class ScreenStateReceiver extends BroadcastReceiver implements Automation
|
||||
{
|
||||
if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF))
|
||||
{
|
||||
ScreenStateReceiver.screenState = 0;
|
||||
ScreenStateReceiver.screenPowerState = SCREEN_STATE_OFF;
|
||||
|
||||
// Method 2
|
||||
// PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
|
||||
@ -134,10 +135,13 @@ public class ScreenStateReceiver extends BroadcastReceiver implements Automation
|
||||
Miscellaneous.logEvent("i", "ScreenStateReceiver", "keyguardManager.isKeyguardLocked(): " + String.valueOf(keyguardManager.isKeyguardLocked()), 4);
|
||||
Miscellaneous.logEvent("i", "ScreenStateReceiver", "keyguardManager.isDeviceLocked(): " + String.valueOf(keyguardManager.isDeviceLocked()), 4);
|
||||
|
||||
boolean locked = keyguardManager.isKeyguardLocked() && keyguardManager.isDeviceLocked();
|
||||
if (locked)
|
||||
if(keyguardManager.isKeyguardLocked() && !keyguardManager.isDeviceLocked())
|
||||
{
|
||||
sendLockBroadcast(context);
|
||||
sendLockBroadcast(Miscellaneous.getAnyContext(), broadcastScreenLockedWithoutSecurity);
|
||||
}
|
||||
else if(keyguardManager.isDeviceLocked())
|
||||
{
|
||||
sendLockBroadcast(Miscellaneous.getAnyContext(), broadcastScreenLockedWithSecurity);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -148,15 +152,19 @@ public class ScreenStateReceiver extends BroadcastReceiver implements Automation
|
||||
}
|
||||
else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON))
|
||||
{
|
||||
ScreenStateReceiver.screenState = 1;
|
||||
ScreenStateReceiver.screenPowerState = SCREEN_STATE_ON;
|
||||
}
|
||||
else if (intent.getAction().equals(Intent.ACTION_USER_PRESENT))
|
||||
{
|
||||
ScreenStateReceiver.screenState = 2;
|
||||
ScreenStateReceiver.screenLockState = SCREEN_STATE_UNLOCKED;
|
||||
}
|
||||
else if (intent.getAction().equals(broadcastScreenLocked))
|
||||
else if (intent.getAction().equals(broadcastScreenLockedWithoutSecurity))
|
||||
{
|
||||
ScreenStateReceiver.screenState = 3;
|
||||
ScreenStateReceiver.screenLockState = SCREEN_STATE_LOCKED_WITHOUT_SECURITY;
|
||||
}
|
||||
else if (intent.getAction().equals(broadcastScreenLockedWithSecurity))
|
||||
{
|
||||
ScreenStateReceiver.screenLockState = SCREEN_STATE_LOCKED_WITH_SECURITY;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -222,10 +230,18 @@ public class ScreenStateReceiver extends BroadcastReceiver implements Automation
|
||||
{
|
||||
KeyguardManager keyguardManager = (KeyguardManager) Miscellaneous.getAnyContext().getSystemService(Context.KEYGUARD_SERVICE);
|
||||
|
||||
boolean locked = keyguardManager.isKeyguardLocked() && keyguardManager.isDeviceLocked();
|
||||
if (locked)
|
||||
Miscellaneous.logEvent("i", "ScreenStateReceiver", "keyguardManager.isKeyguardLocked(): " + String.valueOf(keyguardManager.isKeyguardLocked()), 4);
|
||||
Miscellaneous.logEvent("i", "ScreenStateReceiver", "keyguardManager.isDeviceLocked(): " + String.valueOf(keyguardManager.isDeviceLocked()), 4);
|
||||
|
||||
if(keyguardManager.isKeyguardLocked() && !keyguardManager.isDeviceLocked())
|
||||
{
|
||||
sendLockBroadcast(Miscellaneous.getAnyContext());
|
||||
sendLockBroadcast(Miscellaneous.getAnyContext(), broadcastScreenLockedWithoutSecurity);
|
||||
timer.purge();
|
||||
timer.cancel();
|
||||
}
|
||||
else if(keyguardManager.isDeviceLocked())
|
||||
{
|
||||
sendLockBroadcast(Miscellaneous.getAnyContext(), broadcastScreenLockedWithSecurity);
|
||||
timer.purge();
|
||||
timer.cancel();
|
||||
}
|
||||
@ -258,10 +274,10 @@ public class ScreenStateReceiver extends BroadcastReceiver implements Automation
|
||||
}
|
||||
}
|
||||
|
||||
static void sendLockBroadcast(Context context)
|
||||
static void sendLockBroadcast(Context context, String lockType)
|
||||
{
|
||||
Intent lockedBroadcastIntent = new Intent();
|
||||
lockedBroadcastIntent.setAction(broadcastScreenLocked);
|
||||
lockedBroadcastIntent.setAction(lockType);
|
||||
context.sendBroadcast(lockedBroadcastIntent);
|
||||
}
|
||||
}
|
@ -14,14 +14,13 @@ import com.jens.automation2.Trigger.Trigger_Enum;
|
||||
public class TimeZoneListener extends BroadcastReceiver implements AutomationListenerInterface
|
||||
{
|
||||
private static TimeZoneListener timeZoneListenerInstance = null;
|
||||
protected static boolean timeZoneListenerActive = false;
|
||||
protected static boolean timezoneListenerActive = false;
|
||||
protected static AutomationService automationServiceRef = null;
|
||||
protected static IntentFilter timeZoneListenerIntentFilter = null;
|
||||
|
||||
protected static IntentFilter timezoneListenerIntentFilter = null;
|
||||
|
||||
public static boolean isTimeZoneListenerActive()
|
||||
public static boolean isTimezoneListenerActive()
|
||||
{
|
||||
return timeZoneListenerActive;
|
||||
return timezoneListenerActive;
|
||||
}
|
||||
|
||||
public static void startTimeZoneListener(AutomationService automationService)
|
||||
@ -33,19 +32,19 @@ public class TimeZoneListener extends BroadcastReceiver implements AutomationLis
|
||||
|
||||
try
|
||||
{
|
||||
if(!timeZoneListenerActive && Rule.isAnyRuleUsing(Trigger_Enum.timeFrame))
|
||||
if(!timezoneListenerActive && Rule.isAnyRuleUsing(Trigger_Enum.timeFrame))
|
||||
{
|
||||
Miscellaneous.logEvent("i", "TimeZoneListener", "Starting TimeZoneListener", 4);
|
||||
timeZoneListenerActive = true;
|
||||
timezoneListenerActive = true;
|
||||
|
||||
if(timeZoneListenerIntentFilter == null)
|
||||
if(timezoneListenerIntentFilter == null)
|
||||
{
|
||||
timeZoneListenerIntentFilter = new IntentFilter();
|
||||
timeZoneListenerIntentFilter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
|
||||
timeZoneListenerIntentFilter.addAction(Intent.ACTION_TIME_CHANGED);
|
||||
timezoneListenerIntentFilter = new IntentFilter();
|
||||
timezoneListenerIntentFilter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
|
||||
timezoneListenerIntentFilter.addAction(Intent.ACTION_TIME_CHANGED);
|
||||
}
|
||||
|
||||
automationService.registerReceiver(timeZoneListenerInstance, timeZoneListenerIntentFilter);
|
||||
automationService.registerReceiver(timeZoneListenerInstance, timezoneListenerIntentFilter);
|
||||
}
|
||||
}
|
||||
catch(Exception ex)
|
||||
@ -57,11 +56,11 @@ public class TimeZoneListener extends BroadcastReceiver implements AutomationLis
|
||||
{
|
||||
try
|
||||
{
|
||||
if(timeZoneListenerActive)
|
||||
if(timezoneListenerActive)
|
||||
{
|
||||
Miscellaneous.logEvent("i", "TimeZoneListener", "Stopping TimeZoneListener", 4);
|
||||
automationServiceRef.unregisterReceiver(timeZoneListenerInstance);
|
||||
timeZoneListenerActive = false;
|
||||
timezoneListenerActive = false;
|
||||
}
|
||||
}
|
||||
catch(Exception ex)
|
||||
@ -81,7 +80,7 @@ public class TimeZoneListener extends BroadcastReceiver implements AutomationLis
|
||||
}
|
||||
else if(action.equals(Intent.ACTION_TIME_CHANGED))
|
||||
{
|
||||
Miscellaneous.logEvent("i", "TimeZoneListener", "Device time changed. Reloading alarms.", 4);
|
||||
Miscellaneous.logEvent("i", "TimeZoneListener", "Device time changed. Reloading alarms.", 3);
|
||||
DateTimeListener.reloadAlarms();
|
||||
}
|
||||
}
|
||||
@ -104,7 +103,7 @@ public class TimeZoneListener extends BroadcastReceiver implements AutomationLis
|
||||
@Override
|
||||
public boolean isListenerRunning()
|
||||
{
|
||||
return TimeZoneListener.isTimeZoneListenerActive();
|
||||
return TimeZoneListener.isTimezoneListenerActive();
|
||||
}
|
||||
@Override
|
||||
public Trigger_Enum[] getMonitoredTrigger()
|
||||
|
Reference in New Issue
Block a user