用到的代码文件
vendor/mediatek/proprietary/packages/apps/Bluetooth/:
src/com/android/bluetooth/btservice/AdapterService.java
src/com/android/bluetooth/btservice/AdapterProperties.java
jni/com_android_bluetooth_btservice_AdapterService.cpp
system/bt/:
btif/src/bluetooth.cc
btif/src/btif_core.cc
btif/src/btif_storage.cc
btif/include/btif_common.h
device/src/controller.cc
代码执行流程图
https://tuzhao.org/article/31#directory044241015592155225
------
frameworks\base\packages\SettingsLib\src\com\android\settingslib\deviceinfo\AbstractBluetoothAddressPreferenceController.java
@SuppressLint("HardwareIds")
@Override
protected void updateConnectivity() {
BluetoothAdapter bluetooth = BluetoothAdapter.getDefaultAdapter();
if (bluetooth != null && mBtAddress != null) {
String address = bluetooth.isEnabled() ? bluetooth.getAddress() : null;
if (!TextUtils.isEmpty(address)) {
// Convert the address to lowercase for consistency with the wifi MAC address.
mBtAddress.setSummary(address.toLowerCase());
} else {
mBtAddress.setSummary(R.string.status_unavailable);
}
}
}
frameworks\base\core\java\android\bluetooth\BluetoothAdapter.java
public String getAddress() {
try {
return mManagerService.getAddress();
} catch (RemoteException e) {
Log.e(TAG, "", e);
}
return null;
}
指向 private final IBluetoothManager mManagerService;
system\bt\binder\android\bluetooth\IBluetoothManager.aidl
frameworks\base\services\core\java\com\android\server\BluetoothManagerService.java
不是IBluetoothManager.aidl文件,而是BluetoothManagerService,因为BluetoothManagerService是继承IBluetoothManager的。
class BluetoothManagerService extends IBluetoothManager.Stub {
public String getAddress() {
mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
if ((Binder.getCallingUid() != Process.SYSTEM_UID) && (!checkIfCallerIsForegroundUser())) {
Slog.w(TAG, "getAddress(): not allowed for non-active and non system user");
return null;
}
if (mContext.checkCallingOrSelfPermission(Manifest.permission.LOCAL_MAC_ADDRESS)
!= PackageManager.PERMISSION_GRANTED) {
return BluetoothAdapter.DEFAULT_MAC_ADDRESS;
}
try {
mBluetoothLock.readLock().lock();
if (mBluetooth != null) {
//到这里
return mBluetooth.getAddress();
}
} catch (RemoteException e) {
Slog.e(TAG,
"getAddress(): Unable to retrieve address remotely. Returning cached address",
e);
} finally {
mBluetoothLock.readLock().unlock();
}
// mAddress is accessed from outside.
/