use of android.printservice.PrintServiceInfo in project android_frameworks_base by AOSPA.
the class PrintActivity method onLoadFinished.
@Override
public void onLoadFinished(Loader<List<PrintServiceInfo>> loader, List<PrintServiceInfo> services) {
ComponentName newAdvancedPrintOptionsActivity = null;
if (mCurrentPrinter != null && services != null) {
final int numServices = services.size();
for (int i = 0; i < numServices; i++) {
PrintServiceInfo service = services.get(i);
if (service.getComponentName().equals(mCurrentPrinter.getId().getServiceName())) {
String advancedOptionsActivityName = service.getAdvancedOptionsActivityName();
if (!TextUtils.isEmpty(advancedOptionsActivityName)) {
newAdvancedPrintOptionsActivity = new ComponentName(service.getComponentName().getPackageName(), advancedOptionsActivityName);
break;
}
}
}
}
if (!Objects.equals(newAdvancedPrintOptionsActivity, mAdvancedPrintOptionsActivity)) {
mAdvancedPrintOptionsActivity = newAdvancedPrintOptionsActivity;
updateOptionsUi();
}
boolean newArePrintServicesEnabled = services != null && !services.isEmpty();
if (mArePrintServicesEnabled != newArePrintServicesEnabled) {
mArePrintServicesEnabled = newArePrintServicesEnabled;
// reads that in DestinationAdapter#getMoreItemTitle
if (mDestinationSpinnerAdapter != null) {
mDestinationSpinnerAdapter.notifyDataSetChanged();
}
}
}
use of android.printservice.PrintServiceInfo in project android_frameworks_base by ResurrectionRemix.
the class SelectPrinterActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getActionBar().setIcon(R.drawable.ic_print);
setContentView(R.layout.select_printer_activity);
mEnabledPrintServices = new ArrayMap<>();
mPrinterRegistry = new PrinterRegistry(this, null, LOADER_ID_PRINT_REGISTRY, LOADER_ID_PRINT_REGISTRY_INT);
// Hook up the list view.
mListView = (ListView) findViewById(android.R.id.list);
final DestinationAdapter adapter = new DestinationAdapter();
adapter.registerDataSetObserver(new DataSetObserver() {
@Override
public void onChanged() {
if (!isFinishing() && adapter.getCount() <= 0) {
updateEmptyView(adapter);
}
}
@Override
public void onInvalidated() {
if (!isFinishing()) {
updateEmptyView(adapter);
}
}
});
mListView.setAdapter(adapter);
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (!((DestinationAdapter) mListView.getAdapter()).isActionable(position)) {
return;
}
PrinterInfo printer = (PrinterInfo) mListView.getAdapter().getItem(position);
if (printer == null) {
startAddPrinterActivity();
} else {
onPrinterSelected(printer);
}
}
});
findViewById(R.id.button).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
startAddPrinterActivity();
}
});
registerForContextMenu(mListView);
getLoaderManager().initLoader(LOADER_ID_ENABLED_PRINT_SERVICES, null, this);
// If some are disabled and some are enabled show a toast to notify the user
if (savedInstanceState == null || !savedInstanceState.getBoolean(KEY_NOT_FIRST_CREATE)) {
List<PrintServiceInfo> allServices = ((PrintManager) getSystemService(Context.PRINT_SERVICE)).getPrintServices(PrintManager.ALL_SERVICES);
boolean hasEnabledServices = false;
boolean hasDisabledServices = false;
if (allServices != null) {
final int numServices = allServices.size();
for (int i = 0; i < numServices; i++) {
if (allServices.get(i).isEnabled()) {
hasEnabledServices = true;
} else {
hasDisabledServices = true;
}
}
}
if (!hasEnabledServices) {
startAddPrinterActivity();
} else if (hasDisabledServices) {
String disabledServicesSetting = Settings.Secure.getString(getContentResolver(), Settings.Secure.DISABLED_PRINT_SERVICES);
if (!TextUtils.isEmpty(disabledServicesSetting)) {
Toast.makeText(this, getString(R.string.print_services_disabled_toast), Toast.LENGTH_LONG).show();
}
}
}
}
use of android.printservice.PrintServiceInfo in project android_frameworks_base by ResurrectionRemix.
the class UserState method dump.
public void dump(@NonNull FileDescriptor fd, @NonNull PrintWriter pw, @NonNull String prefix) {
pw.append(prefix).append("user state ").append(String.valueOf(mUserId)).append(":");
pw.println();
String tab = " ";
pw.append(prefix).append(tab).append("installed services:").println();
final int installedServiceCount = mInstalledServices.size();
for (int i = 0; i < installedServiceCount; i++) {
PrintServiceInfo installedService = mInstalledServices.get(i);
String installedServicePrefix = prefix + tab + tab;
pw.append(installedServicePrefix).append("service:").println();
ResolveInfo resolveInfo = installedService.getResolveInfo();
ComponentName componentName = new ComponentName(resolveInfo.serviceInfo.packageName, resolveInfo.serviceInfo.name);
pw.append(installedServicePrefix).append(tab).append("componentName=").append(componentName.flattenToString()).println();
pw.append(installedServicePrefix).append(tab).append("settingsActivity=").append(installedService.getSettingsActivityName()).println();
pw.append(installedServicePrefix).append(tab).append("addPrintersActivity=").append(installedService.getAddPrintersActivityName()).println();
pw.append(installedServicePrefix).append(tab).append("avancedOptionsActivity=").append(installedService.getAdvancedOptionsActivityName()).println();
}
pw.append(prefix).append(tab).append("disabled services:").println();
for (ComponentName disabledService : mDisabledServices) {
String disabledServicePrefix = prefix + tab + tab;
pw.append(disabledServicePrefix).append("service:").println();
pw.append(disabledServicePrefix).append(tab).append("componentName=").append(disabledService.flattenToString());
pw.println();
}
pw.append(prefix).append(tab).append("active services:").println();
final int activeServiceCount = mActiveServices.size();
for (int i = 0; i < activeServiceCount; i++) {
RemotePrintService activeService = mActiveServices.valueAt(i);
activeService.dump(pw, prefix + tab + tab);
pw.println();
}
pw.append(prefix).append(tab).append("cached print jobs:").println();
mPrintJobForAppCache.dump(pw, prefix + tab + tab);
pw.append(prefix).append(tab).append("discovery mediator:").println();
if (mPrinterDiscoverySession != null) {
mPrinterDiscoverySession.dump(pw, prefix + tab + tab);
}
pw.append(prefix).append(tab).append("print spooler:").println();
mSpooler.dump(fd, pw, prefix + tab + tab);
pw.println();
}
use of android.printservice.PrintServiceInfo in project android_frameworks_base by ResurrectionRemix.
the class UserState method readInstalledPrintServicesLocked.
private void readInstalledPrintServicesLocked() {
Set<PrintServiceInfo> tempPrintServices = new HashSet<PrintServiceInfo>();
List<ResolveInfo> installedServices = mContext.getPackageManager().queryIntentServicesAsUser(mQueryIntent, GET_SERVICES | GET_META_DATA | MATCH_DEBUG_TRIAGED_MISSING, mUserId);
final int installedCount = installedServices.size();
for (int i = 0, count = installedCount; i < count; i++) {
ResolveInfo installedService = installedServices.get(i);
if (!android.Manifest.permission.BIND_PRINT_SERVICE.equals(installedService.serviceInfo.permission)) {
ComponentName serviceName = new ComponentName(installedService.serviceInfo.packageName, installedService.serviceInfo.name);
Slog.w(LOG_TAG, "Skipping print service " + serviceName.flattenToShortString() + " since it does not require permission " + android.Manifest.permission.BIND_PRINT_SERVICE);
continue;
}
tempPrintServices.add(PrintServiceInfo.create(installedService, mContext));
}
mInstalledServices.clear();
mInstalledServices.addAll(tempPrintServices);
}
use of android.printservice.PrintServiceInfo in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class PrintServiceSettingsFragment method onLoadFinished.
@Override
public void onLoadFinished(Loader<List<PrintServiceInfo>> loader, List<PrintServiceInfo> services) {
PrintServiceInfo service = null;
if (services != null) {
final int numServices = services.size();
for (int i = 0; i < numServices; i++) {
if (services.get(i).getComponentName().equals(mComponentName)) {
service = services.get(i);
break;
}
}
}
if (service == null) {
// The print service was uninstalled
finishFragment();
}
mServiceEnabled = service.isEnabled();
if (service.getSettingsActivityName() != null) {
Intent settingsIntent = new Intent(Intent.ACTION_MAIN);
settingsIntent.setComponent(new ComponentName(service.getComponentName().getPackageName(), service.getSettingsActivityName()));
List<ResolveInfo> resolvedActivities = getPackageManager().queryIntentActivities(settingsIntent, 0);
if (!resolvedActivities.isEmpty()) {
// The activity is a component name, therefore it is one or none.
if (resolvedActivities.get(0).activityInfo.exported) {
mSettingsIntent = settingsIntent;
}
}
} else {
mSettingsIntent = null;
}
if (service.getAddPrintersActivityName() != null) {
Intent addPrintersIntent = new Intent(Intent.ACTION_MAIN);
addPrintersIntent.setComponent(new ComponentName(service.getComponentName().getPackageName(), service.getAddPrintersActivityName()));
List<ResolveInfo> resolvedActivities = getPackageManager().queryIntentActivities(addPrintersIntent, 0);
if (!resolvedActivities.isEmpty()) {
// The activity is a component name, therefore it is one or none.
if (resolvedActivities.get(0).activityInfo.exported) {
mAddPrintersIntent = addPrintersIntent;
}
}
} else {
mAddPrintersIntent = null;
}
updateUiForServiceState();
}
Aggregations