1 /* 2 * Copyright (c) 2021-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 16 #ifndef I_ACCESSTOKEN_MANAGER_H 17 #define I_ACCESSTOKEN_MANAGER_H 18 19 #include <string> 20 21 #include "access_token.h" 22 #include "accesstoken_service_ipc_interface_code.h" 23 #include "errors.h" 24 #include "hap_info_parcel.h" 25 #include "hap_policy_parcel.h" 26 #include "hap_token_info_for_sync_parcel.h" 27 #include "hap_token_info_parcel.h" 28 #include "iremote_broker.h" 29 #include "i_permission_state_callback.h" 30 #include "native_token_info_for_sync_parcel.h" 31 #include "native_token_info_parcel.h" 32 #include "permission_def_parcel.h" 33 #include "permission_list_state_parcel.h" 34 #include "permission_state_full_parcel.h" 35 #include "permission_state_change_scope_parcel.h" 36 #include "system_ability_definition.h" 37 38 namespace OHOS { 39 namespace Security { 40 namespace AccessToken { 41 class IAccessTokenManager : public IRemoteBroker { 42 public: 43 static const int SA_ID_ACCESSTOKEN_MANAGER_SERVICE = ACCESS_TOKEN_MANAGER_SERVICE_ID; 44 45 DECLARE_INTERFACE_DESCRIPTOR(u"ohos.security.accesstoken.IAccessTokenManager"); 46 47 virtual int VerifyAccessToken(AccessTokenID tokenID, const std::string& permissionName) = 0; 48 virtual int GetDefPermission(const std::string& permissionName, PermissionDefParcel& permissionDefResult) = 0; 49 virtual int GetDefPermissions(AccessTokenID tokenID, std::vector<PermissionDefParcel>& permList) = 0; 50 virtual int GetReqPermissions( 51 AccessTokenID tokenID, std::vector<PermissionStateFullParcel>& reqPermList, bool isSystemGrant) = 0; 52 virtual int GetPermissionFlag(AccessTokenID tokenID, const std::string& permissionName, int& flag) = 0; 53 virtual PermissionOper GetSelfPermissionsState( 54 std::vector<PermissionListStateParcel>& permListParcel) = 0; 55 virtual int GrantPermission(AccessTokenID tokenID, const std::string& permissionName, int flag) = 0; 56 virtual int RevokePermission(AccessTokenID tokenID, const std::string& permissionName, int flag) = 0; 57 virtual int ClearUserGrantedPermissionState(AccessTokenID tokenID) = 0; 58 virtual AccessTokenIDEx AllocHapToken(const HapInfoParcel& hapInfo, const HapPolicyParcel& policyParcel) = 0; 59 virtual int DeleteToken(AccessTokenID tokenID) = 0; 60 virtual int GetTokenType(AccessTokenID tokenID) = 0; 61 virtual int CheckNativeDCap(AccessTokenID tokenID, const std::string& dcap) = 0; 62 virtual AccessTokenIDEx GetHapTokenID(int32_t userID, const std::string& bundleName, int32_t instIndex) = 0; 63 virtual AccessTokenID AllocLocalTokenID(const std::string& remoteDeviceID, AccessTokenID remoteTokenID) = 0; 64 virtual int GetNativeTokenInfo(AccessTokenID tokenID, NativeTokenInfoParcel& nativeTokenInfoRes) = 0; 65 virtual int GetHapTokenInfo(AccessTokenID tokenID, HapTokenInfoParcel& hapTokenInfoRes) = 0; 66 virtual int UpdateHapToken(AccessTokenIDEx& tokenIdEx, bool isSystemApp, const std::string& appIDDesc, 67 int32_t apiVersion, const HapPolicyParcel& policyParcel) = 0; 68 virtual int32_t RegisterPermStateChangeCallback( 69 const PermStateChangeScopeParcel& scope, const sptr<IRemoteObject>& callback) = 0; 70 virtual int32_t UnRegisterPermStateChangeCallback(const sptr<IRemoteObject>& callback) = 0; 71 #ifndef ATM_BUILD_VARIANT_USER_ENABLE 72 virtual int32_t ReloadNativeTokenInfo() = 0; 73 #endif 74 virtual AccessTokenID GetNativeTokenId(const std::string& processName) = 0; 75 76 #ifdef TOKEN_SYNC_ENABLE 77 virtual int GetHapTokenInfoFromRemote(AccessTokenID tokenID, 78 HapTokenInfoForSyncParcel& hapSyncParcel) = 0; 79 virtual int GetAllNativeTokenInfo(std::vector<NativeTokenInfoForSyncParcel>& nativeTokenInfoRes) = 0; 80 virtual int SetRemoteHapTokenInfo(const std::string& deviceID, 81 HapTokenInfoForSyncParcel& hapSyncParcel) = 0; 82 virtual int SetRemoteNativeTokenInfo(const std::string& deviceID, 83 std::vector<NativeTokenInfoForSyncParcel>& nativeTokenInfoForSyncParcel) = 0; 84 virtual int DeleteRemoteToken(const std::string& deviceID, AccessTokenID tokenID) = 0; 85 virtual AccessTokenID GetRemoteNativeTokenID(const std::string& deviceID, AccessTokenID tokenID) = 0; 86 virtual int DeleteRemoteDeviceTokens(const std::string& deviceID) = 0; 87 #endif 88 89 virtual void DumpTokenInfo(AccessTokenID tokenID, std::string& tokenInfo) = 0; 90 }; 91 } // namespace AccessToken 92 } // namespace Security 93 } // namespace OHOS 94 95 #endif // I_ACCESSTOKEN_MANAGER_H 96