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

NEW: Add Android backButtonLeavesApp to New Input #1914

Closed

Conversation

manugildev
Copy link
Collaborator

@manugildev manugildev commented Apr 24, 2024

Description

Add backButtonLeavesApp support for New Input System.

Changes made

This PR creates a new AndroidDevice that is registered during initialization. This AndroidDevice represents a handheld device, and can be use to store device specific input functions that are not part of other input devices such as the keyboard, gamepad or sensors.

We also added SetCustomCommand and GetCustomCommand used to be able to set and get respectively a payload between the InputSystem package and runtime. This is then used to set and get backButtonLeavesApp to the native runtime. This two new commands are general purpose commands, and can be used for any other input device.

backButtonLeavesApp, is just a boolean flag needed for Predictive Back Gesture (PBG) support to work on Android. This allows users to preview the destination or other result of a back gesture before fully completing it, allowing them to decide whether to continue or stay in the current view.

Notes

This new API can be used as such:

InputSystem.settings.android.backButtonLeavesApp = true;

Checklist

Before review:

  • Changelog entry added.
    • Explains the change in Changed, Fixed, Added sections.
    • For API change contains an example snippet and/or migration example.
    • FogBugz ticket attached, example ([case %number%](https://issuetracker.unity3d.com/issues/...)).
    • FogBugz is marked as "Resolved" with next release version correctly set.
  • Tests added/changed, if applicable.
    • Functional tests Area_CanDoX, Area_CanDoX_EvenIfYIsTheCase, Area_WhenIDoX_AndYHappens_ThisIsTheResult.
    • Performance tests.
    • Integration tests.
  • Docs for new/changed API's.
    • Xmldoc cross references are set correctly.
    • Added explanation how the API works.
    • Usage code examples added.
    • The manual is updated, if needed.

During merge:

  • Commit message for squash-merge is prefixed with one of the list:
    • NEW: ___.
    • FIX: ___.
    • DOCS: ___.
    • CHANGE: ___.
    • RELEASE: 1.1.0-preview.3.

@unity-cla-assistant
Copy link

unity-cla-assistant commented Apr 24, 2024

CLA assistant check
All committers have signed the CLA.

Copy link
Collaborator

@ekcoh ekcoh left a comment

Choose a reason for hiding this comment

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

@manugildev Thanks for submitting this PR. Would you mind filling in the PR template to aid the review process for this new functionality and API surface being proposed? Instructions for filling in the PR template are available in the PR itself but also here: https://github.com/Unity-Technologies/InputSystem/blob/develop/.github/pull_request_template.md
Clearly describing the purpose of the PR and motivating the changes made makes it simpler to understand and review.

In addition som initial questions:

  • This is adding a new type of device, AndroidDevice that communicates with the native backend/run-time via IOCTL command GCC. However I do not see any Unity version dependent #ifdef checks present. Is this IOCTL command available back to Unity 2019 which the Input System package is still compliant with? If not, please guard the availability of this feature under appropriate compile-time version checks if intended to just return default if runtime is not implementing the IOCTL command and document from which Unity version this is expected to work, or guard the API under a certain UNITY version to control availability.
  • Noted that CHANGELOG.md do not contain an addition under ADD section describing the addition, would it be possible to get that added?

@todi1856
Copy link
Member

P.S you probably need to some tests to validate SetCustomCommand/GetCustomCommand works fine

@manugildev manugildev force-pushed the platform/android/add-back-button-leaves-app-new-input branch from 971e6e3 to ab07662 Compare April 30, 2024 13:14
@manugildev manugildev force-pushed the platform/android/add-back-button-leaves-app-new-input branch from a28f01d to 04e1db1 Compare April 30, 2024 14:31
@manugildev manugildev force-pushed the platform/android/add-back-button-leaves-app-new-input branch 3 times, most recently from 37c9174 to 6f93df2 Compare April 30, 2024 14:50
@manugildev manugildev force-pushed the platform/android/add-back-button-leaves-app-new-input branch from 6f93df2 to 2dc6312 Compare April 30, 2024 16:10
@manugildev manugildev marked this pull request as ready for review April 30, 2024 17:05
@manugildev manugildev requested a review from ekcoh April 30, 2024 17:05
public class AndroidDevice : InputDevice
{
[InputControl(synthetic = true)]
public ButtonControl button { get; protected set; }
Copy link
Member

Choose a reason for hiding this comment

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

What's this? I see it's a public API, how would user use it ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not sure how to get rid of this ButtonControl. InputDevices need to have AT LEAST one control. If not they throw an exception. In our case, this controls is not needed

Copy link
Collaborator

Choose a reason for hiding this comment

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

@manugildev Could you provide some additional context regarding what exception/trace you did get?

Copy link
Collaborator Author

@manugildev manugildev Jun 20, 2024

Choose a reason for hiding this comment

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

@ekcoh I have tried pretty much everything but I couldn't find a way to have no ButtonControl. This is the exception I am hitting (code).

Could not create a device for 'AndroidDevice (Android)' (exception: System.InvalidOperationException: Control '/AndroidDevice' with layout 'AndroidDevice' has no size set and has no children to compute size from
 at UnityEngine.InputSystem.Layouts.InputDeviceBuilder.ComputeStateLayout (UnityEngine.InputSystem.InputControl control)
 at UnityEngine.InputSystem.Layouts.InputDeviceBuilder.InstantiateLayout (UnityEngine.InputSystem.Layouts.InputControlLayout layout, UnityEngine.InputSystem.Utilities.InternedString variants, UnityEngine.InputSystem.Utilities.InternedString name, UnityEngine.InputSystem.InputControl parent) 
 at UnityEngine.InputSystem.Layouts.InputDeviceBuilder.Setup (UnityEngine.InputSystem.Utilities.InternedString layout, UnityEngine.InputSystem.Utilities.InternedString variants, UnityEngine.InputSystem.Layouts.InputDeviceDescription deviceDescription)

There is in fact a test that check that a DeviceWithNoControls fails to be created: Controls_CanTurnControlPathIntoHumanReadableText_EvenIfLayoutCannotBeFoundOrHasErrors

@ritamerkl
Copy link
Collaborator

Add/change deprecation message to Input.bindings backButtonLeavesApp once ready to land.

Copy link
Collaborator

@ekcoh ekcoh left a comment

Choose a reason for hiding this comment

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

Left another round of review comments. Generally I struggle a bit to see how this fits API-wise. It seems like we are transforming a cross-platform interface into a OS-specific here and introducing what I assume is supposed to be a non-removable device representing the system.

Thanks for updating migration doc but I also think there is some guidance needed to explain how this boolean flag is expected to be used for the preview render feature. At the moment I do not fully understand how I should reason about this setting or what I need to do differently depending on how this flag is set. Happy to follow-up via DM or have a chat and maybe a demo that helps clarify this.

Assets/Tests/InputSystem/CoreTests_Devices.cs Outdated Show resolved Hide resolved
Assets/Tests/InputSystem/CoreTests_Devices.cs Outdated Show resolved Hide resolved
Assets/Tests/InputSystem/Plugins/AndroidTests.cs Outdated Show resolved Hide resolved
public class AndroidDevice : InputDevice
{
[InputControl(synthetic = true)]
public ButtonControl button { get; protected set; }
Copy link
Collaborator

Choose a reason for hiding this comment

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

@manugildev Could you provide some additional context regarding what exception/trace you did get?

/// Project-wide input settings for the Android platform.
/// </summary>
[Serializable]
public class AndroidSettings
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why would this be something Android specific when we advertise it as cross-platform on 3 operating systems for the UnityEngine.Input counterpart? https://docs.unity3d.com/ScriptReference/Input-backButtonLeavesApp.html

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@ekcoh backButtonLeavesApp is a legacy input setting. It's only living on Android land now, it is needed for predictive back gesture to work (which is something we have implemented for Android 14 as per Google's request).

Even if we have the code for Windows platforms still living in unity/unity, there are no supported device that has a physical back button anymore. They only had them in Windows Phones and early Windows RT tablets, none of which are supported anymore. This has been confirmed by the windows-platform team.

So it makes sense that moving into the new Input System, we only added in the only device that still has a back button functionality, Android.

@manugildev manugildev force-pushed the platform/android/add-back-button-leaves-app-new-input branch 2 times, most recently from 6b5b8fb to fb47d36 Compare June 21, 2024 15:07
@manugildev
Copy link
Collaborator Author

(force push the only contains auto formatter changes)

@manugildev manugildev force-pushed the platform/android/add-back-button-leaves-app-new-input branch from fb47d36 to 98add9b Compare June 24, 2024 09:01
@manugildev manugildev requested a review from ekcoh June 24, 2024 09:43
@manugildev
Copy link
Collaborator Author

@ekcoh I did some new changes based on the code review. Let me know if this is ready so I can proceed with landing the unity/unity PR first.

@ekcoh
Copy link
Collaborator

ekcoh commented Jun 25, 2024

Sorry for providing this feedback at this stage, but I would suggest we do not land this PR for the following reasons:

  • This API (backButtonLeavesApp), is a poor fit for a device representation. Only adds overhead and contains no streaming data and isn't tightly related to input.
  • A corresponding API backButtonLeavesApp already exists in UnityEngine.Input and seems (in native implementation) to not be tied to InputManager at all so I see no reason to have two versions of the same API?

Please let me know or DM me if there is some value you see with this additional API in addition to what already exists in Unity.Input?

@seeyam-q
Copy link

seeyam-q commented Aug 2, 2024

@ekcoh Hello I stumbled upon this thread as I was searching for the Input System's equivalent to backButtonLeavesApp. Because it is recommended to only have the new Input System enabled in the Unity project, backButtonLeavesApp in UnityEngine.Input doesn't work anymore.

It is very confusing to say "No corresponding API yet." in the Input System doc without providing a workaround to handle back button on Android, especially considering back button behavior is required by Google Play Store.

If Unity is not supporting backButtonLeavesApp in the Input System for engineering reasons, can you at least provide a work around of handling back button in the Input System in the documentation?

@manugildev
Copy link
Collaborator Author

manugildev commented Aug 5, 2024

@seeyam-q thanks for bringing this up! Actually, last friday we merged a change to make Input.backButtonLeavesApp work on the new Input System on Android.

We are expecting these changes to land in 6000.0.14f1, 2022.3.42f1 and 2021.3.43f1.

Issue Tracker Link UUM-41638

@manugildev manugildev closed this Aug 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants