Android上的现代用户存储

To protect user data and reduce the amount of space consumed by apps, Android 10 introduced changes to the behavior of the external storage permission. Android 11 Developer Preview continues this effort while adding improvements designed to help developers adapt to the changes.

为了保护用户数据并减少应用程序占用的空间量,Android 10引入了对外部存储权限行为的更改。 Android 11开发人员预览版将继续这项工作,同时添加旨在帮助开发人员适应更改的改进。

Most of the apps published on Google Play that request the storage permission do so for common reasons, such as saving files on SD cards or reading media files. These apps are able to save a large number of files on disk that remain after the app is uninstalled. They can also read potentially sensitive files from other apps.

在Google Play上发布的大多数需要存储权限的应用都是出于常见原因这样做的,例如将文件保存在SD卡上或读取媒体文件。 这些应用程序能够在卸载应用程序后将大量文件保留在磁盘上。 他们还可以从其他应用程序读取可能敏感的文件。

With Android 10, we adjusted how storage permission works, to give apps the access they need. This also limits file clutter by encouraging apps to save files in their designated directories which are cleared when an app is deleted.

使用Android 10,我们调整了存储权限的工作方式,为应用提供所需的访问权限。 通过鼓励应用程序将文件保存在指定目录中,这些文件会在删除应用程序时清除,从而限制了文件混乱。

The storage changes in Android 10 followed three basic principles:

Android 10中的存储更改遵循以下三个基本原则:

  • Better attribution: The system knows what files belong to which apps, making it easier for users to manage their files. And when an app is uninstalled, the content that it created shouldn’t stay unless the user wants it to

    更好的归因 :系统知道哪些文件属于哪些应用程序,从而使用户更易于管理文件。 而且,在卸载应用程序后,除非用户希望该应用程序创建的内容,否则不应保留该内容

  • Protecting app data: When an app writes app-specific files to external storage, these files should not be visible to other apps

    保护应用程序数据 :当一个应用程序将特定于应用程序的文件写入外部存储时,其他应用程序应该看不到这些文件

  • Protecting user data: When the user downloads files, such as sensitive email attachments, these files should not be visible to most apps

    保护用户数据 :当用户下载文件(例如敏感的电子邮件附件)时,这些文件对大多数应用程序都不可见

Apps targeting Android 10 can contribute to their own external app directories and organize media collections (audio, video, images, and downloads) without needing to request the storage permission. The Storage permission only allows apps to read media files shared by other apps in the audio, video, and image collections. However, it does not give read access to files in the Downloads collection that the app did not create. The only way for apps to access non-media files created by other apps in Android 10 is by using the document picker provided by the Storage Access Framework.

定位到Android 10的应用程序可以添加到自己的外部应用程序目录中,并组织媒体集合(音频,视频,图像和下载),而无需请求存储许可。 “存储”权限仅允许应用读取音频,视频和图像集合中其他应用共享的媒体文件。 但是,它不授予对该应用程序未创建的Downloads集合中文件的读取访问权限。 应用程序访问Android 10中其他应用程序创建的非媒体文件的唯一方法是使用Storage Access Framework提供的文档选择器。

In Android 11, we will continue to improve the developer experience related to Scoped Storage by introducing the following changes.

在Android 11中,我们将通过引入以下更改来继续改善与范围存储相关的开发人员体验。

媒体商店的改进 (Media store improvements)

Android 10 required that all apps use MediaStore APIs to access photos, videos, and music files. This will continue to be our recommendation. However, we understand that many apps depend heavily on APIs that use file paths, including third-party libraries, that cannot easily switch to using file descriptors. So in Android 11, APIs and libraries that use file paths will be enabled again. Your app can use the requestLegacyExternalStorage manifest attribute to ensure compatibility for users running Android 10.

Android 10要求所有应用都使用MediaStore API来访问照片,视频和音乐文件。 这将继续是我们的建议。 但是,我们了解到许多应用程序严重依赖使用文件路径的API(包括第三方库),而这些API无法轻易切换为使用文件描述符。 因此,在Android 11中,将再次启用使用文件路径的API和库。 您的应用可以使用requestLegacyExternalStorage清单属性来确保与运行Android 10的用户的兼容性。

Under the hood, I/O requests using file paths are delegated to the MediaStore API. This redirection has some performance impact when used to read files outside of your isolated storage. Further, using file paths does not provide any feature benefits over the MediaStore APIs, hence our strong recommendation to use the MediaStore directly.

在后台,使用文件路径的I / O请求被委派给MediaStore API。 当用于读取隔离存储之外的文件时,此重定向会对性能产生影响。 此外,与MediaStore API相比,使用文件路径不会提供任何功能优势,因此我们强烈建议直接使用MediaStore。

On Android 10, users were required to confirm each file that an app requested to edit or delete. With Android 11, apps can request to modify or delete several media files at once. The system gallery app will never show these dialogs. We hope that this improvement makes the user experience more streamlined.

在Android 10上,要求用户确认应用程序请求编辑或删除的每个文件。 使用Android 11,应用程序可以请求一次修改或删除多个媒体文件 。 系统图库应用程序将永远不会显示这些对话框。 我们希望这种改进可以使用户体验更加流畅。

存储访问框架更改 (Storage Access Framework changes)

After we limited access to broad storage, several app developers attempted to use the Storage Access framework to traverse the entire file system. However, SAF isn’t a suitable tool to support broad access to shared storage. We therefore updated it to limit visibility to certain paths.

在我们限制对广泛存储的访问之后,一些应用程序开发人员尝试使用Storage Access框架遍历整个文件系统。 但是,SAF不是支持广泛访问共享存储的合适工具。 因此,我们对其进行了更新,以将可见性限制为某些路径。

In Android 11, users will not be able to grant directory access to the root Downloads directory, the root directory of each reliable SD card volume, or external app directories. Apps can still use the Storage Access Framework API and the document picker to ask the user to select individual files from shared storage.

在Android 11中,用户将无法授予目录访问根下载目录,每个可靠SD卡卷的根目录或外部应用程序目录的权限。 应用程序仍然可以使用Storage Access Framework API和文档选择器来要求用户从共享存储中选择单个文件。

文件管理器应用程序的特殊权限 (Special permission for file manager apps)

For apps that require broad access to shared storage, such as file managers or backup apps, Android 11 will introduce a special permission called MANAGE_EXTERNAL_STORAGE. This will grant read and write access to all shared storage, including non-media files. However, the contents of app-specific directories, both within internal and external storage, will not be accessible.

对于需要广泛访问共享存储的应用程序(例如文件管理器或备份应用程序),Android 11将引入名为MANAGE_EXTERNAL_STORAGE的特殊权限。 这将授予对所有共享存储(包括非媒体文件)的读写访问权限。 但是,内部和外部存储中特定于应用程序的目录的内容将无法访问。

We want to continue allowing some apps to have broad access to files on external storage, provided they have a use case that truly requires it. In Android 11, these apps can declare MANAGE_EXTERNAL_STORAGE which will allow them to request the user to grant them “All Files Access” in settings. The following are a couple of app examples that will be allowed:

我们希望继续允许某些应用程序具有对外部存储中文件的广泛访问,只要它们具有真正需要的用例即可。 在Android 11中,这些应用可以声明MANAGE_EXTERNAL_STORAGE ,这将使它们可以请求用户在设置中授予他们“所有文件访问权限”。 以下是几个允许使用的应用示例:

  • File managers— apps whose main purpose is to let the user manage files

    文件管理器-主要目的是让用户管理文件的应用
  • Backup and restore — apps that require bulk access to files (e.g. switching devices or backing up to the cloud)

    备份和还原-需要批量访问文件的应用程序(例如,交换设备或备份到云)

However, if your app requires access to a single file, such as a word processor app, you should instead use the Storage Access Framework. You can check out the Google Play policy regarding this permission here.

但是,如果您的应用程序需要访问单个文件,例如文字处理器应用程序,则应改用Storage Access Framework。 您可以在此处查看有关此权限的Google Play政策。

On Android 11, if your app requires MANAGE_EXTERNAL_STORAGE or uses APIs that rely on file paths, you can support backwards compatibility on older versions by declaring requestLegacyExternalStorage=true in your Android manifest.

在Android 11上,如果您的应用程序需要MANAGE_EXTERNAL_STORAGE或使用依赖于文件路径的API,则可以通过在Android清单中声明requestLegacyExternalStorage=true来支持较旧版本的向后兼容性。

You can read more about this in the developer documentation and our talk from the Android Dev Summit 2019.

您可以在开发人员文档以及我们在Android Dev Summit 2019中的演讲中了解更多相关信息。

We value your feedback! You can report issues or feature requests through the issues tracker. Stay tuned for upcoming articles about how to use Scoped Storage with the MediaStore and Storage Access Framework APIs.

我们重视您的反馈! 您可以通过问题跟踪器报告问题或功能请求。 请继续关注有关如何将范围存储与MediaStore和Storage Access Framework API一起使用的文章。

翻译自: https://medium.com/androiddevelopers/modern-user-storage-on-android-e9469e8624f9

你可能感兴趣的:(python,android,安卓,java)