microsoftconnect / ms-intune-app-sdk-android

Intune App SDK for Android enables data protection features and mobile app management via Microsoft Intune
43 stars 17 forks source link

Qt compatibility issue (keyboard missing, black screen on resume) #108

Closed didldum closed 2 years ago

didldum commented 2 years ago

Describe the bug: When integrating the intune SDK into a Qt android application, the keyboard isn't working, and the screen is black when resuming the app after sending it to the background.

To Reproduce Steps to reproduce the behavior:

  1. Open and run attached project in Qt Creator (or install and run this apk, which is already built).
  2. Click on the text input field
  3. The keyboard should appear, but is not visible.
  4. Change to home screen of android device (without force closing the app)
  5. Open app again
  6. An empty screen appears, only the cursor hint from text input is visible.

Expected behavior: The keyboard should work, and the app should resume properly.

Screenshots and logs:

Smartphone (please complete the following information):

Intune App SDK for Android (please complete the following information):

Additional context: Our guess on the cause: The intune SDK is rewriting classes, in a similar way Qt is structured and this seems to prevent Qt from working (Qt's invokeDelegateMethod fails because methods have been moved to Intune's parent classes - QtActivity extends MAMActivity).

We are aware this is an issue only occurring in combination with Qt, and one could argue this is something to be changed on Qt's side. Since this would probably require a major rewrite on Qt's side, we think it would be good for intune to support Qt applications the way there are.

We even managed to solve the keyboard and black screen by changing the intune configuration, and excluding some classes from intune rewriting. But this is a trial and error approach, we fear might break with future updates. Also maybe some other features besides keyboard and resume might not work which we have not noticed yet.

In the attached demo, uncomment excludeClasses to make the keyboard work again.

intunemam {
    // TODO exclude QtActivity to make keyboard work again
    //excludeClasses = ['org.qtproject.qt.android.bindings.QtActivity']
    report = true
    //verify = true
}

A more verbose exclude setting with also solves the black screen is: excludeClasses = ['org.qtproject.qt.android.bindings.QtActivity','org.qtproject.qt.android.QtLayout','org.qtproject.qt.android.bindings.QtService','org.qtproject.qt.android.bindings.QtApplication','org.qtproject.qt.android.EditContextView$ContextButton','org.qtproject.qt5.android.bindings.QtActivity']

Also when the Qt project doesn't come with a custom activity (therefore intune rewriting QtActivity itself, instead of it's "App" extension), the resume usecase works fine. Only the keyboard issue exists.

didldum commented 2 years ago

Some snippets of the dex2jar code of the compiled app (not from the sample project, but the enterprise application we would like make compatible with intune). We think this snippets might related to the issue.

public class QtActivity extends MAMActivity {
...
    @Override // com.microsoft.intune.mam.client.app.MAMActivity, com.microsoft.intune.mam.client.app.HookedActivity
    public void onMAMActivityResult(int i, int i2, Intent intent) {
        if (QtApplication.m_delegateObject == null || QtApplication.onActivityResult == null) {
            if (i == 62446) {
                this.m_loader.startApp(false);
            }
            super.onMAMActivityResult(i, i2, intent);
            return;
        }
        QtApplication.invokeDelegateMethod(QtApplication.onActivityResult, Integer.valueOf(i), Integer.valueOf(i2), intent);
    }
...
    public void super_onActivityResult(int i, int i2, Intent intent) {
        super.onMAMActivityResult(i, i2, intent);
    }
public abstract class MAMActivity extends Activity implements HookedActivity {
...

    /* access modifiers changed from: protected */
    public final void onActivityResult(int i, int i2, Intent intent) {
        this.mBehavior.onActivityResult(i, i2, intent);
    }

...
    @Override // com.microsoft.intune.mam.client.app.HookedActivity
    public final void onActivityResultReal(int i, int i2, Intent intent) {
        super.onActivityResult(i, i2, intent);
    }
...    
   @Override // com.microsoft.intune.mam.client.app.HookedActivity
    public void onMAMActivityResult(int i, int i2, Intent intent) {
        this.mBehavior.onMAMActivityResult(i, i2, intent);
    }
Archit-Pikle commented 2 years ago

Hi @didldum, does this issue occur even without the keyboard? I tested the sent apk and skipped steps 2 and 3 and still got a black screen. The issue with the keyboard not appearing may be different than the black screen

didldum commented 2 years ago

Yes they occur unrelated, the cause is probably the same.

Archit-Pikle commented 2 years ago

Can you send logs from an enrolled app?

rygo-msft commented 2 years ago

If I am understanding correctly, it looks like Qt is calling some delegate function through invokeDelegateMethod(). There may be some reflection hidden within native libraries that MAM does not currently have a way to handle. Depending on how the delegate is defined, there may be a way to work around this to restore the functionality

@didldum can you share details on this delegate? Is this something the you provide as the app developer or is it part of Qt?

meghandaly commented 2 years ago

@didldum Can you share the details requested by my teammates?

didldum commented 2 years ago

@rygo-msft @meghandaly @Archit-Pikle This is the log from an enrolled device with the production app (not the minimal demo I included to showcase the issue). enrolled.log

didldum commented 2 years ago

@rygo-msft @meghandaly @Archit-Pikle Have you been able to reproduce the problem with the included sample project? Is this something you might address with a fix or change?

bannus commented 2 years ago

We're tracking this internally (bug 15188646), no other details to share currently

bannus commented 2 years ago

We do not currently have plans to support the Qt framework. The Intune SDK has been tested with native Android applications. We know that partners have incorporated the native Intune libraries into third party Android platforms, but this is not something we test. Some platforms may be trying to integrate with the same Android APIs we use, and this may make them incompatible.