mirror of
https://github.com/f-droid/fdroidclient.git
synced 2026-06-18 20:59:48 -04:00
move main project files into standard gradle/Android Studio layout
This makes it a lot easier to setup all the testing stuff. Mostly, I'm tired of fighting Android Studio's fragility, so I want to remove as much non-standardness as possible in the hopes of improving that situation. closes #534 https://gitlab.com/fdroid/fdroidclient/issues/534
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
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 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;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user