Add decompiled APK source code (JADX)

- 28,932 files
- Full Java source code
- Smali files
- Resources

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
2026-02-18 14:52:23 -08:00
parent cc210a65ea
commit f9d20bb3fc
26991 changed files with 2541449 additions and 0 deletions

View File

@@ -0,0 +1,243 @@
package com.helpshift.chat;
import android.content.Intent;
import android.webkit.ValueCallback;
import android.webkit.WebView;
import com.helpshift.cache.HelpshiftResourceCacheManager;
import com.helpshift.concurrency.HSThreadingService;
import com.helpshift.config.HSConfigManager;
import com.helpshift.log.HSLogger;
import com.helpshift.migrator.NativeToSdkxMigrator;
import com.helpshift.storage.HSGenericDataManager;
import com.helpshift.user.UserManager;
import java.lang.ref.WeakReference;
import org.json.JSONObject;
/* loaded from: classes3.dex */
public class HSChatEventsHandler {
public final HSConfigManager configManager;
public final HSGenericDataManager genericDataManager;
public final NativeToSdkxMigrator nativeToSdkxMigrator;
public final HelpshiftResourceCacheManager resourceCacheManager;
public final HSThreadingService services;
public WeakReference uiCallback;
public final UserManager userManager;
public HSChatEventsHandler(UserManager userManager, HSThreadingService hSThreadingService, HSConfigManager hSConfigManager, HelpshiftResourceCacheManager helpshiftResourceCacheManager, HSGenericDataManager hSGenericDataManager, NativeToSdkxMigrator nativeToSdkxMigrator) {
this.services = hSThreadingService;
this.userManager = userManager;
this.configManager = hSConfigManager;
this.resourceCacheManager = helpshiftResourceCacheManager;
this.genericDataManager = hSGenericDataManager;
this.nativeToSdkxMigrator = nativeToSdkxMigrator;
}
public void setUiEventsListener(HSWebchatToUiCallback hSWebchatToUiCallback) {
this.uiCallback = new WeakReference(hSWebchatToUiCallback);
}
public void sdkxMigrationLogSynced(boolean z) {
this.nativeToSdkxMigrator.setErrorLogsSyncedWithWebchat(z);
}
public void onSetLocalStorage(final String str) {
this.services.runSerial(new Runnable() { // from class: com.helpshift.chat.HSChatEventsHandler.1
@Override // java.lang.Runnable
public void run() {
HSChatEventsHandler.this.configManager.setLocalStorageData(str);
}
});
}
public void onRemoveLocalStorage(final String str) {
this.services.runSerial(new Runnable() { // from class: com.helpshift.chat.HSChatEventsHandler.2
@Override // java.lang.Runnable
public void run() {
HSChatEventsHandler.this.configManager.removeLocalStorageData(str);
}
});
}
public void getHelpcenterData() {
HSWebchatToUiCallback hSWebchatToUiCallback = (HSWebchatToUiCallback) this.uiCallback.get();
if (hSWebchatToUiCallback != null) {
hSWebchatToUiCallback.setHelpcenterData();
}
}
public void onReceivePushTokenSyncRequestData(String str) {
this.services.runSerial(new Runnable() { // from class: com.helpshift.chat.HSChatEventsHandler.3
@Override // java.lang.Runnable
public void run() {
HSChatEventsHandler.this.userManager.setPushTokenSynced(true);
}
});
}
public void onRemoveAnonymousUser() {
this.services.runSerial(new Runnable() { // from class: com.helpshift.chat.HSChatEventsHandler.4
@Override // java.lang.Runnable
public void run() {
HSChatEventsHandler.this.userManager.removeAnonymousUser();
}
});
}
public void setPollingStatus(String str) {
try {
this.userManager.setShouldPollFlag(new JSONObject(str).optBoolean("shouldPoll", false));
} catch (Exception e) {
HSLogger.e("wbEvntHndlr", "Error getting polling status", e);
}
}
public void setGenericSdkData(final String str) {
this.services.runSerial(new Runnable() { // from class: com.helpshift.chat.HSChatEventsHandler.5
@Override // java.lang.Runnable
public void run() {
HSChatEventsHandler.this.genericDataManager.saveGenericSdkData(str);
}
});
}
public void setIssueExistsForUser(final String str) {
this.services.runSerial(new Runnable() { // from class: com.helpshift.chat.HSChatEventsHandler.6
@Override // java.lang.Runnable
public void run() {
try {
HSChatEventsHandler.this.userManager.setShowChatIconInHelpcenter(new JSONObject(str).optBoolean("issueExists", false));
} catch (Exception e) {
HSLogger.e("wbEvntHndlr", "error in getting the issue exist flag", e);
}
}
});
}
public void onWebchatClosed() {
this.services.runOnUIThread(new Runnable() { // from class: com.helpshift.chat.HSChatEventsHandler.7
@Override // java.lang.Runnable
public void run() {
HSWebchatToUiCallback hSWebchatToUiCallback = (HSWebchatToUiCallback) HSChatEventsHandler.this.uiCallback.get();
if (hSWebchatToUiCallback != null) {
hSWebchatToUiCallback.onWebchatClosed();
}
}
});
}
public void onWebchatLoaded() {
this.services.runOnUIThread(new Runnable() { // from class: com.helpshift.chat.HSChatEventsHandler.8
@Override // java.lang.Runnable
public void run() {
HSWebchatToUiCallback hSWebchatToUiCallback = (HSWebchatToUiCallback) HSChatEventsHandler.this.uiCallback.get();
if (hSWebchatToUiCallback != null) {
hSWebchatToUiCallback.onWebchatLoaded();
}
}
});
}
public void onWebchatError() {
deleteAllCachedFilesOfWebchat();
this.services.runOnUIThread(new Runnable() { // from class: com.helpshift.chat.HSChatEventsHandler.9
@Override // java.lang.Runnable
public void run() {
HSWebchatToUiCallback hSWebchatToUiCallback = (HSWebchatToUiCallback) HSChatEventsHandler.this.uiCallback.get();
if (hSWebchatToUiCallback != null) {
hSWebchatToUiCallback.onWebchatError();
}
}
});
}
public void onUserAuthenticationFailure() {
deleteAllCachedFilesOfWebchat();
this.services.runOnUIThread(new Runnable() { // from class: com.helpshift.chat.HSChatEventsHandler.10
@Override // java.lang.Runnable
public void run() {
HSWebchatToUiCallback hSWebchatToUiCallback = (HSWebchatToUiCallback) HSChatEventsHandler.this.uiCallback.get();
if (hSWebchatToUiCallback != null) {
hSWebchatToUiCallback.onUserAuthenticationFailure();
}
}
});
}
public final void deleteAllCachedFilesOfWebchat() {
this.services.runSerial(new Runnable() { // from class: com.helpshift.chat.HSChatEventsHandler.11
@Override // java.lang.Runnable
public void run() {
HSChatEventsHandler.this.resourceCacheManager.deleteAllCachedFiles();
}
});
}
public void addWebviewToCurrentUI(final WebView webView) {
this.services.runOnUIThread(new Runnable() { // from class: com.helpshift.chat.HSChatEventsHandler.12
@Override // java.lang.Runnable
public void run() {
HSWebchatToUiCallback hSWebchatToUiCallback = (HSWebchatToUiCallback) HSChatEventsHandler.this.uiCallback.get();
if (hSWebchatToUiCallback != null) {
hSWebchatToUiCallback.addWebviewToCurrentUI(webView);
}
}
});
}
public void onUiConfigChange(final String str) {
saveUiConfigDataForWebchat(str);
this.services.runOnUIThread(new Runnable() { // from class: com.helpshift.chat.HSChatEventsHandler.13
@Override // java.lang.Runnable
public void run() {
HSWebchatToUiCallback hSWebchatToUiCallback = (HSWebchatToUiCallback) HSChatEventsHandler.this.uiCallback.get();
if (hSWebchatToUiCallback != null) {
hSWebchatToUiCallback.onUiConfigChange(str);
}
}
});
}
public final void saveUiConfigDataForWebchat(final String str) {
this.services.runSerial(new Runnable() { // from class: com.helpshift.chat.HSChatEventsHandler.14
@Override // java.lang.Runnable
public void run() {
HSChatEventsHandler.this.configManager.saveUiConfigDataOfWebchat(str);
}
});
}
public void setAttachmentFilePathCallback(ValueCallback valueCallback) {
HSWebchatToUiCallback hSWebchatToUiCallback = (HSWebchatToUiCallback) this.uiCallback.get();
if (hSWebchatToUiCallback != null) {
hSWebchatToUiCallback.setAttachmentFilePathCallback(valueCallback);
}
}
public void openFileChooser(Intent intent, int i) {
HSWebchatToUiCallback hSWebchatToUiCallback = (HSWebchatToUiCallback) this.uiCallback.get();
if (hSWebchatToUiCallback != null) {
hSWebchatToUiCallback.openFileChooser(intent, i);
}
}
public void sendIntentToSystemApp(Intent intent) {
HSWebchatToUiCallback hSWebchatToUiCallback = (HSWebchatToUiCallback) this.uiCallback.get();
if (hSWebchatToUiCallback != null) {
hSWebchatToUiCallback.sendIntentToSystemApp(intent);
}
}
public void requestConversationMetadata(String str) {
HSWebchatToUiCallback hSWebchatToUiCallback = (HSWebchatToUiCallback) this.uiCallback.get();
if (hSWebchatToUiCallback != null) {
hSWebchatToUiCallback.requestConversationMetadata(str);
}
}
public void webchatJsFileLoaded() {
HSWebchatToUiCallback hSWebchatToUiCallback = (HSWebchatToUiCallback) this.uiCallback.get();
if (hSWebchatToUiCallback != null) {
hSWebchatToUiCallback.webchatJsFileLoaded();
}
}
}

View File

@@ -0,0 +1,470 @@
package com.helpshift.chat;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.graphics.Rect;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.webkit.ValueCallback;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.widget.LinearLayout;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.browser.customtabs.CustomTabsCallback;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import com.applovin.impl.sdk.utils.JsonUtils;
import com.facebook.share.internal.ShareConstants;
import com.helpshift.R$id;
import com.helpshift.R$layout;
import com.helpshift.activities.FragmentTransactionListener;
import com.helpshift.config.HSConfigManager;
import com.helpshift.core.HSContext;
import com.helpshift.log.HSLogger;
import com.helpshift.user_lifecyle.UserLifecycleListener;
import com.helpshift.util.ApplicationUtil;
import com.helpshift.util.HSTimer;
import com.helpshift.util.Utils;
import com.helpshift.util.ViewUtil;
import com.helpshift.util.network.connectivity.HSConnectivityManager;
import com.helpshift.util.network.connectivity.HSNetworkConnectivityCallback;
import com.helpshift.views.HSWebView;
import com.ironsource.nb;
import com.vungle.ads.internal.presenter.MRAIDPresenter;
import org.json.JSONArray;
import org.json.JSONObject;
/* loaded from: classes3.dex */
public class HSChatFragment extends Fragment implements HSWebchatToUiCallback, UserLifecycleListener, View.OnClickListener, HSNetworkConnectivityCallback {
public static final int REQUEST_SELECT_FILE = 1001;
public static final String TAG = "HSChatFragment";
public static final String localHostUrl = "https://localhost/";
private HSChatWebChromeClient chromeClient;
private HSChatEventsHandler eventsHandler;
private ValueCallback<Uri[]> filePathCallback;
private boolean isWebchatSourceChanged;
private View loadingView;
private View retryView;
private FragmentTransactionListener transactionListener;
private HSWebView webView;
private String webchatJsFileLoadingTime;
private String webchatSource;
private LinearLayout webviewLayout;
private boolean shouldSendPollerEvent = true;
private boolean isKeyboardVisible = false;
private final ViewTreeObserver.OnGlobalLayoutListener globalLayoutListener = new ViewTreeObserver.OnGlobalLayoutListener() { // from class: com.helpshift.chat.HSChatFragment.1
@Override // android.view.ViewTreeObserver.OnGlobalLayoutListener
public void onGlobalLayout() {
if (HSChatFragment.this.webView == null) {
return;
}
Rect rect = new Rect();
HSChatFragment.this.webView.getWindowVisibleDisplayFrame(rect);
int height = HSChatFragment.this.webView.getRootView().getHeight();
boolean z = ((double) (height - rect.bottom)) > ((double) height) * 0.15d;
if (z != HSChatFragment.this.isKeyboardVisible) {
HSChatFragment.this.sendKeyboardToggleEvent(z);
}
HSChatFragment.this.isKeyboardVisible = z;
}
};
@Override // com.helpshift.chat.HSWebchatToUiCallback
public void setAttachmentFilePathCallback(ValueCallback<Uri[]> valueCallback) {
this.filePathCallback = valueCallback;
}
public void setTransactionListener(FragmentTransactionListener fragmentTransactionListener) {
this.transactionListener = fragmentTransactionListener;
}
@Override // androidx.fragment.app.Fragment
@Nullable
public View onCreateView(@NonNull LayoutInflater layoutInflater, @Nullable ViewGroup viewGroup, @Nullable Bundle bundle) {
HSLogger.d(TAG, "onCreateView() - " + hashCode());
View inflate = layoutInflater.inflate(R$layout.hs__webchat_fragment_layout, viewGroup, false);
if (getArguments() != null) {
this.webchatSource = getArguments().getString(ShareConstants.FEED_SOURCE_PARAM);
}
return inflate;
}
@Override // androidx.fragment.app.Fragment
public void onViewCreated(@NonNull View view, @Nullable Bundle bundle) {
super.onViewCreated(view, bundle);
HSLogger.d(TAG, "onViewCreated() - " + hashCode());
HSContext.getInstance().getUserManager().setUserLifecycleListener(this);
initViews(view);
startChatView();
}
private void initViews(View view) {
this.loadingView = view.findViewById(R$id.hs__loading_view);
this.retryView = view.findViewById(R$id.hs__retry_view);
this.webviewLayout = (LinearLayout) view.findViewById(R$id.hs__webview_layout);
this.webView = (HSWebView) view.findViewById(R$id.hs__webchat_webview);
view.findViewById(R$id.hs__retry_view_close_btn).setOnClickListener(this);
view.findViewById(R$id.hs__loading_view_close_btn).setOnClickListener(this);
view.findViewById(R$id.hs__retry_button).setOnClickListener(this);
}
private void startChatView() {
String webchatEmbeddedCodeString = HSContext.getInstance().getJsGenerator().getWebchatEmbeddedCodeString(getContext());
if (Utils.isEmpty(webchatEmbeddedCodeString)) {
HSLogger.e(TAG, "Error in reading the source code from assets folder");
onWebchatError();
} else {
showLoadingView();
initWebviewWithWebchat(webchatEmbeddedCodeString);
}
}
private void initWebviewWithWebchat(String str) {
HSLogger.d(TAG, "Webview is launched");
HSContext hSContext = HSContext.getInstance();
HSChatEventsHandler hSChatEventsHandler = new HSChatEventsHandler(hSContext.getUserManager(), hSContext.getHsThreadingService(), hSContext.getConfigManager(), hSContext.getChatResourceCacheManager(), hSContext.getGenericDataManager(), hSContext.getNativeToSdkxMigrator());
this.eventsHandler = hSChatEventsHandler;
hSChatEventsHandler.setUiEventsListener(this);
HSChatWebChromeClient hSChatWebChromeClient = new HSChatWebChromeClient(this.eventsHandler);
this.chromeClient = hSChatWebChromeClient;
hSChatWebChromeClient.setFilePathCallback(this.filePathCallback);
this.webView.setWebChromeClient(this.chromeClient);
this.webView.setWebViewClient(new HSChatWebViewClient(this.eventsHandler, hSContext.getChatResourceCacheManager()));
this.webView.addJavascriptInterface(new HSChatToNativeBridge(hSContext.getHsEventProxy(), this.eventsHandler), "HSInterface");
this.webView.loadDataWithBaseURL(localHostUrl, str, "text/html", nb.N, null);
}
@Override // androidx.fragment.app.Fragment
public void onStop() {
super.onStop();
HSLogger.d(TAG, "onStop() - " + hashCode());
if (this.shouldSendPollerEvent) {
sendLifecycleEventToWebchat(false);
}
HSContext.getInstance().setWebchatUIIsOpen(false);
this.webView.getViewTreeObserver().removeOnGlobalLayoutListener(this.globalLayoutListener);
}
@Override // androidx.fragment.app.Fragment
public void onStart() {
super.onStart();
HSLogger.d(TAG, "onStart() -" + hashCode());
sendLifecycleEventToWebchat(true);
HSContext.getInstance().setWebchatUIIsOpen(true);
this.webView.getViewTreeObserver().addOnGlobalLayoutListener(this.globalLayoutListener);
}
@Override // androidx.fragment.app.Fragment
public void onPause() {
super.onPause();
HSLogger.d(TAG, "onPause() -" + hashCode());
FragmentActivity activity = getActivity();
if (activity != null && !activity.isChangingConfigurations()) {
HSContext.getInstance().getConversationPoller().startPoller();
}
HSConnectivityManager.getInstance(getContext()).unregisterNetworkConnectivityListener(this);
}
@Override // androidx.fragment.app.Fragment
public void onResume() {
super.onResume();
HSLogger.d(TAG, "onResume() -" + hashCode());
FragmentActivity activity = getActivity();
if (activity != null && !activity.isChangingConfigurations()) {
HSContext.getInstance().getConversationPoller().stopPoller();
}
HSConnectivityManager.getInstance(getContext()).registerNetworkConnectivityListener(this);
HSContext hSContext = HSContext.getInstance();
if (hSContext.isWebchatUIOpen() && this.isWebchatSourceChanged) {
HSLogger.d(TAG, "Updating config with latest config in same webchat session");
try {
callWebchatApi("window.helpshiftConfig = JSON.parse(JSON.stringify(" + hSContext.getConfigManager().getWebchatConfigJs(hSContext.isIsWebchatOpenedFromHelpcenter()) + "));Helpshift('updateClientConfigWithoutReload');", null);
} catch (Exception e) {
HSLogger.e(TAG, "Failed to update webchat config with latest config ", e);
}
}
}
@Override // com.helpshift.chat.HSWebchatToUiCallback
public void sendIntentToSystemApp(Intent intent) {
try {
startActivity(intent);
} catch (Exception e) {
HSLogger.e(TAG, "Error in opening a link in system app", e);
}
}
@Override // androidx.fragment.app.Fragment
public void onDestroy() {
super.onDestroy();
HSLogger.d(TAG, "onDestroy() -" + hashCode());
HSContext hSContext = HSContext.getInstance();
hSContext.getUserManager().removeUserLifeCycleListener();
HSChatEventsHandler hSChatEventsHandler = this.eventsHandler;
if (hSChatEventsHandler != null) {
hSChatEventsHandler.setUiEventsListener(null);
}
this.webviewLayout.removeView(this.webView);
this.webView.destroyCustomWebview();
this.webView = null;
hSContext.getPersistentStorage().setLastRequestUnreadCountApiAccess(0L);
hSContext.getUserManager().markAllPushMessagesAsRead();
}
@Override // com.helpshift.chat.HSWebchatToUiCallback
public void onWebchatClosed() {
HSLogger.d(TAG, "onWebchatClosed");
FragmentTransactionListener fragmentTransactionListener = this.transactionListener;
if (fragmentTransactionListener != null) {
fragmentTransactionListener.closeWebchat();
}
}
@Override // com.helpshift.chat.HSWebchatToUiCallback
public void onWebchatLoaded() {
HSLogger.d(TAG, "onWebchatLoaded");
showWebchatView();
clearNotifications();
HSContext.getInstance().getUserManager().markAllMessagesAsRead();
HSContext.getInstance().getUserManager().markAllPushMessagesAsRead();
String migrationErrorLogs = HSContext.getInstance().getNativeToSdkxMigrator().getMigrationErrorLogs();
if (Utils.isNotEmpty(migrationErrorLogs)) {
callWebchatApi("Helpshift('sdkxMigrationLog', '" + migrationErrorLogs + "' ) ", null);
}
sendKeyboardToggleEvent(this.isKeyboardVisible);
sendOrientationChangeEventToWebchat(getResources().getConfiguration().orientation);
sendNetworkConfigurationChangeEvent(HSContext.getInstance().getDevice().isOnline() ? CustomTabsCallback.ONLINE_EXTRAS_KEY : "offline");
if (Utils.isNotEmpty(this.webchatJsFileLoadingTime)) {
sendTimeToLoadWebchatEvent(this.webchatJsFileLoadingTime);
}
}
private void clearNotifications() {
Context context = getContext();
if (context != null) {
ApplicationUtil.cancelNotification(context);
}
}
@Override // com.helpshift.chat.HSWebchatToUiCallback
public void onWebchatError() {
HSLogger.e(TAG, "Received onWebchatError event");
showErrorView();
}
@Override // com.helpshift.chat.HSWebchatToUiCallback
public void addWebviewToCurrentUI(WebView webView) {
this.webviewLayout.addView(webView);
}
@Override // com.helpshift.chat.HSWebchatToUiCallback
public void onUiConfigChange(String str) {
FragmentTransactionListener fragmentTransactionListener = this.transactionListener;
if (fragmentTransactionListener != null) {
fragmentTransactionListener.changeStatusBarColor(str);
}
}
@Override // com.helpshift.chat.HSWebchatToUiCallback
public void onUserAuthenticationFailure() {
HSLogger.e(TAG, "Received onUserAuthenticationFailure event");
showErrorView();
}
@Override // com.helpshift.chat.HSWebchatToUiCallback
public void webchatJsFileLoaded() {
long endTimer = HSTimer.endTimer(this.webchatSource);
if (endTimer > 0) {
this.webchatJsFileLoadingTime = getWebchatJsFileLoadingTime(Long.valueOf(endTimer));
}
HSLogger.d(TAG, "Webchat.js Loaded, Stopping loading timer");
}
private String getWebchatJsFileLoadingTime(Long l) {
JSONObject jSONObject = new JSONObject();
try {
jSONObject.put(ShareConstants.FEED_SOURCE_PARAM, this.webchatSource);
jSONObject.put("time", l.toString());
return jSONObject.toString();
} catch (Exception e) {
HSLogger.e(TAG, "Failed to calculate webchat.js loading time", e);
return "";
}
}
@Override // com.helpshift.chat.HSWebchatToUiCallback
public void requestConversationMetadata(String str) {
try {
JSONObject jSONObject = new JSONObject(str);
int i = jSONObject.getInt("bclConfig");
int i2 = jSONObject.getInt("dbglConfig");
HSLogger.d(TAG, "Log limits: breadcrumb: " + i + ", debug logs: " + i2);
HSConfigManager configManager = HSContext.getInstance().getConfigManager();
JSONArray breadCrumbs = configManager.getBreadCrumbs(i);
JSONArray debugLogs = configManager.getDebugLogs(i2);
JSONObject jSONObject2 = new JSONObject();
jSONObject2.put("bcl", breadCrumbs);
jSONObject2.put("dbgl", debugLogs);
String jSONObject3 = jSONObject2.toString();
HSLogger.d(TAG, "Sending log/crumb data to webchat: " + jSONObject3);
callWebchatApi("Helpshift('syncConversationMetadata',JSON.stringify(" + jSONObject3 + "));", null);
} catch (Exception e) {
HSLogger.e(TAG, "Error with request conversation meta call", e);
}
}
@Override // com.helpshift.chat.HSWebchatToUiCallback
public void setHelpcenterData() {
try {
String additionalInfo = HSContext.getInstance().getConfigManager().getAdditionalInfo();
if (Utils.isEmpty(additionalInfo)) {
additionalInfo = JsonUtils.EMPTY_JSON;
}
callWebchatApi("Helpshift('setHelpcenterData','" + additionalInfo + "');", null);
HSLogger.d(TAG, "Called setHelpcenterData function on webchat");
} catch (Exception e) {
HSLogger.e(TAG, "Error with setHelpcenterData call", e);
}
}
@Override // com.helpshift.user_lifecyle.UserLifecycleListener
public void onUserDidLogout() {
updateWebchatConfig();
}
@Override // com.helpshift.user_lifecyle.UserLifecycleListener
public void onUserDidLogin() {
updateWebchatConfig();
}
public void setWebchatSourceChanged(String str) {
this.isWebchatSourceChanged = true;
HSLogger.d(TAG, "Webchat source changed to " + str + " from " + this.webchatSource);
this.webchatSource = str;
}
public void updateWebchatConfig() {
callWebchatApi("window.helpshiftConfig = JSON.parse(JSON.stringify(" + HSContext.getInstance().getConfigManager().getWebchatConfigJs(false) + "));Helpshift('updateHelpshiftConfig')", null);
}
@Override // com.helpshift.chat.HSWebchatToUiCallback
public void openFileChooser(Intent intent, int i) {
this.shouldSendPollerEvent = false;
startActivityForResult(intent, i);
}
@Override // androidx.fragment.app.Fragment
public void onActivityResult(int i, int i2, Intent intent) {
this.shouldSendPollerEvent = true;
HSLogger.d(TAG, "onActivityResult, request code: " + i + " , resultCode: " + i2);
if (i == 0) {
this.filePathCallback.onReceiveValue(null);
return;
}
if (i != 1001) {
super.onActivityResult(i, i2, intent);
return;
}
ValueCallback<Uri[]> valueCallback = this.filePathCallback;
if (valueCallback == null) {
HSLogger.d(TAG, "filePathCallback is null, return");
return;
}
valueCallback.onReceiveValue(WebChromeClient.FileChooserParams.parseResult(i2, intent));
this.filePathCallback = null;
this.chromeClient.setFilePathCallback(null);
}
@Override // android.view.View.OnClickListener
public void onClick(View view) {
int id = view.getId();
if (id == R$id.hs__loading_view_close_btn || id == R$id.hs__retry_view_close_btn) {
onWebchatClosed();
} else if (id == R$id.hs__retry_button) {
startChatView();
}
}
@Override // androidx.fragment.app.Fragment, android.content.ComponentCallbacks
public void onConfigurationChanged(Configuration configuration) {
super.onConfigurationChanged(configuration);
sendOrientationChangeEventToWebchat(configuration.orientation);
}
@Override // com.helpshift.util.network.connectivity.HSNetworkConnectivityCallback
public void onNetworkAvailable() {
sendNetworkConfigurationChangeEvent(CustomTabsCallback.ONLINE_EXTRAS_KEY);
}
@Override // com.helpshift.util.network.connectivity.HSNetworkConnectivityCallback
public void onNetworkUnavailable() {
sendNetworkConfigurationChangeEvent("offline");
}
private void showErrorView() {
ViewUtil.setVisibility(this.retryView, true);
ViewUtil.setVisibility(this.loadingView, false);
}
private void showWebchatView() {
ViewUtil.setVisibility(this.loadingView, false);
ViewUtil.setVisibility(this.retryView, false);
}
private void showLoadingView() {
ViewUtil.setVisibility(this.loadingView, true);
ViewUtil.setVisibility(this.retryView, false);
}
private void callWebchatApi(final String str, final ValueCallback<String> valueCallback) {
HSContext.getInstance().getHsThreadingService().runOnUIThread(new Runnable() { // from class: com.helpshift.chat.HSChatFragment.2
@Override // java.lang.Runnable
public void run() {
if (HSChatFragment.this.webView == null) {
HSLogger.d(HSChatFragment.TAG, "error callWebchatApi, webview is null");
return;
}
HSLogger.d(HSChatFragment.TAG, "Executing command: " + str);
ViewUtil.callJavascriptCode(HSChatFragment.this.webView, str, valueCallback);
}
});
}
public void sendLifecycleEventToWebchat(boolean z) {
callWebchatApi("Helpshift('sdkxIsInForeground'," + z + ");", null);
}
public void sendOrientationChangeEventToWebchat(int i) {
callWebchatApi("Helpshift('onOrientationChange','" + (i == 1 ? "portrait" : "landscape") + "');", null);
}
public void sendKeyboardToggleEvent(boolean z) {
callWebchatApi("Helpshift('onKeyboardToggle','" + (!z ? "close" : MRAIDPresenter.OPEN) + "');", null);
}
public void sendTimeToLoadWebchatEvent(String str) {
callWebchatApi("Helpshift('nativeLoadTime','" + str + "');", null);
}
public void sendNetworkConfigurationChangeEvent(String str) {
callWebchatApi("Helpshift('onNetworkStatusChange','" + str + "');", null);
}
public void handleBackPress() {
callWebchatApi("Helpshift('backBtnPress');", new ValueCallback() { // from class: com.helpshift.chat.HSChatFragment.3
@Override // android.webkit.ValueCallback
public void onReceiveValue(String str) {
HSLogger.d(HSChatFragment.TAG, "Back press handle from webchat" + str);
if (HSChatFragment.this.transactionListener != null) {
HSChatFragment.this.transactionListener.handleBackPress(Boolean.parseBoolean(str));
}
}
});
}
}

View File

@@ -0,0 +1,157 @@
package com.helpshift.chat;
import android.webkit.JavascriptInterface;
import com.helpshift.log.HSLogger;
import com.helpshift.util.Utils;
import com.tapjoy.TJAdUnitConstants;
import java.util.Iterator;
import org.json.JSONException;
import org.json.JSONObject;
/* loaded from: classes3.dex */
public class HSChatToNativeBridge {
public final HSEventProxy delegate;
public final HSChatEventsHandler eventsHandler;
public boolean isWebSdkConfigLoaded;
public HSChatToNativeBridge(HSEventProxy hSEventProxy, HSChatEventsHandler hSChatEventsHandler) {
this.delegate = hSEventProxy;
this.eventsHandler = hSChatEventsHandler;
}
@JavascriptInterface
public void sendEvent(String str) {
HSLogger.d("ChatNativeBridge", "Received event from webview.");
if (this.delegate == null || Utils.isEmpty(str)) {
return;
}
try {
JSONObject jSONObject = new JSONObject(str);
Iterator<String> keys = jSONObject.keys();
while (keys.hasNext()) {
String next = keys.next();
this.delegate.sendEvent(next, Utils.jsonStringToMap(jSONObject.optString(next, "")));
}
} catch (JSONException e) {
HSLogger.e("ChatNativeBridge", "Error in sending public event", e);
}
}
@JavascriptInterface
public void widgetToggle(String str) {
HSLogger.d("ChatNativeBridge", "webchat widget toggle: " + str);
if (Utils.isEmpty(str) || !this.isWebSdkConfigLoaded) {
return;
}
try {
if (new JSONObject(str).optBoolean(TJAdUnitConstants.String.VISIBLE, false)) {
this.eventsHandler.onWebchatLoaded();
} else {
this.eventsHandler.onWebchatClosed();
}
} catch (JSONException e) {
HSLogger.e("ChatNativeBridge", "Error in closing the webchat", e);
}
}
@JavascriptInterface
public void onWebSdkConfigLoad() {
HSLogger.d("ChatNativeBridge", "Received event when web sdk config loaded");
if (this.isWebSdkConfigLoaded) {
return;
}
this.isWebSdkConfigLoaded = true;
this.eventsHandler.onWebchatLoaded();
}
@JavascriptInterface
public void setIssueExistsFlag(String str) {
HSLogger.d("ChatNativeBridge", "Received event to set the issue exist as -" + str);
this.eventsHandler.setIssueExistsForUser(str);
}
@JavascriptInterface
public void setLocalStorage(String str) {
HSLogger.d("ChatNativeBridge", "Received event to set data in local store from webview.");
this.eventsHandler.onSetLocalStorage(str);
}
@JavascriptInterface
public void removeLocalStorage(String str) {
HSLogger.d("ChatNativeBridge", "Received event to remove data from local store from webview.");
this.eventsHandler.onRemoveLocalStorage(str);
}
@JavascriptInterface
public void getHelpcenterData() {
HSLogger.d("ChatNativeBridge", "Received event to get Aditional info of HC from WC from webview.");
this.eventsHandler.getHelpcenterData();
}
@JavascriptInterface
public void onWebchatError() {
HSLogger.d("ChatNativeBridge", "Received error from webview.");
this.eventsHandler.onWebchatError();
}
@JavascriptInterface
public void sendPushTokenSyncRequestData(String str) {
this.eventsHandler.onReceivePushTokenSyncRequestData(str);
}
@JavascriptInterface
public void onUIConfigChange(String str) {
this.eventsHandler.onUiConfigChange(str);
}
@JavascriptInterface
public void sendUserAuthFailureEvent(String str) {
if (this.delegate == null || Utils.isEmpty(str)) {
return;
}
String str2 = "Authentication Failure";
try {
JSONObject jSONObject = new JSONObject(str);
if (jSONObject.has("message")) {
String string = jSONObject.getString("message");
if (!Utils.isEmpty(string.trim())) {
str2 = string;
}
}
} catch (Exception unused) {
HSLogger.e("ChatNativeBridge", "Error in reading auth failure event ");
}
this.eventsHandler.onUserAuthenticationFailure();
this.delegate.sendAuthFailureEvent(str2);
}
@JavascriptInterface
public void onRemoveAnonymousUser() {
this.eventsHandler.onRemoveAnonymousUser();
}
@JavascriptInterface
public void setPollingStatus(String str) {
this.eventsHandler.setPollingStatus(str);
}
@JavascriptInterface
public void setGenericSdkData(String str) {
this.eventsHandler.setGenericSdkData(str);
}
@JavascriptInterface
public void sdkxMigrationLogSynced(boolean z) {
this.eventsHandler.sdkxMigrationLogSynced(z);
}
@JavascriptInterface
public void requestConversationMetadata(String str) {
this.eventsHandler.requestConversationMetadata(str);
}
@JavascriptInterface
public void webchatJsFileLoaded() {
this.eventsHandler.webchatJsFileLoaded();
}
}

View File

@@ -0,0 +1,92 @@
package com.helpshift.chat;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.net.Uri;
import android.os.Message;
import android.webkit.ConsoleMessage;
import android.webkit.ValueCallback;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import com.helpshift.log.HSLogger;
import com.helpshift.log.WebviewConsoleLogger;
import com.helpshift.util.Utils;
/* loaded from: classes3.dex */
public class HSChatWebChromeClient extends WebChromeClient {
public final HSChatEventsHandler eventsHandler;
public ValueCallback filePathCallback;
public void setFilePathCallback(ValueCallback valueCallback) {
this.filePathCallback = valueCallback;
}
public HSChatWebChromeClient(HSChatEventsHandler hSChatEventsHandler) {
this.eventsHandler = hSChatEventsHandler;
}
@Override // android.webkit.WebChromeClient
public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
WebviewConsoleLogger.log(consoleMessage.messageLevel(), "chatWVClient", consoleMessage.message() + " -- From line " + consoleMessage.lineNumber() + " of " + consoleMessage.sourceId());
return super.onConsoleMessage(consoleMessage);
}
@Override // android.webkit.WebChromeClient
public boolean onCreateWindow(WebView webView, boolean z, boolean z2, Message message) {
if (!z2) {
return false;
}
WebView.HitTestResult hitTestResult = webView.getHitTestResult();
String createUriForSystemAppLaunch = createUriForSystemAppLaunch(hitTestResult.getType(), hitTestResult.getExtra());
if (Utils.isNotEmpty(createUriForSystemAppLaunch)) {
this.eventsHandler.sendIntentToSystemApp(new Intent("android.intent.action.VIEW", Uri.parse(createUriForSystemAppLaunch)));
return true;
}
WebView webView2 = new WebView(webView.getContext());
this.eventsHandler.addWebviewToCurrentUI(webView2);
((WebView.WebViewTransport) message.obj).setWebView(webView2);
message.sendToTarget();
return true;
}
public final String createUriForSystemAppLaunch(int i, String str) {
if (i != 2) {
return i != 7 ? "" : str;
}
return "tel:" + str;
}
@Override // android.webkit.WebChromeClient
public boolean onShowFileChooser(WebView webView, ValueCallback valueCallback, WebChromeClient.FileChooserParams fileChooserParams) {
if (this.filePathCallback != null) {
HSLogger.d("chatWVClient", "filePathCallback is not null, returning false.");
this.filePathCallback.onReceiveValue(null);
this.filePathCallback = null;
return false;
}
this.filePathCallback = valueCallback;
this.eventsHandler.setAttachmentFilePathCallback(valueCallback);
try {
Intent createIntent = fileChooserParams.createIntent();
createIntent.setType("*/*");
String[] acceptTypes = fileChooserParams.getAcceptTypes();
if (acceptTypes.length != 0) {
createIntent.putExtra("android.intent.extra.MIME_TYPES", acceptTypes);
}
createIntent.setAction("android.intent.action.OPEN_DOCUMENT");
createIntent.addCategory("android.intent.category.OPENABLE");
HSLogger.d("chatWVClient", "Starting open file chooser request.");
this.eventsHandler.openFileChooser(createIntent, 1001);
HSLogger.d("chatWVClient", "onShowFileChooser success, returning true");
return true;
} catch (ActivityNotFoundException e) {
HSLogger.e("chatWVClient", "ActivityNotFoundException error in opening the attachment file chooser.", e);
this.filePathCallback = null;
return true;
} catch (Exception e2) {
HSLogger.e("chatWVClient", "error in opening the attachment in browser window, returning false", e2);
this.filePathCallback = null;
return false;
}
}
}

View File

@@ -0,0 +1,59 @@
package com.helpshift.chat;
import android.content.Intent;
import android.net.Uri;
import android.webkit.WebResourceRequest;
import android.webkit.WebResourceResponse;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import com.helpshift.cache.HelpshiftResourceCacheManager;
import com.helpshift.log.HSLogger;
import com.helpshift.util.ResourceCacheUtil;
/* loaded from: classes3.dex */
public class HSChatWebViewClient extends WebViewClient {
public final HelpshiftResourceCacheManager chatResourceCacheManager;
public final HSChatEventsHandler eventsHandler;
public boolean resourceCacheManagerInitialized;
public HSChatWebViewClient(HSChatEventsHandler hSChatEventsHandler, HelpshiftResourceCacheManager helpshiftResourceCacheManager) {
this.eventsHandler = hSChatEventsHandler;
this.chatResourceCacheManager = helpshiftResourceCacheManager;
}
@Override // android.webkit.WebViewClient
public boolean shouldOverrideUrlLoading(WebView webView, String str) {
this.eventsHandler.sendIntentToSystemApp(new Intent("android.intent.action.VIEW", Uri.parse(str)));
return true;
}
@Override // android.webkit.WebViewClient
public WebResourceResponse shouldInterceptRequest(WebView webView, WebResourceRequest webResourceRequest) {
if (!"GET".equalsIgnoreCase(webResourceRequest.getMethod())) {
return super.shouldInterceptRequest(webView, webResourceRequest);
}
initResourceCacheManager();
if (!this.chatResourceCacheManager.shouldCacheUrl(webResourceRequest.getUrl().getPath())) {
return super.shouldInterceptRequest(webView, webResourceRequest);
}
WebResourceResponse webResourceResponse = ResourceCacheUtil.getWebResourceResponse(this.chatResourceCacheManager, webResourceRequest);
if (webResourceResponse != null) {
return webResourceResponse;
}
WebResourceResponse shouldInterceptRequest = super.shouldInterceptRequest(webView, webResourceRequest);
if (shouldInterceptRequest != null) {
HSLogger.d("ChatWebClient", "Webview response received for request-" + webResourceRequest.toString() + " status:" + shouldInterceptRequest.getStatusCode() + " MimeType:" + shouldInterceptRequest.getMimeType());
} else {
HSLogger.e("ChatWebClient", "Webview response error for request-" + webResourceRequest.getUrl());
}
return shouldInterceptRequest;
}
public final void initResourceCacheManager() {
if (this.resourceCacheManagerInitialized) {
return;
}
this.chatResourceCacheManager.ensureCacheURLsListAvailable();
this.resourceCacheManagerInitialized = true;
}
}

View File

@@ -0,0 +1,53 @@
package com.helpshift.chat;
import com.helpshift.HelpshiftAuthenticationFailureReason;
import com.helpshift.HelpshiftEventsListener;
import com.helpshift.concurrency.HSThreadingService;
import com.helpshift.log.HSLogger;
import java.util.Map;
/* loaded from: classes3.dex */
public class HSEventProxy {
public HelpshiftEventsListener eventsListener;
public final HSThreadingService hsThreadingService;
public void setHelpshiftEventsListener(HelpshiftEventsListener helpshiftEventsListener) {
this.eventsListener = helpshiftEventsListener;
}
public HSEventProxy(HSThreadingService hSThreadingService) {
this.hsThreadingService = hSThreadingService;
}
public void sendEvent(final String str, final Map map) {
HSLogger.d("HSEvntPrxy", "Event occurred: " + str);
this.hsThreadingService.runOnUIThread(new Runnable() { // from class: com.helpshift.chat.HSEventProxy.1
@Override // java.lang.Runnable
public void run() {
if (HSEventProxy.this.eventsListener == null) {
return;
}
HSEventProxy.this.eventsListener.onEventOccurred(str, map);
}
});
}
public void sendAuthFailureEvent(final String str) {
HSLogger.d("HSEvntPrxy", "Authentication failure, reason: " + str);
this.hsThreadingService.runOnUIThread(new Runnable() { // from class: com.helpshift.chat.HSEventProxy.2
@Override // java.lang.Runnable
public void run() {
if (HSEventProxy.this.eventsListener == null) {
return;
}
HelpshiftAuthenticationFailureReason helpshiftAuthenticationFailureReason = HelpshiftAuthenticationFailureReason.UNKNOWN;
if ("missing user auth token".equals(str)) {
helpshiftAuthenticationFailureReason = HelpshiftAuthenticationFailureReason.REASON_AUTH_TOKEN_NOT_PROVIDED;
} else if ("invalid user auth token".equals(str)) {
helpshiftAuthenticationFailureReason = HelpshiftAuthenticationFailureReason.REASON_INVALID_AUTH_TOKEN;
}
HSEventProxy.this.eventsListener.onUserAuthenticationFailure(helpshiftAuthenticationFailureReason);
}
});
}
}

View File

@@ -0,0 +1,32 @@
package com.helpshift.chat;
import android.content.Intent;
import android.webkit.ValueCallback;
import android.webkit.WebView;
/* loaded from: classes3.dex */
public interface HSWebchatToUiCallback {
void addWebviewToCurrentUI(WebView webView);
void onUiConfigChange(String str);
void onUserAuthenticationFailure();
void onWebchatClosed();
void onWebchatError();
void onWebchatLoaded();
void openFileChooser(Intent intent, int i);
void requestConversationMetadata(String str);
void sendIntentToSystemApp(Intent intent);
void setAttachmentFilePathCallback(ValueCallback valueCallback);
void setHelpcenterData();
void webchatJsFileLoaded();
}