Merge "Remove exceptions from the printer discovery session APIs." into klp-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
371c46fe29
@@ -18926,7 +18926,6 @@ package android.printservice {
|
|||||||
public abstract class PrinterDiscoverySession {
|
public abstract class PrinterDiscoverySession {
|
||||||
ctor public PrinterDiscoverySession(android.content.Context);
|
ctor public PrinterDiscoverySession(android.content.Context);
|
||||||
method public final void addPrinters(java.util.List<android.print.PrinterInfo>);
|
method public final void addPrinters(java.util.List<android.print.PrinterInfo>);
|
||||||
method public final boolean isClosed();
|
|
||||||
method public abstract void onClose();
|
method public abstract void onClose();
|
||||||
method public abstract void onOpen(java.util.List<android.print.PrinterId>);
|
method public abstract void onOpen(java.util.List<android.print.PrinterId>);
|
||||||
method public abstract void onRequestPrinterUpdate(android.print.PrinterId);
|
method public abstract void onRequestPrinterUpdate(android.print.PrinterId);
|
||||||
|
|||||||
@@ -109,21 +109,19 @@ public abstract class PrinterDiscoverySession {
|
|||||||
* Removed printers can be added again. You can call this method multiple
|
* Removed printers can be added again. You can call this method multiple
|
||||||
* times during printer discovery.
|
* times during printer discovery.
|
||||||
* <p>
|
* <p>
|
||||||
* <strong>Note: </strong> Calling this method when the session is closed,
|
* <strong>Note: </strong> Calls to this method before the session is opened,
|
||||||
* which is if {@link #isClosed()} returns true, will throw an {@link
|
* i.e. before the {@link #onOpen(List)} call, and after the session is closed,
|
||||||
* IllegalStateException}.
|
* i.e. after the call to {@link #onClose()}, will be ignored.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param printers The printers to add.
|
* @param printers The printers to add.
|
||||||
*
|
*
|
||||||
* @see #removePrinters(List)
|
* @see #removePrinters(List)
|
||||||
* @see #updatePrinters(List)
|
* @see #updatePrinters(List)
|
||||||
* @see #isClosed()
|
|
||||||
*/
|
*/
|
||||||
public final void addPrinters(List<PrinterInfo> printers) {
|
public final void addPrinters(List<PrinterInfo> printers) {
|
||||||
final IPrinterDiscoverySessionObserver observer;
|
final IPrinterDiscoverySessionObserver observer;
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
throwIfClosedLocked();
|
|
||||||
observer = mObserver;
|
observer = mObserver;
|
||||||
}
|
}
|
||||||
if (observer != null) {
|
if (observer != null) {
|
||||||
@@ -132,6 +130,8 @@ public abstract class PrinterDiscoverySession {
|
|||||||
} catch (RemoteException re) {
|
} catch (RemoteException re) {
|
||||||
Log.e(LOG_TAG, "Error adding printers", re);
|
Log.e(LOG_TAG, "Error adding printers", re);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
Log.w(LOG_TAG, "Printer discovery session not open not adding printers.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,21 +140,19 @@ public abstract class PrinterDiscoverySession {
|
|||||||
* printer has no effect. Removed printers can be added again. You
|
* printer has no effect. Removed printers can be added again. You
|
||||||
* can call this method multiple times during printer discovery.
|
* can call this method multiple times during printer discovery.
|
||||||
* <p>
|
* <p>
|
||||||
* <strong>Note: </strong> Calling this method when the session is closed,
|
* <strong>Note: </strong> Calls to this method before the session is opened,
|
||||||
* which is if {@link #isClosed()} returns true, will throw an {@link
|
* i.e. before the {@link #onOpen(List)} call, and after the session is closed,
|
||||||
* IllegalStateException}.
|
* i.e. after the call to {@link #onClose()}, will be ignored.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param printerIds The ids of the removed printers.
|
* @param printerIds The ids of the removed printers.
|
||||||
*
|
*
|
||||||
* @see #addPrinters(List)
|
* @see #addPrinters(List)
|
||||||
* @see #updatePrinters(List)
|
* @see #updatePrinters(List)
|
||||||
* @see #isClosed()
|
|
||||||
*/
|
*/
|
||||||
public final void removePrinters(List<PrinterId> printerIds) {
|
public final void removePrinters(List<PrinterId> printerIds) {
|
||||||
final IPrinterDiscoverySessionObserver observer;
|
final IPrinterDiscoverySessionObserver observer;
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
throwIfClosedLocked();
|
|
||||||
observer = mObserver;
|
observer = mObserver;
|
||||||
}
|
}
|
||||||
if (observer != null) {
|
if (observer != null) {
|
||||||
@@ -163,6 +161,8 @@ public abstract class PrinterDiscoverySession {
|
|||||||
} catch (RemoteException re) {
|
} catch (RemoteException re) {
|
||||||
Log.e(LOG_TAG, "Error removing printers", re);
|
Log.e(LOG_TAG, "Error removing printers", re);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
Log.w(LOG_TAG, "Printer discovery session not open not removing printers.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,21 +171,19 @@ public abstract class PrinterDiscoverySession {
|
|||||||
* was removed has no effect. You can call this method multiple times
|
* was removed has no effect. You can call this method multiple times
|
||||||
* during printer discovery.
|
* during printer discovery.
|
||||||
* <p>
|
* <p>
|
||||||
* <strong>Note: </strong> Calling this method when the session is closed,
|
* <strong>Note: </strong> Calls to this method before the session is opened,
|
||||||
* which is if {@link #isClosed()} returns true, will throw an {@link
|
* i.e. before the {@link #onOpen(List)} call, and after the session is closed,
|
||||||
* IllegalStateException}.
|
* i.e. after the call to {@link #onClose()}, will be ignored.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param printers The printers to update.
|
* @param printers The printers to update.
|
||||||
*
|
*
|
||||||
* @see #addPrinters(List)
|
* @see #addPrinters(List)
|
||||||
* @see #removePrinters(List)
|
* @see #removePrinters(List)
|
||||||
* @see #isClosed()
|
|
||||||
*/
|
*/
|
||||||
public final void updatePrinters(List<PrinterInfo> printers) {
|
public final void updatePrinters(List<PrinterInfo> printers) {
|
||||||
final IPrinterDiscoverySessionObserver observer;
|
final IPrinterDiscoverySessionObserver observer;
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
throwIfClosedLocked();
|
|
||||||
observer = mObserver;
|
observer = mObserver;
|
||||||
}
|
}
|
||||||
if (observer != null) {
|
if (observer != null) {
|
||||||
@@ -194,6 +192,8 @@ public abstract class PrinterDiscoverySession {
|
|||||||
} catch (RemoteException re) {
|
} catch (RemoteException re) {
|
||||||
Log.e(LOG_TAG, "Error updating printers", re);
|
Log.e(LOG_TAG, "Error updating printers", re);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
Log.w(LOG_TAG, "Printer discovery session not open not updating printers.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -217,7 +217,6 @@ public abstract class PrinterDiscoverySession {
|
|||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @see #onClose()
|
* @see #onClose()
|
||||||
* @see #isClosed()
|
|
||||||
* @see #addPrinters(List)
|
* @see #addPrinters(List)
|
||||||
* @see #removePrinters(List)
|
* @see #removePrinters(List)
|
||||||
* @see #updatePrinters(List)
|
* @see #updatePrinters(List)
|
||||||
@@ -226,16 +225,9 @@ public abstract class PrinterDiscoverySession {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Callback notifying you that the session is closed and you should stop
|
* Callback notifying you that the session is closed and you should stop
|
||||||
* printer discovery. After the session is closed and any attempt to call
|
* printer discovery. After the session is closed any call to the methods
|
||||||
* any of its methods will throw an exception. Whether a session is closed
|
* of this instance will be ignored. Once the session is closed
|
||||||
* can be checked by calling {@link #isClosed()}. Once the session is closed
|
|
||||||
* it will never be opened again.
|
* it will never be opened again.
|
||||||
*
|
|
||||||
* @see #onOpen(List)
|
|
||||||
* @see #isClosed()
|
|
||||||
* @see #addPrinters(List)
|
|
||||||
* @see #removePrinters(List)
|
|
||||||
* @see #updatePrinters(List)
|
|
||||||
*/
|
*/
|
||||||
public abstract void onClose();
|
public abstract void onClose();
|
||||||
|
|
||||||
@@ -263,31 +255,13 @@ public abstract class PrinterDiscoverySession {
|
|||||||
*/
|
*/
|
||||||
public abstract void onRequestPrinterUpdate(PrinterId printerId);
|
public abstract void onRequestPrinterUpdate(PrinterId printerId);
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets whether this session is closed.
|
|
||||||
*
|
|
||||||
* @return Whether the session is closed.
|
|
||||||
*/
|
|
||||||
public final boolean isClosed() {
|
|
||||||
synchronized (mLock) {
|
|
||||||
return (mController == null && mObserver == null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void close() {
|
void close() {
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
throwIfClosedLocked();
|
|
||||||
mController = null;
|
mController = null;
|
||||||
mObserver = null;
|
mObserver = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void throwIfClosedLocked() {
|
|
||||||
if (isClosed()) {
|
|
||||||
throw new IllegalStateException("Session is closed");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private final class SessionHandler extends Handler {
|
private final class SessionHandler extends Handler {
|
||||||
public static final int MSG_OPEN = 1;
|
public static final int MSG_OPEN = 1;
|
||||||
public static final int MSG_CLOSE = 2;
|
public static final int MSG_CLOSE = 2;
|
||||||
|
|||||||
Reference in New Issue
Block a user