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