Sergey Yakovlev | 989c44b | 2016-11-18 18:59:47 +0300 | [diff] [blame] | 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 | */ |
| 17 | package com.android.printservice.recommendation.plugin.samsung; |
| 18 | |
| 19 | import android.net.nsd.NsdServiceInfo; |
| 20 | import android.text.TextUtils; |
| 21 | import android.util.Log; |
| 22 | |
| 23 | import com.android.printservice.recommendation.util.MDNSFilteredDiscovery; |
| 24 | import com.android.printservice.recommendation.util.MDNSUtils; |
| 25 | |
| 26 | import java.util.HashSet; |
| 27 | import java.util.Set; |
| 28 | |
| 29 | /** |
| 30 | * Printer filter for Mopria printer models supported by the print service plugin |
| 31 | */ |
| 32 | class 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 | } |