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

Commit b9e8a8ec authored by Kelvin Kwan's avatar Kelvin Kwan Committed by Android (Google) Code Review
Browse files

Merge "startActivity with proper user and uri according to the attached userId"

parents c085688e a34bbd91
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -264,7 +264,7 @@ public abstract class AbstractActionHandler<T extends FragmentActivity & CommonA
    }

    @Override
    public void showAppDetails(ResolveInfo info) {
    public void showAppDetails(ResolveInfo info, UserId userId) {
        throw new UnsupportedOperationException("Can't show app details.");
    }

@@ -455,7 +455,7 @@ public abstract class AbstractActionHandler<T extends FragmentActivity & CommonA
        }

        try {
            mActivity.startActivity(intent);
            doc.userId.startActivityAsUser(mActivity, intent);
            return true;
        } catch (ActivityNotFoundException e) {
            mDialogs.showNoApplicationFound();
@@ -479,7 +479,7 @@ public abstract class AbstractActionHandler<T extends FragmentActivity & CommonA
        if (intent != null) {
            // TODO: un-work around issue b/24963914. Should be fixed soon.
            try {
                mActivity.startActivity(intent);
                doc.userId.startActivityAsUser(mActivity, intent);
                return true;
            } catch (SecurityException e) {
                // Carry on to regular view mode.
@@ -498,7 +498,7 @@ public abstract class AbstractActionHandler<T extends FragmentActivity & CommonA
            Intent manage = new Intent(DocumentsContract.ACTION_MANAGE_DOCUMENT);
            manage.setData(doc.derivedUri);
            try {
                mActivity.startActivity(manage);
                doc.userId.startActivityAsUser(mActivity, manage);
                return true;
            } catch (ActivityNotFoundException ex) {
                // Fall back to regular handling.
+2 −1
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import com.android.documentsui.base.BooleanConsumer;
import com.android.documentsui.base.DocumentInfo;
import com.android.documentsui.base.DocumentStack;
import com.android.documentsui.base.RootInfo;
import com.android.documentsui.base.UserId;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -88,7 +89,7 @@ public interface ActionHandler {
     */
    void startAuthentication(PendingIntent intent);

    void showAppDetails(ResolveInfo info);
    void showAppDetails(ResolveInfo info, UserId userId);

    void openRoot(RootInfo root);

+4 −1
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import android.os.UserManager;
import android.util.Log;

import androidx.annotation.GuardedBy;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import androidx.core.os.BuildCompat;

@@ -55,12 +56,14 @@ public interface UserIdManager {
     * Returns the system user from {@link #getUserIds()} if the list at least 2 users. Otherwise,
     * returns null.
     */
    @Nullable
    UserId getSystemUser();

    /**
     * Returns the managed user from {@link #getUserIds()} if the list at least 2 users. Otherwise,
     * returns null.
     */
    @Nullable
    UserId getManagedUser();

    /**
@@ -148,7 +151,7 @@ public interface UserIdManager {
            return mManagedUser;
        }

        public List<UserId> getUserIdsInternal() {
        private List<UserId> getUserIdsInternal() {
            final List<UserId> result = new ArrayList<>();
            result.add(mCurrentUser);

+12 −0
Original line number Diff line number Diff line
@@ -325,6 +325,18 @@ public class DocumentInfo implements Durable, Parcelable {
        return (flags & Document.FLAG_DIR_PREFERS_LAST_MODIFIED) != 0;
    }

    /**
     * Returns a document uri representing this {@link DocumentInfo}. The URI contains user
     * information. Use this when uri is needed externally. For usage within DocsUI, use
     * {@link #derivedUri}.
     */
    public Uri getDocumentUri() {
        if (UserId.CURRENT_USER.equals(userId)) {
            return derivedUri;
        }
        return userId.buildDocumentUriAsUser(authority, documentId);
    }

    @Override
    public int hashCode() {
        return userId.hashCode() + derivedUri.hashCode() + mimeType.hashCode();
+16 −0
Original line number Diff line number Diff line
@@ -20,11 +20,13 @@ import static androidx.core.util.Preconditions.checkNotNull;

import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Process;
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.DocumentsContract;

import androidx.annotation.VisibleForTesting;
import androidx.loader.content.CursorLoader;
@@ -118,6 +120,20 @@ public final class UserId {
        return userManager.isManagedProfile(mUserHandle.getIdentifier());
    }

    /**
     * Returns a document uri representing this user.
     */
    public Uri buildDocumentUriAsUser(String authority, String documentId) {
        return DocumentsContract.buildDocumentUriAsUser(authority, documentId, mUserHandle);
    }

    /**
     * Starts activity for this user
     */
    public void startActivityAsUser(Context context, Intent intent) {
        context.startActivityAsUser(intent, mUserHandle);
    }

    /**
     * Returns an identifier stored in this user id. This can be used to recreate the {@link UserId}
     * by {@link UserId#of(int)}.
Loading