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

Commit 57c829c2 authored by Jeff Sharkey's avatar Jeff Sharkey Committed by android-build-merger
Browse files

Merge "Reconnect to installd when it restarts." am: 48d5d6cd am: fe35f0f4

am: e286d1b2

Change-Id: Ib7ff45fee2865a28e7cb138d9fd418d7a3e50c94
parents 6c00eb1f e286d1b2
Loading
Loading
Loading
Loading
+32 −2
Original line number Diff line number Diff line
@@ -20,10 +20,15 @@ import android.annotation.Nullable;
import android.content.Context;
import android.content.pm.PackageStats;
import android.os.Build;
import android.os.IBinder;
import android.os.IBinder.DeathRecipient;
import android.os.IInstalld;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.text.format.DateUtils;
import android.util.Slog;

import com.android.internal.os.BackgroundThread;
import com.android.server.SystemService;

import dalvik.system.VMRuntime;
@@ -52,7 +57,6 @@ public class Installer extends SystemService {

    private final boolean mIsolated;

    // TODO: reconnect if installd restarts
    private volatile IInstalld mInstalld;
    private volatile Object mWarnIfHeld;

@@ -83,7 +87,33 @@ public class Installer extends SystemService {
        if (mIsolated) {
            mInstalld = null;
        } else {
            mInstalld = IInstalld.Stub.asInterface(ServiceManager.getService("installd"));
            connect();
        }
    }

    private void connect() {
        IBinder binder = ServiceManager.getService("installd");
        if (binder != null) {
            try {
                binder.linkToDeath(new DeathRecipient() {
                    @Override
                    public void binderDied() {
                        Slog.w(TAG, "installd died; reconnecting");
                        connect();
                    }
                }, 0);
            } catch (RemoteException e) {
                binder = null;
            }
        }

        if (binder != null) {
            mInstalld = IInstalld.Stub.asInterface(binder);
        } else {
            Slog.w(TAG, "installd not found; trying again");
            BackgroundThread.getHandler().postDelayed(() -> {
                connect();
            }, DateUtils.SECOND_IN_MILLIS);
        }
    }