Merge "Remove AudioManagerCompatWrapper.java"

main
Ken Wakasa 2012-12-17 02:50:17 -08:00 committed by Android (Google) Code Review
commit e57e9fbd18
2 changed files with 11 additions and 71 deletions

View File

@ -32,7 +32,6 @@ import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityManager;
import android.view.inputmethod.EditorInfo;
import com.android.inputmethod.compat.AudioManagerCompatWrapper;
import com.android.inputmethod.compat.SettingsSecureCompatUtils;
import com.android.inputmethod.latin.InputTypeUtils;
import com.android.inputmethod.latin.R;
@ -40,14 +39,14 @@ import com.android.inputmethod.latin.R;
public final class AccessibilityUtils {
private static final String TAG = AccessibilityUtils.class.getSimpleName();
private static final String CLASS = AccessibilityUtils.class.getClass().getName();
private static final String PACKAGE = AccessibilityUtils.class.getClass().getPackage()
.getName();
private static final String PACKAGE =
AccessibilityUtils.class.getClass().getPackage().getName();
private static final AccessibilityUtils sInstance = new AccessibilityUtils();
private Context mContext;
private AccessibilityManager mAccessibilityManager;
private AudioManagerCompatWrapper mAudioManager;
private AudioManager mAudioManager;
/*
* Setting this constant to {@code false} will disable all keyboard
@ -57,8 +56,7 @@ public final class AccessibilityUtils {
private static final boolean ENABLE_ACCESSIBILITY = true;
public static void init(InputMethodService inputMethod) {
if (!ENABLE_ACCESSIBILITY)
return;
if (!ENABLE_ACCESSIBILITY) return;
// These only need to be initialized if the kill switch is off.
sInstance.initInternal(inputMethod);
@ -76,12 +74,9 @@ public final class AccessibilityUtils {
private void initInternal(Context context) {
mContext = context;
mAccessibilityManager = (AccessibilityManager) context
.getSystemService(Context.ACCESSIBILITY_SERVICE);
final AudioManager audioManager = (AudioManager) context
.getSystemService(Context.AUDIO_SERVICE);
mAudioManager = new AudioManagerCompatWrapper(audioManager);
mAccessibilityManager =
(AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE);
mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
}
/**
@ -120,20 +115,19 @@ public final class AccessibilityUtils {
* @return {@code true} if the device should obscure password characters.
*/
public boolean shouldObscureInput(EditorInfo editorInfo) {
if (editorInfo == null)
return false;
if (editorInfo == null) return false;
// The user can optionally force speaking passwords.
if (SettingsSecureCompatUtils.ACCESSIBILITY_SPEAK_PASSWORD != null) {
final boolean speakPassword = Settings.Secure.getInt(mContext.getContentResolver(),
SettingsSecureCompatUtils.ACCESSIBILITY_SPEAK_PASSWORD, 0) != 0;
if (speakPassword)
return false;
if (speakPassword) return false;
}
// Always speak if the user is listening through headphones.
if (mAudioManager.isWiredHeadsetOn() || mAudioManager.isBluetoothA2dpOn())
if (mAudioManager.isWiredHeadsetOn() || mAudioManager.isBluetoothA2dpOn()) {
return false;
}
// Don't speak if the IME is connected to a password field.
return InputTypeUtils.isPasswordInputType(editorInfo.inputType);

View File

@ -1,54 +0,0 @@
/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.inputmethod.compat;
import android.media.AudioManager;
import java.lang.reflect.Method;
public final class AudioManagerCompatWrapper {
private static final Method METHOD_isWiredHeadsetOn = CompatUtils.getMethod(
AudioManager.class, "isWiredHeadsetOn");
private static final Method METHOD_isBluetoothA2dpOn = CompatUtils.getMethod(
AudioManager.class, "isBluetoothA2dpOn");
private final AudioManager mManager;
public AudioManagerCompatWrapper(AudioManager manager) {
mManager = manager;
}
/**
* Checks whether audio routing to the wired headset is on or off.
*
* @return true if audio is being routed to/from wired headset;
* false if otherwise
*/
public boolean isWiredHeadsetOn() {
return (Boolean) CompatUtils.invoke(mManager, false, METHOD_isWiredHeadsetOn);
}
/**
* Checks whether A2DP audio routing to the Bluetooth headset is on or off.
*
* @return true if A2DP audio is being routed to/from Bluetooth headset;
* false if otherwise
*/
public boolean isBluetoothA2dpOn() {
return (Boolean) CompatUtils.invoke(mManager, false, METHOD_isBluetoothA2dpOn);
}
}