[TIMOB-26157] Android: A semi-transparent or modal Window with a fixed orientation crashes on Android 8
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Medium |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2018-06-27T22:20:31.000+0000 |
Affected Version/s | Release 7.3.0 |
Fix Version/s | Release 7.3.0 |
Components | Android |
Labels | android, modal, opacity, window |
Reporter | Joshua Quick |
Assignee | Joshua Quick |
Created | 2018-06-26T00:53:35.000+0000 |
Updated | 2018-06-28T22:14:52.000+0000 |
Description
*Summary:*
An app targeting API Level 26 (aka: Android 8.0) or higher will crash with an
IllegalStateException
when opening a fixed orientation window
(ie: portrait-only or landscape-only) using properties:
* opacity
set to any value, including 1.0
* modal
set to true
* backgroundColor
with semi-transparency such as "rgba(255,0,0,138)"
*Steps to reproduce:*
Create a Titanium 7.3.0 project.
Build and run the below code on an Android 8 device.
Note that the app crashes (or hangs) on startup and fails to display the window.
Build and run on an Android 7 or older device.
Note that the app runs just fine.
var window = Ti.UI.createWindow({
opacity: 0.5,
// modal: true,
// backgroundColor: "rgba(0,0,255,128)",
orientationModes: [Ti.UI.PORTRAIT],
});
window.open();
*Notes:*
* This issue only happens when targeting API Level 26+, which Titanium does by default as of v7.3.0.
* This issue can also be reproduced by using a semitransparent backgroundColor
as well.
* You "can" use the opacity
or modal
property as long as you never use the orientationModes
property.
* You "can" use the orientationModes
property as long as you never use the opacity
or modal
properties.
* Setting the fullscreen
property to true
does *+not+* appear to work-around the issue as suggested by the exception message.
*Reason:*
Google has introduced a breaking change where you can no longer assign an orientation to a "translucent" activity window. Setting the modal
and opacity
properties causes Titanium to use a translucent themed activity window. Calling the Java setRequestedOrientation()
method on such a window will cause the following exception to be thrown.
java.lang.IllegalStateException: Only fullscreen opaque activities can request orientation
Note that this is not an issue if the app targets API Level 25 or lower on an Android 8 device. But lowering the API Level is not a valid work-around since Google Play will soon reject apps which do not target Android 8.
This issue can be seen happening to other native Android devs here...
https://stackoverflow.com/questions/48072438/java-lang-illegalstateexception-only-fullscreen-opaque-activities-can-request-o
Google's code change that introduced this issue can be seen below. See the Java ActivityRecord.setRequestedOrientation()
method.
https://github.com/aosp-mirror/platform_frameworks_base/commit/39791594560b2326625b663ed6796882900c220f#diff-960c6fdd4a4b336d98b785268b2a78ff
*Work-Arounds:*
* If you need to use the orientationModes
property, then you cannot use the modal
or opacity
properties.
* If you need to use the modal
or opacity
properties, then you cannot use the orientationModes
properties, which means the window will support all orientations.
* No other work-around is known for the moment... other than to mock your own modal/semitransparent window using views instead.
PR (master): https://github.com/appcelerator/titanium_mobile/pull/10134
Note that this PR catches the exception and logs the error. This PR does not attempt to "force" the Android OS to apply a fixed orientation to a semi-transparent or modal window. Meaning that the given orientation will be ignored and the window will use the default
SCREEN_ORIENTATION_UNSPECIFIED
setting which supports all orientations (but honors the orientation-lock setting). This appears to be something Google no longer supports (why? who knows) and we didn't want to go against the grain. The error message states that if the app is fullscreen and hides the app title bar, then fixed orientation should be allowed, but I haven't been successful in doing so yet.Can we do a 7_3_X for this?
That's the plan. Was waiting for a code review first.
PR (7.3.x): https://github.com/appcelerator/titanium_mobile/pull/10138
Verified the fix in SDK 7.3.0.v20180628132121. No crash or app hang seen. Closing. Studio Ver: 5.1.0.201806280846 SDK Ver: 7.3.0.v20180628132121 OS Ver: 4.2.13 Xcode Ver: 7.0.4 Appc NPM: 1.1.3 Appc CLI: 10.13.5 Daemon Ver: Xcode 9.4.1 Ti CLI Ver: 5.1.1 Alloy Ver: 1.12.0 Node Ver: 8.9.1 NPM Ver: 5.5.1 Java Ver: 10.0.1 Devices: ⇨ google Nexus 5 --- Android 6.0.1 ⇨ google Nexus 6P --- Android 8.1.0 Emulator: ⇨ Android 8.0.0