From ea1acce9b02cc6cf305c75cad733939527c7775b Mon Sep 17 00:00:00 2001 From: linyuh Date: Fri, 27 Apr 2018 09:58:00 -0700 Subject: Handle missing permission.READ_CALL_LOG when initializing the badge for missed calls. Bug: 78458610 Test: MainActivityOldPeerTest PiperOrigin-RevId: 194555035 Change-Id: Ib3ef02ec3f4a8ce7cfce6d052fce3b9b6daf75e5 --- java/com/android/dialer/main/impl/OldMainActivityPeer.java | 14 ++++++++++---- .../main/impl/bottomnav/MissedCallCountObserver.java | 9 +++------ 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/java/com/android/dialer/main/impl/OldMainActivityPeer.java b/java/com/android/dialer/main/impl/OldMainActivityPeer.java index 9ac351094..e3d42fa9e 100644 --- a/java/com/android/dialer/main/impl/OldMainActivityPeer.java +++ b/java/com/android/dialer/main/impl/OldMainActivityPeer.java @@ -457,6 +457,7 @@ public class OldMainActivityPeer implements MainActivityPeer, FragmentUtilListen return DialpadFragment.isAddCallMode(intent); } + @SuppressLint("MissingPermission") @Override public void onActivityResume() { callLogFragmentListener.onActivityResume(); @@ -492,11 +493,16 @@ public class OldMainActivityPeer implements MainActivityPeer, FragmentUtilListen bottomNavTabListener.ensureCorrectCallLogShown(); bottomNavTabListener.ensureCorrectVoicemailShown(); + // Config the badge of missed calls for the new call log. if (bottomNavTabListener.newCallLogFragmentActive()) { - missedCallCountObserver.onChange(false); // Set the initial value for the badge - activity - .getContentResolver() - .registerContentObserver(Calls.CONTENT_URI, true, missedCallCountObserver); + if (PermissionsUtil.hasCallLogReadPermissions(activity)) { + missedCallCountObserver.onChange(false); // Set the initial value for the badge + activity + .getContentResolver() + .registerContentObserver(Calls.CONTENT_URI, true, missedCallCountObserver); + } else { + bottomNav.setNotificationCount(TabIndex.CALL_LOG, 0); + } } // add 1 sec delay to get memory snapshot so that dialer wont react slowly on resume. diff --git a/java/com/android/dialer/main/impl/bottomnav/MissedCallCountObserver.java b/java/com/android/dialer/main/impl/bottomnav/MissedCallCountObserver.java index ee7f6d006..a4995c1e6 100644 --- a/java/com/android/dialer/main/impl/bottomnav/MissedCallCountObserver.java +++ b/java/com/android/dialer/main/impl/bottomnav/MissedCallCountObserver.java @@ -16,15 +16,15 @@ package com.android.dialer.main.impl.bottomnav; -import android.annotation.SuppressLint; +import android.Manifest; import android.content.Context; import android.database.ContentObserver; import android.database.Cursor; import android.provider.CallLog.Calls; +import android.support.annotation.RequiresPermission; import com.android.dialer.common.concurrent.DialerExecutorComponent; import com.android.dialer.common.concurrent.UiListener; import com.android.dialer.main.impl.bottomnav.BottomNavBar.TabIndex; -import com.android.dialer.util.PermissionsUtil; import com.google.common.util.concurrent.ListenableFuture; /** @@ -45,7 +45,7 @@ public final class MissedCallCountObserver extends ContentObserver { this.uiListener = uiListener; } - @SuppressLint("MissingPermission") + @RequiresPermission(Manifest.permission.READ_CALL_LOG) @Override public void onChange(boolean selfChange) { ListenableFuture countFuture = @@ -53,9 +53,6 @@ public final class MissedCallCountObserver extends ContentObserver { .backgroundExecutor() .submit( () -> { - if (!PermissionsUtil.hasCallLogReadPermissions(appContext)) { - return 0; - } try (Cursor cursor = appContext .getContentResolver() -- cgit v1.2.3