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

Commit ecc59b12 authored by Todd Kennedy's avatar Todd Kennedy Committed by gitbuildkicker
Browse files

Bind with the correct action

While services themselves don't need an action when an explicit
component is specified, services in GMS may be different. In
the case of instant apps, the resolver service is hidden behind
a proxy that uses the action to route to the actual, implementing
service.

Bug: 36594944
Test: see that ephemeral resolution occurs
Change-Id: Id8c352614f780dc63f36c65be2ddb2d480b6846b
(cherry picked from commit 02a6b73e)
parent bee0b778
Loading
Loading
Loading
Loading
+15 −0
Original line number Original line Diff line number Diff line
@@ -21,6 +21,7 @@ import android.app.Service;
import android.content.Context;
import android.content.Context;
import android.content.Intent;
import android.content.Intent;
import android.content.pm.InstantAppResolveInfo;
import android.content.pm.InstantAppResolveInfo;
import android.os.Build;
import android.os.Bundle;
import android.os.Bundle;
import android.os.Handler;
import android.os.Handler;
import android.os.IBinder;
import android.os.IBinder;
@@ -28,9 +29,12 @@ import android.os.IRemoteCallback;
import android.os.Looper;
import android.os.Looper;
import android.os.Message;
import android.os.Message;
import android.os.RemoteException;
import android.os.RemoteException;
import android.util.Log;
import android.util.Slog;


import com.android.internal.os.SomeArgs;
import com.android.internal.os.SomeArgs;


import java.util.Arrays;
import java.util.List;
import java.util.List;


/**
/**
@@ -39,6 +43,9 @@ import java.util.List;
 */
 */
@SystemApi
@SystemApi
public abstract class InstantAppResolverService extends Service {
public abstract class InstantAppResolverService extends Service {
    private static final boolean DEBUG_EPHEMERAL = Build.IS_DEBUGGABLE;
    private static final String TAG = "PackageManager";

    /** @hide */
    /** @hide */
    public static final String EXTRA_RESOLVE_INFO = "android.app.extra.RESOLVE_INFO";
    public static final String EXTRA_RESOLVE_INFO = "android.app.extra.RESOLVE_INFO";
    /** @hide */
    /** @hide */
@@ -132,11 +139,19 @@ public abstract class InstantAppResolverService extends Service {
    @Deprecated
    @Deprecated
    void _onGetInstantAppResolveInfo(int[] digestPrefix, String token,
    void _onGetInstantAppResolveInfo(int[] digestPrefix, String token,
            InstantAppResolutionCallback callback) {
            InstantAppResolutionCallback callback) {
        if (DEBUG_EPHEMERAL) {
            Slog.d(TAG, "Instant resolver; getInstantAppResolveInfo;"
                    + " prefix: " + Arrays.toString(digestPrefix));
        }
        onGetInstantAppResolveInfo(digestPrefix, token, callback);
        onGetInstantAppResolveInfo(digestPrefix, token, callback);
    }
    }
    @Deprecated
    @Deprecated
    void _onGetInstantAppIntentFilter(int digestPrefix[], String token, String hostName,
    void _onGetInstantAppIntentFilter(int digestPrefix[], String token, String hostName,
            InstantAppResolutionCallback callback) {
            InstantAppResolutionCallback callback) {
        if (DEBUG_EPHEMERAL) {
            Slog.d(TAG, "Instant resolver; getInstantAppIntentFilter;"
                    + " prefix: " + Arrays.toString(digestPrefix));
        }
        onGetInstantAppIntentFilter(digestPrefix, token, callback);
        onGetInstantAppIntentFilter(digestPrefix, token, callback);
    }
    }


+3 −2
Original line number Original line Diff line number Diff line
@@ -64,9 +64,10 @@ final class EphemeralResolverConnection implements DeathRecipient {
    private volatile boolean mBindRequested;
    private volatile boolean mBindRequested;
    private IInstantAppResolver mRemoteInstance;
    private IInstantAppResolver mRemoteInstance;


    public EphemeralResolverConnection(Context context, ComponentName componentName) {
    public EphemeralResolverConnection(
            Context context, ComponentName componentName, String action) {
        mContext = context;
        mContext = context;
        mIntent = new Intent(Intent.ACTION_RESOLVE_INSTANT_APP_PACKAGE).setComponent(componentName);
        mIntent = new Intent(action).setComponent(componentName);
    }
    }


    public final List<InstantAppResolveInfo> getInstantAppResolveInfoList(int hashPrefix[],
    public final List<InstantAppResolveInfo> getInstantAppResolveInfoList(int hashPrefix[],
+17 −13
Original line number Original line Diff line number Diff line
@@ -2813,15 +2813,17 @@ public class PackageManagerService extends IPackageManager.Stub {
            }
            }
            mInstallerService = new PackageInstallerService(context, this);
            mInstallerService = new PackageInstallerService(context, this);
            final ComponentName ephemeralResolverComponent = getEphemeralResolverLPr();
            final Pair<ComponentName, String> instantAppResolverComponent =
            if (ephemeralResolverComponent != null) {
                    getInstantAppResolverLPr();
            if (instantAppResolverComponent != null) {
                if (DEBUG_EPHEMERAL) {
                if (DEBUG_EPHEMERAL) {
                    Slog.d(TAG, "Set ephemeral resolver: " + ephemeralResolverComponent);
                    Slog.d(TAG, "Set ephemeral resolver: " + instantAppResolverComponent);
                }
                }
                mInstantAppResolverConnection =
                mInstantAppResolverConnection = new EphemeralResolverConnection(
                        new EphemeralResolverConnection(mContext, ephemeralResolverComponent);
                        mContext, instantAppResolverComponent.first,
                        instantAppResolverComponent.second);
                mInstantAppResolverSettingsComponent =
                mInstantAppResolverSettingsComponent =
                        getEphemeralResolverSettingsLPr(ephemeralResolverComponent);
                        getInstantAppResolverSettingsLPr(instantAppResolverComponent.first);
            } else {
            } else {
                mInstantAppResolverConnection = null;
                mInstantAppResolverConnection = null;
                mInstantAppResolverSettingsComponent = null;
                mInstantAppResolverSettingsComponent = null;
@@ -2868,7 +2870,7 @@ public class PackageManagerService extends IPackageManager.Stub {
    private void updateInstantAppInstallerLocked() {
    private void updateInstantAppInstallerLocked() {
        final ComponentName oldInstantAppInstallerComponent = mInstantAppInstallerComponent;
        final ComponentName oldInstantAppInstallerComponent = mInstantAppInstallerComponent;
        final ActivityInfo newInstantAppInstaller = getEphemeralInstallerLPr();
        final ActivityInfo newInstantAppInstaller = getInstantAppInstallerLPr();
        ComponentName newInstantAppInstallerComponent = newInstantAppInstaller == null
        ComponentName newInstantAppInstallerComponent = newInstantAppInstaller == null
                ? null : newInstantAppInstaller.getComponentName();
                ? null : newInstantAppInstaller.getComponentName();
@@ -3045,7 +3047,7 @@ public class PackageManagerService extends IPackageManager.Stub {
        }
        }
    }
    }
    private @Nullable ComponentName getEphemeralResolverLPr() {
    private @Nullable Pair<ComponentName, String> getInstantAppResolverLPr() {
        final String[] packageArray =
        final String[] packageArray =
                mContext.getResources().getStringArray(R.array.config_ephemeralResolverPackage);
                mContext.getResources().getStringArray(R.array.config_ephemeralResolverPackage);
        if (packageArray.length == 0 && !Build.IS_DEBUGGABLE) {
        if (packageArray.length == 0 && !Build.IS_DEBUGGABLE) {
@@ -3060,7 +3062,8 @@ public class PackageManagerService extends IPackageManager.Stub {
                MATCH_DIRECT_BOOT_AWARE
                MATCH_DIRECT_BOOT_AWARE
                | MATCH_DIRECT_BOOT_UNAWARE
                | MATCH_DIRECT_BOOT_UNAWARE
                | (!Build.IS_DEBUGGABLE ? MATCH_SYSTEM_ONLY : 0);
                | (!Build.IS_DEBUGGABLE ? MATCH_SYSTEM_ONLY : 0);
        final Intent resolverIntent = new Intent(Intent.ACTION_RESOLVE_INSTANT_APP_PACKAGE);
        String actionName = Intent.ACTION_RESOLVE_INSTANT_APP_PACKAGE;
        final Intent resolverIntent = new Intent(actionName);
        List<ResolveInfo> resolvers = queryIntentServicesInternal(resolverIntent, null,
        List<ResolveInfo> resolvers = queryIntentServicesInternal(resolverIntent, null,
                resolveFlags, UserHandle.USER_SYSTEM, callingUid, false /*includeInstantApps*/);
                resolveFlags, UserHandle.USER_SYSTEM, callingUid, false /*includeInstantApps*/);
        // temporarily look for the old action
        // temporarily look for the old action
@@ -3068,7 +3071,8 @@ public class PackageManagerService extends IPackageManager.Stub {
            if (DEBUG_EPHEMERAL) {
            if (DEBUG_EPHEMERAL) {
                Slog.d(TAG, "Ephemeral resolver not found with new action; try old one");
                Slog.d(TAG, "Ephemeral resolver not found with new action; try old one");
            }
            }
            resolverIntent.setAction(Intent.ACTION_RESOLVE_EPHEMERAL_PACKAGE);
            actionName = Intent.ACTION_RESOLVE_EPHEMERAL_PACKAGE;
            resolverIntent.setAction(actionName);
            resolvers = queryIntentServicesInternal(resolverIntent, null,
            resolvers = queryIntentServicesInternal(resolverIntent, null,
                    resolveFlags, UserHandle.USER_SYSTEM, callingUid, false /*includeInstantApps*/);
                    resolveFlags, UserHandle.USER_SYSTEM, callingUid, false /*includeInstantApps*/);
        }
        }
@@ -3101,7 +3105,7 @@ public class PackageManagerService extends IPackageManager.Stub {
                Slog.v(TAG, "Ephemeral resolver found;"
                Slog.v(TAG, "Ephemeral resolver found;"
                        + " pkg: " + packageName + ", info:" + info);
                        + " pkg: " + packageName + ", info:" + info);
            }
            }
            return new ComponentName(packageName, info.serviceInfo.name);
            return new Pair<>(new ComponentName(packageName, info.serviceInfo.name), actionName);
        }
        }
        if (DEBUG_EPHEMERAL) {
        if (DEBUG_EPHEMERAL) {
            Slog.v(TAG, "Ephemeral resolver NOT found");
            Slog.v(TAG, "Ephemeral resolver NOT found");
@@ -3109,7 +3113,7 @@ public class PackageManagerService extends IPackageManager.Stub {
        return null;
        return null;
    }
    }
    private @Nullable ActivityInfo getEphemeralInstallerLPr() {
    private @Nullable ActivityInfo getInstantAppInstallerLPr() {
        final Intent intent = new Intent(Intent.ACTION_INSTALL_INSTANT_APP_PACKAGE);
        final Intent intent = new Intent(Intent.ACTION_INSTALL_INSTANT_APP_PACKAGE);
        intent.addCategory(Intent.CATEGORY_DEFAULT);
        intent.addCategory(Intent.CATEGORY_DEFAULT);
        intent.setDataAndType(Uri.fromFile(new File("foo.apk")), PACKAGE_MIME_TYPE);
        intent.setDataAndType(Uri.fromFile(new File("foo.apk")), PACKAGE_MIME_TYPE);
@@ -3151,7 +3155,7 @@ public class PackageManagerService extends IPackageManager.Stub {
        }
        }
    }
    }
    private @Nullable ComponentName getEphemeralResolverSettingsLPr(
    private @Nullable ComponentName getInstantAppResolverSettingsLPr(
            @NonNull ComponentName resolver) {
            @NonNull ComponentName resolver) {
        final Intent intent =  new Intent(Intent.ACTION_INSTANT_APP_RESOLVER_SETTINGS)
        final Intent intent =  new Intent(Intent.ACTION_INSTANT_APP_RESOLVER_SETTINGS)
                .addCategory(Intent.CATEGORY_DEFAULT)
                .addCategory(Intent.CATEGORY_DEFAULT)