summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/com/android/photos/data/PhotoDatabase.java71
-rw-r--r--src/com/android/photos/data/PhotoProvider.java143
-rw-r--r--tests/src/com/android/photos/data/PhotoDatabaseTest.java83
-rw-r--r--tests/src/com/android/photos/data/PhotoDatabaseUtils.java48
-rw-r--r--tests/src/com/android/photos/data/PhotoProviderTest.java15
5 files changed, 238 insertions, 122 deletions
diff --git a/src/com/android/photos/data/PhotoDatabase.java b/src/com/android/photos/data/PhotoDatabase.java
index 35de185..8585edc 100644
--- a/src/com/android/photos/data/PhotoDatabase.java
+++ b/src/com/android/photos/data/PhotoDatabase.java
@@ -19,10 +19,14 @@ import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
+import com.android.photos.data.PhotoProvider.Accounts;
import com.android.photos.data.PhotoProvider.Albums;
import com.android.photos.data.PhotoProvider.Metadata;
import com.android.photos.data.PhotoProvider.Photos;
+import java.util.ArrayList;
+import java.util.List;
+
/**
* Used in PhotoProvider to create and access the database containing
* information about photo and video information stored on the server.
@@ -36,22 +40,32 @@ public class PhotoDatabase extends SQLiteOpenHelper {
private static final String[][] CREATE_PHOTO = {
{ Photos._ID, "INTEGER PRIMARY KEY AUTOINCREMENT" },
- { Photos.SERVER_ID, "INTEGER UNIQUE" },
+ // Photos.ACCOUNT_ID is a foreign key to Accounts._ID
+ { Photos.ACCOUNT_ID, "INTEGER NOT NULL" },
{ Photos.WIDTH, "INTEGER NOT NULL" },
{ Photos.HEIGHT, "INTEGER NOT NULL" },
{ Photos.DATE_TAKEN, "INTEGER NOT NULL" },
// Photos.ALBUM_ID is a foreign key to Albums._ID
{ Photos.ALBUM_ID, "INTEGER" },
{ Photos.MIME_TYPE, "TEXT NOT NULL" },
+ { Photos.TITLE, "TEXT" },
+ { Photos.DATE_MODIFIED, "INTEGER" },
+ { Photos.ROTATION, "INTEGER" },
};
private static final String[][] CREATE_ALBUM = {
{ Albums._ID, "INTEGER PRIMARY KEY AUTOINCREMENT" },
- // Albums.PARENT_ID is a foriegn key to Albums._ID
+ // Albums.ACCOUNT_ID is a foreign key to Accounts._ID
+ { Albums.ACCOUNT_ID, "INTEGER NOT NULL" },
+ // Albums.PARENT_ID is a foreign key to Albums._ID
{ Albums.PARENT_ID, "INTEGER" },
{ Albums.NAME, "Text NOT NULL" },
{ Albums.VISIBILITY, "INTEGER NOT NULL" },
- { Albums.SERVER_ID, "INTEGER UNIQUE" },
+ { Albums.LOCATION_STRING, "TEXT" },
+ { Albums.TITLE, "TEXT" },
+ { Albums.SUMMARY, "TEXT" },
+ { Albums.DATE_PUBLISHED, "INTEGER" },
+ { Albums.DATE_MODIFIED, "INTEGER" },
createUniqueConstraint(Albums.PARENT_ID, Albums.NAME),
};
@@ -64,11 +78,17 @@ public class PhotoDatabase extends SQLiteOpenHelper {
createUniqueConstraint(Metadata.PHOTO_ID, Metadata.KEY),
};
+ private static final String[][] CREATE_ACCOUNT = {
+ { Accounts._ID, "INTEGER PRIMARY KEY AUTOINCREMENT" },
+ { Accounts.ACCOUNT_NAME, "TEXT NOT NULL" },
+ };
+
@Override
public void onCreate(SQLiteDatabase db) {
- createTable(db, Albums.TABLE, CREATE_ALBUM);
- createTable(db, Photos.TABLE, CREATE_PHOTO);
- createTable(db, Metadata.TABLE, CREATE_METADATA);
+ createTable(db, Accounts.TABLE, getAccountTableDefinition());
+ createTable(db, Albums.TABLE, getAlbumTableDefinition());
+ createTable(db, Photos.TABLE, getPhotoTableDefinition());
+ createTable(db, Metadata.TABLE, getMetadataTableDefinition());
}
public PhotoDatabase(Context context, String dbName) {
@@ -79,7 +99,23 @@ public class PhotoDatabase extends SQLiteOpenHelper {
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
- protected static void createTable(SQLiteDatabase db, String table, String[][] columns) {
+ protected List<String[]> getAlbumTableDefinition() {
+ return tableCreationStrings(CREATE_ALBUM);
+ }
+
+ protected List<String[]> getPhotoTableDefinition() {
+ return tableCreationStrings(CREATE_PHOTO);
+ }
+
+ protected List<String[]> getMetadataTableDefinition() {
+ return tableCreationStrings(CREATE_METADATA);
+ }
+
+ protected List<String[]> getAccountTableDefinition() {
+ return tableCreationStrings(CREATE_ACCOUNT);
+ }
+
+ protected static void createTable(SQLiteDatabase db, String table, List<String[]> columns) {
StringBuilder create = new StringBuilder(SQL_CREATE_TABLE);
create.append(table).append('(');
boolean first = true;
@@ -107,4 +143,25 @@ public class PhotoDatabase extends SQLiteOpenHelper {
"UNIQUE(", column1, ",", column2, ")"
};
}
+
+ protected static List<String[]> tableCreationStrings(String[][] createTable) {
+ ArrayList<String[]> create = new ArrayList<String[]>(createTable.length);
+ for (String[] line: createTable) {
+ create.add(line);
+ }
+ return create;
+ }
+
+ protected static void addToTable(List<String[]> createTable, String[][] columns, String[][] constraints) {
+ if (columns != null) {
+ for (String[] column: columns) {
+ createTable.add(0, column);
+ }
+ }
+ if (constraints != null) {
+ for (String[] constraint: constraints) {
+ createTable.add(constraint);
+ }
+ }
+ }
}
diff --git a/src/com/android/photos/data/PhotoProvider.java b/src/com/android/photos/data/PhotoProvider.java
index 27afb58..52ebd6e 100644
--- a/src/com/android/photos/data/PhotoProvider.java
+++ b/src/com/android/photos/data/PhotoProvider.java
@@ -23,6 +23,7 @@ import android.database.DatabaseUtils;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteQueryBuilder;
+import android.media.ExifInterface;
import android.net.Uri;
import android.os.CancellationSignal;
import android.provider.BaseColumns;
@@ -60,28 +61,37 @@ public class PhotoProvider extends ContentProvider {
}
/**
- * Contains columns that can be accessed via PHOTOS_CONTENT_URI.
+ * Contains columns that can be accessed via Accounts.CONTENT_URI
*/
- public static interface Photos extends BaseColumns {
+ public static interface Accounts extends BaseColumns {
/**
- * Internal database table used for basic photo information.
+ * Internal database table used for account information
*/
- public static final String TABLE = "photo";
+ public static final String TABLE = "accounts";
/**
- * Content URI for basic photo and video information.
+ * Content URI for account information
*/
public static final Uri CONTENT_URI = Uri.withAppendedPath(BASE_CONTENT_URI, TABLE);
/**
- * Identifier used on the server. Long value.
- */
- public static final String SERVER_ID = "server_id";
- /**
- * Column name for the width of the original image. Integer value.
+ * User name for this account.
*/
+ public static final String ACCOUNT_NAME = "name";
+ }
+
+ /**
+ * Contains columns that can be accessed via Photos.CONTENT_URI.
+ */
+ public static interface Photos extends BaseColumns {
+ /** Internal database table used for basic photo information. */
+ public static final String TABLE = "photo";
+ /** Content URI for basic photo and video information. */
+ public static final Uri CONTENT_URI = Uri.withAppendedPath(BASE_CONTENT_URI, TABLE);
+
+ /** Long foreign key to Accounts._ID */
+ public static final String ACCOUNT_ID = "account_id";
+ /** Column name for the width of the original image. Integer value. */
public static final String WIDTH = "width";
- /**
- * Column name for the height of the original image. Integer value.
- */
+ /** Column name for the height of the original image. Integer value. */
public static final String HEIGHT = "height";
/**
* Column name for the date that the original image was taken. Long
@@ -94,42 +104,49 @@ public class PhotoProvider extends ContentProvider {
* server.
*/
public static final String ALBUM_ID = "album_id";
+ /** The column name for the mime-type String. */
+ public static final String MIME_TYPE = "mime_type";
+ /** The title of the photo. String value. */
+ public static final String TITLE = "title";
+ /** The date the photo entry was last updated. Long value. */
+ public static final String DATE_MODIFIED = "date_modified";
/**
- * The column name for the mime-type String.
+ * The rotation of the photo in degrees, if rotation has not already
+ * been applied. Integer value.
*/
- public static final String MIME_TYPE = "mime_type";
+ public static final String ROTATION = "rotation";
}
/**
* Contains columns and Uri for accessing album information.
*/
public static interface Albums extends BaseColumns {
- /**
- * Internal database table used album information.
- */
+ /** Internal database table used album information. */
public static final String TABLE = "album";
- /**
- * Content URI for album information.
- */
+ /** Content URI for album information. */
public static final Uri CONTENT_URI = Uri.withAppendedPath(BASE_CONTENT_URI, TABLE);
- /**
- * Parent directory or null if this is in the root.
- */
- public static final String PARENT_ID = "parent";
- /**
- * Column name for the name of the album. String value.
- */
+
+ /** Long foreign key to Accounts._ID */
+ public static final String ACCOUNT_ID = "account_id";
+ /** Parent directory or null if this is in the root. */
+ public static final String PARENT_ID = "parent_id";
+ /** Column name for the name of the album. String value. */
public static final String NAME = "name";
/**
* Column name for the visibility level of the album. Can be any of the
* VISIBILITY_* values.
*/
public static final String VISIBILITY = "visibility";
- /**
- * Column name for the server identifier for this album. NULL if the
- * server doesn't have this album yet.
- */
- public static final String SERVER_ID = "server_id";
+ /** The user-specified location associated with the album. String value. */
+ public static final String LOCATION_STRING = "location_string";
+ /** The title of the album. String value. */
+ public static final String TITLE = "title";
+ /** A short summary of the contents of the album. String value. */
+ public static final String SUMMARY = "summary";
+ /** The date the album was created. Long value */
+ public static final String DATE_PUBLISHED = "date_published";
+ /** The date the album entry was last updated. Long value. */
+ public static final String DATE_MODIFIED = "date_modified";
// Privacy values for Albums.VISIBILITY
public static final int VISIBILITY_PRIVATE = 1;
@@ -141,35 +158,53 @@ public class PhotoProvider extends ContentProvider {
* Contains columns and Uri for accessing photo and video metadata
*/
public static interface Metadata extends BaseColumns {
- /**
- * Internal database table used metadata information.
- */
+ /** Internal database table used metadata information. */
public static final String TABLE = "metadata";
- /**
- * Content URI for photo and video metadata.
- */
+ /** Content URI for photo and video metadata. */
public static final Uri CONTENT_URI = Uri.withAppendedPath(BASE_CONTENT_URI, TABLE);
- /**
- * Foreign key to photo_id. Long value.
- */
+ /** Foreign key to photo_id. Long value. */
public static final String PHOTO_ID = "photo_id";
- /**
- * Metadata key. String value
- */
+ /** Metadata key. String value */
public static final String KEY = "key";
/**
* Metadata value. Type is based on key.
*/
public static final String VALUE = "value";
+
+ /** A short summary of the photo. String value. */
+ public static final String KEY_SUMMARY = "summary";
+ /** The date the photo was added. Long value. */
+ public static final String KEY_PUBLISHED = "date_published";
+ /** The date the photo was last updated. Long value. */
+ public static final String KEY_DATE_UPDATED = "date_updated";
+ /** The size of the photo is bytes. Integer value. */
+ public static final String KEY_SIZE_IN_BTYES = "size";
+ /** The latitude associated with the photo. Double value. */
+ public static final String KEY_LATITUDE = "latitude";
+ /** The longitude associated with the photo. Double value. */
+ public static final String KEY_LONGITUDE = "longitude";
+
+ /** The make of the camera used. String value. */
+ public static final String KEY_EXIF_MAKE = ExifInterface.TAG_MAKE;
+ /** The model of the camera used. String value. */
+ public static final String KEY_EXIF_MODEL = ExifInterface.TAG_MODEL;;
+ /** The exposure time used. Float value. */
+ public static final String KEY_EXIF_EXPOSURE = ExifInterface.TAG_EXPOSURE_TIME;
+ /** Whether the flash was used. Boolean value. */
+ public static final String KEY_EXIF_FLASH = ExifInterface.TAG_FLASH;
+ /** The focal length used. Float value. */
+ public static final String KEY_EXIF_FOCAL_LENGTH = ExifInterface.TAG_FOCAL_LENGTH;
+ /** The fstop value used. Float value. */
+ public static final String KEY_EXIF_FSTOP = ExifInterface.TAG_APERTURE;
+ /** The ISO equivalent value used. Integer value. */
+ public static final String KEY_EXIF_ISO = ExifInterface.TAG_ISO;
}
/**
* Contains columns and Uri for maintaining the image cache.
*/
public static interface ImageCache extends BaseColumns {
- /**
- * Internal database table used for the image cache
- */
+ /** Internal database table used for the image cache */
public static final String TABLE = "image_cache";
/**
@@ -189,17 +224,11 @@ public class PhotoProvider extends ContentProvider {
*/
public static final Uri CONTENT_URI = Uri.withAppendedPath(BASE_CONTENT_URI, TABLE);
- /**
- * Foreign key to the photos._id. Long value.
- */
+ /** Foreign key to the photos._id. Long value. */
public static final String PHOTO_ID = "photo_id";
- /**
- * One of IMAGE_TYPE_* values.
- */
+ /** One of IMAGE_TYPE_* values. */
public static final String IMAGE_TYPE = "image_type";
- /**
- * The String path to the image.
- */
+ /** The String path to the image. */
public static final String PATH = "path";
};
diff --git a/tests/src/com/android/photos/data/PhotoDatabaseTest.java b/tests/src/com/android/photos/data/PhotoDatabaseTest.java
index d8c5e42..70edee2 100644
--- a/tests/src/com/android/photos/data/PhotoDatabaseTest.java
+++ b/tests/src/com/android/photos/data/PhotoDatabaseTest.java
@@ -31,6 +31,8 @@ public class PhotoDatabaseTest extends InstrumentationTestCase {
private PhotoDatabase mDBHelper;
private static final String DB_NAME = "dummy.db";
+ private static final long PARENT_ID1 = 100;
+ private static final long PARENT_ID2 = 101;
@Override
protected void setUp() throws Exception {
@@ -68,45 +70,38 @@ public class PhotoDatabaseTest extends InstrumentationTestCase {
SQLiteDatabase db = getWriteableDB();
db.beginTransaction();
try {
+ long accountId = 100;
// Test NOT NULL constraint on name
- assertFalse(PhotoDatabaseUtils
- .insertAlbum(db, null, null, Albums.VISIBILITY_PRIVATE, null));
+ assertFalse(PhotoDatabaseUtils.insertAlbum(db, null, null, Albums.VISIBILITY_PRIVATE,
+ accountId));
// test NOT NULL constraint on privacy
- assertFalse(PhotoDatabaseUtils.insertAlbum(db, null, "hello", null, null));
+ assertFalse(PhotoDatabaseUtils.insertAlbum(db, null, "hello", null, accountId));
- // Normal insert
- assertTrue(PhotoDatabaseUtils.insertAlbum(db, null, "hello", Albums.VISIBILITY_PRIVATE,
- 100L));
-
- // Test server id uniqueness
- assertFalse(PhotoDatabaseUtils.insertAlbum(db, null, "world", Albums.VISIBILITY_PRIVATE,
- 100L));
-
- // Different server id allowed
- assertTrue(PhotoDatabaseUtils.insertAlbum(db, null, "world", Albums.VISIBILITY_PRIVATE,
- 101L));
-
- // Allow null server id
- assertTrue(PhotoDatabaseUtils.insertAlbum(db, null, "hello world",
+ // test NOT NULL constraint on account_id
+ assertFalse(PhotoDatabaseUtils.insertAlbum(db, null, "hello",
Albums.VISIBILITY_PRIVATE, null));
- long albumId = PhotoDatabaseUtils.queryAlbumIdFromServerId(db, 100);
+ // Normal insert
+ assertTrue(PhotoDatabaseUtils.insertAlbum(db, PARENT_ID1, "hello",
+ Albums.VISIBILITY_PRIVATE, accountId));
+
+ long albumId = PhotoDatabaseUtils.queryAlbumIdFromParentId(db, PARENT_ID1);
// Assign a valid child
- assertTrue(PhotoDatabaseUtils.insertAlbum(db, albumId, "hello", Albums.VISIBILITY_PRIVATE,
- null));
+ assertTrue(PhotoDatabaseUtils.insertAlbum(db, PARENT_ID2, "hello",
+ Albums.VISIBILITY_PRIVATE, accountId));
- long otherAlbumId = PhotoDatabaseUtils.queryAlbumIdFromServerId(db, 101);
+ long otherAlbumId = PhotoDatabaseUtils.queryAlbumIdFromParentId(db, PARENT_ID2);
assertNotSame(albumId, otherAlbumId);
// This is a valid child of another album.
assertTrue(PhotoDatabaseUtils.insertAlbum(db, otherAlbumId, "hello",
- Albums.VISIBILITY_PRIVATE, null));
+ Albums.VISIBILITY_PRIVATE, accountId));
// This isn't allowed due to uniqueness constraint (parent_id/name)
assertFalse(PhotoDatabaseUtils.insertAlbum(db, otherAlbumId, "hello",
- Albums.VISIBILITY_PRIVATE, null));
+ Albums.VISIBILITY_PRIVATE, accountId));
} finally {
db.endTransaction();
}
@@ -120,26 +115,31 @@ public class PhotoDatabaseTest extends InstrumentationTestCase {
int height = 100;
long dateTaken = System.currentTimeMillis();
String mimeType = "test/test";
+ long accountId = 100;
// Test NOT NULL mime-type
- assertFalse(PhotoDatabaseUtils.insertPhoto(db, null, width, height, dateTaken, null,
- null));
+ assertFalse(PhotoDatabaseUtils.insertPhoto(db, width, height, dateTaken, null, null,
+ accountId));
// Test NOT NULL width
- assertFalse(PhotoDatabaseUtils.insertPhoto(db, null, null, height, dateTaken, null,
- mimeType));
+ assertFalse(PhotoDatabaseUtils.insertPhoto(db, null, height, dateTaken, null, mimeType,
+ accountId));
// Test NOT NULL height
- assertFalse(PhotoDatabaseUtils.insertPhoto(db, null, width, null, dateTaken, null,
- mimeType));
+ assertFalse(PhotoDatabaseUtils.insertPhoto(db, width, null, dateTaken, null, mimeType,
+ accountId));
// Test NOT NULL dateTaken
- assertFalse(PhotoDatabaseUtils.insertPhoto(db, null, width, height, null, null,
- mimeType));
+ assertFalse(PhotoDatabaseUtils.insertPhoto(db, width, height, null, null, mimeType,
+ accountId));
+
+ // Test NOT NULL accountId
+ assertFalse(PhotoDatabaseUtils.insertPhoto(db, width, height, dateTaken, null,
+ mimeType, null));
// Test normal insert
- assertTrue(PhotoDatabaseUtils.insertPhoto(db, null, width, height, dateTaken, null,
- mimeType));
+ assertTrue(PhotoDatabaseUtils.insertPhoto(db, width, height, dateTaken, null, mimeType,
+ accountId));
} finally {
db.endTransaction();
}
@@ -150,9 +150,8 @@ public class PhotoDatabaseTest extends InstrumentationTestCase {
db.beginTransaction();
try {
final String mimeType = "test/test";
- long photoServerId = 100;
- PhotoDatabaseUtils.insertPhoto(db, photoServerId, 100, 100, 100L, null, mimeType);
- long photoId = PhotoDatabaseUtils.queryPhotoIdFromServerId(db, photoServerId);
+ PhotoDatabaseUtils.insertPhoto(db, 100, 100, 100L, PARENT_ID1, mimeType, 100L);
+ long photoId = PhotoDatabaseUtils.queryPhotoIdFromAlbumId(db, PARENT_ID1);
// Test NOT NULL PHOTO_ID constraint.
assertFalse(PhotoDatabaseUtils.insertMetadata(db, null, "foo", "bar"));
@@ -167,6 +166,18 @@ public class PhotoDatabaseTest extends InstrumentationTestCase {
}
}
+ public void testAccountsConstraints() {
+ SQLiteDatabase db = getWriteableDB();
+ db.beginTransaction();
+ try {
+ assertFalse(PhotoDatabaseUtils.insertAccount(db, null));
+ assertTrue(PhotoDatabaseUtils.insertAccount(db, "hello"));
+ assertTrue(PhotoDatabaseUtils.insertAccount(db, "hello"));
+ } finally {
+ db.endTransaction();
+ }
+ }
+
private SQLiteDatabase getReadableDB() {
return mDBHelper.getReadableDatabase();
}
diff --git a/tests/src/com/android/photos/data/PhotoDatabaseUtils.java b/tests/src/com/android/photos/data/PhotoDatabaseUtils.java
index 73a6c78..1840eb1 100644
--- a/tests/src/com/android/photos/data/PhotoDatabaseUtils.java
+++ b/tests/src/com/android/photos/data/PhotoDatabaseUtils.java
@@ -19,6 +19,7 @@ import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
+import com.android.photos.data.PhotoProvider.Accounts;
import com.android.photos.data.PhotoProvider.Albums;
import com.android.photos.data.PhotoProvider.Metadata;
import com.android.photos.data.PhotoProvider.Photos;
@@ -28,10 +29,15 @@ import junit.framework.AssertionFailedError;
public class PhotoDatabaseUtils {
public static String[] PROJECTION_ALBUMS = {
Albums._ID,
+ Albums.ACCOUNT_ID,
Albums.PARENT_ID,
- Albums.VISIBILITY,
Albums.NAME,
- Albums.SERVER_ID,
+ Albums.VISIBILITY,
+ Albums.LOCATION_STRING,
+ Albums.TITLE,
+ Albums.SUMMARY,
+ Albums.DATE_PUBLISHED,
+ Albums.DATE_MODIFIED,
};
public static String[] PROJECTION_METADATA = {
@@ -42,23 +48,31 @@ public class PhotoDatabaseUtils {
public static String[] PROJECTION_PHOTOS = {
Photos._ID,
- Photos.SERVER_ID,
+ Photos.ACCOUNT_ID,
Photos.WIDTH,
Photos.HEIGHT,
Photos.DATE_TAKEN,
Photos.ALBUM_ID,
Photos.MIME_TYPE,
+ Photos.TITLE,
+ Photos.DATE_MODIFIED,
+ Photos.ROTATION,
+ };
+
+ public static String[] PROJECTION_ACCOUNTS = {
+ Accounts._ID,
+ Accounts.ACCOUNT_NAME,
};
- private static String SELECTION_ALBUM_SERVER_ID = Albums.SERVER_ID + " = ?";
- private static String SELECTION_PHOTO_SERVER_ID = Photos.SERVER_ID + " = ?";
+ private static String SELECTION_ALBUM_PARENT_ID = Albums.PARENT_ID + " = ?";
+ private static String SELECTION_PHOTO_ALBUM_ID = Photos.ALBUM_ID + " = ?";
- public static long queryAlbumIdFromServerId(SQLiteDatabase db, long serverId) {
- return queryId(db, Albums.TABLE, PROJECTION_ALBUMS, SELECTION_ALBUM_SERVER_ID, serverId);
+ public static long queryAlbumIdFromParentId(SQLiteDatabase db, long parentId) {
+ return queryId(db, Albums.TABLE, PROJECTION_ALBUMS, SELECTION_ALBUM_PARENT_ID, parentId);
}
- public static long queryPhotoIdFromServerId(SQLiteDatabase db, long serverId) {
- return queryId(db, Photos.TABLE, PROJECTION_PHOTOS, SELECTION_PHOTO_SERVER_ID, serverId);
+ public static long queryPhotoIdFromAlbumId(SQLiteDatabase db, long albumId) {
+ return queryId(db, Photos.TABLE, PROJECTION_PHOTOS, SELECTION_PHOTO_ALBUM_ID, albumId);
}
public static long queryId(SQLiteDatabase db, String table, String[] projection,
@@ -79,25 +93,25 @@ public class PhotoDatabaseUtils {
}
}
- public static boolean insertPhoto(SQLiteDatabase db, Long serverId, Integer width,
- Integer height, Long dateTaken, Long albumId, String mimeType) {
+ public static boolean insertPhoto(SQLiteDatabase db, Integer width, Integer height,
+ Long dateTaken, Long albumId, String mimeType, Long accountId) {
ContentValues values = new ContentValues();
- values.put(Photos.SERVER_ID, serverId);
values.put(Photos.WIDTH, width);
values.put(Photos.HEIGHT, height);
values.put(Photos.DATE_TAKEN, dateTaken);
values.put(Photos.ALBUM_ID, albumId);
values.put(Photos.MIME_TYPE, mimeType);
+ values.put(Photos.ACCOUNT_ID, accountId);
return db.insert(Photos.TABLE, null, values) != -1;
}
public static boolean insertAlbum(SQLiteDatabase db, Long parentId, String name,
- Integer privacy, Long serverId) {
+ Integer privacy, Long accountId) {
ContentValues values = new ContentValues();
values.put(Albums.PARENT_ID, parentId);
values.put(Albums.NAME, name);
values.put(Albums.VISIBILITY, privacy);
- values.put(Albums.SERVER_ID, serverId);
+ values.put(Albums.ACCOUNT_ID, accountId);
return db.insert(Albums.TABLE, null, values) != -1;
}
@@ -108,4 +122,10 @@ public class PhotoDatabaseUtils {
values.put(Metadata.VALUE, value);
return db.insert(Metadata.TABLE, null, values) != -1;
}
+
+ public static boolean insertAccount(SQLiteDatabase db, String name) {
+ ContentValues values = new ContentValues();
+ values.put(Accounts.ACCOUNT_NAME, name);
+ return db.insert(Accounts.TABLE, null, values) != -1;
+ }
}
diff --git a/tests/src/com/android/photos/data/PhotoProviderTest.java b/tests/src/com/android/photos/data/PhotoProviderTest.java
index 525abec..2e644a3 100644
--- a/tests/src/com/android/photos/data/PhotoProviderTest.java
+++ b/tests/src/com/android/photos/data/PhotoProviderTest.java
@@ -35,8 +35,7 @@ public class PhotoProviderTest extends ProviderTestCase2<PhotoProvider> {
private static final String MIME_TYPE = "test/test";
private static final String ALBUM_NAME = "My Album";
- private static final long ALBUM_SERVER_ID = 100;
- private static final long PHOTO_SERVER_ID = 50;
+ private static final long ALBUM_PARENT_ID = 100;
private static final String META_KEY = "mykey";
private static final String META_VALUE = "myvalue";
@@ -70,12 +69,12 @@ public class PhotoProviderTest extends ProviderTestCase2<PhotoProvider> {
SQLiteDatabase db = mDBHelper.getWritableDatabase();
db.beginTransaction();
try {
- PhotoDatabaseUtils.insertAlbum(db, null, ALBUM_NAME, Albums.VISIBILITY_PRIVATE,
- ALBUM_SERVER_ID);
- mAlbumId = PhotoDatabaseUtils.queryAlbumIdFromServerId(db, ALBUM_SERVER_ID);
- PhotoDatabaseUtils.insertPhoto(db, PHOTO_SERVER_ID, 100, 100,
- System.currentTimeMillis(), mAlbumId, MIME_TYPE);
- mPhotoId = PhotoDatabaseUtils.queryPhotoIdFromServerId(db, PHOTO_SERVER_ID);
+ PhotoDatabaseUtils.insertAlbum(db, ALBUM_PARENT_ID, ALBUM_NAME,
+ Albums.VISIBILITY_PRIVATE, 100L);
+ mAlbumId = PhotoDatabaseUtils.queryAlbumIdFromParentId(db, ALBUM_PARENT_ID);
+ PhotoDatabaseUtils.insertPhoto(db, 100, 100, System.currentTimeMillis(), mAlbumId,
+ MIME_TYPE, 100L);
+ mPhotoId = PhotoDatabaseUtils.queryPhotoIdFromAlbumId(db, mAlbumId);
PhotoDatabaseUtils.insertMetadata(db, mPhotoId, META_KEY, META_VALUE);
String[] projection = {
BaseColumns._ID,