From 2e84af05f94e2bff1f3a5f9fdab298ea28ed21c9 Mon Sep 17 00:00:00 2001 From: zixing <1311817771@qq.com> Date: Tue, 16 Nov 2021 11:21:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=8F=AF=E4=BB=A5=E5=9C=A8ka?= =?UTF-8?q?ios=E8=BF=90=E8=A1=8C=E7=9A=84=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 更新可以在kaios运行的版本 --- bld/main-all.js | 4 +- config/runtests.js | 6 +- img/icon-128.png | Bin 0 -> 4362 bytes img/icon-512.png | Bin 0 -> 4362 bytes index.html | 2 +- keymap.js | 11 +- main.html | 2 +- manifest.webapp | 14 +- tests/index.js | 38 ++++ tests/mozactivitymock.js | 65 ++++++ tests/mozactivitymock.unprivileged.js | 38 ++++ tests/native.js | 298 ++++++++++++++++++++++++++ 12 files changed, 463 insertions(+), 15 deletions(-) create mode 100644 img/icon-128.png create mode 100644 img/icon-512.png create mode 100644 tests/index.js create mode 100644 tests/mozactivitymock.js create mode 100644 tests/mozactivitymock.unprivileged.js create mode 100644 tests/native.js diff --git a/bld/main-all.js b/bld/main-all.js index 6a5e898..6011b6c 100644 --- a/bld/main-all.js +++ b/bld/main-all.js @@ -5682,7 +5682,8 @@ var DumbPipe = {recipients:{}, nextPipeID:0, open:function(type, message, recipi window.nextTickBeforeEvents(this.runSendQueue.bind(this)); } }, runSendQueue:function() { - alert(JSON.stringify(this.sendQueue.shift())); + this.sendQueue.shift(); + //alert(JSON.stringify(this.sendQueue.shift())); if (this.sendQueue.length > 0) { window.nextTickBeforeEvents(this.runSendQueue.bind(this)); } else { @@ -13233,6 +13234,7 @@ window.onload = function() { } setTimeout(sample, 2E3); }; + setTimeout(start, 2000); }; function requestTimelineBuffers(fn) { if (J2ME.timeline) { diff --git a/config/runtests.js b/config/runtests.js index 34b14cb..2b4699a 100644 --- a/config/runtests.js +++ b/config/runtests.js @@ -1,6 +1,6 @@ -config.jars = "tests/tests.jar"; -config.jad = "tests/runtests.jad"; -config.midletClassName = "RunTestsMIDlet"; +config.jars = "tests/Anyview4.0.jar"; +config.jad = "tests/Anyview4.0.jad"; +config.midletClassName = "com.ismyway.anyview.Anyview"; MIDlet.shouldStartBackgroundService = function() { return fs.exists("/startBackgroundService"); diff --git a/img/icon-128.png b/img/icon-128.png new file mode 100644 index 0000000000000000000000000000000000000000..c170c1153dd465d97456e86bc7ad261bccee8398 GIT binary patch literal 4362 zcmV+l5%ungP)*;qcl!2HeU_Tb9Th?kY1LPM zci(gFJ>TE|)_q1q2!a34jXd$h6Zo{oIY)PQH@dpI5Jk~y##lc9{<%CLAs84KK(Sa< zzu(!}DP*4l=wXa?%ja1^DZPadGFYuvzb|o8_R(tdv5Y2(KTIk8bNK*k0We&DL)`N6 z`Me^U%jMvC9(>!OuvW4y4`+O^_0%lPyay)#AjO zeU@JRxZ>DyW0U{nlSlDsEeu2Q@WVsi=$Cl-;cW zr908v-wt6`l2VfKb?3X5jqVF!Xc@vWBhdW@v~Yc)6_*@RYH450k^E|!r@<>LGg|OeB*1I045v(&B^uS#4?Oj z&yhyz`X!X$`vleCi}}BM?w#)*J8}4r@;NU8$fqm7T-1^qOwBA{kuj9(HCzoBQL4_P zv`|LAt$7<&-oauPzVMPSXZ!pGmaAwMl_@yTR?&Xi1h{Bb;`)hJQu)S>w!Hx zHht~H$zvM|K2C#>&$bYvl&BwyB916z2qnBA0&*T|^#CN&Bx(&Qp*T|sV*4>gG$E*@ zSQ-$Pv{P6R0W%BQb12Q1C>8k36#%=4sQ^cf6r5S#)gS;BSr@QPSeOBin?Di+U7yG9 z6In0;J6e7zeEqNwY0{)f`YPcPS{XKIJJM;Bw=ai9gO@R!dY%t6yC+iYX15D3@+zb~G0$f5Ee-wr^ zn3OIXB!gfguw_YeBrSvUbQVZ{#>7o>0n3UDt{;Xen3C6I1HQz{I1&zMvhsE=B^h%T zKyFqHU@8a_M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uXr&&!tuze-cJ$s5^y&b<6&56C756J!0gGer(J-j zTtGCp0IL^AR!b+Ai2hJAaRzBlt0GVFafOVCfycMFJ^*Uq8{~|%Um_@_MbGnS7)G`t z1P2G<6cm~%W4e0b?o2R2SS-T@jBrJf%M7VMozuwv?-Um2!BgZ(yl*YQGo%X=IRnpt z3qf;*LVJy|YCGpl|9QKz0-`rH4H-%B*xv|cDzau-VCgY;exG&&(=yi*A%rFG$H}Jv zYXKx-0a*nILcO5adHcBUzu!MUKL;*U!UIu~0cu}Q-1|X=OfG5OM3cTq1;r&4TFe85 zJjq32KvD|eh9ghy{e_=RfuLC#2KDg#zf!T`d;R^D9>x}(eu(xW-;fn z*SH-Wi}fQ-%)!r+ho4eHoHR-Ivobr^0>m=FowUu7k4YArXLe4LaG(ZWyl+5KN}%a` zn-aHJUgIq)fH#?o_gVTn{XosDK_|2G$c(e3owAnOTDO4Z&u3OEJEl!cy!p8KJp#*W z*(k2ie9W7C)?#*QZpyB?xu#0JehX+`C8Q*p6VA^4A9nXnq - + diff --git a/keymap.js b/keymap.js index f17075f..f045247 100644 --- a/keymap.js +++ b/keymap.js @@ -2,8 +2,10 @@ //----------------------keymap -function handleKeydown(e) { - console.log(e.key); +function handleKeydown(e) { +if (e.key != "EndCall" && e.key!="Backspace") { + e.preventDefault();//清除默认行为(滚动屏幕等) +} switch(e.key) { case 'ArrowUp': MIDP.sendKeyPress(-1); @@ -57,6 +59,7 @@ function handleKeydown(e) { MIDP.sendKeyPress(42); break; case '#': + start(); MIDP.sendKeyPress(35); break; } @@ -64,7 +67,9 @@ function handleKeydown(e) { function handleKeyup(e) { - console.log(e.key); +if (e.key != "EndCall" && e.key!="Backspace") { + e.preventDefault();//清除默认行为(滚动屏幕等) + } switch(e.key) { case 'ArrowUp': MIDP.sendKeyRelease(-1); diff --git a/main.html b/main.html index 96e8e1d..332dd6b 100644 --- a/main.html +++ b/main.html @@ -47,7 +47,7 @@ - + diff --git a/manifest.webapp b/manifest.webapp index b966bf9..a128c93 100644 --- a/manifest.webapp +++ b/manifest.webapp @@ -1,8 +1,8 @@ { - "name": "PluotSorbet", + "name": "AnyView", "description": "a J2ME-compatible virtual machine written in JavaScript", - "launch_path": "/index.html?jars=tests/Anyview4.0.jar&jad=tests/Anyview4.0.jad&midletClassName=com.ismyway.anyview.Anyview", - "origin": "app://pluotsorbet.mozilla.org", + "launch_path": "/main.html", + "origin": "app://pluotsorbet.AnyView.org", "version": "1624444801", "icons": { "128": "/img/icon-128.png", @@ -51,16 +51,18 @@ } }, "messages": [ - { "alarm": "/index.html" } + { "alarm": "/main.html" } ], "activities": { "share": { - "href": "/index.html", + "href": "/main.html", "disposition": "window", "filters": { "type": ["image/*", "video/*", "audio/*"] } } }, - "type": "privileged" + "type": "web", + "cursor": false, + "fullscreen": true } diff --git a/tests/index.js b/tests/index.js new file mode 100644 index 0000000..2b9692e --- /dev/null +++ b/tests/index.js @@ -0,0 +1,38 @@ +DumbPipe.registerOpener("echo", function(message, sender) { + sender(message); +}); + +// Generate faked location data for tests +LocationProvider.AVAILABLE = 1; +DumbPipe.registerOpener("locationprovider", function(message, sender) { + return function(message) { + switch (message.type) { + case "requestData": + sender({ + type: "data", + position: { + timestamp: Date.now(), + latitude: 45, + longitude: -122, + altitude: 500, + horizontalAccuracy: 200, + verticalAccuracy: 10, + speed: 90, + course: 2 + }, + state: LocationProvider.AVAILABLE + }); + break; + } + }; +}); + +var backgroundChecks = 0; + +DumbPipe.registerOpener("backgroundCheck", function() { + backgroundChecks++; +}); + +DumbPipe.registerOpener("getBackgroundChecks", function(message, sender) { + sender(backgroundChecks); +}); diff --git a/tests/mozactivitymock.js b/tests/mozactivitymock.js new file mode 100644 index 0000000..cfa2a27 --- /dev/null +++ b/tests/mozactivitymock.js @@ -0,0 +1,65 @@ +/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */ + +var lastSMSNumber = null; +var lastSMSBody = null; +var lastAddContactParams = null; + +DumbPipe.registerOpener("lastSMSNumber", function(message, sender) { + sender(lastSMSNumber); +}); + +DumbPipe.registerOpener("lastSMSBody", function(message, sender) { + sender(lastSMSBody); +}); + +DumbPipe.registerOpener("lastAddContactParams", function(message, sender) { + sender(lastAddContactParams); +}); + +function MozActivity(obj) { + if (obj.name === "new") { + switch (obj.data.type) { + case "websms/sms": + lastSMSNumber = obj.data.number; + lastSMSBody = obj.data.body; + break; + + case "webcontacts/contact": + lastAddContactParams = obj.data.params; + + break; + + default: + throw new Error("MozActivity with type " + obj.data.type + " not supported"); + } + + nextTickBeforeEvents((function() { + this.onsuccess(); + }).bind(this)); + + } else { + throw new Error("MozActivity " + obj.name + " not supported"); + } +} + +var messageHandlers = {}; +navigator.mozSetMessageHandler = function(name, func) { + messageHandlers[name] = func; +} + +DumbPipe.registerOpener("callShareActivityMessageHandler", function(message, sender) { + var activity = { + source: { + name: "share", + data: { + "type": "image/*", + "number": 1, + "blobs": [ new Blob([]) ], + "filenames": ["j2mesharetestimage" + message.num + ".jpg"], + "filepaths": ["/sdcard/DCIM/100MZLLA/j2mesharetestimage" + message.num + ".jpg"] + }, + }, + }; + messageHandlers["activity"](activity); +}); diff --git a/tests/mozactivitymock.unprivileged.js b/tests/mozactivitymock.unprivileged.js new file mode 100644 index 0000000..5562d28 --- /dev/null +++ b/tests/mozactivitymock.unprivileged.js @@ -0,0 +1,38 @@ +/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */ + +Native["javax/wireless/messaging/SendSMSTest.getNumber.()Ljava/lang/String;"] = function(addr) { + asyncImpl("Ljava/lang/String;", new Promise(function(resolve, reject) { + var sender = DumbPipe.open("lastSMSNumber", {}, function(lastSMSNumber) { + DumbPipe.close(sender); + resolve(J2ME.newString(lastSMSNumber)); + }); + })); +}; + +Native["javax/wireless/messaging/SendSMSTest.getBody.()Ljava/lang/String;"] = function(addr) { + asyncImpl("Ljava/lang/String;", new Promise(function(resolve, reject) { + var sender = DumbPipe.open("lastSMSBody", {}, function(lastSMSBody) { + DumbPipe.close(sender); + resolve(J2ME.newString(lastSMSBody)); + }); + })); +}; + +Native["com/sun/midp/midlet/AddContactTest.getNumber.()Ljava/lang/String;"] = function(addr) { + asyncImpl("Ljava/lang/String;", new Promise(function(resolve, reject) { + var sender = DumbPipe.open("lastAddContactParams", {}, function(lastAddContactParams) { + DumbPipe.close(sender); + resolve(J2ME.newString(lastAddContactParams.tel)); + }); + })); +}; + +Native["com/sun/midp/midlet/AddContactTest.hasNumber.()Z"] = function(addr) { + asyncImpl("Z", new Promise(function(resolve, reject) { + var sender = DumbPipe.open("lastAddContactParams", {}, function(lastAddContactParams) { + DumbPipe.close(sender); + resolve(lastAddContactParams.tel ? 1 : 0); + }); + })); +}; diff --git a/tests/native.js b/tests/native.js new file mode 100644 index 0000000..98caad3 --- /dev/null +++ b/tests/native.js @@ -0,0 +1,298 @@ +/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */ + +Native["gnu/testlet/vm/NativeTest.getInt.()I"] = function(addr) { + return ~~(0xFFFFFFFF); +}; + +Native["gnu/testlet/vm/NativeTest.getLongReturnLong.(J)J"] = function(addr, valLow, valHigh) { + return J2ME.returnLong(valLow + 40, valHigh); +}; + +Native["gnu/testlet/vm/NativeTest.getLongReturnInt.(J)I"] = function(addr, valLow, valHigh) { + return ~~(40 + J2ME.longToNumber(valLow, valHigh)); +}; + +Native["gnu/testlet/vm/NativeTest.getIntReturnLong.(I)J"] = function(addr, val) { + return J2ME.returnLongValue(40 + val); +}; + +Native["gnu/testlet/vm/NativeTest.throwException.()V"] = function(addr) { + throw $.newNullPointerException("An exception"); +}; + +Native["gnu/testlet/vm/NativeTest.throwExceptionAfterPause.()V"] = function(addr) { + var ctx = $.ctx; + asyncImpl("V", new Promise(function(resolve, reject) { + setTimeout(function() { + ctx.setAsCurrentContext(); + reject($.newNullPointerException("An exception")) + }, 100); + })); +}; + +Native["gnu/testlet/vm/NativeTest.returnAfterPause.()I"] = function(addr) { + asyncImpl("I", new Promise(function(resolve, reject) { + setTimeout(resolve.bind(null, 42), 100); + })); +}; + +Native["gnu/testlet/vm/NativeTest.nonStatic.(I)I"] = function(addr, val) { + return val + 40; +}; + +Native["gnu/testlet/vm/NativeTest.fromStringAddr.(Ljava/lang/String;)I"] = function(addr, stringAddr) { + return J2ME.fromStringAddr(stringAddr).length; +}; + +Native["gnu/testlet/vm/NativeTest.decodeUtf8.([B)I"] = function(addr, strAddr) { + var str = J2ME.getArrayFromAddr(strAddr); + return util.decodeUtf8(str).length; +}; + +Native["gnu/testlet/vm/NativeTest.newFunction.()Z"] = function(addr) { + try { + var fn = new Function("return true;"); + return fn() ? 1 : 0; + } catch(ex) { + console.error(ex); + return 0; + } +}; + +Native["gnu/testlet/vm/NativeTest.dumbPipe.()Z"] = function(addr) { + asyncImpl("Z", new Promise(function(resolve, reject) { + // Ensure we can echo a large amount of data. + var array = []; + for (var i = 0; i < 128 * 1024; i++) { + array[i] = i; + } + DumbPipe.open("echo", array, function(message) { + resolve(JSON.stringify(array) === JSON.stringify(message) ? 1 : 0); + }); + })); +}; + +Native["org/mozilla/regression/TestVectorNull.nativeThatReturnsNull.()Ljava/lang/Object;"] = function(addr) { + return J2ME.Constants.NULL; +}; + +Native["com/nokia/mid/ui/TestVirtualKeyboard.hideKeyboard.()V"] = function(addr) { + MIDP.isVKVisible = function() { return false; }; + MIDP.sendVirtualKeyboardEvent(); +}; + +Native["com/nokia/mid/ui/TestVirtualKeyboard.showKeyboard.()V"] = function(addr) { + MIDP.isVKVisible = function() { return true; }; + MIDP.sendVirtualKeyboardEvent(); +}; + +Native["javax/microedition/lcdui/TestAlert.isTextEditorReallyFocused.()Z"] = function(addr) { + return (currentlyFocusedTextEditor && currentlyFocusedTextEditor.focused) ? 1 : 0; +}; + +Native["javax/microedition/lcdui/TestTextEditorFocus.isTextEditorReallyFocused.(Lcom/nokia/mid/ui/TextEditor;)Z"] = +function(addr, textEditorAddr) { + var nativeTextEditor = NativeMap.get(textEditorAddr); + return (currentlyFocusedTextEditor == nativeTextEditor && currentlyFocusedTextEditor.focused) ? 1 : 0; +}; + +Native["gnu/testlet/TestHarness.getNumDifferingPixels.(Ljava/lang/String;)I"] = function(addr, referenceImagePathAddr) { + var path = J2ME.fromStringAddr(referenceImagePathAddr); + asyncImpl("I", new Promise(function(resolve, reject) { + var gotCanvas = document.getElementById("canvas"); + var gotPixels = new Uint32Array(gotCanvas.getContext("2d").getImageData(0, 0, gotCanvas.width, gotCanvas.height).data.buffer); + + var img = new Image(); + img.src = "tests/" + path; + + img.onerror = function() { + console.error("Error while loading image: " + img.src); + reject($.newException("Error while loading image: " + img.src)); + } + img.onload = function() { + var expectedCanvas = document.createElement('canvas'); + expectedCanvas.width = img.width; + expectedCanvas.height = img.height; + expectedCanvas.getContext("2d").drawImage(img, 0, 0); + + var expectedPixels = new Uint32Array(expectedCanvas.getContext("2d").getImageData(0, 0, img.width, img.height).data.buffer); + + if (expectedCanvas.width !== gotCanvas.width || expectedCanvas.height !== gotCanvas.height) { + var message = "Width (got: " + gotCanvas.width + ", expected: " + expectedCanvas.width + "), " + + "height (got: " + gotCanvas.height + ", expected: " + expectedCanvas.width + ")"; + console.error(message); + reject($.newException(message)); + return; + } + + var different = 0; + var i = 0; + for (var x = 0; x < gotCanvas.width; x++) { + for (var y = 0; y < gotCanvas.height; y++) { + if (expectedPixels[i] !== gotPixels[i]) { + different++; + } + + i++; + } + } + + resolve(different); + }; + })); +}; + +Native["com/nokia/mid/impl/jms/core/TestLauncher.checkImageModalDialog.()Z"] = function(addr) { + return document.getElementById("image-launcher") != null ? 1 : 0; +}; + +Native["org/mozilla/io/TestNokiaPhoneStatusServer.sendFakeOnlineEvent.()V"] = function(addr) { + window.dispatchEvent(new CustomEvent("online")); +}; + +Native["org/mozilla/io/TestNokiaPhoneStatusServer.sendFakeOfflineEvent.()V"] = function(addr) { + window.dispatchEvent(new CustomEvent("offline")); +}; + +Native["javax/microedition/media/TestAudioRecorder.convert3gpToAmr.([B)[B"] = function(addr, dataAddr) { + var data = J2ME.getArrayFromAddr(dataAddr); + var converted = Media.convert3gpToAmr(new Uint8Array(data)); + var resultAddr = J2ME.newByteArray(converted.length); + var result = J2ME.getArrayFromAddr(resultAddr); + result.set(converted); + return resultAddr; +}; + +Native["com/sun/midp/i18n/TestResourceConstants.setLanguage.(Ljava/lang/String;)V"] = function(addr, languageAddr) { + MIDP.localizedStrings = null; + config.language = J2ME.fromStringAddr(languageAddr); +} + +// Many tests create FileConnection objects to files with the "/" root, +// so add it to the list of valid roots. +MIDP.fsRoots.push("/"); + +Native["org/mozilla/MemorySampler.sampleMemory.(Ljava/lang/String;)V"] = function(addr, labelAddr) { + if (typeof Benchmark !== "undefined") { + asyncImpl("V", Benchmark.sampleMemory().then(function(memory) { + var keys = ["totalSize", "domSize", "styleSize", "jsObjectsSize", "jsStringsSize", "jsOtherSize", "otherSize"]; + var rows = []; + rows.push(keys); + rows.push(keys.map(function(k) { return memory[k] })); + var RIGHT = Benchmark.RIGHT; + var alignment = [RIGHT, RIGHT, RIGHT, RIGHT, RIGHT, RIGHT, RIGHT]; + console.log((J2ME.fromStringAddr(labelAddr) || "Memory sample") + ":\n" + Benchmark.prettyTable(rows, alignment)); + })); + } +}; + +Native["org/mozilla/Test.callSyncNative.()V"] = function(addr) { + // A noop sync implementation for comparison with the noop async one. +}; + +Native["org/mozilla/Test.callAsyncNative.()V"] = function(addr) { + // A noop async implementation for comparison with the noop sync one. + asyncImpl("V", new Promise(function (resolve, reject) { + resolve(); + })); + + // This is even faster, but not very handy, unless your native is really + // synchronous, and you just want to force the thread to yield. + // asyncImpl("V", Promise.resolve()); +}; + +var readerOpened = false; +var readerOpenedWaiting = null; + +Native["tests/recordstore/ReaderMIDlet.readerOpened.()V"] = function(addr) { + readerOpened = true; + + if (readerOpenedWaiting) { + readerOpenedWaiting(); + } +}; + +Native["tests/recordstore/WriterMIDlet.waitReaderOpened.()V"] = function(addr) { + asyncImpl("V", new Promise(function(resolve, reject) { + if (readerOpened) { + resolve(); + } else { + readerOpenedWaiting = resolve; + } + })); +}; + +var writerWrote = false; +var writerWroteWaiting = null; + +Native["tests/recordstore/WriterMIDlet.writerWrote.()V"] = function(addr) { + writerWrote = true; + + if (writerWroteWaiting) { + writerWroteWaiting(); + } +}; + +Native["tests/recordstore/ReaderMIDlet.waitWriterWrote.()V"] = function(addr) { + asyncImpl("V", new Promise(function(resolve, reject) { + if (writerWrote) { + resolve(); + } else { + writerWroteWaiting = resolve; + } + })); +}; + +Native["tests/background/DestroyMIDlet.sendDestroyMIDletEvent.()V"] = function(addr) { + MIDP.setDestroyedForRestart(true); + MIDP.sendDestroyMIDletEvent("tests.background.DestroyMIDlet"); +}; + +Native["tests/background/DestroyMIDlet.sendExecuteMIDletEvent.()V"] = function(addr) { + setTimeout(function() { + MIDP.sendExecuteMIDletEvent(); + }, 0); +}; + +var called = 0; +Native["tests/background/DestroyMIDlet.maybePrintDone.()V"] = function(addr) { + if (++called === 2) { + console.log("DONE"); + } +}; + +Native["javax/microedition/content/TestContentHandler.addInvocation.(Ljava/lang/String;Ljava/lang/String;)V"] = +function(addr, argumentAddr, actionAddr) { + Content.addInvocation(J2ME.fromStringAddr(argumentAddr), J2ME.fromStringAddr(actionAddr)); +}; + +var ContentHandlerMIDletStarted = 0; + +Native["tests/midlets/ContentHandlerMIDlet.sendShareMessage.()V"] = +Native["tests/midlets/ContentHandlerStarterMIDlet.sendShareMessage.()V"] = function(addr) { + DumbPipe.close(DumbPipe.open("callShareActivityMessageHandler", { num: ContentHandlerMIDletStarted })); +}; + +Native["tests/midlets/ContentHandlerStarterMIDlet.startMIDlet.()V"] = function(addr) { + setTimeout(function() { + MIDP.sendExecuteMIDletEvent(1, "tests.midlets.ContentHandlerMIDlet"); + }, 0); +}; + +Native["tests/midlets/ContentHandlerMIDlet.shouldStop.()Z"] = function(addr) { + if (++ContentHandlerMIDletStarted === 3) { + return 1; + } + + return 0; +}; + +Native["tests/midlets/background/ForegroundEnableBackgroundServiceMIDlet.startedBackgroundAlarm.()I"] = function() { + asyncImpl("I", new Promise(function(resolve, reject) { + var sender = DumbPipe.open("getBackgroundChecks", {}, function(backgroundChecks) { + DumbPipe.close(sender); + resolve(backgroundChecks); + }); + })); +};