Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8c43376e authored by Svetoslav Ganov's avatar Svetoslav Ganov
Browse files

First cut of the print notifications.

    1. Added notifications for a queued print job, for a started print job,
       for ongoing canceling a print job, and for a failed print job. The
       notifications for queued and started state have a cancel action. The
       notification for failed print job has a cancel and a restart action.

    2. Propagating failure message from the print service to the notifications.

    3. PrintJobConfigActivity was not setting the initial value for the
       print job copies and was not updating the UI immediately after creation.

    4. Refactored PrintJobConfigActivity to avoid using the hack to avoid
       reaction for item selection change in a spinner for an event that
       happened before the callback was registered.

    5. Removed the label attribute from PrinterInfo and now PrinterId is
       composed of the printer name and the service component name. This
       is nice since for restarting print jobs we do not need to store
       information about the printer except the printer id which is
       already part of the PrintJobInfo's data. Also the printer name
       is not expected to change anyway.

    6. Allowing cancellation of a queued print job. Also no print job is
       cancelled without asking the managing print service to do that.
       Before we were immediately canceling print jobs in queued state
       but it was possible for a buggy print service to not set the
       print job state to started before starting to do expensive work
       that will not be canceled.

    7. PrintServiceInfo was throwing an exception the the meta-data
       XML for the print service was not well-formed which would crash
       the system process. Now we just ignore not well-formed meta-data.

    8. Removed unused permissions from the PrintSpooler's manifest.

Change-Id: Iba2dd14b487f56e137b90d1da17c3033422ab5e6
parent 55b409a9
Loading
Loading
Loading
Loading
+2 −3
Original line number Original line Diff line number Diff line
@@ -18641,7 +18641,7 @@ package android.print {
  public final class PrinterId implements android.os.Parcelable {
  public final class PrinterId implements android.os.Parcelable {
    method public int describeContents();
    method public int describeContents();
    method public java.lang.String getLocalId();
    method public java.lang.String getPrinterName();
    method public void writeToParcel(android.os.Parcel, int);
    method public void writeToParcel(android.os.Parcel, int);
    field public static final android.os.Parcelable.Creator CREATOR;
    field public static final android.os.Parcelable.Creator CREATOR;
  }
  }
@@ -18654,7 +18654,6 @@ package android.print {
    method public int getFittingModes();
    method public int getFittingModes();
    method public android.print.PrinterId getId();
    method public android.print.PrinterId getId();
    method public java.util.List<android.print.PrintAttributes.Tray> getInputTrays();
    method public java.util.List<android.print.PrintAttributes.Tray> getInputTrays();
    method public java.lang.CharSequence getLabel();
    method public java.util.List<android.print.PrintAttributes.MediaSize> getMediaSizes();
    method public java.util.List<android.print.PrintAttributes.MediaSize> getMediaSizes();
    method public android.print.PrintAttributes.Margins getMinMargins();
    method public android.print.PrintAttributes.Margins getMinMargins();
    method public int getOrientations();
    method public int getOrientations();
@@ -18668,7 +18667,7 @@ package android.print {
  }
  }
  public static final class PrinterInfo.Builder {
  public static final class PrinterInfo.Builder {
    ctor public PrinterInfo.Builder(android.print.PrinterId, java.lang.CharSequence);
    ctor public PrinterInfo.Builder(android.print.PrinterId);
    method public android.print.PrinterInfo.Builder addInputTray(android.print.PrintAttributes.Tray, boolean);
    method public android.print.PrinterInfo.Builder addInputTray(android.print.PrintAttributes.Tray, boolean);
    method public android.print.PrinterInfo.Builder addMediaSize(android.print.PrintAttributes.MediaSize, boolean);
    method public android.print.PrinterInfo.Builder addMediaSize(android.print.PrintAttributes.MediaSize, boolean);
    method public android.print.PrinterInfo.Builder addOutputTray(android.print.PrintAttributes.Tray, boolean);
    method public android.print.PrinterInfo.Builder addOutputTray(android.print.PrintAttributes.Tray, boolean);
+1 −0
Original line number Original line Diff line number Diff line
@@ -33,4 +33,5 @@ interface IPrintManager {
            in IPrintDocumentAdapter printAdapter, in PrintAttributes attributes,
            in IPrintDocumentAdapter printAdapter, in PrintAttributes attributes,
            int appId, int userId);
            int appId, int userId);
    void cancelPrintJob(int printJobId, int appId, int userId);
    void cancelPrintJob(int printJobId, int appId, int userId);
    void restartPrintJob(int printJobId, int appId, int userId);
}
}
+2 −4
Original line number Original line Diff line number Diff line
@@ -40,10 +40,8 @@ oneway interface IPrintSpooler {
    void createPrintJob(String printJobName, in IPrintClient client,
    void createPrintJob(String printJobName, in IPrintClient client,
            in IPrintDocumentAdapter printAdapter, in PrintAttributes attributes,
            in IPrintDocumentAdapter printAdapter, in PrintAttributes attributes,
            IPrintSpoolerCallbacks callback, int appId, int sequence);
            IPrintSpoolerCallbacks callback, int appId, int sequence);
    void cancelPrintJob(int printJobId, IPrintSpoolerCallbacks callback,
    void setPrintJobState(int printJobId, int status, CharSequence error,
            int appId, int sequence);
            IPrintSpoolerCallbacks callback, int sequence);
    void setPrintJobState(int printJobId, int status, IPrintSpoolerCallbacks callback,
            int sequence);
    void setPrintJobTag(int printJobId, String tag, IPrintSpoolerCallbacks callback,
    void setPrintJobTag(int printJobId, String tag, IPrintSpoolerCallbacks callback,
            int sequence);
            int sequence);
    void writePrintJobData(in ParcelFileDescriptor fd, int printJobId);
    void writePrintJobData(in ParcelFileDescriptor fd, int printJobId);
+35 −0
Original line number Original line Diff line number Diff line
@@ -124,6 +124,9 @@ public final class PrintJobInfo implements Parcelable {
    /** How many copies to print. */
    /** How many copies to print. */
    private int mCopies;
    private int mCopies;


    /** Failure reason if this job failed. */
    private CharSequence mFailureReason;

    /** The pages to print */
    /** The pages to print */
    private PageRange[] mPageRanges;
    private PageRange[] mPageRanges;


@@ -148,6 +151,7 @@ public final class PrintJobInfo implements Parcelable {
        mUserId = other.mUserId;
        mUserId = other.mUserId;
        mTag = other.mTag;
        mTag = other.mTag;
        mCopies = other.mCopies;
        mCopies = other.mCopies;
        mFailureReason = other.mFailureReason;
        mPageRanges = other.mPageRanges;
        mPageRanges = other.mPageRanges;
        mAttributes = other.mAttributes;
        mAttributes = other.mAttributes;
        mDocumentInfo = other.mDocumentInfo;
        mDocumentInfo = other.mDocumentInfo;
@@ -162,6 +166,9 @@ public final class PrintJobInfo implements Parcelable {
        mUserId = parcel.readInt();
        mUserId = parcel.readInt();
        mTag = parcel.readString();
        mTag = parcel.readString();
        mCopies = parcel.readInt();
        mCopies = parcel.readInt();
        if (parcel.readInt() == 1) {
            mFailureReason = parcel.readCharSequence();
        }
        if (parcel.readInt() == 1) {
        if (parcel.readInt() == 1) {
            Parcelable[] parcelables = parcel.readParcelableArray(null);
            Parcelable[] parcelables = parcel.readParcelableArray(null);
            mPageRanges = new PageRange[parcelables.length];
            mPageRanges = new PageRange[parcelables.length];
@@ -344,6 +351,28 @@ public final class PrintJobInfo implements Parcelable {
        mCopies = copyCount;
        mCopies = copyCount;
    }
    }


    /**
     * The failure reason if this print job failed.
     *
     * @return The failure reason.
     *
     * @hide
     */
    public CharSequence getFailureReason() {
        return mFailureReason;
    }

    /**
     * The failure reason if this print job failed.
     *
     * @param failureReason The failure reason.
     *
     * @hide
     */
    public void setFailureReason(CharSequence failureReason) {
        mFailureReason = failureReason;
    }

    /**
    /**
     * Gets the included pages.
     * Gets the included pages.
     *
     *
@@ -421,6 +450,12 @@ public final class PrintJobInfo implements Parcelable {
        parcel.writeInt(mUserId);
        parcel.writeInt(mUserId);
        parcel.writeString(mTag);
        parcel.writeString(mTag);
        parcel.writeInt(mCopies);
        parcel.writeInt(mCopies);
        if (mFailureReason != null) {
            parcel.writeInt(1);
            parcel.writeCharSequence(mFailureReason);
        } else {
            parcel.writeInt(0);
        }
        if (mPageRanges != null) {
        if (mPageRanges != null) {
            parcel.writeInt(1);
            parcel.writeInt(1);
            parcel.writeParcelableArray(mPageRanges, flags);
            parcel.writeParcelableArray(mPageRanges, flags);
+26 −26
Original line number Original line Diff line number Diff line
@@ -26,26 +26,26 @@ import android.text.TextUtils;
 */
 */
public final class PrinterId implements Parcelable {
public final class PrinterId implements Parcelable {


    private final ComponentName mServiceComponentName;
    private final ComponentName mServiceName;


    private final String mLocalId;
    private final String mPrinterName;


    /**
    /**
     * Creates a new instance.
     * Creates a new instance.
     *
     *
     * @param serviceComponentName The managing print service.
     * @param serviceName The managing print service.
     * @param localId The unique id within the managing service.
     * @param printerName The unique name within the managing service.
     *
     *
     * @hide
     * @hide
     */
     */
    public PrinterId(ComponentName serviceComponentName, String localId) {
    public PrinterId(ComponentName serviceName, String printerName) {
        mServiceComponentName = serviceComponentName;
        mServiceName = serviceName;
        mLocalId = localId;
        mPrinterName = printerName;
    }
    }


    private PrinterId(Parcel parcel) {
    private PrinterId(Parcel parcel) {
        mServiceComponentName = parcel.readParcelable(null);
        mServiceName = parcel.readParcelable(null);
        mLocalId = parcel.readString();
        mPrinterName = parcel.readString();
    }
    }


    /**
    /**
@@ -55,18 +55,18 @@ public final class PrinterId implements Parcelable {
     *
     *
     * @hide
     * @hide
     */
     */
    public ComponentName getService() {
    public ComponentName getServiceName() {
        return mServiceComponentName;
        return mServiceName;
    }
    }


    /**
    /**
     * Gets the local id of this printer in the context
     * Gets the name of this printer which is unique in the context
     * of the print service that manages it.
     * of the print service that manages it.
     *
     *
     * @return The local id.
     * @return The printer name.
     */
     */
    public String getLocalId() {
    public String getPrinterName() {
        return mLocalId;
        return mPrinterName;
    }
    }


    @Override
    @Override
@@ -76,8 +76,8 @@ public final class PrinterId implements Parcelable {


    @Override
    @Override
    public void writeToParcel(Parcel parcel, int flags) {
    public void writeToParcel(Parcel parcel, int flags) {
        parcel.writeParcelable(mServiceComponentName, flags);
        parcel.writeParcelable(mServiceName, flags);
        parcel.writeString(mLocalId);
        parcel.writeString(mPrinterName);
    }
    }


    @Override
    @Override
@@ -92,14 +92,14 @@ public final class PrinterId implements Parcelable {
            return false;
            return false;
        }
        }
        PrinterId other = (PrinterId) object;
        PrinterId other = (PrinterId) object;
        if (mServiceComponentName == null) {
        if (mServiceName == null) {
            if (other.mServiceComponentName != null) {
            if (other.mServiceName != null) {
                return false;
                return false;
            }
            }
        } else if (!mServiceComponentName.equals(other.mServiceComponentName)) {
        } else if (!mServiceName.equals(other.mServiceName)) {
            return false;
            return false;
        }
        }
        if (!TextUtils.equals(mLocalId, other.mLocalId)) {
        if (!TextUtils.equals(mPrinterName, other.mPrinterName)) {
            return false;
            return false;
        }
        }
        return true;
        return true;
@@ -109,9 +109,9 @@ public final class PrinterId implements Parcelable {
    public int hashCode() {
    public int hashCode() {
        final int prime = 31;
        final int prime = 31;
        int hashCode = 1;
        int hashCode = 1;
        hashCode = prime * hashCode + ((mServiceComponentName != null)
        hashCode = prime * hashCode + ((mServiceName != null)
                ? mServiceComponentName.hashCode() : 1);
                ? mServiceName.hashCode() : 1);
        hashCode = prime * hashCode + mLocalId.hashCode();
        hashCode = prime * hashCode + mPrinterName.hashCode();
        return hashCode;
        return hashCode;
    }
    }


@@ -119,9 +119,9 @@ public final class PrinterId implements Parcelable {
    public String toString() {
    public String toString() {
        StringBuilder builder = new StringBuilder();
        StringBuilder builder = new StringBuilder();
        builder.append("PrinterId{");
        builder.append("PrinterId{");
        builder.append(mServiceComponentName.flattenToString());
        builder.append(mServiceName.flattenToString());
        builder.append(":");
        builder.append(":");
        builder.append(mLocalId);
        builder.append(mPrinterName);
        builder.append('}');
        builder.append('}');
        return builder.toString();
        return builder.toString();
    }
    }
Loading