导航菜单

页面标题

页面副标题

bbinstant v6.24.0 - KapChatWebView.java 源代码

正在查看: bbinstant v6.24.0 应用的 KapChatWebView.java JAVA 源代码文件

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


package com.adjetter.kapchatsdk.activity;

import android.app.DownloadManager;
import android.content.ContentResolver;
import android.content.ContentUris;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.ConnectivityManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.provider.DocumentsContract;
import android.provider.MediaStore;
import android.view.KeyEvent;
import android.view.Window;
import android.webkit.CookieManager;
import android.webkit.DownloadListener;
import android.webkit.MimeTypeMap;
import android.webkit.URLUtil;
import android.webkit.ValueCallback;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.b;
import androidx.core.content.a;
import com.adjetter.kapchatsdk.R;
import com.adjetter.kapchatsdk.encryption.EncUtil;
import com.amazonaws.http.HttpHeader;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.net.URLEncoder;
import java.util.Calendar;

public class KapChatWebView extends AppCompatActivity {
    private static final int FILECHOOSER_RESULTCODE = 1;
    public static final int REQUEST_SELECT_FILE = 100;
    public static WebView webView;
    ContentResolver cR;
    Intent chooser;
    Uri imageUri;
    private ValueCallback<Uri[]> mUploadMessage;
    File photo;
    public ValueCallback<Uri[]> uploadMessage;
    boolean doubleBackToExitPressedOnce = false;
    MimeTypeMap mime = MimeTypeMap.getSingleton();

    public static String getDataColumn(Context context, Uri uri, String str, String[] strArr) {
        Cursor cursor = null;
        try {
            Cursor query = context.getContentResolver().query(uri, new String[]{"_data"}, str, strArr, null);
            if (query != null) {
                try {
                    if (query.moveToFirst()) {
                        String string = query.getString(query.getColumnIndexOrThrow("_data"));
                        query.close();
                        return string;
                    }
                } catch (Throwable th) {
                    th = th;
                    cursor = query;
                    if (cursor != null) {
                        cursor.close();
                    }
                    throw th;
                }
            }
            if (query != null) {
                query.close();
            }
            return null;
        } catch (Throwable th2) {
            th = th2;
        }
    }

    public static String getRealPathFromURI(Context context, Uri uri) {
        Uri uri2 = null;
        if (DocumentsContract.isDocumentUri(context, uri)) {
            if (isExternalStorageDocument(uri)) {
                String[] split = DocumentsContract.getDocumentId(uri).split(":");
                if ("primary".equalsIgnoreCase(split[0])) {
                    return Environment.getExternalStorageDirectory() + "/" + split[1];
                }
            } else {
                if (isDownloadsDocument(uri)) {
                    return getDataColumn(context, ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(DocumentsContract.getDocumentId(uri)).longValue()), null, null);
                }
                if (isMediaDocument(uri)) {
                    String[] split2 = DocumentsContract.getDocumentId(uri).split(":");
                    String str = split2[0];
                    if ("image".equals(str)) {
                        uri2 = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
                    } else if ("video".equals(str)) {
                        uri2 = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
                    } else if ("audio".equals(str)) {
                        uri2 = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
                    }
                    return getDataColumn(context, uri2, "_id=?", new String[]{split2[1]});
                }
            }
        } else {
            if ("content".equalsIgnoreCase(uri.getScheme())) {
                return isGooglePhotosUri(uri) ? uri.getLastPathSegment() : getDataColumn(context, uri, null, null);
            }
            if ("file".equalsIgnoreCase(uri.getScheme())) {
                return uri.getPath();
            }
        }
        return null;
    }

    public static boolean isDownloadsDocument(Uri uri) {
        return "com.android.providers.downloads.documents".equals(uri.getAuthority());
    }

    public static boolean isExternalStorageDocument(Uri uri) {
        return "com.android.externalstorage.documents".equals(uri.getAuthority());
    }

    public static boolean isGooglePhotosUri(Uri uri) {
        return "com.google.android.apps.photos.content".equals(uri.getAuthority());
    }

    public static boolean isMediaDocument(Uri uri) {
        return "com.android.providers.media.documents".equals(uri.getAuthority());
    }

    private boolean isOnline() {
        try {
            return ((ConnectivityManager) getApplicationContext().getSystemService("connectivity")).getActiveNetworkInfo().isConnectedOrConnecting();
        } catch (Exception unused) {
            return false;
        }
    }

    public int calculateInSampleSize(BitmapFactory.Options options, int i, int i2) {
        int round;
        int i3 = options.outHeight;
        int i4 = options.outWidth;
        if (i3 > i2 || i4 > i) {
            round = Math.round(i3 / i2);
            int round2 = Math.round(i4 / i);
            if (round >= round2) {
                round = round2;
            }
        } else {
            round = 1;
        }
        while ((i4 * i3) / (round * round) > i * i2 * 2) {
            round++;
        }
        return round;
    }

    public void checkPermission(String[] strArr, int i) {
        int i2 = Build.VERSION.SDK_INT;
        if (i2 > 28 || (a.checkSelfPermission(getApplicationContext(), "android.permission.READ_EXTERNAL_STORAGE") == 0 && a.checkSelfPermission(getApplicationContext(), "android.permission.WRITE_EXTERNAL_STORAGE") == 0 && a.checkSelfPermission(getApplicationContext(), "android.permission.CAMERA") == 0)) {
            if (i2 <= 28) {
                return;
            }
            if (a.checkSelfPermission(getApplicationContext(), "android.permission.READ_EXTERNAL_STORAGE") == 0 && a.checkSelfPermission(getApplicationContext(), "android.permission.CAMERA") == 0) {
                return;
            }
        }
        b.requestPermissions(this, strArr, i);
    }

    public android.net.Uri compressImage(android.content.Context r18, android.net.Uri r19) {
        throw new UnsupportedOperationException("Method not decompiled: com.adjetter.kapchatsdk.activity.KapChatWebView.compressImage(android.content.Context, android.net.Uri):android.net.Uri");
    }

    public String getFilename(Context context) {
        try {
            File file = Build.VERSION.SDK_INT > 28 ? new File(context.getFilesDir(), "MyFolder/Images") : new File(Environment.getExternalStorageDirectory().getPath(), "MyFolder/Images");
            if (!file.exists()) {
                file.mkdirs();
            }
            return file.getAbsolutePath() + "/" + System.currentTimeMillis() + ".jpg";
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    public Uri getImageUri(Context context, Bitmap bitmap) {
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, new ByteArrayOutputStream());
        return Uri.parse(MediaStore.Images.Media.insertImage(context.getContentResolver(), bitmap, "IMG_" + Calendar.getInstance().getTime(), (String) null));
    }

    @Override
    public void onActivityResult(int r20, int r21, android.content.Intent r22) {
        throw new UnsupportedOperationException("Method not decompiled: com.adjetter.kapchatsdk.activity.KapChatWebView.onActivityResult(int, int, android.content.Intent):void");
    }

    @Override
    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView(R.layout.kapchatwebview_activity);
        getIntent().getStringExtra("message");
        boolean booleanExtra = getIntent().getBooleanExtra("flag", false);
        Window window = getWindow();
        window.clearFlags(androidx.core.view.accessibility.b.TYPE_VIEW_TARGETED_BY_SCROLL);
        window.addFlags(Integer.MIN_VALUE);
        window.setStatusBarColor(a.getColor(this, R.color.kapchatbbtool));
        SharedPreferences sharedPreferences = getSharedPreferences("kapchatnewRef", 0);
        String string = sharedPreferences.getString("ccEncoded", "");
        String string2 = sharedPreferences.getString("iv", "");
        if (string.equalsIgnoreCase("") || string2.equalsIgnoreCase("")) {
            Toast.makeText(getApplicationContext(), "Invalid Login", 1).show();
            finish();
            setResult(-1);
        }
        String replace = ("customer_code=" + URLEncoder.encode(string) + "&iv=" + URLEncoder.encode(string2) + ("&response=" + URLEncoder.encode(EncUtil.decrypt(getApplicationContext(), getSharedPreferences("kapchatpreference", 0).getString("initLoginResponse", "")))) + "&status=success&api_version=2.0").replace(" ", "+");
        this.cR = getApplicationContext().getContentResolver();
        WebView webView2 = (WebView) findViewById(R.id.kapchat_web_view);
        webView = webView2;
        webView2.setLayerType(2, null);
        WebSettings settings = webView.getSettings();
        settings.setJavaScriptEnabled(true);
        settings.setUseWideViewPort(true);
        settings.setLoadWithOverviewMode(true);
        settings.setAllowFileAccess(true);
        settings.setJavaScriptCanOpenWindowsAutomatically(true);
        settings.setPluginState(WebSettings.PluginState.ON);
        settings.setAllowContentAccess(true);
        settings.setCacheMode(1);
        settings.setDomStorageEnabled(true);
        if (isOnline()) {
            webView.loadUrl("https://selfserveapp.kapturecrm.com/bb_instant.html?" + replace + "&is_fresh=" + booleanExtra);
        } else {
            Toast.makeText(getApplicationContext(), "No Internet Connection", 1).show();
            webView.destroy();
            finish();
            setResult(-1);
        }
        webView.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView webView3, String str) {
                if (!str.equalsIgnoreCase("http://adjetter.designcan.in/chat-bot/bb/go-back")) {
                    return super.shouldOverrideUrlLoading(webView3, str);
                }
                KapChatWebView.webView.destroy();
                KapChatWebView.this.finish();
                return true;
            }
        });
        webView.setDownloadListener(new DownloadListener() {
            @Override
            public void onDownloadStart(String str, String str2, String str3, String str4, long j2) {
                DownloadManager.Request request = new DownloadManager.Request(Uri.parse(str));
                request.setMimeType(str4);
                request.addRequestHeader("cookie", CookieManager.getInstance().getCookie(str));
                request.addRequestHeader(HttpHeader.USER_AGENT, str2);
                request.setDescription("Downloading file...");
                request.setTitle(URLUtil.guessFileName(str, str3, str4));
                request.allowScanningByMediaScanner();
                request.setNotificationVisibility(1);
                request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, URLUtil.guessFileName(str, str3, str4));
                ((DownloadManager) KapChatWebView.this.getSystemService("download")).enqueue(request);
                Toast.makeText(KapChatWebView.this.getApplicationContext(), "Downloading File", 1).show();
            }
        });
        webView.setWebChromeClient(new WebChromeClient() {
            @Override
            public Bitmap getDefaultVideoPoster() {
                return Bitmap.createBitmap(10, 10, Bitmap.Config.ARGB_8888);
            }

            @Override
            public boolean onShowFileChooser(android.webkit.WebView r17, android.webkit.ValueCallback<android.net.Uri[]> r18, android.webkit.WebChromeClient.FileChooserParams r19) {
                throw new UnsupportedOperationException("Method not decompiled: com.adjetter.kapchatsdk.activity.KapChatWebView.AnonymousClass3.onShowFileChooser(android.webkit.WebView, android.webkit.ValueCallback, android.webkit.WebChromeClient$FileChooserParams):boolean");
            }

            protected void openFileChooser(ValueCallback valueCallback, String str) {
                KapChatWebView.this.mUploadMessage = valueCallback;
                Intent intent = new Intent("android.intent.action.GET_CONTENT");
                intent.addCategory("android.intent.category.OPENABLE");
                intent.setType("image/*,video/*");
                KapChatWebView.this.startActivityForResult(Intent.createChooser(intent, "File Browser"), 1);
            }

            protected void openFileChooser(ValueCallback<Uri[]> valueCallback, String str, String str2) {
                KapChatWebView.this.mUploadMessage = valueCallback;
                Intent intent = new Intent("android.intent.action.GET_CONTENT");
                intent.addCategory("android.intent.category.OPENABLE");
                intent.setType("video/*|image/*");
                intent.putExtra("android.intent.extra.ALLOW_MULTIPLE", true);
                Intent intent2 = new Intent("android.media.action.IMAGE_CAPTURE");
                KapChatWebView.this.photo = new File(Environment.getExternalStorageDirectory(), System.currentTimeMillis() + "Pic.jpg");
                intent2.putExtra("output", Uri.fromFile(KapChatWebView.this.photo));
                KapChatWebView kapChatWebView = KapChatWebView.this;
                kapChatWebView.imageUri = Uri.fromFile(kapChatWebView.photo);
                Intent intent3 = new Intent("android.intent.action.CHOOSER");
                intent3.putExtra("android.intent.extra.TITLE", "Choose");
                intent3.putExtra("android.intent.extra.INTENT", intent);
                intent3.putExtra("android.intent.extra.INITIAL_INTENTS", new Intent[]{intent2});
                KapChatWebView.this.startActivityForResult(Intent.createChooser(intent, "File Browser"), 1);
            }

            protected void openFileChooser(ValueCallback<Uri[]> valueCallback) {
                KapChatWebView.this.mUploadMessage = valueCallback;
                Intent intent = new Intent("android.intent.action.GET_CONTENT");
                intent.addCategory("android.intent.category.OPENABLE");
                intent.setType("video/*|image/*");
                KapChatWebView.this.startActivityForResult(Intent.createChooser(intent, "File Chooser"), 1);
            }
        });
    }

    @Override
    public boolean onKeyDown(int i, KeyEvent keyEvent) {
        if (keyEvent.getAction() != 0 || i != 4) {
            return super.onKeyDown(i, keyEvent);
        }
        if (webView.canGoBack()) {
            webView.goBack();
        } else {
            try {
                if (this.doubleBackToExitPressedOnce) {
                    super.onBackPressed();
                    setResult(-1);
                }
                this.doubleBackToExitPressedOnce = true;
                Toast.makeText(this, "Please click BACK again to exit", 0).show();
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        KapChatWebView.this.doubleBackToExitPressedOnce = false;
                    }
                }, 2000L);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return true;
    }

    @Override
    public void onRequestPermissionsResult(int i, String[] strArr, int[] iArr) {
        super.onRequestPermissionsResult(i, strArr, iArr);
        boolean z = true;
        for (int i2 : iArr) {
            if (i2 != 0) {
                ValueCallback<Uri[]> valueCallback = this.uploadMessage;
                if (valueCallback != null) {
                    valueCallback.onReceiveValue(null);
                    this.uploadMessage = null;
                }
                Toast.makeText(getApplicationContext(), "File upload will not work as permission is not granted", 1).show();
                z = false;
            }
        }
        if (z) {
            startActivityForResult(this.chooser, 100);
        }
    }

    @Override
    public void onResume() {
        super.onResume();
        SharedPreferences.Editor edit = getSharedPreferences("kapchatnewRef", 0).edit();
        edit.putInt("unreadCount", 0);
        edit.apply();
        SharedPreferences.Editor edit2 = getSharedPreferences("kapchatnewRef", 0).edit();
        edit2.putBoolean("webviewseen", true);
        edit2.apply();
    }

    @Override
    protected void onStop() {
        super.onStop();
        SharedPreferences.Editor edit = getSharedPreferences("kapchatnewRef", 0).edit();
        edit.putBoolean("webviewseen", false);
        edit.apply();
    }
}