Implement persistence/restoring of print spooler state.
1. Implemented the persistence and restoring of the print spooler state. The print spooler state is saved as an XML on every print job change and is restored when we bind to the spooler. The system does not unbind from the spooler until the state persistence completes. We are now storing the entire state, i.e. all print jobs, when a single one changes. This is not optimal but we are not expecting to have many such at the same time, so for now we err for simplicity of implementation. 2. Enforcing a non-empty print job name. 3. Hidden the STATE_CREATED print job state which should never be visible to a client since this is the state of a print job during construction, i.e. the print dialog is up and we are doing back and forth with the app. 4. Fixed some PrintAttributes APIs that were incorrectly taking in a PackageManager instance. 5. Updated the PrintSpooler build file due to splitting the framework into multiple jars. Change-Id: I52c88eaa1ec9c64920359cc143c79832a4c3d25b
This commit is contained in:
@ -42,8 +42,10 @@ public final class PageRange implements Parcelable {
|
||||
* @throws IllegalArgumentException If start is less than zero.
|
||||
* @throws IllegalArgumentException If end is less than zero.
|
||||
* @throws IllegalArgumentException If start greater than end.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
PageRange(int start, int end) {
|
||||
public PageRange(int start, int end) {
|
||||
if (start < 0) {
|
||||
throw new IllegalArgumentException("start cannot be less than zero.");
|
||||
}
|
||||
|
@ -1007,7 +1007,7 @@ public final class PrintAttributes implements Parcelable {
|
||||
*
|
||||
* @return The human readable label.
|
||||
*/
|
||||
public CharSequence getLabel(PackageManager packageManager) {
|
||||
public CharSequence getLabel() {
|
||||
return mLabel;
|
||||
}
|
||||
|
||||
@ -1203,7 +1203,7 @@ public final class PrintAttributes implements Parcelable {
|
||||
*
|
||||
* @return The human readable label.
|
||||
*/
|
||||
public CharSequence getLabel(PackageManager packageManager) {
|
||||
public CharSequence getLabel() {
|
||||
return mLabel;
|
||||
}
|
||||
|
||||
|
@ -110,6 +110,16 @@ public final class PrintDocumentInfo implements Parcelable {
|
||||
parcel.writeInt(mContentType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("PrintDocumentInfo{");
|
||||
builder.append("pageCount: ").append(mPageCount);
|
||||
builder.append(", contentType: ").append(mContentType);
|
||||
builder.append("}");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Builder for creating an {@link PrintDocumentInfo}.
|
||||
*/
|
||||
|
@ -34,12 +34,21 @@ public final class PrintJobInfo implements Parcelable {
|
||||
*/
|
||||
public static final int STATE_ANY = -1;
|
||||
|
||||
/**
|
||||
* Constant for matching any print job state.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public static final int STATE_ANY_VISIBLE_TO_CLIENTS = -2;
|
||||
|
||||
/**
|
||||
* Print job state: The print job is being created but not yet
|
||||
* ready to be printed.
|
||||
* <p>
|
||||
* Next valid states: {@link #STATE_QUEUED}
|
||||
* </p>
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public static final int STATE_CREATED = 1;
|
||||
|
||||
@ -132,6 +141,7 @@ public final class PrintJobInfo implements Parcelable {
|
||||
mState = other.mState;
|
||||
mAppId = other.mAppId;
|
||||
mUserId = other.mUserId;
|
||||
mTag = other.mTag;
|
||||
mAttributes = other.mAttributes;
|
||||
mDocumentInfo = other.mDocumentInfo;
|
||||
}
|
||||
@ -143,6 +153,7 @@ public final class PrintJobInfo implements Parcelable {
|
||||
mState = parcel.readInt();
|
||||
mAppId = parcel.readInt();
|
||||
mUserId = parcel.readInt();
|
||||
mTag = parcel.readString();
|
||||
if (parcel.readInt() == 1) {
|
||||
mPageRanges = (PageRange[]) parcel.readParcelableArray(null);
|
||||
}
|
||||
@ -373,6 +384,7 @@ public final class PrintJobInfo implements Parcelable {
|
||||
parcel.writeInt(mState);
|
||||
parcel.writeInt(mAppId);
|
||||
parcel.writeInt(mUserId);
|
||||
parcel.writeString(mTag);
|
||||
if (mPageRanges != null) {
|
||||
parcel.writeInt(1);
|
||||
parcel.writeParcelableArray(mPageRanges, flags);
|
||||
|
@ -29,6 +29,7 @@ import android.os.ParcelFileDescriptor;
|
||||
import android.os.RemoteException;
|
||||
import android.print.PrintDocumentAdapter.LayoutResultCallback;
|
||||
import android.print.PrintDocumentAdapter.WriteResultCallback;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.internal.os.SomeArgs;
|
||||
@ -184,6 +185,9 @@ public final class PrintManager {
|
||||
*/
|
||||
public PrintJob print(String printJobName, PrintDocumentAdapter documentAdapter,
|
||||
PrintAttributes attributes) {
|
||||
if (TextUtils.isEmpty(printJobName)) {
|
||||
throw new IllegalArgumentException("priintJobName cannot be empty");
|
||||
}
|
||||
PrintDocumentAdapterDelegate delegate = new PrintDocumentAdapterDelegate(documentAdapter,
|
||||
mContext.getMainLooper());
|
||||
try {
|
||||
|
@ -125,26 +125,6 @@ public final class PrinterId implements Parcelable {
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
public String flattenToString() {
|
||||
return mServiceComponentName.flattenToString() + ":" + mLocalId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
public static PrinterId unflattenFromString(String string) {
|
||||
String[] split = string.split(":");
|
||||
if (split.length != 2) {
|
||||
throw new IllegalArgumentException("Not well-formed printer id:" + string);
|
||||
}
|
||||
ComponentName component = ComponentName.unflattenFromString(split[0]);
|
||||
String localId = String.valueOf(split[1]);
|
||||
return new PrinterId(component, localId);
|
||||
}
|
||||
|
||||
public static final Parcelable.Creator<PrinterId> CREATOR =
|
||||
new Creator<PrinterId>() {
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user