Home | History | Annotate | Download | only in util
      1 /*
      2  * Copyright (C) 2014 The Android Open Source Project
      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 package com.android.printspooler.util;
     18 
     19 import android.content.ComponentName;
     20 import android.content.Context;
     21 import android.content.pm.ServiceInfo;
     22 import android.print.PrintManager;
     23 import android.printservice.PrintServiceInfo;
     24 
     25 import java.util.List;
     26 
     27 public class PrintOptionUtils {
     28 
     29     private PrintOptionUtils() {
     30         /* ignore - hide constructor */
     31     }
     32 
     33     /**
     34      * Gets the advanced options activity name for a print service.
     35      *
     36      * @param context Context for accessing system resources.
     37      * @param serviceName The print service name.
     38      * @return The advanced options activity name or null.
     39      */
     40     public static String getAdvancedOptionsActivityName(Context context,
     41             ComponentName serviceName) {
     42         PrintManager printManager = (PrintManager) context.getSystemService(
     43                 Context.PRINT_SERVICE);
     44         List<PrintServiceInfo> printServices = printManager.getEnabledPrintServices();
     45         final int printServiceCount = printServices.size();
     46         for (int i = 0; i < printServiceCount; i ++) {
     47             PrintServiceInfo printServiceInfo = printServices.get(i);
     48             ServiceInfo serviceInfo = printServiceInfo.getResolveInfo().serviceInfo;
     49             if (serviceInfo.name.equals(serviceName.getClassName())
     50                     && serviceInfo.packageName.equals(serviceName.getPackageName())) {
     51                 return printServiceInfo.getAdvancedOptionsActivityName();
     52             }
     53         }
     54         return null;
     55     }
     56 }
     57