blob: c98de88527353422127d2deb9969be1711385452 [file] [log] [blame]
Santos Cordon3e3b5412013-12-16 17:33:45 -08001/*
2 * Copyright (C) 2013 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
17package com.android.telecomm;
18
19import android.content.BroadcastReceiver;
20import android.content.Context;
21import android.content.Intent;
Ben Giladc5b22692014-02-18 20:03:22 -080022import android.telecomm.CallServiceDescriptor;
Santos Cordon3e3b5412013-12-16 17:33:45 -080023import android.util.Log;
24
Santos Cordon657cdd82014-02-13 16:40:19 -080025import com.google.common.base.Strings;
26
Santos Cordon3e3b5412013-12-16 17:33:45 -080027/**
28 * Receiver for public intents relating to Telecomm.
29 */
30public class TelecommReceiver extends BroadcastReceiver {
Ben Giladdd8c6082013-12-30 14:44:08 -080031
Santos Cordon3e3b5412013-12-16 17:33:45 -080032 private static final String TAG = TelecommReceiver.class.getSimpleName();
33
34 /**
Santos Cordon657cdd82014-02-13 16:40:19 -080035 * Action used by call services to notify Telecomm that there is an incoming call. This intent
36 * starts the incoming call sequence which will ultimately connect to the call service described
37 * in the intent extras. A new call object along with the token (also provided in the intent
38 * extras) will ultimately be sent to the call service indicating that Telecomm has received its
39 * incoming call.
Ben Giladc5b22692014-02-18 20:03:22 -080040 * Extras used: {@link #EXTRA_CALL_SERVICE_DESCRIPTOR}, {@link #EXTRA_INCOMING_CALL_TOKEN}
Santos Cordon657cdd82014-02-13 16:40:19 -080041 * TODO(santoscordon): As this gets finalized, this should eventually move to TelecommConstants.
42 * TODO(santoscordon): Expose a new service like TelephonyManager for Telecomm and expose
43 * a method for incoming calls instead of forcing the call service to build and send an Intent.
Santos Cordon3e3b5412013-12-16 17:33:45 -080044 */
Santos Cordon657cdd82014-02-13 16:40:19 -080045 public static final String ACTION_INCOMING_CALL = "com.android.telecomm.INCOMING_CALL";
Santos Cordon3e3b5412013-12-16 17:33:45 -080046
47 /**
Ben Giladc5b22692014-02-18 20:03:22 -080048 * The {@link CallServiceDescriptor} describing the call service for an incoming call.
Santos Cordon3e3b5412013-12-16 17:33:45 -080049 */
Ben Giladc5b22692014-02-18 20:03:22 -080050 static final String EXTRA_CALL_SERVICE_DESCRIPTOR = "com.android.telecomm.CALL_SERVICE_DESCRIPTOR";
Santos Cordon3e3b5412013-12-16 17:33:45 -080051
52 /**
Santos Cordon657cdd82014-02-13 16:40:19 -080053 * A String-based token used to identify the incoming call. Telecomm will use this token when
54 * providing a call object to the call service so that the call service can map the call object
55 * with the appropriate incoming call. Telecomm does not use or manipulate this token in any
56 * way; it simply passes it through to the call service. Cannot be empty or null.
Santos Cordon3e3b5412013-12-16 17:33:45 -080057 */
Santos Cordon657cdd82014-02-13 16:40:19 -080058 static final String EXTRA_INCOMING_CALL_TOKEN = "com.android.telecomm.INCOMING_CALL_TOKEN";
Santos Cordon3e3b5412013-12-16 17:33:45 -080059
Ben Giladdd8c6082013-12-30 14:44:08 -080060 private CallsManager mCallsManager = CallsManager.getInstance();
61
Santos Cordon3e3b5412013-12-16 17:33:45 -080062 /** {@inheritDoc} */
63 @Override
64 public void onReceive(Context context, Intent intent) {
65 String action = intent.getAction();
Santos Cordon657cdd82014-02-13 16:40:19 -080066 if (ACTION_INCOMING_CALL.equals(action)) {
67 handleIncomingCall(intent);
Santos Cordon3e3b5412013-12-16 17:33:45 -080068 }
69 }
70
71 /**
Santos Cordon657cdd82014-02-13 16:40:19 -080072 * Notifies CallsManager that a call service has an incoming call and it should start the
73 * incoming call sequence.
Santos Cordon3e3b5412013-12-16 17:33:45 -080074 *
Santos Cordon657cdd82014-02-13 16:40:19 -080075 * @param intent The incoming call intent.
Santos Cordon3e3b5412013-12-16 17:33:45 -080076 */
Santos Cordon657cdd82014-02-13 16:40:19 -080077 private void handleIncomingCall(Intent intent) {
Ben Giladc5b22692014-02-18 20:03:22 -080078 CallServiceDescriptor descriptor = intent.getParcelableExtra(EXTRA_CALL_SERVICE_DESCRIPTOR);
79 if (descriptor == null) {
80 Log.w(TAG, "Rejecting incoming call due to null descriptor");
Santos Cordon3e3b5412013-12-16 17:33:45 -080081 return;
82 }
83
Ben Giladc5b22692014-02-18 20:03:22 -080084 String token = Strings.emptyToNull(intent.getStringExtra(EXTRA_INCOMING_CALL_TOKEN));
85 if (token == null) {
86 Log.w(TAG, "Rejecting incoming call due to null token");
87 }
88
Santos Cordon657cdd82014-02-13 16:40:19 -080089 // TODO(santoscordon): Notify CallsManager.
Santos Cordon3e3b5412013-12-16 17:33:45 -080090 }
91}