1/* 2 * Copyright (c) 2023-2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import router from '@ohos.router'; 17import { Log } from '@ohos/common'; 18import bundleManager from '@ohos.bundle.bundleManager'; 19import common from '@ohos.app.ability.common'; 20import { GlobalThisHelper, GlobalThisStorageKey} from '@ohos/common'; 21import { PreferencesKey} from '@ohos/common'; 22import PreferencesAdapter from '../Common/Adapter/PreferencesAdapter'; 23import {PrivacyStatementDialog} from './PrivacyStatementDialog'; 24import {CancelButton} from './component/BaseComponent'; 25 26const TAG = 'PrivacyStatementPage'; 27 28@Entry 29@Component 30struct PrivacyStatementPage { 31 @State versionName: string = undefined; 32 private readonly PRIVACY_STATEMENT_STORE: string = 'privacyStatementStore'; 33 private abilityContext: common.UIAbilityContext = undefined 34 private dialogController: CustomDialogController = new CustomDialogController({ 35 builder: PrivacyStatementDialog(), 36 autoCancel: false, 37 customStyle: true, 38 }) 39 40 aboutToAppear() { 41 bundleManager.getBundleInfoForSelf(bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT) 42 .then((bundleInfo) => { 43 Log.info(TAG, 'bundleInfo: ' + JSON.stringify(bundleInfo)); 44 this.versionName = bundleInfo.versionName; 45 }) 46 this.abilityContext = GlobalThisHelper.getValue<common.UIAbilityContext>(GlobalThisStorageKey.KEY_MAIN_ABILITY_CONTEXT) 47 } 48 49 build() { 50 Flex({ justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { 51 Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Center }) { 52 Column() { 53 Image($r('app.media.logo')) 54 .width($r('app.float.privacy_statement_print_log_width_height')) 55 .height($r("app.float.privacy_statement_print_log_width_height")) 56 .margin({top: $r('app.float.print_log_margin_top')}) 57 Text($r('app.string.welcome')) 58 .margin({ top: $r('app.float.privacy_statement_text_relative_img_margin_top')}) 59 .fontColor($r('sys.color.ohos_id_color_text_tertiary')) 60 .fontSize($r('sys.float.ohos_id_text_size_over_line')) 61 .fontWeight(FontWeight.Regular) 62 .height($r('app.float.privacy_statement_text_tertiary_height')) 63 Text($r('app.string.MainAbility_label')) 64 .fontSize($r('sys.float.ohos_id_text_size_headline7')) 65 .fontColor($r('sys.color.ohos_id_color_text_primary')) 66 .fontWeight(FontWeight.Bolder) 67 .height($r('app.float.privacy_statement_text_headline_height')) 68 .margin({top: $r('app.float.privacy_statement_text_relative_text_margin_top')}) 69 Text($r('app.string.print_slogan')) 70 .fontColor($r('sys.color.ohos_id_color_text_tertiary')) 71 .fontSize($r('sys.float.ohos_id_text_size_over_line')) 72 .fontWeight(FontWeight.Regular) 73 .margin({top: $r('app.float.privacy_statement_text_relative_text_margin_top')}) 74 .height($r('app.float.privacy_statement_text_tertiary_height')) 75 } 76 77 Column() { 78 Image($r('app.media.ic_public_shield')) 79 .width($r('app.float.shield_width_height')) 80 .height($r('app.float.shield_width_height')) 81 Text() { 82 ForEach(this.getPrivacyStatementText(), (privacyStatementText) => { 83 if (privacyStatementText === this.abilityContext.resourceManager.getStringByNameSync('location_information') || 84 privacyStatementText === this.abilityContext.resourceManager.getStringByNameSync('print_permission_network')) { 85 Span(privacyStatementText).fontWeight(FontWeight.Bolder) 86 } else { 87 Span(privacyStatementText) 88 } 89 }) 90 Span($r('app.string.about_privacy_statement_text')) 91 .onClick(() => { 92 router.replaceUrl({ 93 url: 'pages/PrivacyStatementWebPage', 94 params: { 95 info: true 96 } 97 }); 98 }) 99 .fontColor($r('sys.color.ohos_id_color_text_hyperlink')) 100 .fontSize($r('sys.float.ohos_id_text_size_body3')) 101 Span('、') 102 Span($r('app.string.permissions_notice')) 103 .fontColor($r('sys.color.ohos_id_color_text_hyperlink')) 104 .fontSize($r('sys.float.ohos_id_text_size_body3')) 105 .onClick(() => { 106 this.dialogController.open(); 107 }) 108 Span('。') 109 } 110 .fontColor($r('sys.color.ohos_id_color_text_primary')) 111 .fontSize($r('sys.float.ohos_id_text_size_body3')) 112 .margin({ 113 top: $r('app.float.privacy_statement_text_relative_img_margin_top'), 114 left: $r('app.float.privacy_statement_text_margin_left_right'), 115 right: $r('app.float.privacy_statement_text_margin_left_right') 116 }) 117 Row() { 118 CancelButton({ 119 cancelLabel: $r('app.string.Cancel'), 120 cancelWidth: $r('app.float.privacy_statement_button_width'), 121 cancelHeight: $r('app.float.privacy_statement_button_height'), 122 cancelClick: () => { 123 this.abilityContext.terminateSelf(); 124 } 125 }) 126 .margin({right: $r('app.float.privacy_statement_button_space')}) 127 Button($r('app.string.Agree')) 128 .onClick(() => { 129 this.agreePrivacyStatement(); 130 router.replaceUrl({url: 'pages/PrintPage'}); 131 }) 132 .width($r('app.float.privacy_statement_button_width')) 133 .height($r('app.float.privacy_statement_button_height')) 134 } 135 .margin({ 136 top: $r('app.float.privacy_statement_button_to_text_margin_top'), 137 bottom: $r('app.float.privacy_statement_button_margin_bottom'), 138 }) 139 } 140 } 141 } 142 .width('100%') 143 .height('100%') 144 } 145 146 async agreePrivacyStatement() { 147 Log.info(TAG, "agreePrivacyStatement"); 148 PreferencesAdapter.getInstance().getOrCreatePreferencesSync(this.PRIVACY_STATEMENT_STORE).then((successGet) => { 149 Log.info(TAG, 'agreePrivacyStatement getOrCreatePreferencesSync successGet: ' + successGet); 150 if (successGet) { 151 PreferencesAdapter.getInstance().putValue(PreferencesKey.KEY_PRIVACY_STATEMENT_PREFERENCES, true).then((successPut) => { 152 Log.info(TAG, 'agreePrivacyStatement putValue successPut: ' + successPut); 153 if (successPut) { 154 PreferencesAdapter.getInstance().flush(); 155 } 156 }) 157 } 158 }); 159 } 160 161 private getPrivacyStatementText() : Array<string> { 162 var privacyStatementTextList = new Array<string>(); 163 var privacyStatementText = this.abilityContext.resourceManager.getStringByNameSync('privacy_statement_text'); 164 var printPermissionNetwork = this.abilityContext.resourceManager.getStringByNameSync('print_permission_network'); 165 var locationInformation = this.abilityContext.resourceManager.getStringByNameSync('location_information'); 166 167 var privacyStatementTexts = privacyStatementText.split(printPermissionNetwork); 168 privacyStatementTextList.push(privacyStatementTexts[0]); 169 privacyStatementTextList.push(printPermissionNetwork); 170 privacyStatementTexts = privacyStatementTexts[1].split(locationInformation); 171 privacyStatementTextList.push(privacyStatementTexts[0]); 172 privacyStatementTextList.push(locationInformation); 173 privacyStatementTextList.push(privacyStatementTexts[1]); 174 return privacyStatementTextList; 175 } 176}