diff options
Diffstat (limited to 'java/src/com/android/inputmethod/dictionarypack/ActionBatch.java')
-rw-r--r-- | java/src/com/android/inputmethod/dictionarypack/ActionBatch.java | 45 |
1 files changed, 31 insertions, 14 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); } } |