导航菜单

页面标题

页面副标题

Vi App v10.18.0 - VIUPIIntentWebView.java 源代码

正在查看: Vi App v10.18.0 应用的 VIUPIIntentWebView.java JAVA 源代码文件

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


package com.mventus.selfcare.activity.viweb;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.content.IntentSender;
import android.graphics.Bitmap;
import android.location.LocationManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.webkit.GeolocationPermissions;
import android.webkit.WebChromeClient;
import android.webkit.WebResourceError;
import android.webkit.WebResourceRequest;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;
import android.widget.Toast;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import com.google.android.gms.common.api.ApiException;
import com.google.android.gms.location.FusedLocationProviderClient;
import com.google.android.gms.location.LocationRequest;
import com.google.android.gms.location.LocationServices;
import com.google.android.gms.location.LocationSettingsRequest;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.mventus.selfcare.activity.R;
import com.viapps.viappwebview.NetworkUtil;
import in.juspay.hyper.webview.upi.HyperWebViewServices;
import kotlin.Deprecated;
import kotlin.jvm.internal.DefaultConstructorMarker;
import kotlin.jvm.internal.Intrinsics;
import kotlin.text.StringsKt;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public final class VIUPIIntentWebView extends AppCompatActivity {

    @NotNull
    public static final Companion Companion = new Companion(null);

    @Nullable
    private View errorView;
    private boolean fromNeoDeeplinkb;

    @Nullable
    private FusedLocationProviderClient fusedLocationClient;

    @Nullable
    private HyperWebViewServices hyperWebViewServices;
    private boolean isWebViewDestroyed;

    @Nullable
    private ProgressBar viProgressBar;

    @Nullable
    private WebView viWebView;

    @Nullable
    private GeolocationPermissions.Callback wcallback;

    @Nullable
    private String webviewUrl;

    @Nullable
    private String worigin;

    public static final class Companion {
        private Companion() {
        }

        public Companion(DefaultConstructorMarker defaultConstructorMarker) {
            this();
        }
    }

    public final class WebAppInterface {

        @NotNull
        private Context mContext;
        public final VIUPIIntentWebView this$0;

        public WebAppInterface(@NotNull VIUPIIntentWebView vIUPIIntentWebView, Context context) {
            Intrinsics.checkNotNullParameter(context, "mContext");
            this.this$0 = vIUPIIntentWebView;
            this.mContext = context;
        }
    }

    public final void checkLocationEnabled(String str, GeolocationPermissions.Callback callback) {
        Object systemService = getSystemService("location");
        Intrinsics.checkNotNull(systemService, "null cannot be cast to non-null type android.location.LocationManager");
        LocationManager locationManager = (LocationManager) systemService;
        if (locationManager.isProviderEnabled("gps") || locationManager.isProviderEnabled("network")) {
            Intrinsics.checkNotNull(callback);
            callback.invoke(str, true, false);
        } else {
            this.wcallback = callback;
            this.worigin = str;
            requestGPSSettings();
        }
    }

    public final void handleBackPressed() {
        WebView webView = this.viWebView;
        if (webView != null) {
            Intrinsics.checkNotNull(webView);
            if (webView.isFocused()) {
                WebView webView2 = this.viWebView;
                Intrinsics.checkNotNull(webView2);
                if (webView2.canGoBack()) {
                    WebView webView3 = this.viWebView;
                    Intrinsics.checkNotNull(webView3);
                    webView3.goBack();
                    return;
                }
            }
        }
        if (this.fromNeoDeeplinkb) {
            WebView webView4 = this.viWebView;
            if (webView4 != null) {
                Intrinsics.checkNotNull(webView4);
                webView4.destroy();
            }
            super/*androidx.activity.ComponentActivity*/.onBackPressed();
            Intent intent = new Intent();
            intent.putExtra("message", "fromdeeplink");
            setResult(-1, intent);
            finish();
            return;
        }
        WebView webView5 = this.viWebView;
        if (webView5 != null) {
            Intrinsics.checkNotNull(webView5);
            webView5.destroy();
        }
        super/*androidx.activity.ComponentActivity*/.onBackPressed();
        Intent intent2 = new Intent();
        intent2.putExtra("message", "false");
        setResult(-1, intent2);
        finish();
    }

    private final void requestGPSSettings() {
        LocationRequest build = new LocationRequest.Builder(102, 2000L).setMinUpdateIntervalMillis(500L).build();
        Intrinsics.checkNotNullExpressionValue(build, "build(...)");
        LocationSettingsRequest.Builder addLocationRequest = new LocationSettingsRequest.Builder().addLocationRequest(build);
        Intrinsics.checkNotNullExpressionValue(addLocationRequest, "addLocationRequest(...)");
        addLocationRequest.setAlwaysShow(true);
        Task checkLocationSettings = LocationServices.getSettingsClient(this).checkLocationSettings(addLocationRequest.build());
        Intrinsics.checkNotNullExpressionValue(checkLocationSettings, "checkLocationSettings(...)");
        checkLocationSettings.addOnCompleteListener(new OnCompleteListener() {
            public final void onComplete(Task task) {
                VIUPIIntentWebView.requestGPSSettings$lambda$2(VIUPIIntentWebView.this, task);
            }
        });
    }

    public static final void requestGPSSettings$lambda$2(VIUPIIntentWebView vIUPIIntentWebView, Task task) {
        Intrinsics.checkNotNullParameter(vIUPIIntentWebView, "this$0");
        Intrinsics.checkNotNullParameter(task, "task");
        try {
            task.getResult(ApiException.class);
            Toast.makeText(vIUPIIntentWebView.getApplication(), "GPS is already enabled", 0).show();
        } catch (ApiException e) {
            int statusCode = e.getStatusCode();
            if (statusCode != 6) {
                if (statusCode != 8502) {
                    return;
                }
                Toast.makeText(vIUPIIntentWebView.getApplication(), "Location settings are inadequate, and cannot be fixed here", 0).show();
            } else {
                try {
                    Intrinsics.checkNotNull(e, "null cannot be cast to non-null type com.google.android.gms.common.api.ResolvableApiException");
                    e.startResolutionForResult(vIUPIIntentWebView, 2);
                } catch (IntentSender.SendIntentException unused) {
                }
            }
        }
    }

    @SuppressLint({"LogNotTimber"})
    private final void safelyDestroyWebView(final WebView webView) {
        if (this.isWebViewDestroyed) {
            return;
        }
        if (webView != null) {
            webView.loadUrl("about:blank");
        }
        ViewParent parent = webView != null ? webView.getParent() : null;
        ViewGroup viewGroup = parent instanceof ViewGroup ? (ViewGroup) parent : null;
        if (viewGroup != null) {
            viewGroup.removeView(webView);
        }
        new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
            @Override
            public final void run() {
                VIUPIIntentWebView.safelyDestroyWebView$lambda$3(webView, this);
            }
        }, 300L);
    }

    public static final void safelyDestroyWebView$lambda$3(WebView webView, VIUPIIntentWebView vIUPIIntentWebView) {
        Intrinsics.checkNotNullParameter(vIUPIIntentWebView, "this$0");
        if (webView != null) {
            try {
                webView.removeAllViews();
            } catch (Exception unused) {
                return;
            }
        }
        if (webView != null) {
            webView.clearHistory();
        }
        if (webView != null) {
            webView.clearCache(true);
        }
        if (webView != null) {
            webView.destroy();
        }
        vIUPIIntentWebView.isWebViewDestroyed = true;
    }

    @Nullable
    public final ProgressBar getViProgressBar() {
        return this.viProgressBar;
    }

    @Nullable
    public final WebView getViWebView() {
        return this.viWebView;
    }

    @Deprecated(message = "Deprecated in Java")
    public void onActivityResult(int i, int i2, @Nullable Intent intent) {
        HyperWebViewServices hyperWebViewServices;
        super/*androidx.fragment.app.FragmentActivity*/.onActivityResult(i, i2, intent);
        if (i == 2) {
            checkLocationEnabled(this.worigin, this.wcallback);
        } else if (i == 19 && (hyperWebViewServices = this.hyperWebViewServices) != null) {
            hyperWebViewServices.onActivityResult(i, i2, intent);
        }
        if (i == 2) {
            if (i2 != -1) {
                GeolocationPermissions.Callback callback = this.wcallback;
                if (callback != null) {
                    callback.invoke(this.worigin, false, false);
                    return;
                }
                return;
            }
            Object systemService = getSystemService("location");
            Intrinsics.checkNotNull(systemService, "null cannot be cast to non-null type android.location.LocationManager");
            LocationManager locationManager = (LocationManager) systemService;
            if (locationManager.isProviderEnabled("gps") || locationManager.isProviderEnabled("network")) {
                GeolocationPermissions.Callback callback2 = this.wcallback;
                if (callback2 != null) {
                    callback2.invoke(this.worigin, true, false);
                    return;
                }
                return;
            }
            Toast.makeText((Context) this, (CharSequence) "Location is still not enabled. Please enable it manually.", 0).show();
            GeolocationPermissions.Callback callback3 = this.wcallback;
            if (callback3 != null) {
                callback3.invoke(this.worigin, false, false);
            }
        }
    }

    @Deprecated(message = "Deprecated in Java")
    @SuppressLint({"MissingSuperCall"})
    public void onBackPressed() {
        handleBackPressed();
    }

    @SuppressLint({"SetJavaScriptEnabled", "JavascriptInterface"})
    public void onCreate(@Nullable Bundle bundle) {
        String str;
        super/*androidx.fragment.app.FragmentActivity*/.onCreate(bundle);
        requestWindowFeature(1);
        setContentView(R.layout.activity_vi_onmobile_webview);
        View findViewById = findViewById(R.id.vi_native_webView);
        Intrinsics.checkNotNull(findViewById, "null cannot be cast to non-null type android.webkit.WebView");
        this.viWebView = (WebView) findViewById;
        this.errorView = findViewById(R.id.errorView);
        NetworkUtil networkUtil = new NetworkUtil(this);
        WebView webView = this.viWebView;
        Intrinsics.checkNotNull(webView);
        View view = this.errorView;
        Intrinsics.checkNotNull(view);
        networkUtil.checkNetworkAndShowError(this, webView, view);
        ActionBar supportActionBar = getSupportActionBar();
        if (supportActionBar != null) {
            supportActionBar.setDisplayHomeAsUpEnabled(true);
        }
        if (getIntent().getStringExtra("title") != null || !Intrinsics.areEqual(getIntent().getStringExtra("title"), "")) {
            Intrinsics.checkNotNull(supportActionBar);
            supportActionBar.setTitle(getIntent().getStringExtra("title"));
        }
        ProgressBar progressBar = (ProgressBar) findViewById(R.id.vi_native_progressBar);
        this.viProgressBar = progressBar;
        if (progressBar != null) {
            progressBar.setVisibility(0);
        }
        String stringExtra = getIntent().getStringExtra("url");
        this.webviewUrl = stringExtra;
        if (stringExtra == null) {
            this.webviewUrl = "https://www.google.co.in";
        }
        this.fromNeoDeeplinkb = getIntent().getBooleanExtra("fromNeoDeeplink", false);
        WebView webView2 = this.viWebView;
        Intrinsics.checkNotNull(webView2);
        HyperWebViewServices hyperWebViewServices = new HyperWebViewServices(this, webView2);
        this.hyperWebViewServices = hyperWebViewServices;
        hyperWebViewServices.attach();
        WebView webView3 = this.viWebView;
        WebSettings settings = webView3 != null ? webView3.getSettings() : null;
        if (settings != null) {
            settings.setDomStorageEnabled(true);
        }
        if (settings != null) {
            settings.setCacheMode(2);
        }
        if (settings != null) {
            settings.setLoadWithOverviewMode(true);
        }
        if (settings != null) {
            settings.setUseWideViewPort(true);
        }
        if (settings != null) {
            settings.setAllowFileAccessFromFileURLs(true);
        }
        if (settings != null) {
            settings.setAllowUniversalAccessFromFileURLs(true);
        }
        if (settings != null) {
            settings.setJavaScriptEnabled(true);
        }
        WebView webView4 = this.viWebView;
        if (webView4 != null) {
            webView4.setInitialScale(1);
        }
        WebView webView5 = this.viWebView;
        if (webView5 != null) {
            webView5.addJavascriptInterface(new WebAppInterface(this, this), "AndroidInterface");
        }
        this.fusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
        WebView webView6 = this.viWebView;
        Intrinsics.checkNotNull(webView6);
        webView6.setWebChromeClient(new WebChromeClient() {
            @Override
            public void onGeolocationPermissionsShowPrompt(@NotNull String str2, @NotNull GeolocationPermissions.Callback callback) {
                Intrinsics.checkNotNullParameter(str2, "origin");
                Intrinsics.checkNotNullParameter(callback, "callback");
                if (ContextCompat.checkSelfPermission(VIUPIIntentWebView.this, "android.permission.ACCESS_FINE_LOCATION") == 0) {
                    VIUPIIntentWebView.this.checkLocationEnabled(str2, callback);
                    return;
                }
                ActivityCompat.requestPermissions(VIUPIIntentWebView.this, new String[]{"android.permission.ACCESS_FINE_LOCATION"}, 1);
                VIUPIIntentWebView.this.setWcallback(callback);
                VIUPIIntentWebView.this.setWorigin(str2);
            }
        });
        WebView webView7 = this.viWebView;
        if (webView7 != null && (str = this.webviewUrl) != null) {
            webView7.loadUrl(str);
        }
        WebView webView8 = this.viWebView;
        if (webView8 == null) {
            return;
        }
        webView8.setWebViewClient(new WebViewClient() {
            @Override
            public void onPageFinished(@NotNull WebView webView9, @NotNull String str2) {
                Intrinsics.checkNotNullParameter(webView9, "view");
                Intrinsics.checkNotNullParameter(str2, "url");
                super.onPageFinished(webView9, str2);
                ProgressBar viProgressBar = VIUPIIntentWebView.this.getViProgressBar();
                if (viProgressBar != null) {
                    viProgressBar.setVisibility(8);
                }
                WebView viWebView = VIUPIIntentWebView.this.getViWebView();
                if (viWebView == null) {
                    return;
                }
                viWebView.setVisibility(0);
            }

            @Override
            public void onPageStarted(@NotNull WebView webView9, @NotNull String str2, @Nullable Bitmap bitmap) {
                View view2;
                Intrinsics.checkNotNullParameter(webView9, "view");
                Intrinsics.checkNotNullParameter(str2, "url");
                ProgressBar viProgressBar = VIUPIIntentWebView.this.getViProgressBar();
                if (viProgressBar != null) {
                    viProgressBar.setVisibility(8);
                }
                WebView viWebView = VIUPIIntentWebView.this.getViWebView();
                if (viWebView != null) {
                    viWebView.setVisibility(0);
                }
                view2 = VIUPIIntentWebView.this.errorView;
                if (view2 == null) {
                    return;
                }
                view2.setVisibility(8);
            }

            @Override
            @Deprecated(message = "Deprecated in Java")
            public void onReceivedError(@NotNull WebView webView9, int i, @NotNull String str2, @NotNull String str3) {
                Intrinsics.checkNotNullParameter(webView9, "view");
                Intrinsics.checkNotNullParameter(str2, "description");
                Intrinsics.checkNotNullParameter(str3, "failingUrl");
                ProgressBar viProgressBar = VIUPIIntentWebView.this.getViProgressBar();
                if (viProgressBar != null) {
                    viProgressBar.setVisibility(8);
                }
                VIUPIIntentWebView.this.webviewUrl = str3;
                super.onReceivedError(webView9, i, str2, str3);
                if (StringsKt.startsWith$default(str3, "tel:", false, 2, (Object) null)) {
                    VIUPIIntentWebView.this.handleBackPressed();
                }
                Toast.makeText(VIUPIIntentWebView.this.getApplicationContext(), "Sorry, something went wrong. Please try again", 1).show();
            }

            @Override
            @Deprecated(message = "Deprecated in Java")
            public boolean shouldOverrideUrlLoading(@NotNull WebView webView9, @NotNull String str2) {
                WebView viWebView;
                Intrinsics.checkNotNullParameter(webView9, "wv");
                Intrinsics.checkNotNullParameter(str2, "overrideurl");
                if (StringsKt.startsWith$default(str2, "intent:", false, 2, (Object) null) || StringsKt.startsWith$default(str2, "mailto:", false, 2, (Object) null) || StringsKt.startsWith$default(str2, "maps:", false, 2, (Object) null) || StringsKt.startsWith$default(str2, "geo:", false, 2, (Object) null) || StringsKt.startsWith$default(str2, "sms:", false, 2, (Object) null) || StringsKt.startsWith$default(str2, "whatsapp", false, 2, (Object) null) || StringsKt.startsWith$default(str2, "tel:", false, 2, (Object) null)) {
                    try {
                        VIUPIIntentWebView.this.startActivity(new Intent("android.intent.action.VIEW", Uri.parse(StringsKt.startsWith$default(str2, "intent:", false, 2, (Object) null) ? StringsKt.replace$default(str2, "intent://", "https://", false, 4, (Object) null) : str2)));
                        if (!StringsKt.startsWith$default(str2, "tel:", false, 2, (Object) null) && (viWebView = VIUPIIntentWebView.this.getViWebView()) != null) {
                            viWebView.goBack();
                        }
                        return true;
                    } catch (Exception unused) {
                        Toast.makeText(VIUPIIntentWebView.this.getApplicationContext(), "Sorry, something went wrong. Please try again", 1).show();
                    }
                }
                return false;
            }

            @Override
            public void onReceivedError(@NotNull WebView webView9, @NotNull WebResourceRequest webResourceRequest, @NotNull WebResourceError webResourceError) {
                Intrinsics.checkNotNullParameter(webView9, "view");
                Intrinsics.checkNotNullParameter(webResourceRequest, "request");
                Intrinsics.checkNotNullParameter(webResourceError, "error");
                super.onReceivedError(webView9, webResourceRequest, webResourceError);
            }
        });
    }

    public void onDestroy() {
        super.onDestroy();
        safelyDestroyWebView(this.viWebView);
    }

    public boolean onOptionsItemSelected(@NotNull MenuItem menuItem) {
        Intrinsics.checkNotNullParameter(menuItem, "item");
        if (menuItem.getItemId() != 16908332) {
            return super/*android.app.Activity*/.onOptionsItemSelected(menuItem);
        }
        handleBackPressed();
        return true;
    }

    public void onRequestPermissionsResult(int i, @NotNull String[] strArr, @NotNull int[] iArr) {
        Intrinsics.checkNotNullParameter(strArr, "permissions");
        Intrinsics.checkNotNullParameter(iArr, "grantResults");
        super/*androidx.fragment.app.FragmentActivity*/.onRequestPermissionsResult(i, strArr, iArr);
        if (i == 1) {
            if ((!(iArr.length == 0)) && iArr[0] == 0) {
                checkLocationEnabled(this.worigin, this.wcallback);
            } else {
                Toast.makeText((Context) this, (CharSequence) "Location permission is needed to show your location in the WebView.", 0).show();
            }
        }
    }

    public final void setWcallback(@Nullable GeolocationPermissions.Callback callback) {
        this.wcallback = callback;
    }

    public final void setWorigin(@Nullable String str) {
        this.worigin = str;
    }
}