From a06002dcddc6bbf1d01350a2978d00f3c7665e6e Mon Sep 17 00:00:00 2001 From: uabdullah Date: Tue, 19 Dec 2017 17:02:50 -0800 Subject: Register content observer when voicemail table changes. When a new voicemail is received, it is written in the voicemail table by the Voicemail service. However the new voicemail will not get updated/shown in the New Voicemail UI as the annotated call log would be stale. This CL ensures that when the voicemail is added, the annotated call log is marked dirty and refreshed. This way the new voicemail will be shown in the new voicemail UI. Since a new voicemail is also added, we want to make sure the headers for "today" and "older", their positions are also updated accordingly. Bug: 64882313 Test: Unit tests PiperOrigin-RevId: 179623267 Change-Id: I5dfc84f62f9f37c57ffb2dbbe7e848a58306a19d --- .../systemcalllog/SystemCallLogDataSource.java | 25 ++++++++++++++++------ .../voicemail/listui/NewVoicemailAdapter.java | 19 ++++++++++++++-- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/java/com/android/dialer/calllog/datasources/systemcalllog/SystemCallLogDataSource.java b/java/com/android/dialer/calllog/datasources/systemcalllog/SystemCallLogDataSource.java index 0ed185966..95fbf9d04 100644 --- a/java/com/android/dialer/calllog/datasources/systemcalllog/SystemCallLogDataSource.java +++ b/java/com/android/dialer/calllog/datasources/systemcalllog/SystemCallLogDataSource.java @@ -27,6 +27,7 @@ import android.os.Build; import android.os.Handler; import android.provider.CallLog; import android.provider.CallLog.Calls; +import android.provider.VoicemailContract; import android.support.annotation.ColorInt; import android.support.annotation.MainThread; import android.support.annotation.Nullable; @@ -92,13 +93,21 @@ public class SystemCallLogDataSource implements CallLogDataSource { } // TODO(zachh): Need to somehow register observers if user enables permission after launch? + CallLogObserver callLogObserver = + new CallLogObserver(ThreadUtil.getUiThreadHandler(), appContext, contentObserverCallbacks); + appContext .getContentResolver() - .registerContentObserver( - CallLog.Calls.CONTENT_URI_WITH_VOICEMAIL, - true, - new CallLogObserver( - ThreadUtil.getUiThreadHandler(), appContext, contentObserverCallbacks)); + .registerContentObserver(CallLog.Calls.CONTENT_URI_WITH_VOICEMAIL, true, callLogObserver); + + if (!PermissionsUtil.hasAddVoicemailPermissions(appContext)) { + LogUtil.i("SystemCallLogDataSource.registerContentObservers", "no add voicemail permissions"); + return; + } + // TODO(uabdullah): Need to somehow register observers if user enables permission after launch? + appContext + .getContentResolver() + .registerContentObserver(VoicemailContract.Status.CONTENT_URI, true, callLogObserver); } @Override @@ -462,7 +471,11 @@ public class SystemCallLogDataSource implements CallLogDataSource { @Override public void onChange(boolean selfChange, Uri uri) { Assert.isMainThread(); - LogUtil.enterBlock("SystemCallLogDataSource.CallLogObserver.onChange"); + LogUtil.i( + "SystemCallLogDataSource.CallLogObserver.onChange", + "Uri:%s, SelfChange:%b", + String.valueOf(uri), + selfChange); super.onChange(selfChange, uri); /* diff --git a/java/com/android/dialer/voicemail/listui/NewVoicemailAdapter.java b/java/com/android/dialer/voicemail/listui/NewVoicemailAdapter.java index d94a21465..93d5cda3e 100644 --- a/java/com/android/dialer/voicemail/listui/NewVoicemailAdapter.java +++ b/java/com/android/dialer/voicemail/listui/NewVoicemailAdapter.java @@ -67,9 +67,9 @@ final class NewVoicemailAdapter extends RecyclerView.Adapter private final Clock clock; /** {@link Integer#MAX_VALUE} when the "Today" header should not be displayed. */ - private final int todayHeaderPosition; + private int todayHeaderPosition = Integer.MAX_VALUE; /** {@link Integer#MAX_VALUE} when the "Older" header should not be displayed. */ - private final int olderHeaderPosition; + private int olderHeaderPosition = Integer.MAX_VALUE; private final FragmentManager fragmentManager; /** A valid id for {@link VoicemailEntry} is greater than 0 */ @@ -107,7 +107,15 @@ final class NewVoicemailAdapter extends RecyclerView.Adapter this.clock = clock; this.fragmentManager = fragmentManager; initializeMediaPlayerListeners(); + updateHeaderPositions(); + } + private void updateHeaderPositions() { + LogUtil.i( + "NewVoicemailAdapter.updateHeaderPositions", + "before updating todayPos:%d, olderPos:%d", + todayHeaderPosition, + olderHeaderPosition); // Calculate header adapter positions by reading cursor. long currentTimeMillis = clock.currentTimeMillis(); if (cursor.moveToNext()) { @@ -134,6 +142,11 @@ final class NewVoicemailAdapter extends RecyclerView.Adapter this.todayHeaderPosition = Integer.MAX_VALUE; this.olderHeaderPosition = Integer.MAX_VALUE; } + LogUtil.i( + "NewVoicemailAdapter.updateHeaderPositions", + "after updating todayPos:%d, olderPos:%d", + todayHeaderPosition, + olderHeaderPosition); } private void initializeMediaPlayerListeners() { @@ -143,8 +156,10 @@ final class NewVoicemailAdapter extends RecyclerView.Adapter } public void updateCursor(Cursor updatedCursor) { + LogUtil.enterBlock("NewVoicemailAdapter.updateCursor"); deletedVoicemailPosition.clear(); this.cursor = updatedCursor; + updateHeaderPositions(); notifyDataSetChanged(); } -- cgit v1.2.3