Skip to content
This repository has been archived by the owner on Mar 9, 2022. It is now read-only.

Commit

Permalink
Remove artifacts of install over network code
Browse files Browse the repository at this point in the history
  • Loading branch information
daleharvey committed Aug 12, 2011
1 parent a575e9f commit ca52f26
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 48 deletions.
6 changes: 2 additions & 4 deletions src/com/couchbase/libcouch/CouchDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

public class CouchDB {

private static String releaseUrl;
private static String releaseName;

private static ICouchService couchService;
Expand All @@ -23,7 +22,7 @@ public class CouchDB {
public void onServiceConnected(ComponentName className, final IBinder service) {
try {
couchService = ICouchService.Stub.asInterface(service);
couchService.initCouchDB(couchClient, releaseUrl, releaseName);
couchService.initCouchDB(couchClient, releaseName);
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Expand All @@ -36,8 +35,7 @@ public void onServiceDisconnected(ComponentName className) {
}
};

public static ServiceConnection getService(Context ctx, String url, String release, ICouchClient client) {
releaseUrl = url;
public static ServiceConnection getService(Context ctx, String release, ICouchClient client) {
releaseName = release;
couchClient = client;
ctx.bindService(new Intent(ctx, CouchService.class), mConnection, Context.BIND_AUTO_CREATE);
Expand Down
47 changes: 8 additions & 39 deletions src/com/couchbase/libcouch/CouchInstaller.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
import org.apache.commons.compress.utils.IOUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

import android.os.Environment;
import android.os.Handler;
import android.os.Message;
Expand All @@ -43,7 +36,7 @@ public static String indexFile() {
return dataPath() + "/installedfiles.index";
}

public static void doInstall(String url, String pkg, Handler handler, CouchService service)
public static void doInstall(String pkg, Handler handler, CouchService service)
throws IOException {

if(!checkInstalled(pkg)) {
Expand All @@ -68,7 +61,7 @@ public static void doInstall(String url, String pkg, Handler handler, CouchServi
deleteDirectory(erlangDir);
}

installPackage(url, pkg, handler, service);
installPackage(pkg, handler, service);
}

Message done = Message.obtain();
Expand All @@ -79,7 +72,7 @@ public static void doInstall(String url, String pkg, Handler handler, CouchServi
/*
* This fetches a given package from amazon and tarbombs it to the filsystem
*/
private static void installPackage(String baseUrl, String pkg, Handler handler, CouchService service)
private static void installPackage(String pkg, Handler handler, CouchService service)
throws IOException {

Log.v(TAG, "Installing " + pkg);
Expand All @@ -91,33 +84,11 @@ private static void installPackage(String baseUrl, String pkg, Handler handler,
Map<String, String> allInstalledFileTypes = new HashMap<String, String>();
Map<String, String> allInstalledLinks = new HashMap<String, String>();

InputStream instream = null;

// If no URL is provided, load tarball from assets.
if (baseUrl == null) {
// XXX Stupid android 2.1 bug
// XXX Cannot load compressed assets >1M and
// XXX most files are automatically compressed,
// XXX Certain files are NOT auto compressed (eg. jpg).
instream = service.getAssets().open(pkg + ".tgz" + ".jpg");
}

else {
HttpClient pkgHttpClient = new DefaultHttpClient();
HttpGet tgzrequest = new HttpGet(baseUrl + pkg + ".tgz");
HttpResponse response = pkgHttpClient.execute(tgzrequest);
StatusLine status = response.getStatusLine();
Log.d(TAG, "Request returned status " + status);

if (status.getStatusCode() == 200) {
HttpEntity entity = response.getEntity();
instream = entity.getContent();
}

else {
throw new IOException();
}
}
// XXX Stupid android 2.1 bug
// XXX Cannot load compressed assets >1M and
// XXX most files are automatically compressed,
// XXX Certain files are NOT auto compressed (eg. jpg).
InputStream instream = service.getAssets().open(pkg + ".tgz" + ".jpg");

// Ensure /sdcard/Android/data/com.my.app/db exists
File externalPath = new File(externalPath() + "/db/");
Expand All @@ -129,7 +100,6 @@ private static void installPackage(String baseUrl, String pkg, Handler handler,
new GZIPInputStream(instream));
TarArchiveEntry e = null;

int files = 0;
float filesInArchive = 0;
float filesUnpacked = 0;

Expand Down Expand Up @@ -183,7 +153,6 @@ private static void installPackage(String baseUrl, String pkg, Handler handler,
Runtime.getRuntime().exec("chmod 755 " + fullName);

// This tells the ui how much progress has been made
files++;
Message progress = new Message();
progress.arg1 = (int) ++filesUnpacked;
progress.arg2 = (int) filesInArchive;
Expand Down
8 changes: 4 additions & 4 deletions src/com/couchbase/libcouch/CouchService.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ public IBinder onBind(Intent intent) {
public class CouchServiceImpl extends ICouchService.Stub {

@Override
public void initCouchDB(ICouchClient cb, final String url, final String pkg) throws RemoteException {
public void initCouchDB(ICouchClient cb, final String pkg) throws RemoteException {
client = cb;
if (!CouchInstaller.checkInstalled(pkg)) {
installCouch(url, pkg);
installCouch(pkg);
} else {
if (couch.started == true) {
couchStarted();
Expand Down Expand Up @@ -121,13 +121,13 @@ void startCouch() {
couch.start("/system/bin/sh", CouchInstaller.dataPath() + "/couchdb/bin/couchdb", "", mHandler);
}

void installCouch(final String url, final String pkg) {
void installCouch(final String pkg) {
final CouchService service = this;
new Thread() {
@Override
public void run() {
try {
CouchInstaller.doInstall(url, pkg, mHandler, service);
CouchInstaller.doInstall(pkg, mHandler, service);
} catch (Exception e) {
e.printStackTrace();
}
Expand Down
2 changes: 1 addition & 1 deletion src/com/couchbase/libcouch/ICouchService.aidl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interface ICouchService
/* Starts couchDB, calls "couchStarted" callback when
* complete
*/
void initCouchDB(ICouchClient callback, String url, String pkg);
void initCouchDB(ICouchClient callback, String pkg);

/*
*
Expand Down

0 comments on commit ca52f26

Please sign in to comment.