Skip to content
Browse files

Fix NPE

Bug: 5067161
Change-Id: I466d40fc1bffa01efc1205a47b3330ae6f30bc66
  • Loading branch information...
1 parent a2bb8e8 commit 9a1d6a1c6b303985fbe44a54bb2fa68f9b2d06aa Tadashi G. Takaoka committed with The Android Automerger Jul 22, 2011
Showing with 44 additions and 21 deletions.
  1. +44 −21 java/src/com/android/inputmethod/deprecated/VoiceProxy.java
View
65 java/src/com/android/inputmethod/deprecated/VoiceProxy.java
@@ -158,7 +158,10 @@ public void resetVoiceStates(boolean isPasswordText) {
}
public void flushVoiceInputLogs(boolean configurationChanged) {
- if (VOICE_INSTALLED && !configurationChanged) {
+ if (!VOICE_INSTALLED) {
+ return;
+ }
+ if (!configurationChanged) {
if (mAfterVoiceInput) {
mVoiceInput.flushAllTextModificationCounters();
mVoiceInput.logInputEnded();
@@ -301,6 +304,9 @@ public void onClick(View widget) {
}
public void showPunctuationHintIfNecessary() {
+ if (!VOICE_INSTALLED) {
+ return;
+ }
InputConnection ic = mService.getCurrentInputConnection();
if (!mImmediatelyAfterVoiceInput && mAfterVoiceInput && ic != null) {
if (mHints.showPunctuationHintIfNecessary(ic)) {
@@ -375,9 +381,6 @@ public boolean getAndResetIsShowingHint() {
}
private void revertVoiceInput() {
- if (!VOICE_INSTALLED) {
- return;
- }
InputConnection ic = mService.getCurrentInputConnection();
if (ic != null) ic.commitText("", 1);
mService.updateSuggestions();
@@ -394,7 +397,10 @@ public void commitVoiceInput() {
}
public boolean logAndRevertVoiceInput() {
- if (VOICE_INSTALLED && mVoiceInputHighlighted) {
+ if (!VOICE_INSTALLED) {
+ return false;
+ }
+ if (mVoiceInputHighlighted) {
mVoiceInput.incrementTextModificationDeleteCount(
mVoiceResults.candidates.get(0).toString().length());
revertVoiceInput();
@@ -505,7 +511,10 @@ public void handleSeparator() {
}
public void handleClose() {
- if (VOICE_INSTALLED & mRecognizing) {
+ if (!VOICE_INSTALLED) {
+ return;
+ }
+ if (mRecognizing) {
mVoiceInput.cancel();
}
}
@@ -553,6 +562,9 @@ public void handleVoiceResults(boolean capitalizeFirstWord) {
}
public void switchToRecognitionStatusView(final Configuration configuration) {
+ if (!VOICE_INSTALLED) {
+ return;
+ }
mHandler.post(new Runnable() {
@Override
public void run() {
@@ -597,6 +609,9 @@ public void run() {
}
private void switchToLastInputMethod() {
+ if (!VOICE_INSTALLED) {
+ return;
+ }
final IBinder token = mService.getWindow().getWindow().getAttributes().token;
new AsyncTask<Void, Void, Boolean>() {
@Override
@@ -662,14 +677,15 @@ private void reallyStartListening(boolean swipe) {
}
public void startListening(final boolean swipe, IBinder token) {
+ if (!VOICE_INSTALLED) {
+ return;
+ }
// TODO: remove swipe which is no longer used.
- if (VOICE_INSTALLED) {
- if (needsToShowWarningDialog()) {
- // Calls reallyStartListening if user clicks OK, does nothing if user clicks Cancel.
- showVoiceWarningDialog(swipe, token);
- } else {
- reallyStartListening(swipe);
- }
+ if (needsToShowWarningDialog()) {
+ // Calls reallyStartListening if user clicks OK, does nothing if user clicks Cancel.
+ showVoiceWarningDialog(swipe, token);
+ } else {
+ reallyStartListening(swipe);
}
}
@@ -704,17 +720,18 @@ public void loadSettings(EditorInfo attribute, SharedPreferences sp) {
mLocaleSupportedForVoiceInput = SubtypeSwitcher.getInstance().isVoiceSupported(
SubtypeSwitcher.getInstance().getInputLocaleStr());
- if (VOICE_INSTALLED) {
- final String voiceMode = sp.getString(PREF_VOICE_MODE,
- mService.getString(R.string.voice_mode_main));
- mVoiceButtonEnabled = !voiceMode.equals(mService.getString(R.string.voice_mode_off))
- && shouldShowVoiceButton(makeFieldContext(), attribute);
- mVoiceButtonOnPrimary = voiceMode.equals(mService.getString(R.string.voice_mode_main));
- }
+ final String voiceMode = sp.getString(PREF_VOICE_MODE,
+ mService.getString(R.string.voice_mode_main));
+ mVoiceButtonEnabled = !voiceMode.equals(mService.getString(R.string.voice_mode_off))
+ && shouldShowVoiceButton(makeFieldContext(), attribute);
+ mVoiceButtonOnPrimary = voiceMode.equals(mService.getString(R.string.voice_mode_main));
}
public void destroy() {
- if (VOICE_INSTALLED && mVoiceInput != null) {
+ if (!VOICE_INSTALLED) {
+ return;
+ }
+ if (mVoiceInput != null) {
mVoiceInput.destroy();
}
}
@@ -826,10 +843,16 @@ private VoiceInputWrapper() {
}
public void cancel() {
+ if (!VOICE_INSTALLED) {
+ return;
+ }
if (mVoiceInput != null) mVoiceInput.cancel();
}
public void reset() {
+ if (!VOICE_INSTALLED) {
+ return;
+ }
if (mVoiceInput != null) mVoiceInput.reset();
}
}

0 comments on commit 9a1d6a1

Please sign in to comment.
Something went wrong with that request. Please try again.