2626import org .xmlpull .v1 .XmlSerializer ;
2727
2828import android .Manifest ;
29+ import android .bluetooth .BluetoothAdapter ;
30+ import android .bluetooth .BluetoothDevice ;
2931import android .content .BroadcastReceiver ;
3032import android .content .ComponentName ;
3133import android .content .Context ;
5658import android .os .RemoteException ;
5759import android .provider .Settings ;
5860import android .provider .Settings .SettingNotFoundException ;
61+ import android .server .BluetoothService ;
5962import android .util .Log ;
6063import android .util .Slog ;
6164import android .util .SparseArray ;
@@ -106,6 +109,7 @@ public class InputManagerService extends IInputManager.Stub implements Watchdog.
106109 private final Callbacks mCallbacks ;
107110 private final InputManagerHandler mHandler ;
108111 private boolean mSystemReady ;
112+ private BluetoothService mBluetoothService ;
109113
110114 // Persistent data store. Must be locked each time during use.
111115 private final PersistentDataStore mDataStore = new PersistentDataStore ();
@@ -167,6 +171,7 @@ private static native void nativeVibrate(int ptr, int deviceId, long[] pattern,
167171 int repeat , int token );
168172 private static native void nativeCancelVibrate (int ptr , int deviceId , int token );
169173 private static native void nativeReloadKeyboardLayouts (int ptr );
174+ private static native void nativeReloadDeviceAliases (int ptr );
170175 private static native String nativeDump (int ptr );
171176 private static native void nativeMonitor (int ptr );
172177
@@ -217,12 +222,12 @@ public void start() {
217222 updateShowTouchesFromSettings ();
218223 }
219224
220- public void systemReady () {
225+ public void systemReady (BluetoothService bluetoothService ) {
221226 if (DEBUG ) {
222227 Slog .d (TAG , "System ready." );
223228 }
229+ mBluetoothService = bluetoothService ;
224230 mSystemReady = true ;
225- reloadKeyboardLayouts ();
226231
227232 IntentFilter filter = new IntentFilter (Intent .ACTION_PACKAGE_ADDED );
228233 filter .addAction (Intent .ACTION_PACKAGE_REMOVED );
@@ -237,12 +242,30 @@ public void onReceive(Context context, Intent intent) {
237242 reloadKeyboardLayouts ();
238243 }
239244 }, filter , null , mHandler );
245+
246+ filter = new IntentFilter (BluetoothDevice .ACTION_ALIAS_CHANGED );
247+ mContext .registerReceiver (new BroadcastReceiver () {
248+ @ Override
249+ public void onReceive (Context context , Intent intent ) {
250+ if (DEBUG ) {
251+ Slog .d (TAG , "Bluetooth alias changed, reloading device names." );
252+ }
253+ reloadDeviceAliases ();
254+ }
255+ }, filter , null , mHandler );
256+
257+ reloadKeyboardLayouts ();
258+ reloadDeviceAliases ();
240259 }
241260
242261 private void reloadKeyboardLayouts () {
243262 nativeReloadKeyboardLayouts (mPtr );
244263 }
245264
265+ private void reloadDeviceAliases () {
266+ nativeReloadDeviceAliases (mPtr );
267+ }
268+
246269 public void setDisplaySize (int displayId , int width , int height ,
247270 int externalWidth , int externalHeight ) {
248271 if (width <= 0 || height <= 0 || externalWidth <= 0 || externalHeight <= 0 ) {
@@ -1121,6 +1144,15 @@ public void visitKeyboardLayout(Resources resources,
11211144 return result ;
11221145 }
11231146
1147+ // Native callback.
1148+ private String getDeviceAlias (String uniqueId ) {
1149+ if (mBluetoothService != null &&
1150+ BluetoothAdapter .checkBluetoothAddress (uniqueId )) {
1151+ return mBluetoothService .getRemoteAlias (uniqueId );
1152+ }
1153+ return null ;
1154+ }
1155+
11241156
11251157 /**
11261158 * Callback interface implemented by the Window Manager.
0 commit comments