• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 android.telecom.Voicemail;
23 import com.android.phone.VoicemailStatus;
24 import com.android.phone.vvm.omtp.scheduling.BaseTask;
25 import com.android.phone.vvm.omtp.scheduling.RetryPolicy;
26 import com.android.phone.vvm.omtp.utils.PhoneAccountHandleConverter;
27 
28 /**
29  * Task to download a single voicemail from the server. This task is initiated by a SMS notifying
30  * the new voicemail arrival, and ignores the duplicated tasks constraint.
31  */
32 public class SyncOneTask extends BaseTask {
33 
34     private static final int RETRY_TIMES = 2;
35     private static final int RETRY_INTERVAL_MILLIS = 5_000;
36 
37     private static final String EXTRA_PHONE_ACCOUNT_HANDLE = "extra_phone_account_handle";
38     private static final String EXTRA_SYNC_TYPE = "extra_sync_type";
39     private static final String EXTRA_VOICEMAIL = "extra_voicemail";
40 
41     private PhoneAccountHandle mPhone;
42     private String mSyncType;
43     private Voicemail mVoicemail;
44 
start(Context context, PhoneAccountHandle phone, Voicemail voicemail)45     public static void start(Context context, PhoneAccountHandle phone, Voicemail voicemail) {
46         Intent intent = BaseTask
47                 .createIntent(context, SyncOneTask.class,
48                         PhoneAccountHandleConverter.toSubId(phone));
49         intent.putExtra(EXTRA_PHONE_ACCOUNT_HANDLE, phone);
50         intent.putExtra(EXTRA_SYNC_TYPE, OmtpVvmSyncService.SYNC_DOWNLOAD_ONE_TRANSCRIPTION);
51         intent.putExtra(EXTRA_VOICEMAIL, voicemail);
52         context.startService(intent);
53     }
54 
SyncOneTask()55     public SyncOneTask() {
56         super(TASK_ALLOW_DUPLICATES);
57         addPolicy(new RetryPolicy(RETRY_TIMES, RETRY_INTERVAL_MILLIS));
58     }
59 
onCreate(Context context, Intent intent, int flags, int startId)60     public void onCreate(Context context, Intent intent, int flags, int startId) {
61         super.onCreate(context, intent, flags, startId);
62         mPhone = intent.getParcelableExtra(EXTRA_PHONE_ACCOUNT_HANDLE);
63         mSyncType = intent.getStringExtra(EXTRA_SYNC_TYPE);
64         mVoicemail = intent.getParcelableExtra(EXTRA_VOICEMAIL);
65     }
66 
67     @Override
onExecuteInBackgroundThread()68     public void onExecuteInBackgroundThread() {
69         OmtpVvmSyncService service = new OmtpVvmSyncService(getContext());
70         service.sync(this, mSyncType, mPhone, mVoicemail,
71                 VoicemailStatus.edit(getContext(), mPhone));
72     }
73 
74     @Override
createRestartIntent()75     public Intent createRestartIntent() {
76         Intent intent = super.createRestartIntent();
77         intent.putExtra(EXTRA_PHONE_ACCOUNT_HANDLE, mPhone);
78         intent.putExtra(EXTRA_SYNC_TYPE, mSyncType);
79         intent.putExtra(EXTRA_VOICEMAIL, mVoicemail);
80         return intent;
81     }
82 
83 }
84