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

Return AuthenticationCallback results on the UI thread (if the AT/ATS call was invoked there) #1094

Closed
wants to merge 3 commits into from

Conversation

iambmelt
Copy link
Member

@iambmelt iambmelt commented Jan 17, 2018

See issue raised by #1076

This PR does not fix the issue, but adds logging to accompany newly created test cases for this problem.

Edit - PR has been updated to resolve #1076 (see commit ae859af)

Interactive Auth w/o Broker | AuthenticationCallback returns on UI Thread - Test Case 345978
Interactive Auth w/  Broker | AuthenticationCallback returns on UI Thread - Test Case 345980
Silent Auth w/o Broker      | AuthenticationCallback returns on UI Thread - Test Case 345991
Silent Auth w/  Broker      | AuthenticationCallback returns on UI Thread - Test Case 346012

@@ -320,12 +328,14 @@ private void callAcquireTokenSilent(final String resource, final String userUniq

@Override
public void onSuccess(AuthenticationResult authenticationResult) {
verifyThread();
Copy link
Contributor

Choose a reason for hiding this comment

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

furthermore, in the method body of "showMessage", could we use something similar to:
runOnUiThread(new Runnable() {
@OverRide
public void run() {
Toast.makeText(MainActivity.this, msg, Toast.LENGTH_LONG).show();
}
});

thanks

Copy link
Member

@heidijinxujia heidijinxujia left a comment

Choose a reason for hiding this comment

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

Thanks a lot for the repro and the detailed test cases. These are super helpful. Currently, it seems to be a 100% repro bug on Callback and we definitely need to deliver a fix before more customers encountering this issue.

Just an open suggestion, as we are not going to merge this PR into the release branch. I think it could be better to add the fix of this issue, like using "runOnUiThread" besides logging.

I will leave the priority to @nazukj and @addev-ashish .

@nazukj nazukj added this to the February2018 milestone Jan 19, 2018
immmediate use. Detect if call is on the UI thread: if they are, create
a Handler for that thread. If they are not: create an arbitrary Handler
and let the caller sort out the threading.
@iambmelt iambmelt changed the title Add logging to AuthenticationCallback to report which thread is used Return AuthenticationCallback results on the UI thread (if the AT/ATS call was invoked there) Jan 22, 2018
@iambmelt
Copy link
Member Author

@heidijinxujia @piqiums See commit ae859af

This commit conditionally creates the CallbackHandler on the UI thread if acquireToken or acquireTokenSilent was called on it.

@iambmelt
Copy link
Member Author

Relevant: #888 #906

@iambmelt
Copy link
Member Author

Alternatively, if the memory issue is a concern, we could consider running the following implementation through the tests and seeing how it fares

private static Handler mUiThreadHandler;
private static Handler mBackgroundHandler;

private static Handler mUiThreadHandler;
    private static Handler mBackgroundHandler;

    private synchronized Handler getHandler() {
        final Handler handler;

        if (onUiThread()) {
            if (null == mUiThreadHandler) {
                // Callback should be invoked on the UI thread.
                mUiThreadHandler = new Handler(Looper.getMainLooper());
            }

            Logger.v(TAG, "Using UI thread Handler.");
            handler = mUiThreadHandler;
        } else {
            if (null == mBackgroundHandler) {
                // We're on a background thread, so the handler can be anything...
                HandlerThread acquireTokenHandlerThread = new HandlerThread("AcquireTokenRequestHandlerThread");
                acquireTokenHandlerThread.start();
                mBackgroundHandler = new Handler(acquireTokenHandlerThread.getLooper());
            }

            Logger.v(TAG, "Using arbitrary thread Handler.");
            handler = mBackgroundHandler;
        }

        return handler;
    }

@iambmelt
Copy link
Member Author

Not a priority right now - no cycles to run stress test.

Closing.

@iambmelt iambmelt closed this Feb 22, 2018
@iambmelt iambmelt deleted the iambmelt/userappwithbroker-uithread_logging branch May 9, 2018 20:56
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.

Only the original thread that created a view hierarchy can touch its views.
4 participants