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 
     24 import com.android.printservice.recommendation.R;
     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 
     29 import java.net.InetAddress;
     30 import java.util.ArrayList;
     31 
     32 public class MopriaRecommendationPlugin extends ServiceRecommendationPlugin {
     33 
     34     private static final String PDL__PDF = "application/pdf";
     35     private static final String PDL__PCLM = "application/PCLm";
     36     private static final String PDL__PWG_RASTER = "image/pwg-raster";
     37 
     38     public MopriaRecommendationPlugin(Context context) {
     39         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"});
     40     }
     41 
     42     @Override
     43     public boolean matchesCriteria(String vendor, NsdServiceInfo nsdServiceInfo) {
     44         String pdls = MDnsUtils.getString(nsdServiceInfo.getAttributes().get(PDL_ATTRIBUTE));
     45         return (!TextUtils.isEmpty(pdls)
     46                 && (pdls.contains(PDL__PDF)
     47                 || pdls.contains(PDL__PCLM)
     48                 || pdls.contains(PDL__PWG_RASTER)));
     49     }
     50 
     51     @Override
     52     public ArrayList<InetAddress> getPrinters() {
     53         return mListener.getPrinters();
     54     }
     55 }
     56