diff --git a/BUILD.gn b/BUILD.gn index 1d07fc45455e0697b75899158b1556cad9198de7..5ec5d0389bae1650357da8e4587734dfcad6ac8f 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -11,24 +11,27 @@ # See the License for the specific language governing permissions and # limitations under the License. -#import("//base/security/permission/permission.gni") +import("//base/security/access_token/access_token.gni") import("//build/ohos.gni") + group("accesstoken_build_module") { if (is_standard_system) { deps = [ "//base/security/access_token/interfaces/innerkits/accesstoken:libaccesstoken_sdk", "//base/security/access_token/interfaces/innerkits/nativetoken:libnativetoken", "//base/security/access_token/interfaces/innerkits/token_setproc:libtoken_setproc", - "//base/security/access_token/interfaces/kits:napi_packages", "//base/security/access_token/services/accesstokenmanager:accesstoken_manager_service", "//base/security/access_token/services/accesstokenmanager/main/sa_profile:accesstoken_sa_profile_standard", "//base/security/access_token/tools:tools_atm", ] } + if (support_jsapi) { + deps += [ "//base/security/access_token/interfaces/kits:napi_packages" ] + } } group("tokensync_build_module") { - if (is_standard_system) { + if (is_standard_system && token_sync_enable == true) { deps = [ "//base/security/access_token/interfaces/innerkits/tokensync:libtokensync_sdk", "//base/security/access_token/services/tokensyncmanager:token_sync_manager_service", @@ -45,8 +48,12 @@ group("accesstoken_build_module_test") { "//base/security/access_token/interfaces/innerkits/accesstoken/test:unittest", "//base/security/access_token/interfaces/innerkits/nativetoken/test:unittest", "//base/security/access_token/interfaces/innerkits/token_setproc/test:unittest", - "//base/security/access_token/interfaces/innerkits/tokensync/test:unittest", "//base/security/access_token/services/accesstokenmanager/test:unittest", + ] + } + if (token_sync_enable == true) { + deps += [ + "//base/security/access_token/interfaces/innerkits/tokensync/test:unittest", "//base/security/access_token/services/tokensyncmanager/test/unittest/token_sync_service:unittest", ] } diff --git a/access_token.gni b/access_token.gni new file mode 100644 index 0000000000000000000000000000000000000000..a6a6a3bd984692328e8a83390fe1d1207a9731d4 --- /dev/null +++ b/access_token.gni @@ -0,0 +1,19 @@ +# 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. + +if (!defined(global_parts_info) || + defined(global_parts_info.distributedhardware_device_manager_base)) { + token_sync_enable = true +} else { + token_sync_enable = false +} diff --git a/frameworks/accesstoken/include/i_accesstoken_manager.h b/frameworks/accesstoken/include/i_accesstoken_manager.h index f620e2f56612dd2db108b3b23a846b3fd1c71937..c593a4c27b79fba0da0e737f594e5c1943206887 100644 --- a/frameworks/accesstoken/include/i_accesstoken_manager.h +++ b/frameworks/accesstoken/include/i_accesstoken_manager.h @@ -59,6 +59,7 @@ public: virtual int UpdateHapToken( AccessTokenID tokenID, const std::string& appIDDesc, const HapPolicyParcel& policyParcel) = 0; +#ifdef TOKEN_SYNC_ENABLE virtual int GetHapTokenInfoFromRemote(AccessTokenID tokenID, HapTokenInfoForSyncParcel& hapSyncParcel) = 0; virtual int GetAllNativeTokenInfo(std::vector& nativeTokenInfoRes) = 0; @@ -69,6 +70,7 @@ public: virtual int DeleteRemoteToken(const std::string& deviceID, AccessTokenID tokenID) = 0; virtual AccessTokenID GetRemoteNativeTokenID(const std::string& deviceID, AccessTokenID tokenID) = 0; virtual int DeleteRemoteDeviceTokens(const std::string& deviceID) = 0; +#endif virtual void DumpTokenInfo(std::string& tokenInfo) = 0; diff --git a/frameworks/com.ohos.permissionmanager/entry/src/main/config.json b/frameworks/com.ohos.permissionmanager/entry/src/main/config.json index 165e0d3bd16be20696ddac1f4660634cb7ffb98f..fb8fc1e71695110ce8fce76357df0def3d29d0bb 100644 --- a/frameworks/com.ohos.permissionmanager/entry/src/main/config.json +++ b/frameworks/com.ohos.permissionmanager/entry/src/main/config.json @@ -11,10 +11,10 @@ "module": { "package": "com.ohos.permissionmanager", "name": ".MyApplication", - "mainAbility": "com.ohos.permissionmanager.MainAbility", + "mainAbility": ".MainAbility", + "srcPath": "", "deviceType": [ - "phone", - "tablet" + "phone" ], "distro": { "deliveryWithInstall": true, @@ -34,10 +34,14 @@ ] } ], + "orientation": "unspecified", "visible": true, - "name": "com.ohos.permissionmanager.MainAbility", + "srcPath": "MainAbility", + "name": ".MainAbility", + "srcLanguage": "ets", "icon": "$media:icon", - "description": "$string:mainability_description", + "description": "$string:description_mainability", + "formsEnabled": false, "label": "$string:entry_MainAbility", "type": "page", "launchType": "standard" @@ -50,9 +54,10 @@ "type": "pageAbility" }, "pages": [ - "pages/index" + "pages/index", + "pages/second" ], - "name": "default", + "name": ".MainAbility", "window": { "designWidth": 720, "autoDesignWidth": false diff --git a/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/dynamic/app.ets b/frameworks/com.ohos.permissionmanager/entry/src/main/ets/MainAbility/app.ets similarity index 97% rename from frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/dynamic/app.ets rename to frameworks/com.ohos.permissionmanager/entry/src/main/ets/MainAbility/app.ets index 9ae634daa0e52dc81de9365c78bb0df598f4c085..1007addd5895518aa431843702e1c585e1d81bc2 100644 --- a/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/dynamic/app.ets +++ b/frameworks/com.ohos.permissionmanager/entry/src/main/ets/MainAbility/app.ets @@ -12,12 +12,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -export default { + + export default { onCreate() { console.info('Application onCreate') }, onDestroy() { console.info('Application onDestroy') }, -} +} \ No newline at end of file diff --git a/frameworks/com.ohos.permissionmanager/entry/src/main/java/com/ohos/permissionmanager/MainAbility.java b/frameworks/com.ohos.permissionmanager/entry/src/main/ets/MainAbility/pages/index.ets similarity index 43% rename from frameworks/com.ohos.permissionmanager/entry/src/main/java/com/ohos/permissionmanager/MainAbility.java rename to frameworks/com.ohos.permissionmanager/entry/src/main/ets/MainAbility/pages/index.ets index 4b70570892cb6b0e231a5ac34fde0c91b6683241..a438be437ac49ace945f8423caf1256896724bdf 100644 --- a/frameworks/com.ohos.permissionmanager/entry/src/main/java/com/ohos/permissionmanager/MainAbility.java +++ b/frameworks/com.ohos.permissionmanager/entry/src/main/ets/MainAbility/pages/index.ets @@ -13,19 +13,41 @@ * limitations under the License. */ -package com.ohos.permissionmanager; +import router from '@system.router'; -import ohos.ace.ability.AceAbility; -import ohos.aafwk.content.Intent; - -public class MainAbility extends AceAbility { - @Override - public void onStart(Intent intent) { - super.onStart(intent); - } +async function routePage() { + let options = { + uri: 'pages/second' + } + try { + await router.push(options) + } catch (err) { + console.error(`fail callback, code: ${err.code}, msg: ${err.msg}`) + } +} - @Override - public void onStop() { - super.onStop(); +@Entry +@Component +struct Index { + build() { + Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Text('Hello World') + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button() { + Text('next page') + .fontSize(25) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .onClick(() => { + routePage() + }) } -} + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/frameworks/com.ohos.permissionmanager/entry/src/main/ets/default/pages/index.ets b/frameworks/com.ohos.permissionmanager/entry/src/main/ets/MainAbility/pages/second.ets similarity index 68% rename from frameworks/com.ohos.permissionmanager/entry/src/main/ets/default/pages/index.ets rename to frameworks/com.ohos.permissionmanager/entry/src/main/ets/MainAbility/pages/second.ets index 5e693e0f5e895263df503b50680b067fc0009436..2a9a10d491c54eabeb71b3387b548efb8098f1ce 100644 --- a/frameworks/com.ohos.permissionmanager/entry/src/main/ets/default/pages/index.ets +++ b/frameworks/com.ohos.permissionmanager/entry/src/main/ets/MainAbility/pages/second.ets @@ -13,16 +13,32 @@ * limitations under the License. */ +import router from '@system.router'; + @Entry @Component -struct Index { +struct Second { + private content: string = "Second Page" + build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Text('Hello World') + Text(`${this.content}`) .fontSize(50) .fontWeight(FontWeight.Bold) + Button() { + Text('back to index') + .fontSize(20) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .onClick(() => { + router.back() + }) } .width('100%') .height('100%') } -} +} \ No newline at end of file diff --git a/frameworks/com.ohos.permissionmanager/entry/src/main/java/com/ohos/permissionmanager/MyApplication.java b/frameworks/com.ohos.permissionmanager/entry/src/main/java/com/ohos/permissionmanager/MyApplication.java deleted file mode 100644 index 6c8f0f649747c73fedd1c7f6f8bbbf4ff7684444..0000000000000000000000000000000000000000 --- a/frameworks/com.ohos.permissionmanager/entry/src/main/java/com/ohos/permissionmanager/MyApplication.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2021-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. - */ - -package com.ohos.permissionmanager; - -import ohos.aafwk.ability.AbilityPackage; - -public class MyApplication extends AbilityPackage { - @Override - public void onInitialize() { - super.onInitialize(); - } -} diff --git a/frameworks/com.ohos.permissionmanager/entry/src/main/resources/base/element/string.json b/frameworks/com.ohos.permissionmanager/entry/src/main/resources/base/element/string.json index bc3df790ef54add880b08cf9dbd43bc45a9137d4..b93f540e29265a34f883a977c442fa85349b94ca 100644 --- a/frameworks/com.ohos.permissionmanager/entry/src/main/resources/base/element/string.json +++ b/frameworks/com.ohos.permissionmanager/entry/src/main/resources/base/element/string.json @@ -5,7 +5,7 @@ "value": "entry_MainAbility" }, { - "name": "mainability_description", + "name": "description_mainability", "value": "eTS_Empty Ability" } ] diff --git a/frameworks/com.ohos.permissionmanager/entry/src/ohosTest/ets/default/app.ets b/frameworks/com.ohos.permissionmanager/entry/src/ohosTest/ets/default/app.ets deleted file mode 100644 index 03748140d89081db2a38ad1b7076b234a4185bbd..0000000000000000000000000000000000000000 --- a/frameworks/com.ohos.permissionmanager/entry/src/ohosTest/ets/default/app.ets +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2021-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. - */ - -export default { - onCreate() { - console.info('Application onCreate') - }, - onShow() { - console.info('Application onShow') - }, - onDestroy() { - console.info('Application onDestroy') - }, -} diff --git a/frameworks/com.ohos.permissionmanager/entry/src/ohosTest/ets/default/i18n/en-US.json b/frameworks/com.ohos.permissionmanager/entry/src/ohosTest/ets/default/i18n/en-US.json deleted file mode 100644 index 55561b83737c3c31d082fbfa11e5fc987a351104..0000000000000000000000000000000000000000 --- a/frameworks/com.ohos.permissionmanager/entry/src/ohosTest/ets/default/i18n/en-US.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "strings": { - "hello": "Hello", - "world": "World" - }, - "Files": { - } -} \ No newline at end of file diff --git a/frameworks/com.ohos.permissionmanager/entry/src/ohosTest/ets/default/i18n/zh-CN.json b/frameworks/com.ohos.permissionmanager/entry/src/ohosTest/ets/default/i18n/zh-CN.json deleted file mode 100644 index cce1af06761a42add0cac1a0567aa3237eda8cb4..0000000000000000000000000000000000000000 --- a/frameworks/com.ohos.permissionmanager/entry/src/ohosTest/ets/default/i18n/zh-CN.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "strings": { - "hello": "您好", - "world": "世界" - }, - "Files": { - } -} \ No newline at end of file diff --git a/frameworks/com.ohos.permissionmanager/entry/src/ohosTest/ets/default/pages/index/index.ets b/frameworks/com.ohos.permissionmanager/entry/src/ohosTest/ets/default/pages/index/index.ets deleted file mode 100644 index 61dc37aa5443151e25e529cd4e08219670768aaa..0000000000000000000000000000000000000000 --- a/frameworks/com.ohos.permissionmanager/entry/src/ohosTest/ets/default/pages/index/index.ets +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2021-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 {Core, ExpectExtend, InstrumentLog} from "deccjsunit/index" -import testsuite from "../../../test/List.test.ets" -import featureAbility from "@ohos.ability.featureAbility" - -@Entry -@Component -struct MyComponent { - aboutToAppear() { - console.info("start run testcase!!!!") - featureAbility.getWant() - .then((Want) => { - const core = Core.getInstance() - const expectExtend = new ExpectExtend({ - 'id': 'extend' - }) - const instrumentLog = new InstrumentLog({ - 'id': 'report', 'unity': 'true' - }) - core.addService('expect', expectExtend) - core.addService('report', instrumentLog) - core.init() - core.subscribeEvent('spec', instrumentLog) - core.subscribeEvent('suite', instrumentLog) - core.subscribeEvent('task', instrumentLog) - const configService = core.getDefaultService('config') - configService.setConfig(Want.parameters) - testsuite() - core.execute() - console.info('Operation successful. Data: ' + JSON.stringify(Want)); - }) - .catch((error) => { - console.error('Operation failed. Cause: ' + JSON.stringify(error)); - }) - } - - build() { - Flex({ - direction: FlexDirection.Column, - alignItems: ItemAlign.Center, - justifyContent: FlexAlign.Center - }) { - Text('Hello World') - .fontSize(50) - .fontWeight(FontWeight.Bold) - } - .width('100%') - .height('100%') - } -} diff --git a/frameworks/com.ohos.permissionmanager/entry/src/ohosTest/ets/test/ExampleJsunit.test.ets b/frameworks/com.ohos.permissionmanager/entry/src/ohosTest/ets/test/ExampleJsunit.test.ets deleted file mode 100644 index c76c23ebb2e6db5bd021d5c6366e7fca8bdc1a40..0000000000000000000000000000000000000000 --- a/frameworks/com.ohos.permissionmanager/entry/src/ohosTest/ets/test/ExampleJsunit.test.ets +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2021-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 "deccjsunit/index" -import app from '@system.app' - -export default function exampleJsunit() { - describe('appInfoTest', function () { - it('app_info_test_001', 0, function () { - var info = app.getInfo() - expect("1.0").assertEqual('1.0') - expect(info.versionCode).assertEqual('3') - }) - }) -} diff --git a/frameworks/com.ohos.permissionmanager/entry/src/ohosTest/ets/test/List.test.ets b/frameworks/com.ohos.permissionmanager/entry/src/ohosTest/ets/test/List.test.ets deleted file mode 100644 index 23005224d04a66d893c235ae3d8a75d7cb363473..0000000000000000000000000000000000000000 --- a/frameworks/com.ohos.permissionmanager/entry/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (c) 2021-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 exampleJsunit from "../test/ExampleJsunit.test.ets" - -export default function testsuite() { - exampleJsunit() -} diff --git a/frameworks/com.ohos.permissionmanager/entry/src/ohosTest/java/com/ohos/permissionmanager/ExampleOhosTest.java b/frameworks/com.ohos.permissionmanager/entry/src/ohosTest/java/com/ohos/permissionmanager/ExampleOhosTest.java deleted file mode 100644 index e0c56a5cd908397fcedaa314224a4d7261152bc6..0000000000000000000000000000000000000000 --- a/frameworks/com.ohos.permissionmanager/entry/src/ohosTest/java/com/ohos/permissionmanager/ExampleOhosTest.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2021-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. - */ - -package com.ohos.permissionmanager; - -import ohos.aafwk.ability.delegation.AbilityDelegatorRegistry; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -public class ExampleOhosTest { - @Test - public void testBundleName() { - final String actualBundleName = AbilityDelegatorRegistry.getArguments().getTestBundleName(); - assertEquals("com.ohos.permissionmanager", actualBundleName); - } -} \ No newline at end of file diff --git a/frameworks/com.ohos.permissionmanager/entry/src/ohosTest/resources/base/element/string.json b/frameworks/com.ohos.permissionmanager/entry/src/ohosTest/resources/base/element/string.json deleted file mode 100644 index 998415d3588045c96c5d9db329c45087769c1d92..0000000000000000000000000000000000000000 --- a/frameworks/com.ohos.permissionmanager/entry/src/ohosTest/resources/base/element/string.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "string": [ - { - "name": "app_name", - "value": "finalApplication" - }, - { - "name": "mainability_description", - "value": "hap sample empty page" - } - ] -} diff --git a/frameworks/com.ohos.permissionmanager/entry/src/ohosTest/resources/base/media/icon.png b/frameworks/com.ohos.permissionmanager/entry/src/ohosTest/resources/base/media/icon.png deleted file mode 100644 index ce307a8827bd75456441ceb57d530e4c8d45d36c..0000000000000000000000000000000000000000 Binary files a/frameworks/com.ohos.permissionmanager/entry/src/ohosTest/resources/base/media/icon.png and /dev/null differ diff --git a/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/config.json b/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/config.json index a4a9a97f0ef67c3b63977a95a086b41cd8388b72..92df3c93f053e081803708e17f37b7c6c21daac4 100644 --- a/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/config.json +++ b/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/config.json @@ -11,7 +11,8 @@ "module": { "package": "com.ohos.permissionmanager", "name": ".MyApplication", - "mainAbility": "com.ohos.permissionmanager.GrantAbility", + "mainAbility": ".MainAbility", + "srcPath": "", "deviceType": [ "phone" ], @@ -24,21 +25,23 @@ "abilities": [ { "visible": true, - "name": "com.ohos.permissionmanager.MainAbility", - "description": "$string:mainability_description", + "srcPath": "MainAbility", + "name": ".MainAbility", + "srcLanguage": "ets", + "description": "$string:description_mainability", "label": "$string:permissionmanager_MainAbility", "type": "page", - "launchType": "standard", - "srcPath": "default" + "launchType": "standard" }, { "visible": true, - "name": "com.ohos.permissionmanager.GrantAbility", - "description": "$string:grantability_description", + "srcPath": "GrantAbility", + "name": ".GrantAbility", + "srcLanguage": "ets", + "description": "$string:description_grantability", "label": "$string:permissionmanager_GrantAbility", "type": "page", - "launchType": "standard", - "srcPath": "dynamic" + "launchType": "standard" } ], "js": [ @@ -53,9 +56,10 @@ "pages/authority-secondary", "pages/authority-tertiary", "pages/application-tertiary", - "pages/other-permissions" + "pages/other-permissions", + "pages/authority-tertiary-groups" ], - "name": "default", + "name": ".MainAbility", "window": { "designWidth": 720, "autoDesignWidth": false @@ -69,7 +73,7 @@ "pages": [ "pages/dialogPlus" ], - "name": "dynamic", + "name": ".GrantAbility", "window": { "designWidth": 720, "autoDesignWidth": false @@ -99,4 +103,4 @@ } ] } -} +} \ No newline at end of file diff --git a/frameworks/com.ohos.permissionmanager/entry/src/main/ets/default/app.ets b/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/GrantAbility/app.ets similarity index 100% rename from frameworks/com.ohos.permissionmanager/entry/src/main/ets/default/app.ets rename to frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/GrantAbility/app.ets diff --git a/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/dynamic/common/components/dialog.ets b/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/GrantAbility/common/components/dialog.ets similarity index 75% rename from frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/dynamic/common/components/dialog.ets rename to frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/GrantAbility/common/components/dialog.ets index b5d27831965882f840958829b6840cb26a17d142..451678bfa4d237b32d3a24d08ee655e3f73fb8cb 100644 --- a/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/dynamic/common/components/dialog.ets +++ b/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/GrantAbility/common/components/dialog.ets @@ -21,6 +21,8 @@ import abilityAccessCtrl from '@ohos.abilityAccessCtrl' import bundle from '@ohos.bundle' import Resmgr from '@ohos.resourceManager' +var TAG = "PermissionManager_GrantAbility" + @Extend(Button) function customizeButton() { .backgroundColor($r('app.color.default_background_color')) .fontColor($r('app.color.button_color')) @@ -42,14 +44,14 @@ export struct privacyDialog { build() { Column() { - if ((this.initStatus != Constants.INIT_NEED_TO_WAIT) && this.verify(this.reqPerms[this.count])) { + if ((this.initStatus != Constants.INIT_NEED_TO_WAIT) && this.verify()) { Image(this.grantGroups[this.count].icon) .width(Constants.DIALOG_ICON_WIDTH) .height(Constants.DIALOG_ICON_HEIGHT) .margin({ top: Constants.DIALOG_ICON_MARGIN_TOP }) - Text(`${this.count + 1} / ${this.reqPerms.length}`) + Text(`${this.count + 1} / ${this.grantGroups.length}`) .fontSize(Constants.DIALOG_LABEL_FONT_SIZE) .fontColor($r('app.color.secondary_font_color')) .margin({ @@ -108,39 +110,19 @@ export struct privacyDialog { .height(Constants.DIALOG_HEIGHT) .width(Constants.DIALOG_WIDTH) } - async verify(permission) { + verify() { if((this.initStatus == Constants.INIT_NEED_TO_TERMINATED) || (this.count >= this.grantGroups.length)) { this.controller.close() this.aboutToDisappear() return false } - if(this.grantGroups[this.count] == 0) { - this.result[this.count] = -1 - this.count ++ - return false - } - var acManager = abilityAccessCtrl.createAtManager() - var flag = await acManager.getPermissionFlags(this.accessTokenId, permission) - console.log("GrantAbility permission: " + permission + " flag : " + flag) - if(flag == this.userFixedFlag) { - console.log("GrantAbility permission has been fixed:" + permission) - var ret = await acManager.verifyAccessToken(this.accessTokenId, permission) - if (ret == 0) { - this.result[this.count] = 0 - } else { - this.result[this.count] = -1 - } - this.count ++ - return false - } - this.result[this.count] = -1 return true } getApplicationName(uid) { bundle.getNameForUid(uid).then((data) => { - console.log("GrantAbility getApplicationName bundleName:" + data) - console.log("GrantAbility getApplicationName userId:" + Math.floor(uid/200000)) + console.log(TAG + "GrantAbility getApplicationName bundleName:" + data) + console.log(TAG + "GrantAbility getApplicationName userId:" + Math.floor(uid/200000)) bundle.getApplicationInfo(data, BundleFlag.GET_BUNDLE_DEFAULT, Math.floor(uid/200000)).then(applicationInfo => { Resmgr.getResourceManager(data).then(item => { item.getString(applicationInfo.labelId, (err, value) => { @@ -149,47 +131,72 @@ export struct privacyDialog { } else { this.appName = value } - console.log("GrantAbility hap label:" + applicationInfo.label + ", value:"+this.appName) + console.log(TAG + "GrantAbility hap label:" + applicationInfo.label + ", value:"+this.appName) }) }) }).catch(err => { - console.log("GrantAbility applicationInfo error :" + err) + console.log(TAG + "GrantAbility applicationInfo error :" + err) this.initStatus = Constants.INIT_NEED_TO_TERMINATED }) }).catch(err => { - console.log("GrantAbility getNameForUid error :" + JSON.stringify(err)) + console.log(TAG + "GrantAbility getNameForUid error :" + JSON.stringify(err)) this.initStatus = Constants.INIT_NEED_TO_TERMINATED }) } + getgrantGroups() { + var acManager = abilityAccessCtrl.createAtManager() + var num =0 + this.reqPerms.forEach(async (permission, idx) => { + var flag = await acManager.getPermissionFlags(this.accessTokenId, permission) + if(flag == this.userFixedFlag) { + console.log(TAG + "GrantAbility permission has been fixed:" + permission) + var ret = await acManager.verifyAccessToken(this.accessTokenId, permission) + if(ret == abilityAccessCtrl.GrantStatus.PERMISSION_GRANTED) { + this.result[idx] = abilityAccessCtrl.GrantStatus.PERMISSION_GRANTED; + } + }else { + var group = getPermissionGroup(permission) + if(!group) { + console.log(TAG + "GrantAbility permission not find:" + permission) + }else { + var exist = this.grantGroups.find(grantGroup => grantGroup.name == group.name) + if(!exist) { + this.grantGroups.push(group) + } + } + } + num ++ + if(num == this.reqPerms.length) { + if(this.grantGroups.length == 0) { + this.initStatus = Constants.INIT_NEED_TO_TERMINATED + }else { + this.initStatus = Constants.INIT_NEED_TO_VERIFY + } + } + }) + } + aboutToAppear() { this.count = 0; this.initStatus = Constants.INIT_NEED_TO_WAIT this.result = [] featureAbility.getWant((err, want) => { if (err.code != 0) { - console.log("GrantAbility featureAbility.getWant err:" + err) + console.log(TAG + "GrantAbility featureAbility.getWant err:" + err) this.initStatus = Constants.INIT_NEED_TO_TERMINATED return } this.reqPerms = want.parameters['ohos.user.grant.permission'] this.accessTokenId = want.parameters['ohos.aafwk.param.callerToken'] if (this.reqPerms == undefined || this.accessTokenId == undefined || this.reqPerms.length == 0) { - console.log("GrantAbility invalid parameters") + console.log(TAG + "GrantAbility invalid parameters") this.initStatus = Constants.INIT_NEED_TO_TERMINATED return } - console.log("GrantAbility request permission=" + JSON.stringify(this.reqPerms) + ", tokenId = " + this.accessTokenId) - this.reqPerms.forEach(item => { - var group = getPermissionGroup(item) - if(!group) { - this.grantGroups.push(0) - console.log("GrantAbility permission not find:" + item) - }else { - this.grantGroups.push(group) - } - }) - this.initStatus = Constants.INIT_NEED_TO_VERIFY + console.log(TAG + "GrantAbility request permission=" + JSON.stringify(this.reqPerms) + ", tokenId = " + this.accessTokenId) + this.result = new Array(this.reqPerms.length).fill(-1); + this.getgrantGroups(); this.getApplicationName(want.parameters['ohos.aafwk.param.callerUid']) }) } @@ -199,7 +206,7 @@ export struct privacyDialog { if (this.initStatus == Constants.INIT_NEED_TO_TERMINATED) { ret = Constants.RESULT_FAILURE } - console.log("GrantAbility code:" + ret + ", result=" + JSON.stringify(this.result)) + console.log(TAG + "GrantAbility code:" + ret + ", result=" + JSON.stringify(this.result)) featureAbility.terminateSelfWithResult({ resultCode: ret, want: { diff --git a/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/dynamic/common/model/bundle.ets b/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/GrantAbility/common/model/bundle.ets similarity index 100% rename from frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/dynamic/common/model/bundle.ets rename to frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/GrantAbility/common/model/bundle.ets diff --git a/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/dynamic/common/model/permissionGroup.ets b/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/GrantAbility/common/model/permissionGroup.ets similarity index 100% rename from frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/dynamic/common/model/permissionGroup.ets rename to frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/GrantAbility/common/model/permissionGroup.ets diff --git a/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/dynamic/common/utils/constant.ets b/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/GrantAbility/common/utils/constant.ets similarity index 100% rename from frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/dynamic/common/utils/constant.ets rename to frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/GrantAbility/common/utils/constant.ets diff --git a/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/dynamic/common/utils/utils.ets b/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/GrantAbility/common/utils/utils.ets similarity index 100% rename from frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/dynamic/common/utils/utils.ets rename to frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/GrantAbility/common/utils/utils.ets diff --git a/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/dynamic/pages/dialogPlus.ets b/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/GrantAbility/pages/dialogPlus.ets similarity index 55% rename from frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/dynamic/pages/dialogPlus.ets rename to frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/GrantAbility/pages/dialogPlus.ets index bb999651940bc9410fecd81d3ad8e879ed5d2053..cb5c9c93dd89960832131c2d7ed4f414ad09e20a 100644 --- a/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/dynamic/pages/dialogPlus.ets +++ b/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/GrantAbility/pages/dialogPlus.ets @@ -16,6 +16,8 @@ import { privacyDialog } from "../common/components/dialog.ets" import abilityAccessCtrl from '@ohos.abilityAccessCtrl'; +var TAG = "PermissionManager_GrantAbility" + @Entry @Component struct dialogPlusPage { @@ -28,49 +30,37 @@ struct dialogPlusPage { alignment: DialogAlignment.Center }) async privacyAccept(group, accessTokenId, permissionList, userFixedFlag) { - try { - var acManager = abilityAccessCtrl.createAtManager() - var num = 0 - group.permissions.forEach(async permission => { - console.log("GrantAbility grant permission:" + permission) - const result = await acManager.grantUserGrantedPermission(accessTokenId, permission, userFixedFlag) - num ++ - console.log("GrantAbility grant permission result:" + result) - var index = permissionList.indexOf(permission) - if (index == -1) { - console.log("GrantAbility grant permission index err:" + permission) - }else { - if (result == 0) { - this.result[index] = 0 - console.log("GrantAbility grant permission success:" + permission) - } else { - console.log("GrantAbility failed to grant permission:" + permission + " ret:" + result) + var acManager = abilityAccessCtrl.createAtManager() + var num = 0 + group.permissions.forEach(async permission => { + const result = await acManager.grantUserGrantedPermission(accessTokenId, permission, userFixedFlag) + num ++ + console.log(TAG + "GrantAbility grant permission result:" + result + "permission" + permission) + if (result == abilityAccessCtrl.GrantStatus.PERMISSION_GRANTED) { + permissionList.forEach((req, idx) => { + if(req == permission) { + this.result[idx] = abilityAccessCtrl.GrantStatus.PERMISSION_GRANTED; } - } - if(num == group.permissions.length) { - this.count ++ - } - }) - }catch { - this.count ++ - } + }) + console.log(TAG + "GrantAbility grant permission success:" + permission) + } else { + console.log(TAG + "GrantAbility failed to grant permission:" + permission + " ret:" + result) + } + if(num == group.permissions.length) { + this.count ++ + } + }) } async privacyCancel(group, accessTokenId, permissionList, userFixedFlag) { var acManager = abilityAccessCtrl.createAtManager() group.permissions.forEach(async permission => { - console.log("GrantAbility revoke permission:" + permission) const result = await acManager.revokeUserGrantedPermission(accessTokenId, permission, userFixedFlag) - console.log("GrantAbility revoke permission result:" + result) - var index = permissionList.indexOf(permission) - if (index != -1 && result == 0) { - this.result[index] = -1 - console.log("GrantAbility revoke permission:" + permission) - } + console.log(TAG + "GrantAbility revoke permission result:" + result + "permission" + permission); }) this.count ++ } privacyExist() { - console.info("exist") + console.info(TAG + "exist") } aboutToAppear() { this.privacyDialogController.open() diff --git a/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/default/app.ets b/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/MainAbility/app.ets similarity index 100% rename from frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/default/app.ets rename to frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/MainAbility/app.ets diff --git a/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/default/common/components/alphabeticalIndex.ets b/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/MainAbility/common/components/alphabeticalIndex.ets similarity index 100% rename from frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/default/common/components/alphabeticalIndex.ets rename to frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/MainAbility/common/components/alphabeticalIndex.ets diff --git a/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/default/common/components/backBar.ets b/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/MainAbility/common/components/backBar.ets similarity index 100% rename from frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/default/common/components/backBar.ets rename to frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/MainAbility/common/components/backBar.ets diff --git a/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/default/common/components/dialog.ets b/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/MainAbility/common/components/dialog.ets similarity index 100% rename from frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/default/common/components/dialog.ets rename to frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/MainAbility/common/components/dialog.ets diff --git a/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/default/common/components/search.ets b/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/MainAbility/common/components/search.ets similarity index 100% rename from frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/default/common/components/search.ets rename to frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/MainAbility/common/components/search.ets diff --git a/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/default/common/model/permissionGroup.ets b/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/MainAbility/common/model/permissionGroup.ets similarity index 97% rename from frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/default/common/model/permissionGroup.ets rename to frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/MainAbility/common/model/permissionGroup.ets index d5a3d0318a82005d9e75e84d4db6efe04fc441b8..77a0fdd33dfda1a7e2b8fe9a14e7360524c68834 100644 --- a/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/default/common/model/permissionGroup.ets +++ b/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/MainAbility/common/model/permissionGroup.ets @@ -193,7 +193,8 @@ export const groups: any[] = [ "permissions": [ "ohos.permission.LOCATION_IN_BACKGROUND", "ohos.permission.LOCATION" - ] + ], + "isShow":true }, { "name": "CAMERA", @@ -202,7 +203,8 @@ export const groups: any[] = [ "description": "访问您的相机", "permissions": [ "ohos.permission.CAMERA" - ] + ], + "isShow":true }, { "name": "MICROPHONE", @@ -211,7 +213,8 @@ export const groups: any[] = [ "description": "访问您的麦克风", "permissions": [ "ohos.permission.MICROPHONE" - ] + ], + "isShow":true }, { "name": "PHONE", @@ -221,7 +224,8 @@ export const groups: any[] = [ "permissions": [ "ohos.permission.ANSWER_CALL", "ohos.permission.MANAGE_VOICEMAIL" - ] + ], + "isShow":false }, { "name": "SMS", @@ -235,7 +239,8 @@ export const groups: any[] = [ "ohos.permission.RECEIVE_SMS", "ohos.permission.RECEIVE_WAP_MESSAGES", "ohos.permission.SEND_MESSAGES" - ] + ], + "isShow":false }, { "name": "CONTACTS", @@ -245,7 +250,8 @@ export const groups: any[] = [ "permissions": [ "ohos.permission.READ_CONTACTS", "ohos.permission.WRITE_CONTACTS" - ] + ], + "isShow":false }, { "name": "CALL_LOG", @@ -255,7 +261,8 @@ export const groups: any[] = [ "permissions": [ "ohos.permission.READ_CALL_LOG", "ohos.permission.WRITE_CALL_LOG" - ] + ], + "isShow":false }, { "name": "MEDIA", @@ -266,7 +273,8 @@ export const groups: any[] = [ "ohos.permission.MEDIA_LOCATION", "ohos.permission.READ_MEDIA", "ohos.permission.WRITE_MEDIA" - ] + ], + "isShow":true }, { "name": "CALENDAR", @@ -276,7 +284,8 @@ export const groups: any[] = [ "permissions": [ "ohos.permission.READ_CALENDAR", "ohos.permission.WRITE_CALENDAR" - ] + ], + "isShow":true }, { "name": "SPORT", @@ -285,7 +294,8 @@ export const groups: any[] = [ "description": "访问您的运动状态", "permissions": [ "ohos.permission.ACTIVITY_MOTION" - ] + ], + "isShow":true }, { "name": "HEALTH", @@ -294,7 +304,8 @@ export const groups: any[] = [ "description": "访问您的健康数据", "permissions": [ "ohos.permission.READ_HEALTH_DATA" - ] + ], + "isShow":true }, { "name": "OTHER", @@ -303,7 +314,8 @@ export const groups: any[] = [ "description": "访问您的其它权限", "permissions": [ "ohos.permission.DISTRIBUTED_DATASYNC" - ] + ], + "isShow":false } ]; diff --git a/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/default/common/utils/constant.ets b/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/MainAbility/common/utils/constant.ets similarity index 93% rename from frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/default/common/utils/constant.ets rename to frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/MainAbility/common/utils/constant.ets index bfcd8362c75ea6b1fa68967a77c6647a0804d01b..cd7dceeae73242a74934a446960e789ad704c817 100644 --- a/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/default/common/utils/constant.ets +++ b/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/MainAbility/common/utils/constant.ets @@ -57,29 +57,30 @@ export default class Constants { static TEXTINPUT_IMAGE_MARGIN_TOP = 12; // grid useSizeType + static GRID_MARGIN = '0vp'; static GUTTER = 0; - static LEFT_XS_SPAN = 1; + static LEFT_XS_SPAN = 0; static LEFT_XS_OFFSET = 0; - static LEFT_SM_SPAN = 1; + static LEFT_SM_SPAN = 0; static LEFT_SM_OFFSET = 0; - static LEFT_MD_SPAN = 1; + static LEFT_MD_SPAN = 0; static LEFT_MD_OFFSET = 0; static LEFT_LG_SPAN = 2; static LEFT_LG_OFFSET = 0; - static MIDDLE_XS_SPAN = 1; - static MIDDLE_XS_OFFSET = 1; - static MIDDLE_SM_SPAN = 2; - static MIDDLE_SM_OFFSET = 1; - static MIDDLE_MD_SPAN = 6; - static MIDDLE_MD_OFFSET = 1; + static MIDDLE_XS_SPAN = 2; + static MIDDLE_XS_OFFSET = 0; + static MIDDLE_SM_SPAN = 4; + static MIDDLE_SM_OFFSET = 0; + static MIDDLE_MD_SPAN = 8; + static MIDDLE_MD_OFFSET = 0; static MIDDLE_LG_SPAN = 8; static MIDDLE_LG_OFFSET = 2; - static RIGHT_XS_SPAN = 1; + static RIGHT_XS_SPAN = 0; static RIGHT_XS_OFFSET = 2; - static RIGHT_SM_SPAN = 1; - static RIGHT_SM_OFFSET = 3; - static RIGHT_MD_SPAN = 1; - static RIGHT_MD_OFFSET = 7; + static RIGHT_SM_SPAN = 0; + static RIGHT_SM_OFFSET = 4; + static RIGHT_MD_SPAN = 0; + static RIGHT_MD_OFFSET = 8; static RIGHT_LG_SPAN = 2; static RIGHT_LG_OFFSET = 10; @@ -170,6 +171,7 @@ export default class Constants { static MANAGEMENT_ROW_PADDING_RIGHT = 12; static MANAGEMENT_ROW_PADDING_TOP = 8; static MANAGEMENT_ROW_MARGIN_TOP = 12; + static MANAGEMENT_TRANSPARENCY = 0.8; static APPLICATION_IMAGE_WIDTH = 40; static APPLICATION_IMAGE_HEIGHT = 40; static APPLICATION_IMAGE_MARGIN_RIGHT = 16; @@ -197,6 +199,7 @@ export default class Constants { // setTimeout static DELAY_TIME = 1000; + static DELAY_TIME_MAX = 2000; // radio static RADIO_ALLOW_NAME = '允许'; diff --git a/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/default/common/utils/utils.ets b/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/MainAbility/common/utils/utils.ets similarity index 100% rename from frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/default/common/utils/utils.ets rename to frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/MainAbility/common/utils/utils.ets diff --git a/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/default/pages/application-secondary.ets b/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/MainAbility/pages/application-secondary.ets similarity index 97% rename from frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/default/pages/application-secondary.ets rename to frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/MainAbility/pages/application-secondary.ets index 0876bbb9b5fe75dfaeaa5c99dce020d11744047c..4ec9944b51a76858c80b306f7202d1bfb49821b3 100644 --- a/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/default/pages/application-secondary.ets +++ b/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/MainAbility/pages/application-secondary.ets @@ -19,6 +19,8 @@ import abilityAccessCtrl from '@ohos.abilityAccessCtrl'; import { groups } from "../common/model/permissionGroup.ets"; import Constants from '../common/utils/constant.ets'; +var TAG = 'PermissionManager_MainAbility:' + const allowedStatus = 0; // Status: Allowed const bannedStatus = 1; // Status: Banned class AllowedObj { @@ -177,7 +179,7 @@ struct appNamePlusPage { build() { Column(){ - GridContainer({ gutter: Constants.GUTTER }) { + GridContainer({ gutter: Constants.GUTTER, margin: Constants.GRID_MARGIN }) { Row({}) { Row() .useSizeType({ @@ -187,7 +189,6 @@ struct appNamePlusPage { lg: { span: Constants.LEFT_LG_SPAN, offset: Constants.LEFT_LG_OFFSET } }) .height(Constants.FULL_HEIGHT) - .backgroundColor(Color.White) Row() { Column() { Row() { @@ -285,7 +286,6 @@ struct appNamePlusPage { } .width(Constants.FULL_WIDTH) .height(Constants.FULL_HEIGHT) - .backgroundColor($r('app.color.background_color')) } .layoutWeight(Constants.LAYOUT_WEIGHT) } @@ -305,10 +305,12 @@ struct appNamePlusPage { lg: { span: Constants.RIGHT_LG_SPAN, offset: Constants.RIGHT_LG_OFFSET } }) .height(Constants.FULL_HEIGHT) - .backgroundColor(Color.White) } .height(Constants.FULL_HEIGHT) - }.backgroundColor(Color.White) + .width(Constants.FULL_WIDTH) + .backgroundColor($r("sys.color.ohos_id_color_sub_background")) + .opacity(Constants.MANAGEMENT_TRANSPARENCY) + } } } } diff --git a/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/default/pages/application-tertiary.ets b/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/MainAbility/pages/application-tertiary.ets similarity index 96% rename from frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/default/pages/application-tertiary.ets rename to frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/MainAbility/pages/application-tertiary.ets index b1d7eab8c1ba415e15e7e88cd60a979788962bd2..8948b24626330a4ea395c872736d33a2798382f9 100644 --- a/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/default/pages/application-tertiary.ets +++ b/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/MainAbility/pages/application-tertiary.ets @@ -22,6 +22,8 @@ import { authorizeDialog } from "../common/components/dialog.ets"; import { permissionDescriptions, permissionGroups } from "../common/model/permissionGroup.ets"; import Constants from '../common/utils/constant.ets'; +var TAG = 'PermissionManager_MainAbility:' + let routerData = router.getParams().routerData; // Routing jump data let backTitle = router.getParams().backTitle; // return title name let status = router.getParams().status; // Status: Allowed, Forbidden @@ -73,7 +75,7 @@ class MediaListObj { struct mediaDocumentPage { build() { Column() { - GridContainer({ gutter: Constants.GUTTER }) { + GridContainer({ gutter: Constants.GUTTER, margin: Constants.GRID_MARGIN }) { Row() { Row() .useSizeType({ @@ -83,7 +85,6 @@ struct mediaDocumentPage { lg: { span: Constants.LEFT_LG_SPAN, offset: Constants.LEFT_LG_OFFSET } }) .height(Constants.FULL_HEIGHT) - .backgroundColor(Color.White) Row() { Column() { Row() { @@ -116,11 +117,13 @@ struct mediaDocumentPage { lg: { span: Constants.RIGHT_LG_SPAN, offset: Constants.RIGHT_LG_OFFSET } }) .height(Constants.FULL_HEIGHT) - .backgroundColor(Color.White) } .height(Constants.FULL_HEIGHT) + .width(Constants.FULL_WIDTH) + .backgroundColor($r("sys.color.ohos_id_color_sub_background")) + .opacity(Constants.MANAGEMENT_TRANSPARENCY) } - }.backgroundColor(Color.White) + } } } @@ -152,7 +155,7 @@ struct mediaDocumentItem { nowGrantResult = result; }) .catch((error) => { - console.error('grantUserGrantedPermission failed. Cause: ' + JSON.stringify(error)); + console.error(TAG + 'grantUserGrantedPermission failed. Cause: ' + JSON.stringify(error)); }) } @@ -167,7 +170,7 @@ struct mediaDocumentItem { nowRevokeResult = result; }) .catch((error) => { - console.error('revokeUserGrantedPermission failed. Cause: ' + JSON.stringify(error)); + console.error(TAG + 'revokeUserGrantedPermission failed. Cause: ' + JSON.stringify(error)); }) } @@ -202,7 +205,7 @@ struct mediaDocumentItem { ) ); }).catch((error) => { - console.error('bundle.getBundleInfo failed. Cause: ' + JSON.stringify(error)); + console.error(TAG + 'bundle.getBundleInfo failed. Cause: ' + JSON.stringify(error)); this.mediaListItem = new MediaListObj('', '', '', permissionDescription); this.mediaDocListItem.push( new MeidaDocObj(Constants.RADIO_ALLOW_NAME, Constants.RADIO_ALLOW_INDEX, @@ -379,8 +382,7 @@ struct mediaDocumentItem { }) .width(Constants.FULL_WIDTH) .height(Constants.FULL_HEIGHT) - .backgroundColor($r('app.color.background_color')) } - .backgroundColor($r('app.color.background_color')).width(Constants.FULL_WIDTH) + .width(Constants.FULL_WIDTH) } } diff --git a/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/default/pages/authority-management.ets b/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/MainAbility/pages/authority-management.ets similarity index 89% rename from frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/default/pages/authority-management.ets rename to frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/MainAbility/pages/authority-management.ets index a1ee72c452beb2c62297a19384452d585ab6a078..318e24e6aef581d3613e8f22408b8f31ae95f096 100644 --- a/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/default/pages/authority-management.ets +++ b/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/MainAbility/pages/authority-management.ets @@ -24,6 +24,8 @@ import { permissionGroups, permissionPermissionGroup, permissionGroupIds } from import { makePy } from "../common/utils/utils.ets"; import Constants from '../common/utils/constant.ets'; +var TAG = 'PermissionManager_MainAbility:' + @Extend(Image) function customizeImage(width: number, height: number) { .objectFit(ImageFit.Contain) .width(width) @@ -50,7 +52,8 @@ interface groupPermission { 'group': string, 'permissions': string[], 'groupName': string, - 'icon': string + 'icon': string, + 'isShow':boolean }; let bundleInfosList: any[] = []; // Permission information array @@ -92,24 +95,22 @@ struct authorityManagementPage { uri: 'pages/authority-secondary', params: { routerData: this.allPermissionApplications, backTitle: item.groupName } }) - } else { - if (item.permissions.length > 1) { - router.push({ - uri: 'pages/authority-secondary', - params: { routerData: this.allPermissionApplications, backTitle: item.groupName } - }) - } else { + }else if((item.groupName === '电话' || item.groupName === '通讯录' || item.groupName === '信息' + || item.groupName === '通话记录' || item.groupName === '日历')){ + router.push({ + uri: 'pages/authority-secondary', + params: { routerData: this.allPermissionApplications, backTitle: item.groupName } + }) + }else { + var dataList = this.allPermissionApplications.filter((ele) => { - return ele.permission === item.permissions[0] + return ele.groupName === item.group }) - var tertiaryLabel = permissionGroups.filter((ele) => { - return ele.permissionName === item.permissions[0] - })[0].label + router.push({ - uri: 'pages/authority-tertiary', - params: { routerData: dataList, backTitle: tertiaryLabel } + uri: 'pages/authority-tertiary-groups', + params: { routerData: dataList, backTitle: item.groupName } }) - } } }) } @@ -168,7 +169,7 @@ struct authorityManagementPage { const bundleInfos = res; var count = bundleInfos.length; if (count <= 0) { - console.info('bundle.getAllBundleInfo result.length less than or equal to zero'); + console.info(TAG + 'bundle.getAllBundleInfo result.length less than or equal to zero'); return; } var infoIndex = 0; @@ -203,7 +204,7 @@ struct authorityManagementPage { }) }) .catch((error) => { - console.error('bundle.getAllBundleInfo failed. Cause: ' + JSON.stringify(error)); + console.error(TAG + 'bundle.getAllBundleInfo failed. Cause: ' + JSON.stringify(error)); }) } @@ -259,22 +260,60 @@ struct authorityManagementPage { */ getAllGroupPermission() { const this_ = this; + var temp1 = []; + temp1 = ["LOCATION","CAMERA","MICROPHONE","MEDIA","CALENDAR","SPORT","HEALTH"]; + groups.forEach((item) => { + if (temp1.indexOf(item.name) > -1) { + var gp: groupPermission = { + "group": item.name, + "permissions": item.permissions, + 'groupName': item.groupName, + 'icon': item.icon, + 'isShow': item.isShow + }; + this_.allGroupPermission.push(gp); + } + }) + let temp2 = []; + groups.forEach((item) => { + if (item.isShow && temp1.indexOf(item.name) === -1) { + var gp: groupPermission = { + "group": item.name, + "permissions": item.permissions, + 'groupName': item.groupName, + 'icon': item.icon, + 'isShow': item.isShow + }; + temp2.push(item.name); + this_.allGroupPermission.push(gp); + } + }) for (let i = 0; i < this_.allPermissionApplications.length; i++) { - if (this_.allGroups.length > 0) { - if (this_.allGroups.indexOf(this_.allPermissionApplications[i].groupName) == -1) { + if (this_.allGroups.indexOf(this_.allPermissionApplications[i].groupName) == -1 + && temp1.indexOf(this_.allPermissionApplications[i].groupName) == -1) { this_.allGroups.push(this_.allPermissionApplications[i].groupName); } - } else { - this_.allGroups.push(this_.allPermissionApplications[i].groupName); - } } + // Permission layout + var temp = this_.allGroups; + temp = temp.filter(function(item) { + return temp1.indexOf(item) == -1 && temp2.indexOf(item) == -1; + }); + if (temp.indexOf("OTHER") > -1) { + temp.splice(temp.indexOf("OTHER"),1); + temp.push("OTHER"); + }else { + temp.push("OTHER"); + } + this_.allGroups = temp; for (let i = 0; i < this_.allGroups.length; i++) { var permissions: string[] = permissionGroupPermissions[this_.allGroups[i]]; var gp: groupPermission = { "group": this_.allGroups[i], "permissions": permissions, 'groupName': '', - 'icon': '' + 'icon': '', + 'isShow': false }; this_.allGroupPermission.push(gp); } @@ -283,6 +322,7 @@ struct authorityManagementPage { if (ele.group === item.name) { ele.groupName = item.groupName; ele.icon = item.icon; + ele.isShow = item.isShow; } }); }) @@ -349,7 +389,7 @@ struct authorityManagementPage { } }) }).catch(error => { - console.error('Resmgr.getResourceManager failed. Cause: ' + JSON.stringify(error)); + console.error(TAG + 'Resmgr.getResourceManager failed. Cause: ' + JSON.stringify(error)); }) } @@ -368,7 +408,7 @@ struct authorityManagementPage { info['iconId'] = value; }) }).catch(error => { - console.error('Resmgr.getResourceManager failed. Cause: ' + JSON.stringify(error)); + console.error(TAG + 'Resmgr.getResourceManager failed. Cause: ' + JSON.stringify(error)); }) } @@ -380,7 +420,7 @@ struct authorityManagementPage { } build() { - GridContainer({ gutter: Constants.GUTTER }) { + GridContainer({ gutter: Constants.GUTTER, margin: Constants.GRID_MARGIN }) { Row() { Row() .useSizeType({ @@ -423,7 +463,6 @@ struct authorityManagementPage { }) } }.width(Constants.FULL_WIDTH) - .backgroundColor($r('app.color.background_color')) } }.tabBar($r('app.string.authority')) TabContent() { @@ -433,7 +472,6 @@ struct authorityManagementPage { }) }.tabBar($r('app.string.application')) } - .backgroundColor($r('app.color.background_color')) .barWidth(Constants.BAR_WIDTH) .barMode(BarMode.Fixed) }.height(Constants.FULL_HEIGHT) @@ -460,6 +498,9 @@ struct authorityManagementPage { .height(Constants.FULL_HEIGHT) } .height(Constants.FULL_HEIGHT) + .width(Constants.FULL_WIDTH) + .backgroundColor($r("sys.color.ohos_id_color_sub_background")) + .opacity(Constants.MANAGEMENT_TRANSPARENCY) } } } diff --git a/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/default/pages/authority-secondary.ets b/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/MainAbility/pages/authority-secondary.ets similarity index 95% rename from frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/default/pages/authority-secondary.ets rename to frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/MainAbility/pages/authority-secondary.ets index be6785d47e943d21037f6a891905a365f15008f9..61df8d7fd14f4031b4a9bc584ecb5d6dc5534a21 100644 --- a/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/default/pages/authority-secondary.ets +++ b/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/MainAbility/pages/authority-secondary.ets @@ -18,6 +18,8 @@ import { permissionGroups, groups } from "../common/model/permissionGroup.ets"; import router from '@system.router'; import Constants from '../common/utils/constant.ets'; +var TAG = 'PermissionManager_MainAbility:' + class CalendarObj { permissionName: string groupName: string @@ -39,7 +41,7 @@ struct appNamePage { private backTitle = router.getParams().backTitle; // return title name build() { - GridContainer({ gutter: Constants.GUTTER }) { + GridContainer({ gutter: Constants.GUTTER, margin: Constants.GRID_MARGIN }) { Row() { Row() .useSizeType({ @@ -80,6 +82,9 @@ struct appNamePage { .height(Constants.FULL_HEIGHT) } .height(Constants.FULL_HEIGHT) + .width(Constants.FULL_WIDTH) + .backgroundColor($r("sys.color.ohos_id_color_sub_background")) + .opacity(Constants.MANAGEMENT_TRANSPARENCY) } } } @@ -166,7 +171,6 @@ struct appNameItem { } .width(Constants.FULL_WIDTH) .height(Constants.FULL_HEIGHT) - .backgroundColor($r('app.color.background_color')) } } } diff --git a/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/MainAbility/pages/authority-tertiary-groups.ets b/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/MainAbility/pages/authority-tertiary-groups.ets new file mode 100644 index 0000000000000000000000000000000000000000..b2dfa6ab70f19d44ab8cea9ca59287aaf85bd2f6 --- /dev/null +++ b/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/MainAbility/pages/authority-tertiary-groups.ets @@ -0,0 +1,382 @@ +/* + * Copyright (c) 2021-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 { backBar } from "../common/components/backBar.ets"; +import { alphabetIndexerComponent } from "../common/components/alphabeticalIndex.ets"; +import { textInput } from "../common/components/search.ets"; +import router from '@system.router'; +import bundle from "@ohos.bundle"; +import abilityAccessCtrl from '@ohos.abilityAccessCtrl'; +import { getAppLabel, getAppIcon, verifyAccessToken} from "../common/utils/utils"; +import { makePy } from "../common/utils/utils.ets"; +import { authorizeDialog } from "../common/components/dialog.ets"; +import Constants from '../common/utils/constant.ets'; + +var TAG = 'PermissionManager_MainAbility:' + +@Extend(Image) function customizeImage(width: number, height: number) { + .objectFit(ImageFit.Contain) + .width(width) + .height(height) +} + +let routerData = router.getParams().routerData; // Routing jump data +let backTitle = router.getParams().backTitle; // return title name +let nowGrantResult = Constants.PERMISSION_NUM; // Authorization results now +let nowRevokeResult = Constants.PERMISSION_NUM; // Now deauthorize results +let GrantResultFlag = []; // Authorization result Flag +let RevokeResultFlag = []; // Cancel authorization result Flag + +class ApplicationObj { + labelId: string + iconId: string + index: number + accessTokenId: string + permission: string + alphabeticalIndex: string + constructor( + labelId: string, + iconId: string, + index: number, + accessTokenId: string, + permission: string, + alphabeticalIndex: string) { + this.labelId = labelId + this.iconId = iconId + this.index = index + this.accessTokenId = accessTokenId + this.permission = permission + this.alphabeticalIndex = alphabeticalIndex + } +} // application information + +@Entry +@Component +struct locationInfoPage { + build() { + GridContainer({ gutter: Constants.GUTTER, margin: Constants.GRID_MARGIN }) { + Row() { + Row() + .useSizeType({ + xs: { span: Constants.LEFT_XS_SPAN, offset: Constants.LEFT_XS_OFFSET }, + sm: { span: Constants.LEFT_SM_SPAN, offset: Constants.LEFT_SM_OFFSET }, + md: { span: Constants.LEFT_MD_SPAN, offset: Constants.LEFT_MD_OFFSET }, + lg: { span: Constants.LEFT_LG_SPAN, offset: Constants.LEFT_LG_OFFSET } + }) + .height(Constants.FULL_HEIGHT) + Row() { + Column() { + Row() { + backBar({ title: JSON.stringify(backTitle) }) + } + Row() { + Column() { + applicationItem() + + }.width(Constants.FULL_WIDTH) + } + .layoutWeight(Constants.LAYOUT_WEIGHT) + } + } + .useSizeType({ + xs: { span: Constants.MIDDLE_XS_SPAN, offset: Constants.MIDDLE_XS_OFFSET }, + sm: { span: Constants.MIDDLE_SM_SPAN, offset: Constants.MIDDLE_SM_OFFSET }, + md: { span: Constants.MIDDLE_MD_SPAN, offset: Constants.MIDDLE_MD_OFFSET }, + lg: { span: Constants.MIDDLE_LG_SPAN, offset: Constants.MIDDLE_LG_OFFSET } + }) + .height(Constants.FULL_HEIGHT) + Row() + .useSizeType({ + xs: { span: Constants.RIGHT_XS_SPAN, offset: Constants.RIGHT_XS_OFFSET }, + sm: { span: Constants.RIGHT_SM_SPAN, offset: Constants.RIGHT_SM_OFFSET }, + md: { span: Constants.RIGHT_MD_SPAN, offset: Constants.RIGHT_MD_OFFSET }, + lg: { span: Constants.RIGHT_LG_SPAN, offset: Constants.RIGHT_LG_OFFSET } + }) + .height(Constants.FULL_HEIGHT) + } + .height(Constants.FULL_HEIGHT) + .width(Constants.FULL_WIDTH) + .backgroundColor($r("sys.color.ohos_id_color_sub_background")) + .opacity(Constants.MANAGEMENT_TRANSPARENCY) + } + } +} + +@Component +struct applicationItem { + @State permissionNum: number = Constants.PERMISSION_NUM; // permission num + @State toggleIsOn: object = {}; // toggle switch state array + @State applicationList: ApplicationObj[] = []; // application info array + @State oldApplicationItem: ApplicationObj[] = []; // Original application information array + @State searchResult: boolean = true; // search results + + authorizeDialogController: CustomDialogController = new CustomDialogController({ + builder: authorizeDialog({ }), + autoCancel: true, + alignment: DialogAlignment.Center + }); + + @Builder ListItemLayout(item, index) { + ListItem() { + Row() { + Column() { + Flex({ justifyContent: FlexAlign.Start, alignItems: ItemAlign.Center }) { + Row() { + Image(item.iconId) + .customizeImage(Constants.AUTHORITY_IMAGE_WIDTH, Constants.AUTHORITY_IMAGE_HEIGHT) + .margin({ right: Constants.AUTHORITY_IMAGE_MARGIN_RIGHT }) + Text(item.labelId) + .fontSize(Constants.TEXT_MIDDLE_FONT_SIZE) + .fontColor($r('app.color.text_color')) + .flexGrow(Constants.FLEX_GROW) + Toggle({ type: ToggleType.Switch, isOn: this.toggleIsOn[item.index] }) + .selectedColor($r('app.color.toggle_color')) + .width(Constants.AUTHORITY_TOGGLE_WIDTH) + .height(Constants.AUTHORITY_TOGGLE_HEIGHT) + .onChange((isOn: boolean) => { + if (item.accessTokenId === '' || item.permission === '') { + return; + } + let _this = this; + if (isOn) { + let promises = routerData.map(it => new Promise((resolve, reject) => { + _this.grantUserGrantedPermission(item.accessTokenId, it.permission, item.index, resolve); + })); + Promise.all(promises).then(function(results) { + if(results.indexOf(-1) != -1) { + _this.authorizeDialogController.open(); + _this.toggleIsOn[item.index] = false; + setTimeout(()=> { + _this.authorizeDialogController.close(); + }, Constants.DELAY_TIME) + } else { + _this.toggleIsOn[item.index] = true; + } + let num = Constants.PERMISSION_NUM; + for(let key in _this.toggleIsOn){ + if(_this.toggleIsOn[key]){ + num++; + } + } + _this.permissionNum = num; + }); + } else { + let promises = routerData.map(it => new Promise((resolve, reject) => { + _this.revokeUserGrantedPermission(item.accessTokenId, it.permission, item.index, resolve); + })); + Promise.all(promises).then(function(results) { + if(results.indexOf(-1) != -1) { + _this.authorizeDialogController.open(); + _this.toggleIsOn[item.index] = true; + setTimeout(()=> { + _this.authorizeDialogController.close(); + }, Constants.DELAY_TIME) + } else { + _this.toggleIsOn[item.index] = false; + } + let num = Constants.PERMISSION_NUM; + for(let key in _this.toggleIsOn){ + if(_this.toggleIsOn[key]){ + num++; + } + } + _this.permissionNum = num; + }); + } + }) + } + .width(Constants.FULL_WIDTH) + .height(Constants.AUTHORITY_ROW_HEIGHT) + .constraintSize({ minHeight: Constants.AUTHORITY_CONSTRAINTSIZE_MINHEIGHT }) + } + if (!index) { + Row() { + Column() + .backgroundColor($r('app.color.text_decoration_color')) + .width(Constants.AUTHORITY_TEXT_DECORATION_WIDTH) + .height(Constants.TEXT_DECORATION_HEIGHT) + .margin({ left: Constants.AUTHORITY_TEXT_DECORATION_MARGIN_LEFT }) + } + } + }.onClick(() => { + }) + } + }.padding({ left: Constants.LISTITEM_PADDING_LEFT, right: Constants.AUTHORITY_LISTITEM_PADDING_RIGHT }) + } + + /** + * Grant permissions to the app + * @param {Number} accessTokenId + * @param {String} permission permission name + * @param {Number} index Array index to modify permission status + */ + grantUserGrantedPermission(accessTokenId, permission, index, resolve) { + abilityAccessCtrl.createAtManager().grantUserGrantedPermission( + accessTokenId, permission, Constants.PERMISSION_FLAG).then(result => { + // result: 0 Authorization succeeded; result: -1 Authorization failed + resolve(result); + }).catch(error => { + resolve(-1); + console.error(TAG + 'abilityAccessCtrl.createAtManager.grantUserGrantedPermission failed. Cause: ' + JSON.stringify(error)); + }) + } + + /** + * Deauthorize the app + * @param {Number} accessTokenId + * @param {String} permission permission name + * @param {Number} index Array index to modify permission status + */ + revokeUserGrantedPermission(accessTokenId, permission, index, resolve) { + abilityAccessCtrl.createAtManager().revokeUserGrantedPermission( + accessTokenId, permission, Constants.PERMISSION_FLAG).then(result => { + // result: 0 successfully cancel the authorization; result: -1 cancel the authorization failed + resolve(result); + }).catch(error => { + resolve(-1); + console.error(TAG + 'abilityAccessCtrl.createAtManager.revokeUserGrantedPermission failed. Cause: ' + JSON.stringify(error)); + }) + } + + /** + * Lifecycle function, executed when the page is initialized + */ + aboutToAppear() { + for (let i = 0; i < routerData[0].bundleNames.length; i++) { + // Get BundleInfo based on bundle name + bundle.getBundleInfo(routerData[0].bundleNames[i], Constants.PARMETER_BUNDLE_FLAG).then(res => { + Promise.all([getAppLabel(res.appInfo.labelId, res.name), + getAppIcon(res.appInfo.iconId, res.name), + verifyAccessToken(res.appInfo.accessTokenId, routerData[0].permission) + ]) + .then((values) => { + this.applicationList.push( + new ApplicationObj( + String(values[0]), + String(values[1]), + i, + res.appInfo.accessTokenId, + routerData[0].permission, + makePy(values[0])[0].slice(0, 1)) // Get the first letter in the returned initials array + ); + this.oldApplicationItem.push( + new ApplicationObj( + String(values[0]), + String(values[1]), + i, + res.appInfo.accessTokenId, + routerData[0].permission, + makePy(values[0])[0].slice(0, 1)) // Get the first letter in the returned initials array + ); + this.applicationList.sort((a,b) => a.index - b.index) + this.oldApplicationItem.sort((a,b) => a.index - b.index) + }); + // 0: have permission; -1: no permission + var boole = true; + this.permissionNum++; + for (let j = 0; j < routerData.length; j++) { + verifyAccessToken(res.appInfo.accessTokenId, routerData[j].permission).then((access) => { + if (Number(access) === Constants.PERMISSION_INDEX) { + if(boole){ + this.toggleIsOn[i] = true; + } + } else { + if(boole){ + this.permissionNum-- + } + boole = false; + this.toggleIsOn[i] = false; + } + }); + } + }).catch(() => { + this.applicationList.push( + new ApplicationObj('', '', 0, '', '', '') + ); + this.oldApplicationItem.push( + new ApplicationObj('', '', 0, '', '', '') + ); + }) + + } + } + + build() { + Column() { + Row() { + textInput({ + placeholder: $r('app.string.textInput_placeholder'), + applicationItem: $applicationList, + oldApplicationItem: $oldApplicationItem, + searchResult: $searchResult + }) + }.padding({ + left: Constants.AUTHORITY_TEXTINPUT_PADDING_LEFT, + right: Constants.AUTHORITY_TEXTINPUT_PADDING_RIGHT + }) + Row() { + Flex({ alignItems:ItemAlign.Start, justifyContent: FlexAlign.Start }) { + Column() { + Flex({ justifyContent: FlexAlign.Start }) { + Text(this.permissionNum + '个应用获取此权限') + .fontSize(Constants.TEXT_SMAL_FONT_SIZE) + .fontColor($r('app.color.secondary_font_color')) + .margin({ top: Constants.AUTHORITY_TEXT_MARGIN_TOP, left: Constants.AUTHORITY_TEXT_MARGIN_LEFT }) + } + Scroll() { + Row() { + Column() { + if (!this.applicationList.length) { + if (this.searchResult) { + Row() { + }.margin({ top: Constants.AUTHORITY_ROW_MARGIN_TOP }) + } else { + Row() { + Flex({ justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { + Image($r('app.media.searchnoresult')) + .customizeImage(Constants.SEARCHNORESULT_IMAGE_WIDTH, Constants.SEARCHNORESULT_IMAGE_HEIGHT) + } + }.margin({ top: Constants.AUTHORITY_ROW_MARGIN_TOP }) + } + } else { + Row() { + List() { + ForEach(this.applicationList.slice(Constants.SLICE_START, this.applicationList.length - 1), + (item) => { + this.ListItemLayout(item, Constants.SLICE_START_INDEX) + }, item => item.toString()) + ForEach(this.applicationList.slice(Constants.SLICE_END), (item, index) => { + this.ListItemLayout(item, Constants.SLICE_END_INDEX) + }, item => item.toString()) + } + .backgroundColor($r('app.color.default_background_color')) + .borderRadius(Constants.BORDER_RADIUS) + .padding({ top: Constants.LIST_PADDING_TOP, bottom: Constants.LIST_PADDING_BOTTOM }) + }.margin({ top: Constants.AUTHORITY_ROW_MARGIN_TOP }) + } + }.width(Constants.FULL_WIDTH) + .height(Constants.AUTHORITY_COLUMN_HEIGHT) + } + } + }.padding({ left: Constants.AUTHORITY_LISTITEM_PADDING_LEFT }) + Column() { + alphabetIndexerComponent({ applicationItem: $applicationList, oldApplicationItem: $oldApplicationItem }) + }.width(Constants.AUTHORITY_ALPHABETINDEX_WIDTH) + .padding({ top: Constants.AUTHORITY_ALPHABETINDEX_PADDING_TOP }) + } + } + } + } +} diff --git a/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/default/pages/authority-tertiary.ets b/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/MainAbility/pages/authority-tertiary.ets similarity index 97% rename from frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/default/pages/authority-tertiary.ets rename to frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/MainAbility/pages/authority-tertiary.ets index f0ef99c12be14ea5c45a15c0be08e47d2433340d..2f18b7b92bbfe5418fa05bf05a4494146b42f7b7 100644 --- a/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/default/pages/authority-tertiary.ets +++ b/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/MainAbility/pages/authority-tertiary.ets @@ -24,6 +24,8 @@ import { makePy } from "../common/utils/utils.ets"; import { authorizeDialog } from "../common/components/dialog.ets"; import Constants from '../common/utils/constant.ets'; +var TAG = 'PermissionManager_MainAbility:' + @Extend(Image) function customizeImage(width: number, height: number) { .objectFit(ImageFit.Contain) .width(width) @@ -59,7 +61,7 @@ class ApplicationObj { @Component struct locationInfoPage { build() { - GridContainer({ gutter: Constants.GUTTER }) { + GridContainer({ gutter: Constants.GUTTER, margin: Constants.GRID_MARGIN }) { Row() { Row() .useSizeType({ @@ -100,6 +102,9 @@ struct locationInfoPage { .height(Constants.FULL_HEIGHT) } .height(Constants.FULL_HEIGHT) + .width(Constants.FULL_WIDTH) + .backgroundColor($r("sys.color.ohos_id_color_sub_background")) + .opacity(Constants.MANAGEMENT_TRANSPARENCY) } } } @@ -192,7 +197,7 @@ struct applicationItem { } this.permissionNum = num; }).catch(error => { - console.error('abilityAccessCtrl.createAtManager.grantUserGrantedPermission failed. Cause: ' + JSON.stringify(error)); + console.error(TAG + 'abilityAccessCtrl.createAtManager.grantUserGrantedPermission failed. Cause: ' + JSON.stringify(error)); }) } @@ -288,7 +293,6 @@ struct applicationItem { left: Constants.AUTHORITY_TEXTINPUT_PADDING_LEFT, right: Constants.AUTHORITY_TEXTINPUT_PADDING_RIGHT }) - .backgroundColor($r('app.color.background_color')) Row() { Flex({ alignItems:ItemAlign.Start, justifyContent: FlexAlign.Start }) { Column() { @@ -331,7 +335,6 @@ struct applicationItem { } }.width(Constants.FULL_WIDTH) .height(Constants.AUTHORITY_COLUMN_HEIGHT) - .backgroundColor($r('app.color.background_color')) } } }.padding({ left: Constants.AUTHORITY_LISTITEM_PADDING_LEFT }) @@ -341,7 +344,6 @@ struct applicationItem { .padding({ top: Constants.AUTHORITY_ALPHABETINDEX_PADDING_TOP }) } } - .backgroundColor($r('app.color.background_color')) } } } diff --git a/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/default/pages/other-permissions.ets b/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/MainAbility/pages/other-permissions.ets similarity index 95% rename from frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/default/pages/other-permissions.ets rename to frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/MainAbility/pages/other-permissions.ets index 8f29466ade22bdb42a4f0def89eebfa1d766f418..fa6ff1e8ac2c76bfa1b850510bc7b55a2942ac31 100644 --- a/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/default/pages/other-permissions.ets +++ b/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/MainAbility/pages/other-permissions.ets @@ -18,6 +18,8 @@ import router from '@system.router'; import Constants from '../common/utils/constant.ets'; import { otherPermissionsLabel } from '../common/model/permissionGroup.ets' +var TAG = 'PermissionManager_MainAbility:' + let routerData = router.getParams().routerData; // Routing jump data let backTitle = router.getParams().backTitle; // return title name let status = router.getParams().status; // Status: Allowed, Forbidden @@ -34,7 +36,7 @@ for (let i = 0; i < permissions.length; i++) { @Component struct appNamePage { build() { - GridContainer({ gutter: Constants.GUTTER }) { + GridContainer({ gutter: Constants.GUTTER, margin: Constants.GRID_MARGIN }) { Row() { Row() .useSizeType({ @@ -75,6 +77,9 @@ struct appNamePage { .height(Constants.FULL_HEIGHT) } .height(Constants.FULL_HEIGHT) + .width(Constants.FULL_WIDTH) + .backgroundColor($r("sys.color.ohos_id_color_sub_background")) + .opacity(Constants.MANAGEMENT_TRANSPARENCY) } } } @@ -142,7 +147,6 @@ struct appNameItem { } .width(Constants.FULL_WIDTH) .height(Constants.FULL_HEIGHT) - .backgroundColor($r('app.color.background_color')) } } } diff --git a/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/default/resources/ar/properties/string.json b/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/MainAbility/resources/ar/properties/string.json similarity index 100% rename from frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/default/resources/ar/properties/string.json rename to frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/MainAbility/resources/ar/properties/string.json diff --git a/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/default/resources/dark/properties/string.json b/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/MainAbility/resources/dark/properties/string.json similarity index 100% rename from frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/default/resources/dark/properties/string.json rename to frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/MainAbility/resources/dark/properties/string.json diff --git a/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/default/resources/default/media/icon_actived.png b/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/MainAbility/resources/default/media/icon_actived.png similarity index 100% rename from frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/default/resources/default/media/icon_actived.png rename to frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/MainAbility/resources/default/media/icon_actived.png diff --git a/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/default/resources/default/media/icon_normal.png b/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/MainAbility/resources/default/media/icon_normal.png similarity index 100% rename from frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/default/resources/default/media/icon_normal.png rename to frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/MainAbility/resources/default/media/icon_normal.png diff --git a/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/default/resources/default/properties/string.json b/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/MainAbility/resources/default/properties/string.json similarity index 100% rename from frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/default/resources/default/properties/string.json rename to frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/MainAbility/resources/default/properties/string.json diff --git a/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/default/resources/en/properties/string.json b/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/MainAbility/resources/en/properties/string.json similarity index 100% rename from frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/default/resources/en/properties/string.json rename to frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/MainAbility/resources/en/properties/string.json diff --git a/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/default/resources/light/properties/string.json b/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/MainAbility/resources/light/properties/string.json similarity index 100% rename from frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/default/resources/light/properties/string.json rename to frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/MainAbility/resources/light/properties/string.json diff --git a/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/default/resources/zh/properties/string.json b/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/MainAbility/resources/zh/properties/string.json similarity index 100% rename from frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/default/resources/zh/properties/string.json rename to frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/MainAbility/resources/zh/properties/string.json diff --git a/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/java/com/ohos/permissionmanager/MainAbility.java b/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/java/com/ohos/permissionmanager/MainAbility.java deleted file mode 100644 index a9467b0bf286aa3aaf299ab6f452cc8aad329a36..0000000000000000000000000000000000000000 --- a/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/java/com/ohos/permissionmanager/MainAbility.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2021-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. - */ - -package com.ohos.permissionmanager; - -import ohos.ace.ability.AceAbility; -import ohos.aafwk.content.Intent; - -public class MainAbility extends AceAbility { - @Override - public void onStart(Intent intent) { - setInstanceName("main_ability"); - super.onStart(intent); - } - - @Override - public void onStop() { - super.onStop(); - } -} diff --git a/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/java/com/ohos/permissionmanager/MyApplication.java b/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/java/com/ohos/permissionmanager/MyApplication.java deleted file mode 100644 index 6c8f0f649747c73fedd1c7f6f8bbbf4ff7684444..0000000000000000000000000000000000000000 --- a/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/java/com/ohos/permissionmanager/MyApplication.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2021-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. - */ - -package com.ohos.permissionmanager; - -import ohos.aafwk.ability.AbilityPackage; - -public class MyApplication extends AbilityPackage { - @Override - public void onInitialize() { - super.onInitialize(); - } -} diff --git a/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/resources/base/element/string.json b/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/resources/base/element/string.json index db1d293a5cf6fa1503adc4e40c1b2df350c9be59..f505eefa0783e14fc77e248265e4b4ecf2f11a5c 100644 --- a/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/resources/base/element/string.json +++ b/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/resources/base/element/string.json @@ -5,7 +5,7 @@ "value": "permissionmanager_MainAbility" }, { - "name": "mainability_description", + "name": "description_mainability", "value": "eTS_Empty Ability" }, { @@ -81,7 +81,7 @@ "value": "系统定位服务开关开启时,已允许19个应用获取此设备的位置。" }, { - "name": "grantability_description", + "name": "description_grantability", "value": "eTS_Empty Ability" }, { diff --git a/frameworks/com.ohos.permissionmanager/permissionmanager/src/ohosTest/ets/default/app.ets b/frameworks/com.ohos.permissionmanager/permissionmanager/src/ohosTest/ets/default/app.ets deleted file mode 100644 index 03748140d89081db2a38ad1b7076b234a4185bbd..0000000000000000000000000000000000000000 --- a/frameworks/com.ohos.permissionmanager/permissionmanager/src/ohosTest/ets/default/app.ets +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2021-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. - */ - -export default { - onCreate() { - console.info('Application onCreate') - }, - onShow() { - console.info('Application onShow') - }, - onDestroy() { - console.info('Application onDestroy') - }, -} diff --git a/frameworks/com.ohos.permissionmanager/permissionmanager/src/ohosTest/ets/default/i18n/en-US.json b/frameworks/com.ohos.permissionmanager/permissionmanager/src/ohosTest/ets/default/i18n/en-US.json deleted file mode 100644 index 55561b83737c3c31d082fbfa11e5fc987a351104..0000000000000000000000000000000000000000 --- a/frameworks/com.ohos.permissionmanager/permissionmanager/src/ohosTest/ets/default/i18n/en-US.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "strings": { - "hello": "Hello", - "world": "World" - }, - "Files": { - } -} \ No newline at end of file diff --git a/frameworks/com.ohos.permissionmanager/permissionmanager/src/ohosTest/ets/default/i18n/zh-CN.json b/frameworks/com.ohos.permissionmanager/permissionmanager/src/ohosTest/ets/default/i18n/zh-CN.json deleted file mode 100644 index cce1af06761a42add0cac1a0567aa3237eda8cb4..0000000000000000000000000000000000000000 --- a/frameworks/com.ohos.permissionmanager/permissionmanager/src/ohosTest/ets/default/i18n/zh-CN.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "strings": { - "hello": "您好", - "world": "世界" - }, - "Files": { - } -} \ No newline at end of file diff --git a/frameworks/com.ohos.permissionmanager/permissionmanager/src/ohosTest/ets/default/pages/index/index.ets b/frameworks/com.ohos.permissionmanager/permissionmanager/src/ohosTest/ets/default/pages/index/index.ets deleted file mode 100644 index 61dc37aa5443151e25e529cd4e08219670768aaa..0000000000000000000000000000000000000000 --- a/frameworks/com.ohos.permissionmanager/permissionmanager/src/ohosTest/ets/default/pages/index/index.ets +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2021-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 {Core, ExpectExtend, InstrumentLog} from "deccjsunit/index" -import testsuite from "../../../test/List.test.ets" -import featureAbility from "@ohos.ability.featureAbility" - -@Entry -@Component -struct MyComponent { - aboutToAppear() { - console.info("start run testcase!!!!") - featureAbility.getWant() - .then((Want) => { - const core = Core.getInstance() - const expectExtend = new ExpectExtend({ - 'id': 'extend' - }) - const instrumentLog = new InstrumentLog({ - 'id': 'report', 'unity': 'true' - }) - core.addService('expect', expectExtend) - core.addService('report', instrumentLog) - core.init() - core.subscribeEvent('spec', instrumentLog) - core.subscribeEvent('suite', instrumentLog) - core.subscribeEvent('task', instrumentLog) - const configService = core.getDefaultService('config') - configService.setConfig(Want.parameters) - testsuite() - core.execute() - console.info('Operation successful. Data: ' + JSON.stringify(Want)); - }) - .catch((error) => { - console.error('Operation failed. Cause: ' + JSON.stringify(error)); - }) - } - - build() { - Flex({ - direction: FlexDirection.Column, - alignItems: ItemAlign.Center, - justifyContent: FlexAlign.Center - }) { - Text('Hello World') - .fontSize(50) - .fontWeight(FontWeight.Bold) - } - .width('100%') - .height('100%') - } -} diff --git a/frameworks/com.ohos.permissionmanager/permissionmanager/src/ohosTest/ets/test/ExampleJsunit.test.ets b/frameworks/com.ohos.permissionmanager/permissionmanager/src/ohosTest/ets/test/ExampleJsunit.test.ets deleted file mode 100644 index c76c23ebb2e6db5bd021d5c6366e7fca8bdc1a40..0000000000000000000000000000000000000000 --- a/frameworks/com.ohos.permissionmanager/permissionmanager/src/ohosTest/ets/test/ExampleJsunit.test.ets +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2021-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 "deccjsunit/index" -import app from '@system.app' - -export default function exampleJsunit() { - describe('appInfoTest', function () { - it('app_info_test_001', 0, function () { - var info = app.getInfo() - expect("1.0").assertEqual('1.0') - expect(info.versionCode).assertEqual('3') - }) - }) -} diff --git a/frameworks/com.ohos.permissionmanager/permissionmanager/src/ohosTest/ets/test/List.test.ets b/frameworks/com.ohos.permissionmanager/permissionmanager/src/ohosTest/ets/test/List.test.ets deleted file mode 100644 index 23005224d04a66d893c235ae3d8a75d7cb363473..0000000000000000000000000000000000000000 --- a/frameworks/com.ohos.permissionmanager/permissionmanager/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (c) 2021-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 exampleJsunit from "../test/ExampleJsunit.test.ets" - -export default function testsuite() { - exampleJsunit() -} diff --git a/frameworks/com.ohos.permissionmanager/permissionmanager/src/ohosTest/java/com/ohos/permissionmanager/ExampleOhosTest.java b/frameworks/com.ohos.permissionmanager/permissionmanager/src/ohosTest/java/com/ohos/permissionmanager/ExampleOhosTest.java deleted file mode 100644 index e0c56a5cd908397fcedaa314224a4d7261152bc6..0000000000000000000000000000000000000000 --- a/frameworks/com.ohos.permissionmanager/permissionmanager/src/ohosTest/java/com/ohos/permissionmanager/ExampleOhosTest.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2021-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. - */ - -package com.ohos.permissionmanager; - -import ohos.aafwk.ability.delegation.AbilityDelegatorRegistry; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -public class ExampleOhosTest { - @Test - public void testBundleName() { - final String actualBundleName = AbilityDelegatorRegistry.getArguments().getTestBundleName(); - assertEquals("com.ohos.permissionmanager", actualBundleName); - } -} \ No newline at end of file diff --git a/frameworks/com.ohos.permissionmanager/permissionmanager/src/ohosTest/resources/base/element/string.json b/frameworks/com.ohos.permissionmanager/permissionmanager/src/ohosTest/resources/base/element/string.json deleted file mode 100644 index 0ad161e668b74a19e5820d0d5f43d017b6d43173..0000000000000000000000000000000000000000 --- a/frameworks/com.ohos.permissionmanager/permissionmanager/src/ohosTest/resources/base/element/string.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "string": [ - { - "name": "app_name", - "value": "PermissionManager" - }, - { - "name": "mainability_description", - "value": "hap sample empty page" - } - ] -} diff --git a/frameworks/com.ohos.permissionmanager/permissionmanager/src/ohosTest/resources/base/media/icon.png b/frameworks/com.ohos.permissionmanager/permissionmanager/src/ohosTest/resources/base/media/icon.png deleted file mode 100644 index ce307a8827bd75456441ceb57d530e4c8d45d36c..0000000000000000000000000000000000000000 Binary files a/frameworks/com.ohos.permissionmanager/permissionmanager/src/ohosTest/resources/base/media/icon.png and /dev/null differ diff --git a/fuse_domain.c b/fuse_domain.c new file mode 100644 index 0000000000000000000000000000000000000000..28e62e5dafe94ea1c5feb91d001c593a72b8fb5c --- /dev/null +++ b/fuse_domain.c @@ -0,0 +1,619 @@ +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif +//#define FUSE_USE_VERSION 34 + +#include "config.h" + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct DlpFuseParam { + int dlpFileFd; + char *dlpLinkName; + int cryptType; + unsigned char *key; + unsigned int keyLen; +}; + +struct DlpFuseFile { + fuse_ino_t inode; + int dlpFileFd; + char *dlpLinkName; + int cryptType; + unsigned char *key; + unsigned int keyLen; + struct stat fileStat; + int isWorking; +}; + +#define MAX_SUPPORT_FUSE_SIZE 10; + +//in future use map, key is inode/fileName +struct DlpFuseFile *g_dlpFuseFileArray[MAX_SUPPORT_FUSE_SIZE]; + +//in future use random or index +fuse_ino_t g_inode_List[MAX_SUPPORT_FUSE_SIZE] = { + 0x123456, 0x234567,0x345678, 0x456789, 0x567890, + 0x1234567, 0x234568,0x3456789, 0x4567890, 0x5678901 +}; + +static fuse_ino_t GetValidInode() +{ + static int index = 0; + if (index >= MAX_SUPPORT_FUSE_SIZE) { + return -1; + } + fuse_ino_t ino = g_inode_List[index]; + index++; + return ino; +} + +static int RegisterDlpFuseFileByParams(struct DlpFuseParam* params, struct DlpFuseFile** fuseFilePtr) +{ + if (fuseFilePtr == NULL) { + printf("error:register param failed\n"); + return -1; + } + static int index = 0; + if (index >= MAX_SUPPORT_FUSE_SIZE) { + printf("error:register dlp fuse full\n"); + return -1; + } + + struct DlpFuseFile *fuse = (struct DlpFuseFile*) malloc(sizeof(struct DlpFuseFile)); + if (fuse == NULL) { + printf("error:register dlp fuse alloc false\n"); + return -1; + } + + fuse->inode = GetValidInode(); + if (fuse->inode == -1) { + printf("error:register dlp fuse get inode failed\n"); + free(fuse); + return -1; + } + fuse->dlpFileFd = params->dlpFileFd; + fuse->dlpLinkName = params->dlpLinkName; + fuse->cryptType = params->cryptType; + memcpy_s(fuse->key, sizeof(fuse->key), params->key, sizeof(params->key)); + fuse->keyLen = params->keyLen; + fuse->fileStat.st_ino = fuse->inode; + + g_dlpFuseFileArray[index] = fuse; + *fuseFilePtr = fuse; + return 0; +} + +static int RegisterDlpFuseFileByOpen(struct DlpFuseFile** fuseFilePtr) +{ + if (fuseFilePtr == NULL) { + printf("error:register param failed\n"); + return -1; + } + static int index = 0; + if (index >= MAX_SUPPORT_FUSE_SIZE) { + printf("error:register dlp fuse full\n"); + return -1; + } + + struct DlpFuseFile *fuse = (struct DlpFuseFile*) malloc(sizeof(struct DlpFuseFile)); + if (fuse == NULL) { + printf("error:register dlp fuse alloc false\n"); + return -1; + } + + fuse->inode = GetValidInode(); + if (fuse->inode == -1) { + printf("error:register dlp fuse get inode failed\n"); + free(fuse); + return -1; + } + fuse->fileStat.st_ino = fuse->inode; + + g_dlpFuseFileArray[index] = fuse; + *fuseFilePtr = fuse; + return 0; +} + + +static int GetDlpFuseFile(fuse_ino_t ino, struct DlpFuseFile** fuseFilePtr) +{ + if (fuseFilePtr == NULL) { + return -1; + } + for (int i = 0; i < MAX_SUPPORT_FUSE_SIZE;i++) { + if (g_dlpFuseFileArray[i] != NULL && g_dlpFuseFileArray[i].inode == ino) { + *fuseFilePtr = g_dlpFuseFileArray[i]; + return 0; + } + } + return -1; +} + +#define ROOT_INODE 0 + +char file1[16] = "xxx1"; +char *linkFileArr[] = { + file1, +}; + +struct dirbuf { + char *p; + size_t size; +}; + +static void fuse_domain_readdir(fuse_req_t req, fuse_ino_t ino, size_t size, off_t off, + struct fuse_file_info *fi) +{ + // we do not allow create sub directory + if (ino != ROOT_INODE) { + fuse_reply_err(req, ENOTDIR); + return; + } + + char *buf = (char *)malloc(size); + if (buf == NULL) { + printf("readdir alloc buf failed\n"); + fuse_reply_err(req, EINVAL); + return; + } + memset_s(buf, size, 0, size); + + char *pDir = buf; + size_t usedLen = 0; + size_t addLen = fuse_add_direntry(req, pDir, size - usedLen, + g_dlpFuseFileArray[i]->dlpLinkName, &g_dlpFuseFileArray[i]->fileStat, usedLen); + + pDir += addLen; + usedLen += addLen; + + usedLen = (size_t)(pDir - buf); + + + for(int i = 0; i < MAX_SUPPORT_FUSE_SIZE; i ++) { + if (g_dlpFuseFileArray[i] != NULL) { + usedLen = (size_t)(pDir - buf); + addLen = fuse_add_direntry(req, pDir, size - usedLen, + g_dlpFuseFileArray[i]->dlpLinkName, &g_dlpFuseFileArray[i]->fileStat, usedLen); + pDir += addLen; + usedLen += addLen; + } + } + + if (usedLen <= off) { + fuse_reply_buf(req, NULL, 0); + } else { + fuse_reply_buf(req, buf + off, usedLen - off); + } + free(buf); +#if 0 + size_t entsize; + char *buf; + char *p; + size_t rem = size; + + (void) fi; + if (ino != ROOT_INODE) { + fuse_reply_err(req, ENOTDIR); + return; + } + printf("readdir %lld size %d off %lld\n", ino, size, off); + + buf = calloc(1, size); + if (!buf) { + fuse_reply_err(req, -1); + } + p = buf; + + struct stat st; + /* st.st_ino = 1; + int lsize = fuse_add_direntry(req, NULL, 0, ".", NULL, 0); + entsize = fuse_add_direntry(req, p, rem, ".", &st, lsize); + p += entsize; + rem -= entsize; + + st.st_ino = 1; + lsize += fuse_add_direntry(req, NULL, 0, "..", NULL, 0); + entsize = fuse_add_direntry(req, p, rem, "..", &st, lsize); + p += entsize; + rem -= entsize; + */ + + st.st_ino = 2; + int lsize= fuse_add_direntry(req, NULL, 0, "xxx1", NULL, 0); + entsize = fuse_add_direntry(req, p, rem, "xxx1", &st, lsize); + p += entsize; + rem -= entsize; + + + printf("using space %d\n", size - rem); + //必須根據off來偏移,否則會一直讀到有用的 + fuse_reply_buf(req, buf + off, size - rem - off); + free(buf); +#endif +} + +static void fuse_domain_lookup(fuse_req_t req, fuse_ino_t parent, const char *name) +{ + struct fuse_entry_param fep; + if (parent != ROOT_INODE) { + fuse_reply_err(req, ENOENT); + return; + } + + memset_s(fep, sizeof(struct fuse_entry_param), 0, sizeof(struct fuse_entry_param)); + if (!strcmp(name, ".") || !strcmp(name, "..")) { + fep.ino = ROOT_INODE; + fep.attr.st_mode = S_IFDIR | 0755; + fep.attr.st_nlink = 1; + fuse_reply_entry(req, &fep); + return; + } + + for(int i = 0; i < MAX_SUPPORT_FUSE_SIZE; i ++) { + if (g_dlpFuseFileArray[i] != NULL && !strcmp(name, g_dlpFuseFileArray[i].dlpLinkName)) { + fep.ino = g_dlpFuseFileArray[i].inode; + fep.attr = g_dlpFuseFileArray[i].fileStat; + fuse_reply_entry(req, &fep); + } + } + +#if 0 + + printf("parent %lld name %s\n", parent, name); + if (parent != 1 || strcmp(name, linkFileArr[0]) != 0) + fuse_reply_err(req, ENOENT); + else { + memset(&e, 0, sizeof(e)); + e.ino = 2; + e.attr_timeout = 1.0; + e.entry_timeout = 1.0; + e.attr.st_mode = S_IFREG | 0444; + e.attr.st_nlink = 1; + e.attr.st_size = 100; + + fuse_reply_entry(req, &e); + } +#endif +} + +static void fuse_domain_getattr(fuse_req_t req, fuse_ino_t ino, + struct fuse_file_info *fi) +{ + struct stat fileStat; + memset_s(fileStat, sizeof(struct stat), 0, sizeof(struct stat)); + if (ino == ROOT_INODE) { + fileStat.st_mode = S_IFDIR | 0755; + fileStat.st_nlink = 1; + fuse_reply_attr(req, &fileStat, 1.0); + return; + } + + struct DlpFuseFile* res; + if (GetDlpFuseFile(ino, &res) == -1) { + fuse_reply_err(req, ENOENT); + } else { + fuse_reply_attr(req, &res->fileStat, 1.0); + } + +#if 0 + struct stat stbuf; + (void) fi; + (void) ino; + printf("fuse_domain_getattr ino %lld\n", ino); + memset(&stbuf, 0, sizeof(stbuf)); + //root node FUSE_ROOT_ID + if (ino == 1) { + stbuf.st_mode = S_IFDIR | 0755; + stbuf.st_nlink = 1; + } else { + stbuf.st_mode = S_IFREG | 0444; + stbuf.st_nlink = 1; + stbuf.st_size = 100; + stbuf.st_ino = ino; + stbuf.st_uid = 0; + stbuf.st_gid = 0; + stbuf.st_atime = 0; + stbuf.st_mtime = 0; + stbuf.st_ctime = 0; + } + //if (hello_stat(ino, &stbuf) == -1) + // fuse_reply_err(req, ENOENT); + //else + fuse_reply_attr(req, &stbuf, 1.0); +#endif +} + +static void fuse_domain_open(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi) +{ + if (ino == ROOT_INODE) { + fuse_reply_err(req, ENOENT); + return; + } + struct DlpFuseFile* res; + if (GetDlpFuseFile(ino, &res) == -1) { + fuse_reply_err(req, ENOENT); + } else { + if (res->dlpFileFd == -1) { + fuse_reply_err(req, ENOENT); + return; + } + fi->fh = res->dlpFileFd; + fuse_reply_open(req, fi); + } + UpdateCurrTimeStat(res->fileStat.st_atim); + +#if 0 + if (ino == 2) { + int fd = open("/data/xxx1", fi->flags & ~O_NOFOLLOW); + if (fd == -1) + return (void) fuse_reply_err(req, errno); + fi->fh = fd; + fuse_reply_open(req, fi); + } else { + fuse_reply_err(req, -1); + } +#endif +} + +static void fuse_domain_read(fuse_req_t req, fuse_ino_t ino, size_t size, + off_t offset, struct fuse_file_info *fi) +{ + int fd = fi->fh; + + printf("readdir %lld size %d off %lld\n", ino, size, offset); + + //5-22 添加判断文件是否可用,修改fuse_domain_readdir, + // 添加write,增加时间戳修改和大小,增加锁用于并发 + struct DlpFuseFile *df; + if (GetDlpFuseFile(ino, &df) != 0 && df != NULL && df->isWorking != 1) { + fuse_reply_err(req, EINVAL); + return; + } + + char *buf = calloc(1, size); + if (!buf) { + fuse_reply_err(req, EINVAL); + return; + } + + int readLen = read(fd, buf, size); + if (readLen <= 0) { + fuse_reply_err(req, EIO); + free(buf); + return; + } + printf("readdir buf %s len %lld\n", buf, readLen - offset); + fuse_reply_buf(req, buf + offset, readLen - offset); + + free(buf); +} + +void fuse_domain_write(fuse_req_t req, fuse_ino_t ino, const char *buf, + size_t size, off_t off, struct fuse_file_info *fi) +{ + int fd = fi->fh; + + printf("write %lld size %d off %lld\n", ino, size, offset); + + //5-22 添加判断文件是否可用,修改fuse_domain_readdir, + // 添加write,增加时间戳修改和大小,增加锁用于并发 + struct DlpFuseFile *df; + if (GetDlpFuseFile(ino, &df) != 0 && df != NULL && df->isWorking != 1) { + fuse_reply_err(req, EINVAL); + return; + } + + char *buf = calloc(1, size); + if (!buf) { + fuse_reply_err(req, EINVAL); + return; + } + + int readLen = read(fd, buf, size); + if (readLen <= 0) { + fuse_reply_err(req, EIO); + free(buf); + return; + } + printf("readdir buf %s len %lld\n", buf, readLen - offset); + fuse_reply_write(req, buf + offset, readLen - offset); + + free(buf); + + fuse_reply_write + +} + +static void fuse_domain_lseek(fuse_req_t req, fuse_ino_t ino, off_t off, int whence, + struct fuse_file_info *fi) +{ + off_t res; + + (void)ino; + res = lseek(fi->fh, off, whence); + if (res != -1) + fuse_reply_lseek(req, res); + else + fuse_reply_err(req, errno); +} + +static void UpdateCurrTimeStat(struct timespec *ts) +{ + timespec_get(ts); +} + +static void fuse_domain_mknod(fuse_req_t req, fuse_ino_t parent, + const char *name, mode_t mode, dev_t rdev) +{ + if (parent != ROOT_INODE) { + fuse_reply_err(req, EACCES); + return; + } + if (!S_ISREG(mode)) { + fuse_reply_err(req, EACCES); + return; + } + + struct DlpFuseFile *newFuse; + if (RegisterDlpFuseFileByOpen(&newFuse) != 0) { + fuse_reply_err(req, EACCES); + return; + } + + newFuse->dlpLinkName = name; + newFuse->fileStat.st_dev = rdev; + newFuse->fileStat.st_nlink = 1; + newFuse->fileStat.st_uid = 0; // it will set .. uid + newFuse->fileStat.st_gid = 0; // it will set .. uid + newFuse->fileStat.st_size = 0; + UpdateCurrTimeStat(&newFuse->fileStat.st_atim); + UpdateCurrTimeStat(&newFuse->fileStat.st_mtim); + UpdateCurrTimeStat(&newFuse->fileStat.st_ctim); + newFuse->fileStat.st_mode = mode; + + struct fuse_entry_param fep; + fep.ino = newFuse->inode; + fep.attr = newFuse->fileStat; + fuse_reply_entry(req, &fep); +} + +static const struct fuse_lowlevel_ops lo_oper = { + //.init = lo_init, + //.destroy = lo_destroy, + .lookup = fuse_domain_lookup, + //.mkdir = lo_mkdir, + .mknod = fuse_domain_mknod, + //.symlink = lo_symlink, + //.link = lo_link, + //.unlink = lo_unlink, + //.rmdir = lo_rmdir, + //.rename = lo_rename, + //.forget = lo_forget, + //.forget_multi = lo_forget_multi, + .getattr = fuse_domain_getattr, + //.setattr = lo_setattr, + //.readlink = lo_readlink, + //.opendir = lo_opendir, + .readdir = fuse_domain_readdir, + //.readdirplus = lo_readdirplus, + //.releasedir = lo_releasedir, + //.fsyncdir = lo_fsyncdir, + //.create = lo_create, + .open = fuse_domain_open, + //.release = lo_release, + //.flush = lo_flush, + //.fsync = lo_fsync, + .read = fuse_domain_read, + .write = fuse_domain_write, + //.write_buf = lo_write_buf, + //.statfs = lo_statfs, + //.fallocate = lo_fallocate, + //.flock = lo_flock, + //.getxattr = lo_getxattr, + //.listxattr = lo_listxattr, + //.setxattr = lo_setxattr, + //.removexattr = lo_removexattr, +#ifdef HAVE_COPY_FILE_RANGE + //.copy_file_range = lo_copy_file_range, +#endif + .lseek = fuse_domain_lseek, +}; + +int start(char *mountpoint) +{ + struct fuse_args args = FUSE_ARGS_INIT(0, NULL); + struct fuse_session *se; + //struct fuse_loop_config config; + int ret = -1; + + fuse_opt_add_arg(&args, "fuse"); + se = fuse_session_new(&args, &lo_oper, sizeof(lo_oper), NULL); + if (se == NULL) + goto err_out1; + + if (fuse_session_mount(se, mountpoint) != 0) + goto err_out3; + + /* Block until ctrl+c or fusermount -u */ + ret = fuse_session_loop(se); + /* + if (opts.singlethread) + ret = fuse_session_loop(se); + else { + config.clone_fd = opts.clone_fd; + config.max_idle_threads = opts.max_idle_threads; + ret = fuse_session_loop_mt(se, &config); + } + */ + + fuse_session_unmount(se); +err_out3: + //fuse_remove_signal_handlers(se); +//err_out2: + fuse_session_destroy(se); +err_out1: + //free(opts.mountpoint); + fuse_opt_free_args(&args); + + return ret ? 1 : 0; +} +#include + +int main(int argc, char *argv[]) +{ + (void)argc; + (void)argv; + int fd = open("/dev/fuse", O_RDWR); + if (fd == -1) { + if (errno == ENODEV || errno == ENOENT) + printf("fuse: device not found, try 'modprobe fuse' first\n"); + else + printf("fuse: failed to open /dev/fuse: %s\n", strerror(errno)); + return -1; + } + //char cmdline[512] = ""; + //printf("source %s mnt %s type %s kernel_opts %s\n", source, mnt, type, mo->kernel_opts); + + //res = mount(source, mnt, type, mo->flags, mo->kernel_opts); + //sprintf(cmdline, "mount -t fuse.hello_ll -o fd=%d,rootmode=40000,user_id=0,group_id=8673196 --source hello_ll /data/123", fd); + //system(cmdline); + //source /dev/fuse mnt /data/123 type fuse kernel_opts fd=5,rootmode=40000,user_id=0,group_id=0 + char source[64] = ""; + strcpy(source, "/dev/fuse"); + + char mnt[64] = ""; + strcpy(mnt, "/data/123"); + + char type[64] = ""; + strcpy(type, "fuse"); + + char kernel_opts[128] = ""; + // rootmode return S_ISREG(m) || S_ISDIR(m) || S_ISLNK(m) || S_ISCHR(m) || S_ISBLK(m) || S_ISFIFO(m) || S_ISSOCK(m); + // 40000 S_IFDIR 挂載點的st_mode + // user_id + sprintf(kernel_opts, "fd=%d,rootmode=40000,user_id=0,group_id=0", fd); + int res = mount(source, mnt, type, 6, kernel_opts); + printf("res: %d err %d\n", res, errno); + + char mountpoint[16]; + //strcpy(mountpoint, "/data/123"); + sprintf(mountpoint, "/dev/fd/%u", fd); + return start(mountpoint); +} + diff --git a/interfaces/innerkits/accesstoken/BUILD.gn b/interfaces/innerkits/accesstoken/BUILD.gn index 5e59fdee8b8b3061d96fd95938828979f3261a3b..17346a945f1e7e02f1c32b8a06340b53796eb804 100644 --- a/interfaces/innerkits/accesstoken/BUILD.gn +++ b/interfaces/innerkits/accesstoken/BUILD.gn @@ -11,6 +11,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import("//base/security/access_token/access_token.gni") import("//build/ohos.gni") config("accesstoken") { @@ -58,4 +59,7 @@ ohos_shared_library("libaccesstoken_sdk") { "-DHILOG_ENABLE", "-DDEBUG_API_PERFORMANCE", ] + if (token_sync_enable == true) { + cflags_cc += [ "-DTOKEN_SYNC_ENABLE" ] + } } diff --git a/interfaces/innerkits/accesstoken/include/accesstoken_kit.h b/interfaces/innerkits/accesstoken/include/accesstoken_kit.h index 9f6243cd28d79589546e508c249dfad6bd1dd7f4..2904763cc8b36872d718f438e1dfa658e3e2c9ee 100644 --- a/interfaces/innerkits/accesstoken/include/accesstoken_kit.h +++ b/interfaces/innerkits/accesstoken/include/accesstoken_kit.h @@ -54,6 +54,8 @@ public: static int GrantPermission(AccessTokenID tokenID, const std::string& permissionName, int flag); static int RevokePermission(AccessTokenID tokenID, const std::string& permissionName, int flag); static int ClearUserGrantedPermissionState(AccessTokenID tokenID); + +#ifdef TOKEN_SYNC_ENABLE static int GetHapTokenInfoFromRemote(AccessTokenID tokenID, HapTokenInfoForSync& hapSync); static int GetAllNativeTokenInfo(std::vector& nativeTokenInfosRes); static int SetRemoteHapTokenInfo(const std::string& deviceID, const HapTokenInfoForSync& hapSync); @@ -62,6 +64,7 @@ public: static int DeleteRemoteToken(const std::string& deviceID, AccessTokenID tokenID); static AccessTokenID GetRemoteNativeTokenID(const std::string& deviceID, AccessTokenID tokenID); static int DeleteRemoteDeviceTokens(const std::string& deviceID); +#endif static void DumpTokenInfo(std::string& dumpInfo); }; } // namespace AccessToken diff --git a/interfaces/innerkits/accesstoken/src/accesstoken_kit.cpp b/interfaces/innerkits/accesstoken/src/accesstoken_kit.cpp index f8ba04b10bc354f484edc93b5b47b301d57361e0..182783c89f5cce2059a6dc5e5b1088de098eb0de 100644 --- a/interfaces/innerkits/accesstoken/src/accesstoken_kit.cpp +++ b/interfaces/innerkits/accesstoken/src/accesstoken_kit.cpp @@ -295,6 +295,7 @@ int AccessTokenKit::ClearUserGrantedPermissionState(AccessTokenID tokenID) return AccessTokenManagerClient::GetInstance().ClearUserGrantedPermissionState(tokenID); } +#ifdef TOKEN_SYNC_ENABLE int AccessTokenKit::GetHapTokenInfoFromRemote(AccessTokenID tokenID, HapTokenInfoForSync& hapSync) { ACCESSTOKEN_LOG_INFO(LABEL, "%{public}s called", __func__); @@ -349,6 +350,7 @@ AccessTokenID AccessTokenKit::GetRemoteNativeTokenID(const std::string& deviceID __func__, deviceID.c_str(), tokenID); return AccessTokenManagerClient::GetInstance().GetRemoteNativeTokenID(deviceID, tokenID); } +#endif void AccessTokenKit::DumpTokenInfo(std::string& dumpInfo) { diff --git a/interfaces/innerkits/accesstoken/src/accesstoken_manager_client.cpp b/interfaces/innerkits/accesstoken/src/accesstoken_manager_client.cpp index 9d419a67ae56e63787fd96c91b6d865eb0d2bf96..a10c7114ba7e0e9b5b7eee454c0fc7c30721b3a4 100644 --- a/interfaces/innerkits/accesstoken/src/accesstoken_manager_client.cpp +++ b/interfaces/innerkits/accesstoken/src/accesstoken_manager_client.cpp @@ -275,6 +275,7 @@ int AccessTokenManagerClient::GetNativeTokenInfo(AccessTokenID tokenID, NativeTo return res; } +#ifdef TOKEN_SYNC_ENABLE int AccessTokenManagerClient::GetHapTokenInfoFromRemote(AccessTokenID tokenID, HapTokenInfoForSync& hapSync) { ACCESSTOKEN_LOG_DEBUG(LABEL, "%{public}s: called!", __func__); @@ -383,6 +384,7 @@ int AccessTokenManagerClient::DeleteRemoteDeviceTokens(const std::string& device int res = proxy->DeleteRemoteDeviceTokens(deviceID); return res; } +#endif void AccessTokenManagerClient::DumpTokenInfo(std::string& dumpInfo) { diff --git a/interfaces/innerkits/accesstoken/src/accesstoken_manager_client.h b/interfaces/innerkits/accesstoken/src/accesstoken_manager_client.h index 74df766ed959bff3d915bbaeb9b84371cf345685..37b3fc61c472e7d4d1b342d8d1947333e7780e38 100644 --- a/interfaces/innerkits/accesstoken/src/accesstoken_manager_client.h +++ b/interfaces/innerkits/accesstoken/src/accesstoken_manager_client.h @@ -59,6 +59,8 @@ public: int UpdateHapToken(AccessTokenID tokenID, const std::string& appIDDesc, const HapPolicyParams& policy); int GetHapTokenInfo(AccessTokenID tokenID, HapTokenInfo& hapTokenInfoRes); int GetNativeTokenInfo(AccessTokenID tokenID, NativeTokenInfo& nativeTokenInfoRes); + +#ifdef TOKEN_SYNC_ENABLE int GetHapTokenInfoFromRemote(AccessTokenID tokenID, HapTokenInfoForSync& hapSync); int GetAllNativeTokenInfo(std::vector& nativeTokenInfosRes); int SetRemoteHapTokenInfo(const std::string& deviceID, const HapTokenInfoForSync& hapSync); @@ -67,6 +69,8 @@ public: int DeleteRemoteToken(const std::string& deviceID, AccessTokenID tokenID); AccessTokenID GetRemoteNativeTokenID(const std::string& deviceID, AccessTokenID tokenID); int DeleteRemoteDeviceTokens(const std::string& deviceID); +#endif + void DumpTokenInfo(std::string& dumpInfo); void OnRemoteDiedHandle(); diff --git a/interfaces/innerkits/accesstoken/src/accesstoken_manager_proxy.cpp b/interfaces/innerkits/accesstoken/src/accesstoken_manager_proxy.cpp index 218f1da474a91586075d3b401e2beff8b63b15bb..c6e1a5a0031def3059da18e4833f7923de59dc44 100644 --- a/interfaces/innerkits/accesstoken/src/accesstoken_manager_proxy.cpp +++ b/interfaces/innerkits/accesstoken/src/accesstoken_manager_proxy.cpp @@ -640,6 +640,7 @@ int AccessTokenManagerProxy::UpdateHapToken(AccessTokenID tokenID, return result; } +#ifdef TOKEN_SYNC_ENABLE int AccessTokenManagerProxy::GetHapTokenInfoFromRemote(AccessTokenID tokenID, HapTokenInfoForSyncParcel& hapSyncParcel) { @@ -863,6 +864,7 @@ int AccessTokenManagerProxy::DeleteRemoteDeviceTokens(const std::string& deviceI ACCESSTOKEN_LOG_DEBUG(LABEL, "get result from server data = %{public}d", result); return result; } +#endif void AccessTokenManagerProxy::DumpTokenInfo(std::string& dumpInfo) { diff --git a/interfaces/innerkits/accesstoken/src/accesstoken_manager_proxy.h b/interfaces/innerkits/accesstoken/src/accesstoken_manager_proxy.h index 5463e216bfd43999769b4aaea6aa1ba9858f0992..90c65cee8b4c2741ffb549301d86d4eee0b6d363 100644 --- a/interfaces/innerkits/accesstoken/src/accesstoken_manager_proxy.h +++ b/interfaces/innerkits/accesstoken/src/accesstoken_manager_proxy.h @@ -59,6 +59,7 @@ public: int GetHapTokenInfo(AccessTokenID tokenID, HapTokenInfoParcel& hapTokenInfoRes) override; int GetNativeTokenInfo(AccessTokenID tokenID, NativeTokenInfoParcel& nativeTokenInfoRes) override; +#ifdef TOKEN_SYNC_ENABLE int GetHapTokenInfoFromRemote(AccessTokenID tokenID, HapTokenInfoForSyncParcel& hapSyncParcel) override; int GetAllNativeTokenInfo(std::vector& nativeTokenInfoRes) override; int SetRemoteHapTokenInfo(const std::string& deviceID, HapTokenInfoForSyncParcel& hapSyncParcel) override; @@ -67,6 +68,7 @@ public: int DeleteRemoteToken(const std::string& deviceID, AccessTokenID tokenID) override; AccessTokenID GetRemoteNativeTokenID(const std::string& deviceID, AccessTokenID tokenID) override; int DeleteRemoteDeviceTokens(const std::string& deviceID) override; +#endif void DumpTokenInfo(std::string& dumpInfo) override; private: diff --git a/interfaces/innerkits/accesstoken/test/BUILD.gn b/interfaces/innerkits/accesstoken/test/BUILD.gn index a4782cc9094234cfcc93c78bb0ac79f4258c7169..c9a97a081289fe52cbff9a79bf056646fb123587 100644 --- a/interfaces/innerkits/accesstoken/test/BUILD.gn +++ b/interfaces/innerkits/accesstoken/test/BUILD.gn @@ -11,6 +11,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import("//base/security/access_token/access_token.gni") import("//build/test.gni") ohos_unittest("libaccesstoken_sdk_test") { @@ -37,6 +38,9 @@ ohos_unittest("libaccesstoken_sdk_test") { ] external_deps = [ "hiviewdfx_hilog_native:libhilog" ] + if (token_sync_enable == true) { + cflags_cc += [ "-DTOKEN_SYNC_ENABLE" ] + } } group("unittest") { diff --git a/interfaces/innerkits/accesstoken/test/unittest/src/accesstoken_kit_test.cpp b/interfaces/innerkits/accesstoken/test/unittest/src/accesstoken_kit_test.cpp index 34e30ce682e4e65ffd10ffd376b6a544c74a519a..56a4ada183414994e980c6fb6d840e1fa6c09999 100644 --- a/interfaces/innerkits/accesstoken/test/unittest/src/accesstoken_kit_test.cpp +++ b/interfaces/innerkits/accesstoken/test/unittest/src/accesstoken_kit_test.cpp @@ -185,6 +185,8 @@ void AccessTokenKitTest::SetUp() g_infoManagerTestInfoParms.instIndex); AccessTokenKit::DeleteToken(tokenID); (void)remove("/data/token.json"); + + ACCESSTOKEN_LOG_INFO(LABEL, "SetUp ok."); } void AccessTokenKitTest::TearDown() @@ -2080,6 +2082,7 @@ HWTEST_F(AccessTokenKitTest, GetTokenTypeFlag003, TestSize.Level1) ASSERT_EQ(RET_SUCCESS, res); } +#ifdef TOKEN_SYNC_ENABLE /** * @tc.name: SetRemoteHapTokenInfo001 * @tc.desc: set remote hap token info success @@ -3098,4 +3101,5 @@ HWTEST_F(AccessTokenKitTest, SetRemoteNativeTokenInfo001, TestSize.Level1) ASSERT_EQ(resultInfo.dcap[1], "DMSDCAP"); ASSERT_EQ(resultInfo.tokenID, mapID); ASSERT_EQ(resultInfo.tokenAttr, native1.tokenAttr); -} \ No newline at end of file +} +#endif diff --git a/services/accesstokenmanager/BUILD.gn b/services/accesstokenmanager/BUILD.gn index 9862a58ab5e450c64a83ea318a09c3b15c35e68d..f2663afa5d312186516f764f9dd5ed139fec09e6 100644 --- a/services/accesstokenmanager/BUILD.gn +++ b/services/accesstokenmanager/BUILD.gn @@ -11,6 +11,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import("//base/security/access_token/access_token.gni") import("//build/ohos.gni") ohos_prebuilt_etc("access_token.rc") { @@ -33,7 +34,6 @@ ohos_shared_library("accesstoken_manager_service") { "//base/security/access_token/frameworks/common/include", "//base/security/access_token/frameworks/accesstoken/include", "//base/security/access_token/interfaces/innerkits/accesstoken/include", - "//base/security/access_token/interfaces/innerkits/tokensync/include", "//third_party/json/include", ] @@ -53,26 +53,36 @@ ohos_shared_library("accesstoken_manager_service") { "main/cpp/src/service/accesstoken_manager_stub.cpp", "main/cpp/src/token/accesstoken_id_manager.cpp", "main/cpp/src/token/accesstoken_info_manager.cpp", - "main/cpp/src/token/accesstoken_remote_token_manager.cpp", "main/cpp/src/token/hap_token_info_inner.cpp", "main/cpp/src/token/native_token_info_inner.cpp", "main/cpp/src/token/native_token_receptor.cpp", - "main/cpp/src/token/token_modify_notifier.cpp", ] cflags_cc = [ "-DHILOG_ENABLE" ] deps = [ - #"//base/security/accesstoken/frameworks/accesstooken/permissioncommunicationadapter:permission_standard_communication_adapter_cxx", - #"//base/security/accesstoken/frameworks/accesstooken/common:permission_standard_infrastructure_cxx", "//base/security/access_token/frameworks/accesstoken:accesstoken_communication_adapter_cxx", "//base/security/access_token/frameworks/common:accesstoken_common_cxx", - "//base/security/access_token/interfaces/innerkits/tokensync:libtokensync_sdk", "//base/security/access_token/services/accesstokenmanager:access_token.rc", "//third_party/sqlite:sqlite", "//utils/native/base:utils", ] + if (token_sync_enable == true) { + cflags_cc += [ "-DTOKEN_SYNC_ENABLE" ] + + sources += [ + "main/cpp/src/token/accesstoken_remote_token_manager.cpp", + "main/cpp/src/token/token_modify_notifier.cpp", + ] + + include_dirs += [ + "//base/security/access_token/interfaces/innerkits/tokensync/include", + ] + + deps += [ "//base/security/access_token/interfaces/innerkits/tokensync:libtokensync_sdk" ] + } + external_deps = [ "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", diff --git a/services/accesstokenmanager/main/cpp/include/service/accesstoken_manager_service.h b/services/accesstokenmanager/main/cpp/include/service/accesstoken_manager_service.h index 589b641e4c4c041fbff4f6b1e5af55a2b8dd052d..e8ac7f2f8fe02e380581ccf2eb7f7c94708e46ee 100644 --- a/services/accesstokenmanager/main/cpp/include/service/accesstoken_manager_service.h +++ b/services/accesstokenmanager/main/cpp/include/service/accesstoken_manager_service.h @@ -59,6 +59,8 @@ public: int GetHapTokenInfo(AccessTokenID tokenID, HapTokenInfoParcel& InfoParcel) override; int UpdateHapToken(AccessTokenID tokenID, const std::string& appIDDesc, const HapPolicyParcel& policyParcel) override; + +#ifdef TOKEN_SYNC_ENABLE int GetHapTokenInfoFromRemote(AccessTokenID tokenID, HapTokenInfoForSyncParcel& hapSyncParcel) override; int GetAllNativeTokenInfo(std::vector& nativeTokenInfosRes) override; int SetRemoteHapTokenInfo(const std::string& deviceID, HapTokenInfoForSyncParcel& hapSyncParcel) override; @@ -67,6 +69,7 @@ public: int DeleteRemoteToken(const std::string& deviceID, AccessTokenID tokenID) override; AccessTokenID GetRemoteNativeTokenID(const std::string& deviceID, AccessTokenID tokenID) override; int DeleteRemoteDeviceTokens(const std::string& deviceID) override; +#endif void DumpTokenInfo(std::string& dumpInfo) override; private: diff --git a/services/accesstokenmanager/main/cpp/include/service/accesstoken_manager_stub.h b/services/accesstokenmanager/main/cpp/include/service/accesstoken_manager_stub.h index e382958009b8b38f089a78c0e9c7e33e55c0d060..7b34cc3a7f9cd9a8bd89c94c796948ea54539391 100644 --- a/services/accesstokenmanager/main/cpp/include/service/accesstoken_manager_stub.h +++ b/services/accesstokenmanager/main/cpp/include/service/accesstoken_manager_stub.h @@ -54,6 +54,7 @@ private: void CheckNativeDCapInner(MessageParcel& data, MessageParcel& reply); void GetTokenTypeInner(MessageParcel& data, MessageParcel& reply); +#ifdef TOKEN_SYNC_ENABLE void GetHapTokenInfoFromRemoteInner(MessageParcel& data, MessageParcel& reply); void GetAllNativeTokenInfoInner(MessageParcel& data, MessageParcel& reply); void SetRemoteHapTokenInfoInner(MessageParcel& data, MessageParcel& reply); @@ -62,6 +63,8 @@ private: void DeleteRemoteDeviceTokensInner(MessageParcel& data, MessageParcel& reply); void GetRemoteNativeTokenIDInner(MessageParcel& data, MessageParcel& reply); void GetRemoteHapTokenIDInner(MessageParcel& data, MessageParcel& reply); +#endif + void DumpTokenInfoInner(MessageParcel& data, MessageParcel& reply); bool IsAuthorizedCalling() const; diff --git a/services/accesstokenmanager/main/cpp/include/token/accesstoken_info_manager.h b/services/accesstokenmanager/main/cpp/include/token/accesstoken_info_manager.h index db85e4eda245fa0a676d7c5a365a27889924c620..aa8fa7d72a113564d0ce71cbe98a2b730c592cdc 100644 --- a/services/accesstokenmanager/main/cpp/include/token/accesstoken_info_manager.h +++ b/services/accesstokenmanager/main/cpp/include/token/accesstoken_info_manager.h @@ -53,6 +53,7 @@ public: void DumpTokenInfo(std::string& dumpInfo); void RefreshTokenInfoIfNeeded(); +#ifdef TOKEN_SYNC_ENABLE /* tokensync needed */ int GetHapTokenSync(AccessTokenID tokenID, HapTokenInfoForSync& hapSync); int GetHapTokenInfoFromRemote(AccessTokenID tokenID, @@ -64,6 +65,7 @@ public: int DeleteRemoteToken(const std::string& deviceID, AccessTokenID tokenID); AccessTokenID GetRemoteNativeTokenID(const std::string& deviceID, AccessTokenID tokenID); int DeleteRemoteDeviceTokens(const std::string& deviceID); +#endif private: AccessTokenInfoManager(); diff --git a/services/accesstokenmanager/main/cpp/src/permission/permission_manager.cpp b/services/accesstokenmanager/main/cpp/src/permission/permission_manager.cpp index 4f352d8b3c1307a4f08cc8ce29273170894af321..eaf67ae7af4bc46d421a96db3b4d94ed62f2af32 100644 --- a/services/accesstokenmanager/main/cpp/src/permission/permission_manager.cpp +++ b/services/accesstokenmanager/main/cpp/src/permission/permission_manager.cpp @@ -19,7 +19,9 @@ #include "accesstoken_log.h" #include "permission_definition_cache.h" #include "permission_validator.h" +#ifdef TOKEN_SYNC_ENABLE #include "token_modify_notifier.h" +#endif namespace OHOS { namespace Security { @@ -237,7 +239,9 @@ void PermissionManager::UpdateTokenPermissionState( } permPolicySet->UpdatePermissionStatus(permissionName, isGranted, flag); +#ifdef TOKEN_SYNC_ENABLE TokenModifyNotifier::GetInstance().NotifyTokenModify(tokenID); +#endif } void PermissionManager::GrantPermission(AccessTokenID tokenID, const std::string& permissionName, int flag) diff --git a/services/accesstokenmanager/main/cpp/src/service/accesstoken_manager_service.cpp b/services/accesstokenmanager/main/cpp/src/service/accesstoken_manager_service.cpp index 997da72d38acd1d0f03043cb875ae405b4ef72c0..6eb08a9bdf07e2a39f2ad5dfe7c7f3158c8c2691 100644 --- a/services/accesstokenmanager/main/cpp/src/service/accesstoken_manager_service.cpp +++ b/services/accesstokenmanager/main/cpp/src/service/accesstoken_manager_service.cpp @@ -239,6 +239,7 @@ int AccessTokenManagerService::GetNativeTokenInfo(AccessTokenID tokenID, NativeT return AccessTokenInfoManager::GetInstance().GetNativeTokenInfo(tokenID, InfoParcel.nativeTokenInfoParams); } +#ifdef TOKEN_SYNC_ENABLE int AccessTokenManagerService::GetHapTokenInfoFromRemote(AccessTokenID tokenID, HapTokenInfoForSyncParcel& hapSyncParcel) { @@ -309,6 +310,7 @@ int AccessTokenManagerService::DeleteRemoteDeviceTokens(const std::string& devic return AccessTokenInfoManager::GetInstance().DeleteRemoteDeviceTokens(deviceID); } +#endif void AccessTokenManagerService::DumpTokenInfo(std::string& dumpInfo) { diff --git a/services/accesstokenmanager/main/cpp/src/service/accesstoken_manager_stub.cpp b/services/accesstokenmanager/main/cpp/src/service/accesstoken_manager_stub.cpp index bf92f5464825380ea37c882f705f4fec5fc82d11..c92ab76485744564f29ecaa45d6d85eb61e1460f 100644 --- a/services/accesstokenmanager/main/cpp/src/service/accesstoken_manager_stub.cpp +++ b/services/accesstokenmanager/main/cpp/src/service/accesstoken_manager_stub.cpp @@ -286,6 +286,7 @@ void AccessTokenManagerStub::GetNativeTokenInfoInner(MessageParcel& data, Messag reply.WriteInt32(result); } +#ifdef TOKEN_SYNC_ENABLE void AccessTokenManagerStub::GetHapTokenInfoFromRemoteInner(MessageParcel& data, MessageParcel& reply) { if (!IsAuthorizedCalling()) { @@ -391,6 +392,7 @@ void AccessTokenManagerStub::DeleteRemoteDeviceTokensInner(MessageParcel& data, int result = this->DeleteRemoteDeviceTokens(deviceID); reply.WriteInt32(result); } +#endif void AccessTokenManagerStub::DumpTokenInfoInner(MessageParcel& data, MessageParcel& reply) { @@ -448,6 +450,8 @@ AccessTokenManagerStub::AccessTokenManagerStub() &AccessTokenManagerStub::GetHapTokenInfoInner; requestFuncMap_[static_cast(IAccessTokenManager::InterfaceCode::UPDATE_HAP_TOKEN)] = &AccessTokenManagerStub::UpdateHapTokenInner; + +#ifdef TOKEN_SYNC_ENABLE requestFuncMap_[static_cast(IAccessTokenManager::InterfaceCode::GET_HAP_TOKEN_FROM_REMOTE)] = &AccessTokenManagerStub::GetHapTokenInfoFromRemoteInner; requestFuncMap_[static_cast(IAccessTokenManager::InterfaceCode::GET_ALL_NATIVE_TOKEN_FROM_REMOTE)] = @@ -462,6 +466,8 @@ AccessTokenManagerStub::AccessTokenManagerStub() &AccessTokenManagerStub::DeleteRemoteDeviceTokensInner; requestFuncMap_[static_cast(IAccessTokenManager::InterfaceCode::GET_NATIVE_REMOTE_TOKEN)] = &AccessTokenManagerStub::GetRemoteNativeTokenIDInner; +#endif + requestFuncMap_[static_cast(IAccessTokenManager::InterfaceCode::DUMP_TOKENINFO)] = &AccessTokenManagerStub::DumpTokenInfoInner; } diff --git a/services/accesstokenmanager/main/cpp/src/token/accesstoken_info_manager.cpp b/services/accesstokenmanager/main/cpp/src/token/accesstoken_info_manager.cpp index 059403f0cebf3228e767c29b9baf108c07904fcf..5c0235ccdbc83deea32c7519e416ce845bf61d4e 100644 --- a/services/accesstokenmanager/main/cpp/src/token/accesstoken_info_manager.cpp +++ b/services/accesstokenmanager/main/cpp/src/token/accesstoken_info_manager.cpp @@ -25,8 +25,11 @@ #include "generic_values.h" #include "hap_token_info_inner.h" #include "permission_manager.h" + +#ifdef TOKEN_SYNC_ENABLE #include "token_modify_notifier.h" #include "token_sync_kit.h" +#endif namespace OHOS { namespace Security { @@ -308,7 +311,9 @@ int AccessTokenInfoManager::RemoveHapTokenInfo(AccessTokenID id) AccessTokenIDManager::GetInstance().ReleaseTokenId(id); ACCESSTOKEN_LOG_INFO(LABEL, "remove hap token 0x%{public}x ok!", id); RefreshTokenInfoIfNeeded(); +#ifdef TOKEN_SYNC_ENABLE TokenModifyNotifier::GetInstance().NotifyTokenDelete(id); +#endif return RET_SUCCESS; } @@ -511,11 +516,14 @@ int AccessTokenInfoManager::UpdateHapToken(AccessTokenID tokenID, } PermissionManager::GetInstance().AddDefPermissions(infoPtr, true); +#ifdef TOKEN_SYNC_ENABLE TokenModifyNotifier::GetInstance().NotifyTokenModify(tokenID); +#endif RefreshTokenInfoIfNeeded(); return RET_SUCCESS; } +#ifdef TOKEN_SYNC_ENABLE int AccessTokenInfoManager::GetHapTokenSync(AccessTokenID tokenID, HapTokenInfoForSync& hapSync) { std::shared_ptr infoPtr = GetHapTokenInfoInner(tokenID); @@ -791,6 +799,14 @@ AccessTokenID AccessTokenInfoManager::AllocLocalTokenID(const std::string& remot return AccessTokenRemoteTokenManager::GetInstance().GetDeviceMappingTokenID(remoteDeviceID, remoteTokenID); } +#else +AccessTokenID AccessTokenInfoManager::AllocLocalTokenID(const std::string& remoteDeviceID, + AccessTokenID remoteTokenID) +{ + ACCESSTOKEN_LOG_ERROR(LABEL, "tokensync is disable, check dependent components"); + return 0; +} +#endif AccessTokenInfoManager& AccessTokenInfoManager::GetInstance() { diff --git a/services/accesstokenmanager/main/cpp/src/token/native_token_receptor.cpp b/services/accesstokenmanager/main/cpp/src/token/native_token_receptor.cpp index de1ff1aaaa045b7585c178412091282f2cd609c1..3810056789d2d5cad9cb693d19fb698b53450abe 100644 --- a/services/accesstokenmanager/main/cpp/src/token/native_token_receptor.cpp +++ b/services/accesstokenmanager/main/cpp/src/token/native_token_receptor.cpp @@ -67,7 +67,7 @@ void from_json(const nlohmann::json& j, std::shared_ptr& p if (j.find(JSON_TOKEN_ID) != j.end()) { native.tokenID = j.at(JSON_TOKEN_ID).get(); - if (native.tokenID == 0 && + if (native.tokenID == 0 || AccessTokenIDManager::GetTokenIdTypeEnum(native.tokenID) != TOKEN_NATIVE) { return; } diff --git a/services/tokensyncmanager/BUILD.gn b/services/tokensyncmanager/BUILD.gn index 65e7b718ae1f82cb8d2ed40e0593634f8cd237f5..e35b82ca484ccdf9266ae7dc3795d341a691f4fa 100644 --- a/services/tokensyncmanager/BUILD.gn +++ b/services/tokensyncmanager/BUILD.gn @@ -11,6 +11,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import("//base/security/access_token/access_token.gni") import("//build/ohos.gni") ohos_prebuilt_etc("token_sync.rc") { @@ -75,6 +76,10 @@ ohos_shared_library("token_sync_manager_service") { "//utils/native/base:utils", ] + if (token_sync_enable == true) { + cflags_cc += [ "-DTOKEN_SYNC_ENABLE" ] + } + external_deps = [ "device_manager_base:devicemanagersdk", "dsoftbus_standard:softbus_client", diff --git a/services/tokensyncmanager/test/unittest/token_sync_service/BUILD.gn b/services/tokensyncmanager/test/unittest/token_sync_service/BUILD.gn index 73cb6e221d517d9e80cb787c43f2bc88041076f0..1a7ca56bf981ac3809298bb00c9d6549219bb482 100644 --- a/services/tokensyncmanager/test/unittest/token_sync_service/BUILD.gn +++ b/services/tokensyncmanager/test/unittest/token_sync_service/BUILD.gn @@ -11,6 +11,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import("//base/security/access_token/access_token.gni") import("//build/test.gni") ohos_unittest("libtoken_sync_service_sdk_test") { @@ -86,6 +87,10 @@ ohos_unittest("libtoken_sync_service_sdk_test") { cflags_cc = [ "-DHILOG_ENABLE" ] + if (token_sync_enable == true) { + cflags_cc += [ "-DTOKEN_SYNC_ENABLE" ] + } + external_deps = [ "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core",