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

Commit df634cc0 authored by Matt Pietal's avatar Matt Pietal
Browse files

Sharesheet - Remove pin/unpin actions

The new sharesheet design calls for the removal of
direct share/app pinning and unpinning

Bug: 128521718
Test: atest ChooserActivityTest
Change-Id: I5e89c775d3ce3df31a16310689fc36222ad2a107
parent 01324d87
Loading
Loading
Loading
Loading
+3 −50
Original line number Diff line number Diff line
@@ -42,7 +42,6 @@ import android.content.IntentFilter;
import android.content.IntentSender;
import android.content.IntentSender.SendIntentException;
import android.content.ServiceConnection;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.content.pm.LabeledIntent;
import android.content.pm.LauncherApps;
@@ -65,7 +64,6 @@ import android.metrics.LogMaker;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
@@ -75,7 +73,6 @@ import android.os.RemoteException;
import android.os.ResultReceiver;
import android.os.UserHandle;
import android.os.UserManager;
import android.os.storage.StorageManager;
import android.provider.DocumentsContract;
import android.provider.Downloads;
import android.provider.OpenableColumns;
@@ -114,7 +111,6 @@ import com.android.internal.util.ImageUtils;

import com.google.android.collect.Lists;

import java.io.File;
import java.io.IOException;
import java.lang.annotation.Retention;
import java.util.ArrayList;
@@ -188,10 +184,7 @@ public class ChooserActivity extends ResolverActivity {
    private Drawable mChooserRowLayer;
    private int mChooserRowServiceSpacing;

    private SharedPreferences mPinnedSharedPrefs;
    private static final float PINNED_TARGET_SCORE_BOOST = 1000.f;
    private static final float CALLER_TARGET_SCORE_BOOST = 900.f;
    private static final String PINNED_SHARED_PREFS_NAME = "chooser_pin_settings";
    private static final String TARGET_DETAILS_FRAGMENT_TAG = "targetDetailsFragment";

    private final List<ChooserTargetServiceConnection> mServiceConnections = new ArrayList<>();
@@ -385,7 +378,6 @@ public class ChooserActivity extends ResolverActivity {
            mCallerChooserTargets = targets;
        }

        mPinnedSharedPrefs = getPinnedSharedPrefs(this);
        setRetainInOnStop(intent.getBooleanExtra(EXTRA_PRIVATE_RETAIN_IN_ON_STOP, false));
        super.onCreate(savedInstanceState, target, title, defaultTitleRes, initialIntents,
                null, false);
@@ -817,22 +809,6 @@ public class ChooserActivity extends ResolverActivity {
        return CONTENT_PREVIEW_TEXT;
    }

    static SharedPreferences getPinnedSharedPrefs(Context context) {
        // The code below is because in the android:ui process, no one can hear you scream.
        // The package info in the context isn't initialized in the way it is for normal apps,
        // so the standard, name-based context.getSharedPreferences doesn't work. Instead, we
        // build the path manually below using the same policy that appears in ContextImpl.
        // This fails silently under the hood if there's a problem, so if we find ourselves in
        // the case where we don't have access to credential encrypted storage we just won't
        // have our pinned target info.
        final File prefsFile = new File(new File(
                Environment.getDataUserCePackageDirectory(StorageManager.UUID_PRIVATE_INTERNAL,
                        context.getUserId(), context.getPackageName()),
                "shared_prefs"),
                PINNED_SHARED_PREFS_NAME + ".xml");
        return context.getSharedPreferences(prefsFile, MODE_PRIVATE);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
@@ -928,10 +904,9 @@ public class ChooserActivity extends ResolverActivity {
        }

        ComponentName name = ri.activityInfo.getComponentName();
        boolean pinned = mPinnedSharedPrefs.getBoolean(name.flattenToString(), false);
        ResolverTargetActionsDialogFragment f =
                new ResolverTargetActionsDialogFragment(ri.loadLabel(getPackageManager()),
                        name, pinned);
                        name);
        f.show(getFragmentManager(), TARGET_DETAILS_FRAGMENT_TAG);
    }

@@ -1384,11 +1359,6 @@ public class ChooserActivity extends ResolverActivity {
            super(context, pm, targetIntent, referrerPackageName, launchedFromUid);
        }

        @Override
        boolean isComponentPinned(ComponentName name) {
            return mPinnedSharedPrefs.getBoolean(name.flattenToString(), false);
        }

        @Override
        boolean isComponentFiltered(ComponentName name) {
            if (mFilteredComponentNames == null) {
@@ -1407,11 +1377,8 @@ public class ChooserActivity extends ResolverActivity {
            if (target == null) {
                return CALLER_TARGET_SCORE_BOOST;
            }
            float score = super.getScore(target);
            if (target.isPinned()) {
                score += PINNED_TARGET_SCORE_BOOST;
            }
            return score;

            return super.getScore(target);
        }
    }

@@ -1508,10 +1475,6 @@ public class ChooserActivity extends ResolverActivity {
            return null;
        }

        public boolean isPinned() {
            return false;
        }

        public float getModifiedScore() {
            return 0.1f;
        }
@@ -1742,11 +1705,6 @@ public class ChooserActivity extends ResolverActivity {
            }
            return results;
        }

        @Override
        public boolean isPinned() {
            return mSourceInfo != null ? mSourceInfo.isPinned() : false;
        }
    }

    private void handleScroll(View view, int x, int y, int oldx, int oldy) {
@@ -1854,11 +1812,6 @@ public class ChooserActivity extends ResolverActivity {
            return false;
        }

        @Override
        public boolean isComponentPinned(ComponentName name) {
            return mPinnedSharedPrefs.getBoolean(name.flattenToString(), false);
        }

        @Override
        public View onCreateView(ViewGroup parent) {
            return mInflater.inflate(
+0 −30
Original line number Diff line number Diff line
@@ -1177,7 +1177,6 @@ public class ResolverActivity extends Activity {
        private final CharSequence mExtendedInfo;
        private final Intent mResolvedIntent;
        private final List<Intent> mSourceIntents = new ArrayList<>();
        private boolean mPinned;

        public DisplayResolveInfo(Intent originalIntent, ResolveInfo pri, CharSequence pLabel,
                CharSequence pInfo, Intent pOrigIntent) {
@@ -1204,7 +1203,6 @@ public class ResolverActivity extends Activity {
            mExtendedInfo = other.mExtendedInfo;
            mResolvedIntent = new Intent(other.mResolvedIntent);
            mResolvedIntent.fillIn(fillInIntent, flags);
            mPinned = other.mPinned;
        }

        public ResolveInfo getResolveInfo() {
@@ -1304,15 +1302,6 @@ public class ResolverActivity extends Activity {
            activity.startActivityAsUser(mResolvedIntent, options, user);
            return false;
        }

        @Override
        public boolean isPinned() {
            return mPinned;
        }

        public void setPinned(boolean pinned) {
            mPinned = pinned;
        }
    }

    /**
@@ -1414,11 +1403,6 @@ public class ResolverActivity extends Activity {
         * @return the list of supported source intents deduped against this single target
         */
        List<Intent> getAllSourceIntents();

        /**
         * @return true if this target should be pinned to the front by the request of the user
         */
        boolean isPinned();
    }

    public class ResolveListAdapter extends BaseAdapter {
@@ -1776,7 +1760,6 @@ public class ResolverActivity extends Activity {
            final Intent replaceIntent = getReplacementIntent(add.activityInfo, intent);
            final DisplayResolveInfo dri = new DisplayResolveInfo(intent, add, roLabel,
                    extraInfo, replaceIntent);
            dri.setPinned(rci.isPinned());
            addResolveInfo(dri);
            if (replaceIntent == intent) {
                // Only add alternates if we didn't get a specific replacement from
@@ -1921,10 +1904,6 @@ public class ResolverActivity extends Activity {
            return !TextUtils.isEmpty(info.getExtendedInfo());
        }

        public boolean isComponentPinned(ComponentName name) {
            return false;
        }

        public final void bindView(int position, View view) {
            onBindView(view, getItem(position));
        }
@@ -1967,7 +1946,6 @@ public class ResolverActivity extends Activity {
    @VisibleForTesting
    public static final class ResolvedComponentInfo {
        public final ComponentName name;
        private boolean mPinned;
        private final List<Intent> mIntents = new ArrayList<>();
        private final List<ResolveInfo> mResolveInfos = new ArrayList<>();

@@ -2010,14 +1988,6 @@ public class ResolverActivity extends Activity {
            }
            return -1;
        }

        public boolean isPinned() {
            return mPinned;
        }

        public void setPinned(boolean pinned) {
            mPinned = pinned;
        }
    }

    static class ViewHolder {
+10 −22
Original line number Diff line number Diff line
@@ -325,17 +325,6 @@ class ResolverComparator implements Comparator<ResolvedComponentInfo> {
            }
        }

        final boolean lPinned = lhsp.isPinned();
        final boolean rPinned = rhsp.isPinned();

        if (lPinned && !rPinned) {
            return -1;
        } else if (!lPinned && rPinned) {
            return 1;
        }

        // Pinned items stay stable within a normal lexical sort and ignore scoring.
        if (!lPinned && !rPinned) {
        if (mStats != null) {
            final ResolverTarget lhsTarget = mTargetsDict.get(new ComponentName(
                    lhs.activityInfo.packageName, lhs.activityInfo.name));
@@ -351,7 +340,6 @@ class ResolverComparator implements Comparator<ResolvedComponentInfo> {
                }
            }
        }
        }

        CharSequence  sa = lhs.loadLabel(mPm);
        if (sa == null) sa = lhs.activityInfo.name;
+2 −8
Original line number Diff line number Diff line
@@ -30,14 +30,13 @@ import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.RemoteException;
import android.util.Log;
import com.android.internal.annotations.GuardedBy;

import com.android.internal.annotations.VisibleForTesting;

import java.lang.InterruptedException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.concurrent.CountDownLatch;
import java.util.List;
import java.util.concurrent.CountDownLatch;

/**
 * A helper for the ResolverActivity that exposes methods to retrieve, filter and sort its list of
@@ -147,7 +146,6 @@ public class ResolverListController {
                        newInfo.activityInfo.packageName, newInfo.activityInfo.name);
                final ResolverActivity.ResolvedComponentInfo rci =
                        new ResolverActivity.ResolvedComponentInfo(name, intent, newInfo);
                rci.setPinned(isComponentPinned(name));
                into.add(rci);
            }
        }
@@ -270,10 +268,6 @@ public class ResolverListController {
                && ai.name.equals(b.name.getClassName());
    }

    boolean isComponentPinned(ComponentName name) {
        return false;
    }

    boolean isComponentFiltered(ComponentName componentName) {
        return false;
    }
+3 −24
Original line number Diff line number Diff line
@@ -23,7 +23,6 @@ import android.app.DialogFragment;
import android.content.ComponentName;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Settings;
@@ -36,34 +35,27 @@ import com.android.internal.R;
public class ResolverTargetActionsDialogFragment extends DialogFragment
        implements DialogInterface.OnClickListener {
    private static final String NAME_KEY = "componentName";
    private static final String PINNED_KEY = "pinned";
    private static final String TITLE_KEY = "title";

    // Sync with R.array.resolver_target_actions_* resources
    private static final int TOGGLE_PIN_INDEX = 0;
    private static final int APP_INFO_INDEX = 1;
    private static final int APP_INFO_INDEX = 0;

    public ResolverTargetActionsDialogFragment() {
    }

    public ResolverTargetActionsDialogFragment(CharSequence title, ComponentName name,
            boolean pinned) {
    public ResolverTargetActionsDialogFragment(CharSequence title, ComponentName name) {
        Bundle args = new Bundle();
        args.putCharSequence(TITLE_KEY, title);
        args.putParcelable(NAME_KEY, name);
        args.putBoolean(PINNED_KEY, pinned);
        setArguments(args);
    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        final Bundle args = getArguments();
        final int itemRes = args.getBoolean(PINNED_KEY, false)
                ? R.array.resolver_target_actions_unpin
                : R.array.resolver_target_actions_pin;
        return new Builder(getContext())
                .setCancelable(true)
                .setItems(itemRes, this)
                .setItems(R.array.resolver_target_actions, this)
                .setTitle(args.getCharSequence(TITLE_KEY))
                .create();
    }
@@ -73,19 +65,6 @@ public class ResolverTargetActionsDialogFragment extends DialogFragment
        final Bundle args = getArguments();
        ComponentName name = args.getParcelable(NAME_KEY);
        switch (which) {
            case TOGGLE_PIN_INDEX:
                SharedPreferences sp = ChooserActivity.getPinnedSharedPrefs(getContext());
                final String key = name.flattenToString();
                boolean currentVal = sp.getBoolean(name.flattenToString(), false);
                if (currentVal) {
                    sp.edit().remove(key).apply();
                } else {
                    sp.edit().putBoolean(key, true).apply();
                }

                // Force the chooser to requery and resort things
                getActivity().recreate();
                break;
            case APP_INFO_INDEX:
                Intent in = new Intent().setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
                        .setData(Uri.fromParts("package", name.getPackageName(), null))
Loading