diff --git a/services/ans/BUILD.gn b/services/ans/BUILD.gn index 7843be17ff5049f6e7f497f3ca8ad725688e8286..ec8fdfebfe57dd69d087d6934f7c5a6caf19a90b 100644 --- a/services/ans/BUILD.gn +++ b/services/ans/BUILD.gn @@ -53,7 +53,6 @@ ohos_shared_library("libans") { deps = [ "${core_path}:ans_core", - "${services_path}/dialog/dialog_ui/js:dialog_js_files_etc", "//foundation/arkui/ace_engine/interfaces/inner_api/ui_service_manager:ui_service_mgr", ] diff --git a/services/dialog/dialog_ui/js/common/.gitkeep b/services/dialog/dialog_ui/js/common/.gitkeep deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/services/dialog/dialog_ui/js/i18n/en-US.json b/services/dialog/dialog_ui/js/i18n/en-US.json deleted file mode 100644 index 43b8107010b1589e2760821a9cd8c63dcee9a86c..0000000000000000000000000000000000000000 --- a/services/dialog/dialog_ui/js/i18n/en-US.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "message":{ - "requestNotification": "Allowed to send notification?", - "allowButton": "Allow", - "cancelButton": "Cancel" - } -} diff --git a/services/dialog/dialog_ui/js/i18n/zh-CN.json b/services/dialog/dialog_ui/js/i18n/zh-CN.json deleted file mode 100644 index 0f049cb9973783f5b0a67c09db8047e3b0b54fde..0000000000000000000000000000000000000000 --- a/services/dialog/dialog_ui/js/i18n/zh-CN.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "message": { - "requestNotification": "是否允许发送通知?", - "allowButton": "允许", - "cancelButton": "取消" - } -} diff --git a/services/dialog/dialog_ui/js/pages/index/index.hml b/services/dialog/dialog_ui/js/pages/index/index.hml deleted file mode 100644 index 1b2897d72ecaacdfde9564703723c1ccb6688aa8..0000000000000000000000000000000000000000 --- a/services/dialog/dialog_ui/js/pages/index/index.hml +++ /dev/null @@ -1,35 +0,0 @@ - - -
-
- - {{ requestNotification }} - -
-
-
- -
-
-
- -
-
-
diff --git a/services/dialog/dialog_ui/js/pages/index/index.js b/services/dialog/dialog_ui/js/pages/index/index.js deleted file mode 100644 index 9c9463b90b63bc234247f02fa3a5982b471defb7..0000000000000000000000000000000000000000 --- a/services/dialog/dialog_ui/js/pages/index/index.js +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import router from '@ohos.router' - -export default { - data: { - message: router.getParams().message, - requestNotification: router.getParams().requestNotification, - allowButton: router.getParams().allowButton, - cancelButton: router.getParams().cancelButton, - uid: router.getParams().uid, - }, - onInit() { - console.info('getParams: ' + JSON.stringify(router.getParams())); - this.requestNotification = this.$t('message.requestNotification'); - this.allowButton = this.$t('message.allowButton'); - this.cancelButton = this.$t('message.cancelButton'); - }, - onAllow() { - console.info('clicked allow'); - callNativeHandler("EVENT_ALLOW", router.getParams().uid.toString()); - }, - onCancel() { - console.info('clicked cancel'); - callNativeHandler("EVENT_CANCEL", router.getParams().uid.toString()); - }, -} diff --git a/services/dialog_ui/enable_notification_dialog/AppScope/app.json b/services/dialog_ui/enable_notification_dialog/AppScope/app.json new file mode 100644 index 0000000000000000000000000000000000000000..73dd58c3a19beaa15250e4f60b2907a56183a9b7 --- /dev/null +++ b/services/dialog_ui/enable_notification_dialog/AppScope/app.json @@ -0,0 +1,13 @@ +{ + "app": { + "bundleName": "com.ohos.notificationdialog", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name", + "distributedNotificationEnabled": true, + "minAPIVersion": 9, + "targetAPIVersion": 9 + } +} diff --git a/services/dialog_ui/enable_notification_dialog/AppScope/resources/base/element/string.json b/services/dialog_ui/enable_notification_dialog/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..c80cfe8484a687d703bc39519cedc5cb41638e71 --- /dev/null +++ b/services/dialog_ui/enable_notification_dialog/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "EnableNotificationDialog" + } + ] +} diff --git a/services/dialog_ui/enable_notification_dialog/AppScope/resources/base/media/app_icon.png b/services/dialog_ui/enable_notification_dialog/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/services/dialog_ui/enable_notification_dialog/AppScope/resources/base/media/app_icon.png differ diff --git a/services/dialog/dialog_ui/js/BUILD.gn b/services/dialog_ui/enable_notification_dialog/BUILD.gn similarity index 37% rename from services/dialog/dialog_ui/js/BUILD.gn rename to services/dialog_ui/enable_notification_dialog/BUILD.gn index a083daf062258c24465d167cddb7453152bd9129..90f6f2a56f73b952801554267ec9a63b14862057 100644 --- a/services/dialog/dialog_ui/js/BUILD.gn +++ b/services/dialog_ui/enable_notification_dialog/BUILD.gn @@ -11,17 +11,40 @@ # See the License for the specific language governing permissions and # limitations under the License. -import("//base/notification/distributed_notification_service/notification.gni") -import("//foundation/arkui/ace_engine/build/ace_gen_sa_dialog_js.gni") - -gen_sa_dialog_js("dialog_js_files_etc") { - project_path = "${services_path}/dialog/dialog_ui/js/" - i18n_files = [ - "i18n/en-US.json", - "i18n/zh-CN.json", +import("//build/ohos.gni") + +ohos_hap("enable_notification_dialog_hap") { + hap_profile = "entry/src/main/module.json" + + deps = [ + ":enable_notification_dialog_js_assets", + ":enable_notification_dialog_resources", ] - common_files = [] - dialog_name = "notification_dialog" - subsystem_name = "${subsystem_name}" - part_name = "${component_name}" + + certificate_profile = "signature/openharmony_sx.p7b" + hap_name = "enable_notification_dialog" + subsystem_name = "application" + part_name = "prebuilt_hap" + module_install_dir = "app/com.ohos.notificationdialog" +} + +ohos_js_assets("enable_notification_dialog_js_assets") { + hap_profile = "entry/src/main/module.json" + ets2abc = true + source_dir = "entry/src/main/ets" +} + +ohos_app_scope("enable_notification_dialog_app_profile") { + app_profile = "AppScope/app.json" + sources = [ "AppScope/resources" ] +} + +ohos_resources("enable_notification_dialog_resources") { + sources = [ "entry/src/main/resources" ] + deps = [ ":enable_notification_dialog_app_profile" ] + hap_profile = "entry/src/main/module.json" +} + +group("dialog_hap") { + deps = [ ":enable_notification_dialog_hap" ] } diff --git a/services/dialog/dialog_ui/js/pages/index/index.css b/services/dialog_ui/enable_notification_dialog/entry/src/main/ets/Application/AbilityStage.ts similarity index 41% rename from services/dialog/dialog_ui/js/pages/index/index.css rename to services/dialog_ui/enable_notification_dialog/entry/src/main/ets/Application/AbilityStage.ts index 1121ab576e48fa199d84c520b26df578dddb6ca1..1821f6288597deb3c74186db9ab9a7e3f4f21806 100644 --- a/services/dialog/dialog_ui/js/pages/index/index.css +++ b/services/dialog_ui/enable_notification_dialog/entry/src/main/ets/Application/AbilityStage.ts @@ -13,50 +13,10 @@ * limitations under the License. */ -.container { - display: flex; - flex-direction: column; - justify-content: center; - align-items: center; - width: 397vp; - height: 117vp; - border-radius: 24vp; - background-color: rgba(255, 255, 255, 1); -} +import AbilityStage from "@ohos.application.AbilityStage" -.btn-group { - display: flex; - flex-direction: row; - justify-content: center; -} - -.btn { - width: 116vp; - height: 40vp; - font-size: 16fp; - background-color: rgba(255, 255, 255, 1); - text-color: rgba(13, 129, 242, 1); - text-align: center; - line-height: 22vp; - font-weight: 500; - margin: 9vp 8vp; -} - -text { - align-items: center; - margin-top: 24vp; - width: 350vp; - height: 21vp; - opacity: 1; - font-size: 16fp; - text-color: rgba(24, 36, 49, 1); - text-align: center; - font-weight: 400; -} - -.spli { - width: 0.5vp; - height: 24vp; - background-color: rgba(0, 0, 0, 0); - margin-top: 24vp; +export default class DialogAbilityStage extends AbilityStage { + onCreate() { + console.log("DialogAbilityStage onCreate"); + } } \ No newline at end of file diff --git a/services/dialog_ui/enable_notification_dialog/entry/src/main/ets/ServiceExtAbility/NotificationServiceExtAbility.ts b/services/dialog_ui/enable_notification_dialog/entry/src/main/ets/ServiceExtAbility/NotificationServiceExtAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..a7d0b9d1912ad3be1c094459211ff7aeab5c8ffe --- /dev/null +++ b/services/dialog_ui/enable_notification_dialog/entry/src/main/ets/ServiceExtAbility/NotificationServiceExtAbility.ts @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import extension from '@ohos.application.ServiceExtensionAbility'; +import window from '@ohos.window'; +import display from '@ohos.display'; +const TAG = "NotificationDialog_Service"; + +export default class NotificationDialogServiceExtensionAbility extends extension { + onCreate(want) { + console.debug(TAG, "onCreate, want: " + JSON.stringify(want)); + globalThis.notificationExtensionContext = this.context; + globalThis.callbackImp = want.parameters.callbackStubImpl_; + globalThis.closeDialog = () => { + console.info(TAG, 'click waiting for a response'); + globalThis.notificationExtensionContext.terminateSelf(); + } + } + + onRequest(want, startId) { + globalThis.abilityWant = want; + console.log(TAG, "globalThis.resolution" + JSON.stringify(globalThis.resolution)); + display.getDefaultDisplay().then(dis => { + let thisWidth; + let thisHeight; + if (dis.width < dis.height) { + let widthRatio = 0.75; + let heightRatio = 5; + thisWidth = widthRatio * dis.width; + thisHeight = dis.height / heightRatio; + } else { + let widthRatio = 3; + let heightRatio = 4; + thisWidth = dis.width / widthRatio; + thisHeight = dis.height / heightRatio; + } + + let navigationBarRect = { + left: (dis.width - thisWidth) / 2, + top: (dis.height - thisHeight) / 2, + width: thisWidth, + height: thisHeight + } + globalThis.width = navigationBarRect.width; + globalThis.height = navigationBarRect.height; + this.createWindow("EnableNotificationDialog" + startId, window.WindowType.TYPE_SYSTEM_ALERT, navigationBarRect); + }) + } + + onDestroy() { + console.info(TAG, "onDestroy."); + } + + private async createWindow(name: string, windowType: number, rect) { + console.info(TAG, "create window"); + try { + const win = await window.create(globalThis.notificationExtensionContext, name, windowType); + await win.loadContent('pages/notificationDialog'); + await win.setBackgroundColor("#00000000"); + await win.show(); + } catch { + console.error(TAG, "window create failed!"); + } + } +}; diff --git a/services/dialog_ui/enable_notification_dialog/entry/src/main/ets/pages/notificationDialog.ets b/services/dialog_ui/enable_notification_dialog/entry/src/main/ets/pages/notificationDialog.ets new file mode 100644 index 0000000000000000000000000000000000000000..a64eb2948f4c56d11960d4d6680fa7df469d0f76 --- /dev/null +++ b/services/dialog_ui/enable_notification_dialog/entry/src/main/ets/pages/notificationDialog.ets @@ -0,0 +1,151 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import notification from '@ohos.notification' +import rpc from '@ohos.rpc'; + +class Proxy extends rpc.RemoteProxy { +} + +@Entry +@Component +struct NotificationDialog { + @State private want: any = undefined + @State private uid: any = undefined + @State private style: any = {} + @State callBackImp_: any = {} + @State token_: any = undefined + @State popWidth: any = undefined + @State popHeight: any = undefined + @State bundleName: any = undefined + controller: CustomDialogController + private TAG = "[NotificationDialog_Service]" + + build() { + Flex({direction: FlexDirection.Row, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center}) { + Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { + Flex({ alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Text($r("app.string.if_allow_to_publish_notification")) + .width("350vp") + .height("22vp") + .margin({ top: 32 }) + .fontSize(21) + .fontColor("#182431") + .fontWeight(400) + .opacity(1) + .textAlign(TextAlign.Center) + } + + Flex({ direction: FlexDirection.Row, justifyContent: FlexAlign.Center }) { + Flex({ direction: FlexDirection.Row, justifyContent: FlexAlign.Center }) { + Button() { + Row() { + Text($r("app.string.allow")) + .textAlign(TextAlign.Center) + .fontSize("22fp") + .fontWeight(500) + .fontColor("#0D81F2") + } + } + .onClick(() => { + let popFlag = true + this.privacyChose(popFlag) + console.info("after privacyChose") + }) + .width("116vp") + .height("40vp") + .margin({ top: "9vp", right: "8vp", bottom: "9vp", left: "8vp" }) + .backgroundColor("#FFFFFF") + } + .margin({ top: 15, right: 5, bottom: 8, left: 8 }) + + Flex({ direction: FlexDirection.Row, justifyContent: FlexAlign.Center }) { + Button() { + Row() { + Text($r("app.string.ban")) + .textAlign(TextAlign.Center) + .fontSize("22fp") + .fontWeight(500) + .fontColor("#0D81F2") + } + } + .onClick(() => { + let popFlag = false + this.privacyChose(popFlag) + console.info("after privacyChose") + }) + .width("116vp") + .height("40vp") + .margin({ top: "9vp", right: "8vp", bottom: "9vp", left: "8vp" }) + .backgroundColor("#FFFFFF") + } + .margin({ top: 15, right: 8, bottom: 8, left: 5 }) + } + } + .width(px2vp(globalThis.width)) + .height(px2vp(globalThis.height)) + .borderRadius(32) + .backgroundColor("#FFFFFF") + } + .width("100%") + .height("100%") + } + + async privacyChose(flag) { + let enable = flag; + let bundleOption = { + bundle: globalThis.bundleName + } + console.info("before enableNotification") + await notification.enableNotification(bundleOption, enable, (err) => { + if (err.code) { + console.error('Start enableNotification failed. ErrCode: ' + JSON.stringify(err.code)); + return + } + let option = new rpc.MessageOption() + let data = rpc.MessageParcel.create() + let reply = rpc.MessageParcel.create() + data.writeInterfaceToken("OHOS.Notification.AnsCallbackInterface") + data.writeBoolean(flag) + console.info("before send request") + this.callBackImp_.sendRequest(0, data, reply, option) + .then(function (result) { + console.info("start to send request") + if (result.errCode != 0) { + console.error("send request failed, errCode: " + result.errCode) + return + } + }) + .catch(function (err) { + console.error(this.TAG + "send request got exception: " + err) + }) + .finally(() => { + data.reclaim() + reply.reclaim() + globalThis.closeDialog() + }) + }) + console.info("after send request") + } + + aboutToAppear() { + console.log(this.TAG, "dialog page appears") + this.want = globalThis.abilityWant + this.style = globalThis.style + this.callBackImp_ = globalThis.abilityWant.parameters['callbackStubImpl_'].value + this.token_ = globalThis.abilityWant.parameters['tokenId'].value + globalThis.bundleName = globalThis.abilityWant.parameters['from'] + } +} \ No newline at end of file diff --git a/services/dialog_ui/enable_notification_dialog/entry/src/main/module.json b/services/dialog_ui/enable_notification_dialog/entry/src/main/module.json new file mode 100644 index 0000000000000000000000000000000000000000..ef94d86b69b0d94685f6335ae364923f0d013ac9 --- /dev/null +++ b/services/dialog_ui/enable_notification_dialog/entry/src/main/module.json @@ -0,0 +1,40 @@ +{ + "module": { + "name": "entry", + "type": "entry", + "srcEntrance": "./ets/Application/AbilityStage.ts", + "description": "$string:entry_desc", + "mainElement": "MainAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "uiSyntax": "ets", + "abilities": [], + "extensionAbilities": [ + { + "name": "EnableNotificationDialog", + "srcEntrance": "./ets/ServiceExtAbility/NotificationServiceExtAbility.ts", + "description": "$string:NotificationServiceExtAbility_desc", + "icon": "$media:icon", + "label": "$string:NotificationServiceExtAbility_label", + "visible": true, + "type": "service" + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED" + }, + { + "name": "ohos.permission.START_ABILITIES_FROM_BACKGROUND" + }, + { + "name": "ohos.permission.NOTIFICATION_CONTROLLER" + } + ] + } +} \ No newline at end of file diff --git a/services/dialog_ui/enable_notification_dialog/entry/src/main/resources/base/element/color.json b/services/dialog_ui/enable_notification_dialog/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..95f6870e2b079e5f72d7c8b1f17a8fab54ee5709 --- /dev/null +++ b/services/dialog_ui/enable_notification_dialog/entry/src/main/resources/base/element/color.json @@ -0,0 +1,20 @@ +{ + "color": [ + { + "name": "white", + "value": "#FFFFFF" + }, + { + "name": "default_background_color", + "value": "#ffffff" + }, + { + "name": "divider_color", + "value": "#f3f4f6" + }, + { + "name": "button_color", + "value": "#007DFF" + } + ] +} \ No newline at end of file diff --git a/services/dialog_ui/enable_notification_dialog/entry/src/main/resources/base/element/string.json b/services/dialog_ui/enable_notification_dialog/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..3e437d5205c5572c7ebf5f58bbaeda312d05113d --- /dev/null +++ b/services/dialog_ui/enable_notification_dialog/entry/src/main/resources/base/element/string.json @@ -0,0 +1,28 @@ +{ + "string": [ + { + "name": "entry_desc", + "value": "description" + }, + { + "name": "NotificationServiceExtAbility_desc", + "value": "NotificationDialog" + }, + { + "name": "NotificationServiceExtAbility_label", + "value": "NotificationDialog" + }, + { + "name": "if_allow_to_publish_notification", + "value": "Do you allow the app to publish notification?" + }, + { + "name": "allow", + "value": "allow" + }, + { + "name": "ban", + "value": "ban" + } + ] +} \ No newline at end of file diff --git a/services/dialog_ui/enable_notification_dialog/entry/src/main/resources/base/media/icon.png b/services/dialog_ui/enable_notification_dialog/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/services/dialog_ui/enable_notification_dialog/entry/src/main/resources/base/media/icon.png differ diff --git a/services/dialog_ui/enable_notification_dialog/entry/src/main/resources/base/profile/main_pages.json b/services/dialog_ui/enable_notification_dialog/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..ecceb635d8686b09b77a4916599278bbfb117f31 --- /dev/null +++ b/services/dialog_ui/enable_notification_dialog/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/notificationDialog" + ] +} diff --git a/services/dialog_ui/enable_notification_dialog/entry/src/main/resources/zh/element/string.json b/services/dialog_ui/enable_notification_dialog/entry/src/main/resources/zh/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..b0826edcd40bdf5312b768c96cd383b15a3d6f51 --- /dev/null +++ b/services/dialog_ui/enable_notification_dialog/entry/src/main/resources/zh/element/string.json @@ -0,0 +1,28 @@ +{ + "string": [ + { + "name": "entry_desc", + "value": "description" + }, + { + "name": "NotificationServiceExtAbility_desc", + "value": "NotificationDialog" + }, + { + "name": "NotificationServiceExtAbility_label", + "value": "NotificationDialog" + }, + { + "name": "allow", + "value": "允许" + }, + { + "name": "ban", + "value": "取消" + }, + { + "name": "if_allow_to_publish_notification", + "value": "是否允许发送通知?" + } + ] +} \ No newline at end of file diff --git a/services/dialog_ui/enable_notification_dialog/signature/openharmony_sx.p7b b/services/dialog_ui/enable_notification_dialog/signature/openharmony_sx.p7b new file mode 100644 index 0000000000000000000000000000000000000000..5c21d8d51658c36ffe2f9bff7907e284fb511704 Binary files /dev/null and b/services/dialog_ui/enable_notification_dialog/signature/openharmony_sx.p7b differ