Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V8升级到9.3.345.11, 支持沙箱运行模式 #630

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.text.TextUtils;
import android.util.Log;
Expand Down Expand Up @@ -84,7 +85,7 @@ public class Share extends FeatureExtension {

private ShareAction mShareAction;
private static final int MSG_ONLINE_SHARE = 0x01;
private Handler mHandler = new Handler() {
private Handler mHandler = new Handler(Looper.getMainLooper()) {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@
import org.hapjs.logging.CardLogManager;
import org.hapjs.model.AppInfo;
import org.hapjs.render.jsruntime.JsThreadFactory;
import org.hapjs.render.jsruntime.SandboxProvider;
import org.hapjs.render.jsruntime.SandboxProviderImpl;
import org.hapjs.render.jsruntime.module.ModuleBridge;
import org.hapjs.runtime.HapEngine;
import org.hapjs.runtime.ProviderManager;
import org.hapjs.runtime.ResourceConfig;
import org.hapjs.runtime.Runtime;

Expand All @@ -54,6 +57,7 @@ public void init(Context context, String platform) {
Log.i(TAG, "CardServiceWorker init, platform=" + platform);
ResourceConfig.getInstance().init(context, platform);
Runtime.setPlatform(platform);
ProviderManager.getDefault().addProvider(SandboxProvider.NAME, new SandboxProviderImpl());
Runtime.getInstance().onCreate(context);
configBlacklist();
JsThreadFactory.getInstance().preload(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
import android.text.TextUtils;
import android.util.Log;
import android.webkit.MimeTypeMap;
import com.eclipsesource.v8.utils.typedarrays.ArrayBuffer;

import com.eclipsesource.v8.V8ArrayBuffer;
import com.eclipsesource.v8.utils.ArrayBuffer;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
Expand All @@ -32,6 +35,7 @@
import okhttp3.OkHttpClient;
import okhttp3.RequestBody;
import okhttp3.internal.http.HttpMethod;

import org.hapjs.bridge.CallbackHybridFeature;
import org.hapjs.bridge.Request;
import org.hapjs.bridge.Response;
Expand Down Expand Up @@ -251,15 +255,12 @@ private RequestBody getSimplePostBody(Headers headers, Object objData, String pk
String textParams = joinParams((SerializeObject) objData);
return RequestBody.create(
MediaType.parse(RequestHelper.CONTENT_TYPE_FORM_URLENCODED), textParams);
} else if (objData instanceof ArrayBuffer) {
} else if (objData instanceof byte[]) {
if (TextUtils.isEmpty(contentType)) {
contentType = RequestHelper.CONTENT_TYPE_OCTET_STREAM;
}
ByteBuffer b = ((ArrayBuffer) objData).getByteBuffer();
// copy memory to heap
byte[] buffer = new byte[b.remaining()];
b.get(buffer);
return RequestBody.create(MediaType.parse(contentType), buffer);

return RequestBody.create(MediaType.parse(contentType), (byte[]) objData);
}

contentType =
Expand Down Expand Up @@ -434,7 +435,8 @@ private void parseData(Request request, SerializeObject result, okhttp3.Response
throw new IOException("Fail to Parsing Data to Json!");
}
} else if (RESPONSE_TYPE_ARRAYBUFFER.equalsIgnoreCase(responseType)) {
result.put(RESULT_KEY_DATA, new ArrayBuffer(response.body().bytes()));
byte[] bytes = response.body().bytes();
result.put(RESULT_KEY_DATA, bytes);
} else if (RESPONSE_TYPE_FILE.equalsIgnoreCase(responseType)) {
result.put(RESULT_KEY_DATA, parseFile(request, response));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@
package org.hapjs.features;

import android.util.Log;
import com.eclipsesource.v8.utils.typedarrays.TypedArray;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.CharacterCodingException;
import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;

import org.hapjs.bridge.FeatureExtension;
import org.hapjs.bridge.Request;
import org.hapjs.bridge.Response;
import org.hapjs.bridge.annotation.ActionAnnotation;
import org.hapjs.bridge.annotation.FeatureExtensionAnnotation;
import org.hapjs.common.json.JSONObject;
import org.hapjs.render.jsruntime.serialize.SerializeObject;
import org.hapjs.render.jsruntime.serialize.TypedArrayProxy;
import org.json.JSONException;

@FeatureExtensionAnnotation(
Expand Down Expand Up @@ -67,13 +68,14 @@ private Response decode(Request request) throws JSONException {
String encoding = params.optString(PARAMS_ENCODING, "UTF-8");
boolean fatal = params.optBoolean(PARAMS_FATAL, false);
boolean ignoreBom = params.optBoolean(PARAMS_IGNORE_BOM, false);
TypedArray typedArray = params.optTypedArray(PARAMS_ARRAY_BUFFER);
if (typedArray == null) {
TypedArrayProxy typedArrayProxy = params.optTypedArrayProxy(PARAMS_ARRAY_BUFFER);
if (typedArrayProxy == null) {
jsonObject.put(KEY_ERROR_CODE, ERROR_CODE_TYPE_ERROR);
jsonObject.put(KEY_ERROR_MSG, "The encoded data was not valid.");
return new Response(ERROR_CODE_TYPE_ERROR, jsonObject);
}
return decode(encoding, typedArray.getByteBuffer(), ignoreBom, fatal);

return decode(encoding, typedArrayProxy.getBuffer(), ignoreBom, fatal);
} catch (Exception e) {
Log.e(TAG, "params are not valid.", e);
jsonObject.put(KEY_ERROR_CODE, Response.CODE_ILLEGAL_ARGUMENT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
import android.os.Looper;
import android.util.Log;

import com.eclipsesource.v8.utils.typedarrays.ArrayBuffer;
import com.eclipsesource.v8.utils.typedarrays.UInt8Array;
import com.eclipsesource.v8.V8Value;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import java.nio.ByteBuffer;
import org.hapjs.bridge.Callback;
import org.hapjs.bridge.CallbackContext;
import org.hapjs.bridge.CallbackHybridFeature;
Expand All @@ -36,6 +36,7 @@
import org.hapjs.render.Display;
import org.hapjs.render.jsruntime.serialize.JavaSerializeObject;
import org.hapjs.render.jsruntime.serialize.SerializeObject;
import org.hapjs.render.jsruntime.serialize.TypedArrayProxy;
import org.json.JSONException;
import org.json.JSONObject;

Expand Down Expand Up @@ -472,8 +473,7 @@ public void run() {
private SerializeObject makeResult(boolean isLastFrame, byte[] bytes) {
SerializeObject result = new JavaSerializeObject();
result.put(RESULT_IS_LAST_FRAME, isLastFrame);
UInt8Array array = new UInt8Array(new ArrayBuffer(bytes));
result.put(RESULT_FRAME_BUFFER, array);
result.put(RESULT_FRAME_BUFFER, new TypedArrayProxy(V8Value.UNSIGNED_INT_8_ARRAY, bytes));
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@
import android.util.Log;
import android.util.Pair;
import androidx.annotation.NonNull;
import com.eclipsesource.v8.utils.typedarrays.ArrayBuffer;

import com.eclipsesource.v8.V8ArrayBuffer;
import com.eclipsesource.v8.utils.ArrayBuffer;

import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -38,6 +41,7 @@
import java.util.Vector;
import java.util.concurrent.ConcurrentSkipListSet;
import java.util.concurrent.Semaphore;

import org.hapjs.bridge.CallbackContext;
import org.hapjs.bridge.CallbackHybridFeature;
import org.hapjs.bridge.FeatureExtension;
Expand Down Expand Up @@ -631,11 +635,7 @@ private void writeCharacteristic(final Request request) throws SerializeExceptio
String address = params.getString(PARAM_DEVICE_ID);
String serviceUUID = params.getString(PARAM_SERVICE_UUID);
String charaUUID = params.getString(PARAM_CHARACTERISTIC_UUID);
ArrayBuffer value = (ArrayBuffer) params.get(PARAM_VALUE);
ByteBuffer b = value.getByteBuffer();
// copy memory to heap
byte[] buffer = new byte[b.remaining()];
b.get(buffer);
byte[] buffer = (byte[]) params.get(PARAM_VALUE);
BleManager.getInstance()
.writeCharacteristic(
address, serviceUUID, charaUUID, buffer, getOperationCallback(request));
Expand Down Expand Up @@ -863,7 +863,7 @@ public void onCharacteristicChanged(
serviceUUID.toUpperCase());
result.put(RESULT_CHARACTERISTIC_UUID,
characteristicUUID.toUpperCase());
result.put(RESULT_VALUE, new ArrayBuffer(data));
result.put(RESULT_VALUE, data);
runCallbackContext(
EVENT_ON_CHARACTERISTIC_VALUE_CHANGE,
CODE_ON_CHARACTERISTIC_VALUE_CHANGE,
Expand Down Expand Up @@ -972,10 +972,11 @@ private JavaSerializeObject toJavaSerializeObject() {
new JavaSerializeArray(new JSONArray(mAdvertisServiceUUIDs)));
JavaSerializeObject serviceData = new JavaSerializeObject();
for (Pair<String, byte[]> d : mServiceData) {
serviceData.put(d.first, new ArrayBuffer(d.second));
byte[] bytes = d.second;
serviceData.put(d.first, bytes);
}
result.put(RESULT_SERVICE_DATA, serviceData);
result.put(RESULT_ADVERTIS_DATA, new ArrayBuffer(mAdvertisData));
result.put(RESULT_ADVERTIS_DATA, mAdvertisData);
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
@FeatureExtensionAnnotation(
name = RequestTask.FEATURE_NAME,
actions = {
@ActionAnnotation(name = RequestTask.ACTION_REQUEST, mode = FeatureExtension.Mode.SYNC_CALLBACK),
@ActionAnnotation(name = RequestTask.ACTION_REQUEST, mode = FeatureExtension.Mode.SYNC_CALLBACK, normalize = Extension.Normalize.RAW),
@ActionAnnotation(name = RequestTask.ACTION_ON_HEADERS_RECEIVED, mode = FeatureExtension.Mode.CALLBACK, multiple = Extension.Multiple.MULTI),
@ActionAnnotation(name = RequestTask.ACTION_OFF_HEADERS_RECEIVED, mode = FeatureExtension.Mode.SYNC, multiple = Extension.Multiple.MULTI),
@ActionAnnotation(name = RequestTask.ACTION_ABORT, mode = FeatureExtension.Mode.ASYNC)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import android.text.TextUtils;
import android.util.Log;

import com.eclipsesource.v8.utils.typedarrays.ArrayBuffer;
import com.eclipsesource.v8.V8Value;

import org.hapjs.bridge.ExtensionManager;
import org.hapjs.bridge.InstanceManager;
Expand All @@ -27,14 +27,14 @@
import org.hapjs.render.jsruntime.serialize.SerializeException;
import org.hapjs.render.jsruntime.serialize.SerializeHelper;
import org.hapjs.render.jsruntime.serialize.SerializeObject;
import org.hapjs.render.jsruntime.serialize.TypedArrayProxy;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -101,7 +101,7 @@ public void execute() {
String pkg = mRequest.getApplicationContext().getPackage();
SerializeObject reader = mRequest.getSerializeParams();
String url = reader.getString(RequestTask.PARAMS_KEY_URL);
String responseType = reader.optString(RequestTask.PARAMS_KEY_RESPOSNE_TYPE, RequestTask.RESPONSE_TYPE_TEXT);
String responseType = reader.optString(RequestTask.PARAMS_KEY_RESPOSNE_TYPE, RequestTask.RESPONSE_TYPE_TEXT).toLowerCase();
String dataType = reader.optString(RequestTask.PARAMS_KEY_DATA_TYPE, RequestTask.DATA_TYPE_JSON);
Object dataObj = reader.opt(RequestTask.PARAMS_KEY_DATA);
SerializeObject jsonHeader = reader.optSerializeObject(RequestTask.PARAMS_KEY_HEADER);
Expand Down Expand Up @@ -252,16 +252,17 @@ private RequestBody getSimplePostBody(Headers headers, Object objData)
return RequestBody.create(
MediaType.parse(CONTENT_TYPE_FORM_URLENCODED),
textParams);
} else if (objData instanceof ArrayBuffer) {
} else if (objData instanceof byte[]) {
Log.d(TAG, "getSimplePost objData is ArrayBuffer, contentType=" + contentType);
if (TextUtils.isEmpty(contentType)) {
contentType = CONTENT_TYPE_JSON;
}
ByteBuffer b = ((ArrayBuffer) objData).getByteBuffer();
//copy memory to heap
byte[] buffer = new byte[b.remaining()];
b.get(buffer);
return RequestBody.create(MediaType.parse(contentType), buffer);

try {
return RequestBody.create(MediaType.parse(contentType), new JSONArray(objData).toString());
} catch (JSONException e) {
throw new RuntimeException(e);
}
}

contentType = TextUtils.isEmpty(contentType) ? CONTENT_TYPE_TEXT_PLAIN : contentType;
Expand Down Expand Up @@ -319,7 +320,9 @@ public void onResponse(Call call, okhttp3.Response response) throws IOException
result.put(RequestTask.RESULT_KEY_STATUS_CODE, response.code());
result.put(RequestTask.RESULT_KEY_HEADER, parseHeaders(response));
if (response.body() != null) {
result.put(RequestTask.RESULT_KEY_DATA, new ArrayBuffer(response.body().bytes()));
byte[] bytes = response.body().bytes();

result.put(RequestTask.RESULT_KEY_DATA, new TypedArrayProxy(V8Value.UNSIGNED_INT_8_ARRAY, bytes));
} else {
Log.w(TAG, "response body is invalid");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import android.util.Log;
import android.webkit.URLUtil;

import com.eclipsesource.v8.utils.typedarrays.ArrayBuffer;

import org.hapjs.bridge.Request;
import org.hapjs.bridge.Response;
import org.hapjs.common.utils.FileHelper;
Expand All @@ -23,6 +21,7 @@

import java.io.File;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.Locale;

import okhttp3.Call;
Expand Down Expand Up @@ -97,7 +96,8 @@ private void parseData(SerializeObject result, okhttp3.Response response, String
throw new IOException("Fail to Parsing Data to Json!");
}
} else if (RESPONSE_TYPE_ARRAYBUFFER.equalsIgnoreCase(responseType)) {
result.put(RESULT_KEY_DATA, new ArrayBuffer(response.body().bytes()));
byte[] bytes = response.body().bytes();
result.put(RESULT_KEY_DATA, bytes);
} else if (RESPONSE_TYPE_FILE.equalsIgnoreCase(responseType)) {
result.put(RESULT_KEY_DATA, parseFile(response));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@
import android.nfc.NfcAdapter;
import android.nfc.tech.IsoDep;

import com.eclipsesource.v8.utils.typedarrays.ArrayBuffer;

import org.hapjs.bridge.Request;
import org.hapjs.bridge.Response;
import org.hapjs.features.nfc.base.BaseTagTechInstance;
import org.hapjs.render.jsruntime.serialize.JavaSerializeObject;

import java.io.IOException;
import java.nio.ByteBuffer;

public class IsoDepInstance extends BaseTagTechInstance {

Expand Down Expand Up @@ -44,7 +43,7 @@ public byte[] transceive(byte[] buffer) throws IOException {
public void getHistoricalBytes(Request request) {
byte[] historicalBytes = mIsoDep.getHistoricalBytes();
JavaSerializeObject result = new JavaSerializeObject();
result.put(NFC.RESULT_HISTORICAL_BYTES, new ArrayBuffer(historicalBytes));
result.put(NFC.RESULT_HISTORICAL_BYTES, historicalBytes);
request.getCallback().callback(new Response(result));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
@ActionAnnotation(name = NFC.ACTION_SET_TIMEOUT, mode = FeatureExtension.Mode.ASYNC, permissions = {Manifest.permission.NFC}),
@ActionAnnotation(name = NFC.ACTION_TRANSCEIVE, mode = FeatureExtension.Mode.ASYNC, normalize = FeatureExtension.Normalize.RAW, permissions = {Manifest.permission.NFC}),
// Ndef
@ActionAnnotation(name = NFC.ACTION_WRITE_NDEF_MESSAGE, mode = FeatureExtension.Mode.CALLBACK, permissions = {Manifest.permission.NFC}),
@ActionAnnotation(name = NFC.ACTION_WRITE_NDEF_MESSAGE, mode = FeatureExtension.Mode.CALLBACK, permissions = {Manifest.permission.NFC}, normalize = FeatureExtension.Normalize.RAW),
// IsoDep
@ActionAnnotation(name = NFC.ACTION_GET_HISTORICAL_BYTES, mode = FeatureExtension.Mode.ASYNC, normalize = FeatureExtension.Normalize.RAW),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
import android.text.TextUtils;
import android.util.Log;

import com.eclipsesource.v8.utils.typedarrays.ArrayBuffer;

import org.hapjs.bridge.HybridManager;
import org.hapjs.bridge.InstanceManager;
import org.hapjs.bridge.LifecycleListener;
Expand All @@ -37,6 +35,7 @@
import org.hapjs.render.jsruntime.serialize.SerializeArray;
import org.hapjs.render.jsruntime.serialize.SerializeObject;

import java.nio.ByteBuffer;
import java.util.Arrays;

public class NFCAdapterInstance extends BaseInstance {
Expand Down Expand Up @@ -212,7 +211,7 @@ private void onTagDiscovered(Intent intent) {

byte[] id = mDiscoveredTag.getId();
Log.d(TAG, "id: " + Arrays.toString(id));
resultObj.put(RESULT_ID, new ArrayBuffer(id));
resultObj.put(RESULT_ID, id);
} else {
Log.e(TAG, "null of discovered tag");
}
Expand Down Expand Up @@ -264,9 +263,9 @@ private SerializeArray getMessages(Parcelable[] rawMessages) {
SerializeArray arrayRecord = new JavaSerializeArray();
for (NdefRecord record : ndefRecords) {
SerializeObject recordObj = new JavaSerializeObject();
recordObj.put(RESULT_MESSAGES_RECORD_ID, new ArrayBuffer(record.getId()));
recordObj.put(RESULT_MESSAGES_RECORD_PAYLOAD, new ArrayBuffer(record.getPayload()));
recordObj.put(RESULT_MESSAGES_RECORD_TYPE, new ArrayBuffer(record.getType()));
recordObj.put(RESULT_MESSAGES_RECORD_ID, record.getId());
recordObj.put(RESULT_MESSAGES_RECORD_PAYLOAD, record.getPayload());
recordObj.put(RESULT_MESSAGES_RECORD_TYPE, record.getType());
recordObj.put(RESULT_MESSAGES_RECORD_TNF, record.getTnf());
arrayRecord.put(recordObj);
}
Expand Down
Loading
Loading