Merge "Cleanup under the utils package"

This commit is contained in:
Ken Wakasa 2013-06-25 08:20:56 +00:00 committed by Android (Google) Code Review
commit 12ef7d3702
8 changed files with 64 additions and 78 deletions

View File

@ -28,7 +28,7 @@ import android.util.Log;
import com.android.inputmethod.compat.DownloadManagerCompatUtils; import com.android.inputmethod.compat.DownloadManagerCompatUtils;
import com.android.inputmethod.latin.R; 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 com.android.inputmethod.latin.utils.Utils;
import java.util.LinkedList; import java.util.LinkedList;
@ -100,7 +100,7 @@ public final class ActionBatch {
final boolean mForceStartNow; final boolean mForceStartNow;
public StartDownloadAction(final String clientId, public StartDownloadAction(final String clientId,
final WordListMetadata wordList, final boolean forceStartNow) { final WordListMetadata wordList, final boolean forceStartNow) {
LogUtils.l("New download action for client ", clientId, " : ", wordList); DebugLogUtils.l("New download action for client ", clientId, " : ", wordList);
mClientId = clientId; mClientId = clientId;
mWordList = wordList; mWordList = wordList;
mForceStartNow = forceStartNow; mForceStartNow = forceStartNow;
@ -112,7 +112,7 @@ public final class ActionBatch {
Log.e(TAG, "UpdateAction with a null parameter!"); Log.e(TAG, "UpdateAction with a null parameter!");
return; return;
} }
LogUtils.l("Downloading word list"); DebugLogUtils.l("Downloading word list");
final SQLiteDatabase db = MetadataDbHelper.getDb(context, mClientId); final SQLiteDatabase db = MetadataDbHelper.getDb(context, mClientId);
final ContentValues values = MetadataDbHelper.getContentValuesByWordListId(db, final ContentValues values = MetadataDbHelper.getContentValuesByWordListId(db,
mWordList.mId, mWordList.mVersion); mWordList.mId, mWordList.mVersion);
@ -134,7 +134,7 @@ public final class ActionBatch {
+ " for an upgrade action. Fall back to download."); + " for an upgrade action. Fall back to download.");
} }
// Download it. // Download it.
LogUtils.l("Upgrade word list, downloading", mWordList.mRemoteFilename); DebugLogUtils.l("Upgrade word list, downloading", mWordList.mRemoteFilename);
// TODO: if DownloadManager is disabled or not installed, download by ourselves // TODO: if DownloadManager is disabled or not installed, download by ourselves
if (null == manager) return; if (null == manager) return;
@ -180,7 +180,7 @@ public final class ActionBatch {
final long downloadId = UpdateHandler.registerDownloadRequest(manager, request, db, final long downloadId = UpdateHandler.registerDownloadRequest(manager, request, db,
mWordList.mId, mWordList.mVersion); mWordList.mId, mWordList.mVersion);
LogUtils.l("Starting download of", uri, "with id", downloadId); DebugLogUtils.l("Starting download of", uri, "with id", downloadId);
PrivateLog.log("Starting download of " + uri + ", id : " + downloadId); PrivateLog.log("Starting download of " + uri + ", id : " + downloadId);
} }
} }
@ -197,7 +197,7 @@ public final class ActionBatch {
public InstallAfterDownloadAction(final String clientId, public InstallAfterDownloadAction(final String clientId,
final ContentValues wordListValues) { final ContentValues wordListValues) {
LogUtils.l("New InstallAfterDownloadAction for client ", clientId, " : ", DebugLogUtils.l("New InstallAfterDownloadAction for client ", clientId, " : ",
wordListValues); wordListValues);
mClientId = clientId; mClientId = clientId;
mWordListValues = wordListValues; mWordListValues = wordListValues;
@ -216,7 +216,7 @@ public final class ActionBatch {
+ " for an InstallAfterDownload action. Bailing out."); + " for an InstallAfterDownload action. Bailing out.");
return; return;
} }
LogUtils.l("Setting word list as installed"); DebugLogUtils.l("Setting word list as installed");
final SQLiteDatabase db = MetadataDbHelper.getDb(context, mClientId); final SQLiteDatabase db = MetadataDbHelper.getDb(context, mClientId);
MetadataDbHelper.markEntryAsFinishedDownloadingAndInstalled(db, mWordListValues); MetadataDbHelper.markEntryAsFinishedDownloadingAndInstalled(db, mWordListValues);
} }
@ -232,7 +232,7 @@ public final class ActionBatch {
final WordListMetadata mWordList; final WordListMetadata mWordList;
public EnableAction(final String clientId, final WordListMetadata wordList) { public EnableAction(final String clientId, final WordListMetadata wordList) {
LogUtils.l("New EnableAction for client ", clientId, " : ", wordList); DebugLogUtils.l("New EnableAction for client ", clientId, " : ", wordList);
mClientId = clientId; mClientId = clientId;
mWordList = wordList; mWordList = wordList;
} }
@ -243,7 +243,7 @@ public final class ActionBatch {
Log.e(TAG, "EnableAction with a null parameter!"); Log.e(TAG, "EnableAction with a null parameter!");
return; return;
} }
LogUtils.l("Enabling word list"); DebugLogUtils.l("Enabling word list");
final SQLiteDatabase db = MetadataDbHelper.getDb(context, mClientId); final SQLiteDatabase db = MetadataDbHelper.getDb(context, mClientId);
final ContentValues values = MetadataDbHelper.getContentValuesByWordListId(db, final ContentValues values = MetadataDbHelper.getContentValuesByWordListId(db,
mWordList.mId, mWordList.mVersion); mWordList.mId, mWordList.mVersion);
@ -267,7 +267,7 @@ public final class ActionBatch {
// The word list to disable. May not be null. // The word list to disable. May not be null.
final WordListMetadata mWordList; final WordListMetadata mWordList;
public DisableAction(final String clientId, final WordListMetadata wordlist) { public DisableAction(final String clientId, final WordListMetadata wordlist) {
LogUtils.l("New Disable action for client ", clientId, " : ", wordlist); DebugLogUtils.l("New Disable action for client ", clientId, " : ", wordlist);
mClientId = clientId; mClientId = clientId;
mWordList = wordlist; mWordList = wordlist;
} }
@ -278,7 +278,7 @@ public final class ActionBatch {
Log.e(TAG, "DisableAction with a null word list!"); Log.e(TAG, "DisableAction with a null word list!");
return; return;
} }
LogUtils.l("Disabling word list : " + mWordList); DebugLogUtils.l("Disabling word list : " + mWordList);
final SQLiteDatabase db = MetadataDbHelper.getDb(context, mClientId); final SQLiteDatabase db = MetadataDbHelper.getDb(context, mClientId);
final ContentValues values = MetadataDbHelper.getContentValuesByWordListId(db, final ContentValues values = MetadataDbHelper.getContentValuesByWordListId(db,
mWordList.mId, mWordList.mVersion); mWordList.mId, mWordList.mVersion);
@ -314,7 +314,7 @@ public final class ActionBatch {
// The word list to make available. May not be null. // The word list to make available. May not be null.
final WordListMetadata mWordList; final WordListMetadata mWordList;
public MakeAvailableAction(final String clientId, final WordListMetadata wordlist) { public MakeAvailableAction(final String clientId, final WordListMetadata wordlist) {
LogUtils.l("New MakeAvailable action", clientId, " : ", wordlist); DebugLogUtils.l("New MakeAvailable action", clientId, " : ", wordlist);
mClientId = clientId; mClientId = clientId;
mWordList = wordlist; mWordList = wordlist;
} }
@ -331,7 +331,7 @@ public final class ActionBatch {
Log.e(TAG, "Unexpected state of the word list '" + mWordList.mId + "' " Log.e(TAG, "Unexpected state of the word list '" + mWordList.mId + "' "
+ " for a makeavailable action. Marking as available anyway."); + " for a makeavailable action. Marking as available anyway.");
} }
LogUtils.l("Making word list available : " + mWordList); DebugLogUtils.l("Making word list available : " + mWordList);
// If mLocalFilename is null, then it's a remote file that hasn't been downloaded // If mLocalFilename is null, then it's a remote file that hasn't been downloaded
// yet, so we set the local filename to the empty string. // yet, so we set the local filename to the empty string.
final ContentValues values = MetadataDbHelper.makeContentValues(0, final ContentValues values = MetadataDbHelper.makeContentValues(0,
@ -363,7 +363,7 @@ public final class ActionBatch {
// The word list to mark pre-installed. May not be null. // The word list to mark pre-installed. May not be null.
final WordListMetadata mWordList; final WordListMetadata mWordList;
public MarkPreInstalledAction(final String clientId, final WordListMetadata wordlist) { public MarkPreInstalledAction(final String clientId, final WordListMetadata wordlist) {
LogUtils.l("New MarkPreInstalled action", clientId, " : ", wordlist); DebugLogUtils.l("New MarkPreInstalled action", clientId, " : ", wordlist);
mClientId = clientId; mClientId = clientId;
mWordList = wordlist; mWordList = wordlist;
} }
@ -380,7 +380,7 @@ public final class ActionBatch {
Log.e(TAG, "Unexpected state of the word list '" + mWordList.mId + "' " Log.e(TAG, "Unexpected state of the word list '" + mWordList.mId + "' "
+ " for a markpreinstalled action. Marking as preinstalled anyway."); + " for a markpreinstalled action. Marking as preinstalled anyway.");
} }
LogUtils.l("Marking word list preinstalled : " + mWordList); DebugLogUtils.l("Marking word list preinstalled : " + mWordList);
// This word list is pre-installed : we don't have its file. We should reset // This word list is pre-installed : we don't have its file. We should reset
// the local file name to the empty string so that we don't try to open it // the local file name to the empty string so that we don't try to open it
// accidentally. The remote filename may be set by the application if it so wishes. // accidentally. The remote filename may be set by the application if it so wishes.
@ -404,7 +404,7 @@ public final class ActionBatch {
private final String mClientId; private final String mClientId;
final WordListMetadata mWordList; final WordListMetadata mWordList;
public UpdateDataAction(final String clientId, final WordListMetadata wordlist) { public UpdateDataAction(final String clientId, final WordListMetadata wordlist) {
LogUtils.l("New UpdateData action for client ", clientId, " : ", wordlist); DebugLogUtils.l("New UpdateData action for client ", clientId, " : ", wordlist);
mClientId = clientId; mClientId = clientId;
mWordList = wordlist; mWordList = wordlist;
} }
@ -422,7 +422,7 @@ public final class ActionBatch {
Log.e(TAG, "Trying to update data about a non-existing word list. Bailing out."); Log.e(TAG, "Trying to update data about a non-existing word list. Bailing out.");
return; return;
} }
LogUtils.l("Updating data about a word list : " + mWordList); DebugLogUtils.l("Updating data about a word list : " + mWordList);
final ContentValues values = MetadataDbHelper.makeContentValues( final ContentValues values = MetadataDbHelper.makeContentValues(
oldValues.getAsInteger(MetadataDbHelper.PENDINGID_COLUMN), oldValues.getAsInteger(MetadataDbHelper.PENDINGID_COLUMN),
oldValues.getAsInteger(MetadataDbHelper.TYPE_COLUMN), oldValues.getAsInteger(MetadataDbHelper.TYPE_COLUMN),
@ -456,7 +456,7 @@ public final class ActionBatch {
final boolean mHasNewerVersion; final boolean mHasNewerVersion;
public ForgetAction(final String clientId, final WordListMetadata wordlist, public ForgetAction(final String clientId, final WordListMetadata wordlist,
final boolean hasNewerVersion) { final boolean hasNewerVersion) {
LogUtils.l("New TryRemove action for client ", clientId, " : ", wordlist); DebugLogUtils.l("New TryRemove action for client ", clientId, " : ", wordlist);
mClientId = clientId; mClientId = clientId;
mWordList = wordlist; mWordList = wordlist;
mHasNewerVersion = hasNewerVersion; mHasNewerVersion = hasNewerVersion;
@ -468,7 +468,7 @@ public final class ActionBatch {
Log.e(TAG, "TryRemoveAction with a null word list!"); Log.e(TAG, "TryRemoveAction with a null word list!");
return; return;
} }
LogUtils.l("Trying to remove word list : " + mWordList); DebugLogUtils.l("Trying to remove word list : " + mWordList);
final SQLiteDatabase db = MetadataDbHelper.getDb(context, mClientId); final SQLiteDatabase db = MetadataDbHelper.getDb(context, mClientId);
final ContentValues values = MetadataDbHelper.getContentValuesByWordListId(db, final ContentValues values = MetadataDbHelper.getContentValuesByWordListId(db,
mWordList.mId, mWordList.mVersion); mWordList.mId, mWordList.mVersion);
@ -528,7 +528,7 @@ public final class ActionBatch {
// The word list to delete. May not be null. // The word list to delete. May not be null.
final WordListMetadata mWordList; final WordListMetadata mWordList;
public StartDeleteAction(final String clientId, final WordListMetadata wordlist) { public StartDeleteAction(final String clientId, final WordListMetadata wordlist) {
LogUtils.l("New StartDelete action for client ", clientId, " : ", wordlist); DebugLogUtils.l("New StartDelete action for client ", clientId, " : ", wordlist);
mClientId = clientId; mClientId = clientId;
mWordList = wordlist; mWordList = wordlist;
} }
@ -539,7 +539,7 @@ public final class ActionBatch {
Log.e(TAG, "StartDeleteAction with a null word list!"); Log.e(TAG, "StartDeleteAction with a null word list!");
return; return;
} }
LogUtils.l("Trying to delete word list : " + mWordList); DebugLogUtils.l("Trying to delete word list : " + mWordList);
final SQLiteDatabase db = MetadataDbHelper.getDb(context, mClientId); final SQLiteDatabase db = MetadataDbHelper.getDb(context, mClientId);
final ContentValues values = MetadataDbHelper.getContentValuesByWordListId(db, final ContentValues values = MetadataDbHelper.getContentValuesByWordListId(db,
mWordList.mId, mWordList.mVersion); mWordList.mId, mWordList.mVersion);
@ -567,7 +567,7 @@ public final class ActionBatch {
// The word list to delete. May not be null. // The word list to delete. May not be null.
final WordListMetadata mWordList; final WordListMetadata mWordList;
public FinishDeleteAction(final String clientId, final WordListMetadata wordlist) { public FinishDeleteAction(final String clientId, final WordListMetadata wordlist) {
LogUtils.l("New FinishDelete action for client", clientId, " : ", wordlist); DebugLogUtils.l("New FinishDelete action for client", clientId, " : ", wordlist);
mClientId = clientId; mClientId = clientId;
mWordList = wordlist; mWordList = wordlist;
} }
@ -578,7 +578,7 @@ public final class ActionBatch {
Log.e(TAG, "FinishDeleteAction with a null word list!"); Log.e(TAG, "FinishDeleteAction with a null word list!");
return; return;
} }
LogUtils.l("Trying to delete word list : " + mWordList); DebugLogUtils.l("Trying to delete word list : " + mWordList);
final SQLiteDatabase db = MetadataDbHelper.getDb(context, mClientId); final SQLiteDatabase db = MetadataDbHelper.getDb(context, mClientId);
final ContentValues values = MetadataDbHelper.getContentValuesByWordListId(db, final ContentValues values = MetadataDbHelper.getContentValuesByWordListId(db,
mWordList.mId, mWordList.mVersion); mWordList.mId, mWordList.mVersion);
@ -635,7 +635,7 @@ public final class ActionBatch {
* @param reporter a Reporter to send errors to. * @param reporter a Reporter to send errors to.
*/ */
public void execute(final Context context, final ProblemReporter reporter) { public void execute(final Context context, final ProblemReporter reporter) {
LogUtils.l("Executing a batch of actions"); DebugLogUtils.l("Executing a batch of actions");
Queue<Action> remainingActions = mActions; Queue<Action> remainingActions = mActions;
while (!remainingActions.isEmpty()) { while (!remainingActions.isEmpty()) {
final Action a = remainingActions.poll(); final Action a = remainingActions.poll();

View File

@ -31,7 +31,7 @@ import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.utils.LogUtils; import com.android.inputmethod.latin.utils.DebugLogUtils;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
@ -220,7 +220,7 @@ public final class DictionaryProvider extends ContentProvider {
@Override @Override
public Cursor query(final Uri uri, final String[] projection, final String selection, public Cursor query(final Uri uri, final String[] projection, final String selection,
final String[] selectionArgs, final String sortOrder) { final String[] selectionArgs, final String sortOrder) {
LogUtils.l("Uri =", uri); DebugLogUtils.l("Uri =", uri);
PrivateLog.log("Query : " + uri); PrivateLog.log("Query : " + uri);
final String clientId = getClientId(uri); final String clientId = getClientId(uri);
final int match = matchUri(uri); final int match = matchUri(uri);
@ -228,7 +228,7 @@ public final class DictionaryProvider extends ContentProvider {
case DICTIONARY_V1_WHOLE_LIST: case DICTIONARY_V1_WHOLE_LIST:
case DICTIONARY_V2_WHOLE_LIST: case DICTIONARY_V2_WHOLE_LIST:
final Cursor c = MetadataDbHelper.queryDictionaries(getContext(), clientId); final Cursor c = MetadataDbHelper.queryDictionaries(getContext(), clientId);
LogUtils.l("List of dictionaries with count", c.getCount()); DebugLogUtils.l("List of dictionaries with count", c.getCount());
PrivateLog.log("Returned a list of " + c.getCount() + " items"); PrivateLog.log("Returned a list of " + c.getCount() + " items");
return c; return c;
case DICTIONARY_V2_DICT_INFO: case DICTIONARY_V2_DICT_INFO:

View File

@ -25,7 +25,7 @@ import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.utils.LogUtils; import com.android.inputmethod.latin.utils.DebugLogUtils;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
@ -773,13 +773,13 @@ public class MetadataDbHelper extends SQLiteOpenHelper {
if (TextUtils.isEmpty(valuesClientId) || null == valuesMetadataUri if (TextUtils.isEmpty(valuesClientId) || null == valuesMetadataUri
|| null == valuesMetadataAdditionalId) { || null == valuesMetadataAdditionalId) {
// We need all these columns to be filled in // We need all these columns to be filled in
LogUtils.l("Missing parameter for updateClientInfo"); DebugLogUtils.l("Missing parameter for updateClientInfo");
return; return;
} }
if (!clientId.equals(valuesClientId)) { if (!clientId.equals(valuesClientId)) {
// Mismatch! The client violates the protocol. // Mismatch! The client violates the protocol.
LogUtils.l("Received an updateClientInfo request for ", clientId, " but the values " DebugLogUtils.l("Received an updateClientInfo request for ", clientId,
+ "contain a different ID : ", valuesClientId); " but the values " + "contain a different ID : ", valuesClientId);
return; return;
} }
final SQLiteDatabase defaultDb = getDb(context, ""); final SQLiteDatabase defaultDb = getDb(context, "");
@ -848,7 +848,7 @@ public class MetadataDbHelper extends SQLiteOpenHelper {
final ContentValues r) { final ContentValues r) {
switch (r.getAsInteger(TYPE_COLUMN)) { switch (r.getAsInteger(TYPE_COLUMN)) {
case TYPE_BULK: case TYPE_BULK:
LogUtils.l("Ended processing a wordlist"); DebugLogUtils.l("Ended processing a wordlist");
// Updating a bulk word list is a three-step operation: // Updating a bulk word list is a three-step operation:
// - Add the new entry to the table // - Add the new entry to the table
// - Remove the old entry from the table // - Remove the old entry from the table
@ -870,7 +870,7 @@ public class MetadataDbHelper extends SQLiteOpenHelper {
// the phone is suddenly cut during an update. // the phone is suddenly cut during an update.
final int filenameIndex = c.getColumnIndex(LOCAL_FILENAME_COLUMN); final int filenameIndex = c.getColumnIndex(LOCAL_FILENAME_COLUMN);
do { do {
LogUtils.l("Setting for removal", c.getString(filenameIndex)); DebugLogUtils.l("Setting for removal", c.getString(filenameIndex));
filenames.add(c.getString(filenameIndex)); filenames.add(c.getString(filenameIndex));
} while (c.moveToNext()); } while (c.moveToNext());
} }

View File

@ -38,7 +38,7 @@ import android.util.Log;
import com.android.inputmethod.compat.ConnectivityManagerCompatUtils; import com.android.inputmethod.compat.ConnectivityManagerCompatUtils;
import com.android.inputmethod.compat.DownloadManagerCompatUtils; import com.android.inputmethod.compat.DownloadManagerCompatUtils;
import com.android.inputmethod.latin.R; 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 com.android.inputmethod.latin.utils.Utils;
import java.io.File; import java.io.File;
@ -185,8 +185,8 @@ public final class UpdateHandler {
final String clientId = cursor.getString(0); final String clientId = cursor.getString(0);
final String metadataUri = final String metadataUri =
MetadataDbHelper.getMetadataUriAsString(context, clientId); MetadataDbHelper.getMetadataUriAsString(context, clientId);
PrivateLog.log("Update for clientId " + LogUtils.s(clientId)); PrivateLog.log("Update for clientId " + DebugLogUtils.s(clientId));
LogUtils.l("Update for clientId", clientId, " which uses URI ", metadataUri); DebugLogUtils.l("Update for clientId", clientId, " which uses URI ", metadataUri);
uris.add(metadataUri); uris.add(metadataUri);
} while (cursor.moveToNext()); } while (cursor.moveToNext());
} finally { } finally {
@ -213,14 +213,14 @@ public final class UpdateHandler {
*/ */
private static void updateClientsWithMetadataUri(final Context context, private static void updateClientsWithMetadataUri(final Context context,
final boolean updateNow, final String metadataUri) { 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. // 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 // DownloadManager also stupidly cuts the extension to replace with its own that it
// gets from the content-type. We need to circumvent this. // gets from the content-type. We need to circumvent this.
final String disambiguator = "#" + System.currentTimeMillis() final String disambiguator = "#" + System.currentTimeMillis()
+ Utils.getVersionName(context) + ".json"; + Utils.getVersionName(context) + ".json";
final Request metadataRequest = new Request(Uri.parse(metadataUri + disambiguator)); final Request metadataRequest = new Request(Uri.parse(metadataUri + disambiguator));
LogUtils.l("Request =", metadataRequest); DebugLogUtils.l("Request =", metadataRequest);
final Resources res = context.getResources(); final Resources res = context.getResources();
// By default, download over roaming is allowed and all network types are allowed too. // 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; final long downloadId;
synchronized (sSharedIdProtector) { synchronized (sSharedIdProtector) {
downloadId = manager.enqueue(metadataRequest); 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 // 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 // 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 // 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, public static long registerDownloadRequest(final DownloadManager manager, final Request request,
final SQLiteDatabase db, final String id, final int version) { 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; final long downloadId;
synchronized (sSharedIdProtector) { synchronized (sSharedIdProtector) {
downloadId = manager.enqueue(request); downloadId = manager.enqueue(request);
LogUtils.l("Download requested with id", downloadId); DebugLogUtils.l("Download requested with id", downloadId);
MetadataDbHelper.markEntryAsDownloading(db, id, version, downloadId); MetadataDbHelper.markEntryAsDownloading(db, id, version, downloadId);
} }
return downloadId; return downloadId;
@ -418,7 +418,7 @@ public final class UpdateHandler {
// Get and check the ID of the file that was downloaded // Get and check the ID of the file that was downloaded
final long fileId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, NOT_AN_ID); final long fileId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, NOT_AN_ID);
PrivateLog.log("Download finished with id " + fileId); 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 if (NOT_AN_ID == fileId) return; // Spurious wake-up: ignore
final DownloadManager manager = final DownloadManager manager =
@ -428,7 +428,7 @@ public final class UpdateHandler {
final ArrayList<DownloadRecord> recordList = final ArrayList<DownloadRecord> recordList =
getDownloadRecordsForCompletedDownloadInfo(context, downloadInfo); getDownloadRecordsForCompletedDownloadInfo(context, downloadInfo);
if (null == recordList) return; // It was someone else's download. 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 // 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 // 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) { private static void publishUpdateCycleCompletedEvent(final Context context) {
// Even if this is not successful, we have to publish the new state. // Even if this is not successful, we have to publish the new state.
PrivateLog.log("Publishing update cycle completed event"); 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)) { for (UpdateEventListener listener : linkedCopyOfList(sUpdateEventListeners)) {
listener.updateCycleCompleted(); listener.updateCycleCompleted();
} }
@ -519,12 +519,12 @@ public final class UpdateHandler {
// {@link handleWordList(Context,InputStream,ContentValues)}. // {@link handleWordList(Context,InputStream,ContentValues)}.
// Handle the downloaded file according to its type // Handle the downloaded file according to its type
if (downloadRecord.isMetadata()) { 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() closes its InputStream argument
handleMetadata(context, new ParcelFileDescriptor.AutoCloseInputStream( handleMetadata(context, new ParcelFileDescriptor.AutoCloseInputStream(
manager.openDownloadedFile(fileId)), downloadRecord.mClientId); manager.openDownloadedFile(fileId)), downloadRecord.mClientId);
} else { } 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( final int wordListStatus = downloadRecord.mAttributes.getAsInteger(
MetadataDbHelper.STATUS_COLUMN); MetadataDbHelper.STATUS_COLUMN);
if (MetadataDbHelper.STATUS_DOWNLOADING == wordListStatus) { if (MetadataDbHelper.STATUS_DOWNLOADING == wordListStatus) {
@ -584,7 +584,7 @@ public final class UpdateHandler {
*/ */
private 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 { final String clientId) throws IOException, BadFormatException {
LogUtils.l("Entering handleMetadata"); DebugLogUtils.l("Entering handleMetadata");
final List<WordListMetadata> newMetadata; final List<WordListMetadata> newMetadata;
final InputStreamReader reader = new InputStreamReader(stream); final InputStreamReader reader = new InputStreamReader(stream);
try { try {
@ -594,7 +594,7 @@ public final class UpdateHandler {
reader.close(); reader.close();
} }
LogUtils.l("Downloaded metadata :", newMetadata); DebugLogUtils.l("Downloaded metadata :", newMetadata);
PrivateLog.log("Downloaded metadata\n" + newMetadata); PrivateLog.log("Downloaded metadata\n" + newMetadata);
final ActionBatch actions = computeUpgradeTo(context, clientId, 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 // 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 // it, so we had it download to a temporary place. Now we move it. It will be deleted
// automatically by DownloadManager. // 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); MetadataDbHelper.DESCRIPTION_COLUMN), "for", downloadRecord.mClientId);
PrivateLog.log("Downloaded a new word list with description : " PrivateLog.log("Downloaded a new word list with description : "
+ downloadRecord.mAttributes.getAsString(MetadataDbHelper.DESCRIPTION_COLUMN) + downloadRecord.mAttributes.getAsString(MetadataDbHelper.DESCRIPTION_COLUMN)
@ -678,9 +678,9 @@ public final class UpdateHandler {
*/ */
private static void copyFile(final InputStream in, final OutputStream out) private static void copyFile(final InputStream in, final OutputStream out)
throws IOException { throws IOException {
LogUtils.l("Copying files"); DebugLogUtils.l("Copying files");
if (!(in instanceof FileInputStream) || !(out instanceof FileOutputStream)) { if (!(in instanceof FileInputStream) || !(out instanceof FileOutputStream)) {
LogUtils.l("Not the right types"); DebugLogUtils.l("Not the right types");
copyFileFallback(in, out); copyFileFallback(in, out);
} else { } else {
try { try {
@ -689,7 +689,7 @@ public final class UpdateHandler {
sourceChannel.transferTo(0, Integer.MAX_VALUE, destinationChannel); sourceChannel.transferTo(0, Integer.MAX_VALUE, destinationChannel);
} catch (IOException e) { } catch (IOException e) {
// Can't work with channels, or something went wrong. Copy by hand. // 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); copyFileFallback(in, out);
} }
} }
@ -704,7 +704,7 @@ public final class UpdateHandler {
*/ */
private static void copyFileFallback(final InputStream in, final OutputStream out) private static void copyFileFallback(final InputStream in, final OutputStream out)
throws IOException { 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]; final byte[] buffer = new byte[FILE_COPY_BUFFER_SIZE];
for (int readBytes = in.read(buffer); readBytes >= 0; readBytes = in.read(buffer)) for (int readBytes = in.read(buffer); readBytes >= 0; readBytes = in.read(buffer))
out.write(buffer, 0, readBytes); out.write(buffer, 0, readBytes);
@ -719,10 +719,10 @@ public final class UpdateHandler {
*/ */
private static String getTempFileName(final Context context, final String locale) private static String getTempFileName(final Context context, final String locale)
throws IOException { throws IOException {
LogUtils.l("Entering openTempFileOutput"); DebugLogUtils.l("Entering openTempFileOutput");
final File dir = context.getFilesDir(); final File dir = context.getFilesDir();
final File f = File.createTempFile(locale + "___", DICT_FILE_SUFFIX, dir); 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(); return f.getName();
} }
@ -743,7 +743,7 @@ public final class UpdateHandler {
final String clientId, List<WordListMetadata> from, List<WordListMetadata> to) { final String clientId, List<WordListMetadata> from, List<WordListMetadata> to) {
final ActionBatch actions = new ActionBatch(); final ActionBatch actions = new ActionBatch();
// Upgrade existing word lists // Upgrade existing word lists
LogUtils.l("Comparing dictionaries"); DebugLogUtils.l("Comparing dictionaries");
final Set<String> wordListIds = new TreeSet<String>(); final Set<String> wordListIds = new TreeSet<String>();
// TODO: Can these be null? // TODO: Can these be null?
if (null == from) from = new ArrayList<WordListMetadata>(); if (null == from) from = new ArrayList<WordListMetadata>();
@ -758,7 +758,7 @@ public final class UpdateHandler {
final WordListMetadata newInfo = null == metadataInfo final WordListMetadata newInfo = null == metadataInfo
|| metadataInfo.mFormatVersion > MAXIMUM_SUPPORTED_FORMAT_VERSION || metadataInfo.mFormatVersion > MAXIMUM_SUPPORTED_FORMAT_VERSION
? null : metadataInfo; ? null : metadataInfo;
LogUtils.l("Considering updating ", id, "currentInfo =", currentInfo); DebugLogUtils.l("Considering updating ", id, "currentInfo =", currentInfo);
if (null == currentInfo && null == newInfo) { if (null == currentInfo && null == newInfo) {
// This may happen if a new word list appeared that we can't handle. // This may happen if a new word list appeared that we can't handle.

View File

@ -28,7 +28,7 @@ import android.view.inputmethod.InputConnection;
import com.android.inputmethod.latin.define.ProductionFlag; import com.android.inputmethod.latin.define.ProductionFlag;
import com.android.inputmethod.latin.utils.CapsModeUtils; import com.android.inputmethod.latin.utils.CapsModeUtils;
import com.android.inputmethod.latin.utils.LogUtils; import com.android.inputmethod.latin.utils.DebugLogUtils;
import com.android.inputmethod.latin.utils.StringUtils; import com.android.inputmethod.latin.utils.StringUtils;
import com.android.inputmethod.research.ResearchLogger; import com.android.inputmethod.research.ResearchLogger;
@ -107,7 +107,7 @@ public final class RichInputConnection {
+ "\nActual text = " + reference.length() + " " + reference; + "\nActual text = " + reference.length() + " " + reference;
((LatinIME)mParent).debugDumpStateAndCrashWithException(context); ((LatinIME)mParent).debugDumpStateAndCrashWithException(context);
} else { } else {
Log.e(TAG, LogUtils.getStackTrace(2)); Log.e(TAG, DebugLogUtils.getStackTrace(2));
Log.e(TAG, "Exp <> Actual : " + mCurrentCursorPosition + " <> " + et.selectionStart); Log.e(TAG, "Exp <> Actual : " + mCurrentCursorPosition + " <> " + et.selectionStart);
} }
} }
@ -156,7 +156,7 @@ public final class RichInputConnection {
if (mNestLevel != 1) { if (mNestLevel != 1) {
// TODO: exception instead // TODO: exception instead
Log.e(TAG, "Batch edit level incorrect : " + mNestLevel); Log.e(TAG, "Batch edit level incorrect : " + mNestLevel);
Log.e(TAG, LogUtils.getStackTrace(4)); Log.e(TAG, DebugLogUtils.getStackTrace(4));
} }
} }

View File

@ -26,9 +26,9 @@ import android.util.Log;
import android.view.inputmethod.InputMethodSubtype; import android.view.inputmethod.InputMethodSubtype;
import com.android.inputmethod.latin.utils.CollectionUtils; import com.android.inputmethod.latin.utils.CollectionUtils;
import com.android.inputmethod.latin.utils.DebugLogUtils;
import com.android.inputmethod.latin.utils.LocaleUtils; import com.android.inputmethod.latin.utils.LocaleUtils;
import com.android.inputmethod.latin.utils.LocaleUtils.RunInLocale; import com.android.inputmethod.latin.utils.LocaleUtils.RunInLocale;
import com.android.inputmethod.latin.utils.LogUtils;
import com.android.inputmethod.latin.utils.StringUtils; import com.android.inputmethod.latin.utils.StringUtils;
import java.util.HashMap; import java.util.HashMap;
@ -242,7 +242,7 @@ public final class SubtypeLocale {
+ " nameResId=" + subtype.getNameResId() + " nameResId=" + subtype.getNameResId()
+ " locale=" + subtype.getLocale() + " locale=" + subtype.getLocale()
+ " extra=" + subtype.getExtraValue() + " extra=" + subtype.getExtraValue()
+ "\n" + LogUtils.getStackTrace()); + "\n" + DebugLogUtils.getStackTrace());
return ""; return "";
} }
} }

View File

@ -23,8 +23,8 @@ import com.android.inputmethod.latin.LatinImeLogger;
/** /**
* A class for logging and debugging utility methods. * A class for logging and debugging utility methods.
*/ */
public final class LogUtils { public final class DebugLogUtils {
private final static String TAG = LogUtils.class.getSimpleName(); private final static String TAG = DebugLogUtils.class.getSimpleName();
private final static boolean sDBG = LatinImeLogger.sDBG; private final static boolean sDBG = LatinImeLogger.sDBG;
/** /**

View File

@ -63,20 +63,6 @@ public final class Utils {
// This utility class is not publicly instantiable. // This utility class is not publicly instantiable.
} }
/**
* Cancel an {@link AsyncTask}.
*
* @param mayInterruptIfRunning <tt>true</tt> if the thread executing this
* task should be interrupted; otherwise, in-progress tasks are allowed
* to complete.
*/
public static void cancelTask(final AsyncTask<?, ?, ?> task,
final boolean mayInterruptIfRunning) {
if (task != null && task.getStatus() != AsyncTask.Status.FINISHED) {
task.cancel(mayInterruptIfRunning);
}
}
// TODO: Make this an external class // TODO: Make this an external class
public /* for test */ static final class RingCharBuffer { public /* for test */ static final class RingCharBuffer {
public /* for test */ static final int BUFSIZE = 20; public /* for test */ static final int BUFSIZE = 20;