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_extension.h"
17
18 #include "enterprise_admin_extension_context.h"
19 #include "hilog_wrapper.h"
20 #include "js_enterprise_admin_extension.h"
21 #include "runtime.h"
22
23 namespace OHOS {
24 namespace EDM {
25 using namespace OHOS::AppExecFwk;
Create(const std::unique_ptr<AbilityRuntime::Runtime> & runtime)26 EnterpriseAdminExtension* EnterpriseAdminExtension::Create(const std::unique_ptr<AbilityRuntime::Runtime>& runtime)
27 {
28 if (!runtime) {
29 return new EnterpriseAdminExtension();
30 }
31 HILOG_INFO("EnterpriseAdminExtension::Create runtime");
32 switch (runtime->GetLanguage()) {
33 case AbilityRuntime::Runtime::Language::JS:
34 return JsEnterpriseAdminExtension::Create(runtime);
35 default:
36 return new EnterpriseAdminExtension();
37 }
38 }
39
Init(const std::shared_ptr<AppExecFwk::AbilityLocalRecord> & record,const std::shared_ptr<AppExecFwk::OHOSApplication> & application,std::shared_ptr<AppExecFwk::AbilityHandler> & handler,const sptr<IRemoteObject> & token)40 void EnterpriseAdminExtension::Init(const std::shared_ptr<AppExecFwk::AbilityLocalRecord>& record,
41 const std::shared_ptr<AppExecFwk::OHOSApplication>& application,
42 std::shared_ptr<AppExecFwk::AbilityHandler>& handler,
43 const sptr<IRemoteObject>& token)
44 {
45 HILOG_INFO("EnterpriseAdminExtension begin init");
46 ExtensionBase<EnterpriseAdminExtensionContext>::Init(record, application, handler, token);
47 }
48
CreateAndInitContext(const std::shared_ptr<AppExecFwk::AbilityLocalRecord> & record,const std::shared_ptr<AppExecFwk::OHOSApplication> & application,std::shared_ptr<AppExecFwk::AbilityHandler> & handler,const sptr<IRemoteObject> & token)49 std::shared_ptr<EnterpriseAdminExtensionContext> EnterpriseAdminExtension::CreateAndInitContext(
50 const std::shared_ptr<AppExecFwk::AbilityLocalRecord>& record,
51 const std::shared_ptr<AppExecFwk::OHOSApplication>& application,
52 std::shared_ptr<AppExecFwk::AbilityHandler>& handler,
53 const sptr<IRemoteObject>& token)
54 {
55 std::shared_ptr<EnterpriseAdminExtensionContext> context =
56 ExtensionBase<EnterpriseAdminExtensionContext>::CreateAndInitContext(record, application, handler, token);
57 if (record == nullptr) {
58 HILOG_ERROR("EnterpriseAdminExtension::CreateAndInitContext record is nullptr");
59 return context;
60 }
61 return context;
62 }
63 } // namespace EDM
64 } // namespace OHOS