1/*
2 * Copyright (C) 2014 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.services.telephony;
18
19import com.android.internal.telephony.Connection;
20
21/**
22 * Manages a single phone call handled by GSM.
23 */
24final class GsmConnection extends TelephonyConnection {
25    GsmConnection(Connection connection, String telecomCallId) {
26        super(connection, telecomCallId);
27    }
28
29    /**
30     * Clones the current {@link GsmConnection}.
31     * <p>
32     * Listeners are not copied to the new instance.
33     *
34     * @return The cloned connection.
35     */
36    @Override
37    public TelephonyConnection cloneConnection() {
38        GsmConnection gsmConnection = new GsmConnection(getOriginalConnection(),
39                getTelecomCallId());
40        return gsmConnection;
41    }
42
43    /** {@inheritDoc} */
44    @Override
45    public void onPlayDtmfTone(char digit) {
46        if (getPhone() != null) {
47            getPhone().startDtmf(digit);
48        }
49    }
50
51    /** {@inheritDoc} */
52    @Override
53    public void onStopDtmfTone() {
54        if (getPhone() != null) {
55            getPhone().stopDtmf();
56        }
57    }
58
59    @Override
60    protected int buildConnectionProperties() {
61        int properties = super.buildConnectionProperties();
62        // PROPERTY_IS_DOWNGRADED_CONFERENCE is permanent on GSM connections -- once it is set, it
63        // should be retained.
64        if ((getConnectionProperties() & PROPERTY_IS_DOWNGRADED_CONFERENCE) != 0) {
65            properties |= PROPERTY_IS_DOWNGRADED_CONFERENCE;
66        }
67        return properties;
68    }
69
70    @Override
71    protected int buildConnectionCapabilities() {
72        int capabilities = super.buildConnectionCapabilities();
73        capabilities |= CAPABILITY_MUTE;
74        // Overwrites TelephonyConnection.buildConnectionCapabilities() and resets the hold options
75        // because all GSM calls should hold, even if the carrier config option is set to not show
76        // hold for IMS calls.
77        if (!shouldTreatAsEmergencyCall()) {
78            capabilities |= CAPABILITY_SUPPORT_HOLD;
79            if (getState() == STATE_ACTIVE || getState() == STATE_HOLDING) {
80                capabilities |= CAPABILITY_HOLD;
81            }
82        }
83
84        // For GSM connections, CAPABILITY_CONFERENCE_HAS_NO_CHILDREN should be applied whenever
85        // PROPERTY_IS_DOWNGRADED_CONFERENCE is true.
86        if ((getConnectionProperties() & PROPERTY_IS_DOWNGRADED_CONFERENCE) != 0) {
87            capabilities |= CAPABILITY_CONFERENCE_HAS_NO_CHILDREN;
88        }
89
90        return capabilities;
91    }
92
93    @Override
94    void onRemovedFromCallService() {
95        super.onRemovedFromCallService();
96    }
97}
98