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

Commit 1e781efd authored by Joshua Trask's avatar Joshua Trask
Browse files

Remove ChooserTargetService flow entrypoints.

Despite the `USE_CHOOSER_TARGET_SERVICE_FOR_DIRECT_TARGETS`
flag being hard-coded to true and thus triggering the
deprecated flow, the effects of that flow (modulo potential
bugs) have been suppressed since the ChooserFlag was set to
false. That is, the logic removed in this CL was a (somewhat
misleading) no-op; the *intended* behavior was disabled,
but there were possible unintended consequences of the
vestigial code (which I believe were addressed as of
ag/15662048).

Test: presubmits
Change-Id: I0a2aa6e8bd796e41f6ebc69a54a1f74f9eeebbd9
parent c4c62694
Loading
Loading
Loading
Loading
+1 −105
Original line number Original line Diff line number Diff line
@@ -86,7 +86,6 @@ import android.provider.Downloads;
import android.provider.OpenableColumns;
import android.provider.OpenableColumns;
import android.provider.Settings;
import android.provider.Settings;
import android.service.chooser.ChooserTarget;
import android.service.chooser.ChooserTarget;
import android.service.chooser.ChooserTargetService;
import android.service.chooser.IChooserTargetResult;
import android.service.chooser.IChooserTargetResult;
import android.service.chooser.IChooserTargetService;
import android.service.chooser.IChooserTargetService;
import android.text.TextUtils;
import android.text.TextUtils;
@@ -227,8 +226,6 @@ public class ChooserActivity extends ResolverActivity implements
    // statsd logger wrapper
    // statsd logger wrapper
    protected ChooserActivityLogger mChooserActivityLogger;
    protected ChooserActivityLogger mChooserActivityLogger;


    private static final boolean USE_CHOOSER_TARGET_SERVICE_FOR_DIRECT_TARGETS = true;

    @IntDef(flag = false, prefix = { "TARGET_TYPE_" }, value = {
    @IntDef(flag = false, prefix = { "TARGET_TYPE_" }, value = {
            TARGET_TYPE_DEFAULT,
            TARGET_TYPE_DEFAULT,
            TARGET_TYPE_CHOOSER_TARGET,
            TARGET_TYPE_CHOOSER_TARGET,
@@ -268,7 +265,6 @@ public class ChooserActivity extends ResolverActivity implements
    private long mChooserShownTime;
    private long mChooserShownTime;
    protected boolean mIsSuccessfullySelected;
    protected boolean mIsSuccessfullySelected;


    private long mQueriedTargetServicesTimeMs;
    private long mQueriedSharingShortcutsTimeMs;
    private long mQueriedSharingShortcutsTimeMs;


    private int mChooserRowServiceSpacing;
    private int mChooserRowServiceSpacing;
@@ -1887,96 +1883,6 @@ public class ChooserActivity extends ResolverActivity implements
        }
        }
    }
    }


    @VisibleForTesting
    protected void queryTargetServices(ChooserListAdapter adapter) {

        mQueriedTargetServicesTimeMs = System.currentTimeMillis();

        Context selectedProfileContext = createContextAsUser(
                adapter.getUserHandle(), 0 /* flags */);
        final PackageManager pm = selectedProfileContext.getPackageManager();
        ShortcutManager sm = selectedProfileContext.getSystemService(ShortcutManager.class);
        int targetsToQuery = 0;

        for (int i = 0, N = adapter.getDisplayResolveInfoCount(); i < N; i++) {
            final DisplayResolveInfo dri = adapter.getDisplayResolveInfo(i);
            if (adapter.getScore(dri) == 0) {
                // A score of 0 means the app hasn't been used in some time;
                // don't query it as it's not likely to be relevant.
                continue;
            }
            final ActivityInfo ai = dri.getResolveInfo().activityInfo;
            if (sm.hasShareTargets(ai.packageName)) {
                // Share targets will be queried from ShortcutManager
                continue;
            }
            final Bundle md = ai.metaData;
            final String serviceName = md != null ? convertServiceName(ai.packageName,
                    md.getString(ChooserTargetService.META_DATA_NAME)) : null;
            if (serviceName != null && ChooserFlags.USE_SERVICE_TARGETS_FOR_DIRECT_TARGETS) {
                final ComponentName serviceComponent = new ComponentName(
                        ai.packageName, serviceName);

                UserHandle userHandle = adapter.getUserHandle();
                Pair<ComponentName, UserHandle> requestedItem =
                        new Pair<>(serviceComponent, userHandle);
                if (mServicesRequested.contains(requestedItem)) {
                    continue;
                }
                mServicesRequested.add(requestedItem);

                final Intent serviceIntent = new Intent(ChooserTargetService.SERVICE_INTERFACE)
                        .setComponent(serviceComponent);

                if (DEBUG) {
                    Log.d(TAG, "queryTargets found target with service " + serviceComponent);
                }

                try {
                    final String perm = pm.getServiceInfo(serviceComponent, 0).permission;
                    if (!ChooserTargetService.BIND_PERMISSION.equals(perm)) {
                        Log.w(TAG, "ChooserTargetService " + serviceComponent + " does not require"
                                + " permission " + ChooserTargetService.BIND_PERMISSION
                                + " - this service will not be queried for ChooserTargets."
                                + " add android:permission=\""
                                + ChooserTargetService.BIND_PERMISSION + "\""
                                + " to the <service> tag for " + serviceComponent
                                + " in the manifest.");
                        continue;
                    }
                } catch (NameNotFoundException e) {
                    Log.e(TAG, "Could not look up service " + serviceComponent
                            + "; component name not found");
                    continue;
                }

                final ChooserTargetServiceConnection conn =
                        new ChooserTargetServiceConnection(this, dri,
                                adapter.getUserHandle());

                // Explicitly specify the user handle instead of calling bindService
                // to avoid the warning from calling from the system process without an explicit
                // user handle
                if (bindServiceAsUser(serviceIntent, conn, BIND_AUTO_CREATE | BIND_NOT_FOREGROUND,
                        adapter.getUserHandle())) {
                    if (DEBUG) {
                        Log.d(TAG, "Binding service connection for target " + dri
                                + " intent " + serviceIntent);
                    }
                    mServiceConnections.add(conn);
                    targetsToQuery++;
                }
            }
            if (targetsToQuery >= QUERY_TARGET_SERVICE_LIMIT) {
                if (DEBUG) {
                    Log.d(TAG, "queryTargets hit query target limit "
                            + QUERY_TARGET_SERVICE_LIMIT);
                }
                break;
            }
        }
    }

    private IntentFilter getTargetIntentFilter() {
    private IntentFilter getTargetIntentFilter() {
        try {
        try {
            final Intent intent = getTargetIntent();
            final Intent intent = getTargetIntent();
@@ -2241,10 +2147,7 @@ public class ChooserActivity extends ResolverActivity implements
    }
    }


    private void logDirectShareTargetReceived(int logCategory) {
    private void logDirectShareTargetReceived(int logCategory) {
        final long queryTime =
        final int apiLatency = (int) (System.currentTimeMillis() - mQueriedSharingShortcutsTimeMs);
                logCategory == MetricsEvent.ACTION_DIRECT_SHARE_TARGETS_LOADED_SHORTCUT_MANAGER
                        ? mQueriedSharingShortcutsTimeMs : mQueriedTargetServicesTimeMs;
        final int apiLatency = (int) (System.currentTimeMillis() - queryTime);
        getMetricsLogger().write(new LogMaker(logCategory).setSubtype(apiLatency));
        getMetricsLogger().write(new LogMaker(logCategory).setSubtype(apiLatency));
    }
    }


@@ -2850,13 +2753,6 @@ public class ChooserActivity extends ResolverActivity implements


            queryDirectShareTargets(chooserListAdapter, false);
            queryDirectShareTargets(chooserListAdapter, false);
        }
        }
        if (USE_CHOOSER_TARGET_SERVICE_FOR_DIRECT_TARGETS) {
            if (DEBUG) {
                Log.d(TAG, "List built querying services");
            }

            queryTargetServices(chooserListAdapter);
        }


        getChooserActivityLogger().logSharesheetAppLoadComplete();
        getChooserActivityLogger().logSharesheetAppLoadComplete();
    }
    }
+0 −12
Original line number Original line Diff line number Diff line
@@ -17,24 +17,12 @@
package com.android.internal.app;
package com.android.internal.app;


import android.app.prediction.AppPredictionManager;
import android.app.prediction.AppPredictionManager;
import android.provider.DeviceConfig;

import com.android.internal.config.sysui.SystemUiDeviceConfigFlags;


/**
/**
 * Common flags for {@link ChooserListAdapter} and {@link ChooserActivity}.
 * Common flags for {@link ChooserListAdapter} and {@link ChooserActivity}.
 */
 */
public class ChooserFlags {
public class ChooserFlags {


    /**
     * Whether to use the deprecated {@link android.service.chooser.ChooserTargetService} API for
     * direct share targets. If true, both CTS and Shortcuts will be used to find Direct Share
     * targets. If false, only Shortcuts will be used.
     */
    public static final boolean USE_SERVICE_TARGETS_FOR_DIRECT_TARGETS =
            DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_SYSTEMUI,
                SystemUiDeviceConfigFlags.SHARE_USE_SERVICE_TARGETS, false);

    /**
    /**
     * Whether to use {@link AppPredictionManager} to query for direct share targets (as opposed to
     * Whether to use {@link AppPredictionManager} to query for direct share targets (as opposed to
     * talking directly to {@link android.content.pm.ShortcutManager}.
     * talking directly to {@link android.content.pm.ShortcutManager}.
+0 −24
Original line number Original line Diff line number Diff line
@@ -2243,12 +2243,6 @@ public class ChooserActivityTest {
                    (chooserListAdapter.getUserHandle().getIdentifier() == 10);
                    (chooserListAdapter.getUserHandle().getIdentifier() == 10);
            return null;
            return null;
        };
        };
        boolean[] isQueryTargetServicesCalledOnWorkProfile = new boolean[] { false };
        sOverrides.onQueryTargetServices = chooserListAdapter -> {
            isQueryTargetServicesCalledOnWorkProfile[0] =
                    (chooserListAdapter.getUserHandle().getIdentifier() == 10);
            return null;
        };
        Intent sendIntent = createSendTextIntent();
        Intent sendIntent = createSendTextIntent();
        sendIntent.setType("TestType");
        sendIntent.setType("TestType");


@@ -2261,8 +2255,6 @@ public class ChooserActivityTest {


        assertFalse("Direct share targets were queried on a paused work profile",
        assertFalse("Direct share targets were queried on a paused work profile",
                isQueryDirectShareCalledOnWorkProfile[0]);
                isQueryDirectShareCalledOnWorkProfile[0]);
        assertFalse("Target services were queried on a paused work profile",
                isQueryTargetServicesCalledOnWorkProfile[0]);
    }
    }


    @Test
    @Test
@@ -2282,12 +2274,6 @@ public class ChooserActivityTest {
                    (chooserListAdapter.getUserHandle().getIdentifier() == 10);
                    (chooserListAdapter.getUserHandle().getIdentifier() == 10);
            return null;
            return null;
        };
        };
        boolean[] isQueryTargetServicesCalledOnWorkProfile = new boolean[] { false };
        sOverrides.onQueryTargetServices = chooserListAdapter -> {
            isQueryTargetServicesCalledOnWorkProfile[0] =
                    (chooserListAdapter.getUserHandle().getIdentifier() == 10);
            return null;
        };
        Intent sendIntent = createSendTextIntent();
        Intent sendIntent = createSendTextIntent();
        sendIntent.setType("TestType");
        sendIntent.setType("TestType");


@@ -2300,8 +2286,6 @@ public class ChooserActivityTest {


        assertFalse("Direct share targets were queried on a locked work profile user",
        assertFalse("Direct share targets were queried on a locked work profile user",
                isQueryDirectShareCalledOnWorkProfile[0]);
                isQueryDirectShareCalledOnWorkProfile[0]);
        assertFalse("Target services were queried on a locked work profile user",
                isQueryTargetServicesCalledOnWorkProfile[0]);
    }
    }


    @Test
    @Test
@@ -2346,12 +2330,6 @@ public class ChooserActivityTest {
                    (chooserListAdapter.getUserHandle().getIdentifier() == 10);
                    (chooserListAdapter.getUserHandle().getIdentifier() == 10);
            return null;
            return null;
        };
        };
        boolean[] isQueryTargetServicesCalledOnWorkProfile = new boolean[] { false };
        sOverrides.onQueryTargetServices = chooserListAdapter -> {
            isQueryTargetServicesCalledOnWorkProfile[0] =
                    (chooserListAdapter.getUserHandle().getIdentifier() == 10);
            return null;
        };
        Intent sendIntent = createSendTextIntent();
        Intent sendIntent = createSendTextIntent();
        sendIntent.setType("TestType");
        sendIntent.setType("TestType");


@@ -2364,8 +2342,6 @@ public class ChooserActivityTest {


        assertFalse("Direct share targets were queried on a locked work profile user",
        assertFalse("Direct share targets were queried on a locked work profile user",
                isQueryDirectShareCalledOnWorkProfile[0]);
                isQueryDirectShareCalledOnWorkProfile[0]);
        assertFalse("Target services were queried on a locked work profile user",
                isQueryTargetServicesCalledOnWorkProfile[0]);
    }
    }


    @Test
    @Test
+0 −10
Original line number Original line Diff line number Diff line
@@ -228,14 +228,6 @@ public class ChooserWrapperActivity extends ChooserActivity {
        super.queryDirectShareTargets(adapter, skipAppPredictionService);
        super.queryDirectShareTargets(adapter, skipAppPredictionService);
    }
    }


    @Override
    protected void queryTargetServices(ChooserListAdapter adapter) {
        if (sOverrides.onQueryTargetServices != null) {
            sOverrides.onQueryTargetServices.apply(adapter);
        }
        super.queryTargetServices(adapter);
    }

    @Override
    @Override
    protected boolean isQuietModeEnabled(UserHandle userHandle) {
    protected boolean isQuietModeEnabled(UserHandle userHandle) {
        return sOverrides.isQuietModeEnabled;
        return sOverrides.isQuietModeEnabled;
@@ -267,7 +259,6 @@ public class ChooserWrapperActivity extends ChooserActivity {
        public Function<PackageManager, PackageManager> createPackageManager;
        public Function<PackageManager, PackageManager> createPackageManager;
        public Function<TargetInfo, Boolean> onSafelyStartCallback;
        public Function<TargetInfo, Boolean> onSafelyStartCallback;
        public Function<ChooserListAdapter, Void> onQueryDirectShareTargets;
        public Function<ChooserListAdapter, Void> onQueryDirectShareTargets;
        public Function<ChooserListAdapter, Void> onQueryTargetServices;
        public ResolverListController resolverListController;
        public ResolverListController resolverListController;
        public ResolverListController workResolverListController;
        public ResolverListController workResolverListController;
        public Boolean isVoiceInteraction;
        public Boolean isVoiceInteraction;
@@ -290,7 +281,6 @@ public class ChooserWrapperActivity extends ChooserActivity {
        public void reset() {
        public void reset() {
            onSafelyStartCallback = null;
            onSafelyStartCallback = null;
            onQueryDirectShareTargets = null;
            onQueryDirectShareTargets = null;
            onQueryTargetServices = null;
            isVoiceInteraction = null;
            isVoiceInteraction = null;
            createPackageManager = null;
            createPackageManager = null;
            previewThumbnail = null;
            previewThumbnail = null;