am 1aab945b: am c3f47836: Add an additional ID to the client info.

* commit '1aab945b2ac1a1232f1cdcb843251f93ad1c3232':
  Add an additional ID to the client info.
main
Jean Chalard 2013-05-15 10:58:39 -07:00 committed by Android Git Automerger
commit 5fe03e939f
4 changed files with 110 additions and 25 deletions

View File

@ -45,16 +45,16 @@ public class MetadataDbHelper extends SQLiteOpenHelper {
private static final int METADATA_DATABASE_INITIAL_VERSION = 3; private static final int METADATA_DATABASE_INITIAL_VERSION = 3;
// This is the first released version of the database that implements CLIENTID. It is // This is the first released version of the database that implements CLIENTID. It is
// used to identify the versions for upgrades. This should never change going forward. // used to identify the versions for upgrades. This should never change going forward.
private static final int METADATA_DATABASE_VERSION_WITH_CLIENTID = 5; private static final int METADATA_DATABASE_VERSION_WITH_CLIENTID = 6;
// This is the current database version. It should be updated when the database schema // This is the current database version. It should be updated when the database schema
// gets updated. It is passed to the framework constructor of SQLiteOpenHelper, so // gets updated. It is passed to the framework constructor of SQLiteOpenHelper, so
// that's what the framework uses to track our database version. // that's what the framework uses to track our database version.
private static final int METADATA_DATABASE_VERSION = 5; private static final int METADATA_DATABASE_VERSION = 6;
private final static long NOT_A_DOWNLOAD_ID = -1; private final static long NOT_A_DOWNLOAD_ID = -1;
public static final String METADATA_TABLE_NAME = "pendingUpdates"; public static final String METADATA_TABLE_NAME = "pendingUpdates";
private static final String CLIENT_TABLE_NAME = "clients"; static final String CLIENT_TABLE_NAME = "clients";
public static final String PENDINGID_COLUMN = "pendingid"; // Download Manager ID public static final String PENDINGID_COLUMN = "pendingid"; // Download Manager ID
public static final String TYPE_COLUMN = "type"; public static final String TYPE_COLUMN = "type";
public static final String STATUS_COLUMN = "status"; public static final String STATUS_COLUMN = "status";
@ -73,6 +73,7 @@ public class MetadataDbHelper extends SQLiteOpenHelper {
private static final String CLIENT_CLIENT_ID_COLUMN = "clientid"; private static final String CLIENT_CLIENT_ID_COLUMN = "clientid";
private static final String CLIENT_METADATA_URI_COLUMN = "uri"; private static final String CLIENT_METADATA_URI_COLUMN = "uri";
private static final String CLIENT_METADATA_ADDITIONAL_ID_COLUMN = "additionalid";
private static final String CLIENT_LAST_UPDATE_DATE_COLUMN = "lastupdate"; private static final String CLIENT_LAST_UPDATE_DATE_COLUMN = "lastupdate";
private static final String CLIENT_PENDINGID_COLUMN = "pendingid"; // Download Manager ID private static final String CLIENT_PENDINGID_COLUMN = "pendingid"; // Download Manager ID
@ -128,6 +129,7 @@ public class MetadataDbHelper extends SQLiteOpenHelper {
"CREATE TABLE IF NOT EXISTS " + CLIENT_TABLE_NAME + " (" "CREATE TABLE IF NOT EXISTS " + CLIENT_TABLE_NAME + " ("
+ CLIENT_CLIENT_ID_COLUMN + " TEXT, " + CLIENT_CLIENT_ID_COLUMN + " TEXT, "
+ CLIENT_METADATA_URI_COLUMN + " TEXT, " + CLIENT_METADATA_URI_COLUMN + " TEXT, "
+ CLIENT_METADATA_ADDITIONAL_ID_COLUMN + " TEXT, "
+ CLIENT_LAST_UPDATE_DATE_COLUMN + " INTEGER NOT NULL DEFAULT 0, " + CLIENT_LAST_UPDATE_DATE_COLUMN + " INTEGER NOT NULL DEFAULT 0, "
+ CLIENT_PENDINGID_COLUMN + " INTEGER, " + CLIENT_PENDINGID_COLUMN + " INTEGER, "
+ FLAGS_COLUMN + " INTEGER, " + FLAGS_COLUMN + " INTEGER, "
@ -282,14 +284,15 @@ public class MetadataDbHelper extends SQLiteOpenHelper {
* @return the string representation of the URI * @return the string representation of the URI
*/ */
public static String getMetadataUriAsString(final Context context, final String clientId) { public static String getMetadataUriAsString(final Context context, final String clientId) {
SQLiteDatabase defaultDb = getDb(context, null); SQLiteDatabase defaultDb = MetadataDbHelper.getDb(context, null);
final Cursor cursor = defaultDb.query(CLIENT_TABLE_NAME, final Cursor cursor = defaultDb.query(MetadataDbHelper.CLIENT_TABLE_NAME,
new String[] { CLIENT_METADATA_URI_COLUMN }, new String[] { MetadataDbHelper.CLIENT_METADATA_URI_COLUMN,
CLIENT_CLIENT_ID_COLUMN + " = ?", new String[] { clientId }, MetadataDbHelper.CLIENT_METADATA_ADDITIONAL_ID_COLUMN },
MetadataDbHelper.CLIENT_CLIENT_ID_COLUMN + " = ?", new String[] { clientId },
null, null, null, null); null, null, null, null);
try { try {
if (!cursor.moveToFirst()) return null; if (!cursor.moveToFirst()) return null;
return cursor.getString(0); // Only one column, return it return MetadataUriGetter.getUri(context, cursor.getString(0), cursor.getString(1));
} finally { } finally {
cursor.close(); cursor.close();
} }
@ -298,7 +301,8 @@ public class MetadataDbHelper extends SQLiteOpenHelper {
/** /**
* Update the last metadata update time for all clients using a particular URI. * Update the last metadata update time for all clients using a particular URI.
* *
* All clients using this metadata URI will be indicated as having been updated now. * This method searches for all clients using a particular URI and updates the last
* update time for this client.
* The current time is used as the latest update time. This saved date will be what * The current time is used as the latest update time. This saved date will be what
* is returned henceforth by {@link #getLastUpdateDateForClient(Context, String)}, * is returned henceforth by {@link #getLastUpdateDateForClient(Context, String)},
* until this method is called again. * until this method is called again.
@ -311,8 +315,22 @@ public class MetadataDbHelper extends SQLiteOpenHelper {
final ContentValues values = new ContentValues(); final ContentValues values = new ContentValues();
values.put(CLIENT_LAST_UPDATE_DATE_COLUMN, System.currentTimeMillis()); values.put(CLIENT_LAST_UPDATE_DATE_COLUMN, System.currentTimeMillis());
final SQLiteDatabase defaultDb = getDb(context, null); final SQLiteDatabase defaultDb = getDb(context, null);
defaultDb.update(CLIENT_TABLE_NAME, values, final Cursor cursor = MetadataDbHelper.queryClientIds(context);
CLIENT_METADATA_URI_COLUMN + " = ?", new String[] { uri }); if (null == cursor) return;
try {
if (!cursor.moveToFirst()) return;
do {
final String clientId = cursor.getString(0);
final String metadataUri =
MetadataDbHelper.getMetadataUriAsString(context, clientId);
if (metadataUri.equals(uri)) {
defaultDb.update(CLIENT_TABLE_NAME, values,
CLIENT_CLIENT_ID_COLUMN + " = ?", new String[] { clientId });
}
} while (cursor.moveToNext());
} finally {
cursor.close();
}
} }
/** /**
@ -727,11 +745,13 @@ public class MetadataDbHelper extends SQLiteOpenHelper {
/** /**
* Updates information relative to a specific client. * Updates information relative to a specific client.
* *
* Updatable information includes only the metadata URI, but may be expanded in the future. * Updatable information includes the metadata URI and the additional ID column. It may be
* expanded in the future.
* The passed values must include a client ID in the key CLIENT_CLIENT_ID_COLUMN, and it must * The passed values must include a client ID in the key CLIENT_CLIENT_ID_COLUMN, and it must
* be equal to the string passed as an argument for clientId. * be equal to the string passed as an argument for clientId. It may not be empty.
* The passed values must also include a non-empty metadata URI in the * The passed values must also include a non-null metadata URI in the
* CLIENT_METADATA_URI_COLUMN column. * CLIENT_METADATA_URI_COLUMN column, as well as a non-null additional ID in the
* CLIENT_METADATA_ADDITIONAL_ID_COLUMN. Both these strings may be empty.
* If any of the above is not complied with, this function returns without updating data. * If any of the above is not complied with, this function returns without updating data.
* *
* @param context the context, to open the database * @param context the context, to open the database
@ -743,10 +763,16 @@ public class MetadataDbHelper extends SQLiteOpenHelper {
// Sanity check the content values // Sanity check the content values
final String valuesClientId = values.getAsString(CLIENT_CLIENT_ID_COLUMN); final String valuesClientId = values.getAsString(CLIENT_CLIENT_ID_COLUMN);
final String valuesMetadataUri = values.getAsString(CLIENT_METADATA_URI_COLUMN); final String valuesMetadataUri = values.getAsString(CLIENT_METADATA_URI_COLUMN);
// Empty string is a valid client ID, but external apps may not configure it. final String valuesMetadataAdditionalId =
// Empty string is a valid metadata URI if the client does not want updates. values.getAsString(CLIENT_METADATA_ADDITIONAL_ID_COLUMN);
if (TextUtils.isEmpty(valuesClientId) || null == valuesMetadataUri) { // Empty string is a valid client ID, but external apps may not configure it, so disallow
// We need both these columns to be filled in // both null and empty string.
// Empty string is a valid metadata URI if the client does not want updates, so allow
// empty string but disallow null.
// Empty string is a valid additional ID so allow empty string but disallow null.
if (TextUtils.isEmpty(valuesClientId) || null == valuesMetadataUri
|| null == valuesMetadataAdditionalId) {
// We need all these columns to be filled in
Utils.l("Missing parameter for updateClientInfo"); Utils.l("Missing parameter for updateClientInfo");
return; return;
} }
@ -777,8 +803,9 @@ public class MetadataDbHelper extends SQLiteOpenHelper {
* Register a download ID for a specific metadata URI. * Register a download ID for a specific metadata URI.
* *
* This method should be called when a download for a metadata URI is starting. It will * This method should be called when a download for a metadata URI is starting. It will
* register the download ID for all clients using this metadata URI into the database * search for all clients using this metadata URI and will register for each of them
* for later retrieval by {@link #getDownloadRecordsForDownloadId(Context, long)}. * the download ID into the database for later retrieval by
* {@link #getDownloadRecordsForDownloadId(Context, long)}.
* *
* @param context a context for opening databases * @param context a context for opening databases
* @param uri the metadata URI * @param uri the metadata URI
@ -789,8 +816,22 @@ public class MetadataDbHelper extends SQLiteOpenHelper {
final ContentValues values = new ContentValues(); final ContentValues values = new ContentValues();
values.put(CLIENT_PENDINGID_COLUMN, downloadId); values.put(CLIENT_PENDINGID_COLUMN, downloadId);
final SQLiteDatabase defaultDb = getDb(context, ""); final SQLiteDatabase defaultDb = getDb(context, "");
defaultDb.update(CLIENT_TABLE_NAME, values, final Cursor cursor = MetadataDbHelper.queryClientIds(context);
CLIENT_METADATA_URI_COLUMN + " = ?", new String[] { uri }); if (null == cursor) return;
try {
if (!cursor.moveToFirst()) return;
do {
final String clientId = cursor.getString(0);
final String metadataUri =
MetadataDbHelper.getMetadataUriAsString(context, clientId);
if (metadataUri.equals(uri)) {
defaultDb.update(CLIENT_TABLE_NAME, values,
CLIENT_CLIENT_ID_COLUMN + " = ?", new String[] { clientId });
}
} while (cursor.moveToNext());
} finally {
cursor.close();
}
} }
/** /**

View File

@ -0,0 +1,33 @@
/*
* Copyright (C) 2013 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.android.inputmethod.dictionarypack;
import android.content.Context;
/**
* Helper to get the metadata URI from its base URI and the additional ID, if any.
*/
public class MetadataUriGetter {
private MetadataUriGetter() {
// This helper class is not instantiable.
}
public static String getUri(final Context context, final String baseUri,
final String additionalId) {
return baseUri;
}
}

View File

@ -81,6 +81,7 @@ public final class BinaryDictionaryFileDumper {
private static final String QUERY_PATH_METADATA = "metadata"; private static final String QUERY_PATH_METADATA = "metadata";
private static final String INSERT_METADATA_CLIENT_ID_COLUMN = "clientid"; private static final String INSERT_METADATA_CLIENT_ID_COLUMN = "clientid";
private static final String INSERT_METADATA_METADATA_URI_COLUMN = "uri"; private static final String INSERT_METADATA_METADATA_URI_COLUMN = "uri";
private static final String INSERT_METADATA_METADATA_ADDITIONAL_ID_COLUMN = "additionalid";
// Prevents this class to be accidentally instantiated. // Prevents this class to be accidentally instantiated.
private BinaryDictionaryFileDumper() { private BinaryDictionaryFileDumper() {
@ -423,6 +424,7 @@ public final class BinaryDictionaryFileDumper {
private static void reinitializeClientRecordInDictionaryContentProvider(final Context context, private static void reinitializeClientRecordInDictionaryContentProvider(final Context context,
final ContentProviderClient client, final String clientId) throws RemoteException { final ContentProviderClient client, final String clientId) throws RemoteException {
final String metadataFileUri = MetadataFileUriGetter.getMetadataUri(context); final String metadataFileUri = MetadataFileUriGetter.getMetadataUri(context);
final String metadataAdditionalId = MetadataFileUriGetter.getMetadataAdditionalId(context);
if (TextUtils.isEmpty(metadataFileUri)) return; if (TextUtils.isEmpty(metadataFileUri)) return;
// Tell the content provider to reset all information about this client id // Tell the content provider to reset all information about this client id
final Uri metadataContentUri = getProviderUriBuilder(clientId) final Uri metadataContentUri = getProviderUriBuilder(clientId)
@ -434,6 +436,7 @@ public final class BinaryDictionaryFileDumper {
final ContentValues metadataValues = new ContentValues(); final ContentValues metadataValues = new ContentValues();
metadataValues.put(INSERT_METADATA_CLIENT_ID_COLUMN, clientId); metadataValues.put(INSERT_METADATA_CLIENT_ID_COLUMN, clientId);
metadataValues.put(INSERT_METADATA_METADATA_URI_COLUMN, metadataFileUri); metadataValues.put(INSERT_METADATA_METADATA_URI_COLUMN, metadataFileUri);
metadataValues.put(INSERT_METADATA_METADATA_ADDITIONAL_ID_COLUMN, metadataAdditionalId);
client.insert(metadataContentUri, metadataValues); client.insert(metadataContentUri, metadataValues);
// Update the dictionary list. // Update the dictionary list.

View File

@ -19,10 +19,18 @@ package com.android.inputmethod.latin;
import android.content.Context; import android.content.Context;
/** /**
* Helper class to get the metadata URI. * Helper class to get the metadata URI and the additional ID.
*/ */
public class MetadataFileUriGetter { public class MetadataFileUriGetter {
public static String getMetadataUri(Context context) { private MetadataFileUriGetter() {
// This helper class is not instantiable.
}
public static String getMetadataUri(final Context context) {
return context.getString(R.string.dictionary_pack_metadata_uri); return context.getString(R.string.dictionary_pack_metadata_uri);
} }
public static String getMetadataAdditionalId(final Context context) {
return "";
}
} }