diff options
author | erfanian <erfanian@google.com> | 2017-07-21 11:08:54 -0700 |
---|---|---|
committer | Eric Erfanian <erfanian@google.com> | 2017-07-25 16:43:57 +0000 |
commit | 2919941419a5f814cd2f02a6b3876e56b0478352 (patch) | |
tree | 5e74f6f1d5ecb2a8dee12f227e8a2a5b8dd27769 /java | |
parent | df6f6725e346dfb0f7b068aaa6ba08a4993b2ebb (diff) |
Check for contacts permission before mutating contacts.
Before:
PhoneNumberInteraction only checked if it could Read CONTACT.
This resulted in a crash when setting super primary number preferences.
After:
PhoneNumberInteration checks for R/W.
Any missing, required permissions are now granted.
Steps to reproduce:
1) Add a contact with two different numbers.
2) Mark that contact as a favorite.
3) Long press on the dialer icon, long press on the contact, and add them as an icon to your screen.
4) Tap on the icon
5) Grant contact permissions.
6) App crashes.
Bug: 63668172
Test: on device, unit tests
PiperOrigin-RevId: 162761620
Change-Id: Ic9aefbb8101bc73294eb871cc9684b0464d4bdcd
Diffstat (limited to 'java')
-rw-r--r-- | java/com/android/dialer/interactions/PhoneNumberInteraction.java | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/java/com/android/dialer/interactions/PhoneNumberInteraction.java b/java/com/android/dialer/interactions/PhoneNumberInteraction.java index ef468a9f3..39781cf37 100644 --- a/java/com/android/dialer/interactions/PhoneNumberInteraction.java +++ b/java/com/android/dialer/interactions/PhoneNumberInteraction.java @@ -15,7 +15,6 @@ */ package com.android.dialer.interactions; -import android.Manifest; import android.annotation.SuppressLint; import android.app.Activity; import android.app.AlertDialog; @@ -28,7 +27,6 @@ import android.content.DialogInterface; import android.content.Intent; import android.content.Loader; import android.content.Loader.OnLoadCompleteListener; -import android.content.pm.PackageManager; import android.database.Cursor; import android.net.Uri; import android.os.Bundle; @@ -42,7 +40,6 @@ import android.provider.ContactsContract.RawContacts; import android.support.annotation.IntDef; import android.support.annotation.VisibleForTesting; import android.support.v4.app.ActivityCompat; -import android.support.v4.content.ContextCompat; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -63,10 +60,12 @@ import com.android.dialer.common.LogUtil; import com.android.dialer.logging.InteractionEvent; import com.android.dialer.logging.Logger; import com.android.dialer.util.DialerUtils; +import com.android.dialer.util.PermissionsUtil; import com.android.dialer.util.TransactionSafeActivity; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; /** @@ -221,20 +220,27 @@ public class PhoneNumberInteraction implements OnLoadCompleteListener<Cursor> { // It's possible for a shortcut to have been created, and then permissions revoked. To avoid a // crash when the user tries to use such a shortcut, check for this condition and ask the user // for the permission. - if (ContextCompat.checkSelfPermission(mContext, Manifest.permission.CALL_PHONE) - != PackageManager.PERMISSION_GRANTED) { - LogUtil.i("PhoneNumberInteraction.startInteraction", "No phone permissions"); + String[] deniedPhonePermissions = + PermissionsUtil.getPermissionsCurrentlyDenied( + mContext, PermissionsUtil.allPhoneGroupPermissionsUsedInDialer); + if (deniedPhonePermissions.length > 0) { + LogUtil.i( + "PhoneNumberInteraction.startInteraction", + "Need phone permissions: " + Arrays.toString(deniedPhonePermissions)); ActivityCompat.requestPermissions( - (Activity) mContext, new String[] {Manifest.permission.CALL_PHONE}, REQUEST_CALL_PHONE); + (Activity) mContext, deniedPhonePermissions, REQUEST_CALL_PHONE); return; } - if (ContextCompat.checkSelfPermission(mContext, Manifest.permission.READ_CONTACTS) - != PackageManager.PERMISSION_GRANTED) { - LogUtil.i("PhoneNumberInteraction.startInteraction", "No contact permissions"); + + String[] deniedContactsPermissions = + PermissionsUtil.getPermissionsCurrentlyDenied( + mContext, PermissionsUtil.allContactsGroupPermissionsUsedInDialer); + if (deniedContactsPermissions.length > 0) { + LogUtil.i( + "PhoneNumberInteraction.startInteraction", + "Need contact permissions: " + Arrays.toString(deniedContactsPermissions)); ActivityCompat.requestPermissions( - (Activity) mContext, - new String[] {Manifest.permission.READ_CONTACTS}, - REQUEST_READ_CONTACTS); + (Activity) mContext, deniedContactsPermissions, REQUEST_READ_CONTACTS); return; } |