Improvements on package name use (since we had .debug to it sometimes) + fixed disapearing SIP contacts if they only have presence and no real SIP URI

This commit is contained in:
Sylvain Berfini 2018-12-06 15:44:34 +01:00
parent 54e7760fdd
commit 9d66458f36
8 changed files with 35 additions and 37 deletions

View file

@ -52,6 +52,7 @@ android {
versionName "4.1" versionName "4.1"
applicationId getPackageName() applicationId getPackageName()
multiDexEnabled true multiDexEnabled true
manifestPlaceholders = [absolutePackageName:getPackageName()]
} }
applicationVariants.all { variant -> applicationVariants.all { variant ->

View file

@ -190,35 +190,32 @@ class AsyncContactsLoader extends AsyncTask<Void, Void, AsyncContactsLoader.Asyn
for (LinphoneContact contact : androidContactsCache.values()) { for (LinphoneContact contact : androidContactsCache.values()) {
if (isCancelled()) return data; if (isCancelled()) return data;
boolean hideContactsWithoutPresence = if (contact.getFullName() == null) {
mContext.getResources().getBoolean(R.bool.hide_sip_contacts_without_presence); for (LinphoneNumberOrAddress noa : contact.getNumbersOrAddresses()) {
if (contact.hasAddress()) { if (noa.isSIPAddress()) {
if (contact.getFullName() == null) { contact.setFullName(LinphoneUtils.getAddressDisplayName(noa.getValue()));
for (LinphoneNumberOrAddress noa : contact.getNumbersOrAddresses()) { Log.w(
if (noa.isSIPAddress()) { "[Contacts Manager] Couldn't find a display name for contact "
contact.setFullName( + contact.getFullName()
LinphoneUtils.getAddressDisplayName(noa.getValue())); + ", used SIP address display name / username instead...");
Log.w( break;
"[Contacts Manager] Couldn't find a display name for contact "
+ contact.getFullName()
+ ", used SIP address display name / username instead...");
break;
}
} }
} }
if (hideContactsWithoutPresence) { }
if (contact.getFriend() != null) {
for (LinphoneNumberOrAddress noa : contact.getNumbersOrAddresses()) { if (contact.getFriend() != null) {
PresenceModel pm = for (LinphoneNumberOrAddress noa : contact.getNumbersOrAddresses()) {
contact.getFriend().getPresenceModelForUriOrTel(noa.getValue()); PresenceModel pm =
if (pm != null contact.getFriend().getPresenceModelForUriOrTel(noa.getValue());
&& pm.getBasicStatus().equals(PresenceBasicStatus.Open)) { if (pm != null && pm.getBasicStatus().equals(PresenceBasicStatus.Open)) {
data.sipContacts.add(contact); data.sipContacts.add(contact);
break; break;
}
}
} }
} else { }
}
if (!mContext.getResources().getBoolean(R.bool.hide_sip_contacts_without_presence)) {
if (contact.hasAddress() && !data.sipContacts.contains(contact)) {
data.sipContacts.add(contact); data.sipContacts.add(contact);
} }
} }

View file

@ -267,17 +267,18 @@ public class ContactsManager extends ContentObserver implements FriendListListen
AccountManager accountManager = AccountManager accountManager =
(AccountManager) activity.getSystemService(Context.ACCOUNT_SERVICE); (AccountManager) activity.getSystemService(Context.ACCOUNT_SERVICE);
Account[] accounts = accountManager.getAccountsByType(activity.getPackageName()); Account[] accounts =
accountManager.getAccountsByType(mContext.getString(R.string.sync_account_type));
if (accounts != null && accounts.length == 0) { if (accounts != null && accounts.length == 0) {
Account newAccount = Account newAccount =
new Account( new Account(
mContext.getString(R.string.sync_account_name), mContext.getString(R.string.sync_account_name),
activity.getPackageName()); mContext.getString(R.string.sync_account_type));
try { try {
accountManager.addAccountExplicitly(newAccount, null, null); accountManager.addAccountExplicitly(newAccount, null, null);
} catch (Exception e) { } catch (Exception e) {
Log.e("[Contacts Manager] " + e); Log.e("[Contacts Manager] Couldn't initialize sync account: " + e);
} }
} }
} }

View file

@ -776,10 +776,10 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
&& ContactsManager.getInstance().hasContactsAccess() && ContactsManager.getInstance().hasContactsAccess()
&& mChangesToCommit.size() > 0) { && mChangesToCommit.size() > 0) {
try { try {
createLinphoneTagIfNeeded();
LinphoneService.instance() LinphoneService.instance()
.getContentResolver() .getContentResolver()
.applyBatch(ContactsContract.AUTHORITY, mChangesToCommit); .applyBatch(ContactsContract.AUTHORITY, mChangesToCommit);
createLinphoneTagIfNeeded();
} catch (Exception e) { } catch (Exception e) {
Log.e(e); Log.e(e);
} finally { } finally {

View file

@ -4,9 +4,9 @@
<!-- Global --> <!-- Global -->
<string name="default_domain">sip.linphone.org</string><!-- Set the default domain used for account creation/addresses --> <string name="default_domain">sip.linphone.org</string><!-- Set the default domain used for account creation/addresses -->
<string name="default_conference_factory_uri">sip:conference-factory@sip.linphone.org</string> <string name="default_conference_factory_uri">sip:conference-factory@sip.linphone.org</string>
<string name="file_provider">org.linphone.provider</string> <string name="file_provider">${absolutePackageName}.provider</string>
<string name="sync_account_type">${applicationId}</string> <string name="sync_account_type">${absolutePackageName}</string>
<string name="sync_mimetype">vnd.android.cursor.item/${applicationId}.profile</string> <string name="sync_mimetype">vnd.android.cursor.item/${absolutePackageName}.profile</string>
<string name="rls_uri">sip:rls@sip.linphone.org</string> <string name="rls_uri">sip:rls@sip.linphone.org</string>
<string name="user_agent">LinphoneAndroid</string> <string name="user_agent">LinphoneAndroid</string>
<bool name="orientation_portrait_only">false</bool> <bool name="orientation_portrait_only">false</bool>

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<account-authenticator xmlns:android="http://schemas.android.com/apk/res/android" <account-authenticator xmlns:android="http://schemas.android.com/apk/res/android"
android:accountType="@string/sync_account_type" android:accountType="${absolutePackageName}"
android:icon="@drawable/linphone_logo" android:icon="@drawable/linphone_logo"
android:label="@string/app_name" android:label="@string/app_name"
android:smallIcon="@drawable/linphone_logo" /> android:smallIcon="@drawable/linphone_logo" />

View file

@ -1,12 +1,11 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<ContactsSource xmlns:android="http://schemas.android.com/apk/res/android"> <ContactsSource xmlns:android="http://schemas.android.com/apk/res/android">
<ContactsDataKind <ContactsDataKind
android:detailColumn="data3" android:detailColumn="data3"
android:detailSocialSummary="true" android:detailSocialSummary="true"
android:icon="@drawable/linphone_logo" android:icon="@drawable/linphone_logo"
android:mimeType="vnd.android.cursor.item/${applicationId}.profile" android:mimeType="vnd.android.cursor.item/${absolutePackageName}.profile"
android:summaryColumn="data2" /> android:summaryColumn="data2" />
</ContactsSource> </ContactsSource>

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<sync-adapter xmlns:android="http://schemas.android.com/apk/res/android" <sync-adapter xmlns:android="http://schemas.android.com/apk/res/android"
android:accountType="@string/sync_account_type" android:accountType="${absolutePackageName}"
android:contentAuthority="com.android.contacts" android:contentAuthority="com.android.contacts"
android:supportsUploading="false" android:supportsUploading="false"
android:userVisible="false" /> android:userVisible="false" />