diff --git a/interfaces/innerkits/ability_manager/include/ability_manager_interface.h b/interfaces/innerkits/ability_manager/include/ability_manager_interface.h index a8f5da730a66cefa59e8f5ead23ee35ffe5fe089..447c1c6d5717f6bef76dfd094c533c8bf88512e0 100644 --- a/interfaces/innerkits/ability_manager/include/ability_manager_interface.h +++ b/interfaces/innerkits/ability_manager/include/ability_manager_interface.h @@ -41,6 +41,7 @@ #include "mission_listener_interface.h" #include "mission_info.h" #include "start_options.h" +#include "stop_user_callback.h" namespace OHOS { namespace AAFwk { @@ -527,6 +528,10 @@ public: virtual int MoveMissionToFront(int32_t missionId) = 0; + virtual int StartUser(int userId) = 0; + + virtual int StopUser(int userId, const sptr &callback) = 0; + enum { // ipc id 1-1000 for kit // ipc id for terminating ability (1) @@ -673,6 +678,12 @@ public: // ipc id for get mission snap shot (48) GET_MISSION_SNAPSHOT_BY_ID, + // ipc id for move mission to front (49) + START_USER, + + // ipc id for move mission to front (50) + STOP_USER, + // ipc id 1001-2000 for DMS // ipc id for starting ability (1001) START_ABILITY = 1001, diff --git a/interfaces/innerkits/ability_manager/include/stop_user_callback.h b/interfaces/innerkits/ability_manager/include/stop_user_callback.h new file mode 100644 index 0000000000000000000000000000000000000000..c9e62fae962bcc7803a0d97689df39e682408785 --- /dev/null +++ b/interfaces/innerkits/ability_manager/include/stop_user_callback.h @@ -0,0 +1,35 @@ +/* + * 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_STOP_USER_CALLBACK_H +#define OHOS_AAFWK_STOP_USER_CALLBACK_H + +#include "iremote_broker.h" + +namespace OHOS { +namespace AAFwk { +/** + * @class IStopUserCallback + * stop user callback. + */ +class IStopUserCallback : public OHOS::IRemoteBroker { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"ohos.aafwk.StopUserCallback"); + + virtual void OnStopUserDone(int userId, int errcode) = 0; +}; +} // namespace AAFwk +} // namespace OHOS +#endif // OHOS_AAFWK_STOP_USER_CALLBACK_H \ No newline at end of file diff --git a/services/abilitymgr/include/ability_manager_proxy.h b/services/abilitymgr/include/ability_manager_proxy.h index ee5d9280300ae581d8401b83135c61472d8401a1..9e09a3088d0a1a8acc6be95147b6b9c1688a239d 100644 --- a/services/abilitymgr/include/ability_manager_proxy.h +++ b/services/abilitymgr/include/ability_manager_proxy.h @@ -510,6 +510,10 @@ public: virtual int MoveMissionToFront(int32_t missionId) override; + virtual int StartUser(int userId) override; + + virtual int StopUser(int userId, const sptr &callback) override; + private: template int GetParcelableInfos(MessageParcel &reply, std::vector &parcelableInfos); diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h index 78dfd75dc9147f57ef3c95b09d5c01f942026f20..28cc16439d568e823b610194595556ce931945b8 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -646,6 +646,10 @@ public: */ sptr GetAbilityTokenByMissionId(int32_t missionId); + virtual int StartUser(int userId) override; + + virtual int StopUser(int userId, const sptr &callback) override; + // MSG 0 - 20 represents timeout message static constexpr uint32_t LOAD_TIMEOUT_MSG = 0; static constexpr uint32_t ACTIVE_TIMEOUT_MSG = 1; diff --git a/services/abilitymgr/include/ability_manager_stub.h b/services/abilitymgr/include/ability_manager_stub.h index 13ed51dd0ea3aa639e9e24da24ed48ee11ba7997..fbb6e82b538405cf7fd307f61ef80450c190cc9c 100644 --- a/services/abilitymgr/include/ability_manager_stub.h +++ b/services/abilitymgr/include/ability_manager_stub.h @@ -118,6 +118,8 @@ private: int CleanMissionInner(MessageParcel &data, MessageParcel &reply); int CleanAllMissionsInner(MessageParcel &data, MessageParcel &reply); int MoveMissionToFrontInner(MessageParcel &data, MessageParcel &reply); + int StartUserInner(MessageParcel &data, MessageParcel &reply); + int StopUserInner(MessageParcel &data, MessageParcel &reply); using RequestFuncType = int (AbilityManagerStub::*)(MessageParcel &data, MessageParcel &reply); std::map requestFuncMap_; diff --git a/services/abilitymgr/src/ability_manager_proxy.cpp b/services/abilitymgr/src/ability_manager_proxy.cpp index 60313aafca66e910049b2e9b4624917721416f77..83c95acc546d422cfcb743052f2dedf18fee9306 100644 --- a/services/abilitymgr/src/ability_manager_proxy.cpp +++ b/services/abilitymgr/src/ability_manager_proxy.cpp @@ -1776,5 +1776,53 @@ int AbilityManagerProxy::MoveMissionToFront(int32_t missionId) } return reply.ReadInt32(); } + +int AbilityManagerProxy::StartUser(int userId) +{ + int error; + MessageParcel data; + MessageParcel reply; + MessageOption option; + + if (!WriteInterfaceToken(data)) { + return INNER_ERR; + } + if (!data.WriteInt32(userId)) { + HILOG_ERROR("StartUser:WriteInt32 fail."); + return ERR_INVALID_VALUE; + } + error = Remote()->SendRequest(IAbilityManager::START_USER, data, reply, option); + if (error != NO_ERROR) { + HILOG_ERROR("StartUser:SendRequest error: %d", error); + return error; + } + return reply.ReadInt32(); +} + +int AbilityManagerProxy::StopUser(int userId, const sptr &callback) +{ + int error; + MessageParcel data; + MessageParcel reply; + MessageOption option; + + if (!WriteInterfaceToken(data)) { + return INNER_ERR; + } + if (!data.WriteInt32(userId)) { + HILOG_ERROR("StopUser:WriteInt32 fail."); + return ERR_INVALID_VALUE; + } + if (!data.WriteParcelable(callback->AsObject())) { + HILOG_ERROR("StopUser:write IStopUserCallback fail."); + return ERR_INVALID_VALUE; + } + error = Remote()->SendRequest(IAbilityManager::STOP_USER, data, reply, option); + if (error != NO_ERROR) { + HILOG_ERROR("StopUser:SendRequest error: %d", error); + return error; + } + return reply.ReadInt32(); +} } // namespace AAFwk } // namespace OHOS \ No newline at end of file diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index 18f532650967faedc456ed53ee97eb37f7253e8a..d6afd8de738ba2bce7bd1192922bbddd56f6c30e 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -2438,5 +2438,17 @@ void AbilityManagerService::StartingSettingsDataAbility() want.SetElementName(AbilityConfig::SETTINGS_DATA_BUNDLE_NAME, AbilityConfig::SETTINGS_DATA_ABILITY_NAME); (void)StartAbility(want, DEFAULT_INVAL_VALUE); } + +int AbilityManagerService::StartUser(int userId) +{ + HILOG_DEBUG("%{public}s", __func__); + return 0; +} + +int AbilityManagerService::StopUser(int userId, const sptr &callback) +{ + HILOG_DEBUG("%{public}s", __func__); + return 0; +} } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/src/ability_manager_stub.cpp b/services/abilitymgr/src/ability_manager_stub.cpp index 6b5b6ea239b511858972246e9237c0a317f6c26b..7e74892c8b0840b3d7a7ae77ac5b54ae3eb450f5 100644 --- a/services/abilitymgr/src/ability_manager_stub.cpp +++ b/services/abilitymgr/src/ability_manager_stub.cpp @@ -116,6 +116,8 @@ void AbilityManagerStub::SecondStepInit() requestFuncMap_[CLEAN_MISSION] = &AbilityManagerStub::CleanMissionInner; requestFuncMap_[CLEAN_ALL_MISSIONS] = &AbilityManagerStub::CleanAllMissionsInner; requestFuncMap_[MOVE_MISSION_TO_FRONT] = &AbilityManagerStub::MoveMissionToFrontInner; + requestFuncMap_[START_USER] = &AbilityManagerStub::StartUserInner; + requestFuncMap_[STOP_USER] = &AbilityManagerStub::StopUserInner; } int AbilityManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) @@ -1049,5 +1051,28 @@ int AbilityManagerStub::MoveMissionToFrontInner(MessageParcel &data, MessageParc } return NO_ERROR; } + +int AbilityManagerStub::StartUserInner(MessageParcel &data, MessageParcel &reply) +{ + int32_t userId = data.ReadInt32(); + int result = StartUser(userId); + if (!reply.WriteInt32(result)) { + HILOG_ERROR("StartUser failed."); + return ERR_INVALID_VALUE; + } + return NO_ERROR; +} + +int AbilityManagerStub::StopUserInner(MessageParcel &data, MessageParcel &reply) +{ + int32_t userId = data.ReadInt32(); + auto callback = iface_cast(data.ReadParcelable()); + int result = StopUser(userId, callback); + if (!reply.WriteInt32(result)) { + HILOG_ERROR("StopUser failed."); + return ERR_INVALID_VALUE; + } + return NO_ERROR; +} } // namespace AAFwk } // namespace OHOS