Skip to content

Commit

Permalink
Merge pull request #904 from frolovs/variousFixes
Browse files Browse the repository at this point in the history
Various fixes
  • Loading branch information
asm89 committed Jun 29, 2015
2 parents 1faa3e8 + 23d4729 commit 03dceda
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 35 deletions.
Expand Up @@ -20,7 +20,6 @@
import com.google.common.base.Splitter;
import com.google.common.collect.Lists;
import com.google.common.collect.ObjectArrays;

import io.selendroid.common.SelendroidCapabilities;
import io.selendroid.server.common.exceptions.SelendroidException;
import io.selendroid.server.common.model.ExternalStorageFile;
Expand All @@ -31,7 +30,6 @@
import io.selendroid.standalone.exceptions.AndroidSdkException;
import io.selendroid.standalone.exceptions.ShellCommandException;
import io.selendroid.standalone.io.ShellCommand;

import org.apache.commons.exec.CommandLine;
import org.apache.commons.exec.DefaultExecuteResultHandler;
import org.apache.commons.exec.DefaultExecutor;
Expand All @@ -47,10 +45,8 @@
import org.openqa.selenium.logging.LogEntry;

import javax.imageio.ImageIO;

import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.logging.Level;
Expand Down Expand Up @@ -457,15 +453,14 @@ public byte[] takeScreenshot() throws AndroidDeviceException {
if (rawImage == null) return null;

BufferedImage image =
new BufferedImage(rawImage.width, rawImage.height, BufferedImage.TYPE_INT_ARGB);
new BufferedImage(rawImage.width, rawImage.height, BufferedImage.TYPE_3BYTE_BGR);

int index = 0;
int IndexInc = rawImage.bpp >> 3;
for (int y = 0; y < rawImage.height; y++) {
for (int x = 0; x < rawImage.width; x++) {
int value = rawImage.getARGB(index);
image.setRGB(x, y, rawImage.getARGB(index));
index += IndexInc;
image.setRGB(x, y, value);
}
}
ByteArrayOutputStream stream = new ByteArrayOutputStream();
Expand Down
Expand Up @@ -56,6 +56,7 @@ public class DefaultAndroidEmulator extends AbstractDevice implements AndroidEmu
.put("WVGA800", new Dimension(480, 800))
.put("WVGA854", new Dimension(480, 854))
.put("WXGA", new Dimension(1280, 800))
.put("WXGA720", new Dimension(1280, 720))
.put("WXGA800", new Dimension(1280, 800))
.build();

Expand Down
Expand Up @@ -23,8 +23,20 @@
import io.selendroid.standalone.exceptions.ShellCommandException;
import io.selendroid.standalone.io.ShellCommand;
import io.selendroid.standalone.server.model.SelendroidStandaloneDriver;
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
import org.apache.commons.compress.archivers.zip.ZipFile;
import org.apache.commons.exec.CommandLine;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;

import java.io.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.nio.charset.Charset;
import java.security.KeyStore;
Expand All @@ -37,13 +49,6 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
import org.apache.commons.compress.archivers.zip.ZipFile;
import org.apache.commons.exec.CommandLine;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;

public class SelendroidServerBuilder {

public static final String SELENDROID_TEST_APP_PACKAGE = "io.selendroid.testapp";
Expand All @@ -58,17 +63,16 @@ public class SelendroidServerBuilder {
private AndroidApp selendroidServer = null;
private AndroidApp applicationUnderTest = null;
private SelendroidConfiguration serverConfiguration = null;
private String storepass = null;
private String alias = null;
private String storepass = "android";
private String alias = "androiddebugkey";
private X509Certificate cert509;

/**
* FOR TESTING ONLY
*/
/* package */SelendroidServerBuilder(String selendroidPrebuildServerPath,
String selendroidApplicationXmlTemplate) {
this.selendroidPrebuildServerPath = selendroidPrebuildServerPath;
this.selendroidApplicationXmlTemplate = selendroidApplicationXmlTemplate;
this(selendroidPrebuildServerPath, selendroidApplicationXmlTemplate, null);
}

/**
Expand All @@ -82,15 +86,9 @@ public class SelendroidServerBuilder {
this.serverConfiguration = selendroidConfiguration;
}

public SelendroidServerBuilder() {
this(null);
}

public SelendroidServerBuilder(SelendroidConfiguration serverConfiguration) {
this.selendroidPrebuildServerPath =
PREBUILD_SELENDROID_SERVER_PATH_PREFIX + getJarVersionNumber() + ".apk";
this.selendroidApplicationXmlTemplate = ANDROID_APPLICATION_XML_TEMPLATE;
this.serverConfiguration = serverConfiguration;
public SelendroidServerBuilder(SelendroidConfiguration selendroidConfiguration) {
this(PREBUILD_SELENDROID_SERVER_PATH_PREFIX + getJarVersionNumber() + ".apk",
ANDROID_APPLICATION_XML_TEMPLATE, selendroidConfiguration);
}

/* package */void init(AndroidApp aut) throws IOException, ShellCommandException {
Expand Down Expand Up @@ -260,11 +258,11 @@ public AndroidApp resignApp(File appFile) throws ShellCommandException, AndroidS
commandline.addArgument("-keystore", false);
commandline.addArgument(androidKeyStore.toString(), false);
commandline.addArgument("-storepass", false);
commandline.addArgument("android", false);
commandline.addArgument(storepass, false);
commandline.addArgument("-alias", false);
commandline.addArgument("androiddebugkey", false);
commandline.addArgument(alias, false);
commandline.addArgument("-keypass", false);
commandline.addArgument("android", false);
commandline.addArgument(storepass, false);
commandline.addArgument("-dname", false);
commandline.addArgument("CN=Android Debug,O=Android,C=US", false);
commandline.addArgument("-storetype", false);
Expand All @@ -290,11 +288,11 @@ public AndroidApp resignApp(File appFile) throws ShellCommandException, AndroidS
commandline.addArgument("-signedjar", false);
commandline.addArgument(outputFileName.getAbsolutePath(), false);
commandline.addArgument("-storepass", false);
commandline.addArgument(storepass != null ? storepass : "android", false);
commandline.addArgument(storepass, false);
commandline.addArgument("-keystore", false);
commandline.addArgument(androidKeyStore.toString(), false);
commandline.addArgument(customSelendroidServer.getAbsolutePath(), false);
commandline.addArgument(alias != null ? alias : "androiddebugkey", false);
commandline.addArgument(alias, false);
String output = ShellCommand.exec(commandline, 20000);
if (log.isLoggable(Level.INFO)) {
log.info("App signing output: " + output);
Expand All @@ -308,8 +306,12 @@ private File androidDebugKeystore() {
return new File(FileUtils.getUserDirectory(), File.separatorChar + ".android"
+ File.separatorChar + "debug.keystore");
} else {
storepass = serverConfiguration.getKeystorePassword();
alias = serverConfiguration.getKeystoreAlias();
if (serverConfiguration.getKeystorePassword() != null) {
storepass = serverConfiguration.getKeystorePassword();
}
if (serverConfiguration.getKeystoreAlias() != null) {
alias = serverConfiguration.getKeystoreAlias();
}
// there is a possibility that keystore path may be invalid due to user typo. Should we add a try catch?
return new File(serverConfiguration.getKeystore());
}
Expand Down

0 comments on commit 03dceda

Please sign in to comment.