aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/dictionarypack
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/com/android/inputmethod/dictionarypack')
-rw-r--r--java/src/com/android/inputmethod/dictionarypack/ActionBatch.java45
-rw-r--r--java/src/com/android/inputmethod/dictionarypack/CommonPreferences.java12
-rw-r--r--java/src/com/android/inputmethod/dictionarypack/DictionaryProvider.java14
-rw-r--r--java/src/com/android/inputmethod/dictionarypack/DictionaryService.java19
-rw-r--r--java/src/com/android/inputmethod/dictionarypack/DictionarySettingsFragment.java2
-rw-r--r--java/src/com/android/inputmethod/dictionarypack/DownloadManagerWrapper.java3
-rw-r--r--java/src/com/android/inputmethod/dictionarypack/DownloadOverMeteredDialog.java3
-rw-r--r--java/src/com/android/inputmethod/dictionarypack/MetadataDbHelper.java11
-rw-r--r--java/src/com/android/inputmethod/dictionarypack/UpdateHandler.java111
9 files changed, 149 insertions, 71 deletions
diff --git a/java/src/com/android/inputmethod/dictionarypack/ActionBatch.java b/java/src/com/android/inputmethod/dictionarypack/ActionBatch.java
index 1b526d453..09f8032cc 100644
--- a/java/src/com/android/inputmethod/dictionarypack/ActionBatch.java
+++ b/java/src/com/android/inputmethod/dictionarypack/ActionBatch.java
@@ -25,9 +25,8 @@ import android.net.Uri;
import android.text.TextUtils;
import android.util.Log;
-import com.android.inputmethod.latin.BinaryDictionaryFileDumper;
+import com.android.inputmethod.compat.DownloadManagerCompatUtils;
import com.android.inputmethod.latin.R;
-import com.android.inputmethod.latin.common.LocaleUtils;
import com.android.inputmethod.latin.utils.ApplicationUtils;
import com.android.inputmethod.latin.utils.DebugLogUtils;
@@ -85,7 +84,7 @@ public final class ActionBatch {
* Execute this action NOW.
* @param context the context to get system services, resources, databases
*/
- void execute(final Context context);
+ public void execute(final Context context);
}
/**
@@ -97,10 +96,13 @@ public final class ActionBatch {
private final String mClientId;
// The data to download. May not be null.
final WordListMetadata mWordList;
- public StartDownloadAction(final String clientId, final WordListMetadata wordList) {
+ final boolean mForceStartNow;
+ public StartDownloadAction(final String clientId,
+ final WordListMetadata wordList, final boolean forceStartNow) {
DebugLogUtils.l("New download action for client ", clientId, " : ", wordList);
mClientId = clientId;
mWordList = wordList;
+ mForceStartNow = forceStartNow;
}
@Override
@@ -139,9 +141,32 @@ public final class ActionBatch {
final Request request = new Request(uri);
final Resources res = context.getResources();
- request.setAllowedNetworkTypes(Request.NETWORK_WIFI | Request.NETWORK_MOBILE);
+ if (!mForceStartNow) {
+ if (DownloadManagerCompatUtils.hasSetAllowedOverMetered()) {
+ final boolean allowOverMetered;
+ switch (UpdateHandler.getDownloadOverMeteredSetting(context)) {
+ case UpdateHandler.DOWNLOAD_OVER_METERED_DISALLOWED:
+ // User said no: don't allow.
+ allowOverMetered = false;
+ break;
+ case UpdateHandler.DOWNLOAD_OVER_METERED_ALLOWED:
+ // User said yes: allow.
+ allowOverMetered = true;
+ break;
+ default: // UpdateHandler.DOWNLOAD_OVER_METERED_SETTING_UNKNOWN
+ // Don't know: use the default value from configuration.
+ allowOverMetered = res.getBoolean(R.bool.allow_over_metered);
+ }
+ DownloadManagerCompatUtils.setAllowedOverMetered(request, allowOverMetered);
+ } else {
+ request.setAllowedNetworkTypes(Request.NETWORK_WIFI);
+ }
+ request.setAllowedOverRoaming(res.getBoolean(R.bool.allow_over_roaming));
+ } // if mForceStartNow, then allow all network types and roaming, which is the default.
request.setTitle(mWordList.mDescription);
- request.setNotificationVisibility(Request.VISIBILITY_HIDDEN);
+ request.setNotificationVisibility(
+ res.getBoolean(R.bool.display_notification_for_auto_update)
+ ? Request.VISIBILITY_VISIBLE : Request.VISIBILITY_HIDDEN);
request.setVisibleInDownloadsUi(
res.getBoolean(R.bool.dict_downloads_visible_in_download_UI));
@@ -185,17 +210,9 @@ public final class ActionBatch {
+ " for an InstallAfterDownload action. Bailing out.");
return;
}
-
DebugLogUtils.l("Setting word list as installed");
final SQLiteDatabase db = MetadataDbHelper.getDb(context, mClientId);
MetadataDbHelper.markEntryAsFinishedDownloadingAndInstalled(db, mWordListValues);
-
- // Install the downloaded file by un-compressing and moving it to the staging
- // directory. Ideally, we should do this before updating the DB, but the
- // installDictToStagingFromContentProvider() relies on the db being updated.
- final String localeString = mWordListValues.getAsString(MetadataDbHelper.LOCALE_COLUMN);
- BinaryDictionaryFileDumper.installDictToStagingFromContentProvider(
- LocaleUtils.constructLocaleFromString(localeString), context, false);
}
}
diff --git a/java/src/com/android/inputmethod/dictionarypack/CommonPreferences.java b/java/src/com/android/inputmethod/dictionarypack/CommonPreferences.java
index 3d0e29ed0..3cd822a3c 100644
--- a/java/src/com/android/inputmethod/dictionarypack/CommonPreferences.java
+++ b/java/src/com/android/inputmethod/dictionarypack/CommonPreferences.java
@@ -22,6 +22,8 @@ import android.content.SharedPreferences;
public final class CommonPreferences {
private static final String COMMON_PREFERENCES_NAME = "LatinImeDictPrefs";
+ public static final String PREF_FORCE_DOWNLOAD_DICT = "pref_key_force_download_dict";
+
public static SharedPreferences getCommonPreferences(final Context context) {
return context.getSharedPreferences(COMMON_PREFERENCES_NAME, 0);
}
@@ -37,4 +39,14 @@ public final class CommonPreferences {
editor.putBoolean(id, false);
editor.apply();
}
+
+ public static boolean isForceDownloadDict(Context context) {
+ return getCommonPreferences(context).getBoolean(PREF_FORCE_DOWNLOAD_DICT, false);
+ }
+
+ public static void setForceDownloadDict(Context context, boolean forceDownload) {
+ SharedPreferences.Editor editor = getCommonPreferences(context).edit();
+ editor.putBoolean(PREF_FORCE_DOWNLOAD_DICT, forceDownload);
+ editor.apply();
+ }
}
diff --git a/java/src/com/android/inputmethod/dictionarypack/DictionaryProvider.java b/java/src/com/android/inputmethod/dictionarypack/DictionaryProvider.java
index 308b123e1..659fe5c51 100644
--- a/java/src/com/android/inputmethod/dictionarypack/DictionaryProvider.java
+++ b/java/src/com/android/inputmethod/dictionarypack/DictionaryProvider.java
@@ -243,8 +243,14 @@ public final class DictionaryProvider extends ContentProvider {
// Fall through
case DICTIONARY_V1_DICT_INFO:
final String locale = uri.getLastPathSegment();
+ // If LatinIME does not have a dictionary for this locale at all, it will
+ // send us true for this value. In this case, we may prompt the user for
+ // a decision about downloading a dictionary even over a metered connection.
+ final String mayPromptValue =
+ uri.getQueryParameter(QUERY_PARAMETER_MAY_PROMPT_USER);
+ final boolean mayPrompt = QUERY_PARAMETER_TRUE.equals(mayPromptValue);
final Collection<WordListInfo> dictFiles =
- getDictionaryWordListsForLocale(clientId, locale);
+ getDictionaryWordListsForLocale(clientId, locale, mayPrompt);
// TODO: pass clientId to the following function
DictionaryService.updateNowIfNotUpdatedInAVeryLongTime(getContext());
if (null != dictFiles && dictFiles.size() > 0) {
@@ -337,10 +343,11 @@ public final class DictionaryProvider extends ContentProvider {
*
* @param clientId the ID of the client requesting the list
* @param locale the locale for which we want the list, as a String
+ * @param mayPrompt true if we are allowed to prompt the user for arbitration via notification
* @return a collection of ids. It is guaranteed to be non-null, but may be empty.
*/
private Collection<WordListInfo> getDictionaryWordListsForLocale(final String clientId,
- final String locale) {
+ final String locale, final boolean mayPrompt) {
final Context context = getContext();
final Cursor results =
MetadataDbHelper.queryInstalledOrDeletingOrAvailableDictionaryMetadata(context,
@@ -405,7 +412,8 @@ public final class DictionaryProvider extends ContentProvider {
}
} else if (MetadataDbHelper.STATUS_AVAILABLE == wordListStatus) {
// The locale is the id for the main dictionary.
- UpdateHandler.installIfNeverRequested(context, clientId, wordListId);
+ UpdateHandler.installIfNeverRequested(context, clientId, wordListId,
+ mayPrompt);
continue;
}
final WordListInfo currentBestMatch = dicts.get(wordListCategory);
diff --git a/java/src/com/android/inputmethod/dictionarypack/DictionaryService.java b/java/src/com/android/inputmethod/dictionarypack/DictionaryService.java
index fe988ac70..bbdf2a380 100644
--- a/java/src/com/android/inputmethod/dictionarypack/DictionaryService.java
+++ b/java/src/com/android/inputmethod/dictionarypack/DictionaryService.java
@@ -192,22 +192,27 @@ public final class DictionaryService extends Service {
}
static void dispatchBroadcast(final Context context, final Intent intent) {
- final String action = intent.getAction();
- if (DATE_CHANGED_INTENT_ACTION.equals(action)) {
+ if (DATE_CHANGED_INTENT_ACTION.equals(intent.getAction())) {
+ // Do not force download dictionaries on date change updates.
+ CommonPreferences.setForceDownloadDict(context, false);
// This happens when the date of the device changes. This normally happens
// at midnight local time, but it may happen if the user changes the date
// by hand or something similar happens.
checkTimeAndMaybeSetupUpdateAlarm(context);
- } else if (DictionaryPackConstants.UPDATE_NOW_INTENT_ACTION.equals(action)) {
+ } else if (DictionaryPackConstants.UPDATE_NOW_INTENT_ACTION.equals(intent.getAction())) {
// Intent to trigger an update now.
- UpdateHandler.tryUpdate(context);
- } else if (DictionaryPackConstants.INIT_AND_UPDATE_NOW_INTENT_ACTION.equals(action)) {
+ UpdateHandler.tryUpdate(context, CommonPreferences.isForceDownloadDict(context));
+ } else if (DictionaryPackConstants.INIT_AND_UPDATE_NOW_INTENT_ACTION.equals(
+ intent.getAction())) {
+ // Enable force download of dictionaries irrespective of wifi or metered connection.
+ CommonPreferences.setForceDownloadDict(context, true);
+
// Initialize the client Db.
final String mClientId = context.getString(R.string.dictionary_pack_client_id);
BinaryDictionaryFileDumper.initializeClientRecordHelper(context, mClientId);
// Updates the metadata and the download the dictionaries.
- UpdateHandler.tryUpdate(context);
+ UpdateHandler.tryUpdate(context, true);
} else {
UpdateHandler.downloadFinished(context, intent);
}
@@ -258,7 +263,7 @@ public final class DictionaryService extends Service {
*/
public static void updateNowIfNotUpdatedInAVeryLongTime(final Context context) {
if (!isLastUpdateAtLeastThisOld(context, VERY_LONG_TIME_MILLIS)) return;
- UpdateHandler.tryUpdate(context);
+ UpdateHandler.tryUpdate(context, CommonPreferences.isForceDownloadDict(context));
}
/**
diff --git a/java/src/com/android/inputmethod/dictionarypack/DictionarySettingsFragment.java b/java/src/com/android/inputmethod/dictionarypack/DictionarySettingsFragment.java
index 35b46a978..88ea4e6c3 100644
--- a/java/src/com/android/inputmethod/dictionarypack/DictionarySettingsFragment.java
+++ b/java/src/com/android/inputmethod/dictionarypack/DictionarySettingsFragment.java
@@ -384,7 +384,7 @@ public final class DictionarySettingsFragment extends PreferenceFragment
// We call tryUpdate(), which returns whether we could successfully start an update.
// If we couldn't, we'll never receive the end callback, so we stop the loading
// animation and return to the previous screen.
- if (!UpdateHandler.tryUpdate(activity)) {
+ if (!UpdateHandler.tryUpdate(activity, true)) {
stopLoadingAnimation();
}
}
diff --git a/java/src/com/android/inputmethod/dictionarypack/DownloadManagerWrapper.java b/java/src/com/android/inputmethod/dictionarypack/DownloadManagerWrapper.java
index 6f6b02637..3dbbc9b9b 100644
--- a/java/src/com/android/inputmethod/dictionarypack/DownloadManagerWrapper.java
+++ b/java/src/com/android/inputmethod/dictionarypack/DownloadManagerWrapper.java
@@ -27,8 +27,6 @@ import android.util.Log;
import java.io.FileNotFoundException;
-import javax.annotation.Nullable;
-
/**
* A class to help with calling DownloadManager methods.
*
@@ -80,7 +78,6 @@ public class DownloadManagerWrapper {
throw new FileNotFoundException();
}
- @Nullable
public Cursor query(final Query query) {
try {
if (null != mDownloadManager) {
diff --git a/java/src/com/android/inputmethod/dictionarypack/DownloadOverMeteredDialog.java b/java/src/com/android/inputmethod/dictionarypack/DownloadOverMeteredDialog.java
index 908d931a0..91ed673ae 100644
--- a/java/src/com/android/inputmethod/dictionarypack/DownloadOverMeteredDialog.java
+++ b/java/src/com/android/inputmethod/dictionarypack/DownloadOverMeteredDialog.java
@@ -80,7 +80,8 @@ public final class DownloadOverMeteredDialog extends Activity {
@SuppressWarnings("unused")
public void onClickAllow(final View v) {
UpdateHandler.setDownloadOverMeteredSetting(this, true);
- UpdateHandler.installIfNeverRequested(this, mClientId, mWordListToDownload);
+ UpdateHandler.installIfNeverRequested(this, mClientId, mWordListToDownload,
+ false /* mayPrompt */);
finish();
}
}
diff --git a/java/src/com/android/inputmethod/dictionarypack/MetadataDbHelper.java b/java/src/com/android/inputmethod/dictionarypack/MetadataDbHelper.java
index 7d01351b4..fbc899192 100644
--- a/java/src/com/android/inputmethod/dictionarypack/MetadataDbHelper.java
+++ b/java/src/com/android/inputmethod/dictionarypack/MetadataDbHelper.java
@@ -50,7 +50,7 @@ public class MetadataDbHelper extends SQLiteOpenHelper {
private static final int METADATA_DATABASE_VERSION_WITH_CLIENTID = 6;
// The current database version.
// This MUST be increased every time the dictionary pack metadata URL changes.
- private static final int CURRENT_METADATA_DATABASE_VERSION = 16;
+ private static final int CURRENT_METADATA_DATABASE_VERSION = 14;
private final static long NOT_A_DOWNLOAD_ID = -1;
@@ -266,6 +266,8 @@ public class MetadataDbHelper extends SQLiteOpenHelper {
*/
@Override
public void onUpgrade(final SQLiteDatabase db, final int oldVersion, final int newVersion) {
+ // Allow automatic download of dictionaries on upgrading the database.
+ CommonPreferences.setForceDownloadDict(mContext, true);
if (METADATA_DATABASE_INITIAL_VERSION == oldVersion
&& METADATA_DATABASE_VERSION_WITH_CLIENTID <= newVersion
&& CURRENT_METADATA_DATABASE_VERSION >= newVersion) {
@@ -343,8 +345,6 @@ public class MetadataDbHelper extends SQLiteOpenHelper {
return null != getMetadataUriAsString(context, clientId);
}
- private static final MetadataUriGetter sMetadataUriGetter = new MetadataUriGetter();
-
/**
* Returns the metadata URI as a string.
*
@@ -358,12 +358,13 @@ public class MetadataDbHelper extends SQLiteOpenHelper {
public static String getMetadataUriAsString(final Context context, final String clientId) {
SQLiteDatabase defaultDb = MetadataDbHelper.getDb(context, null);
final Cursor cursor = defaultDb.query(MetadataDbHelper.CLIENT_TABLE_NAME,
- new String[] { MetadataDbHelper.CLIENT_METADATA_URI_COLUMN },
+ new String[] { MetadataDbHelper.CLIENT_METADATA_URI_COLUMN,
+ MetadataDbHelper.CLIENT_METADATA_ADDITIONAL_ID_COLUMN },
MetadataDbHelper.CLIENT_CLIENT_ID_COLUMN + " = ?", new String[] { clientId },
null, null, null, null);
try {
if (!cursor.moveToFirst()) return null;
- return sMetadataUriGetter.getUri(context, cursor.getString(0));
+ return MetadataUriGetter.getUri(context, cursor.getString(0), cursor.getString(1));
} finally {
cursor.close();
}
diff --git a/java/src/com/android/inputmethod/dictionarypack/UpdateHandler.java b/java/src/com/android/inputmethod/dictionarypack/UpdateHandler.java
index a02203d31..e61547a9d 100644
--- a/java/src/com/android/inputmethod/dictionarypack/UpdateHandler.java
+++ b/java/src/com/android/inputmethod/dictionarypack/UpdateHandler.java
@@ -36,6 +36,7 @@ import android.text.TextUtils;
import android.util.Log;
import com.android.inputmethod.compat.ConnectivityManagerCompatUtils;
+import com.android.inputmethod.compat.DownloadManagerCompatUtils;
import com.android.inputmethod.compat.NotificationCompatUtils;
import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.common.LocaleUtils;
@@ -105,9 +106,9 @@ public final class UpdateHandler {
* This is chiefly used by the dictionary manager UI.
*/
public interface UpdateEventListener {
- void downloadedMetadata(boolean succeeded);
- void wordListDownloadFinished(String wordListId, boolean succeeded);
- void updateCycleCompleted();
+ public void downloadedMetadata(boolean succeeded);
+ public void wordListDownloadFinished(String wordListId, boolean succeeded);
+ public void updateCycleCompleted();
}
/**
@@ -178,9 +179,10 @@ public final class UpdateHandler {
/**
* Download latest metadata from the server through DownloadManager for all known clients
* @param context The context for retrieving resources
+ * @param updateNow Whether we should update NOW, or respect bandwidth policies
* @return true if an update successfully started, false otherwise.
*/
- public static boolean tryUpdate(final Context context) {
+ public static boolean tryUpdate(final Context context, final boolean updateNow) {
// TODO: loop through all clients instead of only doing the default one.
final TreeSet<String> uris = new TreeSet<>();
final Cursor cursor = MetadataDbHelper.queryClientIds(context);
@@ -206,7 +208,7 @@ public final class UpdateHandler {
// it should have been rejected at the time of client registration; if there
// is a bug and it happens anyway, doing nothing is the right thing to do.
// For more information, {@see DictionaryProvider#insert(Uri, ContentValues)}.
- updateClientsWithMetadataUri(context, metadataUri);
+ updateClientsWithMetadataUri(context, updateNow, metadataUri);
started = true;
}
}
@@ -217,11 +219,12 @@ public final class UpdateHandler {
* Download latest metadata from the server through DownloadManager for all relevant clients
*
* @param context The context for retrieving resources
+ * @param updateNow Whether we should update NOW, or respect bandwidth policies
* @param metadataUri The client to update
*/
- private static void updateClientsWithMetadataUri(
- final Context context, final String metadataUri) {
- Log.i(TAG, "updateClientsWithMetadataUri() : MetadataUri = " + metadataUri);
+ private static void updateClientsWithMetadataUri(final Context context,
+ final boolean updateNow, final String metadataUri) {
+ PrivateLog.log("Update for metadata URI " + DebugLogUtils.s(metadataUri));
// Adding a disambiguator to circumvent a bug in older versions of DownloadManager.
// DownloadManager also stupidly cuts the extension to replace with its own that it
// gets from the content-type. We need to circumvent this.
@@ -231,10 +234,25 @@ public final class UpdateHandler {
DebugLogUtils.l("Request =", metadataRequest);
final Resources res = context.getResources();
- metadataRequest.setAllowedNetworkTypes(Request.NETWORK_WIFI | Request.NETWORK_MOBILE);
+ // By default, download over roaming is allowed and all network types are allowed too.
+ if (!updateNow) {
+ final boolean allowedOverMetered = res.getBoolean(R.bool.allow_over_metered);
+ // If we don't have to update NOW, then only do it over non-metered connections.
+ if (DownloadManagerCompatUtils.hasSetAllowedOverMetered()) {
+ DownloadManagerCompatUtils.setAllowedOverMetered(metadataRequest,
+ allowedOverMetered);
+ } else if (!allowedOverMetered) {
+ metadataRequest.setAllowedNetworkTypes(Request.NETWORK_WIFI);
+ }
+ metadataRequest.setAllowedOverRoaming(res.getBoolean(R.bool.allow_over_roaming));
+ }
+ final boolean notificationVisible = updateNow
+ ? res.getBoolean(R.bool.display_notification_for_user_requested_update)
+ : res.getBoolean(R.bool.display_notification_for_auto_update);
+
metadataRequest.setTitle(res.getString(R.string.download_description));
- // Do not show the notification when downloading the metadata.
- metadataRequest.setNotificationVisibility(Request.VISIBILITY_HIDDEN);
+ metadataRequest.setNotificationVisibility(notificationVisible
+ ? Request.VISIBILITY_VISIBLE : Request.VISIBILITY_HIDDEN);
metadataRequest.setVisibleInDownloadsUi(
res.getBoolean(R.bool.metadata_downloads_visible_in_download_UI));
@@ -255,7 +273,7 @@ public final class UpdateHandler {
// method will ignore it.
writeMetadataDownloadId(context, metadataUri, downloadId);
}
- Log.i(TAG, "updateClientsWithMetadataUri() : DownloadId = " + downloadId);
+ PrivateLog.log("Requested download with id " + downloadId);
}
/**
@@ -327,11 +345,11 @@ public final class UpdateHandler {
*/
public static long registerDownloadRequest(final DownloadManagerWrapper manager,
final Request request, final SQLiteDatabase db, final String id, final int version) {
- Log.i(TAG, "registerDownloadRequest() : Id = " + id + " : Version = " + version);
+ DebugLogUtils.l("RegisterDownloadRequest for word list id : ", id, ", version ", version);
final long downloadId;
synchronized (sSharedIdProtector) {
downloadId = manager.enqueue(request);
- Log.i(TAG, "registerDownloadRequest() : DownloadId = " + downloadId);
+ DebugLogUtils.l("Download requested with id", downloadId);
MetadataDbHelper.markEntryAsDownloading(db, id, version, downloadId);
}
return downloadId;
@@ -416,7 +434,8 @@ public final class UpdateHandler {
/* package */ static void downloadFinished(final Context context, final Intent intent) {
// Get and check the ID of the file that was downloaded
final long fileId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, NOT_AN_ID);
- Log.i(TAG, "downloadFinished() : DownloadId = " + fileId);
+ PrivateLog.log("Download finished with id " + fileId);
+ DebugLogUtils.l("DownloadFinished with id", fileId);
if (NOT_AN_ID == fileId) return; // Spurious wake-up: ignore
final DownloadManagerWrapper manager = new DownloadManagerWrapper(context);
@@ -432,27 +451,31 @@ public final class UpdateHandler {
// download, so we are pretty sure it's alive. It's theoretically possible that it's
// disabled right inbetween the firing of the intent and the control reaching here.
+ boolean dictionaryDownloaded = false;
+
for (final DownloadRecord record : recordList) {
// downloadSuccessful is not final because we may still have exceptions from now on
boolean downloadSuccessful = false;
try {
if (downloadInfo.wasSuccessful()) {
downloadSuccessful = handleDownloadedFile(context, record, manager, fileId);
- Log.i(TAG, "downloadFinished() : Success = " + downloadSuccessful);
}
} finally {
- final String resultMessage = downloadSuccessful ? "Success" : "Failure";
if (record.isMetadata()) {
- Log.i(TAG, "downloadFinished() : Metadata " + resultMessage);
publishUpdateMetadataCompleted(context, downloadSuccessful);
} else {
- Log.i(TAG, "downloadFinished() : WordList " + resultMessage);
final SQLiteDatabase db = MetadataDbHelper.getDb(context, record.mClientId);
publishUpdateWordListCompleted(context, downloadSuccessful, fileId,
db, record.mAttributes, record.mClientId);
+ dictionaryDownloaded = true;
}
}
}
+
+ if (dictionaryDownloaded) {
+ // Disable the force download after downloading the dictionaries.
+ CommonPreferences.setForceDownloadDict(context, false);
+ }
// Now that we're done using it, we can remove this download from DLManager
manager.remove(fileId);
}
@@ -569,8 +592,6 @@ public final class UpdateHandler {
* Warn Android Keyboard that the state of dictionaries changed and it should refresh its data.
*/
private static void signalNewDictionaryState(final Context context) {
- // TODO: Also provide the locale of the updated dictionary so that the LatinIme
- // does not have to reset if it is a different locale.
final Intent newDictBroadcast =
new Intent(DictionaryPackConstants.NEW_DICTIONARY_INTENT_ACTION);
context.sendBroadcast(newDictBroadcast);
@@ -585,7 +606,7 @@ public final class UpdateHandler {
* @throws BadFormatException if the metadata is not in a known format.
* @throws IOException if the downloaded file can't be read from the disk
*/
- public static void handleMetadata(final Context context, final InputStream stream,
+ private static void handleMetadata(final Context context, final InputStream stream,
final String clientId) throws IOException, BadFormatException {
DebugLogUtils.l("Entering handleMetadata");
final List<WordListMetadata> newMetadata;
@@ -809,7 +830,8 @@ public final class UpdateHandler {
actions.add(new ActionBatch.MakeAvailableAction(clientId, newInfo));
if (status == MetadataDbHelper.STATUS_INSTALLED
|| status == MetadataDbHelper.STATUS_DISABLED) {
- actions.add(new ActionBatch.StartDownloadAction(clientId, newInfo));
+ actions.add(new ActionBatch.StartDownloadAction(
+ clientId, newInfo, CommonPreferences.isForceDownloadDict(context)));
} else {
// Pass true to ForgetAction: this is indeed an update to a non-installed
// word list, so activate status == AVAILABLE check
@@ -907,9 +929,7 @@ public final class UpdateHandler {
// list because it may only install the latest version we know about for this specific
// word list ID / client ID combination.
public static void installIfNeverRequested(final Context context, final String clientId,
- final String wordlistId) {
- Log.i(TAG, "installIfNeverRequested() : ClientId = " + clientId
- + " : WordListId = " + wordlistId);
+ final String wordlistId, final boolean mayPrompt) {
final String[] idArray = wordlistId.split(DictionaryProvider.ID_CATEGORY_SEPARATOR);
// If we have a new-format dictionary id (category:manual_id), then use the
// specified category. Otherwise, it is a main dictionary, so force the
@@ -942,6 +962,17 @@ public final class UpdateHandler {
return;
}
+ if (mayPrompt
+ && DOWNLOAD_OVER_METERED_SETTING_UNKNOWN
+ == getDownloadOverMeteredSetting(context)) {
+ final ConnectivityManager cm =
+ (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
+ if (ConnectivityManagerCompatUtils.isActiveNetworkMetered(cm)) {
+ showDictionaryAvailableNotification(context, clientId, installCandidate);
+ return;
+ }
+ }
+
// We decided against prompting the user for a decision. This may be because we were
// explicitly asked not to, or because we are currently on wi-fi anyway, or because we
// already know the answer to the question. We'll enqueue a request ; StartDownloadAction
@@ -953,18 +984,21 @@ public final class UpdateHandler {
// change the shared preferences. So there is no way for a word list that has been
// auto-installed once to get auto-installed again, and that's what we want.
final ActionBatch actions = new ActionBatch();
- WordListMetadata metadata = WordListMetadata.createFromContentValues(installCandidate);
- actions.add(new ActionBatch.StartDownloadAction(clientId, metadata));
+ actions.add(new ActionBatch.StartDownloadAction(
+ clientId,
+ WordListMetadata.createFromContentValues(installCandidate),
+ CommonPreferences.isForceDownloadDict(context)));
final String localeString = installCandidate.getAsString(MetadataDbHelper.LOCALE_COLUMN);
// We are in a content provider: we can't do any UI at all. We have to defer the displaying
// itself to the service. Also, we only display this when the user does not have a
- // dictionary for this language already.
- final Intent intent = new Intent();
- intent.setClass(context, DictionaryService.class);
- intent.setAction(DictionaryService.SHOW_DOWNLOAD_TOAST_INTENT_ACTION);
- intent.putExtra(DictionaryService.LOCALE_INTENT_ARGUMENT, localeString);
- context.startService(intent);
- Log.i(TAG, "installIfNeverRequested() : StartDownloadAction for " + metadata);
+ // dictionary for this language already: we know that from the mayPrompt argument.
+ if (mayPrompt) {
+ final Intent intent = new Intent();
+ intent.setClass(context, DictionaryService.class);
+ intent.setAction(DictionaryService.SHOW_DOWNLOAD_TOAST_INTENT_ACTION);
+ intent.putExtra(DictionaryService.LOCALE_INTENT_ARGUMENT, localeString);
+ context.startService(intent);
+ }
actions.execute(context, new LogProblemReporter(TAG));
}
@@ -999,7 +1033,9 @@ public final class UpdateHandler {
|| MetadataDbHelper.STATUS_DELETING == status) {
actions.add(new ActionBatch.EnableAction(clientId, wordListMetaData));
} else if (MetadataDbHelper.STATUS_AVAILABLE == status) {
- actions.add(new ActionBatch.StartDownloadAction(clientId, wordListMetaData));
+ boolean forceDownloadDict = CommonPreferences.isForceDownloadDict(context);
+ actions.add(new ActionBatch.StartDownloadAction(clientId, wordListMetaData,
+ forceDownloadDict || allowDownloadOnMeteredData));
} else {
Log.e(TAG, "Unexpected state of the word list for markAsUsed : " + status);
}
@@ -1114,7 +1150,8 @@ public final class UpdateHandler {
}
final ActionBatch actions = new ActionBatch();
- actions.add(new ActionBatch.StartDownloadAction(clientId, wordListMetaData));
+ actions.add(new ActionBatch.StartDownloadAction(
+ clientId, wordListMetaData, CommonPreferences.isForceDownloadDict(context)));
actions.execute(context, new LogProblemReporter(TAG));
} else {
if (DEBUG) {