summaryrefslogtreecommitdiffstats
path: root/core/java
diff options
context:
space:
mode:
authorSvetoslav <svetoslavganov@google.com>2014-05-15 10:47:19 -0700
committersvetoslavganov <svetoslavganov@google.com>2014-06-06 13:33:16 -0700
commita798c0a984f29f7180883a61839f68d2cbf0c6ce (patch)
tree4e0c54dbc67f45dd3b5a243399a28a0ed0a00ed7 /core/java
parent67a0ed001dbd59cd58992508e386f6eb6fefe7ed (diff)
downloadframeworks_base-a798c0a984f29f7180883a61839f68d2cbf0c6ce.zip
frameworks_base-a798c0a984f29f7180883a61839f68d2cbf0c6ce.tar.gz
frameworks_base-a798c0a984f29f7180883a61839f68d2cbf0c6ce.tar.bz2
Refactor printing
Change-Id: I19850154ef2798afff511e4490a268ce38e8cbae
Diffstat (limited to 'core/java')
-rw-r--r--core/java/android/print/ILayoutResultCallback.aidl3
-rw-r--r--core/java/android/print/IPrintDocumentAdapter.aidl1
-rw-r--r--core/java/android/print/IWriteResultCallback.aidl3
-rw-r--r--core/java/android/print/PrintAttributes.java99
-rw-r--r--core/java/android/print/PrintManager.java566
-rw-r--r--core/java/android/print/PrinterDiscoverySession.java6
-rw-r--r--core/java/android/printservice/PrintService.java24
-rw-r--r--core/java/android/view/View.java2
-rw-r--r--core/java/com/android/internal/os/SomeArgs.java2
9 files changed, 390 insertions, 316 deletions
diff --git a/core/java/android/print/ILayoutResultCallback.aidl b/core/java/android/print/ILayoutResultCallback.aidl
index 43b8c30..68c1dac 100644
--- a/core/java/android/print/ILayoutResultCallback.aidl
+++ b/core/java/android/print/ILayoutResultCallback.aidl
@@ -16,6 +16,7 @@
package android.print;
+import android.os.ICancellationSignal;
import android.print.PrintDocumentInfo;
/**
@@ -24,6 +25,8 @@ import android.print.PrintDocumentInfo;
* @hide
*/
oneway interface ILayoutResultCallback {
+ void onLayoutStarted(ICancellationSignal cancellation, int sequence);
void onLayoutFinished(in PrintDocumentInfo info, boolean changed, int sequence);
void onLayoutFailed(CharSequence error, int sequence);
+ void onLayoutCanceled(int sequence);
}
diff --git a/core/java/android/print/IPrintDocumentAdapter.aidl b/core/java/android/print/IPrintDocumentAdapter.aidl
index 2b95c12..9d384fb 100644
--- a/core/java/android/print/IPrintDocumentAdapter.aidl
+++ b/core/java/android/print/IPrintDocumentAdapter.aidl
@@ -37,5 +37,4 @@ oneway interface IPrintDocumentAdapter {
void write(in PageRange[] pages, in ParcelFileDescriptor fd,
IWriteResultCallback callback, int sequence);
void finish();
- void cancel();
}
diff --git a/core/java/android/print/IWriteResultCallback.aidl b/core/java/android/print/IWriteResultCallback.aidl
index 8281c4e..8fb33e1 100644
--- a/core/java/android/print/IWriteResultCallback.aidl
+++ b/core/java/android/print/IWriteResultCallback.aidl
@@ -16,6 +16,7 @@
package android.print;
+import android.os.ICancellationSignal;
import android.print.PageRange;
/**
@@ -24,6 +25,8 @@ import android.print.PageRange;
* @hide
*/
oneway interface IWriteResultCallback {
+ void onWriteStarted(ICancellationSignal cancellation, int sequence);
void onWriteFinished(in PageRange[] pages, int sequence);
void onWriteFailed(CharSequence error, int sequence);
+ void onWriteCanceled(int sequence);
}
diff --git a/core/java/android/print/PrintAttributes.java b/core/java/android/print/PrintAttributes.java
index c6254e0..2810d55 100644
--- a/core/java/android/print/PrintAttributes.java
+++ b/core/java/android/print/PrintAttributes.java
@@ -151,6 +151,105 @@ public final class PrintAttributes implements Parcelable {
mColorMode = colorMode;
}
+ /**
+ * Gets whether this print attributes are in portrait orientation,
+ * which is the media size is in portrait and all orientation dependent
+ * attributes such as resolution and margins are properly adjusted.
+ *
+ * @return Whether this print attributes are in portrait.
+ *
+ * @hide
+ */
+ public boolean isPortrait() {
+ return mMediaSize.isPortrait();
+ }
+
+ /**
+ * Gets a new print attributes instance which is in portrait orientation,
+ * which is the media size is in portrait and all orientation dependent
+ * attributes such as resolution and margins are properly adjusted.
+ *
+ * @return New instance in portrait orientation if this one is in
+ * landscape, otherwise this instance.
+ *
+ * @hide
+ */
+ public PrintAttributes asPortrait() {
+ if (isPortrait()) {
+ return this;
+ }
+
+ PrintAttributes attributes = new PrintAttributes();
+
+ // Rotate the media size.
+ attributes.setMediaSize(getMediaSize().asPortrait());
+
+ // Rotate the resolution.
+ Resolution oldResolution = getResolution();
+ Resolution newResolution = new Resolution(
+ oldResolution.getId(),
+ oldResolution.getLabel(),
+ oldResolution.getVerticalDpi(),
+ oldResolution.getHorizontalDpi());
+ attributes.setResolution(newResolution);
+
+ // Rotate the physical margins.
+ Margins oldMinMargins = getMinMargins();
+ Margins newMinMargins = new Margins(
+ oldMinMargins.getBottomMils(),
+ oldMinMargins.getLeftMils(),
+ oldMinMargins.getTopMils(),
+ oldMinMargins.getRightMils());
+ attributes.setMinMargins(newMinMargins);
+
+ attributes.setColorMode(getColorMode());
+
+ return attributes;
+ }
+
+ /**
+ * Gets a new print attributes instance which is in landscape orientation,
+ * which is the media size is in landscape and all orientation dependent
+ * attributes such as resolution and margins are properly adjusted.
+ *
+ * @return New instance in landscape orientation if this one is in
+ * portrait, otherwise this instance.
+ *
+ * @hide
+ */
+ public PrintAttributes asLandscape() {
+ if (!isPortrait()) {
+ return this;
+ }
+
+ PrintAttributes attributes = new PrintAttributes();
+
+ // Rotate the media size.
+ attributes.setMediaSize(getMediaSize().asLandscape());
+
+ // Rotate the resolution.
+ Resolution oldResolution = getResolution();
+ Resolution newResolution = new Resolution(
+ oldResolution.getId(),
+ oldResolution.getLabel(),
+ oldResolution.getVerticalDpi(),
+ oldResolution.getHorizontalDpi());
+ attributes.setResolution(newResolution);
+
+ // Rotate the physical margins.
+ Margins oldMinMargins = getMinMargins();
+ Margins newMargins = new Margins(
+ oldMinMargins.getTopMils(),
+ oldMinMargins.getRightMils(),
+ oldMinMargins.getBottomMils(),
+ oldMinMargins.getLeftMils());
+ attributes.setMinMargins(newMargins);
+
+ attributes.setColorMode(getColorMode());
+
+ return attributes;
+ }
+
@Override
public void writeToParcel(Parcel parcel, int flags) {
if (mMediaSize != null) {
diff --git a/core/java/android/print/PrintManager.java b/core/java/android/print/PrintManager.java
index 811751d..9361286 100644
--- a/core/java/android/print/PrintManager.java
+++ b/core/java/android/print/PrintManager.java
@@ -24,6 +24,7 @@ import android.content.IntentSender.SendIntentException;
import android.os.Bundle;
import android.os.CancellationSignal;
import android.os.Handler;
+import android.os.ICancellationSignal;
import android.os.Looper;
import android.os.Message;
import android.os.ParcelFileDescriptor;
@@ -41,6 +42,7 @@ import libcore.io.IoUtils;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
@@ -50,12 +52,12 @@ import java.util.Map;
* <p>
* To obtain a handle to the print manager do the following:
* </p>
- *
+ *
* <pre>
* PrintManager printManager =
* (PrintManager) context.getSystemService(Context.PRINT_SERVICE);
* </pre>
- *
+ *
* <h3>Print mechanics</h3>
* <p>
* The key idea behind printing on the platform is that the content to be printed
@@ -344,7 +346,7 @@ public final class PrintManager {
try {
mService.cancelPrintJob(printJobId, mAppId, mUserId);
} catch (RemoteException re) {
- Log.e(LOG_TAG, "Error cancleing a print job: " + printJobId, re);
+ Log.e(LOG_TAG, "Error canceling a print job: " + printJobId, re);
}
}
@@ -505,30 +507,17 @@ public final class PrintManager {
private static final class PrintDocumentAdapterDelegate extends IPrintDocumentAdapter.Stub
implements ActivityLifecycleCallbacks {
-
private final Object mLock = new Object();
- private CancellationSignal mLayoutOrWriteCancellation;
-
- private Activity mActivity; // Strong reference OK - cleared in finish()
-
- private PrintDocumentAdapter mDocumentAdapter; // Strong reference OK - cleared in finish
+ private Activity mActivity; // Strong reference OK - cleared in destroy
- private Handler mHandler; // Strong reference OK - cleared in finish()
+ private PrintDocumentAdapter mDocumentAdapter; // Strong reference OK - cleared in destroy
- private IPrintDocumentAdapterObserver mObserver; // Strong reference OK - cleared in finish
+ private Handler mHandler; // Strong reference OK - cleared in destroy
- private LayoutSpec mLastLayoutSpec;
+ private IPrintDocumentAdapterObserver mObserver; // Strong reference OK - cleared in destroy
- private WriteSpec mLastWriteSpec;
-
- private boolean mStartReqeusted;
- private boolean mStarted;
-
- private boolean mFinishRequested;
- private boolean mFinished;
-
- private boolean mDestroyed;
+ private DestroyableCallback mPendingCallback;
public PrintDocumentAdapterDelegate(Activity activity,
PrintDocumentAdapter documentAdapter) {
@@ -542,11 +531,10 @@ public final class PrintManager {
public void setObserver(IPrintDocumentAdapterObserver observer) {
final boolean destroyed;
synchronized (mLock) {
- if (!mDestroyed) {
- mObserver = observer;
- }
- destroyed = mDestroyed;
+ mObserver = observer;
+ destroyed = isDestroyedLocked();
}
+
if (destroyed) {
try {
observer.onDestroy();
@@ -559,126 +547,89 @@ public final class PrintManager {
@Override
public void start() {
synchronized (mLock) {
- // Started called or finish called or destroyed - nothing to do.
- if (mStartReqeusted || mFinishRequested || mDestroyed) {
- return;
+ // If destroyed the handler is null.
+ if (!isDestroyedLocked()) {
+ mHandler.obtainMessage(MyHandler.MSG_ON_START,
+ mDocumentAdapter).sendToTarget();
}
-
- mStartReqeusted = true;
-
- doPendingWorkLocked();
}
}
@Override
public void layout(PrintAttributes oldAttributes, PrintAttributes newAttributes,
ILayoutResultCallback callback, Bundle metadata, int sequence) {
- final boolean destroyed;
- synchronized (mLock) {
- destroyed = mDestroyed;
- // If start called and not finished called and not destroyed - do some work.
- if (mStartReqeusted && !mFinishRequested && !mDestroyed) {
- // Layout cancels write and overrides layout.
- if (mLastWriteSpec != null) {
- IoUtils.closeQuietly(mLastWriteSpec.fd);
- mLastWriteSpec = null;
- }
-
- mLastLayoutSpec = new LayoutSpec();
- mLastLayoutSpec.callback = callback;
- mLastLayoutSpec.oldAttributes = oldAttributes;
- mLastLayoutSpec.newAttributes = newAttributes;
- mLastLayoutSpec.metadata = metadata;
- mLastLayoutSpec.sequence = sequence;
-
- // Cancel the previous cancellable operation.When the
- // cancellation completes we will do the pending work.
- if (cancelPreviousCancellableOperationLocked()) {
- return;
- }
- doPendingWorkLocked();
- }
+ ICancellationSignal cancellationTransport = CancellationSignal.createTransport();
+ try {
+ callback.onLayoutStarted(cancellationTransport, sequence);
+ } catch (RemoteException re) {
+ // The spooler is dead - can't recover.
+ Log.e(LOG_TAG, "Error notifying for layout start", re);
+ return;
}
- if (destroyed) {
- try {
- callback.onLayoutFailed(null, sequence);
- } catch (RemoteException re) {
- Log.i(LOG_TAG, "Error notifying for cancelled layout", re);
+
+ synchronized (mLock) {
+ // If destroyed the handler is null.
+ if (isDestroyedLocked()) {
+ return;
}
+
+ CancellationSignal cancellationSignal = CancellationSignal.fromTransport(
+ cancellationTransport);
+
+ SomeArgs args = SomeArgs.obtain();
+ args.arg1 = mDocumentAdapter;
+ args.arg2 = oldAttributes;
+ args.arg3 = newAttributes;
+ args.arg4 = cancellationSignal;
+ args.arg5 = new MyLayoutResultCallback(callback, sequence);
+ args.arg6 = metadata;
+
+ mHandler.obtainMessage(MyHandler.MSG_ON_LAYOUT, args).sendToTarget();
}
}
@Override
public void write(PageRange[] pages, ParcelFileDescriptor fd,
IWriteResultCallback callback, int sequence) {
- final boolean destroyed;
- synchronized (mLock) {
- destroyed = mDestroyed;
- // If start called and not finished called and not destroyed - do some work.
- if (mStartReqeusted && !mFinishRequested && !mDestroyed) {
- // Write cancels previous writes.
- if (mLastWriteSpec != null) {
- IoUtils.closeQuietly(mLastWriteSpec.fd);
- mLastWriteSpec = null;
- }
- mLastWriteSpec = new WriteSpec();
- mLastWriteSpec.callback = callback;
- mLastWriteSpec.pages = pages;
- mLastWriteSpec.fd = fd;
- mLastWriteSpec.sequence = sequence;
-
- // Cancel the previous cancellable operation.When the
- // cancellation completes we will do the pending work.
- if (cancelPreviousCancellableOperationLocked()) {
- return;
- }
-
- doPendingWorkLocked();
- }
- }
- if (destroyed) {
- try {
- callback.onWriteFailed(null, sequence);
- } catch (RemoteException re) {
- Log.i(LOG_TAG, "Error notifying for cancelled write", re);
- }
+ ICancellationSignal cancellationTransport = CancellationSignal.createTransport();
+ try {
+ callback.onWriteStarted(cancellationTransport, sequence);
+ } catch (RemoteException re) {
+ // The spooler is dead - can't recover.
+ Log.e(LOG_TAG, "Error notifying for write start", re);
+ return;
}
- }
- @Override
- public void finish() {
synchronized (mLock) {
- // Start not called or finish called or destroyed - nothing to do.
- if (!mStartReqeusted || mFinishRequested || mDestroyed) {
+ // If destroyed the handler is null.
+ if (isDestroyedLocked()) {
return;
}
- mFinishRequested = true;
+ CancellationSignal cancellationSignal = CancellationSignal.fromTransport(
+ cancellationTransport);
- // When the current write or layout complete we
- // will do the pending work.
- if (mLastLayoutSpec != null || mLastWriteSpec != null) {
- if (DEBUG) {
- Log.i(LOG_TAG, "Waiting for current operation");
- }
- return;
- }
+ SomeArgs args = SomeArgs.obtain();
+ args.arg1 = mDocumentAdapter;
+ args.arg2 = pages;
+ args.arg3 = fd;
+ args.arg4 = cancellationSignal;
+ args.arg5 = new MyWriteResultCallback(callback, fd, sequence);
- doPendingWorkLocked();
+ mHandler.obtainMessage(MyHandler.MSG_ON_WRITE, args).sendToTarget();
}
}
@Override
- public void cancel() {
- // Start not called or finish called or destroyed - nothing to do.
- if (!mStartReqeusted || mFinishRequested || mDestroyed) {
- return;
- }
- // Request cancellation of pending work if needed.
+ public void finish() {
synchronized (mLock) {
- cancelPreviousCancellableOperationLocked();
+ // If destroyed the handler is null.
+ if (!isDestroyedLocked()) {
+ mHandler.obtainMessage(MyHandler.MSG_ON_FINISH,
+ mDocumentAdapter).sendToTarget();
+ }
}
}
@@ -719,20 +670,14 @@ public final class PrintManager {
// Note the the spooler has a death recipient that observes if
// this process gets killed so we cover the case of onDestroy not
// being called due to this process being killed to reclaim memory.
- final IPrintDocumentAdapterObserver observer;
+ IPrintDocumentAdapterObserver observer = null;
synchronized (mLock) {
if (activity == mActivity) {
- mDestroyed = true;
observer = mObserver;
- clearLocked();
- } else {
- observer = null;
- activity = null;
+ destroyLocked();
}
}
if (observer != null) {
- activity.getApplication().unregisterActivityLifecycleCallbacks(
- PrintDocumentAdapterDelegate.this);
try {
observer.onDestroy();
} catch (RemoteException re) {
@@ -741,67 +686,39 @@ public final class PrintManager {
}
}
- private boolean isFinished() {
- return mDocumentAdapter == null;
+ private boolean isDestroyedLocked() {
+ return (mActivity == null);
}
- private void clearLocked() {
+ private void destroyLocked() {
+ mActivity.getApplication().unregisterActivityLifecycleCallbacks(
+ PrintDocumentAdapterDelegate.this);
mActivity = null;
+
mDocumentAdapter = null;
+
+ // This method is only called from the main thread, so
+ // clearing the messages guarantees that any time a
+ // message is handled we are not in a destroyed state.
+ mHandler.removeMessages(MyHandler.MSG_ON_START);
+ mHandler.removeMessages(MyHandler.MSG_ON_LAYOUT);
+ mHandler.removeMessages(MyHandler.MSG_ON_WRITE);
+ mHandler.removeMessages(MyHandler.MSG_ON_FINISH);
mHandler = null;
- mLayoutOrWriteCancellation = null;
- mLastLayoutSpec = null;
- if (mLastWriteSpec != null) {
- IoUtils.closeQuietly(mLastWriteSpec.fd);
- mLastWriteSpec = null;
- }
- }
- private boolean cancelPreviousCancellableOperationLocked() {
- if (mLayoutOrWriteCancellation != null) {
- mLayoutOrWriteCancellation.cancel();
- if (DEBUG) {
- Log.i(LOG_TAG, "Cancelling previous operation");
- }
- return true;
- }
- return false;
- }
+ mObserver = null;
- private void doPendingWorkLocked() {
- if (mStartReqeusted && !mStarted) {
- mStarted = true;
- mHandler.sendEmptyMessage(MyHandler.MSG_START);
- } else if (mLastLayoutSpec != null) {
- mHandler.sendEmptyMessage(MyHandler.MSG_LAYOUT);
- } else if (mLastWriteSpec != null) {
- mHandler.sendEmptyMessage(MyHandler.MSG_WRITE);
- } else if (mFinishRequested && !mFinished) {
- mFinished = true;
- mHandler.sendEmptyMessage(MyHandler.MSG_FINISH);
+ if (mPendingCallback != null) {
+ mPendingCallback.destroy();
+ mPendingCallback = null;
}
}
- private class LayoutSpec {
- ILayoutResultCallback callback;
- PrintAttributes oldAttributes;
- PrintAttributes newAttributes;
- Bundle metadata;
- int sequence;
- }
-
- private class WriteSpec {
- IWriteResultCallback callback;
- PageRange[] pages;
- ParcelFileDescriptor fd;
- int sequence;
- }
-
private final class MyHandler extends Handler {
- public static final int MSG_START = 1;
- public static final int MSG_LAYOUT = 2;
- public static final int MSG_WRITE = 3;
- public static final int MSG_FINISH = 4;
+ public static final int MSG_ON_START = 1;
+ public static final int MSG_ON_LAYOUT = 2;
+ public static final int MSG_ON_WRITE = 3;
+ public static final int MSG_ON_FINISH = 4;
public MyHandler(Looper looper) {
super(looper, null, true);
@@ -809,84 +726,71 @@ public final class PrintManager {
@Override
public void handleMessage(Message message) {
- if (isFinished()) {
- return;
- }
switch (message.what) {
- case MSG_START: {
- final PrintDocumentAdapter adapter;
- synchronized (mLock) {
- adapter = mDocumentAdapter;
- }
- if (adapter != null) {
- adapter.onStart();
+ case MSG_ON_START: {
+ if (DEBUG) {
+ Log.i(LOG_TAG, "onStart()");
}
+
+ ((PrintDocumentAdapter) message.obj).onStart();
} break;
- case MSG_LAYOUT: {
- final PrintDocumentAdapter adapter;
- final CancellationSignal cancellation;
- final LayoutSpec layoutSpec;
+ case MSG_ON_LAYOUT: {
+ SomeArgs args = (SomeArgs) message.obj;
+ PrintDocumentAdapter adapter = (PrintDocumentAdapter) args.arg1;
+ PrintAttributes oldAttributes = (PrintAttributes) args.arg2;
+ PrintAttributes newAttributes = (PrintAttributes) args.arg3;
+ CancellationSignal cancellation = (CancellationSignal) args.arg4;
+ LayoutResultCallback callback = (LayoutResultCallback) args.arg5;
+ Bundle metadata = (Bundle) args.arg6;
+ args.recycle();
- synchronized (mLock) {
- adapter = mDocumentAdapter;
- layoutSpec = mLastLayoutSpec;
- mLastLayoutSpec = null;
- cancellation = new CancellationSignal();
- mLayoutOrWriteCancellation = cancellation;
+ if (DEBUG) {
+ StringBuilder builder = new StringBuilder();
+ builder.append("PrintDocumentAdapter#onLayout() {\n");
+ builder.append("\n oldAttributes:").append(oldAttributes);
+ builder.append("\n newAttributes:").append(newAttributes);
+ builder.append("\n preview:").append(metadata.getBoolean(
+ PrintDocumentAdapter.EXTRA_PRINT_PREVIEW));
+ builder.append("\n}");
+ Log.i(LOG_TAG, builder.toString());
}
- if (layoutSpec != null && adapter != null) {
- if (DEBUG) {
- Log.i(LOG_TAG, "Performing layout");
- }
- adapter.onLayout(layoutSpec.oldAttributes,
- layoutSpec.newAttributes, cancellation,
- new MyLayoutResultCallback(layoutSpec.callback,
- layoutSpec.sequence), layoutSpec.metadata);
- }
+ adapter.onLayout(oldAttributes, newAttributes, cancellation,
+ callback, metadata);
} break;
- case MSG_WRITE: {
- final PrintDocumentAdapter adapter;
- final CancellationSignal cancellation;
- final WriteSpec writeSpec;
+ case MSG_ON_WRITE: {
+ SomeArgs args = (SomeArgs) message.obj;
+ PrintDocumentAdapter adapter = (PrintDocumentAdapter) args.arg1;
+ PageRange[] pages = (PageRange[]) args.arg2;
+ ParcelFileDescriptor fd = (ParcelFileDescriptor) args.arg3;
+ CancellationSignal cancellation = (CancellationSignal) args.arg4;
+ WriteResultCallback callback = (WriteResultCallback) args.arg5;
+ args.recycle();
- synchronized (mLock) {
- adapter = mDocumentAdapter;
- writeSpec = mLastWriteSpec;
- mLastWriteSpec = null;
- cancellation = new CancellationSignal();
- mLayoutOrWriteCancellation = cancellation;
+ if (DEBUG) {
+ StringBuilder builder = new StringBuilder();
+ builder.append("PrintDocumentAdapter#onWrite() {\n");
+ builder.append("\n pages:").append(Arrays.toString(pages));
+ builder.append("\n}");
+ Log.i(LOG_TAG, builder.toString());
}
- if (writeSpec != null && adapter != null) {
- if (DEBUG) {
- Log.i(LOG_TAG, "Performing write");
- }
- adapter.onWrite(writeSpec.pages, writeSpec.fd,
- cancellation, new MyWriteResultCallback(writeSpec.callback,
- writeSpec.fd, writeSpec.sequence));
- }
+ adapter.onWrite(pages, fd, cancellation, callback);
} break;
- case MSG_FINISH: {
+ case MSG_ON_FINISH: {
if (DEBUG) {
- Log.i(LOG_TAG, "Performing finish");
+ Log.i(LOG_TAG, "onFinish()");
}
- final PrintDocumentAdapter adapter;
- final Activity activity;
+
+ ((PrintDocumentAdapter) message.obj).onFinish();
+
+ // Done printing, so destroy this instance as it
+ // should not be used anymore.
synchronized (mLock) {
- adapter = mDocumentAdapter;
- activity = mActivity;
- clearLocked();
- }
- if (adapter != null) {
- adapter.onFinish();
- }
- if (activity != null) {
- activity.getApplication().unregisterActivityLifecycleCallbacks(
- PrintDocumentAdapterDelegate.this);
+ destroyLocked();
}
} break;
@@ -898,7 +802,12 @@ public final class PrintManager {
}
}
- private final class MyLayoutResultCallback extends LayoutResultCallback {
+ private interface DestroyableCallback {
+ public void destroy();
+ }
+
+ private final class MyLayoutResultCallback extends LayoutResultCallback
+ implements DestroyableCallback {
private ILayoutResultCallback mCallback;
private final int mSequence;
@@ -910,25 +819,31 @@ public final class PrintManager {
@Override
public void onLayoutFinished(PrintDocumentInfo info, boolean changed) {
- if (info == null) {
- throw new NullPointerException("document info cannot be null");
- }
final ILayoutResultCallback callback;
synchronized (mLock) {
- if (mDestroyed) {
- Log.e(LOG_TAG, "PrintDocumentAdapter is destroyed. Did you "
- + "finish the printing activity before print completion?");
- return;
- }
callback = mCallback;
- clearLocked();
}
- if (callback != null) {
+
+ // If the callback is null we are destroyed.
+ if (callback == null) {
+ Log.e(LOG_TAG, "PrintDocumentAdapter is destroyed. Did you "
+ + "finish the printing activity before print completion "
+ + "or did you invoke a callback after finish?");
+ return;
+ }
+
+ try {
+ if (info == null) {
+ throw new NullPointerException("document info cannot be null");
+ }
+
try {
callback.onLayoutFinished(info, changed, mSequence);
} catch (RemoteException re) {
Log.e(LOG_TAG, "Error calling onLayoutFinished", re);
}
+ } finally {
+ destroy();
}
}
@@ -936,46 +851,64 @@ public final class PrintManager {
public void onLayoutFailed(CharSequence error) {
final ILayoutResultCallback callback;
synchronized (mLock) {
- if (mDestroyed) {
- Log.e(LOG_TAG, "PrintDocumentAdapter is destroyed. Did you "
- + "finish the printing activity before print completion?");
- return;
- }
callback = mCallback;
- clearLocked();
}
- if (callback != null) {
- try {
- callback.onLayoutFailed(error, mSequence);
- } catch (RemoteException re) {
- Log.e(LOG_TAG, "Error calling onLayoutFailed", re);
- }
+
+ // If the callback is null we are destroyed.
+ if (callback == null) {
+ Log.e(LOG_TAG, "PrintDocumentAdapter is destroyed. Did you "
+ + "finish the printing activity before print completion "
+ + "or did you invoke a callback after finish?");
+ return;
+ }
+
+ try {
+ callback.onLayoutFailed(error, mSequence);
+ } catch (RemoteException re) {
+ Log.e(LOG_TAG, "Error calling onLayoutFailed", re);
+ } finally {
+ destroy();
}
}
@Override
public void onLayoutCancelled() {
+ final ILayoutResultCallback callback;
synchronized (mLock) {
- if (mDestroyed) {
- Log.e(LOG_TAG, "PrintDocumentAdapter is destroyed. Did you "
- + "finish the printing activity before print completion?");
- return;
- }
- clearLocked();
+ callback = mCallback;
+ }
+
+ // If the callback is null we are destroyed.
+ if (callback == null) {
+ Log.e(LOG_TAG, "PrintDocumentAdapter is destroyed. Did you "
+ + "finish the printing activity before print completion "
+ + "or did you invoke a callback after finish?");
+ return;
+ }
+
+ try {
+ callback.onLayoutCanceled(mSequence);
+ } catch (RemoteException re) {
+ Log.e(LOG_TAG, "Error calling onLayoutFailed", re);
+ } finally {
+ destroy();
}
}
- private void clearLocked() {
- mLayoutOrWriteCancellation = null;
- mCallback = null;
- doPendingWorkLocked();
+ @Override
+ public void destroy() {
+ synchronized (mLock) {
+ mCallback = null;
+ mPendingCallback = null;
+ }
}
}
- private final class MyWriteResultCallback extends WriteResultCallback {
+ private final class MyWriteResultCallback extends WriteResultCallback
+ implements DestroyableCallback {
private ParcelFileDescriptor mFd;
- private int mSequence;
private IWriteResultCallback mCallback;
+ private final int mSequence;
public MyWriteResultCallback(IWriteResultCallback callback,
ParcelFileDescriptor fd, int sequence) {
@@ -988,26 +921,32 @@ public final class PrintManager {
public void onWriteFinished(PageRange[] pages) {
final IWriteResultCallback callback;
synchronized (mLock) {
- if (mDestroyed) {
- Log.e(LOG_TAG, "PrintDocumentAdapter is destroyed. Did you "
- + "finish the printing activity before print completion?");
- return;
- }
callback = mCallback;
- clearLocked();
- }
- if (pages == null) {
- throw new IllegalArgumentException("pages cannot be null");
}
- if (pages.length == 0) {
- throw new IllegalArgumentException("pages cannot be empty");
+
+ // If the callback is null we are destroyed.
+ if (callback == null) {
+ Log.e(LOG_TAG, "PrintDocumentAdapter is destroyed. Did you "
+ + "finish the printing activity before print completion "
+ + "or did you invoke a callback after finish?");
+ return;
}
- if (callback != null) {
+
+ try {
+ if (pages == null) {
+ throw new IllegalArgumentException("pages cannot be null");
+ }
+ if (pages.length == 0) {
+ throw new IllegalArgumentException("pages cannot be empty");
+ }
+
try {
callback.onWriteFinished(pages, mSequence);
} catch (RemoteException re) {
Log.e(LOG_TAG, "Error calling onWriteFinished", re);
}
+ } finally {
+ destroy();
}
}
@@ -1015,41 +954,58 @@ public final class PrintManager {
public void onWriteFailed(CharSequence error) {
final IWriteResultCallback callback;
synchronized (mLock) {
- if (mDestroyed) {
- Log.e(LOG_TAG, "PrintDocumentAdapter is destroyed. Did you "
- + "finish the printing activity before print completion?");
- return;
- }
callback = mCallback;
- clearLocked();
}
- if (callback != null) {
- try {
- callback.onWriteFailed(error, mSequence);
- } catch (RemoteException re) {
- Log.e(LOG_TAG, "Error calling onWriteFailed", re);
- }
+
+ // If the callback is null we are destroyed.
+ if (callback == null) {
+ Log.e(LOG_TAG, "PrintDocumentAdapter is destroyed. Did you "
+ + "finish the printing activity before print completion "
+ + "or did you invoke a callback after finish?");
+ return;
+ }
+
+ try {
+ callback.onWriteFailed(error, mSequence);
+ } catch (RemoteException re) {
+ Log.e(LOG_TAG, "Error calling onWriteFailed", re);
+ } finally {
+ destroy();
}
}
@Override
public void onWriteCancelled() {
+ final IWriteResultCallback callback;
synchronized (mLock) {
- if (mDestroyed) {
- Log.e(LOG_TAG, "PrintDocumentAdapter is destroyed. Did you "
- + "finish the printing activity before print completion?");
- return;
- }
- clearLocked();
+ callback = mCallback;
+ }
+
+ // If the callback is null we are destroyed.
+ if (callback == null) {
+ Log.e(LOG_TAG, "PrintDocumentAdapter is destroyed. Did you "
+ + "finish the printing activity before print completion "
+ + "or did you invoke a callback after finish?");
+ return;
+ }
+
+ try {
+ callback.onWriteCanceled(mSequence);
+ } catch (RemoteException re) {
+ Log.e(LOG_TAG, "Error calling onWriteCanceled", re);
+ } finally {
+ destroy();
}
}
- private void clearLocked() {
- mLayoutOrWriteCancellation = null;
- IoUtils.closeQuietly(mFd);
- mCallback = null;
- mFd = null;
- doPendingWorkLocked();
+ @Override
+ public void destroy() {
+ synchronized (mLock) {
+ IoUtils.closeQuietly(mFd);
+ mCallback = null;
+ mFd = null;
+ mPendingCallback = null;
+ }
}
}
}
diff --git a/core/java/android/print/PrinterDiscoverySession.java b/core/java/android/print/PrinterDiscoverySession.java
index d32b71b..abb441b 100644
--- a/core/java/android/print/PrinterDiscoverySession.java
+++ b/core/java/android/print/PrinterDiscoverySession.java
@@ -72,9 +72,9 @@ public final class PrinterDiscoverySession {
}
}
- public final void startPrinterDisovery(List<PrinterId> priorityList) {
+ public final void startPrinterDiscovery(List<PrinterId> priorityList) {
if (isDestroyed()) {
- Log.w(LOG_TAG, "Ignoring start printers dsicovery - session destroyed");
+ Log.w(LOG_TAG, "Ignoring start printers discovery - session destroyed");
return;
}
if (!mIsPrinterDiscoveryStarted) {
@@ -122,7 +122,7 @@ public final class PrinterDiscoverySession {
try {
mPrintManager.stopPrinterStateTracking(printerId, mUserId);
} catch (RemoteException re) {
- Log.e(LOG_TAG, "Error stoping printer state tracking", re);
+ Log.e(LOG_TAG, "Error stopping printer state tracking", re);
}
}
diff --git a/core/java/android/printservice/PrintService.java b/core/java/android/printservice/PrintService.java
index eb0ac2e..1557ab0 100644
--- a/core/java/android/printservice/PrintService.java
+++ b/core/java/android/printservice/PrintService.java
@@ -201,9 +201,9 @@ public abstract class PrintService extends Service {
* should build another one using the {@link PrintJobInfo.Builder} class. You
* can specify any standard properties and add advanced, printer specific,
* ones via {@link PrintJobInfo.Builder#putAdvancedOption(String, String)
- * PrintJobInfo.Builder#putAdvancedOption(String, String)} and {@link
+ * PrintJobInfo.Builder.putAdvancedOption(String, String)} and {@link
* PrintJobInfo.Builder#putAdvancedOption(String, int)
- * PrintJobInfo.Builder#putAdvancedOption(String, int)}. The advanced options
+ * PrintJobInfo.Builder.putAdvancedOption(String, int)}. The advanced options
* are not interpreted by the system, they will not be visible to applications,
* and can only be accessed by your print service via {@link
* PrintJob#getAdvancedStringOption(String) PrintJob.getAdvancedStringOption(String)}
@@ -212,14 +212,26 @@ public abstract class PrintService extends Service {
* <p>
* If the advanced print options activity offers changes to the standard print
* options, you can get the current {@link android.print.PrinterInfo} using the
- * "android.intent.extra.print.EXTRA_PRINTER_INFO" extra which will allow you to
- * present the user with UI options supported by the current printer. For example,
- * if the current printer does not support a give media size, you should not
- * offer it in the advanced print options dialog.
+ * {@link #EXTRA_PRINTER_INFO} extra which will allow you to present the user
+ * with UI options supported by the current printer. For example, if the current
+ * printer does not support a given media size, you should not offer it in the
+ * advanced print options UI.
* </p>
+ *
+ * @see #EXTRA_PRINTER_INFO
*/
public static final String EXTRA_PRINT_JOB_INFO = "android.intent.extra.print.PRINT_JOB_INFO";
+ /**
+ * If you declared an optional activity with advanced print options via the
+ * {@link R.attr#advancedPrintOptionsActivity advancedPrintOptionsActivity}
+ * attribute, this extra is used to pass in the currently selected printer's
+ * {@link android.print.PrinterInfo} to your activity allowing you to inspect it.
+ *
+ * @see #EXTRA_PRINT_JOB_INFO
+ */
+ public static final String EXTRA_PRINTER_INFO = "android.intent.extra.print.PRINTER_INFO";
+
private Handler mHandler;
private IPrintServiceClient mClient;
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index e97a768..06869fd 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -7648,7 +7648,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* notification is at at most once every
* {@link ViewConfiguration#getSendRecurringAccessibilityEventsInterval()}
* to avoid unnecessary load to the system. Also once a view has a pending
- * notifucation this method is a NOP until the notification has been sent.
+ * notification this method is a NOP until the notification has been sent.
*
* @hide
*/
diff --git a/core/java/com/android/internal/os/SomeArgs.java b/core/java/com/android/internal/os/SomeArgs.java
index 7edf4cc..c977997 100644
--- a/core/java/com/android/internal/os/SomeArgs.java
+++ b/core/java/com/android/internal/os/SomeArgs.java
@@ -45,6 +45,7 @@ public final class SomeArgs {
public Object arg3;
public Object arg4;
public Object arg5;
+ public Object arg6;
public int argi1;
public int argi2;
public int argi3;
@@ -95,6 +96,7 @@ public final class SomeArgs {
arg3 = null;
arg4 = null;
arg5 = null;
+ arg6 = null;
argi1 = 0;
argi2 = 0;
argi3 = 0;