summaryrefslogtreecommitdiffstats
path: root/packages/PrintSpooler/src
diff options
context:
space:
mode:
authorSvetoslav Ganov <svetoslavganov@google.com>2013-09-26 21:12:47 -0700
committerSvetoslav Ganov <svetoslavganov@google.com>2013-09-27 09:43:32 -0700
commit6be4c76441ecdc11ee4db7211edc421d26a78f1f (patch)
tree98afac282ec643f57f8bfd69bbb32dac4454f0ad /packages/PrintSpooler/src
parent231bd6c514f15cb0b42a04d4fc7fc9631c743686 (diff)
downloadframeworks_base-6be4c76441ecdc11ee4db7211edc421d26a78f1f.zip
frameworks_base-6be4c76441ecdc11ee4db7211edc421d26a78f1f.tar.gz
frameworks_base-6be4c76441ecdc11ee4db7211edc421d26a78f1f.tar.bz2
Adding a timeout for waiting to get the selected printer's capabilities.
A print service may choose to provide only the printer info and then when it is requested to start tracking the state of the printer, the service should provide the printer capabilities. If the capabilities are not received within ten seconds we mark the printer as unavailable and stop tracking it. bug:10748639 Change-Id: I9171cb5dc116fd321c23a8e4ab55109448e2fc6a
Diffstat (limited to 'packages/PrintSpooler/src')
-rw-r--r--packages/PrintSpooler/src/com/android/printspooler/PrintJobConfigActivity.java55
1 files changed, 46 insertions, 9 deletions
diff --git a/packages/PrintSpooler/src/com/android/printspooler/PrintJobConfigActivity.java b/packages/PrintSpooler/src/com/android/printspooler/PrintJobConfigActivity.java
index 8d11a93..963b287 100644
--- a/packages/PrintSpooler/src/com/android/printspooler/PrintJobConfigActivity.java
+++ b/packages/PrintSpooler/src/com/android/printspooler/PrintJobConfigActivity.java
@@ -818,8 +818,6 @@ public class PrintJobConfigActivity extends Activity {
private PrinterInfo mCurrentPrinter;
- private boolean mRequestedCurrentPrinterRefresh;
-
private final OnItemSelectedListener mOnItemSelectedListener =
new AdapterView.OnItemSelectedListener() {
@Override
@@ -839,7 +837,7 @@ public class PrintJobConfigActivity extends Activity {
return;
}
- mRequestedCurrentPrinterRefresh = false;
+ mCapabilitiesTimeout.remove();
mCurrentPrinter = (PrinterInfo) mDestinationSpinnerAdapter
.getItem(position);
@@ -854,8 +852,7 @@ public class PrintJobConfigActivity extends Activity {
PrinterCapabilitiesInfo capabilities = mCurrentPrinter.getCapabilities();
if (capabilities == null) {
- // TODO: We need a timeout for the update.
- mRequestedCurrentPrinterRefresh = true;
+ mCapabilitiesTimeout.post();
updateUi();
refreshCurrentPrinter();
} else {
@@ -1128,6 +1125,9 @@ public class PrintJobConfigActivity extends Activity {
}
};
+ private final WaitForPrinterCapabilitiesTimeout mCapabilitiesTimeout =
+ new WaitForPrinterCapabilitiesTimeout();
+
private int mEditorState;
private boolean mIgnoreNextDestinationChange;
@@ -1173,16 +1173,16 @@ public class PrintJobConfigActivity extends Activity {
if (mCurrentPrinter.getStatus() == PrinterInfo.STATUS_UNAVAILABLE
&& printer.getStatus() != PrinterInfo.STATUS_UNAVAILABLE
&& printer.getCapabilities() == null
- && !mRequestedCurrentPrinterRefresh) {
- mRequestedCurrentPrinterRefresh = true;
+ && !mCapabilitiesTimeout.isPosted()) {
+ mCapabilitiesTimeout.post();
refreshCurrentPrinter();
return;
}
// We just refreshed the current printer.
if (printer.getCapabilities() != null
- && mRequestedCurrentPrinterRefresh) {
- mRequestedCurrentPrinterRefresh = false;
+ && mCapabilitiesTimeout.isPosted()) {
+ mCapabilitiesTimeout.remove();
updatePrintAttributes(printer.getCapabilities());
updateUi();
mController.update();
@@ -1971,6 +1971,43 @@ public class PrintJobConfigActivity extends Activity {
}
}
+ private final class WaitForPrinterCapabilitiesTimeout implements Runnable {
+ private static final long GET_CAPABILITIES_TIMEOUT_MILLIS = 10000; // 10sec
+
+ private boolean mIsPosted;
+
+ public void post() {
+ if (!mIsPosted) {
+ mDestinationSpinner.postDelayed(this,
+ GET_CAPABILITIES_TIMEOUT_MILLIS);
+ mIsPosted = true;
+ }
+ }
+
+ public void remove() {
+ if (mIsPosted) {
+ mIsPosted = false;
+ mDestinationSpinner.removeCallbacks(this);
+ }
+ }
+
+ public boolean isPosted() {
+ return mIsPosted;
+ }
+
+ @Override
+ public void run() {
+ mIsPosted = false;
+ if (mDestinationSpinner.getSelectedItemPosition() >= 0) {
+ View itemView = mDestinationSpinner.getSelectedView();
+ TextView titleView = (TextView) itemView.findViewById(R.id.title);
+ String title = getString(R.string.printer_unavailable,
+ mCurrentPrinter.getName());
+ titleView.setText(title);
+ }
+ }
+ }
+
private final class DestinationAdapter extends BaseAdapter
implements LoaderManager.LoaderCallbacks<List<PrinterInfo>>{
private final List<PrinterInfo> mPrinters = new ArrayList<PrinterInfo>();