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

Commit a7353961 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add token to the resolver APIs"

parents d01a9aee d3c51069
Loading
Loading
Loading
Loading
+2 −4
Original line number Diff line number Diff line
@@ -5002,10 +5002,8 @@ package android.app {
    ctor public InstantAppResolverService();
    method public final void attachBaseContext(android.content.Context);
    method public final android.os.IBinder onBind(android.content.Intent);
    method public void onGetInstantAppIntentFilter(int[], android.app.InstantAppResolverService.InstantAppResolutionCallback);
    method public void onGetInstantAppResolveInfo(int[], android.app.InstantAppResolverService.InstantAppResolutionCallback);
    field public static final java.lang.String EXTRA_RESOLVE_INFO = "android.app.extra.RESOLVE_INFO";
    field public static final java.lang.String EXTRA_SEQUENCE = "android.app.extra.SEQUENCE";
    method public void onGetInstantAppIntentFilter(int[], java.lang.String, android.app.InstantAppResolverService.InstantAppResolutionCallback);
    method public void onGetInstantAppResolveInfo(int[], java.lang.String, android.app.InstantAppResolverService.InstantAppResolutionCallback);
  }
  public static final class InstantAppResolverService.InstantAppResolutionCallback {
+18 −3
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.pm.EphemeralResolveInfo;
import android.content.pm.InstantAppResolveInfo;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
@@ -30,8 +31,10 @@ import android.os.IRemoteCallback;
import android.os.Looper;
import android.os.Message;
import android.os.RemoteException;
import android.util.Log;

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

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

    /**
     * Called to retrieve resolve info for ephemeral applications.
     *
@@ -79,7 +85,12 @@ public abstract class EphemeralResolverService extends InstantAppResolverService
    }

    @Override
    void _onGetInstantAppResolveInfo(int[] digestPrefix, InstantAppResolutionCallback callback) {
    void _onGetInstantAppResolveInfo(int[] digestPrefix, String token,
            InstantAppResolutionCallback callback) {
        if (DEBUG_EPHEMERAL) {
            Log.d(TAG, "Legacy resolver; getInstantAppResolveInfo;"
                    + " prefix: " + Arrays.toString(digestPrefix));
        }
        final List<EphemeralResolveInfo> response = onGetEphemeralResolveInfo(digestPrefix);
        final int responseSize = response == null ? 0 : response.size();
        final List<InstantAppResolveInfo> resultList = new ArrayList<>(responseSize);
@@ -90,8 +101,12 @@ public abstract class EphemeralResolverService extends InstantAppResolverService
    }

    @Override
    void _onGetInstantAppIntentFilter(int[] digestPrefix, String hostName,
            InstantAppResolutionCallback callback) {
    void _onGetInstantAppIntentFilter(int[] digestPrefix, String token,
            String hostName, InstantAppResolutionCallback callback) {
        if (DEBUG_EPHEMERAL) {
            Log.d(TAG, "Legacy resolver; getInstantAppIntentFilter;"
                    + " prefix: " + Arrays.toString(digestPrefix));
        }
        final EphemeralResolveInfo response = onGetEphemeralIntentFilter(hostName);
        final List<InstantAppResolveInfo> resultList = new ArrayList<>(1);
        resultList.add(response.getInstantAppResolveInfo());
+2 −2
Original line number Diff line number Diff line
@@ -21,8 +21,8 @@ import android.os.IRemoteCallback;
/** @hide */
oneway interface IInstantAppResolver {
    void getInstantAppResolveInfoList(in int[] digestPrefix,
            int sequence, IRemoteCallback callback);
            String token, int sequence, IRemoteCallback callback);

    void getInstantAppIntentFilterList(in int[] digestPrefix,
            int sequence, String hostName, IRemoteCallback callback);
            String token, String hostName, IRemoteCallback callback);
}
+41 −33
Original line number Diff line number Diff line
@@ -29,6 +29,8 @@ import android.os.Looper;
import android.os.Message;
import android.os.RemoteException;

import com.android.internal.os.SomeArgs;

import java.util.List;

/**
@@ -37,10 +39,10 @@ import java.util.List;
 */
@SystemApi
public abstract class InstantAppResolverService extends Service {
    /** @hide */
    public static final String EXTRA_RESOLVE_INFO = "android.app.extra.RESOLVE_INFO";
    /** @hide */
    public static final String EXTRA_SEQUENCE = "android.app.extra.SEQUENCE";
    static final String EXTRA_PREFIX = "android.app.PREFIX";
    static final String EXTRA_HOSTNAME = "android.app.HOSTNAME";
    Handler mHandler;

    /**
@@ -49,7 +51,7 @@ public abstract class InstantAppResolverService extends Service {
     * @param digestPrefix The hash prefix of the instant app's domain.
     */
    public void onGetInstantAppResolveInfo(
            int digestPrefix[], InstantAppResolutionCallback callback) {
            int digestPrefix[], String token, InstantAppResolutionCallback callback) {
        throw new IllegalStateException("Must define");
    }

@@ -59,7 +61,7 @@ public abstract class InstantAppResolverService extends Service {
     * @param digestPrefix The hash prefix of the instant app's domain.
     */
    public void onGetInstantAppIntentFilter(
            int digestPrefix[], InstantAppResolutionCallback callback) {
            int digestPrefix[], String token, InstantAppResolutionCallback callback) {
        throw new IllegalStateException("Must define");
    }

@@ -81,25 +83,26 @@ public abstract class InstantAppResolverService extends Service {
        return new IInstantAppResolver.Stub() {
            @Override
            public void getInstantAppResolveInfoList(
                    int digestPrefix[], int sequence, IRemoteCallback callback) {
                final Message msg = mHandler.obtainMessage(
                        ServiceHandler.MSG_GET_INSTANT_APP_RESOLVE_INFO, sequence, 0, callback);
                final Bundle data = new Bundle();
                data.putIntArray(EXTRA_PREFIX, digestPrefix);
                msg.setData(data);
                msg.sendToTarget();
                    int digestPrefix[], String token, int sequence, IRemoteCallback callback) {
                final SomeArgs args = SomeArgs.obtain();
                args.arg1 = callback;
                args.arg2 = digestPrefix;
                args.arg3 = token;
                mHandler.obtainMessage(
                                ServiceHandler.MSG_GET_INSTANT_APP_RESOLVE_INFO, sequence, 0, args)
                        .sendToTarget();
            }

            @Override
            public void getInstantAppIntentFilterList(
                    int digestPrefix[], int sequence, String hostName, IRemoteCallback callback) {
                final Message msg = mHandler.obtainMessage(
                        ServiceHandler.MSG_GET_INSTANT_APP_INTENT_FILTER, sequence, 0, callback);
                final Bundle data = new Bundle();
                data.putString(EXTRA_HOSTNAME, hostName);
                data.putIntArray(EXTRA_PREFIX, digestPrefix);
                msg.setData(data);
                msg.sendToTarget();
                    int digestPrefix[], String token, String hostName, IRemoteCallback callback) {
                final SomeArgs args = SomeArgs.obtain();
                args.arg1 = callback;
                args.arg2 = digestPrefix;
                args.arg3 = token;
                args.arg4 = hostName;
                mHandler.obtainMessage(
                        ServiceHandler.MSG_GET_INSTANT_APP_INTENT_FILTER, callback).sendToTarget();
            }
        };
    }
@@ -117,8 +120,8 @@ public abstract class InstantAppResolverService extends Service {

        public void onInstantAppResolveInfo(List<InstantAppResolveInfo> resolveInfo) {
            final Bundle data = new Bundle();
            data.putInt(EXTRA_SEQUENCE, mSequence);
            data.putParcelableList(EXTRA_RESOLVE_INFO, resolveInfo);
            data.putInt(EXTRA_SEQUENCE, mSequence);
            try {
                mCallback.sendResult(data);
            } catch (RemoteException e) {
@@ -127,13 +130,14 @@ public abstract class InstantAppResolverService extends Service {
    }

    @Deprecated
    void _onGetInstantAppResolveInfo(int[] digestPrefix, InstantAppResolutionCallback callback) {
        onGetInstantAppResolveInfo(digestPrefix, callback);
    void _onGetInstantAppResolveInfo(int[] digestPrefix, String token,
            InstantAppResolutionCallback callback) {
        onGetInstantAppResolveInfo(digestPrefix, token, callback);
    }
    @Deprecated
    void _onGetInstantAppIntentFilter(int digestPrefix[], String hostName,
    void _onGetInstantAppIntentFilter(int digestPrefix[], String token, String hostName,
            InstantAppResolutionCallback callback) {
        onGetInstantAppIntentFilter(digestPrefix, callback);
        onGetInstantAppIntentFilter(digestPrefix, token, callback);
    }

    private final class ServiceHandler extends Handler {
@@ -150,21 +154,25 @@ public abstract class InstantAppResolverService extends Service {
            final int action = message.what;
            switch (action) {
                case MSG_GET_INSTANT_APP_RESOLVE_INFO: {
                    final IRemoteCallback callback = (IRemoteCallback) message.obj;
                    final SomeArgs args = (SomeArgs) message.obj;
                    final IRemoteCallback callback = (IRemoteCallback) args.arg1;
                    final int[] digestPrefix = (int[]) args.arg2;
                    final String token = (String) args.arg3;
                    final int sequence = message.arg1;
                    final int[] digestPrefix = message.getData().getIntArray(EXTRA_PREFIX);
                    _onGetInstantAppResolveInfo(
                            digestPrefix, new InstantAppResolutionCallback(sequence, callback));
                            digestPrefix, token,
                            new InstantAppResolutionCallback(sequence, callback));
                } break;

                case MSG_GET_INSTANT_APP_INTENT_FILTER: {
                    final IRemoteCallback callback = (IRemoteCallback) message.obj;
                    final int sequence = message.arg1;
                    final int[] digestPrefix = message.getData().getIntArray(EXTRA_PREFIX);
                    final String hostName = message.getData().getString(EXTRA_HOSTNAME);
                    final SomeArgs args = (SomeArgs) message.obj;
                    final IRemoteCallback callback = (IRemoteCallback) args.arg1;
                    final int[] digestPrefix = (int[]) args.arg2;
                    final String token = (String) args.arg3;
                    final String hostName = (String) args.arg4;
                    _onGetInstantAppIntentFilter(
                            digestPrefix, hostName,
                            new InstantAppResolutionCallback(sequence, callback));
                            digestPrefix, token, hostName,
                            new InstantAppResolutionCallback(-1 /*sequence*/, callback));
                } break;

                default: {
+10 −9
Original line number Diff line number Diff line
@@ -68,11 +68,12 @@ final class EphemeralResolverConnection {
        mIntent = new Intent(Intent.ACTION_RESOLVE_EPHEMERAL_PACKAGE).setComponent(componentName);
    }

    public final List<InstantAppResolveInfo> getInstantAppResolveInfoList(int hashPrefix[]) {
    public final List<InstantAppResolveInfo> getInstantAppResolveInfoList(int hashPrefix[],
            String token) {
        throwIfCalledOnMainThread();
        try {
            return mGetEphemeralResolveInfoCaller.getEphemeralResolveInfoList(
                    getRemoteInstanceLazy(), hashPrefix);
                    getRemoteInstanceLazy(), hashPrefix, token);
        } catch (RemoteException re) {
        } catch (TimeoutException te) {
        } finally {
@@ -83,8 +84,9 @@ final class EphemeralResolverConnection {
        return null;
    }

    public final void getInstantAppIntentFilterList(int hashPrefix[], String hostName,
            PhaseTwoCallback callback, Handler callbackHandler, final long startTime) {
    public final void getInstantAppIntentFilterList(int hashPrefix[], String token,
            String hostName, PhaseTwoCallback callback, Handler callbackHandler,
            final long startTime) {
        final IRemoteCallback remoteCallback = new IRemoteCallback.Stub() {
            @Override
            public void sendResult(Bundle data) throws RemoteException {
@@ -100,9 +102,8 @@ final class EphemeralResolverConnection {
            }
        };
        try {
            // TODO deprecate sequence; it's never used
            getRemoteInstanceLazy().getInstantAppIntentFilterList(
                    hashPrefix, 0 /*sequence*/, hostName, remoteCallback);
            getRemoteInstanceLazy()
                    .getInstantAppIntentFilterList(hashPrefix, token, hostName, remoteCallback);
        } catch (RemoteException re) {
        } catch (TimeoutException te) {
        }
@@ -215,10 +216,10 @@ final class EphemeralResolverConnection {
        }

        public List<InstantAppResolveInfo> getEphemeralResolveInfoList(
                IInstantAppResolver target, int hashPrefix[])
                IInstantAppResolver target, int hashPrefix[], String token)
                        throws RemoteException, TimeoutException {
            final int sequence = onBeforeRemoteCall();
            target.getInstantAppResolveInfoList(hashPrefix, sequence, mCallback);
            target.getInstantAppResolveInfoList(hashPrefix, token, sequence, mCallback);
            return getResultTimed(sequence);
        }
    }
Loading