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

Commit 8c31b235 authored by Satya Calloji's avatar Satya Calloji Committed by Prerepa Viswanadham
Browse files

LE low power scan feature

LE low power extended scan feature JNI changes
based on Google spec v0.95

Bug: 20029342
Change-Id: I5efd7ee3c644a51371bf250fca535e06c466640e
parent 35ab5372
Loading
Loading
Loading
Loading
+15 −5
Original line number Original line Diff line number Diff line
@@ -174,7 +174,7 @@ static jmethodID method_onBatchScanThresholdCrossed;


static jmethodID method_CreateonTrackAdvFoundLostObject;
static jmethodID method_CreateonTrackAdvFoundLostObject;
static jmethodID method_onTrackAdvFoundLost;
static jmethodID method_onTrackAdvFoundLost;

static jmethodID method_onScanParamSetupCompleted;


/**
/**
 * Server callback methods
 * Server callback methods
@@ -591,6 +591,13 @@ void btgattc_track_adv_event_cb(btgatt_track_adv_info_t *p_adv_track_info)
    checkAndClearExceptionFromCallback(sCallbackEnv, __FUNCTION__);
    checkAndClearExceptionFromCallback(sCallbackEnv, __FUNCTION__);
}
}


void btgattc_scan_parameter_setup_completed_cb(int client_if, btgattc_error_t status)
{
    CHECK_CALLBACK_ENV
    sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onScanParamSetupCompleted, status, client_if);
    checkAndClearExceptionFromCallback(sCallbackEnv, __func__);
}

static const btgatt_client_callbacks_t sGattClientCallbacks = {
static const btgatt_client_callbacks_t sGattClientCallbacks = {
    btgattc_register_app_cb,
    btgattc_register_app_cb,
    btgattc_scan_result_cb,
    btgattc_scan_result_cb,
@@ -623,7 +630,8 @@ static const btgatt_client_callbacks_t sGattClientCallbacks = {
    btgattc_batchscan_startstop_cb,
    btgattc_batchscan_startstop_cb,
    btgattc_batchscan_reports_cb,
    btgattc_batchscan_reports_cb,
    btgattc_batchscan_threshold_cb,
    btgattc_batchscan_threshold_cb,
    btgattc_track_adv_event_cb
    btgattc_track_adv_event_cb,
    btgattc_scan_parameter_setup_completed_cb
};
};




@@ -879,6 +887,7 @@ static void classInitNative(JNIEnv* env, jclass clazz) {
    method_CreateonTrackAdvFoundLostObject = env->GetMethodID(clazz, "CreateonTrackAdvFoundLostObject", "(II[BI[BIIILjava/lang/String;IIII)Lcom/android/bluetooth/gatt/AdvtFilterOnFoundOnLostInfo;");
    method_CreateonTrackAdvFoundLostObject = env->GetMethodID(clazz, "CreateonTrackAdvFoundLostObject", "(II[BI[BIIILjava/lang/String;IIII)Lcom/android/bluetooth/gatt/AdvtFilterOnFoundOnLostInfo;");
    method_onTrackAdvFoundLost = env->GetMethodID(clazz, "onTrackAdvFoundLost",
    method_onTrackAdvFoundLost = env->GetMethodID(clazz, "onTrackAdvFoundLost",
                                                         "(Lcom/android/bluetooth/gatt/AdvtFilterOnFoundOnLostInfo;)V");
                                                         "(Lcom/android/bluetooth/gatt/AdvtFilterOnFoundOnLostInfo;)V");
    method_onScanParamSetupCompleted = env->GetMethodID(clazz, "onScanParamSetupCompleted", "(II)V");


    // Server callbacks
    // Server callbacks


@@ -1308,10 +1317,11 @@ static void gattSetAdvDataNative(JNIEnv *env, jobject object, jint client_if,
}
}


static void gattSetScanParametersNative(JNIEnv* env, jobject object,
static void gattSetScanParametersNative(JNIEnv* env, jobject object,
                                        jint scan_interval_unit, jint scan_window_unit)
                                        jint client_if, jint scan_interval_unit,
                                        jint scan_window_unit)
{
{
    if (!sGattIf) return;
    if (!sGattIf) return;
    sGattIf->client->set_scan_parameters(scan_interval_unit, scan_window_unit);
    sGattIf->client->set_scan_parameters(client_if, scan_interval_unit, scan_window_unit);
}
}


static void gattClientScanFilterParamAddNative(JNIEnv* env, jobject object, jobject params)
static void gattClientScanFilterParamAddNative(JNIEnv* env, jobject object, jobject params)
@@ -1818,7 +1828,7 @@ static JNINativeMethod sScanMethods[] = {
    {"gattClientScanFilterDeleteNative", "(IIIIIJJJJLjava/lang/String;Ljava/lang/String;B[B[B)V", (void *) gattClientScanFilterDeleteNative},
    {"gattClientScanFilterDeleteNative", "(IIIIIJJJJLjava/lang/String;Ljava/lang/String;B[B[B)V", (void *) gattClientScanFilterDeleteNative},
    {"gattClientScanFilterClearNative", "(II)V", (void *) gattClientScanFilterClearNative},
    {"gattClientScanFilterClearNative", "(II)V", (void *) gattClientScanFilterClearNative},
    {"gattClientScanFilterEnableNative", "(IZ)V", (void *) gattClientScanFilterEnableNative},
    {"gattClientScanFilterEnableNative", "(IZ)V", (void *) gattClientScanFilterEnableNative},
    {"gattSetScanParametersNative", "(II)V", (void *) gattSetScanParametersNative},
    {"gattSetScanParametersNative", "(III)V", (void *) gattSetScanParametersNative},
};
};


// JNI functions defined in GattService class.
// JNI functions defined in GattService class.
+12 −1
Original line number Original line Diff line number Diff line
@@ -66,6 +66,8 @@ class AdapterProperties {
    private int mOffloadedScanResultStorageBytes;
    private int mOffloadedScanResultStorageBytes;
    private int mVersSupported;
    private int mVersSupported;
    private int mTotNumOfTrackableAdv;
    private int mTotNumOfTrackableAdv;
    private boolean mIsExtendedScanSupported;
    private boolean mIsDebugLogSupported;
    private boolean mIsActivityAndEnergyReporting;
    private boolean mIsActivityAndEnergyReporting;


    // Lock for all getters and setters.
    // Lock for all getters and setters.
@@ -572,6 +574,10 @@ class AdapterProperties {
        mTotNumOfTrackableAdv = ((0xFF & ((int)val[11])) << 8)
        mTotNumOfTrackableAdv = ((0xFF & ((int)val[11])) << 8)
                            + (0xFF & ((int)val[10]));
                            + (0xFF & ((int)val[10]));


        // TBD - Logic to be modified by Google as needed here
        mIsExtendedScanSupported = ((0xFF & ((int)val[12])) != 0);
        mIsDebugLogSupported = ((0xFF & ((int)val[13])) != 0);

        Log.d(TAG, "BT_PROPERTY_LOCAL_LE_FEATURES: update from BT controller"
        Log.d(TAG, "BT_PROPERTY_LOCAL_LE_FEATURES: update from BT controller"
                + " mNumOfAdvertisementInstancesSupported = "
                + " mNumOfAdvertisementInstancesSupported = "
                + mNumOfAdvertisementInstancesSupported
                + mNumOfAdvertisementInstancesSupported
@@ -587,7 +593,12 @@ class AdapterProperties {
                +" mVersSupported = "
                +" mVersSupported = "
                + mVersSupported
                + mVersSupported
                + " mTotNumOfTrackableAdv = "
                + " mTotNumOfTrackableAdv = "
                + mTotNumOfTrackableAdv);
                + mTotNumOfTrackableAdv
                + " mIsExtendedScanSupported = "
                + mIsExtendedScanSupported
                + " mIsDebugLogSupported = "
                + mIsDebugLogSupported
                );
    }
    }


    void onBluetoothReady() {
    void onBluetoothReady() {
+10 −0
Original line number Original line Diff line number Diff line
@@ -1190,6 +1190,16 @@ public class GattService extends ProfileService {
        }
        }
    }
    }


    void onScanParamSetupCompleted(int status, int clientIf) throws RemoteException {
        ClientMap.App app = mClientMap.getById(clientIf);
        if (app == null || app.callback == null) {
            Log.e(TAG, "Advertise app or callback is null");
            return;
        }
        // TBD - Logic to be modified by Google as needed here
        Log.d(TAG, "onScanParamSetupCompleted : " + status);
    }

    // callback from AdvertiseManager for advertise status dispatch.
    // callback from AdvertiseManager for advertise status dispatch.
    void onMultipleAdvertiseCallback(int clientIf, int status, boolean isStart,
    void onMultipleAdvertiseCallback(int clientIf, int status, boolean isStart,
            AdvertiseSettings settings) throws RemoteException {
            AdvertiseSettings settings) throws RemoteException {
+7 −2
Original line number Original line Diff line number Diff line
@@ -414,13 +414,16 @@ public class ScanManager {
            if (curScanSetting != Integer.MIN_VALUE &&
            if (curScanSetting != Integer.MIN_VALUE &&
                    curScanSetting != ScanSettings.SCAN_MODE_OPPORTUNISTIC) {
                    curScanSetting != ScanSettings.SCAN_MODE_OPPORTUNISTIC) {
                if (curScanSetting != mLastConfiguredScanSetting) {
                if (curScanSetting != mLastConfiguredScanSetting) {
                    // TBD - Logic to be modified by Google as needed here
                    int scanWindow = getScanWindowMillis(client.settings);
                    int scanWindow = getScanWindowMillis(client.settings);
                    int scanInterval = getScanIntervalMillis(client.settings);
                    int scanInterval = getScanIntervalMillis(client.settings);
                    // convert scanWindow and scanInterval from ms to LE scan units(0.625ms)
                    // convert scanWindow and scanInterval from ms to LE scan units(0.625ms)
                    scanWindow = Utils.millsToUnit(scanWindow);
                    scanWindow = Utils.millsToUnit(scanWindow);
                    scanInterval = Utils.millsToUnit(scanInterval);
                    scanInterval = Utils.millsToUnit(scanInterval);
                    gattClientScanNative(false);
                    gattClientScanNative(false);
                    gattSetScanParametersNative(scanInterval, scanWindow);
                    logd("configureRegularScanParams - scanInterval = " + scanInterval +
                        "configureRegularScanParams - scanWindow = " + scanWindow);
                    gattSetScanParametersNative(client.clientIf, scanInterval, scanWindow);
                    gattClientScanNative(true);
                    gattClientScanNative(true);
                    mLastConfiguredScanSetting = curScanSetting;
                    mLastConfiguredScanSetting = curScanSetting;
                }
                }
@@ -902,6 +905,7 @@ public class ScanManager {
            if (settings == null) {
            if (settings == null) {
                return SCAN_MODE_LOW_POWER_WINDOW_MS;
                return SCAN_MODE_LOW_POWER_WINDOW_MS;
            }
            }
            // TBD - Logic to be modified by Google as needed here
            switch (settings.getScanMode()) {
            switch (settings.getScanMode()) {
                case ScanSettings.SCAN_MODE_LOW_LATENCY:
                case ScanSettings.SCAN_MODE_LOW_LATENCY:
                    return SCAN_MODE_LOW_LATENCY_WINDOW_MS;
                    return SCAN_MODE_LOW_LATENCY_WINDOW_MS;
@@ -917,6 +921,7 @@ public class ScanManager {
        private int getScanIntervalMillis(ScanSettings settings) {
        private int getScanIntervalMillis(ScanSettings settings) {
            if (settings == null)
            if (settings == null)
                return SCAN_MODE_LOW_POWER_INTERVAL_MS;
                return SCAN_MODE_LOW_POWER_INTERVAL_MS;
            // TBD - Logic to be modified by Google as needed here
            switch (settings.getScanMode()) {
            switch (settings.getScanMode()) {
                case ScanSettings.SCAN_MODE_LOW_LATENCY:
                case ScanSettings.SCAN_MODE_LOW_LATENCY:
                    return SCAN_MODE_LOW_LATENCY_INTERVAL_MS;
                    return SCAN_MODE_LOW_LATENCY_INTERVAL_MS;
@@ -1015,7 +1020,7 @@ public class ScanManager {
        /************************** Regular scan related native methods **************************/
        /************************** Regular scan related native methods **************************/
        private native void gattClientScanNative(boolean start);
        private native void gattClientScanNative(boolean start);


        private native void gattSetScanParametersNative(int scan_interval,
        private native void gattSetScanParametersNative(int client_if, int scan_interval,
                int scan_window);
                int scan_window);


        /************************** Filter related native methods ********************************/
        /************************** Filter related native methods ********************************/