自己放某个文件到/cache分区,重启后发现文件消失了,那么是怎么消失的呢?


Step 1.

packages\providers\DownloadProvider\src\com\android\providers\downloads\StorageManager.java:

[html] view plain copy print ?
  1. /**
  2. *Removesfilesinthesystemcacheanddownloadsdatadirwithoutcorrespondingentriesin
  3. *thedownloadsdatabase.
  4. *Thiscanoccurifadeleteisdoneonthedatabasebutthefileisnotremovedfromthe
  5. *filesystem(duetosuddendeathoftheprocess,forexample).
  6. *Thisisnotaverycommonoccurrence.So,dothisonlyonceinawhile.
  7. */
  8. privatevoidremoveSpuriousFiles(){
  9. if(true||Constants.LOGV){
  10. Log.i(Constants.TAG,"inremoveSpuriousFiles");
  11. }
  12. //getalistofallfilesinsystemcachediranddownloadsdatadir
  13. List<File>files=newArrayList<File>();
  14. File[]listOfFiles=mSystemCacheDir.listFiles();
  15. if(listOfFiles!=null){
  16. files.addAll(Arrays.asList(listOfFiles));
  17. }
  18. listOfFiles=mDownloadDataDir.listFiles();
  19. if(listOfFiles!=null){
  20. files.addAll(Arrays.asList(listOfFiles));
  21. }
  22. if(files.size()==0){
  23. return;
  24. }
  25. Cursorcursor=mContext.getContentResolver().query(
  26. Downloads.Impl.ALL_DOWNLOADS_CONTENT_URI,
  27. newString[]{Downloads.Impl._DATA},null,null,null);
  28. try{
  29. if(cursor!=null){
  30. while(cursor.moveToNext()){
  31. Stringfilename=cursor.getString(0);
  32. if(!TextUtils.isEmpty(filename)){
  33. if(true||Constants.LOGV){
  34. Log.i(Constants.TAG,"inremoveSpuriousFiles,preservingfile"+
  35. filename);
  36. }
  37. files.remove(newFile(filename));
  38. }
  39. }
  40. }
  41. }finally{
  42. if(cursor!=null){
  43. cursor.close();
  44. }
  45. }
  46. //deletethefilesnotfoundinthedatabase
  47. for(Filefile:files){
  48. if(file.getName().equals(Constants.KNOWN_SPURIOUS_FILENAME)||
  49. file.getName().equalsIgnoreCase(Constants.RECOVERY_DIRECTORY)){
  50. continue;
  51. }
  52. if(true||Constants.LOGV){
  53. Log.i(Constants.TAG,"deletingspuriousfile"+file.getAbsolutePath());
  54. }
  55. file.delete();
  56. }
  57. }
[html] view plain copy print ?
  1. /**Amagicfilenamethatisallowedtoexistwithinthesystemcache*/
  2. publicstaticfinalStringKNOWN_SPURIOUS_FILENAME="lost+found";
  3. /**Amagicfilenamethatisallowedtoexistwithinthesystemcache*/
  4. publicstaticfinalStringRECOVERY_DIRECTORY="recovery";

除 lost+found, recovery这两个目录外的文件都删掉


Setp 2.

frameworks\base\core\java\android\os\RecoverySystem.java:

[html] view plain copy print ?
  1. /**
  2. *Calledafterbootingtoprocessandremoverecovery-relatedfiles.
  3. *@returnthelogfilefromrecovery,ornullifnonewasfound.
  4. *
  5. *@hide
  6. */
  7. publicstaticStringhandleAftermath(){
  8. //RecordthetailoftheLOG_FILE
  9. Stringlog=null;
  10. try{
  11. log=FileUtils.readTextFile(LOG_FILE,-LOG_FILE_MAX_LENGTH,"...\n");
  12. }catch(FileNotFoundExceptione){
  13. Log.i(TAG,"Norecoverylogfile");
  14. }catch(IOExceptione){
  15. Log.e(TAG,"Errorreadingrecoverylog",e);
  16. }
  17. //DeleteeverythinginRECOVERY_DIRexceptthosebeginning
  18. //withLAST_PREFIX
  19. String[]names=RECOVERY_DIR.list();
  20. for(inti=0;names!=null&&i<names.length;i++){
  21. if(names[i].startsWith(LAST_PREFIX))continue;
  22. Filef=newFile(RECOVERY_DIR,names[i]);
  23. if(!f.delete()){
  24. Log.e(TAG,"Can'tdelete:"+f);
  25. }else{
  26. Log.i(TAG,"Deleted:"+f);
  27. }
  28. }
  29. returnlog;
  30. }
[html] view plain copy print ?
  1. privatestaticStringLAST_PREFIX="last_";
/cache/recovery目录中,除last_开头的文件都删掉


------------------------------------------------

开机走完这两步后幸存的文件只有 /cache/lost+found目录中的文件,及/cache/recovery/last_ 开头的文件了

来自:http://blog.csdn.net/zmyde2010/article/details/7408207


更多相关文章

  1. 一款常用的 Squid 日志分析工具
  2. GitHub 标星 8K+!一款开源替代 ls 的工具你值得拥有!
  3. RHEL 6 下 DHCP+TFTP+FTP+PXE+Kickstart 实现无人值守安装
  4. Linux 环境下实战 Rsync 备份工具及配置 rsync+inotify 实时同步
  5. Android之——AIDL小结
  6. android(NDK+JNI)---NDK编译生成so文件
  7. android java.lang.IllegalArgumentException contains a path s
  8. android选择图片或拍照图片上传到服务器(包括上传参数)
  9. Android(安卓)App程序结构

随机推荐

  1. Android(安卓)dependency has different
  2. Android获取3G或WiFi流量信息
  3. android查看so动态库的接口
  4. Android顶部菜单实现
  5. Android对话框之Context
  6. 修改Android(安卓)4.2 源码使支持softap
  7. 打开关闭android如何默认打开小区广播?
  8. “Unable to execute dex: Multiple dex
  9. Android下如何获取CPU序列号
  10. android美化短信聊天记录使得输入长短信