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

Commit bd01f52b authored by Joner Lin's avatar Joner Lin Committed by Gerrit Code Review
Browse files

Merge changes from topic "Handle Shutdown Intent"

* changes:
  Do not allow Bluetooth enabling during device shutting down
  Handle SHUTDOWN Intent in BluetoothManagerService
parents d2bedfe2 5b5bd513
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
@@ -217,6 +217,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
    // used inside handler thread
    private boolean mQuietEnable = false;
    private boolean mEnable;
    private boolean mShutdownInProgress = false;

    private static CharSequence timeToLog(long timestamp) {
        return android.text.format.DateFormat.format("MM-dd HH:mm:ss", timestamp);
@@ -477,6 +478,23 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
                    Slog.i(TAG, "Device disconnected, reactivating pending flag changes");
                    onInitFlagsChanged();
                }
            } else if (action.equals(Intent.ACTION_SHUTDOWN)) {
                Slog.i(TAG, "Device is shutting down.");
                mShutdownInProgress = true;
                mBluetoothLock.readLock().lock();
                try {
                    mEnable = false;
                    mEnableExternal = false;
                    if (mBluetooth != null && (mState == BluetoothAdapter.STATE_BLE_ON)) {
                        synchronousOnBrEdrDown(mContext.getAttributionSource());
                    } else if (mBluetooth != null && (mState == BluetoothAdapter.STATE_ON)) {
                        synchronousDisable(mContext.getAttributionSource());
                    }
                } catch (RemoteException | TimeoutException e) {
                    Slog.e(TAG, "Unable to shutdown Bluetooth", e);
                } finally {
                    mBluetoothLock.readLock().unlock();
                }
            }
        }
    };
@@ -536,6 +554,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
        filter.addAction(Intent.ACTION_SETTING_RESTORED);
        filter.addAction(BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED);
        filter.addAction(BluetoothHearingAid.ACTION_CONNECTION_STATE_CHANGED);
        filter.addAction(Intent.ACTION_SHUTDOWN);
        filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
        mContext.registerReceiver(mReceiver, filter);

@@ -1944,6 +1963,11 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
                case MESSAGE_ENABLE:
                    int quietEnable = msg.arg1;
                    int isBle  = msg.arg2;
                    if (mShutdownInProgress) {
                        Slog.i(TAG, "Skip Bluetooth Enable in device shutdown process");
                        break;
                    }

                    if (mHandler.hasMessages(MESSAGE_HANDLE_DISABLE_DELAYED)
                            || mHandler.hasMessages(MESSAGE_HANDLE_ENABLE_DELAYED)) {
                        // We are handling enable or disable right now, wait for it.