1 /*
2  * Copyright (c) 2022 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 "active_change_response_info.h"
17 #include "permission_record.h"
18 #include "privacy_field_const.h"
19 
20 namespace OHOS {
21 namespace Security {
22 namespace AccessToken {
TranslationIntoGenericValues(const PermissionRecord & record,GenericValues & values)23 void PermissionRecord::TranslationIntoGenericValues(const PermissionRecord& record, GenericValues& values)
24 {
25     values.Put(PrivacyFiledConst::FIELD_TOKEN_ID, static_cast<int32_t>(record.tokenId));
26     values.Put(PrivacyFiledConst::FIELD_OP_CODE, record.opCode);
27     values.Put(PrivacyFiledConst::FIELD_STATUS, record.status);
28     values.Put(PrivacyFiledConst::FIELD_TIMESTAMP, record.timestamp);
29     values.Put(PrivacyFiledConst::FIELD_ACCESS_DURATION, record.accessDuration);
30     values.Put(PrivacyFiledConst::FIELD_USED_TYPE, record.type);
31     values.Put(PrivacyFiledConst::FIELD_ACCESS_COUNT, record.accessCount);
32     values.Put(PrivacyFiledConst::FIELD_REJECT_COUNT, record.rejectCount);
33     values.Put(PrivacyFiledConst::FIELD_LOCKSCREEN_STATUS, record.lockScreenStatus);
34 }
35 
TranslationIntoPermissionRecord(const GenericValues & values,PermissionRecord & record)36 void PermissionRecord::TranslationIntoPermissionRecord(const GenericValues& values, PermissionRecord& record)
37 {
38     record.tokenId = static_cast<uint32_t>(values.GetInt(PrivacyFiledConst::FIELD_TOKEN_ID));
39     record.opCode = values.GetInt(PrivacyFiledConst::FIELD_OP_CODE);
40     record.status = values.GetInt(PrivacyFiledConst::FIELD_STATUS);
41     record.timestamp = values.GetInt64(PrivacyFiledConst::FIELD_TIMESTAMP);
42     record.accessDuration = values.GetInt64(PrivacyFiledConst::FIELD_ACCESS_DURATION);
43     int32_t type = values.GetInt(PrivacyFiledConst::FIELD_USED_TYPE);
44     record.type = static_cast<PermissionUsedType>(type);
45     record.accessCount = values.GetInt(PrivacyFiledConst::FIELD_ACCESS_COUNT);
46     record.rejectCount = values.GetInt(PrivacyFiledConst::FIELD_REJECT_COUNT);
47     int32_t lockScreenStatus = values.GetInt(PrivacyFiledConst::FIELD_LOCKSCREEN_STATUS);
48     record.lockScreenStatus = lockScreenStatus == VariantValue::DEFAULT_VALUE ?
49         LockScreenStatusChangeType::PERM_ACTIVE_IN_UNLOCKED : lockScreenStatus;
50 }
51 } // namespace AccessToken
52 } // namespace Security
53 } // namespace OHOS