diff options
author | Svetoslav <svetoslavganov@google.com> | 2013-10-10 13:36:23 -0700 |
---|---|---|
committer | Svetoslav Ganov <svetoslavganov@google.com> | 2013-10-11 09:11:24 -0700 |
commit | 7bfbbcb04bf4ba8f3069b2df136f708c9849bacf (patch) | |
tree | da453e5f618eacb7cf63de3ef1344507feeecb0a /core/java/android/print | |
parent | 1db8cf12a985425a73d24875d9d308c14c0b4359 (diff) | |
download | frameworks_base-7bfbbcb04bf4ba8f3069b2df136f708c9849bacf.zip frameworks_base-7bfbbcb04bf4ba8f3069b2df136f708c9849bacf.tar.gz frameworks_base-7bfbbcb04bf4ba8f3069b2df136f708c9849bacf.tar.bz2 |
Refactor how the print dialog activity is started.
1. Before the print job activity was started asyncronously with
respect to the print call on to the print manager. This was
creating a situation where the starting activity may finish
before the print dialog appears which may lead to an orphaned
print document adapter with no data to print (as the UI is
is gone), or strange behaviors where the print dialog starts
on as a separate task.
To address this the pending intent for starting the print
dialog is not started by the print spooler since we cannot
call into it synchronously as we have to start its process
and bind to the spooler service which leads to jankyness in
the client app. Now the pending intent is created by the
print manager service in the synchronous print call so
from an app's perspective calling print starts the activity.
The side effect of this design is that the print dialog
activity may start before the system is bound to the spooler
service. In such a case the print activity cannot start
poking the print spooler state as the system registers
callback to observe the spooler state. To address this
the print spooler activity disables the UI and also binds
to the spooler service which happenes immediately after it
is started. As soon as the print dialog binds to the
service it starts the UI.
2. Fixed an bug in the printer adapter of the print dialog that
was leading to a crash if the only item in the adater is the
all pritners option and it is selected.
3. Piping the package name that started the printing so we can
pass it to the storage UI as a hint to open the last location
the app used.
bug:11127269
Change-Id: Ia93820bdae0b0e7600a0930b1f10d9708bd86b68
Diffstat (limited to 'core/java/android/print')
-rw-r--r-- | core/java/android/print/IPrintManager.aidl | 7 | ||||
-rw-r--r-- | core/java/android/print/IPrintSpooler.aidl | 5 | ||||
-rw-r--r-- | core/java/android/print/PrintManager.java | 101 |
3 files changed, 60 insertions, 53 deletions
diff --git a/core/java/android/print/IPrintManager.aidl b/core/java/android/print/IPrintManager.aidl index 3bd515b..8fa7ab9 100644 --- a/core/java/android/print/IPrintManager.aidl +++ b/core/java/android/print/IPrintManager.aidl @@ -16,9 +16,9 @@ package android.print; +import android.os.Bundle; import android.print.IPrinterDiscoveryObserver; import android.print.IPrintDocumentAdapter; -import android.print.IPrintClient; import android.print.PrintJobId; import android.print.IPrintJobStateChangeListener; import android.print.PrinterId; @@ -34,9 +34,8 @@ import android.printservice.PrintServiceInfo; interface IPrintManager { List<PrintJobInfo> getPrintJobInfos(int appId, int userId); PrintJobInfo getPrintJobInfo(in PrintJobId printJobId, int appId, int userId); - PrintJobInfo print(String printJobName, in IPrintClient client, - in IPrintDocumentAdapter printAdapter, in PrintAttributes attributes, - int appId, int userId); + Bundle print(String printJobName, in IPrintDocumentAdapter printAdapter, + in PrintAttributes attributes, String packageName, int appId, int userId); void cancelPrintJob(in PrintJobId printJobId, int appId, int userId); void restartPrintJob(in PrintJobId printJobId, int appId, int userId); diff --git a/core/java/android/print/IPrintSpooler.aidl b/core/java/android/print/IPrintSpooler.aidl index 5f06b83..7b2cf25 100644 --- a/core/java/android/print/IPrintSpooler.aidl +++ b/core/java/android/print/IPrintSpooler.aidl @@ -18,8 +18,6 @@ package android.print; import android.content.ComponentName; import android.os.ParcelFileDescriptor; -import android.print.IPrintDocumentAdapter; -import android.print.IPrintClient; import android.print.IPrintSpoolerClient; import android.print.IPrintSpoolerCallbacks; import android.print.PrinterInfo; @@ -40,8 +38,7 @@ oneway interface IPrintSpooler { int state, int appId, int sequence); void getPrintJobInfo(in PrintJobId printJobId, IPrintSpoolerCallbacks callback, int appId, int sequence); - void createPrintJob(in PrintJobInfo printJob, in IPrintClient client, - in IPrintDocumentAdapter printAdapter); + void createPrintJob(in PrintJobInfo printJob); void setPrintJobState(in PrintJobId printJobId, int status, String stateReason, IPrintSpoolerCallbacks callback, int sequence); void setPrintJobTag(in PrintJobId printJobId, String tag, IPrintSpoolerCallbacks callback, diff --git a/core/java/android/print/PrintManager.java b/core/java/android/print/PrintManager.java index 1cb4e8d..1233da2 100644 --- a/core/java/android/print/PrintManager.java +++ b/core/java/android/print/PrintManager.java @@ -60,8 +60,47 @@ public final class PrintManager { private static final boolean DEBUG = false; - private static final int MSG_START_PRINT_JOB_CONFIG_ACTIVITY = 1; - private static final int MSG_NOTIFY_PRINT_JOB_STATE_CHANGED = 2; + private static final int MSG_NOTIFY_PRINT_JOB_STATE_CHANGED = 1; + + /** + * The action for launching the print dialog activity. + * + * @hide + */ + public static final String ACTION_PRINT_DIALOG = "android.print.PRINT_DIALOG"; + + /** + * Extra with the intent for starting the print dialog. + * <p> + * <strong>Type:</strong> {@link android.content.IntentSender} + * </p> + * + * @hide + */ + public static final String EXTRA_PRINT_DIALOG_INTENT = + "android.print.intent.extra.EXTRA_PRINT_DIALOG_INTENT"; + + /** + * Extra with a print job. + * <p> + * <strong>Type:</strong> {@link android.print.PrintJobInfo} + * </p> + * + * @hide + */ + public static final String EXTRA_PRINT_JOB = + "android.print.intent.extra.EXTRA_PRINT_JOB"; + + /** + * Extra with the print document adapter to be printed. + * <p> + * <strong>Type:</strong> {@link android.print.IPrintDocumentAdapter} + * </p> + * + * @hide + */ + public static final String EXTRA_PRINT_DOCUMENT_ADAPTER = + "android.print.intent.extra.EXTRA_PRINT_DOCUMENT_ADAPTER"; /** @hide */ public static final int APP_ID_ANY = -2; @@ -74,8 +113,6 @@ public final class PrintManager { private final int mAppId; - private final PrintClient mPrintClient; - private final Handler mHandler; private Map<PrintJobStateChangeListener, PrintJobStateChangeListenerWrapper> mPrintJobStateChangeListeners; @@ -103,24 +140,10 @@ public final class PrintManager { mService = service; mUserId = userId; mAppId = appId; - mPrintClient = new PrintClient(this); mHandler = new Handler(context.getMainLooper(), null, false) { @Override public void handleMessage(Message message) { switch (message.what) { - case MSG_START_PRINT_JOB_CONFIG_ACTIVITY: { - SomeArgs args = (SomeArgs) message.obj; - Context context = (Context) args.arg1; - IntentSender intent = (IntentSender) args.arg2; - args.recycle(); - try { - context.startIntentSender(intent, null, 0, 0, 0); - } catch (SendIntentException sie) { - Log.e(LOG_TAG, "Couldn't start print job config activity.", sie); - } - } - break; - case MSG_NOTIFY_PRINT_JOB_STATE_CHANGED: { SomeArgs args = (SomeArgs) message.obj; PrintJobStateChangeListener listener = @@ -128,8 +151,7 @@ public final class PrintManager { PrintJobId printJobId = (PrintJobId) args.arg2; args.recycle(); listener.onPrintJobStateChanged(printJobId); - } - break; + } break; } } }; @@ -279,10 +301,20 @@ public final class PrintManager { PrintDocumentAdapterDelegate delegate = new PrintDocumentAdapterDelegate(documentAdapter, mContext.getMainLooper()); try { - PrintJobInfo printJob = mService.print(printJobName, mPrintClient, delegate, - attributes, mAppId, mUserId); - if (printJob != null) { - return new PrintJob(printJob, this); + Bundle result = mService.print(printJobName, delegate, + attributes, mContext.getPackageName(), mAppId, mUserId); + if (result != null) { + PrintJobInfo printJob = result.getParcelable(EXTRA_PRINT_JOB); + IntentSender intent = result.getParcelable(EXTRA_PRINT_DIALOG_INTENT); + if (printJob == null || intent == null) { + return null; + } + try { + mContext.startIntentSender(intent, null, 0, 0, 0); + return new PrintJob(printJob, this); + } catch (SendIntentException sie) { + Log.e(LOG_TAG, "Couldn't start print job config activity.", sie); + } } } catch (RemoteException re) { Log.e(LOG_TAG, "Error creating a print job", re); @@ -333,27 +365,6 @@ public final class PrintManager { return new PrinterDiscoverySession(mService, mContext, mUserId); } - private static final class PrintClient extends IPrintClient.Stub { - - private final WeakReference<PrintManager> mWeakPrintManager; - - public PrintClient(PrintManager manager) { - mWeakPrintManager = new WeakReference<PrintManager>(manager); - } - - @Override - public void startPrintJobConfigActivity(IntentSender intent) { - PrintManager manager = mWeakPrintManager.get(); - if (manager != null) { - SomeArgs args = SomeArgs.obtain(); - args.arg1 = manager.mContext; - args.arg2 = intent; - manager.mHandler.obtainMessage(MSG_START_PRINT_JOB_CONFIG_ACTIVITY, - args).sendToTarget(); - } - } - } - private static final class PrintDocumentAdapterDelegate extends IPrintDocumentAdapter.Stub { private final Object mLock = new Object(); |