| /* |
| * Copyright (C) 2017 The Android Open Source Project |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License |
| */ |
| |
| package com.android.server.telecom.testapps; |
| |
| import android.os.Bundle; |
| import android.telecom.Connection; |
| import android.telecom.ConnectionRequest; |
| import android.telecom.ConnectionService; |
| import android.telecom.Log; |
| import android.telecom.PhoneAccountHandle; |
| import android.telecom.TelecomManager; |
| |
| import java.util.Objects; |
| |
| /** |
| * Sample implementation of the self-managed {@link ConnectionService} API. |
| * <p> |
| * See {@link android.telecom} for more information on self-managed {@link ConnectionService}s. |
| */ |
| public class SelfManagedConnectionService extends ConnectionService { |
| private final SelfManagedCallList mCallList = SelfManagedCallList.getInstance(); |
| |
| @Override |
| public Connection onCreateOutgoingConnection( |
| PhoneAccountHandle connectionManagerAccount, |
| final ConnectionRequest request) { |
| |
| return createSelfManagedConnection(request, false); |
| } |
| |
| @Override |
| public Connection onCreateIncomingConnection(PhoneAccountHandle connectionManagerPhoneAccount, |
| ConnectionRequest request) { |
| return createSelfManagedConnection(request, true); |
| } |
| |
| @Override |
| public void onCreateIncomingConnectionFailed(ConnectionRequest request) { |
| mCallList.notifyCreateIncomingConnectionFailed(request); |
| } |
| |
| @Override |
| public void onCreateOutgoingConnectionFailed(ConnectionRequest request) { |
| mCallList.notifyCreateOutgoingConnectionFailed(request); |
| } |
| |
| |
| private Connection createSelfManagedConnection(ConnectionRequest request, boolean isIncoming) { |
| SelfManagedConnection connection = new SelfManagedConnection(mCallList, |
| getApplicationContext(), isIncoming); |
| connection.setConnectionProperties(Connection.PROPERTY_SELF_MANAGED); |
| connection.setAddress(request.getAddress(), TelecomManager.PRESENTATION_ALLOWED); |
| connection.setExtras(request.getExtras()); |
| if (isIncoming) { |
| connection.setIsIncomingCallUiShowing(request.shouldShowIncomingCallUi()); |
| } |
| |
| // Track the phone account handle which created this connection so we can distinguish them |
| // in the sample call list later. |
| Bundle moreExtras = new Bundle(); |
| moreExtras.putParcelable(SelfManagedConnection.EXTRA_PHONE_ACCOUNT_HANDLE, |
| request.getAccountHandle()); |
| connection.putExtras(moreExtras); |
| connection.setVideoState(request.getVideoState()); |
| Log.i(this, "createSelfManagedConnection %s", connection); |
| mCallList.addConnection(connection); |
| return connection; |
| } |
| } |