From 61795b180b983d329c2651c77d5f70a486dd6993 Mon Sep 17 00:00:00 2001 From: kirl75 Date: Sat, 19 Aug 2023 16:40:39 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E5=85=85common=E4=B8=8Buiextensioncon?= =?UTF-8?q?text?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: kirl75 --- .../src/main/ets/test/AppManager.test.ets | 117 ++++++++++++++++++ .../ets/UIExtensionAbility/UIExtAbility.ts | 3 +- .../entry/src/main/ets/pages/index.ets | 20 ++- 3 files changed, 138 insertions(+), 2 deletions(-) diff --git a/ability/ability_runtime/actssystemapitest/entry/src/main/ets/test/AppManager.test.ets b/ability/ability_runtime/actssystemapitest/entry/src/main/ets/test/AppManager.test.ets index 525265325..060cd061f 100644 --- a/ability/ability_runtime/actssystemapitest/entry/src/main/ets/test/AppManager.test.ets +++ b/ability/ability_runtime/actssystemapitest/entry/src/main/ets/test/AppManager.test.ets @@ -242,5 +242,122 @@ export default function appManagerTest() { done(); }) }) + + + /** + * @tc.number: System_API_Test_App_Manager_1100 + * @tc.name: callback form GetProcessMemoryByPid system interface interception test + * @tc.desc: Test the third-party application call GetProcessMemoryByPid will be blocked + * @tc.level 3 + */ + it('System_API_Test_App_Manager_1100',0, function (done) { + let TAG = 'System_API_Test_App_Manager_1100'; + let pid = 0; + appManager.getProcessMemoryByPid(pid, (err) => { + console.log(TAG + " err.code: " + err.code); + expect(err.code).assertEqual(ERROR_CODE); + done(); + }); + }) + + /** + * @tc.number: System_API_Test_App_Manager_1200 + * @tc.name: promise form GetProcessMemoryByPid system interface interception test + * @tc.desc: Test the third-party application call GetProcessMemoryByPid will be blocked + * @tc.level 3 + */ + it('System_API_Test_App_Manager_1200',0, function (done) { + let TAG = 'System_API_Test_App_Manager_1200'; + let pid = 0; + appManager.getProcessMemoryByPid(pid) + .then(err => { + console.log(TAG + ` err->${JSON.stringify(err)}`); + expect().assertFail(); + done(); + }) + .catch(err => { + console.log(TAG + " err.code: " + err.code); + expect(err.code).assertEqual(ERROR_CODE); + done(); + }) + }) + + /** + * @tc.number: System_API_Test_App_Manager_1300 + * @tc.name: callback form getRunningProcessInfoByBundleName system interface interception test + * @tc.desc: Test the third-party application call getRunningProcessInfoByBundleName will be blocked + * @tc.level 3 + */ + it('System_API_Test_App_Manager_1300',0, function (done) { + let TAG = 'System_API_Test_App_Manager_1300'; + let bundleName = "com.ohos.application"; + appManager.getRunningProcessInfoByBundleName(bundleName, (err) => { + console.log(TAG + " err.code: " + err.code); + expect(err.code).assertEqual(ERROR_CODE); + done(); + }); + }) + + /** + * @tc.number: System_API_Test_App_Manager_1400 + * @tc.name: promise form getRunningProcessInfoByBundleName system interface interception test + * @tc.desc: Test the third-party application call getRunningProcessInfoByBundleName will be blocked + * @tc.level 3 + */ + it('System_API_Test_App_Manager_1400',0, function (done) { + let TAG = 'System_API_Test_App_Manager_1400'; + let bundleName = "com.ohos.application"; + appManager.getRunningProcessInfoByBundleName(bundleName) + .then(err => { + console.log(TAG + ` err->${JSON.stringify(err)}`); + expect().assertFail(); + done(); + }) + .catch(err => { + console.log(TAG + " err.code: " + err.code); + expect(err.code).assertEqual(ERROR_CODE); + done(); + }) + }) + + /** + * @tc.number: System_API_Test_App_Manager_1500 + * @tc.name: callback form getRunningProcessInfoByBundleName system interface interception test + * @tc.desc: Test the third-party application call getRunningProcessInfoByBundleName will be blocked + * @tc.level 3 + */ + it('System_API_Test_App_Manager_1500',0, function (done) { + let TAG = 'System_API_Test_App_Manager_1500'; + let bundleName = "com.ohos.application"; + let userId = 100; + appManager.getRunningProcessInfoByBundleName(bundleName, userId, (err) => { + console.log(TAG + " err.code: " + err.code); + expect(err.code).assertEqual(ERROR_CODE); + done(); + }); + }) + + /** + * @tc.number: System_API_Test_App_Manager_1600 + * @tc.name: promise form getRunningProcessInfoByBundleName system interface interception test + * @tc.desc: Test the third-party application call getRunningProcessInfoByBundleName will be blocked + * @tc.level 3 + */ + it('System_API_Test_App_Manager_1600',0, function (done) { + let TAG = 'System_API_Test_App_Manager_1600'; + let bundleName = "com.ohos.application"; + let userId = 100; + appManager.getRunningProcessInfoByBundleName(bundleName, userId) + .then(err => { + console.log(TAG + ` err->${JSON.stringify(err)}`); + expect().assertFail(); + done(); + }) + .catch(err => { + console.log(TAG + " err.code: " + err.code); + expect(err.code).assertEqual(ERROR_CODE); + done(); + }) + }) }) } \ No newline at end of file diff --git a/ability/ability_runtime/actsuiextensiontest/uiextensionprovider/entry/src/main/ets/UIExtensionAbility/UIExtAbility.ts b/ability/ability_runtime/actsuiextensiontest/uiextensionprovider/entry/src/main/ets/UIExtensionAbility/UIExtAbility.ts index d6babb94a..4cd1ce4b6 100644 --- a/ability/ability_runtime/actsuiextensiontest/uiextensionprovider/entry/src/main/ets/UIExtensionAbility/UIExtAbility.ts +++ b/ability/ability_runtime/actsuiextensiontest/uiextensionprovider/entry/src/main/ets/UIExtensionAbility/UIExtAbility.ts @@ -15,12 +15,13 @@ import UIExtensionAbility from '@ohos.app.ability.UIExtensionAbility' import Logger from '../model/Logger' - +import common from '@ohos.app.ability.common'; const TAG: string = '[UIExtAbility]' export default class UIExtAbility extends UIExtensionAbility { onCreate() { Logger.log(TAG, `UIExtAbility onCreate`) + let UiExtensionContext:common.UIExtensionContext = this.context; } onForeground() { diff --git a/ability/ability_runtime/actsuiextensiontest/uiextensionprovider/entry/src/main/ets/pages/index.ets b/ability/ability_runtime/actsuiextensiontest/uiextensionprovider/entry/src/main/ets/pages/index.ets index b74f4b036..bd9115243 100644 --- a/ability/ability_runtime/actsuiextensiontest/uiextensionprovider/entry/src/main/ets/pages/index.ets +++ b/ability/ability_runtime/actsuiextensiontest/uiextensionprovider/entry/src/main/ets/pages/index.ets @@ -16,7 +16,8 @@ import UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession' import commonEventManager from '@ohos.commonEventManager' import Logger from '../model/Logger' - +import common from '@ohos.app.ability.common'; +let context= getContext(this) as common.UIExtensionContext; const TAG: string = '[UIExtAbility]' const sleepTimeOne = 1000; @@ -29,6 +30,23 @@ struct Index { private session: UIExtensionContentSession = storage.get('session'); aboutToAppear() { + let options = { + parameters: { + cacheDir: context.cacheDir, + tempDir: context.tempDir, + filesDir: context.filesDir, + databaseDir: context.databaseDir, + preferencesDir: context.preferencesDir, + bundleCodeDir: context.bundleCodeDir, + distributedFilesDir: context.distributedFilesDir, + stageMode: context.stageMode, + area: context.area, + eventHub: context.eventHub + } + } + commonEventManager.publish('0100_UIExtensionAbilityContext', options, (err) => { + console.log('SUB_AA_Extension_UIServiceExtensionAbility_Context_0100 commonEventManager 0100_UIExtensionAbilityContext'); + }) let appearEvent = 'ACTS_UIExtension_AboutToAppear'; let terminateSelfWithResultEvent = 'ACTS_UIExtension_TerminateSelfWithResult'; let sendDataEvent = 'ACTS_UIExtension_SendData'; -- GitLab