diff options
author | Svetoslav Ganov <svetoslavganov@google.com> | 2013-06-25 14:59:53 -0700 |
---|---|---|
committer | Svetoslav Ganov <svetoslavganov@google.com> | 2013-07-16 12:59:59 -0700 |
commit | a00271533f639c8ed36429c663889ac9f654bc72 (patch) | |
tree | 7f0c8045126bc0493c1fa018a114f803d34fa7ef /core/java/android/printservice | |
parent | 15ecbdd2e373195ef920faefa349a6e62200d1f1 (diff) | |
download | frameworks_base-a00271533f639c8ed36429c663889ac9f654bc72.zip frameworks_base-a00271533f639c8ed36429c663889ac9f654bc72.tar.gz frameworks_base-a00271533f639c8ed36429c663889ac9f654bc72.tar.bz2 |
Refactoring of the print sub-system and API clean up.
1. Now a user state has ins own spooler since the spooler app is
running per user. The user state registers an observer for the state
of the spooler to get information needed to orchestrate unbinding
from print serivces that have no work and eventually unbinding from
the spooler when all no service has any work.
2. Abstracted a remote print service from the perspective of the system
in a class that is transparently managing binding and unbinding to
the remote instance.
3. Abstracted the remote print spooler to transparently manage binding
and unbinding to the remote instance when there is work and when
there is no work, respectively.
4. Cleaned up the print document adapter (ex-PrintAdapter) APIs to
enable implementing the all callbacks on a thread of choice. If
the document is really small, using the main thread makes sense.
Now if an app that does not need the UI state to layout the printed
content, it can schedule all the work for allocating resources, laying
out, writing, and releasing resources on a dedicated thread.
5. Added info class for the printed document that is now propagated
the the print services. A print service gets an instance of a
new document class that encapsulates the document info and a method
to access the document's data.
6. Added APIs for describing the type of a document to the new document
info class. This allows a print service to do smarts based on the
doc type. For now we have only photo and document types.
7. Renamed the systemReady method for system services that implement
it with different semantics to systemRunning. Such methods assume
the the service can run third-party code which is not the same as
systemReady.
8. Cleaned up the print job configuration activity.
9. Sigh... code clean up here and there. Factoring out classes to
improve readability.
Change-Id: I637ba28412793166cbf519273fdf022241159a92
Diffstat (limited to 'core/java/android/printservice')
-rw-r--r-- | core/java/android/printservice/IPrintService.aidl | 7 | ||||
-rw-r--r-- | core/java/android/printservice/IPrintServiceClient.aidl | 6 | ||||
-rw-r--r-- | core/java/android/printservice/PrintDocument.java | 91 | ||||
-rw-r--r-- | core/java/android/printservice/PrintJob.java | 91 | ||||
-rw-r--r-- | core/java/android/printservice/PrintService.java | 182 | ||||
-rw-r--r-- | core/java/android/printservice/PrintServiceInfo.java | 15 |
6 files changed, 231 insertions, 161 deletions
diff --git a/core/java/android/printservice/IPrintService.aidl b/core/java/android/printservice/IPrintService.aidl index eabd96d..c72385a 100644 --- a/core/java/android/printservice/IPrintService.aidl +++ b/core/java/android/printservice/IPrintService.aidl @@ -17,6 +17,7 @@ package android.printservice; import android.os.ICancellationSignal; +import android.print.IPrinterDiscoveryObserver; import android.print.PrintJobInfo; import android.print.PrinterId; import android.printservice.IPrintServiceClient; @@ -28,8 +29,8 @@ import android.printservice.IPrintServiceClient; */ oneway interface IPrintService { void setClient(IPrintServiceClient client); - void requestCancelPrintJob(in PrintJobInfo printJob); - void onPrintJobQueued(in PrintJobInfo printJob); - void startPrinterDiscovery(); + void requestCancelPrintJob(in PrintJobInfo printJobInfo); + void onPrintJobQueued(in PrintJobInfo printJobInfo); + void startPrinterDiscovery(IPrinterDiscoveryObserver observer); void stopPrinterDiscovery(); } diff --git a/core/java/android/printservice/IPrintServiceClient.aidl b/core/java/android/printservice/IPrintServiceClient.aidl index cff8c02..cdde4d8 100644 --- a/core/java/android/printservice/IPrintServiceClient.aidl +++ b/core/java/android/printservice/IPrintServiceClient.aidl @@ -27,11 +27,9 @@ import android.print.PrinterInfo; * @hide */ interface IPrintServiceClient { - List<PrintJobInfo> getPrintJobs(); - PrintJobInfo getPrintJob(int printJobId); + List<PrintJobInfo> getPrintJobInfos(); + PrintJobInfo getPrintJobInfo(int printJobId); boolean setPrintJobState(int printJobId, int status); boolean setPrintJobTag(int printJobId, String tag); oneway void writePrintJobData(in ParcelFileDescriptor fd, int printJobId); - oneway void addDiscoveredPrinters(in List<PrinterInfo> printers); - oneway void removeDiscoveredPrinters(in List<PrinterId> printers); } diff --git a/core/java/android/printservice/PrintDocument.java b/core/java/android/printservice/PrintDocument.java new file mode 100644 index 0000000..2a1581a --- /dev/null +++ b/core/java/android/printservice/PrintDocument.java @@ -0,0 +1,91 @@ +/* + * 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.printservice; + +import android.os.ParcelFileDescriptor; +import android.os.RemoteException; +import android.print.PrintDocumentInfo; +import android.util.Log; + +import java.io.FileDescriptor; +import java.io.IOException; + +/** + * This class represents a printed document from the perspective of a print + * service. It exposes APIs to query the document and obtain its data. + */ +public final class PrintDocument { + + private static final String LOG_TAG = "PrintDocument"; + + private final int mPrintJobId; + + private final IPrintServiceClient mPrintServiceClient; + + private final PrintDocumentInfo mInfo; + + PrintDocument(int printJobId, IPrintServiceClient printServiceClient, + PrintDocumentInfo info) { + mPrintJobId = printJobId; + mPrintServiceClient = printServiceClient; + mInfo = info; + } + + /** + * Gets the {@link PrintDocumentInfo} that describes this document. + * + * @return The document info. + */ + public PrintDocumentInfo getInfo() { + return mInfo; + } + + /** + * Gets the data associated with this document. It is a responsibility of the + * client to open a stream to the returned file descriptor and fully read the + * data. + * <p> + * <strong>Note:</strong> It is your responsibility to close the file descriptor. + * </p> + * + * @return A file descriptor for reading the data or <code>null</code>. + */ + public FileDescriptor getData() { + ParcelFileDescriptor source = null; + ParcelFileDescriptor sink = null; + try { + ParcelFileDescriptor[] fds = ParcelFileDescriptor.createPipe(); + source = fds[0]; + sink = fds[1]; + mPrintServiceClient.writePrintJobData(sink, mPrintJobId); + return source.getFileDescriptor(); + } catch (IOException ioe) { + Log.e(LOG_TAG, "Error calling getting print job data!", ioe); + } catch (RemoteException re) { + Log.e(LOG_TAG, "Error calling getting print job data!", re); + } finally { + if (sink != null) { + try { + sink.close(); + } catch (IOException ioe) { + /* ignore */ + } + } + } + return null; + } +} diff --git a/core/java/android/printservice/PrintJob.java b/core/java/android/printservice/PrintJob.java index f490f91..80530a7 100644 --- a/core/java/android/printservice/PrintJob.java +++ b/core/java/android/printservice/PrintJob.java @@ -16,10 +16,6 @@ package android.printservice; -import java.io.FileDescriptor; -import java.io.IOException; - -import android.os.ParcelFileDescriptor; import android.os.RemoteException; import android.print.PrintJobInfo; import android.util.Log; @@ -33,19 +29,16 @@ public final class PrintJob { private static final String LOG_TAG = "PrintJob"; - private final int mId; - private final IPrintServiceClient mPrintServiceClient; + private final PrintDocument mDocument; + private PrintJobInfo mCachedInfo; - PrintJob(PrintJobInfo info, IPrintServiceClient client) { - if (client == null) { - throw new IllegalStateException("Print serivice not connected!"); - } - mCachedInfo = info; - mId = info.getId(); + PrintJob(PrintJobInfo jobInfo, IPrintServiceClient client) { + mCachedInfo = jobInfo; mPrintServiceClient = client; + mDocument = new PrintDocument(mCachedInfo.getId(), client, jobInfo.getDocumentInfo()); } /** @@ -54,7 +47,7 @@ public final class PrintJob { * @return The id. */ public int getId() { - return mId; + return mCachedInfo.getId(); } /** @@ -70,9 +63,9 @@ public final class PrintJob { public PrintJobInfo getInfo() { PrintJobInfo info = null; try { - info = mPrintServiceClient.getPrintJob(mId); + info = mPrintServiceClient.getPrintJobInfo(mCachedInfo.getId()); } catch (RemoteException re) { - Log.e(LOG_TAG, "Couldn't get info for job: " + mId, re); + Log.e(LOG_TAG, "Couldn't get info for job: " + mCachedInfo.getId(), re); } if (info != null) { mCachedInfo = info; @@ -81,6 +74,15 @@ public final class PrintJob { } /** + * Gets the document of this print job. + * + * @return The document. + */ + public PrintDocument getDocument() { + return mDocument; + } + + /** * Gets whether this print job is queued. Such a print job is * ready to be printed and can be started. * @@ -103,7 +105,7 @@ public final class PrintJob { * @see #fail(CharSequence) */ public boolean isStarted() { - return getInfo().getState() == PrintJobInfo.STATE_STARTED; + return getInfo().getState() == PrintJobInfo.STATE_STARTED; } /** @@ -181,48 +183,13 @@ public final class PrintJob { */ public boolean setTag(String tag) { try { - return mPrintServiceClient.setPrintJobTag(mId, tag); + return mPrintServiceClient.setPrintJobTag(mCachedInfo.getId(), tag); } catch (RemoteException re) { - Log.e(LOG_TAG, "Error setting tag for job:" + mId, re); + Log.e(LOG_TAG, "Error setting tag for job: " + mCachedInfo.getId(), re); } return false; } - /** - * Gets the data associated with this print job. It is a responsibility of - * the print service to open a stream to the returned file descriptor - * and fully read the content. - * <p> - * <strong>Note:</strong> It is your responsibility to close the file descriptor. - * </p> - * - * @return A file descriptor for reading the data or <code>null</code>. - */ - public final FileDescriptor getData() { - ParcelFileDescriptor source = null; - ParcelFileDescriptor sink = null; - try { - ParcelFileDescriptor[] fds = ParcelFileDescriptor.createPipe(); - source = fds[0]; - sink = fds[1]; - mPrintServiceClient.writePrintJobData(sink, mId); - return source.getFileDescriptor(); - } catch (IOException ioe) { - Log.e(LOG_TAG, "Error calling getting print job data!", ioe); - } catch (RemoteException re) { - Log.e(LOG_TAG, "Error calling getting print job data!", re); - } finally { - if (sink != null) { - try { - sink.close(); - } catch (IOException ioe) { - /* ignore */ - } - } - } - return null; - } - @Override public boolean equals(Object obj) { if (this == obj) { @@ -235,23 +202,25 @@ public final class PrintJob { return false; } PrintJob other = (PrintJob) obj; - return (mId == other.mId); + return (mCachedInfo.getId() == other.mCachedInfo.getId()); } @Override public int hashCode() { - return mId; + return mCachedInfo.getId(); } private boolean setState(int state) { - // Best effort - update the state of the cached info since - // we may not be able to re-fetch it later if the job gets - // removed from the spooler. - mCachedInfo.setState(state); try { - return mPrintServiceClient.setPrintJobState(mId, state); + if (mPrintServiceClient.setPrintJobState(mCachedInfo.getId(), state)) { + // Best effort - update the state of the cached info since + // we may not be able to re-fetch it later if the job gets + // removed from the spooler as a result of the state change. + mCachedInfo.setState(state); + return true; + } } catch (RemoteException re) { - Log.e(LOG_TAG, "Error setting the state of job:" + mId, re); + Log.e(LOG_TAG, "Error setting the state of job: " + mCachedInfo.getId(), re); } return false; } diff --git a/core/java/android/printservice/PrintService.java b/core/java/android/printservice/PrintService.java index 9256966..820c2d8 100644 --- a/core/java/android/printservice/PrintService.java +++ b/core/java/android/printservice/PrintService.java @@ -25,6 +25,7 @@ import android.os.IBinder; import android.os.Looper; import android.os.Message; import android.os.RemoteException; +import android.print.IPrinterDiscoveryObserver; import android.print.PrintJobInfo; import android.print.PrinterId; import android.print.PrinterInfo; @@ -47,7 +48,7 @@ import java.util.List; * {@link #onStartPrinterDiscovery()} and ends with a call to * {@link #onStopPrinterDiscovery()}. During a printer discovery * period the print service reports newly discovered printers by - * calling {@link #addDiscoveredPrinters(List)} and added printers + * calling {@link #addDiscoveredPrinters(List)} and reports added printers * that disappeared by calling {@link #removeDiscoveredPrinters(List)}. * Calls to {@link #addDiscoveredPrinters(List)} and * {@link #removeDiscoveredPrinters(List)} before a call to @@ -67,26 +68,30 @@ import java.util.List; * a call to {@link #onPrintJobQueued(PrintJob)} is made and the print * service may handle it immediately or schedule that for an appropriate * time in the future. The list of all print jobs for this service - * are be available by calling {@link #getPrintJobs()}. A queued print - * job is one whose {@link PrintJob#isQueued()} return true. + * are be available by calling {@link #getPrintJobs()}. * </p> * <p> * A print service is responsible for setting the print job state as * appropriate while processing it. Initially, a print job is in a * {@link PrintJobInfo#STATE_QUEUED} state which means that the data to * be printed is spooled by the system and the print service can obtain - * that data by calling {@link PrintJob#getData()}. After the print - * service starts printing the data it should set the print job state - * to {@link PrintJobInfo#STATE_STARTED}. Upon successful completion, the - * print job state has to be set to {@link PrintJobInfo#STATE_COMPLETED}. - * In a case of a failure, the print job state should be set to - * {@link PrintJobInfo#STATE_FAILED}. If a print job is in a - * {@link PrintJobInfo#STATE_STARTED} state and the user requests to - * cancel it, the print service will receive a call to - * {@link #onRequestCancelPrintJob(PrintJob)} which requests from the - * service to do a best effort in canceling the job. In case the job - * is successfully canceled, its state has to be set to - * {@link PrintJobInfo#STATE_CANCELED}. + * that data by calling {@link PrintJob#getDocument()}. A queued print + * job's {@link PrintJob#isQueued()} method returns true. + * </p> + * <p> + * After the print service starts printing the data it should set the + * print job state to {@link PrintJobInfo#STATE_STARTED} by calling + * {@link PrintJob#start()}. Upon successful completion, the print job + * state has to be set to {@link PrintJobInfo#STATE_COMPLETED} by calling + * {@link PrintJob#complete()}. In case of a failure, the print job + * state should be set to {@link PrintJobInfo#STATE_FAILED} by calling + * {@link PrintJob#fail(CharSequence)}. If a print job is in a + * {@link PrintJobInfo#STATE_STARTED} state, i.e. {@link PrintJob#isStarted()} + * return true, and the user requests to cancel it, the print service will + * receive a call to {@link #onRequestCancelPrintJob(PrintJob)} which + * requests from the service to do a best effort in canceling the job. In + * case the job is successfully canceled, its state has to be set to + * {@link PrintJobInfo#STATE_CANCELED}. by calling {@link PrintJob#cancel()}. * </p> * <h3>Lifecycle</h3> * <p> @@ -124,9 +129,9 @@ import java.util.List; * <p> * A print service can be configured by specifying an optional settings * activity which exposes service specific options, an optional add - * prints activity which is used for manual addition of printers, etc. - * It is a responsibility of the system to launch the settings and add - * printers activities when appropriate. + * prints activity which is used for manual addition of printers, vendor + * name ,etc. It is a responsibility of the system to launch the settings + * and add printers activities when appropriate. * </p> * <p> * A print service is configured by providing a @@ -148,7 +153,7 @@ import java.util.List; */ public abstract class PrintService extends Service { - private static final String LOG_TAG = PrintService.class.getSimpleName(); + private static final String LOG_TAG = "PrintService"; /** * The {@link Intent} action that must be declared as handled by a service @@ -162,6 +167,7 @@ public abstract class PrintService extends Service { * <code><{@link android.R.styleable#PrintService print-service}></code> * tag. This is a a sample XML file configuring a print service: * <pre> <print-service + * android:vendor="SomeVendor" * android:settingsActivity="foo.bar.MySettingsActivity" * andorid:addPrintersActivity="foo.bar.MyAddPrintersActivity." * . . . @@ -175,7 +181,7 @@ public abstract class PrintService extends Service { private IPrintServiceClient mClient; - private boolean mDiscoveringPrinters; + private IPrinterDiscoveryObserver mDiscoveryObserver; @Override protected void attachBaseContext(Context base) { @@ -230,29 +236,29 @@ public abstract class PrintService extends Service { * printers have to be added. You can call this method as many times as * necessary during the discovery period but should not pass in already * added printers. If a printer is already added in the same printer - * discovery period, it will be ignored. + * discovery period, it will be ignored. If you want to update an already + * added printer, you should removed it and then re-add it. * </p> * * @param printers A list with discovered printers. * - * @throws IllegalStateException If this service is not connected. - * * @see #removeDiscoveredPrinters(List) * @see #onStartPrinterDiscovery() * @see #onStopPrinterDiscovery() + * + * @throws IllegalStateException If this service is not connected. */ public final void addDiscoveredPrinters(List<PrinterInfo> printers) { + final IPrinterDiscoveryObserver observer; synchronized (mLock) { - if (mClient == null) { - throw new IllegalStateException("Print serivice not connected!"); - } - if (mDiscoveringPrinters) { - try { - // Calling with a lock into the system is fine. - mClient.addDiscoveredPrinters(printers); - } catch (RemoteException re) { - Log.e(LOG_TAG, "Error adding discovered printers!", re); - } + throwIfNotConnectedLocked(); + observer = mDiscoveryObserver; + } + if (observer != null) { + try { + observer.addDiscoveredPrinters(printers); + } catch (RemoteException re) { + Log.e(LOG_TAG, "Error adding discovered printers", re); } } } @@ -269,37 +275,38 @@ public abstract class PrintService extends Service { * this method as many times as necessary during the discovery period * but should not pass in already removed printer ids. If a printer with * a given id is already removed in the same discovery period, it will - * be ignored. + * be ignored. If you want to update an already added printer, you should + * removed it and then re-add it. * </p> * * @param printerIds A list with disappeared printer ids. * - * @throws IllegalStateException If this service is not connected. - * * @see #addDiscoveredPrinters(List) * @see #onStartPrinterDiscovery() * @see #onStopPrinterDiscovery() + * + * @throws IllegalStateException If this service is not connected. */ public final void removeDiscoveredPrinters(List<PrinterId> printerIds) { + final IPrinterDiscoveryObserver observer; synchronized (mLock) { - if (mClient == null) { - throw new IllegalStateException("Print serivice not connected!"); - } - if (mDiscoveringPrinters) { - try { - // Calling with a lock into the system is fine. - mClient.removeDiscoveredPrinters(printerIds); - } catch (RemoteException re) { - Log.e(LOG_TAG, "Error removing discovered printers!", re); - } + throwIfNotConnectedLocked(); + observer = mDiscoveryObserver; + } + if (observer != null) { + try { + observer.removeDiscoveredPrinters(printerIds); + } catch (RemoteException re) { + Log.e(LOG_TAG, "Error removing discovered printers", re); } } } /** * Called when canceling of a print job is requested. The service - * should do best effort to fulfill the request. After the print - * job is canceled by calling {@link PrintJob#cancel()}. + * should do best effort to fulfill the request. After the cancellation + * is performed, the print job should be set to a cancelled state by + * calling {@link PrintJob#cancel()}. * * @param printJob The print job to be canceled. */ @@ -310,11 +317,12 @@ public abstract class PrintService extends Service { * Called when there is a queued print job for one of the printers * managed by this print service. A queued print job is ready for * processing by a print service which can get the data to be printed - * by calling {@link PrintJob#getData()}. This service may start + * by calling {@link PrintJob#getDocument()}. This service may start * processing the passed in print job or schedule handling of queued * print jobs at a convenient time. The service can get the print * jobs by a call to {@link #getPrintJobs()} and examine their state - * to find the ones with state {@link PrintJobInfo#STATE_QUEUED}. + * to find the ones with state {@link PrintJobInfo#STATE_QUEUED} by + * calling {@link PrintJob#isQueued()}. * * @param printJob The new queued print job. * @@ -330,28 +338,31 @@ public abstract class PrintService extends Service { * @throws IllegalStateException If this service is not connected. */ public final List<PrintJob> getPrintJobs() { + final IPrintServiceClient client; synchronized (mLock) { - if (mClient == null) { - throw new IllegalStateException("Print serivice not connected!"); - } - try { - List<PrintJob> printJobs = null; - List<PrintJobInfo> printJobInfos = mClient.getPrintJobs(); - if (printJobInfos != null) { - final int printJobInfoCount = printJobInfos.size(); - printJobs = new ArrayList<PrintJob>(printJobInfoCount); - for (int i = 0; i < printJobInfoCount; i++) { - printJobs.add(new PrintJob(printJobInfos.get(i), mClient)); - } - } - if (printJobs != null) { - return printJobs; + throwIfNotConnectedLocked(); + client = mClient; + } + if (client == null) { + return Collections.emptyList(); + } + try { + List<PrintJob> printJobs = null; + List<PrintJobInfo> printJobInfos = client.getPrintJobInfos(); + if (printJobInfos != null) { + final int printJobInfoCount = printJobInfos.size(); + printJobs = new ArrayList<PrintJob>(printJobInfoCount); + for (int i = 0; i < printJobInfoCount; i++) { + printJobs.add(new PrintJob(printJobInfos.get(i), client)); } - } catch (RemoteException re) { - Log.e(LOG_TAG, "Error calling getPrintJobs()", re); } - return Collections.emptyList(); + if (printJobs != null) { + return printJobs; + } + } catch (RemoteException re) { + Log.e(LOG_TAG, "Error calling getPrintJobs()", re); } + return Collections.emptyList(); } /** @@ -375,8 +386,9 @@ public abstract class PrintService extends Service { } @Override - public void startPrinterDiscovery() { - mHandler.sendEmptyMessage(MyHandler.MESSAGE_START_PRINTER_DISCOVERY); + public void startPrinterDiscovery(IPrinterDiscoveryObserver observer) { + mHandler.obtainMessage(MyHandler.MESSAGE_START_PRINTER_DISCOVERY, + observer).sendToTarget(); } @Override @@ -385,18 +397,25 @@ public abstract class PrintService extends Service { } @Override - public void requestCancelPrintJob(PrintJobInfo printJob) { - mHandler.obtainMessage(MyHandler.MESSAGE_CANCEL_PRINTJOB, printJob).sendToTarget(); + public void requestCancelPrintJob(PrintJobInfo printJobInfo) { + mHandler.obtainMessage(MyHandler.MESSAGE_CANCEL_PRINTJOB, + printJobInfo).sendToTarget(); } @Override - public void onPrintJobQueued(PrintJobInfo printJob) { + public void onPrintJobQueued(PrintJobInfo printJobInfo) { mHandler.obtainMessage(MyHandler.MESSAGE_ON_PRINTJOB_QUEUED, - printJob).sendToTarget(); + printJobInfo).sendToTarget(); } }; } + private void throwIfNotConnectedLocked() { + if (mClient == null) { + throw new IllegalStateException("Print serivice not connected"); + } + } + private final class MyHandler extends Handler { public static final int MESSAGE_START_PRINTER_DISCOVERY = 1; public static final int MESSAGE_STOP_PRINTER_DISCOVERY = 2; @@ -414,26 +433,26 @@ public abstract class PrintService extends Service { switch (action) { case MESSAGE_START_PRINTER_DISCOVERY: { synchronized (mLock) { - mDiscoveringPrinters = true; + mDiscoveryObserver = (IPrinterDiscoveryObserver) message.obj; } onStartPrinterDiscovery(); } break; case MESSAGE_STOP_PRINTER_DISCOVERY: { synchronized (mLock) { - mDiscoveringPrinters = false; + mDiscoveryObserver = null; } onStopPrinterDiscovery(); } break; case MESSAGE_CANCEL_PRINTJOB: { - PrintJobInfo printJob = (PrintJobInfo) message.obj; - onRequestCancelPrintJob(new PrintJob(printJob, mClient)); + PrintJobInfo printJobInfo = (PrintJobInfo) message.obj; + onRequestCancelPrintJob(new PrintJob(printJobInfo, mClient)); } break; case MESSAGE_ON_PRINTJOB_QUEUED: { - PrintJobInfo printJob = (PrintJobInfo) message.obj; - onPrintJobQueued(new PrintJob(printJob, mClient)); + PrintJobInfo printJobInfo = (PrintJobInfo) message.obj; + onPrintJobQueued(new PrintJob(printJobInfo, mClient)); } break; case MESSAGE_SET_CLEINT: { @@ -441,13 +460,12 @@ public abstract class PrintService extends Service { synchronized (mLock) { mClient = client; if (client == null) { - mDiscoveringPrinters = false; + mDiscoveryObserver = null; } } if (client != null) { onConnected(); } else { - onStopPrinterDiscovery(); onDisconnected(); } } break; diff --git a/core/java/android/printservice/PrintServiceInfo.java b/core/java/android/printservice/PrintServiceInfo.java index 0370a25..43dd1b6 100644 --- a/core/java/android/printservice/PrintServiceInfo.java +++ b/core/java/android/printservice/PrintServiceInfo.java @@ -48,8 +48,6 @@ import java.io.IOException; */ public final class PrintServiceInfo implements Parcelable { - private static final boolean DEBUG = false; - private static final String LOG_TAG = PrintServiceInfo.class.getSimpleName(); private static final String TAG_PRINT_SERVICE = "print-service"; @@ -97,7 +95,6 @@ public final class PrintServiceInfo implements Parcelable { * @param context Context for accessing resources. * @throws XmlPullParserException If a XML parsing error occurs. * @throws IOException If a I/O error occurs. - * @hide */ public static PrintServiceInfo create(ResolveInfo resolveInfo, Context context) { String settingsActivityName = null; @@ -117,7 +114,7 @@ public final class PrintServiceInfo implements Parcelable { String nodeName = parser.getName(); if (!TAG_PRINT_SERVICE.equals(nodeName)) { throw new XmlPullParserException( - "Meta-data does not start with" + TAG_PRINT_SERVICE + " tag"); + "Meta-data does not start with " + TAG_PRINT_SERVICE + " tag"); } Resources resources = packageManager.getResourcesForApplication( @@ -213,7 +210,7 @@ public final class PrintServiceInfo implements Parcelable { @Override public int hashCode() { - return 31 * 1 + ((mId == null) ? 0 : mId.hashCode()); + return 31 + ((mId == null) ? 0 : mId.hashCode()); } @Override @@ -244,12 +241,8 @@ public final class PrintServiceInfo implements Parcelable { builder.append("PrintServiceInfo{"); builder.append("id:").append(mId).append(", "); builder.append("resolveInfo:").append(mResolveInfo).append(", "); - if (DEBUG) { - builder.append("settingsActivityName:").append(mSettingsActivityName); - builder.append("addPrintersActivityName:").append(mAddPrintersActivityName); - } else if (mSettingsActivityName != null || mAddPrintersActivityName != null) { - builder.append("<has meta-data>"); - } + builder.append("settingsActivityName:").append(mSettingsActivityName); + builder.append("addPrintersActivityName:").append(mAddPrintersActivityName); builder.append("}"); return builder.toString(); } |