summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDipankar Bhardwaj <dipankarb@google.com>2023-02-09 17:39:42 +0000
committerDipankar Bhardwaj <dipankarb@google.com>2023-02-14 12:18:31 +0000
commita6cd749b36e7fcb922c537fd02b2186f49fc25f0 (patch)
treea03bc3ec37ea2ca3e74dfb9a73f2b8d1c4011194
parente5192fd118ec87164aca4862ffc62ae900c5e974 (diff)
downloadMediaProvider-a6cd749b36e7fcb922c537fd02b2186f49fc25f0.tar.gz
Update DB triggers to add needed fields for Stable uris
Updated existing triggers to fetch user_id, is_trashed and date_expires fields. Updated schema version to ensure latest trigger creation. Bug: 259258273 Test: atest DatabaseHelperTest Change-Id: I4c8aad89004e64aa09192aad6549af27fff8c1b2
-rw-r--r--src/com/android/providers/media/DatabaseHelper.java41
-rw-r--r--src/com/android/providers/media/dao/FileRow.java25
2 files changed, 58 insertions, 8 deletions
diff --git a/src/com/android/providers/media/DatabaseHelper.java b/src/com/android/providers/media/DatabaseHelper.java
index 3dda852b7..53ac55406 100644
--- a/src/com/android/providers/media/DatabaseHelper.java
+++ b/src/com/android/providers/media/DatabaseHelper.java
@@ -359,19 +359,27 @@ public class DatabaseHelper extends SQLiteOpenHelper implements AutoCloseable {
db.setCustomScalarFunction("_INSERT", (arg) -> {
if (arg != null && mFilesListener != null
&& !mSchemaLock.isWriteLockedByCurrentThread()) {
- final String[] split = arg.split(":", 6);
+ final String[] split = arg.split(":", 10);
final String volumeName = split[0];
final long id = Long.parseLong(split[1]);
final int mediaType = Integer.parseInt(split[2]);
final boolean isDownload = Integer.parseInt(split[3]) != 0;
final boolean isPending = Integer.parseInt(split[4]) != 0;
- final String path = split[5];
+ final boolean isTrashed = Integer.parseInt(split[5]) != 0;
+ final boolean isFavorite = Integer.parseInt(split[6]) != 0;
+ final int userId = Integer.parseInt(split[7]);
+ final String dateExpires = split[8];
+ final String path = split[9];
FileRow insertedRow = FileRow.newBuilder(id)
.setVolumeName(volumeName)
.setMediaType(mediaType)
.setIsDownload(isDownload)
.setIsPending(isPending)
+ .setIsTrashed(isTrashed)
+ .setIsFavorite(isFavorite)
+ .setUserId(userId)
+ .setDateExpires(dateExpires)
.setPath(path)
.build();
Trace.beginSection(traceSectionName("_INSERT"));
@@ -386,7 +394,7 @@ public class DatabaseHelper extends SQLiteOpenHelper implements AutoCloseable {
db.setCustomScalarFunction("_UPDATE", (arg) -> {
if (arg != null && mFilesListener != null
&& !mSchemaLock.isWriteLockedByCurrentThread()) {
- final String[] split = arg.split(":", 18);
+ final String[] split = arg.split(":", 22);
final String volumeName = split[0];
final long oldId = Long.parseLong(split[1]);
final int oldMediaType = Integer.parseInt(split[2]);
@@ -404,7 +412,11 @@ public class DatabaseHelper extends SQLiteOpenHelper implements AutoCloseable {
final int newSpecialFormat = Integer.parseInt(split[14]);
final String oldOwnerPackage = split[15];
final String newOwnerPackage = split[16];
- final String oldPath = split[17];
+ final int oldUserId = Integer.parseInt(split[17]);
+ final int newUserId = Integer.parseInt(split[18]);
+ final String oldDateExpires = split[19];
+ final String newDateExpires = split[20];
+ final String oldPath = split[21];
FileRow oldRow = FileRow.newBuilder(oldId)
.setVolumeName(volumeName)
@@ -415,6 +427,8 @@ public class DatabaseHelper extends SQLiteOpenHelper implements AutoCloseable {
.setIsFavorite(oldIsFavorite)
.setSpecialFormat(oldSpecialFormat)
.setOwnerPackageName(oldOwnerPackage)
+ .setUserId(oldUserId)
+ .setDateExpires(oldDateExpires)
.setPath(oldPath)
.build();
FileRow newRow = FileRow.newBuilder(newId)
@@ -426,6 +440,8 @@ public class DatabaseHelper extends SQLiteOpenHelper implements AutoCloseable {
.setIsFavorite(newIsFavorite)
.setSpecialFormat(newSpecialFormat)
.setOwnerPackageName(newOwnerPackage)
+ .setUserId(newUserId)
+ .setDateExpires(newDateExpires)
.build();
Trace.beginSection(traceSectionName("_UPDATE"));
@@ -1672,8 +1688,9 @@ public class DatabaseHelper extends SQLiteOpenHelper implements AutoCloseable {
makePristineTriggers(db);
final String insertArg =
- "new.volume_name||':'||new._id||':'||new.media_type||':'||new.is_download"
- + "||':'||new.is_pending||':'||new._data";
+ "new.volume_name||':'||new._id||':'||new.media_type||':'||new"
+ + ".is_download||':'||new.is_pending||':'||new.is_trashed||':'||new"
+ + ".is_favorite||':'||new._user_id||':'||new.date_expires||':'||new._data";
final String updateArg =
"old.volume_name||':'||old._id||':'||old.media_type||':'||old.is_download"
+ "||':'||new._id||':'||new.media_type||':'||new.is_download"
@@ -1684,7 +1701,12 @@ public class DatabaseHelper extends SQLiteOpenHelper implements AutoCloseable {
+ "||':'||ifnull(old._special_format,0)"
+ "||':'||ifnull(new._special_format,0)"
+ "||':'||ifnull(old.owner_package_name,'null')"
- + "||':'||ifnull(new.owner_package_name,'null')||':'||old._data";
+ + "||':'||ifnull(new.owner_package_name,'null')"
+ + "||':'||ifnull(old._user_id,0)"
+ + "||':'||ifnull(new._user_id,0)"
+ + "||':'||old.date_expires"
+ + "||':'||new.date_expires"
+ + "||':'||old._data";
final String deleteArg =
"old.volume_name||':'||old._id||':'||old.media_type||':'||old.is_download"
+ "||':'||ifnull(old.owner_package_name,'null')||':'||old._data";
@@ -2042,7 +2064,7 @@ public class DatabaseHelper extends SQLiteOpenHelper implements AutoCloseable {
static final int VERSION_T = 1308;
// Leave some gaps in database version tagging to allow T schema changes
// to go independent of U schema changes.
- static final int VERSION_U = 1402;
+ static final int VERSION_U = 1403;
public static final int VERSION_LATEST = VERSION_U;
/**
@@ -2252,6 +2274,9 @@ public class DatabaseHelper extends SQLiteOpenHelper implements AutoCloseable {
updateAddMediaGrantsTable(db);
}
}
+ if (fromVersion < 1403) {
+ // Empty version bump to ensure triggers are recreated
+ }
// If this is the legacy database, it's not worth recomputing data
// values locally, since they'll be recomputed after the migration
diff --git a/src/com/android/providers/media/dao/FileRow.java b/src/com/android/providers/media/dao/FileRow.java
index 3410c0c2c..1dbe8341d 100644
--- a/src/com/android/providers/media/dao/FileRow.java
+++ b/src/com/android/providers/media/dao/FileRow.java
@@ -29,6 +29,9 @@ public class FileRow {
private boolean mIsTrashed;
private boolean mIsFavorite;
private int mSpecialFormat;
+ private int mUserId;
+ // String data type used as value can be null
+ private String mDateExpires;
public static class Builder {
private final long mId;
@@ -41,6 +44,8 @@ public class FileRow {
private boolean mIsTrashed;
private boolean mIsFavorite;
private int mSpecialFormat;
+ private int mUserId;
+ private String mDateExpires;
Builder(long id) {
this.mId = id;
@@ -91,6 +96,16 @@ public class FileRow {
return this;
}
+ public Builder setUserId(int userId) {
+ this.mUserId = userId;
+ return this;
+ }
+
+ public Builder setDateExpires(String dateExpires) {
+ this.mDateExpires = dateExpires;
+ return this;
+ }
+
public FileRow build() {
FileRow fileRow = new FileRow(this.mId);
fileRow.mPath = this.mPath;
@@ -102,6 +117,8 @@ public class FileRow {
fileRow.mIsTrashed = this.mIsTrashed;
fileRow.mIsFavorite = this.mIsFavorite;
fileRow.mSpecialFormat = this.mSpecialFormat;
+ fileRow.mUserId = this.mUserId;
+ fileRow.mDateExpires = this.mDateExpires;
return fileRow;
}
@@ -154,4 +171,12 @@ public class FileRow {
public int getSpecialFormat() {
return mSpecialFormat;
}
+
+ public int getUserId() {
+ return mUserId;
+ }
+
+ public String getDateExpires() {
+ return mDateExpires;
+ }
}