Bug 1017242 - Part 4: remove API 8 code from GeckoAppShell. r=kats

This commit is contained in:
Richard Newman 2014-07-18 16:47:08 -07:00
parent 6f3878311a
commit c2a5d5d717

View File

@ -8,18 +8,17 @@ package org.mozilla.gecko;
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.File;
import java.io.FileReader;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.URLConnection;
import java.net.MalformedURLException;
import java.net.Proxy;
import java.net.URL;
import java.net.URLConnection;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Iterator;
@ -44,7 +43,6 @@ import org.mozilla.gecko.mozglue.RobocopTarget;
import org.mozilla.gecko.mozglue.generatorannotations.OptionalGeneratedParameter;
import org.mozilla.gecko.mozglue.generatorannotations.WrapElementForJNI;
import org.mozilla.gecko.prompts.PromptService;
import org.mozilla.gecko.util.GeckoEventListener;
import org.mozilla.gecko.util.HardwareUtils;
import org.mozilla.gecko.util.NativeJSContainer;
import org.mozilla.gecko.util.ProxySelector;
@ -718,9 +716,6 @@ public class GeckoAppShell
@WrapElementForJNI
public static void startMonitoringGamepad() {
if (Build.VERSION.SDK_INT < 9) {
return;
}
ThreadUtils.postToUiThread(new Runnable() {
@Override
public void run() {
@ -731,10 +726,6 @@ public class GeckoAppShell
@WrapElementForJNI
public static void stopMonitoringGamepad() {
if (Build.VERSION.SDK_INT < 9) {
return;
}
ThreadUtils.postToUiThread(new Runnable() {
@Override
public void run() {
@ -2177,17 +2168,12 @@ public class GeckoAppShell
int[] result = new int[4];
result[0] = 0;
if (Build.VERSION.SDK_INT >= 9) {
if (android.hardware.Camera.getNumberOfCameras() == 0)
return result;
if (android.hardware.Camera.getNumberOfCameras() == 0) {
return result;
}
try {
// no front/back camera before API level 9
if (Build.VERSION.SDK_INT >= 9)
sCamera = android.hardware.Camera.open(aCamera);
else
sCamera = android.hardware.Camera.open();
sCamera = android.hardware.Camera.open(aCamera);
android.hardware.Camera.Parameters params = sCamera.getParameters();
params.setPreviewFormat(ImageFormat.NV21);
@ -2419,113 +2405,15 @@ public class GeckoAppShell
GeckoNetworkManager.getInstance().disableNotifications();
}
// values taken from android's Base64
public static final int BASE64_DEFAULT = 0;
public static final int BASE64_URL_SAFE = 8;
/**
* taken from http://www.source-code.biz/base64coder/java/Base64Coder.java.txt and modified (MIT License)
*/
// Mapping table from 6-bit nibbles to Base64 characters.
private static final byte[] map1 = new byte[64];
private static final byte[] map1_urlsafe;
static {
int i=0;
for (byte c='A'; c<='Z'; c++) map1[i++] = c;
for (byte c='a'; c<='z'; c++) map1[i++] = c;
for (byte c='0'; c<='9'; c++) map1[i++] = c;
map1[i++] = '+'; map1[i++] = '/';
map1_urlsafe = map1.clone();
map1_urlsafe[62] = '-'; map1_urlsafe[63] = '_';
}
// Mapping table from Base64 characters to 6-bit nibbles.
private static final byte[] map2 = new byte[128];
static {
for (int i=0; i<map2.length; i++) map2[i] = -1;
for (int i=0; i<64; i++) map2[map1[i]] = (byte)i;
map2['-'] = (byte)62; map2['_'] = (byte)63;
}
final static byte EQUALS_ASCII = (byte) '=';
/**
* Encodes a byte array into Base64 format.
* No blanks or line breaks are inserted in the output.
* @param in An array containing the data bytes to be encoded.
* @return A character array containing the Base64 encoded data.
*/
public static byte[] encodeBase64(byte[] in, int flags) {
if (Build.VERSION.SDK_INT >=Build.VERSION_CODES.FROYO)
return Base64.encode(in, flags | Base64.NO_WRAP);
int oDataLen = (in.length*4+2)/3; // output length without padding
int oLen = ((in.length+2)/3)*4; // output length including padding
byte[] out = new byte[oLen];
int ip = 0;
int iEnd = in.length;
int op = 0;
byte[] toMap = ((flags & BASE64_URL_SAFE) == 0 ? map1 : map1_urlsafe);
while (ip < iEnd) {
int i0 = in[ip++] & 0xff;
int i1 = ip < iEnd ? in[ip++] & 0xff : 0;
int i2 = ip < iEnd ? in[ip++] & 0xff : 0;
int o0 = i0 >>> 2;
int o1 = ((i0 & 3) << 4) | (i1 >>> 4);
int o2 = ((i1 & 0xf) << 2) | (i2 >>> 6);
int o3 = i2 & 0x3F;
out[op++] = toMap[o0];
out[op++] = toMap[o1];
out[op] = op < oDataLen ? toMap[o2] : EQUALS_ASCII; op++;
out[op] = op < oDataLen ? toMap[o3] : EQUALS_ASCII; op++;
}
return out;
}
/**
* Decodes a byte array from Base64 format.
* No blanks or line breaks are allowed within the Base64 encoded input data.
* @param in A character array containing the Base64 encoded data.
* @param iOff Offset of the first character in <code>in</code> to be processed.
* @param iLen Number of characters to process in <code>in</code>, starting at <code>iOff</code>.
* @param s A string containing the Base64 encoded data.
* @return An array containing the decoded data bytes.
* @throws IllegalArgumentException If the input is not valid Base64 encoded data.
*/
public static byte[] decodeBase64(byte[] in, int flags) {
if (Build.VERSION.SDK_INT >=Build.VERSION_CODES.FROYO)
return Base64.decode(in, flags);
int iOff = 0;
int iLen = in.length;
if (iLen%4 != 0) throw new IllegalArgumentException ("Length of Base64 encoded input string is not a multiple of 4.");
while (iLen > 0 && in[iOff+iLen-1] == '=') iLen--;
int oLen = (iLen*3) / 4;
byte[] out = new byte[oLen];
int ip = iOff;
int iEnd = iOff + iLen;
int op = 0;
while (ip < iEnd) {
int i0 = in[ip++];
int i1 = in[ip++];
int i2 = ip < iEnd ? in[ip++] : 'A';
int i3 = ip < iEnd ? in[ip++] : 'A';
if (i0 > 127 || i1 > 127 || i2 > 127 || i3 > 127)
throw new IllegalArgumentException ("Illegal character in Base64 encoded data.");
int b0 = map2[i0];
int b1 = map2[i1];
int b2 = map2[i2];
int b3 = map2[i3];
if (b0 < 0 || b1 < 0 || b2 < 0 || b3 < 0)
throw new IllegalArgumentException ("Illegal character in Base64 encoded data.");
int o0 = ( b0 <<2) | (b1>>>4);
int o1 = ((b1 & 0xf)<<4) | (b2>>>2);
int o2 = ((b2 & 3)<<6) | b3;
out[op++] = (byte)o0;
if (op<oLen) out[op++] = (byte)o1;
if (op<oLen) out[op++] = (byte)o2; }
return out;
}
public static byte[] decodeBase64(String s, int flags) {
return decodeBase64(s.getBytes(), flags);
return Base64.decode(s.getBytes(), flags);
}
@WrapElementForJNI(stubName = "GetScreenOrientationWrapper")