16a6e769af983b973a67cff3e8926597525835aa9Ihab Awad/*
26a6e769af983b973a67cff3e8926597525835aa9Ihab Awad * Copyright (C) 2014 The Android Open Source Project
36a6e769af983b973a67cff3e8926597525835aa9Ihab Awad *
46a6e769af983b973a67cff3e8926597525835aa9Ihab Awad * Licensed under the Apache License, Version 2.0 (the "License");
56a6e769af983b973a67cff3e8926597525835aa9Ihab Awad * you may not use this file except in compliance with the License.
66a6e769af983b973a67cff3e8926597525835aa9Ihab Awad * You may obtain a copy of the License at
76a6e769af983b973a67cff3e8926597525835aa9Ihab Awad *
86a6e769af983b973a67cff3e8926597525835aa9Ihab Awad *      http://www.apache.org/licenses/LICENSE-2.0
96a6e769af983b973a67cff3e8926597525835aa9Ihab Awad *
106a6e769af983b973a67cff3e8926597525835aa9Ihab Awad * Unless required by applicable law or agreed to in writing, software
116a6e769af983b973a67cff3e8926597525835aa9Ihab Awad * distributed under the License is distributed on an "AS IS" BASIS,
126a6e769af983b973a67cff3e8926597525835aa9Ihab Awad * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
136a6e769af983b973a67cff3e8926597525835aa9Ihab Awad * See the License for the specific language governing permissions and
146a6e769af983b973a67cff3e8926597525835aa9Ihab Awad * limitations under the License.
156a6e769af983b973a67cff3e8926597525835aa9Ihab Awad */
166a6e769af983b973a67cff3e8926597525835aa9Ihab Awad
176a6e769af983b973a67cff3e8926597525835aa9Ihab Awadpackage com.android.services.telephony;
186a6e769af983b973a67cff3e8926597525835aa9Ihab Awad
194d45d1cf58a2003378fd35912d6d73a00001bf06Tyler Gunnimport android.telecom.PhoneCapabilities;
20f64d8ca4278e0bfb3afd9023058f86dfc8e92ff6Sailesh Nepal
21de3635ab336e469c2799b4947de582040f5b4c47Santos Cordonimport com.android.internal.telephony.CallStateException;
226a6e769af983b973a67cff3e8926597525835aa9Ihab Awadimport com.android.internal.telephony.Connection;
236a6e769af983b973a67cff3e8926597525835aa9Ihab Awad
246a6e769af983b973a67cff3e8926597525835aa9Ihab Awad/**
256a6e769af983b973a67cff3e8926597525835aa9Ihab Awad * Manages a single phone call handled by GSM.
266a6e769af983b973a67cff3e8926597525835aa9Ihab Awad */
273199aa7f8bcb48569eb8289abc055ba0f8496ba8Sailesh Nepalfinal class GsmConnection extends TelephonyConnection {
283199aa7f8bcb48569eb8289abc055ba0f8496ba8Sailesh Nepal    GsmConnection(Connection connection) {
293199aa7f8bcb48569eb8289abc055ba0f8496ba8Sailesh Nepal        super(connection);
306a6e769af983b973a67cff3e8926597525835aa9Ihab Awad    }
316a6e769af983b973a67cff3e8926597525835aa9Ihab Awad
326a6e769af983b973a67cff3e8926597525835aa9Ihab Awad    /** {@inheritDoc} */
336a6e769af983b973a67cff3e8926597525835aa9Ihab Awad    @Override
34ab777070da7e83983739414f1222177c6aeebe1aSantos Cordon    public void onPlayDtmfTone(char digit) {
353199aa7f8bcb48569eb8289abc055ba0f8496ba8Sailesh Nepal        if (getPhone() != null) {
363199aa7f8bcb48569eb8289abc055ba0f8496ba8Sailesh Nepal            getPhone().startDtmf(digit);
373199aa7f8bcb48569eb8289abc055ba0f8496ba8Sailesh Nepal        }
386a6e769af983b973a67cff3e8926597525835aa9Ihab Awad    }
396a6e769af983b973a67cff3e8926597525835aa9Ihab Awad
406a6e769af983b973a67cff3e8926597525835aa9Ihab Awad    /** {@inheritDoc} */
416a6e769af983b973a67cff3e8926597525835aa9Ihab Awad    @Override
42ab777070da7e83983739414f1222177c6aeebe1aSantos Cordon    public void onStopDtmfTone() {
433199aa7f8bcb48569eb8289abc055ba0f8496ba8Sailesh Nepal        if (getPhone() != null) {
443199aa7f8bcb48569eb8289abc055ba0f8496ba8Sailesh Nepal            getPhone().stopDtmf();
453199aa7f8bcb48569eb8289abc055ba0f8496ba8Sailesh Nepal        }
466a6e769af983b973a67cff3e8926597525835aa9Ihab Awad    }
47de3635ab336e469c2799b4947de582040f5b4c47Santos Cordon
4853b84fe2dc796ef172d7c0f4b9bdc177cdeb0c0fSantos Cordon    @Override
4953b84fe2dc796ef172d7c0f4b9bdc177cdeb0c0fSantos Cordon    public void performConference(TelephonyConnection otherConnection) {
503199aa7f8bcb48569eb8289abc055ba0f8496ba8Sailesh Nepal        Log.d(this, "performConference - %s", this);
513199aa7f8bcb48569eb8289abc055ba0f8496ba8Sailesh Nepal        if (getPhone() != null) {
523199aa7f8bcb48569eb8289abc055ba0f8496ba8Sailesh Nepal            try {
5353b84fe2dc796ef172d7c0f4b9bdc177cdeb0c0fSantos Cordon                // We dont use the "other" connection because there is no concept of that in the
5453b84fe2dc796ef172d7c0f4b9bdc177cdeb0c0fSantos Cordon                // implementation of calls inside telephony. Basically, you can "conference" and it
5553b84fe2dc796ef172d7c0f4b9bdc177cdeb0c0fSantos Cordon                // will conference with the background call.  We know that otherConnection is the
5653b84fe2dc796ef172d7c0f4b9bdc177cdeb0c0fSantos Cordon                // background call because it would never have called setConferenceableConnections()
5753b84fe2dc796ef172d7c0f4b9bdc177cdeb0c0fSantos Cordon                // otherwise.
583199aa7f8bcb48569eb8289abc055ba0f8496ba8Sailesh Nepal                getPhone().conference();
593199aa7f8bcb48569eb8289abc055ba0f8496ba8Sailesh Nepal            } catch (CallStateException e) {
603199aa7f8bcb48569eb8289abc055ba0f8496ba8Sailesh Nepal                Log.e(this, e, "Failed to conference call.");
613199aa7f8bcb48569eb8289abc055ba0f8496ba8Sailesh Nepal            }
62de3635ab336e469c2799b4947de582040f5b4c47Santos Cordon        }
63de3635ab336e469c2799b4947de582040f5b4c47Santos Cordon    }
64f64d8ca4278e0bfb3afd9023058f86dfc8e92ff6Sailesh Nepal
65f64d8ca4278e0bfb3afd9023058f86dfc8e92ff6Sailesh Nepal    @Override
66f64d8ca4278e0bfb3afd9023058f86dfc8e92ff6Sailesh Nepal    protected int buildCallCapabilities() {
6776f3b4ec8d9bcb8926db1b3e4fb2d1e969b09fbbIhab Awad        int capabilities = PhoneCapabilities.MUTE | PhoneCapabilities.SUPPORT_HOLD;
6876f3b4ec8d9bcb8926db1b3e4fb2d1e969b09fbbIhab Awad        if (getState() == STATE_ACTIVE || getState() == STATE_HOLDING) {
6976f3b4ec8d9bcb8926db1b3e4fb2d1e969b09fbbIhab Awad            capabilities |= PhoneCapabilities.HOLD;
70f64d8ca4278e0bfb3afd9023058f86dfc8e92ff6Sailesh Nepal        }
71f64d8ca4278e0bfb3afd9023058f86dfc8e92ff6Sailesh Nepal        return capabilities;
72f64d8ca4278e0bfb3afd9023058f86dfc8e92ff6Sailesh Nepal    }
733199aa7f8bcb48569eb8289abc055ba0f8496ba8Sailesh Nepal
743199aa7f8bcb48569eb8289abc055ba0f8496ba8Sailesh Nepal    @Override
753199aa7f8bcb48569eb8289abc055ba0f8496ba8Sailesh Nepal    void onRemovedFromCallService() {
763199aa7f8bcb48569eb8289abc055ba0f8496ba8Sailesh Nepal        super.onRemovedFromCallService();
773199aa7f8bcb48569eb8289abc055ba0f8496ba8Sailesh Nepal    }
786a6e769af983b973a67cff3e8926597525835aa9Ihab Awad}
79