aboutsummaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2018-11-23 08:30:12 +0100
committerChristian Schneppe <christian@pix-art.de>2018-11-23 08:51:39 +0100
commit35d5d97544cd6abc45809a19324898dfbf457467 (patch)
tree0d358bcb048a3de2aa99f18d1baa71d71b0c29de /src/main
parent9ec0a87cc28d134c974e8ca0e0b3fda3d89bca7a (diff)
refactored phone contact loading in preperation for sync
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/de/pixart/messenger/android/AbstractPhoneContact.java39
-rw-r--r--src/main/java/de/pixart/messenger/android/JabberIdContact.java73
-rw-r--r--src/main/java/de/pixart/messenger/entities/Contact.java32
-rw-r--r--src/main/java/de/pixart/messenger/services/AbstractQuickConversationsService.java26
-rw-r--r--src/main/java/de/pixart/messenger/services/QuickConversationsService.java28
-rw-r--r--src/main/java/de/pixart/messenger/services/ShortcutService.java2
-rw-r--r--src/main/java/de/pixart/messenger/services/XmppConnectionService.java68
-rw-r--r--src/main/java/de/pixart/messenger/ui/EditAccountActivity.java7
-rw-r--r--src/main/java/de/pixart/messenger/utils/Namespace.java1
-rw-r--r--src/main/java/de/pixart/messenger/utils/PhoneHelper.java67
-rw-r--r--src/main/java/de/pixart/messenger/utils/ReplacingSerialSingleThreadExecutor.java12
-rw-r--r--src/main/java/de/pixart/messenger/utils/ReplacingTaskManager.java2
-rw-r--r--src/main/java/de/pixart/messenger/utils/SerialSingleThreadExecutor.java8
13 files changed, 222 insertions, 143 deletions
diff --git a/src/main/java/de/pixart/messenger/android/AbstractPhoneContact.java b/src/main/java/de/pixart/messenger/android/AbstractPhoneContact.java
new file mode 100644
index 000000000..abab89aee
--- /dev/null
+++ b/src/main/java/de/pixart/messenger/android/AbstractPhoneContact.java
@@ -0,0 +1,39 @@
+package de.pixart.messenger.android;
+
+import android.database.Cursor;
+import android.net.Uri;
+import android.provider.ContactsContract;
+import android.text.TextUtils;
+
+abstract class AbstractPhoneContact {
+
+ private final Uri lookupUri;
+ private final String displayName;
+ private final String photoUri;
+
+
+ AbstractPhoneContact(Cursor cursor) {
+ int phoneId = cursor.getInt(cursor.getColumnIndex(ContactsContract.Data._ID));
+ String lookupKey = cursor.getString(cursor.getColumnIndex(ContactsContract.Data.LOOKUP_KEY));
+ this.lookupUri = ContactsContract.Contacts.getLookupUri(phoneId, lookupKey);
+ this.displayName = cursor.getString(cursor.getColumnIndex(ContactsContract.Data.DISPLAY_NAME));
+ this.photoUri = cursor.getString(cursor.getColumnIndex(ContactsContract.Data.PHOTO_URI));
+ }
+
+ public Uri getLookupUri() {
+ return lookupUri;
+ }
+
+ public String getDisplayName() {
+ return displayName;
+ }
+
+ public String getPhotoUri() {
+ return photoUri;
+ }
+
+
+ public int rating() {
+ return (TextUtils.isEmpty(displayName) ? 0 : 2) + (TextUtils.isEmpty(photoUri) ? 0 : 1);
+ }
+} \ No newline at end of file
diff --git a/src/main/java/de/pixart/messenger/android/JabberIdContact.java b/src/main/java/de/pixart/messenger/android/JabberIdContact.java
new file mode 100644
index 000000000..bfafb54c9
--- /dev/null
+++ b/src/main/java/de/pixart/messenger/android/JabberIdContact.java
@@ -0,0 +1,73 @@
+package de.pixart.messenger.android;
+
+import android.Manifest;
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.database.Cursor;
+import android.os.Build;
+import android.provider.ContactsContract;
+import android.util.Log;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import de.pixart.messenger.Config;
+import rocks.xmpp.addr.Jid;
+
+public class JabberIdContact extends AbstractPhoneContact {
+
+ private final Jid jid;
+
+ private JabberIdContact(Cursor cursor) throws IllegalArgumentException {
+ super(cursor);
+ try {
+ this.jid = Jid.of(cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Im.DATA)));
+ } catch (IllegalArgumentException | NullPointerException e) {
+ throw new IllegalArgumentException(e);
+ }
+ }
+
+ public Jid getJid() {
+ return jid;
+ }
+
+ public static Map<Jid, JabberIdContact> load(Context context) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && context.checkSelfPermission(Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) {
+ return Collections.emptyMap();
+ }
+ final String[] PROJECTION = new String[]{ContactsContract.Data._ID,
+ ContactsContract.Data.DISPLAY_NAME,
+ ContactsContract.Data.PHOTO_URI,
+ ContactsContract.Data.LOOKUP_KEY,
+ ContactsContract.CommonDataKinds.Im.DATA};
+
+ final String SELECTION = "(" + ContactsContract.Data.MIMETYPE + "=\""
+ + ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE
+ + "\") AND (" + ContactsContract.CommonDataKinds.Im.PROTOCOL
+ + "=\"" + ContactsContract.CommonDataKinds.Im.PROTOCOL_JABBER
+ + "\")";
+ final Cursor cursor;
+ try {
+ cursor = context.getContentResolver().query(ContactsContract.Data.CONTENT_URI, PROJECTION, SELECTION, null, null);
+ } catch (Exception e) {
+ return Collections.emptyMap();
+ }
+ final HashMap<Jid, JabberIdContact> contacts = new HashMap<>();
+ while (cursor != null && cursor.moveToNext()) {
+ try {
+ final JabberIdContact contact = new JabberIdContact(cursor);
+ final JabberIdContact preexisting = contacts.put(contact.getJid(), contact);
+ if (preexisting == null || preexisting.rating() < contact.rating()) {
+ contacts.put(contact.getJid(), contact);
+ }
+ } catch (IllegalArgumentException e) {
+ Log.d(Config.LOGTAG,"unable to create jabber id contact");
+ }
+ }
+ if (cursor != null) {
+ cursor.close();
+ }
+ return contacts;
+ }
+} \ No newline at end of file
diff --git a/src/main/java/de/pixart/messenger/entities/Contact.java b/src/main/java/de/pixart/messenger/entities/Contact.java
index a74b09dff..fad4806de 100644
--- a/src/main/java/de/pixart/messenger/entities/Contact.java
+++ b/src/main/java/de/pixart/messenger/entities/Contact.java
@@ -48,7 +48,7 @@ public class Contact implements ListItem, Blockable {
private String commonName;
protected Jid jid;
private int subscription = 0;
- private String systemAccount;
+ private Uri systemAccount;
private String photoUri;
private final JSONObject keys;
private JSONArray groups = new JSONArray();
@@ -62,7 +62,7 @@ public class Contact implements ListItem, Blockable {
public Contact(final String account, final String systemName, final String serverName,
final Jid jid, final int subscription, final String photoUri,
- final String systemAccount, final String keys, final String avatar, final long lastseen,
+ final Uri systemAccount, final String keys, final String avatar, final long lastseen,
final String presence, final String groups) {
this.accountUuid = account;
this.systemName = systemName;
@@ -105,13 +105,19 @@ public class Contact implements ListItem, Blockable {
// TODO: Borked DB... handle this somehow?
return null;
}
+ Uri systemAccount;
+ try {
+ systemAccount = Uri.parse(cursor.getString(cursor.getColumnIndex(SYSTEMACCOUNT)));
+ } catch (Exception e) {
+ systemAccount = null;
+ }
return new Contact(cursor.getString(cursor.getColumnIndex(ACCOUNT)),
cursor.getString(cursor.getColumnIndex(SYSTEMNAME)),
cursor.getString(cursor.getColumnIndex(SERVERNAME)),
jid,
cursor.getInt(cursor.getColumnIndex(OPTIONS)),
cursor.getString(cursor.getColumnIndex(PHOTOURI)),
- cursor.getString(cursor.getColumnIndex(SYSTEMACCOUNT)),
+ systemAccount,
cursor.getString(cursor.getColumnIndex(KEYS)),
cursor.getString(cursor.getColumnIndex(AVATAR)),
cursor.getLong(cursor.getColumnIndex(LAST_TIME)),
@@ -203,7 +209,7 @@ public class Contact implements ListItem, Blockable {
values.put(SERVERNAME, serverName);
values.put(JID, jid.toString());
values.put(OPTIONS, subscription);
- values.put(SYSTEMACCOUNT, systemAccount);
+ values.put(SYSTEMACCOUNT, systemAccount != null ? systemAccount.toString() : null);
values.put(PHOTOURI, photoUri);
values.put(KEYS, keys.toString());
values.put(AVATAR, avatar == null ? null : avatar.getFilename());
@@ -277,21 +283,11 @@ public class Contact implements ListItem, Blockable {
}
public Uri getSystemAccount() {
- if (systemAccount == null) {
- return null;
- } else {
- String[] parts = systemAccount.split("#");
- if (parts.length != 2) {
- return null;
- } else {
- long id = Long.parseLong(parts[0]);
- return ContactsContract.Contacts.getLookupUri(id, parts[1]);
- }
- }
+ return systemAccount;
}
- public void setSystemAccount(String account) {
- this.systemAccount = account;
+ public void setSystemAccount(Uri lookupUri) {
+ this.systemAccount = lookupUri;
}
private Collection<String> getGroups(final boolean unique) {
@@ -391,7 +387,7 @@ public class Contact implements ListItem, Blockable {
}
public boolean showInPhoneBook() {
- return systemAccount != null && !systemAccount.trim().isEmpty();
+ return systemAccount != null;
}
public void parseSubscriptionFromElement(Element item) {
diff --git a/src/main/java/de/pixart/messenger/services/AbstractQuickConversationsService.java b/src/main/java/de/pixart/messenger/services/AbstractQuickConversationsService.java
new file mode 100644
index 000000000..f5647bd60
--- /dev/null
+++ b/src/main/java/de/pixart/messenger/services/AbstractQuickConversationsService.java
@@ -0,0 +1,26 @@
+package de.pixart.messenger.services;
+
+public abstract class AbstractQuickConversationsService {
+
+ protected final XmppConnectionService service;
+
+ public AbstractQuickConversationsService(XmppConnectionService service) {
+ this.service = service;
+ }
+
+ public abstract void considerSync();
+
+ public static boolean isQuicksy() {
+ return false;
+ }
+
+ public static boolean isConversations() {
+ return true;
+ }
+
+ public abstract void signalAccountStateChange();
+
+ public abstract boolean isSynchronizing();
+
+ public abstract void considerSyncBackground(boolean force);
+} \ No newline at end of file
diff --git a/src/main/java/de/pixart/messenger/services/QuickConversationsService.java b/src/main/java/de/pixart/messenger/services/QuickConversationsService.java
new file mode 100644
index 000000000..e268ac856
--- /dev/null
+++ b/src/main/java/de/pixart/messenger/services/QuickConversationsService.java
@@ -0,0 +1,28 @@
+package de.pixart.messenger.services;
+
+public class QuickConversationsService extends AbstractQuickConversationsService {
+
+ QuickConversationsService(XmppConnectionService xmppConnectionService) {
+ super(xmppConnectionService);
+ }
+
+ @Override
+ public void considerSync() {
+
+ }
+
+ @Override
+ public void signalAccountStateChange() {
+
+ }
+
+ @Override
+ public boolean isSynchronizing() {
+ return false;
+ }
+
+ @Override
+ public void considerSyncBackground(boolean force) {
+
+ }
+} \ No newline at end of file
diff --git a/src/main/java/de/pixart/messenger/services/ShortcutService.java b/src/main/java/de/pixart/messenger/services/ShortcutService.java
index 0578a8ce5..8051c8849 100644
--- a/src/main/java/de/pixart/messenger/services/ShortcutService.java
+++ b/src/main/java/de/pixart/messenger/services/ShortcutService.java
@@ -24,7 +24,7 @@ import rocks.xmpp.addr.Jid;
public class ShortcutService {
private final XmppConnectionService xmppConnectionService;
- private final ReplacingSerialSingleThreadExecutor replacingSerialSingleThreadExecutor = new ReplacingSerialSingleThreadExecutor(false);
+ private final ReplacingSerialSingleThreadExecutor replacingSerialSingleThreadExecutor = new ReplacingSerialSingleThreadExecutor(ShortcutService.class.getSimpleName());
public ShortcutService(XmppConnectionService xmppConnectionService) {
this.xmppConnectionService = xmppConnectionService;
diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
index bb704c6b6..7238beec2 100644
--- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
+++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
@@ -81,6 +81,7 @@ import java.util.concurrent.atomic.AtomicLong;
import de.pixart.messenger.BuildConfig;
import de.pixart.messenger.Config;
import de.pixart.messenger.R;
+import de.pixart.messenger.android.JabberIdContact;
import de.pixart.messenger.crypto.OmemoSetting;
import de.pixart.messenger.crypto.PgpDecryptionService;
import de.pixart.messenger.crypto.PgpEngine;
@@ -243,7 +244,7 @@ public class XmppConnectionService extends Service {
}
};
public HttpConnectionManager mHttpConnectionManager = new HttpConnectionManager(this);
- private ReplacingSerialSingleThreadExecutor mContactMergerExecutor = new ReplacingSerialSingleThreadExecutor(true);
+ private ReplacingSerialSingleThreadExecutor mContactMergerExecutor = new ReplacingSerialSingleThreadExecutor("ContactMerger");
private long mLastActivity = 0;
private MemorizingTrustManager mMemorizingTrustManager;
private NotificationService mNotificationService = new NotificationService(this);
@@ -286,6 +287,7 @@ public class XmppConnectionService extends Service {
private AvatarService mAvatarService = new AvatarService(this);
private MessageArchiveService mMessageArchiveService = new MessageArchiveService(this);
private PushManagementService mPushManagementService = new PushManagementService(this);
+ private QuickConversationsService mQuickConversationsService = new QuickConversationsService(this);
private final OnBindListener mOnBindListener = new OnBindListener() {
@Override
@@ -1720,45 +1722,35 @@ public class XmppConnectionService extends Service {
}
public void loadPhoneContacts() {
- mContactMergerExecutor.execute(() -> PhoneHelper.loadPhoneContacts(XmppConnectionService.this, new OnPhoneContactsLoadedListener() {
- @Override
- public void onPhoneContactsLoaded(List<Bundle> phoneContacts) {
- Log.d(Config.LOGTAG, "start merging phone contacts with roster");
- for (Account account : accounts) {
- List<Contact> withSystemAccounts = account.getRoster().getWithSystemAccounts();
- for (Bundle phoneContact : phoneContacts) {
- Jid jid;
- try {
- jid = Jid.of(phoneContact.getString("jid"));
- } catch (final IllegalArgumentException e) {
- continue;
- }
- final Contact contact = account.getRoster().getContact(jid);
- String systemAccount = phoneContact.getInt("phoneid")
- + "#"
- + phoneContact.getString("lookup");
- contact.setSystemAccount(systemAccount);
- boolean needsCacheClean = contact.setPhotoUri(phoneContact.getString("photouri"));
- needsCacheClean |= contact.setSystemName(phoneContact.getString("displayname"));
- if (needsCacheClean) {
- getAvatarService().clear(contact);
- }
- withSystemAccounts.remove(contact);
+ mContactMergerExecutor.execute(() -> {
+ Map<Jid, JabberIdContact> contacts = JabberIdContact.load(this);
+ Log.d(Config.LOGTAG, "start merging phone contacts with roster");
+ for (Account account : accounts) {
+ List<Contact> withSystemAccounts = account.getRoster().getWithSystemAccounts();
+ for (JabberIdContact jidContact : contacts.values()) {
+ final Contact contact = account.getRoster().getContact(jidContact.getJid());
+ contact.setSystemAccount(jidContact.getLookupUri());
+ boolean needsCacheClean = contact.setPhotoUri(jidContact.getPhotoUri());
+ needsCacheClean |= contact.setSystemName(jidContact.getDisplayName());
+ if (needsCacheClean) {
+ getAvatarService().clear(contact);
}
- for (Contact contact : withSystemAccounts) {
- contact.setSystemAccount(null);
- boolean needsCacheClean = contact.setPhotoUri(null);
- needsCacheClean |= contact.setSystemName(null);
- if (needsCacheClean) {
- getAvatarService().clear(contact);
- }
+ withSystemAccounts.remove(contact);
+ }
+ for (Contact contact : withSystemAccounts) {
+ contact.setSystemAccount(null);
+ boolean needsCacheClean = contact.setPhotoUri(null);
+ needsCacheClean |= contact.setSystemName(null);
+ if (needsCacheClean) {
+ getAvatarService().clear(contact);
}
}
- Log.d(Config.LOGTAG, "finished merging phone contacts");
- mShortcutService.refresh(mInitialAddressbookSyncCompleted.compareAndSet(false, true));
- updateRosterUi();
}
- }));
+ Log.d(Config.LOGTAG, "finished merging phone contacts");
+ mShortcutService.refresh(mInitialAddressbookSyncCompleted.compareAndSet(false, true));
+ updateRosterUi();
+ mQuickConversationsService.considerSync();
+ });
}
public void syncRoster(final Account account) {
@@ -3683,11 +3675,11 @@ public class XmppConnectionService extends Service {
}
public boolean useTorToConnect() {
- return Config.FORCE_ORBOT || getBooleanPreference("use_tor", R.bool.use_tor);
+ return QuickConversationsService.isConversations() && getBooleanPreference("use_tor", R.bool.use_tor);
}
public boolean showExtendedConnectionOptions() {
- return getBooleanPreference("show_connection_options", R.bool.show_connection_options);
+ return QuickConversationsService.isConversations() && getBooleanPreference("show_connection_options", R.bool.show_connection_options);
}
public boolean warnUnecryptedChat() {
diff --git a/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java b/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java
index 5daaafacd..2f004a165 100644
--- a/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java
@@ -56,6 +56,7 @@ import de.pixart.messenger.entities.Presence;
import de.pixart.messenger.entities.PresenceTemplate;
import de.pixart.messenger.entities.ServiceDiscoveryResult;
import de.pixart.messenger.services.BarcodeProvider;
+import de.pixart.messenger.services.QuickConversationsService;
import de.pixart.messenger.services.XmppConnectionService;
import de.pixart.messenger.services.XmppConnectionService.OnAccountUpdate;
import de.pixart.messenger.services.XmppConnectionService.OnCaptchaRequested;
@@ -689,8 +690,8 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
}
}
SharedPreferences preferences = getPreferences();
- mUseTor = Config.FORCE_ORBOT || preferences.getBoolean("use_tor", false);
- this.mShowOptions = mUseTor || preferences.getBoolean("show_connection_options", false);
+ mUseTor = QuickConversationsService.isConversations() && preferences.getBoolean("use_tor", getResources().getBoolean(R.bool.use_tor));
+ this.mShowOptions = mUseTor || (QuickConversationsService.isConversations() && preferences.getBoolean("show_connection_options", getResources().getBoolean(R.bool.show_connection_options)));
this.binding.namePort.setVisibility(mShowOptions ? View.VISIBLE : View.GONE);
}
@@ -976,7 +977,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
}
- final boolean editable = !mAccount.isOptionSet(Account.OPTION_LOGGED_IN_SUCCESSFULLY);
+ final boolean editable = !mAccount.isOptionSet(Account.OPTION_LOGGED_IN_SUCCESSFULLY) && QuickConversationsService.isConversations();
this.binding.accountJid.setEnabled(editable);
this.binding.accountJid.setFocusable(editable);
this.binding.accountJid.setFocusableInTouchMode(editable);
diff --git a/src/main/java/de/pixart/messenger/utils/Namespace.java b/src/main/java/de/pixart/messenger/utils/Namespace.java
index 146a9784d..71906cd4a 100644
--- a/src/main/java/de/pixart/messenger/utils/Namespace.java
+++ b/src/main/java/de/pixart/messenger/utils/Namespace.java
@@ -22,4 +22,5 @@ public final class Namespace {
public static final String P1_S3_FILE_TRANSFER = "p1:s3filetransfer";
public static final String BOOKMARKS_CONVERSION = "urn:xmpp:bookmarks-conversion:0";
public static final String BOOKMARKS = "storage:bookmarks";
+ public static final String SYNCHRONIZATION = "im.quicksy.synchronization";
}
diff --git a/src/main/java/de/pixart/messenger/utils/PhoneHelper.java b/src/main/java/de/pixart/messenger/utils/PhoneHelper.java
index f5e2ffde1..327ae1904 100644
--- a/src/main/java/de/pixart/messenger/utils/PhoneHelper.java
+++ b/src/main/java/de/pixart/messenger/utils/PhoneHelper.java
@@ -24,55 +24,6 @@ public class PhoneHelper {
return Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
}
- public static void loadPhoneContacts(Context context, final OnPhoneContactsLoadedListener listener) {
- final List<Bundle> phoneContacts = new ArrayList<>();
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
- && context.checkSelfPermission(Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) {
- listener.onPhoneContactsLoaded(phoneContacts);
- return;
- }
- final String[] PROJECTION = new String[]{ContactsContract.Data._ID,
- ContactsContract.Data.DISPLAY_NAME,
- ContactsContract.Data.PHOTO_URI,
- ContactsContract.Data.LOOKUP_KEY,
- ContactsContract.CommonDataKinds.Im.DATA};
-
- final String SELECTION = "(" + ContactsContract.Data.MIMETYPE + "=\""
- + ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE
- + "\") AND (" + ContactsContract.CommonDataKinds.Im.PROTOCOL
- + "=\"" + ContactsContract.CommonDataKinds.Im.PROTOCOL_JABBER
- + "\")";
-
- CursorLoader mCursorLoader = new NotThrowCursorLoader(context,
- ContactsContract.Data.CONTENT_URI, PROJECTION, SELECTION, null,
- null);
- mCursorLoader.registerListener(0, (arg0, c) -> {
- if (c != null) {
- while (c.moveToNext()) {
- Bundle contact = new Bundle();
- contact.putInt("phoneid", c.getInt(c.getColumnIndex(ContactsContract.Data._ID)));
- contact.putString("displayname", c.getString(c.getColumnIndex(ContactsContract.Data.DISPLAY_NAME)));
- contact.putString("photouri", c.getString(c.getColumnIndex(ContactsContract.Data.PHOTO_URI)));
- contact.putString("lookup", c.getString(c.getColumnIndex(ContactsContract.Data.LOOKUP_KEY)));
- contact.putString("jid", c.getString(c.getColumnIndex(ContactsContract.CommonDataKinds.Im.DATA)));
- phoneContacts.add(contact);
- }
- c.close();
- }
-
- if (listener != null) {
- listener.onPhoneContactsLoaded(phoneContacts);
- }
- });
- try {
- mCursorLoader.startLoading();
- } catch (RejectedExecutionException e) {
- if (listener != null) {
- listener.onPhoneContactsLoaded(phoneContacts);
- }
- }
- }
-
public static Uri getProfilePictureUri(Context context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && context.checkSelfPermission(Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) {
return null;
@@ -106,24 +57,6 @@ public class PhoneHelper {
}
}
- private static class NotThrowCursorLoader extends CursorLoader {
-
- private NotThrowCursorLoader(Context c, Uri u, String[] p, String s, String[] sa, String so) {
- super(c, u, p, s, sa, so);
- }
-
- @Override
- public Cursor loadInBackground() {
-
- try {
- return (super.loadInBackground());
- } catch (Throwable e) {
- return (null);
- }
- }
-
- }
-
public static String getOSVersion(Context context) {
return "Android/" + android.os.Build.MODEL + "/" + android.os.Build.VERSION.RELEASE;
}
diff --git a/src/main/java/de/pixart/messenger/utils/ReplacingSerialSingleThreadExecutor.java b/src/main/java/de/pixart/messenger/utils/ReplacingSerialSingleThreadExecutor.java
index bf4d6e8c2..79e5126b2 100644
--- a/src/main/java/de/pixart/messenger/utils/ReplacingSerialSingleThreadExecutor.java
+++ b/src/main/java/de/pixart/messenger/utils/ReplacingSerialSingleThreadExecutor.java
@@ -3,17 +3,13 @@ package de.pixart.messenger.utils;
public class ReplacingSerialSingleThreadExecutor extends SerialSingleThreadExecutor {
public ReplacingSerialSingleThreadExecutor(String name) {
- super(name, false);
- }
-
- public ReplacingSerialSingleThreadExecutor(boolean prepareLooper) {
- super(ReplacingSerialSingleThreadExecutor.class.getName(), prepareLooper);
+ super(name);
}
@Override
public synchronized void execute(final Runnable r) {
tasks.clear();
- if (active != null && active instanceof Cancellable) {
+ if (active instanceof Cancellable) {
((Cancellable) active).cancel();
}
super.execute(r);
@@ -21,8 +17,8 @@ public class ReplacingSerialSingleThreadExecutor extends SerialSingleThreadExecu
public synchronized void cancelRunningTasks() {
tasks.clear();
- if (active != null && active instanceof Cancellable) {
+ if (active instanceof Cancellable) {
((Cancellable) active).cancel();
}
}
-}
+} \ No newline at end of file
diff --git a/src/main/java/de/pixart/messenger/utils/ReplacingTaskManager.java b/src/main/java/de/pixart/messenger/utils/ReplacingTaskManager.java
index 3c9f386cd..c25c6fce4 100644
--- a/src/main/java/de/pixart/messenger/utils/ReplacingTaskManager.java
+++ b/src/main/java/de/pixart/messenger/utils/ReplacingTaskManager.java
@@ -41,7 +41,7 @@ public class ReplacingTaskManager {
synchronized (this.executors) {
executor = this.executors.get(account);
if (executor == null) {
- executor = new ReplacingSerialSingleThreadExecutor(false);
+ executor = new ReplacingSerialSingleThreadExecutor(ReplacingTaskManager.class.getSimpleName());
this.executors.put(account, executor);
}
executor.execute(runnable);
diff --git a/src/main/java/de/pixart/messenger/utils/SerialSingleThreadExecutor.java b/src/main/java/de/pixart/messenger/utils/SerialSingleThreadExecutor.java
index 500b03c5b..9846146a8 100644
--- a/src/main/java/de/pixart/messenger/utils/SerialSingleThreadExecutor.java
+++ b/src/main/java/de/pixart/messenger/utils/SerialSingleThreadExecutor.java
@@ -16,14 +16,8 @@ public class SerialSingleThreadExecutor implements Executor {
private final String name;
protected Runnable active;
- public SerialSingleThreadExecutor(String name) {
- this(name, false);
- }
- SerialSingleThreadExecutor(String name, boolean prepareLooper) {
- if (prepareLooper) {
- execute(Looper::prepare);
- }
+ public SerialSingleThreadExecutor(String name) {
this.name = name;
}