summaryrefslogtreecommitdiffstats
path: root/services/java/com/android
diff options
context:
space:
mode:
authorSvetoslav Ganov <svetoslavganov@google.com>2013-08-11 21:42:53 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2013-08-11 21:42:54 +0000
commitc7c4d6dd4df2b177d0b6e382fdcde9bf2032baea (patch)
tree16844d8d5e02286f09932469c69aaec9bbd4bb9e /services/java/com/android
parent0dd303cfdbd95e4aa0d4221cf547fdcdbc7c3756 (diff)
parent798bed6cc7d273e72b0253288605db9cd2b57740 (diff)
downloadframeworks_base-c7c4d6dd4df2b177d0b6e382fdcde9bf2032baea.zip
frameworks_base-c7c4d6dd4df2b177d0b6e382fdcde9bf2032baea.tar.gz
frameworks_base-c7c4d6dd4df2b177d0b6e382fdcde9bf2032baea.tar.bz2
Merge "Refinement of the print service APIs." into klp-dev
Diffstat (limited to 'services/java/com/android')
-rw-r--r--services/java/com/android/server/print/RemotePrintService.java126
-rw-r--r--services/java/com/android/server/print/RemotePrintSpooler.java37
-rw-r--r--services/java/com/android/server/print/UserState.java39
3 files changed, 44 insertions, 158 deletions
diff --git a/services/java/com/android/server/print/RemotePrintService.java b/services/java/com/android/server/print/RemotePrintService.java
index 28a7362..322de6c 100644
--- a/services/java/com/android/server/print/RemotePrintService.java
+++ b/services/java/com/android/server/print/RemotePrintService.java
@@ -24,13 +24,14 @@ import android.os.Binder;
import android.os.Build;
import android.os.Handler;
import android.os.IBinder;
+import android.os.IBinder.DeathRecipient;
import android.os.Looper;
import android.os.Message;
import android.os.ParcelFileDescriptor;
import android.os.RemoteException;
import android.os.UserHandle;
-import android.os.IBinder.DeathRecipient;
-import android.print.IPrinterDiscoveryObserver;
+import android.print.IPrinterDiscoverySessionController;
+import android.print.IPrinterDiscoverySessionObserver;
import android.print.PrintJobInfo;
import android.print.PrintManager;
import android.print.PrinterId;
@@ -128,18 +129,18 @@ final class RemotePrintService implements DeathRecipient {
printJob).sendToTarget();
}
- private void handleOnRequestCancelPrintJob(final PrintJobInfo printJob) {
+ private void handleRequestCancelPrintJob(final PrintJobInfo printJob) {
throwIfDestroyed();
// If we are not bound, then we have no print jobs to handle
// which means that there are no print jobs to be cancelled.
if (isBound()) {
if (DEBUG) {
- Slog.i(LOG_TAG, "[user: " + mUserId + "] handleOnRequestCancelPrintJob()");
+ Slog.i(LOG_TAG, "[user: " + mUserId + "] handleRequestCancelPrintJob()");
}
try {
- mPrintService.onRequestCancelPrintJob(printJob);
+ mPrintService.requestCancelPrintJob(printJob);
} catch (RemoteException re) {
- Slog.e(LOG_TAG, "Error canceling pring job.", re);
+ Slog.e(LOG_TAG, "Error canceling a pring job.", re);
}
}
}
@@ -171,85 +172,34 @@ final class RemotePrintService implements DeathRecipient {
}
}
- public void onStartPrinterDiscovery(IPrinterDiscoveryObserver observer) {
- mHandler.obtainMessage(MyHandler.MSG_ON_START_PRINTER_DISCOVERY, observer).sendToTarget();
+ public void createPrinterDiscoverySession(IPrinterDiscoverySessionObserver observer) {
+ mHandler.obtainMessage(MyHandler.MSG_CREATE_PRINTER_DISCOVERY_SESSION,
+ observer).sendToTarget();
}
- private void handleOnStartPrinterDiscovery(final IPrinterDiscoveryObserver observer) {
+ private void handleCreatePrinterDiscoverySession(
+ final IPrinterDiscoverySessionObserver observer) {
throwIfDestroyed();
if (!isBound()) {
ensureBound();
mPendingCommands.add(new Runnable() {
@Override
public void run() {
- handleOnStartPrinterDiscovery(observer);
+ handleCreatePrinterDiscoverySession(observer);
}
});
} else {
if (DEBUG) {
- Slog.i(LOG_TAG, "[user: " + mUserId + "] onStartPrinterDiscovery()");
+ Slog.i(LOG_TAG, "[user: " + mUserId + "] createPrinterDiscoverySession()");
}
try {
- mPrintService.onStartPrinterDiscovery(observer);
+ mPrintService.createPrinterDiscoverySession(observer);
} catch (RemoteException re) {
Slog.e(LOG_TAG, "Error announcing start printer dicovery.", re);
}
}
}
- public void onStopPrinterDiscovery() {
- mHandler.sendEmptyMessage(MyHandler.MSG_ON_STOP_PRINTER_DISCOVERY);
- }
-
- private void handleStopPrinterDiscovery() {
- throwIfDestroyed();
- if (!isBound()) {
- ensureBound();
- mPendingCommands.add(new Runnable() {
- @Override
- public void run() {
- handleStopPrinterDiscovery();
- }
- });
- } else {
- if (DEBUG) {
- Slog.i(LOG_TAG, "[user: " + mUserId + "] onStopPrinterDiscovery()");
- }
- try {
- mPrintService.onStopPrinterDiscovery();
- } catch (RemoteException re) {
- Slog.e(LOG_TAG, "Error announcing stop printer dicovery.", re);
- }
- }
- }
-
- public void onRequestUpdatePrinters(List<PrinterId> printerIds) {
- mHandler.obtainMessage(MyHandler.MSG_ON_REQUEST_UPDATE_PRINTERS,
- printerIds).sendToTarget();
- }
-
- private void handleReqeustUpdatePrinters(final List<PrinterId> printerIds) {
- throwIfDestroyed();
- if (!isBound()) {
- ensureBound();
- mPendingCommands.add(new Runnable() {
- @Override
- public void run() {
- handleReqeustUpdatePrinters(printerIds);
- }
- });
- } else {
- if (DEBUG) {
- Slog.i(LOG_TAG, "[user: " + mUserId + "] handleReqeustUpdatePrinters()");
- }
- try {
- mPrintService.onRequestUpdatePrinters(printerIds);
- } catch (RemoteException re) {
- Slog.e(LOG_TAG, "Error requesting to update printers.", re);
- }
- }
- }
-
private boolean isBound() {
return mPrintService != null;
}
@@ -331,18 +281,15 @@ final class RemotePrintService implements DeathRecipient {
public static final int MSG_ON_ALL_PRINT_JOBS_HANDLED = 1;
public static final int MSG_ON_REQUEST_CANCEL_PRINT_JOB = 2;
public static final int MSG_ON_PRINT_JOB_QUEUED = 3;
- public static final int MSG_ON_START_PRINTER_DISCOVERY = 4;
- public static final int MSG_ON_STOP_PRINTER_DISCOVERY = 5;
- public static final int MSG_ON_REQUEST_UPDATE_PRINTERS = 6;
- public static final int MSG_DESTROY = 7;
- public static final int MSG_BINDER_DIED = 8;
+ public static final int MSG_CREATE_PRINTER_DISCOVERY_SESSION = 4;
+ public static final int MSG_DESTROY = 6;
+ public static final int MSG_BINDER_DIED = 7;
public MyHandler(Looper looper) {
super(looper, null, false);
}
@Override
- @SuppressWarnings("unchecked")
public void handleMessage(Message message) {
switch (message.what) {
case MSG_ON_ALL_PRINT_JOBS_HANDLED: {
@@ -351,7 +298,7 @@ final class RemotePrintService implements DeathRecipient {
case MSG_ON_REQUEST_CANCEL_PRINT_JOB: {
PrintJobInfo printJob = (PrintJobInfo) message.obj;
- handleOnRequestCancelPrintJob(printJob);
+ handleRequestCancelPrintJob(printJob);
} break;
case MSG_ON_PRINT_JOB_QUEUED: {
@@ -359,21 +306,13 @@ final class RemotePrintService implements DeathRecipient {
handleOnPrintJobQueued(printJob);
} break;
- case MSG_ON_START_PRINTER_DISCOVERY: {
- IPrinterDiscoveryObserver observer = (IPrinterDiscoveryObserver) message.obj;
- handleOnStartPrinterDiscovery(new SecurePrinterDiscoveryObserver(
+ case MSG_CREATE_PRINTER_DISCOVERY_SESSION: {
+ IPrinterDiscoverySessionObserver observer =
+ (IPrinterDiscoverySessionObserver) message.obj;
+ handleCreatePrinterDiscoverySession(new SecurePrinterDiscoverySessionObserver(
mComponentName, observer));
} break;
- case MSG_ON_REQUEST_UPDATE_PRINTERS: {
- List<PrinterId> printerIds = (List<PrinterId>) message.obj;
- handleReqeustUpdatePrinters(printerIds);
- } break;
-
- case MSG_ON_STOP_PRINTER_DISCOVERY: {
- handleStopPrinterDiscovery();
- } break;
-
case MSG_DESTROY: {
handleDestroy();
} break;
@@ -464,14 +403,14 @@ final class RemotePrintService implements DeathRecipient {
}
}
- private static final class SecurePrinterDiscoveryObserver
- extends IPrinterDiscoveryObserver.Stub {
+ private static final class SecurePrinterDiscoverySessionObserver
+ extends IPrinterDiscoverySessionObserver.Stub {
private final ComponentName mComponentName;
- private final IPrinterDiscoveryObserver mDecoratedObsever;
+ private final IPrinterDiscoverySessionObserver mDecoratedObsever;
- public SecurePrinterDiscoveryObserver(ComponentName componentName,
- IPrinterDiscoveryObserver observer) {
+ public SecurePrinterDiscoverySessionObserver(ComponentName componentName,
+ IPrinterDiscoverySessionObserver observer) {
mComponentName = componentName;
mDecoratedObsever = observer;
}
@@ -506,6 +445,15 @@ final class RemotePrintService implements DeathRecipient {
}
}
+ @Override
+ public void setController(IPrinterDiscoverySessionController controller) {
+ try {
+ mDecoratedObsever.setController(controller);
+ } catch (RemoteException re) {
+ Slog.e(LOG_TAG, "Error setting controller", re);
+ }
+ }
+
private void throwIfPrinterIdsForPrinterInfoTampered(
List<PrinterInfo> printerInfos) {
final int printerInfoCount = printerInfos.size();
diff --git a/services/java/com/android/server/print/RemotePrintSpooler.java b/services/java/com/android/server/print/RemotePrintSpooler.java
index 3a96a5b..c932e9b 100644
--- a/services/java/com/android/server/print/RemotePrintSpooler.java
+++ b/services/java/com/android/server/print/RemotePrintSpooler.java
@@ -32,10 +32,9 @@ import android.print.IPrintDocumentAdapter;
import android.print.IPrintSpooler;
import android.print.IPrintSpoolerCallbacks;
import android.print.IPrintSpoolerClient;
-import android.print.IPrinterDiscoveryObserver;
+import android.print.IPrinterDiscoverySessionObserver;
import android.print.PrintAttributes;
import android.print.PrintJobInfo;
-import android.print.PrinterId;
import android.util.Slog;
import android.util.TimedRemoteCaller;
@@ -92,10 +91,8 @@ final class RemotePrintSpooler {
public static interface PrintSpoolerCallbacks {
public void onPrintJobQueued(PrintJobInfo printJob);
- public void onStartPrinterDiscovery(IPrinterDiscoveryObserver observer);
- public void onStopPrinterDiscovery();
public void onAllPrintJobsForServiceHandled(ComponentName printService);
- public void onRequestUpdatePrinters(List<PrinterId> printerIds);
+ public void createPrinterDiscoverySession(IPrinterDiscoverySessionObserver observer);
}
public RemotePrintSpooler(Context context, int userId,
@@ -600,38 +597,12 @@ final class RemotePrintSpooler {
}
@Override
- public void onStartPrinterDiscovery(IPrinterDiscoveryObserver observer) {
+ public void createPrinterDiscoverySession(IPrinterDiscoverySessionObserver observer) {
RemotePrintSpooler spooler = mWeakSpooler.get();
if (spooler != null) {
final long identity = Binder.clearCallingIdentity();
try {
- spooler.mCallbacks.onStartPrinterDiscovery(observer);
- } finally {
- Binder.restoreCallingIdentity(identity);
- }
- }
- }
-
- @Override
- public void onStopPrinterDiscovery() {
- RemotePrintSpooler spooler = mWeakSpooler.get();
- if (spooler != null) {
- final long identity = Binder.clearCallingIdentity();
- try {
- spooler.mCallbacks.onStopPrinterDiscovery();
- } finally {
- Binder.restoreCallingIdentity(identity);
- }
- }
- }
-
- @Override
- public void onRequestUpdatePrinters(List<PrinterId> printerIds) {
- RemotePrintSpooler spooler = mWeakSpooler.get();
- if (spooler != null) {
- final long identity = Binder.clearCallingIdentity();
- try {
- spooler.mCallbacks.onRequestUpdatePrinters(printerIds);
+ spooler.mCallbacks.createPrinterDiscoverySession(observer);
} finally {
Binder.restoreCallingIdentity(identity);
}
diff --git a/services/java/com/android/server/print/UserState.java b/services/java/com/android/server/print/UserState.java
index 00cc2ff..ffcc9c3 100644
--- a/services/java/com/android/server/print/UserState.java
+++ b/services/java/com/android/server/print/UserState.java
@@ -21,9 +21,8 @@ import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
-import android.print.IPrinterDiscoveryObserver;
+import android.print.IPrinterDiscoverySessionObserver;
import android.print.PrintJobInfo;
-import android.print.PrinterId;
import android.printservice.PrintServiceInfo;
import android.provider.Settings;
import android.text.TextUtils;
@@ -106,7 +105,7 @@ final class UserState implements PrintSpoolerCallbacks {
}
@Override
- public void onStartPrinterDiscovery(IPrinterDiscoveryObserver observer) {
+ public void createPrinterDiscoverySession(IPrinterDiscoverySessionObserver observer) {
final List<RemotePrintService> services;
synchronized (mLock) {
throwIfDestroyedLocked();
@@ -118,39 +117,7 @@ final class UserState implements PrintSpoolerCallbacks {
final int serviceCount = services.size();
for (int i = 0; i < serviceCount; i++) {
RemotePrintService service = services.get(i);
- service.onStartPrinterDiscovery(observer);
- }
- }
-
- @Override
- public void onStopPrinterDiscovery() {
- final List<RemotePrintService> services;
- synchronized (mLock) {
- throwIfDestroyedLocked();
- if (mActiveServices.isEmpty()) {
- return;
- }
- services = new ArrayList<RemotePrintService>(mActiveServices.values());
- }
- final int serviceCount = services.size();
- for (int i = 0; i < serviceCount; i++) {
- RemotePrintService service = services.get(i);
- service.onStopPrinterDiscovery();
- }
- }
-
- @Override
- public void onRequestUpdatePrinters(List<PrinterId> printerIds) {
- final RemotePrintService service;
- synchronized (mLock) {
- throwIfDestroyedLocked();
- if (mActiveServices.isEmpty()) {
- return;
- }
- service = mActiveServices.get(printerIds.get(0).getServiceName());
- }
- if (service != null) {
- service.onRequestUpdatePrinters(printerIds);
+ service.createPrinterDiscoverySession(observer);
}
}