• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.content.Intent;
20 import android.os.IBinder;
21 import android.telecom.InCallService;
22 import java.util.Observable;
23 import android.telecom.Call;
24 
25 import com.android.cts.verifier.telecom.CtsIncomingCall;
26 import com.android.cts.verifier.telecom.CtsVerifierInCallUi;
27 
28 public class DialerCallTestService extends InCallService {
29   public static final String EXTRA_CALL_NAME = "incoming_call_name";
30 
31   private static DialerCallTestServiceObservable sObservable =
32       new DialerCallTestServiceObservable();
33 
34   @Override
onBind(Intent intent)35   public IBinder onBind(Intent intent) {
36     return super.onBind(intent);
37   }
38 
getObservable()39   public static DialerCallTestServiceObservable getObservable() {
40     return sObservable;
41   }
42 
43   public static class DialerCallTestServiceObservable extends Observable {
44     private boolean onIncoming;
45 
setOnIncoming(boolean value)46     public void setOnIncoming(boolean value) {
47       this.onIncoming = value;
48       setChanged();
49       notifyObservers(value);
50     }
51 
getOnIncoming()52     public boolean getOnIncoming() {
53       return this.onIncoming;
54     }
55   }
56 
57   @Override
onCallAdded(Call call)58   public void onCallAdded(Call call) {
59     if (call.getState() == Call.STATE_RINGING) {
60       getObservable().setOnIncoming(true);
61       CtsIncomingCall.getInstance().setCall(call);
62       Intent intent = new Intent(Intent.ACTION_MAIN);
63       if (call.getDetails().getHandle() != null) {
64         intent.putExtra(EXTRA_CALL_NAME, call.getDetails().getHandle().getSchemeSpecificPart());
65       }
66       intent.setFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION | Intent.FLAG_ACTIVITY_NEW_TASK);
67       intent.setClass(this, CtsVerifierInCallUi.class);
68       startActivity(intent);
69     }
70   }
71 }
72