diff --git a/inputmethod/InputMethodEngine/entry/src/main/ets/InputMethodEngineKey/InputKeyService.ts b/inputmethod/InputMethodEngine/entry/src/main/ets/InputMethodEngineKey/InputKeyService.ts new file mode 100755 index 0000000000000000000000000000000000000000..5244e56d263e097c135c7eeae8b65b5d960ed168 --- /dev/null +++ b/inputmethod/InputMethodEngine/entry/src/main/ets/InputMethodEngineKey/InputKeyService.ts @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import InputMethodExtensionAbility from '@ohos.InputMethodExtensionAbility'; +import { KeyboardController } from './KeyboardController'; + +export default class InputKeyService extends InputMethodExtensionAbility { + private keyboardController: KeyboardController; + + onCreate(want) { + console.log("====>onCreate onCreate onCreate onCreate onCreate onCreate InputKeyService************************"); + + this.keyboardController = new KeyboardController(this.context); + this.keyboardController.onCreate(); + } + + onDestroy() { + console.log("onDestroy InputKeyService**"); + this.context.destroy(); + } +} \ No newline at end of file diff --git a/inputmethod/InputMethodEngine/entry/src/main/ets/InputMethodEngineKey/KeyboardController.ts b/inputmethod/InputMethodEngine/entry/src/main/ets/InputMethodEngineKey/KeyboardController.ts new file mode 100755 index 0000000000000000000000000000000000000000..1e2dc5396c24a10c5001badd71586cf03992790f --- /dev/null +++ b/inputmethod/InputMethodEngine/entry/src/main/ets/InputMethodEngineKey/KeyboardController.ts @@ -0,0 +1,343 @@ +import prompt from '@ohos.prompt'; +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import inputmethodengine from '@ohos.inputMethodEngine'; +import display from '@ohos.display'; +import windowManager from '@ohos.window'; +import commoneventmanager from '@ohos.commonEventManager'; + + +let inputKeyboardDelegate = inputmethodengine.getKeyboardDelegate(); +let inputMethodAbility = inputmethodengine.getInputMethodAbility(); +const TAG = "keyboardController"; + +export class KeyboardController { + mContext; + WINDOW_TYPE_INPUT_METHOD_FLOAT = 2105; + windowName = 'inputApp'; + + constructor(context) { + this.mContext = context; + } + + public onCreate(): void { + let that = this; + inputMethodAbility.on("inputStop", () => { + this.mContext.destroy((err, data) => { + console.info(TAG + '====>inputMethodEngine destorey err:' + JSON.stringify(err)); + console.info(TAG + '====>inputMethodEngine destorey data:' + JSON.stringify(data)); + }); + }); + + function subscriberCallback(err, data) { + console.debug(TAG + '====>receive event err: ' + JSON.stringify(err)); + console.debug(TAG + '====>receive event data ' + JSON.stringify(data)); + switch (data.code) { + case 10: + console.debug(TAG + '====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0010 event:' + data.event); + that.SUB_Misc_InputMethod_Manage_Physical_Buttons_0010(); + break; + case 20: + console.debug(TAG + '====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0020 event:' + data.event); + that.SUB_Misc_InputMethod_Manage_Physical_Buttons_0020(); + break; + case 30: + console.debug(TAG + '====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0030 event:' + data.event); + that.SUB_Misc_InputMethod_Manage_Physical_Buttons_0030(); + break; + case 40: + console.debug(TAG + '====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0040 event:' + data.event); + that.SUB_Misc_InputMethod_Manage_Physical_Buttons_0040(); + break; + case 50: + console.debug(TAG + '====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0050 event:' + data.event); + that.SUB_Misc_InputMethod_Manage_Physical_Buttons_0050(); + break; + case 60: + console.debug(TAG + '====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0060 event:' + data.event); + that.SUB_Misc_InputMethod_Manage_Physical_Buttons_0060(); + break; + case 70: + console.debug(TAG + '====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0070 event:' + data.event); + that.SUB_Misc_InputMethod_Manage_Physical_Buttons_0070(); + break; + } + } + + var commonEventSubscribeInfo = { + events: ["test"] + }; + + var subscriber; + commoneventmanager.createSubscriber(commonEventSubscribeInfo).then(function (data) { + subscriber = data; + commoneventmanager.subscribe(subscriber, subscriberCallback); + console.debug(TAG + '====>scene subscribe finish===='); + }); + } + + private publishCallback(err): void { + if (err) { + console.error(TAG + '====>publish failed: ' + JSON.stringify(err)); + } else { + console.log(TAG + '====>publish'); + } + } + + public onDestroy(): void { + console.log('imsakitjsapp onDestroy'); + globalThis.textInputClient.getTextIndexAtCursor().then((index) => { + console.log('imsakitjsapp getTextIndexAtCursor: index = ' + index); + prompt.showToast({ message: 'getTextIndexAtCursor success' + index, duration: 200, bottom: 500 }); + var win = windowManager.findWindow(this.windowName); + win.destroyWindow(); + this.mContext.terminateSelf(); + return true; + }).catch((err) => { + prompt.showToast({ message: 'getTextIndexAtCursor failed', duration: 200, bottom: 500 }); + }); + } + + private SUB_Misc_InputMethod_Manage_Physical_Buttons_0010(): void{ + let commonEventPublishData = { + data: "FAILED" + }; + console.info(TAG + '====>receive SUB_Misc_InputMethod_Manage_Physical_Buttons_0010 success'); + inputKeyboardDelegate.on('keyEvent', (KeyEvents) => { + inputKeyboardDelegate.off("keyEvent"); + console.info(TAG + "====>inputKeyboardDelegate.on('keyEvent')"); + try{ + console.info(TAG + "====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0010 keyEvent: " + KeyEvents.action); + console.info(TAG + "====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0010 keyEvent: " + KeyEvents.key.code); + if (KeyEvents.key.code === 2045){ + commonEventPublishData = { + data: "SUCCESS" + }; + } + }catch(err){ + console.error("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0010 keyDown throw_error: " + err); + } + return true; + }); + let t = setTimeout(() => { + clearTimeout(t); + commoneventmanager.publish("SUB_Misc_InputMethod_Manage_Physical_Buttons_0010", commonEventPublishData, this.publishCallback); + }, 500); + } + + private SUB_Misc_InputMethod_Manage_Physical_Buttons_0020(): void{ + let commonEventPublishData = { + data: "FAILED" + }; + console.info(TAG + '====>receive SUB_Misc_InputMethod_Manage_Physical_Buttons_0020 success'); + inputKeyboardDelegate.on('keyEvent', (KeyEvents) => { + inputKeyboardDelegate.off("keyEvent"); + console.info(TAG + "====>inputKeyboardDelegate.on('keyEvent')"); + try{ + console.info(TAG + "====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0020 keyEvent: " + KeyEvents.action); + console.info(TAG + "====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0020 keyEvent: " + KeyEvents.key.code); + if (KeyEvents.key.code === 2017 && KeyEvents.action === 1){ + commonEventPublishData = { + data: "SUCCESS" + }; + }else{ + commonEventPublishData = { + data: "FAILED" + }; + } + }catch(err){ + console.error("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0020 keyDown throw_error: " + err); + } + return true; + }); + let t = setTimeout(() => { + clearTimeout(t); + commoneventmanager.publish("SUB_Misc_InputMethod_Manage_Physical_Buttons_0020", commonEventPublishData, this.publishCallback); + }, 500); + } + + private SUB_Misc_InputMethod_Manage_Physical_Buttons_0030(): void{ + let commonEventPublishData = { + data: "FAILED" + }; + let arr = new Array(); + console.info(TAG + '====>receive SUB_Misc_InputMethod_Manage_Physical_Buttons_0030 success'); + inputKeyboardDelegate.on('keyEvent', (KeyEvents) => { + console.info(TAG + "====>inputKeyboardDelegate.on('keyEvent')"); + try{ + console.info(TAG + "====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0030 keyEvent: " + KeyEvents.action); + console.info(TAG + "====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0030 keyEvent: " + KeyEvents.key.code); + arr.push(KeyEvents.action); + arr.push(KeyEvents.key.code); + }catch(err){ + console.error("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0030 keyDown throw_error: " + err); + } + return true; + }); + let t = setTimeout(() => { + clearTimeout(t); + inputKeyboardDelegate.off("keyEvent"); + console.info(TAG + "====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0030 arr: " + JSON.stringify(arr)); + console.info(TAG + "====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0030 arr: " + arr.join()); + if (arr.join() === '1,2045,1,2049,2,2049,2,2045'){ + commonEventPublishData = { + data: "SUCCESS" + }; + commoneventmanager.publish("SUB_Misc_InputMethod_Manage_Physical_Buttons_0030", commonEventPublishData, this.publishCallback); + }else{ + commoneventmanager.publish("SUB_Misc_InputMethod_Manage_Physical_Buttons_0030", commonEventPublishData, this.publishCallback); + } + }, 500); + } + + private SUB_Misc_InputMethod_Manage_Physical_Buttons_0040(): void{ + let commonEventPublishData = { + data: "FAILED" + }; + let arr = new Array(); + console.info(TAG + '====>receive SUB_Misc_InputMethod_Manage_Physical_Buttons_0040 success'); + inputKeyboardDelegate.on('keyEvent', (KeyEvents) => { + console.info(TAG + "====>inputKeyboardDelegate.on('keyEvent')"); + try{ + console.info(TAG + "====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0040 keyEvent: " + KeyEvents.action); + console.info(TAG + "====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0040 keyEvent: " + KeyEvents.key.code); + arr.push(KeyEvents.action); + arr.push(KeyEvents.key.code); + }catch(err){ + console.error("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0040 keyDown throw_error: " + err); + } + return true; + }); + let t = setTimeout(() => { + clearTimeout(t); + inputKeyboardDelegate.off("keyEvent"); + console.info(TAG + "====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0040 arr: " + JSON.stringify(arr)); + console.info(TAG + "====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0040 arr: " + arr.join()); + if (arr.join() === '1,2017,1,2047,2,2017,2,2047'){ + commonEventPublishData = { + data: "SUCCESS" + }; + commoneventmanager.publish("SUB_Misc_InputMethod_Manage_Physical_Buttons_0040", commonEventPublishData, this.publishCallback); + }else { + commoneventmanager.publish("SUB_Misc_InputMethod_Manage_Physical_Buttons_0040", commonEventPublishData, this.publishCallback); + } + }, 500); + } + + private SUB_Misc_InputMethod_Manage_Physical_Buttons_0050(): void{ + let commonEventPublishData = { + data: "FAILED" + }; + let arr = new Array(); + console.info(TAG + '====>receive SUB_Misc_InputMethod_Manage_Physical_Buttons_0050 success'); + inputKeyboardDelegate.on('keyEvent', (KeyEvents) => { + console.info(TAG + "====>inputKeyboardDelegate.on('keyEvent')"); + try{ + console.info(TAG + "====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0050 keyEvent: " + KeyEvents.action); + console.info(TAG + "====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0050 keyEvent: " + KeyEvents.key.code); + arr.push(KeyEvents.action); + arr.push(KeyEvents.key.code); + }catch(err){ + console.error("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0050 keyDown throw_error: " + err); + } + return true; + }); + let t = setTimeout(() => { + clearTimeout(t); + inputKeyboardDelegate.off("keyEvent"); + console.info(TAG + "====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0050 arr: " + JSON.stringify(arr)); + console.info(TAG + "====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0050 arr: " + arr.join()); + if (arr.join() === '1,2047,1,2017,2,2017,2,2047'){ + commonEventPublishData = { + data: "SUCCESS" + }; + commoneventmanager.publish("SUB_Misc_InputMethod_Manage_Physical_Buttons_0050", commonEventPublishData, this.publishCallback); + }else { + commoneventmanager.publish("SUB_Misc_InputMethod_Manage_Physical_Buttons_0050", commonEventPublishData, this.publishCallback); + } + }, 500); + } + + private SUB_Misc_InputMethod_Manage_Physical_Buttons_0060(): void{ + let commonEventPublishData = { + data: "FAILED" + }; + let arr = new Array(); + console.info(TAG + '====>receive SUB_Misc_InputMethod_Manage_Physical_Buttons_0060 success'); + inputKeyboardDelegate.on('keyEvent', (KeyEvents) => { + console.info(TAG + "====>inputKeyboardDelegate.on('keyEvent')"); + try{ + console.info(TAG + "====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0060 keyEvent: " + KeyEvents.action); + console.info(TAG + "====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0060 keyEvent: " + KeyEvents.key.code); + arr.push(KeyEvents.action); + arr.push(KeyEvents.key.code); + }catch(err){ + console.error("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0060 keyDown throw_error: " + err); + } + return true; + }); + let t = setTimeout(() => { + clearTimeout(t); + inputKeyboardDelegate.off("keyEvent"); + console.info(TAG + "====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0060 arr: " + JSON.stringify(arr)); + console.info(TAG + "====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0060 arr: " + arr.join()); + if (arr.join() === '1,2072,1,2045,1,2055,2,2055,2,2045,2,2072'){ + commonEventPublishData = { + data: "SUCCESS" + }; + commoneventmanager.publish("SUB_Misc_InputMethod_Manage_Physical_Buttons_0060", commonEventPublishData, this.publishCallback); + }else { + commoneventmanager.publish("SUB_Misc_InputMethod_Manage_Physical_Buttons_0060", commonEventPublishData, this.publishCallback); + } + }, 500); + } + + private SUB_Misc_InputMethod_Manage_Physical_Buttons_0070(): void{ + let commonEventPublishData = { + data: "FAILED" + }; + let arr = new Array(); + console.info(TAG + '====>receive r success'); + inputKeyboardDelegate.on('keyEvent', (KeyEvents) => { + console.info(TAG + "====>inputKeyboardDelegate.on('keyEvent')"); + try{ + console.info(TAG + "====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0070 keyEvent: " + KeyEvents.action); + console.info(TAG + "====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0070 keyEvent: " + KeyEvents.key.code); + arr.push(KeyEvents.action); + arr.push(KeyEvents.key.code); + }catch(err){ + console.error("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0070 keyDown throw_error: " + err); + } + return true; + }); + let t = setTimeout(() => { + clearTimeout(t); + inputKeyboardDelegate.off("keyEvent"); + console.info(TAG + "====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0070 arr: " + JSON.stringify(arr)); + console.info(TAG + "====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0070 arr: " + arr.join()); + if (arr.join() === '1,2072,1,2045,1,2017,2,2017,2,2045,2,2072'){ + commonEventPublishData = { + data: "SUCCESS" + }; + commoneventmanager.publish("SUB_Misc_InputMethod_Manage_Physical_Buttons_0070", commonEventPublishData, this.publishCallback); + }else { + commoneventmanager.publish("SUB_Misc_InputMethod_Manage_Physical_Buttons_0070", commonEventPublishData, this.publishCallback); + } + }, 500); + } + + + +} \ No newline at end of file diff --git a/inputmethod/InputMethodEngine/entry/src/main/ets/test/List.test.ets b/inputmethod/InputMethodEngine/entry/src/main/ets/test/List.test.ets index 974ce5b62dd6de453ce0c29ea22ca24d32e99947..24cd5ca0597a9881bfd41d92faed997a427840b3 100644 --- a/inputmethod/InputMethodEngine/entry/src/main/ets/test/List.test.ets +++ b/inputmethod/InputMethodEngine/entry/src/main/ets/test/List.test.ets @@ -12,10 +12,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import inputMethodEngine from './inputMethodEngine.test' -import inputMethodAbility from './inputMethodAbility.test' +import inputMethodEngine from './inputMethodEngine.test'; +import inputMethodAbility from './inputMethodAbility.test'; +import inputMethodEngineKey from './inputMethodEngineKey.test'; export default function testsuite() { inputMethodEngine(); inputMethodAbility(); + inputMethodEngineKey(); } \ No newline at end of file diff --git a/inputmethod/InputMethodEngine/entry/src/main/ets/test/inputMethodEngineKey.test.ets b/inputmethod/InputMethodEngine/entry/src/main/ets/test/inputMethodEngineKey.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..190ecde214fab2065b99f6502d90d8b8f42bf123 --- /dev/null +++ b/inputmethod/InputMethodEngine/entry/src/main/ets/test/inputMethodEngineKey.test.ets @@ -0,0 +1,493 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' +import commoneventmanager from '@ohos.commonEventManager'; +import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; +import subtype from '@ohos.InputMethodSubtype'; +import inputMethod from '@ohos.inputMethod'; +import display from '@ohos.display'; + + +export default function inputMethodEngineKeyJSUnit() { + describe('inputMethodEngineKeyEvent', function () { + var inputSever = { + packageName: '', + methodId: '', + name: '', + id: '', + extra: {} + } + + /** + * beforeEach: Prerequisites at the test case level, which are executed before each test case is executed. + */ + beforeAll(async (done) => { + let inputM = inputMethod.getCurrentInputMethod(); + console.info("====>beforeAll: getCurrentInputMethod inputMethodEngineJSUnit to: " + JSON.stringify(inputM)); + inputSever.packageName = inputM.packageName; + inputSever.methodId = inputM.methodId; + inputSever.name = inputM.packageName; + inputSever.id = inputM.methodId; + + let InputKeyService: subtype = { + id: "InputKeyService", + label: "", + name: "com.acts.inputmethodengine.test", + mode: "lower", + locale: "", + language: "", + icon: "", + iconId: 0, + extra: {} + } + try { + await inputMethod.switchCurrentInputMethodSubtype(InputKeyService); + setTimeout(() => { + console.info("====>beforeAll: inputMethodEngineJSUnit switchCurrentInputMethodSubtype success"); + done(); + }, 2000) + } catch (err) { + console.info("====>beforeAll: inputMethodEngineJSUnit fail" + JSON.stringify(err)); + } + }) + + /** + * afterEach: Test case-level clearance conditions, which are executed after each test case is executed. + */ + afterAll(async (done) => { + try { + await inputMethod.switchInputMethod(inputSever); + setTimeout(() => { + console.info("====>afterAll: inputMethodEngineJSUnit switchInputMethod success"); + done(); + }, 2000) + } catch (err) { + console.info("====>afterAll: inputMethodEngineJSUnit fail" + JSON.stringify(err)); + } + }) + + let dis = display.getDefaultDisplaySync(); + let w = dis.width / 2; + let h = dis.height /2; + let getFocusCmd = `uinput -T -c ${w} ${h}` + let abilityDelegator; + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); + async function runCmd(cmd) { + console.info("====>runCmdInfo: " + cmd); + await abilityDelegator.executeShellCommand(cmd); + } + + it('SUB_Misc_InputMethod_Manage_Physical_Buttons_0010', 0, async function (done) { + function unSubscriberCallback (err){ + console.info("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0010 unSubscriberCallback start"); + if (err){ + console.info("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0010 unSubscriberCallback failed:" + + JSON.stringify(err)); + } else { + console.info("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0010 unSubscriberCallback finish"); + } + } + + function subscriberCallback (err, data){ + console.info("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0010 subscriberCallback data:" + + JSON.stringify(data)); + commoneventmanager.unsubscribe(subscriber, unSubscriberCallback); + let t = setTimeout(() => { + try{ + expect(data.data).assertEqual("SUCCESS"); + console.info("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0010 end"); + clearTimeout(t); + done(); + }catch(err){ + console.info("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0010 err:" + JSON.stringify(err)); + clearTimeout(t); + done(); + } + }, 500) + } + + async function publishCallback(err){ + console.info("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0010 publishCallback start"); + if (err){ + console.info("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0010 publishCallback failed:" + JSON.stringify(err)); + } else { + let cmd = 'uinput -K -d 2045 -u 2045'; + await abilityDelegator.executeShellCommand(cmd); + console.info("====>runCmdInfo success: " + cmd); + + } + } + + var commonEventSubscribeInfo = { + events: ["SUB_Misc_InputMethod_Manage_Physical_Buttons_0010"] + } + var subscriber; + commoneventmanager.createSubscriber(commonEventSubscribeInfo).then((data)=>{ + subscriber = data; + console.info("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0010 subscriber data:" + JSON.stringify(data)); + commoneventmanager.subscribe(subscriber, subscriberCallback); + console.info("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0010 subscriber finish"); + + var commonEventPublishData = { + code: 10 + } + commoneventmanager.publish('test', commonEventPublishData, publishCallback); + }) + }); + + it('SUB_Misc_InputMethod_Manage_Physical_Buttons_0020', 0, async function (done) { + function unSubscriberCallback (err){ + console.info("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0020 unSubscriberCallback start"); + if (err){ + console.info("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0020 unSubscriberCallback failed:" + + JSON.stringify(err)); + } else { + console.info("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0020 unSubscriberCallback finish"); + } + } + + function subscriberCallback (err, data){ + console.info("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0020 subscriberCallback data:" + + JSON.stringify(data)); + commoneventmanager.unsubscribe(subscriber, unSubscriberCallback); + let t = setTimeout(() => { + try{ + expect(data.data).assertEqual("SUCCESS"); + console.info("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0020 end"); + clearTimeout(t); + done(); + }catch(err){ + console.info("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0020 err:" + JSON.stringify(err)); + clearTimeout(t); + done(); + } + }, 500); + } + + async function publishCallback(err){ + console.info("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0020 publishCallback start"); + if (err){ + console.info("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0020 publishCallback failed:" + JSON.stringify(err)); + } else { + let cmd = 'uinput -K -d 2017 -u 2017' + await abilityDelegator.executeShellCommand(cmd); + console.info("====>runCmdInfo success: " + cmd); + } + } + + var commonEventSubscribeInfo = { + events: ["SUB_Misc_InputMethod_Manage_Physical_Buttons_0020"] + } + var subscriber; + commoneventmanager.createSubscriber(commonEventSubscribeInfo).then((data)=>{ + subscriber = data; + console.info("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0020 subscriber data:" + JSON.stringify(data)); + commoneventmanager.subscribe(subscriber, subscriberCallback); + console.info("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0020 subscriber finish"); + + var commonEventPublishData = { + code: 20 + } + commoneventmanager.publish('test', commonEventPublishData, publishCallback); + }) + }); + + it('SUB_Misc_InputMethod_Manage_Physical_Buttons_0030', 0, async function (done) { + function unSubscriberCallback (err){ + console.info("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0030 unSubscriberCallback start"); + if (err){ + console.info("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0030 unSubscriberCallback failed:" + + JSON.stringify(err)); + } else { + console.info("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0030 unSubscriberCallback finish"); + } + } + + function subscriberCallback (err, data){ + console.info("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0030 subscriberCallback data:" + + JSON.stringify(data)); + commoneventmanager.unsubscribe(subscriber, unSubscriberCallback); + let t = setTimeout(() => { + try{ + expect(data.data).assertEqual("SUCCESS"); + console.info("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0030 end"); + clearTimeout(t); + done(); + }catch(err){ + console.info("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0030 err:" + JSON.stringify(err)); + clearTimeout(t); + done(); + } + }, 500); + } + + async function publishCallback(err){ + console.info("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0030 publishCallback start"); + if (err){ + console.info("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0030 publishCallback failed:" + JSON.stringify(err)); + } else { + let cmd = 'uinput -K -d 2045 -d 2049 -u 2049 -u 2045' + await abilityDelegator.executeShellCommand(cmd); + console.info("====>runCmdInfo success: " + cmd); + } + } + + var commonEventSubscribeInfo = { + events: ["SUB_Misc_InputMethod_Manage_Physical_Buttons_0030"] + } + var subscriber; + commoneventmanager.createSubscriber(commonEventSubscribeInfo).then((data)=>{ + subscriber = data; + console.info("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0030 subscriber data:" + JSON.stringify(data)); + commoneventmanager.subscribe(subscriber, subscriberCallback); + console.info("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0030 subscriber finish"); + + var commonEventPublishData = { + code: 30 + } + commoneventmanager.publish('test', commonEventPublishData, publishCallback); + }) + }); + + it('SUB_Misc_InputMethod_Manage_Physical_Buttons_0040', 0, async function (done) { + function unSubscriberCallback (err){ + console.info("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0040 unSubscriberCallback start"); + if (err){ + console.info("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0040 unSubscriberCallback failed:" + + JSON.stringify(err)); + } else { + console.info("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0040 unSubscriberCallback finish"); + } + } + + function subscriberCallback (err, data){ + console.info("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0040 subscriberCallback data:" + + JSON.stringify(data)); + commoneventmanager.unsubscribe(subscriber, unSubscriberCallback); + let t = setTimeout(() => { + try{ + expect(data.data).assertEqual("SUCCESS"); + console.info("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0040 end"); + clearTimeout(t); + done(); + }catch(err){ + console.info("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0040 err:" + JSON.stringify(err)); + clearTimeout(t); + done(); + } + }, 500) + } + + async function publishCallback(err){ + console.info("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0040 publishCallback start"); + if (err){ + console.info("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0040 publishCallback failed:" + JSON.stringify(err)); + } else { + let cmd = 'uinput -K -d 2017 -d 2047 -u 2017 -u 2047' + await abilityDelegator.executeShellCommand(cmd); + console.info("====>runCmdInfo success: " + cmd); + } + } + + var commonEventSubscribeInfo = { + events: ["SUB_Misc_InputMethod_Manage_Physical_Buttons_0040"] + } + var subscriber; + commoneventmanager.createSubscriber(commonEventSubscribeInfo).then((data)=>{ + subscriber = data; + console.info("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0040 subscriber data:" + JSON.stringify(data)); + commoneventmanager.subscribe(subscriber, subscriberCallback); + console.info("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0040 subscriber finish"); + + var commonEventPublishData = { + code: 40 + } + commoneventmanager.publish('test', commonEventPublishData, publishCallback); + }) + }); + + it('SUB_Misc_InputMethod_Manage_Physical_Buttons_0050', 0, async function (done) { + function unSubscriberCallback (err){ + console.info("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0050 unSubscriberCallback start"); + if (err){ + console.info("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0050 unSubscriberCallback failed:" + + JSON.stringify(err)); + } else { + console.info("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0050 unSubscriberCallback finish"); + } + } + + function subscriberCallback (err, data){ + console.info("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0050 subscriberCallback data:" + + JSON.stringify(data)); + commoneventmanager.unsubscribe(subscriber, unSubscriberCallback); + let t = setTimeout(() => { + try{ + expect(data.data).assertEqual("SUCCESS"); + console.info("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0050 end"); + clearTimeout(t); + done(); + }catch(err){ + console.info("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0050 err:" + JSON.stringify(err)); + clearTimeout(t); + done(); + } + }, 500) + } + + async function publishCallback(err){ + console.info("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0050 publishCallback start"); + if (err){ + console.info("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0050 publishCallback failed:" + JSON.stringify(err)); + } else { + let cmd = 'uinput -K -d 2047 -d 2017 -u 2017 -u 2047' + await abilityDelegator.executeShellCommand(cmd); + console.info("====>runCmdInfo success: " + cmd); + } + } + + var commonEventSubscribeInfo = { + events: ["SUB_Misc_InputMethod_Manage_Physical_Buttons_0050"] + } + var subscriber; + commoneventmanager.createSubscriber(commonEventSubscribeInfo).then((data)=>{ + subscriber = data; + console.info("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0050 subscriber data:" + JSON.stringify(data)); + commoneventmanager.subscribe(subscriber, subscriberCallback); + console.info("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0050 subscriber finish"); + + var commonEventPublishData = { + code: 50 + } + commoneventmanager.publish('test', commonEventPublishData, publishCallback); + }) + }); + + it('SUB_Misc_InputMethod_Manage_Physical_Buttons_0060', 0, async function (done) { + function unSubscriberCallback (err){ + console.info("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0060 unSubscriberCallback start"); + if (err){ + console.info("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0060 unSubscriberCallback failed:" + + JSON.stringify(err)); + } else { + console.info("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0060 unSubscriberCallback finish"); + } + } + + function subscriberCallback (err, data){ + console.info("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0060 subscriberCallback data:" + + JSON.stringify(data)); + commoneventmanager.unsubscribe(subscriber, unSubscriberCallback); + let t = setTimeout(() => { + try{ + expect(data.data).assertEqual("SUCCESS"); + console.info("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0060 end"); + clearTimeout(t); + done(); + }catch(err){ + console.info("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0060 err:" + JSON.stringify(err)); + clearTimeout(t); + done(); + } + }, 500) + } + + async function publishCallback(err){ + console.info("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0060 publishCallback start"); + if (err){ + console.info("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0060 publishCallback failed:" + JSON.stringify(err)); + } else { + let cmd = 'uinput -K -d 2072 -d 2045 -d 2055 -u 2055 -u 2045 -u 2072' + await abilityDelegator.executeShellCommand(cmd); + console.info("====>runCmdInfo success: " + cmd); + } + } + + var commonEventSubscribeInfo = { + events: ["SUB_Misc_InputMethod_Manage_Physical_Buttons_0060"] + } + var subscriber; + commoneventmanager.createSubscriber(commonEventSubscribeInfo).then((data)=>{ + subscriber = data; + console.info("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0060 subscriber data:" + JSON.stringify(data)); + commoneventmanager.subscribe(subscriber, subscriberCallback); + console.info("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0060 subscriber finish"); + + var commonEventPublishData = { + code: 60 + } + commoneventmanager.publish('test', commonEventPublishData, publishCallback); + }) + }); + + it('SUB_Misc_InputMethod_Manage_Physical_Buttons_0070', 0, async function (done) { + function unSubscriberCallback (err){ + console.info("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0070 unSubscriberCallback start"); + if (err){ + console.info("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0070 unSubscriberCallback failed:" + + JSON.stringify(err)); + } else { + console.info("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0070 unSubscriberCallback finish"); + } + } + + function subscriberCallback (err, data){ + console.info("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0070 subscriberCallback data:" + + JSON.stringify(data)); + commoneventmanager.unsubscribe(subscriber, unSubscriberCallback); + let t = setTimeout(() => { + try{ + expect(data.data).assertEqual("SUCCESS"); + console.info("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0070 end"); + clearTimeout(t); + done(); + }catch(err){ + console.info("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0070 err:" + JSON.stringify(err)); + clearTimeout(t); + done(); + } + }, 500) + } + + async function publishCallback(err){ + console.info("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0070 publishCallback start"); + if (err){ + console.info("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0070 publishCallback failed:" + JSON.stringify(err)); + } else { + let cmd = 'uinput -K -d 2072 -d 2045 -d 2017 -u 2017 -u 2045 -u 2072' + await abilityDelegator.executeShellCommand(cmd); + console.info("====>runCmdInfo success: " + cmd); + } + } + + var commonEventSubscribeInfo = { + events: ["SUB_Misc_InputMethod_Manage_Physical_Buttons_0070"] + } + var subscriber; + commoneventmanager.createSubscriber(commonEventSubscribeInfo).then((data)=>{ + subscriber = data; + console.info("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0070 subscriber data:" + JSON.stringify(data)); + commoneventmanager.subscribe(subscriber, subscriberCallback); + console.info("====>SUB_Misc_InputMethod_Manage_Physical_Buttons_0070 subscriber finish"); + + var commonEventPublishData = { + code: 70 + } + commoneventmanager.publish('test', commonEventPublishData, publishCallback); + }) + }); + + }) +} \ No newline at end of file diff --git a/inputmethod/InputMethodEngine/entry/src/main/module.json b/inputmethod/InputMethodEngine/entry/src/main/module.json index a1fc730ccf4245c7a94dcbe69c5bb4acb98130a5..7f2599246954b54d83a0435ac73c31af962265a7 100644 --- a/inputmethod/InputMethodEngine/entry/src/main/module.json +++ b/inputmethod/InputMethodEngine/entry/src/main/module.json @@ -53,6 +53,14 @@ "srcEntrance": "./ets/InputMethodEngine/InputDemoService.ts", "type": "inputMethod", "visible": true + }, + { + "description": "keyEventDemo", + "icon": "$media:icon", + "name": "InputKeyService", + "srcEntrance": "./ets/InputMethodEngineKey/InputKeyService.ts", + "type": "inputMethod", + "visible":true } ], "requestPermissions": [