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
This commit is contained in:
Hans-Christoph Steiner 2014-05-05 20:25:55 -04:00
parent 08346b9b18
commit 5f31703316
3 changed files with 16 additions and 8 deletions

View File

@ -66,7 +66,6 @@ import java.security.KeyManagementException;
import java.security.KeyStore; import java.security.KeyStore;
import java.security.KeyStoreException; import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.util.HashSet;
import java.util.Set; import java.util.Set;
import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.HttpsURLConnection;
@ -85,7 +84,7 @@ public class FDroidApp extends Application {
public static String bssid = ""; public static String bssid = "";
public static Repo repo = new Repo(); public static Repo repo = new Repo();
public static LocalRepoManager localRepo = null; public static LocalRepoManager localRepo = null;
public static Set<String> selectedApps = new HashSet<String>(); public static Set<String> selectedApps = null; // init in SelectLocalAppsFragment
private static Messenger localRepoServiceMessenger = null; private static Messenger localRepoServiceMessenger = null;
private static boolean localRepoServiceIsBound = false; private static boolean localRepoServiceIsBound = false;

View File

@ -220,7 +220,6 @@ public class LocalRepoManager {
OutputStream out = sh.getOutputStream(); OutputStream out = sh.getOutputStream();
String command = "/system/bin/ln -s " + inFile.getAbsolutePath() + " " + outFile String command = "/system/bin/ln -s " + inFile.getAbsolutePath() + " " + outFile
+ "\nexit\n"; + "\nexit\n";
Log.i(TAG, "Running: " + command);
out.write(command.getBytes("ASCII")); out.write(command.getBytes("ASCII"));
final char buf[] = new char[40]; final char buf[] = new char[40];
@ -239,7 +238,6 @@ public class LocalRepoManager {
e.printStackTrace(); e.printStackTrace();
return false; return false;
} }
Log.i(TAG, "symlink exitcode: " + exitCode);
return exitCode == 0; 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]; byte[] buf = new byte[1024];
int readBytes; int readBytes;
try try {
{
while ((readBytes = inStream.read(buf)) > 0) { while ((readBytes = inStream.read(buf)) > 0) {
outStream.write(buf, 0, readBytes); outStream.write(buf, 0, readBytes);
} }

View File

@ -33,6 +33,8 @@ import org.fdroid.fdroid.data.InstalledAppProvider;
import org.fdroid.fdroid.data.InstalledAppProvider.DataColumns; import org.fdroid.fdroid.data.InstalledAppProvider.DataColumns;
import org.fdroid.fdroid.views.SelectLocalAppsActivity; import org.fdroid.fdroid.views.SelectLocalAppsActivity;
import java.util.HashSet;
public class SelectLocalAppsFragment extends ListFragment implements LoaderCallbacks<Cursor> { public class SelectLocalAppsFragment extends ListFragment implements LoaderCallbacks<Cursor> {
private SelectLocalAppsActivity selectLocalAppsActivity; 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 // either reconnect with an existing loader or start a new one
getLoaderManager().initLoader(0, null, this); 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<String>();
for (String filename : FDroidApp.localRepo.repoDir.list()) {
if (filename.matches(".*\\.apk")) {
String packageName = filename.substring(0, filename.indexOf("_"));
FDroidApp.selectedApps.add(packageName);
}
}
}
} }
@TargetApi(11) @TargetApi(11)