force foreground service during onCreate()
creating / upgrading the database and reading accounts can be expensive and will otherwise trigger an AN
This commit is contained in:
parent
d02fd73af8
commit
004411cf51
|
@ -900,9 +900,10 @@ public class NotificationService {
|
||||||
final Notification.Builder mBuilder = new Notification.Builder(mXmppConnectionService);
|
final Notification.Builder mBuilder = new Notification.Builder(mXmppConnectionService);
|
||||||
mBuilder.setContentTitle(mXmppConnectionService.getString(R.string.app_name));
|
mBuilder.setContentTitle(mXmppConnectionService.getString(R.string.app_name));
|
||||||
if (Compatibility.runsAndTargetsTwentySix(mXmppConnectionService) || Config.SHOW_CONNECTED_ACCOUNTS) {
|
if (Compatibility.runsAndTargetsTwentySix(mXmppConnectionService) || Config.SHOW_CONNECTED_ACCOUNTS) {
|
||||||
List<Account> accounts = mXmppConnectionService.getAccounts();
|
final List<Account> accounts = mXmppConnectionService.getAccounts();
|
||||||
int enabled = 0;
|
int enabled = 0;
|
||||||
int connected = 0;
|
int connected = 0;
|
||||||
|
if (accounts != null) {
|
||||||
for (Account account : accounts) {
|
for (Account account : accounts) {
|
||||||
if (account.isOnlineAndConnected()) {
|
if (account.isOnlineAndConnected()) {
|
||||||
connected++;
|
connected++;
|
||||||
|
@ -911,6 +912,7 @@ public class NotificationService {
|
||||||
enabled++;
|
enabled++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
mBuilder.setContentText(mXmppConnectionService.getString(R.string.connected_accounts, connected, enabled));
|
mBuilder.setContentText(mXmppConnectionService.getString(R.string.connected_accounts, connected, enabled));
|
||||||
} else {
|
} else {
|
||||||
mBuilder.setContentText(mXmppConnectionService.getString(R.string.touch_to_open_conversations));
|
mBuilder.setContentText(mXmppConnectionService.getString(R.string.touch_to_open_conversations));
|
||||||
|
|
|
@ -198,6 +198,7 @@ public class XmppConnectionService extends Service {
|
||||||
private ShortcutService mShortcutService = new ShortcutService(this);
|
private ShortcutService mShortcutService = new ShortcutService(this);
|
||||||
private AtomicBoolean mInitialAddressbookSyncCompleted = new AtomicBoolean(false);
|
private AtomicBoolean mInitialAddressbookSyncCompleted = new AtomicBoolean(false);
|
||||||
private AtomicBoolean mForceForegroundService = new AtomicBoolean(false);
|
private AtomicBoolean mForceForegroundService = new AtomicBoolean(false);
|
||||||
|
private AtomicBoolean mForceDuringOnCreate = new AtomicBoolean(false);
|
||||||
private OnMessagePacketReceived mMessageParser = new MessageParser(this);
|
private OnMessagePacketReceived mMessageParser = new MessageParser(this);
|
||||||
private OnPresencePacketReceived mPresenceParser = new PresenceParser(this);
|
private OnPresencePacketReceived mPresenceParser = new PresenceParser(this);
|
||||||
private IqParser mIqParser = new IqParser(this);
|
private IqParser mIqParser = new IqParser(this);
|
||||||
|
@ -964,6 +965,11 @@ public class XmppConnectionService extends Service {
|
||||||
@SuppressLint("TrulyRandom")
|
@SuppressLint("TrulyRandom")
|
||||||
@Override
|
@Override
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
|
if (Compatibility.runsTwentySix()) {
|
||||||
|
mNotificationService.initializeChannels();
|
||||||
|
}
|
||||||
|
mForceDuringOnCreate.set(Compatibility.runsAndTargetsTwentySix(this));
|
||||||
|
toggleForegroundService();
|
||||||
this.destroyed = false;
|
this.destroyed = false;
|
||||||
OmemoSetting.load(this);
|
OmemoSetting.load(this);
|
||||||
ExceptionHelper.init(getApplicationContext());
|
ExceptionHelper.init(getApplicationContext());
|
||||||
|
@ -975,9 +981,6 @@ public class XmppConnectionService extends Service {
|
||||||
Resolver.init(this);
|
Resolver.init(this);
|
||||||
this.mRandom = new SecureRandom();
|
this.mRandom = new SecureRandom();
|
||||||
updateMemorizingTrustmanager();
|
updateMemorizingTrustmanager();
|
||||||
if (Compatibility.runsTwentySix()) {
|
|
||||||
mNotificationService.initializeChannels();
|
|
||||||
}
|
|
||||||
final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
|
final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
|
||||||
final int cacheSize = maxMemory / 8;
|
final int cacheSize = maxMemory / 8;
|
||||||
this.mBitmapCache = new LruCache<String, Bitmap>(cacheSize) {
|
this.mBitmapCache = new LruCache<String, Bitmap>(cacheSize) {
|
||||||
|
@ -1046,6 +1049,8 @@ public class XmppConnectionService extends Service {
|
||||||
intentFilter.addAction(NotificationManager.ACTION_INTERRUPTION_FILTER_CHANGED);
|
intentFilter.addAction(NotificationManager.ACTION_INTERRUPTION_FILTER_CHANGED);
|
||||||
registerReceiver(this.mInternalEventReceiver, intentFilter);
|
registerReceiver(this.mInternalEventReceiver, intentFilter);
|
||||||
}
|
}
|
||||||
|
mForceDuringOnCreate.set(false);
|
||||||
|
toggleForegroundService();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkForDeletedFiles() {
|
private void checkForDeletedFiles() {
|
||||||
|
@ -1132,7 +1137,7 @@ public class XmppConnectionService extends Service {
|
||||||
|
|
||||||
private void toggleForegroundService(boolean force) {
|
private void toggleForegroundService(boolean force) {
|
||||||
final boolean status;
|
final boolean status;
|
||||||
if (force || mForceForegroundService.get() || (Compatibility.keepForegroundService(this) && hasEnabledAccounts())) {
|
if (force || mForceDuringOnCreate.get() || mForceForegroundService.get() || (Compatibility.keepForegroundService(this) && hasEnabledAccounts())) {
|
||||||
startForeground(NotificationService.FOREGROUND_NOTIFICATION_ID, this.mNotificationService.createForegroundNotification());
|
startForeground(NotificationService.FOREGROUND_NOTIFICATION_ID, this.mNotificationService.createForegroundNotification());
|
||||||
status = true;
|
status = true;
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue