1/* 2 * Copyright (c) 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 UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession'; 17import ability from '@ohos.ability.ability'; 18import Constants from '../common/constant'; 19import GlobalContext from '../common/GlobalContext'; 20import { directionStatus, isPC } from '../common/utils'; 21import common from '@ohos.app.ability.common'; 22import emitter from '@ohos.events.emitter'; 23 24const TAG = "[DLPManager_PermStat]"; 25 26let abilityResult: ability.AbilityResult = { 27 "resultCode": 0, 28 "want": {} 29}; 30 31class Content_ { 32 label: Resource | undefined = undefined 33 value: boolean = false 34 date?: boolean 35} 36 37class TitleContent { 38 title: Resource | undefined = undefined 39 content: Content_[] = [] 40} 41 42let storage = LocalStorage.getShared(); 43@Entry(storage) 44@Component 45struct PermissionStatus { 46 @State session: UIExtensionContentSession | undefined = storage === undefined ? undefined : storage.get<UIExtensionContentSession>('session'); 47 @State directionStatus: number = 0; 48 @State authPerm: number = Constants.PP_IMAGE_PAD; 49 @State authPermFlag: boolean = false; 50 @State accountId: string = ''; 51 @State validity: number = 0; 52 private array1: TitleContent[] = [ 53 { 54 title: ($r('app.string.perm_list_title_read_only')), 55 content: [ 56 { 57 label: ($r('app.string.perm_list_title_read_only')), value: true 58 } 59 ] 60 }, 61 { 62 title: ($r('app.string.header_title_edit')), 63 content: [ 64 { 65 label: ($r('app.string.save')), value: false 66 }, 67 { 68 label: ($r('app.string.save_as')), value: false 69 }, 70 { 71 label: ($r('app.string.header_title_edit_content')), value: false 72 }, 73 { 74 label: ($r('app.string.screenshot')), value: false 75 }, 76 { 77 label: ($r('app.string.share_the_screen')), value: false 78 }, 79 { 80 label: ($r('app.string.screen_recording')), value: false 81 }, 82 { 83 label: ($r('app.string.duplicate')), value: false 84 }, 85 { 86 label: ($r('app.string.print')), value: false 87 }, 88 ] 89 }, 90 { 91 title: ($r('app.string.Document_valid')), 92 content: [ 93 { 94 label: ($r('app.string.Document_valid_until')), value: false, date: true 95 } 96 ] 97 } 98 ]; 99 private array2: TitleContent[] = [ 100 { 101 title: ($r('app.string.perm_list_title_read_only')), 102 content: [ 103 { 104 label: ($r('app.string.perm_list_title_read_only')), value: true 105 } 106 ] 107 }, 108 { 109 title: ($r('app.string.header_title_edit')), 110 content: [ 111 { 112 label: ($r('app.string.save')), value: true 113 }, 114 { 115 label: ($r('app.string.save_as')), value: true 116 }, 117 { 118 label: ($r('app.string.header_title_edit_content')), value: true 119 }, 120 { 121 label: ($r('app.string.screenshot')), value: true 122 }, 123 { 124 label: ($r('app.string.share_the_screen')), value: true 125 }, 126 { 127 label: ($r('app.string.screen_recording')), value: true 128 }, 129 { 130 label: ($r('app.string.duplicate')), value: true 131 }, 132 { 133 label: ($r('app.string.print')), value: true 134 }, 135 ] 136 }, 137 { 138 title: ($r('app.string.Document_valid')), 139 content: [ 140 { 141 label: ($r('app.string.Document_valid_until')), value: false, date: true 142 } 143 ] 144 } 145 ]; 146 147 aboutToAppear() { 148 console.info(TAG, 'aboutToAppear'); 149 this.authPerm = AppStorage.get('authPerm') ?? 1; 150 this.accountId = AppStorage.get('contactAccount') ?? ''; 151 this.validity = AppStorage.get('validity') ?? 0; 152 this.directionStatus = (GlobalContext 153 .load('context') as common.UIAbilityContext).config.direction ?? -1; 154 directionStatus((counter) => { 155 this.directionStatus = counter; 156 }) 157 } 158 159 getTime(validity: number) { 160 if (validity === 0) { 161 return $r('app.string.permanently'); 162 } 163 let date: Date = new Date(validity); 164 let year = date.getFullYear(); 165 let month = date.getMonth() + 1; 166 let day = date.getDate(); 167 let hour = date.getHours(); 168 let minute = date.getMinutes(); 169 return `${year}/${month}/${day} ${hour}:${minute}`; 170 } 171 172 @Builder itemHead(text?: string | Resource) { 173 Text(text) 174 .fontSize($r('sys.float.ohos_id_text_size_body2')) 175 .width(Constants.HEADER_COLUMN_WIDTH) 176 .height(Constants.HEADER_COLUMN_HEIGHT_READONLY) 177 .fontColor($r('sys.color.ohos_id_color_text_secondary')) 178 } 179 180 aboutToDisappear() { 181 emitter.off(Constants.ENCRYPTION_EMIT_COLOR_MODE); 182 } 183 184 build() { 185 GridRow({ 186 columns: { 187 xs: Constants.XS_COLUMNS, 188 sm: Constants.SM_COLUMNS, 189 md: Constants.MD_COLUMNS, 190 lg: Constants.LG_COLUMNS 191 }, 192 gutter: Constants.DIALOG_GUTTER 193 }) { 194 GridCol({ 195 span: { 196 xs: Constants.XS_SPAN, 197 sm: Constants.SM_SPAN, 198 md: Constants.SM_SPAN, 199 lg: Constants.SM_SPAN 200 }, 201 offset: { 202 xs: Constants.XS_OFFSET, 203 sm: Constants.SM_OFFSET, 204 md: Constants.LG_OFFSET, 205 lg: Constants.SM_SPAN 206 } 207 }) { 208 Flex({ justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center, 209 direction: FlexDirection.Column }) { 210 Flex({ alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { 211 Column() { 212 Row() { 213 Text($r('app.string.header_title')) 214 .fontWeight(FontWeight.Medium) 215 .fontColor($r('sys.color.ohos_id_color_text_primary')) 216 .fontSize($r('sys.float.ohos_id_text_size_dialog_tittle')) 217 .lineHeight(Constants.HEADER_TEXT_LINE_HEIGHT) 218 .width(Constants.HEADER_TEXT_WIDTH) 219 .align(Alignment.Start) 220 } 221 .width(Constants.HEADER_COLUMN_WIDTH) 222 .height(Constants.HEADER_COLUMN_HEIGHT) 223 .padding({ 224 left: Constants.HEADER_COLUMN_PADDING_LEFT, 225 right: Constants.HEADER_COLUMN_PADDING_RIGHT 226 }) 227 228 Scroll() { 229 Column() { 230 Row() { 231 Text(this.authPerm === Constants.FOOTER_OPACITY_ONE ? $r('app.string.permission_status_readOnly') : $r('app.string.permission_status_title')) 232 .fontWeight(FontWeight.Regular) 233 .fontColor($r('sys.color.ohos_id_color_text_secondary')) 234 .fontSize($r('sys.float.ohos_id_text_size_body1')) 235 .width(Constants.HEADER_TEXT_WIDTH) 236 .align(Alignment.Start) 237 } 238 .width(Constants.HEADER_COLUMN_WIDTH) 239 .margin({ bottom: Constants.DU_LINE_MARGIN_TOP2 }) 240 241 List() { 242 ForEach(this.authPerm === Constants.FOOTER_OPACITY_ONE ? this.array1 : this.array2, (item: TitleContent) => { 243 ListItemGroup({ header: this.itemHead(item.title) }) { 244 ForEach(item.content, (item: Content_) => { 245 ListItem() { 246 Row() { 247 Text(item.label) 248 .height(Constants.HEADER_COLUMN_HEIGHT_READONLY) 249 .fontSize($r('sys.float.ohos_id_text_size_body1')) 250 .textAlign(TextAlign.Start) 251 .fontWeight(FontWeight.Medium) 252 Blank() 253 if (item.date) { 254 Text(this.getTime(this.validity)) 255 .height(Constants.HEADER_COLUMN_HEIGHT_READONLY) 256 .fontSize($r('sys.float.ohos_id_text_size_body2')) 257 .textAlign(TextAlign.Start) 258 .fontWeight(FontWeight.Regular) 259 .opacity(Constants.ENCRYPTION_STATUS_VALUE_COLOR) 260 } else { 261 Image(item.value ? $r('app.media.ok') : $r('app.media.cancel')) 262 .width(Constants.PP_IMAGE_WIDTH) 263 .height(Constants.PP_IMAGE_HEIGHT) 264 .fillColor($r('sys.color.ohos_id_color_text_primary')) 265 .opacity(Constants.ENCRYPTION_STATUS_VALUE_COLOR) 266 } 267 } 268 .width(Constants.HEADER_TEXT_WIDTH) 269 } 270 }, (item: Content_) => JSON.stringify(item)) 271 } 272 .divider({ 273 strokeWidth: Constants.FOOTER_OPACITY_ONE, 274 color: $r('app.color.encryption_divider_color') 275 }) 276 }) 277 } 278 } 279 }.constraintSize({ 280 maxHeight: this.directionStatus === 0 ? Constants.CHANGE_MAX_HEIGHT : Constants.ENCRYPTION_SUCCESS_MAX_HEIGHT 281 }) 282 .padding({ 283 left: Constants.HEADER_COLUMN_PADDING_LEFT, 284 right: Constants.HEADER_COLUMN_PADDING_RIGHT 285 }) 286 287 Row() { 288 Text($r('app.string.apply_for_the_permission', this.accountId)) 289 .fontColor($r('sys.color.ohos_id_color_text_secondary')) 290 .fontSize($r('sys.float.ohos_id_text_size_body1')) 291 .align(Alignment.Start) 292 .fontWeight(FontWeight.Regular) 293 } 294 .width(Constants.HEADER_COLUMN_WIDTH) 295 .margin({ top: Constants.DA_MARGIN_TOP, bottom: Constants.DU_LINE_MARGIN_TOP2 }) 296 .padding({ 297 left: Constants.HEADER_COLUMN_PADDING_LEFT, 298 right: Constants.HEADER_COLUMN_PADDING_RIGHT 299 }) 300 301 Row() { 302 Button($r('app.string.da_button'), { type: ButtonType.Capsule, stateEffect: true }) 303 .backgroundColor($r('app.color.base_button_color')) 304 .fontColor($r('app.color.encryption_cancel')) 305 .width(Constants.ENCRYPTION_PERMISSION_STATUS_WIDTH) 306 .height(Constants.FOOTER_BUTTON_HEIGHT) 307 .onClick(() => { 308 if (this.session !== undefined) { 309 this.session.terminateSelfWithResult({ 310 'resultCode': 0, 311 'want': { 312 'bundleName': Constants.DLP_MANAGER_BUNDLE_NAME, 313 }, 314 }); 315 } else { 316 if (GlobalContext.load('fileOpenHistoryFromMain')) { 317 (GlobalContext.load('fileOpenHistoryFromMain') as Map<string, Object>).delete(GlobalContext.load('uri') as string) 318 } 319 abilityResult.resultCode = 0; 320 (GlobalContext.load('context') as common.UIAbilityContext).terminateSelfWithResult(abilityResult); 321 } 322 }) 323 } 324 .justifyContent(FlexAlign.Center) 325 .padding({ 326 top: Constants.FOOTER_ROW_PAD_LEFT, 327 bottom: Constants.HEADER_COLUMN_PADDING_BOTTOM, 328 left: Constants.FOOTER_ROW_PAD_LEFT, 329 right: Constants.FOOTER_ROW_PAD_RIGHT 330 }) 331 } 332 .width( isPC() ? Constants.ENCRYPTION_PC_FIXING_STATUS_WIDTH : Constants.HEADER_COLUMN_WIDTH) 333 .backgroundColor($r('sys.color.ohos_id_color_dialog_bg')) 334 .borderRadius($r('sys.float.ohos_id_corner_radius_dialog')) 335 .shadow(ShadowStyle.OUTER_DEFAULT_SM) 336 .constraintSize({ minWidth: isPC() ? Constants.ENCRYPTION_PC_FIXING_STATUS_WIDTH : Constants.ENCRYPTION_PC_FIXING_MINWIDTH }) 337 } 338 } 339 } 340 } 341 } 342} 343