From 2fbd2a7f070f246ddafd9de94efa9a98861e9136 Mon Sep 17 00:00:00 2001 From: Svetoslav Date: Mon, 16 Sep 2013 17:53:51 -0700 Subject: App UI freezes when printing. API clean up. 1. The UI of a printing app was freezing a little when calling the print method since the print manager service was waiting for it to bind to the print spooler which generated the print job id (and the initial print job info really). Now the print manager service is responsible for job id generation and does not not wait for the print spooler to spin. Hence, the app UI is not blocked at all. Note that the print manager initiates the binding to the spooler and as soon as it completes the spooler shows the print UI which is hosted in its process. It is not possible to show the print UI before the system is bound to the spooler since during this binding the system passes a callback to the spooler so the latter can talk to the system. 2. Changed the print job id to be an opaque class allowing us to vary the way we generate print job ids in the future. 3. The queued print job state was hidden but the print job returned by the print method of the print manager is in that state. Now now hidden. 4. We were incorrecly removing print job infos if they are completed or cancelled. Doing that is problematic since the print job returned by the print method allows the app to query for the job info after the job has been say completed. Hence, an app can initiate printing and get a print job whose state is "created" and hold onto it until after the job is completed, now if the app asks for the print job info it will get an info in "created" state even though the job is "completed" since the spooler was not retaining the completed jobs. Now the spooler removes the PDF files for the completed and cancelled print jobs but keeps around the infos (also persisting them to disc) so it can answer questions about them. On first boot or switch to a user we purge the persisted print jobs in completed/cancelled state since they are obsolete - no app can have a handle to them. 5. Removed the print method that takes a file since we have a public PrintDocumentAdapter implementation for printing files. Once can instantiate a PrintFileDocumentAdapter and pass it to the print method. This class also allows overriding of the finish method to know when the data is spooled and deleted the file if desired, etc. 6. Replaced the wrong code to slice a large list of parcelables to use ParceledListSlice class. bug:10748093 Change-Id: I1ebeeb47576e88fce550851cdd3e401fcede6e2b --- core/java/android/print/IPrintManager.aidl | 7 +- core/java/android/print/IPrintSpooler.aidl | 17 +-- .../java/android/print/IPrintSpoolerCallbacks.aidl | 1 - .../android/print/IPrinterDiscoveryObserver.aidl | 5 +- core/java/android/print/PrintJob.java | 15 +-- core/java/android/print/PrintJobId.aidl | 19 ++++ core/java/android/print/PrintJobId.java | 122 +++++++++++++++++++++ core/java/android/print/PrintJobInfo.java | 12 +- core/java/android/print/PrintManager.java | 23 +--- .../android/print/PrinterDiscoverySession.java | 11 +- .../android/printservice/IPrintServiceClient.aidl | 14 ++- core/java/android/printservice/PrintDocument.java | 5 +- core/java/android/printservice/PrintJob.java | 7 +- .../printservice/PrinterDiscoverySession.java | 75 +++++-------- 14 files changed, 220 insertions(+), 113 deletions(-) create mode 100644 core/java/android/print/PrintJobId.aidl create mode 100644 core/java/android/print/PrintJobId.java (limited to 'core') diff --git a/core/java/android/print/IPrintManager.aidl b/core/java/android/print/IPrintManager.aidl index d2ae5e6..4e839c6 100644 --- a/core/java/android/print/IPrintManager.aidl +++ b/core/java/android/print/IPrintManager.aidl @@ -19,6 +19,7 @@ package android.print; import android.print.IPrinterDiscoveryObserver; import android.print.IPrintDocumentAdapter; import android.print.IPrintClient; +import android.print.PrintJobId; import android.print.PrinterId; import android.print.PrintJobInfo; import android.print.PrintAttributes; @@ -31,12 +32,12 @@ import android.printservice.PrintServiceInfo; */ interface IPrintManager { List getPrintJobInfos(int appId, int userId); - PrintJobInfo getPrintJobInfo(int printJobId, 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); - void cancelPrintJob(int printJobId, int appId, int userId); - void restartPrintJob(int printJobId, int appId, int userId); + void cancelPrintJob(in PrintJobId printJobId, int appId, int userId); + void restartPrintJob(in PrintJobId printJobId, int appId, int userId); List getEnabledPrintServices(int userId); diff --git a/core/java/android/print/IPrintSpooler.aidl b/core/java/android/print/IPrintSpooler.aidl index 0a77dab..291e81f 100644 --- a/core/java/android/print/IPrintSpooler.aidl +++ b/core/java/android/print/IPrintSpooler.aidl @@ -24,6 +24,8 @@ import android.print.IPrintSpoolerClient; import android.print.IPrintSpoolerCallbacks; import android.print.PrinterInfo; import android.print.PrintAttributes; +import android.print.PrintJobId; +import android.print.PrintJobInfo; /** * Interface for communication with the print spooler service. @@ -33,17 +35,18 @@ import android.print.PrintAttributes; * @hide */ oneway interface IPrintSpooler { + void removeObsoletePrintJobs(); + void forgetPrintJobs(in List printJob); void getPrintJobInfos(IPrintSpoolerCallbacks callback, in ComponentName componentName, int state, int appId, int sequence); - void getPrintJobInfo(int printJobId, IPrintSpoolerCallbacks callback, + void getPrintJobInfo(in PrintJobId printJobId, IPrintSpoolerCallbacks callback, int appId, int sequence); - void createPrintJob(String printJobName, in IPrintClient client, - in IPrintDocumentAdapter printAdapter, in PrintAttributes attributes, - IPrintSpoolerCallbacks callback, int appId, int sequence); - void setPrintJobState(int printJobId, int status, String error, + void createPrintJob(in PrintJobInfo printJob, in IPrintClient client, + in IPrintDocumentAdapter printAdapter); + void setPrintJobState(in PrintJobId printJobId, int status, String stateReason, IPrintSpoolerCallbacks callback, int sequence); - void setPrintJobTag(int printJobId, String tag, IPrintSpoolerCallbacks callback, + void setPrintJobTag(in PrintJobId printJobId, String tag, IPrintSpoolerCallbacks callback, int sequence); - void writePrintJobData(in ParcelFileDescriptor fd, int printJobId); + void writePrintJobData(in ParcelFileDescriptor fd, in PrintJobId printJobId); void setClient(IPrintSpoolerClient client); } diff --git a/core/java/android/print/IPrintSpoolerCallbacks.aidl b/core/java/android/print/IPrintSpoolerCallbacks.aidl index 51b5439..45c5332 100644 --- a/core/java/android/print/IPrintSpoolerCallbacks.aidl +++ b/core/java/android/print/IPrintSpoolerCallbacks.aidl @@ -28,7 +28,6 @@ import java.util.List; */ oneway interface IPrintSpoolerCallbacks { void onGetPrintJobInfosResult(in List printJob, int sequence); - void onCreatePrintJobResult(in PrintJobInfo printJob, int sequence); void onCancelPrintJobResult(boolean canceled, int sequence); void onSetPrintJobStateResult(boolean success, int sequence); void onSetPrintJobTagResult(boolean success, int sequence); diff --git a/core/java/android/print/IPrinterDiscoveryObserver.aidl b/core/java/android/print/IPrinterDiscoveryObserver.aidl index b558011..2be7b6b 100644 --- a/core/java/android/print/IPrinterDiscoveryObserver.aidl +++ b/core/java/android/print/IPrinterDiscoveryObserver.aidl @@ -18,6 +18,7 @@ package android.print; import android.print.PrinterId; import android.print.PrinterInfo; +import android.content.pm.ParceledListSlice; /** * Interface for observing discovered printers by a discovery session. @@ -25,6 +26,6 @@ import android.print.PrinterInfo; * @hide */ oneway interface IPrinterDiscoveryObserver { - void onPrintersAdded(in List printers); - void onPrintersRemoved(in List printerIds); + void onPrintersAdded(in ParceledListSlice printers); + void onPrintersRemoved(in ParceledListSlice printerIds); } diff --git a/core/java/android/print/PrintJob.java b/core/java/android/print/PrintJob.java index 42bea6d..00ade07 100644 --- a/core/java/android/print/PrintJob.java +++ b/core/java/android/print/PrintJob.java @@ -22,8 +22,6 @@ package android.print; */ public final class PrintJob { - private final int mId; - private final PrintManager mPrintManager; private PrintJobInfo mCachedInfo; @@ -31,7 +29,6 @@ public final class PrintJob { PrintJob(PrintJobInfo info, PrintManager printManager) { mCachedInfo = info; mPrintManager = printManager; - mId = info.getId(); } /** @@ -39,8 +36,8 @@ public final class PrintJob { * * @return The id. */ - public int getId() { - return mId; + public PrintJobId getId() { + return mCachedInfo.getId(); } /** @@ -57,7 +54,7 @@ public final class PrintJob { if (isInImmutableState()) { return mCachedInfo; } - PrintJobInfo info = mPrintManager.getPrintJobInfo(mId); + PrintJobInfo info = mPrintManager.getPrintJobInfo(mCachedInfo.getId()); if (info != null) { mCachedInfo = info; } @@ -69,7 +66,7 @@ public final class PrintJob { */ public void cancel() { if (!isInImmutableState()) { - mPrintManager.cancelPrintJob(mId); + mPrintManager.cancelPrintJob(mCachedInfo.getId()); } } @@ -91,11 +88,11 @@ public final class PrintJob { return false; } PrintJob other = (PrintJob) obj; - return mId == other.mId; + return mCachedInfo.getId().equals(other.mCachedInfo.getId()); } @Override public int hashCode() { - return mId; + return mCachedInfo.getId().hashCode(); } } diff --git a/core/java/android/print/PrintJobId.aidl b/core/java/android/print/PrintJobId.aidl new file mode 100644 index 0000000..759f25f --- /dev/null +++ b/core/java/android/print/PrintJobId.aidl @@ -0,0 +1,19 @@ +/** + * Copyright (c) 2013, The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.print; + +parcelable PrintJobId; diff --git a/core/java/android/print/PrintJobId.java b/core/java/android/print/PrintJobId.java new file mode 100644 index 0000000..01550e2 --- /dev/null +++ b/core/java/android/print/PrintJobId.java @@ -0,0 +1,122 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.print; + +import android.os.Parcel; +import android.os.Parcelable; +import android.text.TextUtils; + +import java.util.UUID; + +/** + * This class represents the id of a print job. + */ +public final class PrintJobId implements Parcelable { + private final String mValue; + + /** + * Creates a new instance. + * + * @hide + */ + public PrintJobId() { + this(UUID.randomUUID().toString()); + } + + /** + * Creates a new instance. + * + * @param value The internal value. + * + * @hide + */ + public PrintJobId(String value) { + mValue = value; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((mValue != null) ? mValue.hashCode() : 0); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + PrintJobId other = (PrintJobId) obj; + if (!TextUtils.equals(mValue, other.mValue)) { + return false; + } + return true; + } + + @Override + public void writeToParcel(Parcel parcel, int flags) { + parcel.writeString(mValue); + } + + @Override + public int describeContents() { + return 0; + } + + /** + * Flattens this id to a string. + * + * @return The flattened id. + * + * @hide + */ + public String flattenToString() { + return mValue; + } + + /** + * Unflattens a print job id from a string. + * + * @string The string. + * @return The unflattened id, or null if the string is malformed. + * + * @hide + */ + public static PrintJobId unflattenFromString(String string) { + return new PrintJobId(string); + } + + public static final Parcelable.Creator CREATOR = + new Parcelable.Creator() { + @Override + public PrintJobId createFromParcel(Parcel parcel) { + return new PrintJobId(parcel.readString()); + } + + @Override + public PrintJobId[] newArray(int size) { + return new PrintJobId[size]; + } + }; +} diff --git a/core/java/android/print/PrintJobInfo.java b/core/java/android/print/PrintJobInfo.java index b919ad6..502a9f2 100644 --- a/core/java/android/print/PrintJobInfo.java +++ b/core/java/android/print/PrintJobInfo.java @@ -56,8 +56,6 @@ public final class PrintJobInfo implements Parcelable { *

* Next valid states: {@link #STATE_QUEUED} *

- * - * @hide */ public static final int STATE_CREATED = 1; @@ -117,7 +115,7 @@ public final class PrintJobInfo implements Parcelable { public static final int STATE_CANCELED = 7; /** The unique print job id. */ - private int mId; + private PrintJobId mId; /** The human readable print job label. */ private String mLabel; @@ -178,7 +176,7 @@ public final class PrintJobInfo implements Parcelable { } private PrintJobInfo(Parcel parcel) { - mId = parcel.readInt(); + mId = parcel.readParcelable(null); mLabel = parcel.readString(); mPrinterId = parcel.readParcelable(null); mPrinterName = parcel.readString(); @@ -208,7 +206,7 @@ public final class PrintJobInfo implements Parcelable { * * @return The id. */ - public int getId() { + public PrintJobId getId() { return mId; } @@ -219,7 +217,7 @@ public final class PrintJobInfo implements Parcelable { * * @hide */ - public void setId(int id) { + public void setId(PrintJobId id) { this.mId = id; } @@ -485,7 +483,7 @@ public final class PrintJobInfo implements Parcelable { @Override public void writeToParcel(Parcel parcel, int flags) { - parcel.writeInt(mId); + parcel.writeParcelable(mId, flags); parcel.writeString(mLabel); parcel.writeParcelable(mPrinterId, flags); parcel.writeString(mPrinterName); diff --git a/core/java/android/print/PrintManager.java b/core/java/android/print/PrintManager.java index 10cc771..5429155 100644 --- a/core/java/android/print/PrintManager.java +++ b/core/java/android/print/PrintManager.java @@ -36,7 +36,6 @@ import com.android.internal.os.SomeArgs; import libcore.io.IoUtils; -import java.io.File; import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.Collections; @@ -114,7 +113,7 @@ public final class PrintManager { return new PrintManager(mContext, mService, userId, APP_ID_ANY); } - PrintJobInfo getPrintJobInfo(int printJobId) { + PrintJobInfo getPrintJobInfo(PrintJobId printJobId) { try { return mService.getPrintJobInfo(printJobId, mAppId, mUserId); } catch (RemoteException re) { @@ -148,7 +147,7 @@ public final class PrintManager { return Collections.emptyList(); } - void cancelPrintJob(int printJobId) { + void cancelPrintJob(PrintJobId printJobId) { try { mService.cancelPrintJob(printJobId, mAppId, mUserId); } catch (RemoteException re) { @@ -157,24 +156,6 @@ public final class PrintManager { } /** - * Creates a print job for printing a file with default print attributes. - * - * @param printJobName A name for the new print job. - * @param pdfFile The PDF file to print. - * @param documentInfo Information about the printed document. - * @param attributes The default print job attributes. - * @return The created print job on success or null on failure. - * - * @see PrintJob - */ - public PrintJob print(String printJobName, File pdfFile, PrintDocumentInfo documentInfo, - PrintAttributes attributes) { - PrintFileDocumentAdapter documentAdapter = new PrintFileDocumentAdapter( - mContext, pdfFile, documentInfo); - return print(printJobName, documentAdapter, attributes); - } - - /** * Creates a print job for printing a {@link PrintDocumentAdapter} with default print * attributes. * diff --git a/core/java/android/print/PrinterDiscoverySession.java b/core/java/android/print/PrinterDiscoverySession.java index 64249b4..c6dbc16 100644 --- a/core/java/android/print/PrinterDiscoverySession.java +++ b/core/java/android/print/PrinterDiscoverySession.java @@ -17,6 +17,7 @@ package android.print; import android.content.Context; +import android.content.pm.ParceledListSlice; import android.os.Handler; import android.os.Looper; import android.os.Message; @@ -270,20 +271,22 @@ public final class PrinterDiscoverySession { } @Override - public void onPrintersAdded(List printers) { + @SuppressWarnings("rawtypes") + public void onPrintersAdded(ParceledListSlice printers) { PrinterDiscoverySession session = mWeakSession.get(); if (session != null) { session.mHandler.obtainMessage(MSG_PRINTERS_ADDED, - printers).sendToTarget(); + printers.getList()).sendToTarget(); } } @Override - public void onPrintersRemoved(List printerIds) { + @SuppressWarnings("rawtypes") + public void onPrintersRemoved(ParceledListSlice printerIds) { PrinterDiscoverySession session = mWeakSession.get(); if (session != null) { session.mHandler.obtainMessage(MSG_PRINTERS_REMOVED, - printerIds).sendToTarget(); + printerIds.getList()).sendToTarget(); } } } diff --git a/core/java/android/printservice/IPrintServiceClient.aidl b/core/java/android/printservice/IPrintServiceClient.aidl index ad3c04f..c2dfc30 100644 --- a/core/java/android/printservice/IPrintServiceClient.aidl +++ b/core/java/android/printservice/IPrintServiceClient.aidl @@ -20,6 +20,8 @@ import android.os.ParcelFileDescriptor; import android.print.PrintJobInfo; import android.print.PrinterId; import android.print.PrinterInfo; +import android.print.PrintJobId; +import android.content.pm.ParceledListSlice; /** * The top-level interface from a print service to the system. @@ -28,11 +30,11 @@ import android.print.PrinterInfo; */ interface IPrintServiceClient { List getPrintJobInfos(); - PrintJobInfo getPrintJobInfo(int printJobId); - boolean setPrintJobState(int printJobId, int state, String error); - boolean setPrintJobTag(int printJobId, String tag); - oneway void writePrintJobData(in ParcelFileDescriptor fd, int printJobId); + PrintJobInfo getPrintJobInfo(in PrintJobId printJobId); + boolean setPrintJobState(in PrintJobId printJobId, int state, String error); + boolean setPrintJobTag(in PrintJobId printJobId, String tag); + oneway void writePrintJobData(in ParcelFileDescriptor fd, in PrintJobId printJobId); - void onPrintersAdded(in List printers); - void onPrintersRemoved(in List printerIds); + void onPrintersAdded(in ParceledListSlice printers); + void onPrintersRemoved(in ParceledListSlice printerIds); } diff --git a/core/java/android/printservice/PrintDocument.java b/core/java/android/printservice/PrintDocument.java index 8292cfb..e43f2a8 100644 --- a/core/java/android/printservice/PrintDocument.java +++ b/core/java/android/printservice/PrintDocument.java @@ -19,6 +19,7 @@ package android.printservice; import android.os.ParcelFileDescriptor; import android.os.RemoteException; import android.print.PrintDocumentInfo; +import android.print.PrintJobId; import android.util.Log; import java.io.IOException; @@ -35,13 +36,13 @@ public final class PrintDocument { private static final String LOG_TAG = "PrintDocument"; - private final int mPrintJobId; + private final PrintJobId mPrintJobId; private final IPrintServiceClient mPrintServiceClient; private final PrintDocumentInfo mInfo; - PrintDocument(int printJobId, IPrintServiceClient printServiceClient, + PrintDocument(PrintJobId printJobId, IPrintServiceClient printServiceClient, PrintDocumentInfo info) { mPrintJobId = printJobId; mPrintServiceClient = printServiceClient; diff --git a/core/java/android/printservice/PrintJob.java b/core/java/android/printservice/PrintJob.java index 4ff7f0c..2fcae6b 100644 --- a/core/java/android/printservice/PrintJob.java +++ b/core/java/android/printservice/PrintJob.java @@ -17,6 +17,7 @@ package android.printservice; import android.os.RemoteException; +import android.print.PrintJobId; import android.print.PrintJobInfo; import android.text.TextUtils; import android.util.Log; @@ -52,7 +53,7 @@ public final class PrintJob { * * @return The id. */ - public int getId() { + public PrintJobId getId() { PrintService.throwIfNotCalledOnMainThread(); return mCachedInfo.getId(); } @@ -312,12 +313,12 @@ public final class PrintJob { return false; } PrintJob other = (PrintJob) obj; - return (mCachedInfo.getId() == other.mCachedInfo.getId()); + return (mCachedInfo.getId().equals(other.mCachedInfo.getId())); } @Override public int hashCode() { - return mCachedInfo.getId(); + return mCachedInfo.getId().hashCode(); } private boolean isInImmutableState() { diff --git a/core/java/android/printservice/PrinterDiscoverySession.java b/core/java/android/printservice/PrinterDiscoverySession.java index b0bf3da..17cb68f 100644 --- a/core/java/android/printservice/PrinterDiscoverySession.java +++ b/core/java/android/printservice/PrinterDiscoverySession.java @@ -16,6 +16,7 @@ package android.printservice; +import android.content.pm.ParceledListSlice; import android.os.RemoteException; import android.print.PrinterCapabilitiesInfo; import android.print.PrinterId; @@ -80,8 +81,6 @@ import java.util.List; public abstract class PrinterDiscoverySession { private static final String LOG_TAG = "PrinterDiscoverySession"; - private static final int MAX_ITEMS_PER_CALLBACK = 50; - private static int sIdCounter = 0; private final int mId; @@ -112,7 +111,11 @@ public abstract class PrinterDiscoverySession { // If some printers were added in the method that // created the session, send them over. if (!mPrinters.isEmpty()) { - sendAddedPrinters(mObserver, getPrinters()); + try { + mObserver.onPrintersAdded(new ParceledListSlice(getPrinters())); + } catch (RemoteException re) { + Log.e(LOG_TAG, "Error sending added printers", re); + } } } @@ -184,7 +187,11 @@ public abstract class PrinterDiscoverySession { // Send the added printers, if such. if (addedPrinters != null) { - sendAddedPrinters(mObserver, addedPrinters); + try { + mObserver.onPrintersAdded(new ParceledListSlice(addedPrinters)); + } catch (RemoteException re) { + Log.e(LOG_TAG, "Error sending added printers", re); + } } } else { // Remember the last sent printers if needed. @@ -203,27 +210,6 @@ public abstract class PrinterDiscoverySession { } } - private static void sendAddedPrinters(IPrintServiceClient observer, - List printers) { - try { - final int printerCount = printers.size(); - if (printerCount <= MAX_ITEMS_PER_CALLBACK) { - observer.onPrintersAdded(printers); - } else { - // Send the added printers in chunks avoiding the binder transaction limit. - final int transactionCount = (printerCount / MAX_ITEMS_PER_CALLBACK) + 1; - for (int i = 0; i < transactionCount; i++) { - final int start = i * MAX_ITEMS_PER_CALLBACK; - final int end = Math.min(start + MAX_ITEMS_PER_CALLBACK, printerCount); - List subPrinters = printers.subList(start, end); - observer.onPrintersAdded(subPrinters); - } - } - } catch (RemoteException re) { - Log.e(LOG_TAG, "Error sending added printers", re); - } - } - /** * Removes added printers. Removing an already removed or never added * printer has no effect. Removed printers can be added again. You can @@ -261,7 +247,12 @@ public abstract class PrinterDiscoverySession { // Send the removed printers, if such. if (!removedPrinterIds.isEmpty()) { - sendRemovedPrinters(mObserver, removedPrinterIds); + try { + mObserver.onPrintersRemoved(new ParceledListSlice( + removedPrinterIds)); + } catch (RemoteException re) { + Log.e(LOG_TAG, "Error sending removed printers", re); + } } } else { // Remember the last sent printers if needed. @@ -278,26 +269,6 @@ public abstract class PrinterDiscoverySession { } } - private static void sendRemovedPrinters(IPrintServiceClient observer, - List printerIds) { - try { - final int printerIdCount = printerIds.size(); - if (printerIdCount <= MAX_ITEMS_PER_CALLBACK) { - observer.onPrintersRemoved(printerIds); - } else { - final int transactionCount = (printerIdCount / MAX_ITEMS_PER_CALLBACK) + 1; - for (int i = 0; i < transactionCount; i++) { - final int start = i * MAX_ITEMS_PER_CALLBACK; - final int end = Math.min(start + MAX_ITEMS_PER_CALLBACK, printerIdCount); - List subPrinterIds = printerIds.subList(start, end); - observer.onPrintersRemoved(subPrinterIds); - } - } - } catch (RemoteException re) { - Log.e(LOG_TAG, "Error sending removed printers", re); - } - } - private void sendOutOfDiscoveryPeriodPrinterChanges() { // Noting changed since the last discovery period - nothing to do. if (mLastSentPrinters == null || mLastSentPrinters.isEmpty()) { @@ -319,7 +290,11 @@ public abstract class PrinterDiscoverySession { // Send the added printers, if such. if (addedPrinters != null) { - sendAddedPrinters(mObserver, addedPrinters); + try { + mObserver.onPrintersAdded(new ParceledListSlice(addedPrinters)); + } catch (RemoteException re) { + Log.e(LOG_TAG, "Error sending added printers", re); + } } // Determine the removed printers. @@ -335,7 +310,11 @@ public abstract class PrinterDiscoverySession { // Send the removed printers, if such. if (removedPrinterIds != null) { - sendRemovedPrinters(mObserver, removedPrinterIds); + try { + mObserver.onPrintersRemoved(new ParceledListSlice(removedPrinterIds)); + } catch (RemoteException re) { + Log.e(LOG_TAG, "Error sending removed printers", re); + } } mLastSentPrinters = null; -- cgit v1.1