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.cts.verifier.voicemail; 18 19 import android.telecom.PhoneAccountHandle; 20 import android.telephony.VisualVoicemailService; 21 import android.telephony.VisualVoicemailSms; 22 23 /** 24 * Forwards {@link VisualVoicemailService} events to tests. The CTS Verifier app needs to be set to 25 * the default dialer for it to receive the events. 26 */ 27 public class CtsVisualVoicemailService extends VisualVoicemailService { 28 29 public abstract static class Callback { 30 onCellServiceConnected(VisualVoicemailTask task, PhoneAccountHandle phoneAccountHandle)31 public abstract void onCellServiceConnected(VisualVoicemailTask task, 32 PhoneAccountHandle phoneAccountHandle); 33 onSimRemoved(VisualVoicemailTask task, PhoneAccountHandle phoneAccountHandle)34 public abstract void onSimRemoved(VisualVoicemailTask task, 35 PhoneAccountHandle phoneAccountHandle); 36 } 37 38 private static Callback sCallback; 39 setCallback(Callback callback)40 public static void setCallback(Callback callback) { 41 sCallback = callback; 42 } 43 44 @Override onCellServiceConnected(VisualVoicemailTask task, PhoneAccountHandle phoneAccountHandle)45 public void onCellServiceConnected(VisualVoicemailTask task, 46 PhoneAccountHandle phoneAccountHandle) { 47 if (sCallback != null) { 48 sCallback.onCellServiceConnected(task, phoneAccountHandle); 49 } 50 task.finish(); 51 } 52 53 @Override onSmsReceived(VisualVoicemailTask task, VisualVoicemailSms sms)54 public void onSmsReceived(VisualVoicemailTask task, VisualVoicemailSms sms) { 55 task.finish(); 56 } 57 58 @Override onSimRemoved(VisualVoicemailTask task, PhoneAccountHandle phoneAccountHandle)59 public void onSimRemoved(VisualVoicemailTask task, PhoneAccountHandle phoneAccountHandle) { 60 if (sCallback != null) { 61 sCallback.onSimRemoved(task, phoneAccountHandle); 62 } 63 task.finish(); 64 } 65 66 @Override onStopped(VisualVoicemailTask task)67 public void onStopped(VisualVoicemailTask task) { 68 task.finish(); 69 } 70 } 71