OSDN Git Service

Init MidiService once system user gets unlocked.
authorPhilip P. Moltmann <moltmann@google.com>
Mon, 9 May 2016 19:40:19 +0000 (12:40 -0700)
committerPhilip P. Moltmann <moltmann@google.com>
Mon, 9 May 2016 19:51:18 +0000 (12:51 -0700)
Bug: 28621670
Change-Id: I358aa8db6d1408c317f4ca66b4e5c5cbbcfe0826

services/midi/java/com/android/server/midi/MidiService.java

index 723be24..1c18c9b 100644 (file)
@@ -41,6 +41,7 @@ import android.os.Bundle;
 import android.os.IBinder;
 import android.os.Process;
 import android.os.RemoteException;
+import android.os.UserHandle;
 import android.util.Log;
 
 import com.android.internal.content.PackageMonitor;
@@ -71,6 +72,13 @@ public class MidiService extends IMidiManager.Stub {
             mMidiService = new MidiService(getContext());
             publishBinderService(Context.MIDI_SERVICE, mMidiService);
         }
+
+        @Override
+        public void onUnlockUser(int userHandle) {
+            if (userHandle == UserHandle.USER_SYSTEM) {
+                mMidiService.onUnlockUser();
+            }
+        }
     }
 
     private static final String TAG = "MidiService";
@@ -97,7 +105,7 @@ public class MidiService extends IMidiManager.Stub {
     private final PackageManager mPackageManager;
 
     // UID of BluetoothMidiService
-    private final int mBluetoothServiceUid;
+    private int mBluetoothServiceUid;
 
     // PackageMonitor for listening to package changes
     private final PackageMonitor mPackageMonitor = new PackageMonitor() {
@@ -557,7 +565,12 @@ public class MidiService extends IMidiManager.Stub {
     public MidiService(Context context) {
         mContext = context;
         mPackageManager = context.getPackageManager();
-        mPackageMonitor.register(context, null, true);
+
+        mBluetoothServiceUid = -1;
+    }
+
+    private void onUnlockUser() {
+        mPackageMonitor.register(mContext, null, true);
 
         Intent intent = new Intent(MidiDeviceService.SERVICE_INTERFACE);
         List<ResolveInfo> resolveInfos = mPackageManager.queryIntentServices(intent,
@@ -583,7 +596,7 @@ public class MidiService extends IMidiManager.Stub {
         } else {
             mBluetoothServiceUid = -1;
         }
-   }
+    }
 
     @Override
     public void registerListener(IBinder token, IMidiDeviceListener listener) {