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

Commit 9c4aa5c7 authored by Patrick Baumann's avatar Patrick Baumann
Browse files

Attempts to optimistically bind to AIA resolver

To avoid the first resolve of an Instant App needing to bind to the
Instant App resolver during resolution, we attempt to bind soon after
device boot and subsequently whenever the resolver connection dies (such
as on app kill on upgrade).

Bug: 73771940
Test: manual - attempt resolve soon after boot and observe successful resolve
Test: manual - force-stop com.google.android.gms and observe rebind
Change-Id: Iba13cafd98e3477b1b1fe0288ea83f90dd399aba
parent b1d5004c
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.server.pm;

import android.annotation.AnyThread;
import android.annotation.WorkerThread;
import android.app.IInstantAppResolver;
import android.app.InstantAppResolverService;
import android.content.ComponentName;
@@ -37,6 +39,7 @@ import android.util.Slog;
import android.util.TimedRemoteCaller;

import com.android.internal.annotations.GuardedBy;
import com.android.internal.os.BackgroundThread;

import java.util.ArrayList;
import java.util.List;
@@ -68,6 +71,7 @@ final class InstantAppResolverConnection implements DeathRecipient {
    private static final int STATE_IDLE    = 0; // no bind operation is ongoing
    private static final int STATE_BINDING = 1; // someone is binding and waiting
    private static final int STATE_PENDING = 2; // a bind is pending, but the caller is not waiting
    private final Handler mBgHandler;

    @GuardedBy("mLock")
    private int mBindState = STATE_IDLE;
@@ -78,6 +82,7 @@ final class InstantAppResolverConnection implements DeathRecipient {
            Context context, ComponentName componentName, String action) {
        mContext = context;
        mIntent = new Intent(action).setComponent(componentName);
        mBgHandler = BackgroundThread.getHandler();
    }

    public final List<InstantAppResolveInfo> getInstantAppResolveInfoList(Intent sanitizedIntent,
@@ -131,6 +136,7 @@ final class InstantAppResolverConnection implements DeathRecipient {
        }
    }

    @WorkerThread
    private IInstantAppResolver getRemoteInstanceLazy(String token)
            throws ConnectionException, TimeoutException, InterruptedException {
        long binderToken = Binder.clearCallingIdentity();
@@ -157,6 +163,7 @@ final class InstantAppResolverConnection implements DeathRecipient {
        }
    }

    @WorkerThread
    private IInstantAppResolver bind(String token)
            throws ConnectionException, TimeoutException, InterruptedException {
        boolean doUnbind = false;
@@ -241,6 +248,19 @@ final class InstantAppResolverConnection implements DeathRecipient {
        }
    }

    @AnyThread
    void optimisticBind() {
        mBgHandler.post(() -> {
            try {
                if (bind("Optimistic Bind") != null && DEBUG_INSTANT) {
                    Slog.i(TAG, "Optimistic bind succeeded.");
                }
            } catch (ConnectionException | TimeoutException | InterruptedException e) {
                Slog.e(TAG, "Optimistic bind failed.", e);
            }
        });
    }

    @Override
    public void binderDied() {
        if (DEBUG_INSTANT) {
@@ -249,6 +269,7 @@ final class InstantAppResolverConnection implements DeathRecipient {
        synchronized (mLock) {
            handleBinderDiedLocked();
        }
        optimisticBind();
    }

    @GuardedBy("mLock")
+10 −0
Original line number Diff line number Diff line
@@ -20873,6 +20873,16 @@ Slog.v(TAG, ":: stepped forward, applying functor at tag " + parser.getName());
        reconcileApps(StorageManager.UUID_PRIVATE_INTERNAL);
        mPermissionManager.systemReady();
        if (mInstantAppResolverConnection != null) {
            mContext.registerReceiver(new BroadcastReceiver() {
                @Override
                public void onReceive(Context context, Intent intent) {
                    mInstantAppResolverConnection.optimisticBind();
                    mContext.unregisterReceiver(this);
                }
            }, new IntentFilter(Intent.ACTION_BOOT_COMPLETED));
        }
    }
    public void waitForAppDataPrepared() {