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

Commit 7e01895e authored by Philip P. Moltmann's avatar Philip P. Moltmann
Browse files

Return inet addr for discoverable printers

... by extending the RecommendationInfo to store the inet addresses not
just the count. Thankfully the recommendation plugins already contained
all the printers, not only the count.

Also expose the print service state as system APIs as they will be used
by the default print service.

Bug: 35765644
Test: Ran AddPrinterActivity on network that had printers to discover
Change-Id: I929a177adb75f6848848ba30a472cf0343d2e67e
parent 0ff1b458
Loading
Loading
Loading
Loading
+25 −1
Original line number Diff line number Diff line
@@ -35598,8 +35598,23 @@ package android.print {
  }
  public final class PrintManager {
    method public void addPrintServiceRecommendationsChangeListener(android.print.PrintManager.PrintServiceRecommendationsChangeListener, android.os.Handler);
    method public void addPrintServicesChangeListener(android.print.PrintManager.PrintServicesChangeListener, android.os.Handler);
    method public java.util.List<android.print.PrintJob> getPrintJobs();
    method public java.util.List<android.printservice.recommendation.RecommendationInfo> getPrintServiceRecommendations();
    method public java.util.List<android.printservice.PrintServiceInfo> getPrintServices(int);
    method public android.print.PrintJob print(java.lang.String, android.print.PrintDocumentAdapter, android.print.PrintAttributes);
    method public void removePrintServiceRecommendationsChangeListener(android.print.PrintManager.PrintServiceRecommendationsChangeListener);
    method public void removePrintServicesChangeListener(android.print.PrintManager.PrintServicesChangeListener);
    field public static final int ENABLED_SERVICES = 1; // 0x1
  }
  public static abstract interface PrintManager.PrintServiceRecommendationsChangeListener {
    method public abstract void onPrintServiceRecommendationsChanged();
  }
  public static abstract interface PrintManager.PrintServicesChangeListener {
    method public abstract void onPrintServicesChanged();
  }
  public final class PrinterCapabilitiesInfo implements android.os.Parcelable {
@@ -35728,6 +35743,13 @@ package android.printservice {
    field public static final java.lang.String SERVICE_META_DATA = "android.printservice";
  }
  public final class PrintServiceInfo implements android.os.Parcelable {
    method public int describeContents();
    method public android.content.ComponentName getComponentName();
    method public void writeToParcel(android.os.Parcel, int);
    field public static final android.os.Parcelable.Creator<android.printservice.PrintServiceInfo> CREATOR;
  }
  public abstract class PrinterDiscoverySession {
    ctor public PrinterDiscoverySession();
    method public final void addPrinters(java.util.List<android.print.PrinterInfo>);
@@ -35750,8 +35772,10 @@ package android.printservice {
package android.printservice.recommendation {
  public final class RecommendationInfo implements android.os.Parcelable {
    ctor public RecommendationInfo(java.lang.CharSequence, java.lang.CharSequence, int, boolean);
    ctor public RecommendationInfo(java.lang.CharSequence, java.lang.CharSequence, java.util.List<java.net.InetAddress>, boolean);
    ctor public deprecated RecommendationInfo(java.lang.CharSequence, java.lang.CharSequence, int, boolean);
    method public int describeContents();
    method public java.util.List<java.net.InetAddress> getDiscoveredPrinters();
    method public java.lang.CharSequence getName();
    method public int getNumDiscoveredPrinters();
    method public java.lang.CharSequence getPackageName();
+54 −44
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package android.print;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.app.Activity;
import android.app.Application.ActivityLifecycleCallbacks;
import android.content.ComponentName;
@@ -43,8 +44,8 @@ import android.util.ArrayMap;
import android.util.Log;

import com.android.internal.os.SomeArgs;

import com.android.internal.util.Preconditions;

import libcore.io.IoUtils;

import java.lang.ref.WeakReference;
@@ -115,8 +116,6 @@ public final class PrintManager {
    private static final boolean DEBUG = false;

    private static final int MSG_NOTIFY_PRINT_JOB_STATE_CHANGED = 1;
    private static final int MSG_NOTIFY_PRINT_SERVICES_CHANGED = 2;
    private static final int MSG_NOTIFY_PRINT_SERVICE_RECOMMENDATIONS_CHANGED = 3;

    /**
     * Package name of print spooler.
@@ -131,6 +130,7 @@ public final class PrintManager {
     * @see #getPrintServices
     * @hide
     */
    @SystemApi
    public static final int ENABLED_SERVICES = 1 << 0;

    /**
@@ -221,16 +221,26 @@ public final class PrintManager {
        public void onPrintJobStateChanged(PrintJobId printJobId);
    }

    /** @hide */
    /**
     * Listen for changes to {@link #getPrintServices(int)}.
     *
     * @hide
     */
    @SystemApi
    public interface PrintServicesChangeListener {

        /**
         * Callback notifying that the print services changed.
         */
        public void onPrintServicesChanged();
        void onPrintServicesChanged();
    }

    /** @hide */
    /**
     * Listen for changes to {@link #getPrintServiceRecommendations()}.
     *
     * @hide
     */
    @SystemApi
    public interface PrintServiceRecommendationsChangeListener {

        /**
@@ -268,22 +278,6 @@ public final class PrintManager {
                        }
                        args.recycle();
                    } break;
                    case MSG_NOTIFY_PRINT_SERVICES_CHANGED: {
                        PrintServicesChangeListenerWrapper wrapper =
                                (PrintServicesChangeListenerWrapper) message.obj;
                        PrintServicesChangeListener listener = wrapper.getListener();
                        if (listener != null) {
                            listener.onPrintServicesChanged();
                        }
                    } break;
                    case MSG_NOTIFY_PRINT_SERVICE_RECOMMENDATIONS_CHANGED: {
                        PrintServiceRecommendationsChangeListenerWrapper wrapper =
                                (PrintServiceRecommendationsChangeListenerWrapper) message.obj;
                        PrintServiceRecommendationsChangeListener listener = wrapper.getListener();
                        if (listener != null) {
                            listener.onPrintServiceRecommendationsChanged();
                        }
                    } break;
                }
            }
        };
@@ -325,8 +319,7 @@ public final class PrintManager {
            return;
        }
        if (mPrintJobStateChangeListeners == null) {
            mPrintJobStateChangeListeners = new ArrayMap<PrintJobStateChangeListener,
                    PrintJobStateChangeListenerWrapper>();
            mPrintJobStateChangeListeners = new ArrayMap<>();
        }
        PrintJobStateChangeListenerWrapper wrappedListener =
                new PrintJobStateChangeListenerWrapper(listener, mHandler);
@@ -399,7 +392,7 @@ public final class PrintManager {
     * @param printerId the id of the printer the icon should be loaded for
     * @return the custom icon to be used for the printer or null if the icon is
     *         not yet available
     * @see android.print.PrinterInfo.Builder#setHasCustomPrinterIcon()
     * @see android.print.PrinterInfo.Builder#setHasCustomPrinterIcon(boolean)
     * @hide
     */
    public Icon getCustomPrinterIcon(PrinterId printerId) {
@@ -558,12 +551,21 @@ public final class PrintManager {
     * Listen for changes to the installed and enabled print services.
     *
     * @param listener the listener to add
     * @param handler the handler the listener is called back on
     *
     * @see android.print.PrintManager#getPrintServices
     *
     * @hide
     */
    void addPrintServicesChangeListener(@NonNull PrintServicesChangeListener listener) {
    @SystemApi
    public void addPrintServicesChangeListener(@NonNull PrintServicesChangeListener listener,
            @Nullable Handler handler) {
        Preconditions.checkNotNull(listener);

        if (handler == null) {
            handler = mHandler;
        }

        if (mService == null) {
            Log.w(LOG_TAG, "Feature android.software.print not available");
            return;
@@ -572,7 +574,7 @@ public final class PrintManager {
            mPrintServicesChangeListeners = new ArrayMap<>();
        }
        PrintServicesChangeListenerWrapper wrappedListener =
                new PrintServicesChangeListenerWrapper(listener, mHandler);
                new PrintServicesChangeListenerWrapper(listener, handler);
        try {
            mService.addPrintServicesChangeListener(wrappedListener, mUserId);
            mPrintServicesChangeListeners.put(listener, wrappedListener);
@@ -587,8 +589,11 @@ public final class PrintManager {
     * @param listener the listener to remove
     *
     * @see android.print.PrintManager#getPrintServices
     *
     * @hide
     */
    void removePrintServicesChangeListener(@NonNull PrintServicesChangeListener listener) {
    @SystemApi
    public void removePrintServicesChangeListener(@NonNull PrintServicesChangeListener listener) {
        Preconditions.checkNotNull(listener);

        if (mService == null) {
@@ -623,11 +628,12 @@ public final class PrintManager {
     *
     * @return The print service list or an empty list.
     *
     * @see #addPrintServicesChangeListener(PrintServicesChangeListener)
     * @see #addPrintServicesChangeListener(PrintServicesChangeListener, Handler)
     * @see #removePrintServicesChangeListener(PrintServicesChangeListener)
     *
     * @hide
     */
    @SystemApi
    public @NonNull List<PrintServiceInfo> getPrintServices(int selectionFlags) {
        Preconditions.checkFlagsArgument(selectionFlags, ALL_SERVICES);

@@ -646,13 +652,22 @@ public final class PrintManager {
     * Listen for changes to the print service recommendations.
     *
     * @param listener the listener to add
     * @param handler the handler the listener is called back on
     *
     * @see android.print.PrintManager#getPrintServiceRecommendations
     *
     * @hide
     */
    void addPrintServiceRecommendationsChangeListener(
            @NonNull PrintServiceRecommendationsChangeListener listener) {
    @SystemApi
    public void addPrintServiceRecommendationsChangeListener(
            @NonNull PrintServiceRecommendationsChangeListener listener,
            @Nullable Handler handler) {
        Preconditions.checkNotNull(listener);

        if (handler == null) {
            handler = mHandler;
        }

        if (mService == null) {
            Log.w(LOG_TAG, "Feature android.software.print not available");
            return;
@@ -661,7 +676,7 @@ public final class PrintManager {
            mPrintServiceRecommendationsChangeListeners = new ArrayMap<>();
        }
        PrintServiceRecommendationsChangeListenerWrapper wrappedListener =
                new PrintServiceRecommendationsChangeListenerWrapper(listener, mHandler);
                new PrintServiceRecommendationsChangeListenerWrapper(listener, handler);
        try {
            mService.addPrintServiceRecommendationsChangeListener(wrappedListener, mUserId);
            mPrintServiceRecommendationsChangeListeners.put(listener, wrappedListener);
@@ -676,8 +691,11 @@ public final class PrintManager {
     * @param listener the listener to remove
     *
     * @see android.print.PrintManager#getPrintServiceRecommendations
     *
     * @hide
     */
    void removePrintServiceRecommendationsChangeListener(
    @SystemApi
    public void removePrintServiceRecommendationsChangeListener(
            @NonNull PrintServiceRecommendationsChangeListener listener) {
        Preconditions.checkNotNull(listener);

@@ -715,6 +733,7 @@ public final class PrintManager {
     *
     * @hide
     */
    @SystemApi
    public @NonNull List<RecommendationInfo> getPrintServiceRecommendations() {
        try {
            List<RecommendationInfo> recommendations =
@@ -1349,17 +1368,13 @@ public final class PrintManager {
            Handler handler = mWeakHandler.get();
            PrintServicesChangeListener listener = mWeakListener.get();
            if (handler != null && listener != null) {
                handler.obtainMessage(MSG_NOTIFY_PRINT_SERVICES_CHANGED, this).sendToTarget();
                handler.post(listener::onPrintServicesChanged);
            }
        }

        public void destroy() {
            mWeakListener.clear();
        }

        public PrintServicesChangeListener getListener() {
            return mWeakListener.get();
        }
    }

    /**
@@ -1381,17 +1396,12 @@ public final class PrintManager {
            Handler handler = mWeakHandler.get();
            PrintServiceRecommendationsChangeListener listener = mWeakListener.get();
            if (handler != null && listener != null) {
                handler.obtainMessage(MSG_NOTIFY_PRINT_SERVICE_RECOMMENDATIONS_CHANGED,
                        this).sendToTarget();
                handler.post(listener::onPrintServiceRecommendationsChanged);
            }
        }

        public void destroy() {
            mWeakListener.clear();
        }

        public PrintServiceRecommendationsChangeListener getListener() {
            return mWeakListener.get();
        }
    }
}
+2 −1
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.content.Loader;
import android.os.Handler;
import android.os.Message;
import android.printservice.recommendation.RecommendationInfo;

import com.android.internal.util.Preconditions;

import java.util.List;
@@ -77,7 +78,7 @@ public class PrintServiceRecommendationsLoader extends Loader<List<Recommendatio
            }
        };

        mPrintManager.addPrintServiceRecommendationsChangeListener(mListener);
        mPrintManager.addPrintServiceRecommendationsChangeListener(mListener, null);

        // Immediately deliver a result
        deliverResult(mPrintManager.getPrintServiceRecommendations());
+2 −1
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.content.Loader;
import android.os.Handler;
import android.os.Message;
import android.printservice.PrintServiceInfo;

import com.android.internal.util.Preconditions;

import java.util.List;
@@ -82,7 +83,7 @@ public class PrintServicesLoader extends Loader<List<PrintServiceInfo>> {
            }
        };

        mPrintManager.addPrintServicesChangeListener(mListener);
        mPrintManager.addPrintServicesChangeListener(mListener, null);

        // Immediately deliver a result
        deliverResult(mPrintManager.getPrintServices(mSelectionFlags));
+22 −2
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package android.printservice;

import android.annotation.NonNull;
import android.annotation.SystemApi;
import android.content.ComponentName;
import android.content.Context;
import android.content.pm.PackageManager;
@@ -47,6 +48,7 @@ import java.io.IOException;
 *
 * @hide
 */
@SystemApi
public final class PrintServiceInfo implements Parcelable {

    private static final String LOG_TAG = PrintServiceInfo.class.getSimpleName();
@@ -86,6 +88,8 @@ public final class PrintServiceInfo implements Parcelable {
     * @param settingsActivityName Optional settings activity name.
     * @param addPrintersActivityName Optional add printers activity name.
     * @param advancedPrintOptionsActivityName Optional advanced print options activity.
     *
     * @hide
     */
    public PrintServiceInfo(ResolveInfo resolveInfo, String settingsActivityName,
            String addPrintersActivityName, String advancedPrintOptionsActivityName) {
@@ -110,11 +114,13 @@ public final class PrintServiceInfo implements Parcelable {
    /**
     * Creates a new instance.
     *
     * @param resolveInfo The service resolve info.
     * @param context Context for accessing resources.
     * @param resolveInfo The service resolve info.
     * @return The created instance.
     *
     * @hide
     */
    public static PrintServiceInfo create(ResolveInfo resolveInfo, Context context) {
    public static PrintServiceInfo create(Context context, ResolveInfo resolveInfo) {
        String settingsActivityName = null;
        String addPrintersActivityName = null;
        String advancedPrintOptionsActivityName = null;
@@ -177,6 +183,8 @@ public final class PrintServiceInfo implements Parcelable {
     * </p>
     *
     * @return The id.
     *
     * @hide
     */
    public String getId() {
        return mId;
@@ -186,6 +194,8 @@ public final class PrintServiceInfo implements Parcelable {
     * If the service was enabled when it was read from the system.
     *
     * @return The id.
     *
     * @hide
     */
    public boolean isEnabled() {
        return mIsEnabled;
@@ -195,6 +205,8 @@ public final class PrintServiceInfo implements Parcelable {
     * Mark a service as enabled or not
     *
     * @param isEnabled If the service should be marked as enabled.
     *
     * @hide
     */
    public void setIsEnabled(boolean isEnabled) {
        mIsEnabled = isEnabled;
@@ -204,6 +216,8 @@ public final class PrintServiceInfo implements Parcelable {
     * The service {@link ResolveInfo}.
     *
     * @return The info.
     *
     * @hide
     */
    public ResolveInfo getResolveInfo() {
        return mResolveInfo;
@@ -217,6 +231,8 @@ public final class PrintServiceInfo implements Parcelable {
     * </p>
     *
     * @return The settings activity name.
     *
     * @hide
     */
    public String getSettingsActivityName() {
        return mSettingsActivityName;
@@ -230,6 +246,8 @@ public final class PrintServiceInfo implements Parcelable {
     * </p>
     *
     * @return The add printers activity name.
     *
     * @hide
     */
    public String getAddPrintersActivityName() {
        return mAddPrintersActivityName;
@@ -243,6 +261,8 @@ public final class PrintServiceInfo implements Parcelable {
     * </p>
     *
     * @return The advanced print options activity name.
     *
     * @hide
     */
    public String getAdvancedOptionsActivityName() {
        return mAdvancedPrintOptionsActivityName;
Loading