1 /* 2 * Copyright (c) 2021-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 PRINT_SERVICE_HELPER_H 17 #define PRINT_SERVICE_HELPER_H 18 19 #include <string> 20 #include "ability_manager_client.h" 21 #include "bundle_mgr_proxy.h" 22 #include "bundle_mgr_client.h" 23 #include "ability_connect_callback_stub.h" 24 #include "system_ability.h" 25 #include "print_log.h" 26 #include "print_event_subscriber.h" 27 28 namespace OHOS::Print { 29 class PrintServiceHelper { 30 public: 31 virtual ~PrintServiceHelper(); 32 virtual bool CheckPermission(const std::string &name); 33 virtual bool StartAbility(const AAFwk::Want &want); 34 virtual sptr<IRemoteObject> GetBundleMgr(); 35 virtual bool QueryAccounts(std::vector<int> &accountList); 36 virtual bool QueryExtension(sptr<AppExecFwk::IBundleMgr> mgr, int userId, 37 std::vector<AppExecFwk::ExtensionAbilityInfo> &extensionInfos); 38 virtual bool QueryNameForUid(sptr<AppExecFwk::IBundleMgr> mgr, int32_t userId, std::string& name); 39 virtual bool IsSyncMode(); 40 virtual bool StartPluginPrintIconExtAbility(const AAFwk::Want &want); 41 virtual void PrintSubscribeCommonEvent(); 42 43 private: 44 class PrintAbilityConnection : public AAFwk::AbilityConnectionStub { OnAbilityConnectDone(const AppExecFwk::ElementName & element,const sptr<IRemoteObject> & remoteObject,int32_t resultCode)45 void OnAbilityConnectDone(const AppExecFwk::ElementName &element, const sptr<IRemoteObject> &remoteObject, 46 int32_t resultCode) override 47 { 48 PRINT_HILOGI("connect done"); 49 } OnAbilityDisconnectDone(const AppExecFwk::ElementName & element,int32_t resultCode)50 void OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int32_t resultCode) override 51 { 52 PRINT_HILOGI("disconnect done"); 53 } 54 }; 55 56 private: 57 std::shared_ptr<PrintEventSubscriber> userStatusListener; 58 bool isSubscribeCommonEvent = false; 59 }; 60 } // namespace OHOS 61 #endif // PRINT_SERVICE_HELPER_H 62