• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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.google.android.car.kitchensink.bluetooth;
18 
19 import android.content.Intent;
20 import android.os.Binder;
21 import android.os.IBinder;
22 import android.os.Process;
23 import android.telecom.Call;
24 import android.telecom.InCallService;
25 import android.util.Log;
26 
27 /**
28  * Custom {@link InCallService} that allows Kitchen Sink to manage phone calls using the public
29  * Telecom APIs. See https://developer.android.com/reference/android/telecom/InCallService.
30  *
31  * <p> Kitchen Sink must be selected as the default phone app in order to manage phone calls.
32  */
33 public class InCallServiceImpl extends InCallService {
34     private static final String TAG = "InCallServiceImpl";
35     public static final String ACTION_LOCAL_BIND = "local_bind";
36 
37     @Override
onBind(Intent intent)38     public IBinder onBind(Intent intent) {
39         Log.d(TAG, "onBind: " + intent);
40         return ACTION_LOCAL_BIND.equals(intent.getAction())
41                 ? new LocalBinder()
42                 : super.onBind(intent);
43     }
44 
45     @Override
onUnbind(Intent intent)46     public boolean onUnbind(Intent intent) {
47         Log.d(TAG, "onUnbind, intent: " + intent);
48         if (ACTION_LOCAL_BIND.equals(intent.getAction())) {
49             return false;
50         }
51         return super.onUnbind(intent);
52     }
53 
54     @Override
onCallAdded(Call call)55     public void onCallAdded(Call call) {
56         super.onCallAdded(call);
57         Log.i(TAG, "Call" + call.toString() + " added");
58     }
59 
60     public class LocalBinder extends Binder {
getService()61         public InCallServiceImpl getService() {
62             if (getCallingPid() == Process.myPid()) {
63                 return InCallServiceImpl.this;
64             }
65             return null;
66         }
67     }
68 }
69