aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/dictionarypack/UpdateHandler.java
diff options
context:
space:
mode:
authorKen Wakasa <kwakasa@google.com>2013-06-25 17:03:05 +0900
committerKen Wakasa <kwakasa@google.com>2013-06-25 17:09:12 +0900
commit03118a276014cd44d44d0d46f4f39622765e8e0c (patch)
treea111d9338181b849192b85838760ce8dd679c604 /java/src/com/android/inputmethod/dictionarypack/UpdateHandler.java
parent10585620bdfad418f6c093ab4bfd8efaa2d84abf (diff)
downloadlatinime-03118a276014cd44d44d0d46f4f39622765e8e0c.tar.gz
latinime-03118a276014cd44d44d0d46f4f39622765e8e0c.tar.xz
latinime-03118a276014cd44d44d0d46f4f39622765e8e0c.zip
Cleanup under the utils package
Change-Id: If2f7bd1346cc5085bf57645830f0faac44d017e4
Diffstat (limited to 'java/src/com/android/inputmethod/dictionarypack/UpdateHandler.java')
-rw-r--r--java/src/com/android/inputmethod/dictionarypack/UpdateHandler.java48
1 files changed, 24 insertions, 24 deletions
diff --git a/java/src/com/android/inputmethod/dictionarypack/UpdateHandler.java b/java/src/com/android/inputmethod/dictionarypack/UpdateHandler.java
index 936d00d25..719f24e59 100644
--- a/java/src/com/android/inputmethod/dictionarypack/UpdateHandler.java
+++ b/java/src/com/android/inputmethod/dictionarypack/UpdateHandler.java
@@ -38,7 +38,7 @@ import android.util.Log;
import com.android.inputmethod.compat.ConnectivityManagerCompatUtils;
import com.android.inputmethod.compat.DownloadManagerCompatUtils;
import com.android.inputmethod.latin.R;
-import com.android.inputmethod.latin.utils.LogUtils;
+import com.android.inputmethod.latin.utils.DebugLogUtils;
import com.android.inputmethod.latin.utils.Utils;
import java.io.File;
@@ -185,8 +185,8 @@ public final class UpdateHandler {
final String clientId = cursor.getString(0);
final String metadataUri =
MetadataDbHelper.getMetadataUriAsString(context, clientId);
- PrivateLog.log("Update for clientId " + LogUtils.s(clientId));
- LogUtils.l("Update for clientId", clientId, " which uses URI ", metadataUri);
+ PrivateLog.log("Update for clientId " + DebugLogUtils.s(clientId));
+ DebugLogUtils.l("Update for clientId", clientId, " which uses URI ", metadataUri);
uris.add(metadataUri);
} while (cursor.moveToNext());
} finally {
@@ -213,14 +213,14 @@ public final class UpdateHandler {
*/
private static void updateClientsWithMetadataUri(final Context context,
final boolean updateNow, final String metadataUri) {
- PrivateLog.log("Update for metadata URI " + LogUtils.s(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.
final String disambiguator = "#" + System.currentTimeMillis()
+ Utils.getVersionName(context) + ".json";
final Request metadataRequest = new Request(Uri.parse(metadataUri + disambiguator));
- LogUtils.l("Request =", metadataRequest);
+ DebugLogUtils.l("Request =", metadataRequest);
final Resources res = context.getResources();
// By default, download over roaming is allowed and all network types are allowed too.
@@ -256,7 +256,7 @@ public final class UpdateHandler {
final long downloadId;
synchronized (sSharedIdProtector) {
downloadId = manager.enqueue(metadataRequest);
- LogUtils.l("Metadata download requested with id", downloadId);
+ DebugLogUtils.l("Metadata download requested with id", downloadId);
// If there is already a download in progress, it's been there for a while and
// there is probably something wrong with download manager. It's best to just
// overwrite the id and request it again. If the old one happens to finish
@@ -328,11 +328,11 @@ public final class UpdateHandler {
*/
public static long registerDownloadRequest(final DownloadManager manager, final Request request,
final SQLiteDatabase db, final String id, final int version) {
- LogUtils.l("RegisterDownloadRequest for word list id : ", id, ", version ", version);
+ DebugLogUtils.l("RegisterDownloadRequest for word list id : ", id, ", version ", version);
final long downloadId;
synchronized (sSharedIdProtector) {
downloadId = manager.enqueue(request);
- LogUtils.l("Download requested with id", downloadId);
+ DebugLogUtils.l("Download requested with id", downloadId);
MetadataDbHelper.markEntryAsDownloading(db, id, version, downloadId);
}
return downloadId;
@@ -418,7 +418,7 @@ public final class UpdateHandler {
// Get and check the ID of the file that was downloaded
final long fileId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, NOT_AN_ID);
PrivateLog.log("Download finished with id " + fileId);
- LogUtils.l("DownloadFinished with id", fileId);
+ DebugLogUtils.l("DownloadFinished with id", fileId);
if (NOT_AN_ID == fileId) return; // Spurious wake-up: ignore
final DownloadManager manager =
@@ -428,7 +428,7 @@ public final class UpdateHandler {
final ArrayList<DownloadRecord> recordList =
getDownloadRecordsForCompletedDownloadInfo(context, downloadInfo);
if (null == recordList) return; // It was someone else's download.
- LogUtils.l("Received result for download ", fileId);
+ DebugLogUtils.l("Received result for download ", fileId);
// TODO: handle gracefully a null pointer here. This is practically impossible because
// we come here only when DownloadManager explicitly called us when it ended a
@@ -505,7 +505,7 @@ public final class UpdateHandler {
private static void publishUpdateCycleCompletedEvent(final Context context) {
// Even if this is not successful, we have to publish the new state.
PrivateLog.log("Publishing update cycle completed event");
- LogUtils.l("Publishing update cycle completed event");
+ DebugLogUtils.l("Publishing update cycle completed event");
for (UpdateEventListener listener : linkedCopyOfList(sUpdateEventListeners)) {
listener.updateCycleCompleted();
}
@@ -519,12 +519,12 @@ public final class UpdateHandler {
// {@link handleWordList(Context,InputStream,ContentValues)}.
// Handle the downloaded file according to its type
if (downloadRecord.isMetadata()) {
- LogUtils.l("Data D/L'd is metadata for", downloadRecord.mClientId);
+ DebugLogUtils.l("Data D/L'd is metadata for", downloadRecord.mClientId);
// #handleMetadata() closes its InputStream argument
handleMetadata(context, new ParcelFileDescriptor.AutoCloseInputStream(
manager.openDownloadedFile(fileId)), downloadRecord.mClientId);
} else {
- LogUtils.l("Data D/L'd is a word list");
+ DebugLogUtils.l("Data D/L'd is a word list");
final int wordListStatus = downloadRecord.mAttributes.getAsInteger(
MetadataDbHelper.STATUS_COLUMN);
if (MetadataDbHelper.STATUS_DOWNLOADING == wordListStatus) {
@@ -584,7 +584,7 @@ public final class UpdateHandler {
*/
private static void handleMetadata(final Context context, final InputStream stream,
final String clientId) throws IOException, BadFormatException {
- LogUtils.l("Entering handleMetadata");
+ DebugLogUtils.l("Entering handleMetadata");
final List<WordListMetadata> newMetadata;
final InputStreamReader reader = new InputStreamReader(stream);
try {
@@ -594,7 +594,7 @@ public final class UpdateHandler {
reader.close();
}
- LogUtils.l("Downloaded metadata :", newMetadata);
+ DebugLogUtils.l("Downloaded metadata :", newMetadata);
PrivateLog.log("Downloaded metadata\n" + newMetadata);
final ActionBatch actions = computeUpgradeTo(context, clientId, newMetadata);
@@ -619,7 +619,7 @@ public final class UpdateHandler {
// DownloadManager does not have the ability to put the file directly where we want
// it, so we had it download to a temporary place. Now we move it. It will be deleted
// automatically by DownloadManager.
- LogUtils.l("Downloaded a new word list :", downloadRecord.mAttributes.getAsString(
+ DebugLogUtils.l("Downloaded a new word list :", downloadRecord.mAttributes.getAsString(
MetadataDbHelper.DESCRIPTION_COLUMN), "for", downloadRecord.mClientId);
PrivateLog.log("Downloaded a new word list with description : "
+ downloadRecord.mAttributes.getAsString(MetadataDbHelper.DESCRIPTION_COLUMN)
@@ -678,9 +678,9 @@ public final class UpdateHandler {
*/
private static void copyFile(final InputStream in, final OutputStream out)
throws IOException {
- LogUtils.l("Copying files");
+ DebugLogUtils.l("Copying files");
if (!(in instanceof FileInputStream) || !(out instanceof FileOutputStream)) {
- LogUtils.l("Not the right types");
+ DebugLogUtils.l("Not the right types");
copyFileFallback(in, out);
} else {
try {
@@ -689,7 +689,7 @@ public final class UpdateHandler {
sourceChannel.transferTo(0, Integer.MAX_VALUE, destinationChannel);
} catch (IOException e) {
// Can't work with channels, or something went wrong. Copy by hand.
- LogUtils.l("Won't work");
+ DebugLogUtils.l("Won't work");
copyFileFallback(in, out);
}
}
@@ -704,7 +704,7 @@ public final class UpdateHandler {
*/
private static void copyFileFallback(final InputStream in, final OutputStream out)
throws IOException {
- LogUtils.l("Falling back to slow copy");
+ DebugLogUtils.l("Falling back to slow copy");
final byte[] buffer = new byte[FILE_COPY_BUFFER_SIZE];
for (int readBytes = in.read(buffer); readBytes >= 0; readBytes = in.read(buffer))
out.write(buffer, 0, readBytes);
@@ -719,10 +719,10 @@ public final class UpdateHandler {
*/
private static String getTempFileName(final Context context, final String locale)
throws IOException {
- LogUtils.l("Entering openTempFileOutput");
+ DebugLogUtils.l("Entering openTempFileOutput");
final File dir = context.getFilesDir();
final File f = File.createTempFile(locale + "___", DICT_FILE_SUFFIX, dir);
- LogUtils.l("File name is", f.getName());
+ DebugLogUtils.l("File name is", f.getName());
return f.getName();
}
@@ -743,7 +743,7 @@ public final class UpdateHandler {
final String clientId, List<WordListMetadata> from, List<WordListMetadata> to) {
final ActionBatch actions = new ActionBatch();
// Upgrade existing word lists
- LogUtils.l("Comparing dictionaries");
+ DebugLogUtils.l("Comparing dictionaries");
final Set<String> wordListIds = new TreeSet<String>();
// TODO: Can these be null?
if (null == from) from = new ArrayList<WordListMetadata>();
@@ -758,7 +758,7 @@ public final class UpdateHandler {
final WordListMetadata newInfo = null == metadataInfo
|| metadataInfo.mFormatVersion > MAXIMUM_SUPPORTED_FORMAT_VERSION
? null : metadataInfo;
- LogUtils.l("Considering updating ", id, "currentInfo =", currentInfo);
+ DebugLogUtils.l("Considering updating ", id, "currentInfo =", currentInfo);
if (null == currentInfo && null == newInfo) {
// This may happen if a new word list appeared that we can't handle.