Work around a bug in older DownloadManager versions.

This adds a number to the extension.

Note that for DownloadManager to keep this, the server
needs to send it a mime type it does not recognize. Right
now, it does not recognize application/json so it's okay,
but we'd do well to remove the content/type header from
the server to prevent problems.

Bug: 8467516
Change-Id: Ic484f66ac3f67c36f59f2c0bcb8c7fdeb6e8590d
main
Jean Chalard 2013-04-25 17:16:03 +09:00
parent 4dc77dcf4c
commit 43590149a5
4 changed files with 21 additions and 5 deletions

View File

@ -138,7 +138,12 @@ public final class ActionBatch {
if (null == manager) return;
// This is an upgraded word list: we should download it.
final Uri uri = Uri.parse(mWordList.mRemoteFilename);
// 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.
final String disambiguator = "#" + System.currentTimeMillis()
+ com.android.inputmethod.latin.Utils.getVersionName(context) + ".dict";
final Uri uri = Uri.parse(mWordList.mRemoteFilename + disambiguator);
final Request request = new Request(uri);
final Resources res = context.getResources();

View File

@ -212,7 +212,12 @@ public final class UpdateHandler {
private static void updateClientsWithMetadataUri(final Context context,
final boolean updateNow, final String metadataUri) {
PrivateLog.log("Update for metadata URI " + Utils.s(metadataUri));
final Request metadataRequest = new Request(Uri.parse(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.
final String disambiguator = "#" + System.currentTimeMillis()
+ com.android.inputmethod.latin.Utils.getVersionName(context) + ".json";
final Request metadataRequest = new Request(Uri.parse(metadataUri + disambiguator));
Utils.l("Request =", metadataRequest);
final Resources res = context.getResources();
@ -351,7 +356,13 @@ public final class UpdateHandler {
final int columnUri = cursor.getColumnIndex(DownloadManager.COLUMN_URI);
final int error = cursor.getInt(columnError);
status = cursor.getInt(columnStatus);
uri = cursor.getString(columnUri);
final String uriWithAnchor = cursor.getString(columnUri);
int anchorIndex = uriWithAnchor.indexOf('#');
if (anchorIndex != -1) {
uri = uriWithAnchor.substring(0, anchorIndex);
} else {
uri = uriWithAnchor;
}
if (DownloadManager.STATUS_SUCCESSFUL != status) {
Log.e(TAG, "Permanent failure of download " + downloadId
+ " with error code: " + error);

View File

@ -122,7 +122,7 @@ public final class DebugSettings extends PreferenceFragment
}
boolean isDebugMode = mDebugMode.isChecked();
final String version = getResources().getString(
R.string.version_text, Utils.getSdkVersion(getActivity()));
R.string.version_text, Utils.getVersionName(getActivity()));
if (!isDebugMode) {
mDebugMode.setTitle(version);
mDebugMode.setSummary("");

View File

@ -475,7 +475,7 @@ public final class Utils {
return 0;
}
public static String getSdkVersion(Context context) {
public static String getVersionName(Context context) {
try {
if (context == null) {
return "";