diff options
author | 2020-03-06 14:42:12 -0700 | |
---|---|---|
committer | 2020-03-07 17:50:44 -0700 | |
commit | d5a429288176f8e49489070dc9ca9d433de5e9d0 (patch) | |
tree | 833236d664f7efd1c44218ace02f199d0dbea796 /legacy | |
parent | e04e2c6a41cc9629f3b7b8b8ee8e362f172a1398 (diff) |
Updates based on API council feedback.
-- Promote generally-useful PFD API to public.
-- Add @WorkerThread annotations.
-- Add docs to explain how AUTHORITY_LEGACY works, and add explicit
START/FINISH_LEGACY_MIGRATION_CALL verbs to communicate progress.
-- Expand docs for createWriteRequest() to explain broader access
that it grants. Expand all request methods to indicate the action
is fully completed before the result is delivered.
-- Expand docs for new generation fields to explain that version
also needs to be inspected.
-- Explicitly call out why getKindSize() is deprecated, and guide
towards better alternative.
Bug: 148867182, 148403418, 148011561, 147760276
Test: none
Change-Id: Ibfae5a0b490d4b4b3f1725b72e246833f79c50e2
Diffstat (limited to 'legacy')
-rw-r--r-- | legacy/src/com/android/providers/media/LegacyMediaProvider.java | 44 |
1 files changed, 40 insertions, 4 deletions
diff --git a/legacy/src/com/android/providers/media/LegacyMediaProvider.java b/legacy/src/com/android/providers/media/LegacyMediaProvider.java index 93d1b8ead..b79a955e8 100644 --- a/legacy/src/com/android/providers/media/LegacyMediaProvider.java +++ b/legacy/src/com/android/providers/media/LegacyMediaProvider.java @@ -26,6 +26,7 @@ import android.content.Context; import android.content.pm.ProviderInfo; import android.database.Cursor; import android.net.Uri; +import android.os.Bundle; import android.provider.MediaStore; import android.provider.MediaStore.MediaColumns; @@ -37,6 +38,7 @@ import java.io.File; import java.io.FileDescriptor; import java.io.IOException; import java.io.PrintWriter; +import java.util.Objects; /** * Very limited subset of {@link MediaProvider} which only surfaces @@ -46,6 +48,9 @@ public class LegacyMediaProvider extends ContentProvider { private DatabaseHelper mInternalDatabase; private DatabaseHelper mExternalDatabase; + public static final String START_LEGACY_MIGRATION_CALL = "start_legacy_migration"; + public static final String FINISH_LEGACY_MIGRATION_CALL = "finish_legacy_migration"; + @Override public void attachInfo(Context context, ProviderInfo info) { // Sanity check our setup @@ -68,9 +73,9 @@ public class LegacyMediaProvider extends ContentProvider { Logging.initPersistent(persistentDir); mInternalDatabase = new DatabaseHelper(context, INTERNAL_DATABASE_NAME, - true, false, true, null, null, null); + true, false, true, null, null, null, null); mExternalDatabase = new DatabaseHelper(context, EXTERNAL_DATABASE_NAME, - false, false, true, null, null, null); + false, false, true, null, null, null, null); return true; } @@ -79,9 +84,9 @@ public class LegacyMediaProvider extends ContentProvider { final String volumeName = MediaStore.getVolumeName(uri); switch (volumeName) { case MediaStore.VOLUME_INTERNAL: - return mInternalDatabase; + return Objects.requireNonNull(mInternalDatabase, "Missing internal database"); default: - return mExternalDatabase; + return Objects.requireNonNull(mExternalDatabase, "Missing external database"); } } @@ -124,6 +129,37 @@ public class LegacyMediaProvider extends ContentProvider { } @Override + public Bundle call(String authority, String method, String arg, Bundle extras) { + switch (method) { + case START_LEGACY_MIGRATION_CALL: { + // Nice to know, but nothing actionable + break; + } + case FINISH_LEGACY_MIGRATION_CALL: { + // We're only going to hear this once, since we've either + // successfully migrated legacy data, or we're never going to + // try again, so it's time to clean things up + final String volumeName = arg; + switch (volumeName) { + case MediaStore.VOLUME_INTERNAL: { + mInternalDatabase.close(); + mInternalDatabase = null; + getContext().deleteDatabase(INTERNAL_DATABASE_NAME); + break; + } + default: { + mExternalDatabase.close(); + mExternalDatabase = null; + getContext().deleteDatabase(EXTERNAL_DATABASE_NAME); + break; + } + } + } + } + return null; + } + + @Override public void dump(FileDescriptor fd, PrintWriter writer, String[] args) { Logging.dumpPersistent(writer); } |