Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 99a9b349 authored by Prerepa Viswanadham's avatar Prerepa Viswanadham Committed by Android Git Automerger
Browse files

am 2de2358f: LE energy info feature

* commit '2de2358f':
  LE energy info feature
parents 60cb5c8f 2de2358f
Loading
Loading
Loading
Loading
+30 −1
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ static jmethodID method_setWakeAlarm;
static jmethodID method_acquireWakeLock;
static jmethodID method_releaseWakeLock;
static jmethodID method_deviceMasInstancesFoundCallback;
static jmethodID method_energyInfo;

static const bt_interface_t *sBluetoothInterface = NULL;
static const btsock_interface_t *sBluetoothSocketInterface = NULL;
@@ -446,6 +447,21 @@ static void le_test_mode_recv_callback (bt_status_t status, uint16_t packet_coun

    ALOGV("%s: status:%d packet_count:%d ", __FUNCTION__, status, packet_count);
}

static void energy_info_recv_callback(bt_activity_energy_info *p_energy_info)
{
    if (!checkCallbackThread()) {
       ALOGE("Callback: '%s' is not called on the correct thread", __FUNCTION__);
       return;
    }

    callbackEnv->CallVoidMethod(sJniCallbacksObj, 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);

    checkAndClearExceptionFromCallback(callbackEnv, __FUNCTION__);
}

static bt_callbacks_t sBluetoothCallbacks = {
    sizeof(sBluetoothCallbacks),
    adapter_state_change_callback,
@@ -460,7 +476,8 @@ static bt_callbacks_t sBluetoothCallbacks = {
    callback_thread_event,
    dut_mode_recv_callback,

    le_test_mode_recv_callback
    le_test_mode_recv_callback,
    energy_info_recv_callback
};

// The callback to call when the wake alarm fires.
@@ -689,6 +706,7 @@ static void classInitNative(JNIEnv* env, jclass clazz) {
    method_deviceMasInstancesFoundCallback = env->GetMethodID(jniCallbackClass,
                                                    "deviceMasInstancesFoundCallback",
                                                    "(I[B[Ljava/lang/String;[I[I[I)V");
    method_energyInfo = env->GetMethodID(clazz, "energyInfoCallback", "(IIJJJJ)V");

    char value[PROPERTY_VALUE_MAX];
    property_get("bluetooth.mock_stack", value, "");
@@ -1179,6 +1197,16 @@ static jboolean configHciSnoopLogNative(JNIEnv* env, jobject obj, jboolean enabl
    return result;
}

static int readEnergyInfo()
{
    ALOGV("%s:",__FUNCTION__);
    jboolean result = JNI_FALSE;
    if (!sBluetoothInterface) return result;
    int ret = sBluetoothInterface->read_energy_info();
    result = (ret == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
    return result;
}

static JNINativeMethod sMethods[] = {
    /* name, signature, funcPtr */
    {"classInitNative", "()V", (void *) classInitNative},
@@ -1206,6 +1234,7 @@ static JNINativeMethod sMethods[] = {
     (void*) createSocketChannelNative},
    {"configHciSnoopLogNative", "(Z)Z", (void*) configHciSnoopLogNative},
    {"alarmFiredNative", "()V", (void *) alarmFiredNative},
    {"readEnergyInfo", "()I", (void*) readEnergyInfo},
};

int register_com_android_bluetooth_btservice_AdapterService(JNIEnv* env)
+0 −2
Original line number Diff line number Diff line
@@ -149,7 +149,6 @@ static jmethodID method_onWriteCharacteristic;
static jmethodID method_onExecuteCompleted;
static jmethodID method_onSearchCompleted;
static jmethodID method_onSearchResult;
static jmethodID method_onReadDescrExtProp;
static jmethodID method_onReadDescriptor;
static jmethodID method_onWriteDescriptor;
static jmethodID method_onNotify;
@@ -564,7 +563,6 @@ void btgattc_track_adv_event_cb(int client_if, int filt_index, int addr_type,
    checkAndClearExceptionFromCallback(sCallbackEnv, __FUNCTION__);
}


static const btgatt_client_callbacks_t sGattClientCallbacks = {
    btgattc_register_app_cb,
    btgattc_scan_result_cb,
+1 −0
Original line number Diff line number Diff line
@@ -537,6 +537,7 @@ class AdapterProperties {
                        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
+21 −0
Original line number Diff line number Diff line
@@ -959,6 +959,11 @@ 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()) {
@@ -1522,6 +1527,11 @@ public class AdapterService extends Service {
          return mAdapterProperties.getOffloadedScanResultStorage();
      }

    public int getEnergyInfo() {
        enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
        return readEnergyInfo();
    }

    private static int convertScanModeToHal(int mode) {
        switch (mode) {
            case BluetoothAdapter.SCAN_MODE_NONE:
@@ -1611,6 +1621,16 @@ public class AdapterService extends Service {
        return true;
    }

    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 +
        "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);
    }
@@ -1658,6 +1678,7 @@ public class AdapterService extends Service {
    /*package*/ native boolean getRemoteServicesNative(byte[] address);
    /*package*/ native boolean getRemoteMasInstancesNative(byte[] address);

    private native int readEnergyInfo();
    // TODO(BT) move this to ../btsock dir
    private native int connectSocketNative(byte[] address, int type,
                                           byte[] uuid, int port, int flag);