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

  • 相关阅读:
    按行打印二叉树结点值
    Kafka消息队列(继续深挖)
    【Java IO模式】Java BIO NIO AIO总结
    JAVA线程池的执行过程
    CentOS7升级版本
    【转】KVM中打开virt-manager报错或者将其显示为中文界面的办法
    【转】linux kvm虚拟机配置及常见问题处理
    【转】关于Quartus ii无法识别Modelsim路径的问题
    【转】[git]error: pack-objects died of signal
    storm kafka整合
  • 原文地址:https://www.cnblogs.com/jacobchen/p/3579265.html
Copyright © 2020-2023  润新知