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 } from '../common/utils'; 21import common from '@ohos.app.ability.common'; 22import { HiLog } from '../common/HiLog'; 23 24const TAG = 'PermStat'; 25 26let abilityResult: ability.AbilityResult = { 27 'resultCode': 0, 28 'want': {} 29}; 30 31class StatusContent { 32 public label: Resource | undefined = undefined 33 public value: boolean = false 34 public date?: boolean 35} 36 37class TitleContent { 38 public title: Resource | undefined = undefined 39 public content: StatusContent[] = [] 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 HiLog.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 = (getContext(this) as common.UIAbilityContext).config.direction ?? -1; 153 directionStatus((counter) => { 154 this.directionStatus = counter; 155 }) 156 } 157 158 getTime(validity: number) { 159 if (validity === 0) { 160 return $r('app.string.permanently'); 161 } 162 let date: Date = new Date(validity); 163 let year = date.getFullYear(); 164 let month = date.getMonth() + 1; 165 let day = date.getDate(); 166 let hour = date.getHours(); 167 let minute = date.getMinutes(); 168 return `${year}/${month}/${day} ${hour}:${minute}`; 169 } 170 171 @Builder 172 itemHead(text?: string | Resource) { 173 Text(text) 174 .fontSize($r('sys.float.ohos_id_text_size_sub_title3')) 175 .fontWeight(FontWeight.Medium) 176 .fontColor($r('sys.color.ohos_id_color_text_secondary')) 177 .width(Constants.HEADER_COLUMN_WIDTH) 178 .constraintSize({ minHeight: Constants.SUB_HEADER_HEIGHT }) 179 } 180 181 build() { 182 GridRow({ 183 columns: { 184 xs: Constants.XS_COLUMNS, 185 sm: Constants.SM_COLUMNS, 186 md: Constants.MD_COLUMNS, 187 lg: Constants.LG_COLUMNS 188 }, 189 gutter: Constants.DIALOG_GUTTER 190 }) { 191 GridCol({ 192 span: { 193 xs: Constants.XS_SPAN, 194 sm: Constants.SM_SPAN, 195 md: Constants.SM_SPAN, 196 lg: Constants.SM_SPAN 197 }, 198 offset: { 199 xs: Constants.XS_OFFSET, 200 sm: Constants.SM_OFFSET, 201 md: Constants.LG_OFFSET, 202 lg: Constants.SM_SPAN 203 } 204 }) { 205 Flex({ justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center, 206 direction: FlexDirection.Column }) { 207 Flex({ alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { 208 Column() { 209 Row() { 210 Text($r('app.string.header_title')) 211 .fontWeight(FontWeight.Bold) 212 .fontColor($r('sys.color.ohos_id_color_text_primary')) 213 .fontSize($r('sys.float.ohos_id_text_size_dialog_tittle')) 214 .lineHeight(Constants.HEADER_TEXT_LINE_HEIGHT) 215 .width(Constants.HEADER_TEXT_WIDTH) 216 .align(Alignment.Start) 217 } 218 .width(Constants.HEADER_COLUMN_WIDTH) 219 .height(Constants.HEADER_COLUMN_HEIGHT) 220 .padding({ 221 left: Constants.HEADER_COLUMN_PADDING_LEFT, 222 right: Constants.HEADER_COLUMN_PADDING_RIGHT 223 }) 224 .margin({ bottom: Constants.HEADER_COLUMN_MARGIN_BOTTOM }); 225 226 Scroll() { 227 Column() { 228 Row() { 229 Text(this.authPerm === Constants.FOOTER_OPACITY_ONE ? 230 $r('app.string.permission_status_readOnly') : $r('app.string.permission_status_title')) 231 .fontWeight(FontWeight.Regular) 232 .fontColor($r('sys.color.ohos_id_color_text_secondary')) 233 .fontSize($r('sys.float.ohos_id_text_size_body1')) 234 .width(Constants.HEADER_TEXT_WIDTH) 235 .align(Alignment.Start) 236 } 237 .width(Constants.HEADER_COLUMN_WIDTH) 238 .margin({ bottom: Constants.DU_LINE_MARGIN_TOP2 }) 239 240 List() { 241 ForEach(this.authPerm === Constants.FOOTER_OPACITY_ONE ? 242 this.array1 : this.array2, (item: TitleContent) => { 243 ListItemGroup({ header: this.itemHead(item.title) }) { 244 ForEach(item.content, (item: StatusContent) => { 245 ListItem() { 246 Column() { 247 Row() { 248 Text(item.label) 249 .constraintSize({ minHeight: Constants.SUB_HEADER_HEIGHT }) 250 .fontSize($r('sys.float.ohos_id_text_size_body1')) 251 .textAlign(TextAlign.Start) 252 .fontWeight(FontWeight.Medium) 253 Blank() 254 if (item.date) { 255 Text(this.getTime(this.validity)) 256 .constraintSize({ minHeight: Constants.SUB_HEADER_HEIGHT }) 257 .fontSize($r('sys.float.ohos_id_text_size_body2')) 258 .textAlign(TextAlign.Start) 259 .fontWeight(FontWeight.Regular) 260 .opacity(Constants.ENCRYPTION_STATUS_VALUE_COLOR) 261 } else { 262 Image(item.value ? $r('app.media.ok') : $r('app.media.cancel')) 263 .width(Constants.PP_IMAGE_WIDTH) 264 .height(Constants.PP_IMAGE_HEIGHT) 265 .fillColor($r('sys.color.ohos_id_color_text_primary')) 266 .opacity(Constants.ENCRYPTION_STATUS_VALUE_COLOR) 267 } 268 } 269 .width(Constants.HEADER_TEXT_WIDTH); 270 Divider() 271 .width(Constants.HEADER_TEXT_WIDTH) 272 .height(Constants.FOOTER_OPACITY_ONE) 273 .color($r('sys.color.comp_divider')); 274 } 275 } 276 }, (item: StatusContent) => JSON.stringify(item)) 277 } 278 }) 279 } 280 281 Row() { 282 Text() { 283 Span($r('app.string.apply_for_the_subject')) 284 if (this.authPerm === Constants.FOOTER_OPACITY_ONE) { 285 Span($r('app.string.apply_for_the_permission', this.accountId)) 286 } 287 } 288 .fontColor($r('sys.color.ohos_id_color_text_secondary')) 289 .fontSize($r('sys.float.ohos_id_text_size_body1')) 290 .align(Alignment.Start) 291 .fontWeight(FontWeight.Regular) 292 } 293 .width(Constants.HEADER_COLUMN_WIDTH) 294 .margin({ top: Constants.DA_MARGIN_TOP }); 295 } 296 }.constraintSize({ 297 maxHeight: this.directionStatus === 298 0 ? Constants.CHANGE_MAX_HEIGHT : Constants.ENCRYPTION_SUCCESS_MAX_HEIGHT 299 }) 300 .padding({ 301 left: Constants.HEADER_COLUMN_PADDING_LEFT, 302 right: Constants.HEADER_COLUMN_PADDING_RIGHT 303 }) 304 305 Row() { 306 Button($r('app.string.da_button'), { type: ButtonType.Capsule, stateEffect: true }) 307 .backgroundColor($r('sys.color.ohos_id_color_button_normal')) 308 .fontColor($r('sys.color.ohos_id_color_text_primary_activated')) 309 .width(Constants.ENCRYPTION_PERMISSION_STATUS_WIDTH) 310 .height(Constants.FOOTER_BUTTON_HEIGHT) 311 .onClick(() => { 312 if (this.session !== undefined) { 313 this.session.terminateSelfWithResult({ 314 'resultCode': 0, 315 'want': { 316 'bundleName': Constants.DLP_MANAGER_BUNDLE_NAME, 317 }, 318 }); 319 } else { 320 if (GlobalContext.load('fileOpenHistoryFromMain')) { 321 (GlobalContext.load('fileOpenHistoryFromMain') as Map<string, Object>).delete(GlobalContext.load('uri') as string) 322 } 323 abilityResult.resultCode = 0; 324 (getContext(this) as common.UIAbilityContext).terminateSelfWithResult(abilityResult); 325 } 326 }) 327 } 328 .justifyContent(FlexAlign.Center) 329 .padding({ 330 top: Constants.FOOTER_ROW_PAD_LEFT, 331 bottom: Constants.HEADER_COLUMN_PADDING_BOTTOM, 332 left: Constants.FOOTER_ROW_PAD_LEFT, 333 right: Constants.FOOTER_ROW_PAD_RIGHT 334 }) 335 } 336 .width(Constants.ENCRYPTION_PC_FIXING_STATUS_WIDTH) 337 .backgroundColor($r('sys.color.ohos_id_color_dialog_bg')) 338 .borderRadius($r('sys.float.ohos_id_corner_radius_dialog')) 339 .shadow(ShadowStyle.OUTER_DEFAULT_MD) 340 .constraintSize({ minWidth: Constants.ENCRYPTION_PC_FIXING_STATUS_WIDTH }) 341 .backgroundBlurStyle(BlurStyle.COMPONENT_ULTRA_THICK); 342 } 343 } 344 } 345 } 346 } 347} 348