• 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.server.telecom.testapps;
18 
19 import android.os.Bundle;
20 import android.telecom.Connection;
21 import android.telecom.ConnectionRequest;
22 import android.telecom.ConnectionService;
23 import android.telecom.Log;
24 import android.telecom.PhoneAccountHandle;
25 import android.telecom.TelecomManager;
26 import android.telecom.VideoProfile;
27 
28 import java.util.Objects;
29 import java.util.Random;
30 
31 /**
32  * Sample implementation of the self-managed {@link ConnectionService} API.
33  * <p>
34  * See {@link android.telecom} for more information on self-managed {@link ConnectionService}s.
35  */
36 public class SelfManagedConnectionService extends ConnectionService {
37     private static final String[] TEST_NAMES = {"Tom Smith", "Jane Appleseed", "Joseph Engleton",
38             "Claudia McPherson", "Chris P. Bacon", "Seymour Butz", "Hugh Mungus", "Anita Bath"};
39     private final SelfManagedCallList mCallList = SelfManagedCallList.getInstance();
40 
41     @Override
onCreateOutgoingConnection( PhoneAccountHandle connectionManagerAccount, final ConnectionRequest request)42     public Connection onCreateOutgoingConnection(
43             PhoneAccountHandle connectionManagerAccount,
44             final ConnectionRequest request) {
45 
46         return createSelfManagedConnection(request, false);
47     }
48 
49     @Override
onCreateIncomingConnection(PhoneAccountHandle connectionManagerPhoneAccount, ConnectionRequest request)50     public Connection onCreateIncomingConnection(PhoneAccountHandle connectionManagerPhoneAccount,
51             ConnectionRequest request) {
52         return createSelfManagedConnection(request, true);
53     }
54 
55     @Override
onCreateIncomingConnectionFailed(PhoneAccountHandle connectionManagerPhoneAccount, ConnectionRequest request)56     public void onCreateIncomingConnectionFailed(PhoneAccountHandle connectionManagerPhoneAccount,
57                                                  ConnectionRequest request) {
58         mCallList.notifyCreateIncomingConnectionFailed(request);
59     }
60 
61     @Override
onCreateOutgoingConnectionFailed(PhoneAccountHandle connectionManagerPhoneAccount, ConnectionRequest request)62     public void onCreateOutgoingConnectionFailed(PhoneAccountHandle connectionManagerPhoneAccount,
63                                                  ConnectionRequest request) {
64         mCallList.notifyCreateOutgoingConnectionFailed(request);
65     }
66 
createSelfManagedConnection(ConnectionRequest request, boolean isIncoming)67     private Connection createSelfManagedConnection(ConnectionRequest request, boolean isIncoming) {
68         SelfManagedConnection connection = new SelfManagedConnection(mCallList,
69                 getApplicationContext(), isIncoming);
70         connection.setListener(mCallList.getConnectionListener());
71         connection.setConnectionProperties(Connection.PROPERTY_SELF_MANAGED);
72         connection.setAddress(request.getAddress(), TelecomManager.PRESENTATION_ALLOWED);
73         connection.setAudioModeIsVoip(true);
74         connection.setVideoState(request.getVideoState());
75         Random random = new Random();
76         connection.setCallerDisplayName(TEST_NAMES[random.nextInt(TEST_NAMES.length)],
77                 TelecomManager.PRESENTATION_ALLOWED);
78         connection.setExtras(request.getExtras());
79         if (isIncoming) {
80             connection.setIsIncomingCallUiShowing(request.shouldShowIncomingCallUi());
81         }
82 
83         // Track the phone account handle which created this connection so we can distinguish them
84         // in the sample call list later.
85         Bundle moreExtras = new Bundle();
86         moreExtras.putParcelable(SelfManagedConnection.EXTRA_PHONE_ACCOUNT_HANDLE,
87                 request.getAccountHandle());
88         connection.putExtras(moreExtras);
89         connection.setVideoState(request.getVideoState());
90         Log.i(this, "createSelfManagedConnection %s", connection);
91         mCallList.addConnection(connection);
92         return connection;
93     }
94 }
95