Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cc234da3 authored by peter.zhang's avatar peter.zhang Committed by Michael Bestas
Browse files

Fix StorageManagerService linkToDeath more than one time when vold/storaged died.

Storaged and vold register Binder.linkToDeath in the same method, once one died,
the other would register Binder.linkToDeath many times. Once the other died, it
would receive binderDied callBack many times, then executing volume reset command
many times in very short time, it's a bad user experience.

Bug:135167044
Test:kill vold and storaged, just one time binderDied callBack, so just run one
time volume reset.

Change-Id: I881af5b6ce399dad39274fc2598e92a3b9f88a77
parent e8d1a4d5
Loading
Loading
Loading
Loading
+18 −7
Original line number Diff line number Diff line
@@ -1560,10 +1560,11 @@ class StorageManagerService extends IStorageManager.Stub
    }

    private void start() {
        connect();
        connectStoraged();
        connectVold();
    }

    private void connect() {
    private void connectStoraged() {
        IBinder binder = ServiceManager.getService("storaged");
        if (binder != null) {
            try {
@@ -1572,7 +1573,7 @@ class StorageManagerService extends IStorageManager.Stub
                    public void binderDied() {
                        Slog.w(TAG, "storaged died; reconnecting");
                        mStoraged = null;
                        connect();
                        connectStoraged();
                    }
                }, 0);
            } catch (RemoteException e) {
@@ -1586,7 +1587,17 @@ class StorageManagerService extends IStorageManager.Stub
            Slog.w(TAG, "storaged not found; trying again");
        }

        binder = ServiceManager.getService("vold");
        if (mStoraged == null) {
            BackgroundThread.getHandler().postDelayed(() -> {
                connectStoraged();
            }, DateUtils.SECOND_IN_MILLIS);
        } else {
            onDaemonConnected();
        }
    }

    private void connectVold() {
        IBinder binder = ServiceManager.getService("vold");
        if (binder != null) {
            try {
                binder.linkToDeath(new DeathRecipient() {
@@ -1594,7 +1605,7 @@ class StorageManagerService extends IStorageManager.Stub
                    public void binderDied() {
                        Slog.w(TAG, "vold died; reconnecting");
                        mVold = null;
                        connect();
                        connectVold();
                    }
                }, 0);
            } catch (RemoteException e) {
@@ -1614,9 +1625,9 @@ class StorageManagerService extends IStorageManager.Stub
            Slog.w(TAG, "vold not found; trying again");
        }

        if (mStoraged == null || mVold == null) {
        if (mVold == null) {
            BackgroundThread.getHandler().postDelayed(() -> {
                connect();
                connectVold();
            }, DateUtils.SECOND_IN_MILLIS);
        } else {
            onDaemonConnected();