1 /* 2 (c) Copyright 2016 HP 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 package com.android.printservice.recommendation.plugin.hp; 18 19 import android.content.Context; 20 import android.net.nsd.NsdServiceInfo; 21 import android.text.TextUtils; 22 23 import com.android.printservice.recommendation.R; 24 25 import java.util.Locale; 26 27 public class HPRecommendationPlugin extends ServiceRecommendationPlugin { 28 29 private static final String PDL__PCL = "application/vnd.hp-PCL"; 30 private static final String PDL__PCLM = "application/PCLm"; 31 private static final String PDL__PDF = "application/pdf"; 32 private static final String PDL__PWG_RASTER = "image/pwg-raster"; 33 34 private static final String TAG_DESIGNJET = "DESIGNJET"; 35 private static final String TAG_PAGEWIDE = "PAGEWIDE"; 36 private static final String TAG_LATEX = "LATEX"; 37 private static final String TAG_SCITEX = "SCITEX"; 38 private static final String TAG_XL = "XL"; 39 private static final String ATTRIBUTE_VALUE__TRUE = "T"; 40 private static final String MDNS_ATTRIBUTE__HPLFMOBILEPRINTER = "hplfpmobileprinter"; 41 private static final String MDNS_ATTRIBUTE__TY = "ty"; 42 43 44 private static String[] mSupportedDesignJet = new String[]{ 45 "HP DESIGNJET T120", 46 "HP DESIGNJET T520", 47 "HP DESIGNJET T930", 48 "HP DESIGNJET T1530", 49 "HP DESIGNJET T2530", 50 "HP DESIGNJET T730", 51 "HP DESIGNJET T830", 52 }; 53 54 private boolean isPrintSupported(String printerModel) { 55 boolean isSupported; 56 if (!TextUtils.isEmpty(printerModel)) { 57 String modelToUpper = printerModel.toUpperCase(Locale.US); 58 if (modelToUpper.contains(TAG_DESIGNJET)) { 59 isSupported = isSupportedDesignjet(printerModel); 60 } else 61 isSupported = !(modelToUpper.contains(TAG_LATEX) || modelToUpper.contains(TAG_SCITEX)) && !(modelToUpper.contains(TAG_PAGEWIDE) && modelToUpper.contains(TAG_XL)); 62 } else { 63 isSupported = false; 64 } 65 66 return isSupported; 67 } 68 69 private static boolean isSupportedDesignjet(String printerModel) { 70 boolean isSupported = false; 71 if (!TextUtils.isEmpty(printerModel)) { 72 String modelToUpper = printerModel.toUpperCase(Locale.US); 73 for (String supportedPrinter : mSupportedDesignJet) { 74 if (modelToUpper.contains(supportedPrinter)) { 75 isSupported = true; 76 } 77 } 78 } 79 return isSupported; 80 } 81 82 public HPRecommendationPlugin(Context context) { 83 super(context, R.string.plugin_vendor_hp, new VendorInfo(context.getResources(), R.array.known_print_vendor_info_for_hp), new String[]{"_pdl-datastream._tcp","_ipp._tcp", "_ipps._tcp"}); 84 } 85 86 @Override 87 public boolean matchesCriteria(String vendor, NsdServiceInfo nsdServiceInfo) { 88 if (!TextUtils.equals(vendor, mVendorInfo.mVendorID)) return false; 89 90 String pdls = MDnsUtils.getString(nsdServiceInfo.getAttributes().get(PDL_ATTRIBUTE)); 91 boolean hasMobileSupport = TextUtils.equals(ATTRIBUTE_VALUE__TRUE, MDnsUtils.getString(nsdServiceInfo.getAttributes().get(MDNS_ATTRIBUTE__HPLFMOBILEPRINTER))); 92 93 return (((hasMobileSupport || isPrintSupported(MDnsUtils.getString(nsdServiceInfo.getAttributes().get(MDNS_ATTRIBUTE__TY)))) 94 &&!TextUtils.isEmpty(pdls)) 95 && (pdls.contains(PDL__PCL) 96 || pdls.contains(PDL__PDF) 97 || pdls.contains(PDL__PCLM) 98 || pdls.contains(PDL__PWG_RASTER))); 99 } 100 } 101