1 /*
2 * Copyright (c) 2022-2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "enterprise_conn_manager.h"
17
18 #include <if_system_ability_manager.h>
19 #include <ipc_skeleton.h>
20 #include <iservice_registry.h>
21 #include <string_ex.h>
22 #include <system_ability_definition.h>
23
24 #include "edm_log.h"
25 #include "extension_manager_client.h"
26 #include "extension_manager_proxy.h"
27 #include "managed_event.h"
28
29 using namespace OHOS::AAFwk;
30
31 namespace OHOS {
32 namespace EDM {
CreateAdminConnection(const AAFwk::Want & want,uint32_t code,uint32_t userId,bool isOnAdminEnabled)33 sptr<IEnterpriseConnection> EnterpriseConnManager::CreateAdminConnection(const AAFwk::Want &want,
34 uint32_t code, uint32_t userId, bool isOnAdminEnabled)
35 {
36 sptr<IEnterpriseConnection> connection(new (std::nothrow) EnterpriseAdminConnection(want, code, userId,
37 isOnAdminEnabled));
38 return connection;
39 }
40
CreateBundleConnection(const AAFwk::Want & want,uint32_t code,uint32_t userId,const std::string & bundleName,const int32_t accountId)41 sptr<IEnterpriseConnection> EnterpriseConnManager::CreateBundleConnection(const AAFwk::Want &want,
42 uint32_t code, uint32_t userId, const std::string &bundleName, const int32_t accountId)
43 {
44 sptr<IEnterpriseConnection> connection(new (std::nothrow) EnterpriseBundleConnection(want,
45 code, userId, bundleName, accountId));
46 return connection;
47 }
48
CreateUpdateConnection(const AAFwk::Want & want,uint32_t userId,const UpdateInfo & updateInfo)49 sptr<IEnterpriseConnection> EnterpriseConnManager::CreateUpdateConnection(const AAFwk::Want &want,
50 uint32_t userId, const UpdateInfo &updateInfo)
51 {
52 sptr<IEnterpriseConnection> connection(new (std::nothrow)EnterpriseUpdateConnection(want,
53 static_cast<uint32_t>(ManagedEvent::SYSTEM_UPDATE), userId, updateInfo));
54 return connection;
55 }
56
ConnectAbility(const sptr<IEnterpriseConnection> & connection)57 bool EnterpriseConnManager::ConnectAbility(const sptr<IEnterpriseConnection>& connection)
58 {
59 if (connection == nullptr) {
60 return false;
61 }
62 int32_t ret = ExtensionManagerClient::GetInstance().ConnectEnterpriseAdminExtensionAbility(connection->GetWant(),
63 connection, nullptr, connection->GetUserId());
64 if (ret != ERR_OK) {
65 EDMLOGE("EnterpriseConnManager::ConnectAbility connect extenison ability failed:%{public}d.", ret);
66 return false;
67 }
68 return true;
69 }
70 } // namespace EDM
71 } // namespace OHOS
72