private void configImageLoader() {
    File cacheDir = StorageUtils.getCacheDirectory(getApplicationContext());
    if (cacheDir == null) {
      cacheDir = Environment.getDownloadCacheDirectory();
    }

    // TODO config image resolution cache for low end devices

    DisplayImageOptions options = getDefaultDisplayOptionsBuilder().build();
    int maxWidth = 800;
    int maxHeight = 480;
    int threadPoolSize = 1;

    ImageLoaderConfiguration.Builder builder =
        new ImageLoaderConfiguration.Builder(getApplicationContext())
            .threadPoolSize(threadPoolSize)
            .memoryCacheExtraOptions(maxWidth, maxHeight)
            .memoryCache(new LRULimitedMemoryCache(3 * 1024 * 1024))
            .diskCacheExtraOptions(maxWidth, maxHeight, null)
            .diskCache(new LimitedAgeDiskCache(cacheDir, 3600 * 24 * 7))
            .diskCacheFileNameGenerator(new HashCodeFileNameGenerator())
            .imageDownloader(new BaseImageDownloader(getApplicationContext()))
            .defaultDisplayImageOptions(options);

    ImageLoaderConfiguration config = builder.build();
    ImageLoader mImageLoader = ImageLoader.getInstance();
    mImageLoader.init(config);
  }
  /** Clean up orphan downloads, both in database and on disk. */
  public void cleanOrphans() {
    final ContentResolver resolver = getContentResolver();

    // Collect known files from database
    final HashSet<ConcreteFile> fromDb = Sets.newHashSet();
    final Cursor cursor =
        resolver.query(
            Downloads.Impl.ALL_DOWNLOADS_CONTENT_URI, OrphanQuery.PROJECTION, null, null, null);
    try {
      while (cursor.moveToNext()) {
        final String path = cursor.getString(OrphanQuery._DATA);
        if (TextUtils.isEmpty(path)) continue;

        final File file = new File(path);
        try {
          fromDb.add(new ConcreteFile(file));
        } catch (ErrnoException e) {
          // File probably no longer exists
          final String state = Environment.getExternalStorageState(file);
          if (Environment.MEDIA_UNKNOWN.equals(state) || Environment.MEDIA_MOUNTED.equals(state)) {
            // File appears to live on internal storage, or a
            // currently mounted device, so remove it from database.
            // This logic preserves files on external storage while
            // media is removed.
            final long id = cursor.getLong(OrphanQuery._ID);
            Slog.d(TAG, "Missing " + file + ", deleting " + id);
            resolver.delete(
                ContentUris.withAppendedId(Downloads.Impl.ALL_DOWNLOADS_CONTENT_URI, id),
                null,
                null);
          }
        }
      }
    } finally {
      IoUtils.closeQuietly(cursor);
    }

    // Collect known files from disk
    final int uid = android.os.Process.myUid();
    final ArrayList<ConcreteFile> fromDisk = Lists.newArrayList();
    fromDisk.addAll(listFilesRecursive(getCacheDir(), null, uid));
    fromDisk.addAll(listFilesRecursive(getFilesDir(), null, uid));
    fromDisk.addAll(listFilesRecursive(Environment.getDownloadCacheDirectory(), null, uid));

    Slog.d(TAG, "Found " + fromDb.size() + " files in database");
    Slog.d(TAG, "Found " + fromDisk.size() + " files on disk");

    // Delete files no longer referenced by database
    for (ConcreteFile file : fromDisk) {
      if (!fromDb.contains(file)) {
        Slog.d(TAG, "Missing db entry, deleting " + file.file);
        file.file.delete();
      }
    }
  }
  public static String getDefaultSaveRootPath() {
    if (!TextUtils.isEmpty(DEFAULT_SAVE_ROOT_PATH)) {
      return DEFAULT_SAVE_ROOT_PATH;
    }

    if (FileDownloadHelper.getAppContext().getExternalCacheDir() == null) {
      return Environment.getDownloadCacheDirectory().getAbsolutePath();
    } else {
      return FileDownloadHelper.getAppContext().getExternalCacheDir().getAbsolutePath();
    }
  }
Example #4
0
 /** @return the root of the filesystem containing the given path */
 public static File getFilesystemRoot(String path) {
   File cache = Environment.getDownloadCacheDirectory();
   if (path.startsWith(cache.getPath())) {
     return cache;
   }
   File external = Environment.getExternalStorageDirectory();
   if (path.startsWith(external.getPath())) {
     return external;
   }
   throw new IllegalArgumentException("Cannot determine filesystem root for " + path);
 }
  /** 安装apk */
  private void installApk() {
    String fileAbsolutePath = null;
    File apkfile = null;
    //        LogUtil.e(TAG, " Environment.getExternalStorageDirectory() = "+
    // Environment.getExternalStorageDirectory());
    //        LogUtil.e(TAG, " Environment.getDownloadCacheDirectory() = "+
    // Environment.getDownloadCacheDirectory());
    //        LogUtil.e(TAG, " Environment.getDataDirectory() = "+ Environment.getDataDirectory());

    if (Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)) {
      fileAbsolutePath =
          Environment.getExternalStorageDirectory()
              + File.separator
              + filePath
              + File.separator
              + fileName;
      LogUtil.e(TAG, "MEDIA_MOUNTED + fileAbsolutePath = " + fileAbsolutePath);
    } else if (Environment.getDataDirectory() != null) {
      String dataDir = Environment.getDataDirectory().toString();
      fileAbsolutePath = dataDir + File.separator + fileName;
    } else if (Environment.getDownloadCacheDirectory() != null) {
      String downloadCacheDir = Environment.getDownloadCacheDirectory().toString();
      fileAbsolutePath = downloadCacheDir + File.separator + fileName;
    } else {
      LogUtil.e(TAG, mContext.getString(R.string.error_no_usable_storage));
    }

    // LogUtil.e(TAG, "fileAbsolutePath = " + fileAbsolutePath);
    if (fileAbsolutePath != null) apkfile = new File(fileAbsolutePath);
    if (apkfile != null && !apkfile.exists()) {
      return;
    }
    // LogUtil.e(TAG, "apkfile.getAbsolutePath() = " + apkfile.getAbsolutePath());
    Intent i = new Intent(Intent.ACTION_VIEW);
    // 安装,如果签名不一致,可能出现程序未安装提示
    i.setDataAndType(
        Uri.fromFile(new File(apkfile.getAbsolutePath())),
        "application/vnd.android.package-archive");
    mContext.startActivity(i);
  }
 public static File a(String s) {
   File file = Environment.getDownloadCacheDirectory();
   if (!s.startsWith(file.getPath())) {
     if (!s.startsWith((file = Environment.getExternalStorageDirectory()).getPath())) {
       throw new IllegalArgumentException(
           (new StringBuilder())
               .append("Cannot determine filesystem root for ")
               .append(s)
               .toString());
     }
   }
   return file;
 }
    @Override
    protected Void doInBackground(Void... params) {

      // note to future_me: yea one thinks we only need to search root here, but root was /system
      // for me and so
      // did not contain "/SDCARD" #dontoptimize
      // on my phone:
      // search in /system
      // (26110): search in /mnt/sdcard
      // (26110): search in /cache
      // (26110): search in /data
      search_in(Environment.getRootDirectory().toString());
      search_in(Environment.getExternalStorageDirectory().toString());
      search_in(Environment.getDownloadCacheDirectory().toString());
      search_in(Environment.getDataDirectory().toString());
      return null;
    }
Example #8
0
 public void mOnClick(View v) {
   switch (v.getId()) {
     case R.id.test:
       String rootdir = Environment.getRootDirectory().getAbsolutePath();
       String datadir = Environment.getDataDirectory().getAbsolutePath();
       String cachedir = Environment.getDownloadCacheDirectory().getAbsolutePath();
       mEdit.setText(
           String.format(
               "ext = %s\nroot=%s\ndata=%s\ncache=%s", mSdPath, rootdir, datadir, cachedir));
       break;
     case R.id.save:
       File dir = new File(mSdPath + "/dir");
       dir.mkdir();
       File file = new File(mSdPath + "/dir/file.txt");
       try {
         FileOutputStream fos = new FileOutputStream(file);
         String str = "This file exists in SDcard";
         fos.write(str.getBytes());
         fos.close();
         mEdit.setText("write success");
       } catch (FileNotFoundException e) {
         mEdit.setText("File Not Found." + e.getMessage());
       } catch (SecurityException e) {
         mEdit.setText("Security Exception");
       } catch (Exception e) {
         mEdit.setText(e.getMessage());
       }
       break;
     case R.id.load:
       try {
         FileInputStream fis = new FileInputStream(mSdPath + "/dir/file.txt");
         byte[] data = new byte[fis.available()];
         while (fis.read(data) != -1) {;
         }
         fis.close();
         mEdit.setText(new String(data));
       } catch (FileNotFoundException e) {
         mEdit.setText("File Not Found");
       } catch (Exception e) {;
       }
       break;
   }
 }
Example #9
0
 /**
  * 返回SD卡路径,如果没有返回默认的下载缓存路径
  *
  * @return the sD path
  */
 public static String getSDPath() {
   return isExternalStorageWritable()
       ? Environment.getExternalStorageDirectory().getPath()
       : Environment.getDownloadCacheDirectory().getPath();
 }
 public CacheFileDeletedObserver() {
   super(Environment.getDownloadCacheDirectory().getAbsolutePath(), FileObserver.DELETE);
 }
Example #11
0
  private String getDeviceInfos() throws IllegalAccessException, IllegalArgumentException {
    if (_deviceInfos != null) {
      return _deviceInfos;
    }

    String result = "<table>";
    List<Field> list = new ArrayList<Field>();

    list.addAll(Arrays.asList(android.os.Build.VERSION.class.getDeclaredFields()));
    list.addAll(Arrays.asList(android.os.Build.class.getDeclaredFields()));

    for (Field field : list) {
      field.setAccessible(true);
      try {
        result +=
            "<tr><td>"
                + field.getDeclaringClass().toString().substring(6).replace("$", ".")
                + "."
                + field.getName()
                + "</td><td>"
                + field.get(null).toString()
                + "</td></tr>\n";
      } catch (IllegalAccessException e1) {
      } catch (IllegalArgumentException e1) {
      }
    }

    for (Entry<Object, Object> e : System.getProperties().entrySet()) {
      result += "<tr><td>Property: " + e.getKey() + "</td><td>" + e.getValue() + "</td></tr>\n";
    }

    result +=
        "<tr><td>Environment: getDataDirectory()</td><td>"
            + Environment.getDataDirectory()
            + "</td></tr>\n";
    result +=
        "<tr><td>Environment: getDownloadCacheDirectory()</td><td>"
            + Environment.getDownloadCacheDirectory()
            + "</td></tr>\n";
    result +=
        "<tr><td>Environment: getExternalStorageDirectory()"
            + "</td><td>"
            + Environment.getExternalStorageDirectory()
            + "</td></tr>\n";
    result +=
        "<tr><td>Environment: getExternalStoragePublicDirectory(DIRECTORY_ALARMS)</td><td>"
            + Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_ALARMS)
            + "</td></tr>\n";
    result +=
        "<tr><td>Environment: getExternalStoragePublicDirectory(DIRECTORY_DCIM)</td><td>"
            + Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM)
            + "</td></tr>\n";
    result +=
        "<tr><td>Environment: getExternalStoragePublicDirectory(DIRECTORY_DOWNLOAD)</td><td>"
            + Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)
            + "</td></tr>\n";
    result +=
        "<tr><td>Environment: getExternalStoragePublicDirectory(DIRECTORY_MOVIES)</td><td>"
            + Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES)
            + "</td></tr>\n";
    result +=
        "<tr><td>Environment: getExternalStoragePublicDirectory(DIRECTORY_MUSIC)</td><td>"
            + Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC)
            + "</td></tr>\n";
    result +=
        "<tr><td>Environment: getExternalStoragePublicDirectory(DIRECTORY_NOTIFICATIONS)</td><td>"
            + Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_NOTIFICATIONS)
            + "</td></tr>\n";
    result +=
        "<tr><td>Environment: getExternalStoragePublicDirectory(DIRECTORY_PICTURES)</td><td>"
            + Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)
            + "</td></tr>\n";
    result +=
        "<tr><td>Environment: getExternalStoragePublicDirectory(DIRECTORY_PODCASTS)</td><td>"
            + Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PODCASTS)
            + "</td></tr>\n";
    result +=
        "<tr><td>Environment: getExternalStoragePublicDirectory(DIRECTORY_RINGTONES)</td><td>"
            + Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_RINGTONES)
            + "</td></tr>\n";
    result +=
        "<tr><td>Environment: getRootDirectory()</td><td>"
            + Environment.getRootDirectory()
            + "</td></tr>\n";

    result +=
        "<tr><td>Context: getPackageResourcePath()</td><td>"
            + _context.getPackageResourcePath()
            + "</td></tr>\n";
    result += "<tr><td>Context: getCacheDir()</td><td>" + _context.getCacheDir() + "</td></tr>\n";
    result +=
        "<tr><td>Context: getExternalCacheDir()</td><td>"
            + _context.getExternalCacheDir()
            + "</td></tr>\n";
    result +=
        "<tr><td>Context: getExternalFilesDir(DIRECTORY_ALARMS)</td><td>"
            + _context.getExternalFilesDir(Environment.DIRECTORY_ALARMS)
            + "</td></tr>\n";
    result +=
        "<tr><td>Context: getExternalFilesDir(DIRECTORY_DCIM)</td><td>"
            + _context.getExternalFilesDir(Environment.DIRECTORY_DCIM)
            + "</td></tr>\n";
    result +=
        "<tr><td>Context: getExternalFilesDir(DIRECTORY_DOWNLOADS)</td><td>"
            + _context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS)
            + "</td></tr>\n";
    result +=
        "<tr><td>Context: getExternalFilesDir(DIRECTORY_MOVIES)</td><td>"
            + _context.getExternalFilesDir(Environment.DIRECTORY_MOVIES)
            + "</td></tr>\n";
    result +=
        "<tr><td>Context: getExternalFilesDir(DIRECTORY_MUSIC)</td><td>"
            + _context.getExternalFilesDir(Environment.DIRECTORY_MUSIC)
            + "</td></tr>\n";
    result +=
        "<tr><td>Context: getExternalFilesDir(DIRECTORY_NOTIFICATIONS)</td><td>"
            + _context.getExternalFilesDir(Environment.DIRECTORY_NOTIFICATIONS)
            + "</td></tr>\n";
    result +=
        "<tr><td>Context: getExternalFilesDir(DIRECTORY_PICTURES)</td><td>"
            + _context.getExternalFilesDir(Environment.DIRECTORY_PICTURES)
            + "</td></tr>\n";
    result +=
        "<tr><td>Context: getExternalFilesDir(DIRECTORY_PODCASTS)</td><td>"
            + _context.getExternalFilesDir(Environment.DIRECTORY_PODCASTS)
            + "</td></tr>\n";
    result +=
        "<tr><td>Context: getExternalFilesDir(DIRECTORY_RINGTONES)</td><td>"
            + _context.getExternalFilesDir(Environment.DIRECTORY_RINGTONES)
            + "</td></tr>\n";

    result += "<tr><td>Context: getFilesDir()</td><td>" + _context.getFilesDir() + "</td></tr>\n";

    {
      for (Class<?> subclass : ContactsContract.CommonDataKinds.class.getDeclaredClasses()) {
        Log.d(AppConfig.TAG_APP, TAG + "getDeviceInfos: looking at " + subclass.getName());
        if (subclass != null) {
          Method m = null;

          for (Method mm : subclass.getDeclaredMethods()) {
            if (mm.getName().equals("getTypeLabelResource")
                || mm.getName().equals("getTypeResource")) {
              m = mm;
              break;
            }
          }

          if (m != null) {
            for (Field field : subclass.getDeclaredFields()) {
              if (field.getName().startsWith("TYPE_")) {
                Object obj = field.get(null);
                if (obj instanceof Integer) {
                  try {
                    int type = (Integer) obj;
                    int res = (Integer) m.invoke(null, type);

                    result +=
                        "<tr><td>ContactsContract.CommonDataKinds."
                            + field.getDeclaringClass().getSimpleName()
                            + "."
                            + field.getName()
                            + "</td><td>"
                            + _context.getString(res)
                            + "</td></tr>\n";
                  } catch (InvocationTargetException e1) {
                    Log.e(AppConfig.TAG_APP, TAG + "getDeviceInfos: error", e1);
                  }
                }
              }
            }
          }
        }
      }
    }

    result += "</table>";

    _deviceInfos = result;
    return result;
  }
Example #12
0
 /** Checks whether the filename looks legitimate */
 public static boolean isFilenameValid(String filename) {
   filename = filename.replaceFirst("/+", "/"); // normalize leading
   // slashes
   return filename.startsWith(Environment.getDownloadCacheDirectory().toString())
       || filename.startsWith(Environment.getExternalStorageDirectory().toString());
 }
Example #13
0
 protected final void DV()
 {
   boolean bool2 = true;
   Object localObject2 = null;
   hdM = ((ListView)findViewById(a.i.qqmail_file_explorer_list_lv));
   hdO = ((TextView)findViewById(a.i.root_tab));
   hdQ = findViewById(a.i.root_tab_selector);
   hdP = ((TextView)findViewById(a.i.sdcard_tab));
   hdR = findViewById(a.i.sdcard_tab_selector);
   a(new k(this));
   hdS = getString(a.n.plugin_qqmail_file_explorer_root_tag);
   hdT = getString(a.n.plugin_qqmail_file_explorer_sdcard_tag);
   File localFile1;
   label126:
   File localFile2;
   label140:
   Object localObject1;
   if (bn.iW(bisbhN))
   {
     localFile1 = Environment.getRootDirectory();
     if (!localFile1.canRead()) {
       break label470;
     }
     if (!ax.tl().isSDCardAvailable()) {
       break label497;
     }
     localFile2 = com.tencent.mm.compatible.util.j.getExternalStorageDirectory();
     h localh = ax.tl().rf();
     if (localFile1 != null) {
       break label558;
     }
     localObject1 = null;
     label155:
     localObject1 = (String)localh.get(131073, localObject1);
     if ((localObject1 == null) || (localFile1 == null) || (localFile1.getAbsolutePath().equals(localObject1))) {
       break label567;
     }
     localObject1 = new File((String)localObject1);
     if (!((File)localObject1).exists()) {
       break label567;
     }
     label210:
     hdU = ((File)localObject1);
     localh = ax.tl().rf();
     if (localFile2 != null) {
       break label573;
     }
     localObject1 = localObject2;
     label233:
     localObject1 = (String)localh.get(131074, localObject1);
     if ((localObject1 == null) || (localFile2 == null) || (localFile2.getAbsolutePath().equals(localObject1))) {
       break label583;
     }
     localObject1 = new File((String)localObject1);
     if (!((File)localObject1).exists()) {
       break label583;
     }
     label290:
     hdV = ((File)localObject1);
     hdN = new a((byte)0);
     if (localFile2 == null) {
       break label590;
     }
     lS(1);
     hdN.fqn = localFile2.getPath();
     hdN.a(hdV.getParentFile(), hdV);
     label349:
     localObject1 = hdO;
     if (localFile1 == null) {
       break label641;
     }
     bool1 = true;
     label361:
     ((TextView)localObject1).setEnabled(bool1);
     localObject1 = hdP;
     if (localFile2 == null) {
       break label646;
     }
   }
   label470:
   label497:
   label552:
   label558:
   label567:
   label573:
   label583:
   label590:
   label641:
   label646:
   for (boolean bool1 = bool2;; bool1 = false)
   {
     ((TextView)localObject1).setEnabled(bool1);
     hdM.setAdapter(hdN);
     hdN.notifyDataSetChanged();
     hdM.setOnItemClickListener(new l(this));
     hdO.setOnClickListener(new m(this, localFile1));
     hdP.setOnClickListener(new n(this, localFile2));
     return;
     localFile1 = new File(bisbhN);
     break;
     localFile1 = com.tencent.mm.compatible.util.j.getDataDirectory();
     if (localFile1.canRead())
     {
       hdS = localFile1.getName();
       break label126;
     }
     localFile1 = null;
     break label126;
     if (bn.iW(bisbhP)) {}
     for (localFile2 = Environment.getDownloadCacheDirectory();; localFile2 = new File(bisbhP))
     {
       if (!localFile2.canRead()) {
         break label552;
       }
       hdT = localFile2.getName();
       break;
     }
     localFile2 = null;
     break label140;
     localObject1 = localFile1.getAbsolutePath();
     break label155;
     localObject1 = localFile1;
     break label210;
     localObject1 = localFile2.getAbsolutePath();
     break label233;
     localObject1 = localFile2;
     break label290;
     if (localFile1 != null)
     {
       lS(0);
       hdN.fqn = localFile1.getPath();
       hdN.a(hdU.getParentFile(), hdU);
       break label349;
     }
     t.d("!32@/B4Tb64lLpKKG/WupdUGi6Sns9bhKpSP", "left and right tag disabled in the same time.");
     return;
     bool1 = false;
     break label361;
   }
 }