diff --git a/frameworks/kits/appkit/BUILD.gn b/frameworks/kits/appkit/BUILD.gn index 43cb6d0433db9b019514453b87cf786582ddeecf..969611ed98acb4c674db046f7a3659f3a55e7797 100644 --- a/frameworks/kits/appkit/BUILD.gn +++ b/frameworks/kits/appkit/BUILD.gn @@ -170,6 +170,7 @@ ohos_shared_library("appkit_native") { "bytrace_standard:bytrace_core", "hisysevent_native:libhisysevent", "hiviewdfx_hilog_native:libhilog", + "hisysevent_native:libhisysevent", "ipc:ipc_core", "napi:ace_napi", ] diff --git a/frameworks/kits/appkit/native/app/src/main_thread.cpp b/frameworks/kits/appkit/native/app/src/main_thread.cpp index faace598f7c8a2a8391ce4ec743166f30ef01461..be52ac2a8bc9072b53888890b58af998f6fb090c 100644 --- a/frameworks/kits/appkit/native/app/src/main_thread.cpp +++ b/frameworks/kits/appkit/native/app/src/main_thread.cpp @@ -46,6 +46,8 @@ #include "task_handler_client.h" #include "faultloggerd_client.h" #include "dfx_dump_catcher.h" +#include "hisysevent.h" +#include "js_runtime_utils.h" #if defined(ABILITY_LIBRARY_LOADER) || defined(APPLICATION_LIBRARY_LOADER) #include @@ -60,6 +62,13 @@ namespace { constexpr int32_t DELIVERY_TIME = 200; constexpr int32_t DISTRIBUTE_TIME = 100; constexpr int32_t UNSPECIFIED_USERID = -2; + +constexpr char EVENT_KEY_UID[] = "UID"; +constexpr char EVENT_KEY_PID[] = "PID"; +constexpr char EVENT_KEY_MESSAGE[] = "MSG"; +constexpr char EVENT_KEY_PACKAGE_NAME[] = "PACKAGE_NAME"; +constexpr char EVENT_KEY_PROCESS_NAME[] = "PROCESS_NAME"; +constexpr uint8_t CAP_MAX_SIZE = 64; } #define ACEABILITY_LIBRARY_LOADER @@ -870,7 +879,58 @@ void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, con APP_LOGE("OHOSApplication::OHOSApplication: Failed to create runtime"); return; } - + auto& jsEngine = (static_cast(*runtime)).GetNativeEngine(); + auto bundleName = appInfo.bundleName; + auto uid = appInfo.uid; + auto processName = processInfo.GetProcessName(); + auto processPid = processInfo.GetPid(); + wptr weak = this; + auto uncaughtTask = [weak, uid, processPid, bundleName, processName](NativeValue* v) { + APP_LOGI("RegisterUncaughtExceptionHandler Begin"); + NativeObject* obj = AbilityRuntime::ConvertNativeValueTo(v); + NativeValue* message = obj->GetProperty("message"); + NativeString* messageStr = AbilityRuntime::ConvertNativeValueTo(message); + if (messageStr == nullptr) { + APP_LOGE("messageStr Convert failed"); + return; + } + size_t messagebufferLen = messageStr->GetLength(); + size_t messagestrLen = 0; + char messagecap[CAP_MAX_SIZE] = { 0 }; + messageStr->GetCString(messagecap, messagebufferLen + 1, &messagestrLen); + APP_LOGI("messagecap = %{public}s", messagecap); + NativeValue* stack = obj->GetProperty("stack"); + NativeString* stackStr = AbilityRuntime::ConvertNativeValueTo(stack); + if (stackStr == nullptr) { + APP_LOGE("stackStr Convert failed"); + return; + } + size_t stackbufferLen = stackStr->GetLength(); + size_t stackstrLen = 0; + char stackcap[CAP_MAX_SIZE] = { 0 }; + messageStr->GetCString(stackcap, stackbufferLen + 1, &stackstrLen); + APP_LOGI("stackcap = %{public}s", stackcap); + auto appThread = weak.promote(); + if (appThread == nullptr) { + APP_LOGE("appThread is nullptr, HandleLaunchApplication failed."); + return; + } + std::string eventType = "JS_EXCEPTION"; + std::string msgContent; + std::string tempMessageStr(messagecap); + std::string tempStackStr(stackcap); + msgContent = "message:" + tempMessageStr + "tempStack:" + tempStackStr; + auto ret = OHOS::HiviewDFX::HiSysEvent::Write(OHOS::HiviewDFX::HiSysEvent::Domain::AAFWK, eventType, + OHOS::HiviewDFX::HiSysEvent::EventType::FAULT, + EVENT_KEY_UID, std::to_string(uid), + EVENT_KEY_PID, std::to_string(processPid), + EVENT_KEY_PACKAGE_NAME, bundleName, + EVENT_KEY_PROCESS_NAME, processName, + EVENT_KEY_MESSAGE, msgContent); + appThread->ScheduleProcessSecurityExit(); + APP_LOGI("RegisterUncaughtExceptionHandler End ret = %{public}d", ret); + }; + jsEngine.RegisterUncaughtExceptionHandler(uncaughtTask); application_->SetRuntime(std::move(runtime)); auto usertestInfo = appLaunchData.GetUserTestInfo(); if (usertestInfo.observer) { diff --git a/interfaces/innerkits/app_manager/BUILD.gn b/interfaces/innerkits/app_manager/BUILD.gn index 19ae968ddfd68bb49c7bc0aad4a8be27f77433b3..ac8817a19cf9d1f06c7f7dcb9d7080d9a2e6a7cd 100644 --- a/interfaces/innerkits/app_manager/BUILD.gn +++ b/interfaces/innerkits/app_manager/BUILD.gn @@ -59,8 +59,6 @@ ohos_shared_library("app_manager") { "src/appmgr/process_data.cpp", "src/appmgr/process_info.cpp", "src/appmgr/profile.cpp", - "src/appmgr/render_scheduler_host.cpp", - "src/appmgr/render_scheduler_proxy.cpp", "src/appmgr/running_process_info.cpp", "src/appmgr/start_specified_ability_response_proxy.cpp", "src/appmgr/start_specified_ability_response_stub.cpp", diff --git a/interfaces/innerkits/app_manager/include/appmgr/ams_mgr_interface.h b/interfaces/innerkits/app_manager/include/appmgr/ams_mgr_interface.h index 28d20995083140e02235b80d18d41dda383f049f..0656a1b624323f08482faad4504f2f94f1250b9f 100644 --- a/interfaces/innerkits/app_manager/include/appmgr/ams_mgr_interface.h +++ b/interfaces/innerkits/app_manager/include/appmgr/ams_mgr_interface.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -80,6 +80,13 @@ public: */ virtual void RegisterAppStateCallback(const sptr &callback) = 0; + /** + * Reset,call Reset() through the proxy object, reset DFX of AppMgr. + * + * @return + */ + virtual void Reset() = 0; + /** * AbilityBehaviorAnalysis,call AbilityBehaviorAnalysis() through the proxy object, * ability behavior analysis assistant process optimization. @@ -178,6 +185,7 @@ public: UPDATE_ABILITY_STATE, UPDATE_EXTENSION_STATE, REGISTER_APP_STATE_CALLBACK, + RESET, ABILITY_BEHAVIOR_ANALYSIS, KILL_PEOCESS_BY_ABILITY_TOKEN, KILL_PROCESSES_BY_USERID, diff --git a/interfaces/innerkits/app_manager/include/appmgr/ams_mgr_proxy.h b/interfaces/innerkits/app_manager/include/appmgr/ams_mgr_proxy.h index 4be57ed5e915c3bdbacd5e477bfec1b5e558faec..ef95912b1a23909e26df8b2327ed6a486e576dc7 100644 --- a/interfaces/innerkits/app_manager/include/appmgr/ams_mgr_proxy.h +++ b/interfaces/innerkits/app_manager/include/appmgr/ams_mgr_proxy.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -74,6 +74,13 @@ public: */ virtual void RegisterAppStateCallback(const sptr &callback) override; + /** + * Reset,call Reset() through the proxy object, reset DFX of AppMgr. + * + * @return + */ + virtual void Reset() override; + /** * AbilityBehaviorAnalysis,call AbilityBehaviorAnalysis() through the proxy object, * ability behavior analysis assistant process optimization. diff --git a/interfaces/innerkits/app_manager/include/appmgr/app_mgr_client.h b/interfaces/innerkits/app_manager/include/appmgr/app_mgr_client.h index 432cf349e9e15445f3693e90cd2daebf4748a178..c392772e6d45cdb363862e33d6b97c9fd52dbe48 100644 --- a/interfaces/innerkits/app_manager/include/appmgr/app_mgr_client.h +++ b/interfaces/innerkits/app_manager/include/appmgr/app_mgr_client.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -25,7 +25,6 @@ #include "app_mgr_constants.h" #include "bundle_info.h" #include "iapp_state_callback.h" -#include "irender_scheduler.h" #include "running_process_info.h" #include "system_memory_attr.h" #include "istart_specified_ability_response.h" @@ -84,6 +83,13 @@ public: */ virtual AppMgrResultCode ConnectAppMgrService(); + /** + * Ability manager resst. + * + * @return Returns RESULT_OK on success, others on failure. + */ + virtual AppMgrResultCode Reset(); + /** * AbilityBehaviorAnalysis, ability behavior analysis assistant process optimization. * @@ -169,6 +175,23 @@ public: */ virtual AppMgrResultCode GetConfiguration(Configuration& config); + /** + * SetAppSuspendTimes, Setting the Freezing Time of APP Background. + * + * @param time, The timeout recorded when the application enters the background . + * + * @return Success or Failure . + */ + virtual AppMgrResultCode SetAppFreezingTime(int time); + + /** + * GetAppFreezingTime, Getting the Freezing Time of APP Background. + * + * @param time, The timeout recorded when the application enters the background . + * + * @return Success or Failure . + */ + virtual AppMgrResultCode GetAppFreezingTime(int &time); virtual void AbilityAttachTimeOut(const sptr &token); virtual void PrepareTerminate(const sptr &token); @@ -233,25 +256,6 @@ public: */ virtual int GetAbilityRecordsByProcessID(const int pid, std::vector> &tokens); - /** - * Start webview render process, called by webview host. - * - * @param renderParam, params passed to renderprocess. - * @param ipcFd, ipc file descriptior for web browser and render process. - * @param sharedFd, shared memory file descriptior. - * @param renderPid, created render pid. - * @return Returns ERR_OK on success, others on failure. - */ - virtual int StartRenderProcess(const std::string &renderParam, int32_t ipcFd, - int32_t sharedFd, pid_t &renderPid); - - /** - * Render process call this to attach app manager service. - * - * @param renderScheduler, scheduler of render process. - */ - virtual void AttachRenderProcess(const sptr &renderScheduler); - private: void SetServiceManager(std::unique_ptr serviceMgr); diff --git a/interfaces/innerkits/app_manager/include/appmgr/app_mgr_interface.h b/interfaces/innerkits/app_manager/include/appmgr/app_mgr_interface.h index 4a34d7ab3906bc4ef2d31a3187b8e85fa1ccdfe3..26302e4fd87b25ddebb6fd4fcaf4799211050267 100644 --- a/interfaces/innerkits/app_manager/include/appmgr/app_mgr_interface.h +++ b/interfaces/innerkits/app_manager/include/appmgr/app_mgr_interface.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -105,6 +105,15 @@ public: */ virtual int32_t ClearUpApplicationData(const std::string &bundleName) = 0; + /** + * IsBackgroundRunningRestricted, call IsBackgroundRunningRestricted() through proxy project, + * Checks whether the process of this application is forbidden to run in the background. + * + * @param bundleName, bundle name in Application record. + * @return ERR_OK, return back success, others fail. + */ + virtual int IsBackgroundRunningRestricted(const std::string &bundleName) = 0; + /** * GetAllRunningProcesses, call GetAllRunningProcesses() through proxy project. * Obtains information about application processes that are running on the device. @@ -124,6 +133,24 @@ public: */ virtual int GetProcessRunningInfosByUserId(std::vector &info, int32_t userId) = 0; + /** + * SetAppSuspendTimes, Setting the Freezing Time of APP Background. + * + * @param time, The timeout recorded when the application enters the background . + * + * @return Success or Failure . + */ + virtual void SetAppFreezingTime(int time) = 0; + + /** + * GetAppFreezingTime, Getting the Freezing Time of APP Background. + * + * @param time, The timeout recorded when the application enters the background . + * + * @return Success or Failure . + */ + virtual void GetAppFreezingTime(int &time) = 0; + /** * Get system memory information. * @param SystemMemoryAttr, memory information. @@ -183,25 +210,6 @@ public: */ virtual int GetAbilityRecordsByProcessID(const int pid, std::vector> &tokens) = 0; - /** - * Start webview render process, called by webview host. - * - * @param renderParam, params passed to renderprocess. - * @param ipcFd, ipc file descriptior for web browser and render process. - * @param sharedFd, shared memory file descriptior. - * @param renderPid, created render pid. - * @return Returns ERR_OK on success, others on failure. - */ - virtual int StartRenderProcess(const std::string &renderParam, int32_t ipcFd, - int32_t sharedFd, pid_t &renderPid) = 0; - - /** - * Render process call this to attach app manager service. - * - * @param renderScheduler, scheduler of render process. - */ - virtual void AttachRenderProcess(const sptr &renderScheduler) = 0; - enum class Message { APP_ATTACH_APPLICATION = 0, APP_APPLICATION_FOREGROUNDED, @@ -211,8 +219,11 @@ public: APP_ABILITY_CLEANED, APP_GET_MGR_INSTANCE, APP_CLEAR_UP_APPLICATION_DATA, + APP_IS_BACKGROUND_RUNNING_RESTRICTED, APP_GET_ALL_RUNNING_PROCESSES, APP_GET_RUNNING_PROCESSES_BY_USER_ID, + APP_SET_APP_FREEZING_TIME, + APP_GET_APP_FREEZING_TIME, APP_GET_SYSTEM_MEMORY_ATTR, APP_ADD_ABILITY_STAGE_INFO_DONE, STARTUP_RESIDENT_PROCESS, @@ -222,8 +233,6 @@ public: START_USER_TEST_PROCESS, SCHEDULE_ACCEPT_WANT_DONE, APP_GET_ABILITY_RECORDS_BY_PROCESS_ID, - START_RENDER_PROCESS, - ATTACH_RENDER_PROCESS, }; }; } // namespace AppExecFwk diff --git a/interfaces/innerkits/app_manager/include/appmgr/app_mgr_proxy.h b/interfaces/innerkits/app_manager/include/appmgr/app_mgr_proxy.h index 0a2b53f4384ade47b75f48d32d49a17a60823636..20f1cb3eddf9cbb04805357e26d9df2ef9c53434 100644 --- a/interfaces/innerkits/app_manager/include/appmgr/app_mgr_proxy.h +++ b/interfaces/innerkits/app_manager/include/appmgr/app_mgr_proxy.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -98,6 +98,15 @@ public: */ virtual int32_t ClearUpApplicationData(const std::string &bundleName) override; + /** + * IsBackgroundRunningRestricted, call IsBackgroundRunningRestricted() through proxy project, + * Checks whether the process of this application is forbidden to run in the background. + * + * @param bundleName, bundle name in Application record. + * @return ERR_OK, return back success, others fail. + */ + virtual int32_t IsBackgroundRunningRestricted(const std::string &bundleName) override; + /** * GetAllRunningProcesses, call GetAllRunningProcesses() through proxy project. * Obtains information about application processes that are running on the device. @@ -116,6 +125,24 @@ public: */ virtual int32_t GetProcessRunningInfosByUserId(std::vector &info, int32_t userId) override; + /** + * SetAppSuspendTimes, Setting the Freezing Time of APP Background. + * + * @param time, The timeout recorded when the application enters the background . + * + * @return Success or Failure . + */ + virtual void SetAppFreezingTime(int time) override; + + /** + * GetAppFreezingTime, Getting the Freezing Time of APP Background. + * + * @param time, The timeout recorded when the application enters the background . + * + * @return Success or Failure . + */ + virtual void GetAppFreezingTime(int &time) override; + /** * Get system memory information. * @param SystemMemoryAttr, memory information. @@ -176,25 +203,6 @@ public: */ virtual int GetAbilityRecordsByProcessID(const int pid, std::vector> &tokens) override; - /** - * Start webview render process, called by webview host. - * - * @param renderParam, params passed to renderprocess. - * @param ipcFd, ipc file descriptior for web browser and render process. - * @param sharedFd, shared memory file descriptior. - * @param renderPid, created render pid. - * @return Returns ERR_OK on success, others on failure. - */ - virtual int StartRenderProcess(const std::string &renderParam, int32_t ipcFd, - int32_t sharedFd, pid_t &renderPid) override; - - /** - * Render process call this to attach app manager service. - * - * @param renderApp, information needed to start the Application. - */ - virtual void AttachRenderProcess(const sptr &renderApp) override; - private: bool SendTransactCmd(IAppMgr::Message code, MessageParcel &data, MessageParcel &reply); bool WriteInterfaceToken(MessageParcel &data); diff --git a/interfaces/innerkits/app_manager/include/appmgr/app_mgr_stub.h b/interfaces/innerkits/app_manager/include/appmgr/app_mgr_stub.h index 0de454b1fb29db5f01bbb10be53df8bfc4111209..396f34aa2f539f9745612cab4738df520d44f4c6 100644 --- a/interfaces/innerkits/app_manager/include/appmgr/app_mgr_stub.h +++ b/interfaces/innerkits/app_manager/include/appmgr/app_mgr_stub.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -63,8 +63,11 @@ private: int32_t HandleAbilityCleaned(MessageParcel &data, MessageParcel &reply); int32_t HandleGetAmsMgr(MessageParcel &data, MessageParcel &reply); int32_t HandleClearUpApplicationData(MessageParcel &data, MessageParcel &reply); + int32_t HandleIsBackgroundRunningRestricted(MessageParcel &data, MessageParcel &reply); int32_t HandleGetAllRunningProcesses(MessageParcel &data, MessageParcel &reply); int32_t HandleGetProcessRunningInfosByUserId(MessageParcel &data, MessageParcel &reply); + int32_t HandleSetAppFreezingTime(MessageParcel &data, MessageParcel &reply); + int32_t HandleGetAppFreezingTime(MessageParcel &data, MessageParcel &reply); int32_t HandleGetSystemMemoryAttr(MessageParcel &data, MessageParcel &reply); int32_t HandleAddAbilityStageDone(MessageParcel &data, MessageParcel &reply); int32_t HandleStartupResidentProcess(MessageParcel &data, MessageParcel &reply); @@ -74,8 +77,6 @@ private: int32_t HandleStartUserTestProcess(MessageParcel &data, MessageParcel &reply); int32_t HandleScheduleAcceptWantDone(MessageParcel &data, MessageParcel &reply); int32_t HandleGetAbilityRecordsByProcessID(MessageParcel &data, MessageParcel &reply); - int32_t HandleStartRenderProcess(MessageParcel &data, MessageParcel &reply); - int32_t HandleAttachRenderProcess(MessageParcel &data, MessageParcel &reply); using AppMgrFunc = int32_t (AppMgrStub::*)(MessageParcel &data, MessageParcel &reply); std::map memberFuncMap_; diff --git a/interfaces/innerkits/app_manager/include/appmgr/irender_scheduler.h b/interfaces/innerkits/app_manager/include/appmgr/irender_scheduler.h deleted file mode 100644 index d4d7cba7c0d23dbb459d17bd16dd26f4ee9d90b2..0000000000000000000000000000000000000000 --- a/interfaces/innerkits/app_manager/include/appmgr/irender_scheduler.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_APPEXECFWK_CORE_INCLUDE_APPMGR_IRENDER_SCHEDULER_H -#define FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_APPEXECFWK_CORE_INCLUDE_APPMGR_IRENDER_SCHEDULER_H - -#include "iremote_broker.h" - -namespace OHOS { -namespace AppExecFwk { -/** - * @class IRenderScheduler - * Ipc interface of render process to app mgr service. - */ -class IRenderScheduler : public IRemoteBroker { -public: - DECLARE_INTERFACE_DESCRIPTOR(u"ohos.appexecfwk.RenderScheduler"); - - /** - * Notify Browser's fd to render process. - * - * @param ipcFd, ipc file descriptior for web browser and render process. - * @param sharedFd, shared memory file descriptior. - */ - virtual void NotifyBrowserFd(int32_t ipcFd, int32_t sharedFd) = 0; - - enum class Message { - NOTIFY_BROWSER_FD = 1, - }; -}; -} // namespace AppExecFwk -} // namespace OHOS -#endif // FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_APPEXECFWK_CORE_INCLUDE_APPMGR_IRENDER_SCHEDULER_H diff --git a/interfaces/innerkits/app_manager/include/appmgr/render_scheduler_host.h b/interfaces/innerkits/app_manager/include/appmgr/render_scheduler_host.h deleted file mode 100644 index 5b13f250e8a59bdc05fa231cee99b28d8cefea93..0000000000000000000000000000000000000000 --- a/interfaces/innerkits/app_manager/include/appmgr/render_scheduler_host.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_APPEXECFWK_CORE_INCLUDE_APPMGR_RENDER_SCHEDULER_HOST_H -#define FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_APPEXECFWK_CORE_INCLUDE_APPMGR_RENDER_SCHEDULER_HOST_H - -#include - -#include "irender_scheduler.h" -#include "iremote_object.h" -#include "iremote_stub.h" -#include "nocopyable.h" - -namespace OHOS { -namespace AppExecFwk { -/** - * @class RenderSchedulerHost - * RenderScheduler stub. - */ -class RenderSchedulerHost : public IRemoteStub { -public: - RenderSchedulerHost(); - virtual ~RenderSchedulerHost(); - - virtual int OnRemoteRequest( - uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; - -private: - int32_t HandleNotifyBrowserFd(MessageParcel &data, MessageParcel &reply); - - using RenderSchedulerFunc = int32_t (RenderSchedulerHost::*)(MessageParcel &data, MessageParcel &reply); - std::map memberFuncMap_; - - DISALLOW_COPY_AND_MOVE(RenderSchedulerHost); -}; -} // namespace AppExecFwk -} // namespace OHOS - -#endif // FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_APPEXECFWK_CORE_INCLUDE_APPMGR_RENDER_SCHEDULER_HOST_H diff --git a/interfaces/innerkits/app_manager/include/appmgr/render_scheduler_proxy.h b/interfaces/innerkits/app_manager/include/appmgr/render_scheduler_proxy.h deleted file mode 100644 index 196fe3d9d06648c3bf16bb89df9824fca3473f97..0000000000000000000000000000000000000000 --- a/interfaces/innerkits/app_manager/include/appmgr/render_scheduler_proxy.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_APPEXECFWK_CORE_INCLUDE_APPMGR_RENDER_SCHEDULER_PROXY_H -#define FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_APPEXECFWK_CORE_INCLUDE_APPMGR_RENDER_SCHEDULER_PROXY_H - -#include "irender_scheduler.h" - -#include "iremote_proxy.h" - -namespace OHOS { -namespace AppExecFwk { -/** - * @class RenderSchedulerProxy - * RenderScheduler proxy. - */ -class RenderSchedulerProxy : public IRemoteProxy { -public: - explicit RenderSchedulerProxy(const sptr &impl); - - virtual ~RenderSchedulerProxy() = default; - - /** - * Notify Browser's fd to render process. - * - * @param ipcFd, ipc file descriptior for web browser and render process. - * @param sharedFd, shared memory file descriptior. - */ - virtual void NotifyBrowserFd(int32_t ipcFd, int32_t sharedFd) override; - -private: - bool WriteInterfaceToken(MessageParcel &data); - static inline BrokerDelegator delegator_; -}; -} // namespace AppExecFwk -} // namespace OHOS - -#endif // FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_APPEXECFWK_CORE_INCLUDE_APPMGR_RENDER_SCHEDULER_PROXY_H diff --git a/interfaces/innerkits/app_manager/src/appmgr/ams_mgr_proxy.cpp b/interfaces/innerkits/app_manager/src/appmgr/ams_mgr_proxy.cpp index f0801563e3057fbf95a848a2dc9fd13d570b9692..d1b349653f5b1691c0ab686c3d20f310cb7fc3f0 100644 --- a/interfaces/innerkits/app_manager/src/appmgr/ams_mgr_proxy.cpp +++ b/interfaces/innerkits/app_manager/src/appmgr/ams_mgr_proxy.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -170,6 +170,27 @@ void AmsMgrProxy::RegisterAppStateCallback(const sptr &callba APP_LOGD("end"); } +void AmsMgrProxy::Reset() +{ + APP_LOGD("start"); + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + if (!WriteInterfaceToken(data)) { + return; + } + sptr remote = Remote(); + if (remote == nullptr) { + APP_LOGE("Remote() is NULL"); + return; + } + int32_t ret = remote->SendRequest(static_cast(IAmsMgr::Message::RESET), data, reply, option); + if (ret != NO_ERROR) { + APP_LOGW("SendRequest is failed, error code: %{public}d", ret); + } + APP_LOGD("end"); +} + void AmsMgrProxy::AbilityBehaviorAnalysis(const sptr &token, const sptr &preToken, const int32_t visibility, const int32_t perceptibility, const int32_t connectionState) { diff --git a/interfaces/innerkits/app_manager/src/appmgr/ams_mgr_stub.cpp b/interfaces/innerkits/app_manager/src/appmgr/ams_mgr_stub.cpp index ec7cc1ef19350af6f118917dc7ea969eeb9a65d7..eb7e502a84410a65efdeb1a457493561726f0c6d 100644 --- a/interfaces/innerkits/app_manager/src/appmgr/ams_mgr_stub.cpp +++ b/interfaces/innerkits/app_manager/src/appmgr/ams_mgr_stub.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -40,6 +40,7 @@ AmsMgrStub::AmsMgrStub() &AmsMgrStub::HandleUpdateExtensionState; memberFuncMap_[static_cast(IAmsMgr::Message::REGISTER_APP_STATE_CALLBACK)] = &AmsMgrStub::HandleRegisterAppStateCallback; + memberFuncMap_[static_cast(IAmsMgr::Message::RESET)] = &AmsMgrStub::HandleReset; memberFuncMap_[static_cast(IAmsMgr::Message::ABILITY_BEHAVIOR_ANALYSIS)] = &AmsMgrStub::HandleAbilityBehaviorAnalysis; memberFuncMap_[static_cast(IAmsMgr::Message::KILL_PEOCESS_BY_ABILITY_TOKEN)] = @@ -155,6 +156,13 @@ ErrCode AmsMgrStub::HandleRegisterAppStateCallback(MessageParcel &data, MessageP return NO_ERROR; } +ErrCode AmsMgrStub::HandleReset(MessageParcel &data, MessageParcel &reply) +{ + BYTRACE(BYTRACE_TAG_APP); + Reset(); + return NO_ERROR; +} + ErrCode AmsMgrStub::HandleAbilityBehaviorAnalysis(MessageParcel &data, MessageParcel &reply) { BYTRACE(BYTRACE_TAG_APP); diff --git a/interfaces/innerkits/app_manager/src/appmgr/app_mgr_client.cpp b/interfaces/innerkits/app_manager/src/appmgr/app_mgr_client.cpp index a3f7aeb832699b096e07f71794ae5fdcdfef02b3..1591d40106c7d81a460e4d2adc22085b9beed6cd 100644 --- a/interfaces/innerkits/app_manager/src/appmgr/app_mgr_client.cpp +++ b/interfaces/innerkits/app_manager/src/appmgr/app_mgr_client.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -106,6 +106,19 @@ AppMgrResultCode AppMgrClient::RegisterAppStateCallback(const sptr service = iface_cast(remote_); + if (service != nullptr) { + sptr amsService = service->GetAmsMgr(); + if (amsService != nullptr) { + amsService->Reset(); + return AppMgrResultCode::RESULT_OK; + } + } + return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED; +} + AppMgrResultCode AppMgrClient::AbilityBehaviorAnalysis(const sptr &token, const sptr &preToken, const int32_t visibility, const int32_t perceptibility, const int32_t connectionState) @@ -234,6 +247,26 @@ AppMgrResultCode AppMgrClient::GetConfiguration(Configuration& config) return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED; } +AppMgrResultCode AppMgrClient::SetAppFreezingTime(int time) +{ + sptr service = iface_cast(remote_); + if (service != nullptr) { + service->SetAppFreezingTime(time); + return AppMgrResultCode::RESULT_OK; + } + return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED; +} + +AppMgrResultCode AppMgrClient::GetAppFreezingTime(int &time) +{ + sptr service = iface_cast(remote_); + if (service != nullptr) { + service->GetAppFreezingTime(time); + return AppMgrResultCode::RESULT_OK; + } + return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED; +} + AppMgrResultCode AppMgrClient::ConnectAppMgrService() { if (!serviceManager_) { @@ -414,37 +447,5 @@ int AppMgrClient::GetAbilityRecordsByProcessID(const int pid, std::vectorGetAbilityRecordsByProcessID(pid, tokens); } - -int AppMgrClient::StartRenderProcess(const std::string &renderParam, int32_t ipcFd, - int32_t sharedFd, pid_t &renderPid) -{ - if (!remote_) { - ConnectAppMgrService(); - } - - sptr service = iface_cast(remote_); - if (service != nullptr) { - return service->StartRenderProcess(renderParam, ipcFd, sharedFd, renderPid); - } - return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED; -} - -void AppMgrClient::AttachRenderProcess(const sptr &renderScheduler) -{ - if (!renderScheduler) { - APP_LOGI("renderScheduler is nullptr"); - return; - } - - if (!remote_) { - ConnectAppMgrService(); - } - - sptr service = iface_cast(remote_); - if (service != nullptr) { - APP_LOGI("AttachRenderProcess"); - service->AttachRenderProcess(renderScheduler->AsObject()); - } -} } // namespace AppExecFwk } // namespace OHOS diff --git a/interfaces/innerkits/app_manager/src/appmgr/app_mgr_proxy.cpp b/interfaces/innerkits/app_manager/src/appmgr/app_mgr_proxy.cpp index 6b36e57d4fc50cf100a2a1b16981c1fbb5394b0a..a552833259782993c7a0932ff3bfa03da2704812 100644 --- a/interfaces/innerkits/app_manager/src/appmgr/app_mgr_proxy.cpp +++ b/interfaces/innerkits/app_manager/src/appmgr/app_mgr_proxy.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -226,6 +226,34 @@ int32_t AppMgrProxy::ClearUpApplicationData(const std::string &bundleName) return reply.ReadInt32(); } +int32_t AppMgrProxy::IsBackgroundRunningRestricted(const std::string &bundleName) +{ + APP_LOGD("start"); + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + if (!WriteInterfaceToken(data)) { + return ERR_FLATTEN_OBJECT; + } + sptr remote = Remote(); + if (remote == nullptr) { + APP_LOGE("Remote() is NULL"); + return ERR_NULL_OBJECT; + } + if (!data.WriteString(bundleName)) { + APP_LOGE("parcel WriteString failed"); + return ERR_FLATTEN_OBJECT; + } + int32_t ret = remote->SendRequest( + static_cast(IAppMgr::Message::APP_IS_BACKGROUND_RUNNING_RESTRICTED), data, reply, option); + if (ret != NO_ERROR) { + APP_LOGW("SendRequest is failed, error code: %{public}d", ret); + return ret; + } + APP_LOGD("end"); + return reply.ReadInt32(); +} + int32_t AppMgrProxy::GetAllRunningProcesses(std::vector &info) { APP_LOGD("start"); @@ -298,6 +326,46 @@ bool AppMgrProxy::SendTransactCmd(IAppMgr::Message code, MessageParcel &data, Me return true; } +void AppMgrProxy::SetAppFreezingTime(int time) +{ + APP_LOGD("start"); + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + if (!WriteInterfaceToken(data)) { + return; + } + + if (!data.WriteInt32(time)) { + APP_LOGE("parcel WriteInt32 failed"); + return; + } + if (!SendTransactCmd(IAppMgr::Message::APP_SET_APP_FREEZING_TIME, data, reply)) { + APP_LOGE("SendTransactCmd faild"); + return; + } + APP_LOGD("end"); +} + +void AppMgrProxy::GetAppFreezingTime(int &time) +{ + APP_LOGD("start"); + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + if (!WriteInterfaceToken(data)) { + APP_LOGE("WriteInterfaceToken faild"); + return; + } + + if (!SendTransactCmd(IAppMgr::Message::APP_GET_APP_FREEZING_TIME, data, reply)) { + APP_LOGE("SendTransactCmd faild"); + return; + } + time = reply.ReadInt32(); + APP_LOGE("get freeze time : %{public}d ", time); +} + /** * Get system memory information. * @param SystemMemoryAttr, memory information. @@ -537,73 +605,5 @@ int AppMgrProxy::GetAbilityRecordsByProcessID(const int pid, std::vectorSendRequest(static_cast(IAppMgr::Message::START_RENDER_PROCESS), data, reply, option); - if (ret != NO_ERROR) { - APP_LOGW("StartRenderProcess SendRequest is failed, error code: %{public}d", ret); - return ret; - } - - auto result = reply.ReadInt32(); - renderPid = reply.ReadInt32(); - if (result != 0) { - APP_LOGW("StartRenderProcess failed, result: %{public}d", ret); - return ret; - } - return 0; -} - -void AppMgrProxy::AttachRenderProcess(const sptr &renderScheduler) -{ - if (!renderScheduler) { - APP_LOGE("renderScheduler is null"); - return; - } - - APP_LOGD("AttachRenderProcess start"); - MessageParcel data; - MessageParcel reply; - MessageOption option; - if (!WriteInterfaceToken(data)) { - return; - } - if (!data.WriteParcelable(renderScheduler)) { - APP_LOGE("renderScheduler write failed."); - return; - } - - if (!SendTransactCmd(IAppMgr::Message::ATTACH_RENDER_PROCESS, data, reply)) { - APP_LOGE("SendTransactCmd ATTACH_RENDER_PROCESS faild"); - return; - } -} } // namespace AppExecFwk } // namespace OHOS diff --git a/interfaces/innerkits/app_manager/src/appmgr/app_mgr_stub.cpp b/interfaces/innerkits/app_manager/src/appmgr/app_mgr_stub.cpp index 12bc8d566b0101d617f80c8808b51294c4baf1d7..e5ba070ede898d1c8681201438b6494e334b53e6 100644 --- a/interfaces/innerkits/app_manager/src/appmgr/app_mgr_stub.cpp +++ b/interfaces/innerkits/app_manager/src/appmgr/app_mgr_stub.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -48,10 +48,16 @@ AppMgrStub::AppMgrStub() memberFuncMap_[static_cast(IAppMgr::Message::APP_GET_MGR_INSTANCE)] = &AppMgrStub::HandleGetAmsMgr; memberFuncMap_[static_cast(IAppMgr::Message::APP_CLEAR_UP_APPLICATION_DATA)] = &AppMgrStub::HandleClearUpApplicationData; + memberFuncMap_[static_cast(IAppMgr::Message::APP_IS_BACKGROUND_RUNNING_RESTRICTED)] = + &AppMgrStub::HandleIsBackgroundRunningRestricted; memberFuncMap_[static_cast(IAppMgr::Message::APP_GET_ALL_RUNNING_PROCESSES)] = &AppMgrStub::HandleGetAllRunningProcesses; memberFuncMap_[static_cast(IAppMgr::Message::APP_GET_RUNNING_PROCESSES_BY_USER_ID)] = &AppMgrStub::HandleGetProcessRunningInfosByUserId; + memberFuncMap_[static_cast(IAppMgr::Message::APP_SET_APP_FREEZING_TIME)] = + &AppMgrStub::HandleSetAppFreezingTime; + memberFuncMap_[static_cast(IAppMgr::Message::APP_GET_APP_FREEZING_TIME)] = + &AppMgrStub::HandleGetAppFreezingTime; memberFuncMap_[static_cast(IAppMgr::Message::APP_GET_SYSTEM_MEMORY_ATTR)] = &AppMgrStub::HandleGetSystemMemoryAttr; memberFuncMap_[static_cast(IAppMgr::Message::APP_ADD_ABILITY_STAGE_INFO_DONE)] = @@ -70,10 +76,6 @@ AppMgrStub::AppMgrStub() &AppMgrStub::HandleScheduleAcceptWantDone; memberFuncMap_[static_cast(IAppMgr::Message::APP_GET_ABILITY_RECORDS_BY_PROCESS_ID)] = &AppMgrStub::HandleGetAbilityRecordsByProcessID; - memberFuncMap_[static_cast(IAppMgr::Message::START_RENDER_PROCESS)] = - &AppMgrStub::HandleStartRenderProcess; - memberFuncMap_[static_cast(IAppMgr::Message::ATTACH_RENDER_PROCESS)] = - &AppMgrStub::HandleAttachRenderProcess; } AppMgrStub::~AppMgrStub() @@ -175,6 +177,15 @@ int32_t AppMgrStub::HandleClearUpApplicationData(MessageParcel &data, MessagePar return NO_ERROR; } +int32_t AppMgrStub::HandleIsBackgroundRunningRestricted(MessageParcel &data, MessageParcel &reply) +{ + BYTRACE(BYTRACE_TAG_APP); + std::string bundleName = data.ReadString(); + int32_t result = IsBackgroundRunningRestricted(bundleName); + reply.WriteInt32(result); + return NO_ERROR; +} + int32_t AppMgrStub::HandleGetAllRunningProcesses(MessageParcel &data, MessageParcel &reply) { BYTRACE(BYTRACE_TAG_APP); @@ -210,6 +221,22 @@ int32_t AppMgrStub::HandleGetProcessRunningInfosByUserId(MessageParcel &data, Me return NO_ERROR; } +int32_t AppMgrStub::HandleSetAppFreezingTime(MessageParcel &data, MessageParcel &reply) +{ + BYTRACE(BYTRACE_TAG_APP); + SetAppFreezingTime(data.ReadInt32()); + return NO_ERROR; +} + +int32_t AppMgrStub::HandleGetAppFreezingTime(MessageParcel &data, MessageParcel &reply) +{ + BYTRACE(BYTRACE_TAG_APP); + int time = 0; + GetAppFreezingTime(time); + reply.WriteInt32(time); + return NO_ERROR; +} + int32_t AppMgrStub::HandleGetSystemMemoryAttr(MessageParcel &data, MessageParcel &reply) { BYTRACE(BYTRACE_TAG_APP); @@ -336,30 +363,5 @@ int32_t AppMgrStub::HandleGetAbilityRecordsByProcessID(MessageParcel &data, Mess } return NO_ERROR; } - -int32_t AppMgrStub::HandleStartRenderProcess(MessageParcel &data, MessageParcel &reply) -{ - std::string renderParam = data.ReadString(); - int32_t ipcFd = data.ReadFileDescriptor(); - int32_t sharedFd = data.ReadFileDescriptor(); - int32_t renderPid = 0; - int32_t result = StartRenderProcess(renderParam, ipcFd, sharedFd, renderPid); - if (!reply.WriteInt32(result)) { - APP_LOGE("write result error."); - return ERR_INVALID_VALUE; - } - if (!reply.WriteInt32(renderPid)) { - APP_LOGE("write renderPid error."); - return ERR_INVALID_VALUE; - } - return result; -} - -int32_t AppMgrStub::HandleAttachRenderProcess(MessageParcel &data, MessageParcel &reply) -{ - sptr scheduler = data.ReadParcelable(); - AttachRenderProcess(scheduler); - return NO_ERROR; -} } // namespace AppExecFwk } // namespace OHOS diff --git a/interfaces/innerkits/app_manager/src/appmgr/render_scheduler_host.cpp b/interfaces/innerkits/app_manager/src/appmgr/render_scheduler_host.cpp deleted file mode 100644 index 91a2db26d845aa4966508277fab5f0592da0392b..0000000000000000000000000000000000000000 --- a/interfaces/innerkits/app_manager/src/appmgr/render_scheduler_host.cpp +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "render_scheduler_host.h" - -#include "app_log_wrapper.h" -#include "ipc_types.h" - -namespace OHOS { -namespace AppExecFwk { -RenderSchedulerHost::RenderSchedulerHost() -{ - memberFuncMap_[static_cast(IRenderScheduler::Message::NOTIFY_BROWSER_FD)] = - &RenderSchedulerHost::HandleNotifyBrowserFd; -} - -RenderSchedulerHost::~RenderSchedulerHost() -{ - memberFuncMap_.clear(); -} - -int RenderSchedulerHost::OnRemoteRequest(uint32_t code, MessageParcel &data, - MessageParcel &reply, MessageOption &option) -{ - APP_LOGI("RenderSchedulerHost::OnReceived, code = %{public}d, flags= %{public}d.", code, option.GetFlags()); - std::u16string descriptor = RenderSchedulerHost::GetDescriptor(); - std::u16string remoteDescriptor = data.ReadInterfaceToken(); - if (descriptor != remoteDescriptor) { - APP_LOGE("local descriptor is not equal to remote"); - return ERR_INVALID_STATE; - } - - auto itFunc = memberFuncMap_.find(code); - if (itFunc != memberFuncMap_.end()) { - auto memberFunc = itFunc->second; - if (memberFunc != nullptr) { - return (this->*memberFunc)(data, reply); - } - } - return IPCObjectStub::OnRemoteRequest(code, data, reply, option); -} - -int RenderSchedulerHost::HandleNotifyBrowserFd(MessageParcel &data, MessageParcel &reply) -{ - int32_t ipcFd = data.ReadFileDescriptor(); - int32_t sharedFd = data.ReadFileDescriptor(); - NotifyBrowserFd(ipcFd, sharedFd); - return 0; -} -} // namespace AppExecFwk -} // namespace OHOS diff --git a/interfaces/innerkits/app_manager/src/appmgr/render_scheduler_proxy.cpp b/interfaces/innerkits/app_manager/src/appmgr/render_scheduler_proxy.cpp deleted file mode 100644 index e409655b648f9b964c9333fec3ad12231413dd99..0000000000000000000000000000000000000000 --- a/interfaces/innerkits/app_manager/src/appmgr/render_scheduler_proxy.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "render_scheduler_proxy.h" - -#include "ipc_types.h" - -#include "app_log_wrapper.h" - -namespace OHOS { -namespace AppExecFwk { -RenderSchedulerProxy::RenderSchedulerProxy( - const sptr &impl) : IRemoteProxy(impl) -{} - -bool RenderSchedulerProxy::WriteInterfaceToken(MessageParcel &data) -{ - if (!data.WriteInterfaceToken(RenderSchedulerProxy::GetDescriptor())) { - APP_LOGE("write interface token failed"); - return false; - } - return true; -} - -void RenderSchedulerProxy::NotifyBrowserFd(int32_t ipcFd, int32_t sharedFd) -{ - APP_LOGD("NotifyBrowserFd start"); - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_ASYNC); - if (!WriteInterfaceToken(data)) { - return; - } - - if (!data.WriteFileDescriptor(ipcFd) || !data.WriteFileDescriptor(sharedFd)) { - APP_LOGE("want fd failed, ipcFd:%{public}d, sharedFd:%{public}d", ipcFd, sharedFd); - return; - } - - sptr remote = Remote(); - if (remote == nullptr) { - APP_LOGE("Remote() is NULL"); - return; - } - int32_t ret = remote->SendRequest( - static_cast(IRenderScheduler::Message::NOTIFY_BROWSER_FD), - data, reply, option); - if (ret != NO_ERROR) { - APP_LOGW("SendRequest is failed, error code: %{public}d", ret); - } - APP_LOGD("NotifyBrowserFd end"); -} -} // namespace AppExecFwk -} // namespace OHOS diff --git a/interfaces/innerkits/form_manager/src/form_provider_data.cpp b/interfaces/innerkits/form_manager/src/form_provider_data.cpp index da96cab7fa96772f6529ee2b907e1cd2e98a8c87..66072d552401a7793ffaaad31772a78e60843701 100755 --- a/interfaces/innerkits/form_manager/src/form_provider_data.cpp +++ b/interfaces/innerkits/form_manager/src/form_provider_data.cpp @@ -16,7 +16,6 @@ #include #include #include -#include #include #include "form_provider_data.h" @@ -106,10 +105,6 @@ void FormProviderData::AddImageData(std::string picName, char *data, int32_t siz return; } - auto iterator = rawImageBytesMap_.find(picName); - if (iterator != rawImageBytesMap_.end()) { - delete[] iterator->second.first; - } rawImageBytesMap_[picName] = std::make_pair(data, size); imageDataState_ = IMAGE_DATA_STATE_ADDED; @@ -123,24 +118,34 @@ void FormProviderData::AddImageData(std::string picName, char *data, int32_t siz void FormProviderData::AddImageData(std::string picName, int fd) { HILOG_INFO("%{public}s called", __func__); - if (fd < 0) { + if (fd <= 0) { return; } - - int32_t size = lseek(fd, 0L, SEEK_END); - if (size <= 0) { - HILOG_ERROR("Get file size failed, errno is %{public}d", errno); + std::string fdPath = "/proc/self/fd/" + std::to_string(fd); + char fileName[PATH_MAX + 1] = {0}; + int ret = readlink(fdPath.c_str(), fileName, PATH_MAX); + if (ret < 0 || ret > PATH_MAX) { + HILOG_ERROR("Get fileName failed, ret is: %{public}d!", ret); return; } - HILOG_INFO("File size is %{public}d", size); - if (lseek(fd, 0L, SEEK_SET) == -1) { + fileName[ret] = '\0'; + + std::ifstream file(fileName, std::ios::in | std::ios::binary | std::ios::ate); + if (!file.is_open()) { + HILOG_INFO("open failed"); return; } - char *data = new char[size]; - if (read(fd, data, size) < 0) { - HILOG_ERROR("Read failed, errno is %{public}d", errno); + + file.seekg(0, std::ios::end); + int32_t size = file.tellg(); + HILOG_INFO("File size %{public}d", size); + if (size < 0) { return; } + file.seekg(0, std::ios::beg); + char *data = new char[size]; + file.read(data, size); + file.close(); AddImageData(picName, data, size); HILOG_INFO("%{public}s called end.", __func__); } diff --git a/interfaces/innerkits/runtime/include/js_runtime_utils.h b/interfaces/innerkits/runtime/include/js_runtime_utils.h index 85fb368679d3951753174873a863e55febdde75b..047fe42ea4539622169f55d7f55d917094e4ff9e 100644 --- a/interfaces/innerkits/runtime/include/js_runtime_utils.h +++ b/interfaces/innerkits/runtime/include/js_runtime_utils.h @@ -81,11 +81,9 @@ inline bool ConvertFromJsValue(NativeEngine& engine, NativeValue* jsValue, T& va if (stringValue == nullptr) { return false; } - size_t len = stringValue->GetLength() + 1; - auto buffer = std::make_unique(len); - size_t strLength = 0; - stringValue->GetCString(buffer.get(), len, &strLength); - value = buffer.get(); + size_t len = stringValue->GetLength(); + value.resize(len); + stringValue->GetCString(value.data(), len, &len); return true; } else if constexpr (std::is_enum_v) { auto numberValue = ConvertNativeValueTo(jsValue); diff --git a/ohos.build b/ohos.build index 210459f71cf8321a2138e613b7a54586556da773..b40f83d76aef96ef371383ff15167b0b0bec7b39 100644 --- a/ohos.build +++ b/ohos.build @@ -82,9 +82,7 @@ "appmgr/iapp_state_callback.h", "appmgr/app_state_callback_host.h", "appmgr/app_mgr_constants.h", - "appmgr/app_process_data.h", - "appmgr/irender_scheduler.h", - "appmgr/render_scheduler_host.h" + "appmgr/app_process_data.h" ] }, "name": "//foundation/aafwk/standard/interfaces/innerkits/app_manager:app_manager" diff --git a/services/BUILD.gn b/services/BUILD.gn index 5770614a362fd4896f25b4c86720fcd783b9d0f1..c11ef1cb046b90849cfd5fe7ab504e9cdfe3290b 100644 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -15,7 +15,6 @@ group("services_target") { deps = [ "abilitymgr:abilityms_target", "appmgr:ams_target", - "common:perm_verification", "dataobsmgr:dataobsms", "uripermmgr:upms_target", ] diff --git a/services/abilitymgr/BUILD.gn b/services/abilitymgr/BUILD.gn index 99e4e269f86b3b351ac8d4dcca68cea7844952d2..15cce1742287e2a8927c27b2083917e593b09fb9 100644 --- a/services/abilitymgr/BUILD.gn +++ b/services/abilitymgr/BUILD.gn @@ -80,7 +80,6 @@ ohos_shared_library("abilityms") { "${innerkits_path}/base:base", "${innerkits_path}/uri_permission:uri_permission_mgr", "${innerkits_path}/want:want", - "${services_path}/common:perm_verification", "//base/account/os_account/frameworks/osaccount/native:os_account_innerkits", "//base/global/i18n_standard/frameworks/intl:intl_util", "//base/hiviewdfx/hiview/adapter/utility:hiview_adapter_utility", diff --git a/services/abilitymgr/abilitymgr.gni b/services/abilitymgr/abilitymgr.gni index 286ba3d4b74cb457e93b904959af08ffdec6b2c9..c23b483029c2ffc4719f08573c950ba254cde607 100644 --- a/services/abilitymgr/abilitymgr.gni +++ b/services/abilitymgr/abilitymgr.gni @@ -46,6 +46,7 @@ abilityms_files = [ "${services_path}/abilitymgr/src/ability_mission_info.cpp", "${services_path}/abilitymgr/src/mission_description_info.cpp", "${services_path}/abilitymgr/src/mission_snapshot.cpp", + "${services_path}/abilitymgr/src/kernal_system_app_manager.cpp", "${services_path}/abilitymgr/src/caller_info.cpp", "${services_path}/abilitymgr/src/sender_info.cpp", "${services_path}/abilitymgr/src/wants_info.cpp", diff --git a/services/abilitymgr/include/ability_connect_manager.h b/services/abilitymgr/include/ability_connect_manager.h index 99fa6b0c8f47488040d45cf774a30064af437b71..09313891463febe0d19c531ddc500935ac805494 100644 --- a/services/abilitymgr/include/ability_connect_manager.h +++ b/services/abilitymgr/include/ability_connect_manager.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -183,13 +183,9 @@ public: ConnectListType GetConnectRecordListByCallback(sptr callback); void RemoveAll(); - void GetExtensionRunningInfos(int upperLimit, std::vector &info, - const int32_t userId, bool isPerm); + void GetExtensionRunningInfos(int upperLimit, std::vector &info, const int32_t userId); - void GetAbilityRunningInfos(std::vector &info, bool isPerm); - - void GetExtensionRunningInfo(std::shared_ptr &abilityRecord, const int32_t userId, - std::vector &info); + void GetAbilityRunningInfos(std::vector &info); /** * SetEventHandler. diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h index 705e9ea224d7219beda2d30b5b90f26441203acd..e413cb5de48c7fbb01bf786f154a28b5f7b3ea58 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -32,6 +32,7 @@ #include "data_ability_manager.h" #include "hilog_wrapper.h" #include "iremote_object.h" +#include "kernal_system_app_manager.h" #include "mission_list_manager.h" #include "system_ability.h" #include "uri.h" @@ -746,9 +747,6 @@ public: virtual int GetExtensionRunningInfos(int upperLimit, std::vector &info) override; virtual int GetProcessRunningInfos(std::vector &info) override; int GetProcessRunningInfosByUserId(std::vector &info, int32_t userId); - void GetAbilityRunningInfo(std::vector &info, std::shared_ptr &abilityRecord); - void GetExtensionRunningInfo(std::shared_ptr &abilityRecord, const int32_t userId, - std::vector &info); int GetMissionSaveTime() const; @@ -1141,10 +1139,6 @@ private: bool IsNeedTimeoutForTest(const std::string &abilityName, const std::string &state) const; void StartupResidentProcess(); - int VerifyMissionPermission(); - - int VerifyAccountPermission(int32_t userId); - using DumpFuncType = void (AbilityManagerService::*)(const std::string &args, std::vector &info); std::map dumpFuncMap_; @@ -1175,6 +1169,7 @@ private: std::shared_ptr systemDataAbilityManager_; std::unordered_map> pendingWantManagers_; std::shared_ptr pendingWantManager_; + std::shared_ptr systemAppManager_; std::shared_ptr amsConfigResolver_; const static std::map dumpMap; const static std::map dumpsysMap; diff --git a/services/abilitymgr/include/data_ability_manager.h b/services/abilitymgr/include/data_ability_manager.h index f1ac566670dc601b8ab86a70f4e2594efdab7dd8..a3561ea6511e479fe93d7a4c387de7af0ab2cbf9 100644 --- a/services/abilitymgr/include/data_ability_manager.h +++ b/services/abilitymgr/include/data_ability_manager.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -48,8 +48,8 @@ public: void Dump(const char *func, int line); void DumpState(std::vector &info, const std::string &args = "") const; void DumpSysState(std::vector &info, bool isClient = false, const std::string &args = "") const; + void GetAbilityRunningInfos(std::vector &info); bool ContainsDataAbility(const sptr &scheduler); - void GetAbilityRunningInfos(std::vector &info, bool isPerm); private: using DataAbilityRecordPtr = std::shared_ptr; diff --git a/services/abilitymgr/include/kernal_system_app_manager.h b/services/abilitymgr/include/kernal_system_app_manager.h new file mode 100644 index 0000000000000000000000000000000000000000..eb30240281ad46de6d5411a11099491cfd2ab805 --- /dev/null +++ b/services/abilitymgr/include/kernal_system_app_manager.h @@ -0,0 +1,168 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_AAFWK_KERNAL_SYSTEM_APP_MANAGER_H +#define OHOS_AAFWK_KERNAL_SYSTEM_APP_MANAGER_H + +#include +#include + +#include "mission_record.h" +#include "mission_stack.h" +#include "want.h" + +namespace OHOS { +namespace AAFwk { +/** + * @class KernalSystemAppManager + * KernalSystemAppManager provides a facility for managing systerm ability life cycle. + */ +class KernalSystemAppManager : public std::enable_shared_from_this { +public: + explicit KernalSystemAppManager(int userId); + ~KernalSystemAppManager(); + + /** + * init kernal system app manager. + * + */ + void Init(); + /** + * StartAbility with request. + * + * @param abilityRequest, the request of the ability to start. + * @return Returns ERR_OK on success, others on failure. + */ + int StartAbility(const AbilityRequest &abilityRequest); + /** + * attach ability thread ipc object. + * + * @param scheduler, ability thread ipc object. + * @param token, the token of ability. + * @return Returns ERR_OK on success, others on failure. + */ + int AttachAbilityThread(const sptr &scheduler, const sptr &token); + /** + * AbilityTransitionDone, ability call this interface after lift cycle was changed. + * + * @param token,.ability's token. + * @param state,.the state of ability lift cycle. + * @return Returns ERR_OK on success, others on failure. + */ + int AbilityTransitionDone(const sptr &token, int state); + /** + * OnAbilityRequestDone, app manager service call this interface after ability request done. + * + * @param token,ability's token. + * @param state,the state of ability lift cycle. + */ + void OnAbilityRequestDone(const sptr &token, const int32_t state); + + void OnAppStateChanged(const AppInfo &info); + + /** + * get manager's user id. + */ + int GetManagerUserId() const; + + void DumpState(std::vector &info); + + void DumpSysState(std::vector &info, bool isClient = false); + + void OnAbilityDied(std::shared_ptr abilityRecord); + + void OnTimeOut(uint32_t msgId, int64_t eventId); + + /** + * get the ability record by token. + * + * @return abilityRecord, target ability. + */ + std::shared_ptr GetAbilityRecordByToken(const sptr &token); + + void RestartAbility(const std::shared_ptr abilityRecord); + +private: + /** + * StartAbilityLocked. + * + * @param abilityRequest the request of the ability to start. + * @return Returns ERR_OK on success, others on failure. + */ + int StartAbilityLocked(const AbilityRequest &abilityRequest); + /** + * push waitting ability to queue. + * + * @param abilityRequest, the request of ability. + */ + void EnqueueWaittingAbility(const AbilityRequest &abilityRequest); + /** + * pop waitting ability. + * + */ + void DequeueWaittingAbility(); + /** + * get current top ability of stack. + * + * @return top ability record. + */ + std::shared_ptr GetCurrentTopAbility() const; + /** + * get or create the target ability record of system app. + * + * @param abilityRequest, the request of ability. + * @param targetAbility, target ability record. + */ + void GetOrCreateAbilityRecord(const AbilityRequest &abilityRequest, std::shared_ptr &targetAbility); + /** + * get the flag of the target ability record. + * + * @param bundleName, target bundleName. + * @param abilityName, target ability name. + */ + static std::string GetFlagOfAbility(const std::string &bundleName, const std::string &abilityName); + /** + * get the ability record by eventId. + * + * @return abilityRecord, target ability. + */ + std::shared_ptr GetAbilityRecordByEventId(const int64_t eventId) const; + /** + * dispatch ability life cycle . + * + * @param abilityRecord. + * @param state. + */ + int DispatchActive(const std::shared_ptr &abilityRecord, int state); + int DispatchInactive(const std::shared_ptr &abilityRecord, int state); + /** + * complete ability life cycle . + * + * @param abilityRecord. + */ + void CompleteActive(const std::shared_ptr &abilityRecord); + void CompleteInactive(const std::shared_ptr &abilityRecord); + + bool RemoveAbilityRecord(std::shared_ptr ability); + +private: + std::recursive_mutex stackLock_; + std::list> abilities_; + std::queue waittingAbilityQueue_; + int userId_; +}; +} // namespace AAFwk +} // namespace OHOS +#endif // OHOS_AAFWK_KERNAL_SYSTEM_APP_MANAGER_H diff --git a/services/abilitymgr/include/mission_list_manager.h b/services/abilitymgr/include/mission_list_manager.h index 00e9b20baee520c69f2f99caf1dac5a410a5bf39..632cfb5dfe7187b595968c96cbb018c99393be3d 100644 --- a/services/abilitymgr/include/mission_list_manager.h +++ b/services/abilitymgr/include/mission_list_manager.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -322,7 +322,7 @@ public: */ bool GetMissionSnapshot(int32_t missionId, const sptr& abilityToken, MissionSnapshot& missionSnapshot); - void GetAbilityRunningInfos(std::vector &info, bool isPerm); + void GetAbilityRunningInfos(std::vector &info); /** * @brief get current top ability by bundle name diff --git a/services/abilitymgr/src/ability_connect_manager.cpp b/services/abilitymgr/src/ability_connect_manager.cpp index e09a1150e1755a22586729eb6bf02caa5555d6be..1fe56f890a166d8c1e8d34f645a6f8b9c263fe51 100755 --- a/services/abilitymgr/src/ability_connect_manager.cpp +++ b/services/abilitymgr/src/ability_connect_manager.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -990,94 +990,80 @@ void AbilityConnectManager::DumpState(std::vector &info, bool isCli } void AbilityConnectManager::GetExtensionRunningInfos(int upperLimit, std::vector &info, - const int32_t userId, bool isPerm) + const int32_t userId) { HILOG_INFO("Get extension running info."); std::lock_guard guard(Lock_); - auto mgr = shared_from_this(); - auto queryInfo = [&info, upperLimit, userId, isPerm, mgr](ServiceMapType::reference service) { + auto queryInfo = [&info, upperLimit, userId](ServiceMapType::reference service) { if (static_cast(info.size()) >= upperLimit) { return; } auto abilityRecord = service.second; CHECK_POINTER(abilityRecord); - - if (isPerm) { - mgr->GetExtensionRunningInfo(abilityRecord, userId, info); - } else { - auto callingTokenId = IPCSkeleton::GetCallingTokenID(); - auto tokenID = abilityRecord->GetApplicationInfo().accessTokenId; - if (callingTokenId == tokenID) { - mgr->GetExtensionRunningInfo(abilityRecord, userId, info); + ExtensionRunningInfo extensionInfo; + AppExecFwk::RunningProcessInfo processInfo; + extensionInfo.extension = abilityRecord->GetWant().GetElement(); + auto bms = AbilityUtil::GetBundleManager(); + CHECK_POINTER(bms); + std::vector extensionInfos; + bool queryResult = bms->QueryExtensionAbilityInfos(abilityRecord->GetWant(), + AppExecFwk::AbilityInfoFlag::GET_ABILITY_INFO_WITH_APPLICATION, userId, extensionInfos); + if (queryResult) { + HILOG_INFO("Query Extension Ability Infos Success."); + auto abilityInfo = abilityRecord->GetAbilityInfo(); + auto isExist = [&abilityInfo](const AppExecFwk::ExtensionAbilityInfo &extensionInfo) { + HILOG_INFO("%{public}s, %{public}s", extensionInfo.bundleName.c_str(), extensionInfo.name.c_str()); + return extensionInfo.bundleName == abilityInfo.bundleName && extensionInfo.name == abilityInfo.name + && extensionInfo.applicationInfo.uid == abilityInfo.applicationInfo.uid; + }; + auto infoIter = std::find_if(extensionInfos.begin(), extensionInfos.end(), isExist); + if (infoIter != extensionInfos.end()) { + HILOG_INFO("Get target success."); + extensionInfo.type = (*infoIter).type; } } + DelayedSingleton::GetInstance()-> + GetRunningProcessInfoByToken(abilityRecord->GetToken(), processInfo); + extensionInfo.pid = processInfo.pid_; + extensionInfo.uid = processInfo.uid_; + extensionInfo.processName = processInfo.processName_; + extensionInfo.startTime = abilityRecord->GetStartTime(); + ConnectListType connectRecordList = abilityRecord->GetConnectRecordList(); + for (auto &connectRecord : connectRecordList) { + CHECK_POINTER(connectRecord); + auto callerAbilityRecord = Token::GetAbilityRecordByToken(connectRecord->GetToken()); + CHECK_POINTER(callerAbilityRecord); + std::string package = callerAbilityRecord->GetAbilityInfo().bundleName; + extensionInfo.clientPackage.emplace_back(package); + } + info.emplace_back(extensionInfo); + // extension type }; std::for_each(serviceMap_.begin(), serviceMap_.end(), queryInfo); } -void AbilityConnectManager::GetAbilityRunningInfos(std::vector &info, bool isPerm) +void AbilityConnectManager::GetAbilityRunningInfos(std::vector &info) { HILOG_INFO("Query running ability infos."); std::lock_guard guard(Lock_); - auto queryInfo = [&info, isPerm](ServiceMapType::reference service) { + auto queryInfo = [&info](ServiceMapType::reference service) { auto abilityRecord = service.second; CHECK_POINTER(abilityRecord); - - if (isPerm) { - DelayedSingleton::GetInstance()->GetAbilityRunningInfo(info, abilityRecord); - } else { - auto callingTokenId = IPCSkeleton::GetCallingTokenID(); - auto tokenID = abilityRecord->GetApplicationInfo().accessTokenId; - if (callingTokenId == tokenID) { - DelayedSingleton::GetInstance()->GetAbilityRunningInfo(info, abilityRecord); - } - } + AbilityRunningInfo runningInfo; + AppExecFwk::RunningProcessInfo processInfo; + runningInfo.ability = abilityRecord->GetWant().GetElement(); + DelayedSingleton::GetInstance()-> + GetRunningProcessInfoByToken(abilityRecord->GetToken(), processInfo); + runningInfo.pid = processInfo.pid_; + runningInfo.uid = processInfo.uid_; + runningInfo.processName = processInfo.processName_; + runningInfo.startTime = abilityRecord->GetStartTime(); + runningInfo.abilityState = static_cast(abilityRecord->GetAbilityState()); + info.emplace_back(runningInfo); }; std::for_each(serviceMap_.begin(), serviceMap_.end(), queryInfo); } - -void AbilityConnectManager::GetExtensionRunningInfo(std::shared_ptr &abilityRecord, const int32_t userId, - std::vector &info) -{ - ExtensionRunningInfo extensionInfo; - AppExecFwk::RunningProcessInfo processInfo; - extensionInfo.extension = abilityRecord->GetWant().GetElement(); - auto bms = AbilityUtil::GetBundleManager(); - CHECK_POINTER(bms); - std::vector extensionInfos; - bool queryResult = bms->QueryExtensionAbilityInfos(abilityRecord->GetWant(), - AppExecFwk::AbilityInfoFlag::GET_ABILITY_INFO_WITH_APPLICATION, userId, extensionInfos); - if (queryResult) { - HILOG_INFO("Query Extension Ability Infos Success."); - auto abilityInfo = abilityRecord->GetAbilityInfo(); - auto isExist = [&abilityInfo](const AppExecFwk::ExtensionAbilityInfo &extensionInfo) { - HILOG_INFO("%{public}s, %{public}s", extensionInfo.bundleName.c_str(), extensionInfo.name.c_str()); - return extensionInfo.bundleName == abilityInfo.bundleName && extensionInfo.name == abilityInfo.name - && extensionInfo.applicationInfo.uid == abilityInfo.applicationInfo.uid; - }; - auto infoIter = std::find_if(extensionInfos.begin(), extensionInfos.end(), isExist); - if (infoIter != extensionInfos.end()) { - HILOG_INFO("Get target success."); - extensionInfo.type = (*infoIter).type; - } - } - DelayedSingleton::GetInstance()-> - GetRunningProcessInfoByToken(abilityRecord->GetToken(), processInfo); - extensionInfo.pid = processInfo.pid_; - extensionInfo.uid = processInfo.uid_; - extensionInfo.processName = processInfo.processName_; - extensionInfo.startTime = abilityRecord->GetStartTime(); - ConnectListType connectRecordList = abilityRecord->GetConnectRecordList(); - for (auto &connectRecord : connectRecordList) { - CHECK_POINTER(connectRecord); - auto callerAbilityRecord = Token::GetAbilityRecordByToken(connectRecord->GetToken()); - CHECK_POINTER(callerAbilityRecord); - std::string package = callerAbilityRecord->GetAbilityInfo().bundleName; - extensionInfo.clientPackage.emplace_back(package); - } - info.emplace_back(extensionInfo); -} } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index 5ea8d0a8ede88e650bbacc6eff4f9fb783ac3eb5..f41c9e1bd3f71d2c827ebb5c9f7372401afc81fe 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -41,8 +41,6 @@ #include "lock_screen_white_list.h" #include "mission/mission_info_converter.h" #include "mission_info_mgr.h" -#include "permission_constants.h" -#include "permission_verification.h" #include "sa_mgr_client.h" #include "softbus_bus_center.h" #include "string_ex.h" @@ -191,6 +189,8 @@ bool AbilityManagerService::Init() useNewMission_ = amsConfigResolver_->IsUseNewMission(); SetStackManager(userId, true); + systemAppManager_ = std::make_shared(0); + CHECK_POINTER_RETURN_BOOL(systemAppManager_); InitMissionListManager(userId, true); @@ -264,9 +264,9 @@ int AbilityManagerService::StartAbilityInner(const Want &want, const sptrStartAbility(abilityRequest); } else { + if (IsSystemUiApp(abilityRequest.abilityInfo)) { + HILOG_DEBUG("%{public}s OldMission Start SystemUiApp", __func__); + return systemAppManager_->StartAbility(abilityRequest); + } + auto stackManager = GetStackManagerByUserId(validUserId); if (!stackManager) { HILOG_ERROR("stackManager is nullptr. userId=%{public}d", validUserId); @@ -360,9 +365,9 @@ int AbilityManagerService::StartAbility(const Want &want, const AbilityStartSett BYTRACE_NAME(BYTRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); HILOG_DEBUG("Start ability setting."); - if (VerifyAccountPermission(userId) == CHECK_PERMISSION_FAILED) { - HILOG_ERROR("%{public}s: Permission verification failed", __func__); - return CHECK_PERMISSION_FAILED; + if (userId != INVALID_USER_ID && !CheckCallerIsSystemAppByIpc()) { + HILOG_ERROR("caller is not systemApp"); + return CALLER_ISNOT_SYSTEMAPP; } if (callerToken != nullptr && !VerificationAllToken(callerToken)) { @@ -430,6 +435,10 @@ int AbilityManagerService::StartAbility(const Want &want, const AbilityStartSett } return missionListManager->StartAbility(abilityRequest); } else { + if (IsSystemUiApp(abilityRequest.abilityInfo)) { + return systemAppManager_->StartAbility(abilityRequest); + } + auto stackManager = GetStackManagerByUserId(validUserId); if (!stackManager) { HILOG_ERROR("stackManager is nullptr. userId=%{public}d", validUserId); @@ -445,9 +454,9 @@ int AbilityManagerService::StartAbility(const Want &want, const StartOptions &st BYTRACE_NAME(BYTRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); HILOG_DEBUG("Start ability options."); - if (VerifyAccountPermission(userId) == CHECK_PERMISSION_FAILED) { - HILOG_ERROR("%{public}s: Permission verification failed", __func__); - return CHECK_PERMISSION_FAILED; + if (userId != INVALID_USER_ID && !CheckCallerIsSystemAppByIpc()) { + HILOG_ERROR("caller is not systemApp"); + return CALLER_ISNOT_SYSTEMAPP; } if (callerToken != nullptr && !VerificationAllToken(callerToken)) { @@ -632,7 +641,7 @@ int AbilityManagerService::TerminateAbilityWithFlag(const sptr &t if ((resultWant != nullptr) && AbilityUtil::IsSystemDialogAbility( - abilityRecord->GetAbilityInfo().bundleName, abilityRecord->GetAbilityInfo().name) && + abilityRecord->GetAbilityInfo().bundleName, abilityRecord->GetAbilityInfo().name) && resultWant->HasParameter(AbilityConfig::SYSTEM_DIALOG_KEY) && resultWant->HasParameter(AbilityConfig::SYSTEM_DIALOG_CALLER_BUNDLENAME) && resultWant->HasParameter(AbilityConfig::SYSTEM_DIALOG_REQUEST_PERMISSIONS)) { @@ -972,9 +981,9 @@ int AbilityManagerService::ConnectAbility( CHECK_POINTER_AND_RETURN(connect, ERR_INVALID_VALUE); CHECK_POINTER_AND_RETURN(connect->AsObject(), ERR_INVALID_VALUE); - if (VerifyAccountPermission(userId) == CHECK_PERMISSION_FAILED) { - HILOG_ERROR("%{public}s: Permission verification failed", __func__); - return CHECK_PERMISSION_FAILED; + if (userId != INVALID_USER_ID && !CheckCallerIsSystemAppByIpc()) { + HILOG_ERROR("caller is not systemApp"); + return CALLER_ISNOT_SYSTEMAPP; } if (CheckIfOperateRemote(want)) { @@ -1372,10 +1381,11 @@ int AbilityManagerService::LockMissionForCleanup(int32_t missionId) HILOG_INFO("request unlock mission for clean up all, id :%{public}d", missionId); CHECK_POINTER_AND_RETURN(currentStackManager_, ERR_NO_INIT); - if (VerifyMissionPermission() == CHECK_PERMISSION_FAILED) { - HILOG_ERROR("%{public}s: Permission verification failed", __func__); - return CHECK_PERMISSION_FAILED; + if (!CheckCallerIsSystemAppByIpc()) { + HILOG_ERROR("caller is not system app"); + return CALLER_ISNOT_SYSTEMAPP; } + return currentMissionListManager_->SetMissionLockedState(missionId, true); } @@ -1384,10 +1394,11 @@ int AbilityManagerService::UnlockMissionForCleanup(int32_t missionId) HILOG_INFO("request unlock mission for clean up all, id :%{public}d", missionId); CHECK_POINTER_AND_RETURN(currentStackManager_, ERR_NO_INIT); - if (VerifyMissionPermission() == CHECK_PERMISSION_FAILED) { - HILOG_ERROR("%{public}s: Permission verification failed", __func__); - return CHECK_PERMISSION_FAILED; + if (!CheckCallerIsSystemAppByIpc()) { + HILOG_ERROR("caller is not system app"); + return CALLER_ISNOT_SYSTEMAPP; } + return currentMissionListManager_->SetMissionLockedState(missionId, false); } @@ -1395,11 +1406,13 @@ int AbilityManagerService::RegisterMissionListener(const sptr { HILOG_INFO("request RegisterMissionListener "); CHECK_POINTER_AND_RETURN(currentMissionListManager_, ERR_NO_INIT); + CHECK_POINTER_AND_RETURN(iBundleManager_, ERR_NO_INIT); - if (VerifyMissionPermission() == CHECK_PERMISSION_FAILED) { - HILOG_ERROR("%{public}s: Permission verification failed", __func__); - return CHECK_PERMISSION_FAILED; + if (!CheckCallerIsSystemAppByIpc()) { + HILOG_ERROR("caller is not system app"); + return CALLER_ISNOT_SYSTEMAPP; } + return currentMissionListManager_->RegisterMissionListener(listener); } @@ -1407,11 +1420,13 @@ int AbilityManagerService::UnRegisterMissionListener(const sptrUnRegisterMissionListener(listener); } @@ -1420,10 +1435,11 @@ int AbilityManagerService::GetMissionInfos(const std::string& deviceId, int32_t { HILOG_INFO("request GetMissionInfos."); CHECK_POINTER_AND_RETURN(currentMissionListManager_, ERR_NO_INIT); + CHECK_POINTER_AND_RETURN(iBundleManager_, ERR_NO_INIT); - if (VerifyMissionPermission() == CHECK_PERMISSION_FAILED) { - HILOG_ERROR("%{public}s: Permission verification failed", __func__); - return CHECK_PERMISSION_FAILED; + if (!CheckCallerIsSystemAppByIpc()) { + HILOG_ERROR("caller is not system app"); + return CALLER_ISNOT_SYSTEMAPP; } if (CheckIsRemote(deviceId)) { @@ -1451,10 +1467,11 @@ int AbilityManagerService::GetMissionInfo(const std::string& deviceId, int32_t m { HILOG_INFO("request GetMissionInfo, missionId:%{public}d", missionId); CHECK_POINTER_AND_RETURN(currentMissionListManager_, ERR_NO_INIT); + CHECK_POINTER_AND_RETURN(iBundleManager_, ERR_NO_INIT); - if (VerifyMissionPermission() == CHECK_PERMISSION_FAILED) { - HILOG_ERROR("%{public}s: Permission verification failed", __func__); - return CHECK_PERMISSION_FAILED; + if (!CheckCallerIsSystemAppByIpc()) { + HILOG_ERROR("caller is not system app"); + return CALLER_ISNOT_SYSTEMAPP; } if (CheckIsRemote(deviceId)) { @@ -1487,10 +1504,11 @@ int AbilityManagerService::CleanMission(int32_t missionId) { HILOG_INFO("request CleanMission, missionId:%{public}d", missionId); CHECK_POINTER_AND_RETURN(currentMissionListManager_, ERR_NO_INIT); + CHECK_POINTER_AND_RETURN(iBundleManager_, ERR_NO_INIT); - if (VerifyMissionPermission() == CHECK_PERMISSION_FAILED) { - HILOG_ERROR("%{public}s: Permission verification failed", __func__); - return CHECK_PERMISSION_FAILED; + if (!CheckCallerIsSystemAppByIpc()) { + HILOG_ERROR("caller is not system app"); + return CALLER_ISNOT_SYSTEMAPP; } return currentMissionListManager_->ClearMission(missionId); @@ -1500,10 +1518,11 @@ int AbilityManagerService::CleanAllMissions() { HILOG_INFO("request CleanAllMissions "); CHECK_POINTER_AND_RETURN(currentMissionListManager_, ERR_NO_INIT); + CHECK_POINTER_AND_RETURN(iBundleManager_, ERR_NO_INIT); - if (VerifyMissionPermission() == CHECK_PERMISSION_FAILED) { - HILOG_ERROR("%{public}s: Permission verification failed", __func__); - return CHECK_PERMISSION_FAILED; + if (!CheckCallerIsSystemAppByIpc()) { + HILOG_ERROR("caller is not system app"); + return CALLER_ISNOT_SYSTEMAPP; } return currentMissionListManager_->ClearAllMissions(); @@ -1513,10 +1532,11 @@ int AbilityManagerService::MoveMissionToFront(int32_t missionId) { HILOG_INFO("request MoveMissionToFront, missionId:%{public}d", missionId); CHECK_POINTER_AND_RETURN(currentMissionListManager_, ERR_NO_INIT); + CHECK_POINTER_AND_RETURN(iBundleManager_, ERR_NO_INIT); - if (VerifyMissionPermission() == CHECK_PERMISSION_FAILED) { - HILOG_ERROR("%{public}s: Permission verification failed", __func__); - return CHECK_PERMISSION_FAILED; + if (!CheckCallerIsSystemAppByIpc()) { + HILOG_ERROR("caller is not system app"); + return CALLER_ISNOT_SYSTEMAPP; } return currentMissionListManager_->MoveMissionToFront(missionId); @@ -1526,10 +1546,11 @@ int AbilityManagerService::MoveMissionToFront(int32_t missionId, const StartOpti { HILOG_INFO("request MoveMissionToFront, missionId:%{public}d", missionId); CHECK_POINTER_AND_RETURN(currentMissionListManager_, ERR_NO_INIT); + CHECK_POINTER_AND_RETURN(iBundleManager_, ERR_NO_INIT); - if (VerifyMissionPermission() == CHECK_PERMISSION_FAILED) { - HILOG_ERROR("%{public}s: Permission verification failed", __func__); - return CHECK_PERMISSION_FAILED; + if (!CheckCallerIsSystemAppByIpc()) { + HILOG_ERROR("caller is not system app"); + return CALLER_ISNOT_SYSTEMAPP; } auto options = std::make_shared(startOptions); @@ -1954,6 +1975,7 @@ void AbilityManagerService::DataDumpSysStateInner( void AbilityManagerService::SystemDumpSysStateInner( const std::string& args, std::vector& info, bool isClient, bool isUserID, int userId) { + systemAppManager_->DumpSysState(info, isClient); } void AbilityManagerService::DumpInner(const std::string &args, std::vector &info) @@ -2094,6 +2116,7 @@ void AbilityManagerService::DataDumpStateInner(const std::string &args, std::vec void AbilityManagerService::SystemDumpStateInner(const std::string &args, std::vector &info) { + systemAppManager_->DumpState(info); } void AbilityManagerService::DumpState(const std::string &args, std::vector &info) @@ -2189,6 +2212,9 @@ int AbilityManagerService::AbilityTransitionDone(const sptr &toke } return missionListManager->AbilityTransactionDone(token, state, saveData); } else { + if (IsSystemUiApp(abilityInfo)) { + return systemAppManager_->AbilityTransitionDone(token, state); + } auto stackManager = GetStackManagerByUserId(userId); if (!stackManager) { HILOG_ERROR("stackManager is nullptr. userId=%{public}d", userId); @@ -2329,6 +2355,10 @@ void AbilityManagerService::OnAbilityRequestDone(const sptr &toke } missionListManager->OnAbilityRequestDone(token, state); } else { + if (IsSystemUiApp(abilityRecord->GetAbilityInfo())) { + systemAppManager_->OnAbilityRequestDone(token, state); + break; + } auto stackManager = GetStackManagerByUserId(userId); if (!stackManager) { HILOG_ERROR("stackManager is nullptr. userId=%{public}d", userId); @@ -2349,6 +2379,7 @@ void AbilityManagerService::OnAppStateChanged(const AppInfo &info) currentMissionListManager_->OnAppStateChanged(info); } else { currentStackManager_->OnAppStateChanged(info); + systemAppManager_->OnAppStateChanged(info); } dataAbilityManager_->OnAppStateChanged(info); } @@ -2661,6 +2692,11 @@ void AbilityManagerService::OnAbilityDied(std::shared_ptr ability return; } } else { + if (systemAppManager_ && abilityRecord->IsKernalSystemAbility()) { + systemAppManager_->OnAbilityDied(abilityRecord); + return; + } + auto manager = GetStackManagerByToken(abilityRecord->GetToken()); if (manager) { manager->OnAbilityDied(abilityRecord); @@ -2703,6 +2739,11 @@ bool AbilityManagerService::IsUseNewMission() int AbilityManagerService::KillProcess(const std::string &bundleName) { HILOG_DEBUG("Kill process, bundleName: %{public}s", bundleName.c_str()); + if (!CheckCallerIsSystemAppByIpc()) { + HILOG_ERROR("caller is not systemApp"); + return CALLER_ISNOT_SYSTEMAPP; + } + auto bms = GetBundleManager(); CHECK_POINTER_AND_RETURN(bms, KILL_PROCESS_FAILED); int32_t userId = GetUserId(); @@ -2727,6 +2768,10 @@ int AbilityManagerService::KillProcess(const std::string &bundleName) int AbilityManagerService::ClearUpApplicationData(const std::string &bundleName) { HILOG_DEBUG("ClearUpApplicationData, bundleName: %{public}s", bundleName.c_str()); + if (!CheckCallerIsSystemAppByIpc()) { + HILOG_ERROR("caller is not systemApp"); + return CALLER_ISNOT_SYSTEMAPP; + } int ret = DelayedSingleton::GetInstance()->ClearUpApplicationData(bundleName); if (ret != ERR_OK) { return CLEAR_APPLICATION_DATA_FAIL; @@ -2737,13 +2782,6 @@ int AbilityManagerService::ClearUpApplicationData(const std::string &bundleName) int AbilityManagerService::UninstallApp(const std::string &bundleName) { HILOG_DEBUG("Uninstall app, bundleName: %{public}s", bundleName.c_str()); - pid_t callingPid = IPCSkeleton::GetCallingPid(); - pid_t pid = getpid(); - if (callingPid != pid) { - HILOG_ERROR("%{public}s: Not bundleMgr call.", __func__); - return CHECK_PERMISSION_FAILED; - } - CHECK_POINTER_AND_RETURN(currentStackManager_, ERR_NO_INIT); currentStackManager_->UninstallApp(bundleName); CHECK_POINTER_AND_RETURN(pendingWantManager_, ERR_NO_INIT); @@ -2847,6 +2885,9 @@ void AbilityManagerService::HandleLoadTimeOut(int64_t eventId) } } } else { + if (systemAppManager_) { + systemAppManager_->OnTimeOut(AbilityManagerService::LOAD_TIMEOUT_MSG, eventId); + } for (auto& item : stackManagers_) { if (item.second) { item.second->OnTimeOut(AbilityManagerService::LOAD_TIMEOUT_MSG, eventId); @@ -2866,6 +2907,9 @@ void AbilityManagerService::HandleActiveTimeOut(int64_t eventId) } } } else { + if (systemAppManager_) { + systemAppManager_->OnTimeOut(AbilityManagerService::ACTIVE_TIMEOUT_MSG, eventId); + } for (auto& item : stackManagers_) { if (item.second) { item.second->OnTimeOut(AbilityManagerService::ACTIVE_TIMEOUT_MSG, eventId); @@ -2902,6 +2946,9 @@ void AbilityManagerService::HandleForegroundNewTimeOut(int64_t eventId) } } } else { + if (systemAppManager_) { + systemAppManager_->OnTimeOut(AbilityManagerService::FOREGROUNDNEW_TIMEOUT_MSG, eventId); + } for (auto& item : stackManagers_) { if (item.second) { item.second->OnTimeOut(AbilityManagerService::FOREGROUNDNEW_TIMEOUT_MSG, eventId); @@ -2920,6 +2967,9 @@ void AbilityManagerService::HandleBackgroundNewTimeOut(int64_t eventId) } } } else { + if (systemAppManager_) { + systemAppManager_->OnTimeOut(AbilityManagerService::BACKGROUNDNEW_TIMEOUT_MSG, eventId); + } for (auto& item : stackManagers_) { if (item.second) { item.second->OnTimeOut(AbilityManagerService::BACKGROUNDNEW_TIMEOUT_MSG, eventId); @@ -2934,6 +2984,7 @@ bool AbilityManagerService::VerificationToken(const sptr &token) CHECK_POINTER_RETURN_BOOL(dataAbilityManager_); CHECK_POINTER_RETURN_BOOL(connectManager_); CHECK_POINTER_RETURN_BOOL(currentStackManager_); + CHECK_POINTER_RETURN_BOOL(systemAppManager_); CHECK_POINTER_RETURN_BOOL(currentMissionListManager_); if (useNewMission_) { @@ -2961,6 +3012,12 @@ bool AbilityManagerService::VerificationToken(const sptr &token) return true; } + if (!useNewMission_) { + if (systemAppManager_->GetAbilityRecordByToken(token)) { + return true; + } + } + HILOG_ERROR("Failed to verify token."); return false; } @@ -3003,6 +3060,12 @@ bool AbilityManagerService::VerificationAllToken(const sptr &toke } } + if (!useNewMission_) { + if (systemAppManager_->GetAbilityRecordByToken(token)) { + return true; + } + } + HILOG_ERROR("Failed to verify all token."); return false; } @@ -3257,6 +3320,7 @@ void AbilityManagerService::RestartAbility(const sptr &token) { HILOG_INFO("%{public}s called", __func__); CHECK_POINTER(currentStackManager_); + CHECK_POINTER(systemAppManager_); if (!VerificationAllToken(token)) { return; } @@ -3613,12 +3677,6 @@ int AbilityManagerService::SetMissionLabel(const sptr &token, con int AbilityManagerService::StartUser(int userId) { HILOG_DEBUG("%{public}s, userId:%{public}d", __func__, userId); - auto isSaCall = AAFwk::PermissionVerification::GetInstance()->IsSACall(); - if (!isSaCall) { - HILOG_ERROR("%{public}s: Permission verification failed", __func__); - return CHECK_PERMISSION_FAILED; - } - if (userController_) { return userController_->StartUser(userId, true); } @@ -3628,12 +3686,6 @@ int AbilityManagerService::StartUser(int userId) int AbilityManagerService::StopUser(int userId, const sptr &callback) { HILOG_DEBUG("%{public}s", __func__); - auto isSaCall = AAFwk::PermissionVerification::GetInstance()->IsSACall(); - if (!isSaCall) { - HILOG_ERROR("%{public}s: Permission verification failed", __func__); - return CHECK_PERMISSION_FAILED; - } - auto ret = -1; if (userController_) { ret = userController_->StopUser(userId); @@ -3659,15 +3711,27 @@ void AbilityManagerService::OnStartSpecifiedAbilityTimeoutResponse(const AAFwk:: { return; } - int AbilityManagerService::GetAbilityRunningInfos(std::vector &info) { HILOG_DEBUG("Get running ability infos."); - auto isPerm = AAFwk::PermissionVerification::GetInstance()->VerifyRunningInfoPerm(); + auto bundleMgr = GetBundleManager(); + if (!bundleMgr) { + HILOG_ERROR("bundleMgr is nullptr."); + return INNER_ERR; + } - currentMissionListManager_->GetAbilityRunningInfos(info, isPerm); - connectManager_->GetAbilityRunningInfos(info, isPerm); - dataAbilityManager_->GetAbilityRunningInfos(info, isPerm); + auto callerUid = IPCSkeleton::GetCallingUid(); + auto isSystem = bundleMgr->CheckIsSystemAppByUid(callerUid); + HILOG_DEBUG("callerUid : %{public}d, isSystem : %{public}d", callerUid, static_cast(isSystem)); + + if (!isSystem) { + HILOG_ERROR("callar is not system app."); + return INNER_ERR; + } + + currentMissionListManager_->GetAbilityRunningInfos(info); + connectManager_->GetAbilityRunningInfos(info); + dataAbilityManager_->GetAbilityRunningInfos(info); return ERR_OK; } @@ -3675,9 +3739,22 @@ int AbilityManagerService::GetAbilityRunningInfos(std::vector &info) { HILOG_DEBUG("Get extension infos, upperLimit : %{public}d", upperLimit); - auto isPerm = AAFwk::PermissionVerification::GetInstance()->VerifyRunningInfoPerm(); + auto bundleMgr = GetBundleManager(); + if (!bundleMgr) { + HILOG_ERROR("bundleMgr is nullptr."); + return INNER_ERR; + } + + auto callerUid = IPCSkeleton::GetCallingUid(); + auto isSystem = bundleMgr->CheckIsSystemAppByUid(callerUid); + HILOG_DEBUG("callerUid : %{public}d, isSystem : %{public}d", callerUid, static_cast(isSystem)); + + if (!isSystem) { + HILOG_ERROR("callar is not system app."); + return INNER_ERR; + } - connectManager_->GetExtensionRunningInfos(upperLimit, info, GetUserId(), isPerm); + connectManager_->GetExtensionRunningInfos(upperLimit, info, GetUserId()); return ERR_OK; } @@ -3703,12 +3780,6 @@ void AbilityManagerService::ClearUserData(int32_t userId) int AbilityManagerService::RegisterSnapshotHandler(const sptr& handler) { - auto isSaCall = AAFwk::PermissionVerification::GetInstance()->IsSACall(); - if (!isSaCall) { - HILOG_ERROR("%{public}s: Permission verification failed", __func__); - return 0; - } - if (!currentMissionListManager_) { HILOG_ERROR("snapshot: currentMissionListManager_ is nullptr."); return INNER_ERR; @@ -3721,11 +3792,6 @@ int AbilityManagerService::RegisterSnapshotHandler(const sptr& int32_t AbilityManagerService::GetMissionSnapshot(const std::string& deviceId, int32_t missionId, MissionSnapshot& missionSnapshot) { - if (VerifyMissionPermission() == CHECK_PERMISSION_FAILED) { - HILOG_ERROR("%{public}s: Permission verification failed", __func__); - return CHECK_PERMISSION_FAILED; - } - if (CheckIsRemote(deviceId)) { HILOG_INFO("get remote mission snapshot."); return GetRemoteMissionSnapshotInfo(deviceId, missionId, missionSnapshot); @@ -3987,12 +4053,6 @@ int AbilityManagerService::SetAbilityController(const sptr & int AbilityManagerService::SendANRProcessID(int pid) { - auto isSaCall = AAFwk::PermissionVerification::GetInstance()->IsSACall(); - if (!isSaCall) { - HILOG_ERROR("%{public}s: Permission verification failed", __func__); - return CHECK_PERMISSION_FAILED; - } - int anrTimeOut = amsConfigResolver_->GetANRTimeOutTime(); auto timeoutTask = [pid]() { if (kill(pid, SIGKILL) != ERR_OK) { @@ -4502,57 +4562,5 @@ void AbilityManagerService::StartupResidentProcess() DelayedSingleton::GetInstance()->StartupResidentProcess(); } - -int AbilityManagerService::VerifyMissionPermission() -{ - auto isSaCall = AAFwk::PermissionVerification::GetInstance()->IsSACall(); - if (isSaCall) { - return ERR_OK; - } - auto isCallingPerm = AAFwk::PermissionVerification::GetInstance()->VerifyCallingPermission( - PermissionConstants::PERMISSION_MANAGE_MISSION); - if (isCallingPerm) { - HILOG_DEBUG("%{public}s: Permission verification succeeded.", __func__); - return ERR_OK; - } - HILOG_ERROR("%{public}s: Permission verification failed", __func__); - return CHECK_PERMISSION_FAILED; -} - -void AbilityManagerService::GetAbilityRunningInfo(std::vector &info, - std::shared_ptr &abilityRecord) -{ - AbilityRunningInfo runningInfo; - AppExecFwk::RunningProcessInfo processInfo; - - runningInfo.ability = abilityRecord->GetWant().GetElement(); - runningInfo.startTime = abilityRecord->GetStartTime(); - runningInfo.abilityState = static_cast(abilityRecord->GetAbilityState()); - - DelayedSingleton::GetInstance()-> - GetRunningProcessInfoByToken(abilityRecord->GetToken(), processInfo); - runningInfo.pid = processInfo.pid_; - runningInfo.uid = processInfo.uid_; - runningInfo.processName = processInfo.processName_; - info.emplace_back(runningInfo); -} - -int AbilityManagerService::VerifyAccountPermission(int32_t userId) -{ - if ((userId < 0) || (userController_ && (userController_->GetCurrentUserId() == userId))) { - return ERR_OK; - } - auto isSaCall = AAFwk::PermissionVerification::GetInstance()->IsSACall(); - if (isSaCall) { - return ERR_OK; - } - auto isCallingPerm = AAFwk::PermissionVerification::GetInstance()->VerifyCallingPermission( - PermissionConstants::PERMISSION_INTERACT_ACROSS_LOCAL_ACCOUNTS); - if (isCallingPerm) { - return ERR_OK; - } - HILOG_ERROR("%{public}s: Permission verification failed", __func__); - return CHECK_PERMISSION_FAILED; -} } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/src/data_ability_manager.cpp b/services/abilitymgr/src/data_ability_manager.cpp index 42df78a47da63f0b721768fd96c5c21254c5228e..898ecdb426994eccaff43df0bc1d719f9fd10e74 100644 --- a/services/abilitymgr/src/data_ability_manager.cpp +++ b/services/abilitymgr/src/data_ability_manager.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -18,7 +18,6 @@ #include #include -#include "ability_manager_service.h" #include "ability_util.h" #include "hilog_wrapper.h" @@ -556,12 +555,12 @@ void DataAbilityManager::DumpSysState(std::vector &info, bool isCli return; } -void DataAbilityManager::GetAbilityRunningInfos(std::vector &info, bool isPerm) +void DataAbilityManager::GetAbilityRunningInfos(std::vector &info) { HILOG_INFO("Get ability running infos"); std::lock_guard locker(mutex_); - auto queryInfo = [&info, isPerm](DataAbilityRecordPtrMap::reference data) { + auto queryInfo = [&info](DataAbilityRecordPtrMap::reference data) { auto dataAbilityRecord = data.second; if (!dataAbilityRecord) { return; @@ -572,15 +571,17 @@ void DataAbilityManager::GetAbilityRunningInfos(std::vector return; } - if (isPerm) { - DelayedSingleton::GetInstance()->GetAbilityRunningInfo(info, abilityRecord); - } else { - auto callingTokenId = IPCSkeleton::GetCallingTokenID(); - auto tokenID = abilityRecord->GetApplicationInfo().accessTokenId; - if (callingTokenId == tokenID) { - DelayedSingleton::GetInstance()->GetAbilityRunningInfo(info, abilityRecord); - } - } + AbilityRunningInfo runningInfo; + AppExecFwk::RunningProcessInfo processInfo; + runningInfo.ability = abilityRecord->GetWant().GetElement(); + DelayedSingleton::GetInstance()-> + GetRunningProcessInfoByToken(abilityRecord->GetToken(), processInfo); + runningInfo.pid = processInfo.pid_; + runningInfo.uid = processInfo.uid_; + runningInfo.processName = processInfo.processName_; + runningInfo.startTime = abilityRecord->GetStartTime(); + runningInfo.abilityState = static_cast(abilityRecord->GetAbilityState()); + info.emplace_back(runningInfo); }; std::for_each(dataAbilityRecordsLoading_.begin(), dataAbilityRecordsLoading_.end(), queryInfo); diff --git a/services/abilitymgr/src/kernal_system_app_manager.cpp b/services/abilitymgr/src/kernal_system_app_manager.cpp new file mode 100644 index 0000000000000000000000000000000000000000..76ab01a7c45ac4e179f7778c08de9cd7e8fa9dc3 --- /dev/null +++ b/services/abilitymgr/src/kernal_system_app_manager.cpp @@ -0,0 +1,408 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "kernal_system_app_manager.h" + +#include "ability_manager_errors.h" +#include "ability_manager_service.h" +#include "ability_util.h" +#include "app_scheduler.h" +#include "bytrace.h" +#include "hilog_wrapper.h" + +namespace OHOS { +namespace AAFwk { +KernalSystemAppManager::KernalSystemAppManager(int userId) : userId_(userId) +{} + +KernalSystemAppManager::~KernalSystemAppManager() +{} + +int KernalSystemAppManager::StartAbility(const AbilityRequest &abilityRequest) +{ + BYTRACE_NAME(BYTRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); + HILOG_INFO("start kernal systerm ability."); + std::lock_guard guard(stackLock_); + if (!waittingAbilityQueue_.empty()) { + HILOG_INFO("waiting queue is not empty, so enqueue systerm ui ability for waiting."); + EnqueueWaittingAbility(abilityRequest); + return START_ABILITY_WAITING; + } + + std::shared_ptr topAbilityRecord = GetCurrentTopAbility(); + auto requestFlag = GetFlagOfAbility(abilityRequest.abilityInfo.bundleName, abilityRequest.abilityInfo.name); + if (topAbilityRecord != nullptr) { + auto topFlag = + GetFlagOfAbility(topAbilityRecord->GetAbilityInfo().bundleName, topAbilityRecord->GetAbilityInfo().name); + if (topFlag == requestFlag && topAbilityRecord->GetAbilityState() == INITIAL) { + HILOG_INFO("top systerm ui ability need to restart."); + } + if (topAbilityRecord->GetAbilityState() == ACTIVATING) { + HILOG_INFO("top systerm ui ability is not active, so enqueue ability for waiting."); + EnqueueWaittingAbility(abilityRequest); + return START_ABILITY_WAITING; + } + } + + return StartAbilityLocked(abilityRequest); +} + +int KernalSystemAppManager::StartAbilityLocked(const AbilityRequest &abilityRequest) +{ + std::shared_ptr targetAbility; + GetOrCreateAbilityRecord(abilityRequest, targetAbility); + CHECK_POINTER_AND_RETURN(targetAbility, ERR_INVALID_VALUE); + targetAbility->SetKernalSystemAbility(); + + HILOG_INFO("Load kernal system ability, bundleName:%{public}s , abilityName:%{public}s", + abilityRequest.abilityInfo.bundleName.c_str(), + abilityRequest.abilityInfo.name.c_str()); + + if (targetAbility->IsAbilityState(AbilityState::ACTIVE) || + targetAbility->IsAbilityState(AbilityState::ACTIVATING)) { + HILOG_INFO("kernal system ability is already activing or activated."); + targetAbility->Activate(); + return ERR_OK; + } + return targetAbility->LoadAbility(); +} + +int KernalSystemAppManager::AttachAbilityThread( + const sptr &scheduler, const sptr &token) +{ + HILOG_INFO("Attach ability thread."); + std::lock_guard guard(stackLock_); + auto abilityRecord = GetAbilityRecordByToken(token); + CHECK_POINTER_AND_RETURN(abilityRecord, ERR_INVALID_VALUE); + + std::string flag = KernalSystemAppManager::GetFlagOfAbility( + abilityRecord->GetAbilityInfo().bundleName, abilityRecord->GetAbilityInfo().name); + HILOG_INFO("ability: %{public}s", flag.c_str()); + + auto handler = DelayedSingleton::GetInstance()->GetEventHandler(); + CHECK_POINTER_AND_RETURN(handler, ERR_INVALID_VALUE); + + handler->RemoveEvent(AbilityManagerService::LOAD_TIMEOUT_MSG, abilityRecord->GetEventId()); + + abilityRecord->SetScheduler(scheduler); + DelayedSingleton::GetInstance()->MoveToForground(token); + + return ERR_OK; +} + +void KernalSystemAppManager::OnAbilityRequestDone(const sptr &token, const int32_t state) +{ + HILOG_INFO("On ability request done."); + std::lock_guard guard(stackLock_); + AppAbilityState abilitState = DelayedSingleton::GetInstance()->ConvertToAppAbilityState(state); + if (abilitState == AppAbilityState::ABILITY_STATE_FOREGROUND) { + auto abilityRecord = GetAbilityRecordByToken(token); + CHECK_POINTER(abilityRecord); + abilityRecord->Activate(); + } +} + +void KernalSystemAppManager::OnAppStateChanged(const AppInfo &info) +{ + std::lock_guard guard(stackLock_); + for (auto ability : abilities_) { + if (ability && (info.processName == ability->GetAbilityInfo().process || + info.processName == ability->GetApplicationInfo().bundleName)) { + auto appName = ability->GetApplicationInfo().name; + auto isExist = [&appName](const AppData &appData) { + return appData.appName == appName; + }; + auto iter = std::find_if(info.appData.begin(), info.appData.end(), isExist); + if (iter != info.appData.end()) { + ability->SetAppState(info.state); + } + } + } +} + +int KernalSystemAppManager::AbilityTransitionDone(const sptr &token, int state) +{ + HILOG_INFO("Ability transition done."); + std::lock_guard guard(stackLock_); + auto abilityRecord = GetAbilityRecordByToken(token); + CHECK_POINTER_AND_RETURN(abilityRecord, ERR_INVALID_VALUE); + + std::string flag = KernalSystemAppManager::GetFlagOfAbility( + abilityRecord->GetAbilityInfo().bundleName, abilityRecord->GetAbilityInfo().name); + int targetState = AbilityRecord::ConvertLifeCycleToAbilityState(static_cast(state)); + std::string abilityState = AbilityRecord::ConvertAbilityState(static_cast(targetState)); + HILOG_INFO("ability: %{public}s, state: %{public}s", flag.c_str(), abilityState.c_str()); + + switch (targetState) { + case AbilityState::ACTIVE: { + return DispatchActive(abilityRecord, targetState); + } + default: { + HILOG_WARN("don't support transiting state: %d", targetState); + return ERR_INVALID_VALUE; + } + } +} + +int KernalSystemAppManager::DispatchActive(const std::shared_ptr &abilityRecord, int state) +{ + auto handler = DelayedSingleton::GetInstance()->GetEventHandler(); + CHECK_POINTER_AND_RETURN(handler, ERR_INVALID_VALUE); + CHECK_POINTER_AND_RETURN(abilityRecord, ERR_INVALID_VALUE); + + if (!abilityRecord->IsAbilityState(AbilityState::ACTIVATING)) { + HILOG_ERROR("kernal ability transition life state error. start:%{public}d", state); + return ERR_INVALID_VALUE; + } + handler->RemoveEvent(AbilityManagerService::ACTIVE_TIMEOUT_MSG, abilityRecord->GetEventId()); + + auto task = [weak = weak_from_this(), abilityRecord]() { + auto kernalManager = weak.lock(); + if (kernalManager == nullptr) { + HILOG_ERROR("kernalManager is null, CompleteActive failed"); + return; + } + kernalManager->CompleteActive(abilityRecord); + }; + handler->PostTask(task); + return ERR_OK; +} + +void KernalSystemAppManager::CompleteActive(const std::shared_ptr &abilityRecord) +{ + HILOG_INFO("Complete active."); + std::lock_guard guard(stackLock_); + abilityRecord->SetAbilityState(AbilityState::ACTIVE); + + auto handler = DelayedSingleton::GetInstance()->GetEventHandler(); + CHECK_POINTER(handler); + + auto task = [weak = weak_from_this()]() { + auto kernalManager = weak.lock(); + if (kernalManager == nullptr) { + HILOG_ERROR("kernalManager is null, DequeueWaittingAbility failed"); + return; + } + kernalManager->DequeueWaittingAbility(); + }; + handler->PostTask(task, "DequeueWaittingAbility"); +} + +void KernalSystemAppManager::GetOrCreateAbilityRecord( + const AbilityRequest &abilityRequest, std::shared_ptr &targetAbility) +{ + std::string abilityFlag = KernalSystemAppManager::GetFlagOfAbility( + abilityRequest.abilityInfo.bundleName, abilityRequest.abilityInfo.name); + auto isExist = [targetFlag = abilityFlag](const std::shared_ptr &ability) { + if (ability == nullptr) { + return false; + } + return KernalSystemAppManager::GetFlagOfAbility( + ability->GetAbilityInfo().bundleName, + ability->GetAbilityInfo().name) == targetFlag; + }; + auto iter = std::find_if(abilities_.begin(), abilities_.end(), isExist); + if (iter != abilities_.end()) { + targetAbility = *iter; + targetAbility->SetWant(abilityRequest.want); + targetAbility->SetIsNewWant(true); + return; + } + targetAbility = AbilityRecord::CreateAbilityRecord(abilityRequest); + abilities_.push_front(targetAbility); +} + +std::string KernalSystemAppManager::GetFlagOfAbility(const std::string &bundleName, const std::string &abilityName) +{ + return bundleName + ":" + abilityName; +} + +int KernalSystemAppManager::GetManagerUserId() const +{ + return userId_; +} + +std::shared_ptr KernalSystemAppManager::GetCurrentTopAbility() const +{ + if (abilities_.empty()) { + return nullptr; + } + return abilities_.front(); +} + +std::shared_ptr KernalSystemAppManager::GetAbilityRecordByToken(const sptr &token) +{ + std::lock_guard guard(stackLock_); + auto abilityToFind = Token::GetAbilityRecordByToken(token); + CHECK_POINTER_AND_RETURN(abilityToFind, nullptr); + + auto isExist = [targetAbility = abilityToFind](const std::shared_ptr &ability) { + if (ability == nullptr) { + return false; + } + return targetAbility == ability; + }; + auto iter = std::find_if(abilities_.begin(), abilities_.end(), isExist); + if (iter != abilities_.end()) { + return *iter; + } + + return nullptr; +} + +std::shared_ptr KernalSystemAppManager::GetAbilityRecordByEventId(const int64_t eventId) const +{ + auto isExist = [targetEventId = eventId](const std::shared_ptr &ability) { + if (ability == nullptr) { + return false; + } + return (ability->GetEventId() == targetEventId); + }; + auto iter = std::find_if(abilities_.begin(), abilities_.end(), isExist); + if (iter != abilities_.end()) { + return *iter; + } + return nullptr; +} + +bool KernalSystemAppManager::RemoveAbilityRecord(std::shared_ptr ability) +{ + CHECK_POINTER_RETURN_BOOL(ability); + for (auto iter = abilities_.begin(); iter != abilities_.end(); iter++) { + if ((*iter) == ability) { + abilities_.erase(iter); + return true; + } + } + HILOG_ERROR("can not find ability"); + return false; +} + +void KernalSystemAppManager::EnqueueWaittingAbility(const AbilityRequest &abilityRequest) +{ + waittingAbilityQueue_.push(abilityRequest); + return; +} + +void KernalSystemAppManager::DequeueWaittingAbility() +{ + std::lock_guard guard(stackLock_); + std::shared_ptr topAbility = GetCurrentTopAbility(); + if (topAbility != nullptr && topAbility->GetAbilityState() != ACTIVE) { + HILOG_INFO("top ability is not active, must return for waiting again"); + return; + } + if (!waittingAbilityQueue_.empty()) { + AbilityRequest abilityRequest = waittingAbilityQueue_.front(); + waittingAbilityQueue_.pop(); + HILOG_INFO("bundleName: %{public}s, abilityName: %{public}s", + abilityRequest.abilityInfo.bundleName.c_str(), + abilityRequest.abilityInfo.name.c_str()); + + StartAbilityLocked(abilityRequest); + } +} +void KernalSystemAppManager::DumpState(std::vector &info) +{ + info.emplace_back("SystemUIRecords:"); + for (auto &ability : abilities_) { + ability->Dump(info); + } +} +void KernalSystemAppManager::DumpSysState(std::vector &info, bool isClient) +{ + info.emplace_back("SystemUIRecords:"); + for (auto &ability : abilities_) { + ability->DumpSys(info, isClient); + } +} + +void KernalSystemAppManager::OnAbilityDied(std::shared_ptr abilityRecord) +{ + std::lock_guard guard(stackLock_); + CHECK_POINTER(abilityRecord); + if (!abilityRecord->IsKernalSystemAbility()) { + HILOG_ERROR("System UI on scheduler died, ability type is not system ui"); + return; + } + + if (GetAbilityRecordByToken(abilityRecord->GetToken()) == nullptr) { + HILOG_ERROR("System UI on scheduler died, record is not exist."); + return; + } + auto abilityms = DelayedSingleton::GetInstance(); + CHECK_POINTER(abilityms); + + auto handler = abilityms->GetEventHandler(); + CHECK_POINTER(handler); + + HILOG_INFO("System UI on scheduler died: '%{public}s'", abilityRecord->GetAbilityInfo().name.c_str()); + std::string name = abilityRecord->GetAbilityInfo().name; + abilityRecord->SetAbilityState(AbilityState::INITIAL); + auto timeoutTask = [abilityms, abilityRecord]() { + if (abilityRecord) { + abilityms->StartingSystemUiAbility(); + } + }; + handler->PostTask(timeoutTask, "SystemUi_Die_" + name, AbilityManagerService::RESTART_TIMEOUT); +} +void KernalSystemAppManager::OnTimeOut(uint32_t msgId, int64_t eventId) +{ + std::lock_guard guard(stackLock_); + if (abilities_.empty()) { + HILOG_ERROR("System UI on time out event: ability stack is empty."); + return; + } + + auto abilityRecord = GetAbilityRecordByEventId(eventId); + CHECK_POINTER(abilityRecord); + + auto abilityMS = DelayedSingleton::GetInstance(); + CHECK_POINTER(abilityMS); + + auto handler = abilityMS->GetEventHandler(); + CHECK_POINTER(handler); + + switch (msgId) { + case AbilityManagerService::LOAD_TIMEOUT_MSG: + case AbilityManagerService::ACTIVE_TIMEOUT_MSG: { + std::string bundleName = abilityRecord->GetAbilityInfo().bundleName; + std::string name = abilityRecord->GetAbilityInfo().name; + RemoveAbilityRecord(abilityRecord); + auto task = [abilityMS, bundleName]() { + abilityMS->KillProcess(bundleName); + HILOG_ERROR("System UI on time out event: KillProcess:%{public}s", bundleName.c_str()); + }; + handler->PostTask(task); + auto timeoutTask = [abilityMS, name]() { + abilityMS->StartingSystemUiAbility(); + HILOG_ERROR("System UI on time out event: restart:%{public}s", name.c_str()); + }; + handler->PostTask(timeoutTask, "SystemUi_Timeout_" + name, AbilityManagerService::RESTART_TIMEOUT); + break; + } + default: + break; + } +} + +void KernalSystemAppManager::RestartAbility(const std::shared_ptr abilityRecord) +{ + CHECK_POINTER(abilityRecord); + HILOG_DEBUG("Restart ability system ui. %{public}s", abilityRecord->GetAbilityInfo().name.c_str()); + return; +} +} // namespace AAFwk +} // namespace OHOS \ No newline at end of file diff --git a/services/abilitymgr/src/mission_list_manager.cpp b/services/abilitymgr/src/mission_list_manager.cpp index 0883b31759826259a0578004c204e751afc89b91..bbfb8d8c588badba7d3d051f1c90894dc8eaf03c 100644 --- a/services/abilitymgr/src/mission_list_manager.cpp +++ b/services/abilitymgr/src/mission_list_manager.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -2130,11 +2130,11 @@ bool MissionListManager::GetMissionSnapshot(int32_t missionId, const sptr &info, bool isPerm) +void MissionListManager::GetAbilityRunningInfos(std::vector &info) { std::lock_guard guard(managerLock_); - auto func = [&info, isPerm](const std::shared_ptr &mission) { + auto func = [&info](const std::shared_ptr &mission) { if (!mission) { return; } @@ -2144,15 +2144,19 @@ void MissionListManager::GetAbilityRunningInfos(std::vector return; } - if (isPerm) { - DelayedSingleton::GetInstance()->GetAbilityRunningInfo(info, ability); - } else { - auto callingTokenId = IPCSkeleton::GetCallingTokenID(); - auto tokenID = ability->GetApplicationInfo().accessTokenId; - if (callingTokenId == tokenID) { - DelayedSingleton::GetInstance()->GetAbilityRunningInfo(info, ability); - } - } + AbilityRunningInfo runningInfo; + AppExecFwk::RunningProcessInfo processInfo; + + runningInfo.ability = ability->GetWant().GetElement(); + runningInfo.startTime = ability->GetStartTime(); + runningInfo.abilityState = static_cast(ability->GetAbilityState()); + + DelayedSingleton::GetInstance()-> + GetRunningProcessInfoByToken(ability->GetToken(), processInfo); + runningInfo.pid = processInfo.pid_; + runningInfo.uid = processInfo.uid_; + runningInfo.processName = processInfo.processName_; + info.emplace_back(runningInfo); }; if (!(defaultStandardList_->GetAllMissions().empty())) { auto list = defaultStandardList_->GetAllMissions(); diff --git a/services/abilitymgr/test/BUILD.gn b/services/abilitymgr/test/BUILD.gn index f434c2e139969f01c1defa1f792a7e1ef78bbefa..62275bf0ba3988b60e05932e0e14e175ddf87c62 100644 --- a/services/abilitymgr/test/BUILD.gn +++ b/services/abilitymgr/test/BUILD.gn @@ -43,6 +43,7 @@ ohos_source_set("abilityms_test_source") { "${services_path}/abilitymgr/src/data_ability_record.cpp", "${services_path}/abilitymgr/src/image_info.cpp", "${services_path}/abilitymgr/src/inner_mission_info.cpp", + "${services_path}/abilitymgr/src/kernal_system_app_manager.cpp", "${services_path}/abilitymgr/src/launch_param.cpp", "${services_path}/abilitymgr/src/lifecycle_deal.cpp", "${services_path}/abilitymgr/src/lifecycle_state_info.cpp", @@ -186,6 +187,7 @@ group("unittest") { "unittest/phone/data_ability_manager_test:unittest", "unittest/phone/data_ability_record_test:unittest", "unittest/phone/info_test:unittest", + "unittest/phone/kernal_system_app_manager_test:unittest", "unittest/phone/lifecycle_deal_test:unittest", "unittest/phone/lifecycle_test:unittest", "unittest/phone/lock_screen_white_list_test:unittest", diff --git a/services/abilitymgr/test/mock/libs/appexecfwk_core/src/appmgr/app_mgr_client.cpp b/services/abilitymgr/test/mock/libs/appexecfwk_core/src/appmgr/app_mgr_client.cpp index 8b67084fd6b1d1e36811e58288eb9aa1384b71f8..5166af58d6fa67c7fb401eb7a29be3667a6339b0 100644 --- a/services/abilitymgr/test/mock/libs/appexecfwk_core/src/appmgr/app_mgr_client.cpp +++ b/services/abilitymgr/test/mock/libs/appexecfwk_core/src/appmgr/app_mgr_client.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -55,6 +55,11 @@ AppMgrResultCode AppMgrClient::RegisterAppStateCallback(const sptr &token, const sptr &preToken, const int32_t visibility, const int32_t perceptibility, const int32_t connectionState) @@ -87,6 +92,16 @@ AppMgrResultCode AppMgrClient::GetAllRunningProcesses(std::vectorSetStackManager(userId, true); EXPECT_TRUE(g_abilityMs->GetStackManager()); g_abilityMs->stackManagers_.emplace(0, g_abilityMs->GetStackManager()); + g_abilityMs->systemAppManager_ = std::make_shared(userId); + EXPECT_TRUE(g_abilityMs->systemAppManager_); g_abilityMs->eventLoop_->Run(); diff --git a/services/abilitymgr/test/unittest/phone/ability_manager_proxy_test/BUILD.gn b/services/abilitymgr/test/unittest/phone/ability_manager_proxy_test/BUILD.gn index bc4eb8244c2b62c625f6ff35bde07ec3975e2a6e..f52e46e79d2898dd08f909dd2abbd43e4e402b80 100755 --- a/services/abilitymgr/test/unittest/phone/ability_manager_proxy_test/BUILD.gn +++ b/services/abilitymgr/test/unittest/phone/ability_manager_proxy_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# Copyright (c) 2021 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -44,7 +44,6 @@ ohos_unittest("ability_manager_proxy_test") { "${services_path}/abilitymgr/test/mock/libs/aakit:aakit_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_appmgr_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", - "${services_path}/common:perm_verification", "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", "//foundation/aafwk/standard/frameworks/kits/ability/native:dummy_classes", "//foundation/aafwk/standard/services/abilitymgr:abilityms", diff --git a/services/abilitymgr/test/unittest/phone/ability_manager_service_test/BUILD.gn b/services/abilitymgr/test/unittest/phone/ability_manager_service_test/BUILD.gn index ab7a3c736d9aebdf41cb09bc2aa21f6231c05fc1..e57df554d35e3510d750652a816a293ed2bc125b 100755 --- a/services/abilitymgr/test/unittest/phone/ability_manager_service_test/BUILD.gn +++ b/services/abilitymgr/test/unittest/phone/ability_manager_service_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# Copyright (c) 2021 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -44,7 +44,6 @@ ohos_unittest("ability_manager_service_test") { "${services_path}/abilitymgr/test/mock/libs/aakit:aakit_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_appmgr_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", - "${services_path}/common:perm_verification", "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", "//foundation/aafwk/standard/frameworks/kits/ability/native:dummy_classes", "//foundation/aafwk/standard/interfaces/innerkits/app_manager:app_manager", diff --git a/services/abilitymgr/test/unittest/phone/ability_manager_service_test/ability_manager_service_test.cpp b/services/abilitymgr/test/unittest/phone/ability_manager_service_test/ability_manager_service_test.cpp index c75b01ef44cf47bf91c6ec133d60c2564f1c5fcb..6a0eb76d93ed42e5292c9976defc853b90372850 100644 --- a/services/abilitymgr/test/unittest/phone/ability_manager_service_test/ability_manager_service_test.cpp +++ b/services/abilitymgr/test/unittest/phone/ability_manager_service_test/ability_manager_service_test.cpp @@ -149,6 +149,8 @@ void AbilityManagerServiceTest::OnStartAms() abilityMs_->SetStackManager(userId, true); EXPECT_TRUE(abilityMs_->GetStackManager()); abilityMs_->stackManagers_.emplace(0, abilityMs_->GetStackManager()); + abilityMs_->systemAppManager_ = std::make_shared(userId); + EXPECT_TRUE(abilityMs_->systemAppManager_); abilityMs_->eventLoop_->Run(); return; } @@ -1982,6 +1984,208 @@ HWTEST_F(AbilityManagerServiceTest, systemDialog_002, TestSize.Level1) EXPECT_EQ(MusicAbility->GetAbilityInfo().bundleName, "com.ix.hiMusic"); } +/* + * Feature: AbilityManagerService + * Function: HandleLoadTimeOut + * SubFunction: NA + * FunctionPoints: AbilityManagerService HandleLoadTimeOut + * EnvConditions: NA + * CaseDescription: Verify function HandleLoadTimeOut + * When you start systemui, when HandleLoadTimeOut called, restart systemui + */ +HWTEST_F(AbilityManagerServiceTest, handleloadtimeout_001, TestSize.Level1) +{ + // start SYSTEM_UI_STATUS_BAR when device get up + Want want; + ElementName elementbar("device", AbilityConfig::SYSTEM_UI_BUNDLE_NAME, AbilityConfig::SYSTEM_UI_STATUS_BAR); + want.SetElement(elementbar); + auto result = StartAbility(want); + EXPECT_EQ(OHOS::ERR_OK, result); + + auto stackManager = abilityMs_->systemAppManager_; + auto barAbility = stackManager->GetCurrentTopAbility(); + AbilityRecordInfo barAbilityInfo; + barAbility->GetAbilityRecordInfo(barAbilityInfo); + auto dialogtoken = barAbility->GetToken(); + + OHOS::sptr scheduler = new AbilityScheduler(); + EXPECT_EQ(abilityMs_->AttachAbilityThread(scheduler, dialogtoken), OHOS::ERR_OK); + EXPECT_TRUE(barAbility->GetAbilityInfo().bundleName == AbilityConfig::SYSTEM_UI_BUNDLE_NAME); + + abilityMs_->HandleLoadTimeOut(barAbility->GetEventId()); + + auto newStackManager = abilityMs_->systemAppManager_; + auto newBarAbility = newStackManager->GetCurrentTopAbility(); + + // Remove Ability Record + EXPECT_FALSE(newBarAbility); +} + +/* + * Feature: AbilityManagerService + * Function: HandleLoadTimeOut + * SubFunction: NA + * FunctionPoints: AbilityManagerService HandleLoadTimeOut + * EnvConditions: NA + * CaseDescription: Verify function HandleLoadTimeOut + * When you start systemui, when HandleLoadTimeOut called, restart systemui + */ +HWTEST_F(AbilityManagerServiceTest, handleloadtimeout_002, TestSize.Level1) +{ + // start SYSTEM_UI_NAVIGATION_BAR when device get up + Want want; + ElementName elementdialog("device", AbilityConfig::SYSTEM_UI_BUNDLE_NAME, AbilityConfig::SYSTEM_UI_NAVIGATION_BAR); + want.SetElement(elementdialog); + auto result = StartAbility(want); + WaitUntilTaskFinished(); + EXPECT_EQ(OHOS::ERR_OK, result); + + auto stackManager = abilityMs_->systemAppManager_; + auto navigationAbility = stackManager->GetCurrentTopAbility(); + auto dialogtoken = navigationAbility->GetToken(); + + OHOS::sptr scheduler = new AbilityScheduler(); + EXPECT_EQ(abilityMs_->AttachAbilityThread(scheduler, dialogtoken), OHOS::ERR_OK); + EXPECT_TRUE(navigationAbility->GetAbilityInfo().bundleName == AbilityConfig::SYSTEM_UI_BUNDLE_NAME); + + abilityMs_->HandleLoadTimeOut(navigationAbility->GetEventId()); + WaitUntilTaskFinishedByTimer(); + + auto newStackManager = abilityMs_->systemAppManager_; + auto newNavigationAbility = newStackManager->GetCurrentTopAbility(); + EXPECT_TRUE(newNavigationAbility->GetAbilityInfo().bundleName == AbilityConfig::SYSTEM_UI_BUNDLE_NAME); + EXPECT_NE(navigationAbility, newNavigationAbility); +} + +/* + * Feature: AbilityManagerService + * Function: HandleLoadTimeOut + * SubFunction: NA + * FunctionPoints: AbilityManagerService HandleLoadTimeOut + * EnvConditions: NA + * CaseDescription: Verify function HandleLoadTimeOut + * When you start systemui, when timeout ,the HandleLoadTimeOut called, restart systemui + */ +HWTEST_F(AbilityManagerServiceTest, handleloadtimeout_003, TestSize.Level1) +{ + // start SYSTEM_UI_STATUS_BAR when device get up + Want want; + ElementName elementbar("device", AbilityConfig::SYSTEM_UI_BUNDLE_NAME, AbilityConfig::SYSTEM_UI_STATUS_BAR); + want.SetElement(elementbar); + auto result = StartAbility(want); + EXPECT_EQ(OHOS::ERR_OK, result); + + auto stackManager = abilityMs_->systemAppManager_; + auto barAbility = stackManager->GetCurrentTopAbility(); + AbilityRecordInfo barAbilityInfo; + barAbility->GetAbilityRecordInfo(barAbilityInfo); + EXPECT_TRUE(barAbility->GetAbilityInfo().bundleName == AbilityConfig::SYSTEM_UI_BUNDLE_NAME); + + abilityMs_->HandleLoadTimeOut(barAbility->GetEventId()); + WaitUntilTaskFinishedByTimer(); + + auto newStackManager = abilityMs_->systemAppManager_; + auto newBarAbility = newStackManager->GetCurrentTopAbility(); + AbilityRecordInfo newAbilityInfo; + newBarAbility->GetAbilityRecordInfo(newAbilityInfo); + EXPECT_TRUE(newBarAbility->GetAbilityInfo().bundleName == AbilityConfig::SYSTEM_UI_BUNDLE_NAME); + EXPECT_NE(barAbilityInfo.id, newAbilityInfo.id); +} + +/* + * Feature: AbilityManagerService + * Function: HandleLoadTimeOut + * SubFunction: NA + * FunctionPoints: AbilityManagerService HandleLoadTimeOut + * EnvConditions: NA + * CaseDescription: Verify function HandleLoadTimeOut + * When you start systemui, when timeout ,the HandleLoadTimeOut called, restart systemui + */ +HWTEST_F(AbilityManagerServiceTest, handleloadtimeout_004, TestSize.Level1) +{ + // start SYSTEM_UI_NAVIGATION_BAR when device get up + Want want; + ElementName elementbar("device", AbilityConfig::SYSTEM_UI_BUNDLE_NAME, AbilityConfig::SYSTEM_UI_NAVIGATION_BAR); + want.SetElement(elementbar); + auto result = StartAbility(want); + EXPECT_EQ(OHOS::ERR_OK, result); + + auto stackManager = abilityMs_->systemAppManager_; + auto navigationAbility = stackManager->GetCurrentTopAbility(); + EXPECT_TRUE(navigationAbility->GetAbilityInfo().bundleName == AbilityConfig::SYSTEM_UI_BUNDLE_NAME); + + abilityMs_->HandleLoadTimeOut(navigationAbility->GetEventId()); + WaitUntilTaskFinishedByTimer(); + + auto newStackManager = abilityMs_->systemAppManager_; + auto newNavigationAbility = newStackManager->GetCurrentTopAbility(); + EXPECT_TRUE(newNavigationAbility->GetAbilityInfo().bundleName == AbilityConfig::SYSTEM_UI_BUNDLE_NAME); + EXPECT_NE(navigationAbility, newNavigationAbility); +} + +/* + * Feature: AbilityManagerService + * Function: HandleLoadTimeOut + * SubFunction: NA + * FunctionPoints: AbilityManagerService HandleLoadTimeOut + * EnvConditions: NA + * CaseDescription: Verify function HandleLoadTimeOut + * When you start systemui, when HandleLoadTimeOut called, restart systemui + */ +HWTEST_F(AbilityManagerServiceTest, handleloadtimeout_005, TestSize.Level1) +{ + // start SYSTEM_UI_STATUS_BAR when device get up + Want want; + ElementName elementbar("device", AbilityConfig::SYSTEM_UI_BUNDLE_NAME, AbilityConfig::SYSTEM_UI_STATUS_BAR); + want.SetElement(elementbar); + auto result = StartAbility(want); + EXPECT_EQ(OHOS::ERR_OK, result); + + auto stackManager = abilityMs_->systemAppManager_; + auto barAbility = stackManager->GetCurrentTopAbility(); + auto bartoken = barAbility->GetToken(); + OHOS::sptr scheduler = new AbilityScheduler(); + EXPECT_EQ(abilityMs_->AttachAbilityThread(scheduler, bartoken), OHOS::ERR_OK); + EXPECT_TRUE(barAbility->GetAbilityInfo().bundleName == AbilityConfig::SYSTEM_UI_BUNDLE_NAME); + + auto newStackManager = abilityMs_->systemAppManager_; + auto newBarAbility = newStackManager->GetCurrentTopAbility(); + EXPECT_TRUE(newBarAbility->GetAbilityInfo().bundleName == AbilityConfig::SYSTEM_UI_BUNDLE_NAME); + EXPECT_EQ(barAbility, newBarAbility); +} + +/* + * Feature: AbilityManagerService + * Function: HandleLoadTimeOut + * SubFunction: NA + * FunctionPoints: AbilityManagerService HandleLoadTimeOut + * EnvConditions: NA + * CaseDescription: Verify function HandleLoadTimeOut + * When you start systemui, when HandleLoadTimeOut called, restart systemui + */ +HWTEST_F(AbilityManagerServiceTest, handleloadtimeout_006, TestSize.Level1) +{ + // start SYSTEM_UI_NAVIGATION_BAR when device get up + Want want; + ElementName elementbar("device", AbilityConfig::SYSTEM_UI_BUNDLE_NAME, AbilityConfig::SYSTEM_UI_NAVIGATION_BAR); + want.SetElement(elementbar); + auto result = StartAbility(want); + EXPECT_EQ(OHOS::ERR_OK, result); + + auto stackManager = abilityMs_->systemAppManager_; + auto navigationAbility = stackManager->GetCurrentTopAbility(); + auto navigationtoken = navigationAbility->GetToken(); + OHOS::sptr scheduler = new AbilityScheduler(); + + EXPECT_EQ(abilityMs_->AttachAbilityThread(scheduler, navigationtoken), OHOS::ERR_OK); + EXPECT_TRUE(navigationAbility->GetAbilityInfo().bundleName == AbilityConfig::SYSTEM_UI_BUNDLE_NAME); + + auto newStackManager = abilityMs_->systemAppManager_; + auto newNavigationAbility = newStackManager->GetCurrentTopAbility(); + EXPECT_TRUE(newNavigationAbility->GetAbilityInfo().bundleName == AbilityConfig::SYSTEM_UI_BUNDLE_NAME); + EXPECT_EQ(navigationAbility, newNavigationAbility); +} + /* * Feature: AbilityManagerService * Function: HandleLoadTimeOut diff --git a/services/abilitymgr/test/unittest/phone/ability_manager_stub_test/BUILD.gn b/services/abilitymgr/test/unittest/phone/ability_manager_stub_test/BUILD.gn index f4ecbd64c5e0429830138d39f3e9595042441ce7..92fbd890229182c0ffb6b78be80f42da8399f54e 100755 --- a/services/abilitymgr/test/unittest/phone/ability_manager_stub_test/BUILD.gn +++ b/services/abilitymgr/test/unittest/phone/ability_manager_stub_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# Copyright (c) 2021 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -45,7 +45,6 @@ ohos_unittest("ability_manager_stub_test") { "${services_path}/abilitymgr/test/mock/libs/aakit:aakit_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_appmgr_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", - "${services_path}/common:perm_verification", "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", "//foundation/aafwk/standard/frameworks/kits/ability/native:dummy_classes", "//foundation/aafwk/standard/services/abilitymgr:abilityms", diff --git a/services/abilitymgr/test/unittest/phone/ability_record_test/BUILD.gn b/services/abilitymgr/test/unittest/phone/ability_record_test/BUILD.gn index 36e84040fda70028ded88bbb7145cdcb3e30b340..0e35f783aa0e1440e0435a6be303c0de7ae0c103 100755 --- a/services/abilitymgr/test/unittest/phone/ability_record_test/BUILD.gn +++ b/services/abilitymgr/test/unittest/phone/ability_record_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# Copyright (c) 2021 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -43,7 +43,6 @@ ohos_unittest("ability_record_test") { "${services_path}/abilitymgr/test/mock/libs/aakit:aakit_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_appmgr_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", - "${services_path}/common:perm_verification", "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", "//foundation/aafwk/standard/frameworks/kits/ability/native:dummy_classes", "//foundation/aafwk/standard/services/abilitymgr:abilityms", diff --git a/services/abilitymgr/test/unittest/phone/ability_scheduler_proxy_test/BUILD.gn b/services/abilitymgr/test/unittest/phone/ability_scheduler_proxy_test/BUILD.gn index b4c07ed6ccdcb341c0b9556f8a4a9bfa0dae24de..02d680eff9af1b73c0a0bd1faa57d6fd76ef75ec 100755 --- a/services/abilitymgr/test/unittest/phone/ability_scheduler_proxy_test/BUILD.gn +++ b/services/abilitymgr/test/unittest/phone/ability_scheduler_proxy_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# Copyright (c) 2021 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -44,7 +44,6 @@ ohos_unittest("ability_scheduler_proxy_test") { "${services_path}/abilitymgr/test/mock/libs/aakit:aakit_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_appmgr_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", - "${services_path}/common:perm_verification", "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", "//foundation/aafwk/standard/frameworks/kits/ability/native:dummy_classes", "//foundation/aafwk/standard/services/abilitymgr:abilityms", diff --git a/services/abilitymgr/test/unittest/phone/ability_scheduler_stub_test/BUILD.gn b/services/abilitymgr/test/unittest/phone/ability_scheduler_stub_test/BUILD.gn index 74b0042fa29534d425e48ea65416de0fb5bd7882..99516fcda778cbf29034ffb9957bfa86dfdad416 100755 --- a/services/abilitymgr/test/unittest/phone/ability_scheduler_stub_test/BUILD.gn +++ b/services/abilitymgr/test/unittest/phone/ability_scheduler_stub_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# Copyright (c) 2021 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -43,7 +43,6 @@ ohos_unittest("ability_scheduler_stub_test") { "${services_path}/abilitymgr/test/mock/libs/aakit:aakit_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_appmgr_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", - "${services_path}/common:perm_verification", "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", "//foundation/aafwk/standard/frameworks/kits/ability/native:dummy_classes", "//foundation/aafwk/standard/services/abilitymgr:abilityms", diff --git a/services/abilitymgr/test/unittest/phone/ability_service_start_test/BUILD.gn b/services/abilitymgr/test/unittest/phone/ability_service_start_test/BUILD.gn index a6d878c6301a7b561509082b8de29b07b217c6db..3448571be2f85f77bc4c17f764b9397564cde948 100755 --- a/services/abilitymgr/test/unittest/phone/ability_service_start_test/BUILD.gn +++ b/services/abilitymgr/test/unittest/phone/ability_service_start_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# Copyright (c) 2021 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -44,7 +44,6 @@ ohos_unittest("ability_service_start_test") { "${services_path}/abilitymgr/test/mock/libs/aakit:aakit_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_appmgr_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", - "${services_path}/common:perm_verification", "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", "//foundation/aafwk/standard/frameworks/kits/ability/native:dummy_classes", "//foundation/aafwk/standard/services/abilitymgr:abilityms", diff --git a/services/abilitymgr/test/unittest/phone/ability_stack_manager_test/BUILD.gn b/services/abilitymgr/test/unittest/phone/ability_stack_manager_test/BUILD.gn index 2df340911a28e0b9e30a426ace7c73ad3393732a..8237b90354290a607cab820d912219ea9198f9b6 100755 --- a/services/abilitymgr/test/unittest/phone/ability_stack_manager_test/BUILD.gn +++ b/services/abilitymgr/test/unittest/phone/ability_stack_manager_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# Copyright (c) 2021 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -45,7 +45,6 @@ ohos_unittest("ability_stack_manager_test") { "${services_path}/abilitymgr/test/mock/libs/aakit:aakit_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_appmgr_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", - "${services_path}/common:perm_verification", "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", "//foundation/aafwk/standard/frameworks/kits/ability/native:dummy_classes", "//foundation/aafwk/standard/interfaces/innerkits/app_manager:app_manager", diff --git a/services/abilitymgr/test/unittest/phone/ability_stack_manager_test/ability_stack_manager_test.cpp b/services/abilitymgr/test/unittest/phone/ability_stack_manager_test/ability_stack_manager_test.cpp index cc177c0234a13f9bbd36e6402c8caef6c8071e14..d4a48a6cb73637d3c7e62a4bedf34a960710ee78 100644 --- a/services/abilitymgr/test/unittest/phone/ability_stack_manager_test/ability_stack_manager_test.cpp +++ b/services/abilitymgr/test/unittest/phone/ability_stack_manager_test/ability_stack_manager_test.cpp @@ -102,6 +102,8 @@ void AbilityStackManagerTest::OnStartabilityMs() int userId = abilityMs_->GetUserId(); abilityMs_->SetStackManager(userId, true); + abilityMs_->systemAppManager_ = std::make_shared(userId); + EXPECT_TRUE(abilityMs_->systemAppManager_); abilityMs_->eventLoop_->Run(); diff --git a/services/abilitymgr/test/unittest/phone/ability_token_proxy_test/BUILD.gn b/services/abilitymgr/test/unittest/phone/ability_token_proxy_test/BUILD.gn index cae5d4e59794230fb9d545484e5187924f2e3354..d494af6662b67cb84237ad856ab9cc808f9f1558 100755 --- a/services/abilitymgr/test/unittest/phone/ability_token_proxy_test/BUILD.gn +++ b/services/abilitymgr/test/unittest/phone/ability_token_proxy_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# Copyright (c) 2021 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -43,7 +43,6 @@ ohos_unittest("ability_token_proxy_test") { "${services_path}/abilitymgr/test/mock/libs/aakit:aakit_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_appmgr_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", - "${services_path}/common:perm_verification", "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", "//foundation/aafwk/standard/frameworks/kits/ability/native:dummy_classes", "//foundation/aafwk/standard/services/abilitymgr:abilityms", diff --git a/services/abilitymgr/test/unittest/phone/ability_token_stub_test/BUILD.gn b/services/abilitymgr/test/unittest/phone/ability_token_stub_test/BUILD.gn index 39f371c0d4911cf4fee4766c5f1d408e5eeb7c68..0938daba97e7b5b651fe5786369db18bc8a063aa 100755 --- a/services/abilitymgr/test/unittest/phone/ability_token_stub_test/BUILD.gn +++ b/services/abilitymgr/test/unittest/phone/ability_token_stub_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# Copyright (c) 2021 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -43,7 +43,6 @@ ohos_unittest("ability_token_stub_test") { "${services_path}/abilitymgr/test/mock/libs/aakit:aakit_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_appmgr_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", - "${services_path}/common:perm_verification", "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", "//foundation/aafwk/standard/frameworks/kits/ability/native:dummy_classes", "//foundation/aafwk/standard/services/abilitymgr:abilityms", diff --git a/services/abilitymgr/test/unittest/phone/ability_with_applications_test/BUILD.gn b/services/abilitymgr/test/unittest/phone/ability_with_applications_test/BUILD.gn index 323939e7dfb279ffb9e49885f6af4c75e167ded5..960e6bc85b4df2050ec76f0def1814005a61cfa7 100755 --- a/services/abilitymgr/test/unittest/phone/ability_with_applications_test/BUILD.gn +++ b/services/abilitymgr/test/unittest/phone/ability_with_applications_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# Copyright (c) 2021 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -45,7 +45,6 @@ ohos_unittest("ability_with_applications_test") { "${services_path}/abilitymgr/test/mock/libs/aakit:aakit_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_appmgr_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", - "${services_path}/common:perm_verification", "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", "//foundation/aafwk/standard/frameworks/kits/ability/native:dummy_classes", "//foundation/aafwk/standard/interfaces/innerkits/app_manager:app_manager", diff --git a/services/abilitymgr/test/unittest/phone/ability_with_applications_test/ability_with_applications_test.cpp b/services/abilitymgr/test/unittest/phone/ability_with_applications_test/ability_with_applications_test.cpp index 3832cc4892c5d48c1f119c991d44e45252e49365..8f43d1050790e6a553fcd47f9ac62192e958308e 100644 --- a/services/abilitymgr/test/unittest/phone/ability_with_applications_test/ability_with_applications_test.cpp +++ b/services/abilitymgr/test/unittest/phone/ability_with_applications_test/ability_with_applications_test.cpp @@ -116,6 +116,8 @@ void AbilityWithApplicationsTest::OnStartabilityAms() int userId = abilityMs_->GetUserId(); abilityMs_->SetStackManager(userId, true); + abilityMs_->systemAppManager_ = std::make_shared(userId); + EXPECT_TRUE(abilityMs_->systemAppManager_); abilityMs_->eventLoop_->Run(); diff --git a/services/abilitymgr/test/unittest/phone/abilityms_appms_test/BUILD.gn b/services/abilitymgr/test/unittest/phone/abilityms_appms_test/BUILD.gn index 0e61c748a6c10adbd3e90d0a4e091cc99b5fdb1e..404a2f9920b1b783acebfe05bb67f42cfc03b7d0 100755 --- a/services/abilitymgr/test/unittest/phone/abilityms_appms_test/BUILD.gn +++ b/services/abilitymgr/test/unittest/phone/abilityms_appms_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# Copyright (c) 2021 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -45,7 +45,6 @@ ohos_unittest("abilityms_appms_test") { "${services_path}/abilitymgr/test/mock/libs/aakit:aakit_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_appmgr_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", - "${services_path}/common:perm_verification", "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", "//foundation/aafwk/standard/frameworks/kits/ability/native:dummy_classes", "//foundation/aafwk/standard/interfaces/innerkits/app_manager:app_manager", diff --git a/services/abilitymgr/test/unittest/phone/abilityms_appms_test/abilityms_appms_test.cpp b/services/abilitymgr/test/unittest/phone/abilityms_appms_test/abilityms_appms_test.cpp index 920430901c3c01bbf35dc10b2e5401ec8d05152b..a529e853178f331ecd1a0a2491bc7356270dafe6 100644 --- a/services/abilitymgr/test/unittest/phone/abilityms_appms_test/abilityms_appms_test.cpp +++ b/services/abilitymgr/test/unittest/phone/abilityms_appms_test/abilityms_appms_test.cpp @@ -122,6 +122,8 @@ void AbilityMsAppmsTest::OnStartabilityAms() int userId = abilityMs_->GetUserId(); abilityMs_->SetStackManager(userId, true); + abilityMs_->systemAppManager_ = std::make_shared(userId); + EXPECT_TRUE(abilityMs_->systemAppManager_); abilityMs_->eventLoop_->Run(); diff --git a/services/abilitymgr/test/unittest/phone/app_scheduler_test/BUILD.gn b/services/abilitymgr/test/unittest/phone/app_scheduler_test/BUILD.gn index 1389f55322ee64adcb35177a8b862d68788e0592..1c807996239a4ab9ea009de004544102bf5b69a7 100755 --- a/services/abilitymgr/test/unittest/phone/app_scheduler_test/BUILD.gn +++ b/services/abilitymgr/test/unittest/phone/app_scheduler_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# Copyright (c) 2021 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -45,7 +45,6 @@ ohos_unittest("app_scheduler_test") { "${services_path}/abilitymgr/test/mock/libs/aakit:aakit_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_appmgr_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", - "${services_path}/common:perm_verification", "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", "//foundation/aafwk/standard/frameworks/kits/ability/native:dummy_classes", "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base:appexecfwk_base", diff --git a/services/abilitymgr/test/unittest/phone/configuration_test/BUILD.gn b/services/abilitymgr/test/unittest/phone/configuration_test/BUILD.gn index 3ca2e5d755aa6b863707768ae0d35449511e1717..5550f0a415d89bf70c83c65bbb28121e98e625a5 100755 --- a/services/abilitymgr/test/unittest/phone/configuration_test/BUILD.gn +++ b/services/abilitymgr/test/unittest/phone/configuration_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# Copyright (c) 2021 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -45,7 +45,6 @@ ohos_unittest("configuration_test") { "${services_path}/abilitymgr/test/mock/libs/aakit:aakit_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_appmgr_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", - "${services_path}/common:perm_verification", "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", "//foundation/aafwk/standard/frameworks/kits/ability/native:dummy_classes", "//foundation/aafwk/standard/interfaces/innerkits/base:base", diff --git a/services/abilitymgr/test/unittest/phone/connection_record_test/BUILD.gn b/services/abilitymgr/test/unittest/phone/connection_record_test/BUILD.gn index 1f24c5e8acc8a68d89a2e716c90ac2e0fbd09669..5d93f1f55a26d7bb71ffdeab81ebb4c2ff9eac8a 100755 --- a/services/abilitymgr/test/unittest/phone/connection_record_test/BUILD.gn +++ b/services/abilitymgr/test/unittest/phone/connection_record_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# Copyright (c) 2021 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -43,7 +43,6 @@ ohos_unittest("connection_record_test") { "${services_path}/abilitymgr/test/mock/libs/aakit:aakit_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_appmgr_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", - "${services_path}/common:perm_verification", "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", "//foundation/aafwk/standard/frameworks/kits/ability/native:dummy_classes", "//foundation/aafwk/standard/services/abilitymgr:abilityms", diff --git a/services/abilitymgr/test/unittest/phone/data_ability_manager_test/BUILD.gn b/services/abilitymgr/test/unittest/phone/data_ability_manager_test/BUILD.gn index 795322688f75aa9809d9e552cc8c235973259819..2d2f88add92261cb5b6158783ca5110445448bb7 100755 --- a/services/abilitymgr/test/unittest/phone/data_ability_manager_test/BUILD.gn +++ b/services/abilitymgr/test/unittest/phone/data_ability_manager_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# Copyright (c) 2021 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -52,7 +52,6 @@ ohos_unittest("data_ability_manager_test") { "${services_path}/abilitymgr/test/mock/libs/aakit:aakit_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_appmgr_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", - "${services_path}/common:perm_verification", "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", "//foundation/aafwk/standard/frameworks/kits/ability/native:dummy_classes", diff --git a/services/abilitymgr/test/unittest/phone/data_ability_record_test/BUILD.gn b/services/abilitymgr/test/unittest/phone/data_ability_record_test/BUILD.gn index 343f99b46dd6998afa69239a47c4874257765910..e9a738877fb7ffc681598a911c1a71efa81d252c 100755 --- a/services/abilitymgr/test/unittest/phone/data_ability_record_test/BUILD.gn +++ b/services/abilitymgr/test/unittest/phone/data_ability_record_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# Copyright (c) 2021 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -49,7 +49,6 @@ ohos_unittest("data_ability_record_test") { "${services_path}/abilitymgr/test/mock/libs/aakit:aakit_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_appmgr_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", - "${services_path}/common:perm_verification", "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", "//foundation/aafwk/standard/frameworks/kits/ability/native:dummy_classes", "//foundation/aafwk/standard/services/abilitymgr:abilityms", diff --git a/services/abilitymgr/test/unittest/phone/info_test/BUILD.gn b/services/abilitymgr/test/unittest/phone/info_test/BUILD.gn index 6a0d2bd51d49f7e20ac6412f3d560de92ea93caa..41e10660eecb94b4ed1aba2aab8d7ac01c33a374 100755 --- a/services/abilitymgr/test/unittest/phone/info_test/BUILD.gn +++ b/services/abilitymgr/test/unittest/phone/info_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# Copyright (c) 2021 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -43,7 +43,6 @@ ohos_unittest("info_test") { "${services_path}/abilitymgr/test/mock/libs/aakit:aakit_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_appmgr_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", - "${services_path}/common:perm_verification", "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", "//foundation/aafwk/standard/frameworks/kits/ability/native:dummy_classes", "//foundation/aafwk/standard/services/abilitymgr:abilityms", diff --git a/services/abilitymgr/test/unittest/phone/kernal_system_app_manager_test/BUILD.gn b/services/abilitymgr/test/unittest/phone/kernal_system_app_manager_test/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..50f8c4b2e439aa2f3522d179b4a052255d4259de --- /dev/null +++ b/services/abilitymgr/test/unittest/phone/kernal_system_app_manager_test/BUILD.gn @@ -0,0 +1,72 @@ +# Copyright (c) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/test.gni") +import("//foundation/aafwk/standard/aafwk.gni") + +module_output_path = "ability_runtime/abilitymgr" + +ohos_unittest("kernal_system_app_mgr_test") { + module_out_path = module_output_path + + include_dirs = [ + "${services_path}/abilitymgr/test/mock/libs/system_ability_mock", + "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy/include", + "//foundation/distributedschedule/samgr/adapter/interfaces/innerkits/include/", + "//foundation/aafwk/standard/services/abilitymgr/test/mock/libs/ability_scheduler_mock", + "//foundation/aafwk/standard/services/abilitymgr/include/", + "//foundation/aafwk/standard/services/abilitymgr/test/mock/libs/appexecfwk_core/include", + "//foundation/aafwk/standard/services/abilitymgr/test/mock/include", + "//foundation/aafwk/standard/services/abilitymgr/include", + ] + + sources = [ + "//foundation/aafwk/standard/services/abilitymgr/test/mock/libs/appexecfwk_core/src/appmgr/mock_app_scheduler.cpp", + "kernal_system_app_manager_test.cpp", # add mock file + ] + + configs = [ "${services_path}/abilitymgr:abilityms_config" ] + cflags = [] + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } + deps = [ + "${innerkits_path}/want:want", + "${services_path}/abilitymgr/test:abilityms_test_source", + "${services_path}/abilitymgr/test/mock/libs/aakit:aakit_mock", + "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_appmgr_mock", + "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", + "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", + "//foundation/aafwk/standard/frameworks/kits/ability/native:dummy_classes", + "//foundation/aafwk/standard/services/abilitymgr:abilityms", + "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base:appexecfwk_base", + "//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler:libeventhandler", + "//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri", + "//third_party/googletest:gmock_main", + "//third_party/googletest:gtest_main", + "//third_party/libpng:libpng", + "//utils/native/base:utils", + ] + external_deps = [ + "access_token:libaccesstoken_sdk", + "device_manager_base:devicemanagersdk", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + ] +} + +group("unittest") { + testonly = true + + deps = [ ":kernal_system_app_mgr_test" ] +} diff --git a/services/abilitymgr/test/unittest/phone/kernal_system_app_manager_test/kernal_system_app_manager_test.cpp b/services/abilitymgr/test/unittest/phone/kernal_system_app_manager_test/kernal_system_app_manager_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..73f7fdbb84154775661c44f6303a71dbc65d715a --- /dev/null +++ b/services/abilitymgr/test/unittest/phone/kernal_system_app_manager_test/kernal_system_app_manager_test.cpp @@ -0,0 +1,614 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#if 1 +#include + +#define private public +#include "sa_mgr_client.h" +#include "kernal_system_app_manager.h" +#include "app_scheduler.h" +#undef private + +#include "ability_config.h" +#include "ability_manager_service.h" +#include "ability_manager_errors.h" +#include "ability_scheduler_mock.h" +#include "bundlemgr/mock_bundle_manager.h" +#include "mock_app_manager_client.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace AAFwk { + +static void WaitUntilTaskFinished() +{ + const uint32_t maxRetryCount = 1000; + const uint32_t sleepTime = 1000; + uint32_t count = 0; + auto handler = OHOS::DelayedSingleton::GetInstance()->GetEventHandler(); + std::atomic taskCalled(false); + auto f = [&taskCalled]() { taskCalled.store(true); }; + if (handler->PostTask(f)) { + while (!taskCalled.load()) { + ++count; + if (count >= maxRetryCount) { + break; + } + usleep(sleepTime); + } + } +} + +class KernalSystemAppManagerTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); + void StartSystemUI(); + +public: + std::shared_ptr kernalSystemMgr_ {nullptr}; + int usrId_ = 10; + Want want_ {}; + AppExecFwk::AbilityInfo abilityInfo_ {}; + AppExecFwk::ApplicationInfo appInfo_ {}; +}; + +void KernalSystemAppManagerTest::SetUpTestCase() +{ + int systemAbilityId = 401; + OHOS::DelayedSingleton::GetInstance()->RegisterSystemAbility( + systemAbilityId, new (std::nothrow) AppExecFwk::BundleMgrService()); + DelayedSingleton::GetInstance()->OnStart(); +} + +void KernalSystemAppManagerTest::TearDownTestCase() +{ + OHOS::DelayedSingleton::GetInstance()->OnStop(); + OHOS::DelayedSingleton::DestroyInstance(); +} + +void KernalSystemAppManagerTest::SetUp() +{ + kernalSystemMgr_ = std::make_shared(usrId_); + kernalSystemMgr_->abilities_.clear(); + std::queue().swap(kernalSystemMgr_->waittingAbilityQueue_); +} + +void KernalSystemAppManagerTest::TearDown() +{ + kernalSystemMgr_.reset(); +} + +void KernalSystemAppManagerTest::StartSystemUI() +{ + Want want; + want.SetElementName(AbilityConfig::SYSTEM_UI_BUNDLE_NAME, AbilityConfig::SYSTEM_UI_STATUS_BAR); + + AbilityRequest request; + request.want = want; + request.requestCode = -1; + request.callerToken = nullptr; + request.abilityInfo.name = AbilityConfig::SYSTEM_UI_STATUS_BAR; + request.abilityInfo.bundleName = AbilityConfig::SYSTEM_UI_BUNDLE_NAME; + request.appInfo.isLauncherApp = true; + request.appInfo.name = AbilityConfig::SYSTEM_UI_STATUS_BAR; + request.appInfo.bundleName = AbilityConfig::SYSTEM_UI_BUNDLE_NAME; + + EXPECT_TRUE(kernalSystemMgr_); + + auto ref = kernalSystemMgr_->StartAbility(request); + WaitUntilTaskFinished(); + EXPECT_EQ(ERR_OK, ref); +} + +/* + * Feature: KernalSystemAppManager + * Function: StartAbility,StartAbilityLocked + * SubFunction: Processing preconditions + * FunctionPoints: KernalSystemAppManager StartAbility + * EnvConditions:Is Kernal System Ability + * CaseDescription: Start a system level aa + */ +HWTEST_F(KernalSystemAppManagerTest, StartAbility_001, TestSize.Level1) +{ + // start a system ui + Want want; + want.SetElementName(AbilityConfig::SYSTEM_UI_BUNDLE_NAME, AbilityConfig::SYSTEM_UI_STATUS_BAR); + + AbilityRequest request; + request.want = want; + request.requestCode = -1; + request.callerToken = nullptr; + request.abilityInfo.name = AbilityConfig::SYSTEM_UI_STATUS_BAR; + request.abilityInfo.bundleName = AbilityConfig::SYSTEM_UI_BUNDLE_NAME; + request.appInfo.isLauncherApp = true; + request.appInfo.name = "syetemUi"; + request.appInfo.bundleName = AbilityConfig::SYSTEM_UI_BUNDLE_NAME; + EXPECT_TRUE(kernalSystemMgr_); + + auto ref = kernalSystemMgr_->StartAbility(request); + WaitUntilTaskFinished(); + EXPECT_EQ(ERR_OK, ref); + EXPECT_EQ(static_cast(kernalSystemMgr_->abilities_.size()), 1); + + auto topAbilityRecord = kernalSystemMgr_->GetCurrentTopAbility(); + EXPECT_TRUE(topAbilityRecord); + EXPECT_TRUE(topAbilityRecord->IsKernalSystemAbility()); + topAbilityRecord->SetAbilityState(AbilityState::INITIAL); + + // start agin + auto refBegin = kernalSystemMgr_->StartAbility(request); + WaitUntilTaskFinished(); + EXPECT_EQ(ERR_OK, refBegin); + // same aa, so size is 1. Just update not push + EXPECT_EQ(static_cast(kernalSystemMgr_->abilities_.size()), 1); + EXPECT_TRUE(topAbilityRecord->IsNewWant()); +} + +/* + * Feature: KernalSystemAppManager + * Function: StartAbility,StartAbilityLocked + * SubFunction: Processing preconditions + * FunctionPoints: KernalSystemAppManager StartAbility + * EnvConditions:Is Kernal System Ability + * CaseDescription: Start a system level aa + */ +HWTEST_F(KernalSystemAppManagerTest, StartAbility_002, TestSize.Level1) +{ + // start a system ui + Want want; + want.SetElementName(AbilityConfig::SYSTEM_UI_BUNDLE_NAME, AbilityConfig::SYSTEM_UI_STATUS_BAR); + AbilityRequest request; + request.want = want; + request.requestCode = -1; + request.callerToken = nullptr; + request.abilityInfo.name = AbilityConfig::SYSTEM_UI_STATUS_BAR; + request.abilityInfo.bundleName = AbilityConfig::SYSTEM_UI_BUNDLE_NAME; + request.appInfo.isLauncherApp = true; + request.appInfo.name = "syetemUi"; + request.appInfo.bundleName = AbilityConfig::SYSTEM_UI_BUNDLE_NAME; + + Want wantBar; + wantBar.SetElementName(AbilityConfig::SYSTEM_UI_BUNDLE_NAME, AbilityConfig::SYSTEM_UI_NAVIGATION_BAR); + AbilityRequest requestBar; + requestBar.want = wantBar; + requestBar.requestCode = -1; + requestBar.callerToken = nullptr; + requestBar.abilityInfo.name = AbilityConfig::SYSTEM_UI_STATUS_BAR; + requestBar.abilityInfo.bundleName = AbilityConfig::SYSTEM_UI_NAVIGATION_BAR; + requestBar.appInfo.isLauncherApp = true; + requestBar.appInfo.name = "syetemUi"; + requestBar.appInfo.bundleName = AbilityConfig::SYSTEM_UI_BUNDLE_NAME; + + // nullptr name and bundlename + Want wantPage; + AbilityRequest requestPage; + requestPage.want = wantPage; + requestPage.requestCode = -1; + requestPage.callerToken = nullptr; + EXPECT_TRUE(kernalSystemMgr_); + + int firstStartRef = kernalSystemMgr_->StartAbility(request); + WaitUntilTaskFinished(); + auto topAbilityRecord = kernalSystemMgr_->GetCurrentTopAbility(); + EXPECT_TRUE(topAbilityRecord); + topAbilityRecord->SetAbilityState(AbilityState::ACTIVATING); + + int secondStartRef = kernalSystemMgr_->StartAbility(requestBar); + int thirdStartRef = kernalSystemMgr_->StartAbility(requestPage); + + EXPECT_EQ(static_cast(kernalSystemMgr_->abilities_.size()), 1); + EXPECT_EQ(static_cast(kernalSystemMgr_->waittingAbilityQueue_.size()), 2); + EXPECT_EQ(ERR_OK, firstStartRef); + EXPECT_EQ(START_ABILITY_WAITING, secondStartRef); + EXPECT_EQ(START_ABILITY_WAITING, thirdStartRef); +} + +/* + * Feature: KernalSystemAppManager + * Function: AttachAbilityThread + * SubFunction: binding app + * FunctionPoints: bingding app and move to forground + * EnvConditions:Is Kernal System Ability + * CaseDescription: have a ability to attach + */ +HWTEST_F(KernalSystemAppManagerTest, AttachAbilityThread_001, TestSize.Level1) +{ + EXPECT_TRUE(kernalSystemMgr_); + sptr scheduler = nullptr; + sptr token = nullptr; + + int ref = kernalSystemMgr_->AttachAbilityThread(scheduler, token); + EXPECT_EQ(ERR_INVALID_VALUE, ref); + + StartSystemUI(); + auto topAbilityRecord = kernalSystemMgr_->GetCurrentTopAbility(); + EXPECT_TRUE(topAbilityRecord); + // scheduler judge null is on the upper level, in ams, so is return ok + ref = kernalSystemMgr_->AttachAbilityThread(scheduler, topAbilityRecord->GetToken()); + EXPECT_EQ(ERR_OK, ref); + + sptr mokecheduler = new AbilitySchedulerMock(); + ref = kernalSystemMgr_->AttachAbilityThread(mokecheduler, topAbilityRecord->GetToken()); + EXPECT_EQ(ERR_OK, ref); +} + +/* + * Feature: KernalSystemAppManager + * Function: AbilityTransitionDone + * SubFunction: Processing preconditions + * FunctionPoints: KernalSystemAppManager StartAbility + * EnvConditions:Is Kernal System Ability + * CaseDescription: Notification status + */ +HWTEST_F(KernalSystemAppManagerTest, AbilityTransitionDone_001, TestSize.Level1) +{ + EXPECT_TRUE(kernalSystemMgr_); + sptr token = nullptr; + + int ref = kernalSystemMgr_->AbilityTransitionDone(token, -1); + EXPECT_EQ(ERR_INVALID_VALUE, ref); + + StartSystemUI(); + auto topAbilityRecord = kernalSystemMgr_->GetCurrentTopAbility(); + EXPECT_TRUE(topAbilityRecord); + ref = kernalSystemMgr_->AbilityTransitionDone(topAbilityRecord->GetToken(), -1); + EXPECT_EQ(ERR_INVALID_VALUE, ref); + + // The right example + topAbilityRecord->SetAbilityState(AbilityState::ACTIVATING); + ref = kernalSystemMgr_->AbilityTransitionDone(topAbilityRecord->GetToken(), AbilityState::ACTIVE); + EXPECT_EQ(ERR_OK, ref); + WaitUntilTaskFinished(); + + ref = kernalSystemMgr_->AbilityTransitionDone(topAbilityRecord->GetToken(), AbilityState::INITIAL); + EXPECT_EQ(ERR_INVALID_VALUE, ref); +} + +/* + * Feature: KernalSystemAppManagerssssssssssssssss + * Function: OnAbilityRequestDone + * SubFunction: Processing preconditions + * FunctionPoints: KernalSystemAppManager OnAbilityRequestDone + * EnvConditions:Is Kernal System Ability + * CaseDescription: Notification status + */ +HWTEST_F(KernalSystemAppManagerTest, OnAbilityRequestDone_001, TestSize.Level1) +{ + EXPECT_TRUE(kernalSystemMgr_); + StartSystemUI(); + auto topAbilityRecord = kernalSystemMgr_->GetCurrentTopAbility(); + EXPECT_TRUE(topAbilityRecord); + kernalSystemMgr_->OnAbilityRequestDone(topAbilityRecord->GetToken(), -1); + EXPECT_NE(topAbilityRecord->GetAbilityState(), AbilityState::ACTIVATING); + + kernalSystemMgr_->OnAbilityRequestDone( + topAbilityRecord->GetToken(), static_cast(AppExecFwk::AbilityState::ABILITY_STATE_FOREGROUND)); + EXPECT_EQ(topAbilityRecord->GetAbilityState(), AbilityState::ACTIVATING); +} + +/* + * Feature: KernalSystemAppManager + * Function: OnAbilityRequestDone + * SubFunction: Processing preconditions + * FunctionPoints: KernalSystemAppManager OnAbilityRequestDone + * EnvConditions:Is Kernal System Ability + * CaseDescription: Notification status + */ +HWTEST_F(KernalSystemAppManagerTest, GetManagerUserId_001, TestSize.Level1) +{ + EXPECT_TRUE(kernalSystemMgr_); + StartSystemUI(); + int testUserID = kernalSystemMgr_->GetManagerUserId(); + EXPECT_EQ(10, testUserID); +} + +/* + * Feature: KernalSystemAppManager + * Function: DumpState + * SubFunction: Processing preconditions + * FunctionPoints: + * EnvConditions:Is Kernal System Ability + * CaseDescription: Notification status + */ +HWTEST_F(KernalSystemAppManagerTest, DumpState_001, TestSize.Level1) +{ + EXPECT_TRUE(kernalSystemMgr_); + StartSystemUI(); + std::vector info; + kernalSystemMgr_->DumpState(info); + + auto isFindAbilityInfo = [](std::string &abilityInfo) { + return std::string::npos != abilityInfo.find(AbilityConfig::SYSTEM_UI_BUNDLE_NAME); + }; + // find the SYSTEM_UI_BUNDLE_NAME + EXPECT_NE(info.end(), std::find_if(info.begin(), info.end(), isFindAbilityInfo)); +} + +/* + * Feature: KernalSystemAppManager + * Function: OnAbilityDied + * SubFunction: Processing preconditions + * FunctionPoints: + * EnvConditions:Is Kernal System Ability + * CaseDescription: Notification ability died + */ +HWTEST_F(KernalSystemAppManagerTest, OnAbilityDied_001, TestSize.Level1) +{ + EXPECT_TRUE(kernalSystemMgr_); + StartSystemUI(); + auto topAbilityRecord = kernalSystemMgr_->GetCurrentTopAbility(); + EXPECT_TRUE(topAbilityRecord); + kernalSystemMgr_->OnAbilityDied(topAbilityRecord); + EXPECT_EQ(topAbilityRecord->GetAbilityState(), AbilityState::INITIAL); +} + +/* + * Feature: KernalSystemAppManager + * Function: OnAbilityDied + * SubFunction: Processing preconditions + * FunctionPoints: + * EnvConditions:Is Kernal System Ability + * CaseDescription: Notification status + */ +HWTEST_F(KernalSystemAppManagerTest, OnAbilityDied_002, TestSize.Level1) +{ + EXPECT_TRUE(kernalSystemMgr_); + StartSystemUI(); + auto topAbilityRecord = kernalSystemMgr_->GetCurrentTopAbility(); + EXPECT_TRUE(topAbilityRecord); + kernalSystemMgr_->OnAbilityDied(topAbilityRecord); + EXPECT_EQ(topAbilityRecord->GetAbilityState(), AbilityState::INITIAL); +} + +/* + * Feature: KernalSystemAppManager + * Function: OnAbilityDied + * SubFunction: Processing preconditions + * FunctionPoints: + * EnvConditions:Is Kernal System Ability + * CaseDescription: Notification status + */ +HWTEST_F(KernalSystemAppManagerTest, OnTimeOut_001, TestSize.Level1) +{ + EXPECT_TRUE(kernalSystemMgr_); + StartSystemUI(); + auto topAbilityRecord = kernalSystemMgr_->GetCurrentTopAbility(); + EXPECT_TRUE(topAbilityRecord); + std::vector info; + kernalSystemMgr_->DumpState(info); + auto isFindAbilityInfo = [](std::string &abilityInfo) { + return std::string::npos != abilityInfo.find(AbilityConfig::SYSTEM_UI_BUNDLE_NAME); + }; + EXPECT_NE(info.end(), std::find_if(info.begin(), info.end(), isFindAbilityInfo)); + + // remove form vector + kernalSystemMgr_->OnTimeOut(AbilityManagerService::LOAD_TIMEOUT_MSG, topAbilityRecord->GetEventId()); + + info.clear(); + kernalSystemMgr_->DumpState(info); + // topAbilityRecord must be delete + EXPECT_EQ(info.end(), std::find_if(info.begin(), info.end(), isFindAbilityInfo)); +} +/* + * Feature: KernalSystemAppManager + * Function: DequeueWaittingAbility + * SubFunction: Processing preconditions + * FunctionPoints: + * EnvConditions:Is Kernal System Ability + * CaseDescription: Notification status + */ +HWTEST_F(KernalSystemAppManagerTest, DequeueWaittingAbility_001, TestSize.Level1) +{ + EXPECT_TRUE(kernalSystemMgr_); + StartSystemUI(); + auto topAbilityRecord = kernalSystemMgr_->GetCurrentTopAbility(); + EXPECT_TRUE(topAbilityRecord); + topAbilityRecord->SetAbilityState(AbilityState::ACTIVATING); + + Want want; + AbilityRequest request; + request.want = want; + request.requestCode = -1; + request.callerToken = nullptr; + request.abilityInfo.name = AbilityConfig::SYSTEM_UI_STATUS_BAR; + request.abilityInfo.bundleName = AbilityConfig::SYSTEM_UI_BUNDLE_NAME; + request.appInfo.isLauncherApp = true; + request.appInfo.name = "syetemUi"; + request.appInfo.bundleName = AbilityConfig::SYSTEM_UI_BUNDLE_NAME; + + // push in waiting queue + kernalSystemMgr_->StartAbility(request); + EXPECT_EQ(static_cast(kernalSystemMgr_->waittingAbilityQueue_.size()), 1); + + topAbilityRecord->SetAbilityState(AbilityState::ACTIVE); + kernalSystemMgr_->DequeueWaittingAbility(); + EXPECT_EQ(static_cast(kernalSystemMgr_->waittingAbilityQueue_.size()), 0); +} + +/* + * Feature: KernalSystemAppManager + * Function: DequeueWaittingAbility + * SubFunction: Processing preconditions + * FunctionPoints: + * EnvConditions:Is Kernal System Ability + * CaseDescription: Notification status + */ +HWTEST_F(KernalSystemAppManagerTest, GetOrCreateAbilityRecord_001, TestSize.Level1) +{ + EXPECT_TRUE(kernalSystemMgr_); + + Want want; + AbilityRequest request; + request.want = want; + request.requestCode = -1; + request.callerToken = nullptr; + request.abilityInfo.name = AbilityConfig::SYSTEM_UI_STATUS_BAR; + request.abilityInfo.bundleName = AbilityConfig::SYSTEM_UI_BUNDLE_NAME; + request.appInfo.isLauncherApp = true; + request.appInfo.name = "syetemUi"; + request.appInfo.bundleName = AbilityConfig::SYSTEM_UI_BUNDLE_NAME; + + std::shared_ptr targetAbility; + EXPECT_FALSE(targetAbility); + kernalSystemMgr_->GetOrCreateAbilityRecord(request, targetAbility); + + EXPECT_EQ(static_cast(kernalSystemMgr_->abilities_.size()), 1); + EXPECT_TRUE(targetAbility); + EXPECT_FALSE(targetAbility->IsNewWant()); + + // again + kernalSystemMgr_->GetOrCreateAbilityRecord(request, targetAbility); + EXPECT_TRUE(targetAbility->IsNewWant()); +} + +/* + * Feature: KernalSystemAppManager + * Function: DequeueWaittingAbility + * SubFunction: Processing preconditions + * FunctionPoints: + * EnvConditions:Is Kernal System Ability + * CaseDescription: Notification status + */ +HWTEST_F(KernalSystemAppManagerTest, GetOrCreateAbilityRecord_002, TestSize.Level1) +{ + EXPECT_TRUE(kernalSystemMgr_); + + Want want; + AbilityRequest request; + request.want = want; + request.requestCode = -1; + request.callerToken = nullptr; + request.abilityInfo.name = AbilityConfig::SYSTEM_UI_STATUS_BAR; + request.abilityInfo.bundleName = AbilityConfig::SYSTEM_UI_BUNDLE_NAME; + request.appInfo.isLauncherApp = true; + request.appInfo.name = "syetemUi"; + request.appInfo.bundleName = AbilityConfig::SYSTEM_UI_BUNDLE_NAME; + + std::shared_ptr targetAbility; + EXPECT_FALSE(targetAbility); + kernalSystemMgr_->GetOrCreateAbilityRecord(request, targetAbility); + + EXPECT_EQ(static_cast(kernalSystemMgr_->abilities_.size()), 1); + EXPECT_TRUE(targetAbility); + EXPECT_FALSE(targetAbility->IsNewWant()); + + // again + kernalSystemMgr_->GetOrCreateAbilityRecord(request, targetAbility); + EXPECT_TRUE(targetAbility->IsNewWant()); + EXPECT_EQ(static_cast(kernalSystemMgr_->abilities_.size()), 1); + + std::string abilityNameInfo = AbilityConfig::SYSTEM_UI_BUNDLE_NAME + ":" + AbilityConfig::SYSTEM_UI_STATUS_BAR; + auto abilityFlag = + kernalSystemMgr_->GetFlagOfAbility(AbilityConfig::SYSTEM_UI_BUNDLE_NAME, AbilityConfig::SYSTEM_UI_STATUS_BAR); + EXPECT_TRUE(abilityNameInfo == abilityFlag); +} + +/* + * Feature: KernalSystemAppManager + * Function: DequeueWaittingAbility + * SubFunction: Processing preconditions + * FunctionPoints: + * EnvConditions:Is Kernal System Ability + * CaseDescription: Notification status + */ +HWTEST_F(KernalSystemAppManagerTest, GetAbilityRecordByToken_001, TestSize.Level1) +{ + EXPECT_TRUE(kernalSystemMgr_); + + StartSystemUI(); + auto topAbilityRecord = kernalSystemMgr_->GetCurrentTopAbility(); + EXPECT_TRUE(topAbilityRecord); + auto testRecord = kernalSystemMgr_->GetAbilityRecordByToken(topAbilityRecord->GetToken()); + EXPECT_TRUE(testRecord == topAbilityRecord); + + sptr token; + auto testRecord1 = kernalSystemMgr_->GetAbilityRecordByToken(token); + EXPECT_TRUE(testRecord1 == nullptr); + + auto testRecord2 = kernalSystemMgr_->GetAbilityRecordByEventId(topAbilityRecord->GetEventId()); + EXPECT_TRUE(testRecord2 == topAbilityRecord); + + auto testRecord3 = kernalSystemMgr_->GetAbilityRecordByEventId(-1); + EXPECT_TRUE(testRecord3 == nullptr); +} + +/* + * Feature: KernalSystemAppManager + * Function: DispatchActive + * SubFunction: Processing preconditions + * FunctionPoints: + * EnvConditions:Is Kernal System Ability + * CaseDescription: Notification status + */ +HWTEST_F(KernalSystemAppManagerTest, DispatchActive_001, TestSize.Level1) +{ + EXPECT_TRUE(kernalSystemMgr_); + + StartSystemUI(); + auto topAbilityRecord = kernalSystemMgr_->GetCurrentTopAbility(); + EXPECT_TRUE(topAbilityRecord); + topAbilityRecord->SetAbilityState(AbilityState::ACTIVATING); + + Want want; + AbilityRequest request; + request.want = want; + request.requestCode = -1; + request.callerToken = nullptr; + request.abilityInfo.name = AbilityConfig::SYSTEM_UI_STATUS_BAR; + request.abilityInfo.bundleName = AbilityConfig::SYSTEM_UI_BUNDLE_NAME; + request.appInfo.isLauncherApp = true; + request.appInfo.name = "syetemUi"; + request.appInfo.bundleName = AbilityConfig::SYSTEM_UI_BUNDLE_NAME; + + kernalSystemMgr_->EnqueueWaittingAbility(request); + EXPECT_EQ(static_cast(kernalSystemMgr_->waittingAbilityQueue_.size()), 1); + + int ref = kernalSystemMgr_->DispatchActive(topAbilityRecord, AbilityState::ACTIVE); + WaitUntilTaskFinished(); + EXPECT_EQ(ERR_OK, ref); +} + +/* + * Feature: KernalSystemAppManager + * Function: RemoveAbilityRecord + * SubFunction: Processing preconditions + * FunctionPoints: + * EnvConditions:Is Kernal System Ability + * CaseDescription: Notification status + */ +HWTEST_F(KernalSystemAppManagerTest, DispatchActive_002, TestSize.Level1) +{ + EXPECT_TRUE(kernalSystemMgr_); + StartSystemUI(); + auto topAbilityRecord = kernalSystemMgr_->GetCurrentTopAbility(); + EXPECT_TRUE(topAbilityRecord); + + EXPECT_EQ(static_cast(kernalSystemMgr_->abilities_.size()), 1); + bool isRemove = kernalSystemMgr_->RemoveAbilityRecord(topAbilityRecord); + EXPECT_TRUE(isRemove); + + isRemove = kernalSystemMgr_->RemoveAbilityRecord(nullptr); + EXPECT_FALSE(isRemove); +} + +} // namespace AAFwk +} // namespace OHOS + +#endif diff --git a/services/abilitymgr/test/unittest/phone/lifecycle_deal_test/BUILD.gn b/services/abilitymgr/test/unittest/phone/lifecycle_deal_test/BUILD.gn index 9b5bbe37abc0276e8aa919e9128207bc59c1972f..cfc5daf2eb8e9c3201ae22cee67d2866ce530b64 100755 --- a/services/abilitymgr/test/unittest/phone/lifecycle_deal_test/BUILD.gn +++ b/services/abilitymgr/test/unittest/phone/lifecycle_deal_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# Copyright (c) 2021 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -44,7 +44,6 @@ ohos_unittest("lifecycle_deal_test") { "${services_path}/abilitymgr/test/mock/libs/aakit:aakit_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_appmgr_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", - "${services_path}/common:perm_verification", "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", "//foundation/aafwk/standard/frameworks/kits/ability/native:dummy_classes", "//foundation/aafwk/standard/services/abilitymgr:abilityms", diff --git a/services/abilitymgr/test/unittest/phone/lifecycle_test/BUILD.gn b/services/abilitymgr/test/unittest/phone/lifecycle_test/BUILD.gn index 34037869d7e1352d651f4064167f4c5ed70fbf9d..f7d87c2c354a9892d965eeecbe2f2a5a886d89b6 100755 --- a/services/abilitymgr/test/unittest/phone/lifecycle_test/BUILD.gn +++ b/services/abilitymgr/test/unittest/phone/lifecycle_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# Copyright (c) 2021 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -44,7 +44,6 @@ ohos_unittest("lifecycle_test") { "${services_path}/abilitymgr/test/mock/libs/aakit:aakit_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_appmgr_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", - "${services_path}/common:perm_verification", "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", "//foundation/aafwk/standard/frameworks/kits/ability/native:dummy_classes", "//foundation/aafwk/standard/services/abilitymgr:abilityms", diff --git a/services/abilitymgr/test/unittest/phone/lifecycle_test/lifecycle_test.cpp b/services/abilitymgr/test/unittest/phone/lifecycle_test/lifecycle_test.cpp index 6b5ae0920f026c47448ff6b8c433cbab896d4a24..caba94dd3fd1cd9ffacc30f96407bc0ad0639ad1 100644 --- a/services/abilitymgr/test/unittest/phone/lifecycle_test/lifecycle_test.cpp +++ b/services/abilitymgr/test/unittest/phone/lifecycle_test/lifecycle_test.cpp @@ -120,6 +120,8 @@ void LifecycleTest::OnStartabilityAms() abilityMs_->SetStackManager(userId, true); EXPECT_TRUE(abilityMs_->GetStackManager()); abilityMs_->stackManagers_.emplace(0, abilityMs_->GetStackManager()); + abilityMs_->systemAppManager_ = std::make_shared(userId); + EXPECT_TRUE(abilityMs_->systemAppManager_); abilityMs_->eventLoop_->Run(); return; } diff --git a/services/abilitymgr/test/unittest/phone/lock_screen_white_list_test/BUILD.gn b/services/abilitymgr/test/unittest/phone/lock_screen_white_list_test/BUILD.gn index 41196f58b533ff9db5a9cf6fff716d6cb9e37c70..2b8b768ba8817d6c778e5f9589e658c2ecb9a7a3 100755 --- a/services/abilitymgr/test/unittest/phone/lock_screen_white_list_test/BUILD.gn +++ b/services/abilitymgr/test/unittest/phone/lock_screen_white_list_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# Copyright (c) 2021 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -46,7 +46,6 @@ ohos_unittest("lock_screen_white_list_test") { "${services_path}/abilitymgr/test/mock/libs/aakit:aakit_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_appmgr_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", - "${services_path}/common:perm_verification", "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", "//foundation/aafwk/standard/frameworks/kits/ability/native:dummy_classes", "//foundation/aafwk/standard/interfaces/innerkits/app_manager:app_manager", diff --git a/services/abilitymgr/test/unittest/phone/mission_list_test/BUILD.gn b/services/abilitymgr/test/unittest/phone/mission_list_test/BUILD.gn index 501e6cb30c8507fe5caa18a3f0977dbb69c91807..edcc5c6c6c07945cacd10e400c89b22e0d0c849f 100755 --- a/services/abilitymgr/test/unittest/phone/mission_list_test/BUILD.gn +++ b/services/abilitymgr/test/unittest/phone/mission_list_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# Copyright (c) 2021 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -43,7 +43,6 @@ ohos_unittest("mission_list_test") { "${services_path}/abilitymgr/test/mock/libs/aakit:aakit_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_appmgr_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", - "${services_path}/common:perm_verification", "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", "//foundation/aafwk/standard/frameworks/kits/ability/native:dummy_classes", "//foundation/aafwk/standard/services/abilitymgr:abilityms", diff --git a/services/abilitymgr/test/unittest/phone/mission_record_test/BUILD.gn b/services/abilitymgr/test/unittest/phone/mission_record_test/BUILD.gn index 83bb54d7996866bc299dc349833a6925f19ccdce..32fe28154ff1fc68439cf5f2416c0cd7c12f81bf 100755 --- a/services/abilitymgr/test/unittest/phone/mission_record_test/BUILD.gn +++ b/services/abilitymgr/test/unittest/phone/mission_record_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# Copyright (c) 2021 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -43,7 +43,6 @@ ohos_unittest("mission_record_test") { "${services_path}/abilitymgr/test/mock/libs/aakit:aakit_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_appmgr_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", - "${services_path}/common:perm_verification", "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", "//foundation/aafwk/standard/frameworks/kits/ability/native:dummy_classes", "//foundation/aafwk/standard/services/abilitymgr:abilityms", diff --git a/services/abilitymgr/test/unittest/phone/mission_stack_test/BUILD.gn b/services/abilitymgr/test/unittest/phone/mission_stack_test/BUILD.gn index 8ed7ffa2963bbcba09d65ec7d048f739c0a8a686..e593f79c7045d656b740d98c99ee4b796d0f4b52 100755 --- a/services/abilitymgr/test/unittest/phone/mission_stack_test/BUILD.gn +++ b/services/abilitymgr/test/unittest/phone/mission_stack_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# Copyright (c) 2021 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -43,7 +43,6 @@ ohos_unittest("mission_stack_test") { "${services_path}/abilitymgr/test/mock/libs/aakit:aakit_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_appmgr_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", - "${services_path}/common:perm_verification", "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", "//foundation/aafwk/standard/frameworks/kits/ability/native:dummy_classes", "//foundation/aafwk/standard/services/abilitymgr:abilityms", diff --git a/services/abilitymgr/test/unittest/phone/mission_test/BUILD.gn b/services/abilitymgr/test/unittest/phone/mission_test/BUILD.gn index b10cf3ff3fa76367c235599f59ab20db1b942014..1016e3b220b25e2e066ef621fc56dd9e42341118 100755 --- a/services/abilitymgr/test/unittest/phone/mission_test/BUILD.gn +++ b/services/abilitymgr/test/unittest/phone/mission_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# Copyright (c) 2021 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -43,7 +43,6 @@ ohos_unittest("mission_test") { "${services_path}/abilitymgr/test/mock/libs/aakit:aakit_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_appmgr_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", - "${services_path}/common:perm_verification", "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", "//foundation/aafwk/standard/frameworks/kits/ability/native:dummy_classes", "//foundation/aafwk/standard/services/abilitymgr:abilityms", diff --git a/services/abilitymgr/test/unittest/phone/pending_want_key_test/BUILD.gn b/services/abilitymgr/test/unittest/phone/pending_want_key_test/BUILD.gn index 57f608cbbbac48aabc3d43b07392d5be93d7dfbf..3e0e13e260b70fbb4bcb7a8a6140798759b13702 100755 --- a/services/abilitymgr/test/unittest/phone/pending_want_key_test/BUILD.gn +++ b/services/abilitymgr/test/unittest/phone/pending_want_key_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# Copyright (c) 2021 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -37,7 +37,6 @@ ohos_unittest("pending_want_key_test") { "${services_path}/abilitymgr/test/mock/libs/aakit:aakit_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_appmgr_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", - "${services_path}/common:perm_verification", "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", "//foundation/aafwk/standard/frameworks/kits/ability/native:dummy_classes", "//foundation/aafwk/standard/services/abilitymgr:abilityms", diff --git a/services/abilitymgr/test/unittest/phone/pending_want_manager_test/BUILD.gn b/services/abilitymgr/test/unittest/phone/pending_want_manager_test/BUILD.gn index 553196a5e537ea55de5d644eeb05fd56548cd747..e721a1d5bce30466fd28ed81cb25d9ad48f46b57 100755 --- a/services/abilitymgr/test/unittest/phone/pending_want_manager_test/BUILD.gn +++ b/services/abilitymgr/test/unittest/phone/pending_want_manager_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# Copyright (c) 2021 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -41,7 +41,6 @@ ohos_unittest("pending_want_manager_test") { "${services_path}/abilitymgr/test/mock/libs/aakit:aakit_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_appmgr_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", - "${services_path}/common:perm_verification", "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", "//foundation/aafwk/standard/frameworks/kits/ability/native:dummy_classes", "//foundation/aafwk/standard/services/abilitymgr:abilityms", diff --git a/services/abilitymgr/test/unittest/phone/pending_want_record_test/BUILD.gn b/services/abilitymgr/test/unittest/phone/pending_want_record_test/BUILD.gn index d8144184708caafafbf9f2f85c4db3f934d7b8bc..3923e207737ac861961889bfd0e1b002ee985a4b 100755 --- a/services/abilitymgr/test/unittest/phone/pending_want_record_test/BUILD.gn +++ b/services/abilitymgr/test/unittest/phone/pending_want_record_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# Copyright (c) 2021 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -41,7 +41,6 @@ ohos_unittest("pending_want_record_test") { "${services_path}/abilitymgr/test/mock/libs/aakit:aakit_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_appmgr_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", - "${services_path}/common:perm_verification", "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", "//foundation/aafwk/standard/frameworks/kits/ability/native:dummy_classes", "//foundation/aafwk/standard/services/abilitymgr:abilityms", diff --git a/services/abilitymgr/test/unittest/phone/resume_mission_container_test/BUILD.gn b/services/abilitymgr/test/unittest/phone/resume_mission_container_test/BUILD.gn index 2a67e2b4f726efb0d865c87bc85ee842d9ba48e5..c50b7e90963f181969f4357e2e9ce6e7280926fc 100755 --- a/services/abilitymgr/test/unittest/phone/resume_mission_container_test/BUILD.gn +++ b/services/abilitymgr/test/unittest/phone/resume_mission_container_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# Copyright (c) 2021 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -41,7 +41,6 @@ ohos_unittest("resume_mission_container_test") { "${services_path}/abilitymgr/test/mock/libs/aakit:aakit_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_appmgr_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", - "${services_path}/common:perm_verification", "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", "//foundation/aafwk/standard/frameworks/kits/ability/native:dummy_classes", "//foundation/aafwk/standard/services/abilitymgr:abilityms", diff --git a/services/abilitymgr/test/unittest/phone/screenshot_handler_test/BUILD.gn b/services/abilitymgr/test/unittest/phone/screenshot_handler_test/BUILD.gn index 8eb265421830a1c296a913ea2228abfad44affa2..e0d5bbbf1f9a6ad51854473251f6cc621235ccb8 100755 --- a/services/abilitymgr/test/unittest/phone/screenshot_handler_test/BUILD.gn +++ b/services/abilitymgr/test/unittest/phone/screenshot_handler_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# Copyright (c) 2021 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -46,7 +46,6 @@ ohos_unittest("ability_screenshot_handler_test") { "${services_path}/abilitymgr/test/mock/libs/aakit:aakit_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_appmgr_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", - "${services_path}/common:perm_verification", "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", "//foundation/aafwk/standard/frameworks/kits/ability/native:dummy_classes", "//foundation/aafwk/standard/interfaces/innerkits/app_manager:app_manager", diff --git a/services/abilitymgr/test/unittest/phone/sender_info_test/BUILD.gn b/services/abilitymgr/test/unittest/phone/sender_info_test/BUILD.gn index a32ff3cced1c2e187792fc5afd9520edb856271e..e6fda6bebe4c4fee87f852a6b56daa73344b8400 100755 --- a/services/abilitymgr/test/unittest/phone/sender_info_test/BUILD.gn +++ b/services/abilitymgr/test/unittest/phone/sender_info_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# Copyright (c) 2021 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -41,7 +41,6 @@ ohos_unittest("sender_info_test") { "${services_path}/abilitymgr/test/mock/libs/aakit:aakit_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_appmgr_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", - "${services_path}/common:perm_verification", "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", "//foundation/aafwk/standard/frameworks/kits/ability/native:dummy_classes", "//foundation/aafwk/standard/services/abilitymgr:abilityms", diff --git a/services/abilitymgr/test/unittest/phone/terminate_ability_test/BUILD.gn b/services/abilitymgr/test/unittest/phone/terminate_ability_test/BUILD.gn index 613e21d71d50751f8a2ba44503561f15b0175f46..b96dcc1575981b150c418263a889d66c6433b937 100755 --- a/services/abilitymgr/test/unittest/phone/terminate_ability_test/BUILD.gn +++ b/services/abilitymgr/test/unittest/phone/terminate_ability_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# Copyright (c) 2021 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -46,7 +46,6 @@ ohos_unittest("terminate_ability_test") { "${services_path}/abilitymgr/test/mock/libs/aakit:aakit_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_appmgr_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", - "${services_path}/common:perm_verification", "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", "//foundation/aafwk/standard/frameworks/kits/ability/native:dummy_classes", "//foundation/aafwk/standard/services/abilitymgr:abilityms", diff --git a/services/abilitymgr/test/unittest/phone/terminate_ability_test/terminate_ability_test.cpp b/services/abilitymgr/test/unittest/phone/terminate_ability_test/terminate_ability_test.cpp index cb23413e4c7090d5854cd4ebbb778c3a87476612..cbfeec4338f69c11bb18a1bf0880ee96a7555516 100644 --- a/services/abilitymgr/test/unittest/phone/terminate_ability_test/terminate_ability_test.cpp +++ b/services/abilitymgr/test/unittest/phone/terminate_ability_test/terminate_ability_test.cpp @@ -160,6 +160,8 @@ void TerminateAbilityTest::OnStartAms() int userId = g_aams->GetUserId(); g_aams->SetStackManager(userId, true); + g_aams->systemAppManager_ = std::make_shared(userId); + EXPECT_TRUE(g_aams->systemAppManager_); g_aams->eventLoop_->Run(); diff --git a/services/abilitymgr/test/unittest/phone/want_receiver_proxy_test/BUILD.gn b/services/abilitymgr/test/unittest/phone/want_receiver_proxy_test/BUILD.gn index 7f086e86c11480814b5c0f0ca6666831cf278574..ef69a506a6c29cdc2eb85db1472a1056a7740bfb 100755 --- a/services/abilitymgr/test/unittest/phone/want_receiver_proxy_test/BUILD.gn +++ b/services/abilitymgr/test/unittest/phone/want_receiver_proxy_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# Copyright (c) 2021 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -42,7 +42,6 @@ ohos_unittest("want_receiver_proxy_test") { "${services_path}/abilitymgr/test/mock/libs/aakit:aakit_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_appmgr_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", - "${services_path}/common:perm_verification", "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", "//foundation/aafwk/standard/frameworks/kits/ability/native:dummy_classes", "//foundation/aafwk/standard/services/abilitymgr:abilityms", diff --git a/services/abilitymgr/test/unittest/phone/want_receiver_stub_test/BUILD.gn b/services/abilitymgr/test/unittest/phone/want_receiver_stub_test/BUILD.gn index 36fbb48a4fb3bf476d154a1ca7a4c0e23a7fd171..5a2d38e81a668154efd24577a8a0abfa5037883c 100755 --- a/services/abilitymgr/test/unittest/phone/want_receiver_stub_test/BUILD.gn +++ b/services/abilitymgr/test/unittest/phone/want_receiver_stub_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# Copyright (c) 2021 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -43,7 +43,6 @@ ohos_unittest("want_receiver_stub_test") { "${services_path}/abilitymgr/test/mock/libs/aakit:aakit_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_appmgr_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", - "${services_path}/common:perm_verification", "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", "//foundation/aafwk/standard/frameworks/kits/ability/native:dummy_classes", "//foundation/aafwk/standard/services/abilitymgr:abilityms", diff --git a/services/abilitymgr/test/unittest/phone/want_sender_info_test/BUILD.gn b/services/abilitymgr/test/unittest/phone/want_sender_info_test/BUILD.gn index bde67718101a382905563ac5f3bb8b12f244467d..e55ba85c80d511d7988f180146b59594eebb55e8 100755 --- a/services/abilitymgr/test/unittest/phone/want_sender_info_test/BUILD.gn +++ b/services/abilitymgr/test/unittest/phone/want_sender_info_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# Copyright (c) 2021 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -41,7 +41,6 @@ ohos_unittest("want_sender_info_test") { "${services_path}/abilitymgr/test/mock/libs/aakit:aakit_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_appmgr_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", - "${services_path}/common:perm_verification", "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", "//foundation/aafwk/standard/frameworks/kits/ability/native:dummy_classes", "//foundation/aafwk/standard/services/abilitymgr:abilityms", diff --git a/services/abilitymgr/test/unittest/phone/want_sender_proxy_test/BUILD.gn b/services/abilitymgr/test/unittest/phone/want_sender_proxy_test/BUILD.gn index 2568f4a7e6ba05d1389674395b5cb4f470da2050..3c9d898325bb325e8bdd9d5c8316cc18108c9255 100755 --- a/services/abilitymgr/test/unittest/phone/want_sender_proxy_test/BUILD.gn +++ b/services/abilitymgr/test/unittest/phone/want_sender_proxy_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# Copyright (c) 2021 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -42,7 +42,6 @@ ohos_unittest("want_sender_proxy_test") { "${services_path}/abilitymgr/test/mock/libs/aakit:aakit_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_appmgr_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", - "${services_path}/common:perm_verification", "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", "//foundation/aafwk/standard/frameworks/kits/ability/native:dummy_classes", "//foundation/aafwk/standard/services/abilitymgr:abilityms", diff --git a/services/abilitymgr/test/unittest/phone/want_sender_stub_test/BUILD.gn b/services/abilitymgr/test/unittest/phone/want_sender_stub_test/BUILD.gn index ab2095d8d702dace0c407aaca3aa1702b7ec5ea4..59a0a0489ac2d162987b14efca73206c12f676ce 100755 --- a/services/abilitymgr/test/unittest/phone/want_sender_stub_test/BUILD.gn +++ b/services/abilitymgr/test/unittest/phone/want_sender_stub_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# Copyright (c) 2021 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -43,7 +43,6 @@ ohos_unittest("want_sender_stub_test") { "${services_path}/abilitymgr/test/mock/libs/aakit:aakit_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_appmgr_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", - "${services_path}/common:perm_verification", "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", "//foundation/aafwk/standard/frameworks/kits/ability/native:dummy_classes", "//foundation/aafwk/standard/services/abilitymgr:abilityms", diff --git a/services/abilitymgr/test/unittest/phone/wants_info_test/BUILD.gn b/services/abilitymgr/test/unittest/phone/wants_info_test/BUILD.gn index d69aeb94ad31910384458cecde70576ceefa0d08..28e7e5b1894937b86e503bdb243c60fb8c5e9508 100755 --- a/services/abilitymgr/test/unittest/phone/wants_info_test/BUILD.gn +++ b/services/abilitymgr/test/unittest/phone/wants_info_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# Copyright (c) 2021 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -42,7 +42,6 @@ ohos_unittest("wants_info_test") { "${services_path}/abilitymgr/test/mock/libs/aakit:aakit_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_appmgr_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", - "${services_path}/common:perm_verification", "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", "//foundation/aafwk/standard/frameworks/kits/ability/native:dummy_classes", "//foundation/aafwk/standard/services/abilitymgr:abilityms", diff --git a/services/abilitymgr/test/unittest/phone/window_info_test/BUILD.gn b/services/abilitymgr/test/unittest/phone/window_info_test/BUILD.gn index f3a17d0b33db8961bb9cd55c9ff181ea0c991ed8..75d7230e7d7525beb7b0bb303d1a2e305c8d9461 100755 --- a/services/abilitymgr/test/unittest/phone/window_info_test/BUILD.gn +++ b/services/abilitymgr/test/unittest/phone/window_info_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# Copyright (c) 2021 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -37,7 +37,6 @@ ohos_unittest("window_info_test") { "${innerkits_path}/want:want", "${services_path}/abilitymgr/test:abilityms_test_source", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_appmgr_mock", - "${services_path}/common:perm_verification", "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", "//foundation/aafwk/standard/frameworks/kits/ability/native:dummy_classes", "//foundation/aafwk/standard/services/abilitymgr:abilityms", diff --git a/services/appmgr/BUILD.gn b/services/appmgr/BUILD.gn index 0ef3e87b2399d3f2a93bd44c6825d02acd50c02b..4647bde21cc3645e7a4ef89db49730324db452a4 100644 --- a/services/appmgr/BUILD.gn +++ b/services/appmgr/BUILD.gn @@ -17,7 +17,6 @@ import("//foundation/aafwk/standard/aafwk.gni") config("appmgr_config") { include_dirs = [ "include", - "${services_path}/common/include", "//base/startup/appspawn_standard/interfaces/innerkits/include", "//utils/system/safwk/native/include", "//base/account/os_account/interfaces/innerkits/osaccount/native/include", @@ -116,7 +115,6 @@ ohos_shared_library("libams") { "${appexecfwk_path}/interfaces/innerkits/appexecfwk_core:appexecfwk_core", "${appexecfwk_path}/libs/libeventhandler:libeventhandler_target", "${innerkits_path}/uri_permission:uri_permission_mgr", - "${services_path}/common:perm_verification", "//base/account/os_account/frameworks/osaccount/native:os_account_innerkits", "//base/global/i18n_standard/frameworks/intl:intl_util", "//base/security/permission/interfaces/innerkits/permission_standard/permissionsdk:libpermissionsdk_standard", diff --git a/services/appmgr/include/ams_mgr_scheduler.h b/services/appmgr/include/ams_mgr_scheduler.h index 990f6c597764d9cbcbd5e3fb1759588b5be26d61..a148acf9c8fe149c656c6599d5a85327f1fad2f0 100644 --- a/services/appmgr/include/ams_mgr_scheduler.h +++ b/services/appmgr/include/ams_mgr_scheduler.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -88,6 +88,13 @@ public: */ virtual void RegisterAppStateCallback(const sptr &callback) override; + /** + * Reset,call Reset() through the proxy object, reset DFX of AppMgr. + * + * @return + */ + virtual void Reset() override; + /** * AbilityBehaviorAnalysis, ability behavior analysis assistant process optimization. * diff --git a/services/appmgr/include/app_death_recipient.h b/services/appmgr/include/app_death_recipient.h index 0bd39e48c3ab32105a57d5e14bcacc1ff6ad29ad..39179e0b3a0e9864b882dc210820b8634f83b888 100644 --- a/services/appmgr/include/app_death_recipient.h +++ b/services/appmgr/include/app_death_recipient.h @@ -42,10 +42,7 @@ public: */ void SetAppMgrServiceInner(const std::shared_ptr &serviceInner); - void SetIsRenderProcess(bool isRenderProcess); - private: - bool isRenderProcess_ = false; std::weak_ptr handler_; std::weak_ptr appMgrServiceInner_; }; diff --git a/services/appmgr/include/app_mgr_service.h b/services/appmgr/include/app_mgr_service.h index 47eaf0b10628d2471eb8f18fb5c8f592ec1f5293..a623851bfad915fe555387c2daeabcc944c3edf1 100644 --- a/services/appmgr/include/app_mgr_service.h +++ b/services/appmgr/include/app_mgr_service.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -113,6 +113,15 @@ public: */ virtual int32_t ClearUpApplicationData(const std::string &bundleName) override; + /** + * IsBackgroundRunningRestricted, call IsBackgroundRunningRestricted() through proxy project, + * Checks whether the process of this application is forbidden to run in the background. + * + * @param bundleName, bundle name in Application record. + * @return ERR_OK, return back success, others fail. + */ + virtual int32_t IsBackgroundRunningRestricted(const std::string &bundleName) override; + /** * GetAllRunningProcesses, call GetAllRunningProcesses() through proxy project. * Obtains information about application processes that are running on the device. @@ -158,6 +167,24 @@ public: */ virtual sptr GetAmsMgr() override; + /** + * SetAppSuspendTimes, Setting the Freezing Time of APP Background. + * + * @param time, The timeout recorded when the application enters the background . + * + * @return Success or Failure . + */ + virtual void SetAppFreezingTime(int time) override; + + /** + * GetAppFreezingTime, Getting the Freezing Time of APP Background. + * + * @param time, The timeout recorded when the application enters the background . + * + * @return Success or Failure . + */ + virtual void GetAppFreezingTime(int &time) override; + /** * Get system memory information. * @param SystemMemoryAttr, memory information. @@ -197,11 +224,6 @@ public: */ int GetAbilityRecordsByProcessID(const int pid, std::vector> &tokens) override; - virtual int StartRenderProcess(const std::string &renderParam, int32_t ipcFd, - int32_t sharedFd, pid_t &renderPid) override; - - virtual void AttachRenderProcess(const sptr &shceduler) override; - private: /** * Init, Initialize application services. diff --git a/services/appmgr/include/app_mgr_service_inner.h b/services/appmgr/include/app_mgr_service_inner.h index d498c3b1a2345a89a1869060089221e9c22487ea..646b7562b715a2fab46c19cde58a04f6e9baa977 100644 --- a/services/appmgr/include/app_mgr_service_inner.h +++ b/services/appmgr/include/app_mgr_service_inner.h @@ -121,6 +121,13 @@ public: */ virtual void RegisterAppStateCallback(const sptr &callback); + /** + * StopAllProcess, Terminate all processes. + * + * @return + */ + virtual void StopAllProcess(); + /** * AbilityBehaviorAnalysis, ability behavior analysis assistant process optimization. * @@ -235,6 +242,16 @@ public: */ virtual void ClearUpApplicationData(const std::string &bundleName, const int32_t callerUid, const pid_t callerPid); + /** + * IsBackgroundRunningRestricted, Checks whether the process of this application is forbidden + * to run in the background. + * + * @param bundleName, bundle name in Application record. + * + * @return ERR_OK, return back success, others fail. + */ + virtual int32_t IsBackgroundRunningRestricted(const std::string &bundleName); + /** * GetAllRunningProcesses, Obtains information about application processes that are running on the device. * @@ -391,10 +408,9 @@ public: * OnRemoteDied, Equipment death notification. * * @param remote, Death client. - * @param isRenderProcess is render process died. * @return */ - void OnRemoteDied(const wptr &remote, bool isRenderProcess = false); + void OnRemoteDied(const wptr &remote); /** * AddAppDeathRecipient, Add monitoring death application record. @@ -435,6 +451,23 @@ public: virtual void OptimizerAppStateChanged( const std::shared_ptr &appRecord, const ApplicationState state); + /** + * SetAppSuspendTimes, Setting the Freezing Time of APP Background. + * + * @param time, The timeout(second) recorded when the application enters the background . + * + * @return Success or Failure . + */ + void SetAppFreezingTime(int time); + + /** + * GetAppFreezingTime, Getting the Freezing Time of APP Background. + * + * @param time, The timeout(second) recorded when the application enters the background . + * + * @return Success or Failure . + */ + void GetAppFreezingTime(int &time); void HandleTimeOut(const InnerEvent::Pointer &event); void SetEventHandler(const std::shared_ptr &handler); @@ -528,11 +561,6 @@ public: */ int GetAbilityRecordsByProcessID(const int pid, std::vector> &tokens); - virtual int32_t StartRenderProcess(const pid_t hostPid, const std::string &renderParam, - int32_t ipcFd, int32_t sharedFd, pid_t &renderPid); - - virtual void AttachRenderProcess(const pid_t pid, const sptr &scheduler); - private: void StartEmptyResidentProcess(const BundleInfo &info, const std::string &processName, int restartCount); @@ -757,13 +785,6 @@ private: void GetGlobalConfiguration(); - void GetRunningProcesses(const std::shared_ptr &appRecord, std::vector &info); - - int StartRenderProcessImpl(const std::shared_ptr &renderRecord, - const std::shared_ptr appRecord, pid_t &renderPid); - - void OnRenderRemoteDied(const wptr &remote); - private: /** * ClearUpApplicationData, clear the application data. @@ -778,12 +799,6 @@ private: void ClearUpApplicationDataByUserId(const std::string &bundleName, int32_t callerUid, pid_t callerPid, const int userId); - int VerifyProcessPermission(); - - int VerifyAccountPermission(const std::string &permissionName, const int userId); - - int VerifyObserverPermission(); - private: /** * Notify application status. diff --git a/services/appmgr/include/app_running_manager.h b/services/appmgr/include/app_running_manager.h index 480fb095df42bb9d8c71075c3847e87bb95b54de..8d38a1c0b23f1da23b2f05c7aac9468f451f85f4 100644 --- a/services/appmgr/include/app_running_manager.h +++ b/services/appmgr/include/app_running_manager.h @@ -148,8 +148,6 @@ public: void ClipStringContent(const std::regex &re, const std::string &sorce, std::string &afferCutStr); void HandleAddAbilityStageTimeOut(const int64_t eventId); void HandleStartSpecifiedAbilityTimeOut(const int64_t eventId); - std::shared_ptr GetAppRunningRecordByRenderPid(const pid_t pid); - void OnRemoteRenderDied(const wptr &remote); private: std::shared_ptr GetAbilityRunningRecord(const int64_t eventId); diff --git a/services/appmgr/include/app_running_record.h b/services/appmgr/include/app_running_record.h index 759010ff9bfaf8e808acac8a8f7799cc856b61dc..3eadad2e2da40477dbc545818c83e0e5800e7293 100644 --- a/services/appmgr/include/app_running_record.h +++ b/services/appmgr/include/app_running_record.h @@ -21,7 +21,6 @@ #include #include #include "iremote_object.h" -#include "irender_scheduler.h" #include "ability_running_record.h" #include "ability_state_data.h" #include "application_info.h" @@ -34,7 +33,6 @@ #include "priority_object.h" #include "app_lifecycle_deal.h" #include "module_running_record.h" -#include "app_spawn_msg_wrapper.h" namespace OHOS { namespace AppExecFwk { @@ -43,45 +41,6 @@ const int RESTART_RESIDENT_PROCESS_MAX_TIMES = 15; } class AbilityRunningRecord; class AppMgrServiceInner; -class AppRunningRecord; - -/** - * @class RenderRecord - * Record webview render process info. - */ -class RenderRecord { -public: - RenderRecord(pid_t hostPid, const std::string& renderParam, - int32_t ipcFd, int32_t sharedFd, const std::shared_ptr &host); - - virtual ~RenderRecord(); - - static std::shared_ptr CreateRenderRecord(pid_t hostPid, const std::string& renderParam, - int32_t ipcFd, int32_t sharedFd, const std::shared_ptr &host); - - void SetPid(pid_t pid); - pid_t GetPid(); - pid_t GetHostPid(); - std::string GetRenderParam(); - int32_t GetIpcFd(); - int32_t GetSharedFd(); - std::shared_ptr GetHostRecord(); - sptr GetScheduler(); - void SetScheduler(const sptr &scheduler); - void SetDeathRecipient(const sptr recipient); - void RegisterDeathRecipient(); - -private: - pid_t pid_ = 0; - pid_t hostPid_ = 0; - std::string renderParam_; - int32_t ipcFd_ = 0; - int32_t sharedFd_ = 0; - std::weak_ptr host_; // webview host - sptr renderScheduler_; - sptr deathRecipient_ = nullptr; -}; - class AppRunningRecord : public std::enable_shared_from_this { public: static int64_t appEventId_; @@ -486,11 +445,6 @@ public: void ScheduleAcceptWantDone(); const AAFwk::Want &GetSpecifiedWant() const; - void SetRenderRecord(const std::shared_ptr &record); - std::shared_ptr GetRenderRecord(); - void SetStartMsg(const AppSpawnStartMsg &msg); - AppSpawnStartMsg GetStartMsg(); - private: /** * SearchTheModuleInfoNeedToUpdated, Get an uninitialized abilitystage data. @@ -569,10 +523,6 @@ private: std::string moduleName_; UserTestRecord userTestRecord_; - - // render record - std::shared_ptr renderRecord_ = nullptr; - AppSpawnStartMsg startMsg_; }; } // namespace AppExecFwk } // namespace OHOS diff --git a/services/appmgr/include/app_spawn_client.h b/services/appmgr/include/app_spawn_client.h index 96c6cbdba27046306c8b9d65858fd98828835268..862e80345572bd60bf1a0838b9bd4063119a2a53 100644 --- a/services/appmgr/include/app_spawn_client.h +++ b/services/appmgr/include/app_spawn_client.h @@ -29,7 +29,7 @@ public: /** * Constructor. */ - explicit AppSpawnClient(bool isWebViewSpawn = false); + AppSpawnClient(); /** * Destructor diff --git a/services/appmgr/include/app_spawn_msg_wrapper.h b/services/appmgr/include/app_spawn_msg_wrapper.h index acbaeef24d978795a6759501dd11ec1abb369d93..5415b6385be33acbacc76abaffed44ad3de1503a 100644 --- a/services/appmgr/include/app_spawn_msg_wrapper.h +++ b/services/appmgr/include/app_spawn_msg_wrapper.h @@ -34,7 +34,6 @@ struct AppSpawnStartMsg { uint32_t accessTokenId; std::string apl; std::string bundleName; - std::string renderParam; // only webview spawn need this param. }; using AppSpawnMsg = AppSpawn::ClientSocket::AppProperty; diff --git a/services/appmgr/include/app_spawn_socket.h b/services/appmgr/include/app_spawn_socket.h index a4c60afa08f60296bf7d822b69cfcf17c07a9930..ef133c455abd192461b499a405cbd054df8b95fa 100644 --- a/services/appmgr/include/app_spawn_socket.h +++ b/services/appmgr/include/app_spawn_socket.h @@ -29,7 +29,7 @@ public: /** * Constructor. */ - explicit AppSpawnSocket(bool isWebViewSpawn = false); + AppSpawnSocket(); /** * Destructor diff --git a/services/appmgr/include/process_optimizer.h b/services/appmgr/include/process_optimizer.h index 6e336b5b17acf81df68f7e1aec65708babfe5095..10b4028bcff4cc9ac3228b8d814f66f98fcc183d 100644 --- a/services/appmgr/include/process_optimizer.h +++ b/services/appmgr/include/process_optimizer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -66,6 +66,8 @@ public: virtual void OnAbilityVisibleChanged(const AbilityPtr &ability); virtual void OnAbilityPerceptibleChanged(const AbilityPtr &ability); virtual void OnAbilityRemoved(const AbilityPtr &ability); + virtual void SetAppFreezingTime(int time); + virtual void GetAppFreezingTime(int &time); protected: bool SetAppOomAdj(const AppPtr &app, int oomAdj); diff --git a/services/appmgr/include/process_optimizer_uba.h b/services/appmgr/include/process_optimizer_uba.h index 6d34c93c99f0b5cd49cd3f3fc5b40982988afa8a..89c0440afd1ef1ec8e6eeaa633fa76c2e438cbca 100644 --- a/services/appmgr/include/process_optimizer_uba.h +++ b/services/appmgr/include/process_optimizer_uba.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -55,6 +55,8 @@ public: void OnAbilityVisibleChanged(const AbilityPtr &ability) override; void OnAbilityPerceptibleChanged(const AbilityPtr &ability) override; void OnAbilityRemoved(const AbilityPtr &ability) override; + void SetAppFreezingTime(int time) override; + void GetAppFreezingTime(int &time) override; protected: void OnLowMemoryAlert(const CgroupManager::LowMemoryLevel level) override; diff --git a/services/appmgr/include/remote_client_manager.h b/services/appmgr/include/remote_client_manager.h index 1ab9ff8344523f64eab755a8784019f4512366d1..35656ea55639e172bd943573e30a873e93afac95 100644 --- a/services/appmgr/include/remote_client_manager.h +++ b/services/appmgr/include/remote_client_manager.h @@ -57,12 +57,9 @@ public: */ void SetBundleManager(sptr bundleManager); - std::shared_ptr GetWebviewSpawnClient(); - private: std::shared_ptr appSpawnClient_; sptr bundleManager_; - std::shared_ptr webviewSpawnClient_; }; } // namespace AppExecFwk } // namespace OHOS diff --git a/services/appmgr/src/ams_mgr_scheduler.cpp b/services/appmgr/src/ams_mgr_scheduler.cpp index 44a9928623f2c4eebd364f6ec91abe691e8d5eab..5a91e41d3702b09c9e843f0df04b2324a66dd404 100644 --- a/services/appmgr/src/ams_mgr_scheduler.cpp +++ b/services/appmgr/src/ams_mgr_scheduler.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -110,6 +110,15 @@ void AmsMgrScheduler::RegisterAppStateCallback(const sptr &ca amsHandler_->PostTask(registerAppStateCallbackFunc, TASK_REGISTER_APP_STATE_CALLBACK); } +void AmsMgrScheduler::Reset() +{ + if (!IsReady()) { + return; + } + std::function resetFunc = std::bind(&AppMgrServiceInner::StopAllProcess, amsMgrServiceInner_); + amsHandler_->PostTask(resetFunc, TASK_STOP_ALL_PROCESS); +} + void AmsMgrScheduler::AbilityBehaviorAnalysis(const sptr &token, const sptr &preToken, const int32_t visibility, const int32_t perceptibility, const int32_t connectionState) { diff --git a/services/appmgr/src/app_death_recipient.cpp b/services/appmgr/src/app_death_recipient.cpp index 6ccba58de7f011804bdb2f9fb1a8ec7b93c74372..9c841c0310a1b08c55678815b701ebe69a1185d9 100644 --- a/services/appmgr/src/app_death_recipient.cpp +++ b/services/appmgr/src/app_death_recipient.cpp @@ -42,7 +42,7 @@ void AppDeathRecipient::OnRemoteDied(const wptr &remote) return; } - auto onRemoteDiedFunc = std::bind(&AppMgrServiceInner::OnRemoteDied, serviceInner, remote, isRenderProcess_); + std::function onRemoteDiedFunc = std::bind(&AppMgrServiceInner::OnRemoteDied, serviceInner, remote); handler->PostTask(onRemoteDiedFunc, TASK_ON_REMOTE_DIED); } @@ -55,10 +55,5 @@ void AppDeathRecipient::SetAppMgrServiceInner(const std::shared_ptrIsBackgroundRunningRestricted(bundleName); +} + int32_t AppMgrService::GetAllRunningProcesses(std::vector &info) { if (!IsReady()) { @@ -285,6 +292,24 @@ int32_t AppMgrService::GetProcessRunningInfosByUserId(std::vectorGetProcessRunningInfosByUserId(info, userId); } +void AppMgrService::SetAppFreezingTime(int time) +{ + APP_LOGI("set app freeze time %{public}d", time); + if (!IsReady()) { + return; + } + appMgrServiceInner_->SetAppFreezingTime(time); +} + +void AppMgrService::GetAppFreezingTime(int &time) +{ + if (!IsReady()) { + return; + } + appMgrServiceInner_->GetAppFreezingTime(time); + APP_LOGE("get app freeze time %{public}d ", time); +} + /** * Get system memory information. * @param SystemMemoryAttr, memory information. @@ -382,31 +407,5 @@ int AppMgrService::GetAbilityRecordsByProcessID(const int pid, std::vectorGetAbilityRecordsByProcessID(pid, tokens); } - -int32_t AppMgrService::StartRenderProcess(const std::string &renderParam, int32_t ipcFd, - int32_t sharedFd, pid_t &renderPid) -{ - if (!IsReady()) { - APP_LOGE("StartRenderProcess failed, AppMgrService not ready."); - return ERR_INVALID_OPERATION; - } - - return appMgrServiceInner_->StartRenderProcess(IPCSkeleton::GetCallingPid(), - renderParam, ipcFd, sharedFd, renderPid); -} - -void AppMgrService::AttachRenderProcess(const sptr &scheduler) -{ - APP_LOGD("AttachRenderProcess called."); - if (!IsReady()) { - APP_LOGE("AttachRenderProcess failed, not ready."); - return; - } - - auto pid = IPCSkeleton::GetCallingPid(); - auto fun = std::bind(&AppMgrServiceInner::AttachRenderProcess, - appMgrServiceInner_, pid, iface_cast(scheduler)); - handler_->PostTask(fun, TASK_ATTACH_RENDER_PROCESS); -} } // namespace AppExecFwk } // namespace OHOS diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index 61b4b47c902f4a072c19ea2aa75e9578ffc1baf0..00efa107c1037ac405ccc01369de190a0c06ebbc 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -18,7 +18,6 @@ #include #include #include -#include #include "app_log_wrapper.h" #include "application_state_observer_stub.h" @@ -36,8 +35,6 @@ #include "ipc_skeleton.h" #include "os_account_manager.h" #include "permission/permission_kit.h" -#include "permission_constants.h" -#include "permission_verification.h" #include "system_ability_definition.h" #include "locale_config.h" #include "uri_permission_manager_client.h" @@ -58,7 +55,6 @@ constexpr int KILL_PROCESS_DELAYTIME_MICRO_SECONDS = 200; const std::string CLASS_NAME = "ohos.app.MainThread"; const std::string FUNC_NAME = "main"; const std::string SO_PATH = "system/lib64/libmapleappkit.z.so"; -const std::string RENDER_PARAM = "invalidparam"; const int32_t SIGNAL_KILL = 9; const std::string REQ_PERMISSION = "ohos.permission.LOCATION_IN_BACKGROUND"; constexpr int32_t SYSTEM_UID = 1000; @@ -67,9 +63,6 @@ constexpr int32_t USER_SCALE = 200000; constexpr int32_t BASE_USER_RANGE = 200000; -constexpr ErrCode APPMGR_ERR_OFFSET = ErrCodeOffset(SUBSYS_APPEXECFWK, 0x01); -constexpr ErrCode ERR_ALREADY_EXIST_RENDER = APPMGR_ERR_OFFSET + 100; // error code for already exist render. - int32_t GetUserIdByUid(int32_t uid) { return uid / BASE_USER_RANGE; @@ -365,11 +358,6 @@ int32_t AppMgrServiceInner::KillApplication(const std::string &bundleName) return ERR_NO_INIT; } - if (VerifyProcessPermission() == ERR_PERMISSION_DENIED) { - APP_LOGE("%{public}s: Permission verification failed", __func__); - return ERR_PERMISSION_DENIED; - } - int result = ERR_OK; int64_t startTime = SystemTimeMillis(); std::list pids; @@ -400,12 +388,6 @@ int32_t AppMgrServiceInner::KillApplicationByUid(const std::string &bundleName, APP_LOGE("appRunningManager_ is nullptr"); return ERR_NO_INIT; } - - if (VerifyProcessPermission() == ERR_PERMISSION_DENIED) { - APP_LOGE("%{public}s: Permission verification failed", __func__); - return ERR_PERMISSION_DENIED; - } - int result = ERR_OK; int64_t startTime = SystemTimeMillis(); std::list pids; @@ -443,13 +425,6 @@ int32_t AppMgrServiceInner::KillApplicationByUserId(const std::string &bundleNam APP_LOGE("appRunningManager_ is nullptr"); return ERR_NO_INIT; } - - if (VerifyAccountPermission(AAFwk::PermissionConstants::PERMISSION_CLEAN_BACKGROUND_PROCESSES, userId) == - ERR_PERMISSION_DENIED) { - APP_LOGE("%{public}s: Permission verification failed", __func__); - return ERR_PERMISSION_DENIED; - } - int result = ERR_OK; int64_t startTime = SystemTimeMillis(); std::list pids; @@ -493,16 +468,6 @@ int32_t AppMgrServiceInner::KillApplicationByUserId(const std::string &bundleNam void AppMgrServiceInner::ClearUpApplicationData(const std::string &bundleName, int32_t callerUid, pid_t callerPid) { BYTRACE_NAME(BYTRACE_TAG_APP, __PRETTY_FUNCTION__); - auto isSaCall = AAFwk::PermissionVerification::GetInstance()->IsSACall(); - if (!isSaCall) { - auto isCallingPerm = AAFwk::PermissionVerification::GetInstance()->VerifyCallingPermission( - AAFwk::PermissionConstants::PERMISSION_CLEAN_APPLICATION_DATA); - if (!isCallingPerm) { - APP_LOGE("%{public}s: Permission verification failed", __func__); - return; - } - } - auto userId = GetUserIdByUid(callerUid); APP_LOGI("userId:%{public}d", userId); ClearUpApplicationDataByUserId(bundleName, callerUid, callerPid, userId); @@ -547,30 +512,41 @@ void AppMgrServiceInner::ClearUpApplicationDataByUserId( NotifyAppStatus(bundleName, EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_DATA_CLEARED); } -int32_t AppMgrServiceInner::GetAllRunningProcesses(std::vector &info) +int32_t AppMgrServiceInner::IsBackgroundRunningRestricted(const std::string &bundleName) { - auto isPerm = AAFwk::PermissionVerification::GetInstance()->VerifyRunningInfoPerm(); + auto bundleMgr_ = remoteClientManager_->GetBundleManager(); + if (bundleMgr_ == nullptr) { + APP_LOGE("GetBundleManager fail"); + return ERR_DEAD_OBJECT; + } + return bundleMgr_->CheckPermission(bundleName, REQ_PERMISSION); +} +int32_t AppMgrServiceInner::GetAllRunningProcesses(std::vector &info) +{ + auto bundleMgr_ = remoteClientManager_->GetBundleManager(); + if (bundleMgr_ == nullptr) { + APP_LOGE("GetBundleManager fail"); + return ERR_DEAD_OBJECT; + } // check permission for (const auto &item : appRunningManager_->GetAppRunningRecordMap()) { const auto &appRecord = item.second; + if (USER_SCALE == 0) { + APP_LOGE("USER_SCALE is not zero"); + return ERR_WOULD_BLOCK; + } int32_t userId = static_cast(appRecord->GetUid() / USER_SCALE); bool isExist = false; auto errCode = AccountSA::OsAccountManager::IsOsAccountActived(userId, isExist); if ((errCode == ERR_OK) && isExist) { - if (isPerm) { - GetRunningProcesses(appRecord, info); - } else { - auto applicationInfo = appRecord->GetApplicationInfo(); - if (!applicationInfo) { - continue; - } - auto callingTokenId = IPCSkeleton::GetCallingTokenID(); - auto tokenId = applicationInfo->accessTokenId; - if (callingTokenId == tokenId) { - GetRunningProcesses(appRecord, info); - } - } + RunningProcessInfo runningProcessInfo; + runningProcessInfo.processName_ = appRecord->GetProcessName(); + runningProcessInfo.pid_ = appRecord->GetPriorityObject()->GetPid(); + runningProcessInfo.uid_ = appRecord->GetUid(); + runningProcessInfo.state_ = static_cast(appRecord->GetState()); + appRecord->GetBundleNames(runningProcessInfo.bundleNames); + info.emplace_back(runningProcessInfo); } } return ERR_OK; @@ -578,34 +554,32 @@ int32_t AppMgrServiceInner::GetAllRunningProcesses(std::vector &info, int32_t userId) { - if (VerifyAccountPermission(AAFwk::PermissionConstants::PERMISSION_GET_RUNNING_INFO, userId) == - ERR_PERMISSION_DENIED) { - APP_LOGE("%{public}s: Permission verification failed", __func__); - return ERR_PERMISSION_DENIED; + auto bundleMgr_ = remoteClientManager_->GetBundleManager(); + if (bundleMgr_ == nullptr) { + APP_LOGE("GetBundleManager fail"); + return ERR_DEAD_OBJECT; } for (const auto &item : appRunningManager_->GetAppRunningRecordMap()) { const auto &appRecord = item.second; + if (USER_SCALE == 0) { + APP_LOGE("USER_SCALE is not zero"); + return ERR_WOULD_BLOCK; + } int32_t userIdTemp = static_cast(appRecord->GetUid() / USER_SCALE); if (userIdTemp == userId) { - GetRunningProcesses(appRecord, info); + RunningProcessInfo runningProcessInfo; + runningProcessInfo.processName_ = appRecord->GetProcessName(); + runningProcessInfo.pid_ = appRecord->GetPriorityObject()->GetPid(); + runningProcessInfo.uid_ = appRecord->GetUid(); + runningProcessInfo.state_ = static_cast(appRecord->GetState()); + appRecord->GetBundleNames(runningProcessInfo.bundleNames); + info.emplace_back(runningProcessInfo); } } return ERR_OK; } -void AppMgrServiceInner::GetRunningProcesses(const std::shared_ptr &appRecord, - std::vector &info) -{ - RunningProcessInfo runningProcessInfo; - runningProcessInfo.processName_ = appRecord->GetProcessName(); - runningProcessInfo.pid_ = appRecord->GetPriorityObject()->GetPid(); - runningProcessInfo.uid_ = appRecord->GetUid(); - runningProcessInfo.state_ = static_cast(appRecord->GetState()); - appRecord->GetBundleNames(runningProcessInfo.bundleNames); - info.emplace_back(runningProcessInfo); -} - int32_t AppMgrServiceInner::KillProcessByPid(const pid_t pid) const { int32_t ret = -1; @@ -847,18 +821,19 @@ void AppMgrServiceInner::SetBundleManager(sptr bundleManager) void AppMgrServiceInner::RegisterAppStateCallback(const sptr &callback) { - pid_t callingPid = IPCSkeleton::GetCallingPid(); - pid_t pid = getpid(); - if (callingPid != pid) { - APP_LOGE("%{public}s: Not abilityMgr call.", __func__); - return; - } BYTRACE_NAME(BYTRACE_TAG_APP, __PRETTY_FUNCTION__); if (callback != nullptr) { appStateCallbacks_.push_back(callback); } } +void AppMgrServiceInner::StopAllProcess() +{ + BYTRACE_NAME(BYTRACE_TAG_APP, __PRETTY_FUNCTION__); + ClearRecentAppList(); + appRunningManager_->ClearAppRunningRecordMap(); +} + void AppMgrServiceInner::AbilityBehaviorAnalysis(const sptr &token, const sptr &preToken, const int32_t visibility, // 0:false,1:true const int32_t perceptibility, // 0:false,1:true @@ -911,11 +886,6 @@ void AppMgrServiceInner::KillProcessByAbilityToken(const sptr &to return; } - if (VerifyProcessPermission() == ERR_PERMISSION_DENIED) { - APP_LOGE("%{public}s: Permission verification failed", __func__); - return; - } - // befor exec ScheduleProcessSecurityExit return // The resident process won't let him die if (appRecord->IsKeepAliveApp()) { @@ -944,12 +914,6 @@ void AppMgrServiceInner::KillProcessesByUserId(int32_t userId) return; } - if (VerifyAccountPermission(AAFwk::PermissionConstants::PERMISSION_CLEAN_BACKGROUND_PROCESSES, userId) == - ERR_PERMISSION_DENIED) { - APP_LOGE("%{public}s: Permission verification failed", __func__); - return; - } - int64_t startTime = SystemTimeMillis(); std::list pids; if (!appRunningManager_->GetPidsByUserId(userId, pids)) { @@ -1319,7 +1283,6 @@ void AppMgrServiceInner::StartProcess(const std::string &appName, const std::str startMsg.accessTokenId = (*bundleInfoIter).applicationInfo.accessTokenId; startMsg.apl = (*bundleInfoIter).applicationInfo.appPrivilegeLevel; startMsg.bundleName = bundleName; - startMsg.renderParam = RENDER_PARAM; APP_LOGD("StartProcess come, accessTokenId: %{public}d, apl: %{public}s, bundleName: %{public}s", startMsg.accessTokenId, startMsg.apl.c_str(), bundleName.c_str()); @@ -1342,7 +1305,6 @@ void AppMgrServiceInner::StartProcess(const std::string &appName, const std::str APP_LOGI("newPid:%{public}d uid:%{public}d", pid, startMsg.uid); appRecord->GetPriorityObject()->SetPid(pid); appRecord->SetUid(startMsg.uid); - appRecord->SetStartMsg(startMsg); OptimizerAppStateChanged(appRecord, ApplicationState::APP_STATE_CREATE); appRecord->SetAppMgrServiceInner(weak_from_this()); OnAppStateChanged(appRecord, ApplicationState::APP_STATE_CREATE); @@ -1411,14 +1373,9 @@ void AppMgrServiceInner::ClearRecentAppList() appProcessManager_->ClearRecentAppList(); } -void AppMgrServiceInner::OnRemoteDied(const wptr &remote, bool isRenderProcess) +void AppMgrServiceInner::OnRemoteDied(const wptr &remote) { APP_LOGE("On remote died."); - if (isRenderProcess) { - OnRenderRemoteDied(remote); - return; - } - auto appRecord = appRunningManager_->OnRemoteDied(remote); if (appRecord) { // clear uri permission @@ -1437,13 +1394,6 @@ void AppMgrServiceInner::OnRemoteDied(const wptr &remote, bool is OptimizerAppStateChanged(appRecord, ApplicationState::APP_STATE_TERMINATED); RemoveAppFromRecentListById(appRecord->GetRecordId()); OnProcessDied(appRecord); - - // kill render if exist. - auto renderRecord = appRecord->GetRenderRecord(); - if (renderRecord && renderRecord->GetPid() > 0) { - APP_LOGD("Kill render process when webviehost died."); - KillProcessByPid(renderRecord->GetPid()); - } } if (appRecord && appRecord->IsKeepAliveApp()) { @@ -1590,6 +1540,27 @@ void AppMgrServiceInner::OptimizerAppStateChanged( } } +void AppMgrServiceInner::SetAppFreezingTime(int time) +{ + if (!processOptimizerUBA_) { + APP_LOGE("process optimizer is not init"); + return; + } + + std::lock_guard setFreezeTimeLock(serviceLock_); + processOptimizerUBA_->SetAppFreezingTime(time); +} + +void AppMgrServiceInner::GetAppFreezingTime(int &time) +{ + if (!processOptimizerUBA_) { + APP_LOGE("process optimizer is not init"); + return; + } + std::lock_guard getFreezeTimeLock(serviceLock_); + processOptimizerUBA_->GetAppFreezingTime(time); +} + void AppMgrServiceInner::HandleTimeOut(const InnerEvent::Pointer &event) { APP_LOGI("handle time out"); @@ -1753,26 +1724,12 @@ void AppMgrServiceInner::GetRunningProcessInfoByToken( APP_LOGE("appRunningManager_ is nullptr"); return; } - - auto isPerm = AAFwk::PermissionVerification::GetInstance()->VerifyRunningInfoPerm(); - if (!isPerm) { - APP_LOGE("%{public}s: Permission verification failed", __func__); - return; - } - appRunningManager_->GetRunningProcessInfoByToken(token, info); } void AppMgrServiceInner::LoadResidentProcess() { APP_LOGI("%{public}s called", __func__); - pid_t callingPid = IPCSkeleton::GetCallingPid(); - pid_t pid = getpid(); - if (callingPid != pid) { - APP_LOGE("%{public}s: Not SA call.", __func__); - return; - } - if (!CheckRemoteClient()) { APP_LOGE("GetBundleManager fail"); return; @@ -1929,10 +1886,6 @@ void AppMgrServiceInner::NotifyAppStatus(const std::string &bundleName, const st int32_t AppMgrServiceInner::RegisterApplicationStateObserver(const sptr &observer) { APP_LOGI("%{public}s begin", __func__); - if (VerifyObserverPermission() == ERR_PERMISSION_DENIED) { - APP_LOGE("%{public}s: Permission verification failed", __func__); - return ERR_PERMISSION_DENIED; - } std::lock_guard lockRegister(observerLock_); if (observer == nullptr) { APP_LOGE("Observer nullptr"); @@ -1951,10 +1904,6 @@ int32_t AppMgrServiceInner::RegisterApplicationStateObserver(const sptr &observer) { APP_LOGI("%{public}s begin", __func__); - if (VerifyObserverPermission() == ERR_PERMISSION_DENIED) { - APP_LOGE("%{public}s: Permission verification failed", __func__); - return ERR_PERMISSION_DENIED; - } std::lock_guard lockUnregister(observerLock_); if (observer == nullptr) { APP_LOGE("Observer nullptr"); @@ -2049,12 +1998,6 @@ void AppMgrServiceInner::HandleObserverDiedTask(const sptr &obser int32_t AppMgrServiceInner::GetForegroundApplications(std::vector &list) { APP_LOGI("%{public}s, begin.", __func__); - auto isPerm = AAFwk::PermissionVerification::GetInstance()->VerifyRunningInfoPerm(); - if (!isPerm) { - APP_LOGE("%{public}s: Permission verification failed", __func__); - return ERR_PERMISSION_DENIED; - } - appRunningManager_->GetForegroundApplications(list); return ERR_OK; } @@ -2185,13 +2128,6 @@ void AppMgrServiceInner::RegisterStartSpecifiedAbilityResponse(const sptrIsSACall(); - if (!isSaCall) { - auto isCallingPerm = AAFwk::PermissionVerification::GetInstance()->VerifyCallingPermission( - AAFwk::PermissionConstants::PERMISSION_UPDATE_CONFIGURATION); - if (!isCallingPerm) { - APP_LOGE("%{public}s: Permission verification failed", __func__); - return; - } - } - if (!appRunningManager_) { APP_LOGE("appRunningManager_ is null"); return; @@ -2274,181 +2200,8 @@ int AppMgrServiceInner::GetAbilityRecordsByProcessID(const int pid, std::vector< for (auto &item : appRecord->GetAbilities()) { tokens.emplace_back(item.first); } - return ERR_OK; -} - -int AppMgrServiceInner::VerifyProcessPermission() -{ - auto isSaCall = AAFwk::PermissionVerification::GetInstance()->IsSACall(); - if (isSaCall) { - return ERR_OK; - } - auto isCallingPerm = AAFwk::PermissionVerification::GetInstance()->VerifyCallingPermission( - AAFwk::PermissionConstants::PERMISSION_CLEAN_BACKGROUND_PROCESSES); - if (isCallingPerm) { - APP_LOGE("%{public}s: Permission verification succeeded", __func__); - return ERR_OK; - } - APP_LOGE("%{public}s: Permission verification failed", __func__); - return ERR_PERMISSION_DENIED; -} - -int AppMgrServiceInner::VerifyAccountPermission(const std::string &permissionName, const int userId) -{ - auto isSaCall = AAFwk::PermissionVerification::GetInstance()->IsSACall(); - if (isSaCall) { - return ERR_OK; - } - const int currentUserId = getuid() / Constants::BASE_USER_RANGE; - if (userId != currentUserId) { - auto isCallingPermAccount = AAFwk::PermissionVerification::GetInstance()->VerifyCallingPermission( - AAFwk::PermissionConstants::PERMISSION_INTERACT_ACROSS_LOCAL_ACCOUNTS); - if (!isCallingPermAccount) { - APP_LOGE("%{public}s: Permission accounts verification failed", __func__); - return ERR_PERMISSION_DENIED; - } - } - auto isCallingPerm = AAFwk::PermissionVerification::GetInstance()->VerifyCallingPermission(permissionName); - if (isCallingPerm) { - APP_LOGD("%{public}s: Permission verification succeeded", __func__); - return ERR_OK; - } - APP_LOGE("%{public}s: Permission verification failed", __func__); - return ERR_PERMISSION_DENIED; -} - -int AppMgrServiceInner::VerifyObserverPermission() -{ - auto isSaCall = AAFwk::PermissionVerification::GetInstance()->IsSACall(); - if (isSaCall) { - return ERR_OK; - } - auto isCallingPerm = AAFwk::PermissionVerification::GetInstance()->VerifyCallingPermission( - AAFwk::PermissionConstants::PERMISSION_RUNNING_STATE_OBSERVER); - if (isCallingPerm) { - APP_LOGE("%{public}s: Permission verification succeeded", __func__); - return ERR_OK; - } - APP_LOGE("%{public}s: Permission verification failed", __func__); - return ERR_PERMISSION_DENIED; -} - -int AppMgrServiceInner::StartRenderProcess(const pid_t hostPid, const std::string &renderParam, - int32_t ipcFd, int32_t sharedFd, pid_t &renderPid) -{ - APP_LOGI("start render process, webview hostpid:%{public}d", hostPid); - if (hostPid <= 0 || renderParam.empty() || ipcFd <= 0 || sharedFd <= 0) { - APP_LOGE("invalid param, hostPid:%{public}d, renderParam:%{public}s, ipcFd:%{public}d, sharedFd:%{public}d", - hostPid, renderParam.c_str(), ipcFd, sharedFd); - return ERR_INVALID_VALUE; - } - - if (!appRunningManager_) { - APP_LOGE("appRunningManager_ is , not start render process"); - return ERR_INVALID_VALUE; - } - - auto appRecord = GetAppRunningRecordByPid(hostPid); - if (!appRecord) { - APP_LOGE("no such appRecord, hostpid:%{public}d", hostPid); - return ERR_INVALID_VALUE; - } - - auto renderRecord = appRecord->GetRenderRecord(); - if (renderRecord) { - APP_LOGW("already exit render process,do not request again, renderPid:%{public}d", renderRecord->GetPid()); - renderPid = renderRecord->GetPid(); - return ERR_ALREADY_EXIST_RENDER; - } - - renderRecord = RenderRecord::CreateRenderRecord(hostPid, renderParam, ipcFd, sharedFd, appRecord); - if (!renderRecord) { - APP_LOGE("create render record failed, hostpid:%{public}d", hostPid); - return ERR_INVALID_VALUE; - } - - return StartRenderProcessImpl(renderRecord, appRecord, renderPid); -} - -void AppMgrServiceInner::AttachRenderProcess(const pid_t pid, const sptr &scheduler) -{ - APP_LOGD("attach render process start"); - if (pid <= 0) { - APP_LOGE("invalid render process pid:%{public}d", pid); - return; - } - if (!scheduler) { - APP_LOGE("render scheduler is null"); - return; - } - - if (!appRunningManager_) { - APP_LOGE("appRunningManager_ is null"); - return; - } - - APP_LOGI("attach render process pid:%{public}d", pid); - auto appRecord = appRunningManager_->GetAppRunningRecordByRenderPid(pid); - if (!appRecord) { - APP_LOGE("no such app Record, pid:%{public}d", pid); - return; - } - - auto renderRecord = appRecord->GetRenderRecord(); - if (!renderRecord) { - APP_LOGE("no such render Record, pid:%{public}d", pid); - return; - } - - sptr appDeathRecipient = new AppDeathRecipient(); - appDeathRecipient->SetEventHandler(eventHandler_); - appDeathRecipient->SetAppMgrServiceInner(shared_from_this()); - appDeathRecipient->SetIsRenderProcess(true); - renderRecord->SetScheduler(scheduler); - renderRecord->SetDeathRecipient(appDeathRecipient); - renderRecord->RegisterDeathRecipient(); - - // notify fd to render process - scheduler->NotifyBrowserFd(renderRecord->GetIpcFd(), renderRecord->GetSharedFd()); -} - -int AppMgrServiceInner::StartRenderProcessImpl(const std::shared_ptr &renderRecord, - const std::shared_ptr appRecord, pid_t &renderPid) -{ - if (!renderRecord || !appRecord) { - APP_LOGE("renderRecord or appRecord is nullptr."); - return ERR_INVALID_VALUE; - } - - auto webviewSpawnClient = remoteClientManager_->GetWebviewSpawnClient(); - if (!webviewSpawnClient) { - APP_LOGE("webviewSpawnClient is null"); - return ERR_INVALID_VALUE; - } - - AppSpawnStartMsg startMsg = appRecord->GetStartMsg(); - startMsg.renderParam = renderRecord->GetRenderParam(); - pid_t pid = 0; - ErrCode errCode = webviewSpawnClient->StartProcess(startMsg, pid); - if (FAILED(errCode)) { - APP_LOGE("failed to spawn new render process, errCode %{public}08x", errCode); - return ERR_INVALID_VALUE; - } - renderPid = pid; - appRecord->SetRenderRecord(renderRecord); - renderRecord->SetPid(pid); - APP_LOGI("start render process successed, hostPid:%{public}d, pid:%{public}d uid:%{public}d", - renderRecord->GetHostPid(), pid, startMsg.uid); - return 0; -} - -void AppMgrServiceInner::OnRenderRemoteDied(const wptr &remote) -{ - APP_LOGE("On render remote died."); - if (appRunningManager_) { - appRunningManager_->OnRemoteRenderDied(remote); - } + return ERR_OK; } } // namespace AppExecFwk } // namespace OHOS diff --git a/services/appmgr/src/app_running_manager.cpp b/services/appmgr/src/app_running_manager.cpp index 3b0bc1dd4cc3e08029b08bb583a6f5b5e78c6a2f..3b3c210475a04d361f5f372af89d08f1bfb37b0b 100644 --- a/services/appmgr/src/app_running_manager.cpp +++ b/services/appmgr/src/app_running_manager.cpp @@ -462,48 +462,5 @@ void AppRunningManager::UpdateConfiguration(const Configuration &config) } } } - -std::shared_ptr AppRunningManager::GetAppRunningRecordByRenderPid(const pid_t pid) -{ - std::lock_guard guard(lock_); - auto iter = std::find_if(appRunningRecordMap_.begin(), appRunningRecordMap_.end(), [&pid](const auto &pair) { - auto renderRecord = pair.second->GetRenderRecord(); - return renderRecord && renderRecord->GetPid() == pid; - }); - return ((iter == appRunningRecordMap_.end()) ? nullptr : iter->second); -} - -void AppRunningManager::OnRemoteRenderDied(const wptr &remote) -{ - std::lock_guard guard(lock_); - if (remote == nullptr) { - APP_LOGE("remote is null"); - return; - } - sptr object = remote.promote(); - if (!object) { - APP_LOGE("promote failed."); - return; - } - - const auto &it = - std::find_if(appRunningRecordMap_.begin(), appRunningRecordMap_.end(), [&object](const auto &pair) { - if (!pair.second) { - return false; - } - - auto renderRecord = pair.second->GetRenderRecord(); - if (!renderRecord) { - return false; - } - - auto scheduler = renderRecord->GetScheduler(); - return scheduler && scheduler->AsObject() == object; - }); - if (it != appRunningRecordMap_.end()) { - auto appRecord = it->second; - appRecord->SetRenderRecord(nullptr); - } -} } // namespace AppExecFwk -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/services/appmgr/src/app_running_record.cpp b/services/appmgr/src/app_running_record.cpp index fceaaec9b47925c303199407a050c3c41721238e..827235eb1c80b9b978ce4dbe3ff39d6faa0d4c4c 100644 --- a/services/appmgr/src/app_running_record.cpp +++ b/services/appmgr/src/app_running_record.cpp @@ -21,91 +21,6 @@ namespace OHOS { namespace AppExecFwk { int64_t AppRunningRecord::appEventId_ = 0; - -RenderRecord::RenderRecord(pid_t hostPid, const std::string& renderParam, - int32_t ipcFd, int32_t sharedFd, const std::shared_ptr &host) - : hostPid_(hostPid), renderParam_(renderParam), ipcFd_(ipcFd), sharedFd_(sharedFd), host_(host) -{} - -RenderRecord::~RenderRecord() -{} - -std::shared_ptr RenderRecord::CreateRenderRecord(pid_t hostPid, const std::string& renderParam, - int32_t ipcFd, int32_t sharedFd, const std::shared_ptr &host) -{ - if (hostPid <= 0 || renderParam.empty() || ipcFd <= 0 || sharedFd <= 0 || !host) { - return nullptr; - } - - auto renderRecord = std::make_shared(hostPid, renderParam, ipcFd, sharedFd, host); - if (!renderRecord) { - APP_LOGE("create render record failed, hostPid:%{public}d.", hostPid); - return nullptr; - } - - return renderRecord; -} - -void RenderRecord::SetPid(pid_t pid) -{ - pid_ = pid; -} - -pid_t RenderRecord::GetPid() -{ - return pid_; -} - -pid_t RenderRecord::GetHostPid() -{ - return hostPid_; -} - -std::string RenderRecord::GetRenderParam() -{ - return renderParam_; -} - -int32_t RenderRecord::GetIpcFd() -{ - return ipcFd_; -} - -int32_t RenderRecord::GetSharedFd() -{ - return sharedFd_; -} - -std::shared_ptr RenderRecord::GetHostRecord() -{ - return host_.lock(); -} - -sptr RenderRecord::GetScheduler() -{ - return renderScheduler_; -} - -void RenderRecord::SetScheduler(const sptr &scheduler) -{ - renderScheduler_ = scheduler; -} - -void RenderRecord::SetDeathRecipient(const sptr recipient) -{ - deathRecipient_ = recipient; -} - -void RenderRecord::RegisterDeathRecipient() -{ - if (renderScheduler_ && deathRecipient_) { - auto obj = renderScheduler_->AsObject(); - if (obj) { - obj->AddDeathRecipient(deathRecipient_); - } - } -} - AppRunningRecord::AppRunningRecord( const std::shared_ptr &info, const int32_t recordId, const std::string &processName) : appRecordId_(recordId), processName_(processName) @@ -994,25 +909,5 @@ void AppRunningRecord::UpdateConfiguration(const Configuration &config) } appLifeCycleDeal_->UpdateConfiguration(config); } - -void AppRunningRecord::SetRenderRecord(const std::shared_ptr &record) -{ - renderRecord_ = record; -} - -std::shared_ptr AppRunningRecord::GetRenderRecord() -{ - return renderRecord_; -} - -void AppRunningRecord::SetStartMsg(const AppSpawnStartMsg &msg) -{ - startMsg_ = msg; -} - -AppSpawnStartMsg AppRunningRecord::GetStartMsg() -{ - return startMsg_; -} } // namespace AppExecFwk -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/services/appmgr/src/app_spawn_client.cpp b/services/appmgr/src/app_spawn_client.cpp index 521653972ab1f251bc01164d784f51acccfd81c8..2229827afac0e8e054b1183e63dd9ab0e67671f6 100644 --- a/services/appmgr/src/app_spawn_client.cpp +++ b/services/appmgr/src/app_spawn_client.cpp @@ -25,9 +25,9 @@ const int32_t CONNECT_RETRY_DELAY = 200 * 1000; // 200ms const int32_t CONNECT_RETRY_MAX_TIMES = 15; } // namespace -AppSpawnClient::AppSpawnClient(bool isWebViewSpawn) +AppSpawnClient::AppSpawnClient() { - socket_ = std::make_shared(isWebViewSpawn); + socket_ = std::make_shared(); state_ = SpawnConnectionState::STATE_NOT_CONNECT; } diff --git a/services/appmgr/src/app_spawn_socket.cpp b/services/appmgr/src/app_spawn_socket.cpp index 4714dd47d1e402dd881e170eb0eb97cd4836d674..327b5255cee3cbc79a513c0b3027c839cc3fbb39 100644 --- a/services/appmgr/src/app_spawn_socket.cpp +++ b/services/appmgr/src/app_spawn_socket.cpp @@ -19,15 +19,11 @@ namespace OHOS { namespace AppExecFwk { -// arg "AppSpawn" or "WebViewSpawn" cannot be defined as string object since REGISTER_SYSTEM_ABILITY will +// arg "AppSpawn" cannot be defined as string object since REGISTER_SYSTEM_ABILITY will // firstly start without init this string object, which leads to error. -AppSpawnSocket::AppSpawnSocket(bool isWebViewSpawn) -{ - clientSocket_ = isWebViewSpawn ? - std::make_unique("/dev/unix/socket/WebViewSpawn") : - std::make_unique("AppSpawn"); -} +AppSpawnSocket::AppSpawnSocket() : clientSocket_(std::make_unique("AppSpawn")) +{} AppSpawnSocket::~AppSpawnSocket() {} diff --git a/services/appmgr/src/lmks/lmks_utils.cpp b/services/appmgr/src/lmks/lmks_utils.cpp index c3280f09ac848d62f3c6b6843f2ea4c9c8a2b010..8a1833a30f7ef6e35545cc3eb438986b3d1f4efa 100644 --- a/services/appmgr/src/lmks/lmks_utils.cpp +++ b/services/appmgr/src/lmks/lmks_utils.cpp @@ -54,8 +54,14 @@ int LmksUtils::RemoveProcess(pid_t pid) } // kill process - HiLog::Info(LABEL, "kill pid %{public}d success, name %{public}s size %{public}d", - pid, procName.c_str(), procSize); + int ret = kill(pid, SIGKILL); + if (ret) { + HiLog::Warn(LABEL, "kill pid %{public}d err %{public}s", pid, strerror(errno)); + return (-errno); + } else { + HiLog::Info( + LABEL, "kill pid %{public}d success, name %{public}s size %{public}d", pid, procName.c_str(), procSize); + } return 0; } diff --git a/services/appmgr/src/process_optimizer.cpp b/services/appmgr/src/process_optimizer.cpp index f03e0a4e149f13c19cd1d5b2d3f2a1873d299ee6..534f4cd5df5ef3a33d34a0a6106f08d85d64d772 100644 --- a/services/appmgr/src/process_optimizer.cpp +++ b/services/appmgr/src/process_optimizer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -61,6 +61,8 @@ constexpr int APP_OOM_ADJ_UNKNOWN_VALUE = 64 * 1024; constexpr std::string_view SYSTEM_UI_BUNDLE_NAME = "com.ohos.systemui"; +constexpr int TIME_ADVANCE_RATE = 1000; + // pressure level low constexpr int LMKS_OOM_ADJ_LOW = 800; // pressure level medium @@ -684,5 +686,26 @@ std::string ProcessOptimizer::GetAppSuspendTimerName(const AppPtr &app) return ret; } + +void ProcessOptimizer::SetAppFreezingTime(int time) +{ + APP_LOGE("input second time:[%{public}d]", time); + + if (time > APP_SUSPEND_TIMEOUT_MAX && time < 0) { + APP_LOGE("input time error."); + return; + } + + suspendTimeout_ = time; + // convert seconds to milliseconds + suspendTimeout_ *= TIME_ADVANCE_RATE; +} + +void ProcessOptimizer::GetAppFreezingTime(int &time) +{ + time = suspendTimeout_ / TIME_ADVANCE_RATE; + APP_LOGE("current freez time:[%{public}d]", time); + return; +} } // namespace AppExecFwk } // namespace OHOS diff --git a/services/appmgr/src/process_optimizer_uba.cpp b/services/appmgr/src/process_optimizer_uba.cpp index 1dfe17b118df1dedc29acdd4cd436f79e5a36e90..679243386a983b981c7362714d4e5f9e0485b5d6 100644 --- a/services/appmgr/src/process_optimizer_uba.cpp +++ b/services/appmgr/src/process_optimizer_uba.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -384,5 +384,25 @@ UbaServicePtr ProcessOptimizerUBA::GetUbaService() // try to get uba service here. return nullptr; } + +void ProcessOptimizerUBA::SetAppFreezingTime(int time) +{ + auto ubaService = GetUbaService(); + if (ubaService) { + APP_LOGI("ubaService implement."); + } else { + ProcessOptimizer::SetAppFreezingTime(time); + } +} + +void ProcessOptimizerUBA::GetAppFreezingTime(int &time) +{ + auto ubaService = GetUbaService(); + if (ubaService) { + APP_LOGI("ubaService implement."); + } else { + ProcessOptimizer::GetAppFreezingTime(time); + } +} } // namespace AppExecFwk } // namespace OHOS diff --git a/services/appmgr/src/remote_client_manager.cpp b/services/appmgr/src/remote_client_manager.cpp index 8184aa67b9f0f65047e07308d11d6c209501ee1b..711b395c0d57de2491df62c07cafaf88066a5ff5 100644 --- a/services/appmgr/src/remote_client_manager.cpp +++ b/services/appmgr/src/remote_client_manager.cpp @@ -22,8 +22,7 @@ namespace OHOS { namespace AppExecFwk { -RemoteClientManager::RemoteClientManager() - : appSpawnClient_(std::make_shared()), webviewSpawnClient_(std::make_shared(true)) +RemoteClientManager::RemoteClientManager() : appSpawnClient_(std::make_shared()) {} RemoteClientManager::~RemoteClientManager() @@ -60,10 +59,5 @@ void RemoteClientManager::SetBundleManager(sptr bundleManager) { bundleManager_ = bundleManager; } - -std::shared_ptr RemoteClientManager::GetWebviewSpawnClient() -{ - return webviewSpawnClient_; -} } // namespace AppExecFwk } // namespace OHOS \ No newline at end of file diff --git a/services/appmgr/test/BUILD.gn b/services/appmgr/test/BUILD.gn index 845e14df8fdd7ae77cc8ca7e7ddd927634baee5a..372b896a424fb82a6898d829726c08c30809ff21 100644 --- a/services/appmgr/test/BUILD.gn +++ b/services/appmgr/test/BUILD.gn @@ -49,8 +49,6 @@ ohos_source_set("appmgr_test_source") { "${aafwk_path}/interfaces/innerkits/app_manager/src/appmgr/configuration.cpp", "${aafwk_path}/interfaces/innerkits/app_manager/src/appmgr/process_info.cpp", "${aafwk_path}/interfaces/innerkits/app_manager/src/appmgr/profile.cpp", - "${aafwk_path}/interfaces/innerkits/app_manager/src/appmgr/render_scheduler_host.cpp", - "${aafwk_path}/interfaces/innerkits/app_manager/src/appmgr/render_scheduler_proxy.cpp", "${aafwk_path}/interfaces/innerkits/app_manager/src/appmgr/running_process_info.cpp", "${appexecfwk_path}/interfaces/innerkits/appexecfwk_base/src/ability_info.cpp", "${appexecfwk_path}/interfaces/innerkits/appexecfwk_base/src/application_info.cpp", diff --git a/services/appmgr/test/mock/include/mock_app_mgr_service.h b/services/appmgr/test/mock/include/mock_app_mgr_service.h index dbd56b7565bd12d64f920a83124a6a28269bcbfb..7c6908a5041dd725bc03e9fb9e857ec0e75d4760 100644 --- a/services/appmgr/test/mock/include/mock_app_mgr_service.h +++ b/services/appmgr/test/mock/include/mock_app_mgr_service.h @@ -48,8 +48,6 @@ public: MOCK_METHOD2(GetSystemMemoryAttr, void(SystemMemoryAttr &memoryInfo, std::string &strConfig)); MOCK_METHOD0(StartupResidentProcess, void()); MOCK_METHOD1(AddAbilityStageDone, void(const int32_t recordId)); - MOCK_METHOD4(StartRenderProcess, int(const std::string&, int32_t, int32_t, pid_t&)); - MOCK_METHOD1(AttachRenderProcess, void(const sptr &renderScheduler)); MOCK_METHOD1(RegisterApplicationStateObserver, int32_t(const sptr &observer)); MOCK_METHOD1(UnregisterApplicationStateObserver, int32_t(const sptr &observer)); MOCK_METHOD3(ScheduleAcceptWantDone, diff --git a/services/appmgr/test/mock/include/mock_app_spawn_socket.h b/services/appmgr/test/mock/include/mock_app_spawn_socket.h index ea102b63e8e27c3e4a782bfe91be40040c876766..4a14ec5ee108c0857ada0934989c1e03131a748a 100644 --- a/services/appmgr/test/mock/include/mock_app_spawn_socket.h +++ b/services/appmgr/test/mock/include/mock_app_spawn_socket.h @@ -26,7 +26,7 @@ namespace OHOS { namespace AppExecFwk { class MockAppSpawnSocket : public AppSpawnSocket { public: - MockAppSpawnSocket() : AppSpawnSocket(false) {} + MockAppSpawnSocket() = default; virtual ~MockAppSpawnSocket() = default; MOCK_METHOD0(OpenAppSpawnConnection, ErrCode()); diff --git a/services/appmgr/test/unittest/ams_ability_running_record_test/BUILD.gn b/services/appmgr/test/unittest/ams_ability_running_record_test/BUILD.gn index da2dfe6863f4999cb2b18fb115d419fe35393b3f..cd40ee74bbb80992eeea2d39440e52d9505aa9b6 100644 --- a/services/appmgr/test/unittest/ams_ability_running_record_test/BUILD.gn +++ b/services/appmgr/test/unittest/ams_ability_running_record_test/BUILD.gn @@ -34,7 +34,6 @@ ohos_unittest("AmsAbilityRunningRecordTest") { sources = [ "${services_path}/appmgr/src/ability_running_record.cpp", - "${services_path}/appmgr/src/app_death_recipient.cpp", "${services_path}/appmgr/src/app_mgr_service_inner.cpp", "${services_path}/appmgr/src/app_running_record.cpp", "${services_path}/appmgr/src/app_spawn_client.cpp", @@ -56,7 +55,6 @@ ohos_unittest("AmsAbilityRunningRecordTest") { "${appexecfwk_path}/libs/libeventhandler:libeventhandler_target", "${innerkits_path}/uri_permission:uri_permission_mgr", "${services_path}/appmgr/test:appmgr_test_source", - "${services_path}/common:perm_verification", "//base/account/os_account/frameworks/osaccount/native:os_account_innerkits", "//foundation/aafwk/standard/interfaces/innerkits/app_manager:app_manager", "//foundation/aafwk/standard/services/appmgr:libams", diff --git a/services/appmgr/test/unittest/ams_app_death_recipient_test/BUILD.gn b/services/appmgr/test/unittest/ams_app_death_recipient_test/BUILD.gn index dc221c935c34464b332b33a1bee46da3352e36a9..d405e30a4a4f3536600f929a5f36a1c000c0251b 100644 --- a/services/appmgr/test/unittest/ams_app_death_recipient_test/BUILD.gn +++ b/services/appmgr/test/unittest/ams_app_death_recipient_test/BUILD.gn @@ -59,7 +59,6 @@ ohos_unittest("AppDeathRecipientTest") { "${appexecfwk_path}/libs/libeventhandler:libeventhandler_target", "${innerkits_path}/uri_permission:uri_permission_mgr", "${services_path}/appmgr/test:appmgr_test_source", - "${services_path}/common:perm_verification", "//base/account/os_account/frameworks/osaccount/native:os_account_innerkits", "//foundation/aafwk/standard/interfaces/innerkits/app_manager:app_manager", "//foundation/aafwk/standard/interfaces/innerkits/base:base", diff --git a/services/appmgr/test/unittest/ams_app_life_cycle_test/BUILD.gn b/services/appmgr/test/unittest/ams_app_life_cycle_test/BUILD.gn index 1554bc6a97398cab74e5dc4a89811f92a76c54d6..1d45a37a3d28d12ec65472e35f2c8041d149d53b 100644 --- a/services/appmgr/test/unittest/ams_app_life_cycle_test/BUILD.gn +++ b/services/appmgr/test/unittest/ams_app_life_cycle_test/BUILD.gn @@ -28,7 +28,6 @@ ohos_unittest("AmsAppLifeCycleTest") { sources = [ "${services_path}/appmgr/src/ability_running_record.cpp", - "${services_path}/appmgr/src/app_death_recipient.cpp", "${services_path}/appmgr/src/app_lifecycle_deal.cpp", "${services_path}/appmgr/src/app_mgr_service_event_handler.cpp", "${services_path}/appmgr/src/app_mgr_service_inner.cpp", @@ -59,7 +58,6 @@ ohos_unittest("AmsAppLifeCycleTest") { "${appexecfwk_path}/libs/libeventhandler:libeventhandler_target", "${innerkits_path}/uri_permission:uri_permission_mgr", "${services_path}/appmgr/test:appmgr_test_source", - "${services_path}/common:perm_verification", "//base/account/os_account/frameworks/osaccount/native:os_account_innerkits", "//foundation/aafwk/standard/interfaces/innerkits/app_manager:app_manager", "//foundation/aafwk/standard/interfaces/innerkits/base:base", diff --git a/services/appmgr/test/unittest/ams_app_life_cycle_test/ams_app_life_cycle_test.cpp b/services/appmgr/test/unittest/ams_app_life_cycle_test/ams_app_life_cycle_test.cpp index 37a4c51cb24e677e5dfca72f9093716a0d601627..cafc0b13ea63d5cf19b0b2942014e2d906894b96 100644 --- a/services/appmgr/test/unittest/ams_app_life_cycle_test/ams_app_life_cycle_test.cpp +++ b/services/appmgr/test/unittest/ams_app_life_cycle_test/ams_app_life_cycle_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -1898,6 +1898,21 @@ HWTEST_F(AmsAppLifeCycleTest, ClearUpApplicationData_001, TestSize.Level1) serviceInner_->ClearUpApplicationData(appRecord->GetBundleName(), appRecord->GetUid(), NEW_PID); } +/* + * Feature: AMS + * Function: AppLifeCycle::IsBackgroundRunningRestricted + * SubFunction: bundleMgr CheckPermission + * FunctionPoints: UnsuspendApplication + * CaseDescription: Check if there is background operation permission + */ +HWTEST_F(AmsAppLifeCycleTest, IsBackgroundRunningRestricted_001, TestSize.Level1) +{ + sptr bundleMgr = new BundleMgrService(); + serviceInner_->SetBundleManager(bundleMgr); + EXPECT_CALL(*bundleMgr, CheckPermission(_, _)).Times(1).WillOnce(Return(ERR_OK)); + EXPECT_EQ(ERR_OK, serviceInner_->IsBackgroundRunningRestricted("bundle")); +} + /* * Feature: AMS * Function: AppLifeCycle::CreateAppRunningRecord diff --git a/services/appmgr/test/unittest/ams_app_mgr_client_test/BUILD.gn b/services/appmgr/test/unittest/ams_app_mgr_client_test/BUILD.gn index 370e73e780d2b00aba57c36d19d74c1332fb7842..3f49da6249649985eb1e3b6b8e919493d08395cc 100644 --- a/services/appmgr/test/unittest/ams_app_mgr_client_test/BUILD.gn +++ b/services/appmgr/test/unittest/ams_app_mgr_client_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# Copyright (c) 2021 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -47,7 +47,6 @@ ohos_unittest("AmsAppMgrClientTest") { "${aafwk_path}/interfaces/innerkits/app_manager:app_manager", "${appexecfwk_path}/libs/libeventhandler:libeventhandler_target", "${services_path}/appmgr/test:appmgr_test_source", - "${services_path}/common:perm_verification", "//base/account/os_account/frameworks/osaccount/native:os_account_innerkits", "//foundation/aafwk/standard/interfaces/innerkits/want:want", "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_core:appexecfwk_core", diff --git a/services/appmgr/test/unittest/ams_app_running_record_test/BUILD.gn b/services/appmgr/test/unittest/ams_app_running_record_test/BUILD.gn index 82442b11ca121637e784796250011340bca2960a..77f587aadce59419ca6988d0cba18f2851255ab7 100644 --- a/services/appmgr/test/unittest/ams_app_running_record_test/BUILD.gn +++ b/services/appmgr/test/unittest/ams_app_running_record_test/BUILD.gn @@ -33,7 +33,6 @@ ohos_unittest("AmsAppRunningRecordTest") { sources = [ "${services_path}/appmgr/src/ability_running_record.cpp", - "${services_path}/appmgr/src/app_death_recipient.cpp", "${services_path}/appmgr/src/app_mgr_service_inner.cpp", "${services_path}/appmgr/src/app_running_record.cpp", "${services_path}/appmgr/src/app_spawn_client.cpp", @@ -54,7 +53,6 @@ ohos_unittest("AmsAppRunningRecordTest") { "${appexecfwk_path}/libs/libeventhandler:libeventhandler_target", "${innerkits_path}/uri_permission:uri_permission_mgr", "${services_path}/appmgr/test:appmgr_test_source", - "${services_path}/common:perm_verification", "//base/account/os_account/frameworks/osaccount/native:os_account_innerkits", "//foundation/aafwk/standard/services/appmgr:libams", "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_core:appexecfwk_core", diff --git a/services/appmgr/test/unittest/ams_app_workflow_test/BUILD.gn b/services/appmgr/test/unittest/ams_app_workflow_test/BUILD.gn index 254ac523d0364e280ed31f878690769596108989..694353fa85188c247a9592b96ff39e7e9c26fc85 100644 --- a/services/appmgr/test/unittest/ams_app_workflow_test/BUILD.gn +++ b/services/appmgr/test/unittest/ams_app_workflow_test/BUILD.gn @@ -29,7 +29,6 @@ ohos_unittest("AmsWorkFlowTest") { sources = [ "${services_path}/appmgr/src/ability_running_record.cpp", - "${services_path}/appmgr/src/app_death_recipient.cpp", "${services_path}/appmgr/src/app_lifecycle_deal.cpp", "${services_path}/appmgr/src/app_mgr_service_event_handler.cpp", "${services_path}/appmgr/src/app_mgr_service_inner.cpp", @@ -57,7 +56,6 @@ ohos_unittest("AmsWorkFlowTest") { "${appexecfwk_path}/libs/libeventhandler:libeventhandler_target", "${innerkits_path}/uri_permission:uri_permission_mgr", "${services_path}/appmgr/test:appmgr_test_source", - "${services_path}/common:perm_verification", "//base/account/os_account/frameworks/osaccount/native:os_account_innerkits", "//foundation/aafwk/standard/interfaces/innerkits/base:base", "//foundation/aafwk/standard/interfaces/innerkits/want:want", diff --git a/services/appmgr/test/unittest/ams_ipc_interface_test/ams_ipc_appmgr_interface_test.cpp b/services/appmgr/test/unittest/ams_ipc_interface_test/ams_ipc_appmgr_interface_test.cpp index 9bfd1a4b3eaa0d5f8fd6b438e60e61e158621b43..4b7f1e95471c1bb7d93bcda8a70574a9cc0b4618 100644 --- a/services/appmgr/test/unittest/ams_ipc_interface_test/ams_ipc_appmgr_interface_test.cpp +++ b/services/appmgr/test/unittest/ams_ipc_interface_test/ams_ipc_appmgr_interface_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -213,6 +213,33 @@ HWTEST_F(AmsIpcAppMgrInterfaceTest, ClearUpApplicationData_008, TestSize.Level1) APP_LOGD("ClearUpApplicationData_008 end"); } +/* + * Feature: AMS + * Function: IPC IsBackgroundRunningRestricted + * SubFunction: appmgr interface + * FunctionPoints: Check background operation + * CaseDescription: test IPC can transact data + */ +HWTEST_F(AmsIpcAppMgrInterfaceTest, IsBackgroundRunningRestricted_009, TestSize.Level1) +{ + APP_LOGD("IsBackgroundRunningRestricted_009 start"); + + sptr mockAppMgr(new MockAppMgrService()); + sptr appMgrClient = iface_cast(mockAppMgr); + + EXPECT_CALL(*mockAppMgr, IsBackgroundRunningRestricted(_)).Times(1).WillOnce(Return(OHOS::NO_ERROR)); + + int32_t ret = appMgrClient->IsBackgroundRunningRestricted("PROCESS"); + + EXPECT_EQ(ret, OHOS::NO_ERROR); + // Returns 32 when the bundle name is empty + EXPECT_CALL(*mockAppMgr, IsBackgroundRunningRestricted(_)).Times(1).WillOnce(Return(32)); + ret = appMgrClient->IsBackgroundRunningRestricted(""); + + EXPECT_EQ(ret, 32); + APP_LOGD("IsBackgroundRunningRestricted_009 end"); +} + /* * Feature: AMS * Function: IPC diff --git a/services/appmgr/test/unittest/ams_mgr_scheduler_test/ams_mgr_scheduler_test.cpp b/services/appmgr/test/unittest/ams_mgr_scheduler_test/ams_mgr_scheduler_test.cpp index 0a99396ef84fbeb4ed45daf2403217eb526aed22..85f35cacbda5657d235f2faef365745ce7d58a1d 100644 --- a/services/appmgr/test/unittest/ams_mgr_scheduler_test/ams_mgr_scheduler_test.cpp +++ b/services/appmgr/test/unittest/ams_mgr_scheduler_test/ams_mgr_scheduler_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -238,6 +238,32 @@ HWTEST_F(AmsMgrSchedulerTest, AmsMgrScheduler_005, TestSize.Level1) APP_LOGD("AmsMgrScheduler_005 end."); } +/* + * Feature: AMS + * Function: AmsMgrScheduler + * SubFunction: Reset + * FunctionPoints: Act normal + * EnvConditions: Mobile that can run ohos test framework. + * CaseDescription: Verify the function Reset can works. + */ +HWTEST_F(AmsMgrSchedulerTest, AmsMgrScheduler_006, TestSize.Level1) +{ + APP_LOGD("AmsMgrScheduler_006 start."); + + auto mockAppMgrServiceInner = GetMockAppMgrServiceInner(); + auto amsEventHandler = GetAmsEventHandler(); + std::unique_ptr amsMgrScheduler = + std::make_unique(mockAppMgrServiceInner, amsEventHandler); + + sptr appStateCallbackHost = new AppStateCallbackHost(); + EXPECT_CALL(*mockAppMgrServiceInner, StopAllProcess()) + .WillOnce(InvokeWithoutArgs(mockAppMgrServiceInner.get(), &MockAppMgrServiceInner::Post)); + amsMgrScheduler->Reset(); + mockAppMgrServiceInner->Wait(); + + APP_LOGD("AmsMgrScheduler_006 end."); +} + /* * Feature: AMS * Function: AmsMgrScheduler diff --git a/services/appmgr/test/unittest/ams_recent_app_list_test/BUILD.gn b/services/appmgr/test/unittest/ams_recent_app_list_test/BUILD.gn index 49ef60e977f6d32fdadf351ccf2b0d1c72ad3c73..10d50345d2831fd7b567f9a8144bb32eb3262794 100644 --- a/services/appmgr/test/unittest/ams_recent_app_list_test/BUILD.gn +++ b/services/appmgr/test/unittest/ams_recent_app_list_test/BUILD.gn @@ -27,7 +27,6 @@ ohos_unittest("AmsRecentAppListTest") { sources = [ "${services_path}/appmgr/src/ability_running_record.cpp", - "${services_path}/appmgr/src/app_death_recipient.cpp", "${services_path}/appmgr/src/app_lifecycle_deal.cpp", "${services_path}/appmgr/src/app_mgr_service_inner.cpp", "${services_path}/appmgr/src/app_process_manager.cpp", @@ -57,7 +56,6 @@ ohos_unittest("AmsRecentAppListTest") { "${appexecfwk_path}/libs/libeventhandler:libeventhandler_target", "${innerkits_path}/uri_permission:uri_permission_mgr", "${services_path}/appmgr/test:appmgr_test_source", - "${services_path}/common:perm_verification", "//base/account/os_account/frameworks/osaccount/native:os_account_innerkits", "//foundation/aafwk/standard/interfaces/innerkits/app_manager:app_manager", "//foundation/aafwk/standard/interfaces/innerkits/base:base", diff --git a/services/appmgr/test/unittest/ams_service_app_spawn_client_test/BUILD.gn b/services/appmgr/test/unittest/ams_service_app_spawn_client_test/BUILD.gn index 477e6e2c17c65ee1a29856e4d25409d8d40f8206..c09f3a61dceb8045687ede9be4f64908a08f4121 100644 --- a/services/appmgr/test/unittest/ams_service_app_spawn_client_test/BUILD.gn +++ b/services/appmgr/test/unittest/ams_service_app_spawn_client_test/BUILD.gn @@ -54,7 +54,6 @@ ohos_unittest("AmsServiceAppSpawnClientTest") { "${appexecfwk_path}/libs/libeventhandler:libeventhandler_target", "${innerkits_path}/uri_permission:uri_permission_mgr", "${services_path}/appmgr/test:appmgr_test_source", - "${services_path}/common:perm_verification", "//base/account/os_account/frameworks/osaccount/native:os_account_innerkits", "//foundation/aafwk/standard/interfaces/innerkits/base:base", "//foundation/aafwk/standard/interfaces/innerkits/want:want", diff --git a/services/appmgr/test/unittest/ams_service_event_drive_test/BUILD.gn b/services/appmgr/test/unittest/ams_service_event_drive_test/BUILD.gn index 4c7f3d6470d60c0fc085ac2e4699ab16280702a8..48fba9708ff1a7b7ddc6110f66a11ae3aac66996 100644 --- a/services/appmgr/test/unittest/ams_service_event_drive_test/BUILD.gn +++ b/services/appmgr/test/unittest/ams_service_event_drive_test/BUILD.gn @@ -56,7 +56,6 @@ ohos_unittest("AmsServiceEventDriveTest") { "${appexecfwk_path}/libs/libeventhandler:libeventhandler_target", "${innerkits_path}/uri_permission:uri_permission_mgr", "${services_path}/appmgr/test:appmgr_test_source", - "${services_path}/common:perm_verification", "//base/account/os_account/frameworks/osaccount/native:os_account_innerkits", "//foundation/aafwk/standard/interfaces/innerkits/base:base", "//foundation/aafwk/standard/interfaces/innerkits/want:want", diff --git a/services/appmgr/test/unittest/ams_service_event_drive_test/ams_service_event_drive_test.cpp b/services/appmgr/test/unittest/ams_service_event_drive_test/ams_service_event_drive_test.cpp index 576239b327492646b2ba4dfbd3ae73a33d554aea..f17bbdbe68929302eb15f30b31a88f0c67a71447 100644 --- a/services/appmgr/test/unittest/ams_service_event_drive_test/ams_service_event_drive_test.cpp +++ b/services/appmgr/test/unittest/ams_service_event_drive_test/ams_service_event_drive_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -226,6 +226,30 @@ HWTEST_F(AmsServiceEventDriveTest, EventDrive_006, TestSize.Level1) APP_LOGI("ams_service_event_drive_test_006 end"); } +/* + * Feature: AppMgrService + * Function: Service + * SubFunction: EventDrive + * FunctionPoints: AppMgrService event drive program model + * EnvConditions: Mobile that can run ohos test framework + * CaseDescription: Verify if post IsBackgroundRunningRestricted task success + */ +HWTEST_F(AmsServiceEventDriveTest, EventDrive_007, TestSize.Level1) +{ + APP_LOGI("ams_service_event_drive_test_007 start"); + + std::shared_ptr innerService = std::make_shared(); + appMgrService_->SetInnerService(innerService); + appMgrService_->OnStart(); + + EXPECT_CALL(*innerService, IsBackgroundRunningRestricted(_)).WillOnce(Return(0)); + + std::string appName = "appName"; + EXPECT_EQ(0, appMgrService_->IsBackgroundRunningRestricted(appName)); + + APP_LOGI("ams_service_event_drive_test_007 end"); +} + /* * Feature: AppMgrService * Function: Service @@ -394,6 +418,28 @@ HWTEST_F(AmsServiceEventDriveTest, EventDrive_014, TestSize.Level1) APP_LOGI("ams_service_event_drive_test_014 end"); } +/* + * Feature: AppMgrService + * Function: Service + * SubFunction: EventDrive + * FunctionPoints: AppMgrService event drive program model + * EnvConditions: Mobile that can run ohos test framework + * CaseDescription: Verify if IsBackgroundRunningRestricted act normal after AppMgrService stopped + */ +HWTEST_F(AmsServiceEventDriveTest, EventDrive_015, TestSize.Level1) +{ + APP_LOGI("ams_service_event_drive_test_015 start"); + + appMgrService_->OnStop(); + std::shared_ptr innerService = std::make_shared(); + appMgrService_->SetInnerService(innerService); + + std::string appName = "appName"; + EXPECT_EQ(OHOS::ERR_INVALID_OPERATION, appMgrService_->IsBackgroundRunningRestricted(appName)); + + APP_LOGI("ams_service_event_drive_test_015 end"); +} + /* * Feature: AppMgrService * Function: Service @@ -564,6 +610,28 @@ HWTEST_F(AmsServiceEventDriveTest, EventDrive_022, TestSize.Level1) APP_LOGI("ams_service_event_drive_test_022 end"); } +/* + * Feature: AppMgrService + * Function: Service + * SubFunction: EventDrive + * FunctionPoints: AppMgrService event drive program model + * EnvConditions: Mobile that can run ohos test framework + * CaseDescription: Verify if IsBackgroundRunningRestricted act normal after AppMgrService stopped + */ +HWTEST_F(AmsServiceEventDriveTest, EventDrive_023, TestSize.Level1) +{ + APP_LOGI("ams_service_event_drive_test_023 start"); + std::shared_ptr innerService = std::make_shared(); + appMgrService_->SetInnerService(innerService); + appMgrService_->OnStart(); + appMgrService_->OnStop(); + + std::string appName = "appName"; + EXPECT_EQ(OHOS::ERR_INVALID_OPERATION, appMgrService_->IsBackgroundRunningRestricted(appName)); + + APP_LOGI("ams_service_event_drive_test_023 end"); +} + /* * Feature: AppMgrService * Function: Service diff --git a/services/appmgr/test/unittest/ams_service_load_ability_process_test/BUILD.gn b/services/appmgr/test/unittest/ams_service_load_ability_process_test/BUILD.gn index 18c0cf797af5076366d4f98b81952ca2ca73f3a7..367663fa6a5180dd130124187748a69cf4d317b6 100644 --- a/services/appmgr/test/unittest/ams_service_load_ability_process_test/BUILD.gn +++ b/services/appmgr/test/unittest/ams_service_load_ability_process_test/BUILD.gn @@ -27,7 +27,6 @@ ohos_unittest("AmsServiceLoadAbilityProcessTest") { sources = [ "${services_path}/appmgr/src/ability_running_record.cpp", - "${services_path}/appmgr/src/app_death_recipient.cpp", "${services_path}/appmgr/src/app_lifecycle_deal.cpp", "${services_path}/appmgr/src/app_mgr_service_inner.cpp", "${services_path}/appmgr/src/app_process_manager.cpp", @@ -61,7 +60,6 @@ ohos_unittest("AmsServiceLoadAbilityProcessTest") { "${appexecfwk_path}/libs/libeventhandler:libeventhandler_target", "${innerkits_path}/uri_permission:uri_permission_mgr", "${services_path}/appmgr/test:appmgr_test_source", - "${services_path}/common:perm_verification", "//base/account/os_account/frameworks/osaccount/native:os_account_innerkits", "//foundation/aafwk/standard/interfaces/innerkits/base:base", "//foundation/aafwk/standard/interfaces/innerkits/want:want", diff --git a/services/appmgr/test/unittest/ams_service_startup_test/BUILD.gn b/services/appmgr/test/unittest/ams_service_startup_test/BUILD.gn index d34b41694905ca6e9568902282e88f0c25a6c587..fc65f97e04a52510e423ec3d043abae212601e59 100644 --- a/services/appmgr/test/unittest/ams_service_startup_test/BUILD.gn +++ b/services/appmgr/test/unittest/ams_service_startup_test/BUILD.gn @@ -51,7 +51,6 @@ ohos_unittest("AmsServiceStartupTest") { "${appexecfwk_path}/libs/libeventhandler:libeventhandler_target", "${innerkits_path}/uri_permission:uri_permission_mgr", "${services_path}/appmgr/test:appmgr_test_source", - "${services_path}/common:perm_verification", "//base/account/os_account/frameworks/osaccount/native:os_account_innerkits", "//foundation/aafwk/standard/interfaces/innerkits/app_manager:app_manager", "//foundation/aafwk/standard/interfaces/innerkits/base:base", diff --git a/services/appmgr/test/unittest/app_mgr_service_event_handler_test/BUILD.gn b/services/appmgr/test/unittest/app_mgr_service_event_handler_test/BUILD.gn index 635e47a975f49282a9a77e753ada1cc4da9e7897..914c579d6186bbda652c61031d89d18ca76dfbcf 100644 --- a/services/appmgr/test/unittest/app_mgr_service_event_handler_test/BUILD.gn +++ b/services/appmgr/test/unittest/app_mgr_service_event_handler_test/BUILD.gn @@ -59,7 +59,6 @@ ohos_unittest("AMSEventHandlerTest") { "${appexecfwk_path}/libs/libeventhandler:libeventhandler_target", "${innerkits_path}/uri_permission:uri_permission_mgr", "${services_path}/appmgr/test:appmgr_test_source", - "${services_path}/common:perm_verification", "//base/account/os_account/frameworks/osaccount/native:os_account_innerkits", "//foundation/aafwk/standard/interfaces/innerkits/app_manager:app_manager", "//foundation/aafwk/standard/interfaces/innerkits/base:base", diff --git a/services/common/BUILD.gn b/services/common/BUILD.gn index 60e148c9e313cbf24a4766380cfcead760692e82..28587377112b6ddcc6b190985d887674baa11bda 100644 --- a/services/common/BUILD.gn +++ b/services/common/BUILD.gn @@ -1,5 +1,5 @@ # -# Copyright (c) 2022 Huawei Device Co., Ltd. +# Copyright (c) 2021 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -29,29 +29,3 @@ ohos_source_set("abilitymgr_common") { external_deps = [ "hiviewdfx_hilog_native:libhilog" ] } - -config("perm_verification_config") { - visibility = [ ":*" ] - include_dirs = [ "include" ] - cflags = [] - if (target_cpu == "arm") { - cflags += [ "-DBINDER_IPC_32BIT" ] - } -} - -#build so -ohos_shared_library("perm_verification") { - public_configs = [ ":perm_verification_config" ] - - sources = [ "src/permission_verification.cpp" ] - - external_deps = [ - "access_token:libaccesstoken_sdk", - "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_core", - "utils_base:utils", - ] - - subsystem_name = "aafwk" - part_name = "ability_runtime" -} diff --git a/services/common/include/permission_constants.h b/services/common/include/permission_constants.h deleted file mode 100644 index fce13bd70ba956c6fd6c302f96f5705d84d2e831..0000000000000000000000000000000000000000 --- a/services/common/include/permission_constants.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_AAFWK_PERMISSION_CONSTANTS_H -#define OHOS_AAFWK_PERMISSION_CONSTANTS_H - -namespace OHOS { -namespace AAFwk { -namespace PermissionConstants { -const std::string PERMISSION_CLEAN_BACKGROUND_PROCESSES = "ohos.permission.CLEAN_BACKGROUND_PROCESSES"; -const std::string PERMISSION_INTERACT_ACROSS_LOCAL_ACCOUNTS = "ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS"; -const std::string PERMISSION_GET_RUNNING_INFO = "ohos.permission.GET_RUNNING_INFO"; -const std::string PERMISSION_UPDATE_CONFIGURATION = "ohos.permission.UPDATE_CONFIGURATION"; -const std::string PERMISSION_CLEAN_APPLICATION_DATA = "ohos.permission.CLEAN_APPLICATION_DATA"; -const std::string PERMISSION_RUNNING_STATE_OBSERVER = "ohos.permission.RUNNING_STATE_OBSERVER"; -const std::string PERMISSION_MANAGE_MISSION = "ohos.permission.MANAGE_MISSIONS"; -} // namespace PermissionConstants -} // namespace AAFwk -} // namespace OHOS -#endif // OHOS_AAFWK_PERMISSION_CONSTANTS_H \ No newline at end of file diff --git a/services/common/include/permission_verification.h b/services/common/include/permission_verification.h deleted file mode 100644 index 89e6fd773aecc538afd658762d693b2ff93c0645..0000000000000000000000000000000000000000 --- a/services/common/include/permission_verification.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_AAFWK_PERMISSION_VERIFICATION_H -#define OHOS_AAFWK_PERMISSION_VERIFICATION_H - -#include - -#include "singleton.h" - -namespace OHOS { -namespace AAFwk { -class PermissionVerification : public DelayedSingleton { -public: - PermissionVerification() = default; - ~PermissionVerification() = default; - - bool VerifyCallingPermission(const std::string &permissionName); - - bool IsSACall(); - - bool VerifyRunningInfoPerm(); - -private: - DISALLOW_COPY_AND_MOVE(PermissionVerification); - unsigned int GetCallingTokenID(); -}; -} // namespace AAFwk -} // namespace OHOS -#endif // OHOS_AAFWK_PERMISSION_VERIFICATION_H \ No newline at end of file diff --git a/services/common/src/permission_verification.cpp b/services/common/src/permission_verification.cpp deleted file mode 100644 index 10d186be7c31ab2233348d6200079998b292f464..0000000000000000000000000000000000000000 --- a/services/common/src/permission_verification.cpp +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "permission_verification.h" - -#include "accesstoken_kit.h" -#include "hilog_wrapper.h" -#include "ipc_skeleton.h" -#include "permission_constants.h" - -namespace OHOS { -namespace AAFwk { -bool PermissionVerification::VerifyCallingPermission(const std::string &permissionName) -{ - HILOG_DEBUG("VerifyCallingPermission permission %{public}s", permissionName.c_str()); - auto callerToken = GetCallingTokenID(); - int32_t ret = Security::AccessToken::AccessTokenKit::VerifyAccessToken(callerToken, permissionName); - if (ret == Security::AccessToken::PermissionState::PERMISSION_DENIED) { - HILOG_ERROR("permission %{public}s: PERMISSION_DENIED", permissionName.c_str()); - return false; - } - HILOG_DEBUG("verify AccessToken success"); - return true; -} - -bool PermissionVerification::IsSACall() -{ - HILOG_DEBUG("AmsMgrScheduler::IsSACall is called."); - auto callerToken = GetCallingTokenID(); - auto tokenType = Security::AccessToken::AccessTokenKit::GetTokenTypeFlag(callerToken); - if (tokenType == Security::AccessToken::ATokenTypeEnum::TOKEN_NATIVE) { - HILOG_DEBUG("caller tokenType is native, verify success"); - return true; - } - HILOG_DEBUG("Not SA called."); - return false; -} - -bool PermissionVerification::VerifyRunningInfoPerm() -{ - if (IsSACall()) { - HILOG_DEBUG("%{public}s: the interface called by SA.", __func__); - return true; - } - if (VerifyCallingPermission(PermissionConstants::PERMISSION_GET_RUNNING_INFO)) { - HILOG_DEBUG("%{public}s: Permission verification succeeded.", __func__); - return true; - } - HILOG_ERROR("%{public}s: Permission verification failed.", __func__); - return false; -} - -unsigned int PermissionVerification::GetCallingTokenID() -{ - auto callerToken = IPCSkeleton::GetCallingTokenID(); - HILOG_DEBUG("callerToken : %{public}u", callerToken); - return callerToken; -} -} // namespace AAFwk -} // namespace OHOS \ No newline at end of file diff --git a/services/formmgr/BUILD.gn b/services/formmgr/BUILD.gn index 1df7b815b4e073966df4a9d3806571d0309cfc33..cc0963ffc1e427bb8ccac55e80f9face31284da3 100644 --- a/services/formmgr/BUILD.gn +++ b/services/formmgr/BUILD.gn @@ -30,7 +30,6 @@ group("fms_target") { ohos_shared_library("libfms") { include_dirs = [ - "${services_path}/common:perm_verification", "//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler/include", "//foundation/aafwk/standard/interfaces/innerkits/ability_manager/include", "//base/security/permission/interfaces/innerkits/permission_standard/permissionsdk/main/cpp/include", @@ -91,7 +90,6 @@ ohos_shared_library("libfms") { deps = [ "${appexecfwk_path}/common:libappexecfwk_common", "${appexecfwk_path}/libs/libeventhandler:libeventhandler_target", - "${services_path}/common:perm_verification", "//base/miscservices/time/services:time_service", "//foundation/aafwk/standard/frameworks/kits/appkit:app_context", "//foundation/aafwk/standard/frameworks/kits/wantagent:wantagent_innerkits", diff --git a/services/formmgr/include/form_info_mgr.h b/services/formmgr/include/form_info_mgr.h index 74bdb8db553f23e421758674f2eda487ec8e1c47..42bfdb441b6d62d01750d96631742b255f6820ad 100644 --- a/services/formmgr/include/form_info_mgr.h +++ b/services/formmgr/include/form_info_mgr.h @@ -79,8 +79,6 @@ public: private: std::shared_ptr GetOrCreateBundleFromInfo(const std::string &bundleName); - bool IsCaller(std::string bundleName); - bool CheckBundlePermission(); mutable std::shared_timed_mutex bundleFormInfoMapMutex_ {}; std::unordered_map> bundleFormInfoMap_ {}; diff --git a/services/formmgr/include/form_mgr_service.h b/services/formmgr/include/form_mgr_service.h index 400a368f6400f1caa487253e7cb541084070f980..ffb36aa484b0f3f1bcedeb7c93efe18d7b05e074 100644 --- a/services/formmgr/include/form_mgr_service.h +++ b/services/formmgr/include/form_mgr_service.h @@ -233,7 +233,19 @@ private: */ ErrCode Init(); + /** + * @brief Permission check by callingUid. + * @param formId the id of the form. + * @return Returns true on success, false on failure. + */ bool CheckFormPermission(); + + /** + * @brief Permission check. + * @param bundleName bundleName. + * @return Returns true on success, false on failure. + */ + bool CheckFormPermission(const std::string &bundleName) const; private: ServiceRunningState state_; diff --git a/services/formmgr/include/form_timer.h b/services/formmgr/include/form_timer.h index db681db10f63b1aba61200c9f9d070f9794631fe..e52bac2530ccd5acfe5e7b8292e030d066869fac 100644 --- a/services/formmgr/include/form_timer.h +++ b/services/formmgr/include/form_timer.h @@ -42,7 +42,7 @@ public: bool isUpdateAt; int64_t refreshTime; bool isEnable = true; - bool isCountTimer; + bool isCountTimer = false; UpdateType type = UpdateType::TYPE_INTERVAL_CHANGE; FormTimer() @@ -54,7 +54,7 @@ public: min = -1; isUpdateAt = false; isCountTimer = false; - refreshTime = LONG_MAX; + refreshTime = 0; type = UpdateType::TYPE_INTERVAL_CHANGE; } @@ -67,7 +67,7 @@ public: min = -1; isUpdateAt = false; isCountTimer = countTimer; - refreshTime = LONG_MAX; + refreshTime = 0; type = UpdateType::TYPE_INTERVAL_CHANGE; } @@ -80,7 +80,7 @@ public: min = -1; isUpdateAt = false; isCountTimer = true; - refreshTime = LONG_MAX; + refreshTime = 0; type = UpdateType::TYPE_INTERVAL_CHANGE; } @@ -93,7 +93,7 @@ public: period = -1; isUpdateAt = true; isCountTimer = false; - refreshTime = LONG_MAX; + refreshTime = 0; type = UpdateType::TYPE_INTERVAL_CHANGE; } ~FormTimer(void){ @@ -105,7 +105,7 @@ public: */ class UpdateAtItem { public: - long updateAtTime = -1; + int updateAtTime = -1; FormTimer refreshTask; }; /** diff --git a/services/formmgr/src/form_info_mgr.cpp b/services/formmgr/src/form_info_mgr.cpp index d4a988f3c381b5d44317e4f0ae0111d7229e7dc1..370e25f79517bae37c98b16c761f1d59f2de04bc 100644 --- a/services/formmgr/src/form_info_mgr.cpp +++ b/services/formmgr/src/form_info_mgr.cpp @@ -23,9 +23,7 @@ #include "form_bms_helper.h" #include "form_info_storage_mgr.h" #include "form_util.h" -#include "ipc_skeleton.h" #include "json_serializer.h" -#include "permission_verification.h" namespace OHOS { namespace AppExecFwk { @@ -276,22 +274,10 @@ ErrCode FormInfoMgr::Remove(const std::string &bundleName) ErrCode FormInfoMgr::GetAllFormsInfo(std::vector &formInfos) { - bool hasPermission = CheckBundlePermission(); std::shared_lock guard(bundleFormInfoMapMutex_); - if (hasPermission) { - for (const auto &bundleFormInfo: bundleFormInfoMap_) { - if (bundleFormInfo.second != nullptr) { - bundleFormInfo.second->GetAllFormsInfo(formInfos); - } - } - } else { - for (const auto &bundleFormInfo: bundleFormInfoMap_) { - if (IsCaller(bundleFormInfo.first)) { - if (bundleFormInfo.second != nullptr) { - bundleFormInfo.second->GetAllFormsInfo(formInfos); - } - return ERR_OK; - } + for (const auto &bundleFormInfo: bundleFormInfoMap_) { + if (bundleFormInfo.second != nullptr) { + bundleFormInfo.second->GetAllFormsInfo(formInfos); } } return ERR_OK; @@ -304,10 +290,6 @@ ErrCode FormInfoMgr::GetFormsInfoByBundle(const std::string &bundleName, std::ve return ERR_APPEXECFWK_FORM_INVALID_PARAM; } - if (!CheckBundlePermission() && !IsCaller(bundleName)) { - return ERR_APPEXECFWK_FORM_PERMISSION_DENY; - } - std::shared_lock guard(bundleFormInfoMapMutex_); auto bundleFormInfoIter = bundleFormInfoMap_.find(bundleName); if (bundleFormInfoIter == bundleFormInfoMap_.end()) { @@ -329,10 +311,6 @@ ErrCode FormInfoMgr::GetFormsInfoByModule(const std::string &bundleName, const s return ERR_APPEXECFWK_FORM_INVALID_PARAM; } - if (!CheckBundlePermission() && !IsCaller(bundleName)) { - return ERR_APPEXECFWK_FORM_PERMISSION_DENY; - } - std::shared_lock guard(bundleFormInfoMapMutex_); auto bundleFormInfoIter = bundleFormInfoMap_.find(bundleName); if (bundleFormInfoIter == bundleFormInfoMap_.end()) { @@ -369,39 +347,5 @@ std::shared_ptr FormInfoMgr::GetOrCreateBundleFromInfo(const std bundleFormInfoMap_[bundleName] = bundleFormInfoPtr; return bundleFormInfoPtr; } - -bool FormInfoMgr::IsCaller(std::string bundleName) -{ - auto bms = FormBmsHelper::GetInstance().GetBundleMgr(); - if (!bms) { - return false; - } - AppExecFwk::BundleInfo bundleInfo; - bool ret = bms->GetBundleInfo(bundleName, GET_BUNDLE_DEFAULT, bundleInfo, FormUtil::GetCurrentAccountId()); - if (!ret) { - APP_LOGE("Failed to get bundle info."); - return false; - } - auto callerToken = IPCSkeleton::GetCallingTokenID(); - if (bundleInfo.applicationInfo.accessTokenId == callerToken) { - return true; - } - return false; -} - -bool FormInfoMgr::CheckBundlePermission() -{ - auto isSaCall = AAFwk::PermissionVerification::GetInstance()->IsSACall(); - if (isSaCall) { - return true; - } - auto isCallingPerm = AAFwk::PermissionVerification::GetInstance()->VerifyCallingPermission( - AppExecFwk::Constants::PERMISSION_GET_BUNDLE_INFO_PRIVILEGED); - if (isCallingPerm) { - return true; - } - APP_LOGE("Permission verification failed"); - return false; -} } // namespace AppExecFwk } // namespace OHOS diff --git a/services/formmgr/src/form_mgr_adapter.cpp b/services/formmgr/src/form_mgr_adapter.cpp index df70f1d0768edcb70dab5f9a44456aafd6792b25..1534979cd2131dc40c14b5f792d255acf0d2d35c 100644 --- a/services/formmgr/src/form_mgr_adapter.cpp +++ b/services/formmgr/src/form_mgr_adapter.cpp @@ -14,6 +14,7 @@ */ #include +#include #include "appexecfwk_errors.h" #include "app_log_wrapper.h" @@ -585,12 +586,10 @@ int FormMgrAdapter::CastTempForm(const int64_t formId, const sptr APP_LOGE("%{public}s fail, add form user uid error, formId:%{public}" PRId64 ".", __func__, matchedFormId); return ERR_APPEXECFWK_FORM_NOT_EXIST_ID; } - - if (!FormDataMgr::GetInstance().GetFormRecord(matchedFormId, formRecord)) { - APP_LOGE("%{public}s fail, not exist such form:%{public}" PRId64 ".", __func__, matchedFormId); - return ERR_APPEXECFWK_FORM_NOT_EXIST_ID; + if (std::find(formRecord.formUserUids.begin(), formRecord.formUserUids.end(), + callingUid) == formRecord.formUserUids.end()) { + formRecord.formUserUids.emplace_back(callingUid); } - if (ErrCode errorCode = FormDbCache::GetInstance().UpdateDBRecord(matchedFormId, formRecord); errorCode != ERR_OK) { APP_LOGE("%{public}s fail, update db record error, formId:%{public}" PRId64 ".", __func__, matchedFormId); return errorCode; @@ -1211,7 +1210,9 @@ ErrCode FormMgrAdapter::CreateFormItemInfo(const BundleInfo &bundleInfo, if (formInfo.moduleName == item.moduleName) { itemInfo.AddHapSourceDirs(item.moduleSourceDir); } - itemInfo.AddModuleInfo(item.moduleName, item.moduleSourceDir); + auto moduleSourceDir = std::regex_replace(item.moduleSourceDir, std::regex(Constants::ABS_CODE_PATH), + Constants::LOCAL_BUNDLES); + itemInfo.AddModuleInfo(item.moduleName, moduleSourceDir); } return ERR_OK; } diff --git a/services/formmgr/src/form_mgr_service.cpp b/services/formmgr/src/form_mgr_service.cpp index cf1ed09d0d2aaa50a8f12023a0338ce749a4ff4d..e61d0f15ae9d196a1fb8cd2b51d183ee3be95871 100644 --- a/services/formmgr/src/form_mgr_service.cpp +++ b/services/formmgr/src/form_mgr_service.cpp @@ -37,7 +37,6 @@ #include "iservice_registry.h" #include "permission/permission.h" #include "permission/permission_kit.h" -#include "permission_verification.h" #include "string_ex.h" #include "system_ability_definition.h" @@ -142,6 +141,10 @@ int FormMgrService::ReleaseForm(const int64_t formId, const sptr int FormMgrService::UpdateForm(const int64_t formId, const std::string &bundleName, const FormProviderData &formBindingData) { + if (!CheckFormPermission()) { + APP_LOGE("%{public}s fail, update form permission denied", __func__); + return ERR_APPEXECFWK_FORM_PERMISSION_DENY; + } return FormMgrAdapter::GetInstance().UpdateForm(formId, bundleName, formBindingData); } @@ -391,20 +394,28 @@ ErrCode FormMgrService::Init() APP_LOGI("init success"); return ERR_OK; } - +/** + * @brief Permission check by callingUid. + * @param formId the id of the form. + * @return Returns true on success, false on failure. + */ bool FormMgrService::CheckFormPermission() { - auto isSaCall = AAFwk::PermissionVerification::GetInstance()->IsSACall(); - if (isSaCall) { - return true; + return true; +} + +bool FormMgrService::CheckFormPermission(const std::string &bundleName) const +{ + if (bundleName.empty()) { + APP_LOGE("%{public}s fail, bundleName can not be empty", __func__); + return false; } - auto isCallingPerm = AAFwk::PermissionVerification::GetInstance()->VerifyCallingPermission( - AppExecFwk::Constants::PERMISSION_REQUIRE_FORM); - if (isCallingPerm) { - return true; + int result = PermissionKit::VerifyPermission(bundleName, Constants::PERMISSION_REQUIRE_FORM, 0); + if (result != PermissionState::PERMISSION_GRANTED) { + APP_LOGW("permission = %{public}s, bundleName = %{public}s, result = %{public}d", + Constants::PERMISSION_REQUIRE_FORM.c_str(), bundleName.c_str(), result); } - APP_LOGE("Permission verification failed"); - return false; + return result == PermissionState::PERMISSION_GRANTED; } /** diff --git a/services/formmgr/src/form_provider_mgr.cpp b/services/formmgr/src/form_provider_mgr.cpp index e0e786ff7bf8020ee9dac41fe3b253335e53c6f3..b58231bc150cf50183330d0948e77ddf75ee7a34 100644 --- a/services/formmgr/src/form_provider_mgr.cpp +++ b/services/formmgr/src/form_provider_mgr.cpp @@ -370,7 +370,7 @@ int FormProviderMgr::MessageEvent(const int64_t formId, const FormRecord &record void FormProviderMgr::IncreaseTimerRefreshCount(const int64_t formId) { FormRecord record; - if (!FormDataMgr::GetInstance().GetFormRecord(formId, record)) { + if (FormDataMgr::GetInstance().GetFormRecord(formId, record)) { APP_LOGE("%{public}s failed, not exist such form:%{public}" PRId64 ".", __func__, formId); return; } diff --git a/services/formmgr/src/form_timer_mgr.cpp b/services/formmgr/src/form_timer_mgr.cpp index 509a0528976557572c0096969853c84c5c7cacf0..036190e94927477537bcbf0f310b6901b8ebe565 100644 --- a/services/formmgr/src/form_timer_mgr.cpp +++ b/services/formmgr/src/form_timer_mgr.cpp @@ -829,7 +829,7 @@ bool FormTimerMgr::UpdateAtTimerAlarm() return true; } - long nextWakeUpTime = findedItem.updateAtTime; + int nextWakeUpTime = findedItem.updateAtTime; tmAtTime.tm_sec = 0; tmAtTime.tm_hour = findedItem.refreshTask.hour; tmAtTime.tm_min = findedItem.refreshTask.min; diff --git a/services/test/moduletest/ability_mgr_service_test/BUILD.gn b/services/test/moduletest/ability_mgr_service_test/BUILD.gn index 62b4ad566d4f4ac33546a811127546078275e935..7114e02f0f5adefb6775bfa4383513d9c4d5abeb 100644 --- a/services/test/moduletest/ability_mgr_service_test/BUILD.gn +++ b/services/test/moduletest/ability_mgr_service_test/BUILD.gn @@ -48,6 +48,7 @@ ohos_moduletest("ability_mgr_module_test") { "//foundation/aafwk/standard/services/abilitymgr/src/connection_record.cpp", "//foundation/aafwk/standard/services/abilitymgr/src/data_ability_manager.cpp", "//foundation/aafwk/standard/services/abilitymgr/src/data_ability_record.cpp", + "//foundation/aafwk/standard/services/abilitymgr/src/kernal_system_app_manager.cpp", "//foundation/aafwk/standard/services/abilitymgr/src/launch_param.cpp", "//foundation/aafwk/standard/services/abilitymgr/src/lifecycle_deal.cpp", "//foundation/aafwk/standard/services/abilitymgr/src/lifecycle_state_info.cpp", @@ -88,7 +89,6 @@ ohos_moduletest("ability_mgr_module_test") { "${aafwk_path}/interfaces/innerkits/app_manager:app_manager", "${innerkits_path}/uri_permission:uri_permission_mgr", "${innerkits_path}/want:want", - "${services_path}/common:perm_verification", "//base/account/os_account/frameworks/osaccount/native:os_account_innerkits", "//base/global/i18n_standard/frameworks/intl:intl_util", "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", diff --git a/services/test/moduletest/ability_mgr_service_test/ability_mgr_module_test.cpp b/services/test/moduletest/ability_mgr_service_test/ability_mgr_module_test.cpp index 12e14d6aecf4c8fe4c7f72c1abf18cf7f653b95b..c6e97ec55511bb5477e7982d0f7bca3833966702 100644 --- a/services/test/moduletest/ability_mgr_service_test/ability_mgr_module_test.cpp +++ b/services/test/moduletest/ability_mgr_service_test/ability_mgr_module_test.cpp @@ -195,6 +195,8 @@ static void OnStartAms() AbilityMgrModuleTest::abilityMgrServ_->SetStackManager(userId, true); AbilityMgrModuleTest::abilityMgrServ_->stackManagers_.emplace(0, AbilityMgrModuleTest::abilityMgrServ_->GetStackManager()); + AbilityMgrModuleTest::abilityMgrServ_->systemAppManager_ = std::make_shared(userId); + EXPECT_TRUE(AbilityMgrModuleTest::abilityMgrServ_->systemAppManager_); AbilityMgrModuleTest::abilityMgrServ_->eventLoop_->Run(); diff --git a/services/test/moduletest/ability_record_test/BUILD.gn b/services/test/moduletest/ability_record_test/BUILD.gn index e59b1ed29369c908def3f67aaf3ac9b214f820fa..7c35ff46dcba1b63e4772e2ddfac9701d2ce500c 100644 --- a/services/test/moduletest/ability_record_test/BUILD.gn +++ b/services/test/moduletest/ability_record_test/BUILD.gn @@ -50,6 +50,7 @@ ohos_moduletest("AbilityRecordModuleTest") { "${services_path}/abilitymgr/src/connection_record.cpp", "${services_path}/abilitymgr/src/data_ability_manager.cpp", "${services_path}/abilitymgr/src/data_ability_record.cpp", + "${services_path}/abilitymgr/src/kernal_system_app_manager.cpp", "${services_path}/abilitymgr/src/launch_param.cpp", "${services_path}/abilitymgr/src/lifecycle_deal.cpp", "${services_path}/abilitymgr/src/lifecycle_state_info.cpp", @@ -91,7 +92,6 @@ ohos_moduletest("AbilityRecordModuleTest") { "${innerkits_path}/base:base", "${innerkits_path}/uri_permission:uri_permission_mgr", "${innerkits_path}/want:want", - "${services_path}/common:perm_verification", "//base/account/os_account/frameworks/osaccount/native:os_account_innerkits", "//base/global/i18n_standard/frameworks/intl:intl_util", "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", diff --git a/services/test/moduletest/ability_stack_test/BUILD.gn b/services/test/moduletest/ability_stack_test/BUILD.gn index d90794db209e66a982fa3de90fe1856ba7f75371..59960e6fc515e296dcd91497d71defbdefde6452 100644 --- a/services/test/moduletest/ability_stack_test/BUILD.gn +++ b/services/test/moduletest/ability_stack_test/BUILD.gn @@ -48,6 +48,7 @@ ohos_moduletest("ability_stack_module_test") { "//foundation/aafwk/standard/services/abilitymgr/src/connection_record.cpp", "//foundation/aafwk/standard/services/abilitymgr/src/data_ability_manager.cpp", "//foundation/aafwk/standard/services/abilitymgr/src/data_ability_record.cpp", + "//foundation/aafwk/standard/services/abilitymgr/src/kernal_system_app_manager.cpp", "//foundation/aafwk/standard/services/abilitymgr/src/launch_param.cpp", "//foundation/aafwk/standard/services/abilitymgr/src/lifecycle_deal.cpp", "//foundation/aafwk/standard/services/abilitymgr/src/lifecycle_state_info.cpp", @@ -90,7 +91,6 @@ ohos_moduletest("ability_stack_module_test") { "${innerkits_path}/base:base", "${innerkits_path}/uri_permission:uri_permission_mgr", "${innerkits_path}/want:want", - "${services_path}/common:perm_verification", "//base/account/os_account/frameworks/osaccount/native:os_account_innerkits", "//base/global/i18n_standard/frameworks/intl:intl_util", "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", diff --git a/services/test/moduletest/ability_stack_test/ability_stack_module_test.cpp b/services/test/moduletest/ability_stack_test/ability_stack_module_test.cpp index d6ba767c0a7534ad452688d0d69d94ab1cfa4e2a..666c937d822970f78e8eac4b0541370a440b014b 100644 --- a/services/test/moduletest/ability_stack_test/ability_stack_module_test.cpp +++ b/services/test/moduletest/ability_stack_test/ability_stack_module_test.cpp @@ -97,6 +97,8 @@ void AbilityStackModuleTest::OnStartabilityMs(std::shared_ptrGetUserId(); abilityMs->SetStackManager(userId, true); abilityMs->stackManagers_.emplace(0, abilityMs->GetStackManager()); + abilityMs->systemAppManager_ = std::make_shared(userId); + EXPECT_TRUE(abilityMs->systemAppManager_); abilityMs->eventLoop_->Run(); return; } diff --git a/services/test/moduletest/common/ams/ability_running_record_test/BUILD.gn b/services/test/moduletest/common/ams/ability_running_record_test/BUILD.gn index d7c077e9022f93bade57d66758b8c16765d2bc67..16ca5ba126c887c707a1459f77639b8d7b7e8325 100755 --- a/services/test/moduletest/common/ams/ability_running_record_test/BUILD.gn +++ b/services/test/moduletest/common/ams/ability_running_record_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# Copyright (c) 2021 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -24,10 +24,7 @@ ohos_moduletest("AmsAbilityRunningRecordModuleTest") { ] sources = [ "ams_ability_running_record_module_test.cpp" ] - deps = [ - "${services_path}/common:perm_verification", - "${services_path}/test/moduletest/common/ams:appmgr_mst_source", - ] + deps = [ "${services_path}/test/moduletest/common/ams:appmgr_mst_source" ] external_deps = [ "ipc:ipc_core" ] } diff --git a/services/test/moduletest/common/ams/app_life_cycle_test/BUILD.gn b/services/test/moduletest/common/ams/app_life_cycle_test/BUILD.gn index 690a1c2fedaa7604ebe62b6ea03faf760417ae21..0a03ebe4df9c01bf2239499c0def04999d16ab2f 100755 --- a/services/test/moduletest/common/ams/app_life_cycle_test/BUILD.gn +++ b/services/test/moduletest/common/ams/app_life_cycle_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# Copyright (c) 2021 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -25,10 +25,7 @@ ohos_moduletest("AmsAppLifeCycleModuleTest") { ] sources = [ "ams_app_life_cycle_module_test.cpp" ] - deps = [ - "${services_path}/common:perm_verification", - "${services_path}/test/moduletest/common/ams:appmgr_mst_source", - ] + deps = [ "${services_path}/test/moduletest/common/ams:appmgr_mst_source" ] external_deps = [ "ipc:ipc_core" ] } diff --git a/services/test/moduletest/common/ams/app_life_cycle_test/ams_app_life_cycle_module_test.cpp b/services/test/moduletest/common/ams/app_life_cycle_test/ams_app_life_cycle_module_test.cpp index 745b7d82bfea9de8702e305fdc7267cec5a6463d..d6b39eb576442e7595d0e710c993a02e9f52de9f 100755 --- a/services/test/moduletest/common/ams/app_life_cycle_test/ams_app_life_cycle_module_test.cpp +++ b/services/test/moduletest/common/ams/app_life_cycle_test/ams_app_life_cycle_module_test.cpp @@ -920,6 +920,14 @@ HWTEST_F(AmsAppLifeCycleModuleTest, StateChange_010, TestSize.Level3) std::vector allRunningProcessInfo; serviceInner_->GetAllRunningProcesses(allRunningProcessInfo); EXPECT_EQ(allRunningProcessInfo.size(), size_t(APPLICATION_NUM)); + + serviceInner_->StopAllProcess(); + + for (int i = 0; i < APPLICATION_NUM; i++) { + serviceInner_->OnRemoteDied(mockAppScheduler[i]); // A faked death recipient. + auto record = serviceInner_->GetAppRunningRecordByAppRecordId(recordId[i]); + EXPECT_EQ(nullptr, record); + } } /* diff --git a/services/test/moduletest/common/ams/app_mgr_service_test/BUILD.gn b/services/test/moduletest/common/ams/app_mgr_service_test/BUILD.gn index 6d7015098076f2c9fa373be012fb42d1bd7c8d0a..d14fc2bb5af3117cb1a866935ca30180ebf3a30e 100755 --- a/services/test/moduletest/common/ams/app_mgr_service_test/BUILD.gn +++ b/services/test/moduletest/common/ams/app_mgr_service_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# Copyright (c) 2021 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -28,7 +28,6 @@ ohos_moduletest("AmsAppMgrServiceModuleTest") { ] deps = [ - "${services_path}/common:perm_verification", "${services_path}/test/moduletest/common/ams:appmgr_mst_source", "//base/global/i18n_standard/frameworks/intl:intl_util", ] diff --git a/services/test/moduletest/common/ams/app_mgr_service_test/ams_app_mgr_service_module_test.cpp b/services/test/moduletest/common/ams/app_mgr_service_test/ams_app_mgr_service_module_test.cpp index c590912c2899fc580a3052155bfa0f874ed433db..abb68fa83aa7fc4e762c39a0dcc95891cc7348bc 100644 --- a/services/test/moduletest/common/ams/app_mgr_service_test/ams_app_mgr_service_module_test.cpp +++ b/services/test/moduletest/common/ams/app_mgr_service_test/ams_app_mgr_service_module_test.cpp @@ -327,6 +327,42 @@ HWTEST_F(AppMgrServiceModuleTest, ClearUpApplicationData_001, TestSize.Level1) } } +/* + * Feature: AppMgrService + * Function: IsBackgroundRunningRestricted + * SubFunction: NA + * FunctionPoints: AppMgrService => AppMgrServiceInner: IsBackgroundRunningRestricted + * CaseDescription: Check IsBackgroundRunningRestricted. + */ +HWTEST_F(AppMgrServiceModuleTest, IsBackgroundRunningRestricted_001, TestSize.Level1) +{ + EXPECT_TRUE(appMgrService_); + EXPECT_TRUE(mockAppMgrServiceInner_); + + std::string testAppName("testApp"); + bool testResult = false; + Semaphore sem(0); + + auto mockHandler = [&testResult, testAppName, &sem](const std::string &appName) { + testResult = (appName == testAppName); + sem.Post(); + return ERR_OK; + }; + + for (int i = 0; i < COUNT; ++i) { + testResult = false; + + EXPECT_CALL(*mockAppMgrServiceInner_, IsBackgroundRunningRestricted(_)).Times(1).WillOnce(Invoke(mockHandler)); + + auto result = appMgrService_->IsBackgroundRunningRestricted(testAppName); + + sem.Wait(); + + EXPECT_TRUE(testResult); + EXPECT_EQ(result, ERR_OK); + } +} + /* * Feature: AppMgrService * Function: GetAllRunningProcesses diff --git a/services/test/moduletest/common/ams/app_recent_list_test/BUILD.gn b/services/test/moduletest/common/ams/app_recent_list_test/BUILD.gn index b174fb58595aed9aa82dfb63a54ef04ac44ec3b3..fc6c4758cf3f10f0c0b56416990e09742c412fb6 100755 --- a/services/test/moduletest/common/ams/app_recent_list_test/BUILD.gn +++ b/services/test/moduletest/common/ams/app_recent_list_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# Copyright (c) 2021 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -24,10 +24,7 @@ ohos_moduletest("AmsAppRecentListModuleTest") { ] sources = [ "ams_app_recent_list_module_test.cpp" ] - deps = [ - "${services_path}/common:perm_verification", - "${services_path}/test/moduletest/common/ams:appmgr_mst_source", - ] + deps = [ "${services_path}/test/moduletest/common/ams:appmgr_mst_source" ] external_deps = [ "ipc:ipc_core" ] } diff --git a/services/test/moduletest/common/ams/app_running_record_test/BUILD.gn b/services/test/moduletest/common/ams/app_running_record_test/BUILD.gn index a300e9b5f69f459576d50a5250abffd1dc7cc8fd..5a949c9b30c66e705614d8266a0525221b7995f8 100755 --- a/services/test/moduletest/common/ams/app_running_record_test/BUILD.gn +++ b/services/test/moduletest/common/ams/app_running_record_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# Copyright (c) 2021 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -25,10 +25,7 @@ ohos_moduletest("AmsAppRunningRecordModuleTest") { ] sources = [ "ams_app_running_record_module_test.cpp" ] - deps = [ - "${services_path}/common:perm_verification", - "${services_path}/test/moduletest/common/ams:appmgr_mst_source", - ] + deps = [ "${services_path}/test/moduletest/common/ams:appmgr_mst_source" ] external_deps = [ "ipc:ipc_core" ] } diff --git a/services/test/moduletest/common/ams/app_service_flow_test/BUILD.gn b/services/test/moduletest/common/ams/app_service_flow_test/BUILD.gn index c88dc7bf73bc87346e908c21e62ce43756d33eb8..71c4adaef32c30f8ea48274bf5eaf7faef2fffdb 100755 --- a/services/test/moduletest/common/ams/app_service_flow_test/BUILD.gn +++ b/services/test/moduletest/common/ams/app_service_flow_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# Copyright (c) 2021 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -23,10 +23,7 @@ ohos_moduletest("AmsAppServiceFlowModuleTest") { [ "//base/hiviewdfx/hilog/interfaces/native/innerkits/include/" ] sources = [ "ams_app_service_flow_module_test.cpp" ] - deps = [ - "${services_path}/common:perm_verification", - "${services_path}/test/moduletest/common/ams:appmgr_mst_source", - ] + deps = [ "${services_path}/test/moduletest/common/ams:appmgr_mst_source" ] external_deps = [ "ipc:ipc_core" ] } diff --git a/services/test/moduletest/common/ams/ipc_ams_mgr_test/BUILD.gn b/services/test/moduletest/common/ams/ipc_ams_mgr_test/BUILD.gn index 2f17712cfc4791a2c9a3f9d706f9fdd31b68567a..81dff48201ce3477e93f998779225d8c7bca7f2a 100755 --- a/services/test/moduletest/common/ams/ipc_ams_mgr_test/BUILD.gn +++ b/services/test/moduletest/common/ams/ipc_ams_mgr_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# Copyright (c) 2021 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -33,7 +33,6 @@ ohos_moduletest("AmsIpcAmsmgrModuleTest") { deps = [ "${appexecfwk_path}/libs/libeventhandler:libeventhandler_target", "${services_path}/appmgr/test:appmgr_test_source", - "${services_path}/common:perm_verification", "${services_path}/test/moduletest/common/ams:appmgr_mst_source", ] diff --git a/services/test/moduletest/common/ams/ipc_app_mgr_test/BUILD.gn b/services/test/moduletest/common/ams/ipc_app_mgr_test/BUILD.gn index d177076a30c39c5611200bac94636fb50be49ab6..7e8d703699985ccf009e2ce8fb06392bbaf55021 100755 --- a/services/test/moduletest/common/ams/ipc_app_mgr_test/BUILD.gn +++ b/services/test/moduletest/common/ams/ipc_app_mgr_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# Copyright (c) 2021 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -23,10 +23,7 @@ ohos_moduletest("AmsIpcAppmgrModuleTest") { sources = [ "ams_ipc_app_mgr_module_test.cpp" ] - deps = [ - "${services_path}/common:perm_verification", - "${services_path}/test/moduletest/common/ams:appmgr_mst_source", - ] + deps = [ "${services_path}/test/moduletest/common/ams:appmgr_mst_source" ] external_deps = [ "ipc:ipc_core" ] } diff --git a/services/test/moduletest/common/ams/ipc_app_mgr_test/ams_ipc_app_mgr_module_test.cpp b/services/test/moduletest/common/ams/ipc_app_mgr_test/ams_ipc_app_mgr_module_test.cpp index d161ac575939b5eb1be6632cb9f3c10e556b20a8..caf863ae46c4cccec695e057ebdae030fd3392e9 100644 --- a/services/test/moduletest/common/ams/ipc_app_mgr_test/ams_ipc_app_mgr_module_test.cpp +++ b/services/test/moduletest/common/ams/ipc_app_mgr_test/ams_ipc_app_mgr_module_test.cpp @@ -231,6 +231,37 @@ HWTEST_F(AmsIpcAppmgrModuleTest, ExcuteAppmgrIPCInterface_007, TestSize.Level3) } } +/* + * Feature: ApplicationFramework + * Function: AppManagerService + * SubFunction: AppmgrIPCInterface + * FunctionPoints: test IsBackgroundRunningRestricted API,then check the function whether is good or not + * EnvConditions: system running normally + * CaseDescription: excute IsBackgroundRunningRestricted API 10000 times + */ +HWTEST_F(AmsIpcAppmgrModuleTest, ExcuteAppmgrIPCInterface_008, TestSize.Level3) +{ + for (int i = 0; i < COUNT; i++) { + sptr mockMockAppMgr(new MockMockAppMgrService()); + sptr appMgrClient = iface_cast(mockMockAppMgr); + std::string testBundleName("testApp"); + bool testResult = false; + + auto mockHandler = [&](const std::string &name) { + testResult = (name == testBundleName); + mockMockAppMgr->Post(); + return 0; + }; + + EXPECT_CALL(*mockMockAppMgr, IsBackgroundRunningRestricted(_)).WillOnce(Invoke(mockHandler)); + + appMgrClient->IsBackgroundRunningRestricted(testBundleName); + mockMockAppMgr->Wait(); + + EXPECT_TRUE(testResult); + } +} + /* * Feature: ApplicationFramework * Function: AppManagerService diff --git a/services/test/moduletest/common/ams/ipc_app_scheduler_test/BUILD.gn b/services/test/moduletest/common/ams/ipc_app_scheduler_test/BUILD.gn index f7a3e7f6f671469fa3f5920c26d4f006127d23b6..2f51d57cbe151aeb965d46ae73d51d3ab83bd0a9 100755 --- a/services/test/moduletest/common/ams/ipc_app_scheduler_test/BUILD.gn +++ b/services/test/moduletest/common/ams/ipc_app_scheduler_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# Copyright (c) 2021 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -22,10 +22,7 @@ ohos_moduletest("AmsIpcAppSchedulerModuleTest") { include_dirs = [] sources = [ "ams_ipc_app_scheduler_module_test.cpp" ] - deps = [ - "${services_path}/common:perm_verification", - "${services_path}/test/moduletest/common/ams:appmgr_mst_source", - ] + deps = [ "${services_path}/test/moduletest/common/ams:appmgr_mst_source" ] external_deps = [ "ipc:ipc_core" ] } diff --git a/services/test/moduletest/common/ams/process_optimizer_uba_test/BUILD.gn b/services/test/moduletest/common/ams/process_optimizer_uba_test/BUILD.gn index 4274b41385ecbb0348c914ebd70d49d131ffe5a7..8277f2720da8a3cb9afb387c5fec9b7347589b5c 100644 --- a/services/test/moduletest/common/ams/process_optimizer_uba_test/BUILD.gn +++ b/services/test/moduletest/common/ams/process_optimizer_uba_test/BUILD.gn @@ -29,10 +29,7 @@ ohos_moduletest("AmsProcessOptimizerModuleTest") { sources = [ "ams_process_optimizer_uba_module_test.cpp" ] - deps = [ - "${services_path}/common:perm_verification", - "${services_path}/test/moduletest/common/ams:appmgr_mst_source", - ] + deps = [ "${services_path}/test/moduletest/common/ams:appmgr_mst_source" ] external_deps = [ "hiviewdfx_hilog_native:libhilog", diff --git a/services/test/moduletest/common/ams/service_app_spawn_client_test/BUILD.gn b/services/test/moduletest/common/ams/service_app_spawn_client_test/BUILD.gn index 6240f1cf7210b331078c5f5b8727588475d6a64f..b81874150a2046a2d8f678bb6554d6f4f3ee1cd2 100755 --- a/services/test/moduletest/common/ams/service_app_spawn_client_test/BUILD.gn +++ b/services/test/moduletest/common/ams/service_app_spawn_client_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# Copyright (c) 2021 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -29,7 +29,6 @@ ohos_moduletest("AmsServiceAppSpawnClientModuleTest") { ] deps = [ - "${services_path}/common:perm_verification", "${services_path}/test/moduletest/common/ams:appmgr_mst_source", "//base/global/i18n_standard/frameworks/intl:intl_util", ] diff --git a/services/test/moduletest/common/ams/service_event_drive_test/BUILD.gn b/services/test/moduletest/common/ams/service_event_drive_test/BUILD.gn index 46b188d1397118b61c05530f54f0ac41a46d0cfb..42b2dec3580e9943c853ba3590d105656ab7792c 100755 --- a/services/test/moduletest/common/ams/service_event_drive_test/BUILD.gn +++ b/services/test/moduletest/common/ams/service_event_drive_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# Copyright (c) 2021 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -30,7 +30,6 @@ ohos_moduletest("AmsServiceEventDriveModuleTest") { ] deps = [ - "${services_path}/common:perm_verification", "${services_path}/test/moduletest/common/ams:appmgr_mst_source", "//base/global/i18n_standard/frameworks/intl:intl_util", ] diff --git a/services/test/moduletest/common/ams/service_start_process_test/BUILD.gn b/services/test/moduletest/common/ams/service_start_process_test/BUILD.gn index 8074d13a6032fd70248bcffde41a92cf77d86f27..b66d65a9261b6223826a61c72ab85b515018683b 100755 --- a/services/test/moduletest/common/ams/service_start_process_test/BUILD.gn +++ b/services/test/moduletest/common/ams/service_start_process_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# Copyright (c) 2021 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -27,7 +27,6 @@ ohos_moduletest("AmsServiceStartModuleTest") { ] deps = [ - "${services_path}/common:perm_verification", "${services_path}/test/moduletest/common/ams:appmgr_mst_source", "//base/global/i18n_standard/frameworks/intl:intl_util", ] diff --git a/services/test/moduletest/dump_module_test/BUILD.gn b/services/test/moduletest/dump_module_test/BUILD.gn index 39647a0f3cff86eeab9bc98eb599632b3034efb4..3dda95945a9ead35e8d0b2bf5f037b929b59d60f 100755 --- a/services/test/moduletest/dump_module_test/BUILD.gn +++ b/services/test/moduletest/dump_module_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# Copyright (c) 2021 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -48,7 +48,6 @@ ohos_moduletest("dump_module_test") { "${services_path}/abilitymgr/test/mock/appmgr_test_service:appmgr_test_service", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_appmgr_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", - "${services_path}/common:perm_verification", "//base/global/i18n_standard/frameworks/intl:intl_util", "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", "//foundation/aafwk/standard/frameworks/kits/ability/native:dummy_classes", diff --git a/services/test/moduletest/dump_module_test/dump_module_test.cpp b/services/test/moduletest/dump_module_test/dump_module_test.cpp index 4f106f4a9f375f97df1309b6d3a856dcbf567251..85d1448ceedd944faa0fb15a76c4500d8377eaef 100644 --- a/services/test/moduletest/dump_module_test/dump_module_test.cpp +++ b/services/test/moduletest/dump_module_test/dump_module_test.cpp @@ -144,6 +144,8 @@ void DumpModuleTest::OnStartAms() int userId = g_abilityMs->GetUserId(); g_abilityMs->SetStackManager(userId, true); g_abilityMs->stackManagers_.emplace(0, g_abilityMs->GetStackManager()); + g_abilityMs->systemAppManager_ = std::make_shared(userId); + EXPECT_TRUE(g_abilityMs->systemAppManager_); g_abilityMs->eventLoop_->Run(); GTEST_LOG_(INFO) << "OnStart success"; return; diff --git a/services/test/moduletest/ipc_ability_connect_test/BUILD.gn b/services/test/moduletest/ipc_ability_connect_test/BUILD.gn index 487dc498f07984346ade7e7e2eb7f13aa4d5ca19..639d6687c5d46874922124609c73234134597465 100644 --- a/services/test/moduletest/ipc_ability_connect_test/BUILD.gn +++ b/services/test/moduletest/ipc_ability_connect_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# Copyright (c) 2021 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -31,7 +31,6 @@ ohos_moduletest("IpcAbilityConnectModuleTest") { } deps = [ "${innerkits_path}/want:want", - "${services_path}/common:perm_verification", "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base:appexecfwk_base", "//third_party/googletest:gmock_main", "//third_party/googletest:gtest_main", diff --git a/services/test/moduletest/ipc_ability_mgr_test/BUILD.gn b/services/test/moduletest/ipc_ability_mgr_test/BUILD.gn index 9341420fdc00b830d611c0155698955f4e04468f..56cbc7392031bb22705464a29d95945f25c2b826 100644 --- a/services/test/moduletest/ipc_ability_mgr_test/BUILD.gn +++ b/services/test/moduletest/ipc_ability_mgr_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# Copyright (c) 2021 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -33,7 +33,6 @@ ohos_moduletest("IpcAbilityMgrServiceModuleTest") { deps = [ "${aafwk_path}/interfaces/innerkits/app_manager:app_manager", "${innerkits_path}/want:want", - "${services_path}/common:perm_verification", "//foundation/aafwk/standard/services/abilitymgr:abilityms", "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base:appexecfwk_base", "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_core:appexecfwk_core", diff --git a/services/test/moduletest/ipc_ability_scheduler_test/BUILD.gn b/services/test/moduletest/ipc_ability_scheduler_test/BUILD.gn index 9c07fbc05ca6aa19303aeefbb4ac7a348fb9a952..4d0ca27ff790f0eb7d518b31f22aa2f8c194a381 100644 --- a/services/test/moduletest/ipc_ability_scheduler_test/BUILD.gn +++ b/services/test/moduletest/ipc_ability_scheduler_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# Copyright (c) 2021 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -46,7 +46,6 @@ ohos_moduletest("IpcAbilitySchedulerModuleTest") { } deps = [ "${innerkits_path}/want:want", - "${services_path}/common:perm_verification", "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", "//foundation/aafwk/standard/frameworks/kits/ability/native:dummy_classes", "//foundation/aafwk/standard/interfaces/innerkits/app_manager:app_manager", diff --git a/services/test/moduletest/panding_want_manager_test/BUILD.gn b/services/test/moduletest/panding_want_manager_test/BUILD.gn index 4a483a0f12ed03595599784770efbfb675e8a217..ff50fe35533fa39e3b30db9672b25161d21a6fd5 100755 --- a/services/test/moduletest/panding_want_manager_test/BUILD.gn +++ b/services/test/moduletest/panding_want_manager_test/BUILD.gn @@ -51,7 +51,6 @@ ohos_moduletest("PandingWantMgrTest") { "${innerkits_path}/base:base", "${innerkits_path}/uri_permission:uri_permission_mgr", "${innerkits_path}/want:want", - "${services_path}/common:perm_verification", "//base/account/os_account/frameworks/osaccount/native:os_account_innerkits", "//base/global/i18n_standard/frameworks/intl:intl_util", "//base/hiviewdfx/hiview/adapter/utility:hiview_adapter_utility", diff --git a/test/resource/amssystemtestability/abilitySrc/amsStDataAbility/BUILD.gn b/test/resource/amssystemtestability/abilitySrc/amsStDataAbility/BUILD.gn index 1e0fab8598d55dcc96693697267efddc809957e7..4631a17f0de0c69cf112e02af0fa6b4e7752fab8 100644 --- a/test/resource/amssystemtestability/abilitySrc/amsStDataAbility/BUILD.gn +++ b/test/resource/amssystemtestability/abilitySrc/amsStDataAbility/BUILD.gn @@ -13,7 +13,7 @@ import("//build/ohos.gni") import("//foundation/aafwk/standard/aafwk.gni") -SUBDEMOSYSTEM_DIR = "//foundation/appexecfwk/standard/test/resource/amssystemtestability/abilitySrc/amsStDataAbility" +SUBDEMOSYSTEM_DIR = "${system_test_app_path}/amsStDataAbility" EVENT_DIR = "//base/notification/ces_standard/cesfwk" config("verify_act_ability_config") { diff --git a/test/resource/amssystemtestability/abilitySrc/amsStDataAbility/include/verify_act_data_ability.h b/test/resource/amssystemtestability/abilitySrc/amsStDataAbility/include/verify_act_data_ability.h index b8967ce1f7bf707f6cd1a4b0b590a8807a824ad6..9f87dcda97ccf6d489008501095208b98ee11a70 100644 --- a/test/resource/amssystemtestability/abilitySrc/amsStDataAbility/include/verify_act_data_ability.h +++ b/test/resource/amssystemtestability/abilitySrc/amsStDataAbility/include/verify_act_data_ability.h @@ -41,13 +41,10 @@ public: virtual int BatchInsert(const Uri &uri, const std::vector &values) override; std::vector> sharedList_; -}; -class InsertTestOpenCallback : public NativeRdb::RdbOpenCallback { -public: - int OnCreate(NativeRdb::RdbStore &rdbStore) override; - int OnUpgrade(NativeRdb::RdbStore &rdbStore, int oldVersion, int newVersion) override; - static const std::string CREATE_TABLE_TEST; + virtual std::vector GetFileTypes(const Uri &uri, const std::string &mimeTypeFilter) override; + virtual Uri NormalizeUri(const Uri &uri) override; + virtual Uri DenormalizeUri(const Uri &uri) override; }; } // namespace AppExecFwk } // namespace OHOS diff --git a/test/resource/amssystemtestability/abilitySrc/amsStDataAbility/src/verify_act_data_ability.cpp b/test/resource/amssystemtestability/abilitySrc/amsStDataAbility/src/verify_act_data_ability.cpp index b5bcbb9676e7a1808257a100d3fb31d57175fd1e..f5887fce9d186dfdfb066bba9d4b2537f655454a 100644 --- a/test/resource/amssystemtestability/abilitySrc/amsStDataAbility/src/verify_act_data_ability.cpp +++ b/test/resource/amssystemtestability/abilitySrc/amsStDataAbility/src/verify_act_data_ability.cpp @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSERETURN_ERROR2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -14,11 +14,13 @@ */ #include "abs_shared_result_set.h" +#include "ability_loader.h" +#include "app_log_wrapper.h" +#include "data_ability_helper.h" #include "data_ability_predicates.h" +#include "rdb_helper.h" +#include "rdb_open_callback.h" #include "values_bucket.h" - -#include "app_log_wrapper.h" -#include "ability_loader.h" #include "verify_act_data_ability.h" namespace OHOS { @@ -28,8 +30,25 @@ static std::shared_ptr testStore; static const std::string RDB_TEST_PATH = "/data/test/"; static const std::string DATABASE_FILE_NAME = "insert_test.db"; static const std::string DATABASE_NAME = RDB_TEST_PATH + "insert_test.db"; -static const int defaultReturn = 1; -} +static int defaultReturn = 1; +static const double ageI = 24; +static const double salaryI = 2024.20; +static const int returnError = 0; +static const int returnError1 = -1; +static const int returnError2 = -2; +static const int returnError3 = -3; +static const int value1 = 0; +static const int value2 = 1; +static const int value3 = 2; +static const int value4 = 3; +} // namespace + +class InsertTestOpenCallback : public NativeRdb::RdbOpenCallback { +public: + int OnCreate(NativeRdb::RdbStore &rdbStore) override; + int OnUpgrade(NativeRdb::RdbStore &rdbStore, int oldVersion, int newVersion) override; + static const std::string CREATE_TABLE_TEST; +}; const std::string InsertTestOpenCallback::CREATE_TABLE_TEST = std::string("CREATE TABLE IF NOT EXISTS test ") + std::string("(id INTEGER PRIMARY KEY AUTOINCREMENT, " @@ -38,12 +57,14 @@ const std::string InsertTestOpenCallback::CREATE_TABLE_TEST = int InsertTestOpenCallback::OnCreate(NativeRdb::RdbStore &store) { + APP_LOGI("VerifyActDataAbility OnCreate"); return store.ExecuteSql(CREATE_TABLE_TEST); } int InsertTestOpenCallback::OnUpgrade(NativeRdb::RdbStore &store, int oldVersion, int newVersion) { - return 0; + APP_LOGI("VerifyActDataAbility OnUpgrade"); + return returnError; } void VerifyActDataAbility::OnStart(const Want &want) @@ -56,48 +77,149 @@ void VerifyActDataAbility::OnStart(const Want &want) int VerifyActDataAbility::Insert(const Uri &uri, const NativeRdb::ValuesBucket &value) { APP_LOGI("VerifyActDataAbility <<<>>>"); + std::shared_ptr dataUri = std::make_shared("dataability:///com.ix.VerifyActDataAbility"); + auto notify = DataAbilityHelper::Creator(GetContext(), dataUri); + if (notify == nullptr) { + APP_LOGE("VerifyActDataAbility <<<>>>"); + return returnError; + } + notify->NotifyChange(*dataUri); + + APP_LOGI("VerifyActDataAbility Insert uri.ToString = %{public}s", uri.ToString().c_str()); + APP_LOGI("VerifyActDataAbility Insert dataUri.ToString = %{public}s", dataUri->ToString().c_str()); + APP_LOGI("VerifyActDataAbility uri.Equals = %{public}d", uri.Equals(*dataUri)); + if (uri.Equals(*dataUri) != 1) { + return returnError1; + } + + defaultReturn = 1; + std::map valuesMap; + value.GetAll(valuesMap); + int valuesMapSize = valuesMap.size(); + APP_LOGI("VerifyActDataAbility value = %{public}d", valuesMapSize); + if (!valuesMapSize) + return returnError2; + for (auto item = valuesMap.begin(); item != valuesMap.end(); item++) { + auto valueFirst = item->first; + auto valueSecond = item->second; + int iEOK = 0; + APP_LOGI("VerifyActDataAbility valueSecond.GetType[%{public}d]]", valueSecond.GetType()); + if (valueFirst.compare("name") == 0) { + std::string val; + iEOK = valueSecond.GetString(val); + APP_LOGI("VerifyActDataAbility it iEOK[%{public}d]]", iEOK); + APP_LOGI("VerifyActDataAbility it[%{public}s],[%{public}s]", valueFirst.c_str(), val.c_str()); + if (val.compare("ActsDataAbilityHelperTest")) { + return returnError2; + break; + } + } else if (valueFirst.compare("age") == 0) { + double age; + iEOK = valueSecond.GetDouble(age); + APP_LOGI("VerifyActDataAbility it iEOK[%{public}d]", iEOK); + APP_LOGI("VerifyActDataAbility it[%{public}s],[%{public}f]", valueFirst.c_str(), age); + if (age != ageI) { + return returnError2; + break; + } + } else if (valueFirst.compare("salary") == 0) { + double salary; + iEOK = valueSecond.GetDouble(salary); + APP_LOGI("VerifyActDataAbility it iEOK[%{public}d]]", iEOK); + APP_LOGI("VerifyActDataAbility it[%{public}s],[%{public}f]", valueFirst.c_str(), salary); + if (salary != salaryI) { + return returnError2; + break; + } + } else { + APP_LOGI("VerifyActDataAbility it default[%{public}s]", valueFirst.c_str()); + break; + } + } + + int errCode = 0; + std::string dbDir = GetDatabaseDir(); + NativeRdb::RdbStoreConfig config(dbDir + "/" + DATABASE_FILE_NAME); + InsertTestOpenCallback helper; + testStore = NativeRdb::RdbHelper::GetRdbStore(config, 1, helper, errCode); + APP_LOGI("VerifyActDataAbility Insert Patch %{public}s", (dbDir + "/" + DATABASE_FILE_NAME).c_str()); + + if (testStore == nullptr) { + APP_LOGI("VerifyActDataAbility <<<>>> testStore is nullptr, data will be empty"); + return returnError3; + } + + int64_t id; + int insertError; + if ((insertError = testStore->Insert(id, "test", value)) != 0) { + APP_LOGE("VerifyActDataAbility <<<>>> store->Insert Error %{public}d", insertError); + return insertError; + } + return defaultReturn; } std::shared_ptr VerifyActDataAbility::Query( const Uri &uri, const std::vector &columns, const NativeRdb::DataAbilityPredicates &predicates) { + APP_LOGI("VerifyActDataAbility <<<>>>"); + std::shared_ptr dataUri = std::make_shared("dataability:///com.ix.VerifyActDataAbility"); + + APP_LOGI("VerifyActDataAbility Query uri.ToString = %{public}s", uri.ToString().c_str()); + APP_LOGI("VerifyActDataAbility Query dataUri.ToString = %{public}s", dataUri->ToString().c_str()); + APP_LOGI("VerifyActDataAbility uri.Equals = %{public}d", uri.Equals(*dataUri)); + if (uri.Equals(*dataUri) != 1) { + return nullptr; + } + int indexI = 0; + for (const auto &item : columns) { + switch (indexI++) { + case value1: + if (item.compare("value1") != 0) + return nullptr; + break; + case value2: + if (item.compare("value2") != 0) + return nullptr; + break; + case value3: + if (item.compare("value3") != 0) + return nullptr; + break; + case value4: + if (item.compare("value4") != 0) + return nullptr; + break; + default: + APP_LOGI("VerifyActDataAbility indexI = [%{public}d]]", indexI); + } + } + + APP_LOGI("VerifyActDataAbility Query predicates"); + APP_LOGI("VerifyActDataAbility Query predicates.Is = %{public}d", predicates.IsRawSelection()); + APP_LOGI("VerifyActDataAbility Query predicates.Get = %{public}d", predicates.GetJudgeSource()); + int errCode = 0; std::string dbDir = GetDatabaseDir(); NativeRdb::RdbStoreConfig config(dbDir + "/" + DATABASE_FILE_NAME); InsertTestOpenCallback helper; testStore = NativeRdb::RdbHelper::GetRdbStore(config, 1, helper, errCode); - APP_LOGI("VerifyActDataAbility <<<>>> Patch %{public}s", (dbDir + "/" + DATABASE_FILE_NAME).c_str()); - - int64_t id; - NativeRdb::ValuesBucket values; - int idValue = 1; - int age = 18; - double salary = 100.5; - - values.PutInt("id", idValue); - values.PutString("name", std::string("zhangsan")); - values.PutInt("age", age); - values.PutDouble("salary", salary); - values.PutBlob("blobType", std::vector {1, 2, 3}); + APP_LOGI("VerifyActDataAbility Query Patch %{public}s", (dbDir + "/" + DATABASE_FILE_NAME).c_str()); if (testStore == nullptr) { APP_LOGI("VerifyActDataAbility <<<>>> testStore is nullptr, data will be empty"); return nullptr; } - if (testStore->Replace(id, "test", values) != 0) { - APP_LOGE("VerifyActDataAbility <<<>>> store->Replace Error"); - return nullptr; - } - std::unique_ptr rresultSet = - testStore->QuerySql("SELECT * FROM test WHERE name = ?", std::vector {"zhangsan"}); + testStore->QuerySql("SELECT * FROM test WHERE name = ?" , + std::vector {"ActsDataAbilityHelperTest"}); if (rresultSet == nullptr) { APP_LOGE("VerifyActDataAbility <<<>>> rresultSet is nullptr"); return nullptr; } + APP_LOGE("VerifyActDataAbility <<<>>> ret(rresultSet.release()"); std::shared_ptr ret(rresultSet.release()); sharedList_.push_back(ret); return ret; @@ -107,30 +229,291 @@ int VerifyActDataAbility::Update( const Uri &uri, const NativeRdb::ValuesBucket &value, const NativeRdb::DataAbilityPredicates &predicates) { APP_LOGI("VerifyActDataAbility <<<>>>"); + std::shared_ptr dataUri = std::make_shared("dataability:///com.ix.VerifyActDataAbility"); + auto notify = DataAbilityHelper::Creator(GetContext(), dataUri); + if (notify == nullptr) { + APP_LOGE("VerifyActDataAbility <<<>>>"); + return returnError; + } + notify->NotifyChange(*dataUri); + + APP_LOGI("VerifyActDataAbility Update uri.ToString = %{public}s", uri.ToString().c_str()); + APP_LOGI("VerifyActDataAbility Update dataUri.ToString = %{public}s", dataUri->ToString().c_str()); + APP_LOGI("VerifyActDataAbility uri.Equals = %{public}d", uri.Equals(*dataUri)); + if (uri.Equals(*dataUri) != 1) { + return returnError1; + } + + defaultReturn = 1; + std::map valuesMap; + value.GetAll(valuesMap); + int valuesMapSize = valuesMap.size(); + APP_LOGI("VerifyActDataAbility value = %{public}d", valuesMapSize); + if (!valuesMapSize) + return returnError2; + for (auto item = valuesMap.begin(); item != valuesMap.end(); item++) { + auto valueFirst = item->first; + auto valueSecond = item->second; + APP_LOGI("VerifyActDataAbility valueSecond.GetType[%{public}d]]", valueSecond.GetType()); + if (valueFirst.compare("name") == 0) { + std::string val; + valueSecond.GetString(val); + APP_LOGI("VerifyActDataAbility it[%{public}s],[%{public}s]", valueFirst.c_str(), val.c_str()); + if (val.compare("ActsDataAbilityHelperTest")) { + return returnError2; + break; + } + } else if (valueFirst.compare("age") == 0) { + double age; + valueSecond.GetDouble(age); + APP_LOGI("VerifyActDataAbility it[%{public}s],[%{public}f]", valueFirst.c_str(), age); + if (age != ageI) { + return returnError2; + break; + } + } else if (valueFirst.compare("salary") == 0) { + double salary; + valueSecond.GetDouble(salary); + APP_LOGI("VerifyActDataAbility it[%{public}s],[%{public}f]", valueFirst.c_str(), salary); + if (salary != salaryI) { + return returnError2; + break; + } + } else { + APP_LOGI("VerifyActDataAbility it default[%{public}s]", valueFirst.c_str()); + break; + } + } + APP_LOGI("VerifyActDataAbility Update predicates = %{public}d", predicates.IsRawSelection()); + APP_LOGI("VerifyActDataAbility Update predicates.Get = %{public}d", predicates.GetJudgeSource()); + + int errCode = 0; + std::string dbDir = GetDatabaseDir(); + NativeRdb::RdbStoreConfig config(dbDir + "/" + DATABASE_FILE_NAME); + InsertTestOpenCallback helper; + testStore = NativeRdb::RdbHelper::GetRdbStore(config, 1, helper, errCode); + APP_LOGI("VerifyActDataAbility Update Patch %{public}s", (dbDir + "/" + DATABASE_FILE_NAME).c_str()); + + if (testStore == nullptr) { + APP_LOGI("VerifyActDataAbility <<<>>> testStore is nullptr, data will be empty"); + return returnError3; + } + + int changedRows; + int updatError; + if ((updatError = testStore->Update(changedRows, "test", value)) != 0) { + APP_LOGE("VerifyActDataAbility <<<>>> store->Replace changedRows %{public}d Error %{public}d", + changedRows, + updatError); + return updatError; + } return defaultReturn; } int VerifyActDataAbility::Delete(const Uri &uri, const NativeRdb::DataAbilityPredicates &predicates) { APP_LOGI("VerifyActDataAbility <<<>>>"); + std::shared_ptr dataUri = std::make_shared("dataability:///com.ix.VerifyActDataAbility"); + auto notify = DataAbilityHelper::Creator(GetContext(), dataUri); + if (notify == nullptr) { + APP_LOGE("VerifyActDataAbility <<<>>>"); + return returnError; + } + notify->NotifyChange(*dataUri); + + defaultReturn = 1; + APP_LOGI("VerifyActDataAbility Delete uri.ToString = %{public}s", uri.ToString().c_str()); + APP_LOGI("VerifyActDataAbility Delete dataUri.ToString = %{public}s", dataUri->ToString().c_str()); + APP_LOGI("VerifyActDataAbility uri.Equals is = %{public}d", uri.Equals(*dataUri)); + if (uri.Equals(*dataUri) != 1) { + return returnError; + } + APP_LOGI("VerifyActDataAbility Delete predicates.Is = %{public}d", predicates.IsRawSelection()); + APP_LOGI("VerifyActDataAbility Delete predicates.Get = %{public}d", predicates.GetJudgeSource()); + + int errCode = 0; + std::string dbDir = GetDatabaseDir(); + NativeRdb::RdbStoreConfig config(dbDir + "/" + DATABASE_FILE_NAME); + InsertTestOpenCallback helper; + testStore = NativeRdb::RdbHelper::GetRdbStore(config, 1, helper, errCode); + APP_LOGI("VerifyActDataAbility Delete Patch %{public}s", (dbDir + "/" + DATABASE_FILE_NAME).c_str()); + + if (testStore == nullptr) { + APP_LOGI("VerifyActDataAbility <<<>>> testStore is nullptr, data will be empty"); + return returnError3; + } + + int changedRows; + int deleteError; + if ((deleteError = testStore->Delete(changedRows, "test")) != 0) { + APP_LOGE("VerifyActDataAbility <<<>>> store->Delete changedRows %{public}d Error %{public}d", + changedRows, + deleteError); + return deleteError; + } return defaultReturn; } std::string VerifyActDataAbility::GetType(const Uri &uri) { APP_LOGI("VerifyActDataAbility <<<>>>"); + APP_LOGI("VerifyActDataAbility GetType uri = %{public}s", uri.ToString().c_str()); + std::shared_ptr dataUri = std::make_shared("dataability:///com.ix.VerifyActDataAbility3"); + APP_LOGI("VerifyActDataAbility GetType dataUri.ToString = %{public}s", dataUri->ToString().c_str()); + APP_LOGI("VerifyActDataAbility uri.Equals = %{public}d", uri.Equals(*dataUri)); + if (uri.Equals(*dataUri) == 1) { + return nullptr; + } std::string retval(uri.ToString()); return retval; } int VerifyActDataAbility::OpenFile(const Uri &uri, const std::string &mode) { APP_LOGI("VerifyActDataAbility <<<>>>"); - return 0; + std::shared_ptr dataUri = std::make_shared("dataability:///com.ix.VerifyActDataAbility"); + defaultReturn = 1; + APP_LOGI("VerifyActDataAbility Delete uri.ToString = %{public}s", uri.ToString().c_str()); + APP_LOGI("VerifyActDataAbility Delete dataUri.ToString = %{public}s", dataUri->ToString().c_str()); + APP_LOGI("VerifyActDataAbility uri.Equals = %{public}d", uri.Equals(*dataUri)); + if (uri.Equals(*dataUri) != 1) { + return returnError1; + } + APP_LOGI("VerifyActDataAbility OpenFile mode = %{public}s", mode.c_str()); + if (!(mode.compare("r") == 0 || mode.compare("w") == 0 || mode.compare("wt") == 0 || mode.compare("wa") == 0 || + mode.compare("rw") == 0 || mode.compare("rwt") == 0)) { + if (mode.compare("A1@k#4%$,.<>)(oioiu*((*&(&*giIGT^%&^Ug;sdfk;losd*7873iug8%&^$&%]ERFUy&^%&&R7") == 0) { + defaultReturn = returnError2; + } else + defaultReturn = returnError3; + } + APP_LOGI("VerifyActDataAbility OpenFile defaultReturn = %{public}d", defaultReturn); + return defaultReturn; } int VerifyActDataAbility::BatchInsert(const Uri &uri, const std::vector &values) { APP_LOGI("VerifyActDataAbility <<<>>>"); - return Ability::BatchInsert(uri, values); + std::shared_ptr dataUri = std::make_shared("dataability:///com.ix.VerifyActDataAbility"); + defaultReturn = 1; + APP_LOGI("VerifyActDataAbility BatchInsert uri.ToString = %{public}s", uri.ToString().c_str()); + APP_LOGI("VerifyActDataAbility BatchInsert dataUri.ToString = %{public}s", dataUri->ToString().c_str()); + APP_LOGI("VerifyActDataAbility uri.Equals = %{public}d", uri.Equals(*dataUri)); + if (uri.Equals(*dataUri) != 1) { + return returnError1; + } + + defaultReturn = 1; + std::map valuesMap; + for (auto it = values.begin(); it != values.end(); it++) { + it->GetAll(valuesMap); + int valuesMapSize = values.size(); + APP_LOGI("VerifyActDataAbility value = %{public}d", valuesMapSize); + if (!valuesMapSize) + return returnError2; + for (auto item = valuesMap.begin(); item != valuesMap.end(); item++) { + auto valueFirst = item->first; + auto valueSecond = item->second; + APP_LOGI("VerifyActDataAbility valueSecond.GetType[%{public}d]]", valueSecond.GetType()); + if (valueFirst.compare("name") == 0) { + std::string val; + valueSecond.GetString(val); + APP_LOGI("VerifyActDataAbility it[%{public}s],[%{public}s]", valueFirst.c_str(), val.c_str()); + if (val.compare("ActsDataAbilityHelperTest")) { + return returnError2; + break; + } + } else if (valueFirst.compare("age") == 0) { + double age; + valueSecond.GetDouble(age); + APP_LOGI("VerifyActDataAbility it[%{public}s],[%{public}f]", valueFirst.c_str(), age); + if (age != ageI) { + return returnError2; + break; + } + } else if (valueFirst.compare("salary") == 0) { + double salary; + valueSecond.GetDouble(salary); + APP_LOGI("VerifyActDataAbility it[%{public}s],[%{public}f]", valueFirst.c_str(), salary); + if (salary != salaryI) { + return returnError2; + break; + } + } else { + APP_LOGI("VerifyActDataAbility it default[%{public}s]", valueFirst.c_str()); + break; + } + } + } + + int retAbilityBatchInsert = Ability::BatchInsert(uri, values); + APP_LOGI("VerifyActDataAbility BatchInsert retAbility = %{public}d", retAbilityBatchInsert); + return retAbilityBatchInsert; +} +std::vector VerifyActDataAbility::GetFileTypes(const Uri &uri, const std::string &mimeTypeFilter) +{ + APP_LOGI("VerifyActDataAbility <<<>>>"); + std::shared_ptr dataUri = std::make_shared("dataability:///com.ix.VerifyActDataAbility"); + defaultReturn = 1; + APP_LOGI("VerifyActDataAbility Delete uri.ToString = %{public}s", uri.ToString().c_str()); + APP_LOGI("VerifyActDataAbility Delete dataUri.ToString = %{public}s", dataUri->ToString().c_str()); + APP_LOGI("VerifyActDataAbility uri.Equals = %{public}d", uri.Equals(*dataUri)); + std::vector vectorFileTypes; + if (uri.Equals(*dataUri) != 1) { + APP_LOGE("VerifyActDataAbility uri.Equals(*dataUri) != 1"); + vectorFileTypes.push_back("Uri error"); + return vectorFileTypes; + } + + if (mimeTypeFilter.compare("*/*") == 0) { + vectorFileTypes.push_back("hap"); + vectorFileTypes.push_back("jpg"); + vectorFileTypes.push_back("image/png"); + } else if (mimeTypeFilter.compare("image/*") == 0) { + vectorFileTypes.push_back("image/png"); + } else if (mimeTypeFilter.compare("*/jpg") == 0) { + vectorFileTypes.push_back("jpg"); + } else if (mimeTypeFilter.compare("returnUndefined") == 0) { + return {}; + } + + return vectorFileTypes; } +Uri VerifyActDataAbility::NormalizeUri(const Uri &uri) +{ + APP_LOGI("VerifyActDataAbility <<<>>>"); + APP_LOGI("VerifyActDataAbility NormalizeUri uri = %{public}s", uri.ToString().c_str()); + std::shared_ptr dataUri = std::make_shared("dataability:///com.ix.VerifyActDataAbility"); + std::shared_ptr dataUri3 = std::make_shared("dataability:///com.ix.VerifyActDataAbility3"); + Uri dataUriNull(""); + Uri dataUriError("errorUri"); + APP_LOGI("VerifyActDataAbility NormalizeUri dataUri.ToString = %{public}s", dataUri->ToString().c_str()); + APP_LOGI("VerifyActDataAbility uri.Equals = %{public}d", uri.Equals(*dataUri)); + if (uri.Equals(*dataUri) != 1) { + if (uri.Equals(*dataUri3) == 1) { + return dataUriNull; + } + return dataUriError; + } + return uri; +} + +Uri VerifyActDataAbility::DenormalizeUri(const Uri &uri) +{ + APP_LOGI("VerifyActDataAbility <<<>>>"); + APP_LOGI("VerifyActDataAbility DenormalizeUri uri = %{public}s", uri.ToString().c_str()); + std::shared_ptr dataUri = std::make_shared("dataability:///com.ix.VerifyActDataAbility"); + std::shared_ptr dataUri3 = std::make_shared("dataability:///com.ix.VerifyActDataAbility3"); + Uri dataUriNull(""); + Uri dataUriError("errorUri"); + APP_LOGI("VerifyActDataAbility DenormalizeUri dataUri.ToString = %{public}s", dataUri->ToString().c_str()); + APP_LOGI("VerifyActDataAbility uri.Equals = %{public}d", uri.Equals(*dataUri)); + + if (uri.Equals(*dataUri) != 1) { + if (uri.Equals(*dataUri3) == 1) { + return dataUriNull; + } + return dataUriError; + } + return uri; +} REGISTER_AA(VerifyActDataAbility); } // namespace AppExecFwk } // namespace OHOS diff --git a/zidl/bundle.json b/zidl/bundle.json deleted file mode 100644 index 5127a051270eadcfa02b16b87ed6df6283e59b82..0000000000000000000000000000000000000000 --- a/zidl/bundle.json +++ /dev/null @@ -1,37 +0,0 @@ -{ - "name": "@ohos/zidl", - "description": "提供自动生成Extension 服务端及客户端接口文件的能力", - "version": "3.1", - "license": "Apache License 2.0", - "publishAs": "code-segment", - "segment": { - "destPath": "foundation/aafwk/standard/zidl" - }, - "dirs": {}, - "scripts": {}, - "component": { - "name": "zidl", - "subsystem": "aafwk", - "syscap": [], - "features": [], - "adapted_system_type": [ - "standard" - ], - "rom": "", - "ram": "", - "deps": { - "components": [ - "hiviewdfx_hilog_native", - "ipc", - "samgr_standard", - "utils_base" - ], - "third_party": [] - }, - "build": { - "sub_component": [], - "inner_kits": [], - "test": [] - } - } -} \ No newline at end of file diff --git a/zidl/test/native/BUILD.gn b/zidl/test/native/BUILD.gn deleted file mode 100644 index 8dc9839a534d3031f43865f20e9d586abb410ba7..0000000000000000000000000000000000000000 --- a/zidl/test/native/BUILD.gn +++ /dev/null @@ -1,69 +0,0 @@ -# Copyright (C) 2021 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//build/ohos.gni") - -IPC_SUBSYSTEM_DIR = "//foundation/communication/ipc" -ZIDL_TEST_DIR = "//foundation/aafwk/standard/zidl/test/native" - -config("ipc_test_config") { - include_dirs = [ - "//utils/native/base/include", - "$ZIDL_TEST_DIR/include", - "$IPC_SUBSYSTEM_DIR/utils/include", - "$IPC_SUBSYSTEM_DIR/ipc/native/src/mock/include", - "//utils/system/safwk/native/include", - ] -} - -ohos_executable("zidl_server_test") { - sources = [ - "./src/main_server.cpp", - "./src/test_service.cpp", - "./src/zidl_test_service_stub.cpp", - ] - - configs = [ ":ipc_test_config" ] - - deps = [ "//utils/native/base:utils" ] - - external_deps = [ - "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_core", - "samgr_standard:samgr_proxy", - ] - - subsystem_name = "aafwk" - part_name = "zidl" -} - -ohos_executable("zidl_client_test") { - sources = [ - "./src/main_client.cpp", - "./src/test_client.cpp", - "./src/zidl_test_service_proxy.cpp", - ] - - configs = [ ":ipc_test_config" ] - - deps = [ "//utils/native/base:utils" ] - - external_deps = [ - "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_core", - "samgr_standard:samgr_proxy", - ] - - subsystem_name = "aafwk" - part_name = "zidl" -} diff --git a/zidl/test/native/include/izidl_test_service.h b/zidl/test/native/include/izidl_test_service.h deleted file mode 100644 index 3f6308363a862f1f80097c1ee05e42f1674e2e20..0000000000000000000000000000000000000000 --- a/zidl/test/native/include/izidl_test_service.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_IZIDLTESTSERVICE_H -#define OHOS_IZIDLTESTSERVICE_H - -#include -#include - -namespace OHOS { -class IZidlTestService : public IRemoteBroker { -public: - DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.IZidlTestService"); - - virtual ErrCode TestIntTransaction( - /* [in] */ int _data, - /* [out] */ int& result) = 0; - - virtual ErrCode TestStringTransaction( - /* [in] */ const std::string& _data) = 0; -}; -} // namespace OHOS -#endif // OHOS_IZIDLTESTSERVICE_H - diff --git a/zidl/test/native/include/test_client.h b/zidl/test/native/include/test_client.h deleted file mode 100644 index 4d54213003bfe72fd624092c6743bf2ae1e8f840..0000000000000000000000000000000000000000 --- a/zidl/test/native/include/test_client.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_IPC_TEST_SERVICE_CLIENT_H -#define OHOS_IPC_TEST_SERVICE_CLIENT_H - -#include "ipc_debug.h" -#include "log_tags.h" -#include "zidl_test_service_proxy.h" - -namespace OHOS { -class TestClient { -public: - int ConnectService(); - void StartIntTransaction(); - void StartStringTransaction(); -private: - static constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_ID_IPC, "TestClient" }; - sptr testService_; -}; -} // namespace OHOS -#endif // OHOS_IPC_TEST_SERVICE_CLIENT_H diff --git a/zidl/test/native/include/test_service.h b/zidl/test/native/include/test_service.h deleted file mode 100644 index 2c29658c7610e136a528f3f3173ac0162ace7a14..0000000000000000000000000000000000000000 --- a/zidl/test/native/include/test_service.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_IPC_TEST_SERVICE_H -#define OHOS_IPC_TEST_SERVICE_H - -#include "hilog/log.h" -#include "log_tags.h" -#include "zidl_test_service_stub.h" - -namespace OHOS { -class TestService : public ZidlTestServiceStub { -public: - TestService(); - ~TestService(); - static int Instantiate(); - ErrCode TestIntTransaction(int data, int &rep) override; - ErrCode TestStringTransaction(const std::string& data) override; -private: - static constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_ID_IPC, "TestService" }; -}; -} // namespace OHOS -#endif // OHOS_IPC_TEST_SERVICE_H - diff --git a/zidl/test/native/include/zidl_test_service_proxy.h b/zidl/test/native/include/zidl_test_service_proxy.h deleted file mode 100644 index 56a6dcef68c68525aebcce630ac661f606776469..0000000000000000000000000000000000000000 --- a/zidl/test/native/include/zidl_test_service_proxy.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_ZIDLTESTSERVICEPROXY_H -#define OHOS_ZIDLTESTSERVICEPROXY_H - -#include - -#include "izidl_test_service.h" - -namespace OHOS { -class ZidlTestServiceProxy : public IRemoteProxy { -public: - explicit ZidlTestServiceProxy( - /* [in] */ const sptr& remote) - : IRemoteProxy(remote) - {} - - virtual ~ZidlTestServiceProxy() - {} - - ErrCode TestIntTransaction( - /* [in] */ int _data, - /* [out] */ int& result) override; - - ErrCode TestStringTransaction( - /* [in] */ const std::string& _data) override; - -private: - static constexpr int COMMAND_TEST_INT_TRANSACTION = MIN_TRANSACTION_ID + 0; - static constexpr int COMMAND_TEST_STRING_TRANSACTION = MIN_TRANSACTION_ID + 1; - - static inline BrokerDelegator delegator_; -}; -} // namespace OHOS -#endif // OHOS_ZIDLTESTSERVICEPROXY_H - diff --git a/zidl/test/native/include/zidl_test_service_stub.h b/zidl/test/native/include/zidl_test_service_stub.h deleted file mode 100644 index eed5cd8875acf4f1e1e41479ca8c74b852c109e4..0000000000000000000000000000000000000000 --- a/zidl/test/native/include/zidl_test_service_stub.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_ZIDLTESTSERVICESTUB_H -#define OHOS_ZIDLTESTSERVICESTUB_H - -#include - -#include "izidl_test_service.h" - -namespace OHOS { -class ZidlTestServiceStub : public IRemoteStub { -public: - int OnRemoteRequest( - /* [in] */ uint32_t code, - /* [in] */ MessageParcel& data, - /* [out] */ MessageParcel& reply, - /* [in] */ MessageOption& option) override; - -private: - static constexpr int COMMAND_TEST_INT_TRANSACTION = MIN_TRANSACTION_ID + 0; - static constexpr int COMMAND_TEST_STRING_TRANSACTION = MIN_TRANSACTION_ID + 1; -}; -} // namespace OHOS -#endif // OHOS_ZIDLTESTSERVICESTUB_H - diff --git a/zidl/test/native/src/main_client.cpp b/zidl/test/native/src/main_client.cpp deleted file mode 100644 index 7238b197b761aae55e91afc61943e2e57bdb0a79..0000000000000000000000000000000000000000 --- a/zidl/test/native/src/main_client.cpp +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -#include "ipc_debug.h" -#include "ipc_skeleton.h" -#include "log_tags.h" -#include "test_client.h" - -using namespace OHOS; -using namespace OHOS::HiviewDFX; -static constexpr HiLogLabel LABEL = { LOG_CORE, LOG_ID_IPC, "IPCTestClient" }; - -enum TestCommand { - TEST_CMD_NONE = 0, - TEST_CMD_INT_TRANS = 1, - TEST_CMD_STRING_TRANS = 2 -}; - -namespace { -std::vector GetArgvOptions(int argc, char **argv) -{ - std::vector argvOptions; - for (int i = 1; i < argc; i++) { - argvOptions.emplace_back(std::string(argv[i])); - } - return argvOptions; -} -} - -int main(int argc, char *argv[]) -{ - TestCommand commandId = TestCommand::TEST_CMD_INT_TRANS; - if (argc > 1) { - commandId = TestCommand(atoi(argv[1])); - } else { - ZLOGE(LABEL, "unknown command"); - } - std::vector argvOptions; - argvOptions = GetArgvOptions(argc, argv); - std::unique_ptr testClient = std::make_unique(); - if (testClient->ConnectService()) { - return -1; - } - - ZLOGE(LABEL, "commandId= : %{public}d", commandId); - switch (commandId) { - case TestCommand::TEST_CMD_INT_TRANS: - testClient->StartIntTransaction(); - break; - case TestCommand::TEST_CMD_STRING_TRANS: - testClient->StartStringTransaction(); - break; - default: - ZLOGI(LABEL, "main arg error"); - break; - } - - IPCSkeleton::JoinWorkThread(); - return 0; -} diff --git a/zidl/test/native/src/main_server.cpp b/zidl/test/native/src/main_server.cpp deleted file mode 100644 index 0765721662f13cc7186abd8f38f65ae55ab2e32c..0000000000000000000000000000000000000000 --- a/zidl/test/native/src/main_server.cpp +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "ipc_debug.h" -#include "ipc_skeleton.h" -#include "log_tags.h" -#include "test_service.h" - -using namespace OHOS; -using namespace OHOS::HiviewDFX; - -[[maybe_unused]]static constexpr HiLogLabel LABEL = { LOG_CORE, LOG_ID_IPC, "IPCTestServer" }; - -int main(int argc __attribute__((unused)), char **argv __attribute__((unused))) -{ - TestService::Instantiate(); - ZLOGI(LABEL, "call StartThreadPool"); - IPCSkeleton::JoinWorkThread(); -} diff --git a/zidl/test/native/src/test_client.cpp b/zidl/test/native/src/test_client.cpp deleted file mode 100644 index b2e7abd8e58246ac15daa516e5d6448c387610d9..0000000000000000000000000000000000000000 --- a/zidl/test/native/src/test_client.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "test_client.h" - -#include "if_system_ability_manager.h" -#include "ipc_debug.h" -#include "ipc_skeleton.h" -#include "iservice_registry.h" -#include "system_ability_definition.h" - -namespace OHOS { -int TestClient::ConnectService() -{ - auto saMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - if (saMgr == nullptr) { - ZLOGE(LABEL, "get registry fail"); - return -1; - } - - sptr object = saMgr->GetSystemAbility(IPC_TEST_SERVICE); - - if (object != nullptr) { - ZLOGE(LABEL, "Got test Service object"); - testService_ = (new (std::nothrow) ZidlTestServiceProxy(object)); - } - - if (testService_ == nullptr) { - ZLOGE(LABEL, "Could not find Test Service!"); - return -1; - } - - return 0; -} - -void TestClient::StartIntTransaction() -{ - if (testService_ != nullptr) { - ZLOGE(LABEL, "StartIntTransaction"); - [[maybe_unused]] int result = 0; - testService_->TestIntTransaction(1234, result); // 1234 : test number - ZLOGE(LABEL, "Rec result from server %{public}d.", result); - } -} - -void TestClient::StartStringTransaction() -{ - if (testService_ != nullptr) { - ZLOGI(LABEL, "StartIntTransaction"); - testService_->TestStringTransaction("ZIDL Test"); - } -} -} // namespace OHOS diff --git a/zidl/test/native/src/test_service.cpp b/zidl/test/native/src/test_service.cpp deleted file mode 100644 index acf2f6346c17ab84290836cc40f4043b6bead25c..0000000000000000000000000000000000000000 --- a/zidl/test/native/src/test_service.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "test_service.h" - -#include - -#include "if_system_ability_manager.h" -#include "ipc_debug.h" -#include "ipc_skeleton.h" -#include "iservice_registry.h" -#include "system_ability_definition.h" - -namespace OHOS { -using namespace OHOS::HiviewDFX; - -int TestService::Instantiate() -{ - ZLOGI(LABEL, "%{public}s call in", __func__); - auto saMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - if (saMgr == nullptr) { - ZLOGE(LABEL, "%{public}s:fail to get Registry", __func__); - return -ENODEV; - } - - sptr newInstance = new TestService(); - int result = saMgr->AddSystemAbility(IPC_TEST_SERVICE, newInstance); - ZLOGI(LABEL, "%{public}s: IPC_TEST_SERVICE result = %{public}d", __func__, result); - return result; -} - -TestService::TestService() -{ -} - -TestService::~TestService() -{ -} - -ErrCode TestService::TestIntTransaction(int data, int &rep) -{ - ZLOGE(LABEL, " TestService:read from client data = %{public}d", data); - rep = data + data; - return ERR_NONE; -} - -ErrCode TestService::TestStringTransaction(const std::string &data) -{ - ZLOGE(LABEL, "TestService:read string from client data = %{public}s", data.c_str()); - return data.size(); -} -} // namespace OHOS diff --git a/zidl/test/native/src/zidl_test_service_proxy.cpp b/zidl/test/native/src/zidl_test_service_proxy.cpp deleted file mode 100644 index 314cadb6a2439edfa10ee96f7592b1e1398496d7..0000000000000000000000000000000000000000 --- a/zidl/test/native/src/zidl_test_service_proxy.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "zidl_test_service_proxy.h" - -namespace OHOS { -ErrCode ZidlTestServiceProxy::TestIntTransaction( - /* [in] */ int _data, - /* [out] */ int& result) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - - data.WriteInt32(_data); - - int32_t st = Remote()->SendRequest(COMMAND_TEST_INT_TRANSACTION, data, reply, option); - if (st != ERR_NONE) { - return st; - } - - ErrCode ec = reply.ReadInt32(); - if (FAILED(ec)) { - return ec; - } - - result = reply.ReadInt32(); - return ERR_OK; -} - -ErrCode ZidlTestServiceProxy::TestStringTransaction( - /* [in] */ const std::string& _data) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - - data.WriteString16(Str8ToStr16(_data)); - - int32_t st = Remote()->SendRequest(COMMAND_TEST_STRING_TRANSACTION, data, reply, option); - if (st != ERR_NONE) { - return st; - } - - ErrCode ec = reply.ReadInt32(); - if (FAILED(ec)) { - return ec; - } - - return ERR_OK; -} -} // namespace OHOS diff --git a/zidl/test/native/src/zidl_test_service_stub.cpp b/zidl/test/native/src/zidl_test_service_stub.cpp deleted file mode 100644 index adf63cd1dec69afef101456b7cffca5198ed5be7..0000000000000000000000000000000000000000 --- a/zidl/test/native/src/zidl_test_service_stub.cpp +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "zidl_test_service_stub.h" - -namespace OHOS { -int ZidlTestServiceStub::OnRemoteRequest( - /* [in] */ uint32_t code, - /* [in] */ MessageParcel& data, - /* [out] */ MessageParcel& reply, - /* [in] */ MessageOption& option) -{ - switch (code) { - case COMMAND_TEST_INT_TRANSACTION: { - int _data = data.ReadInt32(); - int result; - ErrCode ec = TestIntTransaction(_data, result); - reply.WriteInt32(ec); - if (SUCCEEDED(ec)) { - reply.WriteInt32(result); - } - return ERR_NONE; - } - case COMMAND_TEST_STRING_TRANSACTION: { - std::string _data = Str16ToStr8(data.ReadString16()); - ErrCode ec = TestStringTransaction(_data); - reply.WriteInt32(ec); - return ERR_NONE; - } - default: - return IPCObjectStub::OnRemoteRequest(code, data, reply, option); - } - - return ERR_TRANSACTION_FAILED; -} -} // namespace OHOS diff --git a/zidl/test/zidlgen/IZidlTestService.zidl b/zidl/test/zidlgen/IZidlTestService.zidl deleted file mode 100644 index 8d2fa0b91c567c7389072eccfddf51cded5daa18..0000000000000000000000000000000000000000 --- a/zidl/test/zidlgen/IZidlTestService.zidl +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -interface OHOS.IZidlTestService { - int TestIntTransaction([in] int data); - void TestStringTransaction([in] String data); -} \ No newline at end of file diff --git a/zidl/test/zidlgen/zidl b/zidl/test/zidlgen/zidl deleted file mode 100644 index c3bde7295221617c5bdc4e7a695702a580ac0c22..0000000000000000000000000000000000000000 Binary files a/zidl/test/zidlgen/zidl and /dev/null differ