From c18ca0fba4375134107c6e71dab9bd0f85a2c968 Mon Sep 17 00:00:00 2001 From: mdooley Date: Thu, 7 Sep 2017 17:15:59 -0700 Subject: Updating voicemail notifications This is mostly just a revived version of cl/158901400. It adds a job service that is triggered by changes to the voicemail database. The job updates voicemail notifications, as necessary. video of notification update: https://drive.google.com/open?id=0B9o_KvtLkcuId1ptNk1EbGotWFU Bug: 37340510,27535759 Test: manual and unit test PiperOrigin-RevId: 167934550 Change-Id: I36f03c0769645f7a0cb478172171f1079eca2108 --- .../calllog/VoicemailNotificationJobService.java | 89 ++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 java/com/android/dialer/app/calllog/VoicemailNotificationJobService.java (limited to 'java/com/android/dialer/app/calllog/VoicemailNotificationJobService.java') diff --git a/java/com/android/dialer/app/calllog/VoicemailNotificationJobService.java b/java/com/android/dialer/app/calllog/VoicemailNotificationJobService.java new file mode 100644 index 000000000..ba61601ae --- /dev/null +++ b/java/com/android/dialer/app/calllog/VoicemailNotificationJobService.java @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +package com.android.dialer.app.calllog; + +import android.app.job.JobInfo; +import android.app.job.JobParameters; +import android.app.job.JobScheduler; +import android.app.job.JobService; +import android.content.ComponentName; +import android.content.Context; +import android.os.Build; +import android.provider.VoicemailContract; +import com.android.dialer.common.LogUtil; +import com.android.dialer.constants.ScheduledJobIds; + +/** Monitors voicemail provider changes to update active notifications. */ +public class VoicemailNotificationJobService extends JobService { + + private static JobInfo jobInfo; + + /** + * Start monitoring the provider. The provider should be monitored whenever a visual voicemail + * notification is visible. + */ + public static void scheduleJob(Context context) { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { + LogUtil.i("VoicemailNotificationJobService.scheduleJob", "not supported"); + } else { + context.getSystemService(JobScheduler.class).schedule(getJobInfo(context)); + LogUtil.i("VoicemailNotificationJobService.scheduleJob", "job scheduled"); + } + } + + /** + * Stop monitoring the provider. The provider should not be monitored when visual voicemail + * notification is cleared. + */ + public static void cancelJob(Context context) { + context.getSystemService(JobScheduler.class).cancel(ScheduledJobIds.VVM_NOTIFICATION_JOB); + LogUtil.i("VoicemailNotificationJobService.scheduleJob", "job canceled"); + } + + @Override + public boolean onStartJob(JobParameters params) { + LogUtil.i("VoicemailNotificationJobService.onStartJob", "updating notification"); + VisualVoicemailUpdateTask.scheduleTask( + this, + () -> { + jobFinished(params, false); + }); + return true; // Running in background + } + + @Override + public boolean onStopJob(JobParameters params) { + return false; + } + + private static JobInfo getJobInfo(Context context) { + if (jobInfo == null) { + jobInfo = + new JobInfo.Builder( + ScheduledJobIds.VVM_NOTIFICATION_JOB, + new ComponentName(context, VoicemailNotificationJobService.class)) + .addTriggerContentUri( + new JobInfo.TriggerContentUri( + VoicemailContract.Voicemails.CONTENT_URI, + JobInfo.TriggerContentUri.FLAG_NOTIFY_FOR_DESCENDANTS)) + .setTriggerContentMaxDelay(0) + .build(); + } + + return jobInfo; + } +} -- cgit v1.2.3