1 /*
2 * Copyright (c) 2020 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 #include "app_info_ability_slice.h"
17 #include "gfx_utils/style.h"
18
19 namespace OHOS {
REGISTER_AS(AppInfoAbilitySlice)20 REGISTER_AS(AppInfoAbilitySlice)
21
22 AppInfoAbilitySlice::~AppInfoAbilitySlice()
23 {
24 if (scrollView_) {
25 DeleteChildren(scrollView_);
26 scrollView_ = nullptr;
27 }
28
29 if (headView_) {
30 DeleteChildren(headView_);
31 headView_ = nullptr;
32 }
33
34 if (!buttonBackListener_) {
35 delete buttonBackListener_;
36 buttonBackListener_ = nullptr;
37 }
38
39 if (permissions_) {
40 free(permissions_);
41 }
42 ListNode<ToggBtnOnListener*>* node = listListener_.Begin();
43 while (node != listListener_.End()) {
44 delete node->data_;
45 node = node->next_;
46 }
47 listListener_.Clear();
48 }
49
SetButtonListener(void)50 void AppInfoAbilitySlice::SetButtonListener(void)
51 {
52 auto onClick = [this](UIView& view, const Event& event) -> bool {
53 Terminate();
54 return true;
55 };
56 buttonBackListener_ = new EventListener(onClick, nullptr);
57 }
58
SetHead()59 void AppInfoAbilitySlice::SetHead()
60 {
61 headView_ = new UIViewGroup();
62 rootView_->Add(headView_);
63 headView_->SetPosition(DE_HEAD_X, DE_HEAD_Y, DE_HEAD_WIDTH, DE_HEAD_HEIGHT);
64 headView_->SetStyle(STYLE_BACKGROUND_OPA, 0);
65 headView_->SetTouchable(true);
66 headView_->SetOnClickListener(buttonBackListener_);
67
68 UIImageView* imageView = new UIImageView();
69 headView_->Add(imageView);
70 imageView->SetPosition(DE_HEAD_IMAGE_X, DE_HEAD_IMAGE_Y, DE_HEAD_IMAGE_WIDTH, DE_HEAD_IMAGE_HEIGHT);
71 imageView->SetSrc(DE_IMAGE_BACK);
72
73 printf("[LOG] bundleName_-> %s +11->%s \n", bundleName_, bundleName_ + 11); // 11:jump behind bundleName
74 UILabel* lablelFont = new UILabel();
75 lablelFont->SetPosition(DE_HEAD_TEXT_X, DE_HEAD_TEXT_Y, DE_HEAD_TEXT_WIDTH, DE_HEAD_TEXT_HEIGHT);
76 lablelFont->SetText(bundleName_ + 11); // 11:jump behind bundleName
77 lablelFont->SetFont(DE_FONT_OTF, DE_HEAD_TEXT_SIZE);
78 lablelFont->SetStyle(STYLE_TEXT_COLOR, DE_HEAD_TEXT_COLOR);
79 headView_->Add(lablelFont);
80 }
81
SetAppPermissionInfo(int index,PermissionSaved & permissions)82 void AppInfoAbilitySlice::SetAppPermissionInfo(int index, PermissionSaved& permissions)
83 {
84 UIViewGroup* itemView = new UIViewGroup();
85 if (itemView == nullptr) {
86 return;
87 }
88 int useX = 0;
89 int useY = index * DE_ITEM_INTERVAL;
90 itemView->SetPosition(useX, useY, DE_BUTTON_WIDTH, DE_BUTTON_HEIGHT);
91 itemView->SetStyle(STYLE_BACKGROUND_COLOR, DE_BUTTON_BACKGROUND_COLOR);
92 itemView->SetStyle(STYLE_BACKGROUND_OPA, DE_OPACITY_ALL);
93 itemView->SetStyle(STYLE_BORDER_RADIUS, DE_BUTTON_RADIUS);
94 scrollView_->Add(itemView);
95
96 UILabel* nameLabel = new UILabel();
97 nameLabel->SetPosition(DE_TITLE_TEXT_X, DE_TITLE_TEXT_Y, DE_TITLE_TEXT_WIDTH, DE_TITLE_TEXT_HEIGHT);
98 nameLabel->SetText(permissions.name + 16); // 16 is get offset name
99 nameLabel->SetFont(DE_FONT_OTF, DE_TITLE_TEXT_SIZE);
100 nameLabel->SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER);
101 nameLabel->SetStyle(STYLE_TEXT_COLOR, DE_TITLE_TEXT_COLOR);
102 itemView->Add(nameLabel);
103 UIToggleButton* togglebutton = new UIToggleButton();
104 togglebutton->SetPosition(DE_TOGGLE_BUTTON_X, DE_TOGGLE_BUTTON_Y);
105 if (permissions.granted == 0) {
106 togglebutton->SetState(false);
107 } else {
108 togglebutton->SetState(true);
109 }
110 ToggBtnOnListener* listener = new ToggBtnOnListener(togglebutton);
111 listener->SetPermissionName(permissions.name, strlen(permissions.name));
112 listener->SetBundleName(bundleName_, strlen(bundleName_));
113 togglebutton->SetOnClickListener(listener);
114 listListener_.PushBack(listener);
115 itemView->Add(togglebutton);
116 }
117
PermissionInfoList()118 void AppInfoAbilitySlice::PermissionInfoList()
119 {
120 int permNum = 0;
121 scrollView_ = new UIScrollView();
122 scrollView_->SetStyle(STYLE_BACKGROUND_COLOR, DE_SCROLL_COLOR);
123 scrollView_->SetPosition(DE_SCROLL_X, DE_SCROLL_Y, DE_SCROLL_WIDTH, DE_SCROLL_HEIGHT);
124 scrollView_->SetXScrollBarVisible(false);
125 scrollView_->SetYScrollBarVisible(true);
126 rootView_->Add(scrollView_);
127 int ret = QueryPermission(bundleName_, &permissions_, &permNum);
128 if (ret == 0) {
129 printf("[LOG]PermissionInfoList bundleName_ -> %s ,permNum->%d\n", bundleName_, permNum);
130 for (int i = 0; i < permNum; i++) {
131 if (permissions_ != nullptr) {
132 printf("[LOG]PermissionInfoList xxx -> name %s \n", permissions_->name);
133 SetAppPermissionInfo(i, permissions_[i]);
134 }
135 }
136 }
137 }
138
OnStart(const Want & want)139 void AppInfoAbilitySlice::OnStart(const Want& want)
140 {
141 int ret;
142 printf("[LOG]receive the data -> %s\n", static_cast<char*>(want.data));
143 AbilitySlice::OnStart(want);
144
145 ret = memcpy_s(bundleName_, sizeof(bundleName_), want.data, want.dataLength);
146 if (ret != EOK) {
147 return;
148 }
149 rootView_ = RootView::GetWindowRootView();
150 rootView_->SetPosition(DE_ROOT_X, DE_ROOT_Y, DE_ROOT_WIDTH, DE_ROOT_HEIGHT);
151 rootView_->SetStyle(STYLE_BACKGROUND_COLOR, DE_ROOT_BACKGROUND_COLOR);
152 SetButtonListener();
153 SetHead();
154 PermissionInfoList();
155 SetUIContent(rootView_);
156 }
157
OnInactive()158 void AppInfoAbilitySlice::OnInactive()
159 {
160 AbilitySlice::OnInactive();
161 }
162
OnActive(const Want & want)163 void AppInfoAbilitySlice::OnActive(const Want &want)
164 {
165 AbilitySlice::OnActive(want);
166 }
167
OnBackground()168 void AppInfoAbilitySlice::OnBackground()
169 {
170 AbilitySlice::OnBackground();
171 }
172
OnStop()173 void AppInfoAbilitySlice::OnStop()
174 {
175 AbilitySlice::OnStop();
176 }
177 } // namespace OHOS
178