1# Interface (SecureSession) 2<!--Kit: Camera Kit--> 3<!--Subsystem: Multimedia--> 4<!--Owner: @qano--> 5<!--SE: @leo_ysl--> 6<!--TSE: @xchaosioda--> 7 8> **NOTE** 9> 10> - The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version. 11> - The initial APIs of this interface are supported since API version 12. 12 13SecureSession inherits from [Session](arkts-apis-camera-Session.md), [Flash](arkts-apis-camera-Flash.md), [AutoExposure](arkts-apis-camera-AutoExposure.md), [WhiteBalance](arkts-apis-camera-WhiteBalance.md), [Focus](arkts-apis-camera-Focus.md), and [Zoom](arkts-apis-camera-Zoom.md). 14 15It implements a secure session, which provides operations on the flash, exposure, white balance, focus, and zoom. 16 17> **NOTE** 18> 19> You can call [createSession](arkts-apis-camera-CameraManager.md#createsession11) with [SceneMode](arkts-apis-camera-e.md#scenemode11) set to **SECURE_PHOTO** to create a session in secure mode. This class is designed for applications with high security requirements, such as facial recognition systems and banking services. It must be used together with the <!--RP1-->security TA<!--RP1End--> to support service scenarios where both standard preview streams and security streams are generated.<!--RP2--> 20> 21> The security TA can verify the signature of data delivered by the server, sign images, parse and assemble TLV logic, and read, create, and operate keys. It applies to image processing.<!--RP2End--> 22 23## Modules to Import 24 25```ts 26import { camera } from '@kit.CameraKit'; 27``` 28 29## addSecureOutput<sup>12+</sup> 30 31addSecureOutput(previewOutput: PreviewOutput): void 32 33Marks a [PreviewOutput](arkts-apis-camera-PreviewOutput.md) stream as secure output. 34 35**Atomic service API**: This API can be used in atomic services since API version 19. 36 37**System capability**: SystemCapability.Multimedia.Camera.Core 38 39**Parameters** 40 41| Name | Type | Mandatory| Description | 42| ------------- | ------------------------------- | ---- |---------------| 43| previewOutput | [PreviewOutput](arkts-apis-camera-PreviewOutput.md) | Yes | Preview output stream. An error code is returned if the input parameter is invalid.| 44 45**Error codes** 46 47For details about the error codes, see [Camera Error Codes](errorcode-camera.md). 48 49| ID | Error Message | 50| --------------- | --------------- | 51| 7400101 | Parameter missing or parameter type incorrect. | 52| 7400102 | Operation not allowed. | 53 54**Example** 55 56```ts 57import { BusinessError } from '@kit.BasicServicesKit'; 58 59function addSecureOutput(session: camera.SecureSession, previewOutput: camera.PreviewOutput): void { 60 try { 61 session.addSecureOutput(previewOutput); 62 } catch (error) { 63 // If the operation fails, error.code is returned and processed. 64 let err = error as BusinessError; 65 console.error(`The addOutput call failed. error code: ${err.code}`); 66 } 67} 68``` 69 70## on('error')<sup>12+</sup> 71 72on(type: 'error', callback: ErrorCallback): void 73 74Subscribes to SecureSession error events. This API uses an asynchronous callback to return the result. 75 76> **NOTE** 77> 78> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**. 79 80**Atomic service API**: This API can be used in atomic services since API version 19. 81 82**System capability**: SystemCapability.Multimedia.Camera.Core 83 84**Parameters** 85 86| Name | Type | Mandatory| Description | 87| -------- | ------------------ | ---- | ------------------------------ | 88| type | string | Yes | Event type. The value is fixed at **'error'**. The event can be listened for when a session is created. This event is triggered and the error message is returned when an error occurs during the calling of a session-related API such as [beginConfig](arkts-apis-camera-Session.md#beginconfig11), [commitConfig](arkts-apis-camera-Session.md#commitconfig11-1), and [addInput](arkts-apis-camera-Session.md#addinput11).| 89| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | Yes | Callback used to return an error code defined in [CameraErrorCode](arkts-apis-camera-e.md#cameraerrorcode). | 90 91**Example** 92 93```ts 94import { BusinessError } from '@kit.BasicServicesKit'; 95 96function callback(err: BusinessError): void { 97 console.error(`Video session error code: ${err.code}`); 98} 99 100function registerSessionError(secureSession: camera.SecureSession): void { 101 secureSession.on('error', callback); 102} 103``` 104 105## off('error')<sup>12+</sup> 106 107off(type: 'error', callback?: ErrorCallback): void 108 109Unsubscribes from SecureSession error events. 110 111**Atomic service API**: This API can be used in atomic services since API version 19. 112 113**System capability**: SystemCapability.Multimedia.Camera.Core 114 115**Parameters** 116 117| Name | Type | Mandatory| Description | 118| -------- | --------------------------- | ---- | ------------------------------ | 119| type | string | Yes | Event type. The value is fixed at **'error'**. The event can be listened for when a session is created.| 120| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback)| No | Callback used to return the result. If this parameter is specified, the subscription to the specified event with the specified callback is canceled. (The callback object cannot be an anonymous function.) Otherwise, the subscriptions to the specified event with all the callbacks are canceled.| 121 122**Example** 123 124```ts 125function unregisterSessionError(secureSession: camera.SecureSession): void { 126 secureSession.off('error'); 127} 128``` 129 130## on('focusStateChange')<sup>12+</sup> 131 132on(type: 'focusStateChange', callback: AsyncCallback\<FocusState\>): void 133 134Subscribes to focus state change events. This API uses an asynchronous callback to return the result. 135 136> **NOTE** 137> 138> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**. 139 140**Atomic service API**: This API can be used in atomic services since API version 19. 141 142**System capability**: SystemCapability.Multimedia.Camera.Core 143 144**Parameters** 145 146| Name | Type | Mandatory| Description | 147| -------- | ---------------- | ---- | ------------------------ | 148| type | string | Yes | Event type. The value is fixed at **'focusStateChange'**. The event can be listened for when a session is created. This event is triggered only when the camera focus state changes in auto focus mode.| 149| callback | AsyncCallback\<[FocusState](arkts-apis-camera-e.md#focusstate)\> | Yes | Callback used to return the focus state change. | 150 151**Example** 152 153```ts 154import { BusinessError } from '@kit.BasicServicesKit'; 155 156function callback(err: BusinessError, focusState: camera.FocusState): void { 157 if (err !== undefined && err.code !== 0) { 158 console.error(`Callback Error, errorCode: ${err.code}`); 159 return; 160 } 161 console.info(`Focus state: ${focusState}`); 162} 163 164function registerFocusStateChange(secureSession: camera.SecureSession): void { 165 secureSession.on('focusStateChange', callback); 166} 167``` 168 169## off('focusStateChange')<sup>12+</sup> 170 171off(type: 'focusStateChange', callback?: AsyncCallback\<FocusState\>): void 172 173Unsubscribes from focus state change events. 174 175**Atomic service API**: This API can be used in atomic services since API version 19. 176 177**System capability**: SystemCapability.Multimedia.Camera.Core 178 179**Parameters** 180 181| Name | Type | Mandatory| Description | 182| -------- | ----------------------------------------- | ---- | ------------------------ | 183| type | string | Yes | Event type. The value is fixed at **'focusStateChange'**. The event can be listened for when a session is created.| 184| callback | AsyncCallback\<[FocusState](arkts-apis-camera-e.md#focusstate)\> | No | Callback used to return the result. If this parameter is specified, the subscription to the specified event with the specified callback is canceled. (The callback object cannot be an anonymous function.) Otherwise, the subscriptions to the specified event with all the callbacks are canceled.| 185 186**Example** 187 188```ts 189function unregisterFocusStateChange(secureSession: camera.SecureSession): void { 190 secureSession.off('focusStateChange'); 191} 192``` 193