Skip to content

Commit

Permalink
[hapjs-platform#629]沙箱fix:channel can only be accessed from one singl…
Browse files Browse the repository at this point in the history
…e thread
  • Loading branch information
charles-chai authored and jianghai33 committed Dec 12, 2023
1 parent 6dcdf37 commit c135be6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,14 @@ public void attach(Handler mainHandler,
protected void onInit() {
SandboxProvider provider = ProviderManager.getDefault().getProvider(SandboxProvider.NAME);
mNative = provider.createNativeImpl(mRenderActionManager,
frameTimeNanos -> mEngine.onFrameCallback(frameTimeNanos));
frameTimeNanos -> {
mHandler.post(new Runnable() {
@Override
public void run() {
mEngine.onFrameCallback(frameTimeNanos);
}
});
});

if (provider.isSandboxEnabled()) {
ParcelFileDescriptor[][] channelDescriptors = SandboxProcessLauncher.getInstance().getChannelDescriptor();
Expand Down Expand Up @@ -223,7 +230,7 @@ protected void onInit() {
}

private void initInfras() {
executeVoidFunction(new Object[] {"initInfras", null});
executeVoidFunction(new Object[]{"initInfras", null});
}

public boolean isApplicationDebugEnabled() {
Expand Down Expand Up @@ -284,7 +291,7 @@ private void createRuntime() {
}
}
RuntimeLogManager.getDefault().logJsThreadTaskEnd(mContext.getPackageName(), RuntimeLogManager.KEY_INFRAS_JS_LOAD);
executeVoidScript(new Object[] {script, "infras.js", 0});
executeVoidScript(new Object[]{script, "infras.js", 0});
}
mApplicationState = STATE_RUNTIME_INITED;
} catch (V8RuntimeException ex) {
Expand Down Expand Up @@ -341,15 +348,15 @@ public void postCreateApplication(String jsContent, String css) {
}

public void postOnRequestApplication() {
Message.obtain(mHandler, H.MSG_ON_REQUEST_APPLICATION, new Object[] {mAppId}).sendToTarget();
Message.obtain(mHandler, H.MSG_ON_REQUEST_APPLICATION, new Object[]{mAppId}).sendToTarget();
}

public void postOnShowApplication() {
Message.obtain(mHandler, H.MSG_ON_SHOW_APPLICATION, new Object[] {mAppId}).sendToTarget();
Message.obtain(mHandler, H.MSG_ON_SHOW_APPLICATION, new Object[]{mAppId}).sendToTarget();
}

public void postOnHideApplication() {
Message.obtain(mHandler, H.MSG_ON_HIDE_APPLICATION, new Object[] {mAppId}).sendToTarget();
Message.obtain(mHandler, H.MSG_ON_HIDE_APPLICATION, new Object[]{mAppId}).sendToTarget();
}

public void postOnMenuButtonPress(Page page, HybridView.OnKeyUpListener onKeyUpIsConsumption) {
Expand All @@ -358,7 +365,7 @@ public void postOnMenuButtonPress(Page page, HybridView.OnKeyUpListener onKeyUpI
}

public void postPageNotFound(Page page) {
Message.obtain(mHandler, H.MSG_PAGE_NOT_FOUND, new Object[] {mAppId, page.getTargetPageUri(), page.getPageId()}).sendToTarget();
Message.obtain(mHandler, H.MSG_PAGE_NOT_FOUND, new Object[]{mAppId, page.getTargetPageUri(), page.getPageId()}).sendToTarget();
}

public void postBackPress(Page page) {
Expand All @@ -370,7 +377,7 @@ protected boolean backPress(Object msgObj) {
Page page = (Page) msgObj;
boolean consumed = false;
if (page != null && page.getState() >= Page.STATE_CREATED) {
consumed = super.backPress(new Object[] {page.pageId});
consumed = super.backPress(new Object[]{page.pageId});
}
if (!consumed && null != mMainHandler) {
mMainHandler.sendEmptyMessage(RootView.MSG_BACK_PRESS);
Expand All @@ -384,7 +391,7 @@ protected boolean menuButtonPressPage(Object msgObj) {
HybridView.OnKeyUpListener onKeyUpIsConsumption = (HybridView.OnKeyUpListener) ((Object[]) msgObj)[1];
boolean consumed = false;
if (page != null && page.getState() >= Page.STATE_CREATED) {
consumed = super.menuButtonPressPage(new Object[] {page.pageId});
consumed = super.menuButtonPressPage(new Object[]{page.pageId});
// TODO: onKeyUpIsConsumption.consume(false);?
}
onKeyUpIsConsumption.consume(consumed);
Expand All @@ -411,15 +418,15 @@ protected boolean firePageKeyEvent(JsEventCallbackData data) {
}

public void postMenuPress(Page page) {
mHandler.obtainMessage(H.MSG_MENU_PRESS, new Object[] {page}).sendToTarget();
mHandler.obtainMessage(H.MSG_MENU_PRESS, new Object[]{page}).sendToTarget();
}

@Override
protected boolean onMenuPress(Object msgObj) {
Page page = (Page) ((Object[]) msgObj)[0];
boolean consumed = false;
if (page != null && page.getState() >= Page.STATE_CREATED) {
consumed = super.onMenuPress(new Object[] {page.pageId});
consumed = super.onMenuPress(new Object[]{page.pageId});
}

if (!consumed) {
Expand All @@ -429,15 +436,15 @@ protected boolean onMenuPress(Object msgObj) {
}

public void postOrientationChange(Page page, ScreenOrientation screenOrientation) {
mHandler.obtainMessage(H.MSG_ORIENTATION_CHANGE, new Object[] {page, screenOrientation}).sendToTarget();
mHandler.obtainMessage(H.MSG_ORIENTATION_CHANGE, new Object[]{page, screenOrientation}).sendToTarget();
}

@Override
protected void onOrientationChange(Object msgObj) {
Page page = (Page) ((Object[]) msgObj)[0];
ScreenOrientation screenOrientation = (ScreenOrientation) ((Object[]) msgObj)[1];
if (page != null && page.getState() >= Page.STATE_CREATED) {
super.onOrientationChange(new Object[] {page.pageId, screenOrientation.getOrientation(), screenOrientation.getAngel()});
super.onOrientationChange(new Object[]{page.pageId, screenOrientation.getOrientation(), screenOrientation.getAngel()});
}
}

Expand Down Expand Up @@ -496,7 +503,7 @@ public void postInitializePage(int pageId) {

public void postDestroyPage(Page page) {
if (page.getState() > Page.STATE_NONE) {
mHandler.obtainMessage(H.MSG_DESTROY_PAGE, new Object[] {page.pageId}).sendToTarget();
mHandler.obtainMessage(H.MSG_DESTROY_PAGE, new Object[]{page.pageId}).sendToTarget();
page.setState(Page.STATE_NONE);
} else {
Log.d(TAG, "skip page destroy: " + page.toString());
Expand Down Expand Up @@ -590,7 +597,7 @@ protected void createPage(Object msgObj) {

preCreateSkeleton(page);
preCreateBody(page.pageId);
super.createPage(new Object[] {mAppId, page.pageId, js, css, page.params, page.intent, page.meta});
super.createPage(new Object[]{mAppId, page.pageId, js, css, page.params, page.intent, page.meta});
Message.obtain(mMainHandler, MSG_APP_LOAD_END).sendToTarget();
}

Expand Down Expand Up @@ -703,7 +710,7 @@ protected void destroyPage(Object msgObj) {
}

private void postDestroyApplication() {
Message.obtain(mHandler, H.MSG_DESTROY_APPLICATION, new Object[] {mAppId}).sendToTarget();
Message.obtain(mHandler, H.MSG_DESTROY_APPLICATION, new Object[]{mAppId}).sendToTarget();
}

@Override
Expand All @@ -719,7 +726,7 @@ public void postFireEvent(final int pageId, final List<JsEventCallbackData> data
post(new Runnable() {
@Override
public void run() {
fireEvent(new Object[] {pageId, datas, listener});
fireEvent(new Object[]{pageId, datas, listener});
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void onFrameCallback(long frameTimeNanos) {
continue;
}
final int N = callbackIds.size();
for (int index = 0; index < N; ++index) {
for (int index = N - 1; index >= 0; index--) {
int callbackId = callbackIds.keyAt(index);
CallbackType type = callbackIds.valueAt(index);
if (type == CallbackType.Animation) {
Expand Down

0 comments on commit c135be6

Please sign in to comment.