1 /* 2 (c) Copyright 2016 Samsung Electronics.. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 18 package com.android.printservice.recommendation.plugin.samsung; 19 20 import android.content.Context; 21 import android.net.nsd.NsdServiceInfo; 22 import android.text.TextUtils; 23 24 import java.util.Locale; 25 import java.util.Map; 26 27 import com.android.printservice.recommendation.R; 28 29 public class SamsungRecommendationPlugin extends ServiceRecommendationPlugin { 30 31 private static final String TAG = "SamsungRecommendation"; 32 33 private static final String ATTR_USB_MFG = "usb_MFG"; 34 private static final String ATTR_MFG = "mfg"; 35 private static final String ATTR_USB_MDL = "usb_MDL"; 36 private static final String ATTR_MDL = "mdl"; 37 private static final String ATTR_PRODUCT = "product"; 38 private static final String ATTR_TY = "ty"; 39 40 private static String[] mNotSupportedDevices = new String[]{ 41 "SCX-5x15", 42 "SF-555P", 43 "CF-555P", 44 "SCX-4x16", 45 "SCX-4214F", 46 "CLP-500", 47 "CJX-", 48 "MJC-" 49 }; 50 51 private static boolean isSupportedModel(String model) { 52 if (!TextUtils.isEmpty(model)) { 53 String modelToUpper = model.toUpperCase(Locale.US); 54 for (String unSupportedPrinter : mNotSupportedDevices) { 55 if (modelToUpper.contains(unSupportedPrinter)) { 56 return false; 57 } 58 } 59 } 60 return true; 61 } 62 63 public SamsungRecommendationPlugin(Context context) { 64 super(context, R.string.plugin_vendor_samsung, new VendorInfo(context.getResources(), R.array.known_print_vendor_info_for_samsung), new String[]{"_pdl-datastream._tcp"}); 65 } 66 67 @Override 68 public boolean matchesCriteria(String vendor, NsdServiceInfo nsdServiceInfo) { 69 if (!TextUtils.equals(vendor, mVendorInfo.mVendorID)) return false; 70 71 String modelName = getModelName(nsdServiceInfo); 72 if (modelName != null) { 73 return (isSupportedModel(modelName)); 74 } 75 return false; 76 } 77 78 private String getModelName(NsdServiceInfo resolvedDevice) { 79 Map<String,byte[]> attributes = resolvedDevice.getAttributes(); 80 String usb_mfg = MDnsUtils.getString(attributes.get(ATTR_USB_MFG)); 81 if (TextUtils.isEmpty(usb_mfg)) { 82 usb_mfg = MDnsUtils.getString(attributes.get(ATTR_MFG)); 83 } 84 85 String usb_mdl = MDnsUtils.getString(attributes.get(ATTR_USB_MDL)); 86 if (TextUtils.isEmpty(usb_mdl)) { 87 usb_mdl = MDnsUtils.getString(attributes.get(ATTR_MDL)); 88 } 89 90 String modelName = null; 91 if (!TextUtils.isEmpty(usb_mfg) && !TextUtils.isEmpty(usb_mdl)) { 92 modelName = usb_mfg.trim() + " " + usb_mdl.trim(); 93 } else { 94 modelName = MDnsUtils.getString(attributes.get(ATTR_PRODUCT)); 95 if (TextUtils.isEmpty(modelName)) { 96 modelName = MDnsUtils.getString(attributes.get(ATTR_TY)); 97 } 98 } 99 100 return modelName; 101 } 102 } 103