Merge "Change hasCustomPrintIcon and setStatus as requested by API council." into nyc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
ebf397625e
@@ -30270,7 +30270,7 @@ package android.print {
|
|||||||
method public android.print.PrinterInfo build();
|
method public android.print.PrinterInfo build();
|
||||||
method public android.print.PrinterInfo.Builder setCapabilities(android.print.PrinterCapabilitiesInfo);
|
method public android.print.PrinterInfo.Builder setCapabilities(android.print.PrinterCapabilitiesInfo);
|
||||||
method public android.print.PrinterInfo.Builder setDescription(java.lang.String);
|
method public android.print.PrinterInfo.Builder setDescription(java.lang.String);
|
||||||
method public android.print.PrinterInfo.Builder setHasCustomPrinterIcon();
|
method public android.print.PrinterInfo.Builder setHasCustomPrinterIcon(boolean);
|
||||||
method public android.print.PrinterInfo.Builder setIconResourceId(int);
|
method public android.print.PrinterInfo.Builder setIconResourceId(int);
|
||||||
method public android.print.PrinterInfo.Builder setInfoIntent(android.app.PendingIntent);
|
method public android.print.PrinterInfo.Builder setInfoIntent(android.app.PendingIntent);
|
||||||
method public android.print.PrinterInfo.Builder setName(java.lang.String);
|
method public android.print.PrinterInfo.Builder setName(java.lang.String);
|
||||||
@@ -30322,6 +30322,7 @@ package android.printservice {
|
|||||||
method public boolean isStarted();
|
method public boolean isStarted();
|
||||||
method public void setProgress(float);
|
method public void setProgress(float);
|
||||||
method public void setStatus(java.lang.CharSequence);
|
method public void setStatus(java.lang.CharSequence);
|
||||||
|
method public void setStatus(int);
|
||||||
method public boolean setTag(java.lang.String);
|
method public boolean setTag(java.lang.String);
|
||||||
method public boolean start();
|
method public boolean start();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32583,7 +32583,7 @@ package android.print {
|
|||||||
method public android.print.PrinterInfo build();
|
method public android.print.PrinterInfo build();
|
||||||
method public android.print.PrinterInfo.Builder setCapabilities(android.print.PrinterCapabilitiesInfo);
|
method public android.print.PrinterInfo.Builder setCapabilities(android.print.PrinterCapabilitiesInfo);
|
||||||
method public android.print.PrinterInfo.Builder setDescription(java.lang.String);
|
method public android.print.PrinterInfo.Builder setDescription(java.lang.String);
|
||||||
method public android.print.PrinterInfo.Builder setHasCustomPrinterIcon();
|
method public android.print.PrinterInfo.Builder setHasCustomPrinterIcon(boolean);
|
||||||
method public android.print.PrinterInfo.Builder setIconResourceId(int);
|
method public android.print.PrinterInfo.Builder setIconResourceId(int);
|
||||||
method public android.print.PrinterInfo.Builder setInfoIntent(android.app.PendingIntent);
|
method public android.print.PrinterInfo.Builder setInfoIntent(android.app.PendingIntent);
|
||||||
method public android.print.PrinterInfo.Builder setName(java.lang.String);
|
method public android.print.PrinterInfo.Builder setName(java.lang.String);
|
||||||
@@ -32635,6 +32635,7 @@ package android.printservice {
|
|||||||
method public boolean isStarted();
|
method public boolean isStarted();
|
||||||
method public void setProgress(float);
|
method public void setProgress(float);
|
||||||
method public void setStatus(java.lang.CharSequence);
|
method public void setStatus(java.lang.CharSequence);
|
||||||
|
method public void setStatus(int);
|
||||||
method public boolean setTag(java.lang.String);
|
method public boolean setTag(java.lang.String);
|
||||||
method public boolean start();
|
method public boolean start();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30262,7 +30262,7 @@ package android.print {
|
|||||||
method public android.print.PrinterId getPrinterId();
|
method public android.print.PrinterId getPrinterId();
|
||||||
method public float getProgress();
|
method public float getProgress();
|
||||||
method public int getState();
|
method public int getState();
|
||||||
method public java.lang.CharSequence getStatus();
|
method public java.lang.CharSequence getStatus(android.content.pm.PackageManager);
|
||||||
method public void writeToParcel(android.os.Parcel, int);
|
method public void writeToParcel(android.os.Parcel, int);
|
||||||
field public static final android.os.Parcelable.Creator<android.print.PrintJobInfo> CREATOR;
|
field public static final android.os.Parcelable.Creator<android.print.PrintJobInfo> CREATOR;
|
||||||
field public static final int STATE_BLOCKED = 4; // 0x4
|
field public static final int STATE_BLOCKED = 4; // 0x4
|
||||||
@@ -30339,7 +30339,7 @@ package android.print {
|
|||||||
method public android.print.PrinterInfo build();
|
method public android.print.PrinterInfo build();
|
||||||
method public android.print.PrinterInfo.Builder setCapabilities(android.print.PrinterCapabilitiesInfo);
|
method public android.print.PrinterInfo.Builder setCapabilities(android.print.PrinterCapabilitiesInfo);
|
||||||
method public android.print.PrinterInfo.Builder setDescription(java.lang.String);
|
method public android.print.PrinterInfo.Builder setDescription(java.lang.String);
|
||||||
method public android.print.PrinterInfo.Builder setHasCustomPrinterIcon();
|
method public android.print.PrinterInfo.Builder setHasCustomPrinterIcon(boolean);
|
||||||
method public android.print.PrinterInfo.Builder setIconResourceId(int);
|
method public android.print.PrinterInfo.Builder setIconResourceId(int);
|
||||||
method public android.print.PrinterInfo.Builder setInfoIntent(android.app.PendingIntent);
|
method public android.print.PrinterInfo.Builder setInfoIntent(android.app.PendingIntent);
|
||||||
method public android.print.PrinterInfo.Builder setName(java.lang.String);
|
method public android.print.PrinterInfo.Builder setName(java.lang.String);
|
||||||
@@ -30391,6 +30391,7 @@ package android.printservice {
|
|||||||
method public boolean isStarted();
|
method public boolean isStarted();
|
||||||
method public void setProgress(float);
|
method public void setProgress(float);
|
||||||
method public void setStatus(java.lang.CharSequence);
|
method public void setStatus(java.lang.CharSequence);
|
||||||
|
method public void setStatus(int);
|
||||||
method public boolean setTag(java.lang.String);
|
method public boolean setTag(java.lang.String);
|
||||||
method public boolean start();
|
method public boolean start();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,6 +60,15 @@ oneway interface IPrintSpooler {
|
|||||||
*/
|
*/
|
||||||
void setStatus(in PrintJobId printJobId, in CharSequence status);
|
void setStatus(in PrintJobId printJobId, in CharSequence status);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the status of this print job
|
||||||
|
*
|
||||||
|
* @param printJobId The print job to update
|
||||||
|
* @param status The new status as a string resource
|
||||||
|
* @param appPackageName App package name the resource belongs to
|
||||||
|
*/
|
||||||
|
void setStatusRes(in PrintJobId printJobId, int status, in CharSequence appPackageName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle that a custom icon for a printer was loaded.
|
* Handle that a custom icon for a printer was loaded.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -21,7 +21,10 @@ import android.annotation.IntDef;
|
|||||||
import android.annotation.IntRange;
|
import android.annotation.IntRange;
|
||||||
import android.annotation.NonNull;
|
import android.annotation.NonNull;
|
||||||
import android.annotation.Nullable;
|
import android.annotation.Nullable;
|
||||||
|
import android.annotation.StringRes;
|
||||||
import android.annotation.TestApi;
|
import android.annotation.TestApi;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
|
import android.content.res.Resources;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
@@ -181,7 +184,11 @@ public final class PrintJobInfo implements Parcelable {
|
|||||||
private float mProgress;
|
private float mProgress;
|
||||||
|
|
||||||
/** A short string describing the status of this job. */
|
/** A short string describing the status of this job. */
|
||||||
private CharSequence mStatus;
|
private @Nullable CharSequence mStatus;
|
||||||
|
|
||||||
|
/** A string resource describing the status of this job. */
|
||||||
|
private @StringRes int mStatusRes;
|
||||||
|
private @Nullable CharSequence mStatusResAppPackageName;
|
||||||
|
|
||||||
/** Advanced printer specific options. */
|
/** Advanced printer specific options. */
|
||||||
private Bundle mAdvancedOptions;
|
private Bundle mAdvancedOptions;
|
||||||
@@ -210,6 +217,8 @@ public final class PrintJobInfo implements Parcelable {
|
|||||||
mDocumentInfo = other.mDocumentInfo;
|
mDocumentInfo = other.mDocumentInfo;
|
||||||
mProgress = other.mProgress;
|
mProgress = other.mProgress;
|
||||||
mStatus = other.mStatus;
|
mStatus = other.mStatus;
|
||||||
|
mStatusRes = other.mStatusRes;
|
||||||
|
mStatusResAppPackageName = other.mStatusResAppPackageName;
|
||||||
mCanceling = other.mCanceling;
|
mCanceling = other.mCanceling;
|
||||||
mAdvancedOptions = other.mAdvancedOptions;
|
mAdvancedOptions = other.mAdvancedOptions;
|
||||||
}
|
}
|
||||||
@@ -235,8 +244,14 @@ public final class PrintJobInfo implements Parcelable {
|
|||||||
mDocumentInfo = (PrintDocumentInfo) parcel.readParcelable(null);
|
mDocumentInfo = (PrintDocumentInfo) parcel.readParcelable(null);
|
||||||
mProgress = parcel.readFloat();
|
mProgress = parcel.readFloat();
|
||||||
mStatus = parcel.readCharSequence();
|
mStatus = parcel.readCharSequence();
|
||||||
|
mStatusRes = parcel.readInt();
|
||||||
|
mStatusResAppPackageName = parcel.readCharSequence();
|
||||||
mCanceling = (parcel.readInt() == 1);
|
mCanceling = (parcel.readInt() == 1);
|
||||||
mAdvancedOptions = parcel.readBundle();
|
mAdvancedOptions = parcel.readBundle();
|
||||||
|
|
||||||
|
if (mAdvancedOptions != null) {
|
||||||
|
Preconditions.checkArgument(!mAdvancedOptions.containsKey(null));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -370,9 +385,27 @@ public final class PrintJobInfo implements Parcelable {
|
|||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
public void setStatus(@Nullable CharSequence status) {
|
public void setStatus(@Nullable CharSequence status) {
|
||||||
|
mStatusRes = 0;
|
||||||
|
mStatusResAppPackageName = null;
|
||||||
|
|
||||||
mStatus = status;
|
mStatus = status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the status of the print job.
|
||||||
|
*
|
||||||
|
* @param status The new status as a string resource
|
||||||
|
* @param appPackageName App package name the resource belongs to
|
||||||
|
*
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public void setStatus(@StringRes int status, @NonNull CharSequence appPackageName) {
|
||||||
|
mStatus = null;
|
||||||
|
|
||||||
|
mStatusRes = status;
|
||||||
|
mStatusResAppPackageName = appPackageName;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the owning application id.
|
* Sets the owning application id.
|
||||||
*
|
*
|
||||||
@@ -633,6 +666,8 @@ public final class PrintJobInfo implements Parcelable {
|
|||||||
parcel.writeParcelable(mDocumentInfo, 0);
|
parcel.writeParcelable(mDocumentInfo, 0);
|
||||||
parcel.writeFloat(mProgress);
|
parcel.writeFloat(mProgress);
|
||||||
parcel.writeCharSequence(mStatus);
|
parcel.writeCharSequence(mStatus);
|
||||||
|
parcel.writeInt(mStatusRes);
|
||||||
|
parcel.writeCharSequence(mStatusResAppPackageName);
|
||||||
parcel.writeInt(mCanceling ? 1 : 0);
|
parcel.writeInt(mCanceling ? 1 : 0);
|
||||||
parcel.writeBundle(mAdvancedOptions);
|
parcel.writeBundle(mAdvancedOptions);
|
||||||
}
|
}
|
||||||
@@ -659,6 +694,9 @@ public final class PrintJobInfo implements Parcelable {
|
|||||||
builder.append(", progress: " + mProgress);
|
builder.append(", progress: " + mProgress);
|
||||||
builder.append(", status: " + (mStatus != null
|
builder.append(", status: " + (mStatus != null
|
||||||
? mStatus.toString() : null));
|
? mStatus.toString() : null));
|
||||||
|
builder.append(", statusRes: " + mStatusRes);
|
||||||
|
builder.append(", statusResAppPackageName: " + (mStatusResAppPackageName != null
|
||||||
|
? mStatusResAppPackageName.toString() : null));
|
||||||
builder.append("}");
|
builder.append("}");
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
@@ -707,12 +745,23 @@ public final class PrintJobInfo implements Parcelable {
|
|||||||
/**
|
/**
|
||||||
* Get the status of this job.
|
* Get the status of this job.
|
||||||
*
|
*
|
||||||
|
* @param pm Package manager used to resolve the string
|
||||||
|
*
|
||||||
* @return the status of this job or null if not set
|
* @return the status of this job or null if not set
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
@TestApi
|
@TestApi
|
||||||
public @Nullable CharSequence getStatus() {
|
public @Nullable CharSequence getStatus(@NonNull PackageManager pm) {
|
||||||
return mStatus;
|
if (mStatusRes == 0) {
|
||||||
|
return mStatus;
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
return pm.getResourcesForApplication(mStatusResAppPackageName.toString())
|
||||||
|
.getString(mStatusRes);
|
||||||
|
} catch (PackageManager.NameNotFoundException | Resources.NotFoundException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -789,6 +838,8 @@ public final class PrintJobInfo implements Parcelable {
|
|||||||
* @param value The option value.
|
* @param value The option value.
|
||||||
*/
|
*/
|
||||||
public void putAdvancedOption(@NonNull String key, @Nullable String value) {
|
public void putAdvancedOption(@NonNull String key, @Nullable String value) {
|
||||||
|
Preconditions.checkNotNull(key, "key cannot be null");
|
||||||
|
|
||||||
if (mPrototype.mAdvancedOptions == null) {
|
if (mPrototype.mAdvancedOptions == null) {
|
||||||
mPrototype.mAdvancedOptions = new Bundle();
|
mPrototype.mAdvancedOptions = new Bundle();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -467,10 +467,12 @@ public final class PrinterInfo implements Parcelable {
|
|||||||
* {@link android.printservice.PrinterDiscoverySession#onRequestCustomPrinterIcon}.
|
* {@link android.printservice.PrinterDiscoverySession#onRequestCustomPrinterIcon}.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
|
* @param hasCustomPrinterIcon If the printer has a custom icon or not.
|
||||||
|
*
|
||||||
* @return This builder.
|
* @return This builder.
|
||||||
*/
|
*/
|
||||||
public @NonNull Builder setHasCustomPrinterIcon() {
|
public @NonNull Builder setHasCustomPrinterIcon(boolean hasCustomPrinterIcon) {
|
||||||
mHasCustomPrinterIcon = true;
|
mHasCustomPrinterIcon = hasCustomPrinterIcon;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -52,6 +52,15 @@ interface IPrintServiceClient {
|
|||||||
*/
|
*/
|
||||||
void setStatus(in PrintJobId printJobId, in CharSequence status);
|
void setStatus(in PrintJobId printJobId, in CharSequence status);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the status of this print job
|
||||||
|
*
|
||||||
|
* @param printJobId The print job to update
|
||||||
|
* @param status The new status as a string resource
|
||||||
|
* @param appPackageName The app package name the string belongs to
|
||||||
|
*/
|
||||||
|
void setStatusRes(in PrintJobId printJobId, int status, in CharSequence appPackageName);
|
||||||
|
|
||||||
void onPrintersAdded(in ParceledListSlice printers);
|
void onPrintersAdded(in ParceledListSlice printers);
|
||||||
void onPrintersRemoved(in ParceledListSlice printerIds);
|
void onPrintersRemoved(in ParceledListSlice printerIds);
|
||||||
|
|
||||||
|
|||||||
@@ -20,11 +20,14 @@ import android.annotation.FloatRange;
|
|||||||
import android.annotation.MainThread;
|
import android.annotation.MainThread;
|
||||||
import android.annotation.NonNull;
|
import android.annotation.NonNull;
|
||||||
import android.annotation.Nullable;
|
import android.annotation.Nullable;
|
||||||
|
import android.annotation.StringRes;
|
||||||
|
import android.content.Context;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.print.PrintJobId;
|
import android.print.PrintJobId;
|
||||||
import android.print.PrintJobInfo;
|
import android.print.PrintJobInfo;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import com.android.internal.util.Preconditions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class represents a print job from the perspective of a print
|
* This class represents a print job from the perspective of a print
|
||||||
@@ -45,7 +48,12 @@ public final class PrintJob {
|
|||||||
|
|
||||||
private PrintJobInfo mCachedInfo;
|
private PrintJobInfo mCachedInfo;
|
||||||
|
|
||||||
PrintJob(@NonNull PrintJobInfo jobInfo, @NonNull IPrintServiceClient client) {
|
/** Context that created the object */
|
||||||
|
private final Context mContext;
|
||||||
|
|
||||||
|
PrintJob(@NonNull Context context, @NonNull PrintJobInfo jobInfo,
|
||||||
|
@NonNull IPrintServiceClient client) {
|
||||||
|
mContext = context;
|
||||||
mCachedInfo = jobInfo;
|
mCachedInfo = jobInfo;
|
||||||
mPrintServiceClient = client;
|
mPrintServiceClient = client;
|
||||||
mDocument = new PrintDocument(mCachedInfo.getId(), client,
|
mDocument = new PrintDocument(mCachedInfo.getId(), client,
|
||||||
@@ -216,11 +224,10 @@ public final class PrintJob {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Blocks the print job. You should call this method if {@link
|
* Blocks the print job. You should call this method if {@link #isStarted()} returns true and
|
||||||
* #isStarted()} or {@link #isBlocked()} returns true and you need
|
* you need to block the print job. For example, the user has to add some paper to continue
|
||||||
* to block the print job. For example, the user has to add some
|
* printing. To resume the print job call {@link #start()}. To change the reason call
|
||||||
* paper to continue printing. To resume the print job call {@link
|
* {@link #setStatus(CharSequence)}.
|
||||||
* #start()}.
|
|
||||||
*
|
*
|
||||||
* @param reason The human readable, short, and translated reason why the print job is blocked.
|
* @param reason The human readable, short, and translated reason why the print job is blocked.
|
||||||
* @return Whether the job was blocked.
|
* @return Whether the job was blocked.
|
||||||
@@ -233,9 +240,7 @@ public final class PrintJob {
|
|||||||
PrintService.throwIfNotCalledOnMainThread();
|
PrintService.throwIfNotCalledOnMainThread();
|
||||||
PrintJobInfo info = getInfo();
|
PrintJobInfo info = getInfo();
|
||||||
final int state = info.getState();
|
final int state = info.getState();
|
||||||
if (state == PrintJobInfo.STATE_STARTED
|
if (state == PrintJobInfo.STATE_STARTED || state == PrintJobInfo.STATE_BLOCKED) {
|
||||||
|| (state == PrintJobInfo.STATE_BLOCKED
|
|
||||||
&& !TextUtils.equals(info.getStatus(), reason))) {
|
|
||||||
return setState(PrintJobInfo.STATE_BLOCKED, reason);
|
return setState(PrintJobInfo.STATE_BLOCKED, reason);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -320,6 +325,9 @@ public final class PrintJob {
|
|||||||
/**
|
/**
|
||||||
* Sets the status of this print job. This should be a human readable, short, and translated
|
* Sets the status of this print job. This should be a human readable, short, and translated
|
||||||
* description of the current state of the print job.
|
* description of the current state of the print job.
|
||||||
|
* <p />
|
||||||
|
* This overrides any previously set status set via {@link #setStatus(CharSequence)},
|
||||||
|
* {@link #setStatus(int)}, {@link #block(String)}, or {@link #fail(String)},
|
||||||
*
|
*
|
||||||
* @param status The new status. If null the status will be empty.
|
* @param status The new status. If null the status will be empty.
|
||||||
*/
|
*/
|
||||||
@@ -334,6 +342,29 @@ public final class PrintJob {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the status of this print job as a string resource.
|
||||||
|
* <p />
|
||||||
|
* This overrides any previously set status set via {@link #setStatus(CharSequence)},
|
||||||
|
* {@link #setStatus(int)}, {@link #block(String)}, or {@link #fail(String)},
|
||||||
|
* <p />
|
||||||
|
* To clear the status use {@link #setStatus(CharSequence) <code>setStatus(null)</code>}
|
||||||
|
*
|
||||||
|
* @param status The new status as a String resource.
|
||||||
|
*/
|
||||||
|
@MainThread
|
||||||
|
public void setStatus(@StringRes int status) {
|
||||||
|
PrintService.throwIfNotCalledOnMainThread();
|
||||||
|
Preconditions.checkArgument(status != 0, "status has to be != 0");
|
||||||
|
|
||||||
|
try {
|
||||||
|
mPrintServiceClient.setStatusRes(mCachedInfo.getId(), status,
|
||||||
|
mContext.getPackageName());
|
||||||
|
} catch (RemoteException re) {
|
||||||
|
Log.e(LOG_TAG, "Error setting status for job: " + mCachedInfo.getId(), re);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets a tag that is valid in the context of a {@link PrintService}
|
* Sets a tag that is valid in the context of a {@link PrintService}
|
||||||
* and is not interpreted by the system. For example, a print service
|
* and is not interpreted by the system. For example, a print service
|
||||||
|
|||||||
@@ -329,7 +329,7 @@ public abstract class PrintService extends Service {
|
|||||||
final int printJobInfoCount = printJobInfos.size();
|
final int printJobInfoCount = printJobInfos.size();
|
||||||
printJobs = new ArrayList<PrintJob>(printJobInfoCount);
|
printJobs = new ArrayList<PrintJob>(printJobInfoCount);
|
||||||
for (int i = 0; i < printJobInfoCount; i++) {
|
for (int i = 0; i < printJobInfoCount; i++) {
|
||||||
printJobs.add(new PrintJob(printJobInfos.get(i), mClient));
|
printJobs.add(new PrintJob(this, printJobInfos.get(i), mClient));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (printJobs != null) {
|
if (printJobs != null) {
|
||||||
@@ -549,7 +549,7 @@ public abstract class PrintService extends Service {
|
|||||||
+ getPackageName());
|
+ getPackageName());
|
||||||
}
|
}
|
||||||
PrintJobInfo printJobInfo = (PrintJobInfo) message.obj;
|
PrintJobInfo printJobInfo = (PrintJobInfo) message.obj;
|
||||||
onRequestCancelPrintJob(new PrintJob(printJobInfo, mClient));
|
onRequestCancelPrintJob(new PrintJob(PrintService.this, printJobInfo, mClient));
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case MSG_ON_PRINTJOB_QUEUED: {
|
case MSG_ON_PRINTJOB_QUEUED: {
|
||||||
@@ -561,7 +561,7 @@ public abstract class PrintService extends Service {
|
|||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Log.i(LOG_TAG, "Queued: " + printJobInfo);
|
Log.i(LOG_TAG, "Queued: " + printJobInfo);
|
||||||
}
|
}
|
||||||
onPrintJobQueued(new PrintJob(printJobInfo, mClient));
|
onPrintJobQueued(new PrintJob(PrintService.this, printJobInfo, mClient));
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case MSG_SET_CLIENT: {
|
case MSG_SET_CLIENT: {
|
||||||
|
|||||||
@@ -34,6 +34,20 @@ public class Preconditions {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ensures that an expression checking an argument is true.
|
||||||
|
*
|
||||||
|
* @param expression the expression to check
|
||||||
|
* @param errorMessage the exception message to use if the check fails; will
|
||||||
|
* be converted to a string using {@link String#valueOf(Object)}
|
||||||
|
* @throws IllegalArgumentException if {@code expression} is false
|
||||||
|
*/
|
||||||
|
public static void checkArgument(boolean expression, final Object errorMessage) {
|
||||||
|
if (!expression) {
|
||||||
|
throw new IllegalArgumentException(String.valueOf(errorMessage));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ensures that an string reference passed as a parameter to the calling
|
* Ensures that an string reference passed as a parameter to the calling
|
||||||
* method is not empty.
|
* method is not empty.
|
||||||
|
|||||||
@@ -208,7 +208,7 @@ final class NotificationController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CharSequence status = printJob.getStatus();
|
CharSequence status = printJob.getStatus(mContext.getPackageManager());
|
||||||
if (status != null) {
|
if (status != null) {
|
||||||
builder.setContentText(status);
|
builder.setContentText(status);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ package com.android.printspooler.model;
|
|||||||
import android.annotation.FloatRange;
|
import android.annotation.FloatRange;
|
||||||
import android.annotation.NonNull;
|
import android.annotation.NonNull;
|
||||||
import android.annotation.Nullable;
|
import android.annotation.Nullable;
|
||||||
|
import android.annotation.StringRes;
|
||||||
import android.app.Service;
|
import android.app.Service;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@@ -575,19 +576,35 @@ public final class PrintSpoolerService extends Service {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the status for a print job.
|
* Set the status for a print job.
|
||||||
*
|
*
|
||||||
* @param printJobId ID of the print job to update
|
* @param printJobId ID of the print job to update
|
||||||
* @param status the new status
|
* @param status the new status
|
||||||
*/
|
*/
|
||||||
public void setStatus(@NonNull PrintJobId printJobId, @Nullable CharSequence status) {
|
public void setStatus(@NonNull PrintJobId printJobId, @Nullable CharSequence status) {
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
getPrintJobInfo(printJobId, PrintManager.APP_ID_ANY).setStatus(status);
|
getPrintJobInfo(printJobId, PrintManager.APP_ID_ANY).setStatus(status);
|
||||||
|
|
||||||
mNotificationController.onUpdateNotifications(mPrintJobs);
|
mNotificationController.onUpdateNotifications(mPrintJobs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the status for a print job.
|
||||||
|
*
|
||||||
|
* @param printJobId ID of the print job to update
|
||||||
|
* @param status the new status as a string resource
|
||||||
|
* @param appPackageName app package the resource belongs to
|
||||||
|
*/
|
||||||
|
public void setStatus(@NonNull PrintJobId printJobId, @StringRes int status,
|
||||||
|
@Nullable CharSequence appPackageName) {
|
||||||
|
synchronized (mLock) {
|
||||||
|
getPrintJobInfo(printJobId, PrintManager.APP_ID_ANY).setStatus(status, appPackageName);
|
||||||
|
|
||||||
|
mNotificationController.onUpdateNotifications(mPrintJobs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public boolean hasActivePrintJobsLocked() {
|
public boolean hasActivePrintJobsLocked() {
|
||||||
final int printJobCount = mPrintJobs.size();
|
final int printJobCount = mPrintJobs.size();
|
||||||
@@ -884,7 +901,7 @@ public final class PrintSpoolerService extends Service {
|
|||||||
serializer.attribute(null, ATTR_PROGRESS, String.valueOf(progress));
|
serializer.attribute(null, ATTR_PROGRESS, String.valueOf(progress));
|
||||||
}
|
}
|
||||||
|
|
||||||
CharSequence status = printJob.getStatus();
|
CharSequence status = printJob.getStatus(getPackageManager());
|
||||||
if (!TextUtils.isEmpty(status)) {
|
if (!TextUtils.isEmpty(status)) {
|
||||||
serializer.attribute(null, ATTR_STATUS, status.toString());
|
serializer.attribute(null, ATTR_STATUS, status.toString());
|
||||||
}
|
}
|
||||||
@@ -1435,6 +1452,13 @@ public final class PrintSpoolerService extends Service {
|
|||||||
PrintSpoolerService.this.setStatus(printJobId, status);
|
PrintSpoolerService.this.setStatus(printJobId, status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setStatusRes(@NonNull PrintJobId printJobId, @StringRes int status,
|
||||||
|
@NonNull CharSequence appPackageName) throws RemoteException {
|
||||||
|
PrintSpoolerService.this.setStatus(printJobId, status, appPackageName);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public PrintSpoolerService getService() {
|
public PrintSpoolerService getService() {
|
||||||
return PrintSpoolerService.this;
|
return PrintSpoolerService.this;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ package com.android.server.print;
|
|||||||
import android.annotation.FloatRange;
|
import android.annotation.FloatRange;
|
||||||
import android.annotation.NonNull;
|
import android.annotation.NonNull;
|
||||||
import android.annotation.Nullable;
|
import android.annotation.Nullable;
|
||||||
|
import android.annotation.StringRes;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
@@ -812,6 +813,20 @@ final class RemotePrintService implements DeathRecipient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setStatusRes(@NonNull PrintJobId printJobId, @StringRes int status,
|
||||||
|
@NonNull CharSequence appPackageName) {
|
||||||
|
RemotePrintService service = mWeakService.get();
|
||||||
|
if (service != null) {
|
||||||
|
final long identity = Binder.clearCallingIdentity();
|
||||||
|
try {
|
||||||
|
service.mSpooler.setStatus(printJobId, status, appPackageName);
|
||||||
|
} finally {
|
||||||
|
Binder.restoreCallingIdentity(identity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||||
public void onPrintersAdded(ParceledListSlice printers) {
|
public void onPrintersAdded(ParceledListSlice printers) {
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ package com.android.server.print;
|
|||||||
import android.annotation.FloatRange;
|
import android.annotation.FloatRange;
|
||||||
import android.annotation.NonNull;
|
import android.annotation.NonNull;
|
||||||
import android.annotation.Nullable;
|
import android.annotation.Nullable;
|
||||||
|
import android.annotation.StringRes;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
@@ -300,6 +301,35 @@ final class RemotePrintSpooler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set status of a print job.
|
||||||
|
*
|
||||||
|
* @param printJobId The print job to update
|
||||||
|
* @param status The new status as a string resource
|
||||||
|
* @param appPackageName The app package name the string res belongs to
|
||||||
|
*/
|
||||||
|
public final void setStatus(@NonNull PrintJobId printJobId, @StringRes int status,
|
||||||
|
@NonNull CharSequence appPackageName) {
|
||||||
|
throwIfCalledOnMainThread();
|
||||||
|
synchronized (mLock) {
|
||||||
|
throwIfDestroyedLocked();
|
||||||
|
mCanUnbind = false;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
getRemoteInstanceLazy().setStatusRes(printJobId, status, appPackageName);
|
||||||
|
} catch (RemoteException|TimeoutException re) {
|
||||||
|
Slog.e(LOG_TAG, "Error setting status.", re);
|
||||||
|
} finally {
|
||||||
|
if (DEBUG) {
|
||||||
|
Slog.i(LOG_TAG, "[user: " + mUserHandle.getIdentifier() + "] setStatus()");
|
||||||
|
}
|
||||||
|
synchronized (mLock) {
|
||||||
|
mCanUnbind = true;
|
||||||
|
mLock.notifyAll();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle that a custom icon for a printer was loaded.
|
* Handle that a custom icon for a printer was loaded.
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user