1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.voicemail.impl.sync; 18 19 import android.content.Context; 20 import android.content.Intent; 21 import android.os.Bundle; 22 import android.telecom.PhoneAccountHandle; 23 import com.android.dialer.logging.DialerImpression; 24 import com.android.dialer.proguard.UsedByReflection; 25 import com.android.voicemail.impl.Voicemail; 26 import com.android.voicemail.impl.VoicemailStatus; 27 import com.android.voicemail.impl.scheduling.BaseTask; 28 import com.android.voicemail.impl.scheduling.RetryPolicy; 29 import com.android.voicemail.impl.utils.LoggerUtils; 30 31 /** 32 * Task to download a single voicemail from the server. This task is initiated by a SMS notifying 33 * the new voicemail arrival, and ignores the duplicated tasks constraint. 34 */ 35 @UsedByReflection(value = "Tasks.java") 36 public class SyncOneTask extends BaseTask { 37 38 private static final int RETRY_TIMES = 2; 39 private static final int RETRY_INTERVAL_MILLIS = 5_000; 40 41 private static final String EXTRA_PHONE_ACCOUNT_HANDLE = "extra_phone_account_handle"; 42 private static final String EXTRA_VOICEMAIL = "extra_voicemail"; 43 44 private PhoneAccountHandle phone; 45 private Voicemail voicemail; 46 start(Context context, PhoneAccountHandle phone, Voicemail voicemail)47 public static void start(Context context, PhoneAccountHandle phone, Voicemail voicemail) { 48 Intent intent = BaseTask.createIntent(context, SyncOneTask.class, phone); 49 intent.putExtra(EXTRA_PHONE_ACCOUNT_HANDLE, phone); 50 intent.putExtra(EXTRA_VOICEMAIL, voicemail); 51 context.sendBroadcast(intent); 52 } 53 SyncOneTask()54 public SyncOneTask() { 55 super(TASK_ALLOW_DUPLICATES); 56 addPolicy(new RetryPolicy(RETRY_TIMES, RETRY_INTERVAL_MILLIS)); 57 } 58 59 @Override onCreate(Context context, Bundle extras)60 public void onCreate(Context context, Bundle extras) { 61 super.onCreate(context, extras); 62 phone = extras.getParcelable(EXTRA_PHONE_ACCOUNT_HANDLE); 63 voicemail = extras.getParcelable(EXTRA_VOICEMAIL); 64 } 65 66 @Override onExecuteInBackgroundThread()67 public void onExecuteInBackgroundThread() { 68 OmtpVvmSyncService service = new OmtpVvmSyncService(getContext()); 69 service.sync(this, phone, voicemail, VoicemailStatus.edit(getContext(), phone)); 70 } 71 72 @Override createRestartIntent()73 public Intent createRestartIntent() { 74 LoggerUtils.logImpressionOnMainThread(getContext(), DialerImpression.Type.VVM_AUTO_RETRY_SYNC); 75 Intent intent = super.createRestartIntent(); 76 intent.putExtra(EXTRA_PHONE_ACCOUNT_HANDLE, phone); 77 intent.putExtra(EXTRA_VOICEMAIL, voicemail); 78 return intent; 79 } 80 } 81