FileDocCategorySizeDatePackage
ObscureSpeechDelegate.javaAPI DocAndroid 5.1 API3827Thu Mar 12 22:22:42 GMT 2015com.android.keyguard

ObscureSpeechDelegate

public class ObscureSpeechDelegate extends android.view.View.AccessibilityDelegate
Accessibility delegate that obscures speech for a view when the user has not turned on the "speak passwords" preference and is not listening through headphones.

Fields Summary
static boolean
sAnnouncedHeadset
Whether any client has announced the "headset" notification.
private final android.content.ContentResolver
mContentResolver
private final android.media.AudioManager
mAudioManager
Constructors Summary
public ObscureSpeechDelegate(android.content.Context context)


       
        mContentResolver = context.getContentResolver();
        mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    
Methods Summary
public voidonInitializeAccessibilityNodeInfo(android.view.View host, android.view.accessibility.AccessibilityNodeInfo info)

        super.onInitializeAccessibilityNodeInfo(host, info);

        if (shouldObscureSpeech()) {
            final Context ctx = host.getContext();
            info.setText(null);
            info.setContentDescription(
                    ctx.getString(R.string.keyboard_password_character_no_headset));
        }
    
public voidonPopulateAccessibilityEvent(android.view.View host, android.view.accessibility.AccessibilityEvent event)

        super.onPopulateAccessibilityEvent(host, event);

        if ((event.getEventType() != AccessibilityEvent.TYPE_ANNOUNCEMENT)
                && shouldObscureSpeech()) {
            event.getText().clear();
            event.setContentDescription(host.getContext().getString(
                    R.string.keyboard_password_character_no_headset));
        }
    
public voidsendAccessibilityEvent(android.view.View host, int eventType)

        super.sendAccessibilityEvent(host, eventType);

        // Play the "headset required" announcement the first time the user
        // places accessibility focus on a key.
        if ((eventType == AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED)
                && !sAnnouncedHeadset && shouldObscureSpeech()) {
            sAnnouncedHeadset = true;
            host.announceForAccessibility(host.getContext().getString(
                    R.string.keyboard_headset_required_to_hear_password));
        }
    
private booleanshouldObscureSpeech()

        // The user can optionally force speaking passwords.
        if (Settings.Secure.getIntForUser(mContentResolver,
                Settings.Secure.ACCESSIBILITY_SPEAK_PASSWORD, 0, UserHandle.USER_CURRENT) != 0) {
            return false;
        }

        // Always speak if the user is listening through headphones.
        if (mAudioManager.isWiredHeadsetOn() || mAudioManager.isBluetoothA2dpOn()) {
            return false;
        }

        // Don't speak since this key is used to type a password.
        return true;