Skip to content

Commit 8424c1b

Browse files
committed
Revert "Avoid wakecounter."
This reverts commit 74109ad.
1 parent 74109ad commit 8424c1b

File tree

1 file changed

+28
-19
lines changed

1 file changed

+28
-19
lines changed

src/android/BackgroundModeExt.java

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,15 @@ public class BackgroundModeExt extends CordovaPlugin {
8989
private PendingIntent alarmIntent;
9090
final String RECEIVER = ".AlarmReceiver";
9191
final int TIMEOUT = 240 * 1000; // 4 mins
92+
final int WAKELIMIT = 2;
9293
private boolean isOnBg = false;
9394

9495
private class AlarmReceiver extends BroadcastReceiver {
9596
private PowerManager.WakeLock wakeLock = null;
9697
private AlarmManager alarmMgr;
9798
private PendingIntent alarmIntent;
9899
private WifiLock wfl = null;
100+
private int wakeCounter = 0;
99101

100102

101103
@Override
@@ -104,34 +106,41 @@ public void onReceive(Context context, Intent intent) {
104106
PowerManager pm = (PowerManager)context.getSystemService(POWER_SERVICE);
105107
WifiManager wm = (WifiManager)context.getSystemService(Context.WIFI_SERVICE);
106108

107-
getApp().runOnUiThread(() -> {
109+
if(++wakeCounter == WAKELIMIT) {
110+
getApp().runOnUiThread(() -> {
108111
View view = webView.getEngine().getView();
109112
Log.d("MlesAlarm", "Updating visibility " + View.VISIBLE);
110113
view.dispatchWindowVisibilityChanged(View.VISIBLE);
111114
});
112115

113-
if(null == wakeLock) {
114-
wakeLock = pm.newWakeLock(
115-
PARTIAL_WAKE_LOCK, "backgroundmode:wakelock");
116-
wakeLock.acquire();
117-
}
118-
if(null == wfl) {
119-
wfl = wm.createWifiLock(WIFI_MODE_FULL_HIGH_PERF, "backgroundmode:sync_all_wifi");
120-
wfl.acquire();
121-
}
122-
123-
webView.loadUrl("javascript:syncReconnect()");
124-
125-
wfl.release();
126-
wfl = null;
127-
wakeLock.release();
128-
wakeLock = null;
129-
130-
getApp().runOnUiThread(() -> {
116+
Log.d("MlesAlarm", "Acquiring locks");
117+
if(null == wakeLock) {
118+
wakeLock = pm.newWakeLock(
119+
PARTIAL_WAKE_LOCK, "backgroundmode:wakelock");
120+
wakeLock.acquire();
121+
}
122+
if(null == wfl) {
123+
wfl = wm.createWifiLock(WIFI_MODE_FULL_HIGH_PERF, "backgroundmode:sync_all_wifi");
124+
wfl.acquire();
125+
}
126+
127+
Log.d("MlesAlarm", "Calling resync");
128+
webView.loadUrl("javascript:syncReconnect()");
129+
130+
Log.d("MlesAlarm", "Releasing acquired locks");
131+
wfl.release();
132+
wfl = null;
133+
wakeLock.release();
134+
wakeLock = null;
135+
136+
getApp().runOnUiThread(() -> {
131137
View view = webView.getEngine().getView();
132138
Log.d("MlesAlarm", "Updating visibility " + View.GONE);
133139
view.dispatchWindowVisibilityChanged(View.GONE);
134140
});
141+
142+
wakeCounter = 0;
143+
}
135144
}
136145

137146
alarmMgr = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);

0 commit comments

Comments
 (0)