Loading android/app/jni/com_android_bluetooth_btservice_AdapterService.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -455,7 +455,7 @@ static void energy_info_recv_callback(bt_activity_energy_info *p_energy_info) return; } callbackEnv->CallVoidMethod(sJniCallbacksObj, method_energyInfo, p_energy_info->status, callbackEnv->CallVoidMethod(sJniAdapterServiceObj, method_energyInfo, p_energy_info->status, p_energy_info->ctrl_state, p_energy_info->tx_time, p_energy_info->rx_time, p_energy_info->idle_time, p_energy_info->energy_used); Loading android/app/src/com/android/bluetooth/btservice/AdapterProperties.java +27 −15 Original line number Diff line number Diff line Loading @@ -64,6 +64,7 @@ class AdapterProperties { private int mNumOfOffloadedIrkSupported; private int mNumOfOffloadedScanFilterSupported; private int mOffloadedScanResultStorageBytes; private boolean mIsActivityAndEnergyReporting; // Lock for all getters and setters. // If finer grained locking is needer, more locks Loading Loading @@ -251,6 +252,12 @@ class AdapterProperties { return mOffloadedScanResultStorageBytes; } /** * @return tx/rx/idle activity and energy info */ boolean isActivityAndEnergyReportingSupported() { return mIsActivityAndEnergyReporting; } /** * @return the mBondedDevices */ Loading Loading @@ -532,21 +539,7 @@ class AdapterProperties { break; case AbstractionLayer.BT_PROPERTY_LOCAL_LE_FEATURES: mNumOfAdvertisementInstancesSupported = (0x000000FF & ((int)val[1])); mRpaOffloadSupported = ((0x000000FF & ((int)val[2]))!= 0); mNumOfOffloadedIrkSupported = (0x000000FF & ((int)val[3])); mNumOfOffloadedScanFilterSupported = (0x000000FF & ((int)val[4])); mOffloadedScanResultStorageBytes = (0x000000FF & ((int)val[5])); // TBD for energy support Log.d(TAG, "BT_PROPERTY_LOCAL_LE_FEATURES: update from BT controller" + " mNumOfAdvertisementInstancesSupported = " + mNumOfAdvertisementInstancesSupported + " mRpaOffloadSupported = " + mRpaOffloadSupported + " mNumOfOffloadedIrkSupported = " + mNumOfOffloadedIrkSupported + " mNumOfOffloadedScanFilterSupported = " + mNumOfOffloadedScanFilterSupported + " mOffloadedScanResultStorageBytes = " + mOffloadedScanResultStorageBytes); updateFeatureSupport(val); break; default: Loading @@ -556,6 +549,25 @@ class AdapterProperties { } } void updateFeatureSupport(byte[] val) { mNumOfAdvertisementInstancesSupported = (0xFF & ((int)val[1])); mRpaOffloadSupported = ((0xFF & ((int)val[2]))!= 0); mNumOfOffloadedIrkSupported = (0xFF & ((int)val[3])); mNumOfOffloadedScanFilterSupported = (0xFF & ((int)val[4])); mOffloadedScanResultStorageBytes = (0xFF & ((int)val[5])); mIsActivityAndEnergyReporting = ((0xFF & ((int)val[6])) != 0); Log.d(TAG, "BT_PROPERTY_LOCAL_LE_FEATURES: update from BT controller" + " mNumOfAdvertisementInstancesSupported = " + mNumOfAdvertisementInstancesSupported + " mRpaOffloadSupported = " + mRpaOffloadSupported + " mNumOfOffloadedIrkSupported = " + mNumOfOffloadedIrkSupported + " mNumOfOffloadedScanFilterSupported = " + mNumOfOffloadedScanFilterSupported + " mOffloadedScanResultStorageBytes = " + mOffloadedScanResultStorageBytes + " mIsActivityAndEnergyReporting = " + mIsActivityAndEnergyReporting); } void onBluetoothReady() { Log.d(TAG, "ScanMode = " + mScanMode ); Log.d(TAG, "State = " + getState() ); Loading android/app/src/com/android/bluetooth/btservice/AdapterService.java +73 −17 Original line number Diff line number Diff line Loading @@ -32,6 +32,7 @@ import android.bluetooth.IBluetooth; import android.bluetooth.IBluetoothCallback; import android.bluetooth.IBluetoothManager; import android.bluetooth.IBluetoothManagerCallback; import android.bluetooth.BluetoothActivityEnergyInfo; import android.content.BroadcastReceiver; import android.content.ContentResolver; import android.content.Context; Loading Loading @@ -82,6 +83,12 @@ public class AdapterService extends Service { //For Debugging only private static int sRefCount=0; private int mStackReportedState; private int mTxTimeTotalMs; private int mRxTimeTotalMs; private int mIdleTimeTotalMs; private int mEnergyUsedTotalVoltAmpSecMicro; public static final String ACTION_LOAD_ADAPTER_PROPERTIES = "com.android.bluetooth.btservice.action.LOAD_ADAPTER_PROPERTIES"; public static final String ACTION_SERVICE_STATE_CHANGED = Loading @@ -95,6 +102,8 @@ public class AdapterService extends Service { static final String BLUETOOTH_ADMIN_PERM = android.Manifest.permission.BLUETOOTH_ADMIN; public static final String BLUETOOTH_PRIVILEGED = android.Manifest.permission.BLUETOOTH_PRIVILEGED; static final String BLUETOOTH_PERM = android.Manifest.permission.BLUETOOTH; static final String RECEIVE_MAP_PERM = android.Manifest.permission.RECEIVE_BLUETOOTH_MAP; Loading Loading @@ -959,11 +968,6 @@ public class AdapterService extends Service { service.sendConnectionStateChange(device, profile, state, prevState); } public void getEnergyInfo(){ AdapterService service = getService(); if (service == null) return; service.getEnergyInfo(); } public ParcelFileDescriptor connectSocket(BluetoothDevice device, int type, ParcelUuid uuid, int port, int flag) { if (!Utils.checkCaller()) { Loading Loading @@ -1032,6 +1036,24 @@ public class AdapterService extends Service { int val = service.getOffloadedScanResultStorage(); return (val >= MIN_OFFLOADED_SCAN_STORAGE_BYTES); } public boolean isActivityAndEnergyReportingSupported() { AdapterService service = getService(); if (service == null) return false; return service.isActivityAndEnergyReportingSupported(); } public void getActivityEnergyInfoFromController() { AdapterService service = getService(); if (service == null) return; service.getActivityEnergyInfoFromController(); } public BluetoothActivityEnergyInfo reportActivityInfo() { AdapterService service = getService(); if (service == null) return null; return service.reportActivityInfo(); } }; Loading Loading @@ -1527,9 +1549,31 @@ public class AdapterService extends Service { return mAdapterProperties.getOffloadedScanResultStorage(); } public int getEnergyInfo() { enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission"); return readEnergyInfo(); private boolean isActivityAndEnergyReportingSupported() { enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED, "Need BLUETOOTH permission"); return mAdapterProperties.isActivityAndEnergyReportingSupported(); } private void getActivityEnergyInfoFromController() { enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED, "Need BLUETOOTH permission"); if (isActivityAndEnergyReportingSupported()) { readEnergyInfo(); } } private BluetoothActivityEnergyInfo reportActivityInfo() { enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED, "Need BLUETOOTH permission"); BluetoothActivityEnergyInfo info = new BluetoothActivityEnergyInfo(mStackReportedState, mTxTimeTotalMs, mRxTimeTotalMs, mIdleTimeTotalMs, mEnergyUsedTotalVoltAmpSecMicro); // Read on clear values; a record of data is created with // timstamp and new samples are collected until read again mStackReportedState = 0; mTxTimeTotalMs = 0; mRxTimeTotalMs = 0; mIdleTimeTotalMs = 0; mEnergyUsedTotalVoltAmpSecMicro = 0; return info; } private static int convertScanModeToHal(int mode) { Loading Loading @@ -1624,12 +1668,24 @@ public class AdapterService extends Service { private void energyInfoCallback (int status, int ctrl_state, long tx_time, long rx_time, long idle_time, long energy_used) throws RemoteException { // TBD debugLog("energyInfoCallback " + "status = " + status + // ToDo: Update only status is valid if (ctrl_state >= BluetoothActivityEnergyInfo.BT_STACK_STATE_INVALID && ctrl_state <= BluetoothActivityEnergyInfo.BT_STACK_STATE_STATE_IDLE) { mStackReportedState = ctrl_state; mTxTimeTotalMs += tx_time; mRxTimeTotalMs += rx_time; mIdleTimeTotalMs += idle_time; // Energy is product of mA, V and ms mEnergyUsedTotalVoltAmpSecMicro += energy_used; } if (DBG) { Log.d(TAG, "energyInfoCallback " + "status = " + status + "tx_time = " + tx_time + "rx_time = " + rx_time + "idle_time = " + idle_time + "energy_used = " + energy_used + "ctrl_state = " + ctrl_state); } } private void debugLog(String msg) { if (DBG) Log.d(TAG +"(" +hashCode()+")", msg); Loading Loading
android/app/jni/com_android_bluetooth_btservice_AdapterService.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -455,7 +455,7 @@ static void energy_info_recv_callback(bt_activity_energy_info *p_energy_info) return; } callbackEnv->CallVoidMethod(sJniCallbacksObj, method_energyInfo, p_energy_info->status, callbackEnv->CallVoidMethod(sJniAdapterServiceObj, method_energyInfo, p_energy_info->status, p_energy_info->ctrl_state, p_energy_info->tx_time, p_energy_info->rx_time, p_energy_info->idle_time, p_energy_info->energy_used); Loading
android/app/src/com/android/bluetooth/btservice/AdapterProperties.java +27 −15 Original line number Diff line number Diff line Loading @@ -64,6 +64,7 @@ class AdapterProperties { private int mNumOfOffloadedIrkSupported; private int mNumOfOffloadedScanFilterSupported; private int mOffloadedScanResultStorageBytes; private boolean mIsActivityAndEnergyReporting; // Lock for all getters and setters. // If finer grained locking is needer, more locks Loading Loading @@ -251,6 +252,12 @@ class AdapterProperties { return mOffloadedScanResultStorageBytes; } /** * @return tx/rx/idle activity and energy info */ boolean isActivityAndEnergyReportingSupported() { return mIsActivityAndEnergyReporting; } /** * @return the mBondedDevices */ Loading Loading @@ -532,21 +539,7 @@ class AdapterProperties { break; case AbstractionLayer.BT_PROPERTY_LOCAL_LE_FEATURES: mNumOfAdvertisementInstancesSupported = (0x000000FF & ((int)val[1])); mRpaOffloadSupported = ((0x000000FF & ((int)val[2]))!= 0); mNumOfOffloadedIrkSupported = (0x000000FF & ((int)val[3])); mNumOfOffloadedScanFilterSupported = (0x000000FF & ((int)val[4])); mOffloadedScanResultStorageBytes = (0x000000FF & ((int)val[5])); // TBD for energy support Log.d(TAG, "BT_PROPERTY_LOCAL_LE_FEATURES: update from BT controller" + " mNumOfAdvertisementInstancesSupported = " + mNumOfAdvertisementInstancesSupported + " mRpaOffloadSupported = " + mRpaOffloadSupported + " mNumOfOffloadedIrkSupported = " + mNumOfOffloadedIrkSupported + " mNumOfOffloadedScanFilterSupported = " + mNumOfOffloadedScanFilterSupported + " mOffloadedScanResultStorageBytes = " + mOffloadedScanResultStorageBytes); updateFeatureSupport(val); break; default: Loading @@ -556,6 +549,25 @@ class AdapterProperties { } } void updateFeatureSupport(byte[] val) { mNumOfAdvertisementInstancesSupported = (0xFF & ((int)val[1])); mRpaOffloadSupported = ((0xFF & ((int)val[2]))!= 0); mNumOfOffloadedIrkSupported = (0xFF & ((int)val[3])); mNumOfOffloadedScanFilterSupported = (0xFF & ((int)val[4])); mOffloadedScanResultStorageBytes = (0xFF & ((int)val[5])); mIsActivityAndEnergyReporting = ((0xFF & ((int)val[6])) != 0); Log.d(TAG, "BT_PROPERTY_LOCAL_LE_FEATURES: update from BT controller" + " mNumOfAdvertisementInstancesSupported = " + mNumOfAdvertisementInstancesSupported + " mRpaOffloadSupported = " + mRpaOffloadSupported + " mNumOfOffloadedIrkSupported = " + mNumOfOffloadedIrkSupported + " mNumOfOffloadedScanFilterSupported = " + mNumOfOffloadedScanFilterSupported + " mOffloadedScanResultStorageBytes = " + mOffloadedScanResultStorageBytes + " mIsActivityAndEnergyReporting = " + mIsActivityAndEnergyReporting); } void onBluetoothReady() { Log.d(TAG, "ScanMode = " + mScanMode ); Log.d(TAG, "State = " + getState() ); Loading
android/app/src/com/android/bluetooth/btservice/AdapterService.java +73 −17 Original line number Diff line number Diff line Loading @@ -32,6 +32,7 @@ import android.bluetooth.IBluetooth; import android.bluetooth.IBluetoothCallback; import android.bluetooth.IBluetoothManager; import android.bluetooth.IBluetoothManagerCallback; import android.bluetooth.BluetoothActivityEnergyInfo; import android.content.BroadcastReceiver; import android.content.ContentResolver; import android.content.Context; Loading Loading @@ -82,6 +83,12 @@ public class AdapterService extends Service { //For Debugging only private static int sRefCount=0; private int mStackReportedState; private int mTxTimeTotalMs; private int mRxTimeTotalMs; private int mIdleTimeTotalMs; private int mEnergyUsedTotalVoltAmpSecMicro; public static final String ACTION_LOAD_ADAPTER_PROPERTIES = "com.android.bluetooth.btservice.action.LOAD_ADAPTER_PROPERTIES"; public static final String ACTION_SERVICE_STATE_CHANGED = Loading @@ -95,6 +102,8 @@ public class AdapterService extends Service { static final String BLUETOOTH_ADMIN_PERM = android.Manifest.permission.BLUETOOTH_ADMIN; public static final String BLUETOOTH_PRIVILEGED = android.Manifest.permission.BLUETOOTH_PRIVILEGED; static final String BLUETOOTH_PERM = android.Manifest.permission.BLUETOOTH; static final String RECEIVE_MAP_PERM = android.Manifest.permission.RECEIVE_BLUETOOTH_MAP; Loading Loading @@ -959,11 +968,6 @@ public class AdapterService extends Service { service.sendConnectionStateChange(device, profile, state, prevState); } public void getEnergyInfo(){ AdapterService service = getService(); if (service == null) return; service.getEnergyInfo(); } public ParcelFileDescriptor connectSocket(BluetoothDevice device, int type, ParcelUuid uuid, int port, int flag) { if (!Utils.checkCaller()) { Loading Loading @@ -1032,6 +1036,24 @@ public class AdapterService extends Service { int val = service.getOffloadedScanResultStorage(); return (val >= MIN_OFFLOADED_SCAN_STORAGE_BYTES); } public boolean isActivityAndEnergyReportingSupported() { AdapterService service = getService(); if (service == null) return false; return service.isActivityAndEnergyReportingSupported(); } public void getActivityEnergyInfoFromController() { AdapterService service = getService(); if (service == null) return; service.getActivityEnergyInfoFromController(); } public BluetoothActivityEnergyInfo reportActivityInfo() { AdapterService service = getService(); if (service == null) return null; return service.reportActivityInfo(); } }; Loading Loading @@ -1527,9 +1549,31 @@ public class AdapterService extends Service { return mAdapterProperties.getOffloadedScanResultStorage(); } public int getEnergyInfo() { enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission"); return readEnergyInfo(); private boolean isActivityAndEnergyReportingSupported() { enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED, "Need BLUETOOTH permission"); return mAdapterProperties.isActivityAndEnergyReportingSupported(); } private void getActivityEnergyInfoFromController() { enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED, "Need BLUETOOTH permission"); if (isActivityAndEnergyReportingSupported()) { readEnergyInfo(); } } private BluetoothActivityEnergyInfo reportActivityInfo() { enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED, "Need BLUETOOTH permission"); BluetoothActivityEnergyInfo info = new BluetoothActivityEnergyInfo(mStackReportedState, mTxTimeTotalMs, mRxTimeTotalMs, mIdleTimeTotalMs, mEnergyUsedTotalVoltAmpSecMicro); // Read on clear values; a record of data is created with // timstamp and new samples are collected until read again mStackReportedState = 0; mTxTimeTotalMs = 0; mRxTimeTotalMs = 0; mIdleTimeTotalMs = 0; mEnergyUsedTotalVoltAmpSecMicro = 0; return info; } private static int convertScanModeToHal(int mode) { Loading Loading @@ -1624,12 +1668,24 @@ public class AdapterService extends Service { private void energyInfoCallback (int status, int ctrl_state, long tx_time, long rx_time, long idle_time, long energy_used) throws RemoteException { // TBD debugLog("energyInfoCallback " + "status = " + status + // ToDo: Update only status is valid if (ctrl_state >= BluetoothActivityEnergyInfo.BT_STACK_STATE_INVALID && ctrl_state <= BluetoothActivityEnergyInfo.BT_STACK_STATE_STATE_IDLE) { mStackReportedState = ctrl_state; mTxTimeTotalMs += tx_time; mRxTimeTotalMs += rx_time; mIdleTimeTotalMs += idle_time; // Energy is product of mA, V and ms mEnergyUsedTotalVoltAmpSecMicro += energy_used; } if (DBG) { Log.d(TAG, "energyInfoCallback " + "status = " + status + "tx_time = " + tx_time + "rx_time = " + rx_time + "idle_time = " + idle_time + "energy_used = " + energy_used + "ctrl_state = " + ctrl_state); } } private void debugLog(String msg) { if (DBG) Log.d(TAG +"(" +hashCode()+")", msg); Loading