From 5f31703316b479d511d47cab1bcb096893764ebb Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Mon, 5 May 2014 20:25:55 -0400 Subject: [PATCH] init SelectLocalApps list from the apks in the local repo When FDroid has been started, this checks the symlinked APKs in the local repo and uses those package names to build up the list of selected local apps. This gives the SelectLocalApps experience continuity across app restarts. refs #3204 https://dev.guardianproject.info/issues/3204 --- src/org/fdroid/fdroid/FDroidApp.java | 3 +-- .../fdroid/fdroid/localrepo/LocalRepoManager.java | 8 ++------ .../views/fragments/SelectLocalAppsFragment.java | 13 +++++++++++++ 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/org/fdroid/fdroid/FDroidApp.java b/src/org/fdroid/fdroid/FDroidApp.java index d88aae18c..24a572b8b 100644 --- a/src/org/fdroid/fdroid/FDroidApp.java +++ b/src/org/fdroid/fdroid/FDroidApp.java @@ -66,7 +66,6 @@ import java.security.KeyManagementException; import java.security.KeyStore; import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; -import java.util.HashSet; import java.util.Set; import javax.net.ssl.HttpsURLConnection; @@ -85,7 +84,7 @@ public class FDroidApp extends Application { public static String bssid = ""; public static Repo repo = new Repo(); public static LocalRepoManager localRepo = null; - public static Set selectedApps = new HashSet(); + public static Set selectedApps = null; // init in SelectLocalAppsFragment private static Messenger localRepoServiceMessenger = null; private static boolean localRepoServiceIsBound = false; diff --git a/src/org/fdroid/fdroid/localrepo/LocalRepoManager.java b/src/org/fdroid/fdroid/localrepo/LocalRepoManager.java index 240216da0..0a85bf4cd 100644 --- a/src/org/fdroid/fdroid/localrepo/LocalRepoManager.java +++ b/src/org/fdroid/fdroid/localrepo/LocalRepoManager.java @@ -220,7 +220,6 @@ public class LocalRepoManager { OutputStream out = sh.getOutputStream(); String command = "/system/bin/ln -s " + inFile.getAbsolutePath() + " " + outFile + "\nexit\n"; - Log.i(TAG, "Running: " + command); out.write(command.getBytes("ASCII")); final char buf[] = new char[40]; @@ -239,7 +238,6 @@ public class LocalRepoManager { e.printStackTrace(); return false; } - Log.i(TAG, "symlink exitcode: " + exitCode); return exitCode == 0; } @@ -258,12 +256,10 @@ public class LocalRepoManager { } } - public static boolean doCopyStream(InputStream inStream, OutputStream outStream) - { + public static boolean doCopyStream(InputStream inStream, OutputStream outStream) { byte[] buf = new byte[1024]; int readBytes; - try - { + try { while ((readBytes = inStream.read(buf)) > 0) { outStream.write(buf, 0, readBytes); } diff --git a/src/org/fdroid/fdroid/views/fragments/SelectLocalAppsFragment.java b/src/org/fdroid/fdroid/views/fragments/SelectLocalAppsFragment.java index 9eff92157..b9a6b7ce8 100644 --- a/src/org/fdroid/fdroid/views/fragments/SelectLocalAppsFragment.java +++ b/src/org/fdroid/fdroid/views/fragments/SelectLocalAppsFragment.java @@ -33,6 +33,8 @@ import org.fdroid.fdroid.data.InstalledAppProvider; import org.fdroid.fdroid.data.InstalledAppProvider.DataColumns; import org.fdroid.fdroid.views.SelectLocalAppsActivity; +import java.util.HashSet; + public class SelectLocalAppsFragment extends ListFragment implements LoaderCallbacks { private SelectLocalAppsActivity selectLocalAppsActivity; @@ -69,6 +71,17 @@ public class SelectLocalAppsFragment extends ListFragment implements LoaderCallb // either reconnect with an existing loader or start a new one getLoaderManager().initLoader(0, null, this); + + // build list of existing apps from what is on the file system + if (FDroidApp.selectedApps == null) { + FDroidApp.selectedApps = new HashSet(); + for (String filename : FDroidApp.localRepo.repoDir.list()) { + if (filename.matches(".*\\.apk")) { + String packageName = filename.substring(0, filename.indexOf("_")); + FDroidApp.selectedApps.add(packageName); + } + } + } } @TargetApi(11)