diff options
author | Philip P. Moltmann <moltmann@google.com> | 2018-02-14 13:55:57 -0800 |
---|---|---|
committer | Philip P. Moltmann <moltmann@google.com> | 2018-02-14 13:55:57 -0800 |
commit | 5c7d8fafa8d77cb29306791499e699a74740a2fc (patch) | |
tree | 09d76a6262e4113adcbb95211ae2285d48597267 /packages/PrintSpooler/src | |
parent | e047522ecec94e7253761cf45b94b5a9b9e6c691 (diff) |
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
Diffstat (limited to 'packages/PrintSpooler/src')
-rw-r--r-- | packages/PrintSpooler/src/com/android/printspooler/ui/PrintActivity.java | 50 |
1 files changed, 29 insertions, 21 deletions
diff --git a/packages/PrintSpooler/src/com/android/printspooler/ui/PrintActivity.java b/packages/PrintSpooler/src/com/android/printspooler/ui/PrintActivity.java index 44f68eca49a3..d73a5d73e5bf 100644 --- a/packages/PrintSpooler/src/com/android/printspooler/ui/PrintActivity.java +++ b/packages/PrintSpooler/src/com/android/printspooler/ui/PrintActivity.java @@ -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,29 +3146,35 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat @Override public void onServiceConnected(ComponentName name, IBinder service) { - final IPdfEditor editor = IPdfEditor.Stub.asInterface(service); - new AsyncTask<Void, Void, String>() { - @Override - protected String doInBackground(Void... params) { - // It's OK to access the data members as they are - // final and this code is the last one to touch - // them as shredding is the very last step, so the - // UI is not interactive at this point. - try { - doTransform(editor); - updatePrintJob(); - return null; - } catch (IOException | RemoteException | IllegalStateException e) { - return e.toString(); + // 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 + protected String doInBackground(Void... params) { + // It's OK to access the data members as they are + // final and this code is the last one to touch + // them as shredding is the very last step, so the + // UI is not interactive at this point. + try { + doTransform(editor); + updatePrintJob(); + return null; + } catch (IOException | RemoteException | IllegalStateException e) { + return e.toString(); + } } - } - @Override - protected void onPostExecute(String error) { - mContext.unbindService(DocumentTransformer.this); - mCallback.accept(error); - } - }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + @Override + protected void onPostExecute(String error) { + mContext.unbindService(DocumentTransformer.this); + mCallback.accept(error); + } + }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + + mIsTransformationStarted = true; + } } @Override |