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

Commit 5b780945 authored by HsingYuan Lo's avatar HsingYuan Lo Committed by Gerrit Code Review
Browse files

Merge "Expose service changed event to application (3/3)"

parents 121de636 8ebdf692
Loading
Loading
Loading
Loading
+13 −1
Original line number Diff line number Diff line
@@ -142,6 +142,7 @@ static jmethodID method_onGetGattDb;
static jmethodID method_onClientPhyUpdate;
static jmethodID method_onClientPhyRead;
static jmethodID method_onClientConnUpdate;
static jmethodID method_onServiceChanged;

/**
 * Server callback methods
@@ -528,6 +529,13 @@ void btgattc_conn_updated_cb(int conn_id, uint16_t interval, uint16_t latency,
                               conn_id, interval, latency, timeout, status);
}

void btgattc_service_changed_cb(int conn_id) {
  CallbackEnv sCallbackEnv(__func__);
  if (!sCallbackEnv.valid()) return;

  sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onServiceChanged, conn_id);
}

static const btgatt_scanner_callbacks_t sGattScannerCallbacks = {
    btgattc_scan_result_cb,
    btgattc_batchscan_reports_cb,
@@ -554,7 +562,9 @@ static const btgatt_client_callbacks_t sGattClientCallbacks = {
    NULL, /* services_removed_cb */
    NULL, /* services_added_cb */
    btgattc_phy_updated_cb,
    btgattc_conn_updated_cb};
    btgattc_conn_updated_cb,
    btgattc_service_changed_cb,
};

/**
 * BTA server callbacks
@@ -835,6 +845,8 @@ static void classInitNative(JNIEnv* env, jclass clazz) {
      env->GetMethodID(clazz, "onClientPhyUpdate", "(IIII)V");
  method_onClientConnUpdate =
      env->GetMethodID(clazz, "onClientConnUpdate", "(IIIII)V");
  method_onServiceChanged =
      env->GetMethodID(clazz, "onServiceChanged", "(I)V");

  // Server callbacks

+18 −0
Original line number Diff line number Diff line
@@ -1304,6 +1304,24 @@ public class GattService extends ProfileService {
        app.callback.onConnectionUpdated(address, interval, latency, timeout, status);
    }

    void onServiceChanged(int connId) throws RemoteException {
        if (DBG) {
            Log.d(TAG, "onServiceChanged - connId=" + connId);
        }

        String address = mClientMap.addressByConnId(connId);
        if (address == null) {
            return;
        }

        ClientMap.App app = mClientMap.getByConnId(connId);
        if (app == null) {
            return;
        }

        app.callback.onServiceChanged(address);
    }

    void onServerPhyUpdate(int connId, int txPhy, int rxPhy, int status) throws RemoteException {
        if (DBG) {
            Log.d(TAG, "onServerPhyUpdate() - connId=" + connId + ", status=" + status);