summaryrefslogtreecommitdiff
path: root/packages/PrintSpooler/src
diff options
context:
space:
mode:
authorPhilip P. Moltmann <moltmann@google.com>2018-02-15 17:43:01 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2018-02-15 17:43:01 +0000
commit97b0234c575a3dd53adb3d9dc250d9eedae4b636 (patch)
treeafeb31b02b55229a2fbffdf7e737024a6c04965f /packages/PrintSpooler/src
parent2acbf6ce2f93d6050f2713a6b895948f6bd6d842 (diff)
parent5c7d8fafa8d77cb29306791499e699a74740a2fc (diff)
Merge "Do not transform again on crash"
Diffstat (limited to 'packages/PrintSpooler/src')
-rw-r--r--packages/PrintSpooler/src/com/android/printspooler/ui/PrintActivity.java50
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