1/* 2 * (c) Copyright 2016 Samsung Electronics 3 * (c) Copyright 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 */ 17package com.android.printservice.recommendation.plugin.samsung; 18 19import android.net.nsd.NsdServiceInfo; 20import android.text.TextUtils; 21import android.util.Log; 22 23import com.android.printservice.recommendation.util.MDNSFilteredDiscovery; 24import com.android.printservice.recommendation.util.MDNSUtils; 25 26import java.util.HashSet; 27import java.util.Set; 28 29/** 30 * Printer filter for Mopria printer models supported by the print service plugin 31 */ 32class PrinterFilterMopria implements MDNSFilteredDiscovery.PrinterFilter { 33 private static final String TAG = "PrinterFilterMopria"; 34 35 static final Set<String> MOPRIA_MDNS_SERVICES = new HashSet<String>() {{ 36 add("_ipp._tcp"); 37 add("_ipps._tcp"); 38 }}; 39 40 private static final String PDL__PDF = "application/pdf"; 41 private static final String PDL__PCLM = "application/PCLm"; 42 private static final String PDL__PWG_RASTER = "image/pwg-raster"; 43 44 private static final String PDL_ATTRIBUTE = "pdl"; 45 46 @Override 47 public boolean matchesCriteria(NsdServiceInfo nsdServiceInfo) { 48 if (!MDNSUtils.isSupportedServiceType(nsdServiceInfo, MOPRIA_MDNS_SERVICES)) { 49 return false; 50 } 51 52 String pdls = MDNSUtils.getString(nsdServiceInfo.getAttributes().get(PDL_ATTRIBUTE)); 53 boolean isMatch = !TextUtils.isEmpty(pdls) 54 && (pdls.contains(PDL__PDF) 55 || pdls.contains(PDL__PCLM) 56 || pdls.contains(PDL__PWG_RASTER)); 57 58 if (isMatch) { 59 Log.d(TAG, "Mopria printer found: " + nsdServiceInfo.getServiceName()); 60 } 61 return isMatch; 62 } 63} 64