1/*
2 * Copyright (C) 2015 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.server.telecom.testapps;
18
19import android.content.BroadcastReceiver;
20import android.content.Context;
21import android.content.Intent;
22import android.telecom.TelecomManager;
23import android.util.Log;
24
25/**
26 * Test in call service broadcast receiver.
27 */
28public class TestInCallServiceBroadcastReceiver extends BroadcastReceiver {
29    private static final String TAG = "TestInCallServiceBR";
30
31    /**
32     * Sends an upgrade to video request for any live calls.
33     */
34    public static final String ACTION_SEND_UPDATE_REQUEST_FROM_TEST_INCALL_SERVICE =
35            "android.server.telecom.testapps.ACTION_SEND_UPDATE_REQUEST_FROM_TEST_INCALL_SERVICE";
36
37    /**
38     * Sends an a response to an upgrade to video request.
39     */
40    public static final String ACTION_SEND_UPGRADE_RESPONSE =
41            "android.server.telecom.testapps.ACTION_SEND_UPGRADE_RESPONSE";
42
43    /**
44     * Handles broadcasts directed at the {@link TestInCallServiceImpl}.
45     *
46     * @param context The Context in which the receiver is running.
47     * @param intent  The Intent being received.
48     */
49    @Override
50    public void onReceive(Context context, Intent intent) {
51        String action = intent.getAction();
52        Log.v(TAG, "onReceive: " + action);
53
54        if (ACTION_SEND_UPDATE_REQUEST_FROM_TEST_INCALL_SERVICE.equals(action)) {
55            final int videoState = Integer.parseInt(intent.getData().getSchemeSpecificPart());
56            TestCallList.getInstance().sendUpgradeToVideoRequest(videoState);
57        } else if (ACTION_SEND_UPGRADE_RESPONSE.equals(action)) {
58            final int videoState = Integer.parseInt(intent.getData().getSchemeSpecificPart());
59            TestCallList.getInstance().sendUpgradeToVideoResponse(videoState);
60        } else if (TelecomManager.ACTION_PHONE_ACCOUNT_REGISTERED.equals(action)) {
61            Log.i(TAG, "onReceive: registered " + intent.getExtras().get(
62                    TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE));
63        } else if (TelecomManager.ACTION_PHONE_ACCOUNT_UNREGISTERED.equals(action)) {
64            Log.i(TAG, "onReceive: unregistered " + intent.getExtras().get(
65                    TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE));
66        }
67    }
68}
69