Methods Summary |
---|
public void | binderDied()
mHandler.sendEmptyMessage(MyHandler.MSG_BINDER_DIED);
|
public void | createPrinterDiscoverySession()
mHandler.sendEmptyMessage(MyHandler.MSG_CREATE_PRINTER_DISCOVERY_SESSION);
|
public void | destroy()
mHandler.sendEmptyMessage(MyHandler.MSG_DESTROY);
|
public void | destroyPrinterDiscoverySession()
mHandler.sendEmptyMessage(MyHandler.MSG_DESTROY_PRINTER_DISCOVERY_SESSION);
|
public void | dump(java.io.PrintWriter pw, java.lang.String prefix)
String tab = " ";
pw.append(prefix).append("service:").println();
pw.append(prefix).append(tab).append("componentName=")
.append(mComponentName.flattenToString()).println();
pw.append(prefix).append(tab).append("destroyed=")
.append(String.valueOf(mDestroyed)).println();
pw.append(prefix).append(tab).append("bound=")
.append(String.valueOf(isBound())).println();
pw.append(prefix).append(tab).append("hasDicoverySession=")
.append(String.valueOf(mHasPrinterDiscoverySession)).println();
pw.append(prefix).append(tab).append("hasActivePrintJobs=")
.append(String.valueOf(mHasActivePrintJobs)).println();
pw.append(prefix).append(tab).append("isDiscoveringPrinters=")
.append(String.valueOf(mDiscoveryPriorityList != null)).println();
pw.append(prefix).append(tab).append("trackedPrinters=")
.append((mTrackedPrinterList != null) ? mTrackedPrinterList.toString() : "null");
|
private void | ensureBound()
if (isBound() || mBinding) {
return;
}
if (DEBUG) {
Slog.i(LOG_TAG, "[user: " + mUserId + "] ensureBound()");
}
mBinding = true;
mContext.bindServiceAsUser(mIntent, mServiceConnection,
Context.BIND_AUTO_CREATE, new UserHandle(mUserId));
|
private void | ensureUnbound()
if (!isBound() && !mBinding) {
return;
}
if (DEBUG) {
Slog.i(LOG_TAG, "[user: " + mUserId + "] ensureUnbound()");
}
mBinding = false;
mPendingCommands.clear();
mHasActivePrintJobs = false;
mHasPrinterDiscoverySession = false;
mDiscoveryPriorityList = null;
mTrackedPrinterList = null;
if (isBound()) {
try {
mPrintService.setClient(null);
} catch (RemoteException re) {
/* ignore */
}
mPrintService.asBinder().unlinkToDeath(this, 0);
mPrintService = null;
mContext.unbindService(mServiceConnection);
}
|
public android.content.ComponentName | getComponentName()
return mComponentName;
|
private void | handleBinderDied()
mPrintService.asBinder().unlinkToDeath(this, 0);
mPrintService = null;
mServiceDied = true;
mCallbacks.onServiceDied(this);
|
private void | handleCreatePrinterDiscoverySession()
throwIfDestroyed();
mHasPrinterDiscoverySession = true;
if (!isBound()) {
ensureBound();
mPendingCommands.add(new Runnable() {
@Override
public void run() {
handleCreatePrinterDiscoverySession();
}
});
} else {
if (DEBUG) {
Slog.i(LOG_TAG, "[user: " + mUserId + "] createPrinterDiscoverySession()");
}
try {
mPrintService.createPrinterDiscoverySession();
} catch (RemoteException re) {
Slog.e(LOG_TAG, "Error creating printer discovery session.", re);
}
}
|
private void | handleDestroy()
throwIfDestroyed();
// Stop tracking printers.
stopTrackingAllPrinters();
// Stop printer discovery.
if (mDiscoveryPriorityList != null) {
handleStopPrinterDiscovery();
}
// Destroy the discovery session.
if (mHasPrinterDiscoverySession) {
handleDestroyPrinterDiscoverySession();
}
// Unbind.
ensureUnbound();
// Done
mDestroyed = true;
|
private void | handleDestroyPrinterDiscoverySession()
throwIfDestroyed();
mHasPrinterDiscoverySession = false;
if (!isBound()) {
// The service is dead and neither has active jobs nor discovery
// session, so ensure we are unbound since the service has no work.
if (mServiceDied && !mHasActivePrintJobs) {
ensureUnbound();
return;
}
ensureBound();
mPendingCommands.add(new Runnable() {
@Override
public void run() {
handleDestroyPrinterDiscoverySession();
}
});
} else {
if (DEBUG) {
Slog.i(LOG_TAG, "[user: " + mUserId + "] destroyPrinterDiscoverySession()");
}
try {
mPrintService.destroyPrinterDiscoverySession();
} catch (RemoteException re) {
Slog.e(LOG_TAG, "Error destroying printer dicovery session.", re);
}
// If the service has no print jobs and no active discovery
// session anymore we should disconnect from it.
if (!mHasActivePrintJobs) {
ensureUnbound();
}
}
|
private void | handleOnAllPrintJobsHandled()
throwIfDestroyed();
mHasActivePrintJobs = false;
if (!isBound()) {
// The service is dead and neither has active jobs nor discovery
// session, so ensure we are unbound since the service has no work.
if (mServiceDied && !mHasPrinterDiscoverySession) {
ensureUnbound();
return;
}
ensureBound();
mPendingCommands.add(new Runnable() {
@Override
public void run() {
handleOnAllPrintJobsHandled();
}
});
} else {
if (DEBUG) {
Slog.i(LOG_TAG, "[user: " + mUserId + "] onAllPrintJobsHandled()");
}
// If the service has a printer discovery session
// created we should not disconnect from it just yet.
if (!mHasPrinterDiscoverySession) {
ensureUnbound();
}
}
|
private void | handleOnPrintJobQueued(android.print.PrintJobInfo printJob)
throwIfDestroyed();
mHasActivePrintJobs = true;
if (!isBound()) {
ensureBound();
mPendingCommands.add(new Runnable() {
@Override
public void run() {
handleOnPrintJobQueued(printJob);
}
});
} else {
if (DEBUG) {
Slog.i(LOG_TAG, "[user: " + mUserId + "] onPrintJobQueued()");
}
try {
mPrintService.onPrintJobQueued(printJob);
} catch (RemoteException re) {
Slog.e(LOG_TAG, "Error announcing queued pring job.", re);
}
}
|
private void | handleRequestCancelPrintJob(android.print.PrintJobInfo printJob)
throwIfDestroyed();
if (!isBound()) {
ensureBound();
mPendingCommands.add(new Runnable() {
@Override
public void run() {
handleRequestCancelPrintJob(printJob);
}
});
} else {
if (DEBUG) {
Slog.i(LOG_TAG, "[user: " + mUserId + "] requestCancelPrintJob()");
}
try {
mPrintService.requestCancelPrintJob(printJob);
} catch (RemoteException re) {
Slog.e(LOG_TAG, "Error canceling a pring job.", re);
}
}
|
private void | handleStartPrinterDiscovery(java.util.List priorityList)
throwIfDestroyed();
// Take a note that we are doing discovery.
mDiscoveryPriorityList = new ArrayList<PrinterId>();
if (priorityList != null) {
mDiscoveryPriorityList.addAll(priorityList);
}
if (!isBound()) {
ensureBound();
mPendingCommands.add(new Runnable() {
@Override
public void run() {
handleStartPrinterDiscovery(priorityList);
}
});
} else {
if (DEBUG) {
Slog.i(LOG_TAG, "[user: " + mUserId + "] startPrinterDiscovery()");
}
try {
mPrintService.startPrinterDiscovery(priorityList);
} catch (RemoteException re) {
Slog.e(LOG_TAG, "Error starting printer dicovery.", re);
}
}
|
private void | handleStartPrinterStateTracking(android.print.PrinterId printerId)
throwIfDestroyed();
// Take a note we are tracking the printer.
if (mTrackedPrinterList == null) {
mTrackedPrinterList = new ArrayList<PrinterId>();
}
mTrackedPrinterList.add(printerId);
if (!isBound()) {
ensureBound();
mPendingCommands.add(new Runnable() {
@Override
public void run() {
handleStartPrinterStateTracking(printerId);
}
});
} else {
if (DEBUG) {
Slog.i(LOG_TAG, "[user: " + mUserId + "] startPrinterTracking()");
}
try {
mPrintService.startPrinterStateTracking(printerId);
} catch (RemoteException re) {
Slog.e(LOG_TAG, "Error requesting start printer tracking.", re);
}
}
|
private void | handleStopPrinterDiscovery()
throwIfDestroyed();
// We are not doing discovery anymore.
mDiscoveryPriorityList = null;
if (!isBound()) {
ensureBound();
mPendingCommands.add(new Runnable() {
@Override
public void run() {
handleStopPrinterDiscovery();
}
});
} else {
if (DEBUG) {
Slog.i(LOG_TAG, "[user: " + mUserId + "] stopPrinterDiscovery()");
}
// Stop tracking printers.
stopTrackingAllPrinters();
try {
mPrintService.stopPrinterDiscovery();
} catch (RemoteException re) {
Slog.e(LOG_TAG, "Error stopping printer discovery.", re);
}
}
|
private void | handleStopPrinterStateTracking(android.print.PrinterId printerId)
throwIfDestroyed();
// We are no longer tracking the printer.
if (mTrackedPrinterList == null || !mTrackedPrinterList.remove(printerId)) {
return;
}
if (mTrackedPrinterList.isEmpty()) {
mTrackedPrinterList = null;
}
if (!isBound()) {
ensureBound();
mPendingCommands.add(new Runnable() {
@Override
public void run() {
handleStopPrinterStateTracking(printerId);
}
});
} else {
if (DEBUG) {
Slog.i(LOG_TAG, "[user: " + mUserId + "] stopPrinterTracking()");
}
try {
mPrintService.stopPrinterStateTracking(printerId);
} catch (RemoteException re) {
Slog.e(LOG_TAG, "Error requesting stop printer tracking.", re);
}
}
|
private void | handleValidatePrinters(java.util.List printerIds)
throwIfDestroyed();
if (!isBound()) {
ensureBound();
mPendingCommands.add(new Runnable() {
@Override
public void run() {
handleValidatePrinters(printerIds);
}
});
} else {
if (DEBUG) {
Slog.i(LOG_TAG, "[user: " + mUserId + "] validatePrinters()");
}
try {
mPrintService.validatePrinters(printerIds);
} catch (RemoteException re) {
Slog.e(LOG_TAG, "Error requesting printers validation.", re);
}
}
|
private boolean | isBound()
return mPrintService != null;
|
public void | onAllPrintJobsHandled()
mHandler.sendEmptyMessage(MyHandler.MSG_ON_ALL_PRINT_JOBS_HANDLED);
|
public void | onPrintJobQueued(android.print.PrintJobInfo printJob)
mHandler.obtainMessage(MyHandler.MSG_ON_PRINT_JOB_QUEUED,
printJob).sendToTarget();
|
public void | onRequestCancelPrintJob(android.print.PrintJobInfo printJob)
mHandler.obtainMessage(MyHandler.MSG_ON_REQUEST_CANCEL_PRINT_JOB,
printJob).sendToTarget();
|
public void | startPrinterDiscovery(java.util.List priorityList)
mHandler.obtainMessage(MyHandler.MSG_START_PRINTER_DISCOVERY,
priorityList).sendToTarget();
|
public void | startPrinterStateTracking(android.print.PrinterId printerId)
mHandler.obtainMessage(MyHandler.MSG_START_PRINTER_STATE_TRACKING,
printerId).sendToTarget();
|
public void | stopPrinterDiscovery()
mHandler.sendEmptyMessage(MyHandler.MSG_STOP_PRINTER_DISCOVERY);
|
public void | stopPrinterStateTracking(android.print.PrinterId printerId)
mHandler.obtainMessage(MyHandler.MSG_STOP_PRINTER_STATE_TRACKING,
printerId).sendToTarget();
|
private void | stopTrackingAllPrinters()
if (mTrackedPrinterList == null) {
return;
}
final int trackedPrinterCount = mTrackedPrinterList.size();
for (int i = trackedPrinterCount - 1; i >= 0; i--) {
PrinterId printerId = mTrackedPrinterList.get(i);
if (printerId.getServiceName().equals(mComponentName)) {
handleStopPrinterStateTracking(printerId);
}
}
|
private void | throwIfDestroyed()
if (mDestroyed) {
throw new IllegalStateException("Cannot interact with a destroyed service");
}
|
public void | validatePrinters(java.util.List printerIds)
mHandler.obtainMessage(MyHandler.MSG_VALIDATE_PRINTERS,
printerIds).sendToTarget();
|