1/* 2 * Copyright (c) 2024 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 abilityManager from '@ohos.app.ability.abilityManager'; 17import type { BusinessError } from '@ohos.base'; 18import type UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession'; 19 20let storage = LocalStorage.GetShared(); 21const TAG: string = 'AssertFaultDialog_Page'; 22const DEBUG_ASSERT_RESULT: string = 'assertResult'; 23 24@Entry(storage) 25@Component 26struct AssertFaultDialog { 27 @State private textDetail: string = ''; 28 29 aboutToAppear() { 30 console.info(TAG, 'dialog page appears'); 31 this.textDetail = storage.get<string>('textDetail'); 32 } 33 34 existApp() { 35 console.info(TAG, 'Exist app called'); 36 try { 37 AppStorage.setOrCreate(DEBUG_ASSERT_RESULT, abilityManager.UserStatus.ASSERT_TERMINATE); 38 storage.get<UIExtensionContentSession>('session').terminateSelf().then(() => { 39 console.log(TAG, 'terminateSelf success.'); 40 }).catch((err: BusinessError) => { 41 console.error(TAG, `terminateSelf failed, error: ${JSON.stringify(err)}`); 42 }) 43 } catch (error) { 44 console.error(TAG, `try notifyDebugAssertResult failed, error: ${JSON.stringify(error)}`); 45 } 46 } 47 48 onContinueCall() { 49 console.info(TAG, 'On continue called'); 50 try { 51 AppStorage.setOrCreate(DEBUG_ASSERT_RESULT, abilityManager.UserStatus.ASSERT_CONTINUE); 52 storage.get<UIExtensionContentSession>('session').terminateSelf().then(() => { 53 console.log(TAG, 'terminateSelf success.'); 54 }).catch((err: BusinessError) => { 55 console.error(TAG, `terminateSelf failed, error: ${JSON.stringify(err)}`); 56 }) 57 } catch (error) { 58 console.error(TAG, `try notifyDebugAssertResult failed, error: ${JSON.stringify(error)}`); 59 } 60 } 61 62 onRetryCall() { 63 console.info(TAG, 'On retry called'); 64 try { 65 AppStorage.setOrCreate(DEBUG_ASSERT_RESULT, abilityManager.UserStatus.ASSERT_RETRY); 66 storage.get<UIExtensionContentSession>('session').terminateSelf().then(() => { 67 console.log(TAG, 'terminateSelf success.'); 68 }).catch((err: BusinessError) => { 69 console.error(TAG, `terminateSelf failed, error: ${JSON.stringify(err)}`); 70 }) 71 } catch (error) { 72 console.error(TAG, `try notifyDebugAssertResult failed, error: ${JSON.stringify(error)}`); 73 } 74 } 75 76 onTerminationCall() { 77 console.info(TAG, 'On termination called'); 78 try { 79 AppStorage.setOrCreate(DEBUG_ASSERT_RESULT, abilityManager.UserStatus.ASSERT_TERMINATE); 80 storage.get<UIExtensionContentSession>('session').terminateSelf().then(() => { 81 console.log(TAG, 'terminateSelf success.'); 82 }).catch((err: BusinessError) => { 83 console.error(TAG, `terminateSelf failed, error: ${JSON.stringify(err)}`); 84 }) 85 } catch (error) { 86 console.error(TAG, `try notifyDebugAssertResult failed, error: ${JSON.stringify(error)}`); 87 } 88 } 89 90 build() { 91 Column( 92 AlertDialog.show( 93 { 94 title: 'Assert Fault Dialog', 95 message: this.textDetail, 96 autoCancel: false, 97 alignment: DialogAlignment.Center, 98 gridCount: 4, 99 buttonDirection: DialogButtonDirection.HORIZONTAL, 100 cancel: this.existApp, 101 buttons: [ 102 { 103 enabled: true, 104 defaultFocus: false, 105 style: DialogButtonStyle.HIGHLIGHT, 106 value: $r('app.string.button_continue'), 107 fontColor: $r('sys.color.ohos_id_color_foreground_contrary'), 108 backgroundColor: $r('app.color.button_color'), 109 action: this.onContinueCall 110 }, 111 { 112 enabled: true, 113 defaultFocus: false, 114 style: DialogButtonStyle.HIGHLIGHT, 115 value: $r('app.string.button_retry'), 116 fontColor: $r('sys.color.ohos_id_color_foreground_contrary'), 117 backgroundColor: $r('app.color.button_color'), 118 action: this.onRetryCall 119 }, 120 { 121 enabled: true, 122 defaultFocus: true, 123 style: DialogButtonStyle.HIGHLIGHT, 124 value: $r('app.string.button_termination'), 125 fontColor: $r('sys.color.ohos_id_color_foreground_contrary'), 126 backgroundColor: $r('app.color.button_color'), 127 action: this.onTerminationCall 128 } 129 ] 130 } 131 ) 132 ) {} 133 } 134} 135