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

Commit 2efdc281 authored by Adam Lesinski's avatar Adam Lesinski
Browse files

BluetoothManager: Make requestControllerActivityInfo one call

Instead of making multiple calls into the Bluetooth service,
make one call that can timeout. This helps prevent cases
when the Bluetooth process hangs and the system_server is calling into
it and causes a WATCHDOG restart.

Bug:28658141

Change-Id: I84d2c025f4ffb452975444e794a64c82569deb0a
parent 237b60d7
Loading
Loading
Loading
Loading
+17 −12
Original line number Original line Diff line number Diff line
@@ -139,6 +139,8 @@ public class AdapterService extends Service {
      "DUAL"
      "DUAL"
    };
    };


    private static final int CONTROLLER_ENERGY_UPDATE_TIMEOUT_MILLIS = 30;

    static {
    static {
        classInitNative();
        classInitNative();
    }
    }
@@ -1410,12 +1412,6 @@ public class AdapterService extends Service {
             return service.isActivityAndEnergyReportingSupported();
             return service.isActivityAndEnergyReportingSupported();
         }
         }


         public void getActivityEnergyInfoFromController() {
             AdapterService service = getService();
             if (service == null) return;
             service.getActivityEnergyInfoFromController();
         }

         public BluetoothActivityEnergyInfo reportActivityInfo() {
         public BluetoothActivityEnergyInfo reportActivityInfo() {
             AdapterService service = getService();
             AdapterService service = getService();
             if (service == null) return null;
             if (service == null) return null;
@@ -2160,16 +2156,24 @@ public class AdapterService extends Service {
          return mAdapterProperties.isActivityAndEnergyReportingSupported();
          return mAdapterProperties.isActivityAndEnergyReportingSupported();
    }
    }


    private void getActivityEnergyInfoFromController() {
    private BluetoothActivityEnergyInfo reportActivityInfo() {
        enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED, "Need BLUETOOTH permission");
        enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED, "Need BLUETOOTH permission");
        if (isActivityAndEnergyReportingSupported()) {
        if (mAdapterProperties.getState() != BluetoothAdapter.STATE_ON ||
            readEnergyInfo();
                !mAdapterProperties.isActivityAndEnergyReportingSupported()) {
        }
            return null;
        }
        }


    private BluetoothActivityEnergyInfo reportActivityInfo() {
        // Pull the data. The callback will notify mEnergyInfoLock.
        enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED, "Need BLUETOOTH permission");
        readEnergyInfo();

        synchronized (mEnergyInfoLock) {
        synchronized (mEnergyInfoLock) {
            try {
                mEnergyInfoLock.wait(CONTROLLER_ENERGY_UPDATE_TIMEOUT_MILLIS);
            } catch (InterruptedException e) {
                // Just continue, the energy data may be stale but we won't miss anything next time
                // we query.
            }

            final BluetoothActivityEnergyInfo info = new BluetoothActivityEnergyInfo(
            final BluetoothActivityEnergyInfo info = new BluetoothActivityEnergyInfo(
                    SystemClock.elapsedRealtime(),
                    SystemClock.elapsedRealtime(),
                    mStackReportedState,
                    mStackReportedState,
@@ -2336,6 +2340,7 @@ public class AdapterService extends Service {
                        existingTraffic.addTxBytes(traffic.getTxBytes());
                        existingTraffic.addTxBytes(traffic.getTxBytes());
                    }
                    }
                }
                }
                mEnergyInfoLock.notifyAll();
            }
            }
        }
        }