Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android Oreo (8.0) Support #15601

Closed
wants to merge 1 commit into from
Closed

Android Oreo (8.0) Support #15601

wants to merge 1 commit into from

Conversation

AndrewJack
Copy link
Contributor

@AndrewJack AndrewJack commented Aug 22, 2017

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

Test Plan

https://github.com/AndrewJack/react-native-android-oreo tested here

@facebook-github-bot facebook-github-bot added GH Review: review-needed CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. labels Aug 22, 2017
@AndrewJack
Copy link
Contributor Author

AndrewJack commented Aug 22, 2017

Without the changes in this PR you will see the following crash:

FATAL EXCEPTION: main
  Process: com.androido, PID: 25946
  android.view.WindowManager$BadTokenException: Unable to add window android.view.ViewRootImpl$W@49e4bdb -- permission denied for window type 2003
      at android.view.ViewRootImpl.setView(ViewRootImpl.java:789)
      at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:356)
      at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:92)
      at android.app.Dialog.show(Dialog.java:330)
      at com.facebook.react.devsupport.DevSupportManagerImpl$4.run(DevSupportManagerImpl.java:356)
      at android.os.Handler.handleCallback(Handler.java:789)
      at android.os.Handler.dispatchMessage(Handler.java:98)
      at android.os.Looper.loop(Looper.java:164)
      at android.app.ActivityThread.main(ActivityThread.java:6541)
      at java.lang.reflect.Method.invoke(Native Method)
      at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)

@pull-bot
Copy link

pull-bot commented Aug 22, 2017

@facebook-github-bot label Core Team

Generated by 🚫 dangerJS

class WindowOverlayCompat {

private static final int ANDROID_OREO = 26;
private static final int TYPE_APPLICATION_OVERLAY = 2038;
Copy link
Contributor Author

@AndrewJack AndrewJack Aug 22, 2017

Choose a reason for hiding this comment

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

Cannot use the Android constants because react native doesn't compile to v26 yet, it currently uses v23.

* Compatibility wrapper for apps targeting API level 26 or later.
* See https://developer.android.com/about/versions/o/android-8.0-changes.html#cwt
*/
class WindowOverlayCompat {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it could be useful to make this public, if you prefer not to let's just add a /* package */ comment like here for example https://github.com/AndrewJack/react-native/blob/f1cf378cf4ef3e5473fe2ace6d564be897e56a0e/ReactAndroid/src/main/java/com/facebook/react/devsupport/RedBoxDialog.java#L51

Copy link
Contributor Author

@AndrewJack AndrewJack Aug 31, 2017

Choose a reason for hiding this comment

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

I don't think it needs to be public. It's only needed in the devsupport package and I wouldn't like to encourage app developers to use this either.

I'll add /* package */

@janicduplessis
Copy link
Contributor

@shergin Looks good to me if you want to ship.

@ide ide requested a review from shergin September 2, 2017 06:28
@arpit
Copy link

arpit commented Sep 9, 2017

Any update on this? Definitely seeing this crash and the patch looks good. The CI failure seems to be unrelated to this code unless I am missing something

@facebook-github-bot facebook-github-bot added the Import Started This pull request has been imported. This does not imply the PR has been approved. label Sep 9, 2017
@facebook-github-bot
Copy link
Contributor

@shergin has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@janicduplessis
Copy link
Contributor

Thanks @AndrewJack for the PR and @shergin for shipping 🎉

ide pushed a commit to expo/react-native that referenced this pull request Sep 14, 2017
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
ide pushed a commit that referenced this pull request Sep 14, 2017
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 #15601

Reviewed By: achen1

Differential Revision: D5801619

Pulled By: shergin

fbshipit-source-id: 27d1b9bb64018e7f12f9c3d3d222f1fda468b124
ide pushed a commit to expo/react-native that referenced this pull request Sep 19, 2017
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
gpeal pushed a commit to airbnb/react-native that referenced this pull request Oct 30, 2017
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
gpeal pushed a commit to airbnb/react-native that referenced this pull request Nov 3, 2017
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
@rekha110254
Copy link

rekha110254 commented Dec 2, 2017

@AndrewJack @janicduplessis Any update on this?? I'm facing this issue.

FATAL EXCEPTION: main
Process: com.androido, PID: 25946
android.view.WindowManager$BadTokenException: Unable to add window android.view.ViewRootImpl$W@49e4bdb -- permission denied for window type 2003
at android.view.ViewRootImpl.setView(ViewRootImpl.java:789)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:356)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:92)
at android.app.Dialog.show(Dialog.java:330)
at com.facebook.react.devsupport.DevSupportManagerImpl$4.run(DevSupportManagerImpl.java:356)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)

@AndrewJack
Copy link
Contributor Author

@rekha110254 What version are you using? This was only shipped in RN 0.50.

@temitope
Copy link

@AndrewJack thanks for this PR, this bug is kicking my project in the shins. I am using RN 0.41 and wondering if there is a recommended way to incorporate this fix outside of 1) upgrading to RN 0.51 and possibly upsetting my other dependencies and 2) manually updating the source files for RN creating an unsupported unique version of the RN codebase just for me :/? Basically I am hoping and wondering if there is a way to just incorporate these changes related to the overlay or do I just need to take the upgrade plunge?
Thanks

@zaplo00
Copy link

zaplo00 commented Feb 27, 2018

is navigator.geolocation.getCurrentPosition working in Android 8? Could someone with actual device test it, whether it always returns error 3 (location timeout) or actually works with permission allowed, location services enabled and using both gps and wireless?

@rekha110254
Copy link

@AndrewJack RN 0.51.1

dryganets pushed a commit to dryganets/react-native that referenced this pull request Oct 17, 2018
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Import Started This pull request has been imported. This does not imply the PR has been approved.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants