mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
Acquire wakeLock to receive notifications if 'keep-alive' is on.
This commit is contained in:
@@ -1,12 +1,15 @@
|
||||
package com.b44t.messenger;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.SharedPreferences;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.os.PowerManager;
|
||||
import android.util.Log;
|
||||
|
||||
public class ConnectionsManager {
|
||||
|
||||
@@ -17,8 +20,6 @@ public class ConnectionsManager {
|
||||
public final static int ConnectionStateConnected = 3;
|
||||
public final static int ConnectionStateUpdating = 4;
|
||||
|
||||
private long lastPauseTime = System.currentTimeMillis();
|
||||
private boolean appPaused = true;
|
||||
private int lastClassGuid = 1;
|
||||
private PowerManager.WakeLock wakeLock = null;
|
||||
|
||||
@@ -42,6 +43,13 @@ public class ConnectionsManager {
|
||||
PowerManager pm = (PowerManager) ApplicationLoader.applicationContext.getSystemService(Context.POWER_SERVICE);
|
||||
wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "lock");
|
||||
wakeLock.setReferenceCounted(false);
|
||||
|
||||
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
|
||||
if (preferences.getBoolean("pushService", true)) {
|
||||
Log.i("DeltaChat", "*** Acquire wakeLock");
|
||||
wakeLock.acquire();
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
FileLog.e("messenger", e);
|
||||
}
|
||||
@@ -51,14 +59,6 @@ public class ConnectionsManager {
|
||||
return MrMailbox.getCurrentTime();
|
||||
}
|
||||
|
||||
public void cancelRequest(int token, boolean notifyServer) {
|
||||
//native_cancelRequest(token, notifyServer);
|
||||
}
|
||||
|
||||
public void cleanup() {
|
||||
//native_cleanUp();
|
||||
}
|
||||
|
||||
public int getConnectionState() {
|
||||
return ConnectionStateWaitingForNetwork; // EDIT BY MR - we're always disconnected from the view of the caller
|
||||
/* EDIT BY MR
|
||||
@@ -86,29 +86,6 @@ public class ConnectionsManager {
|
||||
//native_resumeNetwork(true);
|
||||
}
|
||||
|
||||
public void setAppPaused(final boolean value, final boolean byScreenState) {
|
||||
if (!byScreenState) {
|
||||
appPaused = value;
|
||||
FileLog.d("messenger", "app paused = " + value);
|
||||
}
|
||||
if (value) {
|
||||
if (lastPauseTime == 0) {
|
||||
lastPauseTime = System.currentTimeMillis();
|
||||
}
|
||||
//native_pauseNetwork();
|
||||
} else {
|
||||
if (appPaused) {
|
||||
return;
|
||||
}
|
||||
FileLog.e("messenger", "reset app pause time");
|
||||
/*if (lastPauseTime != 0 && System.currentTimeMillis() - lastPauseTime > 5000) {
|
||||
ContactsController.getInstance().checkContacts();
|
||||
}*/
|
||||
lastPauseTime = 0;
|
||||
//native_resumeNetwork(false);
|
||||
}
|
||||
}
|
||||
|
||||
public int generateClassGuid() {
|
||||
return lastClassGuid++;
|
||||
}
|
||||
|
||||
@@ -313,14 +313,14 @@ public class FileLoadOperation {
|
||||
}
|
||||
state = stateFailed;
|
||||
cleanup();
|
||||
if (requestInfos != null) {
|
||||
/*if (requestInfos != null) {
|
||||
for (int a = 0; a < requestInfos.size(); a++) {
|
||||
RequestInfo requestInfo = requestInfos.get(a);
|
||||
if (requestInfo.requestToken != 0) {
|
||||
ConnectionsManager.getInstance().cancelRequest(requestInfo.requestToken, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
delegate.didFailedLoadingFile(FileLoadOperation.this, 1);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -26,18 +26,17 @@ package com.b44t.messenger;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.util.Log;
|
||||
|
||||
public class ScreenReceiver extends BroadcastReceiver {
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
|
||||
FileLog.e("messenger", "screen off");
|
||||
ConnectionsManager.getInstance().setAppPaused(true, true);
|
||||
Log.i("DeltaChat", "*** Screen off");
|
||||
ApplicationLoader.isScreenOn = false;
|
||||
} else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
|
||||
FileLog.e("messenger", "screen on");
|
||||
ConnectionsManager.getInstance().setAppPaused(false, true);
|
||||
Log.i("DeltaChat", "*** Screen on");
|
||||
ApplicationLoader.isScreenOn = true;
|
||||
}
|
||||
//NotificationCenter.getInstance().postNotificationName(NotificationCenter.screenStateChanged);
|
||||
|
||||
@@ -523,7 +523,7 @@ public class StickersAlert extends BottomSheet implements NotificationCenter.Not
|
||||
public void dismiss() {
|
||||
super.dismiss();
|
||||
if (reqId != 0) {
|
||||
ConnectionsManager.getInstance().cancelRequest(reqId, true);
|
||||
//ConnectionsManager.getInstance().cancelRequest(reqId, true);
|
||||
reqId = 0;
|
||||
}
|
||||
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.emojiDidLoaded);
|
||||
|
||||
@@ -27,7 +27,6 @@ import android.Manifest;
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Application;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
@@ -409,26 +408,6 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "channel":
|
||||
/* EDIT BY MR
|
||||
if (args != null) {
|
||||
ChannelCreateActivity channel = new ChannelCreateActivity(args);
|
||||
if (actionBarLayout.addFragmentToStack(channel)) {
|
||||
channel.restoreSelfArgs(savedInstanceState);
|
||||
}
|
||||
}
|
||||
*/
|
||||
break;
|
||||
case "edit":
|
||||
/* EDIT BY MR
|
||||
if (args != null) {
|
||||
ChannelEditActivity channel = new ChannelEditActivity(args);
|
||||
if (actionBarLayout.addFragmentToStack(channel)) {
|
||||
channel.restoreSelfArgs(savedInstanceState);
|
||||
}
|
||||
}
|
||||
*/
|
||||
break;
|
||||
case "chat_profile":
|
||||
if (args != null) {
|
||||
ProfileActivity profile = new ProfileActivity(args);
|
||||
@@ -1329,6 +1308,7 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
Log.i("DeltaChat", "*** LaunchActivity.onPause()");
|
||||
super.onPause();
|
||||
ApplicationLoader.mainInterfacePaused = true;
|
||||
onPasscodePause();
|
||||
@@ -1340,7 +1320,6 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
|
||||
if (passcodeView != null) {
|
||||
passcodeView.onPause();
|
||||
}
|
||||
ConnectionsManager.getInstance().setAppPaused(true, false);
|
||||
if (PhotoViewer.getInstance().isVisible()) {
|
||||
PhotoViewer.getInstance().onPause();
|
||||
}
|
||||
@@ -1348,20 +1327,20 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
Log.i("DeltaChat", "*** LaunchActivity.onStart()");
|
||||
super.onStart();
|
||||
//Browser.bindCustomTabsService(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
Log.i("DeltaChat", "*** LaunchActivity.onStop()");
|
||||
super.onStop();
|
||||
//Browser.unbindCustomTabsService(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
Log.i("DeltaChat", "*** LaunchActivity.onDestroy()");
|
||||
PhotoViewer.getInstance().destroyPhotoViewer();
|
||||
//SecretPhotoViewer.getInstance().destroyPhotoViewer();
|
||||
StickerPreviewViewer.getInstance().destroy();
|
||||
try {
|
||||
if (visibleDialog != null) {
|
||||
@@ -1389,6 +1368,7 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
Log.i("DeltaChat", "*** LaunchActivity.onResume()");
|
||||
super.onResume();
|
||||
ApplicationLoader.mainInterfacePaused = false;
|
||||
onPasscodeResume();
|
||||
@@ -1401,7 +1381,6 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
|
||||
} else {
|
||||
passcodeView.onResume();
|
||||
}
|
||||
ConnectionsManager.getInstance().setAppPaused(false, false);
|
||||
ContactsController.cleanupAvatarCache();
|
||||
updateCurrentConnectionState();
|
||||
if (PhotoViewer.getInstance().isVisible()) {
|
||||
@@ -1521,14 +1500,6 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
|
||||
} else if (lastFragment instanceof ProfileActivity && ((ProfileActivity) lastFragment).isChat() && args != null) {
|
||||
outState.putBundle("args", args);
|
||||
outState.putString("fragment", "chat_profile");
|
||||
/* EDIT BY MR
|
||||
} else if (lastFragment instanceof ChannelCreateActivity && args != null && args.getInt("step") == 0) {
|
||||
outState.putBundle("args", args);
|
||||
outState.putString("fragment", "channel");
|
||||
} else if (lastFragment instanceof ChannelEditActivity && args != null) {
|
||||
outState.putBundle("args", args);
|
||||
outState.putString("fragment", "edit");
|
||||
*/
|
||||
}
|
||||
lastFragment.saveSelfArgs(outState);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user