Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 7.7.1

- Use reflective status bar color on pre-Android 15 (API <35) to avoid Play deprecation warnings

## 7.7.0

- Updated to use Embedded Messaging V2 endpoints
Expand Down
4 changes: 2 additions & 2 deletions OptimoveSDK/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx1536m

sdk_version=7.7.0
sdk_version_code=70700
sdk_version=7.7.1
sdk_version_code=70701
sdk_platform=Android
android.useAndroidX=true
android.enableJetifier=true
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import androidx.annotation.AnyThread;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.annotation.UiThread;

import com.optimove.android.BuildConfig;
Expand Down Expand Up @@ -161,27 +160,46 @@ private void sendToClient(String type, JSONObject data) {

String script = "window.postHostMessage(" + j.toString() + ")";

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
wv.evaluateJavascript(script, null);
} else {
wv.loadUrl("javascript:" + script);
wv.evaluateJavascript(script, null);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing the API level check for evaluateJavascript could cause crashes on devices below API 19. Should we keep the fallback to loadUrl?

Suggested change
wv.evaluateJavascript(script, null);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
wv.evaluateJavascript(script, null);
} else {
wv.loadUrl("javascript:" + script);
}

Finding type: Logical Bugs

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The SDK's minimal API is 21

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it! I'll remember that the SDK's minimal API is 21 after the PR is merged.

}

private static boolean isLegacyStatusBarColorSupported() {
return Build.VERSION.SDK_INT < 35;
}

private static int getStatusBarColorLegacy(Window window) {
if (!isLegacyStatusBarColorSupported() || window == null) {
return 0;
}
try {
java.lang.reflect.Method method = Window.class.getMethod("getStatusBarColor");
Object result = method.invoke(window);
if (result instanceof Integer) {
return (Integer) result;
}
} catch (Throwable ignored) {}
return 0;
}

@UiThread
@SuppressWarnings("deprecation")
private void setStatusBarColorForDialog(Activity currentActivity) {
if (currentActivity == null) {
private static void setStatusBarColorLegacy(Window window, int color) {
if (!isLegacyStatusBarColorSupported() || window == null) {
return;
}
try {
java.lang.reflect.Method method = Window.class.getMethod("setStatusBarColor", int.class);
method.invoke(window, color);
} catch (Throwable ignored) {}
}

if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
@UiThread
private void setStatusBarColorForDialog(Activity currentActivity) {
if (currentActivity == null) {
return;
}

Window window = currentActivity.getWindow();

prevStatusBarColor = window.getStatusBarColor();
prevStatusBarColor = getStatusBarColorLegacy(window);

int flags = window.getAttributes().flags;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
Expand All @@ -198,18 +216,17 @@ private void setStatusBarColorForDialog(Activity currentActivity) {
statusBarColor = currentActivity.getResources().getColor(R.color.statusBarColorForNotch);
}

window.setStatusBarColor(statusBarColor);
setStatusBarColorLegacy(window, statusBarColor);
}

@UiThread
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private void unsetStatusBarColorForDialog(Activity dialogActivity) {
if (dialogActivity == null) {
return;
}

Window window = dialogActivity.getWindow();
window.setStatusBarColor(prevStatusBarColor);
setStatusBarColorLegacy(window, prevStatusBarColor);

if (prevFlagTranslucentStatus) {
window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
Expand All @@ -225,7 +242,7 @@ private void closeDialog(Activity dialogActivity) {
if (dialog != null) {
dialog.setOnKeyListener(null);
dialog.dismiss();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
if (Build.VERSION.SDK_INT < 35) {
unsetStatusBarColorForDialog(dialogActivity);
}
}
Expand All @@ -243,7 +260,7 @@ private void closeDialog(Activity dialogActivity) {
@UiThread
private void showWebView(@NonNull final Activity currentActivity) {
try {
if (BuildConfig.DEBUG && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
if (BuildConfig.DEBUG) {
WebView.setWebContentsDebuggingEnabled(true);
}

Expand Down Expand Up @@ -286,9 +303,7 @@ private void showWebView(@NonNull final Activity currentActivity) {

WebSettings settings = wv.getSettings();
settings.setJavaScriptEnabled(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
settings.setMediaPlaybackRequiresUserGesture(false);
}
settings.setMediaPlaybackRequiresUserGesture(false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing the API level check for setMediaPlaybackRequiresUserGesture could cause crashes on devices below API 17. Consider adding the version check back?

Suggested change
settings.setMediaPlaybackRequiresUserGesture(false);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
settings.setMediaPlaybackRequiresUserGesture(false);
}

Finding type: Logical Bugs

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The SDK's minimal API is 21

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it! I'll remember that the SDK's minimal API is 21 after the PR is merged.


wv.addJavascriptInterface(this, JS_NAME);
wv.setWebViewClient(this);
Expand All @@ -315,7 +330,10 @@ private void closeCurrentMessage() {
@Override
public void onPageFinished(WebView view, String url) {
view.setBackgroundColor(android.graphics.Color.TRANSPARENT);
setStatusBarColorForDialog(currentActivity);
if (Build.VERSION.SDK_INT < 35) {
setStatusBarColorForDialog(currentActivity);
}

pageFinished = true;

sendCurrentMessageToClient();
Expand All @@ -324,7 +342,6 @@ public void onPageFinished(WebView view, String url) {
}

@Override
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void onReceivedHttpError(WebView view, WebResourceRequest request, WebResourceResponse errorResponse) {
super.onReceivedHttpError(view, request, errorResponse);

Expand Down Expand Up @@ -458,7 +475,7 @@ private void maybeSetNotchInsets(Context context) {
}

List<Rect> cutoutBoundingRectangles = displayCutout.getBoundingRects();
if (cutoutBoundingRectangles.size() == 0) {
if (cutoutBoundingRectangles.isEmpty()) {
return;
}

Expand Down