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

Commit cbdb8eac authored by Prerepa Viswanadham's avatar Prerepa Viswanadham
Browse files

Merge remote-tracking branch 'goog/mirror-m-wireless-internal-release' into master_merge

parents 5a52c124 0d2a9efe
Loading
Loading
Loading
Loading
+23 −2
Original line number Original line Diff line number Diff line
@@ -1819,14 +1819,19 @@ public class AdapterService extends Service {
    private void energyInfoCallback (int status, int ctrl_state,
    private void energyInfoCallback (int status, int ctrl_state,
        long tx_time, long rx_time, long idle_time, long energy_used)
        long tx_time, long rx_time, long idle_time, long energy_used)
        throws RemoteException {
        throws RemoteException {
        // ToDo: Update only status is valid
        if (ctrl_state >= BluetoothActivityEnergyInfo.BT_STACK_STATE_INVALID &&
        if (ctrl_state >= BluetoothActivityEnergyInfo.BT_STACK_STATE_INVALID &&
                ctrl_state <= BluetoothActivityEnergyInfo.BT_STACK_STATE_STATE_IDLE) {
                ctrl_state <= BluetoothActivityEnergyInfo.BT_STACK_STATE_STATE_IDLE) {
            mStackReportedState = ctrl_state;
            mStackReportedState = ctrl_state;
            mTxTimeTotalMs += tx_time;
            mTxTimeTotalMs += tx_time;
            mRxTimeTotalMs += rx_time;
            mRxTimeTotalMs += rx_time;
            mIdleTimeTotalMs += idle_time;
            mIdleTimeTotalMs += idle_time;
            // Energy is product of mA, V and ms
            // Energy is product of mA, V and ms. If the chipset doesn't
            // report it, we have to compute it from time
            if (energy_used == 0) {
                energy_used = ((mTxTimeTotalMs * getTxCurrentMa()
                    + mRxTimeTotalMs * getRxCurrentMa()
                    + mIdleTimeTotalMs * getIdleCurrentMa()) * getOperatingMilliVolt())/1000;
            }
            mEnergyUsedTotalVoltAmpSecMicro += energy_used;
            mEnergyUsedTotalVoltAmpSecMicro += energy_used;
        }
        }


@@ -1838,6 +1843,22 @@ public class AdapterService extends Service {
        }
        }
    }
    }


    private int getIdleCurrentMa() {
        return getResources().getInteger(R.integer.config_bluetooth_idle_cur_ma);
    }

    private int getTxCurrentMa() {
        return getResources().getInteger(R.integer.config_bluetooth_tx_cur_ma);
    }

    private int getRxCurrentMa() {
        return getResources().getInteger(R.integer.config_bluetooth_rx_cur_ma);
    }

    private int getOperatingMilliVolt() {
        return getResources().getInteger(R.integer.config_bluetooth_operating_voltage_mv);
    }

    private void debugLog(String msg) {
    private void debugLog(String msg) {
        if (DBG) Log.d(TAG +"(" +hashCode()+")", msg);
        if (DBG) Log.d(TAG +"(" +hashCode()+")", msg);
    }
    }
+33 −10
Original line number Original line Diff line number Diff line
@@ -210,16 +210,20 @@ public class ScanManager {
            } else {
            } else {
                mRegularScanClients.add(client);
                mRegularScanClients.add(client);
                mScanNative.startRegularScan(client);
                mScanNative.startRegularScan(client);
                if (!mScanNative.isOpportunisticScanClient(client)) {
                    mScanNative.configureRegularScanParams();
                    mScanNative.configureRegularScanParams();
                }
                }
            }
            }
        }


        void handleStopScan(ScanClient client) {
        void handleStopScan(ScanClient client) {
            Utils.enforceAdminPermission(mService);
            Utils.enforceAdminPermission(mService);
            if (client == null) return;
            if (client == null) return;
            if (mRegularScanClients.contains(client)) {
            if (mRegularScanClients.contains(client)) {
                mScanNative.stopRegularScan(client);
                mScanNative.stopRegularScan(client);
                if (!mScanNative.isOpportunisticScanClient(client)) {
                    mScanNative.configureRegularScanParams();
                    mScanNative.configureRegularScanParams();
                }
            } else {
            } else {
                mScanNative.stopBatchScan(client);
                mScanNative.stopBatchScan(client);
            }
            }
@@ -390,7 +394,8 @@ public class ScanManager {
            logd("configureRegularScanParams() - ScanSetting Scan mode=" + curScanSetting +
            logd("configureRegularScanParams() - ScanSetting Scan mode=" + curScanSetting +
                    " mLastConfiguredScanSetting=" + mLastConfiguredScanSetting);
                    " mLastConfiguredScanSetting=" + mLastConfiguredScanSetting);


            if (curScanSetting != Integer.MIN_VALUE) {
            if (curScanSetting != Integer.MIN_VALUE &&
                    curScanSetting != ScanSettings.SCAN_MODE_OPPORTUNISTIC) {
                if (curScanSetting != mLastConfiguredScanSetting) {
                if (curScanSetting != mLastConfiguredScanSetting) {
                    int scanWindow, scanInterval;
                    int scanWindow, scanInterval;
                    switch (curScanSetting) {
                    switch (curScanSetting) {
@@ -441,27 +446,43 @@ public class ScanManager {
        }
        }


        void startRegularScan(ScanClient client) {
        void startRegularScan(ScanClient client) {
            if (isFilteringSupported() && mFilterIndexStack.isEmpty() &&
            if (isFilteringSupported() && mFilterIndexStack.isEmpty()
                    mClientFilterIndexMap.isEmpty()) {
                    && mClientFilterIndexMap.isEmpty()) {
                initFilterIndexStack();
                initFilterIndexStack();
            }
            }
            if (isFilteringSupported()) {
            if (isFilteringSupported()) {
                configureScanFilters(client);
                configureScanFilters(client);
            }
            }
            // Start scan native only for the first client.
            // Start scan native only for the first client.
            if (mRegularScanClients.size() == 1) {
            if (numRegularScanClients() == 1) {
                gattClientScanNative(true);
                gattClientScanNative(true);
            }
            }
        }
        }


        private int numRegularScanClients() {
            int num = 0;
            for (ScanClient client: mRegularScanClients) {
                if (client.settings.getScanMode() != ScanSettings.SCAN_MODE_OPPORTUNISTIC) {
                    num++;
                }
            }
            return num;
        }

        void startBatchScan(ScanClient client) {
        void startBatchScan(ScanClient client) {
            if (mFilterIndexStack.isEmpty() && isFilteringSupported()) {
            if (mFilterIndexStack.isEmpty() && isFilteringSupported()) {
                initFilterIndexStack();
                initFilterIndexStack();
            }
            }
            configureScanFilters(client);
            configureScanFilters(client);
            if (!isOpportunisticScanClient(client)) {
                // Reset batch scan. May need to stop the existing batch scan and update scan params.
                // Reset batch scan. May need to stop the existing batch scan and update scan params.
                resetBatchScan(client);
                resetBatchScan(client);
            }
            }
        }

        private boolean isOpportunisticScanClient(ScanClient client) {
            return client.settings.getScanMode() == ScanSettings.SCAN_MODE_OPPORTUNISTIC;
        }


        private void resetBatchScan(ScanClient client) {
        private void resetBatchScan(ScanClient client) {
            int clientIf = client.clientIf;
            int clientIf = client.clientIf;
@@ -579,7 +600,7 @@ public class ScanManager {
            // Remove scan filters and recycle filter indices.
            // Remove scan filters and recycle filter indices.
            removeScanFilters(client.clientIf);
            removeScanFilters(client.clientIf);
            mRegularScanClients.remove(client);
            mRegularScanClients.remove(client);
            if (mRegularScanClients.isEmpty()) {
            if (numRegularScanClients() == 0) {
                logd("stop scan");
                logd("stop scan");
                gattClientScanNative(false);
                gattClientScanNative(false);
            }
            }
@@ -588,8 +609,10 @@ public class ScanManager {
        void stopBatchScan(ScanClient client) {
        void stopBatchScan(ScanClient client) {
            mBatchClients.remove(client);
            mBatchClients.remove(client);
            removeScanFilters(client.clientIf);
            removeScanFilters(client.clientIf);
            if (!isOpportunisticScanClient(client)) {
                resetBatchScan(client);
                resetBatchScan(client);
            }
            }
        }


        void flushBatchResults(int clientIf) {
        void flushBatchResults(int clientIf) {
            logd("flushPendingBatchResults - clientIf = " + clientIf);
            logd("flushPendingBatchResults - clientIf = " + clientIf);