OneDrive / onedrive-sdk-android

OneDrive SDK for Android!
https://dev.onedrive.com
Other
148 stars 52 forks source link

The SDK should use executeOnExecutor() method of AsyncTask #107

Closed blazern closed 7 years ago

blazern commented 8 years ago

Some versions of Android use a single thread for all AsyncTasks to run their onBackground(..) if the execution was started with a call of AsyncTask.execute().

A deadlock will happen if client code started an AsyncTask with AsyncTask.execute() and then performed silent login to OneDrive from AsyncTask's onBackground(..) - OneDrive SDK uses the AsyncTask.execute() method too. OneDrive's AsyncTask will wait for client's AsyncTask to finish because they are supposed to run on the same thread, but client's AsyncTask can't finish without OneDrive finishing the authorization.

If the SDK used executeOnExecutor(..) method, the problem would be solved.

daboxu commented 8 years ago

hi @blazern , would you mind sharing the detail Android versions?

blazern commented 8 years ago

@daboxu, the device had Android 6.0.1

daboxu commented 8 years ago

thanks @blazern , I modified our onedrive-explorer-android https://github.com/OneDrive/onedrive-explorer-android for reproducing it, what I did is pretty simple in PlaceholderFragment.java https://github.com/OneDrive/onedrive-explorer-android/blob/master/app/src/main/java/com/microsoft/onedrive/apiexplorer/PlaceholderFragment.java#L77:

                 catch (final UnsupportedOperationException ignored) {
                    AsyncTask.execute(new Runnable() {
                        @Override
                        public void run() {
                            app.createOneDriveClient(getActivity(), serviceCreated);
                        }
                    });
                }

WIth emulator version 6.0 and I cannot reproduce the issue. There could be two potentials to rule out: 1) the emulator does not work 2) my code is not right.

If you don't mind, please share more about the emulator and the code so we can move forward.

blazern commented 7 years ago

Sorry, but I left the place I worked for so the codebase in which I could reproduce the problem is no longer available to me. :(

daboxu commented 7 years ago

Ok, I will close this issue for now and if anyone could reproduce it, feel free to reopen it.