From a2df5e6163b03c1f3bd5747559b614a32de0b04a Mon Sep 17 00:00:00 2001 From: TFStudy <3202410880@qq.com> Date: Mon, 7 Jun 2021 13:57:32 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 6 ++--- .../support/v18/scanner/ScanResult.java | 24 +++++++++++++++++-- .../support/v18/scanner/ObjectsTest.java | 8 ++++--- 3 files changed, 30 insertions(+), 8 deletions(-) rename scanner/src/test/java/no/nordicsemi/{android => }/support/v18/scanner/ObjectsTest.java (93%) diff --git a/README.md b/README.md index 3c7d09b..d8802b5 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/ScanResult.java b/scanner/src/main/java/no/nordicsemi/support/v18/scanner/ScanResult.java index 84a3f86..fe209e8 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. @@ -177,6 +175,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 +185,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 +194,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 +205,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 +214,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 +225,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 +236,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 +247,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 +258,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 +269,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 +281,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/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 f27d574..0c3a3dd 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 { -- Gitee From a30016e8ab44a058e12c87668ce1af427be0dc6c Mon Sep 17 00:00:00 2001 From: TFStudy <3202410880@qq.com> Date: Mon, 7 Jun 2021 14:08:43 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../support/v18/scanner/ScanSettings.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) 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 14fd70f..5e1d8c1 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; @@ -291,6 +297,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 +317,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 +330,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 +349,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 +369,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 +389,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 +408,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 +421,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 +437,11 @@ public final class ScanSettings implements Serializable { return this; } + /** + * build + * + * @return ScanSettings + */ public ScanSettings build() { if (powerSaveRestInterval == 0 && powerSaveScanInterval == 0) updatePowerSaveSettings(); -- Gitee From db54d8acff7e1258501c8fbd52c47215ded0af7f Mon Sep 17 00:00:00 2001 From: TFStudy <3202410880@qq.com> Date: Mon, 7 Jun 2021 14:16:55 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../support/v18/scanner/BluetoothLeScannerCompat.java | 10 ++++++++++ .../nordicsemi/support/v18/scanner/ScanSettings.java | 1 + 2 files changed, 11 insertions(+) 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 008ec50..20c91f1 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,7 @@ public abstract class BluetoothLeScannerCompat { * An app must hold * in order to get results. * + * @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 +108,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 +148,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 +171,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/ScanSettings.java b/scanner/src/main/java/no/nordicsemi/support/v18/scanner/ScanSettings.java index 5e1d8c1..00c28a9 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 @@ -171,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; -- Gitee From b0e0d20f45ea06c8be64b4f338ca36e2238d885c Mon Sep 17 00:00:00 2001 From: TFStudy <3202410880@qq.com> Date: Mon, 7 Jun 2021 14:22:56 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../v18/scanner/BluetoothLeScannerCompat.java | 1 + .../support/v18/scanner/BluetoothUuid.java | 2 ++ .../support/v18/scanner/ScanSettings.java | 14 +++++++++++++- 3 files changed, 16 insertions(+), 1 deletion(-) 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 20c91f1..4cb2e74 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 @@ -85,6 +85,7 @@ 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. 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 be0669e..66cf3b9 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/ScanSettings.java b/scanner/src/main/java/no/nordicsemi/support/v18/scanner/ScanSettings.java index 00c28a9..8d6b350 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 @@ -218,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); @@ -242,6 +243,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 || @@ -263,6 +271,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) { @@ -280,6 +290,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) { -- Gitee From 0722f9368465c4e340f6c7f026740f577485d5d1 Mon Sep 17 00:00:00 2001 From: TFStudy <3202410880@qq.com> Date: Mon, 7 Jun 2021 14:25:54 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/no/nordicsemi/support/v18/scanner/ScanResult.java | 2 ++ .../java/no/nordicsemi/support/v18/scanner/ScanSettings.java | 2 ++ 2 files changed, 4 insertions(+) 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 fe209e8..6a38e92 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 @@ -167,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() { 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 8d6b350..30978ad 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 @@ -234,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) { -- Gitee