1 /* 2 * Copyright (C) 2013 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.services.telephony.common; 18 19 /** 20 * Container class for audio modes. 21 */ 22 public class AudioMode { 23 // These can be used as a bit mask 24 public static int EARPIECE = 0x00000001; 25 public static int BLUETOOTH = 0x00000002; 26 public static int WIRED_HEADSET = 0x00000004; 27 public static int SPEAKER = 0x00000008; 28 29 public static int WIRED_OR_EARPIECE = EARPIECE | WIRED_HEADSET; 30 public static int ALL_MODES = EARPIECE | BLUETOOTH | WIRED_HEADSET | SPEAKER; 31 32 public static String toString(int mode) { 33 if ((mode & ~ALL_MODES) != 0x0) { 34 return "UNKNOWN"; 35 } 36 37 StringBuffer buffer = new StringBuffer(); 38 if ((mode & EARPIECE) == EARPIECE) { 39 listAppend(buffer, "EARPIECE"); 40 } 41 if ((mode & BLUETOOTH) == BLUETOOTH) { 42 listAppend(buffer, "BLUETOOTH"); 43 } 44 if ((mode & WIRED_HEADSET) == WIRED_HEADSET) { 45 listAppend(buffer, "WIRED_HEADSET"); 46 } 47 if ((mode & SPEAKER) == SPEAKER) { 48 listAppend(buffer, "SPEAKER"); 49 } 50 51 return buffer.toString(); 52 } 53 54 private static void listAppend(StringBuffer buffer, String str) { 55 if (buffer.length() > 0) { 56 buffer.append(", "); 57 } 58 buffer.append(str); 59 } 60 } 61