zoukankan      html  css  js  c++  java
  • Android外部存储

    预备知识External Storage Technical Information

    摘要

    "The WRITE_EXTERNAL_STORAGE permission must only grant write access to the primary external storage on a device. Apps must not be allowed to write to secondary external storage devices, except in their package-specific directories as allowed by synthesized permissions. Restricting writes in this way ensures the system can clean up files when applications are uninstalled."

    "Starting in Android 4.4, multiple external storage devices are surfaced to developers through Context.getExternalFilesDirs(), Context.getExternalCacheDirs(), and Context.getObbDirs()."

    Q&A

    *Primary external storage? Secondary external storage?
    -参考source.android.com/devices/tech/storage/config-example.html
    有的手机不支持SD卡扩展(如Nexus 4),所以没有secondary;
    有的手机支持(如Note 3),所以区分primary和secondary。
    是否primary,由android/frameworks/base/core/res/res/xml/storage_list.xml决定。

    一般地,primary是由内部存储(internal storage,比如NAND eMMC)中划分一部分为外部存储(external storage);mountPoint为"/storage/sdcard0";subsystem为"fuse",也就是由FUSE daemon模拟的。
    secondary是可插拔(removable)的SD卡,mountPoint为"/storage/sdcard1"或"/storage/extSdCard";subsystem为"sd"。

    *什么是package-specific directories?
    -如package名为com.app.foo在primary/secondary的Android/data/com.app.foo目录。
    /Android/data目录是由android/system/core/sdcard.c::handle_mkdir被调用时创建的,并同时新建.nomedia文件。
    Context.getExternalFilesDirs(), Context.getExternalCacheDirs()会触发创建package-specific directories。
    而Context.getObbDirs()会触发创建/Android/obb/。

    *app对于SD卡的write权限范围分别在哪儿?
    -在Note3上试验:
    1.不声明WRITE_EXTERNAL_STORAGE情况下,不管是primary还是secondary,在package目录下能够写文件,在Android/data/下都会抛出IOException;
    2.声明后,primary能够在Android/data/目录下写文件,而secondary依然IOException。
    "For example, the app with package name com.example.foo can now freely access Android/data/com.example.foo/ on external storage devices with no permissions."
    "Specifically, configuration and log files should only be stored on internal storage where they can be effectively protected."

    相关讨论:
    为什么 Android 4.4 KitKat 系统下第三方应用的 SD 卡读写权限受到了限制?

  • 相关阅读:
    20201303 2019-2020-2 《Python程序设计》实验三报告
    20201303 2020-2021-2 《Python程序设计》实验二报告
    20201303张奕博 实验一 Python程序设计入门
    2020-2021-1博客汇总
    俄罗斯方块and四则运算实践
    python对于数据库的相关实践
    20201303获奖感言与学习体会
    openssl实践
    2021-2022 2113 2114信息安全导论 第五周总结
    第九章第十章
  • 原文地址:https://www.cnblogs.com/jacobchen/p/3579265.html
Copyright © 2011-2022 走看看