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