Home | History | Annotate | Download | only in mopria
      1 /*
      2  * (c) Copyright 2016 Mopria Alliance, Inc.
      3  * Copyright (C) 2016 The Android Open Source Project
      4  *
      5  * Licensed under the Apache License, Version 2.0 (the "License");
      6  * you may not use this file except in compliance with the License.
      7  * You may obtain a copy of the License at
      8  *
      9  * http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  * Unless required by applicable law or agreed to in writing, software
     12  * distributed under the License is distributed on an "AS IS" BASIS,
     13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  * See the License for the specific language governing permissions and
     15  * limitations under the License.
     16  */
     17 
     18 package com.android.printservice.recommendation.plugin.mopria;
     19 
     20 import android.content.Context;
     21 import android.net.nsd.NsdServiceInfo;
     22 import android.text.TextUtils;
     23 import android.util.Pair;
     24 
     25 import com.android.printservice.recommendation.plugin.hp.MDnsUtils;
     26 import com.android.printservice.recommendation.plugin.hp.ServiceRecommendationPlugin;
     27 import com.android.printservice.recommendation.plugin.hp.VendorInfo;
     28 import com.android.printservice.recommendation.R;
     29 
     30 public class MopriaRecommendationPlugin extends ServiceRecommendationPlugin {
     31 
     32     private static final String PDL__PDF = "application/pdf";
     33     private static final String PDL__PCLM = "application/PCLm";
     34     private static final String PDL__PWG_RASTER = "image/pwg-raster";
     35 
     36     public MopriaRecommendationPlugin(Context context) {
     37         super(context, R.string.plugin_vendor_morpia, new VendorInfo(context.getResources(), R.array.known_print_vendor_info_for_mopria), new String[]{"_ipp._tcp", "_ipps._tcp"});
     38     }
     39 
     40     @Override
     41     public boolean matchesCriteria(String vendor, NsdServiceInfo nsdServiceInfo) {
     42         String pdls = MDnsUtils.getString(nsdServiceInfo.getAttributes().get(PDL_ATTRIBUTE));
     43         return (!TextUtils.isEmpty(pdls)
     44                 && (pdls.contains(PDL__PDF)
     45                 || pdls.contains(PDL__PCLM)
     46                 || pdls.contains(PDL__PWG_RASTER)));
     47     }
     48 
     49     @Override
     50     public int getCount() {
     51         Pair<Integer, Integer> count = mListener.getCount();
     52         return ((count.first > 1) ? count.second : 0);
     53     }
     54 }
     55