Buggy code:
private IBluetooth mBluetooth ; private IQBluetooth mQBluetooth ; private IBluetoothGatt mBluetoothGatt ; private boolean mBinding ; private boolean mUnbinding ; private boolean mQuietEnable = false ; private boolean mQuietEnableExternal ; private boolean mEnableExternal ; private boolean mEnable ; private int mState ; private final BluetoothManagerService . BluetoothHandler mHandler ; private int mErrorRecoveryRetryCounter ; private final int mSystemUiUid ; private boolean mIsBluetoothServiceConnected = false ; private final Map < Integer , BluetoothManagerService . ProfileServiceConnections > mProfileServices = new HashMap < Integer , BluetoothManagerService . ProfileServiceConnections > ( ) ; private void registerForAirplaneMode ( IntentFilter filter ) { } private final IBluetoothCallback mBluetoothCallback = new IBluetoothCallback . Stub ( ) { @ Override public void onBluetoothStateChange ( int prevState , int newState ) throws RemoteException { } } ; private final BroadcastReceiver mReceiver = new BroadcastReceiver ( ) { @ Override public void onReceive ( Context context , Intent intent ) { } } ; BluetoothManagerService ( Context context ) { } private final boolean isAirplaneModeOn ( ) { } private final boolean isBluetoothPersistedStateOn ( ) { } private final boolean isBluetoothPersistedStateOnBluetooth ( ) { } private void persistBluetoothSetting ( int value ) { } private boolean isNameAndAddressSet ( ) { } private void loadStoredNameAndAddress ( ) { } private void storeNameAndAddress ( String name , String address ) { } public IBluetooth registerAdapter ( IBluetoothManagerCallback callback ) { } public void unregisterAdapter ( IBluetoothManagerCallback callback ) { } public IQBluetooth registerQAdapter ( IQBluetoothManagerCallback callback ) { } public void unregisterQAdapter ( IQBluetoothManagerCallback callback ) { } public void registerStateChangeCallback ( IBluetoothStateChangeCallback callback ) { } public void unregisterStateChangeCallback ( IBluetoothStateChangeCallback callback ) { } public boolean isEnabled ( ) { } public void getNameAndAddress ( ) { } public boolean enableNoAutoConnect ( ) { } public boolean enable ( String callingPackage ) { } public boolean disable ( boolean persist ) { } public void unbindAndFinish ( ) { } public IBluetoothGatt getBluetoothGatt ( ) { } @ Override public boolean bindBluetoothProfileService ( int bluetoothProfile , IBluetoothProfileServiceConnection proxy ) { } @ Override public void unbindBluetoothProfileService ( int bluetoothProfile , IBluetoothProfileServiceConnection proxy ) { } private void unbindAllBluetoothProfileServices ( ) { } private final class ProfileServiceConnections implements ServiceConnection , IBinder . DeathRecipient { final RemoteCallbackList < IBluetoothProfileServiceConnection > mProxies = new RemoteCallbackList < IBluetoothProfileServiceConnection > ( ) ; IBinder mService ; ComponentName mClassName ; Intent mIntent ; ProfileServiceConnections ( Intent intent ) { } private boolean bindService ( ) { } private void addProxy ( IBluetoothProfileServiceConnection proxy ) { } private void removeProxy ( IBluetoothProfileServiceConnection proxy ) { } private void removeAllProxies ( ) { } @ Override public void onServiceConnected ( ComponentName className , IBinder service ) { } @ Override public void onServiceDisconnected ( ComponentName className ) { } @ Override public void binderDied ( ) { } } public IQBluetooth getQBluetooth ( ) { } private void sendBluetoothStateCallback ( boolean isUp ) { } private void sendBluetoothServiceUpCallback ( ) { } private void sendBluetoothServiceDownCallback ( ) { } private void sendQBluetoothServiceUpCallback ( ) { } private void sendQBluetoothServiceDownCallback ( ) { } public String getAddress ( ) { } public String getName ( ) { } private class BluetoothServiceConnection implements ServiceConnection { private boolean mGetNameAddressOnly ; public void setGetNameAddressOnly ( boolean getOnly ) { } public boolean isGetNameAddressOnly ( ) { } public void onServiceConnected ( ComponentName className , IBinder service ) { } public void onServiceDisconnected ( ComponentName className ) { } } private BluetoothManagerService . BluetoothServiceConnection mConnection = new BluetoothManagerService . BluetoothServiceConnection ( ) ; private class BluetoothHandler extends Handler { public BluetoothHandler ( Looper looper ) { } @ Override public void handleMessage ( Message msg ) { } } private void handleEnable ( boolean quietMode ) { } boolean doBind ( Intent intent , ServiceConnection conn , int flags , UserHandle user ) { } private void handleDisable ( ) { } private boolean checkIfCallerIsForegroundUser ( ) { } private void bluetoothStateChangeHandler ( int prevState , int newState ) { if ( prevState != newState ) { if ( ( newState == ( BluetoothAdapter . STATE_ON ) ) || ( newState == ( BluetoothAdapter . STATE_OFF ) ) ) { boolean isUp = newState == ( BluetoothAdapter . STATE_ON ) ; sendBluetoothStateCallback ( isUp ) ; if ( isUp ) { if ( mContext . getPackageManager ( ) . hasSystemFeature ( FEATURE_BLUETOOTH_LE ) ) { Intent i = new Intent ( IBluetoothGatt . class . getName ( ) ) ; doBind ( i , mConnection , ( ( Context . BIND_AUTO_CREATE ) | ( Context . BIND_IMPORTANT ) ) , CURRENT ) ; Intent iqc = new Intent ( IQBluetooth . class . getName ( ) ) ; doBind ( iqc , mConnection , ( ( Context . BIND_AUTO_CREATE ) | ( Context . BIND_IMPORTANT ) ) , CURRENT ) ; } } else { if ( ( ! isUp ) && ( canUnbindBluetoothService ( ) ) ) { unbindAllBluetoothProfileServices ( ) ; sendBluetoothServiceDownCallback ( ) ; sendQBluetoothServiceDownCallback ( ) ; unbindAndFinish ( ) ; } } } Intent intent = new Intent ( BluetoothAdapter . ACTION_STATE_CHANGED ) ; intent . putExtra ( EXTRA_PREVIOUS_STATE , prevState ) ; intent . putExtra ( EXTRA_STATE , newState ) ; intent . addFlags ( FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT ) ; intent . addFlags ( FLAG_RECEIVER_FOREGROUND ) ; if ( BluetoothManagerService . DBG ) Log . d ( BluetoothManagerService . TAG , ( ( ( "Bluetooth<seq2seq4repair_space>State<seq2seq4repair_space>Change<seq2seq4repair_space>Intent:<seq2seq4repair_space>" + prevState ) + "<seq2seq4repair_space>-><seq2seq4repair_space>" ) + newState ) ) ; <START_BUG> mContext . sendBroadcastAsUser ( intent , ALL , BluetoothManagerService . BLUETOOTH_PERM ) ; <END_BUG> } } private boolean waitForOnOff ( boolean on , boolean off ) { } private void sendDisableMsg ( ) { } private void sendEnableMsg ( boolean quietMode ) { } private boolean canUnbindBluetoothService ( ) { } private void recoverBluetoothServiceFromError ( ) { } @ Override public void dump ( FileDescriptor fd , PrintWriter writer , String [ ] args ) { } }

Fix:
mContext . sendBroadcastAsUser ( intent , CURRENT , BluetoothManagerService . BLUETOOTH_PERM ) ;