1 /* 2 * Copyright (C) 2011 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.inputmethod.compat; 18 19 import android.media.AudioManager; 20 21 import java.lang.reflect.Method; 22 23 public final class AudioManagerCompatWrapper { 24 private static final Method METHOD_isWiredHeadsetOn = CompatUtils.getMethod( 25 AudioManager.class, "isWiredHeadsetOn"); 26 private static final Method METHOD_isBluetoothA2dpOn = CompatUtils.getMethod( 27 AudioManager.class, "isBluetoothA2dpOn"); 28 29 private final AudioManager mManager; 30 AudioManagerCompatWrapper(AudioManager manager)31 public AudioManagerCompatWrapper(AudioManager manager) { 32 mManager = manager; 33 } 34 35 /** 36 * Checks whether audio routing to the wired headset is on or off. 37 * 38 * @return true if audio is being routed to/from wired headset; 39 * false if otherwise 40 */ isWiredHeadsetOn()41 public boolean isWiredHeadsetOn() { 42 return (Boolean) CompatUtils.invoke(mManager, false, METHOD_isWiredHeadsetOn); 43 } 44 45 /** 46 * Checks whether A2DP audio routing to the Bluetooth headset is on or off. 47 * 48 * @return true if A2DP audio is being routed to/from Bluetooth headset; 49 * false if otherwise 50 */ isBluetoothA2dpOn()51 public boolean isBluetoothA2dpOn() { 52 return (Boolean) CompatUtils.invoke(mManager, false, METHOD_isBluetoothA2dpOn); 53 } 54 } 55