Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 91af0845 authored by Philip P. Moltmann's avatar Philip P. Moltmann Committed by android-build-merger
Browse files

Merge "Add HP and Mopria print recommendation service" into nyc-dev

am: 9e5d4e07

* commit '9e5d4e07':
  Add HP and Mopria print recommendation service

Change-Id: I65e3050622544b9892143fd6a550bcf387bce731
parents cc1c5505 9e5d4e07
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -15,4 +15,25 @@
-->
<resources>
    <string name="app_label">Print Service Recommendation Service</string>

    <!-- HP / Mopria plugin -->
    <string-array name="known_print_vendor_info_for_mopria" translatable="false">
        <item>org.mopria.printplugin</item>
        <item>WFDS</item>
        <!-- no specific mDNS values to list -->
    </string-array>

    <string-array name="known_print_vendor_info_for_hp" translatable="false">
        <item>com.hp.android.printservice</item>
        <item>HP</item>
        <!-- HP has used these values in mDNS records over the years -->
        <item>HP</item>
        <item>Hewlett-Packard</item>
        <item>Hewlett Packard</item>
    </string-array>

    <array name="known_print_plugin_vendors" translatable="false">
        <item>@array/known_print_vendor_info_for_mopria</item>
        <item>@array/known_print_vendor_info_for_hp</item>
    </array>
</resources>
+1 −0
Original line number Diff line number Diff line
@@ -27,4 +27,5 @@
    <string name="plugin_vendor_epson">Epson</string>
    <string name="plugin_vendor_konika_minolta">Konika Minolta</string>
    <string name="plugin_vendor_fuji">Fuji</string>
    <string name="plugin_vendor_morpia">Mopria</string>
</resources>
+0 −10
Original line number Diff line number Diff line
@@ -17,16 +17,6 @@
  -->

<vendors>
    <vendor>
        <name>@string/plugin_vendor_hp</name>
        <package>com.hp.android.printservice</package>
        <mdns-names>
            <mdns-name>HP</mdns-name>
            <mdns-name>Hewlett-Packard</mdns-name>
            <mdns-name>Hewlett Packard</mdns-name>
        </mdns-names>
    </vendor>

    <vendor>
        <name>@string/plugin_vendor_lexmark</name>
        <package>com.lexmark.print.plugin</package>
+18 −0
Original line number Diff line number Diff line
@@ -21,8 +21,10 @@ import android.printservice.recommendation.RecommendationInfo;
import android.printservice.recommendation.RecommendationService;
import android.printservice.PrintService;
import android.util.Log;
import com.android.printservice.recommendation.plugin.hp.HPRecommendationPlugin;
import com.android.printservice.recommendation.plugin.mdnsFilter.MDNSFilterPlugin;
import com.android.printservice.recommendation.plugin.mdnsFilter.VendorConfig;
import com.android.printservice.recommendation.plugin.mopria.MopriaRecommendationPlugin;
import org.xmlpull.v1.XmlPullParserException;

import java.io.IOException;
@@ -56,6 +58,22 @@ public class RecommendationServiceImpl extends RecommendationService
            new RuntimeException("Could not parse vendorconfig", e);
        }

        try {
            mPlugins.add(new RemotePrintServicePlugin(new HPRecommendationPlugin(this), this,
                    false));
        } catch (Exception e) {
            Log.e(LOG_TAG, "Could not initiate " + getString(R.string.plugin_vendor_hp) + " plugin",
                    e);
        }

        try {
            mPlugins.add(new RemotePrintServicePlugin(new MopriaRecommendationPlugin(this), this,
                    true));
        } catch (Exception e) {
            Log.e(LOG_TAG, "Could not initiate " + getString(R.string.plugin_vendor_morpia) +
                    " plugin", e);
        }

        final int numPlugins = mPlugins.size();
        for (int i = 0; i < numPlugins; i++) {
            try {
+100 −0
Original line number Diff line number Diff line
/*
(c) Copyright 2016 HP Inc.
Copyright (C) 2016 The Android Open Source Project

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package com.android.printservice.recommendation.plugin.hp;

import android.content.Context;
import android.net.nsd.NsdServiceInfo;
import android.text.TextUtils;

import com.android.printservice.recommendation.R;

import java.util.Locale;

public class HPRecommendationPlugin extends ServiceRecommendationPlugin {

    private static final String PDL__PCL = "application/vnd.hp-PCL";
    private static final String PDL__PCLM = "application/PCLm";
    private static final String PDL__PDF = "application/pdf";
    private static final String PDL__PWG_RASTER = "image/pwg-raster";

    private static final String TAG_DESIGNJET = "DESIGNJET";
    private static final String TAG_PAGEWIDE = "PAGEWIDE";
    private static final String TAG_LATEX = "LATEX";
    private static final String TAG_SCITEX = "SCITEX";
    private static final String TAG_XL = "XL";
    private static final String ATTRIBUTE_VALUE__TRUE = "T";
    private static final String MDNS_ATTRIBUTE__HPLFMOBILEPRINTER = "hplfpmobileprinter";
    private static final String MDNS_ATTRIBUTE__TY = "ty";


    private static String[] mSupportedDesignJet = new String[]{
        "HP DESIGNJET T120",
        "HP DESIGNJET T520",
        "HP DESIGNJET T930",
        "HP DESIGNJET T1530",
        "HP DESIGNJET T2530",
        "HP DESIGNJET T730",
        "HP DESIGNJET T830",
    };

    private boolean isPrintSupported(String printerModel) {
        boolean isSupported;
        if (!TextUtils.isEmpty(printerModel)) {
            String modelToUpper = printerModel.toUpperCase(Locale.US);
            if (modelToUpper.contains(TAG_DESIGNJET)) {
                isSupported = isSupportedDesignjet(printerModel);
            } else
                isSupported = !(modelToUpper.contains(TAG_LATEX) || modelToUpper.contains(TAG_SCITEX)) && !(modelToUpper.contains(TAG_PAGEWIDE) && modelToUpper.contains(TAG_XL));
        } else {
            isSupported = false;
        }

        return isSupported;
    }

    private static boolean isSupportedDesignjet(String printerModel) {
        boolean isSupported = false;
        if (!TextUtils.isEmpty(printerModel)) {
            String modelToUpper = printerModel.toUpperCase(Locale.US);
            for (String supportedPrinter : mSupportedDesignJet) {
                if (modelToUpper.contains(supportedPrinter)) {
                    isSupported = true;
                }
            }
        }
        return isSupported;
    }

    public HPRecommendationPlugin(Context context) {
        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"});
    }

    @Override
    public boolean matchesCriteria(String vendor, NsdServiceInfo nsdServiceInfo) {
        if (!TextUtils.equals(vendor, mVendorInfo.mVendorID)) return false;

        String pdls = MDnsUtils.getString(nsdServiceInfo.getAttributes().get(PDL_ATTRIBUTE));
        boolean hasMobileSupport = TextUtils.equals(ATTRIBUTE_VALUE__TRUE, MDnsUtils.getString(nsdServiceInfo.getAttributes().get(MDNS_ATTRIBUTE__HPLFMOBILEPRINTER)));

        return (((hasMobileSupport || isPrintSupported(MDnsUtils.getString(nsdServiceInfo.getAttributes().get(MDNS_ATTRIBUTE__TY))))
                    &&!TextUtils.isEmpty(pdls))
                && (pdls.contains(PDL__PCL)
                || pdls.contains(PDL__PDF)
                || pdls.contains(PDL__PCLM)
                || pdls.contains(PDL__PWG_RASTER)));
    }
}
Loading