check whether installed APKs exist and are readable before hashing

I guess APKs could disappear, or perhaps not be readable.

closes #699

Here's the stacktrace:

java.io.FileNotFoundException:
 /system/priv-app/ATT_Ready2Go/ATT_Ready2Go.apk: open failed: ENOENT (No such file or directory)
 at org.fdroid.fdroid.Utils.getBinaryHash(Utils.java:405)
 at org.fdroid.fdroid.data.InstalledAppProviderService.onHandleIntent(InstalledAppProviderService.java:164)
 at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
 at android.os.Handler.dispatchMessage(Handler.java:102)
 at android.os.Looper.loop(Looper.java:135)
 at android.os.HandlerThread.run(HandlerThread.java:61)
This commit is contained in:
Hans-Christoph Steiner 2016-08-23 22:56:31 +02:00
parent fa112ed303
commit 53cbb26209

View File

@ -160,10 +160,13 @@ public class InstalledAppProviderService extends IntentService {
if (ACTION_INSERT.equals(action)) {
PackageInfo packageInfo = getPackageInfo(intent, packageName);
if (packageInfo != null) {
File apk = new File(packageInfo.applicationInfo.publicSourceDir);
if (apk.exists() && apk.canRead()) {
String hashType = "sha256";
String hash = Utils.getBinaryHash(new File(packageInfo.applicationInfo.publicSourceDir), hashType);
String hash = Utils.getBinaryHash(apk, hashType);
insertAppIntoDb(this, packageInfo, hashType, hash);
}
}
} else if (ACTION_DELETE.equals(action)) {
deleteAppFromDb(this, packageName);
}