Home | History | Annotate | Download | only in recommendation
      1 /*
      2  * Copyright (C) 2016 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package android.printservice.recommendation;
     18 
     19 import android.annotation.IntRange;
     20 import android.annotation.NonNull;
     21 import android.annotation.SystemApi;
     22 import android.os.Parcel;
     23 import android.os.Parcelable;
     24 import android.printservice.PrintService;
     25 import com.android.internal.util.Preconditions;
     26 
     27 /**
     28  * A recommendation to install a {@link PrintService print service}.
     29  *
     30  * @hide
     31  */
     32 @SystemApi
     33 public final class RecommendationInfo implements Parcelable {
     34     /** Package name of the print service. */
     35     private @NonNull final CharSequence mPackageName;
     36 
     37     /** Display name of the print service. */
     38     private @NonNull final CharSequence mName;
     39 
     40     /** Number of printers the print service would discover if installed. */
     41     private @IntRange(from = 0) final int mNumDiscoveredPrinters;
     42 
     43     /** If the service detects printer from multiple vendors. */
     44     private final boolean mRecommendsMultiVendorService;
     45 
     46     /**
     47      * Create a new recommendation.
     48      *
     49      * @param packageName                  Package name of the print service
     50      * @param name                         Display name of the print service
     51      * @param numDiscoveredPrinters        Number of printers the print service would discover if
     52      *                                     installed
     53      * @param recommendsMultiVendorService If the service detects printer from multiple vendor
     54      */
     55     public RecommendationInfo(@NonNull CharSequence packageName, @NonNull CharSequence name,
     56             @IntRange(from = 0) int numDiscoveredPrinters, boolean recommendsMultiVendorService) {
     57         mPackageName = Preconditions.checkStringNotEmpty(packageName);
     58         mName = Preconditions.checkStringNotEmpty(name);
     59         mNumDiscoveredPrinters = Preconditions.checkArgumentNonnegative(numDiscoveredPrinters);
     60         mRecommendsMultiVendorService = recommendsMultiVendorService;
     61     }
     62 
     63     /**
     64      * Create a new recommendation from a parcel.
     65      *
     66      * @param parcel The parcel containing the data
     67      *
     68      * @see #CREATOR
     69      */
     70     private RecommendationInfo(@NonNull Parcel parcel) {
     71         this(parcel.readCharSequence(), parcel.readCharSequence(), parcel.readInt(),
     72                 parcel.readByte() != 0);
     73     }
     74 
     75     /**
     76      * @return The package name the recommendations recommends.
     77      */
     78     public CharSequence getPackageName() {
     79         return mPackageName;
     80     }
     81 
     82     /**
     83      * @return Whether the recommended print service detects printers of more than one vendor.
     84      */
     85     public boolean recommendsMultiVendorService() {
     86         return mRecommendsMultiVendorService;
     87     }
     88 
     89     /**
     90      * @return The number of printer the print service would detect.
     91      */
     92     public int getNumDiscoveredPrinters() {
     93         return mNumDiscoveredPrinters;
     94     }
     95 
     96     /**
     97      * @return The name of the recommended print service.
     98      */
     99     public CharSequence getName() {
    100         return mName;
    101     }
    102 
    103     @Override
    104     public int describeContents() {
    105         return 0;
    106     }
    107 
    108     @Override
    109     public void writeToParcel(Parcel dest, int flags) {
    110         dest.writeCharSequence(mPackageName);
    111         dest.writeCharSequence(mName);
    112         dest.writeInt(mNumDiscoveredPrinters);
    113         dest.writeByte((byte) (mRecommendsMultiVendorService ? 1 : 0));
    114     }
    115 
    116     /**
    117      * Utility class used to create new print service recommendation objects from parcels.
    118      *
    119      * @see #RecommendationInfo(Parcel)
    120      */
    121     public static final Creator<RecommendationInfo> CREATOR =
    122             new Creator<RecommendationInfo>() {
    123                 @Override
    124                 public RecommendationInfo createFromParcel(Parcel in) {
    125                     return new RecommendationInfo(in);
    126                 }
    127 
    128                 @Override
    129                 public RecommendationInfo[] newArray(int size) {
    130                     return new RecommendationInfo[size];
    131                 }
    132     };
    133 }
    134