• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021-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
16import BundleMgr from "@ohos.bundle";
17import Context from "application/ServiceExtensionContext";
18import Log from "../Log";
19import SwitchUserManager from "../SwitchUserManager";
20
21const TAG = "BRManager";
22
23export default class BundleManager {
24    static async getResourceManager(tag: string, context: Context, bundleName: string) {
25        Log.showInfo(TAG, `getResourceManager from: ${tag}`);
26        let bundleContext = await context.createBundleContext(bundleName)
27        return await bundleContext.resourceManager;
28    }
29
30    static async getBundleInfo(tag: string, bundleName: string, getInfo:
31    any, requestId?: number) {
32        let userInfo = {
33            userId: requestId ?? (await SwitchUserManager.getInstance().getCurrentUserInfo()).userId,
34        };
35        Log.showDebug(TAG, `getBundleInfo from: ${tag}, userId: ${userInfo.userId}`);
36        return await BundleMgr.getBundleInfo(bundleName, getInfo, userInfo);
37    }
38}