blob: 4863c2496429f948a9465d13e15de454f16eeb7c [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 {
Ben Giladdd8c6082013-12-30 14:44:08 -080029
Santos Cordon3e3b5412013-12-16 17:33:45 -080030 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 Giladdd8c6082013-12-30 14:44:08 -080046 static final String EXTRA_PACKAGE_NAME = "com.android.telecomm.PACKAGE_NAME";
Santos Cordon3e3b5412013-12-16 17:33:45 -080047
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 Giladdd8c6082013-12-30 14:44:08 -080052 static final String EXTRA_CALL_SERVICE_ID =
Santos Cordon3e3b5412013-12-16 17:33:45 -080053 "com.android.telecomm.CALL_SERVICE_ID";
54
Ben Giladdd8c6082013-12-30 14:44:08 -080055 private CallsManager mCallsManager = CallsManager.getInstance();
56
Santos Cordon3e3b5412013-12-16 17:33:45 -080057 /** {@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 Giladdd8c6082013-12-30 14:44:08 -080068 * and call-service ID in the extras of the intent parameter.
Santos Cordon3e3b5412013-12-16 17:33:45 -080069 *
Ben Giladdd8c6082013-12-30 14:44:08 -080070 * @param intent The intent containing the package name and call-service ID as extras.
Santos Cordon3e3b5412013-12-16 17:33:45 -080071 */
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 Charltonf5a56c92013-12-19 09:23:48 -080077 + " packageName: [" + packageName + "]"
Santos Cordon3e3b5412013-12-16 17:33:45 -080078 + ", callServiceId: [" + callServiceId + "]");
79 return;
80 }
81
82 // TODO(santoscordon): Use packageName and callServiceId to connect with the CallService.
83 }
84}