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 "tokenid_kit.h"
17
18 #include <cinttypes>
19
20 #include "accesstoken_common_log.h"
21 #include "access_token.h"
22
23 namespace OHOS {
24 namespace Security {
25 namespace AccessToken {
26 namespace {
27 static const uint64_t SYSTEM_APP_MASK = (static_cast<uint64_t>(1) << 32);
28 static const uint64_t TOKEN_ID_LOWMASK = 0xffffffff;
29 }
30
IsSystemAppByFullTokenID(uint64_t tokenId)31 bool TokenIdKit::IsSystemAppByFullTokenID(uint64_t tokenId)
32 {
33 LOGD(ATM_DOMAIN, ATM_TAG, "Called, tokenId=%{public}" PRId64, tokenId);
34 return (tokenId & SYSTEM_APP_MASK) == SYSTEM_APP_MASK;
35 }
36
GetRenderTokenID(uint64_t tokenId)37 uint64_t TokenIdKit::GetRenderTokenID(uint64_t tokenId)
38 {
39 AccessTokenID id = tokenId & TOKEN_ID_LOWMASK;
40 if (id == INVALID_TOKENID) {
41 LOGE(ATM_DOMAIN, ATM_TAG, "TokenID is invalid");
42 return tokenId;
43 }
44 AccessTokenIDInner* idInner = reinterpret_cast<AccessTokenIDInner*>(&id);
45 idInner->renderFlag = 1;
46
47 id = *reinterpret_cast<AccessTokenID*>(idInner);
48 return static_cast<uint64_t>(id);
49 }
50 } // namespace AccessToken
51 } // namespace Security
52 } // namespace OHOS
53