handle dirs and I/O errors when parsing ACTION_PACKAGE_ADDED Intents
InstalledAppProviderService tries to keep a running log of what is actually installed on the device. It seems that ApplicationInfo.sourceDir and related things sometimes returns a dir rather than an APK. So try to find an APK in that folder. closes #801
This commit is contained in:
parent
b852c0dca0
commit
b9dad4bce6
@ -11,11 +11,13 @@ import android.net.Uri;
|
|||||||
import android.os.Process;
|
import android.os.Process;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
|
|
||||||
|
import org.acra.ACRA;
|
||||||
import org.fdroid.fdroid.Hasher;
|
import org.fdroid.fdroid.Hasher;
|
||||||
import org.fdroid.fdroid.Utils;
|
import org.fdroid.fdroid.Utils;
|
||||||
import org.fdroid.fdroid.data.Schema.InstalledAppTable;
|
import org.fdroid.fdroid.data.Schema.InstalledAppTable;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FilenameFilter;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -154,17 +156,43 @@ public class InstalledAppProviderService extends IntentService {
|
|||||||
@Override
|
@Override
|
||||||
protected void onHandleIntent(Intent intent) {
|
protected void onHandleIntent(Intent intent) {
|
||||||
Process.setThreadPriority(Process.THREAD_PRIORITY_LOWEST);
|
Process.setThreadPriority(Process.THREAD_PRIORITY_LOWEST);
|
||||||
if (intent != null) {
|
if (intent == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
String packageName = intent.getData().getSchemeSpecificPart();
|
String packageName = intent.getData().getSchemeSpecificPart();
|
||||||
final String action = intent.getAction();
|
final String action = intent.getAction();
|
||||||
if (ACTION_INSERT.equals(action)) {
|
if (ACTION_INSERT.equals(action)) {
|
||||||
PackageInfo packageInfo = getPackageInfo(intent, packageName);
|
PackageInfo packageInfo = getPackageInfo(intent, packageName);
|
||||||
if (packageInfo != null) {
|
if (packageInfo != null) {
|
||||||
File apk = new File(packageInfo.applicationInfo.publicSourceDir);
|
File apk = new File(packageInfo.applicationInfo.publicSourceDir);
|
||||||
|
if (apk.isDirectory()) {
|
||||||
|
FilenameFilter filter = new FilenameFilter() {
|
||||||
|
@Override
|
||||||
|
public boolean accept(File dir, String name) {
|
||||||
|
return name.endsWith(".apk");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
File[] files = apk.listFiles(filter);
|
||||||
|
if (files == null) {
|
||||||
|
String msg = packageName + " sourceDir has no APKs: "
|
||||||
|
+ apk.getAbsolutePath();
|
||||||
|
Utils.debugLog(TAG, msg);
|
||||||
|
ACRA.getErrorReporter().handleException(new IllegalArgumentException(msg), false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
apk = files[0];
|
||||||
|
}
|
||||||
if (apk.exists() && apk.canRead()) {
|
if (apk.exists() && apk.canRead()) {
|
||||||
|
try {
|
||||||
String hashType = "sha256";
|
String hashType = "sha256";
|
||||||
String hash = Utils.getBinaryHash(apk, hashType);
|
String hash = Utils.getBinaryHash(apk, hashType);
|
||||||
insertAppIntoDb(this, packageInfo, hashType, hash);
|
insertAppIntoDb(this, packageInfo, hashType, hash);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
Utils.debugLog(TAG, e.getMessage());
|
||||||
|
ACRA.getErrorReporter().handleException(e, false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (ACTION_DELETE.equals(action)) {
|
} else if (ACTION_DELETE.equals(action)) {
|
||||||
@ -172,7 +200,6 @@ public class InstalledAppProviderService extends IntentService {
|
|||||||
}
|
}
|
||||||
notifyEvents.onNext(null);
|
notifyEvents.onNext(null);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class will either have received an intent from the {@link InstalledAppProviderService}
|
* This class will either have received an intent from the {@link InstalledAppProviderService}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user