PackageReceiver: Only fetch the one PackageInfo
We were fetching information on all installed packages and doing a linear search. Which is silly and inefficient since we can directly fetch information on a single installed package by id.
This commit is contained in:
parent
1a4c2ca408
commit
e085e0392b
@ -23,6 +23,7 @@ import android.content.BroadcastReceiver;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.PackageInfo;
|
import android.content.pm.PackageInfo;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
|
|
||||||
import org.fdroid.fdroid.Utils;
|
import org.fdroid.fdroid.Utils;
|
||||||
import org.fdroid.fdroid.data.ApkProvider;
|
import org.fdroid.fdroid.data.ApkProvider;
|
||||||
@ -37,12 +38,13 @@ abstract class PackageReceiver extends BroadcastReceiver {
|
|||||||
protected abstract void handle(Context context, String appId);
|
protected abstract void handle(Context context, String appId);
|
||||||
|
|
||||||
protected PackageInfo getPackageInfo(Context context, String appId) {
|
protected PackageInfo getPackageInfo(Context context, String appId) {
|
||||||
for (PackageInfo info : context.getPackageManager().getInstalledPackages(0)) {
|
PackageInfo info = null;
|
||||||
if (info.packageName.equals(appId)) {
|
try {
|
||||||
return info;
|
info = context.getPackageManager().getPackageInfo(appId, 0);
|
||||||
}
|
} catch (PackageManager.NameNotFoundException e) {
|
||||||
|
// ignore
|
||||||
}
|
}
|
||||||
return null;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user