目录

Sideloading (Sideloading Security Control)

This module provides security control capabilities in sideloading scenarios. Apps can determine whether external binary files can be loaded to support sideloading security control services.

Since: 26.0.1

Modules to Import

import { sideloading } from '@kit.DeviceSecurityKit';

sideloading.isExternalBinaryLoadingEnabled

isExternalBinaryLoadingEnabled(): Promise<boolean>

Queries whether a device allows loading external binary files. This API uses a promise to return the result.

Model restriction: This API can be used only in the stage model.

System capability: SystemCapability.Security.SecurityPrivacyServer

Since: 26.0.1

Device behavior differences:

The device type range (PC/2-in-1 device) supported by this API is smaller than the device type range (phone, tablet, and TV) supported by the system capability. Due to hardware capability limitations, calling this API on phones, cars, wearables, or TVs will return error code 1006205002.

Returns

Type Description
Promise<boolean> Promise used to return the result. The value true indicates that external binary files can be loaded, and the value false indicates that external binary files cannot be loaded.

Error codes:

For details about the error codes, please refer to ArkTS API Error Codes.

ID Error Message
1006205000 Internal error. Possible causes: 1.System is busy or resources are insufficient; 2.Abnormal system environment. Please try again later, you can check the logs for more information.
1006205002 Sideloading is not supported.

Example:

import { sideloading } from '@kit.DeviceSecurityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';

const TAG = "SideloadingTest";

try {
  hilog.info(0x0000, TAG, 'isExternalBinaryLoadingEnabled begin.');
  const result: boolean = await sideloading.isExternalBinaryLoadingEnabled();
  hilog.info(0x0000, TAG, 'isExternalBinaryLoadingEnabled result: %{public}s', result.toString());
} catch (err) {
  let e: BusinessError = err as BusinessError;
  hilog.error(0x0000, TAG, 'isExternalBinaryLoadingEnabled failed: %{public}d %{public}s', e.code, e.message);
}

sideloading.enableExternalBinaryLoadingOnSetting

enableExternalBinaryLoadingOnSetting(context: common.Context): Promise<ExternalBinaryLoadingStatus>

Requests the user to set the binary loading control switch in the UIAbility or UIExtensionAbility pop-up window and returns the result of the user's choice. This API uses a promise to return the result.

Model restriction: This API can be used only in the stage model.

System capability: SystemCapability.Security.SecurityPrivacyServer

Since: 26.0.1

Device behavior differences:

The device type range (PC/2-in-1 device) supported by this API is smaller than the device type range (phone, tablet, and TV) supported by the system capability. Due to hardware capability limitations, calling this API on phones, cars, wearables, or TVs will return error code 1006205002.

Parameters

Name Type Description
context common.Context Context of the UIAbility or UIExtensionAbility that loads the external binary file.

Returns

Type Description
Promise<ExternalBinaryLoadingStatus> Promise used to return the external binary file loading status.

Error codes:

For details about the error codes, please refer to ArkTS API Error Codes.

ID Error Message
1006205000 Internal error. Possible causes: 1.System is busy or resources are insufficient; 2.Abnormal system environment. Please try again later, you can check the logs for more information.
1006205001 Invalid parameter. Possible causes: 1. The context is invalid because it does not belong to the application itself.
1006205002 Sideloading is not supported.

Example:

import { sideloading } from '@kit.DeviceSecurityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';

const TAG = "SideloadingTest";

try {
  hilog.info(0x0000, TAG, 'enableExternalBinaryLoadingOnSetting begin.');
  let context = getContext();
  const result: sideloading.ExternalBinaryLoadingStatus = await sideloading.enableExternalBinaryLoadingOnSetting(context);
  hilog.info(0x0000, TAG, 'enableExternalBinaryLoadingOnSetting result: %{public}d', result);
} catch (err) {
  let e: BusinessError = err as BusinessError;
  hilog.error(0x0000, TAG, 'enableExternalBinaryLoadingOnSetting failed: %{public}d %{public}s', e.code, e.message);
}

ExternalBinaryLoadingStatus

Enumerates the external binary file loading statuses.

Model restriction: This API can be used only in the stage model.

System capability: SystemCapability.Security.SecurityPrivacyServer

Since: 26.0.1

Status Value Description
DENY Loading external binary files is not allowed.
ALLOW Loading external binary files is allowed.