1 /* 2 * Copyright (c) 2021 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 AMS_ABILITY_VISIBALE_TEST_SERVICE_A1 17 #define AMS_ABILITY_VISIBALE_TEST_SERVICE_A1 18 #include "stpageabilityevent.h" 19 #include <string> 20 #include <thread> 21 #include <map> 22 #include "ability_connect_callback_stub.h" 23 #include "ability_connect_callback_proxy.h" 24 #include "abs_shared_result_set.h" 25 #include "ability_loader.h" 26 #include "app_log_wrapper.h" 27 #include "common_event.h" 28 #include "common_event_manager.h" 29 #include "data_ability_predicates.h" 30 #include "values_bucket.h" 31 32 namespace OHOS { 33 namespace AppExecFwk { 34 35 using AbilityConnectionStub = OHOS::AAFwk::AbilityConnectionStub; 36 using Uri = OHOS::Uri; 37 38 class AbilityConnectCallback : public AbilityConnectionStub { 39 public: 40 /** 41 * OnAbilityConnectDone, AbilityMs notify caller ability the result of connect. 42 * 43 * @param element,.service ability's ElementName. 44 * @param remoteObject,.the session proxy of service ability. 45 * @param resultCode, ERR_OK on success, others on failure. 46 */ OnAbilityConnectDone(const AppExecFwk::ElementName & element,const sptr<IRemoteObject> & remoteObject,int resultCode)47 void OnAbilityConnectDone( 48 const AppExecFwk::ElementName &element, const sptr<IRemoteObject> &remoteObject, int resultCode) override 49 { 50 APP_LOGI("AbilityConnectCallback::OnAbilityConnectDone:resultCode = %{public}d", resultCode); 51 } 52 53 /** 54 * OnAbilityDisconnectDone, AbilityMs notify caller ability the result of disconnect. 55 * 56 * @param element,.service ability's ElementName. 57 * @param resultCode, ERR_OK on success, others on failure. 58 */ OnAbilityDisconnectDone(const AppExecFwk::ElementName & element,int resultCode)59 void OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode) override 60 { 61 APP_LOGI("AbilityConnectCallback::OnAbilityDisconnectDone:resultCode = %{public}d", resultCode); 62 } 63 }; 64 65 class AmsAbilityVisibleTestServiceA1 : public Ability { 66 public: 67 ~AmsAbilityVisibleTestServiceA1(); 68 69 protected: 70 virtual void OnStart(const Want &want) override; 71 virtual void OnStop() override; 72 virtual void OnActive() override; 73 virtual void OnInactive() override; 74 virtual void OnBackground() override; 75 virtual void OnNewWant(const Want &want) override; 76 virtual void OnCommand(const AAFwk::Want &want, bool restart, int startId) override; 77 virtual sptr<IRemoteObject> OnConnect(const Want &want) override; 78 virtual void OnDisconnect(const Want &want) override; 79 80 private: 81 void Clear(); 82 void GetWantInfo(const Want &want); 83 std::string Split(std::string &str, std::string delim); 84 85 std::string targetType_; 86 std::string targetBundle_; 87 std::string targetAbility_; 88 STPageAbilityEvent pageAbilityEvent; 89 }; 90 } // namespace AppExecFwk 91 } // namespace OHOS 92 #endif // AMS_ABILITY_VISIBALE_TEST_SERVICE_A1