15a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold/*
25a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold * Copyright (C) 2006 The Android Open Source Project
35a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold *
45a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold * Licensed under the Apache License, Version 2.0 (the "License");
55a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold * you may not use this file except in compliance with the License.
65a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold * You may obtain a copy of the License at
75a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold *
85a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold *      http://www.apache.org/licenses/LICENSE-2.0
95a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold *
105a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold * Unless required by applicable law or agreed to in writing, software
115a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold * distributed under the License is distributed on an "AS IS" BASIS,
125a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
135a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold * See the License for the specific language governing permissions and
145a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold * limitations under the License.
155a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold */
165a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold
175a0618ead121b258204c19b97c37cb85d4ad0856Nathan Haroldpackage com.android.internal.telephony;
185a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold
195a0618ead121b258204c19b97c37cb85d4ad0856Nathan Haroldimport android.telephony.ServiceState;
205a0618ead121b258204c19b97c37cb85d4ad0856Nathan Haroldimport android.telephony.TelephonyManager;
215a0618ead121b258204c19b97c37cb85d4ad0856Nathan Haroldimport android.telephony.PreciseCallState;
225a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold
235a0618ead121b258204c19b97c37cb85d4ad0856Nathan Haroldimport com.android.internal.telephony.PhoneConstants;
245a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold
255a0618ead121b258204c19b97c37cb85d4ad0856Nathan Haroldimport java.util.List;
265a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold
275a0618ead121b258204c19b97c37cb85d4ad0856Nathan Haroldpublic class PhoneConstantConversions {
285a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold    /**
295a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold     * Convert the {@link PhoneConstants.State} enum into the TelephonyManager.CALL_STATE_*
305a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold     * constants for the public API.
315a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold     */
325a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold    public static int convertCallState(PhoneConstants.State state) {
335a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold        switch (state) {
345a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold            case RINGING:
355a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold                return TelephonyManager.CALL_STATE_RINGING;
365a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold            case OFFHOOK:
375a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold                return TelephonyManager.CALL_STATE_OFFHOOK;
385a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold            default:
395a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold                return TelephonyManager.CALL_STATE_IDLE;
405a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold        }
415a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold    }
425a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold
435a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold    /**
445a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold     * Convert the TelephonyManager.CALL_STATE_* constants into the
455a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold     * {@link PhoneConstants.State} enum for the public API.
465a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold     */
475a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold    public static PhoneConstants.State convertCallState(int state) {
485a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold        switch (state) {
495a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold            case TelephonyManager.CALL_STATE_RINGING:
505a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold                return PhoneConstants.State.RINGING;
515a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold            case TelephonyManager.CALL_STATE_OFFHOOK:
525a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold                return PhoneConstants.State.OFFHOOK;
535a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold            default:
545a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold                return PhoneConstants.State.IDLE;
555a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold        }
565a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold    }
575a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold
585a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold    /**
595a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold     * Convert the {@link PhoneConstants.DataState} enum into the TelephonyManager.DATA_* constants
605a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold     * for the public API.
615a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold     */
625a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold    public static int convertDataState(PhoneConstants.DataState state) {
635a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold        switch (state) {
645a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold            case CONNECTING:
655a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold                return TelephonyManager.DATA_CONNECTING;
665a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold            case CONNECTED:
675a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold                return TelephonyManager.DATA_CONNECTED;
685a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold            case SUSPENDED:
695a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold                return TelephonyManager.DATA_SUSPENDED;
705a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold            default:
715a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold                return TelephonyManager.DATA_DISCONNECTED;
725a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold        }
735a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold    }
745a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold
755a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold    /**
765a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold     * Convert the TelephonyManager.DATA_* constants into {@link PhoneConstants.DataState} enum
775a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold     * for the public API.
785a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold     */
795a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold    public static PhoneConstants.DataState convertDataState(int state) {
805a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold        switch (state) {
815a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold            case TelephonyManager.DATA_CONNECTING:
825a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold                return PhoneConstants.DataState.CONNECTING;
835a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold            case TelephonyManager.DATA_CONNECTED:
845a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold                return PhoneConstants.DataState.CONNECTED;
855a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold            case TelephonyManager.DATA_SUSPENDED:
865a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold                return PhoneConstants.DataState.SUSPENDED;
875a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold            default:
885a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold                return PhoneConstants.DataState.DISCONNECTED;
895a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold        }
905a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold    }
915a0618ead121b258204c19b97c37cb85d4ad0856Nathan Harold}
92