OSDN Git Service

Add storaged callbacks in StorageManagerService
authorJin Qian <jinqian@google.com>
Sat, 14 Oct 2017 01:17:04 +0000 (18:17 -0700)
committerJin Qian <jinqian@google.com>
Thu, 19 Oct 2017 19:11:04 +0000 (12:11 -0700)
Notify storaged about user login so that storaged can read proto
files from CE when they become available.

Test: adb shell storaged -p
Bug: 63740245
Change-Id: Id9bd7023e6cfcfe1e5adeab1f0603e04ef586e93

Android.mk
services/core/Android.mk
services/core/java/com/android/server/StorageManagerService.java

index b5efd47..bbbd05a 100644 (file)
@@ -570,6 +570,7 @@ LOCAL_SRC_FILES += \
        ../../system/update_engine/binder_bindings/android/os/IUpdateEngineCallback.aidl \
 
 LOCAL_SRC_FILES += \
+       ../../system/core/storaged/binder/android/os/IStoraged.aidl \
        ../../system/netd/server/binder/android/net/INetd.aidl \
        ../../system/vold/binder/android/os/IVold.aidl \
        ../../system/vold/binder/android/os/IVoldListener.aidl \
@@ -608,6 +609,7 @@ LOCAL_AIDL_INCLUDES += \
        frameworks/av/drm/libmediadrm/aidl \
        frameworks/av/media/libaudioclient/aidl \
        frameworks/native/aidl/gui \
+       system/core/storaged/binder \
        system/netd/server/binder \
        system/vold/binder \
        system/bt/binder
index 1659133..633bb3e 100644 (file)
@@ -6,6 +6,7 @@ LOCAL_MODULE := services.core
 
 LOCAL_AIDL_INCLUDES := \
     frameworks/native/aidl/binder \
+    system/core/storaged/binder \
     system/netd/server/binder \
     system/vold/binder
 
@@ -13,6 +14,7 @@ LOCAL_SRC_FILES += \
     $(call all-java-files-under,java) \
     java/com/android/server/EventLogTags.logtags \
     java/com/android/server/am/EventLogTags.logtags \
+    ../../../../system/core/storaged/binder/android/os/IStoraged.aidl \
     ../../../../system/netd/server/binder/android/net/INetd.aidl \
     ../../../../system/netd/server/binder/android/net/metrics/INetdEventListener.aidl \
     ../../../../system/vold/binder/android/os/IVold.aidl \
index 55391b3..cd25610 100644 (file)
@@ -56,6 +56,7 @@ import android.os.FileUtils;
 import android.os.Handler;
 import android.os.HandlerThread;
 import android.os.IBinder;
+import android.os.IStoraged;
 import android.os.IVold;
 import android.os.IVoldListener;
 import android.os.IVoldTaskListener;
@@ -395,6 +396,7 @@ class StorageManagerService extends IStorageManager.Stub implements Watchdog.Mon
     private final Context mContext;
 
     private volatile IVold mVold;
+    private volatile IStoraged mStoraged;
 
     private volatile boolean mSystemReady = false;
     private volatile boolean mBootCompleted = false;
@@ -809,6 +811,7 @@ class StorageManagerService extends IStorageManager.Stub implements Watchdog.Mon
                 }
                 for (int userId : systemUnlockedUsers) {
                     mVold.onUserStarted(userId);
+                    mStoraged.onUserStarted(userId);
                 }
             } catch (Exception e) {
                 Slog.wtf(TAG, e);
@@ -824,6 +827,7 @@ class StorageManagerService extends IStorageManager.Stub implements Watchdog.Mon
         // bind mount against.
         try {
             mVold.onUserStarted(userId);
+            mStoraged.onUserStarted(userId);
         } catch (Exception e) {
             Slog.wtf(TAG, e);
         }
@@ -850,6 +854,7 @@ class StorageManagerService extends IStorageManager.Stub implements Watchdog.Mon
 
         try {
             mVold.onUserStopped(userId);
+            mStoraged.onUserStopped(userId);
         } catch (Exception e) {
             Slog.wtf(TAG, e);
         }
@@ -1335,13 +1340,36 @@ class StorageManagerService extends IStorageManager.Stub implements Watchdog.Mon
     }
 
     private void connect() {
-        IBinder binder = ServiceManager.getService("vold");
+        IBinder binder = ServiceManager.getService("storaged");
+        if (binder != null) {
+            try {
+                binder.linkToDeath(new DeathRecipient() {
+                    @Override
+                    public void binderDied() {
+                        Slog.w(TAG, "storaged died; reconnecting");
+                        mStoraged = null;
+                        connect();
+                    }
+                }, 0);
+            } catch (RemoteException e) {
+                binder = null;
+            }
+        }
+
+        if (binder != null) {
+            mStoraged = IStoraged.Stub.asInterface(binder);
+        } else {
+            Slog.w(TAG, "storaged not found; trying again");
+        }
+
+        binder = ServiceManager.getService("vold");
         if (binder != null) {
             try {
                 binder.linkToDeath(new DeathRecipient() {
                     @Override
                     public void binderDied() {
                         Slog.w(TAG, "vold died; reconnecting");
+                        mVold = null;
                         connect();
                     }
                 }, 0);
@@ -1354,18 +1382,21 @@ class StorageManagerService extends IStorageManager.Stub implements Watchdog.Mon
             mVold = IVold.Stub.asInterface(binder);
             try {
                 mVold.setListener(mListener);
-                onDaemonConnected();
-                return;
             } catch (RemoteException e) {
+                mVold = null;
                 Slog.w(TAG, "vold listener rejected; trying again", e);
             }
         } else {
             Slog.w(TAG, "vold not found; trying again");
         }
 
-        BackgroundThread.getHandler().postDelayed(() -> {
-            connect();
-        }, DateUtils.SECOND_IN_MILLIS);
+        if (mStoraged == null || mVold == null) {
+            BackgroundThread.getHandler().postDelayed(() -> {
+                connect();
+            }, DateUtils.SECOND_IN_MILLIS);
+        } else {
+            onDaemonConnected();
+        }
     }
 
     private void systemReady() {