

import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION;

export class AppUtils {


  async getAppList() {
    try {
      bundleManager.getAllBundleInfo(bundleFlags, (err, data) => {
        if (err) {
          hilog.error(0x0000, 'testTag', 'getAllBundleInfo failed: %{public}s', err.message);
        } else {
          data.forEach((bundleInfo) => {
            let appInfo = bundleInfo.appInfo;
            hilog.info(0x0000, 'testTag', 'appInfo: %{public}s', JSON.stringify(appInfo));
          });
          hilog.info(0x0000, 'testTag', 'getAllBundleInfo successfully: %{public}s', JSON.stringify(data));
        }
      });
    } catch (err) {
      let message = (err as BusinessError).message;
      //onForeground
      hilog.error(0x0000, 'testTag', 'getAllBundleInfo failed: %{public}s', message);
    }
  }
}