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.proguard.UsedByReflection; 24 import com.android.voicemail.impl.VoicemailStatus; 25 import com.android.voicemail.impl.VvmLog; 26 import com.android.voicemail.impl.scheduling.BaseTask; 27 import com.android.voicemail.impl.scheduling.PostponePolicy; 28 29 /** 30 * Upload task triggered by database changes. Will wait until the database has been stable for 31 * {@link #POSTPONE_MILLIS} to execute. 32 */ 33 @UsedByReflection(value = "Tasks.java") 34 public class UploadTask extends BaseTask { 35 36 private static final String TAG = "VvmUploadTask"; 37 38 private static final int POSTPONE_MILLIS = 5_000; 39 40 public UploadTask() { 41 super(TASK_UPLOAD); 42 addPolicy(new PostponePolicy(POSTPONE_MILLIS)); 43 } 44 45 public static void start(Context context, PhoneAccountHandle phoneAccountHandle) { 46 Intent intent = BaseTask.createIntent(context, UploadTask.class, phoneAccountHandle); 47 context.sendBroadcast(intent); 48 } 49 50 @Override 51 public void onCreate(Context context, Bundle extras) { 52 super.onCreate(context, extras); 53 } 54 55 @Override 56 public void onExecuteInBackgroundThread() { 57 OmtpVvmSyncService service = new OmtpVvmSyncService(getContext()); 58 59 PhoneAccountHandle phoneAccountHandle = getPhoneAccountHandle(); 60 if (phoneAccountHandle == null) { 61 // This should never happen 62 VvmLog.e(TAG, "null phone account for phoneAccountHandle " + getPhoneAccountHandle()); 63 return; 64 } 65 service.sync( 66 this, 67 OmtpVvmSyncService.SYNC_UPLOAD_ONLY, 68 phoneAccountHandle, 69 null, 70 VoicemailStatus.edit(getContext(), phoneAccountHandle)); 71 } 72 } 73