Skip to content

Commit 574a6c7

Browse files
AndrewJackGabriel Peal
authored andcommitted
Android Oreo (8.0) Support
Summary: Apps targeting Android 8.0 (API level 26) cannot use `TYPE_SYSTEM_OVERLAY ` and `TYPE_SYSTEM_OVERLAY `. Targeting 26 will cause the app to crash when in `DEV_MODE`. https://developer.android.com/about/versions/oreo/android-8.0-changes.html#cwt This PR replaces uses of these overlay flags with the new `TYPE_APPLICATION_OVERLAY` when running on a device with Android 8.0 or later. When using `TYPE_APPLICATION_OVERLAY` it still requires the `SYSTEM_ALERT_WINDOW` permission, just like previous android versions. https://developer.android.com/reference/android/view/WindowManager.LayoutParams.html#TYPE_APPLICATION_OVERLAY https://github.com/AndrewJack/react-native-android-oreo tested here Closes facebook#15601 Reviewed By: achen1 Differential Revision: D5801619 Pulled By: shergin fbshipit-source-id: 27d1b9bb64018e7f12f9c3d3d222f1fda468b124
1 parent b2a8323 commit 574a6c7

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

ReactAndroid/src/main/java/com/facebook/react/devsupport/DebugOverlayController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public void setFpsDebugViewVisible(boolean fpsDebugViewVisible) {
4040
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
4141
WindowManager.LayoutParams.MATCH_PARENT,
4242
WindowManager.LayoutParams.MATCH_PARENT,
43-
WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
43+
WindowOverlayCompat.TYPE_SYSTEM_OVERLAY,
4444
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
4545
| WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
4646
PixelFormat.TRANSLUCENT);

ReactAndroid/src/main/java/com/facebook/react/devsupport/DevLoadingViewController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ private void setVisible(boolean visible) {
138138
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
139139
WindowManager.LayoutParams.MATCH_PARENT,
140140
WindowManager.LayoutParams.WRAP_CONTENT,
141-
WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
141+
WindowOverlayCompat.TYPE_SYSTEM_OVERLAY,
142142
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
143143
PixelFormat.TRANSLUCENT);
144144
params.gravity = Gravity.TOP;

ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerImpl.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import android.hardware.SensorManager;
3535
import android.net.Uri;
3636
import android.os.AsyncTask;
37-
import android.view.WindowManager;
3837
import android.widget.Toast;
3938

4039
import com.facebook.common.logging.FLog;
@@ -331,7 +330,7 @@ private void showNewError(
331330
public void run() {
332331
if (mRedBoxDialog == null) {
333332
mRedBoxDialog = new RedBoxDialog(mApplicationContext, DevSupportManagerImpl.this, mRedBoxHandler);
334-
mRedBoxDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
333+
mRedBoxDialog.getWindow().setType(WindowOverlayCompat.TYPE_SYSTEM_ALERT);
335334
}
336335
if (mRedBoxDialog.isShowing()) {
337336
// Sometimes errors cause multiple errors to be thrown in JS in quick succession. Only
@@ -473,7 +472,7 @@ public void onCancel(DialogInterface dialog) {
473472
}
474473
})
475474
.create();
476-
mDevOptionsDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
475+
mDevOptionsDialog.getWindow().setType(WindowOverlayCompat.TYPE_SYSTEM_ALERT);
477476
mDevOptionsDialog.show();
478477
}
479478

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.facebook.react.devsupport;
2+
3+
import android.os.Build;
4+
import android.view.WindowManager;
5+
6+
/**
7+
* Compatibility wrapper for apps targeting API level 26 or later.
8+
* See https://developer.android.com/about/versions/oreo/android-8.0-changes.html#cwt
9+
*/
10+
/* package */ class WindowOverlayCompat {
11+
12+
private static final int ANDROID_OREO = 26;
13+
private static final int TYPE_APPLICATION_OVERLAY = 2038;
14+
15+
static final int TYPE_SYSTEM_ALERT = Build.VERSION.SDK_INT < ANDROID_OREO ? WindowManager.LayoutParams.TYPE_SYSTEM_ALERT : TYPE_APPLICATION_OVERLAY;
16+
static final int TYPE_SYSTEM_OVERLAY = Build.VERSION.SDK_INT < ANDROID_OREO ? WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY : TYPE_APPLICATION_OVERLAY;
17+
18+
}

0 commit comments

Comments
 (0)