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 #ifndef PRIVACY_MANAGER_SERVICE_H 17 #define PRIVACY_MANAGER_SERVICE_H 18 19 #include <string> 20 21 #include "privacy_manager_stub.h" 22 #include "iremote_object.h" 23 #include "nocopyable.h" 24 #include "singleton.h" 25 #include "system_ability.h" 26 27 namespace OHOS { 28 namespace Security { 29 namespace AccessToken { 30 enum class ServiceRunningState { STATE_NOT_START, STATE_RUNNING }; 31 class PrivacyManagerService final : public SystemAbility, public PrivacyManagerStub { 32 DECLARE_DELAYED_SINGLETON(PrivacyManagerService); 33 DECLEAR_SYSTEM_ABILITY(PrivacyManagerService); 34 35 public: 36 void OnStart() override; 37 void OnStop() override; 38 39 int32_t AddPermissionUsedRecord( 40 AccessTokenID tokenId, const std::string& permissionName, int32_t successCount, int32_t failCount) override; 41 int32_t StartUsingPermission(AccessTokenID tokenId, const std::string& permissionName) override; 42 int32_t StartUsingPermission(AccessTokenID tokenId, const std::string& permissionName, 43 const sptr<IRemoteObject>& callback) override; 44 int32_t StopUsingPermission(AccessTokenID tokenId, const std::string& permissionName) override; 45 int32_t RemovePermissionUsedRecords(AccessTokenID tokenId, const std::string& deviceID) override; 46 int32_t GetPermissionUsedRecords( 47 const PermissionUsedRequestParcel& request, PermissionUsedResultParcel& result) override; 48 int32_t GetPermissionUsedRecords( 49 const PermissionUsedRequestParcel& request, const sptr<OnPermissionUsedRecordCallback>& callback) override; 50 int32_t RegisterPermActiveStatusCallback( 51 std::vector<std::string>& permList, const sptr<IRemoteObject>& callback) override; 52 int32_t UnRegisterPermActiveStatusCallback(const sptr<IRemoteObject>& callback) override; 53 bool IsAllowedUsingPermission(AccessTokenID tokenId, const std::string& permissionName) override; 54 int32_t Dump(int32_t fd, const std::vector<std::u16string>& args) override; 55 private: 56 bool Initialize() const; 57 int32_t ResponseDumpCommand(int32_t fd, const std::vector<std::u16string>& args); 58 59 ServiceRunningState state_; 60 }; 61 } // namespace AccessToken 62 } // namespace Security 63 } // namespace OHOS 64 #endif // PRIVACY_MANAGER_SERVICE_H 65