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()29 bool SaveButton::IsTextIconTypeValid()
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 ((static_cast<SaveIcon>(icon_) == SaveIcon::PICTURE_ICON) && !IsSystemAppCalling()) {
37 SC_LOG_ERROR(LABEL, "Picture icon only for system application.");
38 return false;
39 }
40
41 return true;
42 }
43
IsSystemAppCalling() const44 bool SaveButton::IsSystemAppCalling() const
45 {
46 uint64_t fullTokenId = IPCSkeleton::GetCallingFullTokenID();
47 return AccessToken::TokenIdKit::IsSystemAppByFullTokenID(fullTokenId);
48 }
49
IsCorrespondenceType()50 bool SaveButton::IsCorrespondenceType()
51 {
52 return (type_ == SAVE_COMPONENT);
53 }
54
CompareComponentBasicInfo(SecCompBase * other,bool isRectCheck) const55 bool SaveButton::CompareComponentBasicInfo(SecCompBase *other, bool isRectCheck) const
56 {
57 if (!SecCompBase::CompareComponentBasicInfo(other, isRectCheck)) {
58 SC_LOG_ERROR(LABEL, "SecComp base not equal.");
59 return false;
60 }
61 SaveButton* otherSaveButton = reinterpret_cast<SaveButton *>(other);
62 if (otherSaveButton == nullptr) {
63 SC_LOG_ERROR(LABEL, "other is not save button.");
64 return false;
65 }
66 return (icon_ == otherSaveButton->icon_) && (text_ == otherSaveButton->text_) &&
67 (bg_ == otherSaveButton->bg_);
68 }
69 } // namespace SecurityComponent
70 } // namespace Security
71 } // namespace OHOS
72