自 2025 年 3 月 27 日起,我們建議您使用 android-latest-release
而非 aosp-main
建構及貢獻 AOSP。詳情請參閱「Android 開放原始碼計畫變更」。
Sl4aBluetoothUtil
public
class
Sl4aBluetoothUtil
extends Object
java.lang.Object
|
↳ |
com.android.tradefed.util.Sl4aBluetoothUtil
|
公用程式類別會使用 SL4A 在一部或兩部裝置上提供藍牙作業
摘要
公用方法 |
boolean
|
changeProfileAccessPermission(ITestDevice primary, ITestDevice secondary, Sl4aBluetoothUtil.BluetoothProfile profile, Sl4aBluetoothUtil.BluetoothAccessLevel access)
在主要裝置上變更次要裝置的藍牙設定檔存取權,以便次要裝置透過指定的設定檔存取主要裝置
|
boolean
|
connect(ITestDevice primary, ITestDevice secondary, profiles)
在指定的藍牙設定檔中,將主要裝置連線至次要裝置
|
boolean
|
disable(ITestDevice device)
在目標裝置上停用藍牙
|
boolean
|
disableBluetoothSnoopLog(ITestDevice device)
停用藍牙窺探記錄
|
boolean
|
disconnect(ITestDevice primary, ITestDevice secondary, profiles)
將主要裝置與次要裝置的連線中斷
|
boolean
|
enable(ITestDevice device)
在目標裝置上啟用藍牙
|
boolean
|
enableBluetoothSnoopLog(ITestDevice device)
啟用藍牙窺探記錄
|
String
|
getAddress(ITestDevice device)
取得目標裝置的藍牙 MAC 位址
|
|
getBondedDevices(ITestDevice device)
取得目標裝置上已綁定 (配對) 裝置的藍牙 MAC 位址集合
|
boolean
|
pair(ITestDevice primary, ITestDevice secondary)
將主要裝置與次要裝置配對
|
void
|
setBtConnectionTimeout(Duration timeout)
|
void
|
setBtPairTimeout(Duration timeout)
|
boolean
|
setProfilePriority(ITestDevice primary, ITestDevice secondary, profiles, Sl4aBluetoothUtil.BluetoothPriorityLevel priority)
將主要裝置上指定設定檔的優先順序變更為次要裝置
|
void
|
startSl4a(ITestDevice device, File sl4aApkFile)
使用指定裝置和 SL4A apk 檔案,明確啟動 SL4A 用戶端。
|
void
|
stopSl4a()
停止已開啟的 SL4A 用戶端。
|
boolean
|
unpairAll(ITestDevice device)
取消配對目前裝置的所有已配對裝置
|
公用建構函式
Sl4aBluetoothUtil
public Sl4aBluetoothUtil ()
公用方法
changeProfileAccessPermission
public boolean changeProfileAccessPermission (ITestDevice primary,
ITestDevice secondary,
Sl4aBluetoothUtil.BluetoothProfile profile,
Sl4aBluetoothUtil.BluetoothAccessLevel access)
在主要裝置上變更次要裝置的藍牙設定檔存取權,以便次要裝置透過指定設定檔存取主要裝置
參數 |
primary |
ITestDevice :變更權限的裝置 |
secondary |
ITestDevice :在指定設定檔中存取主要裝置的裝置 |
profile |
Sl4aBluetoothUtil.BluetoothProfile :要存取的藍牙設定檔 |
access |
Sl4aBluetoothUtil.BluetoothAccessLevel :存取層級,請參閱 BluetoothAccessLevel |
傳回 |
boolean |
如果權限變更成功,則為 true |
連線
public boolean connect (ITestDevice primary,
ITestDevice secondary,
profiles)
在指定的藍牙設定檔中,將主要裝置連線至次要裝置
參數 |
primary |
ITestDevice :要連線的裝置 |
secondary |
ITestDevice :要連線的裝置 |
profiles |
:需要一組藍牙設定檔才能連線 |
傳回 |
boolean |
如果連線成功,則為 true |
停用
public boolean disable (ITestDevice device)
在目標裝置上停用藍牙
參數 |
device |
ITestDevice :目標裝置 |
傳回 |
boolean |
如果藍牙已成功停用,則為「true」 |
disableBluetoothSnoopLog
public boolean disableBluetoothSnoopLog (ITestDevice device)
停用藍牙窺探記錄
參數 |
device |
ITestDevice :停用窺探記錄 |
取消連結
public boolean disconnect (ITestDevice primary,
ITestDevice secondary,
profiles)
將主要裝置與次要裝置斷開連線
參數 |
primary |
ITestDevice :要執行取消連結作業的裝置 |
secondary |
ITestDevice :要中斷連線的裝置 |
profiles |
:指定需要中斷的藍牙設定檔組合 |
傳回 |
boolean |
如果已成功中斷連線,則為 true |
啟用
public boolean enable (ITestDevice device)
在目標裝置上啟用藍牙
參數 |
device |
ITestDevice :目標裝置 |
傳回 |
boolean |
如果藍牙已成功啟用,則為「true」。 |
enableBluetoothSnoopLog
public boolean enableBluetoothSnoopLog (ITestDevice device)
啟用藍牙窺探記錄
參數 |
device |
ITestDevice :啟用窺探記錄 |
傳回 |
boolean |
如果已成功啟用,則為「true」。 |
getAddress
public String getAddress (ITestDevice device)
取得目標裝置的藍牙 MAC 位址
參數 |
device |
ITestDevice :目標裝置 |
getBondedDevices
public getBondedDevices (ITestDevice device)
取得目標裝置上已綁定 (配對) 裝置的藍牙 MAC 位址組合
參數 |
device |
ITestDevice :目標裝置 |
配對
public boolean pair (ITestDevice primary,
ITestDevice secondary)
將主要裝置與次要裝置配對
參數 |
primary |
ITestDevice :要配對的裝置 |
secondary |
ITestDevice :要配對的裝置 |
傳回 |
boolean |
如果配對成功,則為 true |
setBtConnectionTimeout
public void setBtConnectionTimeout (Duration timeout)
setBtPairTimeout
public void setBtPairTimeout (Duration timeout)
setProfilePriority
public boolean setProfilePriority (ITestDevice primary,
ITestDevice secondary,
profiles,
Sl4aBluetoothUtil.BluetoothPriorityLevel priority)
將主要裝置上指定設定檔的優先順序變更為次要裝置
參數 |
primary |
ITestDevice :要設定優先順序的裝置 |
secondary |
ITestDevice :要設定優先順序的裝置 |
profiles |
:變更優先順序設定的藍牙設定檔 |
priority |
Sl4aBluetoothUtil.BluetoothPriorityLevel :優先順序 |
傳回 |
boolean |
如果已成功設定優先順序,則為 true |
startSl4a
public void startSl4a (ITestDevice device,
File sl4aApkFile)
使用指定裝置和 SL4A apk 檔案,明確啟動 SL4A 用戶端。通常不需要使用這個方法,因為系統會在實際作業前建立 SL4A 連線。
參數 |
device |
ITestDevice :要使用 SL4A 連線的裝置 |
sl4aApkFile |
File :要安裝及使用的 SL4A APK (選用)。 |
stopSl4a
public void stopSl4a ()
停止已開啟的 SL4A 用戶端。它基本上提供一種方法,可在用戶端不再使用時立即清理
unpairAll
public boolean unpairAll (ITestDevice device)
取消配對目前裝置的所有配對裝置
參數 |
device |
ITestDevice :要執行動作的目前裝置 |
傳回 |
boolean |
如果解除配對成功,則為 true |
受保護的方法
完成
protected void finalize ()
清除所有 SL4A 連線
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-03-26 (世界標準時間)。
[null,null,["上次更新時間:2025-03-26 (世界標準時間)。"],[],[]]