diff options
Diffstat (limited to 'src/main/java/de/pixart/messenger/services/XmppConnectionService.java')
-rw-r--r-- | src/main/java/de/pixart/messenger/services/XmppConnectionService.java | 40 |
1 files changed, 21 insertions, 19 deletions
diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java index 896061457..af94d017b 100644 --- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java +++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java @@ -1,5 +1,6 @@ package de.pixart.messenger.services; +import android.Manifest; import android.annotation.SuppressLint; import android.annotation.TargetApi; import android.app.AlarmManager; @@ -114,6 +115,7 @@ import de.pixart.messenger.ui.SettingsActivity; import de.pixart.messenger.ui.UiCallback; import de.pixart.messenger.ui.interfaces.OnAvatarPublication; import de.pixart.messenger.ui.interfaces.OnSearchResultsAvailable; +import de.pixart.messenger.utils.Compatibility; import de.pixart.messenger.utils.ConversationsFileObserver; import de.pixart.messenger.utils.CryptoHelper; import de.pixart.messenger.utils.ExceptionHelper; @@ -170,8 +172,6 @@ public class XmppConnectionService extends Service { public static final String ACTION_FCM_MESSAGE_RECEIVED = "fcm_message_received"; public static final String FDroid = "org.fdroid.fdroid"; public static final String PlayStore = "com.android.vending"; - public static final String Yalp = "com.github.yeriomin.yalpstore"; - private static final String ACTION_MERGE_PHONE_CONTACTS = "merge_phone_contacts"; private static final String SETTING_LAST_ACTIVITY_TS = "last_activity_timestamp"; static { @@ -234,6 +234,7 @@ public class XmppConnectionService extends Service { ) { @Override public void onEvent(int event, String path) { + Log.d(Config.LOGTAG, "event " + event + " path=" + path); markFileDeleted(path); } }; @@ -244,17 +245,16 @@ public class XmppConnectionService extends Service { @Override public void onChange(boolean selfChange) { super.onChange(selfChange); - Intent intent = new Intent(getApplicationContext(), - XmppConnectionService.class); - intent.setAction(ACTION_MERGE_PHONE_CONTACTS); - startService(intent); + if (restoredFromDatabaseLatch.getCount() == 0) { + loadPhoneContacts(); + } } }; private MemorizingTrustManager mMemorizingTrustManager; private NotificationService mNotificationService = new NotificationService(this); private ShortcutService mShortcutService = new ShortcutService(this); private AtomicBoolean mInitialAddressbookSyncCompleted = new AtomicBoolean(false); - private AtomicBoolean mForceForegroundService = new AtomicBoolean(false); + protected AtomicBoolean mForceForegroundService = new AtomicBoolean(false); private OnMessagePacketReceived mMessageParser = new MessageParser(this); private OnPresencePacketReceived mPresenceParser = new PresenceParser(this); private IqParser mIqParser = new IqParser(this); @@ -590,11 +590,6 @@ public class XmppConnectionService extends Service { resetAllAttemptCounts(true, false); } break; - case ACTION_MERGE_PHONE_CONTACTS: - if (restoredFromDatabaseLatch.getCount() == 0) { - loadPhoneContacts(); - } - return START_STICKY; case Intent.ACTION_SHUTDOWN: logoutAndSave(true); return START_NOT_STICKY; @@ -1094,6 +1089,9 @@ public class XmppConnectionService extends Service { Resolver.init(this); this.mRandom = new SecureRandom(); updateMemorizingTrustmanager(); + if (Compatibility.twentySix()) { + mNotificationService.initializeChannels(); + } final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024); final int cacheSize = maxMemory / 8; this.mBitmapCache = new LruCache<String, Bitmap>(cacheSize) { @@ -1120,7 +1118,10 @@ public class XmppConnectionService extends Service { editor.apply(); restoreFromDatabase(); - getContentResolver().registerContentObserver(ContactsContract.Contacts.CONTENT_URI, true, contactObserver); + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || ContextCompat.checkSelfPermission(this, Manifest.permission.READ_CONTACTS) == PackageManager.PERMISSION_GRANTED) { + //TODO get this restarted if users gives permission + getContentResolver().registerContentObserver(ContactsContract.Contacts.CONTENT_URI, true, contactObserver); + } if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || ContextCompat.checkSelfPermission(this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { Log.d(Config.LOGTAG, "starting file observer"); new Thread(fileObserver::startWatching).start(); @@ -1203,7 +1204,7 @@ public class XmppConnectionService extends Service { } public void toggleForegroundService() { - if (mForceForegroundService.get() || (showForegroundService())) { + if (mForceForegroundService.get() || (Compatibility.keepForegroundService(this) && hasEnabledAccounts())) { startForeground(NotificationService.FOREGROUND_NOTIFICATION_ID, this.mNotificationService.createForegroundNotification()); Log.d(Config.LOGTAG, "started foreground service"); } else { @@ -1215,7 +1216,8 @@ public class XmppConnectionService extends Service { @Override public void onTaskRemoved(final Intent rootIntent) { super.onTaskRemoved(rootIntent); - if (showForegroundService() || mForceForegroundService.get()) { + //TODO check for accounts enabled + if ((Compatibility.keepForegroundService(this) && hasEnabledAccounts()) || mForceForegroundService.get()) { Log.d(Config.LOGTAG, "ignoring onTaskRemoved because foreground service is activated"); } else { this.logoutAndSave(false); @@ -2195,6 +2197,7 @@ public class XmppConnectionService extends Service { updateAccountUi(); getNotificationService().updateErrorNotification(); syncEnabledAccountSetting(); + toggleForegroundService(); } } @@ -2637,6 +2640,9 @@ public class XmppConnectionService extends Service { } private boolean hasEnabledAccounts() { + if (this.accounts == null) { + return true; // set to true if accounts could not be fetched - used for notifications + } for (Account account : this.accounts) { if (account.isEnabled()) { return true; @@ -4330,10 +4336,6 @@ public class XmppConnectionService extends Service { return getBooleanPreference(SettingsActivity.BLIND_TRUST_BEFORE_VERIFICATION, R.bool.btbv); } - public boolean showForegroundService() { - return getBooleanPreference(SettingsActivity.SHOW_FOREGROUND_SERVICE, R.bool.show_foreground_service); - } - public void ScheduleAutomaticExport() { //start export log service every day at given time if (Config.ExportLogs) { |