summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--legacy/src/com/android/providers/media/LegacyMediaProvider.java4
-rw-r--r--src/com/android/providers/media/DatabaseHelper.java57
-rw-r--r--src/com/android/providers/media/MediaProvider.java4
-rw-r--r--tests/src/com/android/providers/media/DatabaseHelperTest.java12
-rw-r--r--tests/src/com/android/providers/media/photopicker/data/ExternalDbFacadeTest.java3
5 files changed, 36 insertions, 44 deletions
diff --git a/legacy/src/com/android/providers/media/LegacyMediaProvider.java b/legacy/src/com/android/providers/media/LegacyMediaProvider.java
index d51414b6b..9951bc5ec 100644
--- a/legacy/src/com/android/providers/media/LegacyMediaProvider.java
+++ b/legacy/src/com/android/providers/media/LegacyMediaProvider.java
@@ -80,9 +80,9 @@ public class LegacyMediaProvider extends ContentProvider {
Logging.initPersistent(persistentDir);
mInternalDatabase = new DatabaseHelper(context, INTERNAL_DATABASE_NAME, false, true, null,
- null, null, null, null, null);
+ null, null, null, null, null, false);
mExternalDatabase = new DatabaseHelper(context, EXTERNAL_DATABASE_NAME, false, true, null,
- null, null, null, null, null);
+ null, null, null, null, null, false);
return true;
}
diff --git a/src/com/android/providers/media/DatabaseHelper.java b/src/com/android/providers/media/DatabaseHelper.java
index afed0552f..244c2befd 100644
--- a/src/com/android/providers/media/DatabaseHelper.java
+++ b/src/com/android/providers/media/DatabaseHelper.java
@@ -115,22 +115,26 @@ public class DatabaseHelper extends SQLiteOpenHelper implements AutoCloseable {
/**
* Key name of xattr used to set next row id for internal DB.
*/
- private static final String INTERNAL_DB_NEXT_ROW_ID_XATTR_KEY = "user.intdbnextrowid";
+ private static final String INTERNAL_DB_NEXT_ROW_ID_XATTR_KEY = "user.intdbnextrowid".concat(
+ String.valueOf(UserHandle.myUserId()));
/**
* Key name of xattr used to set next row id for external DB.
*/
- private static final String EXTERNAL_DB_NEXT_ROW_ID_XATTR_KEY = "user.extdbnextrowid";
+ private static final String EXTERNAL_DB_NEXT_ROW_ID_XATTR_KEY = "user.extdbnextrowid".concat(
+ String.valueOf(UserHandle.myUserId()));
/**
* Key name of xattr used to set session id for internal DB.
*/
- private static final String INTERNAL_DB_SESSION_ID_XATTR_KEY = "user.intdbsessionid";
+ private static final String INTERNAL_DB_SESSION_ID_XATTR_KEY = "user.intdbsessionid".concat(
+ String.valueOf(UserHandle.myUserId()));
/**
* Key name of xattr used to set session id for external DB.
*/
- private static final String EXTERNAL_DB_SESSION_ID_XATTR_KEY = "user.extdbsessionid";
+ private static final String EXTERNAL_DB_SESSION_ID_XATTR_KEY = "user.extdbsessionid".concat(
+ String.valueOf(UserHandle.myUserId()));
/** Indicates a billion value used when next row id is not present in respective xattr. */
private static final Long NEXT_ROW_ID_DEFAULT_BILLION_VALUE = Double.valueOf(
@@ -139,16 +143,13 @@ public class DatabaseHelper extends SQLiteOpenHelper implements AutoCloseable {
private static final Long INVALID_ROW_ID = -1L;
/**
- * Path on which {@link DatabaseHelper#DATA_MEDIA_XATTR_DIRECTORY_PATH} is set.
- * /storage/emulated/.. can point to /data/media/.. on ext4/f2fs on modern devices. However, for
- * legacy devices with sdcardfs, it points to /mnt/runtime/.. which then points to
- * /data/media/.. sdcardfs does not support xattrs, hence xattrs are set on /data/media/.. path.
- *
- * TODO(b/220895679): Add logic to handle external sd cards with primary volume with paths
- * /mnt/expand/<volume>/media/<user-id>.
+ * Path used for setting next row id and database session id for each user profile. Storing here
+ * because media provider does not have required permission on path /data/media/<user-id> for
+ * work profiles.
+ * For devices with adoptable storage support, opting for adoptable storage will not delete
+ * /data/media/0 directory.
*/
- public static final String DATA_MEDIA_XATTR_DIRECTORY_PATH = String.format(
- "/data/media/%s", UserHandle.myUserId());
+ public static final String DATA_MEDIA_XATTR_DIRECTORY_PATH = "/data/media/0";
static final String INTERNAL_DATABASE_NAME = "internal.db";
static final String EXTERNAL_DATABASE_NAME = "external.db";
@@ -178,6 +179,7 @@ public class DatabaseHelper extends SQLiteOpenHelper implements AutoCloseable {
private final String mMigrationFileName;
long mScanStartTime;
long mScanStopTime;
+ private boolean mEnableNextRowIdRecovery;
/**
* Unfortunately we can have multiple instances of DatabaseHelper, causing
@@ -242,10 +244,10 @@ public class DatabaseHelper extends SQLiteOpenHelper implements AutoCloseable {
@Nullable OnSchemaChangeListener schemaListener,
@Nullable OnFilesChangeListener filesListener,
@NonNull OnLegacyMigrationListener migrationListener,
- @Nullable UnaryOperator<String> idGenerator) {
+ @Nullable UnaryOperator<String> idGenerator, boolean enableNextRowIdRecovery) {
this(context, name, getDatabaseVersion(context), earlyUpgrade, legacyProvider,
columnAnnotation, exportedSinceAnnotation, schemaListener, filesListener,
- migrationListener, idGenerator);
+ migrationListener, idGenerator, enableNextRowIdRecovery);
}
public DatabaseHelper(Context context, String name, int version,
@@ -255,7 +257,7 @@ public class DatabaseHelper extends SQLiteOpenHelper implements AutoCloseable {
@Nullable OnSchemaChangeListener schemaListener,
@Nullable OnFilesChangeListener filesListener,
@NonNull OnLegacyMigrationListener migrationListener,
- @Nullable UnaryOperator<String> idGenerator) {
+ @Nullable UnaryOperator<String> idGenerator, boolean enableNextRowIdRecovery) {
super(context, name, null, version);
mContext = context;
mName = name;
@@ -276,6 +278,7 @@ public class DatabaseHelper extends SQLiteOpenHelper implements AutoCloseable {
mMigrationListener = migrationListener;
mIdGenerator = idGenerator;
mMigrationFileName = "." + mVolumeName;
+ this.mEnableNextRowIdRecovery = enableNextRowIdRecovery;
// Configure default filters until we hear differently
if (isInternal()) {
@@ -2297,7 +2300,7 @@ public class DatabaseHelper extends SQLiteOpenHelper implements AutoCloseable {
getNextRowIdXattrKeyForDatabase()))));
} catch (Exception e) {
Log.e(TAG, String.format("Xattr:%s not found on external storage.",
- getNextRowIdXattrKeyForDatabase()));
+ getNextRowIdXattrKeyForDatabase()), e);
return Optional.empty();
}
}
@@ -2358,6 +2361,10 @@ public class DatabaseHelper extends SQLiteOpenHelper implements AutoCloseable {
}
boolean isNextRowIdBackupEnabled() {
+ if (!mEnableNextRowIdRecovery) {
+ return false;
+ }
+
if (mVersion < VERSION_R) {
// Do not back up next row id if DB version is less than R. This is unlikely to hit
// as we will backport row id backup changes till Android R.
@@ -2372,11 +2379,6 @@ public class DatabaseHelper extends SQLiteOpenHelper implements AutoCloseable {
return false;
}
- if (hasAdoptableStorage()) {
- Log.v(TAG, "Skipping next row id backup for devices which support adoptable storage.");
- return false;
- }
-
if (!(new File(DATA_MEDIA_XATTR_DIRECTORY_PATH)).exists()) {
Log.w(TAG, String.format("Skipping row id recovery as path:%s does not exist.",
DATA_MEDIA_XATTR_DIRECTORY_PATH));
@@ -2387,17 +2389,6 @@ public class DatabaseHelper extends SQLiteOpenHelper implements AutoCloseable {
false);
}
- boolean hasAdoptableStorage() {
- switch (SystemProperties.get("persist.sys.adoptable")) {
- case "force_on":
- return true;
- case "force_off":
- return false;
- default:
- return SystemProperties.getBoolean("vold.has_adoptable", false);
- }
- }
-
public static int getNextRowIdBackupFrequency() {
return SystemProperties.getInt("persist.sys.fuse.backup.nextrowid_backup_frequency",
1000);
diff --git a/src/com/android/providers/media/MediaProvider.java b/src/com/android/providers/media/MediaProvider.java
index 8c221b8c9..62f0a5ae5 100644
--- a/src/com/android/providers/media/MediaProvider.java
+++ b/src/com/android/providers/media/MediaProvider.java
@@ -1062,10 +1062,10 @@ public class MediaProvider extends ContentProvider {
mInternalDatabase = new DatabaseHelper(context, INTERNAL_DATABASE_NAME, false, false,
Column.class, ExportedSince.class, Metrics::logSchemaChange, mFilesListener,
- MIGRATION_LISTENER, mIdGenerator);
+ MIGRATION_LISTENER, mIdGenerator, true);
mExternalDatabase = new DatabaseHelper(context, EXTERNAL_DATABASE_NAME, false, false,
Column.class, ExportedSince.class, Metrics::logSchemaChange, mFilesListener,
- MIGRATION_LISTENER, mIdGenerator);
+ MIGRATION_LISTENER, mIdGenerator, true);
mExternalDbFacade = new ExternalDbFacade(getContext(), mExternalDatabase, mVolumeCache);
mPickerDbFacade = new PickerDbFacade(context);
diff --git a/tests/src/com/android/providers/media/DatabaseHelperTest.java b/tests/src/com/android/providers/media/DatabaseHelperTest.java
index aee766187..f1ce3504d 100644
--- a/tests/src/com/android/providers/media/DatabaseHelperTest.java
+++ b/tests/src/com/android/providers/media/DatabaseHelperTest.java
@@ -585,7 +585,7 @@ public class DatabaseHelperTest {
private static class DatabaseHelperO extends DatabaseHelper {
public DatabaseHelperO(Context context, String name) {
super(context, name, DatabaseHelper.VERSION_O, false, false, Column.class,
- ExportedSince.class, null, null, null, null);
+ ExportedSince.class, null, null, null, null, false);
}
@Override
@@ -597,7 +597,7 @@ public class DatabaseHelperTest {
private static class DatabaseHelperP extends DatabaseHelper {
public DatabaseHelperP(Context context, String name) {
super(context, name, DatabaseHelper.VERSION_P, false, false, Column.class,
- ExportedSince.class, null, null, null, null);
+ ExportedSince.class, null, null, null, null, false);
}
@Override
@@ -609,7 +609,7 @@ public class DatabaseHelperTest {
private static class DatabaseHelperQ extends DatabaseHelper {
public DatabaseHelperQ(Context context, String name) {
super(context, name, DatabaseHelper.VERSION_Q, false, false, Column.class,
- ExportedSince.class, null, null, null, null);
+ ExportedSince.class, null, null, null, null, false);
}
@Override
@@ -621,7 +621,7 @@ public class DatabaseHelperTest {
private static class DatabaseHelperR extends DatabaseHelper {
public DatabaseHelperR(Context context, String name) {
super(context, name, DatabaseHelper.VERSION_R, false, false, Column.class,
- ExportedSince.class, null, null, MediaProvider.MIGRATION_LISTENER, null);
+ ExportedSince.class, null, null, MediaProvider.MIGRATION_LISTENER, null, false);
}
@Override
@@ -633,7 +633,7 @@ public class DatabaseHelperTest {
private static class DatabaseHelperS extends DatabaseHelper {
public DatabaseHelperS(Context context, String name) {
super(context, name, VERSION_S, false, false, Column.class, ExportedSince.class, null,
- null, MediaProvider.MIGRATION_LISTENER, null);
+ null, MediaProvider.MIGRATION_LISTENER, null, false);
}
@@ -646,7 +646,7 @@ public class DatabaseHelperTest {
private static class DatabaseHelperT extends DatabaseHelper {
public DatabaseHelperT(Context context, String name) {
super(context, name, DatabaseHelper.VERSION_T, false, false, Column.class,
- ExportedSince.class, null, null, MediaProvider.MIGRATION_LISTENER, null);
+ ExportedSince.class, null, null, MediaProvider.MIGRATION_LISTENER, null, false);
}
}
diff --git a/tests/src/com/android/providers/media/photopicker/data/ExternalDbFacadeTest.java b/tests/src/com/android/providers/media/photopicker/data/ExternalDbFacadeTest.java
index eec44bc6e..3a37efaf2 100644
--- a/tests/src/com/android/providers/media/photopicker/data/ExternalDbFacadeTest.java
+++ b/tests/src/com/android/providers/media/photopicker/data/ExternalDbFacadeTest.java
@@ -911,7 +911,8 @@ public class ExternalDbFacadeTest {
private static class TestDatabaseHelper extends DatabaseHelper {
public TestDatabaseHelper(Context context) {
- super(context, TEST_CLEAN_DB, 1, false, false, null, null, null, null, null, null);
+ super(context, TEST_CLEAN_DB, 1, false, false, null, null, null, null, null, null,
+ false);
}
}
}