1fb726d48Sopenharmony_ci/*
2fb726d48Sopenharmony_ci * Copyright (C) 2022 Huawei Device Co., Ltd.
3fb726d48Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4fb726d48Sopenharmony_ci * you may not use this file except in compliance with the License.
5fb726d48Sopenharmony_ci * You may obtain a copy of the License at
6fb726d48Sopenharmony_ci *
7fb726d48Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8fb726d48Sopenharmony_ci *
9fb726d48Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10fb726d48Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11fb726d48Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12fb726d48Sopenharmony_ci * See the License for the specific language governing permissions and
13fb726d48Sopenharmony_ci * limitations under the License.
14fb726d48Sopenharmony_ci */
15fb726d48Sopenharmony_ci
16fb726d48Sopenharmony_ciimport { BaseElement, element } from '../../base-ui/BaseElement';
17fb726d48Sopenharmony_ciimport { SpFlagHtml } from './SpFlag.html';
18fb726d48Sopenharmony_ciconst NUM = '000000';
19fb726d48Sopenharmony_ci//vsync二级下拉选框对应的value和content
20fb726d48Sopenharmony_ciconst VSYNC_CONTENT = [
21fb726d48Sopenharmony_ci  { value: 'H:VsyncGenerator', content: 'VsyncGeneratior' },
22fb726d48Sopenharmony_ci  { value: 'H:rs_SendVsync', content: 'Vsync-rs' },
23fb726d48Sopenharmony_ci  { value: 'H:rs_SendVsync', content: 'Vsync-app' }
24fb726d48Sopenharmony_ci];
25fb726d48Sopenharmony_ci//cat二级下拉选框对应的value和content
26fb726d48Sopenharmony_ciconst CAT_CONTENT = [
27fb726d48Sopenharmony_ci  { value: 'business', content: 'Business first' },
28fb726d48Sopenharmony_ci  { value: 'thread', content: 'Thread first' }
29fb726d48Sopenharmony_ci];
30fb726d48Sopenharmony_ci//hang二级下拉选框对应的value和content
31fb726d48Sopenharmony_ciconst HANG_CONTENT = [
32fb726d48Sopenharmony_ci  { value: `33${NUM}`, content: 'Instant' },
33fb726d48Sopenharmony_ci  { value: `100${NUM}`, content: 'Circumstantial' },
34fb726d48Sopenharmony_ci  { value: `250${NUM}`, content: 'Micro' },
35fb726d48Sopenharmony_ci  { value: `500${NUM}`, content: 'Severe' }
36fb726d48Sopenharmony_ci];
37fb726d48Sopenharmony_ci
38fb726d48Sopenharmony_ci//整合默认值
39fb726d48Sopenharmony_ciconst CONFIG_STATE: unknown = {
40fb726d48Sopenharmony_ci  'VSync': ['vsyncValue', 'VsyncGeneratior'],
41fb726d48Sopenharmony_ci  'Start&Finish Trace Category': ['catValue', 'Business first'],
42fb726d48Sopenharmony_ci  'Hangs Detection': ['hangValue', 'Instant'],
43fb726d48Sopenharmony_ci};
44fb726d48Sopenharmony_ci
45fb726d48Sopenharmony_ci@element('sp-flags')
46fb726d48Sopenharmony_ciexport class SpFlags extends BaseElement {
47fb726d48Sopenharmony_ci  private bodyEl: HTMLElement | undefined | null;
48fb726d48Sopenharmony_ci  private xiaoLubanEl: Element | null | undefined;
49fb726d48Sopenharmony_ci
50fb726d48Sopenharmony_ci  initElements(): void {
51fb726d48Sopenharmony_ci    let parentElement = this.parentNode as HTMLElement;
52fb726d48Sopenharmony_ci    parentElement.style.overflow = 'hidden';
53fb726d48Sopenharmony_ci    this.bodyEl = this.shadowRoot?.querySelector('.body');
54fb726d48Sopenharmony_ci    this.initConfigList();
55fb726d48Sopenharmony_ci  }
56fb726d48Sopenharmony_ci
57fb726d48Sopenharmony_ci  initHtml(): string {
58fb726d48Sopenharmony_ci    return SpFlagHtml;
59fb726d48Sopenharmony_ci  }
60fb726d48Sopenharmony_ci
61fb726d48Sopenharmony_ci  private createConfigDiv(): HTMLDivElement {
62fb726d48Sopenharmony_ci    let configDiv = document.createElement('div');
63fb726d48Sopenharmony_ci    configDiv.className = 'flag-widget';
64fb726d48Sopenharmony_ci    return configDiv;
65fb726d48Sopenharmony_ci  }
66fb726d48Sopenharmony_ci  //控制按钮设置为'Disabled'时,我们需要给一个默认值
67fb726d48Sopenharmony_ci  private createCustomDiv(config: FlagConfigItem, configDiv: HTMLDivElement): void {
68fb726d48Sopenharmony_ci    let configHadDiv = document.createElement('div');
69fb726d48Sopenharmony_ci    configHadDiv.className = 'flag-head-div';
70fb726d48Sopenharmony_ci    let titleLabel = document.createElement('label');
71fb726d48Sopenharmony_ci    titleLabel.textContent = config.title;
72fb726d48Sopenharmony_ci    titleLabel.className = 'flag-title-label';
73fb726d48Sopenharmony_ci    let configSelect = document.createElement('select');
74fb726d48Sopenharmony_ci    configSelect.className = 'flag-select';
75fb726d48Sopenharmony_ci    configSelect.setAttribute('title', config.title);
76fb726d48Sopenharmony_ci    config.switchOptions.forEach((optionItem) => {
77fb726d48Sopenharmony_ci      let configOption = document.createElement('option');
78fb726d48Sopenharmony_ci      configOption.value = optionItem.option;
79fb726d48Sopenharmony_ci      configOption.textContent = optionItem.option;
80fb726d48Sopenharmony_ci      if (optionItem.selected) {
81fb726d48Sopenharmony_ci        configOption.selected = true;
82fb726d48Sopenharmony_ci      }
83fb726d48Sopenharmony_ci      configSelect.appendChild(configOption);
84fb726d48Sopenharmony_ci    });
85fb726d48Sopenharmony_ci    // 页面刷新时,选项并未改变,小鲁班也应当展示
86fb726d48Sopenharmony_ci    this.xiaoLubanEl = document.querySelector('sp-application')?.shadowRoot?.querySelector('#sp-bubbles')
87fb726d48Sopenharmony_ci      ?.shadowRoot?.querySelector('#xiao-luban-help');
88fb726d48Sopenharmony_ci    if (configSelect.title === 'AI' && configSelect.selectedOptions[0].value === 'Enabled') {
89fb726d48Sopenharmony_ci      this.xiaoLubanEl?.setAttribute('enabled', '');
90fb726d48Sopenharmony_ci    }
91fb726d48Sopenharmony_ci    configSelect.addEventListener('change', () => {
92fb726d48Sopenharmony_ci      this.flagSelectListener(configSelect);
93fb726d48Sopenharmony_ci      if (configSelect.title === 'AI') {
94fb726d48Sopenharmony_ci        let userIdInput: HTMLInputElement | null | undefined = this.shadowRoot?.querySelector('#user_id_input');
95fb726d48Sopenharmony_ci        if (configSelect.selectedOptions[0].value === 'Enabled') {
96fb726d48Sopenharmony_ci          if (userIdInput?.value === '') {
97fb726d48Sopenharmony_ci            userIdInput.style.border = '1px solid red';
98fb726d48Sopenharmony_ci          }
99fb726d48Sopenharmony_ci          this.xiaoLubanEl?.setAttribute('enabled', '');
100fb726d48Sopenharmony_ci        } else {
101fb726d48Sopenharmony_ci          userIdInput!.style.border = '1px solid #ccc';
102fb726d48Sopenharmony_ci          this.xiaoLubanEl?.removeAttribute('enabled');
103fb726d48Sopenharmony_ci        }
104fb726d48Sopenharmony_ci      }
105fb726d48Sopenharmony_ci    });
106fb726d48Sopenharmony_ci    let userIdInput: HTMLInputElement | null | undefined = this.shadowRoot?.querySelector('#user_id_input');
107fb726d48Sopenharmony_ci    if (configSelect.title === 'AI' && configSelect.selectedOptions[0].value === 'Enabled' && userIdInput?.value === '') {
108fb726d48Sopenharmony_ci      userIdInput.style.border = '1px solid red';
109fb726d48Sopenharmony_ci    }
110fb726d48Sopenharmony_ci    let description = document.createElement('div');
111fb726d48Sopenharmony_ci    description.className = 'flag-des-div';
112fb726d48Sopenharmony_ci    description.textContent = config.describeContent;
113fb726d48Sopenharmony_ci    configHadDiv.appendChild(titleLabel);
114fb726d48Sopenharmony_ci    configHadDiv.appendChild(configSelect);
115fb726d48Sopenharmony_ci    configDiv.appendChild(configHadDiv);
116fb726d48Sopenharmony_ci    configDiv.appendChild(description);
117fb726d48Sopenharmony_ci  }
118fb726d48Sopenharmony_ci  //监听flag-select的状态选择
119fb726d48Sopenharmony_ci  private flagSelectListener(configSelect: HTMLSelectElement): void {
120fb726d48Sopenharmony_ci    // @ts-ignore
121fb726d48Sopenharmony_ci    let title = configSelect.getAttribute('title');
122fb726d48Sopenharmony_ci    //@ts-ignore
123fb726d48Sopenharmony_ci    let listSelect = this.shadowRoot?.querySelector(`#${CONFIG_STATE[title]?.[0]}`);
124fb726d48Sopenharmony_ci    // @ts-ignore
125fb726d48Sopenharmony_ci    FlagsConfig.updateFlagsConfig(title!, configSelect.selectedOptions[0].value);
126fb726d48Sopenharmony_ci    //@ts-ignore
127fb726d48Sopenharmony_ci    if (listSelect) {
128fb726d48Sopenharmony_ci      // @ts-ignore
129fb726d48Sopenharmony_ci      if (configSelect.selectedOptions[0].value === 'Enabled') {
130fb726d48Sopenharmony_ci        listSelect?.removeAttribute('disabled');
131fb726d48Sopenharmony_ci      } else {
132fb726d48Sopenharmony_ci        listSelect?.childNodes.forEach((child: ChildNode) => {
133fb726d48Sopenharmony_ci          let selectEl = child as HTMLOptionElement;
134fb726d48Sopenharmony_ci          //@ts-ignore
135fb726d48Sopenharmony_ci          if (child.textContent === CONFIG_STATE[title]?.[1]) {
136fb726d48Sopenharmony_ci            selectEl.selected = true;
137fb726d48Sopenharmony_ci            //@ts-ignore
138fb726d48Sopenharmony_ci            FlagsConfig.updateFlagsConfig(CONFIG_STATE[title]?.[0], selectEl.value);
139fb726d48Sopenharmony_ci          } else {
140fb726d48Sopenharmony_ci            selectEl.selected = false;
141fb726d48Sopenharmony_ci          }
142fb726d48Sopenharmony_ci        });
143fb726d48Sopenharmony_ci        listSelect?.setAttribute('disabled', 'disabled');
144fb726d48Sopenharmony_ci      }
145fb726d48Sopenharmony_ci    }
146fb726d48Sopenharmony_ci  }
147fb726d48Sopenharmony_ci
148fb726d48Sopenharmony_ci  //初始化Flag对应的内容
149fb726d48Sopenharmony_ci  private initConfigList(): void {
150fb726d48Sopenharmony_ci    let allConfig = FlagsConfig.getAllFlagConfig();
151fb726d48Sopenharmony_ci    allConfig.forEach((config) => {
152fb726d48Sopenharmony_ci      let configDiv = this.createConfigDiv();
153fb726d48Sopenharmony_ci      this.createCustomDiv(config, configDiv);
154fb726d48Sopenharmony_ci      if (config.title === 'AnimationAnalysis') {
155fb726d48Sopenharmony_ci        let configFooterDiv = document.createElement('div');
156fb726d48Sopenharmony_ci        configFooterDiv.className = 'config_footer';
157fb726d48Sopenharmony_ci        let deviceWidthLabelEl = document.createElement('label');
158fb726d48Sopenharmony_ci        deviceWidthLabelEl.className = 'device_label';
159fb726d48Sopenharmony_ci        deviceWidthLabelEl.textContent = 'PhysicalWidth :';
160fb726d48Sopenharmony_ci        let deviceWidthEl = document.createElement('input');
161fb726d48Sopenharmony_ci        deviceWidthEl.value = <string>config.addInfo!.physicalWidth;
162fb726d48Sopenharmony_ci        deviceWidthEl.addEventListener('keyup', () => {
163fb726d48Sopenharmony_ci          deviceWidthEl.value = deviceWidthEl.value.replace(/\D/g, '');
164fb726d48Sopenharmony_ci        });
165fb726d48Sopenharmony_ci        deviceWidthEl.addEventListener('blur', () => {
166fb726d48Sopenharmony_ci          if (deviceWidthEl.value !== '') {
167fb726d48Sopenharmony_ci            FlagsConfig.updateFlagsConfig('physicalWidth', Number(deviceWidthEl.value));
168fb726d48Sopenharmony_ci          }
169fb726d48Sopenharmony_ci        });
170fb726d48Sopenharmony_ci        deviceWidthEl.className = 'device_input';
171fb726d48Sopenharmony_ci        let deviceHeightLabelEl = document.createElement('label');
172fb726d48Sopenharmony_ci        deviceHeightLabelEl.textContent = 'PhysicalHeight :';
173fb726d48Sopenharmony_ci        deviceHeightLabelEl.className = 'device_label';
174fb726d48Sopenharmony_ci        let deviceHeightEl = document.createElement('input');
175fb726d48Sopenharmony_ci        deviceHeightEl.className = 'device_input';
176fb726d48Sopenharmony_ci        deviceHeightEl.value = <string>config.addInfo!.physicalHeight;
177fb726d48Sopenharmony_ci        deviceHeightEl.addEventListener('keyup', () => {
178fb726d48Sopenharmony_ci          deviceHeightEl.value = deviceHeightEl.value.replace(/\D/g, '');
179fb726d48Sopenharmony_ci        });
180fb726d48Sopenharmony_ci        deviceHeightEl.addEventListener('blur', () => {
181fb726d48Sopenharmony_ci          if (deviceWidthEl.value !== '') {
182fb726d48Sopenharmony_ci            FlagsConfig.updateFlagsConfig('physicalHeight', Number(deviceHeightEl.value));
183fb726d48Sopenharmony_ci          }
184fb726d48Sopenharmony_ci        });
185fb726d48Sopenharmony_ci        configFooterDiv.appendChild(deviceWidthLabelEl);
186fb726d48Sopenharmony_ci        configFooterDiv.appendChild(deviceWidthEl);
187fb726d48Sopenharmony_ci        configFooterDiv.appendChild(deviceHeightLabelEl);
188fb726d48Sopenharmony_ci        configFooterDiv.appendChild(deviceHeightEl);
189fb726d48Sopenharmony_ci        configDiv.appendChild(configFooterDiv);
190fb726d48Sopenharmony_ci      }
191fb726d48Sopenharmony_ci      //@ts-ignore
192fb726d48Sopenharmony_ci      let configKey = CONFIG_STATE[config.title]?.[0];
193fb726d48Sopenharmony_ci      if (config.title === 'VSync') {//初始化Vsync
194fb726d48Sopenharmony_ci        let configFooterDiv = this.createPersonOption(VSYNC_CONTENT, configKey, config);
195fb726d48Sopenharmony_ci        configDiv.appendChild(configFooterDiv);
196fb726d48Sopenharmony_ci      }
197fb726d48Sopenharmony_ci
198fb726d48Sopenharmony_ci      if (config.title === 'Start&Finish Trace Category') {//初始化Start&Finish Trace Category
199fb726d48Sopenharmony_ci        let configFooterDiv = this.createPersonOption(CAT_CONTENT, configKey, config);
200fb726d48Sopenharmony_ci        configDiv.appendChild(configFooterDiv);
201fb726d48Sopenharmony_ci      }
202fb726d48Sopenharmony_ci
203fb726d48Sopenharmony_ci      if (config.title === 'Hangs Detection') {//初始化Hangs Detection
204fb726d48Sopenharmony_ci        let configFooterDiv = this.createPersonOption(HANG_CONTENT, configKey, config);
205fb726d48Sopenharmony_ci        configDiv.appendChild(configFooterDiv);
206fb726d48Sopenharmony_ci      }
207fb726d48Sopenharmony_ci      if (config.title === 'AI') {
208fb726d48Sopenharmony_ci        let configFooterDiv = document.createElement('div');
209fb726d48Sopenharmony_ci        configFooterDiv.className = 'config_footer';
210fb726d48Sopenharmony_ci        let userIdLabelEl = document.createElement('label');
211fb726d48Sopenharmony_ci        userIdLabelEl.className = 'device_label';
212fb726d48Sopenharmony_ci        userIdLabelEl.textContent = 'User Id: ';
213fb726d48Sopenharmony_ci        let userIdInputEl = document.createElement('input');
214fb726d48Sopenharmony_ci        userIdInputEl.value = <string>config.addInfo!.userId;
215fb726d48Sopenharmony_ci        userIdInputEl.addEventListener('blur', () => {
216fb726d48Sopenharmony_ci          if (userIdInputEl.value !== '') {
217fb726d48Sopenharmony_ci            userIdInputEl.style.border = '1px solid #ccc';
218fb726d48Sopenharmony_ci            FlagsConfig.updateFlagsConfig('userId', userIdInputEl.value);
219fb726d48Sopenharmony_ci          } else {
220fb726d48Sopenharmony_ci            userIdInputEl.style.border = '1px solid red';
221fb726d48Sopenharmony_ci          }
222fb726d48Sopenharmony_ci        });
223fb726d48Sopenharmony_ci        userIdInputEl.className = 'device_input';
224fb726d48Sopenharmony_ci        userIdInputEl.id = 'user_id_input';
225fb726d48Sopenharmony_ci        configFooterDiv.appendChild(userIdLabelEl);
226fb726d48Sopenharmony_ci        configFooterDiv.appendChild(userIdInputEl);
227fb726d48Sopenharmony_ci        configDiv.appendChild(configFooterDiv);
228fb726d48Sopenharmony_ci      }
229fb726d48Sopenharmony_ci      this.bodyEl!.appendChild(configDiv);
230fb726d48Sopenharmony_ci    });
231fb726d48Sopenharmony_ci  }
232fb726d48Sopenharmony_ci
233fb726d48Sopenharmony_ci  private createPersonOption(list: unknown, key: string, config: unknown): HTMLDivElement {
234fb726d48Sopenharmony_ci    let configFooterDiv = document.createElement('div');
235fb726d48Sopenharmony_ci    configFooterDiv.className = 'config_footer';
236fb726d48Sopenharmony_ci    let lableEl = document.createElement('lable');
237fb726d48Sopenharmony_ci    lableEl.className = 'list_lable';
238fb726d48Sopenharmony_ci    let typeEl = document.createElement('select');
239fb726d48Sopenharmony_ci    typeEl.setAttribute('id', key);
240fb726d48Sopenharmony_ci    typeEl.className = 'flag-select';
241fb726d48Sopenharmony_ci    //根据给出的list遍历添加option下来选框
242fb726d48Sopenharmony_ci    //@ts-ignore
243fb726d48Sopenharmony_ci    for (const settings of list) {
244fb726d48Sopenharmony_ci      let option = document.createElement('option');
245fb726d48Sopenharmony_ci      option.value = settings.value;
246fb726d48Sopenharmony_ci      option.textContent = settings.content;
247fb726d48Sopenharmony_ci      //初始化二级按钮状态
248fb726d48Sopenharmony_ci      //@ts-ignore
249fb726d48Sopenharmony_ci      if (option.value === config.addInfo?.[key]) {
250fb726d48Sopenharmony_ci        option.selected = true;
251fb726d48Sopenharmony_ci        FlagsConfig.updateFlagsConfig(key, option.value);
252fb726d48Sopenharmony_ci      }
253fb726d48Sopenharmony_ci      typeEl.appendChild(option);
254fb726d48Sopenharmony_ci    }
255fb726d48Sopenharmony_ci    typeEl.addEventListener('change', function () {
256fb726d48Sopenharmony_ci      let selectValue = this.selectedOptions[0].value;
257fb726d48Sopenharmony_ci      FlagsConfig.updateFlagsConfig(key, selectValue);
258fb726d48Sopenharmony_ci    });
259fb726d48Sopenharmony_ci    let flagsItem = window.localStorage.getItem(FlagsConfig.FLAGS_CONFIG_KEY);
260fb726d48Sopenharmony_ci    let flagsItemJson = JSON.parse(flagsItem!);
261fb726d48Sopenharmony_ci    //@ts-ignore
262fb726d48Sopenharmony_ci    let vsync = flagsItemJson[config.title];
263fb726d48Sopenharmony_ci    if (vsync === 'Enabled') {
264fb726d48Sopenharmony_ci      typeEl.removeAttribute('disabled');
265fb726d48Sopenharmony_ci    } else {
266fb726d48Sopenharmony_ci      typeEl.setAttribute('disabled', 'disabled');
267fb726d48Sopenharmony_ci      //@ts-ignore
268fb726d48Sopenharmony_ci      FlagsConfig.updateFlagsConfig(key, config.addInfo?.[key]);
269fb726d48Sopenharmony_ci    }
270fb726d48Sopenharmony_ci    configFooterDiv.appendChild(lableEl);
271fb726d48Sopenharmony_ci    configFooterDiv.appendChild(typeEl);
272fb726d48Sopenharmony_ci    return configFooterDiv;
273fb726d48Sopenharmony_ci  }
274fb726d48Sopenharmony_ci}
275fb726d48Sopenharmony_ci
276fb726d48Sopenharmony_ciexport type Params = {
277fb726d48Sopenharmony_ci  [key: string]: unknown;
278fb726d48Sopenharmony_ci};
279fb726d48Sopenharmony_ci
280fb726d48Sopenharmony_ciexport class FlagsConfig {
281fb726d48Sopenharmony_ci  static FLAGS_CONFIG_KEY = 'FlagsConfig';
282fb726d48Sopenharmony_ci  static DEFAULT_CONFIG: Array<FlagConfigItem> = [
283fb726d48Sopenharmony_ci    {
284fb726d48Sopenharmony_ci      title: 'TaskPool',
285fb726d48Sopenharmony_ci      switchOptions: [{ option: 'Enabled' }, { option: 'Disabled', selected: true }],
286fb726d48Sopenharmony_ci      describeContent: 'Analyze TaskPool templates',
287fb726d48Sopenharmony_ci    },
288fb726d48Sopenharmony_ci    {
289fb726d48Sopenharmony_ci      title: 'AnimationAnalysis',
290fb726d48Sopenharmony_ci      switchOptions: [{ option: 'Enabled' }, { option: 'Disabled', selected: true }],
291fb726d48Sopenharmony_ci      describeContent: 'Analyze Animation effect templates',
292fb726d48Sopenharmony_ci      addInfo: { physicalWidth: 0, physicalHeight: 0 },
293fb726d48Sopenharmony_ci    },
294fb726d48Sopenharmony_ci    {
295fb726d48Sopenharmony_ci      title: 'AppStartup',
296fb726d48Sopenharmony_ci      switchOptions: [{ option: 'Enabled' }, { option: 'Disabled', selected: true }],
297fb726d48Sopenharmony_ci      describeContent: 'App Startup templates',
298fb726d48Sopenharmony_ci    },
299fb726d48Sopenharmony_ci    {
300fb726d48Sopenharmony_ci      title: 'SchedulingAnalysis',
301fb726d48Sopenharmony_ci      switchOptions: [{ option: 'Enabled' }, { option: 'Disabled', selected: true }],
302fb726d48Sopenharmony_ci      describeContent: 'Scheduling analysis templates',
303fb726d48Sopenharmony_ci    },
304fb726d48Sopenharmony_ci    {
305fb726d48Sopenharmony_ci      title: 'BinderRunnable',
306fb726d48Sopenharmony_ci      switchOptions: [{ option: 'Enabled' }, { option: 'Disabled', selected: true }],
307fb726d48Sopenharmony_ci      describeContent: 'support Cpu State Binder-Runnable',
308fb726d48Sopenharmony_ci    },
309fb726d48Sopenharmony_ci    {
310fb726d48Sopenharmony_ci      title: 'FfrtConvert',
311fb726d48Sopenharmony_ci      switchOptions: [{ option: 'Enabled' }, { option: 'Disabled', selected: true }],
312fb726d48Sopenharmony_ci      describeContent: 'Ffrt Convert templates',
313fb726d48Sopenharmony_ci    },
314fb726d48Sopenharmony_ci    {
315fb726d48Sopenharmony_ci      title: 'HMKernel',
316fb726d48Sopenharmony_ci      switchOptions: [{ option: 'Enabled' }, { option: 'Disabled', selected: true }],
317fb726d48Sopenharmony_ci      describeContent: '',
318fb726d48Sopenharmony_ci    },
319fb726d48Sopenharmony_ci    {
320fb726d48Sopenharmony_ci      title: 'VSync',
321fb726d48Sopenharmony_ci      switchOptions: [{ option: 'Enabled' }, { option: 'Disabled', selected: true }],
322fb726d48Sopenharmony_ci      describeContent: 'VSync Signal drawing',
323fb726d48Sopenharmony_ci      addInfo: { vsyncValue: VSYNC_CONTENT[0].value },
324fb726d48Sopenharmony_ci    },
325fb726d48Sopenharmony_ci    {
326fb726d48Sopenharmony_ci      title: 'Hangs Detection',
327fb726d48Sopenharmony_ci      switchOptions: [{ option: 'Enabled' }, { option: 'Disabled', selected: true }],
328fb726d48Sopenharmony_ci      describeContent: 'hangs type:Instant(33ms~100ms),Circumstantial(100ms~250ms),Micro(250ms~500ms),Severe(>=500ms)',
329fb726d48Sopenharmony_ci      addInfo: { hangValue: HANG_CONTENT[0].value },
330fb726d48Sopenharmony_ci    },
331fb726d48Sopenharmony_ci    {
332fb726d48Sopenharmony_ci      title: 'LTPO',
333fb726d48Sopenharmony_ci      switchOptions: [{ option: 'Enabled' }, { option: 'Disabled', selected: true }],
334fb726d48Sopenharmony_ci      describeContent: 'Lost Frame and HitchTime templates',
335fb726d48Sopenharmony_ci    },
336fb726d48Sopenharmony_ci    {
337fb726d48Sopenharmony_ci      title: 'Start&Finish Trace Category',
338fb726d48Sopenharmony_ci      switchOptions: [{ option: 'Enabled' }, { option: 'Disabled', selected: true }],
339fb726d48Sopenharmony_ci      describeContent: 'Asynchronous trace aggregation',
340fb726d48Sopenharmony_ci      addInfo: { catValue: CAT_CONTENT[0].value },
341fb726d48Sopenharmony_ci    },
342fb726d48Sopenharmony_ci    {
343fb726d48Sopenharmony_ci      title: 'UserPluginsRow',
344fb726d48Sopenharmony_ci      switchOptions: [{ option: 'Enabled' }, { option: 'Disabled', selected: true }],
345fb726d48Sopenharmony_ci      describeContent: 'User Upload Plugin To Draw',
346fb726d48Sopenharmony_ci    },
347fb726d48Sopenharmony_ci    {
348fb726d48Sopenharmony_ci      title: 'CPU by Irq',
349fb726d48Sopenharmony_ci      switchOptions: [{ option: 'Enabled' }, { option: 'Disabled', selected: true }],
350fb726d48Sopenharmony_ci      describeContent: 'The real CPU after being split by irq and softirq',
351fb726d48Sopenharmony_ci    },
352fb726d48Sopenharmony_ci    {
353fb726d48Sopenharmony_ci      title: 'RawTraceCutStartTs',
354fb726d48Sopenharmony_ci      switchOptions: [{ option: 'Enabled', selected: true }, { option: 'Disabled' }],
355fb726d48Sopenharmony_ci      describeContent: 'Raw Trace Cut By StartTs, StartTs = Max(Cpu1 StartTs, Cpu2 StartTs, ..., CpuN StartTs)',
356fb726d48Sopenharmony_ci    },
357fb726d48Sopenharmony_ci    {
358fb726d48Sopenharmony_ci      title: 'AI',
359fb726d48Sopenharmony_ci      switchOptions: [{ option: 'Enabled' }, { option: 'Disabled', selected: true }],
360fb726d48Sopenharmony_ci      describeContent: 'Start AI',
361fb726d48Sopenharmony_ci      addInfo: { userId: '' },
362fb726d48Sopenharmony_ci    }
363fb726d48Sopenharmony_ci  ];
364fb726d48Sopenharmony_ci
365fb726d48Sopenharmony_ci  static getAllFlagConfig(): Array<FlagConfigItem> {
366fb726d48Sopenharmony_ci    let flagsConfigStr = window.localStorage.getItem(FlagsConfig.FLAGS_CONFIG_KEY);
367fb726d48Sopenharmony_ci    if (flagsConfigStr === null) {
368fb726d48Sopenharmony_ci      let flagConfigObj: Params = {};
369fb726d48Sopenharmony_ci      FlagsConfig.DEFAULT_CONFIG.forEach((config) => {
370fb726d48Sopenharmony_ci        let selectedOption = config.switchOptions.filter((option) => {
371fb726d48Sopenharmony_ci          return option.selected;
372fb726d48Sopenharmony_ci        });
373fb726d48Sopenharmony_ci        let value = config.switchOptions[0].option;
374fb726d48Sopenharmony_ci        if (selectedOption[0] !== undefined) {
375fb726d48Sopenharmony_ci          value = selectedOption[0].option;
376fb726d48Sopenharmony_ci        }
377fb726d48Sopenharmony_ci        flagConfigObj[config.title] = value;
378fb726d48Sopenharmony_ci        if (config.addInfo) {
379fb726d48Sopenharmony_ci          for (const [key, value] of Object.entries(config.addInfo)) {
380fb726d48Sopenharmony_ci            flagConfigObj[key] = value;
381fb726d48Sopenharmony_ci          }
382fb726d48Sopenharmony_ci        }
383fb726d48Sopenharmony_ci      });
384fb726d48Sopenharmony_ci      window.localStorage.setItem(FlagsConfig.FLAGS_CONFIG_KEY, JSON.stringify(flagConfigObj));
385fb726d48Sopenharmony_ci      return FlagsConfig.DEFAULT_CONFIG;
386fb726d48Sopenharmony_ci    } else {
387fb726d48Sopenharmony_ci      let flagsConfig = JSON.parse(flagsConfigStr);
388fb726d48Sopenharmony_ci      FlagsConfig.DEFAULT_CONFIG.forEach((config) => {
389fb726d48Sopenharmony_ci        let cfg = flagsConfig[config.title];
390fb726d48Sopenharmony_ci        if (cfg) {
391fb726d48Sopenharmony_ci          config.switchOptions.forEach((option) => {
392fb726d48Sopenharmony_ci            if (option.option === cfg) {
393fb726d48Sopenharmony_ci              option.selected = true;
394fb726d48Sopenharmony_ci            } else {
395fb726d48Sopenharmony_ci              option.selected = false;
396fb726d48Sopenharmony_ci            }
397fb726d48Sopenharmony_ci          });
398fb726d48Sopenharmony_ci        }
399fb726d48Sopenharmony_ci        if (config.addInfo) {
400fb726d48Sopenharmony_ci          for (const [key, value] of Object.entries(config.addInfo)) {
401fb726d48Sopenharmony_ci            let cfg = flagsConfig[key];
402fb726d48Sopenharmony_ci            if (cfg) {
403fb726d48Sopenharmony_ci              config.addInfo[key] = cfg;
404fb726d48Sopenharmony_ci            }
405fb726d48Sopenharmony_ci          }
406fb726d48Sopenharmony_ci        }
407fb726d48Sopenharmony_ci      });
408fb726d48Sopenharmony_ci    }
409fb726d48Sopenharmony_ci    return FlagsConfig.DEFAULT_CONFIG;
410fb726d48Sopenharmony_ci  }
411fb726d48Sopenharmony_ci
412fb726d48Sopenharmony_ci  static getSpTraceStreamParseConfig(): string {
413fb726d48Sopenharmony_ci    let parseConfig = {};
414fb726d48Sopenharmony_ci    FlagsConfig.getAllFlagConfig().forEach((configItem) => {
415fb726d48Sopenharmony_ci      let selectedOption = configItem.switchOptions.filter((option) => {
416fb726d48Sopenharmony_ci        return option.selected;
417fb726d48Sopenharmony_ci      });
418fb726d48Sopenharmony_ci      // @ts-ignore
419fb726d48Sopenharmony_ci      parseConfig[configItem.title] = selectedOption[0].option === 'Enabled' ? 1 : 0;
420fb726d48Sopenharmony_ci    });
421fb726d48Sopenharmony_ci    return JSON.stringify({ config: parseConfig });
422fb726d48Sopenharmony_ci  }
423fb726d48Sopenharmony_ci
424fb726d48Sopenharmony_ci  static getFlagsConfig(flagName: string): Params | undefined {
425fb726d48Sopenharmony_ci    let flagConfigObj: Params = {};
426fb726d48Sopenharmony_ci    let configItem = FlagsConfig.getAllFlagConfig().find((config) => {
427fb726d48Sopenharmony_ci      return config.title === flagName;
428fb726d48Sopenharmony_ci    });
429fb726d48Sopenharmony_ci    if (configItem) {
430fb726d48Sopenharmony_ci      let selectedOption = configItem.switchOptions.filter((option) => {
431fb726d48Sopenharmony_ci        return option.selected;
432fb726d48Sopenharmony_ci      });
433fb726d48Sopenharmony_ci      let value = configItem.switchOptions[0].option;
434fb726d48Sopenharmony_ci      if (selectedOption[0] !== undefined) {
435fb726d48Sopenharmony_ci        value = selectedOption[0].option;
436fb726d48Sopenharmony_ci      }
437fb726d48Sopenharmony_ci      flagConfigObj[configItem.title] = value;
438fb726d48Sopenharmony_ci      if (configItem.addInfo) {
439fb726d48Sopenharmony_ci        for (const [key, value] of Object.entries(configItem.addInfo)) {
440fb726d48Sopenharmony_ci          flagConfigObj[key] = value;
441fb726d48Sopenharmony_ci        }
442fb726d48Sopenharmony_ci      }
443fb726d48Sopenharmony_ci      return flagConfigObj;
444fb726d48Sopenharmony_ci    } else {
445fb726d48Sopenharmony_ci      return configItem;
446fb726d48Sopenharmony_ci    }
447fb726d48Sopenharmony_ci  }
448fb726d48Sopenharmony_ci
449fb726d48Sopenharmony_ci  static getFlagsConfigEnableStatus(flagName: string): boolean {
450fb726d48Sopenharmony_ci    let config = FlagsConfig.getFlagsConfig(flagName);
451fb726d48Sopenharmony_ci    let enable: boolean = false;
452fb726d48Sopenharmony_ci    if (config && config[flagName]) {
453fb726d48Sopenharmony_ci      enable = config[flagName] === 'Enabled';
454fb726d48Sopenharmony_ci    }
455fb726d48Sopenharmony_ci    return enable;
456fb726d48Sopenharmony_ci  }
457fb726d48Sopenharmony_ci  //获取Cat的二级下拉选框所选的内容
458fb726d48Sopenharmony_ci  static getSecondarySelectValue(value: string): string {
459fb726d48Sopenharmony_ci    let list = window.localStorage.getItem(FlagsConfig.FLAGS_CONFIG_KEY);
460fb726d48Sopenharmony_ci    let listJson = JSON.parse(list!);
461fb726d48Sopenharmony_ci    let catSelectValue = listJson[value];
462fb726d48Sopenharmony_ci    return catSelectValue;
463fb726d48Sopenharmony_ci  }
464fb726d48Sopenharmony_ci
465fb726d48Sopenharmony_ci  static updateFlagsConfig(key: string, value: unknown): void {
466fb726d48Sopenharmony_ci    let flagsConfigStr = window.localStorage.getItem(FlagsConfig.FLAGS_CONFIG_KEY);
467fb726d48Sopenharmony_ci    let flagConfigObj: Params = {};
468fb726d48Sopenharmony_ci    if (flagsConfigStr !== null) {
469fb726d48Sopenharmony_ci      flagConfigObj = JSON.parse(flagsConfigStr);
470fb726d48Sopenharmony_ci    }
471fb726d48Sopenharmony_ci    flagConfigObj[key] = value;
472fb726d48Sopenharmony_ci    window.localStorage.setItem(FlagsConfig.FLAGS_CONFIG_KEY, JSON.stringify(flagConfigObj));
473fb726d48Sopenharmony_ci  }
474fb726d48Sopenharmony_ci}
475fb726d48Sopenharmony_ci
476fb726d48Sopenharmony_ciexport interface FlagConfigItem {
477fb726d48Sopenharmony_ci  title: string;
478fb726d48Sopenharmony_ci  switchOptions: OptionItem[];
479fb726d48Sopenharmony_ci  describeContent: string;
480fb726d48Sopenharmony_ci  addInfo?: Params;
481fb726d48Sopenharmony_ci}
482fb726d48Sopenharmony_ci
483fb726d48Sopenharmony_ciexport interface OptionItem {
484fb726d48Sopenharmony_ci  option: string;
485fb726d48Sopenharmony_ci  selected?: boolean;
486fb726d48Sopenharmony_ci}
487