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