1/*
2 * Copyright (C) 2022 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16import {PersistentStoreProxy} from 'common/persistent_store_proxy';
17import {Store} from 'common/store';
18import {Trace} from 'trace/trace';
19import {Traces} from 'trace/traces';
20import {TraceType} from 'trace/trace_type';
21import {HierarchyTreeNode} from 'trace/tree_node/hierarchy_tree_node';
22import {NotifyHierarchyViewCallbackType} from 'viewers/common/abstract_hierarchy_viewer_presenter';
23import {AbstractPresenterInputMethod} from 'viewers/common/abstract_presenter_input_method';
24import {VISIBLE_CHIP} from 'viewers/common/chip';
25import {HierarchyPresenter} from 'viewers/common/hierarchy_presenter';
26import {ImeUiData} from 'viewers/common/ime_ui_data';
27import {UpdateSfSubtreeDisplayNames} from 'viewers/common/operations/update_sf_subtree_display_names';
28import {TableProperties} from 'viewers/common/table_properties';
29import {TextFilter} from 'viewers/common/text_filter';
30import {UserOptions} from 'viewers/common/user_options';
31import {UpdateDisplayNames} from './operations/update_display_names';
32
33export class PresenterInputMethodClients extends AbstractPresenterInputMethod {
34  protected override hierarchyPresenter = new HierarchyPresenter(
35    PersistentStoreProxy.new<UserOptions>(
36      'ImeHierarchyOptions',
37      {
38        simplifyNames: {
39          name: 'Simplify names',
40          enabled: true,
41        },
42        showOnlyVisible: {
43          name: 'Show only',
44          chip: VISIBLE_CHIP,
45          enabled: false,
46        },
47        flat: {
48          name: 'Flat',
49          enabled: false,
50        },
51      },
52      this.storage,
53    ),
54    new TextFilter(),
55    [],
56    true,
57    false,
58    this.getHierarchyTreeNameStrategy,
59    [
60      [TraceType.SURFACE_FLINGER, [new UpdateSfSubtreeDisplayNames()]],
61      [TraceType.INPUT_METHOD_CLIENTS, [new UpdateDisplayNames()]],
62    ],
63  );
64  constructor(
65    trace: Trace<HierarchyTreeNode>,
66    traces: Traces,
67    storage: Store,
68    notifyViewCallback: NotifyHierarchyViewCallbackType<ImeUiData>,
69  ) {
70    super(trace, traces, storage, notifyViewCallback);
71  }
72
73  protected override getHierarchyTableProperties(): TableProperties {
74    const client = this.hierarchyPresenter
75      .getCurrentHierarchyTreesForTrace(this.imeTrace)
76      ?.at(0)
77      ?.getChildByName('client');
78    const curId = client
79      ?.getEagerPropertyByName('inputMethodManager')
80      ?.getChildByName('curId')
81      ?.formattedValue();
82    const packageName = client
83      ?.getEagerPropertyByName('editorInfo')
84      ?.getChildByName('packageName')
85      ?.formattedValue();
86    return {
87      ...new ImClientsTableProperties(curId, packageName),
88    };
89  }
90}
91
92class ImClientsTableProperties {
93  constructor(
94    public inputMethodId: string | undefined,
95    public packageName: string | undefined,
96  ) {}
97}
98