Santos Cordon | 3e3b541 | 2013-12-16 17:33:45 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.telecomm; |
| 18 | |
| 19 | import android.content.BroadcastReceiver; |
| 20 | import android.content.Context; |
| 21 | import android.content.Intent; |
Ben Gilad | c5b2269 | 2014-02-18 20:03:22 -0800 | [diff] [blame] | 22 | import android.telecomm.CallServiceDescriptor; |
Santos Cordon | 3e3b541 | 2013-12-16 17:33:45 -0800 | [diff] [blame] | 23 | import android.util.Log; |
| 24 | |
Santos Cordon | 657cdd8 | 2014-02-13 16:40:19 -0800 | [diff] [blame] | 25 | import com.google.common.base.Strings; |
| 26 | |
Santos Cordon | 3e3b541 | 2013-12-16 17:33:45 -0800 | [diff] [blame] | 27 | /** |
| 28 | * Receiver for public intents relating to Telecomm. |
Ben Gilad | ebd9b66 | 2014-02-19 16:03:44 -0800 | [diff] [blame^] | 29 | * |
| 30 | * TODO(gilad): Unify the incoming/outgoing approach to use startActivity in both cases thereby |
| 31 | * eliminating the incoming logic below, as well as this class as a whole. |
Santos Cordon | 3e3b541 | 2013-12-16 17:33:45 -0800 | [diff] [blame] | 32 | */ |
| 33 | public class TelecommReceiver extends BroadcastReceiver { |
Ben Gilad | dd8c608 | 2013-12-30 14:44:08 -0800 | [diff] [blame] | 34 | |
Santos Cordon | 3e3b541 | 2013-12-16 17:33:45 -0800 | [diff] [blame] | 35 | private static final String TAG = TelecommReceiver.class.getSimpleName(); |
| 36 | |
| 37 | /** |
Santos Cordon | 657cdd8 | 2014-02-13 16:40:19 -0800 | [diff] [blame] | 38 | * Action used by call services to notify Telecomm that there is an incoming call. This intent |
| 39 | * starts the incoming call sequence which will ultimately connect to the call service described |
| 40 | * in the intent extras. A new call object along with the token (also provided in the intent |
| 41 | * extras) will ultimately be sent to the call service indicating that Telecomm has received its |
| 42 | * incoming call. |
Ben Gilad | c5b2269 | 2014-02-18 20:03:22 -0800 | [diff] [blame] | 43 | * Extras used: {@link #EXTRA_CALL_SERVICE_DESCRIPTOR}, {@link #EXTRA_INCOMING_CALL_TOKEN} |
Santos Cordon | 657cdd8 | 2014-02-13 16:40:19 -0800 | [diff] [blame] | 44 | * TODO(santoscordon): As this gets finalized, this should eventually move to TelecommConstants. |
| 45 | * TODO(santoscordon): Expose a new service like TelephonyManager for Telecomm and expose |
| 46 | * a method for incoming calls instead of forcing the call service to build and send an Intent. |
Santos Cordon | 3e3b541 | 2013-12-16 17:33:45 -0800 | [diff] [blame] | 47 | */ |
Santos Cordon | 657cdd8 | 2014-02-13 16:40:19 -0800 | [diff] [blame] | 48 | public static final String ACTION_INCOMING_CALL = "com.android.telecomm.INCOMING_CALL"; |
Santos Cordon | 3e3b541 | 2013-12-16 17:33:45 -0800 | [diff] [blame] | 49 | |
| 50 | /** |
Ben Gilad | c5b2269 | 2014-02-18 20:03:22 -0800 | [diff] [blame] | 51 | * The {@link CallServiceDescriptor} describing the call service for an incoming call. |
Santos Cordon | 3e3b541 | 2013-12-16 17:33:45 -0800 | [diff] [blame] | 52 | */ |
Ben Gilad | c5b2269 | 2014-02-18 20:03:22 -0800 | [diff] [blame] | 53 | static final String EXTRA_CALL_SERVICE_DESCRIPTOR = "com.android.telecomm.CALL_SERVICE_DESCRIPTOR"; |
Santos Cordon | 3e3b541 | 2013-12-16 17:33:45 -0800 | [diff] [blame] | 54 | |
| 55 | /** |
Santos Cordon | 657cdd8 | 2014-02-13 16:40:19 -0800 | [diff] [blame] | 56 | * A String-based token used to identify the incoming call. Telecomm will use this token when |
| 57 | * providing a call object to the call service so that the call service can map the call object |
| 58 | * with the appropriate incoming call. Telecomm does not use or manipulate this token in any |
| 59 | * way; it simply passes it through to the call service. Cannot be empty or null. |
Santos Cordon | 3e3b541 | 2013-12-16 17:33:45 -0800 | [diff] [blame] | 60 | */ |
Santos Cordon | 657cdd8 | 2014-02-13 16:40:19 -0800 | [diff] [blame] | 61 | static final String EXTRA_INCOMING_CALL_TOKEN = "com.android.telecomm.INCOMING_CALL_TOKEN"; |
Santos Cordon | 3e3b541 | 2013-12-16 17:33:45 -0800 | [diff] [blame] | 62 | |
Ben Gilad | dd8c608 | 2013-12-30 14:44:08 -0800 | [diff] [blame] | 63 | private CallsManager mCallsManager = CallsManager.getInstance(); |
| 64 | |
Santos Cordon | 3e3b541 | 2013-12-16 17:33:45 -0800 | [diff] [blame] | 65 | /** {@inheritDoc} */ |
| 66 | @Override |
| 67 | public void onReceive(Context context, Intent intent) { |
| 68 | String action = intent.getAction(); |
Santos Cordon | 657cdd8 | 2014-02-13 16:40:19 -0800 | [diff] [blame] | 69 | if (ACTION_INCOMING_CALL.equals(action)) { |
| 70 | handleIncomingCall(intent); |
Santos Cordon | 3e3b541 | 2013-12-16 17:33:45 -0800 | [diff] [blame] | 71 | } |
| 72 | } |
| 73 | |
| 74 | /** |
Santos Cordon | 657cdd8 | 2014-02-13 16:40:19 -0800 | [diff] [blame] | 75 | * Notifies CallsManager that a call service has an incoming call and it should start the |
| 76 | * incoming call sequence. |
Santos Cordon | 3e3b541 | 2013-12-16 17:33:45 -0800 | [diff] [blame] | 77 | * |
Santos Cordon | 657cdd8 | 2014-02-13 16:40:19 -0800 | [diff] [blame] | 78 | * @param intent The incoming call intent. |
Santos Cordon | 3e3b541 | 2013-12-16 17:33:45 -0800 | [diff] [blame] | 79 | */ |
Santos Cordon | 657cdd8 | 2014-02-13 16:40:19 -0800 | [diff] [blame] | 80 | private void handleIncomingCall(Intent intent) { |
Ben Gilad | c5b2269 | 2014-02-18 20:03:22 -0800 | [diff] [blame] | 81 | CallServiceDescriptor descriptor = intent.getParcelableExtra(EXTRA_CALL_SERVICE_DESCRIPTOR); |
| 82 | if (descriptor == null) { |
| 83 | Log.w(TAG, "Rejecting incoming call due to null descriptor"); |
Santos Cordon | 3e3b541 | 2013-12-16 17:33:45 -0800 | [diff] [blame] | 84 | return; |
| 85 | } |
| 86 | |
Ben Gilad | c5b2269 | 2014-02-18 20:03:22 -0800 | [diff] [blame] | 87 | String token = Strings.emptyToNull(intent.getStringExtra(EXTRA_INCOMING_CALL_TOKEN)); |
| 88 | if (token == null) { |
| 89 | Log.w(TAG, "Rejecting incoming call due to null token"); |
| 90 | } |
| 91 | |
Santos Cordon | 657cdd8 | 2014-02-13 16:40:19 -0800 | [diff] [blame] | 92 | // TODO(santoscordon): Notify CallsManager. |
Santos Cordon | 3e3b541 | 2013-12-16 17:33:45 -0800 | [diff] [blame] | 93 | } |
| 94 | } |