Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.printservice; |
| 18 | |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 19 | import android.os.RemoteException; |
Svetoslav | 2fbd2a7 | 2013-09-16 17:53:51 -0700 | [diff] [blame] | 20 | import android.print.PrintJobId; |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 21 | import android.print.PrintJobInfo; |
Svetoslav Ganov | d26d489 | 2013-08-28 14:37:54 -0700 | [diff] [blame] | 22 | import android.text.TextUtils; |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 23 | import android.util.Log; |
| 24 | |
| 25 | /** |
Svetoslav Ganov | 798bed6 | 2013-08-11 12:29:39 -0700 | [diff] [blame] | 26 | * This class represents a print job from the perspective of a print |
| 27 | * service. It provides APIs for observing the print job state and |
| 28 | * performing operations on the print job. |
Svetoslav | 269403b | 2013-08-14 17:31:04 -0700 | [diff] [blame] | 29 | * <p> |
Svetoslav Ganov | 99cc86f | 2013-08-29 21:37:10 -0700 | [diff] [blame] | 30 | * <strong>Note: </strong> All methods of this class must be invoked on |
| 31 | * the main application thread. |
Svetoslav | 269403b | 2013-08-14 17:31:04 -0700 | [diff] [blame] | 32 | * </p> |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 33 | */ |
| 34 | public final class PrintJob { |
| 35 | |
| 36 | private static final String LOG_TAG = "PrintJob"; |
| 37 | |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 38 | private final IPrintServiceClient mPrintServiceClient; |
| 39 | |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 40 | private final PrintDocument mDocument; |
| 41 | |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 42 | private PrintJobInfo mCachedInfo; |
| 43 | |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 44 | PrintJob(PrintJobInfo jobInfo, IPrintServiceClient client) { |
| 45 | mCachedInfo = jobInfo; |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 46 | mPrintServiceClient = client; |
Svetoslav Ganov | 798bed6 | 2013-08-11 12:29:39 -0700 | [diff] [blame] | 47 | mDocument = new PrintDocument(mCachedInfo.getId(), client, |
| 48 | jobInfo.getDocumentInfo()); |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Gets the unique print job id. |
| 53 | * |
| 54 | * @return The id. |
| 55 | */ |
Svetoslav | 2fbd2a7 | 2013-09-16 17:53:51 -0700 | [diff] [blame] | 56 | public PrintJobId getId() { |
Svetoslav | 269403b | 2013-08-14 17:31:04 -0700 | [diff] [blame] | 57 | PrintService.throwIfNotCalledOnMainThread(); |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 58 | return mCachedInfo.getId(); |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Gets the {@link PrintJobInfo} that describes this job. |
| 63 | * <p> |
| 64 | * <strong>Node:</strong>The returned info object is a snapshot of the |
| 65 | * current print job state. Every call to this method returns a fresh |
Svetoslav | fd90651 | 2013-06-24 09:04:48 -0700 | [diff] [blame] | 66 | * info object that reflects the current print job state. |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 67 | * </p> |
| 68 | * |
| 69 | * @return The print job info. |
| 70 | */ |
| 71 | public PrintJobInfo getInfo() { |
Svetoslav | 269403b | 2013-08-14 17:31:04 -0700 | [diff] [blame] | 72 | PrintService.throwIfNotCalledOnMainThread(); |
Svetoslav Ganov | 85b1f88 | 2013-07-24 17:00:06 -0700 | [diff] [blame] | 73 | if (isInImmutableState()) { |
| 74 | return mCachedInfo; |
| 75 | } |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 76 | PrintJobInfo info = null; |
| 77 | try { |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 78 | info = mPrintServiceClient.getPrintJobInfo(mCachedInfo.getId()); |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 79 | } catch (RemoteException re) { |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 80 | Log.e(LOG_TAG, "Couldn't get info for job: " + mCachedInfo.getId(), re); |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 81 | } |
| 82 | if (info != null) { |
| 83 | mCachedInfo = info; |
| 84 | } |
| 85 | return mCachedInfo; |
| 86 | } |
| 87 | |
| 88 | /** |
Svetoslav Ganov | 798bed6 | 2013-08-11 12:29:39 -0700 | [diff] [blame] | 89 | * Gets the printed document. |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 90 | * |
| 91 | * @return The document. |
| 92 | */ |
| 93 | public PrintDocument getDocument() { |
Svetoslav | 269403b | 2013-08-14 17:31:04 -0700 | [diff] [blame] | 94 | PrintService.throwIfNotCalledOnMainThread(); |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 95 | return mDocument; |
| 96 | } |
| 97 | |
| 98 | /** |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 99 | * Gets whether this print job is queued. Such a print job is |
Svetoslav Ganov | 798bed6 | 2013-08-11 12:29:39 -0700 | [diff] [blame] | 100 | * ready to be printed and can be started or cancelled. |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 101 | * |
| 102 | * @return Whether the print job is queued. |
| 103 | * |
| 104 | * @see #start() |
Svetoslav Ganov | 798bed6 | 2013-08-11 12:29:39 -0700 | [diff] [blame] | 105 | * @see #cancel() |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 106 | */ |
| 107 | public boolean isQueued() { |
Svetoslav | 269403b | 2013-08-14 17:31:04 -0700 | [diff] [blame] | 108 | PrintService.throwIfNotCalledOnMainThread(); |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 109 | return getInfo().getState() == PrintJobInfo.STATE_QUEUED; |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Gets whether this print job is started. Such a print job is |
| 114 | * being printed and can be completed or canceled or failed. |
| 115 | * |
| 116 | * @return Whether the print job is started. |
| 117 | * |
| 118 | * @see #complete() |
| 119 | * @see #cancel() |
Svetoslav | fd90651 | 2013-06-24 09:04:48 -0700 | [diff] [blame] | 120 | * @see #fail(CharSequence) |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 121 | */ |
| 122 | public boolean isStarted() { |
Svetoslav | 269403b | 2013-08-14 17:31:04 -0700 | [diff] [blame] | 123 | PrintService.throwIfNotCalledOnMainThread(); |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 124 | return getInfo().getState() == PrintJobInfo.STATE_STARTED; |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | /** |
Svetoslav Ganov | d26d489 | 2013-08-28 14:37:54 -0700 | [diff] [blame] | 128 | * Gets whether this print job is blocked. Such a print job is halted |
| 129 | * due to an abnormal condition and can be started or canceled or failed. |
| 130 | * |
| 131 | * @return Whether the print job is blocked. |
| 132 | * |
| 133 | * @see #start() |
| 134 | * @see #cancel() |
| 135 | * @see #fail(CharSequence) |
| 136 | */ |
| 137 | public boolean isBlocked() { |
| 138 | PrintService.throwIfNotCalledOnMainThread(); |
| 139 | return getInfo().getState() == PrintJobInfo.STATE_BLOCKED; |
| 140 | } |
| 141 | |
| 142 | /** |
Svetoslav Ganov | 798bed6 | 2013-08-11 12:29:39 -0700 | [diff] [blame] | 143 | * Gets whether this print job is completed. Such a print job |
| 144 | * is successfully printed. This is a final state. |
| 145 | * |
| 146 | * @return Whether the print job is completed. |
| 147 | * |
| 148 | * @see #complete() |
| 149 | */ |
| 150 | public boolean isCompleted() { |
Svetoslav | 269403b | 2013-08-14 17:31:04 -0700 | [diff] [blame] | 151 | PrintService.throwIfNotCalledOnMainThread(); |
Svetoslav Ganov | 798bed6 | 2013-08-11 12:29:39 -0700 | [diff] [blame] | 152 | return getInfo().getState() == PrintJobInfo.STATE_COMPLETED; |
| 153 | } |
| 154 | |
| 155 | /** |
| 156 | * Gets whether this print job is failed. Such a print job is |
| 157 | * not successfully printed due to an error. This is a final state. |
| 158 | * |
| 159 | * @return Whether the print job is failed. |
| 160 | * |
| 161 | * @see #fail(CharSequence) |
| 162 | */ |
| 163 | public boolean isFailed() { |
Svetoslav | 269403b | 2013-08-14 17:31:04 -0700 | [diff] [blame] | 164 | PrintService.throwIfNotCalledOnMainThread(); |
Svetoslav Ganov | 798bed6 | 2013-08-11 12:29:39 -0700 | [diff] [blame] | 165 | return getInfo().getState() == PrintJobInfo.STATE_FAILED; |
| 166 | } |
| 167 | |
| 168 | /** |
| 169 | * Gets whether this print job is cancelled. Such a print job was |
| 170 | * cancelled as a result of a user request. This is a final state. |
| 171 | * |
| 172 | * @return Whether the print job is cancelled. |
| 173 | * |
| 174 | * @see #cancel() |
| 175 | */ |
| 176 | public boolean isCancelled() { |
Svetoslav | 269403b | 2013-08-14 17:31:04 -0700 | [diff] [blame] | 177 | PrintService.throwIfNotCalledOnMainThread(); |
Svetoslav Ganov | 704697b | 2013-09-21 20:30:24 -0700 | [diff] [blame] | 178 | return getInfo().getState() == PrintJobInfo.STATE_CANCELED; |
Svetoslav Ganov | 798bed6 | 2013-08-11 12:29:39 -0700 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | /** |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 182 | * Starts the print job. You should call this method if {@link |
Svetoslav Ganov | d26d489 | 2013-08-28 14:37:54 -0700 | [diff] [blame] | 183 | * #isQueued()} or {@link #isBlocked()} returns true and you started |
| 184 | * resumed printing. |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 185 | * |
Svetoslav Ganov | d26d489 | 2013-08-28 14:37:54 -0700 | [diff] [blame] | 186 | * @return Whether the job was started. |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 187 | * |
| 188 | * @see #isQueued() |
Svetoslav Ganov | d26d489 | 2013-08-28 14:37:54 -0700 | [diff] [blame] | 189 | * @see #isBlocked() |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 190 | */ |
| 191 | public boolean start() { |
Svetoslav | 269403b | 2013-08-14 17:31:04 -0700 | [diff] [blame] | 192 | PrintService.throwIfNotCalledOnMainThread(); |
Svetoslav Ganov | d26d489 | 2013-08-28 14:37:54 -0700 | [diff] [blame] | 193 | final int state = getInfo().getState(); |
| 194 | if (state == PrintJobInfo.STATE_QUEUED |
| 195 | || state == PrintJobInfo.STATE_BLOCKED) { |
Svetoslav Ganov | 8c43376 | 2013-08-02 14:22:19 -0700 | [diff] [blame] | 196 | return setState(PrintJobInfo.STATE_STARTED, null); |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 197 | } |
| 198 | return false; |
| 199 | } |
| 200 | |
| 201 | /** |
Svetoslav Ganov | d26d489 | 2013-08-28 14:37:54 -0700 | [diff] [blame] | 202 | * Blocks the print job. You should call this method if {@link |
| 203 | * #isStarted()} or {@link #isBlocked()} returns true and you need |
| 204 | * to block the print job. For example, the user has to add some |
| 205 | * paper to continue printing. To resume the print job call {@link |
| 206 | * #start()}. |
| 207 | * |
| 208 | * @return Whether the job was blocked. |
| 209 | * |
| 210 | * @see #isStarted() |
| 211 | * @see #isBlocked() |
| 212 | */ |
| 213 | public boolean block(String reason) { |
| 214 | PrintService.throwIfNotCalledOnMainThread(); |
| 215 | PrintJobInfo info = getInfo(); |
| 216 | final int state = info.getState(); |
| 217 | if (state == PrintJobInfo.STATE_STARTED |
| 218 | || (state == PrintJobInfo.STATE_BLOCKED |
| 219 | && !TextUtils.equals(info.getStateReason(), reason))) { |
| 220 | return setState(PrintJobInfo.STATE_BLOCKED, reason); |
| 221 | } |
| 222 | return false; |
| 223 | } |
| 224 | |
| 225 | /** |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 226 | * Completes the print job. You should call this method if {@link |
| 227 | * #isStarted()} returns true and you are done printing. |
| 228 | * |
| 229 | * @return Whether the job as completed. |
| 230 | * |
| 231 | * @see #isStarted() |
| 232 | */ |
| 233 | public boolean complete() { |
Svetoslav | 269403b | 2013-08-14 17:31:04 -0700 | [diff] [blame] | 234 | PrintService.throwIfNotCalledOnMainThread(); |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 235 | if (isStarted()) { |
Svetoslav Ganov | 8c43376 | 2013-08-02 14:22:19 -0700 | [diff] [blame] | 236 | return setState(PrintJobInfo.STATE_COMPLETED, null); |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 237 | } |
| 238 | return false; |
| 239 | } |
| 240 | |
| 241 | /** |
| 242 | * Fails the print job. You should call this method if {@link |
Svetoslav Ganov | d26d489 | 2013-08-28 14:37:54 -0700 | [diff] [blame] | 243 | * #isQueued()} or {@link #isStarted()} or {@link #isBlocked()} |
| 244 | * returns true you failed while printing. |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 245 | * |
Svetoslav Ganov | 8c43376 | 2013-08-02 14:22:19 -0700 | [diff] [blame] | 246 | * @param error The human readable, short, and translated reason |
| 247 | * for the failure. |
Svetoslav | fd90651 | 2013-06-24 09:04:48 -0700 | [diff] [blame] | 248 | * @return Whether the job was failed. |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 249 | * |
Svetoslav Ganov | 8c43376 | 2013-08-02 14:22:19 -0700 | [diff] [blame] | 250 | * @see #isQueued() |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 251 | * @see #isStarted() |
Svetoslav Ganov | d26d489 | 2013-08-28 14:37:54 -0700 | [diff] [blame] | 252 | * @see #isBlocked() |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 253 | */ |
Svetoslav | 269403b | 2013-08-14 17:31:04 -0700 | [diff] [blame] | 254 | public boolean fail(String error) { |
| 255 | PrintService.throwIfNotCalledOnMainThread(); |
Svetoslav Ganov | d26d489 | 2013-08-28 14:37:54 -0700 | [diff] [blame] | 256 | if (!isInImmutableState()) { |
Svetoslav Ganov | 8c43376 | 2013-08-02 14:22:19 -0700 | [diff] [blame] | 257 | return setState(PrintJobInfo.STATE_FAILED, error); |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 258 | } |
| 259 | return false; |
| 260 | } |
| 261 | |
| 262 | /** |
| 263 | * Cancels the print job. You should call this method if {@link |
Svetoslav Ganov | d26d489 | 2013-08-28 14:37:54 -0700 | [diff] [blame] | 264 | * #isQueued()} or {@link #isStarted() or #isBlocked()} returns |
| 265 | * true and you canceled the print job as a response to a call to |
| 266 | * {@link PrintService#onRequestCancelPrintJob(PrintJob)}. |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 267 | * |
Svetoslav Ganov | 798bed6 | 2013-08-11 12:29:39 -0700 | [diff] [blame] | 268 | * @return Whether the job is canceled. |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 269 | * |
| 270 | * @see #isStarted() |
Svetoslav Ganov | 798bed6 | 2013-08-11 12:29:39 -0700 | [diff] [blame] | 271 | * @see #isQueued() |
Svetoslav Ganov | d26d489 | 2013-08-28 14:37:54 -0700 | [diff] [blame] | 272 | * @see #isBlocked() |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 273 | */ |
| 274 | public boolean cancel() { |
Svetoslav | 269403b | 2013-08-14 17:31:04 -0700 | [diff] [blame] | 275 | PrintService.throwIfNotCalledOnMainThread(); |
Svetoslav Ganov | d26d489 | 2013-08-28 14:37:54 -0700 | [diff] [blame] | 276 | if (!isInImmutableState()) { |
Svetoslav Ganov | 8c43376 | 2013-08-02 14:22:19 -0700 | [diff] [blame] | 277 | return setState(PrintJobInfo.STATE_CANCELED, null); |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 278 | } |
| 279 | return false; |
| 280 | } |
| 281 | |
| 282 | /** |
| 283 | * Sets a tag that is valid in the context of a {@link PrintService} |
| 284 | * and is not interpreted by the system. For example, a print service |
| 285 | * may set as a tag the key of the print job returned by a remote |
| 286 | * print server, if the printing is off handed to a cloud based service. |
| 287 | * |
| 288 | * @param tag The tag. |
| 289 | * @return True if the tag was set, false otherwise. |
| 290 | */ |
| 291 | public boolean setTag(String tag) { |
Svetoslav | 269403b | 2013-08-14 17:31:04 -0700 | [diff] [blame] | 292 | PrintService.throwIfNotCalledOnMainThread(); |
Svetoslav Ganov | 85b1f88 | 2013-07-24 17:00:06 -0700 | [diff] [blame] | 293 | if (isInImmutableState()) { |
| 294 | return false; |
| 295 | } |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 296 | try { |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 297 | return mPrintServiceClient.setPrintJobTag(mCachedInfo.getId(), tag); |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 298 | } catch (RemoteException re) { |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 299 | Log.e(LOG_TAG, "Error setting tag for job: " + mCachedInfo.getId(), re); |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 300 | } |
| 301 | return false; |
| 302 | } |
| 303 | |
Svetoslav | b450d0d | 2013-10-04 16:20:00 -0700 | [diff] [blame] | 304 | /** |
| 305 | * Gets the print job tag. |
| 306 | * |
Svetoslav | 1c43fce | 2013-10-16 10:57:48 -0700 | [diff] [blame] | 307 | * @return The tag or null. |
Svetoslav | b450d0d | 2013-10-04 16:20:00 -0700 | [diff] [blame] | 308 | * |
| 309 | * @see #setTag(String) |
| 310 | */ |
| 311 | public String getTag() { |
| 312 | PrintService.throwIfNotCalledOnMainThread(); |
| 313 | return getInfo().getTag(); |
| 314 | } |
| 315 | |
Svetoslav | 1c43fce | 2013-10-16 10:57:48 -0700 | [diff] [blame] | 316 | /** |
| 317 | * Gets the value of an advanced (printer specific) print option. |
| 318 | * |
| 319 | * @param key The option key. |
| 320 | * @return The option value. |
| 321 | */ |
| 322 | public String getAdvancedStringOption(String key) { |
| 323 | PrintService.throwIfNotCalledOnMainThread(); |
Svetoslav | b4fda13 | 2013-10-25 18:57:43 -0700 | [diff] [blame] | 324 | return getInfo().getAdvancedStringOption(key); |
Svetoslav | 1c43fce | 2013-10-16 10:57:48 -0700 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | /** |
| 328 | * Gets whether this job has a given advanced (printer specific) print |
| 329 | * option. |
| 330 | * |
| 331 | * @param key The option key. |
| 332 | * @return Whether the option is present. |
| 333 | */ |
| 334 | public boolean hasAdvancedOption(String key) { |
| 335 | PrintService.throwIfNotCalledOnMainThread(); |
Svetoslav | b4fda13 | 2013-10-25 18:57:43 -0700 | [diff] [blame] | 336 | return getInfo().hasAdvancedOption(key); |
Svetoslav | 1c43fce | 2013-10-16 10:57:48 -0700 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | /** |
| 340 | * Gets the value of an advanced (printer specific) print option. |
| 341 | * |
| 342 | * @param key The option key. |
| 343 | * @return The option value. |
| 344 | */ |
| 345 | public int getAdvancedIntOption(String key) { |
| 346 | PrintService.throwIfNotCalledOnMainThread(); |
Svetoslav | b4fda13 | 2013-10-25 18:57:43 -0700 | [diff] [blame] | 347 | return getInfo().getAdvancedIntOption(key); |
Svetoslav | 1c43fce | 2013-10-16 10:57:48 -0700 | [diff] [blame] | 348 | } |
| 349 | |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 350 | @Override |
| 351 | public boolean equals(Object obj) { |
| 352 | if (this == obj) { |
| 353 | return true; |
| 354 | } |
| 355 | if (obj == null) { |
| 356 | return false; |
| 357 | } |
| 358 | if (getClass() != obj.getClass()) { |
| 359 | return false; |
| 360 | } |
| 361 | PrintJob other = (PrintJob) obj; |
Svetoslav | 2fbd2a7 | 2013-09-16 17:53:51 -0700 | [diff] [blame] | 362 | return (mCachedInfo.getId().equals(other.mCachedInfo.getId())); |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | @Override |
| 366 | public int hashCode() { |
Svetoslav | 2fbd2a7 | 2013-09-16 17:53:51 -0700 | [diff] [blame] | 367 | return mCachedInfo.getId().hashCode(); |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 368 | } |
| 369 | |
Svetoslav Ganov | 85b1f88 | 2013-07-24 17:00:06 -0700 | [diff] [blame] | 370 | private boolean isInImmutableState() { |
| 371 | final int state = mCachedInfo.getState(); |
| 372 | return state == PrintJobInfo.STATE_COMPLETED |
Svetoslav Ganov | d26d489 | 2013-08-28 14:37:54 -0700 | [diff] [blame] | 373 | || state == PrintJobInfo.STATE_CANCELED |
| 374 | || state == PrintJobInfo.STATE_FAILED; |
Svetoslav Ganov | 85b1f88 | 2013-07-24 17:00:06 -0700 | [diff] [blame] | 375 | } |
| 376 | |
Svetoslav | 269403b | 2013-08-14 17:31:04 -0700 | [diff] [blame] | 377 | private boolean setState(int state, String error) { |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 378 | try { |
Svetoslav Ganov | 8c43376 | 2013-08-02 14:22:19 -0700 | [diff] [blame] | 379 | if (mPrintServiceClient.setPrintJobState(mCachedInfo.getId(), state, error)) { |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 380 | // Best effort - update the state of the cached info since |
| 381 | // we may not be able to re-fetch it later if the job gets |
| 382 | // removed from the spooler as a result of the state change. |
| 383 | mCachedInfo.setState(state); |
Svetoslav Ganov | d26d489 | 2013-08-28 14:37:54 -0700 | [diff] [blame] | 384 | mCachedInfo.setStateReason(error); |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 385 | return true; |
| 386 | } |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 387 | } catch (RemoteException re) { |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 388 | Log.e(LOG_TAG, "Error setting the state of job: " + mCachedInfo.getId(), re); |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 389 | } |
| 390 | return false; |
| 391 | } |
| 392 | } |