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.content.Context; |
| 20 | import android.net.nsd.NsdServiceInfo; |
| 21 | import android.annotation.NonNull; |
| 22 | |
| 23 | import com.android.printservice.recommendation.PrintServicePlugin; |
| 24 | import com.android.printservice.recommendation.R; |
| 25 | import com.android.printservice.recommendation.util.MDNSFilteredDiscovery; |
| 26 | |
| 27 | import java.util.HashSet; |
| 28 | import java.util.Set; |
| 29 | |
| 30 | public class SamsungRecommendationPlugin implements PrintServicePlugin { |
| 31 | private static final Set<String> ALL_MDNS_SERVICES = new HashSet<String>() {{ |
| 32 | addAll(PrinterFilterMopria.MOPRIA_MDNS_SERVICES); |
| 33 | addAll(PrinterFilterSamsung.SAMSUNG_MDNS_SERVICES); |
| 34 | }}; |
| 35 | |
| 36 | private final @NonNull Context mContext; |
| 37 | private final @NonNull MDNSFilteredDiscovery mMDNSFilteredDiscovery; |
| 38 | |
| 39 | private final @NonNull PrinterFilterSamsung mPrinterFilterSamsung = new PrinterFilterSamsung(); |
| 40 | private final @NonNull PrinterFilterMopria mPrinterFilterMopria = new PrinterFilterMopria(); |
| 41 | |
| 42 | public SamsungRecommendationPlugin(@NonNull Context context) { |
| 43 | mContext = context; |
| 44 | mMDNSFilteredDiscovery = new MDNSFilteredDiscovery(context, ALL_MDNS_SERVICES, |
| 45 | (NsdServiceInfo nsdServiceInfo) -> |
| 46 | mPrinterFilterSamsung.matchesCriteria(nsdServiceInfo) || |
| 47 | mPrinterFilterMopria.matchesCriteria(nsdServiceInfo)); |
| 48 | } |
| 49 | |
| 50 | @Override |
| 51 | public int getName() { |
| 52 | return R.string.plugin_vendor_samsung; |
| 53 | } |
| 54 | |
| 55 | @Override |
| 56 | public @NonNull CharSequence getPackageName() { |
| 57 | return mContext.getString(R.string.plugin_package_samsung); |
| 58 | } |
| 59 | |
| 60 | @Override |
| 61 | public void start(@NonNull PrinterDiscoveryCallback callback) throws Exception { |
| 62 | mMDNSFilteredDiscovery.start(callback); |
| 63 | } |
| 64 | |
| 65 | @Override |
| 66 | public void stop() throws Exception { |
| 67 | mMDNSFilteredDiscovery.stop(); |
| 68 | } |
| 69 | } |