summaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
authorSvetoslav <svetoslavganov@google.com>2013-09-05 05:36:51 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2013-09-05 05:36:51 +0000
commitc5c203d6ef8eea46f1c06f52e3ebfcc59c304760 (patch)
treebb81bb8c546c75bd418338cfd92ffdf446846fbf /services
parent2069b00416c5da60a84ad75a9a9efe56a455e187 (diff)
parent773f54de3de9bce7b6f915aa47ed686b161d77aa (diff)
downloadframeworks_base-c5c203d6ef8eea46f1c06f52e3ebfcc59c304760.zip
frameworks_base-c5c203d6ef8eea46f1c06f52e3ebfcc59c304760.tar.gz
frameworks_base-c5c203d6ef8eea46f1c06f52e3ebfcc59c304760.tar.bz2
Merge "Print API updated." into klp-dev
Diffstat (limited to 'services')
-rw-r--r--services/java/com/android/server/print/RemotePrintService.java14
-rw-r--r--services/java/com/android/server/print/UserState.java102
2 files changed, 12 insertions, 104 deletions
diff --git a/services/java/com/android/server/print/RemotePrintService.java b/services/java/com/android/server/print/RemotePrintService.java
index 3c67aa9..2ded202 100644
--- a/services/java/com/android/server/print/RemotePrintService.java
+++ b/services/java/com/android/server/print/RemotePrintService.java
@@ -684,20 +684,6 @@ final class RemotePrintService implements DeathRecipient {
}
}
- @Override
- public void onPrintersUpdated(List<PrinterInfo> printers) {
- RemotePrintService service = mWeakService.get();
- if (service != null) {
- throwIfPrinterIdsForPrinterInfoTampered(service.mComponentName, printers);
- final long identity = Binder.clearCallingIdentity();
- try {
- service.mUserState.onPrintersUpdated(printers);
- } finally {
- Binder.restoreCallingIdentity(identity);
- }
- }
- }
-
private void throwIfPrinterIdsForPrinterInfoTampered(ComponentName serviceName,
List<PrinterInfo> printerInfos) {
final int printerInfoCount = printerInfos.size();
diff --git a/services/java/com/android/server/print/UserState.java b/services/java/com/android/server/print/UserState.java
index b9c676d..8fe979b 100644
--- a/services/java/com/android/server/print/UserState.java
+++ b/services/java/com/android/server/print/UserState.java
@@ -276,22 +276,6 @@ final class UserState implements PrintSpoolerCallbacks {
}
}
- public void onPrintersUpdated(List<PrinterInfo> printers) {
- synchronized (mLock) {
- throwIfDestroyedLocked();
- // No services - nothing to do.
- if (mActiveServices.isEmpty()) {
- return;
- }
- // No session - nothing to do.
- if (mPrinterDiscoverySession == null) {
- return;
- }
- // Request an updated.
- mPrinterDiscoverySession.onPrintersUpdatedLocked(printers);
- }
- }
-
public void updateIfNeededLocked() {
throwIfDestroyedLocked();
if (readConfigurationLocked()) {
@@ -746,8 +730,8 @@ final class UserState implements PrintSpoolerCallbacks {
final int addedPrinterCount = printers.size();
for (int i = 0; i < addedPrinterCount; i++) {
PrinterInfo printer = printers.get(i);
- if (!mPrinters.containsKey(printer.getId())) {
- mPrinters.put(printer.getId(), printer);
+ PrinterInfo oldPrinter = mPrinters.put(printer.getId(), printer);
+ if (oldPrinter == null || !oldPrinter.equals(printer)) {
if (addedPrinters == null) {
addedPrinters = new ArrayList<PrinterInfo>();
}
@@ -785,32 +769,6 @@ final class UserState implements PrintSpoolerCallbacks {
}
}
- public void onPrintersUpdatedLocked(List<PrinterInfo> printers) {
- if (DEBUG) {
- Log.i(LOG_TAG, "onPrintersUpdatedLocked()");
- }
- if (mIsDestroyed) {
- Log.w(LOG_TAG, "Not updating printers - session destroyed");
- return;
- }
- List<PrinterInfo> updatedPrinters = null;
- final int updatedPrinterCount = printers.size();
- for (int i = 0; i < updatedPrinterCount; i++) {
- PrinterInfo updatedPrinter = printers.get(i);
- if (mPrinters.containsKey(updatedPrinter.getId())) {
- mPrinters.put(updatedPrinter.getId(), updatedPrinter);
- if (updatedPrinters == null) {
- updatedPrinters = new ArrayList<PrinterInfo>();
- }
- updatedPrinters.add(updatedPrinter);
- }
- }
- if (updatedPrinters != null) {
- mHandler.obtainMessage(SessionHandler.MSG_DISPATCH_PRINTERS_UPDATED,
- updatedPrinters).sendToTarget();
- }
- }
-
public void onServiceRemovedLocked(ComponentName serviceName) {
if (mIsDestroyed) {
Log.w(LOG_TAG, "Not updating removed service - session destroyed");
@@ -874,15 +832,6 @@ final class UserState implements PrintSpoolerCallbacks {
mDiscoveryObservers.finishBroadcast();
}
- private void handleDispatchPrintersUpdated(List<PrinterInfo> updatedPrinters) {
- final int observerCount = mDiscoveryObservers.beginBroadcast();
- for (int i = 0; i < observerCount; i++) {
- IPrinterDiscoveryObserver observer = mDiscoveryObservers.getBroadcastItem(i);
- handlePrintersUpdated(observer, updatedPrinters);
- }
- mDiscoveryObservers.finishBroadcast();
- }
-
private void handleDispatchCreatePrinterDiscoverySession(
List<RemotePrintService> services) {
final int serviceCount = services.size();
@@ -976,43 +925,21 @@ final class UserState implements PrintSpoolerCallbacks {
}
}
- private void handlePrintersUpdated(IPrinterDiscoveryObserver observer,
- List<PrinterInfo> updatedPrinters) {
- try {
- final int printerCount = updatedPrinters.size();
- if (printerCount <= MAX_ITEMS_PER_CALLBACK) {
- observer.onPrintersUpdated(updatedPrinters);
- } else {
- // Send the added printers in chunks avoiding the binder transaction limit.
- final int transactionCount = (printerCount / MAX_ITEMS_PER_CALLBACK) + 1;
- for (int i = 0; i < transactionCount; i++) {
- final int start = i * MAX_ITEMS_PER_CALLBACK;
- final int end = Math.min(start + MAX_ITEMS_PER_CALLBACK, printerCount);
- List<PrinterInfo> subPrinters = updatedPrinters.subList(start, end);
- observer.onPrintersUpdated(subPrinters);
- }
- }
- } catch (RemoteException re) {
- Log.e(LOG_TAG, "Error sending updated printers", re);
- }
- }
-
private final class SessionHandler extends Handler {
public static final int MSG_PRINTERS_ADDED = 1;
public static final int MSG_PRINTERS_REMOVED = 2;
public static final int MSG_DISPATCH_PRINTERS_ADDED = 3;
public static final int MSG_DISPATCH_PRINTERS_REMOVED = 4;
- public static final int MSG_DISPATCH_PRINTERS_UPDATED = 5;
-
- public static final int MSG_CREATE_PRINTER_DISCOVERY_SESSION = 6;
- public static final int MSG_START_PRINTER_DISCOVERY = 7;
- public static final int MSG_DISPATCH_CREATE_PRINTER_DISCOVERY_SESSION = 8;
- public static final int MSG_DISPATCH_DESTROY_PRINTER_DISCOVERY_SESSION = 9;
- public static final int MSG_DISPATCH_START_PRINTER_DISCOVERY = 10;
- public static final int MSG_DISPATCH_STOP_PRINTER_DISCOVERY = 11;
- public static final int MSG_VALIDATE_PRINTERS = 12;
- public static final int MSG_START_PRINTER_STATE_TRACKING = 13;
- public static final int MSG_STOP_PRINTER_STATE_TRACKING = 14;
+
+ public static final int MSG_CREATE_PRINTER_DISCOVERY_SESSION = 5;
+ public static final int MSG_START_PRINTER_DISCOVERY = 6;
+ public static final int MSG_DISPATCH_CREATE_PRINTER_DISCOVERY_SESSION = 7;
+ public static final int MSG_DISPATCH_DESTROY_PRINTER_DISCOVERY_SESSION = 8;
+ public static final int MSG_DISPATCH_START_PRINTER_DISCOVERY = 9;
+ public static final int MSG_DISPATCH_STOP_PRINTER_DISCOVERY = 10;
+ public static final int MSG_VALIDATE_PRINTERS = 11;
+ public static final int MSG_START_PRINTER_STATE_TRACKING = 12;
+ public static final int MSG_STOP_PRINTER_STATE_TRACKING = 13;
SessionHandler(Looper looper) {
super(looper, null, false);
@@ -1048,11 +975,6 @@ final class UserState implements PrintSpoolerCallbacks {
handleDispatchPrintersRemoved(removedPrinterIds);
} break;
- case MSG_DISPATCH_PRINTERS_UPDATED: {
- List<PrinterInfo> updatedPrinters = (List<PrinterInfo>) message.obj;
- handleDispatchPrintersUpdated(updatedPrinters);
- } break;
-
case MSG_CREATE_PRINTER_DISCOVERY_SESSION: {
RemotePrintService service = (RemotePrintService) message.obj;
service.createPrinterDiscoverySession();