导航菜单

页面标题

页面副标题

Life Church v15.20.21 - InternalCustomTabsActivitiesHelper.java 源代码

正在查看: Life Church v15.20.21 应用的 InternalCustomTabsActivitiesHelper.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package expo.modules.webbrowser;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import androidx.browser.customtabs.CustomTabsClient;
import androidx.browser.customtabs.CustomTabsIntent;
import expo.modules.core.ModuleRegistry;
import expo.modules.core.errors.CurrentActivityNotFoundException;
import expo.modules.core.interfaces.ActivityProvider;
import expo.modules.core.interfaces.Function;
import expo.modules.webbrowser.error.PackageManagerNotFoundException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;

class InternalCustomTabsActivitiesHelper implements CustomTabsActivitiesHelper {
    private static final String DUMMY_URL = "https://expo.io";
    private ModuleRegistry mModuleRegistry;

    @Override
    public void onDestroy() {
    }

    InternalCustomTabsActivitiesHelper() {
    }

    public static <T, R> ArrayList<R> mapCollectionToDistinctArrayList(Collection<? extends T> collection, Function<T, R> function) {
        LinkedHashSet linkedHashSet = new LinkedHashSet();
        Iterator<? extends T> it = collection.iterator();
        while (it.hasNext()) {
            linkedHashSet.add(function.apply(it.next()));
        }
        return new ArrayList<>(linkedHashSet);
    }

    @Override
    public void onCreate(ModuleRegistry moduleRegistry) {
        this.mModuleRegistry = moduleRegistry;
    }

    @Override
    public ArrayList<String> getCustomTabsResolvingActivities() throws PackageManagerNotFoundException, CurrentActivityNotFoundException {
        return mapCollectionToDistinctArrayList(getResolvingActivities(createDefaultCustomTabsIntent()), new Function() {
            @Override
            public final Object apply(Object obj) {
                String str;
                str = ((ResolveInfo) obj).activityInfo.packageName;
                return str;
            }
        });
    }

    @Override
    public ArrayList<String> getCustomTabsResolvingServices() throws PackageManagerNotFoundException, CurrentActivityNotFoundException {
        return mapCollectionToDistinctArrayList(getPackageManager().queryIntentServices(createDefaultCustomTabsServiceIntent(), 0), new Function() {
            @Override
            public final Object apply(Object obj) {
                String str;
                str = ((ResolveInfo) obj).serviceInfo.packageName;
                return str;
            }
        });
    }

    @Override
    public String getPreferredCustomTabsResolvingActivity(List<String> list) throws PackageManagerNotFoundException, CurrentActivityNotFoundException {
        if (list == null) {
            list = getCustomTabsResolvingActivities();
        }
        return CustomTabsClient.getPackageName(getCurrentActivity(), list);
    }

    @Override
    public String getDefaultCustomTabsResolvingActivity() throws PackageManagerNotFoundException, CurrentActivityNotFoundException {
        ResolveInfo resolveActivity = getPackageManager().resolveActivity(createDefaultCustomTabsIntent(), 0);
        if (resolveActivity == null) {
            return null;
        }
        return resolveActivity.activityInfo.packageName;
    }

    @Override
    public boolean canResolveIntent(Intent intent) throws PackageManagerNotFoundException, CurrentActivityNotFoundException {
        return getResolvingActivities(intent).size() > 0;
    }

    @Override
    public void startCustomTabs(Intent intent) throws CurrentActivityNotFoundException {
        getCurrentActivity().startActivity(intent);
    }

    private List<ResolveInfo> getResolvingActivities(Intent intent) throws PackageManagerNotFoundException, CurrentActivityNotFoundException {
        return getPackageManager().queryIntentActivities(intent, 0);
    }

    private PackageManager getPackageManager() throws PackageManagerNotFoundException, CurrentActivityNotFoundException {
        PackageManager packageManager = getCurrentActivity().getPackageManager();
        if (packageManager != null) {
            return packageManager;
        }
        throw new PackageManagerNotFoundException();
    }

    private Activity getCurrentActivity() throws CurrentActivityNotFoundException {
        ActivityProvider activityProvider = (ActivityProvider) this.mModuleRegistry.getModule(ActivityProvider.class);
        if (activityProvider == null || activityProvider.getCurrentActivity() == null) {
            throw new CurrentActivityNotFoundException();
        }
        return activityProvider.getCurrentActivity();
    }

    private Intent createDefaultCustomTabsIntent() {
        Intent intent = new CustomTabsIntent.Builder().build().intent;
        intent.setData(Uri.parse(DUMMY_URL));
        return intent;
    }

    private Intent createDefaultCustomTabsServiceIntent() {
        Intent intent = new Intent();
        intent.setAction("android.support.customtabs.action.CustomTabsService");
        return intent;
    }

    @Override
    public List<? extends Class> getExportedInterfaces() {
        return Collections.singletonList(CustomTabsActivitiesHelper.class);
    }
}