remove references to Gservices from LatinIME
Open-sourced platform code shouldn't refer to Gservices. Use the platform-standard Secure settings table instead (which we can still push values into from the servers on google-experience devices, like gservices), but can be populated by other mechanisms for non-ged phones. Change-Id: Id0b5830bfc78c1d10dc732dce46546cd09cd1422main
parent
b1cd701602
commit
a16ff1b19e
|
@ -5,7 +5,6 @@
|
||||||
<uses-permission android:name="android.permission.READ_USER_DICTIONARY" />
|
<uses-permission android:name="android.permission.READ_USER_DICTIONARY" />
|
||||||
<uses-permission android:name="android.permission.WRITE_USER_DICTIONARY" />
|
<uses-permission android:name="android.permission.WRITE_USER_DICTIONARY" />
|
||||||
<uses-permission android:name="android.permission.BACKUP_DATA" />
|
<uses-permission android:name="android.permission.BACKUP_DATA" />
|
||||||
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
|
|
||||||
|
|
||||||
<application android:label="@string/english_ime_name"
|
<application android:label="@string/english_ime_name"
|
||||||
android:backupAgent="LatinIMEBackupAgent"
|
android:backupAgent="LatinIMEBackupAgent"
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
package com.android.inputmethod.latin;
|
package com.android.inputmethod.latin;
|
||||||
|
|
||||||
import com.android.inputmethod.voice.GoogleSettingsUtil;
|
import com.android.inputmethod.voice.SettingsUtil;
|
||||||
|
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
@ -68,13 +68,13 @@ public class Hints {
|
||||||
mDisplay = display;
|
mDisplay = display;
|
||||||
|
|
||||||
ContentResolver cr = mContext.getContentResolver();
|
ContentResolver cr = mContext.getContentResolver();
|
||||||
mSwipeHintMaxDaysToShow = GoogleSettingsUtil.getGservicesInt(
|
mSwipeHintMaxDaysToShow = SettingsUtil.getSettingsInt(
|
||||||
cr,
|
cr,
|
||||||
GoogleSettingsUtil.LATIN_IME_VOICE_INPUT_SWIPE_HINT_MAX_DAYS,
|
SettingsUtil.LATIN_IME_VOICE_INPUT_SWIPE_HINT_MAX_DAYS,
|
||||||
DEFAULT_SWIPE_HINT_MAX_DAYS_TO_SHOW);
|
DEFAULT_SWIPE_HINT_MAX_DAYS_TO_SHOW);
|
||||||
mPunctuationHintMaxDisplays = GoogleSettingsUtil.getGservicesInt(
|
mPunctuationHintMaxDisplays = SettingsUtil.getSettingsInt(
|
||||||
cr,
|
cr,
|
||||||
GoogleSettingsUtil.LATIN_IME_VOICE_INPUT_PUNCTUATION_HINT_MAX_DISPLAYS,
|
SettingsUtil.LATIN_IME_VOICE_INPUT_PUNCTUATION_HINT_MAX_DISPLAYS,
|
||||||
DEFAULT_PUNCTUATION_HINT_MAX_DISPLAYS);
|
DEFAULT_PUNCTUATION_HINT_MAX_DISPLAYS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -60,7 +60,7 @@ import android.view.inputmethod.InputMethodManager;
|
||||||
|
|
||||||
import com.android.inputmethod.voice.EditingUtil;
|
import com.android.inputmethod.voice.EditingUtil;
|
||||||
import com.android.inputmethod.voice.FieldContext;
|
import com.android.inputmethod.voice.FieldContext;
|
||||||
import com.android.inputmethod.voice.GoogleSettingsUtil;
|
import com.android.inputmethod.voice.SettingsUtil;
|
||||||
import com.android.inputmethod.voice.VoiceInput;
|
import com.android.inputmethod.voice.VoiceInput;
|
||||||
|
|
||||||
import java.io.FileDescriptor;
|
import java.io.FileDescriptor;
|
||||||
|
@ -1706,9 +1706,9 @@ public class LatinIME extends InputMethodService
|
||||||
// input. Because this method is called by onStartInputView, this should mean that as
|
// input. Because this method is called by onStartInputView, this should mean that as
|
||||||
// long as the locale doesn't change while the user is keeping the IME open, the
|
// long as the locale doesn't change while the user is keeping the IME open, the
|
||||||
// value should never be stale.
|
// value should never be stale.
|
||||||
String supportedLocalesString = GoogleSettingsUtil.getGservicesString(
|
String supportedLocalesString = SettingsUtil.getSettingsString(
|
||||||
getContentResolver(),
|
getContentResolver(),
|
||||||
GoogleSettingsUtil.LATIN_IME_VOICE_INPUT_SUPPORTED_LOCALES,
|
SettingsUtil.LATIN_IME_VOICE_INPUT_SUPPORTED_LOCALES,
|
||||||
DEFAULT_VOICE_INPUT_SUPPORTED_LOCALES);
|
DEFAULT_VOICE_INPUT_SUPPORTED_LOCALES);
|
||||||
ArrayList<String> voiceInputSupportedLocales =
|
ArrayList<String> voiceInputSupportedLocales =
|
||||||
Lists.newArrayList(supportedLocalesString.split("\\s+"));
|
Lists.newArrayList(supportedLocalesString.split("\\s+"));
|
||||||
|
|
|
@ -33,7 +33,7 @@ import android.util.Log;
|
||||||
|
|
||||||
import com.google.android.collect.Lists;
|
import com.google.android.collect.Lists;
|
||||||
|
|
||||||
import com.android.inputmethod.voice.GoogleSettingsUtil;
|
import com.android.inputmethod.voice.SettingsUtil;
|
||||||
import com.android.inputmethod.voice.VoiceInputLogger;
|
import com.android.inputmethod.voice.VoiceInputLogger;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -148,9 +148,9 @@ public class LatinIMESettings extends PreferenceActivity
|
||||||
// Get the current list of supported locales and check the current locale against
|
// Get the current list of supported locales and check the current locale against
|
||||||
// that list, to decide whether to put a warning that voice input will not work in
|
// that list, to decide whether to put a warning that voice input will not work in
|
||||||
// the current language as part of the pop-up confirmation dialog.
|
// the current language as part of the pop-up confirmation dialog.
|
||||||
String supportedLocalesString = GoogleSettingsUtil.getGservicesString(
|
String supportedLocalesString = SettingsUtil.getSettingsString(
|
||||||
getContentResolver(),
|
getContentResolver(),
|
||||||
GoogleSettingsUtil.LATIN_IME_VOICE_INPUT_SUPPORTED_LOCALES,
|
SettingsUtil.LATIN_IME_VOICE_INPUT_SUPPORTED_LOCALES,
|
||||||
LatinIME.DEFAULT_VOICE_INPUT_SUPPORTED_LOCALES);
|
LatinIME.DEFAULT_VOICE_INPUT_SUPPORTED_LOCALES);
|
||||||
ArrayList<String> voiceInputSupportedLocales =
|
ArrayList<String> voiceInputSupportedLocales =
|
||||||
Lists.newArrayList(supportedLocalesString.split("\\s+"));
|
Lists.newArrayList(supportedLocalesString.split("\\s+"));
|
||||||
|
|
|
@ -36,7 +36,7 @@ import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.android.inputmethod.latin.R;
|
import com.android.inputmethod.latin.R;
|
||||||
import com.android.inputmethod.voice.GoogleSettingsUtil;
|
import com.android.inputmethod.voice.SettingsUtil;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
@ -112,10 +112,10 @@ public class RecognitionView {
|
||||||
mView = inflater.inflate(R.layout.recognition_status, null);
|
mView = inflater.inflate(R.layout.recognition_status, null);
|
||||||
|
|
||||||
ContentResolver cr = context.getContentResolver();
|
ContentResolver cr = context.getContentResolver();
|
||||||
mMinMicrophoneLevel = GoogleSettingsUtil.getGservicesFloat(
|
mMinMicrophoneLevel = SettingsUtil.getSettingsFloat(
|
||||||
cr, GoogleSettingsUtil.LATIN_IME_MIN_MICROPHONE_LEVEL, 15.f);
|
cr, SettingsUtil.LATIN_IME_MIN_MICROPHONE_LEVEL, 15.f);
|
||||||
mMaxMicrophoneLevel = GoogleSettingsUtil.getGservicesFloat(
|
mMaxMicrophoneLevel = SettingsUtil.getSettingsFloat(
|
||||||
cr, GoogleSettingsUtil.LATIN_IME_MAX_MICROPHONE_LEVEL, 30.f);
|
cr, SettingsUtil.LATIN_IME_MAX_MICROPHONE_LEVEL, 30.f);
|
||||||
|
|
||||||
// Pre-load volume level images
|
// Pre-load volume level images
|
||||||
Resources r = context.getResources();
|
Resources r = context.getResources();
|
||||||
|
|
|
@ -19,14 +19,13 @@ package com.android.inputmethod.voice;
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.provider.Settings;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility for getting Google-specific settings from GoogleSettings.Partner or
|
* Utility for retrieving settings from Settings.Secure.
|
||||||
* Gservices. Retrieving such settings may fail on a non-Google Experience
|
|
||||||
* Device (GED)
|
|
||||||
*/
|
*/
|
||||||
public class GoogleSettingsUtil {
|
public class SettingsUtil {
|
||||||
/**
|
/**
|
||||||
* A whitespace-separated list of supported locales for voice input from the keyboard.
|
* A whitespace-separated list of supported locales for voice input from the keyboard.
|
||||||
*/
|
*/
|
||||||
|
@ -76,100 +75,39 @@ public class GoogleSettingsUtil {
|
||||||
public static final String LATIN_IME_MAX_VOICE_RESULTS = "latin_ime_max_voice_results";
|
public static final String LATIN_IME_MAX_VOICE_RESULTS = "latin_ime_max_voice_results";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Uri to use to access gservices settings
|
* Get a string-valued setting.
|
||||||
*/
|
|
||||||
private static final Uri GSERVICES_URI = Uri.parse("content://settings/gservices");
|
|
||||||
|
|
||||||
private static final String TAG = GoogleSettingsUtil.class.getSimpleName();
|
|
||||||
|
|
||||||
private static final boolean DBG = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Safely query for a Gservices string setting, which may not be available if this
|
|
||||||
* is not a Google Experience Device.
|
|
||||||
*
|
*
|
||||||
* @param cr The content resolver to use
|
* @param cr The content resolver to use
|
||||||
* @param key The setting to look up
|
* @param key The setting to look up
|
||||||
* @param defaultValue The default value to use if none can be found
|
* @param defaultValue The default value to use if none can be found
|
||||||
* @return The value of the setting, or defaultValue if it couldn't be found
|
* @return The value of the setting, or defaultValue if it couldn't be found
|
||||||
*/
|
*/
|
||||||
public static String getGservicesString(ContentResolver cr, String key, String defaultValue) {
|
public static String getSettingsString(ContentResolver cr, String key, String defaultValue) {
|
||||||
return getSettingString(GSERVICES_URI, cr, key, defaultValue);
|
String result = Settings.Secure.getString(cr, key);
|
||||||
|
return (result == null) ? defaultValue : result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Safely query for a Gservices int setting, which may not be available if this
|
* Get an int-valued setting.
|
||||||
* is not a Google Experience Device.
|
|
||||||
*
|
*
|
||||||
* @param cr The content resolver to use
|
* @param cr The content resolver to use
|
||||||
* @param key The setting to look up
|
* @param key The setting to look up
|
||||||
* @param defaultValue The default value to use if the setting couldn't be found or parsed
|
* @param defaultValue The default value to use if the setting couldn't be found or parsed
|
||||||
* @return The value of the setting, or defaultValue if it couldn't be found or parsed
|
* @return The value of the setting, or defaultValue if it couldn't be found or parsed
|
||||||
*/
|
*/
|
||||||
public static int getGservicesInt(ContentResolver cr, String key, int defaultValue) {
|
public static int getSettingsInt(ContentResolver cr, String key, int defaultValue) {
|
||||||
try {
|
return Settings.Secure.getInt(cr, key, defaultValue);
|
||||||
return Integer.parseInt(getGservicesString(cr, key, String.valueOf(defaultValue)));
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
return defaultValue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Safely query for a Gservices float setting, which may not be available if this
|
* Get a float-valued setting.
|
||||||
* is not a Google Experience Device.
|
|
||||||
*
|
*
|
||||||
* @param cr The content resolver to use
|
* @param cr The content resolver to use
|
||||||
* @param key The setting to look up
|
* @param key The setting to look up
|
||||||
* @param defaultValue The default value to use if the setting couldn't be found or parsed
|
* @param defaultValue The default value to use if the setting couldn't be found or parsed
|
||||||
* @return The value of the setting, or defaultValue if it couldn't be found or parsed
|
* @return The value of the setting, or defaultValue if it couldn't be found or parsed
|
||||||
*/
|
*/
|
||||||
public static float getGservicesFloat(ContentResolver cr, String key, float defaultValue) {
|
public static float getSettingsFloat(ContentResolver cr, String key, float defaultValue) {
|
||||||
try {
|
return Settings.Secure.getFloat(cr, key, defaultValue);
|
||||||
return Float.parseFloat(getGservicesString(cr, key, String.valueOf(defaultValue)));
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
return defaultValue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A safe way to query for a setting on both Google Experience and
|
|
||||||
* non-Google Experience devices, (code adapted from maps application
|
|
||||||
* examples)
|
|
||||||
*
|
|
||||||
* @param uri The uri to provide to the content resolver
|
|
||||||
* @param cr The content resolver to use
|
|
||||||
* @param key The setting to look up
|
|
||||||
* @param defaultValue The default value to use if none can be found
|
|
||||||
* @return The value of the setting, or defaultValue if it couldn't be found
|
|
||||||
*/
|
|
||||||
private static String getSettingString(Uri uri, ContentResolver cr, String key,
|
|
||||||
String defaultValue) {
|
|
||||||
String value = null;
|
|
||||||
|
|
||||||
Cursor cursor = null;
|
|
||||||
try {
|
|
||||||
cursor = cr.query(uri, new String[] {
|
|
||||||
"value"
|
|
||||||
}, "name='" + key + "'", null, null);
|
|
||||||
if ((cursor != null) && cursor.moveToFirst()) {
|
|
||||||
value = cursor.getString(cursor.getColumnIndexOrThrow("value"));
|
|
||||||
}
|
|
||||||
} catch (Throwable t) {
|
|
||||||
// This happens because we're probably running a non Type 1 aka
|
|
||||||
// Google Experience device which doesn't have the Google libraries.
|
|
||||||
if (DBG) {
|
|
||||||
Log.d(TAG, "Error getting setting from " + uri + " for key " + key + ": " + t);
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
if (cursor != null) {
|
|
||||||
cursor.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (DBG && value == null) {
|
|
||||||
Log.i(TAG, "no setting found from " + uri + " for key " + key + ", returning default");
|
|
||||||
}
|
|
||||||
|
|
||||||
return (value != null) ? value : defaultValue;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -145,9 +145,9 @@ public class VoiceInput implements OnClickListener {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
newView();
|
newView();
|
||||||
|
|
||||||
String recommendedPackages = GoogleSettingsUtil.getGservicesString(
|
String recommendedPackages = SettingsUtil.getSettingsString(
|
||||||
context.getContentResolver(),
|
context.getContentResolver(),
|
||||||
GoogleSettingsUtil.LATIN_IME_VOICE_INPUT_RECOMMENDED_PACKAGES,
|
SettingsUtil.LATIN_IME_VOICE_INPUT_RECOMMENDED_PACKAGES,
|
||||||
DEFAULT_RECOMMENDED_PACKAGES);
|
DEFAULT_RECOMMENDED_PACKAGES);
|
||||||
|
|
||||||
mRecommendedList = new Whitelist();
|
mRecommendedList = new Whitelist();
|
||||||
|
@ -215,9 +215,9 @@ public class VoiceInput implements OnClickListener {
|
||||||
intent.putExtra(EXTRA_RECOGNITION_CONTEXT, context.getBundle());
|
intent.putExtra(EXTRA_RECOGNITION_CONTEXT, context.getBundle());
|
||||||
intent.putExtra(EXTRA_CALLING_PACKAGE, "VoiceIME");
|
intent.putExtra(EXTRA_CALLING_PACKAGE, "VoiceIME");
|
||||||
intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS,
|
intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS,
|
||||||
GoogleSettingsUtil.getGservicesInt(
|
SettingsUtil.getSettingsInt(
|
||||||
mContext.getContentResolver(),
|
mContext.getContentResolver(),
|
||||||
GoogleSettingsUtil.LATIN_IME_MAX_VOICE_RESULTS,
|
SettingsUtil.LATIN_IME_MAX_VOICE_RESULTS,
|
||||||
1));
|
1));
|
||||||
|
|
||||||
// Get endpointer params from Gservices.
|
// Get endpointer params from Gservices.
|
||||||
|
@ -226,20 +226,20 @@ public class VoiceInput implements OnClickListener {
|
||||||
putEndpointerExtra(
|
putEndpointerExtra(
|
||||||
cr,
|
cr,
|
||||||
intent,
|
intent,
|
||||||
GoogleSettingsUtil.LATIN_IME_SPEECH_MINIMUM_LENGTH_MILLIS,
|
SettingsUtil.LATIN_IME_SPEECH_MINIMUM_LENGTH_MILLIS,
|
||||||
EXTRA_SPEECH_MINIMUM_LENGTH_MILLIS,
|
EXTRA_SPEECH_MINIMUM_LENGTH_MILLIS,
|
||||||
null /* rely on endpointer default */);
|
null /* rely on endpointer default */);
|
||||||
putEndpointerExtra(
|
putEndpointerExtra(
|
||||||
cr,
|
cr,
|
||||||
intent,
|
intent,
|
||||||
GoogleSettingsUtil.LATIN_IME_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS,
|
SettingsUtil.LATIN_IME_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS,
|
||||||
EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS,
|
EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS,
|
||||||
INPUT_COMPLETE_SILENCE_LENGTH_DEFAULT_VALUE_MILLIS
|
INPUT_COMPLETE_SILENCE_LENGTH_DEFAULT_VALUE_MILLIS
|
||||||
/* our default value is different from the endpointer's */);
|
/* our default value is different from the endpointer's */);
|
||||||
putEndpointerExtra(
|
putEndpointerExtra(
|
||||||
cr,
|
cr,
|
||||||
intent,
|
intent,
|
||||||
GoogleSettingsUtil.
|
SettingsUtil.
|
||||||
LATIN_IME_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS,
|
LATIN_IME_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS,
|
||||||
EXTRA_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS,
|
EXTRA_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS,
|
||||||
null /* rely on endpointer default */);
|
null /* rely on endpointer default */);
|
||||||
|
@ -254,7 +254,7 @@ public class VoiceInput implements OnClickListener {
|
||||||
private void putEndpointerExtra(ContentResolver cr, Intent i,
|
private void putEndpointerExtra(ContentResolver cr, Intent i,
|
||||||
String gservicesKey, String intentExtraKey, String defaultValue) {
|
String gservicesKey, String intentExtraKey, String defaultValue) {
|
||||||
long l = -1;
|
long l = -1;
|
||||||
String s = GoogleSettingsUtil.getGservicesString(cr, gservicesKey, defaultValue);
|
String s = SettingsUtil.getSettingsString(cr, gservicesKey, defaultValue);
|
||||||
if (s != null) {
|
if (s != null) {
|
||||||
try {
|
try {
|
||||||
l = Long.valueOf(s);
|
l = Long.valueOf(s);
|
||||||
|
|
Loading…
Reference in New Issue