mirror of
https://github.com/f-droid/fdroidclient.git
synced 2026-06-18 12:49:59 -04:00
InstalledAppCacheUpdater was a custom Service-like thing with some threading issues. InstalledAppProviderService is an IntentService that relies on the built-in queue and threading of the IntentService to make sure that things are processed nicely in the background and one at a time. This changes the announcing so that each app added/changed/deleted triggers a new annoucement. This keeps the UI more updated, and makes the Installed tab show something as soon as possible, rather than waiting for the all of the install apps to be processed. This becomes more important as more stuff is added to InstalledAppProvider, like the hash of the APK. This also strips down and simplifies the related BroadcastReceivers. BroadcastReceivers work on the UI thread, so they should do as little work as possible. PackageManagerReceiver just rebadges the incoming Intent and sends it off to InstalledAppProviderService for processing.
61 lines
1.7 KiB
Java
61 lines
1.7 KiB
Java
package mock;
|
|
|
|
import android.content.pm.ApplicationInfo;
|
|
import android.content.pm.PackageInfo;
|
|
import android.test.mock.MockPackageManager;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
|
|
public class MockInstallablePackageManager extends MockPackageManager {
|
|
|
|
private final List<PackageInfo> info = new ArrayList<>();
|
|
|
|
@Override
|
|
public List<PackageInfo> getInstalledPackages(int flags) {
|
|
return info;
|
|
}
|
|
|
|
@Override
|
|
public PackageInfo getPackageInfo(String id, int flags) {
|
|
for (PackageInfo i : info) {
|
|
if (i.packageName.equals(id)) {
|
|
return i;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public void install(String id, int version, String versionName) {
|
|
PackageInfo existing = getPackageInfo(id, 0);
|
|
if (existing != null) {
|
|
existing.versionCode = version;
|
|
existing.versionName = versionName;
|
|
} else {
|
|
PackageInfo p = new PackageInfo();
|
|
p.packageName = id;
|
|
p.versionCode = version;
|
|
p.versionName = versionName;
|
|
p.applicationInfo = new MockApplicationInfo(p);
|
|
info.add(p);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public ApplicationInfo getApplicationInfo(String packageName, int flags) throws NameNotFoundException {
|
|
return new MockApplicationInfo(getPackageInfo(packageName, 0));
|
|
}
|
|
|
|
public void remove(String id) {
|
|
for (Iterator<PackageInfo> it = info.iterator(); it.hasNext();) {
|
|
PackageInfo info = it.next();
|
|
if (info.packageName.equals(id)) {
|
|
it.remove();
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|