Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5c7d8faf authored by Philip P. Moltmann's avatar Philip P. Moltmann
Browse files

Do not transform again on crash

Before:

onServiceConnected
   AsyncTask 1: doInBackground
                doTransform
                   PdfEditor service crashes

system restarts PdfEditor service -> onServiceConnected
   AsyncTask 2: doInBackground
                doTransform
		onPostExecute
		   Unbind from service

   AsyncTask 1: onPostExecute
                   Unbind from service again -> crash

Hence we have to only ever create a single async task even if we get
another onServiceConnected.

Test: atest CtsPrintTestCases
Change-Id: Ia18e82fe6258bac9395557b2056645e87a752889
Fixes: 73127227
parent e047522e
Loading
Loading
Loading
Loading
+29 −21
Original line number Diff line number Diff line
@@ -3117,6 +3117,8 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat

        private final Consumer<String> mCallback;

        private boolean mIsTransformationStarted;

        public DocumentTransformer(Context context, PrintJobInfo printJob,
                MutexFileProvider fileProvider, PrintAttributes attributes,
                Consumer<String> callback) {
@@ -3144,6 +3146,9 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat

        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            // We might get several onServiceConnected if the service crashes and restarts.
            // mIsTransformationStarted makes sure that we only try once.
            if (!mIsTransformationStarted) {
                final IPdfEditor editor = IPdfEditor.Stub.asInterface(service);
                new AsyncTask<Void, Void, String>() {
                    @Override
@@ -3167,6 +3172,9 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat
                        mCallback.accept(error);
                    }
                }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);

                mIsTransformationStarted = true;
            }
        }

        @Override