1/** 2 * Copyright (c) 2025 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 16 17import wifi from '@ohos.wifiManager'; 18import hilog from '../model/Logger' 19 20/** 21 * P2pView Component of p2p test 22 */ 23const TAG = 'wifiTestApp [P2pView]' 24 25@Component 26export struct P2pView { 27 private p2p!: wifi.WifiP2pDevice 28 private securityString: Resource = $r('app.string.useful') 29 private p2pConnectState: number = 0 30 @StorageLink('p2pLinkedDeviceName') p2pLinkedDeviceName: string = '' 31 @State isLock: boolean = true 32 33 aboutToAppear() { 34 hilog.info(TAG , `aboutToAppear ${ JSON.stringify(this.p2p) }`) 35 36 this.p2pConnectState = AppStorage.get('p2pConnectState') ! 37 this.p2pLinkedDeviceName = AppStorage.get('p2pLinkedDeviceName') ! 38 if ( this.p2p ) { 39 hilog.info(TAG , 'this.p2p is true'); 40 } else { 41 hilog.info(TAG , 'this.p2p is false'); 42 } 43 } 44 45 build() { 46 Row() { 47 Column() { 48 if ( this.p2p ) { 49 if ( this.p2p.deviceName ) { 50 Text(this.p2p.deviceName) 51 .fontSize(20) 52 .width('100%') 53 } 54 } 55 if ( this.p2pConnectState == 1 && this.p2pLinkedDeviceName == this.p2p.deviceName ) { 56 Text($r('app.string.p2pConnected')) 57 .fontSize(18) 58 .fontColor(Color.Gray) 59 .width('100%') 60 } else { 61 Text($r('app.string.useful')) 62 .fontSize(18) 63 .fontColor(Color.Gray) 64 .width('100%') 65 } 66 } 67 .layoutWeight(1) 68 69 Stack({ alignContent : Alignment.BottomEnd }) { 70 Image($r('app.media.wifi')) 71 .height(30).width(30) 72 .objectFit(ImageFit.Contain) 73 if ( this.isLock ) { 74 Image($r('app.media.lock')) 75 .objectFit(ImageFit.Contain) 76 .width(15).height(15) 77 } 78 } 79 .width(40).height(40) 80 .margin({ right : 10 }) 81 } 82 .backgroundColor(Color.White) 83 .width('100%') 84 .padding(10) 85 } 86}