• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 #include "save_button.h"
16 
17 #include <tuple>
18 #include "ipc_skeleton.h"
19 #include "sec_comp_log.h"
20 #include "tokenid_kit.h"
21 
22 namespace OHOS {
23 namespace Security {
24 namespace SecurityComponent {
25 namespace {
26 constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_SECURITY_COMPONENT, "SaveButton"};
27 }
28 
IsTextIconTypeValid(std::string & message,bool isClicked)29 bool SaveButton::IsTextIconTypeValid(std::string &message, bool isClicked)
30 {
31     if ((text_ <= UNKNOWN_TEXT) || (static_cast<SaveDesc>(text_) >= SaveDesc::MAX_LABEL_TYPE) ||
32         (icon_ <= UNKNOWN_ICON) || (static_cast<SaveIcon>(icon_) >= SaveIcon::MAX_ICON_TYPE)) {
33         return false;
34     }
35 
36     if (isClicked && (static_cast<SaveIcon>(icon_) == SaveIcon::PICTURE_ICON) && !IsSystemAppCalling()) {
37         SC_LOG_ERROR(LABEL, "Picture icon only for system application.");
38         message = ", security component icon type = " + std::to_string(icon_) +
39             ", picture icon only for system application.";
40         return false;
41     }
42 
43     return true;
44 }
45 
IsSystemAppCalling() const46 bool SaveButton::IsSystemAppCalling() const
47 {
48     uint64_t fullTokenId = IPCSkeleton::GetCallingFullTokenID();
49     return AccessToken::TokenIdKit::IsSystemAppByFullTokenID(fullTokenId);
50 }
51 
IsCorrespondenceType()52 bool SaveButton::IsCorrespondenceType()
53 {
54     return (type_ == SAVE_COMPONENT);
55 }
56 
CompareComponentBasicInfo(SecCompBase * other,bool isRectCheck) const57 bool SaveButton::CompareComponentBasicInfo(SecCompBase *other, bool isRectCheck) const
58 {
59     if (!SecCompBase::CompareComponentBasicInfo(other, isRectCheck)) {
60         SC_LOG_ERROR(LABEL, "SecComp base not equal.");
61         return false;
62     }
63     SaveButton* otherSaveButton = reinterpret_cast<SaveButton *>(other);
64     if (otherSaveButton == nullptr) {
65         SC_LOG_ERROR(LABEL, "other is not save button.");
66         return false;
67     }
68     return (icon_ == otherSaveButton->icon_) && (text_ == otherSaveButton->text_) &&
69         (bg_ == otherSaveButton->bg_);
70 }
71 }  // namespace SecurityComponent
72 }  // namespace Security
73 }  // namespace OHOS
74