Fix for contacts not being fetched when permission is denied and is not asked anymore

This commit is contained in:
Sylvain Berfini 2016-08-02 11:10:16 +02:00
parent 02319e73fe
commit c26ae51d3f
3 changed files with 17 additions and 16 deletions

View file

@ -1165,6 +1165,10 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
checkAndRequestPermission(Manifest.permission.READ_CONTACTS, PERMISSIONS_REQUEST_CONTACTS); checkAndRequestPermission(Manifest.permission.READ_CONTACTS, PERMISSIONS_REQUEST_CONTACTS);
} }
private boolean willContactsPermissionBeAsked() {
return LinphonePreferences.instance().firstTimeAskingForPermission(Manifest.permission.READ_CONTACTS) || ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.READ_CONTACTS);
}
public void checkAndRequestWriteContactsPermission() { public void checkAndRequestWriteContactsPermission() {
checkAndRequestPermission(Manifest.permission.WRITE_CONTACTS, 0); checkAndRequestPermission(Manifest.permission.WRITE_CONTACTS, 0);
} }
@ -1265,6 +1269,9 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
ContactsManager.getInstance().enableContactsAccess(); ContactsManager.getInstance().enableContactsAccess();
ContactsManager.getInstance().fetchContactsAsync(); ContactsManager.getInstance().fetchContactsAsync();
fetchedContactsOnce = true; fetchedContactsOnce = true;
} else if (contacts != PackageManager.PERMISSION_GRANTED && !willContactsPermissionBeAsked()) {
ContactsManager.getInstance().fetchContactsAsync();
fetchedContactsOnce = true;
} else { } else {
checkAndRequestReadContactsPermission(); checkAndRequestReadContactsPermission();
} }

View file

@ -419,6 +419,7 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
friend.edit(); friend.edit();
friend.setFamilyName(lastName); friend.setFamilyName(lastName);
friend.setGivenName(firstName); friend.setGivenName(firstName);
friend.setName(fullName);
for (LinphoneAddress address : friend.getAddresses()) { for (LinphoneAddress address : friend.getAddresses()) {
friend.removeAddress(address); friend.removeAddress(address);
@ -443,24 +444,17 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
friend.addPhoneNumber(noa.getValue()); friend.addPhoneNumber(noa.getValue());
} }
} }
if (friend.getAddress() != null) {
friend.setName(fullName);
}
friend.done(); friend.done();
if (friend.getAddress() != null) { try {
if (lc.findFriendByAddress(friend.getAddress().asString()) == null) { LinphoneManager.getLcIfManagerNotDestroyedOrNull().addFriend(friend);
try { if (!ContactsManager.getInstance().hasContactsAccess()) {
lc.addFriend(friend); // This refresh is only needed if app has no contacts permission to refresh the list of LinphoneFriends.
if (!ContactsManager.getInstance().hasContactsAccess()) { // Otherwise contacts will be refreshed due to changes in native contact and the handler in ContactsManager
// This refresh is only needed if app has no contacts permission to refresh the list of LinphoneFriends. ContactsManager.getInstance().fetchContactsAsync();
// Otherwise contacts will be refreshed due to changes in native contact and the handler in ContactsManager
ContactsManager.getInstance().fetchContactsAsync();
}
} catch (LinphoneCoreException e) {
Log.e(e);
}
} }
} catch (LinphoneCoreException e) {
Log.e(e);
} }
} }

@ -1 +1 @@
Subproject commit 4a7099b9833dda9e7ba9908da27a9032c95f38b0 Subproject commit d843d278905d44ae20e51eebc5b6327a121e510f