devrath / refactored-android-scoped-storage

Scoped storage came on the scene from Android 10 giving importance to users privacy

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

refactored-android-scoped-storage πŸ§žβ€

πš†πš‘πšŠπš πš’πšœ 𝚊 πš‚πšŒπš˜πš™πšŽπš πš‚πšπš˜πš›πšŠπšπšŽπŸ’‘

🏷️ We are aware that working with a file system is a very important part of android development. Till the android version-10, once the user gave permission to access the external storage, he could access any file on the device.
🏷️ But most of the time we don't need the entire storage system to be accessed. Users mostly do some action on a file or a group of files and don't need access to the entire file system, due to this there was a concern of security and privacy of the user.
🏷️ The scoped storage enhances the control of user privacy on the device.

π™΅πš•πš˜πš  πšπš’πšŠπšπš›πšŠπš– πš›πšŽπš™πš›πšŽπšœπšŽπš—πšπšŠπšπš’πš˜πš— 𝚘𝚏 πšœπšπš˜πš›πš’πš—πš 𝚍𝚊𝚝𝚊

πš†πš‘πšŠπš πš’πšœ 𝚊 π™΅πš’πš•πšŽ πš‚πš’πšœπšπšŽπš–

π™³πšŽπšπš’πš—πš’πšπš’πš˜πš—:

  • FileSystem is a way of storing data in documents instead of key-value mapping mechanism.
  • Using this mechanism, we can fetch, add, delete, and move it to a different location.
  • We use it to store large sizes of data like images, audio, video, and so on.
  • We can store the data here instead of shared preferences or local database.

π™·πš˜πš  𝚝𝚘 𝚞𝚜𝚎 πšπš‘πšŽ πšπš’πš•πšŽ πšœπš’πšœπšπšŽπš–

  • We need to get access to the root-file or root-directory.
  • Once we have the access, we can add more children files within the accessed location.
  • The file is created with a name using the stream

π™·πš˜πš  πšπš‘πšŽ πšœπšπš›πšŽπšŠπš–πšœ πš πš˜πš›πš”

  • Stream is a pipe that can send data in one direction, or receive the data from the other direction.
  • We have two types of streams an input stream and an output stream.
    • Input streams ---> Used for reading data from a file.
    • Output streams --> Used for writing data to a file.
  • We get a reference to a file or directory, Then Using that obtained reference create an input stream or the output stream. Then using the particular stream we modify or read the data.

πšƒπš’πš™πšŽπšœ 𝚘𝚏 πš‚πšπš˜πš›πšŠπšπšŽπšœ πš’πš— π™°πš—πšπš›πš˜πš’πš

π™Έπš—πšπšŽπš›πš—πšŠπš• πš‚πšπš˜πš›πšŠπšπšŽ

  • Each application has a private directory.
  • Thus many applications have their own individual private directories
  • The private directory of one application is not visible to the other application.
  • This is the easiest way of storing the data
  • Permission is not required to store the data in the internal storage

π™΄πš‘πšπšŽπš›πš—πšŠπš• πš‚πšπš˜πš›πšŠπšπšŽ

  • Everything else apart from the internal storage is considered as external storage.
  • Permission is required for storing data in external storage.
  • Once you store the data(ex:-image) in the external storage, all the apps can access this data.
  • But all the images stored in external storage are tracked by the apps that created it.
  • Say application-1 creates one image in the external storage, and the application-2 cannot delete it directly, instead requires the permission of the user before deleting it.

π™Ώπš›πš˜πš‹πš•πšŽπš–πšœ πšŠπšœπšœπš˜πšŒπš’πšŠπšπšŽπš πš πš’πšπš‘ πšŽπš‘πšπšŽπš›πš—πšŠπš• πšœπšπš˜πš›πšŠπšπšŽ

  • Lot of applications need permission.
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
  • Basically anyone with the above permission can access the files from external storage. Describing more like say We build an app and we can access all the images stored in external storage using above permission
  • But most of them do only simple things with it. One example of this is you want to access photos in external storage, but you might not need pdf, doc etc.
  • They might not have needed to access the whole storage but earlier they could.
  • The files are left in external storage sometimes and occupy space.
  • Even though the application is un-installed still the files are left as it is in the external storage.

π™·πš˜πš  πšœπšŒπš˜πš™πšŽπš πšœπšπš˜πš›πšŠπšπšŽ πš’πšœ 𝚊 πšœπš˜πš•πšžπšπš’πš˜πš— 𝚝𝚘 πšŽπš‘πšπšŽπš›πš—πšŠπš• πšœπšπš˜πš›πšŠπšπšŽ πšπš›πšŠπš πš‹πšŠπšŒπš”πšœ

Scope storage was introduced to increase user privacy and give the end-user the decision making step to control their privacy

  • Scoped storage was a solution to the problem.
  • Scoped storage is optional in android-10 but has become compulsory in android-11.
  • Because of scoped storage, System knows which application has created which file and has a track of each file, Thus when an application is uninstalled all the files that it created are also un-installed.
  • Every application has access to its directory in external storage and does not need permission.

π™Όπš˜πšπš’πšπš’πš’πš—πš πšπš’πš•πšŽπšœ πš’πš— πšŽπš‘πšπšŽπš›πš—πšŠπš• πšœπšπš˜πš›πšŠπšπšŽ πšŒπš›πšŽπšŠπšπšŽπš πšπš›πš˜πš– πš˜πšπš‘πšŽπš› πšŠπš™πš™πš•πš’πšŒπšŠπšπš’πš˜πš—πšœ?

  • We can perform this action using createWriteRequest, createDeleteRequest and modify the files in the directory created by other applications in external storage
  • But the catch here is, that it requires the approval of the user.

π™³πšŽπš•πšŽπšπš’πš—πš πšπš‘πšŽ πšπš’πš•πšŽπšœ

  • We can now move the files to the trash instead of deleting them.
  • We can recover the items from the trash in a 30-days life span.

πš‚πš™πšŽπšŒπš’πšŠπš• πšŠπš™πš™πš•πš’πšŒπšŠπšπš’πš˜πš—πšœ πšπš‘πšŠπš πš’πš—πšŸπš˜πš•πšŸπšŽ πšπš’πš•πšŽ πš‘πšŠπš—πšπš•πš’πš—πš

  • Some of the applications that are just developed to handle the files themselves need access to the entire file system because that's the primary purpose of the application. How will that get handled is using special permission called.
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>
  • If we add this permission, we do get access to the entire file folder.
  • But to add this to the play store, we need to follow a review process and approval from google justifying why this permission is required.
  • After all the process, like any other permission, end users can disable the permission in the settings.

πš‚πšžπš™πš™πš˜πš›πš β˜•

If you feel like support me a coffee for my efforts, I would greatly appreciate it.
Buy Me A Coffee

π™²πš˜πš—πšπš›πš’πš‹πšžπšπšŽ πŸ™‹β€β™‚οΈ

Read contribution guidelines for more information regarding contribution.

π™΅πšŽπšŽπšπš‹πšŠπšŒπš” ✍️

Feature requests are always welcome, File an issue here.

π™΅πš’πš—πš πšπš‘πš’πšœ πš™πš›πš˜πš“πšŽπšŒπš πšžπšœπšŽπšπšžπš• ? ❀️

Support it by clicking the ⭐ button on the upper right of this page. ✌️

π™»πš’πšŒπšŽπš—πšœπšŽ Licence πŸ’³

This project is licensed under the Apache License 2.0 - see the LICENSE file for details

About

Scoped storage came on the scene from Android 10 giving importance to users privacy

License:Apache License 2.0


Languages

Language:Kotlin 100.0%