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);
|
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();
|
||||||
}
|
}
|
||||||
|
|
|
@ -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,15 +444,10 @@ 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) {
|
|
||||||
if (lc.findFriendByAddress(friend.getAddress().asString()) == null) {
|
|
||||||
try {
|
try {
|
||||||
lc.addFriend(friend);
|
LinphoneManager.getLcIfManagerNotDestroyedOrNull().addFriend(friend);
|
||||||
if (!ContactsManager.getInstance().hasContactsAccess()) {
|
if (!ContactsManager.getInstance().hasContactsAccess()) {
|
||||||
// This refresh is only needed if app has no contacts permission to refresh the list of LinphoneFriends.
|
// 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
|
// Otherwise contacts will be refreshed due to changes in native contact and the handler in ContactsManager
|
||||||
|
@ -461,8 +457,6 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
||||||
Log.e(e);
|
Log.e(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void save() {
|
public void save() {
|
||||||
if (isAndroidContact() && ContactsManager.getInstance().hasContactsAccess() && changesToCommit.size() > 0) {
|
if (isAndroidContact() && ContactsManager.getInstance().hasContactsAccess() && changesToCommit.size() > 0) {
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 4a7099b9833dda9e7ba9908da27a9032c95f38b0
|
Subproject commit d843d278905d44ae20e51eebc5b6327a121e510f
|
Loading…
Reference in a new issue