蓝牙名称和扫描逻辑优化

Signed-off-by: weiyunxing <weiyunxing@huawei.com>
This commit is contained in:
weiyunxing 2022-06-24 14:40:50 +08:00
parent eb5144ff2b
commit 2da28fafb0

View File

@ -19,6 +19,7 @@ import Log from '../../../../../../../../common/utils/src/main/ets/default/baseU
import ConfigData from '../../../../../../../../common/utils/src/main/ets/default/baseUtil/ConfigData';
import ISettingsController from '../../../../../../../../common/component/src/main/ets/default/controller/ISettingsController';
import LogUtil from '../../../../../../../../common/utils/src/main/ets/default/baseUtil/LogUtil';
import AboutDeviceModel from '../../model/aboutDeviceImpl/AboutDeviceModel'
const DISCOVERY_DURING_TIME: number = 30000; // 30'
const DISCOVERY_INTERVAL_TIME: number = 3000; // 3'
@ -112,7 +113,7 @@ export default class BluetoothDeviceController extends BaseSettingsController {
* Get Local Name
*/
getLocalName() {
AppStorage.SetOrCreate('bluetoothLocalName', BluetoothModel.getLocalName());
AppStorage.SetOrCreate('bluetoothLocalName', AboutDeviceModel.getSystemName());
}
/**
@ -260,7 +261,7 @@ export default class BluetoothDeviceController extends BaseSettingsController {
this.startBluetoothDiscovery();
} else {
LogUtil.log(this.TAG + 'bluetooth state changed. subscribe')
this.stopBluetoothDiscovery();
this.mStopBluetoothDiscovery();
}
});
}
@ -418,6 +419,21 @@ export default class BluetoothDeviceController extends BaseSettingsController {
}, DISCOVERY_INTERVAL_TIME);
}
/**
* Stop bluetooth discovery.
*/
private mStopBluetoothDiscovery() {
this.isDeviceDiscovering = false;
BluetoothModel.stopBluetoothDiscovery();
if (this.discoveryStartTimeoutId) {
clearTimeout(this.discoveryStartTimeoutId);
}
if (this.discoveryStopTimeoutId) {
clearTimeout(this.discoveryStopTimeoutId);
}
}
/**
* Get available device.
*