Merge "Ignore historical printer records for installed services" into klp-dev
This commit is contained in:
@@ -45,6 +45,7 @@ interface IPrintManager {
|
||||
void removePrintJobStateChangeListener(in IPrintJobStateChangeListener listener,
|
||||
int userId);
|
||||
|
||||
List<PrintServiceInfo> getInstalledPrintServices(int userId);
|
||||
List<PrintServiceInfo> getEnabledPrintServices(int userId);
|
||||
|
||||
void createPrinterDiscoverySession(in IPrinterDiscoveryObserver observer, int userId);
|
||||
|
||||
@@ -289,7 +289,26 @@ public final class PrintManager {
|
||||
return enabledServices;
|
||||
}
|
||||
} catch (RemoteException re) {
|
||||
Log.e(LOG_TAG, "Error getting the enalbed print services", re);
|
||||
Log.e(LOG_TAG, "Error getting the enabled print services", re);
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the list of installed print services.
|
||||
*
|
||||
* @return The installed service list or an empty list.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public List<PrintServiceInfo> getInstalledPrintServices() {
|
||||
try {
|
||||
List<PrintServiceInfo> installedServices = mService.getInstalledPrintServices(mUserId);
|
||||
if (installedServices != null) {
|
||||
return installedServices;
|
||||
}
|
||||
} catch (RemoteException re) {
|
||||
Log.e(LOG_TAG, "Error getting the installed print services", re);
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@@ -19,13 +19,16 @@ package com.android.printspooler;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Loader;
|
||||
import android.content.pm.ServiceInfo;
|
||||
import android.os.AsyncTask;
|
||||
import android.print.PrintManager;
|
||||
import android.print.PrinterDiscoverySession;
|
||||
import android.print.PrinterDiscoverySession.OnPrintersChangeListener;
|
||||
import android.print.PrinterId;
|
||||
import android.print.PrinterInfo;
|
||||
import android.printservice.PrintServiceInfo;
|
||||
import android.util.ArrayMap;
|
||||
import android.util.ArraySet;
|
||||
import android.util.AtomicFile;
|
||||
import android.util.Log;
|
||||
import android.util.Slog;
|
||||
@@ -46,6 +49,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import libcore.io.IoUtils;
|
||||
|
||||
@@ -384,6 +388,30 @@ public class FusedPrintersProvider extends Loader<List<PrinterInfo>> {
|
||||
+ FusedPrintersProvider.this.hashCode());
|
||||
}
|
||||
|
||||
// Ignore printer records whose target services are not installed.
|
||||
PrintManager printManager = (PrintManager) getContext()
|
||||
.getSystemService(Context.PRINT_SERVICE);
|
||||
List<PrintServiceInfo> services = printManager
|
||||
.getInstalledPrintServices();
|
||||
|
||||
Set<ComponentName> installedComponents = new ArraySet<ComponentName>();
|
||||
final int installedServiceCount = services.size();
|
||||
for (int i = 0; i < installedServiceCount; i++) {
|
||||
ServiceInfo serviceInfo = services.get(i).getResolveInfo().serviceInfo;
|
||||
ComponentName componentName = new ComponentName(
|
||||
serviceInfo.packageName, serviceInfo.name);
|
||||
installedComponents.add(componentName);
|
||||
}
|
||||
|
||||
final int printerCount = printers.size();
|
||||
for (int i = printerCount - 1; i >= 0; i--) {
|
||||
ComponentName printerServiceName = printers.get(i).getId().getServiceName();
|
||||
if (!installedComponents.contains(printerServiceName.getPackageName())) {
|
||||
printers.remove(i);
|
||||
}
|
||||
}
|
||||
|
||||
// Store the filtered list.
|
||||
mHistoricalPrinters = printers;
|
||||
|
||||
// Compute the favorite printers.
|
||||
|
||||
@@ -193,6 +193,21 @@ public final class PrintManagerService extends IPrintManager.Stub {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PrintServiceInfo> getInstalledPrintServices(int userId) {
|
||||
final int resolvedUserId = resolveCallingUserEnforcingPermissions(userId);
|
||||
final UserState userState;
|
||||
synchronized (mLock) {
|
||||
userState = getOrCreateUserStateLocked(resolvedUserId);
|
||||
}
|
||||
final long identity = Binder.clearCallingIdentity();
|
||||
try {
|
||||
return userState.getInstalledPrintServices();
|
||||
} finally {
|
||||
Binder.restoreCallingIdentity(identity);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createPrinterDiscoverySession(IPrinterDiscoveryObserver observer,
|
||||
int userId) {
|
||||
|
||||
@@ -205,10 +205,12 @@ final class UserState implements PrintSpoolerCallbacks, PrintServiceCallbacks {
|
||||
// Add everything else the spooler knows about.
|
||||
List<PrintJobInfo> printJobs = mSpooler.getPrintJobInfos(null,
|
||||
PrintJobInfo.STATE_ANY, appId);
|
||||
final int printJobCount = printJobs.size();
|
||||
for (int i = 0; i < printJobCount; i++) {
|
||||
PrintJobInfo printJob = printJobs.get(i);
|
||||
result.put(printJob.getId(), printJob);
|
||||
if (printJobs != null) {
|
||||
final int printJobCount = printJobs.size();
|
||||
for (int i = 0; i < printJobCount; i++) {
|
||||
PrintJobInfo printJob = printJobs.get(i);
|
||||
result.put(printJob.getId(), printJob);
|
||||
}
|
||||
}
|
||||
|
||||
return new ArrayList<PrintJobInfo>(result.values());
|
||||
@@ -272,6 +274,12 @@ final class UserState implements PrintSpoolerCallbacks, PrintServiceCallbacks {
|
||||
}
|
||||
}
|
||||
|
||||
public List<PrintServiceInfo> getInstalledPrintServices() {
|
||||
synchronized (mLock) {
|
||||
return mInstalledServices;
|
||||
}
|
||||
}
|
||||
|
||||
public void createPrinterDiscoverySession(IPrinterDiscoveryObserver observer) {
|
||||
synchronized (mLock) {
|
||||
throwIfDestroyedLocked();
|
||||
|
||||
Reference in New Issue
Block a user