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

Commit 76d7e3ee authored by Philip P. Moltmann's avatar Philip P. Moltmann
Browse files

Check parameters for callers of IPrintManager

- Propagate nullness and non-null-ness up and down from the interfaces.
- Add non-CTS print tests for IPrintManager binder.

Change-Id: I0c310d9cea8aefba5ce386931521ffaf19712bbb
parent 4b461bab
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -535,7 +535,10 @@ public final class PrintManager {
        return new PrinterDiscoverySession(mService, mContext, mUserId);
    }

    private static final class PrintDocumentAdapterDelegate extends IPrintDocumentAdapter.Stub
    /**
     * @hide
     */
    public static final class PrintDocumentAdapterDelegate extends IPrintDocumentAdapter.Stub
            implements ActivityLifecycleCallbacks {
        private final Object mLock = new Object();

@@ -1061,7 +1064,10 @@ public final class PrintManager {
        }
    }

    private static final class PrintJobStateChangeListenerWrapper extends
    /**
     * @hide
     */
    public static final class PrintJobStateChangeListenerWrapper extends
            IPrintJobStateChangeListener.Stub {
        private final WeakReference<PrintJobStateChangeListener> mWeakListener;
        private final WeakReference<Handler> mWeakHandler;
+6 −4
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package android.print;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.Context;
import android.content.pm.ParceledListSlice;
import android.os.Handler;
@@ -72,7 +74,7 @@ public final class PrinterDiscoverySession {
        }
    }

    public final void startPrinterDiscovery(List<PrinterId> priorityList) {
    public final void startPrinterDiscovery(@Nullable List<PrinterId> priorityList) {
        if (isDestroyed()) {
            Log.w(LOG_TAG, "Ignoring start printers discovery - session destroyed");
            return;
@@ -102,7 +104,7 @@ public final class PrinterDiscoverySession {
        }
    }

    public final void startPrinterStateTracking(PrinterId printerId) {
    public final void startPrinterStateTracking(@NonNull PrinterId printerId) {
        if (isDestroyed()) {
            Log.w(LOG_TAG, "Ignoring start printer state tracking - session destroyed");
            return;
@@ -114,7 +116,7 @@ public final class PrinterDiscoverySession {
        }
    }

    public final void stopPrinterStateTracking(PrinterId printerId) {
    public final void stopPrinterStateTracking(@NonNull PrinterId printerId) {
        if (isDestroyed()) {
            Log.w(LOG_TAG, "Ignoring stop printer state tracking - session destroyed");
            return;
@@ -285,7 +287,7 @@ public final class PrinterDiscoverySession {
        }
    }

    private static final class PrinterDiscoveryObserver extends IPrinterDiscoveryObserver.Stub {
    public static final class PrinterDiscoveryObserver extends IPrinterDiscoveryObserver.Stub {

        private final WeakReference<PrinterDiscoverySession> mWeakSession;

+2 −1
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.printservice;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.Service;
import android.content.ComponentName;
@@ -346,7 +347,7 @@ public abstract class PrintService extends Service {
     * @param localId A locally unique id in the context of your print service.
     * @return Global printer id.
     */
    public final PrinterId generatePrinterId(String localId) {
    public @NonNull final PrinterId generatePrinterId(String localId) {
        throwIfNotCalledOnMainThread();
        localId = Preconditions.checkNotNull(localId, "localId cannot be null");
        return new PrinterId(new ComponentName(getPackageName(),
+19 −2
Original line number Diff line number Diff line
@@ -42,6 +42,23 @@ public class Preconditions {
     * @return the string reference that was validated
     * @throws IllegalArgumentException if {@code string} is empty
     */
    public static @NonNull String checkStringNotEmpty(final String string) {
        if (TextUtils.isEmpty(string)) {
            throw new IllegalArgumentException();
        }
        return string;
    }

    /**
     * Ensures that an string reference passed as a parameter to the calling
     * method is not empty.
     *
     * @param string an string reference
     * @param errorMessage the exception message to use if the check fails; will
     *     be converted to a string using {@link String#valueOf(Object)}
     * @return the string reference that was validated
     * @throws IllegalArgumentException if {@code string} is empty
     */
    public static @NonNull String checkStringNotEmpty(final String string,
            final Object errorMessage) {
        if (TextUtils.isEmpty(string)) {
@@ -301,8 +318,8 @@ public class Preconditions {
     *
     * @throws NullPointerException if the {@code value} or any of its elements were {@code null}
     */
    public static <T> Collection<T> checkCollectionElementsNotNull(final Collection<T> value,
            final String valueName) {
    public static @NonNull <C extends Collection<T>, T> C checkCollectionElementsNotNull(
            final C value, final String valueName) {
        if (value == null) {
            throw new NullPointerException(valueName + " must not be null");
        }
+2 −1
Original line number Diff line number Diff line
@@ -32,7 +32,8 @@ LOCAL_STATIC_JAVA_LIBRARIES := \
    littlemock \
    android-support-test \
    mockito-target \
    espresso-core
    espresso-core \
    ub-uiautomator
LOCAL_JAVA_LIBRARIES := android.test.runner conscrypt telephony-common org.apache.http.legacy
LOCAL_PACKAGE_NAME := FrameworksCoreTests

Loading