This module offers unified workspace management capabilities, encompassing creating a workspace, removing a workspace, and subscribing to workspace events, delivering seamless workspace use experience and allowing enterprises to manage workspaces based on their specific service needs.
Since: 6.0.0(20)
Instance of the workspace management service, which provides unified workspace management capabilities.
Since: 6.0.0(20)
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.EnterpriseSpace.ServiceManage
Parameters for creating a workspace.
Since: 6.0.0(20)
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.EnterpriseSpace.ServiceManage
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| shortName | string | No | No | Local abbreviation of a workspace. By default, the value is the same as that of localName in WorkspaceInfo. |
Workspace domain account information.
Since: 6.0.0(20)
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.EnterpriseSpace.ServiceManage
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| domain | string | No | No | Domain name, for example, xx.com. The value is returned only after workspace authentication; otherwise, it is empty. |
| workspaceName | string | No | No | Workspace domain account name. The value is returned only after workspace authentication; otherwise, it is empty. |
| accountId | string | No | Yes | Domain account identifier. The value is returned only after workspace authentication; otherwise, it is empty. The value is a character string automatically generated by the system when the workspace is created. You can leave it empty in setWorkspaceInfo. |
| isAuthenticated | boolean | No | Yes | Indicates whether the workspace is authenticated. - true: yes - false: no The default value is false. |
| serverConfigId | string | No | Yes | Server configuration ID of the workspace domain. The value is automatically generated by the system when the workspace is created. It is returned only after workspace authentication, for example, xx:test.com; otherwise, the value is empty. |
| enterpriseWorkspaceName | string | No | Yes | Workspace name, which is the tag attribute of an enterprise device in a workspace. It is left empty by default. For example, the value is XXX in an enterprise workspace. Since: 6.0.2(22) |
Workspace information.
Since: 6.0.0(20)
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.EnterpriseSpace.ServiceManage
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| workspaceId | number | No | No | Workspace ID. The workspace ID starts at 100 and increments by 1 for each subsequent workspace (for example, 101 and 102). |
| localName | string | No | No | Local account name of the workspace, for example, test. |
| shortName | string | No | Yes | Local abbreviation of the workspace. By default, the value is the same as that of localName. |
| isUnlocked | boolean | No | No | Indicates whether the workspace is unlocked. - true: yes - false: no The default value is false. |
| photo | string | No | No | Workspace profile photo information. The value is a JSON string representing the local photo, consisting of the following fields: type, which indicates photo type and is currently fixed to 0; defaultImg, which indicates the Base64-encoded string of the photo. Example: "{"type":0,"defaultImg":"data:image/png;base64,iVBO******Jggg==}". |
| createTime | number | No | No | Workspace creation time, which is a 10-digit timestamp generated by the system, in seconds. |
| lastLoginTime | number | No | No | Last sign-in time of the workspace, which is a 10-digit timestamp generated by the system, in seconds. |
| serialNumber | number | No | No | Workspace serial number, which is a 9-digit number. |
| isActivated | boolean | No | No | Indicates whether the workspace is activated. - true: yes - false: no The default value is false. |
| isCreateCompleted | boolean | No | No | Indicates whether the workspace creation is completed. - true: yes - false: no The default value is true. |
| isAllowedToBeDeleted | boolean | No | No | Indicates whether the workspace can be deleted. - true: yes - false: no The default value is true. |
| domainInfo | WorkspaceDomainInfo | No | No | Domain information of the workspace. For details, please refer to WorkspaceDomainInfo. |
Paths that a process cannot access.
Since: 6.0.1(21)
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.EnterpriseSpace.ServiceManage
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| processName | string | No | No | System service process name. |
| disallowPaths | string[] | No | No | List of inaccessible paths. The list must be a subset of the ['/data/service','/data/app','/storage','/mnt'] list. |
Enumerates workspace types.
Since: 6.0.0(20)
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.EnterpriseSpace.ServiceManage
| Name | Value | Description |
|---|---|---|
| ADMIN | 0 | Administrator workspace, which has the permission to manage other workspaces. |
Enumerates workspace query types.
Since: 6.0.0(20)
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.EnterpriseSpace.ServiceManage
| Name | Value | Description |
|---|---|---|
| ALL | 0 | Queries all workspaces. |
| NON_DELETABLE | 1 | Queries workspaces that cannot be deleted. |
Enumerates the types of events available for subscription.
Since: 6.0.0(20)
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.EnterpriseSpace.ServiceManage
| Name | Value | Description |
|---|---|---|
| EVENT_WORKSPACE_SWITCHED | 0 | Workspace switch event. |
Enumerates workspace types.
Since: 6.0.1(21)
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.EnterpriseSpace.ServiceManage
| Name | Value | Description |
|---|---|---|
| ENTERPRISE | 0 | Enterprise workspace. |
| PERSONAL | 1 | Personal workspace. |
Workspace event information.
Since: 6.0.0(20)
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.EnterpriseSpace.ServiceManage
Enumerates the types of lockdown mode policy, including the security hardening measures such as background app freezing and public directory encryption/decryption. OFF and EFFICIENT modes are supported.
Since: 6.0.2(22)
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.EnterpriseSpace.ServiceManage
| Name | Value | Description |
|---|---|---|
| OFF | 0 | Disabled. In this mode, background app freezing and public data directory encryption/decryption are not supported. |
| EFFICIENT | 1 | Efficiency mode. In this mode, background app freezing and public data directory encryption/decryption are supported. |
Enumerates the display policies for the personal workspace creation guide page.
Since: 6.1.0(23)
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.EnterpriseSpace.ServiceManage
| Name | Value | Description |
|---|---|---|
| SHOW | 0 | Displays the personal workspace creation guide page. |
| HIDE | 1 | Hides the personal workspace creation guide page. |
Enterprise authentication result.
Since: 6.1.0(23)
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.EnterpriseSpace.ServiceManage
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| result | number | No | No | Authentication result. 0 indicates success and other values indicate failure. |
| workspaceId | number | No | No | Workspace ID of the current API caller. |
Style of the workspace icon in the status bar.
Since: 6.1.0(23)
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.EnterpriseSpace.ServiceManage
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| white | image.PixelMap | No | No | Icon on a dark background. For details about the design style, please refer to the design specifications. |
| black | image.PixelMap | No | No | Icon on a light background. For details about the design style, please refer to the design specifications. |
Enumerates the visibility states of cross-workspace message notifications.
Since: 26.0.0
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.EnterpriseSpace.ServiceManage
| Name | Value | Description |
|---|---|---|
| NOTIFICATION_HIDDEN | 0 | Hides cross-workspace message notifications. |
| NOTIFICATION_VISIBLE | 1 | Displays cross-workspace message notifications. |
Enumerates the states of the cross-workspace message notification function.
Since: 26.0.0
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.EnterpriseSpace.ServiceManage
| Name | Value | Description |
|---|---|---|
| ON | 0 | Cross-workspace message notification enabled. |
| OFF | 1 | Cross-workspace message notification disabled. |
Enumerates the control types of cross-workspace message notification visibility.
Since: 26.0.0
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.EnterpriseSpace.ServiceManage
| Name | Value | Description |
|---|---|---|
| ALLOW_CHANGE | 0 | The status of cross-workspace message notification visibility can be modified. |
| DISALLOW_CHANGE | 1 | The status of cross-workspace message notification visibility cannot be modified. |
Cross-workspace message notification configuration for an app.
Since: 26.0.0
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.EnterpriseSpace.ServiceManage
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| workspaceId | number | No | No | Workspace ID. The workspace ID starts at 100 and increments by 1 for each subsequent workspace (for example, 101 and 102). The value must be an integer within the range of [100,10736]. |
| appIdentifier | string | No | No | Unique ID of an app. For details, please refer to What is appIdentifier? |
| notificationState | NotificationSwitch | No | No | Indicates whether cross-workspace message notification is enabled. For details about the value, please refer to NotificationSwitch. |
| visibilityState | NotificationVisibilitySwitch | No | Yes | Indicates the status of cross-workspace message notification visibility. For details about the value, please refer to NotificationVisibilitySwitch. The default value is NOTIFICATION_HIDDEN. |
| allowVisibilityChange | NotificationVisibilityControl | No | Yes | Indicates whether the status of cross-workspace message notification visibility can be modified. For details about the value, please refer to NotificationVisibilityControl. The default value is ALLOW_CHANGE. |
createWorkspace(localName: string, workspaceType: WorkspaceType, params?: CreateWorkspaceParams): Promise<WorkspaceInfo>
Creates a workspace. This API uses a promise to return the result.
Since version 6.1.0(23), the following validation is added for workspace creation:
Since: 6.0.0(20)
Model restriction: This API can be used only in the stage model.
Required permissions: ohos.permission.ENTERPRISE_MANAGE_LOCAL_PUBLICSPACES or ohos.permission.MANAGE_LOCAL_WORKSPACES
System capability: SystemCapability.EnterpriseSpace.ServiceManage
Parameters
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| localName | string | Yes | Local account name of the workspace, for example, testWorkspace. |
| workspaceType | WorkspaceType | Yes | Workspace type. |
| params | CreateWorkspaceParams | No | Parameters for creating a workspace. For details, please refer to CreateWorkspaceParams. |
Returns
| Type | Description |
|---|---|
| Promise<WorkspaceInfo> | Promise used to return workspace information. |
Error codes:
For details about the error codes, please refer to Universal Error Codes and ArkTS API Error Codes.
| ID | Error Message |
|---|---|
| 201 | The application does not have permission to call this function. |
| 801 | The device type not supported. Applicable versions: 26.0.0+ |
| 1020400001 | System service exception. |
| 1020400002 | Parameter error. |
| 1020400003 | Invalid workspace. |
| 1020400007 | Enterprise workspace not enabled. |
| 1020400011 | Account creation is not permitted. Applicable versions: 6.1.0(23)+ |
| 1020400012 | Full disk encryption is not enabled. Applicable versions: 6.1.0(23)+ |
Example:
import { spaceManager } from '@kit.EnterpriseSpaceKit';
const localName: string = 'testWorkspace';
const workspaceType: spaceManager.WorkspaceType = spaceManager.WorkspaceType.ADMIN;
const params: spaceManager.CreateWorkspaceParams = {
shortName: 'test'
};
const workspaceInfo: spaceManager.WorkspaceInfo = await spaceManager.createWorkspace(localName, workspaceType, params);
console.info(`Succeeded in creating workspace. workspaceInfo: ${JSON.stringify(workspaceInfo)}`); enableWorkspace(enable: boolean): Promise<void>
Enables the enterprise workspace and personal workspace function. An enterprise workspace is a general office space managed by the enterprise, and a personal workspace is used for external communication, operations, open-source development, and other work-related activities. This API uses a promise to return the result.
Since version 6.1.0(23), the following validation is added for enabling the enterprise workspace and personal workspace function.
Since: 6.0.0(20)
Model restriction: This API can be used only in the stage model.
Required permissions: ohos.permission.ENTERPRISE_MANAGE_LOCAL_PUBLICSPACES or ohos.permission.MANAGE_LOCAL_WORKSPACES
System capability: SystemCapability.EnterpriseSpace.ServiceManage
Parameters
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| enable | boolean | Yes | Indicates whether to enable the enterprise workspace and personal workspace function. The default value is false. - true: yes - false: no |
Returns
| Type | Description |
|---|---|
| Promise<void> | Promise that returns no value. |
Error codes:
For details about the error codes, please refer to Universal Error Codes and ArkTS API Error Codes.
| ID | Error Message |
|---|---|
| 201 | The application does not have permission to call this function. |
| 801 | The device type not supported. Applicable versions: 26.0.0+ |
| 1020400001 | System service exception. |
| 1020400002 | Parameter error. |
| 1020400003 | Invalid workspace. Applicable versions: 6.1.0(23)+ |
| 1020400012 | Full disk encryption is not enabled. Applicable versions: 6.1.0(23)+ |
Example:
import { spaceManager } from '@kit.EnterpriseSpaceKit';
const enable: boolean = true;
await spaceManager.enableWorkspace(enable);
console.info(`Succeeded in enabling workspace.`); queryWorkspace(queryFlag: QueryType): Promise<WorkspaceInfo[]>
Queries workspaces. This API uses a promise to return the result.
Since: 6.0.0(20)
Model restriction: This API can be used only in the stage model.
Required permissions: ohos.permission.QUERY_LOCAL_WORKSPACES
System capability: SystemCapability.EnterpriseSpace.ServiceManage
Parameters
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| queryFlag | QueryType | Yes | Workspace type. |
Returns
| Type | Description |
|---|---|
| Promise<WorkspaceInfo[]> | Promise used to return a workspace information list. |
Error codes:
For details about the error codes, please refer to Universal Error Codes and ArkTS API Error Codes.
| ID | Error Message |
|---|---|
| 201 | The application does not have permission to call this function. |
| 801 | The device type not supported. Applicable versions: 26.0.0+ |
| 1020400001 | System service exception. |
| 1020400002 | Parameter error. |
Example:
import { spaceManager } from '@kit.EnterpriseSpaceKit';
const queryFlag: spaceManager.QueryType = spaceManager.QueryType.ALL;
const spaces: spaceManager.WorkspaceInfo[] = await spaceManager.queryWorkspace(queryFlag);
console.info(`Succeeded in querying workspace. spaces: ${JSON.stringify(spaces)}`); removeWorkspace(workspaceId: number): Promise<void>
Removes a workspace. This API uses a promise to return the result.
The first workspace whose ID is 100 cannot be removed. Other workspaces can be removed.
Since: 6.0.0(20)
Model restriction: This API can be used only in the stage model.
Required permissions: ohos.permission.ENTERPRISE_MANAGE_LOCAL_PUBLICSPACES or ohos.permission.MANAGE_LOCAL_WORKSPACES
System capability: SystemCapability.EnterpriseSpace.ServiceManage
Parameters
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| workspaceId | number | Yes | Workspace ID. The workspace ID starts at 100 and increments by 1 for each subsequent workspace (for example, 101 and 102). The value must be an integer within the range of [100,10736]. |
Returns
| Type | Description |
|---|---|
| Promise<void> | Promise that returns no value. |
Error codes:
For details about the error codes, please refer to Universal Error Codes and ArkTS API Error Codes.
| ID | Error Message |
|---|---|
| 201 | The application does not have permission to call this function. |
| 801 | The device type not supported. Applicable versions: 26.0.0+ |
| 1020400001 | System service exception. |
| 1020400002 | Parameter error. |
| 1020400003 | Invalid workspace. |
| 1020400007 | Enterprise workspace not enabled. |
Example:
import { spaceManager } from '@kit.EnterpriseSpaceKit';
const workspaceId: number = 101; // ID of a created workspace.
await spaceManager.removeWorkspace(workspaceId);
console.info(`Succeeded in removing workspace.`); setWorkspaceInfo(workspaceId: number, domainInfo: WorkspaceDomainInfo): Promise<void>
Sets workspace information. This API uses a promise to return the result.
Since: 6.0.0(20)
Model restriction: This API can be used only in the stage model.
Required permissions: ohos.permission.ENTERPRISE_MANAGE_LOCAL_PUBLICSPACES or ohos.permission.MANAGE_LOCAL_WORKSPACES
System capability: SystemCapability.EnterpriseSpace.ServiceManage
Parameters
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| workspaceId | number | Yes | Workspace ID. The workspace ID starts at 100 and increments by 1 for each subsequent workspace (for example, 101 and 102). The value must be an integer within the range of [100,10736]. |
| domainInfo | WorkspaceDomainInfo | Yes | Domain information of the workspace. For details, please refer to WorkspaceDomainInfo. |
Returns
| Type | Description |
|---|---|
| Promise<void> | Promise that returns no value. |
Error codes:
For details about the error codes, please refer to Universal Error Codes and ArkTS API Error Codes.
| ID | Error Message |
|---|---|
| 201 | The application does not have permission to call this function. |
| 801 | The device type not supported. Applicable versions: 26.0.0+ |
| 1020400001 | System service exception. |
| 1020400002 | Parameter error. |
| 1020400003 | Invalid workspace. |
| 1020400007 | Enterprise workspace not enabled. |
Example:
import { spaceManager } from '@kit.EnterpriseSpaceKit';
const workspaceId: number = 100;
const domainInfo: spaceManager.WorkspaceDomainInfo = {
domain: 'test1',
workspaceName: 'test2',
accountId: 'test3',
isAuthenticated: false,
serverConfigId: 'test4',
enterpriseWorkspaceName: 'default'
};
await spaceManager.setWorkspaceInfo(workspaceId, domainInfo);
console.info(`Succeeded in setting workspace info.`); setWorkspaceProfilePhoto(workspaceId: number, photo: string): Promise<void>
Sets the workspace profile photo. This API uses a promise to return the result.
Since: 6.0.0(20)
Model restriction: This API can be used only in the stage model.
Required permissions: ohos.permission.ENTERPRISE_MANAGE_LOCAL_PUBLICSPACES
System capability: SystemCapability.EnterpriseSpace.ServiceManage
Parameters
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| workspaceId | number | Yes | Workspace ID. The workspace ID starts at 100 and increments by 1 for each subsequent workspace (for example, 101 and 102). The value must be an integer within the range of [100,10736]. |
| photo | string | Yes | Workspace profile photo information. The value is a JSON string representing the local photo, consisting of the following fields: type, which indicates photo type and is currently fixed to 0; defaultImg, which indicates the Base64-encoded string of the photo. Example: "{"type":0,"defaultImg":"data:image/png;base64,iVBO******Jggg==}". |
Returns
| Type | Description |
|---|---|
| Promise<void> | Promise that returns no value. |
Error codes:
For details about the error codes, please refer to Universal Error Codes and ArkTS API Error Codes.
| ID | Error Message |
|---|---|
| 201 | The application does not have permission to call this function. |
| 801 | The device type not supported. Applicable versions: 26.0.0+ |
| 1020400001 | System service exception. |
| 1020400002 | Parameter error. |
| 1020400003 | Invalid workspace. |
| 1020400007 | Enterprise workspace not enabled. |
Example:
import { spaceManager } from '@kit.EnterpriseSpaceKit';
const workspaceId: number = 100;
const photo: string = '{"type":0,"defaultImg":"data:image/png;base64,iVBO******Jggg==}';
try {
await spaceManager.setWorkspaceProfilePhoto(workspaceId, photo);
console.info(`Succeeded in setting workspace profile photo.`);
} catch (err) {
console.error(`Failed to set workspace profile photo. Code: ${err.code}, message: ${err.message}`);
} subscribeEvent(eventId: EventType[], callback: AsyncCallback<EventData>): number
Subscribes to workspace events. This API returns the result asynchronously through a callback.
Since: 6.0.0(20)
Model restriction: This API can be used only in the stage model.
Required permissions: ohos.permission.ENTERPRISE_WORKSPACES_EVENT_SUBSCRIBE
System capability: SystemCapability.EnterpriseSpace.ServiceManage
Parameters
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| eventId | EventType[] | Yes | List of the workspace event types to subscribe to. |
| callback | AsyncCallback<EventData> | Yes | Callback function. If the workspace events are successfully subscribed to, err is undefined and data is the obtained workspace event information defined by EventData. Otherwise, err is an error object. |
Returns
| Type | Description |
|---|---|
| number | Subscription ID, which will be used for event unsubscription. The subscription ID starts at 1 and increments by 1 for each subsequent subscription (for example, 2 and 3). |
Error codes:
For details about the error codes, please refer to Universal Error Codes and ArkTS API Error Codes.
| ID | Error Message |
|---|---|
| 201 | The application does not have permission to call this function. |
| 801 | The device type not supported. Applicable versions: 26.0.0+ |
| 1020400001 | System service exception. |
| 1020400002 | Parameter error. |
| 1020400006 | Session disconnected. |
| 1020400007 | Enterprise workspace not enabled. |
Example:
import { spaceManager } from '@kit.EnterpriseSpaceKit';
import { BusinessError } from '@kit.BasicServicesKit';
const subscribeId = spaceManager.subscribeEvent([spaceManager.EventType.EVENT_WORKSPACE_SWITCHED],
(error: BusinessError, data: spaceManager.EventData) => {
if (error) {
console.error(`error info:${error?.code}, err message:${error?.message}`);
} else {
console.info(`event: ${data.event}, currentWorkSpaceId: ${data.currentWorkspaceId}`);
}
});
console.info(`Succeeded in subscribing event. subscribeId: ${subscribeId}`); unsubscribeEvent(subscribeId: number): void
Unsubscribes from a workspace event.
Since: 6.0.0(20)
Model restriction: This API can be used only in the stage model.
Required permissions: ohos.permission.ENTERPRISE_WORKSPACES_EVENT_SUBSCRIBE
System capability: SystemCapability.EnterpriseSpace.ServiceManage
Parameters
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| subscribeId | number | Yes | Subscription ID obtained when a workspace event is successfully subscribed to. |
Error codes:
For details about the error codes, please refer to Universal Error Codes and ArkTS API Error Codes.
| ID | Error Message |
|---|---|
| 201 | The application does not have permission to call this function. |
| 801 | The device type not supported. Applicable versions: 26.0.0+ |
| 1020400001 | System service exception. |
| 1020400002 | Parameter error. |
| 1020400007 | Enterprise workspace not enabled. |
Example:
import { spaceManager } from '@kit.EnterpriseSpaceKit';
const subscribeId: number = 10; // Subscription ID obtained when a workspace event is successfully subscribed to.
spaceManager.unsubscribeEvent(subscribeId);
console.info(`Succeeded in unsubscribing event.`); setRestrictedAccessBackgroundUserdata(userData: UserDataEnum, enable: boolean): Promise<void>
Sets whether to restrict system service processes from accessing background user data. This API uses a promise to return the result.
Since: 6.0.1(21)
Model restriction: This API can be used only in the stage model.
Required permissions: ohos.permission.ENTERPRISE_MANAGE_LOCAL_PUBLICSPACES
System capability: SystemCapability.EnterpriseSpace.ServiceManage
Parameters
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| userData | UserDataEnum | Yes | Workspace type. |
| enable | boolean | Yes | Indicates whether to restrict system service processes from accessing background user data. The default value is true. - true: yes - false: no |
Returns
| Type | Description |
|---|---|
| Promise<void> | Promise that returns no value. |
Error codes:
For details about the error codes, please refer to Universal Error Codes and ArkTS API Error Codes.
| ID | Error Message |
|---|---|
| 201 | The application does not have permission to call this function. |
| 801 | The device type not supported. Applicable versions: 26.0.0+ |
| 1020400001 | System service exception. |
| 1020400002 | Parameter error. |
| 1020400007 | Enterprise workspace not enabled. |
Example:
import { spaceManager } from '@kit.EnterpriseSpaceKit';
const userData: spaceManager.UserDataEnum = spaceManager.UserDataEnum.ENTERPRISE;
const enable: boolean = false;
await spaceManager.setRestrictedAccessBackgroundUserdata(userData, enable);
console.info(`Succeeded in setting restricted access background user data.`); getRestrictedAccessBackgroundUserdataStatus(userData: UserDataEnum): Promise<boolean>
Checks whether system service processes are restricted from accessing background user data. The background user data is in specific subdirectories of directories in the ['/data/service','/data/app','/storage','/mnt'] list. This API uses a promise to return the result.
Since: 6.0.1(21)
Model restriction: This API can be used only in the stage model.
Required permissions: ohos.permission.ENTERPRISE_MANAGE_LOCAL_PUBLICSPACES
System capability: SystemCapability.EnterpriseSpace.ServiceManage
Parameters
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| userData | UserDataEnum | Yes | Workspace type. |
Returns
| Type | Description |
|---|---|
| Promise<boolean> | Promise used to return whether system service processes are restricted from accessing background user data. - true: yes - false: no |
Error codes:
For details about the error codes, please refer to Universal Error Codes and ArkTS API Error Codes.
| ID | Error Message |
|---|---|
| 201 | The application does not have permission to call this function. |
| 801 | The device type not supported. Applicable versions: 26.0.0+ |
| 1020400001 | System service exception. |
| 1020400002 | Parameter error. |
| 1020400007 | Enterprise workspace not enabled. |
Example:
import { spaceManager } from '@kit.EnterpriseSpaceKit';
const userData: spaceManager.UserDataEnum = spaceManager.UserDataEnum.ENTERPRISE;
const status: boolean = await spaceManager.getRestrictedAccessBackgroundUserdataStatus(userData);
console.info(`Succeeded in getting restricted access background user data status. status: ${status}`); getRestrictedAccessBackgroundUserdataProcessList(userData: UserDataEnum): Promise<ProcessConfigInfo[]>
Obtains the list of system service processes that are restricted from accessing background user data. This API uses a promise to return the result.
Since: 6.0.1(21)
Model restriction: This API can be used only in the stage model.
Required permissions: ohos.permission.ENTERPRISE_MANAGE_LOCAL_PUBLICSPACES
System capability: SystemCapability.EnterpriseSpace.ServiceManage
Parameters
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| userData | UserDataEnum | Yes | Workspace type. |
Returns
| Type | Description |
|---|---|
| Promise<ProcessConfigInfo[]> | Promise used to return the list of system service processes that are restricted from accessing background user data. |
Error codes:
For details about the error codes, please refer to Universal Error Codes and ArkTS API Error Codes.
| ID | Error Message |
|---|---|
| 201 | The application does not have permission to call this function. |
| 801 | The device type not supported. Applicable versions: 26.0.0+ |
| 1020400001 | System service exception. |
| 1020400002 | Parameter error. |
| 1020400007 | Enterprise workspace not enabled. |
Example:
import { spaceManager } from '@kit.EnterpriseSpaceKit';
const userData: spaceManager.UserDataEnum = spaceManager.UserDataEnum.ENTERPRISE;
try {
const processConfigInfos: spaceManager.ProcessConfigInfo[] = await spaceManager.getRestrictedAccessBackgroundUserdataProcessList(userData);
console.info(`Succeeded in getting restricted access background user data process list. processConfigInfos: ${JSON.stringify(processConfigInfos)}`);
} catch (err) {
console.error(`Failed to get restricted access background user data process list. Code: ${err.code}, message: ${err.message}`);
} addRestrictedAccessBackgroundUserdataProcessList(userData: UserDataEnum, processName: string, disallowPaths?: string[]): Promise<void>
Adds a list of user data paths that a system service process is restricted from accessing. This API uses a promise to return the result.
Since: 6.0.1(21)
Model restriction: This API can be used only in the stage model.
Required permissions: ohos.permission.ENTERPRISE_MANAGE_LOCAL_PUBLICSPACES
System capability: SystemCapability.EnterpriseSpace.ServiceManage
Parameters
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| userData | UserDataEnum | Yes | Workspace type. |
| processName | string | Yes | System service process name. |
| disallowPaths | string[] | No | Inaccessible path list. - If this parameter is not specified, the default value ['/data/service','/data/app','/storage','/mnt'] is used. - The passed value must be a subset of the ['/data/service','/data/app','/storage','/mnt'] list. |
Returns
| Type | Description |
|---|---|
| Promise<void> | Promise that returns no value. |
Error codes:
For details about the error codes, please refer to Universal Error Codes and ArkTS API Error Codes.
| ID | Error Message |
|---|---|
| 201 | The application does not have permission to call this function. |
| 801 | The device type not supported. Applicable versions: 26.0.0+ |
| 1020400001 | System service exception. |
| 1020400002 | Parameter error. |
| 1020400007 | Enterprise workspace not enabled. |
Example:
import { spaceManager } from '@kit.EnterpriseSpaceKit';
const userData: spaceManager.UserDataEnum = spaceManager.UserDataEnum.ENTERPRISE;
const processName: string = 'testSa'; // Name of the system service process.
const disallowPaths: string[] = ['/data/service', '/data/app'];
try {
await spaceManager.addRestrictedAccessBackgroundUserdataProcessList(userData, processName, disallowPaths);
console.info(`Succeeded in adding restricted access background user data process list.`);
} catch (err) {
console.error(`Failed to add restricted access background user data process list. Code: ${err.code}, message: ${err.message}`);
} deleteRestrictedAccessBackgroundUserdataProcessList(userData: UserDataEnum, processName: string): Promise<void>
Deletes the list of user data paths that a system service process is restricted from accessing. This API uses a promise to return the result.
Since: 6.0.1(21)
Model restriction: This API can be used only in the stage model.
Required permissions: ohos.permission.ENTERPRISE_MANAGE_LOCAL_PUBLICSPACES
System capability: SystemCapability.EnterpriseSpace.ServiceManage
Parameters
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| userData | UserDataEnum | Yes | Workspace type. For details about the parameter values, please refer to UserDataEnum. |
| processName | string | Yes | System service process name. |
Returns
| Type | Description |
|---|---|
| Promise<void> | Promise that returns no value. |
Error codes:
For details about the error codes, please refer to Universal Error Codes and ArkTS API Error Codes.
| ID | Error Message |
|---|---|
| 201 | The application does not have permission to call this function. |
| 801 | The device type not supported. Applicable versions: 26.0.0+ |
| 1020400001 | System service exception. |
| 1020400002 | Parameter error. |
| 1020400007 | Enterprise workspace not enabled. |
Example:
import { spaceManager } from '@kit.EnterpriseSpaceKit';
const userData: spaceManager.UserDataEnum = spaceManager.UserDataEnum.ENTERPRISE;
const processName: string = 'testSa'; // Name of the system service process.
try {
await spaceManager.deleteRestrictedAccessBackgroundUserdataProcessList(userData, processName);
console.info(`Succeeded in deleting restricted access background user data process list.`);
} catch (err) {
console.error(`Failed to delete restricted access background user data process list. Code: ${err.code}, message: ${err.message}`);
} setWorkspacePolicy(key: string, value: number, workspaceId?: number): Promise<void>
Sets a workspace policy. This API uses a promise to return the result.
Since: 6.0.2(22)
Model restriction: This API can be used only in the stage model.
Required permissions: ohos.permission.ENTERPRISE_MANAGE_LOCAL_PUBLICSPACES or ohos.permission.MANAGE_LOCAL_WORKSPACES
System capability: SystemCapability.EnterpriseSpace.ServiceManage
Parameters
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| key | string | Yes | Policy name. Since version 6.0.2(22), the deep freeze policy lockdown is supported; since version 6.1.0(23), the display policy for the personal workspace creation guide page, spaceguide, is supported. |
| value | number | Yes | Policy status. If the key is lockdown, see LockdownModePolicy for the value enumeration. If the key is spaceguide, see SpaceGuidePolicy for the value enumeration. |
| workspaceId | number | No | Workspace ID. The workspace ID starts at 100 and increments by 1 for each subsequent workspace (for example, 101 and 102). If this parameter is not set, the workspace ID of the API caller is used by default. The value must be an integer within the range of [100,10736]. |
Returns
| Type | Description |
|---|---|
| Promise<void> | Promise that returns no value. |
Error codes:
For details about the error codes, please refer to Universal Error Codes and ArkTS API Error Codes.
| ID | Error Message |
|---|---|
| 201 | The application does not have permission to call this function. |
| 801 | The device type not supported. Applicable versions: 26.0.0+ |
| 1020400001 | System service exception. |
| 1020400002 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
Example:
import { spaceManager } from '@kit.EnterpriseSpaceKit';
const key: string = 'lockdown';
const value: spaceManager.LockdownModePolicy = spaceManager.LockdownModePolicy.OFF;
const workspaceId: number = 100;
await spaceManager.setWorkspacePolicy(key, value, workspaceId);
console.info(`Succeeded in setting workspace policy.`); getWorkspacePolicy(key: string, workspaceId?: number): Promise<number>
Queries workspace policies. This API uses a promise to return the result.
Since: 6.0.2(22)
Model restriction: This API can be used only in the stage model.
Required permissions: ohos.permission.QUERY_LOCAL_WORKSPACES or ohos.permission.MANAGE_LOCAL_WORKSPACES
System capability: SystemCapability.EnterpriseSpace.ServiceManage
Parameters
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| key | string | Yes | Policy name. Since version 6.0.2(22), the deep freeze policy lockdown is supported; since version 6.1.0(23), the display policy for the personal workspace creation guide page, spaceguide, is supported. |
| workspaceId | number | No | Workspace ID. The workspace ID starts at 100 and increments by 1 for each subsequent workspace (for example, 101 and 102). If this parameter is not set, the workspace ID of the API caller is used by default. The value must be an integer within the range of [100,10736]. |
Returns
| Type | Description |
|---|---|
| Promise<number> | Promise used to return the policy status. For details about the values, please refer to the enumerated values of LockdownModePolicy or SpaceGuidePolicy based on the passed key. |
Error codes:
For details about the error codes, please refer to Universal Error Codes and ArkTS API Error Codes.
| ID | Error Message |
|---|---|
| 201 | The application does not have permission to call this function. |
| 801 | The device type not supported. Applicable versions: 26.0.0+ |
| 1020400001 | System service exception. |
| 1020400002 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
| 1020400005 | Configuration not set. |
Example:
import { spaceManager } from '@kit.EnterpriseSpaceKit';
const key: string = 'lockdown';
const workspaceId: number = 100;
const value: number = await spaceManager.getWorkspacePolicy(key, workspaceId);
console.info(`Succeeded in getting workspace policy. value: ${value}`); setLockdownExemptionApps(appIds: string[], workspaceId?: number): Promise<void>
Sets the deep freeze exemption list. Apps on the list can function properly in the specified background workspace without being frozen. This API uses a promise to return the result.
Since: 6.0.2(22)
Model restriction: This API can be used only in the stage model.
Required permissions: ohos.permission.ENTERPRISE_MANAGE_LOCAL_PUBLICSPACES
System capability: SystemCapability.EnterpriseSpace.ServiceManage
Parameters
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| appIds | string[] | Yes | Array of app IDs that are on the deep freeze exemption list. The value is a list, for example, ['com.example.test1_BN', 'com.example.test2_BN']. For details, please refer to What Is appId? |
| workspaceId | number | No | Workspace ID. The workspace ID starts at 100 and increments by 1 for each subsequent workspace (for example, 101 and 102). If this parameter is not set, the workspace ID of the API caller is used by default. The value must be an integer within the range of [100,10736]. |
Returns
| Type | Description |
|---|---|
| Promise<void> | Promise that returns no value. |
Error codes:
For details about the error codes, please refer to Universal Error Codes and ArkTS API Error Codes.
| ID | Error Message |
|---|---|
| 201 | The application does not have permission to call this function. |
| 801 | The device type not supported. Applicable versions: 26.0.0+ |
| 1020400001 | System service exception. |
| 1020400002 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
| 1020400007 | Enterprise workspace not enabled. |
Example:
import { spaceManager } from '@kit.EnterpriseSpaceKit';
const workspaceId: number = 100;
const appIds = [
'com.example.test1_BN************',
'com.example.test2_BN************'
];
await spaceManager.setLockdownExemptionApps(appIds, workspaceId);
console.info(`Succeeded in setting lockdown exemption apps.`); getLockdownExemptionApps(workspaceId?: number): Promise<string[]>
Queries the deep freeze exemption list. This API uses a promise to return the result.
Since: 6.0.2(22)
Model restriction: This API can be used only in the stage model.
Required permissions: ohos.permission.QUERY_LOCAL_WORKSPACES or ohos.permission.MANAGE_LOCAL_WORKSPACES
System capability: SystemCapability.EnterpriseSpace.ServiceManage
Parameters
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| workspaceId | number | No | Workspace ID. The workspace ID starts at 100 and increments by 1 for each subsequent workspace (for example, 101 and 102). If this parameter is not set, the workspace ID of the API caller is used by default. The value must be an integer within the range of [100,10736]. |
Returns
| Type | Description |
|---|---|
| Promise<string[]> | Promise used to return the deep freeze exemption list. |
Error codes:
For details about the error codes, please refer to Universal Error Codes and ArkTS API Error Codes.
| ID | Error Message |
|---|---|
| 201 | The application does not have permission to call this function. |
| 801 | The device type not supported. Applicable versions: 26.0.0+ |
| 1020400001 | System service exception. |
| 1020400002 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
| 1020400007 | Enterprise workspace not enabled. |
Example:
import { spaceManager } from '@kit.EnterpriseSpaceKit';
const workspaceId: number = 100;
const apps: string[] = await spaceManager.getLockdownExemptionApps(workspaceId);
console.info(`Succeeded in getting lockdown exemption apps. apps: ${JSON.stringify(apps)}`); authenticate(enterpriseAuthInfo: WorkspaceDomainInfo, credential: Uint8Array): Promise<AuthResult>
Authenticates an enterprise account. This API uses a promise to return the result.
Since: 6.1.0(23)
Model restriction: This API can be used only in the stage model.
Required permissions: ohos.permission.ENTERPRISE_MANAGE_LOCAL_PUBLICSPACES
System capability: SystemCapability.EnterpriseSpace.ServiceManage
Parameters
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| enterpriseAuthInfo | WorkspaceDomainInfo | Yes | Domain information of the workspace. For details, please refer to WorkspaceDomainInfo. |
| credential | Uint8Array | Yes | Sign-in credential (for example, password) of an enterprise user, which needs to be passed by the user. |
Returns
| Type | Description |
|---|---|
| Promise<AuthResult> | Promise used to return the enterprise account authentication result. |
Error codes:
For details about the error codes, please refer to Universal Error Codes and ArkTS API Error Codes.
| ID | Error Message |
|---|---|
| 201 | The application does not have permission to call this function. |
| 801 | The device type not supported. Applicable versions: 26.0.0+ |
| 1020400001 | System service exception. |
| 1020400002 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
| 1020400004 | Authentication failed. |
| 1020400008 | Invalid account name or password. |
| 1020400009 | The account is locked. |
| 1020400010 | Enterprise authentication server unreachable. |
Example:
import { spaceManager } from '@kit.EnterpriseSpaceKit';
try {
const enterpriseAuthInfo: spaceManager.WorkspaceDomainInfo = {
domain: 'testDomain',
workspaceName: 'testAccountName',
serverConfigId: 'testServerConfigId'
};
const credential = new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0])
const authResult: spaceManager.AuthResult = await spaceManager.authenticate(enterpriseAuthInfo, credential);
console.info(`Succeeded in authenticating. authResult: ${JSON.stringify(authResult)}`);
} catch (err) {
console.error(`Failed to authenticate. Code: ${err.code}, message: ${err.message}`);
} getAccessToken(businessParams: Record<string, string>): Promise<Uint8Array>
Obtains the access token of an enterprise app. This API uses a promise to return the result.
Since: 6.1.0(23)
Model restriction: This API can be used only in the stage model.
Required permissions: ohos.permission.ENTERPRISE_MANAGE_LOCAL_PUBLICSPACES
System capability: SystemCapability.EnterpriseSpace.ServiceManage
Parameters
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| businessParams | Record<string, string> | Yes | Service parameters customized by the service party based on the request protocol. |
Returns
| Type | Description |
|---|---|
| Promise<Uint8Array> | Promise used to return the access token, which can be used for password-free sign-in to the enterprise app. |
Error codes:
For details about the error codes, please refer to Universal Error Codes and ArkTS API Error Codes.
| ID | Error Message |
|---|---|
| 201 | The application does not have permission to call this function. |
| 801 | The device type not supported. Applicable versions: 26.0.0+ |
| 1020400001 | System service exception. |
| 1020400002 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
| 1020400003 | Invalid workspace. |
| 1020400004 | Authentication failed. |
| 1020400010 | Enterprise authentication server unreachable. |
Example:
import { spaceManager } from '@kit.EnterpriseSpaceKit';
try {
const params: Record<string, string> = {
'clientId': 'test1'
};
const result: Uint8Array = await spaceManager.getAccessToken(params);
console.info(`Succeeded in getting access token. result: ${JSON.stringify(result)}`);
} catch (err) {
console.error(`Failed to get access token. Code: ${err.code}, message: ${err.message}`);
} setWorkspaceStatusBarIcon(icon: StatusBarIcon, workspaceId?: number): Promise<void>
Sets the workspace status bar icon based on the workspace ID. This API uses a promise to return the result.
This API is available only for MDM apps focused on enterprise security control and granted with the required permissions, and can set the status bar icon only for the workspace where the current MDM app is located. However, if an MDM app is installed under a system-preset user account, this API can be called to change the status bar icon of another workspace.
Since: 6.1.0(23)
Model restriction: This API can be used only in the stage model.
Required permissions: ohos.permission.ENTERPRISE_MANAGE_LOCAL_PUBLICSPACES
System capability: SystemCapability.EnterpriseSpace.ServiceManage
Parameters
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| icon | StatusBarIcon | Yes | Status bar icon of the workspace. |
| workspaceId | number | No | Workspace ID. The workspace ID starts at 100 and increments by 1 for each subsequent workspace (for example, 101 and 102). If this parameter is not set, the workspace ID of the API caller is used by default. The value must be an integer within the range of [100,10736]. |
Returns
| Type | Description |
|---|---|
| Promise<void> | Promise that returns no value. |
Error codes:
For details about the error codes, please refer to Universal Error Codes and ArkTS API Error Codes.
| ID | Error Message |
|---|---|
| 201 | The application does not have permission to call this function. |
| 801 | The device type not supported. Applicable versions: 26.0.0+ |
| 1020400001 | System service exception. |
| 1020400002 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
| 1020400003 | Invalid workspace. |
Example:
import { spaceManager } from '@kit.EnterpriseSpaceKit';
import { resourceManager } from '@kit.LocalizationKit';
import { image } from '@kit.ImageKit';
import { common } from '@kit.AbilityKit';
@Entry
@Component
struct Index {
async test() {
const context = this.getUIContext().getHostContext() as common.UIAbilityContext;
const resourceMgr: resourceManager.ResourceManager = context.resourceManager;
// Create the white pixelMap. You need to preset the CustomWhite.jpg image in the rawfile folder.
const whiteFileData = await resourceMgr.getRawFd('CustomWhite.jpg');
const whiteImageSource: image.ImageSource = image.createImageSource(whiteFileData);
const whitePixelMap: image.PixelMap = await whiteImageSource.createPixelMap();
// Create the black pixelMap. You need to preset the CustomBlack.jpg image in the rawfile folder.
const blackFileData = await resourceMgr.getRawFd('CustomBlack.jpg');
const blackImageSource: image.ImageSource = image.createImageSource(blackFileData);
const blackPixelMap: image.PixelMap = await blackImageSource.createPixelMap();
// Build icon information.
const icon: spaceManager.StatusBarIcon = {
white: whitePixelMap,
black: blackPixelMap
};
const workspaceId: number = 100;
try {
await spaceManager.setWorkspaceStatusBarIcon(icon, workspaceId);
console.info(`Succeeded in setting workspace status bar icon.`);
} catch (err) {
console.error(`Failed to set workspace status bar icon. Code: ${err.code}, message: ${err.message}`);
}
}
build() {
}
} setWorkspaceLocalName(localName: string, workspaceId?: number): Promise<void>
Sets the local name of a workspace based on the workspace ID. This API uses a promise to return the result.
This API is available only for MDM apps focused on enterprise security control and granted with the required permissions, and can set the local name only for the workspace where the current MDM app is located. However, if an MDM app is installed under a system-preset user account, this API can be called to change the local name of another workspace.
Since: 6.1.0(23)
Model restriction: This API can be used only in the stage model.
Required permissions: ohos.permission.ENTERPRISE_MANAGE_LOCAL_PUBLICSPACES
System capability: SystemCapability.EnterpriseSpace.ServiceManage
Parameters
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| localName | string | Yes | Local name of the workspace. |
| workspaceId | number | No | Workspace ID. The workspace ID starts at 100 and increments by 1 for each subsequent workspace (for example, 101 and 102). If this parameter is not set, the workspace ID of the API caller is used by default. The value must be an integer within the range of [100,10736]. |
Returns
| Type | Description |
|---|---|
| Promise<void> | Promise that returns no value. |
Error codes:
For details about the error codes, please refer to Universal Error Codes and ArkTS API Error Codes.
| ID | Error Message |
|---|---|
| 201 | The application does not have permission to call this function. |
| 801 | The device type not supported. Applicable versions: 26.0.0+ |
| 1020400001 | System service exception. |
| 1020400002 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
Example:
import { spaceManager } from '@kit.EnterpriseSpaceKit';
const localName: string = 'localName';
const workspaceId: number = 100;
await spaceManager.setWorkspaceLocalName(localName, workspaceId);
console.info(`Succeeded in setting workspace local name.`); isEnterpriseWorkspaceEnabled(): Promise<boolean>
Checks whether the enterprise digital workspace feature is enabled on the device. This API uses a promise to return the result.
Since: 26.0.0
Model restriction: This API can be used only in the stage model.
Required permissions: ohos.permission.QUERY_LOCAL_WORKSPACES or ohos.permission.MANAGE_LOCAL_WORKSPACES
System capability: SystemCapability.EnterpriseSpace.ServiceManage
Returns
| Type | Description |
|---|---|
| Promise<boolean> | Promise used to return the result. The value true indicates that the enterprise digital space feature is enabled on the device; and the value false indicates that the feature is not enabled on the device. |
Error codes:
For details about the error codes, please refer to Universal Error Codes and ArkTS API Error Codes.
| ID | Error Message |
|---|---|
| 201 | The application does not have permission to call this function. |
| 801 | The device type not supported. |
| 1020400001 | System service exception. |
Example:
import { spaceManager } from '@kit.EnterpriseSpaceKit';
const status = await spaceManager.isEnterpriseWorkspaceEnabled();
console.info(`Succeeded in getting space enable. status: ${status}`); isEnterpriseWorkspace(workspaceId?: number): Promise<boolean>
Checks whether a workspace is an enterprise workspace. This API uses a promise to return the result.
Since: 26.0.0
Model restriction: This API can be used only in the stage model.
Required permissions: ohos.permission.QUERY_LOCAL_WORKSPACES or ohos.permission.MANAGE_LOCAL_WORKSPACES
System capability: SystemCapability.EnterpriseSpace.ServiceManage
Parameters
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| workspaceId | number | No | Workspace ID. The workspace ID starts at 100 and increments by 1 for each subsequent workspace (for example, 101 and 102). If this parameter is not set, the ID of the workspace where the app is located is used by default. The value must be an integer within the range of [100,10736]. |
Returns
| Type | Description |
|---|---|
| Promise<boolean> | Promise used to return the result. The value true indicates that the workspace is an enterprise workspace; and the value false indicates that the workspace is a personal workspace. |
Error codes:
For details about the error codes, please refer to Universal Error Codes and ArkTS API Error Codes.
| ID | Error Message |
|---|---|
| 201 | The application does not have permission to call this function. |
| 801 | The device type not supported. |
| 1020400001 | System service exception. |
| 1020400002 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
| 1020400003 | Invalid workspace. |
| 1020400007 | Enterprise workspace not enabled. |
Example:
import { spaceManager } from '@kit.EnterpriseSpaceKit';
const workspaceId: number = 100;
const isEnterprise = await spaceManager.isEnterpriseWorkspace(workspaceId);
console.info(`Succeeded in getting enterprise space. isEnterprise: ${isEnterprise}`); switchWorkspace(workspaceId?: number): Promise<void>
Switches the workspace. This API uses a promise to return the result.
This API is available only for MDM apps focused on enterprise security control and granted with the required permissions, and can be called only when there are two workspaces.
Since: 26.0.0
Model restriction: This API can be used only in the stage model.
Required permissions: ohos.permission.ENTERPRISE_MANAGE_LOCAL_PUBLICSPACES
System capability: SystemCapability.EnterpriseSpace.ServiceManage
Parameters
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| workspaceId | number | No | ID of the target workspace. If this parameter is not set, the system switches to another workspace by default. The value must be an integer within the range of [100,10736]. |
Returns
| Type | Description |
|---|---|
| Promise<void> | Promise that returns no value. |
Error codes:
For details about the error codes, please refer to Universal Error Codes and ArkTS API Error Codes.
| ID | Error Message |
|---|---|
| 201 | The application does not have permission to call this function. |
| 801 | The device type not supported. |
| 1020400001 | System service exception. |
| 1020400002 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
| 1020400003 | Invalid workspace. |
| 1020400007 | Enterprise workspace not enabled. |
Example:
import { spaceManager } from '@kit.EnterpriseSpaceKit';
const workspaceId: number = 101; // ID of a created workspace.
await spaceManager.switchWorkspace(workspaceId);
console.info(`Succeeded in switching workspace.`); setNotificationConfig(configs: NotificationConfig[]): Promise<void>
Sets the cross-workspace message notification configuration. This API uses a promise to return the result.
Since: 26.0.0
Model restriction: This API can be used only in the stage model.
Required permissions: ohos.permission.ENTERPRISE_MANAGE_LOCAL_PUBLICSPACES
System capability: SystemCapability.EnterpriseSpace.ServiceManage
Parameters
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| configs | NotificationConfig[] | Yes | List of cross-workspace message notification configurations. |
Returns
| Type | Description |
|---|---|
| Promise<void> | Promise that returns no value. |
Error codes:
For details about the error codes, please refer to Universal Error Codes and ArkTS API Error Codes.
| ID | Error Message |
|---|---|
| 201 | The application does not have permission to call this function. |
| 801 | The device type not supported. |
| 1020400001 | System service exception. |
| 1020400002 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
| 1020400007 | Enterprise workspace not enabled. |
| 1020400014 | Configuration quantity exceeds the limit. |
Example:
import { spaceManager } from '@kit.EnterpriseSpaceKit';
const configs: spaceManager.NotificationConfig[] = [
{
workspaceId: 100,
appIdentifier: '691867************',
notificationState: spaceManager.NotificationSwitch.ON,
visibilityState: spaceManager.NotificationVisibilitySwitch.NOTIFICATION_VISIBLE,
allowVisibilityChange: spaceManager.NotificationVisibilityControl.ALLOW_CHANGE
}
];
await spaceManager.setNotificationConfig(configs);
console.info(`Succeeded in setting notification config.`); getNotificationConfig(): Promise<NotificationConfig[]>
Obtains the cross-workspace message notification configuration. This API uses a promise to return the result.
Since: 26.0.0
Model restriction: This API can be used only in the stage model.
Required permissions: ohos.permission.QUERY_LOCAL_WORKSPACES
System capability: SystemCapability.EnterpriseSpace.ServiceManage
Returns
| Type | Description |
|---|---|
| Promise<NotificationConfig[]> | Promise used to return the cross-workspace message notification configuration list. |
Error codes:
For details about the error codes, please refer to Universal Error Codes and ArkTS API Error Codes.
| ID | Error Message |
|---|---|
| 201 | The application does not have permission to call this function. |
| 801 | The device type not supported. |
| 1020400001 | System service exception. |
| 1020400005 | Configuration not set. |
| 1020400007 | Enterprise workspace not enabled. |
Example:
import { spaceManager } from '@kit.EnterpriseSpaceKit';
const configs: spaceManager.NotificationConfig[] = await spaceManager.getNotificationConfig();
console.info(`Succeeded in getting notification config. configs: ${JSON.stringify(configs)}`);