blob: 9ed0fa7ae772d344d37bbd06eecbd6e41004227a [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
30 /** Used to identify log entries by this class. */
Santos Cordon3e3b5412013-12-16 17:33:45 -080031 private static final String TAG = TelecommReceiver.class.getSimpleName();
32
33 /**
34 * Action used as a request for CallsManager to connect with the CallService described in the
35 * extras of this intent.
36 * Extras used: {@link #EXTRA_PACKAGE_NAME}, {@link #EXTRA_CALL_SERVICE_ID}
37 * TODO(santoscordon): As this gets finalized, it should eventually move to a public location.
38 * This would normally go into TelephonyManager.java but we are avoiding more additions to that
39 * file so this may require a new container or it could go into framework's Intent.java.
40 */
41 public static final String ACTION_CONNECT_CALL_SERVICE =
42 "com.android.telecomm.CONNECT_CALL_SERVICE";
43
44 /**
45 * The package name of the {@link ICallServiceProvider} used to get the {@link CallService}.
46 */
Ben Giladdd8c6082013-12-30 14:44:08 -080047 static final String EXTRA_PACKAGE_NAME = "com.android.telecomm.PACKAGE_NAME";
Santos Cordon3e3b5412013-12-16 17:33:45 -080048
49 /**
50 * The CallService ID used to identify the {@link CallService} via {@link ICallServiceProvider}.
51 * IDs are only required to be unique within the scope of an {@link ICallServiceProvider}.
52 */
Ben Giladdd8c6082013-12-30 14:44:08 -080053 static final String EXTRA_CALL_SERVICE_ID =
Santos Cordon3e3b5412013-12-16 17:33:45 -080054 "com.android.telecomm.CALL_SERVICE_ID";
55
Ben Giladdd8c6082013-12-30 14:44:08 -080056 private CallsManager mCallsManager = CallsManager.getInstance();
57
Santos Cordon3e3b5412013-12-16 17:33:45 -080058 /** {@inheritDoc} */
59 @Override
60 public void onReceive(Context context, Intent intent) {
61 String action = intent.getAction();
62 if (ACTION_CONNECT_CALL_SERVICE.equals(action)) {
63 connectToCallService(intent);
64 }
65 }
66
67 /**
68 * Tells CallsManager to connect to the {@link #CallService} identified by the package name
Ben Giladdd8c6082013-12-30 14:44:08 -080069 * and call-service ID in the extras of the intent parameter.
Santos Cordon3e3b5412013-12-16 17:33:45 -080070 *
Ben Giladdd8c6082013-12-30 14:44:08 -080071 * @param intent The intent containing the package name and call-service ID as extras.
Santos Cordon3e3b5412013-12-16 17:33:45 -080072 */
73 private void connectToCallService(Intent intent) {
74 String packageName = intent.getStringExtra(EXTRA_PACKAGE_NAME);
75 String callServiceId = intent.getStringExtra(EXTRA_CALL_SERVICE_ID);
76 if (TextUtils.isEmpty(packageName) || TextUtils.isEmpty(callServiceId)) {
77 Log.w(TAG, "Rejecting request to connect to call service due to lack of data."
Evan Charltonf5a56c92013-12-19 09:23:48 -080078 + " packageName: [" + packageName + "]"
Santos Cordon3e3b5412013-12-16 17:33:45 -080079 + ", callServiceId: [" + callServiceId + "]");
80 return;
81 }
82
83 // TODO(santoscordon): Use packageName and callServiceId to connect with the CallService.
84 }
85}