1 /* 2 * Copyright (C) 2006 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 17 package com.android.internal.telephony; 18 19 import android.telephony.TelephonyManager; 20 21 import com.android.internal.telephony.PhoneConstants; 22 23 public class PhoneConstantConversions { 24 /** 25 * Convert the {@link PhoneConstants.State} enum into the TelephonyManager.CALL_STATE_* 26 * constants for the public API. 27 */ convertCallState(PhoneConstants.State state)28 public static int convertCallState(PhoneConstants.State state) { 29 switch (state) { 30 case RINGING: 31 return TelephonyManager.CALL_STATE_RINGING; 32 case OFFHOOK: 33 return TelephonyManager.CALL_STATE_OFFHOOK; 34 default: 35 return TelephonyManager.CALL_STATE_IDLE; 36 } 37 } 38 39 /** 40 * Convert the TelephonyManager.CALL_STATE_* constants into the 41 * {@link PhoneConstants.State} enum for the public API. 42 */ convertCallState(int state)43 public static PhoneConstants.State convertCallState(int state) { 44 switch (state) { 45 case TelephonyManager.CALL_STATE_RINGING: 46 return PhoneConstants.State.RINGING; 47 case TelephonyManager.CALL_STATE_OFFHOOK: 48 return PhoneConstants.State.OFFHOOK; 49 default: 50 return PhoneConstants.State.IDLE; 51 } 52 } 53 54 /** 55 * Convert the {@link PhoneConstants.DataState} enum into the TelephonyManager.DATA_* constants 56 * for the public API. 57 */ convertDataState(PhoneConstants.DataState state)58 public static int convertDataState(PhoneConstants.DataState state) { 59 switch (state) { 60 case CONNECTING: 61 return TelephonyManager.DATA_CONNECTING; 62 case CONNECTED: 63 return TelephonyManager.DATA_CONNECTED; 64 case SUSPENDED: 65 return TelephonyManager.DATA_SUSPENDED; 66 case DISCONNECTING: 67 return TelephonyManager.DATA_DISCONNECTING; 68 default: 69 return TelephonyManager.DATA_DISCONNECTED; 70 } 71 } 72 73 /** 74 * Convert the TelephonyManager.DATA_* constants into {@link PhoneConstants.DataState} enum 75 * for the public API. 76 */ convertDataState(int state)77 public static PhoneConstants.DataState convertDataState(int state) { 78 switch (state) { 79 case TelephonyManager.DATA_CONNECTING: 80 return PhoneConstants.DataState.CONNECTING; 81 case TelephonyManager.DATA_CONNECTED: 82 return PhoneConstants.DataState.CONNECTED; 83 case TelephonyManager.DATA_SUSPENDED: 84 return PhoneConstants.DataState.SUSPENDED; 85 case TelephonyManager.DATA_DISCONNECTING: 86 return PhoneConstants.DataState.DISCONNECTING; 87 default: 88 return PhoneConstants.DataState.DISCONNECTED; 89 } 90 } 91 } 92