diff --git a/README.md b/README.md index 3c7d09b730245de68707faf70395092a72d4efaa..d8802b53edafd264681907eb9af87b24943d425b 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ - 功能:蓝牙的操作 - 项目移植状态:主功能完成 - 调用差异:无 -- 开发版本:sdk5,DevEco Studio2.1 beta4 +- 开发版本:sdk5,DevEco Studio 2.1 Release - 基线版本:Release v1.4.3 @@ -32,7 +32,7 @@ dependencies { ...... } ``` -在sdk4,DevEco Studio2.1 beta4下项目可直接运行 +在sdk5,DevEco Studio 2.1 Release下项目可直接运行 如无法运行,删除项目.gradle,.idea,build,gradle,build.gradle文件, 并依据自己的版本创建新项目,将新项目的对应文件复制到根目录下 @@ -54,7 +54,7 @@ dependencies { ``` -#### 测试信息 +#### 测试信息 CodeCheck代码测试无异常 diff --git a/scanner/src/main/java/no/nordicsemi/support/v18/scanner/BluetoothLeScannerCompat.java b/scanner/src/main/java/no/nordicsemi/support/v18/scanner/BluetoothLeScannerCompat.java index 008ec50fc8beba38c32f59e4cd1afcd86242b95e..4cb2e74d0eeff56fe2f4ab58a3f3f3fe3304d375 100644 --- a/scanner/src/main/java/no/nordicsemi/support/v18/scanner/BluetoothLeScannerCompat.java +++ b/scanner/src/main/java/no/nordicsemi/support/v18/scanner/BluetoothLeScannerCompat.java @@ -65,6 +65,7 @@ public abstract class BluetoothLeScannerCompat { * An app must hold * in order to get results. * + * @param context context * @param callback Callback used to deliver scan results. * @throws IllegalArgumentException If {@code callback} is null. */ @@ -84,6 +85,8 @@ public abstract class BluetoothLeScannerCompat { * An app must hold * in order to get results. * + * @param filters filters + * @param context context * @param settings Optional settings for the scan. * @param callback Callback used to deliver scan results. * @throws IllegalArgumentException If {@code settings} or {@code callback} is null. @@ -106,6 +109,9 @@ public abstract class BluetoothLeScannerCompat { * An app must hold * in order to get results. * + * @param context context + * @param scanFilters scanFilters + * @param scanSettings scanSettings * @param callback Callback used to deliver scan results. * @param handler Optional handler used to deliver results. * @throws IllegalArgumentException If {@code settings} or {@code callback} is null. @@ -143,6 +149,9 @@ public abstract class BluetoothLeScannerCompat { * contain one or more of the extras {@link #EXTRA_CALLBACK_TYPE}, {@link #EXTRA_ERROR_CODE} and * {@link #EXTRA_LIST_SCAN_RESULT} to indicate the result of the scan. * + * @param filters filters + * @param settings settings + * @param context context * @param callbackIntent The PendingIntent to deliver the result to. * @throws IllegalArgumentException If {@code settings} or {@code callback} is null. */ @@ -163,6 +172,8 @@ public abstract class BluetoothLeScannerCompat { /** * Stops an ongoing Bluetooth LE scan. *
+ * + * @param context context * @param callbackIntent The PendingIntent that was used to start the scan. */ public final void stopScan(final Context context, diff --git a/scanner/src/main/java/no/nordicsemi/support/v18/scanner/BluetoothUuid.java b/scanner/src/main/java/no/nordicsemi/support/v18/scanner/BluetoothUuid.java index be0669ebc296f2c030ad04d8b74f5dc009fff838..66cf3b9cf8f2e2c98969225e211275cf81db67d3 100644 --- a/scanner/src/main/java/no/nordicsemi/support/v18/scanner/BluetoothUuid.java +++ b/scanner/src/main/java/no/nordicsemi/support/v18/scanner/BluetoothUuid.java @@ -29,6 +29,8 @@ import java.util.UUID; * Note UUID is little endian in Bluetooth. * @param uuidBytes Byte representation of uuid. * @throws IllegalArgumentException If the {@code uuidBytes} cannot be parsed. + * + * @return SequenceUuid */ static SequenceUuid parseUuidFrom(final byte[] uuidBytes) { diff --git a/scanner/src/main/java/no/nordicsemi/support/v18/scanner/ScanResult.java b/scanner/src/main/java/no/nordicsemi/support/v18/scanner/ScanResult.java index 84a3f8609d81361e4d693d8e10f640485c1e5e3a..6a38e929322e9840db8fa5dcf6f44c9cec2161a5 100644 --- a/scanner/src/main/java/no/nordicsemi/support/v18/scanner/ScanResult.java +++ b/scanner/src/main/java/no/nordicsemi/support/v18/scanner/ScanResult.java @@ -22,7 +22,6 @@ package no.nordicsemi.support.v18.scanner; - import ohos.bluetooth.ble.BleScanResult; import ohos.utils.Parcel; import ohos.utils.Sequenceable; @@ -33,7 +32,6 @@ import org.jetbrains.annotations.Nullable; */ @SuppressWarnings({"WeakerAccess", "unused"}) public final class ScanResult implements Sequenceable { - /** * For chained advertisements, indicates that the data contained in this * scan result is complete. @@ -169,6 +167,8 @@ public final class ScanResult implements Sequenceable { /** * Returns the remote Bluetooth device identified by the Bluetooth device address. + * + * @return Object */ public Object getDevice() { @@ -177,6 +177,8 @@ public final class ScanResult implements Sequenceable { /** * Returns the scan record, which is a combination of advertisement and scan response. + * + * @return scanRecord */ @Nullable public ScanRecord getScanRecord() { @@ -185,6 +187,8 @@ public final class ScanResult implements Sequenceable { /** * Returns the received signal strength in dBm. The valid range is [-127, 126]. + * + * @return rssi */ public int getRssi() { return rssi; @@ -192,6 +196,8 @@ public final class ScanResult implements Sequenceable { /** * Returns timestamp since boot when the scan record was observed. + * + * @return timestampNanos */ public long getTimestampNanos() { return timestampNanos; @@ -201,6 +207,8 @@ public final class ScanResult implements Sequenceable { * Returns true if this object represents legacy scan result. * Legacy scan results do not contain advanced advertising information * as specified in the Bluetooth Core Specification v5. + * + * @return boolean */ public boolean isLegacy() { return (eventType & ET_LEGACY_MASK) != 0; @@ -208,6 +216,8 @@ public final class ScanResult implements Sequenceable { /** * Returns true if this object represents connectable scan result. + * + * @return boolean */ public boolean isConnectable() { return (eventType & ET_CONNECTABLE_MASK) != 0; @@ -217,6 +227,8 @@ public final class ScanResult implements Sequenceable { * Returns the data status. * Can be one of {@link ScanResult#DATA_COMPLETE} or * {@link ScanResult#DATA_TRUNCATED}. + * + * @return int */ public int getDataStatus() { // return bit 5 and 6 @@ -226,6 +238,8 @@ public final class ScanResult implements Sequenceable { /** * Returns the primary Physical Layer * on which this advertisement was received. + * + * @return primaryPhy */ public int getPrimaryPhy() { return primaryPhy; @@ -235,6 +249,8 @@ public final class ScanResult implements Sequenceable { * Returns the secondary Physical Layer * or {@link ScanResult#PHY_UNUSED} - if the advertisement * was not received on a secondary physical channel. + * + * @return secondaryPhy */ public int getSecondaryPhy() { return secondaryPhy; @@ -244,6 +260,8 @@ public final class ScanResult implements Sequenceable { * Returns the advertising set id. * May return {@link ScanResult#SID_NOT_PRESENT} if * no set id was is present. + * + * @return advertisingSid */ public int getAdvertisingSid() { return advertisingSid; @@ -253,6 +271,8 @@ public final class ScanResult implements Sequenceable { * Returns the transmit power in dBm. * Valid range is [-127, 126]. A value of {@link ScanResult#TX_POWER_NOT_PRESENT} * indicates that the TX power is not present. + * + * @return txPower */ public int getTxPower() { return txPower; @@ -263,6 +283,8 @@ public final class ScanResult implements Sequenceable { * Valid range is 6 (7.5ms) to 65536 (81918.75ms). A value of * {@link ScanResult#PERIODIC_INTERVAL_NOT_PRESENT} means periodic * advertising interval is not present. + * + * @return periodicAdvertisingInterval */ public int getPeriodicAdvertisingInterval() { return periodicAdvertisingInterval; diff --git a/scanner/src/main/java/no/nordicsemi/support/v18/scanner/ScanSettings.java b/scanner/src/main/java/no/nordicsemi/support/v18/scanner/ScanSettings.java index 14fd70fa46d93f363d9f706329981b059ab0a294..30978ad8533846f09debaf61583bfa53fa11f7d9 100644 --- a/scanner/src/main/java/no/nordicsemi/support/v18/scanner/ScanSettings.java +++ b/scanner/src/main/java/no/nordicsemi/support/v18/scanner/ScanSettings.java @@ -88,12 +88,16 @@ public final class ScanSettings implements Serializable { * Returns whether only legacy advertisements will be returned. * Legacy advertisements include advertisements as specified * by the Bluetooth core specification 4.2 and below. + * + * @return legacy */ public boolean getLegacy() { return legacy; } /** * Returns the physical layer used during a scan. + * + * @return phy */ public int getPhy() { return phy; @@ -101,6 +105,8 @@ public final class ScanSettings implements Serializable { /** * Returns report delay timestamp based on the device clock. + * + * @return reportDelayMillis */ public long getReportDelayMillis() { return reportDelayMillis; @@ -165,6 +171,7 @@ public final class ScanSettings implements Serializable { /** * Determine if we should do power-saving sleep on pre-Lollipop + * @return boolean */ public boolean hasPowerSaveMode() { return powerSaveRestInterval > 0 && powerSaveScanInterval > 0; @@ -211,8 +218,9 @@ public final class ScanSettings implements Serializable { * {@link #SCAN_MODE_LOW_LATENCY} or * {@link #SCAN_MODE_OPPORTUNISTIC}. * @throws IllegalArgumentException If the {@code scanMode} is invalid. + * + * @return Builder */ - public Builder setScanMode(final int scanMode) { if (scanMode < SCAN_MODE_OPPORTUNISTIC || scanMode > SCAN_MODE_LOW_LATENCY) { throw new IllegalArgumentException("invalid scan mode " + scanMode); @@ -226,6 +234,8 @@ public final class ScanSettings implements Serializable { * * @param callbackType The callback type flags for the scan. * @throws IllegalArgumentException If the {@code callbackType} is invalid. + * + * @return Builder */ public Builder setCallbackType(final int callbackType) { @@ -235,6 +245,13 @@ public final class ScanSettings implements Serializable { this.callbackType = callbackType; return this; } + + /** + * isValidCallbackType + * + * @param callbackType callbackType + * @return boolean + */ private boolean isValidCallbackType(final int callbackType) { if (callbackType == CALLBACK_TYPE_ALL_MATCHES || callbackType == CALLBACK_TYPE_FIRST_MATCH || @@ -256,6 +273,8 @@ public final class ScanSettings implements Serializable { * will be called in unreliable intervals, but starting from * around 5000 the intervals get even. * @throws IllegalArgumentException If {@code reportDelayMillis} < 0. + * + * @return Builder */ public Builder setReportDelay(final long reportDelayMillis) { if (reportDelayMillis < 0) { @@ -273,6 +292,8 @@ public final class ScanSettings implements Serializable { * {@link ScanSettings#MATCH_NUM_FEW_ADVERTISEMENT} or * {@link ScanSettings#MATCH_NUM_MAX_ADVERTISEMENT} * @throws IllegalArgumentException If the {@code matchMode} is invalid. + * + * @return Builder */ public Builder setNumOfMatches(final int numOfMatches) { @@ -291,6 +312,8 @@ public final class ScanSettings implements Serializable { * {@link ScanSettings#MATCH_MODE_AGGRESSIVE} or * {@link ScanSettings#MATCH_MODE_STICKY} * @throws IllegalArgumentException If the {@code matchMode} is invalid. + * + * @return Builder */ public Builder setMatchMode(final int matchMode) { @@ -309,6 +332,8 @@ public final class ScanSettings implements Serializable { * for compatibility with older apps. * * @param legacy true if only legacy advertisements will be returned + * + * @return Builder */ public Builder setLegacy(final boolean legacy) { this.legacy = legacy; @@ -320,6 +345,9 @@ public final class ScanSettings implements Serializable { * This is used only if {@link Builder#setLegacy} * may be used to check whether LE Coded phy is supported by calling * Selecting an unsupported phy will result in failure to start scan. + * @param phy phy + * + * @return Builder */ public Builder setPhy(final int phy) { @@ -336,6 +364,8 @@ public final class ScanSettings implements Serializable { * @param use true to enable (default) hardware offload filtering. * If false a compat software filtering will be used * (uses much more resources). + * + * @return Builder */ public Builder setUseHardwareFilteringIfSupported(final boolean use) { @@ -354,6 +384,8 @@ public final class ScanSettings implements Serializable { * * @param use true to enable (default) hardware offloaded batching if they are supported. * False to always use compat mechanism. + * + * @return Builder */ public Builder setUseHardwareBatchingIfSupported(final boolean use) { @@ -372,6 +404,8 @@ public final class ScanSettings implements Serializable { * * @param use true to enable (default) the offloaded match reporting if hardware supports it, * false to enable compat implementation. + * + * @return Builder */ public Builder setUseHardwareCallbackTypesIfSupported(final boolean use) { @@ -389,6 +423,8 @@ public final class ScanSettings implements Serializable { * @param deviceTimeoutMillis the time required for the device to be recognized as lost * (default {@link #MATCH_LOST_DEVICE_TIMEOUT_DEFAULT}). * @param taskIntervalMillis the task interval (default {@link #MATCH_LOST_TASK_INTERVAL_DEFAULT}). + * + * @return Builder */ public Builder setMatchOptions(final long deviceTimeoutMillis, final long taskIntervalMillis) { @@ -400,6 +436,13 @@ public final class ScanSettings implements Serializable { return this; } + /** + * setPowerSave + * + * @param scanInterval scanInterval + * @param restInterval restInterval + * @return Builder + */ public Builder setPowerSave(final long scanInterval, final long restInterval) { if (scanInterval <= 0 || restInterval <= 0) { throw new IllegalArgumentException("scanInterval and restInterval must be > 0"); @@ -409,6 +452,11 @@ public final class ScanSettings implements Serializable { return this; } + /** + * build + * + * @return ScanSettings + */ public ScanSettings build() { if (powerSaveRestInterval == 0 && powerSaveScanInterval == 0) updatePowerSaveSettings(); diff --git a/scanner/src/test/java/no/nordicsemi/android/support/v18/scanner/ObjectsTest.java b/scanner/src/test/java/no/nordicsemi/support/v18/scanner/ObjectsTest.java similarity index 93% rename from scanner/src/test/java/no/nordicsemi/android/support/v18/scanner/ObjectsTest.java rename to scanner/src/test/java/no/nordicsemi/support/v18/scanner/ObjectsTest.java index f27d5742235fe8053bff36d07bd125e1513c4a9c..0c3a3dd553264485f2d268068c01e3d5f395962b 100644 --- a/scanner/src/test/java/no/nordicsemi/android/support/v18/scanner/ObjectsTest.java +++ b/scanner/src/test/java/no/nordicsemi/support/v18/scanner/ObjectsTest.java @@ -1,10 +1,12 @@ -package no.nordicsemi.android.support.v18.scanner; +package no.nordicsemi.support.v18.scanner; import org.junit.Test; +import java.util.Objects; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; public class ObjectsTest {