Apk Done v1.0版本的 MD5 值为:44cfb8e1ce639995aa7f0de6a3a6388b
以下内容为反编译后的 WebViewManager.java 源代码,内容仅作参考
package com.onesignal;
import android.app.Activity;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.util.Base64;
import android.webkit.JavascriptInterface;
import android.webkit.ValueCallback;
import android.webkit.WebView;
import com.onesignal.ActivityLifecycleHandler;
import com.onesignal.InAppMessageView;
import com.onesignal.OneSignal;
import io.bidmachine.utils.IabUtils;
import java.io.UnsupportedEncodingException;
import org.json.JSONException;
import org.json.JSONObject;
public class WebViewManager extends ActivityLifecycleHandler.ActivityAvailableListener {
private Activity activity;
private OSInAppMessageInternal message;
private OSInAppMessageContent messageContent;
private InAppMessageView messageView;
private OSWebView webView;
private static final String TAG = WebViewManager.class.getCanonicalName();
private static final int MARGIN_PX_SIZE = OSViewUtils.dpToPx(24);
protected static WebViewManager lastInstance = null;
private final Object messageViewSyncLock = new Object() {
};
private String currentActivityName = null;
private Integer lastPageHeight = null;
private boolean dismissFired = false;
private boolean closing = false;
public interface OneSignalGenericCallback {
void onComplete();
}
public static class AnonymousClass10 {
static final int[] $SwitchMap$com$onesignal$WebViewManager$Position;
static {
int[] iArr = new int[Position.values().length];
$SwitchMap$com$onesignal$WebViewManager$Position = iArr;
try {
iArr[Position.TOP_BANNER.ordinal()] = 1;
} catch (NoSuchFieldError unused) {
}
try {
$SwitchMap$com$onesignal$WebViewManager$Position[Position.BOTTOM_BANNER.ordinal()] = 2;
} catch (NoSuchFieldError unused2) {
}
}
}
public enum Position {
TOP_BANNER,
BOTTOM_BANNER,
CENTER_MODAL,
FULL_SCREEN;
public boolean isBanner() {
int i = AnonymousClass10.$SwitchMap$com$onesignal$WebViewManager$Position[ordinal()];
return i == 1 || i == 2;
}
}
protected WebViewManager(OSInAppMessageInternal oSInAppMessageInternal, Activity activity, OSInAppMessageContent oSInAppMessageContent) {
this.message = oSInAppMessageInternal;
this.activity = activity;
this.messageContent = oSInAppMessageContent;
}
public static void showMessageContent(final OSInAppMessageInternal oSInAppMessageInternal, final OSInAppMessageContent oSInAppMessageContent) {
final Activity currentActivity = OneSignal.getCurrentActivity();
OneSignal.LOG_LEVEL log_level = OneSignal.LOG_LEVEL.DEBUG;
OneSignal.onesignalLog(log_level, "in app message showMessageContent on currentActivity: " + currentActivity);
if (currentActivity != null) {
if (lastInstance != null && oSInAppMessageInternal.isPreview) {
lastInstance.dismissAndAwaitNextMessage(new OneSignalGenericCallback() {
@Override
public void onComplete() {
WebViewManager.lastInstance = null;
WebViewManager.initInAppMessage(currentActivity, oSInAppMessageInternal, oSInAppMessageContent);
}
});
return;
} else {
initInAppMessage(currentActivity, oSInAppMessageInternal, oSInAppMessageContent);
return;
}
}
Looper.prepare();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
WebViewManager.showMessageContent(OSInAppMessageInternal.this, oSInAppMessageContent);
}
}, 200L);
}
public static void dismissCurrentInAppMessage() {
OneSignal.LOG_LEVEL log_level = OneSignal.LOG_LEVEL.DEBUG;
OneSignal.onesignalLog(log_level, "WebViewManager IAM dismissAndAwaitNextMessage lastInstance: " + lastInstance);
WebViewManager webViewManager = lastInstance;
if (webViewManager != null) {
webViewManager.dismissAndAwaitNextMessage(null);
}
}
private static void setContentSafeAreaInsets(OSInAppMessageContent oSInAppMessageContent, Activity activity) {
String contentHtml = oSInAppMessageContent.getContentHtml();
int[] cutoutAndStatusBarInsets = OSViewUtils.getCutoutAndStatusBarInsets(activity);
String format = String.format("\n\n<script>\n setSafeAreaInsets(%s);\n</script>", String.format("{\n top: %d,\n bottom: %d,\n right: %d,\n left: %d,\n}", Integer.valueOf(cutoutAndStatusBarInsets[0]), Integer.valueOf(cutoutAndStatusBarInsets[1]), Integer.valueOf(cutoutAndStatusBarInsets[2]), Integer.valueOf(cutoutAndStatusBarInsets[3])));
oSInAppMessageContent.setContentHtml(contentHtml + format);
}
public static void initInAppMessage(final Activity activity, OSInAppMessageInternal oSInAppMessageInternal, final OSInAppMessageContent oSInAppMessageContent) {
if (oSInAppMessageContent.isFullBleed()) {
setContentSafeAreaInsets(oSInAppMessageContent, activity);
}
try {
final String encodeToString = Base64.encodeToString(oSInAppMessageContent.getContentHtml().getBytes("UTF-8"), 2);
WebViewManager webViewManager = new WebViewManager(oSInAppMessageInternal, activity, oSInAppMessageContent);
lastInstance = webViewManager;
OSUtils.runOnMainUIThread(new Runnable() {
@Override
public void run() {
try {
WebViewManager.this.setupWebView(activity, encodeToString, oSInAppMessageContent.isFullBleed());
} catch (Exception e) {
if (e.getMessage() != null && e.getMessage().contains("No WebView installed")) {
OneSignal.Log(OneSignal.LOG_LEVEL.ERROR, "Error setting up WebView: ", e);
return;
}
throw e;
}
}
});
} catch (UnsupportedEncodingException e) {
OneSignal.Log(OneSignal.LOG_LEVEL.ERROR, "Catch on initInAppMessage: ", e);
e.printStackTrace();
}
}
public class OSJavaScriptInterface {
OSJavaScriptInterface() {
}
@JavascriptInterface
public void postMessage(String str) {
try {
OneSignal.LOG_LEVEL log_level = OneSignal.LOG_LEVEL.DEBUG;
OneSignal.onesignalLog(log_level, "OSJavaScriptInterface:postMessage: " + str);
JSONObject jSONObject = new JSONObject(str);
String string = jSONObject.getString("type");
char c = 65535;
switch (string.hashCode()) {
case -1484226720:
if (string.equals("page_change")) {
c = 3;
break;
}
break;
case -934437708:
if (string.equals("resize")) {
c = 2;
break;
}
break;
case 42998156:
if (string.equals("rendering_complete")) {
c = 0;
break;
}
break;
case 1851145598:
if (string.equals("action_taken")) {
c = 1;
break;
}
break;
}
if (c == 0) {
handleRenderComplete(jSONObject);
} else if (c != 1) {
if (c != 3) {
return;
}
handlePageChange(jSONObject);
} else if (WebViewManager.this.messageView.isDragging()) {
} else {
handleActionTaken(jSONObject);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
private void handleRenderComplete(JSONObject jSONObject) {
Position displayLocation = getDisplayLocation(jSONObject);
int pageHeightData = displayLocation == Position.FULL_SCREEN ? -1 : getPageHeightData(jSONObject);
boolean dragToDismissDisabled = getDragToDismissDisabled(jSONObject);
WebViewManager.this.messageContent.setDisplayLocation(displayLocation);
WebViewManager.this.messageContent.setPageHeight(pageHeightData);
WebViewManager.this.createNewInAppMessageView(dragToDismissDisabled);
}
private int getPageHeightData(JSONObject jSONObject) {
try {
return WebViewManager.this.pageRectToViewHeight(WebViewManager.this.activity, jSONObject.getJSONObject("pageMetaData"));
} catch (JSONException unused) {
return -1;
}
}
private Position getDisplayLocation(JSONObject jSONObject) {
Position position = Position.FULL_SCREEN;
try {
return (!jSONObject.has("displayLocation") || jSONObject.get("displayLocation").equals("")) ? position : Position.valueOf(jSONObject.optString("displayLocation", "FULL_SCREEN").toUpperCase());
} catch (JSONException e) {
e.printStackTrace();
return position;
}
}
private boolean getDragToDismissDisabled(JSONObject jSONObject) {
try {
return jSONObject.getBoolean("dragToDismissDisabled");
} catch (JSONException unused) {
return false;
}
}
private void handleActionTaken(JSONObject jSONObject) throws JSONException {
JSONObject jSONObject2 = jSONObject.getJSONObject("body");
String optString = jSONObject2.optString("id", null);
WebViewManager.this.closing = jSONObject2.getBoolean("close");
if (WebViewManager.this.message.isPreview) {
OneSignal.getInAppMessageController().onMessageActionOccurredOnPreview(WebViewManager.this.message, jSONObject2);
} else if (optString != null) {
OneSignal.getInAppMessageController().onMessageActionOccurredOnMessage(WebViewManager.this.message, jSONObject2);
}
if (WebViewManager.this.closing) {
WebViewManager.this.dismissAndAwaitNextMessage(null);
}
}
private void handlePageChange(JSONObject jSONObject) throws JSONException {
OneSignal.getInAppMessageController().onPageChanged(WebViewManager.this.message, jSONObject);
}
}
public int pageRectToViewHeight(Activity activity, JSONObject jSONObject) {
try {
int dpToPx = OSViewUtils.dpToPx(jSONObject.getJSONObject("rect").getInt(IabUtils.KEY_HEIGHT));
OneSignal.LOG_LEVEL log_level = OneSignal.LOG_LEVEL.DEBUG;
OneSignal.onesignalLog(log_level, "getPageHeightData:pxHeight: " + dpToPx);
int webViewMaxSizeY = getWebViewMaxSizeY(activity);
if (dpToPx > webViewMaxSizeY) {
OneSignal.LOG_LEVEL log_level2 = OneSignal.LOG_LEVEL.DEBUG;
OneSignal.Log(log_level2, "getPageHeightData:pxHeight is over screen max: " + webViewMaxSizeY);
return webViewMaxSizeY;
}
return dpToPx;
} catch (JSONException e) {
OneSignal.Log(OneSignal.LOG_LEVEL.ERROR, "pageRectToViewHeight could not get page height", e);
return -1;
}
}
public void updateSafeAreaInsets() {
OSUtils.runOnMainUIThread(new Runnable() {
@Override
public void run() {
int[] cutoutAndStatusBarInsets = OSViewUtils.getCutoutAndStatusBarInsets(WebViewManager.this.activity);
WebViewManager.this.webView.evaluateJavascript(String.format("setSafeAreaInsets(%s)", String.format("{\n top: %d,\n bottom: %d,\n right: %d,\n left: %d,\n}", Integer.valueOf(cutoutAndStatusBarInsets[0]), Integer.valueOf(cutoutAndStatusBarInsets[1]), Integer.valueOf(cutoutAndStatusBarInsets[2]), Integer.valueOf(cutoutAndStatusBarInsets[3]))), null);
}
});
}
private void calculateHeightAndShowWebViewAfterNewActivity() {
InAppMessageView inAppMessageView = this.messageView;
if (inAppMessageView == null) {
return;
}
if (inAppMessageView.getDisplayPosition() == Position.FULL_SCREEN && !this.messageContent.isFullBleed()) {
showMessageView(null);
return;
}
OneSignal.Log(OneSignal.LOG_LEVEL.DEBUG, "In app message new activity, calculate height and show ");
OSViewUtils.decorViewReady(this.activity, new Runnable() {
@Override
public void run() {
WebViewManager webViewManager = WebViewManager.this;
webViewManager.setWebViewToMaxSize(webViewManager.activity);
if (WebViewManager.this.messageContent.isFullBleed()) {
WebViewManager.this.updateSafeAreaInsets();
}
WebViewManager.this.webView.evaluateJavascript("getPageMetaData()", new ValueCallback<String>() {
@Override
public void onReceiveValue(String str) {
try {
WebViewManager.this.showMessageView(Integer.valueOf(WebViewManager.this.pageRectToViewHeight(WebViewManager.this.activity, new JSONObject(str))));
} catch (JSONException e) {
e.printStackTrace();
}
}
});
}
});
}
@Override
void available(Activity activity) {
String str = this.currentActivityName;
this.activity = activity;
this.currentActivityName = activity.getLocalClassName();
OneSignal.LOG_LEVEL log_level = OneSignal.LOG_LEVEL.DEBUG;
OneSignal.Log(log_level, "In app message activity available currentActivityName: " + this.currentActivityName + " lastActivityName: " + str);
if (str == null) {
showMessageView(null);
} else if (!str.equals(this.currentActivityName)) {
if (this.closing) {
return;
}
InAppMessageView inAppMessageView = this.messageView;
if (inAppMessageView != null) {
inAppMessageView.removeAllViews();
}
showMessageView(this.lastPageHeight);
} else {
calculateHeightAndShowWebViewAfterNewActivity();
}
}
@Override
void stopped(Activity activity) {
OneSignal.LOG_LEVEL log_level = OneSignal.LOG_LEVEL.DEBUG;
OneSignal.Log(log_level, "In app message activity stopped, cleaning views, currentActivityName: " + this.currentActivityName + "\nactivity: " + this.activity + "\nmessageView: " + this.messageView);
if (this.messageView == null || !activity.getLocalClassName().equals(this.currentActivityName)) {
return;
}
this.messageView.removeAllViews();
}
public void showMessageView(Integer num) {
synchronized (this.messageViewSyncLock) {
if (this.messageView == null) {
OneSignal.Log(OneSignal.LOG_LEVEL.WARN, "No messageView found to update a with a new height.");
return;
}
OneSignal.LOG_LEVEL log_level = OneSignal.LOG_LEVEL.DEBUG;
OneSignal.Log(log_level, "In app message, showing first one with height: " + num);
this.messageView.setWebView(this.webView);
if (num != null) {
this.lastPageHeight = num;
this.messageView.updateHeight(num.intValue());
}
this.messageView.showView(this.activity);
this.messageView.checkIfShouldDismiss();
}
}
public void setupWebView(final Activity activity, final String str, boolean z) {
enableWebViewRemoteDebugging();
OSWebView oSWebView = new OSWebView(activity);
this.webView = oSWebView;
oSWebView.setOverScrollMode(2);
this.webView.setVerticalScrollBarEnabled(false);
this.webView.setHorizontalScrollBarEnabled(false);
this.webView.getSettings().setJavaScriptEnabled(true);
this.webView.addJavascriptInterface(new OSJavaScriptInterface(), "OSAndroid");
if (z) {
this.webView.setSystemUiVisibility(3074);
if (Build.VERSION.SDK_INT >= 30) {
this.webView.setFitsSystemWindows(false);
}
}
blurryRenderingWebViewForKitKatWorkAround(this.webView);
OSViewUtils.decorViewReady(activity, new Runnable() {
@Override
public void run() {
WebViewManager.this.setWebViewToMaxSize(activity);
WebViewManager.this.webView.loadData(str, "text/html; charset=utf-8", "base64");
}
});
}
private void blurryRenderingWebViewForKitKatWorkAround(WebView webView) {
if (Build.VERSION.SDK_INT == 19) {
webView.setLayerType(1, null);
}
}
public void setWebViewToMaxSize(Activity activity) {
this.webView.layout(0, 0, getWebViewMaxSizeX(activity), getWebViewMaxSizeY(activity));
}
public void setMessageView(InAppMessageView inAppMessageView) {
synchronized (this.messageViewSyncLock) {
this.messageView = inAppMessageView;
}
}
public void createNewInAppMessageView(boolean z) {
this.lastPageHeight = Integer.valueOf(this.messageContent.getPageHeight());
setMessageView(new InAppMessageView(this.webView, this.messageContent, z));
this.messageView.setMessageController(new InAppMessageView.InAppMessageViewListener() {
@Override
public void onMessageWasShown() {
OneSignal.getInAppMessageController().onMessageWasShown(WebViewManager.this.message);
}
@Override
public void onMessageWillDismiss() {
OneSignal.getInAppMessageController().onMessageWillDismiss(WebViewManager.this.message);
}
@Override
public void onMessageWasDismissed() {
OneSignal.getInAppMessageController().messageWasDismissed(WebViewManager.this.message);
WebViewManager.this.removeActivityListener();
}
});
ActivityLifecycleHandler activityLifecycleHandler = ActivityLifecycleListener.getActivityLifecycleHandler();
if (activityLifecycleHandler != null) {
activityLifecycleHandler.addActivityAvailableListener(TAG + this.message.messageId, this);
}
}
private static void enableWebViewRemoteDebugging() {
if (Build.VERSION.SDK_INT < 19 || !OneSignal.atLogLevel(OneSignal.LOG_LEVEL.DEBUG)) {
return;
}
WebView.setWebContentsDebuggingEnabled(true);
}
private int getWebViewMaxSizeX(Activity activity) {
if (this.messageContent.isFullBleed()) {
return OSViewUtils.getFullbleedWindowWidth(activity);
}
return OSViewUtils.getWindowWidth(activity) - (MARGIN_PX_SIZE * 2);
}
private int getWebViewMaxSizeY(Activity activity) {
return OSViewUtils.getWindowHeight(activity) - (this.messageContent.isFullBleed() ? 0 : MARGIN_PX_SIZE * 2);
}
public void removeActivityListener() {
ActivityLifecycleHandler activityLifecycleHandler = ActivityLifecycleListener.getActivityLifecycleHandler();
if (activityLifecycleHandler != null) {
activityLifecycleHandler.removeActivityAvailableListener(TAG + this.message.messageId);
}
}
protected void dismissAndAwaitNextMessage(final OneSignalGenericCallback oneSignalGenericCallback) {
InAppMessageView inAppMessageView = this.messageView;
if (inAppMessageView == null || this.dismissFired) {
if (oneSignalGenericCallback != null) {
oneSignalGenericCallback.onComplete();
return;
}
return;
}
if (this.message != null && inAppMessageView != null) {
OneSignal.getInAppMessageController().onMessageWillDismiss(this.message);
}
this.messageView.dismissAndAwaitNextMessage(new OneSignalGenericCallback() {
@Override
public void onComplete() {
WebViewManager.this.dismissFired = false;
WebViewManager.this.setMessageView(null);
OneSignalGenericCallback oneSignalGenericCallback2 = oneSignalGenericCallback;
if (oneSignalGenericCallback2 != null) {
oneSignalGenericCallback2.onComplete();
}
}
});
this.dismissFired = true;
}
}