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 android.telephony.cts;
18 
19 import android.os.Bundle;
20 import android.telecom.PhoneAccountHandle;
21 import android.telephony.VisualVoicemailService;
22 import android.telephony.VisualVoicemailSms;
23 
24 import java.util.concurrent.CompletableFuture;
25 
26 /**
27  * A mock {@link VisualVoicemailService} that the tests can set callbacks
28  */
29 public class MockVisualVoicemailService extends VisualVoicemailService {
30 
31     private static CompletableFuture<VisualVoicemailSms> sSmsFuture;
32 
setSmsFuture(CompletableFuture<VisualVoicemailSms> future)33     public static void setSmsFuture(CompletableFuture<VisualVoicemailSms> future) {
34         sSmsFuture = future;
35     }
36 
37     @Override
onCellServiceConnected(VisualVoicemailTask task, PhoneAccountHandle phoneAccountHandle)38     public void onCellServiceConnected(VisualVoicemailTask task,
39             PhoneAccountHandle phoneAccountHandle) {
40         // Do nothing, cannot be tested by automatic CTS
41     }
42 
43     @Override
onSmsReceived(VisualVoicemailTask task, VisualVoicemailSms sms)44     public void onSmsReceived(VisualVoicemailTask task, VisualVoicemailSms sms) {
45         if (sSmsFuture != null) {
46             sSmsFuture.complete(sms);
47         }
48     }
49 
50     @Override
onSimRemoved(VisualVoicemailTask task, PhoneAccountHandle phoneAccountHandle)51     public void onSimRemoved(VisualVoicemailTask task, PhoneAccountHandle phoneAccountHandle) {
52         // Do nothing, cannot be tested by automatic CTS
53     }
54 
55     @Override
onStopped(VisualVoicemailTask task)56     public void onStopped(VisualVoicemailTask task) {
57         // TODO(twyen): test after task timeout is implemented.
58     }
59 }
60