Skip to content

Commit

Permalink
Updated to latest OSVR. Added automatic server binary extraction.
Browse files Browse the repository at this point in the history
  • Loading branch information
JeroMiya committed Oct 16, 2015
1 parent a5f29a9 commit 06562f2
Show file tree
Hide file tree
Showing 23 changed files with 206 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 28 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/app.iml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
</content>
<orderEntry type="jdk" jdkName="Android API 22 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:name="com.osvr.serverlauncher.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
Binary file added app/src/main/assets/lib/libcrystax.so
Binary file not shown.
Binary file added app/src/main/assets/lib/libfunctionality.so
Binary file not shown.
Binary file added app/src/main/assets/lib/libgnustl_shared.so
Binary file not shown.
Binary file added app/src/main/assets/lib/libjsoncpp.so
Binary file not shown.
Binary file added app/src/main/assets/lib/libosvrClient.so
Binary file not shown.
Binary file added app/src/main/assets/lib/libosvrClientKit.so
Binary file not shown.
Binary file added app/src/main/assets/lib/libosvrCommon.so
Binary file not shown.
Binary file added app/src/main/assets/lib/libosvrConnection.so
Binary file not shown.
Binary file added app/src/main/assets/lib/libosvrJointClientKit.so
Binary file not shown.
Binary file added app/src/main/assets/lib/libosvrPluginHost.so
Binary file not shown.
Binary file added app/src/main/assets/lib/libosvrPluginKit.so
Binary file not shown.
Binary file added app/src/main/assets/lib/libosvrServer.so
Binary file not shown.
Binary file added app/src/main/assets/lib/libosvrUtil.so
Binary file not shown.
Binary file added app/src/main/assets/lib/libosvrVRPNServer.so
Binary file not shown.
Binary file added app/src/main/assets/lib/libusb1.0.so
Binary file not shown.
Binary file not shown.
Binary file added app/src/main/assets/lib/xusb
Binary file not shown.
152 changes: 152 additions & 0 deletions app/src/main/java/com/osvr/android/utils/OSVRFileExtractor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
/*
* The MIT License (MIT)
*
* Copyright (C) 2015 Sensics, Inc. and contributors.
* Original author: Koushik Dutta for the androidmono project. Modified from original.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.osvr.android.utils;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.Vector;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

import android.content.ContextWrapper;
import android.util.Log;

public class OSVRFileExtractor {
private final static String ZIP_FILTER = "assets";
private final static int BUFSIZE = 100000;
private final static String LOGTAG = "OSVRFileExtractor";

private static void Log(String string) {
Log.v(LOGTAG, string);
}

private static void copyStreams(InputStream is, FileOutputStream fos) {
BufferedOutputStream os = null;
try {
byte data[] = new byte[BUFSIZE];
int count;
os = new BufferedOutputStream(fos, BUFSIZE);
while ((count = is.read(data, 0, BUFSIZE)) != -1) {
os.write(data, 0, count);
}
os.flush();
} catch (IOException e) {
Log("Exception while copying: " + e);
} finally {
try {
os.close();
is.close();
} catch (IOException e2) {
Log("Exception while closing the stream: " + e2);
}
}
}

private static String getAppRoot(ContextWrapper context) {
return "/data/data/" + context.getPackageName() + "/files";
}

/**
* Extract osvr files from the apk zip file (from assets dir) to the installed directory, if not
* already extracted. Call this prior to instantiating the server.
* @param context Typically an Activity instance.
*/
public static void extractFiles(ContextWrapper context) {
extractAssets(context, false);
}

/**
* Extract assets from the apk zip file to the installed app directory.
* Copies plugins, the config file, and displays.
* @param context Typically an Activity instance.
* @param worldReadable deprecated. Always use false.
*/
private static void extractAssets(ContextWrapper context, boolean worldReadable) {
try {
Runtime runtime = Runtime.getRuntime();
String appRoot = getAppRoot(context);
File zipFile = new File(context.getPackageCodePath());
long zipLastModified = zipFile.lastModified();
ZipFile zip = new ZipFile(context.getPackageCodePath());
Vector<ZipEntry> files = osvrFilesFromZip(zip);
int zipFilterLength = ZIP_FILTER.length();

Enumeration entries = files.elements();
while (entries.hasMoreElements()) {
ZipEntry entry = (ZipEntry) entries.nextElement();
String path = entry.getName().substring(zipFilterLength);
File outputFile = new File(appRoot, path);
outputFile.getParentFile().mkdirs();

if (outputFile.exists() && entry.getSize() == outputFile.length() && zipLastModified < outputFile.lastModified()) {
Log(outputFile.getName() + " already extracted.");
} else {
FileOutputStream fos = new FileOutputStream(outputFile);
Log("Copied " + entry + " to " + appRoot + "/" + path);
copyStreams(zip.getInputStream(entry), fos);
String curPath = outputFile.getAbsolutePath();
if (worldReadable) {
do {
runtime.exec("chmod 755 " + curPath);
curPath = new File(curPath).getParent();
} while (!curPath.equals(appRoot));
}
}
}
} catch (IOException e) {
Log("Error: " + e.getMessage());
}
}

/**
* Check if a file is actually an OSVR file. For the server, just
* copy everything.
* @param filePath The full path of the file.
* @return true, if the path is to an OSVR file, false otherwise
*/
private static boolean isOSVRFile(String filePath) {
return true;
}

/**
* Returns a list of all OSVR files from the apk zip file.
*/
private static Vector<ZipEntry> osvrFilesFromZip(ZipFile zip) {
Vector<ZipEntry> list = new Vector<ZipEntry>();
Enumeration entries = zip.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = (ZipEntry) entries.nextElement();
String entryName = entry.getName();
if(entryName.startsWith(ZIP_FILTER) && isOSVRFile(entryName)) {
list.add(entry);
}
}
return list;
}
}
25 changes: 23 additions & 2 deletions app/src/main/java/com/osvr/serverlauncher/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import android.view.Menu;
import android.view.MenuItem;

import com.osvr.android.utils.OSVRFileExtractor;

import java.io.File;
import java.io.IOException;
import java.util.Map;
Expand All @@ -14,16 +16,35 @@ public class MainActivity extends Activity {

private Process process;

final String serverBin = "/data/data/com.osvr.serverlauncher/files/bin/osvr_server";
final String serverDir = "/data/data/com.osvr.serverlauncher/files/bin";

protected void doChmod() {
String[] args = {"chmod", "775", serverBin};
ProcessBuilder processBuilder = new ProcessBuilder(args)
.directory(new File(serverDir));
try {
Process chmodProcess = processBuilder.start();
chmodProcess.waitFor();
} catch(IOException ex) {
Log.e("com.OSVR", "Error when starting chmod: " + ex.getMessage());
} catch(InterruptedException ex) {
Log.e("com.OSVR", "Error when starting process: " + ex.getMessage());
}
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

try {
String[] args = {"/data/data/com.osvr.serverlauncher/files/bin/osvr_server"};
OSVRFileExtractor.extractFiles(this);
doChmod();
String[] args = {serverBin};
//String[] args = {"/system/bin/ls", "/data/local/tmp/osvr/bin"};
ProcessBuilder processBuilder = new ProcessBuilder(args)
.directory(new File("/data/data/com.osvr.serverlauncher/files/bin"));
.directory(new File(serverDir));

Map<String, String> environment = processBuilder.environment();
environment.put("LD_LIBRARY_PATH", "/data/data/com.osvr.serverlauncher/files/lib");
Expand Down

0 comments on commit 06562f2

Please sign in to comment.