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 卡读写权限受到了限制?

  • 相关阅读:
    树链剖分学习笔记
    [bzoj4445] [SCOI2015]小凸想跑步 (半平面交)
    上下界网络流学习笔记
    LocalMaxima_NOI导刊2009提高(1)(欧拉-马斯刻若尼常数)
    公告
    构造函数
    矩阵线段树
    [SCOI2005]互不侵犯
    牛客网NOIP赛前集训营-提高组(第四场)B区间
    noip提高组模拟赛(QBXT)T2
  • 原文地址:https://www.cnblogs.com/jacobchen/p/3579265.html
Copyright © 2011-2022 走看看