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