-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restructure and add adb connection support for webOS devices
- Loading branch information
Showing
61 changed files
with
1,393 additions
and
524 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
build.xml.data.CRC32=f79bd1cf | ||
build.xml.script.CRC32=4710a49c | ||
build.xml.stylesheet.CRC32=28e38971@1.56.1.46 | ||
build.xml.script.CRC32=1c9e5284 | ||
build.xml.stylesheet.CRC32=8064a381@1.75.2.48 | ||
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. | ||
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. | ||
nbproject/build-impl.xml.data.CRC32=f79bd1cf | ||
nbproject/build-impl.xml.script.CRC32=9b6b82d6 | ||
nbproject/build-impl.xml.stylesheet.CRC32=c6d2a60f@1.56.1.46 | ||
nbproject/build-impl.xml.script.CRC32=2c4d5fef | ||
nbproject/build-impl.xml.stylesheet.CRC32=876e7a8f@1.75.2.48 |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
compile.on.save=false | ||
do.depend=false | ||
do.jar=true | ||
file.reference.json.jar=C:\\Users\\Jason\\NetBeans Projects\\json.jar | ||
file.reference.tar.jar=C:\\Users\\Jason\\NetBeans Projects\\tar.jar | ||
javac.debug=true | ||
javadoc.preview=true | ||
user.properties.file=C:\\Users\\Jason\\AppData\\Roaming\\NetBeans\\8.0.1\\build.properties |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project-private xmlns="http://www.netbeans.org/ns/project-private/1"> | ||
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/> | ||
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2"> | ||
<group/> | ||
</open-files> | ||
</project-private> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
|
||
package ca.canuckcoding.adb; | ||
|
||
import ca.canuckcoding.utils.TextStreamConsumer; | ||
import ca.canuckcoding.webos.WebOSConnection; | ||
import java.io.BufferedWriter; | ||
import java.io.File; | ||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import java.util.ArrayList; | ||
import java.util.ResourceBundle; | ||
import javax.swing.JOptionPane; | ||
|
||
/** | ||
* @author Jason Robitaille | ||
*/ | ||
public class Adb { | ||
public static boolean isInstalled() { | ||
boolean isInstalled = true; | ||
attemptStartAdbServer(); | ||
try { | ||
AdbSocket adb = new AdbSocket(); | ||
isInstalled = adb.sendCommand("host:version"); | ||
adb.close(); | ||
} catch(Exception e) { | ||
isInstalled = false; | ||
} | ||
return isInstalled; | ||
} | ||
|
||
public static AdbDevice[] listDevices() throws AdbException { | ||
ResourceBundle locale = ResourceBundle.getBundle("ca/canuckcoding/webos/Locale"); | ||
ArrayList<AdbDevice> devices = new ArrayList<AdbDevice>(); | ||
try { | ||
AdbSocket adb = new AdbSocket(); | ||
if(adb.sendCommand("host:devices")) { | ||
String line = adb.readline(); | ||
while(line!=null) { | ||
if(line.length()>4) { | ||
String[] parts = line.substring(4).split("\\s+"); | ||
if(parts.length>1) { | ||
AdbDevice curr = new AdbDevice(adb.getHost(), adb.getPort(), parts[0]); | ||
if(isWebOS(curr)) { | ||
devices.add(curr); | ||
} | ||
} | ||
} | ||
line = adb.readline(); | ||
} | ||
} | ||
adb.close(); | ||
} catch(Exception e) {} | ||
return devices.toArray(new AdbDevice[devices.size()]); | ||
} | ||
|
||
private static boolean isWebOS(AdbDevice device) { | ||
boolean result = false; | ||
try { | ||
WebOSConnection con = device.connect(); | ||
try { | ||
String out1 = con.runProgram("/bin/cat", new String[] {"/etc/os-release"}); | ||
result |= out1.toString().contains("webos"); | ||
}catch(Exception e1) {} | ||
try { | ||
String out2 = con.runProgram("/bin/cat", new String[] {"/etc/webos-release"}); | ||
result |= out2.toString().contains("luneos"); | ||
}catch(Exception e2) {} | ||
} catch(Exception e) {} | ||
return result; | ||
} | ||
|
||
public static void attemptStartAdbServer() { | ||
try { | ||
Process adb = Runtime.getRuntime().exec("adb devices"); | ||
doProcess(adb); | ||
} catch (Exception e) {} | ||
} | ||
|
||
public static void launchTerminal(AdbDevice device) { | ||
Process launcher = null; | ||
try { | ||
String platform = System.getProperty("os.name").toLowerCase(); | ||
if(platform.contains("windows") || platform.contains("linux")) { | ||
String tmpFilePath = System.getProperty("java.io.tmpdir"); | ||
File script = new File(tmpFilePath, "adb.cmd"); | ||
if(script.exists()) { | ||
script.delete(); | ||
} | ||
BufferedWriter bw = new BufferedWriter(new FileWriter(script)); | ||
bw.write("adb -s " + device.getId() + " shell"); | ||
bw.flush(); | ||
bw.close(); | ||
if(platform.contains("windows")) { | ||
launcher = Runtime.getRuntime().exec("cmd.exe /c start " + | ||
script.getAbsolutePath()); | ||
} else if(platform.contains("linux")) { | ||
launcher = Runtime.getRuntime().exec(new String[] {"xterm", "+hold", | ||
"-e", "sh \"" + script.getAbsolutePath() + "\""}); | ||
} | ||
} else if(platform.contains("mac")) { | ||
launcher = Runtime.getRuntime().exec(new String[] {"/usr/bin/osascript", | ||
"-e", "tell application \"Terminal\" to do script \"" + | ||
"adb -s " + device.getId() + " shell\""}); | ||
} | ||
if(launcher!=null) { | ||
OutputStream os = launcher.getOutputStream(); | ||
os.flush(); | ||
os.close(); | ||
TextStreamConsumer stdout = new TextStreamConsumer(launcher.getInputStream()); | ||
stdout.start(); | ||
TextStreamConsumer stderr = new TextStreamConsumer(launcher.getErrorStream()); | ||
stderr.start(); | ||
} | ||
} catch(Exception e) { | ||
JOptionPane.showMessageDialog(null, "Unable to launch terminal access.\nMake sure adb " | ||
+ "is in your PATH environment variable"); | ||
} | ||
} | ||
|
||
private static boolean doProcess(Process p) throws IOException, InterruptedException { | ||
OutputStream os; | ||
TextStreamConsumer stdout, stderr; | ||
os = p.getOutputStream(); | ||
os.flush(); | ||
os.close(); | ||
stdout = new TextStreamConsumer(p.getInputStream()); | ||
stdout.start(); | ||
stderr = new TextStreamConsumer(p.getErrorStream()); | ||
stderr.start(); | ||
int exitCode = p.waitFor(); | ||
stdout.waitFor(); | ||
stderr.waitFor(); | ||
return (exitCode==0); | ||
} | ||
} |
Oops, something went wrong.