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; |
| 22 | import android.text.TextUtils; |
| 23 | import android.util.Log; |
| 24 | |
| 25 | /** |
| 26 | * Receiver for public intents relating to Telecomm. |
| 27 | */ |
| 28 | public class TelecommReceiver extends BroadcastReceiver { |
Ben Gilad | dd8c608 | 2013-12-30 14:44:08 -0800 | [diff] [blame] | 29 | |
Santos Cordon | 3e3b541 | 2013-12-16 17:33:45 -0800 | [diff] [blame] | 30 | private static final String TAG = TelecommReceiver.class.getSimpleName(); |
| 31 | |
| 32 | /** |
| 33 | * Action used as a request for CallsManager to connect with the CallService described in the |
| 34 | * extras of this intent. |
| 35 | * Extras used: {@link #EXTRA_PACKAGE_NAME}, {@link #EXTRA_CALL_SERVICE_ID} |
| 36 | * TODO(santoscordon): As this gets finalized, it should eventually move to a public location. |
| 37 | * This would normally go into TelephonyManager.java but we are avoiding more additions to that |
| 38 | * file so this may require a new container or it could go into framework's Intent.java. |
| 39 | */ |
| 40 | public static final String ACTION_CONNECT_CALL_SERVICE = |
| 41 | "com.android.telecomm.CONNECT_CALL_SERVICE"; |
| 42 | |
| 43 | /** |
| 44 | * The package name of the {@link ICallServiceProvider} used to get the {@link CallService}. |
| 45 | */ |
Ben Gilad | dd8c608 | 2013-12-30 14:44:08 -0800 | [diff] [blame] | 46 | static final String EXTRA_PACKAGE_NAME = "com.android.telecomm.PACKAGE_NAME"; |
Santos Cordon | 3e3b541 | 2013-12-16 17:33:45 -0800 | [diff] [blame] | 47 | |
| 48 | /** |
| 49 | * The CallService ID used to identify the {@link CallService} via {@link ICallServiceProvider}. |
| 50 | * IDs are only required to be unique within the scope of an {@link ICallServiceProvider}. |
| 51 | */ |
Ben Gilad | dd8c608 | 2013-12-30 14:44:08 -0800 | [diff] [blame] | 52 | static final String EXTRA_CALL_SERVICE_ID = |
Santos Cordon | 3e3b541 | 2013-12-16 17:33:45 -0800 | [diff] [blame] | 53 | "com.android.telecomm.CALL_SERVICE_ID"; |
| 54 | |
Ben Gilad | dd8c608 | 2013-12-30 14:44:08 -0800 | [diff] [blame] | 55 | private CallsManager mCallsManager = CallsManager.getInstance(); |
| 56 | |
Santos Cordon | 3e3b541 | 2013-12-16 17:33:45 -0800 | [diff] [blame] | 57 | /** {@inheritDoc} */ |
| 58 | @Override |
| 59 | public void onReceive(Context context, Intent intent) { |
| 60 | String action = intent.getAction(); |
| 61 | if (ACTION_CONNECT_CALL_SERVICE.equals(action)) { |
| 62 | connectToCallService(intent); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Tells CallsManager to connect to the {@link #CallService} identified by the package name |
Ben Gilad | dd8c608 | 2013-12-30 14:44:08 -0800 | [diff] [blame] | 68 | * and call-service ID in the extras of the intent parameter. |
Santos Cordon | 3e3b541 | 2013-12-16 17:33:45 -0800 | [diff] [blame] | 69 | * |
Ben Gilad | dd8c608 | 2013-12-30 14:44:08 -0800 | [diff] [blame] | 70 | * @param intent The intent containing the package name and call-service ID as extras. |
Santos Cordon | 3e3b541 | 2013-12-16 17:33:45 -0800 | [diff] [blame] | 71 | */ |
| 72 | private void connectToCallService(Intent intent) { |
| 73 | String packageName = intent.getStringExtra(EXTRA_PACKAGE_NAME); |
| 74 | String callServiceId = intent.getStringExtra(EXTRA_CALL_SERVICE_ID); |
| 75 | if (TextUtils.isEmpty(packageName) || TextUtils.isEmpty(callServiceId)) { |
| 76 | Log.w(TAG, "Rejecting request to connect to call service due to lack of data." |
Evan Charlton | f5a56c9 | 2013-12-19 09:23:48 -0800 | [diff] [blame] | 77 | + " packageName: [" + packageName + "]" |
Santos Cordon | 3e3b541 | 2013-12-16 17:33:45 -0800 | [diff] [blame] | 78 | + ", callServiceId: [" + callServiceId + "]"); |
| 79 | return; |
| 80 | } |
| 81 | |
| 82 | // TODO(santoscordon): Use packageName and callServiceId to connect with the CallService. |
| 83 | } |
| 84 | } |