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 android.print.test.services;
18 
19 import android.content.Context;
20 import android.print.PrinterId;
21 import android.printservice.PrintJob;
22 import android.printservice.PrintService;
23 import android.printservice.PrinterDiscoverySession;
24 import android.util.Log;
25 
26 import java.util.List;
27 
28 public abstract class StubbablePrintService extends PrintService {
29     private static final String LOG_TAG = StubbablePrintService.class.getSimpleName();
30 
31     @Override
onCreatePrinterDiscoverySession()32     public PrinterDiscoverySession onCreatePrinterDiscoverySession() {
33         PrintServiceCallbacks callbacks = getCallbacks();
34         if (callbacks != null) {
35             return new StubbablePrinterDiscoverySession(this,
36                     getCallbacks().onCreatePrinterDiscoverySessionCallbacks());
37         }
38 
39         Log.w(LOG_TAG, "onCreatePrinterDiscoverySession called but no callbacks are set up");
40         return new PrinterDiscoverySession() {
41             @Override
42             public void onStartPrinterDiscovery(List<PrinterId> priorityList) {
43                 // empty
44             }
45 
46             @Override
47             public void onStopPrinterDiscovery() {
48                 // empty
49             }
50 
51             @Override
52             public void onValidatePrinters(List<PrinterId> printerIds) {
53                 // empty
54             }
55 
56             @Override
57             public void onStartPrinterStateTracking(PrinterId printerId) {
58                 // empty
59             }
60 
61             @Override
62             public void onStopPrinterStateTracking(PrinterId printerId) {
63                 // empty
64             }
65 
66             @Override
67             public void onDestroy() {
68                 // empty
69             }
70         };
71     }
72 
73     @Override
onRequestCancelPrintJob(PrintJob printJob)74     public void onRequestCancelPrintJob(PrintJob printJob) {
75         PrintServiceCallbacks callbacks = getCallbacks();
76         if (callbacks != null) {
77             callbacks.onRequestCancelPrintJob(printJob);
78         }
79     }
80 
81     @Override
onPrintJobQueued(PrintJob printJob)82     public void onPrintJobQueued(PrintJob printJob) {
83         PrintServiceCallbacks callbacks = getCallbacks();
84         if (callbacks != null) {
85             callbacks.onPrintJobQueued(printJob);
86         }
87     }
88 
getCallbacks()89     protected abstract PrintServiceCallbacks getCallbacks();
90 
callAttachBaseContext(Context base)91     public void callAttachBaseContext(Context base) {
92         attachBaseContext(base);
93     }
94 
callGetActivePrintJobs()95     public List<PrintJob> callGetActivePrintJobs() {
96         return getActivePrintJobs();
97     }
98 
99 }
100