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.WRITE_USER_DICTIONARY" />
|
||||
<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"
|
||||
android:backupAgent="LatinIMEBackupAgent"
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
package com.android.inputmethod.latin;
|
||||
|
||||
import com.android.inputmethod.voice.GoogleSettingsUtil;
|
||||
import com.android.inputmethod.voice.SettingsUtil;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
|
@ -68,13 +68,13 @@ public class Hints {
|
|||
mDisplay = display;
|
||||
|
||||
ContentResolver cr = mContext.getContentResolver();
|
||||
mSwipeHintMaxDaysToShow = GoogleSettingsUtil.getGservicesInt(
|
||||
mSwipeHintMaxDaysToShow = SettingsUtil.getSettingsInt(
|
||||
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);
|
||||
mPunctuationHintMaxDisplays = GoogleSettingsUtil.getGservicesInt(
|
||||
mPunctuationHintMaxDisplays = SettingsUtil.getSettingsInt(
|
||||
cr,
|
||||
GoogleSettingsUtil.LATIN_IME_VOICE_INPUT_PUNCTUATION_HINT_MAX_DISPLAYS,
|
||||
SettingsUtil.LATIN_IME_VOICE_INPUT_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.FieldContext;
|
||||
import com.android.inputmethod.voice.GoogleSettingsUtil;
|
||||
import com.android.inputmethod.voice.SettingsUtil;
|
||||
import com.android.inputmethod.voice.VoiceInput;
|
||||
|
||||
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
|
||||
// long as the locale doesn't change while the user is keeping the IME open, the
|
||||
// value should never be stale.
|
||||
String supportedLocalesString = GoogleSettingsUtil.getGservicesString(
|
||||
String supportedLocalesString = SettingsUtil.getSettingsString(
|
||||
getContentResolver(),
|
||||
GoogleSettingsUtil.LATIN_IME_VOICE_INPUT_SUPPORTED_LOCALES,
|
||||
SettingsUtil.LATIN_IME_VOICE_INPUT_SUPPORTED_LOCALES,
|
||||
DEFAULT_VOICE_INPUT_SUPPORTED_LOCALES);
|
||||
ArrayList<String> voiceInputSupportedLocales =
|
||||
Lists.newArrayList(supportedLocalesString.split("\\s+"));
|
||||
|
|
|
@ -33,7 +33,7 @@ import android.util.Log;
|
|||
|
||||
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 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
|
||||
// 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.
|
||||
String supportedLocalesString = GoogleSettingsUtil.getGservicesString(
|
||||
String supportedLocalesString = SettingsUtil.getSettingsString(
|
||||
getContentResolver(),
|
||||
GoogleSettingsUtil.LATIN_IME_VOICE_INPUT_SUPPORTED_LOCALES,
|
||||
SettingsUtil.LATIN_IME_VOICE_INPUT_SUPPORTED_LOCALES,
|
||||
LatinIME.DEFAULT_VOICE_INPUT_SUPPORTED_LOCALES);
|
||||
ArrayList<String> voiceInputSupportedLocales =
|
||||
Lists.newArrayList(supportedLocalesString.split("\\s+"));
|
||||
|
|
|
@ -36,7 +36,7 @@ import android.widget.ImageView;
|
|||
import android.widget.TextView;
|
||||
|
||||
import com.android.inputmethod.latin.R;
|
||||
import com.android.inputmethod.voice.GoogleSettingsUtil;
|
||||
import com.android.inputmethod.voice.SettingsUtil;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
|
@ -112,10 +112,10 @@ public class RecognitionView {
|
|||
mView = inflater.inflate(R.layout.recognition_status, null);
|
||||
|
||||
ContentResolver cr = context.getContentResolver();
|
||||
mMinMicrophoneLevel = GoogleSettingsUtil.getGservicesFloat(
|
||||
cr, GoogleSettingsUtil.LATIN_IME_MIN_MICROPHONE_LEVEL, 15.f);
|
||||
mMaxMicrophoneLevel = GoogleSettingsUtil.getGservicesFloat(
|
||||
cr, GoogleSettingsUtil.LATIN_IME_MAX_MICROPHONE_LEVEL, 30.f);
|
||||
mMinMicrophoneLevel = SettingsUtil.getSettingsFloat(
|
||||
cr, SettingsUtil.LATIN_IME_MIN_MICROPHONE_LEVEL, 15.f);
|
||||
mMaxMicrophoneLevel = SettingsUtil.getSettingsFloat(
|
||||
cr, SettingsUtil.LATIN_IME_MAX_MICROPHONE_LEVEL, 30.f);
|
||||
|
||||
// Pre-load volume level images
|
||||
Resources r = context.getResources();
|
||||
|
|
|
@ -19,14 +19,13 @@ package com.android.inputmethod.voice;
|
|||
import android.content.ContentResolver;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.provider.Settings;
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
* Utility for getting Google-specific settings from GoogleSettings.Partner or
|
||||
* Gservices. Retrieving such settings may fail on a non-Google Experience
|
||||
* Device (GED)
|
||||
* Utility for retrieving settings from Settings.Secure.
|
||||
*/
|
||||
public class GoogleSettingsUtil {
|
||||
public class SettingsUtil {
|
||||
/**
|
||||
* 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";
|
||||
|
||||
/**
|
||||
* Uri to use to access gservices settings
|
||||
*/
|
||||
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.
|
||||
* Get a string-valued setting.
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
public static String getGservicesString(ContentResolver cr, String key, String defaultValue) {
|
||||
return getSettingString(GSERVICES_URI, cr, key, defaultValue);
|
||||
public static String getSettingsString(ContentResolver cr, String key, String 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
|
||||
* is not a Google Experience Device.
|
||||
* Get an int-valued setting.
|
||||
*
|
||||
* @param cr The content resolver to use
|
||||
* @param key The setting to look up
|
||||
* @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
|
||||
*/
|
||||
public static int getGservicesInt(ContentResolver cr, String key, int defaultValue) {
|
||||
try {
|
||||
return Integer.parseInt(getGservicesString(cr, key, String.valueOf(defaultValue)));
|
||||
} catch (NumberFormatException e) {
|
||||
return defaultValue;
|
||||
}
|
||||
public static int getSettingsInt(ContentResolver cr, String key, int defaultValue) {
|
||||
return Settings.Secure.getInt(cr, key, defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Safely query for a Gservices float setting, which may not be available if this
|
||||
* is not a Google Experience Device.
|
||||
* Get a float-valued setting.
|
||||
*
|
||||
* @param cr The content resolver to use
|
||||
* @param key The setting to look up
|
||||
* @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
|
||||
*/
|
||||
public static float getGservicesFloat(ContentResolver cr, String key, float defaultValue) {
|
||||
try {
|
||||
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;
|
||||
public static float getSettingsFloat(ContentResolver cr, String key, float defaultValue) {
|
||||
return Settings.Secure.getFloat(cr, key, defaultValue);
|
||||
}
|
||||
}
|
|
@ -145,9 +145,9 @@ public class VoiceInput implements OnClickListener {
|
|||
mContext = context;
|
||||
newView();
|
||||
|
||||
String recommendedPackages = GoogleSettingsUtil.getGservicesString(
|
||||
String recommendedPackages = SettingsUtil.getSettingsString(
|
||||
context.getContentResolver(),
|
||||
GoogleSettingsUtil.LATIN_IME_VOICE_INPUT_RECOMMENDED_PACKAGES,
|
||||
SettingsUtil.LATIN_IME_VOICE_INPUT_RECOMMENDED_PACKAGES,
|
||||
DEFAULT_RECOMMENDED_PACKAGES);
|
||||
|
||||
mRecommendedList = new Whitelist();
|
||||
|
@ -215,9 +215,9 @@ public class VoiceInput implements OnClickListener {
|
|||
intent.putExtra(EXTRA_RECOGNITION_CONTEXT, context.getBundle());
|
||||
intent.putExtra(EXTRA_CALLING_PACKAGE, "VoiceIME");
|
||||
intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS,
|
||||
GoogleSettingsUtil.getGservicesInt(
|
||||
SettingsUtil.getSettingsInt(
|
||||
mContext.getContentResolver(),
|
||||
GoogleSettingsUtil.LATIN_IME_MAX_VOICE_RESULTS,
|
||||
SettingsUtil.LATIN_IME_MAX_VOICE_RESULTS,
|
||||
1));
|
||||
|
||||
// Get endpointer params from Gservices.
|
||||
|
@ -226,20 +226,20 @@ public class VoiceInput implements OnClickListener {
|
|||
putEndpointerExtra(
|
||||
cr,
|
||||
intent,
|
||||
GoogleSettingsUtil.LATIN_IME_SPEECH_MINIMUM_LENGTH_MILLIS,
|
||||
SettingsUtil.LATIN_IME_SPEECH_MINIMUM_LENGTH_MILLIS,
|
||||
EXTRA_SPEECH_MINIMUM_LENGTH_MILLIS,
|
||||
null /* rely on endpointer default */);
|
||||
putEndpointerExtra(
|
||||
cr,
|
||||
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,
|
||||
INPUT_COMPLETE_SILENCE_LENGTH_DEFAULT_VALUE_MILLIS
|
||||
/* our default value is different from the endpointer's */);
|
||||
putEndpointerExtra(
|
||||
cr,
|
||||
intent,
|
||||
GoogleSettingsUtil.
|
||||
SettingsUtil.
|
||||
LATIN_IME_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS,
|
||||
EXTRA_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS,
|
||||
null /* rely on endpointer default */);
|
||||
|
@ -254,7 +254,7 @@ public class VoiceInput implements OnClickListener {
|
|||
private void putEndpointerExtra(ContentResolver cr, Intent i,
|
||||
String gservicesKey, String intentExtraKey, String defaultValue) {
|
||||
long l = -1;
|
||||
String s = GoogleSettingsUtil.getGservicesString(cr, gservicesKey, defaultValue);
|
||||
String s = SettingsUtil.getSettingsString(cr, gservicesKey, defaultValue);
|
||||
if (s != null) {
|
||||
try {
|
||||
l = Long.valueOf(s);
|
||||
|
|
Loading…
Reference in New Issue