openharmony 鸿蒙 changelogs-usbManager

2026-08-25 浏览 (1)

USB Subsystem Changelog

cl.usbManager.1 Change of Error Code from 202 to 201 for Calling a System API When the ohos.permission.MANAGE_USB_CONFIG Permission Is Missing

Access Level

System API

Reason for the Change

When the system API is called, the ohos.permission.MANAGE_USB_CONFIG permission must be added to the permission field in the system application configuration file. If the permission is not configured, error code 201 is returned.

Change Impact

This change is a non-compatible change.

The following is an example:

import { usbManager } from '@kit.BasicServicesKit';
import { bundleManager } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
let devicesName: string = "1-1";
let tokenId: string = "";

  try {
    let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT;
    bundleManager.getBundleInfoForSelf(bundleFlags).then((bundleInfo) => {
      console.info('testTag', 'getBundleInfoForSelf successfully. Data: %{public}s', JSON.stringify(bundleInfo));
      let token = bundleInfo.appInfo.accessTokenId;
      tokenId = token.toString();
      if (usbManager.addDeviceAccessRight(tokenId, devicesName)) {
        console.log(`Succeed in adding right`);
      }
    }).catch((err : BusinessError) => {
      console.error('testTag getBundleInfoForSelf failed' );
    });
  } catch (err) {
    console.error('testTag failed');
  }

Before change: When the system application calls a system API, if the ohos.permission.MANAGE_USB_CONFIG permission is not configured in the permission field in the configuration file, error code 202 is returned.

After change: When the system application calls a system API, if the ohos.permission.MANAGE_USB_CONFIG permission is not configured in the permission field in the configuration file, error code 201 is returned.

Start API Level

12

Change Since

OpenHarmony SDK 5.1.0.45 and later versions

Key API/Component Changes

APIDescription
addDeviceAccessRight(tokenId: string, deviceName: string): booleanAdded error code 201.
getFunctionsFromString(funcs: string): numberAdded error code 201.
getStringFromFunctions(funcs: FunctionType): stringAdded error code 201.
setDeviceFunctions(funcs: FunctionType): Promise<void>Added error code 201.
getDeviceFunctions(): FunctionTypeAdded error code 201.
getPortList(): Array<USBPort>Added error code 201.
getPortSupportModes(portId: number): PortModeTypeAdded error code 201.
setPortRoleTypes(portId: number, powerRole: PowerRoleType, dataRole: DataRoleType): Promise<void>Added error code 201.

Adaptation Guide

Add error code 201 for the system application to call system APIs when the ohos.permission.MANAGE_USB_CONFIG permission is not configured in the permission field in the system application configuration file.

你可能感兴趣的鸿蒙文章

openharmony 鸿蒙 changelogs-arkcompiler

  • 所属分类: 后端技术
  • 本文标签: 鸿蒙 软件
  • 版权声明: 本文链接 https://seaxiang.com/blog/oDVg1SI2