BT connection notification in not updated in status bar for second user
It is due to the system UI is always running as the first user. It can't receive
broadcast intent ACTION_CONNECTION_STATE_CHANGED and ACTION_BOND_STATE_CHANGED
from bluetooth service when We switch to second user. Also the system UI also
is running as uid 10055, which will also call function isEnabled, getState,
getBondedDevices, getAdapterConnectionState and getBondState in bluetooth service.
I allow these functions to be called by all the users.
I forget remove check for getBondState in my first patch set

bug 7333382

Change-Id: I57f39a722e78d6d2453ebfecaab043637fef4d9c
diff --git a/src/com/android/bluetooth/btservice/AdapterProperties.java b/src/com/android/bluetooth/btservice/AdapterProperties.java
index 9b7b2a6..837c446 100755
--- a/src/com/android/bluetooth/btservice/AdapterProperties.java
+++ b/src/com/android/bluetooth/btservice/AdapterProperties.java
@@ -10,6 +10,7 @@
 import android.content.Context;
 import android.content.Intent;
 import android.os.ParcelUuid;
+import android.os.UserHandle;
 import android.util.Log;
 import android.util.Pair;
 
@@ -299,7 +300,8 @@
                 intent.putExtra(BluetoothAdapter.EXTRA_PREVIOUS_CONNECTION_STATE,
                         convertToAdapterState(prevState));
                 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
-                mService.sendBroadcast(intent, mService.BLUETOOTH_PERM);
+                mService.sendBroadcastAsUser(intent, UserHandle.ALL,
+                        mService.BLUETOOTH_PERM);
                 Log.d(TAG, "CONNECTION_STATE_CHANGE: " + device + ": "
                         + prevState + " -> " + state);
             }
diff --git a/src/com/android/bluetooth/btservice/AdapterService.java b/src/com/android/bluetooth/btservice/AdapterService.java
index e32c8c5..988f0ec 100755
--- a/src/com/android/bluetooth/btservice/AdapterService.java
+++ b/src/com/android/bluetooth/btservice/AdapterService.java
@@ -483,24 +483,14 @@
             return null;
         }
         public boolean isEnabled() {
-            if ((Binder.getCallingUid() != Process.SYSTEM_UID) &&
-                (!Utils.checkCaller())) {
-                Log.w(TAG,"isEnabled(): not allowed for non-active user and non system user");
-                return false;
-	    }
-
+            // don't check caller, may be called from system UI
             AdapterService service = getService();
             if (service == null) return false;
             return service.isEnabled();
         }
 
         public int getState() {
-            if ((Binder.getCallingUid() != Process.SYSTEM_UID) &&
-                (!Utils.checkCaller())) {
-                Log.w(TAG,"getState(): not allowed for non-active user and non system user");
-                return BluetoothAdapter.STATE_OFF;
-            }
-
+            // don't check caller, may be called from system UI
             AdapterService service = getService();
             if (service == null) return  BluetoothAdapter.STATE_OFF;
             return service.getState();
@@ -665,22 +655,14 @@
         }
 
         public BluetoothDevice[] getBondedDevices() {
-            if (!Utils.checkCaller()) {
-                Log.w(TAG,"getBondedDevices: not allowed for non-active user");
-                return new BluetoothDevice[0];
-            }
-
+            // don't check caller, may be called from system UI
             AdapterService service = getService();
             if (service == null) return new BluetoothDevice[0];
             return service.getBondedDevices();
         }
 
         public int getAdapterConnectionState() {
-            if (!Utils.checkCaller()) {
-                Log.w(TAG,"getAdapterConnectionState: not allowed for non-active user");
-                return BluetoothAdapter.STATE_DISCONNECTED;
-            }
-
+            // don't check caller, may be called from system UI
             AdapterService service = getService();
             if (service == null) return BluetoothAdapter.STATE_DISCONNECTED;
             return service.getAdapterConnectionState();
@@ -731,11 +713,7 @@
         }
 
         public int getBondState(BluetoothDevice device) {
-            if (!Utils.checkCaller()) {
-                Log.w(TAG,"getBondState(): not allowed for non-active user");
-                return BluetoothDevice.BOND_NONE;
-            }
-
+            // don't check caller, may be called from system UI
             AdapterService service = getService();
             if (service == null) return BluetoothDevice.BOND_NONE;
             return service.getBondState(device);
diff --git a/src/com/android/bluetooth/btservice/BondStateMachine.java b/src/com/android/bluetooth/btservice/BondStateMachine.java
index d192ddc..ffdfab1 100755
--- a/src/com/android/bluetooth/btservice/BondStateMachine.java
+++ b/src/com/android/bluetooth/btservice/BondStateMachine.java
@@ -13,6 +13,7 @@
 import android.content.Context;
 import android.content.Intent;
 import android.os.Message;
+import android.os.UserHandle;
 import android.util.Log;
 
 import com.android.bluetooth.Utils;
@@ -252,7 +253,8 @@
         intent.putExtra(BluetoothDevice.EXTRA_PREVIOUS_BOND_STATE, oldState);
         if (newState == BluetoothDevice.BOND_NONE)
             intent.putExtra(BluetoothDevice.EXTRA_REASON, reason);
-        mAdapterService.sendBroadcast(intent, AdapterService.BLUETOOTH_PERM);
+        mAdapterService.sendBroadcastAsUser(intent, UserHandle.ALL,
+                AdapterService.BLUETOOTH_PERM);
         infoLog("Bond State Change Intent:" + device + " OldState: " + oldState
                 + " NewState: " + newState);
     }