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 #ifndef OHOS_APP_INFO_ABILITY_SLICE_H 17 #define OHOS_APP_INFO_ABILITY_SLICE_H 18 19 #include "ability_info.h" 20 #include "ability_loader.h" 21 #include "ability_manager.h" 22 #include "ability_slice.h" 23 #include "bundle_manager.h" 24 #include "components/ui_image_view.h" 25 #include "components/ui_label.h" 26 #include "components/ui_label_button.h" 27 #include "components/ui_list.h" 28 #include "components/ui_scroll_view.h" 29 #include "components/ui_toggle_button.h" 30 #include "element_name.h" 31 #include "event_listener.h" 32 #include "gfx_utils/list.h" 33 #include "module_info.h" 34 #include "setting_utils.h" 35 #include "want.h" 36 #include "pms_interface.h" 37 38 #include <cstdio> 39 #include <securec.h> 40 41 namespace OHOS { 42 43 class ToggBtnOnListener : public UIView::OnClickListener { 44 public: 45 ToggBtnOnListener(UIToggleButton * togglebutton)46 explicit ToggBtnOnListener(UIToggleButton* togglebutton) 47 { 48 status_ = false; 49 togglebutton_ = togglebutton; 50 } 51 ~ToggBtnOnListener()52 virtual ~ToggBtnOnListener() {} 53 SetPermissionName(const char * permissionsName,int nameLenght)54 void SetPermissionName(const char* permissionsName, int nameLenght) 55 { 56 int ret = 0; 57 ret = memcpy_s(name_, sizeof(name_), permissionsName, nameLenght); 58 if (ret != EOK) { 59 printf("[ERR] memcpy_s func[SetToggleButton]\n"); 60 return; 61 } 62 name_[nameLenght] = 0; 63 } 64 SetBundleName(const char * bundleName,int nameLength)65 void SetBundleName(const char* bundleName, int nameLength) 66 { 67 int ret = 0; 68 ret = memcpy_s(bundleName_, sizeof(bundleName_), bundleName, nameLength); 69 if (ret != EOK) { 70 printf("[ERR] memcpy_s func[SetBundleName]\n"); 71 return; 72 } 73 bundleName_[nameLength] = 0; 74 } 75 OnClick(UIView & view,const ClickEvent & event)76 bool OnClick(UIView& view, const ClickEvent& event) override 77 { 78 int ret; 79 if (status_) { 80 ret = RevokePermission(bundleName_, name_); 81 if (ret == 0) { 82 status_ = false; 83 togglebutton_->SetState(false); 84 } 85 } else { 86 ret = GrantPermission(bundleName_, name_); 87 if (ret == 0) { 88 status_ = true; 89 togglebutton_->SetState(true); 90 } 91 } 92 return true; 93 } 94 private: 95 char name_[128] = {0}; 96 char bundleName_[128] = {0}; 97 bool status_ = false; 98 UIToggleButton* togglebutton_ = nullptr; 99 }; 100 101 class AppInfoAbilitySlice : public AbilitySlice { 102 public: AppInfoAbilitySlice()103 AppInfoAbilitySlice() 104 : headView_(nullptr), scrollView_(nullptr), rootView_(nullptr), permissions_(nullptr), 105 buttonBackListener_(nullptr) {} 106 virtual ~AppInfoAbilitySlice(); 107 protected: 108 void OnStart(const Want& want) override; 109 void OnInactive() override; 110 void OnActive(const Want& want) override; 111 void OnBackground() override; 112 void OnStop() override; 113 private: 114 void SetAppButtonListener(const char* appName); 115 void SetButtonListener(void); 116 void SetHead(void); 117 UIViewGroup* headView_; 118 UIScrollView* scrollView_; 119 RootView* rootView_; 120 PermissionSaved* permissions_; 121 EventListener* buttonBackListener_; 122 List<ToggBtnOnListener*> listListener_; 123 124 void PermissionInfoList(); 125 void SetAppPermissionInfo(int index, PermissionSaved& permissions); 126 char bundleName_[128] = {0}; 127 }; 128 } // namespace OHOS 129 #endif 130