Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Scoped Storage - What , Why & How

Scoped Storage - What , Why & How

When Android Q Beta 1 was released, the main surprising change for developers was what Google calls “scoped storage”. The main two reasons for making this change: Security & to reduce leftover "app clutter". In brief, our ability to work
with files and filesystems will get substantially curtailed, even for apps with a targetSdkVersion of 28 or lower.

However in subsequent Android Q beta releases 4 & 5, it has now been finalised that Apps can either have normal or legacy storage.
With legacy storage, everything behaves as it did in Android 4.4 through 9.0. Without legacy storage, apps still can use getExternalFilesDir() and similar directories without permissions. However, the rest of external storage appears to be inaccessible via filesystem APIs. As per documentation :
“An app that has a filtered view always has read/write access to the files that it creates, both inside and outside its app-specific directory”
The idea is that we should start adapting now. For some apps, switching to the Storage Access Framework (e.g. ACTION_OPEN_DOCUMENT) will be easy. For some apps, it will be painful. We must not wait until 2020, as mentioned in documentation. We should Start migrating our apps now to use the alternative approaches. Through this talk we will try to assess different approaches to be adopted for the changes coming via scoped storage and making sure that apps continue to work seamlessly.

Gaurav Bhatnagar

November 03, 2019
Tweet

More Decks by Gaurav Bhatnagar

Other Decks in Programming

Transcript

  1. Agenda • The Problem and Storage Review • The Solution

    - Scoped Storage • Key Features of Scoped Storage • Special App Access • Legacy Support • Future releases
  2. The Problem • Every App has private android/data/package_name. All other

    storage is Shared Storage. • Private storage location is available for us to read & write w/o permissions but for Shared Storage, we need permissions. • Once access is granted, no one generally revokes the permission. • Many apps, unknown to you, still reads your information all the time. • Another issue is all leftover data from uninstalled apps.
  3. The Solution - Scoped Storage • Compartmentalize the storage into

    specified collections. • Limits the access to broad storage. • Manages spillover from uninstalled apps.
  4. Principles of Scoped Storage Better Attribution • System knows which

    file is generated by which application. • More control over app cleanup. Protecting App Data • Internal storage of the app is anyhow private to the app. • Restricting the shared/external storage from other unrelated apps Protecting User Data • Refine permissions by file type • Files created / downloaded by the app,
  5. Key features of Scoped Storage (1/3) Organized collection - •

    Media collection for images, videos, etc • Download collection for non-media files. Unrestricted access - • Unlimited read/write access to app storage directory on internal & external (using getExternalFilesDir() ) Storage (SD) card. Unrestricted media - • Unrestricted access to media collections & downloads of our own app. • Need READ_EXTERNAL_STORAGE permission to read files created by other apps.
  6. Key features of Scoped Storage(2/3) Media location metadata - •

    ACCESS_MEDIA_LOCATION to read location metadata from image files. • By default, image is stripped of location meta data before sending the file to the app. System Picker (with Storage Access Framework API ) - • To select non-media files. • To select any non-collections files.
  7. Special App Access Need broad access to storage? • Request

    for permission in Google Play Store. • If approved, we get access to unfiltered view of MediaStore that include non- media file. • However, our app will not have access to external app directories.
  8. Legacy Support <manifest ... > <!-- This attribute is "false"

    by default on apps targeting Android 10 or higher. --> <application android:requestLegacyExternalStorage="true" ... > ... </application> </manifest>
  9. Future Releases • Different permission UI for app w/ &

    w/o Scoped Storage. • Enable file path & native libraries for media (for File managers). • Enforcing by target SDK of the App, not platform of the app.