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

Commit 59a42130 authored by Automerger Merge Worker's avatar Automerger Merge Worker
Browse files

Merge "Use ResolveInfo#isCrossProfileIntentForwarderActivity in DocsUI" into...

Merge "Use ResolveInfo#isCrossProfileIntentForwarderActivity in DocsUI" into rvc-dev am: 5bc44936 am: db79d740

Change-Id: I9cf58e43757a2afc90da6f65ff37e52917a2dbc9
parents 4e4bbbea db79d740
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -26,7 +26,6 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.UserHandle;
import android.os.UserManager;
import android.util.Log;
@@ -37,6 +36,7 @@ import androidx.annotation.VisibleForTesting;

import com.android.documentsui.base.Features;
import com.android.documentsui.base.UserId;
import com.android.documentsui.util.VersionUtils;

import java.util.ArrayList;
import java.util.List;
@@ -213,8 +213,7 @@ public interface UserIdManager {
        private static boolean isDeviceSupported(Context context) {
            // The feature requires Android R DocumentsContract APIs and INTERACT_ACROSS_USERS
            // permission.
            return (Build.VERSION.CODENAME.equals("R")
                    || (Build.VERSION.CODENAME.equals("REL") && Build.VERSION.SDK_INT >= 30))
            return VersionUtils.isAtLeastR()
                    && context.checkSelfPermission(Manifest.permission.INTERACT_ACROSS_USERS)
                    == PackageManager.PERMISSION_GRANTED;
        }
+2 −2
Original line number Diff line number Diff line
@@ -65,6 +65,7 @@ import com.android.documentsui.services.FileOperationService;
import com.android.documentsui.sidebar.RootsFragment;
import com.android.documentsui.ui.DialogController;
import com.android.documentsui.ui.MessageBuilder;
import com.android.documentsui.util.CrossProfileUtils;

import java.util.Collection;
import java.util.Collections;
@@ -215,8 +216,7 @@ public class PickActivity extends BaseActivity implements ActionHandler.Addons {
            moreApps.setPackage(null);
            for (ResolveInfo info : getPackageManager().queryIntentActivities(moreApps,
                    PackageManager.MATCH_DEFAULT_ONLY)) {
                if (RootsFragment.PROFILE_TARGET_ACTIVITY.equals(
                        info.activityInfo.targetActivity)) {
                if (CrossProfileUtils.isCrossProfileIntentForwarderActivity(info)) {
                    mState.canShareAcrossProfile = true;
                    break;
                }
+2 −3
Original line number Diff line number Diff line
@@ -75,6 +75,7 @@ import com.android.documentsui.base.UserId;
import com.android.documentsui.roots.ProvidersAccess;
import com.android.documentsui.roots.ProvidersCache;
import com.android.documentsui.roots.RootsLoader;
import com.android.documentsui.util.CrossProfileUtils;

import java.util.ArrayList;
import java.util.Collection;
@@ -92,8 +93,6 @@ public class RootsFragment extends Fragment {

    private static final String TAG = "RootsFragment";
    private static final String EXTRA_INCLUDE_APPS = "includeApps";
    public static final String PROFILE_TARGET_ACTIVITY =
            "com.android.internal.app.IntentForwarderActivity";
    private static final int CONTEXT_MENU_ITEM_TIMEOUT = 500;

    private final OnItemClickListener mItemListener = new OnItemClickListener() {
@@ -399,7 +398,7 @@ public class RootsFragment extends Fragment {
                    appsMapping.put(userPackage, info);

                    // for change personal profile root.
                    if (PROFILE_TARGET_ACTIVITY.equals(info.activityInfo.targetActivity)) {
                    if (CrossProfileUtils.isCrossProfileIntentForwarderActivity(info)) {
                        if (UserId.CURRENT_USER.equals(userId)) {
                            profileItem = new ProfileItem(info, info.loadLabel(pm).toString(),
                                    mActionHandler);
+43 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.documentsui.util;

import android.content.pm.ResolveInfo;

/**
 * A utility class for cross-profile usage.
 */
public class CrossProfileUtils {
    private static final String PROFILE_TARGET_ACTIVITY =
            "com.android.internal.app.IntentForwarderActivity";

    private CrossProfileUtils() {
    }

    /**
     * Returns whether this resolution represents the intent forwarder activity.
     */
    public static boolean isCrossProfileIntentForwarderActivity(ResolveInfo info) {
        if (VersionUtils.isAtLeastR()) {
            return info.isCrossProfileIntentForwarderActivity();
        }
        if (info.activityInfo != null) {
            return PROFILE_TARGET_ACTIVITY.equals(info.activityInfo.targetActivity);
        }
        return false;
    }
}
+36 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.documentsui.util;

import android.os.Build;

/**
 * A utility class for checking Android version.
 */
public class VersionUtils {

    private VersionUtils() {
    }

    /**
     * Returns whether the device is running on the Android R or newer.
     */
    public static boolean isAtLeastR() {
        return Build.VERSION.CODENAME.equals("R")
                || (Build.VERSION.CODENAME.equals("REL") && Build.VERSION.SDK_INT >= 30);
    }
}
Loading