1 /*
2  * Copyright (C) 2017 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.dialer;
18 
19 import android.os.Bundle;
20 import android.view.View;
21 import android.widget.ImageView;
22 import android.widget.TextView;
23 import com.android.cts.verifier.PassFailButtons;
24 import com.android.cts.verifier.R;
25 import com.android.cts.verifier.voicemail.DefaultDialerChanger;
26 import java.util.Observable;
27 import java.util.Observer;
28 
29 /** Tests that a third party dialer will receive incoming calls. */
30 public class DialerIncomingCallTestActivity extends PassFailButtons.Activity implements Observer {
31 
32   private DefaultDialerChanger mDefaultDialerChanger;
33   private ImageView mDialerIncomingCallStatusIcon;
34   private TextView mDialerIncomingCallInstructions;
35 
36   @Override
onCreate(Bundle savedInstanceState)37   protected void onCreate(Bundle savedInstanceState) {
38     super.onCreate(savedInstanceState);
39     View view = getLayoutInflater().inflate(R.layout.dialer_incoming_call, null);
40     setContentView(view);
41     setInfoResources(
42         R.string.dialer_incoming_call_test, R.string.dialer_incoming_call_test_instructions, -1);
43     setPassFailButtonClickListeners();
44     mDialerIncomingCallStatusIcon = (ImageView) findViewById(R.id.dialer_incoming_call_status);
45     mDialerIncomingCallInstructions =
46         (TextView) findViewById(R.id.dialer_check_incoming_call_explanation);
47 
48     getPassButton().setEnabled(false);
49     DialerCallTestService.getObservable().addObserver(this);
50     mDefaultDialerChanger = new DefaultDialerChanger(this);
51   }
52 
53   @Override
update(Observable observable, Object data)54   public void update(Observable observable, Object data) {
55     if (DialerCallTestService.getObservable().getOnIncoming()) {
56       getPassButton().setEnabled(true);
57       mDialerIncomingCallStatusIcon.setImageDrawable(getDrawable(R.drawable.fs_good));
58       mDialerIncomingCallInstructions.setText(R.string.dialer_incoming_call_detected);
59       mDefaultDialerChanger.setRestorePending(true);
60     }
61   }
62 
63   @Override
onDestroy()64   protected void onDestroy() {
65     mDefaultDialerChanger.destroy();
66     DialerCallTestService.getObservable().deleteObserver(this);
67     super.onDestroy();
68   }
69 }
70