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

Commit 2faf7a96 authored by Maryam Dehaini's avatar Maryam Dehaini Committed by Android (Google) Code Review
Browse files

Merge "Remove app to web button for browser apps" into main

parents 4cb60d68 c00a3f87
Loading
Loading
Loading
Loading
+46 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 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.
 */

@file:JvmName("AppToWebUtils")

package com.android.wm.shell.apptoweb

import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.net.Uri

private val browserIntent = Intent()
    .setAction(Intent.ACTION_VIEW)
    .addCategory(Intent.CATEGORY_BROWSABLE)
    .setData(Uri.parse("http:"))

/**
 * Returns a boolean indicating whether a given package is a browser app.
 */
fun isBrowserApp(context: Context, packageName: String, userId: Int): Boolean {
    browserIntent.setPackage(packageName)
    val list = context.packageManager.queryIntentActivitiesAsUser(
        browserIntent, PackageManager.MATCH_ALL, userId
    )

    list.forEach {
        if (it.activityInfo != null && it.handleAllWebDataURI) {
            return true
        }
    }
    return false
}
+7 −0
Original line number Diff line number Diff line
@@ -75,6 +75,7 @@ import com.android.wm.shell.R;
import com.android.wm.shell.RootTaskDisplayAreaOrganizer;
import com.android.wm.shell.ShellTaskOrganizer;
import com.android.wm.shell.apptoweb.AppToWebGenericLinksParser;
import com.android.wm.shell.apptoweb.AppToWebUtils;
import com.android.wm.shell.common.DisplayController;
import com.android.wm.shell.common.DisplayLayout;
import com.android.wm.shell.common.MultiInstanceHelper;
@@ -478,6 +479,12 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin

    @Nullable
    private Uri getBrowserLink() {
        // Do not show browser link in browser applications
        final ComponentName baseActivity = mTaskInfo.baseActivity;
        if (baseActivity != null && AppToWebUtils.isBrowserApp(mContext,
                baseActivity.getPackageName(), mUserContext.getUserId())) {
            return null;
        }
        // If the captured link is available and has not expired, return the captured link.
        // Otherwise, return the generic link which is set to null if a generic link is unavailable.
        if (mCapturedLink != null && !mCapturedLink.mExpired) {