mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-25 01:07:47 +00:00
Make sure the number we add canonicalizes to the number we know.
Fixes #4406 // FREEBIE
This commit is contained in:
parent
0b7b37bf00
commit
b5b564cfe1
@ -23,13 +23,11 @@ import android.content.OperationApplicationException;
|
|||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.database.CursorWrapper;
|
import android.database.CursorWrapper;
|
||||||
import android.database.MatrixCursor;
|
import android.database.MatrixCursor;
|
||||||
import android.database.MergeCursor;
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.provider.BaseColumns;
|
import android.provider.BaseColumns;
|
||||||
import android.provider.ContactsContract;
|
import android.provider.ContactsContract;
|
||||||
import android.provider.ContactsContract.CommonDataKinds.Phone;
|
|
||||||
import android.provider.ContactsContract.RawContacts;
|
import android.provider.ContactsContract.RawContacts;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
@ -38,10 +36,6 @@ import android.util.Log;
|
|||||||
import android.util.Pair;
|
import android.util.Pair;
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.R;
|
import org.thoughtcrime.securesms.R;
|
||||||
import org.thoughtcrime.securesms.database.TextSecureDirectory;
|
|
||||||
import org.thoughtcrime.securesms.recipients.RecipientFactory;
|
|
||||||
import org.thoughtcrime.securesms.util.DirectoryHelper;
|
|
||||||
import org.thoughtcrime.securesms.util.DirectoryHelper.UserCapabilities.Capability;
|
|
||||||
import org.whispersystems.libaxolotl.util.guava.Optional;
|
import org.whispersystems.libaxolotl.util.guava.Optional;
|
||||||
import org.whispersystems.textsecure.api.util.InvalidNumberException;
|
import org.whispersystems.textsecure.api.util.InvalidNumberException;
|
||||||
import org.whispersystems.textsecure.api.util.PhoneNumberFormatter;
|
import org.whispersystems.textsecure.api.util.PhoneNumberFormatter;
|
||||||
@ -119,9 +113,10 @@ public class ContactsDatabase {
|
|||||||
|
|
||||||
for (String number : e164numbers) {
|
for (String number : e164numbers) {
|
||||||
if (!currentContacts.containsKey(number)) {
|
if (!currentContacts.containsKey(number)) {
|
||||||
Optional<SystemContactInfo> systemContactInfo = getSystemContactInfo(number);
|
Optional<SystemContactInfo> systemContactInfo = getSystemContactInfo(number, localNumber);
|
||||||
|
|
||||||
if (systemContactInfo.isPresent()) {
|
if (systemContactInfo.isPresent()) {
|
||||||
|
Log.w(TAG, "Adding number: " + number);
|
||||||
addedNumbers.add(number);
|
addedNumbers.add(number);
|
||||||
addTextSecureRawContact(operations, account, systemContactInfo.get().number, systemContactInfo.get().id);
|
addTextSecureRawContact(operations, account, systemContactInfo.get().number, systemContactInfo.get().id);
|
||||||
}
|
}
|
||||||
@ -280,7 +275,9 @@ public class ContactsDatabase {
|
|||||||
return newNumberCursor;
|
return newNumberCursor;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Optional<SystemContactInfo> getSystemContactInfo(String e164number) {
|
private Optional<SystemContactInfo> getSystemContactInfo(@NonNull String e164number,
|
||||||
|
@NonNull String localNumber)
|
||||||
|
{
|
||||||
Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(e164number));
|
Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(e164number));
|
||||||
String[] projection = {ContactsContract.PhoneLookup.NUMBER,
|
String[] projection = {ContactsContract.PhoneLookup.NUMBER,
|
||||||
ContactsContract.PhoneLookup._ID,
|
ContactsContract.PhoneLookup._ID,
|
||||||
@ -291,7 +288,12 @@ public class ContactsDatabase {
|
|||||||
try {
|
try {
|
||||||
numberCursor = context.getContentResolver().query(uri, projection, null, null, null);
|
numberCursor = context.getContentResolver().query(uri, projection, null, null, null);
|
||||||
|
|
||||||
if (numberCursor != null && numberCursor.moveToNext()) {
|
while (numberCursor != null && numberCursor.moveToNext()) {
|
||||||
|
try {
|
||||||
|
String systemNumber = numberCursor.getString(0);
|
||||||
|
String canonicalizedSystemNumber = PhoneNumberFormatter.formatNumber(systemNumber, localNumber);
|
||||||
|
|
||||||
|
if (canonicalizedSystemNumber.equals(e164number)) {
|
||||||
idCursor = context.getContentResolver().query(RawContacts.CONTENT_URI,
|
idCursor = context.getContentResolver().query(RawContacts.CONTENT_URI,
|
||||||
new String[] {RawContacts._ID},
|
new String[] {RawContacts._ID},
|
||||||
RawContacts.CONTACT_ID + " = ? ",
|
RawContacts.CONTACT_ID + " = ? ",
|
||||||
@ -304,6 +306,10 @@ public class ContactsDatabase {
|
|||||||
idCursor.getLong(0)));
|
idCursor.getLong(0)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (InvalidNumberException e) {
|
||||||
|
Log.w(TAG, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
if (numberCursor != null) numberCursor.close();
|
if (numberCursor != null) numberCursor.close();
|
||||||
if (idCursor != null) idCursor.close();
|
if (idCursor != null) idCursor.close();
|
||||||
|
@ -25,6 +25,8 @@ public class ContactsSyncAdapter extends AbstractThreadedSyncAdapter {
|
|||||||
public void onPerformSync(Account account, Bundle extras, String authority,
|
public void onPerformSync(Account account, Bundle extras, String authority,
|
||||||
ContentProviderClient provider, SyncResult syncResult)
|
ContentProviderClient provider, SyncResult syncResult)
|
||||||
{
|
{
|
||||||
|
Log.w(TAG, "onPerformSync(" + authority +")");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
DirectoryHelper.refreshDirectory(getContext(), KeyCachingService.getMasterSecret(getContext()));
|
DirectoryHelper.refreshDirectory(getContext(), KeyCachingService.getMasterSecret(getContext()));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
@ -2,6 +2,7 @@ package org.thoughtcrime.securesms.jobs;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.PowerManager;
|
import android.os.PowerManager;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.crypto.SecurityEvent;
|
import org.thoughtcrime.securesms.crypto.SecurityEvent;
|
||||||
import org.thoughtcrime.securesms.service.KeyCachingService;
|
import org.thoughtcrime.securesms.service.KeyCachingService;
|
||||||
@ -26,6 +27,7 @@ public class DirectoryRefreshJob extends ContextJob {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRun() throws IOException {
|
public void onRun() throws IOException {
|
||||||
|
Log.w("DirectoryRefreshJob", "DirectoryRefreshJob.onRun()");
|
||||||
PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
|
PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
|
||||||
PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Directory Refresh");
|
PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Directory Refresh");
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user