1e41f4b71Sopenharmony_ci# Pan-sensor Subsystem Changelog 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci 4e41f4b71Sopenharmony_ci## cl.vibrator.1 Added Attributes Related to Custom Vibration 5e41f4b71Sopenharmony_ci 6e41f4b71Sopenharmony_ciThe attributes **VibrateFromFile** (custom vibration effect) and **HapticFileDescriptor** (file descriptor of the custom vibration configuration file) are added. The vibration effect supported by **startVibration** is extended from **VibrateEffect = VibrateTime | VibratePreset** to **VibrateEffect = VibrateTime | VibratePreset | VibrateFromFile**. 7e41f4b71Sopenharmony_ci 8e41f4b71Sopenharmony_ci**Change Impact** 9e41f4b71Sopenharmony_ci 10e41f4b71Sopenharmony_ciWhen developing applications based on OpenHarmony4.0.8.2 and later SDK versions, you can use the **VibrateFromFile** attribute to enable devices that support custom vibration to trigger vibration according to the vibration sequence configured in the custom vibration configuration file. 11e41f4b71Sopenharmony_ci 12e41f4b71Sopenharmony_ci**Key API/Component Changes** 13e41f4b71Sopenharmony_ci 14e41f4b71Sopenharmony_ciAdded the **VibrateFromFile** and **HapticFileDescriptor** attributes to **@ohos.vibrator.d.ts**. 15e41f4b71Sopenharmony_ci 16e41f4b71Sopenharmony_ci| Module| Class| Method/Attribute/Enum/Constant| Change Type| 17e41f4b71Sopenharmony_ci| -- | -- | -- | -- | 18e41f4b71Sopenharmony_ci| @ohos.vibrator.d.ts | vibrator | HapticFileDescriptor | Added| 19e41f4b71Sopenharmony_ci| @ohos.vibrator.d.ts | vibrator | VibrateFromFile | Added| 20e41f4b71Sopenharmony_ci 21e41f4b71Sopenharmony_ci**Adaptation Guide** 22e41f4b71Sopenharmony_ci 23e41f4b71Sopenharmony_ciObtain the resources in the vibration configuration file through the resource management API, and start or stop custom vibration as required. 24e41f4b71Sopenharmony_ci 25e41f4b71Sopenharmony_ci```ts 26e41f4b71Sopenharmony_ciimport vibrator from '@ohos.vibrator'; 27e41f4b71Sopenharmony_ciimport resourceManager from '@ohos.resourceManager'; 28e41f4b71Sopenharmony_ci 29e41f4b71Sopenharmony_ciconst FILE_NAME = "xxx.json"; 30e41f4b71Sopenharmony_ci 31e41f4b71Sopenharmony_ciasync function openResource(fileName) { 32e41f4b71Sopenharmony_ci let fileDescriptor = undefined; 33e41f4b71Sopenharmony_ci let mgr = await resourceManager.getResourceManager(); 34e41f4b71Sopenharmony_ci await mgr.getRawFd(fileName).then(value => { 35e41f4b71Sopenharmony_ci fileDescriptor = {fd: value.fd, offset: value.offset, length: value.length}; 36e41f4b71Sopenharmony_ci console.log('openResource success fileName: ' + fileName); 37e41f4b71Sopenharmony_ci }).catch(error => { 38e41f4b71Sopenharmony_ci console.log('openResource err: ' + error); 39e41f4b71Sopenharmony_ci }); 40e41f4b71Sopenharmony_ci return fileDescriptor; 41e41f4b71Sopenharmony_ci} 42e41f4b71Sopenharmony_ci 43e41f4b71Sopenharmony_ciasync function closeResource(fileName) { 44e41f4b71Sopenharmony_ci let mgr = await resourceManager.getResourceManager(); 45e41f4b71Sopenharmony_ci await mgr.closeRawFd(fileName).then(()=> { 46e41f4b71Sopenharmony_ci console.log('closeResource success fileName: ' + fileName); 47e41f4b71Sopenharmony_ci }).catch(error => { 48e41f4b71Sopenharmony_ci console.log('closeResource err: ' + error); 49e41f4b71Sopenharmony_ci }); 50e41f4b71Sopenharmony_ci} 51e41f4b71Sopenharmony_ci 52e41f4b71Sopenharmony_ci// Obtain the file descriptor of the vibration configuration file. 53e41f4b71Sopenharmony_cilet rawFd = openResource(FILE_NAME); 54e41f4b71Sopenharmony_ci// To use startVibration and stopVibration, you must configure the ohos.permission.VIBRATE permission. 55e41f4b71Sopenharmony_citry { 56e41f4b71Sopenharmony_ci // Start custom vibration. 57e41f4b71Sopenharmony_ci vibrator.startVibration({ 58e41f4b71Sopenharmony_ci type: "file", 59e41f4b71Sopenharmony_ci hapticFd: { fd: rawFd.fd, offset: rawFd.offset, length: rawFd.length } 60e41f4b71Sopenharmony_ci }, { 61e41f4b71Sopenharmony_ci usage: "alarm" 62e41f4b71Sopenharmony_ci }).then(() => { 63e41f4b71Sopenharmony_ci console.info('startVibration success'); 64e41f4b71Sopenharmony_ci }, (error) => { 65e41f4b71Sopenharmony_ci console.info('startVibration error'); 66e41f4b71Sopenharmony_ci }); 67e41f4b71Sopenharmony_ci // Stop vibration in all modes. 68e41f4b71Sopenharmony_ci vibrator.stopVibration(function (error) { 69e41f4b71Sopenharmony_ci if (error) { 70e41f4b71Sopenharmony_ci console.log('error.code' + error.code + 'error.message' + error.message); 71e41f4b71Sopenharmony_ci return; 72e41f4b71Sopenharmony_ci } 73e41f4b71Sopenharmony_ci console.log('Callback returned to indicate successful.'); 74e41f4b71Sopenharmony_ci }) 75e41f4b71Sopenharmony_ci} catch (error) { 76e41f4b71Sopenharmony_ci console.info('errCode: ' + error.code + ' ,msg: ' + error.message); 77e41f4b71Sopenharmony_ci} 78e41f4b71Sopenharmony_ci// Close the vibration configuration file. 79e41f4b71Sopenharmony_cicloseResource(FILE_NAME); 80e41f4b71Sopenharmony_ci``` 81