• 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 com.android.phone.vvm.omtp.scheduling.BaseTask;
23 import com.android.phone.vvm.omtp.scheduling.MinimalIntervalPolicy;
24 import com.android.phone.vvm.omtp.scheduling.RetryPolicy;
25 import com.android.phone.vvm.omtp.utils.PhoneAccountHandleConverter;
26 
27 /**
28  * System initiated sync request.
29  */
30 public class SyncTask extends BaseTask {
31 
32     // Try sync for a total of 5 times, should take around 5 minutes before finally giving up.
33     private static final int RETRY_TIMES = 4;
34     private static final int RETRY_INTERVAL_MILLIS = 5_000;
35     private static final int MINIMAL_INTERVAL_MILLIS = 60_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 
40     private final RetryPolicy mRetryPolicy;
41 
42     private PhoneAccountHandle mPhone;
43     private String mSyncType;
44 
start(Context context, PhoneAccountHandle phone, String syncType)45     public static void start(Context context, PhoneAccountHandle phone, String syncType) {
46         Intent intent = BaseTask
47                 .createIntent(context, SyncTask.class, PhoneAccountHandleConverter.toSubId(phone));
48         intent.putExtra(EXTRA_PHONE_ACCOUNT_HANDLE, phone);
49         intent.putExtra(EXTRA_SYNC_TYPE, syncType);
50         context.startService(intent);
51     }
52 
SyncTask()53     public SyncTask() {
54         super(TASK_SYNC);
55         mRetryPolicy = new RetryPolicy(RETRY_TIMES, RETRY_INTERVAL_MILLIS);
56         addPolicy(mRetryPolicy);
57         addPolicy(new MinimalIntervalPolicy(MINIMAL_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     }
65 
66     @Override
onExecuteInBackgroundThread()67     public void onExecuteInBackgroundThread() {
68         OmtpVvmSyncService service = new OmtpVvmSyncService(getContext());
69         service.sync(this, mSyncType, mPhone, null, mRetryPolicy.getVoicemailStatusEditor());
70     }
71 
72     @Override
createRestartIntent()73     public Intent createRestartIntent() {
74         Intent intent = super.createRestartIntent();
75         intent.putExtra(EXTRA_PHONE_ACCOUNT_HANDLE, mPhone);
76         intent.putExtra(EXTRA_SYNC_TYPE, mSyncType);
77         return intent;
78     }
79 }
80