Fix for contacts not being fetched when permission is denied and is not asked anymore
This commit is contained in:
parent
02319e73fe
commit
c26ae51d3f
3 changed files with 17 additions and 16 deletions
|
@ -1165,6 +1165,10 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
|
|||
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() {
|
||||
checkAndRequestPermission(Manifest.permission.WRITE_CONTACTS, 0);
|
||||
}
|
||||
|
@ -1265,6 +1269,9 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
|
|||
ContactsManager.getInstance().enableContactsAccess();
|
||||
ContactsManager.getInstance().fetchContactsAsync();
|
||||
fetchedContactsOnce = true;
|
||||
} else if (contacts != PackageManager.PERMISSION_GRANTED && !willContactsPermissionBeAsked()) {
|
||||
ContactsManager.getInstance().fetchContactsAsync();
|
||||
fetchedContactsOnce = true;
|
||||
} else {
|
||||
checkAndRequestReadContactsPermission();
|
||||
}
|
||||
|
|
|
@ -419,6 +419,7 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
|||
friend.edit();
|
||||
friend.setFamilyName(lastName);
|
||||
friend.setGivenName(firstName);
|
||||
friend.setName(fullName);
|
||||
|
||||
for (LinphoneAddress address : friend.getAddresses()) {
|
||||
friend.removeAddress(address);
|
||||
|
@ -443,24 +444,17 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
|||
friend.addPhoneNumber(noa.getValue());
|
||||
}
|
||||
}
|
||||
if (friend.getAddress() != null) {
|
||||
friend.setName(fullName);
|
||||
}
|
||||
friend.done();
|
||||
|
||||
if (friend.getAddress() != null) {
|
||||
if (lc.findFriendByAddress(friend.getAddress().asString()) == null) {
|
||||
try {
|
||||
lc.addFriend(friend);
|
||||
if (!ContactsManager.getInstance().hasContactsAccess()) {
|
||||
// This refresh is only needed if app has no contacts permission to refresh the list of LinphoneFriends.
|
||||
// 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);
|
||||
}
|
||||
try {
|
||||
LinphoneManager.getLcIfManagerNotDestroyedOrNull().addFriend(friend);
|
||||
if (!ContactsManager.getInstance().hasContactsAccess()) {
|
||||
// This refresh is only needed if app has no contacts permission to refresh the list of LinphoneFriends.
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 4a7099b9833dda9e7ba9908da27a9032c95f38b0
|
||||
Subproject commit d843d278905d44ae20e51eebc5b6327a121e510f
|
Loading…
Reference in a new issue