From b7330e3802e8f9182ae1f5e54857a713b2f13547 Mon Sep 17 00:00:00 2001 From: Yorke Lee Date: Fri, 22 May 2015 15:55:22 -0700 Subject: Handle runtime phone permission We don't have access to the call log without the phone permission, so disable the following functionality: 1) Call log display 2) Show call history overflow menu option 3) Last number dialed functionality Bug: 20266292 Change-Id: I2f1d4b8b5f747d2fa04c3a9c291f9cf5147646b7 --- src/com/android/dialer/DialtactsActivity.java | 3 +++ src/com/android/dialer/calllog/CallLogFragment.java | 7 +++---- .../dialer/calllog/CallLogNotificationsService.java | 5 +++++ src/com/android/dialer/calllog/CallLogQueryHandler.java | 17 ++++++++++++++++- src/com/android/dialer/dialpad/DialpadFragment.java | 3 +++ 5 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/com/android/dialer/DialtactsActivity.java b/src/com/android/dialer/DialtactsActivity.java index e240cf0aa..96dc415da 100644 --- a/src/com/android/dialer/DialtactsActivity.java +++ b/src/com/android/dialer/DialtactsActivity.java @@ -257,6 +257,9 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O menu.findItem(R.id.menu_import_export).setVisible(hasContactsPermission); menu.findItem(R.id.menu_add_contact).setVisible(hasContactsPermission); + + menu.findItem(R.id.menu_history).setVisible( + PermissionsUtil.hasPhonePermissions(DialtactsActivity.this)); super.show(); } } diff --git a/src/com/android/dialer/calllog/CallLogFragment.java b/src/com/android/dialer/calllog/CallLogFragment.java index e8ed17ec6..f98fc2169 100644 --- a/src/com/android/dialer/calllog/CallLogFragment.java +++ b/src/com/android/dialer/calllog/CallLogFragment.java @@ -188,7 +188,6 @@ public class CallLogFragment extends Fragment mContactsObserver); resolver.registerContentObserver(Status.CONTENT_URI, true, mVoicemailStatusObserver); setHasOptionsMenu(true); - fetchCalls(); } /** Called by the CallLogQueryHandler when the list of calls has been fetched or updated. */ @@ -203,7 +202,7 @@ public class CallLogFragment extends Fragment // This will update the state of the "Clear call log" menu item. getActivity().invalidateOptionsMenu(); - boolean showListView = cursor.getCount() > 0; + boolean showListView = cursor != null && cursor.getCount() > 0; mRecyclerView.setVisibility(showListView ? View.VISIBLE : View.GONE); mEmptyListView.setVisibility(!showListView ? View.VISIBLE : View.GONE); @@ -266,6 +265,7 @@ public class CallLogFragment extends Fragment mRecyclerView.setHasFixedSize(true); mLayoutManager = new LinearLayoutManager(getActivity()); mRecyclerView.setLayoutManager(mLayoutManager); + mEmptyListView = view.findViewById(R.id.empty_list_view); String currentCountryIso = GeoUtil.getCurrentCountryIso(getActivity()); boolean isShowingRecentsTab = mLogLimit != NO_LOG_LIMIT || mDateLimit != NO_DATE_LIMIT; @@ -278,14 +278,13 @@ public class CallLogFragment extends Fragment mRecyclerView.setAdapter(mAdapter); mVoicemailStatusHelper = new VoicemailStatusHelperImpl(); + fetchCalls(); return view; } @Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); - mEmptyListView = view.findViewById(R.id.empty_list_view); - updateEmptyMessage(mCallTypeFilter); } diff --git a/src/com/android/dialer/calllog/CallLogNotificationsService.java b/src/com/android/dialer/calllog/CallLogNotificationsService.java index 22809db8c..9f48b0969 100644 --- a/src/com/android/dialer/calllog/CallLogNotificationsService.java +++ b/src/com/android/dialer/calllog/CallLogNotificationsService.java @@ -22,6 +22,7 @@ import android.content.Intent; import android.net.Uri; import android.util.Log; +import com.android.contacts.common.util.PermissionsUtil; import com.android.dialer.util.TelecomUtil; /** @@ -78,6 +79,10 @@ public class CallLogNotificationsService extends IntentService { return; } + if (!PermissionsUtil.hasPhonePermissions(this)) { + return; + } + if (ACTION_MARK_NEW_VOICEMAILS_AS_OLD.equals(intent.getAction())) { mVoicemailQueryHandler.markNewVoicemailsAsOld(); } else if (ACTION_UPDATE_NOTIFICATIONS.equals(intent.getAction())) { diff --git a/src/com/android/dialer/calllog/CallLogQueryHandler.java b/src/com/android/dialer/calllog/CallLogQueryHandler.java index 49d6a4121..a0e563aef 100644 --- a/src/com/android/dialer/calllog/CallLogQueryHandler.java +++ b/src/com/android/dialer/calllog/CallLogQueryHandler.java @@ -35,6 +35,7 @@ import android.provider.VoicemailContract.Voicemails; import android.util.Log; import com.android.contacts.common.database.NoNullCursorAsyncQueryHandler; +import com.android.contacts.common.util.PermissionsUtil; import com.android.dialer.util.TelecomUtil; import com.android.dialer.voicemail.VoicemailStatusHelperImpl; @@ -93,6 +94,10 @@ public class CallLogQueryHandler extends NoNullCursorAsyncQueryHandler { Log.w(TAG, "Exception on background worker thread", e); } catch (IllegalArgumentException e) { Log.w(TAG, "ContactsProvider not present on device", e); + } catch (SecurityException e) { + // Shouldn't happen if we are protecting the entry points correctly, + // but just in case. + Log.w(TAG, "No permission to access ContactsProvider.", e); } } } @@ -124,7 +129,11 @@ public class CallLogQueryHandler extends NoNullCursorAsyncQueryHandler { */ public void fetchCalls(int callType, long newerThan) { cancelFetch(); - fetchCalls(QUERY_CALLLOG_TOKEN, callType, false /* newOnly */, newerThan); + if (PermissionsUtil.hasPhonePermissions(mContext)) { + fetchCalls(QUERY_CALLLOG_TOKEN, callType, false /* newOnly */, newerThan); + } else { + updateAdapterData(null); + } } public void fetchCalls(int callType) { @@ -187,6 +196,9 @@ public class CallLogQueryHandler extends NoNullCursorAsyncQueryHandler { /** Updates all new calls to mark them as old. */ public void markNewCallsAsOld() { + if (!PermissionsUtil.hasPhonePermissions(mContext)) { + return; + } // Mark all "new" calls as not new anymore. StringBuilder where = new StringBuilder(); where.append(Calls.NEW); @@ -201,6 +213,9 @@ public class CallLogQueryHandler extends NoNullCursorAsyncQueryHandler { /** Updates all missed calls to mark them as read. */ public void markMissedCallsAsRead() { + if (!PermissionsUtil.hasPhonePermissions(mContext)) { + return; + } // Mark all "new" calls as not new anymore. StringBuilder where = new StringBuilder(); where.append(Calls.IS_READ).append(" = 0"); diff --git a/src/com/android/dialer/dialpad/DialpadFragment.java b/src/com/android/dialer/dialpad/DialpadFragment.java index de1d44f89..89cab4162 100644 --- a/src/com/android/dialer/dialpad/DialpadFragment.java +++ b/src/com/android/dialer/dialpad/DialpadFragment.java @@ -1600,6 +1600,9 @@ public class DialpadFragment extends Fragment */ private void queryLastOutgoingCall() { mLastNumberDialed = EMPTY_NUMBER; + if (!PermissionsUtil.hasPhonePermissions(getActivity())) { + return; + } CallLogAsync.GetLastOutgoingCallArgs lastCallArgs = new CallLogAsync.GetLastOutgoingCallArgs( getActivity(), -- cgit v1.2.3