1 /* 2 * Copyright (C) 2018 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.telecom.cts.thirdptyincallservice; 18 19 import static android.content.pm.PackageManager.PERMISSION_GRANTED; 20 21 import android.app.Service; 22 import android.content.Intent; 23 import android.os.IBinder; 24 import android.util.Log; 25 26 public class CtsThirdPartyInCallServiceControl extends Service { 27 28 private static final String TAG = CtsThirdPartyInCallServiceControl.class.getSimpleName(); 29 public static final String CONTROL_INTERFACE_ACTION = 30 "android.telecom.cts.thirdptyincallservice.ACTION_THIRDPTY_CTRL"; 31 32 private final IBinder mCtsCompanionAppControl = new ICtsThirdPartyInCallServiceControl.Stub() { 33 34 @Override 35 public boolean checkBindStatus(boolean bind) { 36 return CtsThirdPartyInCallService.checkBindStatus(bind); 37 } 38 39 @Override 40 public int getLocalCallCount() { 41 return CtsThirdPartyInCallService.getLocalCallCount(); 42 } 43 44 @Override 45 public void resetLatchForServiceBound(boolean bind) { 46 CtsThirdPartyInCallService.resetLatchForServiceBound(bind); 47 } 48 49 @Override 50 public void resetCalls() { 51 CtsThirdPartyInCallService.resetCalls(); 52 } 53 54 @Override 55 public boolean checkPermissionGrant(String permission) { 56 return getPackageManager().checkPermission(permission 57 , getApplication().getPackageName()) == PERMISSION_GRANTED; 58 } 59 60 @Override 61 public void setExpectedExtra(String newKey, String newValue) { 62 CtsThirdPartyInCallService.getInstance().setExpectedExtra(newKey, newValue); 63 } 64 65 @Override 66 public boolean waitUntilExpectedExtrasReceived() { 67 return CtsThirdPartyInCallService.getInstance().waitForExtrasChanged(); 68 } 69 }; 70 71 @Override onBind(Intent intent)72 public IBinder onBind(Intent intent) { 73 if (CONTROL_INTERFACE_ACTION.equals(intent.getAction())) { 74 Log.d(TAG, "onBind: return control interface."); 75 return mCtsCompanionAppControl; 76 } 77 Log.d(TAG, "onBind: invalid intent."); 78 return null; 79 } 80 81 } 82