MmsColdStartTest.ets 5.5 KB
Newer Older
T
tianwenzhe 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/*
 * Copyright (c) 2022-2023 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
15
import router from '@ohos.router';
T
tianwenzhe 已提交
16 17 18 19 20 21 22
import fileio from '@ohos.fileio';
import {CustomContainer} from '../common/StartExperienceCustomContainer';
import FirstDialog from '../model/FirstDialog';
import context from '@ohos.app.ability.common';

let abilityContext = getContext(this) as context.UIAbilityContext;
let path = globalThis.dir;
23 24
let path1 = path + '/ExperienceData';
let MmsColdPath = path1 + '/ColdStartMms.log';
T
tianwenzhe 已提交
25 26 27
@Entry
@Component
struct CustomContainerUser {
28
  @State name: string = 'MmsColdStart';
T
tianwenzhe 已提交
29
  @State StepTips: string = '操作步骤:根据操作提示运行脚本文件,启动应用'+'\n'+'预期结果:所有应用冷启动时延小于2000ms则测试通过';
T
tianwenzhe 已提交
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
  @State Vue: boolean = false;
  @State StartEnable: boolean = true;
  @State num: number = 0;
  @State setNum: number = 0;
  @State photosNum: number = 0;
  @State mmsNum: number = 0;
  @State cameraNum: number = 0;
  @State contactsNum: number = 0;
  async aboutToAppear(){
    await FirstDialog.ChooseDialog(this.StepTips,this.name);
    this.Vue = false;
  }

  @Builder specificNoParam() {
    Column() {
      Flex({direction:FlexDirection.Column,alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) {
        Column(){
          Row(){
            Text(`根据以下操作步骤完成测试`+ '\n' + '\n' )
              .fontColor(Color.White).fontSize('24fp')
          }
          Row(){
T
tianwenzhe 已提交
52 53 54 55
            Text(`测试步骤:`+ '\n' + '\n' + '1.测试设备通过USB连接工作台' + '\n' + '\n' + `2.点击开始键进入系统桌面` + '\n' + '\n'
            + `3.清空后台应用,将底层任务栏中应用拖至桌面` + '\n' + '\n' + `4.工作台运行‘点击启动测试.bat’选择冷启动>信息测试,回车执行`
            + '\n' + '\n' +`5.测试应用自动执行冷启动后手动返回validator界面` + '\n' + '\n' + '6.点击结束键观察测试结果'
            + '\n' + '\n' + `7.若冷启动测试在规定时延内完成则通过测试` + '\n' + '\n' )
T
tianwenzhe 已提交
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
              .fontColor(Color.White).fontSize('20fp')
          }
          Row(){
            Column(){
              Button(`开始`)
                .borderRadius(8)
                .backgroundColor(0x317aff)
                .width('30%')
                .enabled(this.StartEnable)
                .opacity(this.StartEnable? 1 : 0.4)
                .onClick(async () => {
                  this.num = 0;
                  this.StartEnable = !this.StartEnable;
                  let str = {
                    bundleName:"com.ohos.launcher",
                    abilityName: "com.ohos.launcher.MainAbility",
                  }
                  abilityContext.startAbility(str).then((data) => {

                  }).catch((error) => {

                  })
                })
            }
            Column(){
              Button(`结束`)
                .borderRadius(8)
                .backgroundColor(0x317aff)
                .width('30%')
                .enabled(!this.StartEnable)
                .opacity(!this.StartEnable? 1 : 0.4)
                .onClick(() => {
                  this.StartEnable = !this.StartEnable
                  /*
                            mms
                   */
                  let MmsFd = fileio.openSync(MmsColdPath, 0o100 | 0o2002, 0o664);
                  let MmsBuf = new ArrayBuffer(4096);
                  fileio.readSync(MmsFd,MmsBuf);
                  let MmsReport = String.fromCharCode.apply(null,new Uint8Array(MmsBuf));
T
tianwenzhe 已提交
96 97
                  let MmsHead = MmsReport.indexOf('time:');
                  let MmsTime = MmsReport.substring(MmsHead+5);
T
tianwenzhe 已提交
98
                  this.mmsNum = parseFloat(MmsTime);
T
tianwenzhe 已提交
99
                  if( 0 < this.mmsNum && this.mmsNum < 2000 ) {
T
tianwenzhe 已提交
100 101
                    this.num++
                  }
102
                  if( this.num === 1 ) {
T
tianwenzhe 已提交
103 104 105 106 107 108
                    this.Vue = true;
                  }
                })
            }
          }
          Row(){
T
tianwenzhe 已提交
109
            Text('\n' + '\n' + `测试结果:` + '\n' + '\n' + '信息冷启动时延' + this.mmsNum + 'ms')
T
tianwenzhe 已提交
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
              .fontColor(Color.White).fontSize('24fp')
          }
        }

      }
    }.width('100%').height('80%').backgroundColor(Color.Black)
    .justifyContent(FlexAlign.SpaceEvenly)
  }
  build() {
    Column() {
      CustomContainer({
        title: this.name,
        Url:'pages/Experience/Experience_index',
        StepTips:this.StepTips,
        content: this.specificNoParam,
        name:$name,
        Vue: $Vue,
        StartEnable: $StartEnable,
        num: $num,
        setNum: $setNum,
        photosNum: $photosNum,
        mmsNum: $mmsNum,
        cameraNum: $cameraNum,
        contactsNum: $contactsNum,
      })
    }.width('100%').height('100%').backgroundColor(Color.Black)
  }
137 138 139 140 141
  onBackPress(){
    router.replaceUrl({
      url:'pages/Experience/Experience_index',
    })
  }
T
tianwenzhe 已提交
142
}