Adding our own cache of currently installed apks in the database.
authorPeter Serwylo <peter@ivt.com.au>
Sun, 13 Apr 2014 14:08:31 +0000 (00:08 +1000)
committerPeter Serwylo <peter@ivt.com.au>
Sun, 20 Apr 2014 07:20:22 +0000 (16:50 +0930)
commit4e24050760f6295e11020813cf9ecc17319c44cb
tree9f14f8e1b643ce30401c872f3d11e242555d93f4
parent655f2bf7e3243d4f2608cdc74ee963af1959e552
Adding our own cache of currently installed apks in the database.

Previously the data was not stored anywhere, and each time we wanted
to know about all installed apps, we built a ridiculously long SQL
query. The query had essentially one "OR" clause for each installed
app. To make matters worse, it also required one parameter for each
of these, so we could bind the installed app name to a "?" in the query.
SQL has a limit of (usually) 999 parameters which can be provided to
a query, which meant it would fall over if the user had more than
1000 apps installed.

This change introduces a new table called "fdroid_installedApps".
It is initialized on first run, by iterating over the installed apps
as given by the PackageManager. It is subsequenty kept up to date
by a set of BroadcastReceivers, which listen for apps being
uninstalled/installed/upgraded.

It also includes tests to verify that queries of installed apps,
when there are more than 1000 apps installed, don't break.

Finally, tests are also now able to to insert into providers other
than the one under test. This is due to the fact that the providers
often join onto tables managed by other providers.
26 files changed:
AndroidManifest.xml
src/org/fdroid/fdroid/AppDetails.java
src/org/fdroid/fdroid/FDroidApp.java
src/org/fdroid/fdroid/PackageAddedReceiver.java [new file with mode: 0644]
src/org/fdroid/fdroid/PackageReceiver.java
src/org/fdroid/fdroid/PackageRemovedReceiver.java [new file with mode: 0644]
src/org/fdroid/fdroid/PackageUpgradedReceiver.java [new file with mode: 0644]
src/org/fdroid/fdroid/UpdateService.java
src/org/fdroid/fdroid/Utils.java
src/org/fdroid/fdroid/data/ApkProvider.java
src/org/fdroid/fdroid/data/App.java
src/org/fdroid/fdroid/data/AppProvider.java
src/org/fdroid/fdroid/data/DBHelper.java
src/org/fdroid/fdroid/data/FDroidProvider.java
src/org/fdroid/fdroid/data/InstalledAppCacheUpdater.java [new file with mode: 0644]
src/org/fdroid/fdroid/data/InstalledAppProvider.java [new file with mode: 0644]
src/org/fdroid/fdroid/data/QueryBuilder.java
src/org/fdroid/fdroid/views/AppListAdapter.java
src/org/fdroid/fdroid/views/fragments/AppListFragment.java
test/src/mock/MockInstallablePackageManager.java
test/src/org/fdroid/fdroid/AppProviderTest.java
test/src/org/fdroid/fdroid/FDroidProviderTest.java
test/src/org/fdroid/fdroid/InstalledAppCacheTest.java [new file with mode: 0644]
test/src/org/fdroid/fdroid/InstalledAppProviderTest.java [new file with mode: 0644]
test/src/org/fdroid/fdroid/TestUtils.java
test/src/org/fdroid/fdroid/mock/MockInstalledApkCache.java [deleted file]