导航菜单

页面标题

页面副标题

Clash Legends v0.0.1 - CustomTabMainActivity.java 源代码

正在查看: Clash Legends v0.0.1 应用的 CustomTabMainActivity.java JAVA 源代码文件

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


package com.facebook;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.Uri;
import android.os.Bundle;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import com.facebook.internal.CustomTab;
import com.facebook.internal.NativeProtocol;
import com.facebook.internal.Utility;

public class CustomTabMainActivity extends Activity {
    private BroadcastReceiver redirectReceiver;
    private boolean shouldCloseCustomTab = true;
    public static final String EXTRA_ACTION = CustomTabMainActivity.class.getSimpleName() + ".extra_action";
    public static final String EXTRA_PARAMS = CustomTabMainActivity.class.getSimpleName() + ".extra_params";
    public static final String EXTRA_CHROME_PACKAGE = CustomTabMainActivity.class.getSimpleName() + ".extra_chromePackage";
    public static final String EXTRA_URL = CustomTabMainActivity.class.getSimpleName() + ".extra_url";
    public static final String REFRESH_ACTION = CustomTabMainActivity.class.getSimpleName() + ".action_refresh";
    public static final String NO_ACTIVITY_EXCEPTION = CustomTabMainActivity.class.getSimpleName() + ".no_activity_exception";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (CustomTabActivity.CUSTOM_TAB_REDIRECT_ACTION.equals(getIntent().getAction())) {
            setResult(0);
            finish();
            return;
        }
        if (savedInstanceState == null) {
            String action = getIntent().getStringExtra(EXTRA_ACTION);
            Bundle parameters = getIntent().getBundleExtra(EXTRA_PARAMS);
            String chromePackage = getIntent().getStringExtra(EXTRA_CHROME_PACKAGE);
            CustomTab customTab = new CustomTab(action, parameters);
            boolean couldOpenCustomTab = customTab.openCustomTab(this, chromePackage);
            this.shouldCloseCustomTab = false;
            if (!couldOpenCustomTab) {
                setResult(0, getIntent().putExtra(NO_ACTIVITY_EXCEPTION, true));
                finish();
            } else {
                this.redirectReceiver = new BroadcastReceiver() {
                    @Override
                    public void onReceive(Context context, Intent intent) {
                        Intent newIntent = new Intent(CustomTabMainActivity.this, (Class<?>) CustomTabMainActivity.class);
                        newIntent.setAction(CustomTabMainActivity.REFRESH_ACTION);
                        newIntent.putExtra(CustomTabMainActivity.EXTRA_URL, intent.getStringExtra(CustomTabMainActivity.EXTRA_URL));
                        newIntent.addFlags(603979776);
                        CustomTabMainActivity.this.startActivity(newIntent);
                    }
                };
                LocalBroadcastManager.getInstance(this).registerReceiver(this.redirectReceiver, new IntentFilter(CustomTabActivity.CUSTOM_TAB_REDIRECT_ACTION));
            }
        }
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        if (REFRESH_ACTION.equals(intent.getAction())) {
            Intent broadcast = new Intent(CustomTabActivity.DESTROY_ACTION);
            LocalBroadcastManager.getInstance(this).sendBroadcast(broadcast);
            sendResult(-1, intent);
        } else if (CustomTabActivity.CUSTOM_TAB_REDIRECT_ACTION.equals(intent.getAction())) {
            sendResult(-1, intent);
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        if (this.shouldCloseCustomTab) {
            sendResult(0, null);
        }
        this.shouldCloseCustomTab = true;
    }

    private void sendResult(int resultCode, Intent resultIntent) {
        LocalBroadcastManager.getInstance(this).unregisterReceiver(this.redirectReceiver);
        if (resultIntent == null) {
            setResult(resultCode, NativeProtocol.createProtocolResultIntent(getIntent(), null, null));
        } else {
            String responseURL = resultIntent.getStringExtra(EXTRA_URL);
            Bundle results = responseURL != null ? parseResponseUri(responseURL) : new Bundle();
            Intent nativeProtocolResultIntent = NativeProtocol.createProtocolResultIntent(getIntent(), results, null);
            setResult(resultCode, nativeProtocolResultIntent != null ? nativeProtocolResultIntent : resultIntent);
        }
        finish();
    }

    private static Bundle parseResponseUri(String urlString) {
        Uri u = Uri.parse(urlString);
        Bundle b = Utility.parseUrlQueryString(u.getQuery());
        b.putAll(Utility.parseUrlQueryString(u.getFragment()));
        return b;
    }
}