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