• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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_admin_connection.h"
17 
18 #include "admin_manager.h"
19 #include "edm_log.h"
20 #include "enterprise_conn_manager.h"
21 
22 namespace OHOS {
23 namespace EDM {
~EnterpriseAdminConnection()24 EnterpriseAdminConnection::~EnterpriseAdminConnection() {}
25 
SetIsOnAdminEnabled(bool isOnAdminEnabled)26 void EnterpriseAdminConnection::SetIsOnAdminEnabled(bool isOnAdminEnabled)
27 {
28     isOnAdminEnabled_ = isOnAdminEnabled;
29 }
30 
OnAbilityConnectDone(const AppExecFwk::ElementName & element,const sptr<IRemoteObject> & remoteObject,int32_t resultCode)31 void EnterpriseAdminConnection::OnAbilityConnectDone(
32     const AppExecFwk::ElementName& element, const sptr<IRemoteObject>& remoteObject, int32_t resultCode)
33 {
34     EDMLOGI("EnterpriseAdminConnection OnAbilityConnectDone");
35     proxy_ = (new (std::nothrow) EnterpriseAdminProxy(remoteObject));
36     if (!proxy_) {
37         EDMLOGE("EnterpriseAdminConnection get enterpriseAdminProxy failed.");
38         return;
39     }
40     switch (code_) {
41         case IEnterpriseAdmin::COMMAND_ON_ADMIN_ENABLED:
42             if (isOnAdminEnabled_) {
43                 proxy_->OnAdminEnabled();
44             }
45             break;
46         case IEnterpriseAdmin::COMMAND_ON_ADMIN_DISABLED:
47             proxy_->OnAdminDisabled();
48             break;
49         default:
50             return;
51     }
52     EDMLOGI("EnterpriseAdminConnection OnAbilityConnectDone over");
53 }
54 
OnAbilityDisconnectDone(const AppExecFwk::ElementName & element,int32_t resultCode)55 void EnterpriseAdminConnection::OnAbilityDisconnectDone(const AppExecFwk::ElementName& element, int32_t resultCode)
56 {
57     EDMLOGI("EnterpriseAdminConnection OnAbilityDisconnectDone");
58     if (AdminManager::GetInstance()->IsSuperAdmin(want_.GetElement().GetBundleName())) {
59         std::shared_ptr<EnterpriseConnManager> manager = DelayedSingleton<EnterpriseConnManager>::GetInstance();
60         sptr<IEnterpriseConnection> connection =
61             manager->CreateAdminConnection(want_, IEnterpriseAdmin::COMMAND_ON_ADMIN_ENABLED, DEFAULT_USER_ID, false);
62         manager->ConnectAbility(connection);
63     }
64 }
65 }  // namespace EDM
66 }  // namespace OHOS
67