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

Commit a0027153 authored by Svetoslav Ganov's avatar Svetoslav Ganov
Browse files

Refactoring of the print sub-system and API clean up.

1. Now a user state has ins own spooler since the spooler app is
   running per user. The user state registers an observer for the state
   of the spooler to get information needed to orchestrate unbinding
   from print serivces that have no work and eventually unbinding from
   the spooler when all no service has any work.

2. Abstracted a remote print service from the perspective of the system
   in a class that is transparently managing binding and unbinding to
   the remote instance.

3. Abstracted the remote print spooler to transparently manage binding
   and unbinding to the remote instance when there is work and when
   there is no work, respectively.

4. Cleaned up the print document adapter (ex-PrintAdapter) APIs to
   enable implementing the all callbacks on a thread of choice. If
   the document is really small, using the main thread makes sense.

   Now if an app that does not need the UI state to layout the printed
   content, it can schedule all the work for allocating resources, laying
   out, writing, and releasing resources on a dedicated thread.

5. Added info class for the printed document that is now propagated
   the the print services. A print service gets an instance of a
   new document class that encapsulates the document info and a method
   to access the document's data.

6. Added APIs for describing the type of a document to the new document
   info class. This allows a print service to do smarts based on the
   doc type. For now we have only photo and document types.

7. Renamed the systemReady method for system services that implement
   it with different semantics to systemRunning. Such methods assume
   the the service can run third-party code which is not the same as
   systemReady.

8. Cleaned up the print job configuration activity.

9. Sigh... code clean up here and there. Factoring out classes to
   improve readability.

Change-Id: I637ba28412793166cbf519273fdf022241159a92
parent 15ecbdd2
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -159,13 +159,15 @@ LOCAL_SRC_FILES += \
	core/java/android/os/IUserManager.aidl \
	core/java/android/os/IVibratorService.aidl \
	core/java/android/service/notification/INotificationListener.aidl \
	core/java/android/print/ILayoutResultCallback.aidl \
	core/java/android/print/IPrintDocumentAdapter.aidl \
	core/java/android/print/IPrinterDiscoveryObserver.aidl \
	core/java/android/print/IPrintAdapter.aidl \
	core/java/android/print/IPrintClient.aidl \
	core/java/android/print/IPrintResultCallback.aidl \
	core/java/android/print/IPrintManager.aidl \
	core/java/android/print/IPrintSpoolerService.aidl \
	core/java/android/print/IPrintSpoolerServiceCallbacks.aidl \
	core/java/android/print/IPrintSpooler.aidl \
	core/java/android/print/IPrintSpoolerCallbacks.aidl \
	core/java/android/print/IPrintSpoolerClient.aidl \
	core/java/android/print/IWriteResultCallback.aidl \
	core/java/android/printservice/IPrintService.aidl \
	core/java/android/printservice/IPrintServiceClient.aidl \
	core/java/android/service/dreams/IDreamManager.aidl \
+44 −32
Original line number Diff line number Diff line
@@ -18448,36 +18448,6 @@ package android.print {
    field public static final android.os.Parcelable.Creator CREATOR;
  }
  public abstract class PrintAdapter {
    ctor public PrintAdapter();
    method public abstract android.print.PrintAdapterInfo getInfo();
    method public void onFinish();
    method public abstract void onPrint(java.util.List<android.print.PageRange>, java.io.FileDescriptor, android.os.CancellationSignal, android.print.PrintAdapter.PrintResultCallback);
    method public boolean onPrintAttributesChanged(android.print.PrintAttributes);
    method public void onStart();
  }
  public static abstract class PrintAdapter.PrintResultCallback {
    method public void onPrintFailed(java.lang.CharSequence);
    method public void onPrintFinished(java.util.List<android.print.PageRange>);
  }
  public final class PrintAdapterInfo implements android.os.Parcelable {
    method public int describeContents();
    method public int getFlags();
    method public int getPageCount();
    method public void writeToParcel(android.os.Parcel, int);
    field public static final android.os.Parcelable.Creator CREATOR;
    field public static final int PAGE_COUNT_UNKNOWN = -1; // 0xffffffff
  }
  public static final class PrintAdapterInfo.Builder {
    ctor public PrintAdapterInfo.Builder();
    method public android.print.PrintAdapterInfo create();
    method public android.print.PrintAdapterInfo.Builder setFlags(int);
    method public android.print.PrintAdapterInfo.Builder setPageCount(int);
  }
  public final class PrintAttributes implements android.os.Parcelable {
    method public void clear();
    method public int describeContents();
@@ -18588,6 +18558,43 @@ package android.print {
    method public java.lang.CharSequence getLabel(android.content.pm.PackageManager);
  }
  public abstract class PrintDocumentAdapter {
    ctor public PrintDocumentAdapter();
    method public void onFinish();
    method public abstract void onLayout(android.print.PrintAttributes, android.print.PrintAttributes, android.os.CancellationSignal, android.print.PrintDocumentAdapter.LayoutResultCallback);
    method public void onStart();
    method public abstract void onWrite(java.util.List<android.print.PageRange>, java.io.FileDescriptor, android.os.CancellationSignal, android.print.PrintDocumentAdapter.WriteResultCallback);
  }
  public static abstract class PrintDocumentAdapter.LayoutResultCallback {
    method public void onLayoutFailed(java.lang.CharSequence);
    method public void onLayoutFinished(android.print.PrintDocumentInfo, boolean);
  }
  public static abstract class PrintDocumentAdapter.WriteResultCallback {
    method public void onWriteFailed(java.lang.CharSequence);
    method public void onWriteFinished(java.util.List<android.print.PageRange>);
  }
  public final class PrintDocumentInfo implements android.os.Parcelable {
    method public int describeContents();
    method public int getContentType();
    method public int getPageCount();
    method public void writeToParcel(android.os.Parcel, int);
    field public static final int CONTENT_TYPE_DOCUMENT = 0; // 0x0
    field public static final int CONTENT_TYPE_PHOTO = 1; // 0x1
    field public static final int CONTENT_TYPE_UNKNOWN = -1; // 0xffffffff
    field public static final android.os.Parcelable.Creator CREATOR;
    field public static final int PAGE_COUNT_UNKNOWN = -1; // 0xffffffff
  }
  public static final class PrintDocumentInfo.Builder {
    ctor public PrintDocumentInfo.Builder();
    method public android.print.PrintDocumentInfo create();
    method public android.print.PrintDocumentInfo.Builder setContentType(int);
    method public android.print.PrintDocumentInfo.Builder setPageCount(int);
  }
  public final class PrintJob {
    method public void cancel();
    method public int getId();
@@ -18617,7 +18624,7 @@ package android.print {
  public final class PrintManager {
    method public java.util.List<android.print.PrintJob> getPrintJobs();
    method public android.print.PrintJob print(java.lang.String, java.io.File, android.print.PrintAttributes);
    method public android.print.PrintJob print(java.lang.String, android.print.PrintAdapter, android.print.PrintAttributes);
    method public android.print.PrintJob print(java.lang.String, android.print.PrintDocumentAdapter, android.print.PrintAttributes);
  }
  public final class PrinterId implements android.os.Parcelable {
@@ -18699,11 +18706,16 @@ package android.print.pdf {
package android.printservice {
  public final class PrintDocument {
    method public java.io.FileDescriptor getData();
    method public android.print.PrintDocumentInfo getInfo();
  }
  public final class PrintJob {
    method public boolean cancel();
    method public boolean complete();
    method public boolean fail(java.lang.CharSequence);
    method public final java.io.FileDescriptor getData();
    method public android.printservice.PrintDocument getDocument();
    method public int getId();
    method public android.print.PrintJobInfo getInfo();
    method public boolean isQueued();
+18 −15
Original line number Diff line number Diff line
@@ -36,15 +36,15 @@ import java.util.List;
/**
 * Adapter for printing files.
 */
class PrintFileAdapter extends PrintAdapter {
final class FileDocumentAdapter extends PrintDocumentAdapter {

    private static final String LOG_TAG = "PrintFileAdapter";
    private static final String LOG_TAG = "FileDocumentAdapter";

    private final File mFile;

    private WriteFileAsyncTask mWriteFileAsyncTask;

    public PrintFileAdapter(File file) {
    public FileDocumentAdapter(File file) {
        if (file == null) {
            throw new IllegalArgumentException("File cannot be null!");
        }
@@ -52,8 +52,17 @@ class PrintFileAdapter extends PrintAdapter {
    }

    @Override
    public void onPrint(List<PageRange> pages, FileDescriptor destination,
            CancellationSignal cancellationSignal, PrintResultCallback callback) {
    public void onLayout(PrintAttributes oldAttributes, PrintAttributes newAttributes,
            CancellationSignal cancellationSignal, LayoutResultCallback callback) {
        // TODO: When we have a PDF rendering library we should query the page count.
        PrintDocumentInfo info =  new PrintDocumentInfo.Builder()
        .setPageCount(PrintDocumentInfo.PAGE_COUNT_UNKNOWN).create();
        callback.onLayoutFinished(info, false);
    }

    @Override
    public void onWrite(List<PageRange> pages, FileDescriptor destination,
            CancellationSignal cancellationSignal, WriteResultCallback callback) {
        mWriteFileAsyncTask = new WriteFileAsyncTask(mFile, destination, cancellationSignal,
                callback);
        mWriteFileAsyncTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR,
@@ -61,24 +70,18 @@ class PrintFileAdapter extends PrintAdapter {
        
    }

    @Override
    public PrintAdapterInfo getInfo() {
        // TODO: When we have PDF render library we should query the page count.
        return new PrintAdapterInfo.Builder().create();
    }

    private static final class WriteFileAsyncTask extends AsyncTask<Void, Void, Void> {

        private final File mSource;

        private final FileDescriptor mDestination;

        private final PrintResultCallback mResultCallback;
        private final WriteResultCallback mResultCallback;

        private final CancellationSignal mCancellationSignal;

        public WriteFileAsyncTask(File source, FileDescriptor destination,
                CancellationSignal cancellationSignal, PrintResultCallback callback) {
                CancellationSignal cancellationSignal, WriteResultCallback callback) {
            mSource = source;
            mDestination = destination;
            mResultCallback = callback;
@@ -113,9 +116,9 @@ class PrintFileAdapter extends PrintAdapter {
                if (!isCancelled()) {
                    List<PageRange> pages = new ArrayList<PageRange>();
                    pages.add(PageRange.ALL_PAGES);
                    mResultCallback.onPrintFinished(pages);
                    mResultCallback.onWriteFinished(pages);
                } else {
                    mResultCallback.onPrintFailed("Cancelled");
                    mResultCallback.onWriteFailed("Cancelled");
                }
            }
            return null;
+31 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2013 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.print;

import android.os.ICancellationSignal;
import android.print.PrintDocumentInfo;

/**
 * Callback for observing the result of android.print.PrintAdapter#onLayout.
 *
 * @hide
 */
oneway interface ILayoutResultCallback {
    void onLayoutStarted(ICancellationSignal cancellationSignal);
    void onLayoutFinished(in PrintDocumentInfo info, boolean changed);
    void onLayoutFailed(CharSequence error);
}
+7 −5
Original line number Diff line number Diff line
@@ -17,7 +17,8 @@
package android.print;

import android.os.ParcelFileDescriptor;
import android.print.IPrintResultCallback;
import android.print.ILayoutResultCallback;
import android.print.IWriteResultCallback;
import android.print.PageRange;
import android.print.PrintAttributes;

@@ -26,10 +27,11 @@ import android.print.PrintAttributes;
 *
 * @hide
 */
oneway interface IPrintAdapter {
oneway interface IPrintDocumentAdapter {
    void start();
    void printAttributesChanged(in PrintAttributes attributes);
    void print(in List<PageRange> pages, in ParcelFileDescriptor fd,
            IPrintResultCallback callback);
    void layout(in PrintAttributes oldAttributes, in PrintAttributes newAttributes,
            ILayoutResultCallback callback);
    void write(in List<PageRange> pages, in ParcelFileDescriptor fd,
            IWriteResultCallback callback);
    void finish();
}
Loading