Use proper cache storage location (issue #239)

This commit is contained in:
Ciaran Gultnieks 2013-07-10 11:34:19 +01:00
parent 80437abcc0
commit 9d51cd72ac
7 changed files with 28 additions and 17 deletions

View File

@ -379,7 +379,7 @@ public class AppDetails extends ListActivity {
// Set the icon...
ImageView iv = (ImageView) findViewById(R.id.icon);
File icon = new File(DB.getIconsPath(), app.icon);
File icon = new File(DB.getIconsPath(this), app.icon);
if (icon.exists()) {
iv.setImageDrawable(new BitmapDrawable(icon.getPath()));
} else {
@ -664,7 +664,8 @@ public class AppDetails extends ListActivity {
public void onClick(DialogInterface dialog,
int whichButton) {
downloadHandler = new DownloadHandler(curapk,
repoaddress);
repoaddress, DB
.getDataPath(getBaseContext()));
}
});
ask_alrt.setNegativeButton(getString(R.string.no),
@ -692,7 +693,8 @@ public class AppDetails extends ListActivity {
alert.show();
return;
}
downloadHandler = new DownloadHandler(curapk, repoaddress);
downloadHandler = new DownloadHandler(curapk, repoaddress,
DB.getDataPath(this));
}
private void removeApk(String id) {
@ -755,9 +757,9 @@ public class AppDetails extends ListActivity {
private boolean updating;
private String id;
public DownloadHandler(DB.Apk apk, String repoaddress) {
public DownloadHandler(DB.Apk apk, String repoaddress, File destdir) {
id = apk.id;
download = new Downloader(apk, repoaddress);
download = new Downloader(apk, repoaddress, destdir);
download.start();
startUpdates();
}

View File

@ -485,12 +485,19 @@ public class DB {
}
public static File getDataPath() {
return new File(Environment.getExternalStorageDirectory(), ".fdroid");
public static File getDataPath(Context ctx) {
File f;
if (Utils.hasApi(8)) {
f = ctx.getExternalCacheDir();
} else {
f = new File(Environment.getExternalStorageDirectory(),
"Android/data/org.fdroid.fdroid/cache");
}
return f;
}
public static File getIconsPath() {
return new File(getDataPath(), "icons");
public static File getIconsPath(Context ctx) {
return new File(getDataPath(ctx), "icons");
}
private Context mContext;

View File

@ -32,6 +32,7 @@ public class Downloader extends Thread {
private DB.Apk curapk;
private String repoaddress;
private String filename;
private File destdir;
private File localfile;
public static enum Status {
@ -50,9 +51,10 @@ public class Downloader extends Thread {
// Constructor - creates a Downloader to download the given Apk,
// which must have its detail populated.
Downloader(DB.Apk apk, String repoaddress) {
Downloader(DB.Apk apk, String repoaddress, File destdir) {
curapk = apk;
this.repoaddress = repoaddress;
this.destdir = destdir;
}
public synchronized Status getStatus() {
@ -97,7 +99,7 @@ public class Downloader extends Thread {
InputStream input = null;
OutputStream output = null;
String apkname = curapk.apkName;
localfile = new File(DB.getDataPath(), apkname);
localfile = new File(destdir, apkname);
try {
// See if we already have this apk cached...

View File

@ -36,7 +36,7 @@ public class FDroidApp extends Application {
public void onCreate() {
super.onCreate();
File local_path = DB.getDataPath();
File local_path = DB.getDataPath(this);
Log.d("FDroid", "Data path is " + local_path.getPath());
if (!local_path.exists())
local_path.mkdir();
@ -59,7 +59,7 @@ public class FDroidApp extends Application {
}
}
File icon_path = DB.getIconsPath();
File icon_path = DB.getIconsPath(this);
Log.d("FDroid", "Icon path is " + icon_path.getPath());
if (!icon_path.exists())
icon_path.mkdir();

View File

@ -79,10 +79,10 @@ public class Preferences extends PreferenceActivity implements
}
((FDroidApp) getApplication()).invalidateAllApps();
File dp = DB.getDataPath();
File dp = DB.getDataPath(this);
deleteAll(dp);
dp.mkdir();
DB.getIconsPath().mkdir();
DB.getIconsPath(this).mkdir();
Toast.makeText(getBaseContext(),
"Local cached data has been cleared", Toast.LENGTH_LONG)

View File

@ -320,7 +320,7 @@ public class UpdateService extends IntentService implements ProgressListener {
private void getIcon(DB.App app, List<DB.Repo> repos) {
try {
File f = new File(DB.getIconsPath(), app.icon);
File f = new File(DB.getIconsPath(this), app.icon);
if (f.exists())
return;

View File

@ -78,7 +78,7 @@ abstract public class AppListAdapter extends BaseAdapter {
summary.setText(app.summary);
ImageView icon = (ImageView) convertView.findViewById(R.id.icon);
File icn = new File(DB.getIconsPath(), app.icon);
File icn = new File(DB.getIconsPath(mContext), app.icon);
if (icn.exists() && icn.length() > 0) {
new Uri.Builder().build();
icon.setImageURI(Uri.parse(icn.getPath()));