v2.0.1: APK verification, stay awake fix, configurable auto-fix retries
This commit is contained in:
@@ -12,7 +12,8 @@ import com.getcapacitor.annotation.CapacitorPlugin;
|
||||
|
||||
@CapacitorPlugin(name = "Wake")
|
||||
public class WakePlugin extends Plugin {
|
||||
private PowerManager.WakeLock wakeLock;
|
||||
private PowerManager.WakeLock screenWakeLock;
|
||||
private PowerManager.WakeLock cpuWakeLock;
|
||||
private boolean isHeld = false;
|
||||
|
||||
@Override
|
||||
@@ -22,7 +23,7 @@ public class WakePlugin extends Plugin {
|
||||
|
||||
@PluginMethod
|
||||
public void acquire(PluginCall call) {
|
||||
if (isHeld && wakeLock != null) {
|
||||
if (isHeld) {
|
||||
call.resolve(new JSObject().put("held", true));
|
||||
return;
|
||||
}
|
||||
@@ -33,10 +34,20 @@ public class WakePlugin extends Plugin {
|
||||
});
|
||||
|
||||
PowerManager pm = (PowerManager) getContext().getSystemService(Context.POWER_SERVICE);
|
||||
wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "zai-chat:wakelock");
|
||||
wakeLock.acquire(12 * 60 * 60 * 1000L);
|
||||
isHeld = true;
|
||||
|
||||
screenWakeLock = pm.newWakeLock(
|
||||
PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE,
|
||||
"zai-chat:screen"
|
||||
);
|
||||
screenWakeLock.acquire(24 * 60 * 60 * 1000L);
|
||||
|
||||
cpuWakeLock = pm.newWakeLock(
|
||||
PowerManager.PARTIAL_WAKE_LOCK,
|
||||
"zai-chat:cpu"
|
||||
);
|
||||
cpuWakeLock.acquire(24 * 60 * 60 * 1000L);
|
||||
|
||||
isHeld = true;
|
||||
call.resolve(new JSObject().put("held", true));
|
||||
} catch (Exception e) {
|
||||
call.reject("Wake lock failed: " + e.getMessage());
|
||||
@@ -50,12 +61,17 @@ public class WakePlugin extends Plugin {
|
||||
getActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
});
|
||||
|
||||
if (wakeLock != null && wakeLock.isHeld()) {
|
||||
wakeLock.release();
|
||||
if (screenWakeLock != null && screenWakeLock.isHeld()) {
|
||||
screenWakeLock.release();
|
||||
}
|
||||
wakeLock = null;
|
||||
isHeld = false;
|
||||
screenWakeLock = null;
|
||||
|
||||
if (cpuWakeLock != null && cpuWakeLock.isHeld()) {
|
||||
cpuWakeLock.release();
|
||||
}
|
||||
cpuWakeLock = null;
|
||||
|
||||
isHeld = false;
|
||||
call.resolve(new JSObject().put("held", false));
|
||||
} catch (Exception e) {
|
||||
call.reject("Wake release failed: " + e.getMessage());
|
||||
|
||||
Reference in New Issue
Block a user