Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 860f8a6b authored by Svetoslav Ganov's avatar Svetoslav Ganov
Browse files

Spooler should not crash if print service config activities are not exported.

1. If a print service does not export its activities for settings and
   adding printers the print spooler ignores them instead of crashing.
   Also if the service is not enabled its activities are now ignored.

2. Added a dedicated permission for a print service to optionally
   protect its settings and add printer activities such that only the
   system can bind to them.

3. Fixed a crash in the print dialog if its content is detached
   from the window and animators are running.

bug:10680224

Change-Id: I20b57d6622a15f9b2352ba78d04c44e67b316a15
parent c8db445e
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.print.IPrintClient;
import android.print.PrinterId;
import android.print.PrintJobInfo;
import android.print.PrintAttributes;
import android.printservice.PrintServiceInfo;

/**
 * Interface for communication with the core print manager service.
@@ -37,6 +38,8 @@ interface IPrintManager {
    void cancelPrintJob(int printJobId, int appId, int userId);
    void restartPrintJob(int printJobId, int appId, int userId);

    List<PrintServiceInfo> getEnabledPrintServices(int userId);

    void createPrinterDiscoverySession(in IPrinterDiscoveryObserver observer, int userId);
    void startPrinterDiscovery(in IPrinterDiscoveryObserver observer,
            in List<PrinterId> priorityList, int userId);
+20 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.os.ParcelFileDescriptor;
import android.os.RemoteException;
import android.print.PrintDocumentAdapter.LayoutResultCallback;
import android.print.PrintDocumentAdapter.WriteResultCallback;
import android.printservice.PrintServiceInfo;
import android.text.TextUtils;
import android.util.Log;

@@ -203,6 +204,25 @@ public final class PrintManager {
        return null;
    }

    /**
     * Gets the list of enabled print services.
     *
     * @return The enabled service list or an empty list.
     *
     * @hide
     */
    public List<PrintServiceInfo> getEnabledPrintServices() {
        try {
            List<PrintServiceInfo> enabledServices = mService.getEnabledPrintServices(mUserId);
            if (enabledServices != null) {
                return enabledServices;
            }
        } catch (RemoteException re) {
            Log.e(LOG_TAG, "Error getting the enalbed print services", re);
        }
        return Collections.emptyList();
    }

    /**
     * @hide
     */
+8 −0
Original line number Diff line number Diff line
@@ -178,6 +178,14 @@ public abstract class PrintService extends Service {
     * For detailed configuration options that can be specified via the meta-data
     * refer to {@link android.R.styleable#PrintService android.R.styleable.PrintService}.
     * </p>
     * <p>
     * If you declare a settings or add a printers activity, they have to be exported,
     * by setting the {@link android.R.attr#exported} activity attribute to <code>true
     * </code>. Also in case you want only the system to be able to start any of these
     * activities you can specify that they request the android.permission
     * .START_PRINT_SERVICE_CONFIG_ACTIVITY permission by setting the
     * {@link android.R.attr#permission} activity attribute.
     * </p>
     */
    public static final String SERVICE_META_DATA = "android.printservice";

+10 −3
Original line number Diff line number Diff line
@@ -22,17 +22,24 @@
        android:versionCode="1">

    <!-- Allows an application to call APIs that give it access to all print jobs
         on the device. Usually an app can access only the print jobs it created.
    -->
         on the device. Usually an app can access only the print jobs it created. -->
    <permission
        android:name="com.android.printspooler.permission.ACCESS_ALL_PRINT_JOBS"
        android:label="@string/permlab_accessAllPrintJobs"
        android:description="@string/permdesc_accessAllPrintJobs"
        android:protectionLevel="signature" />

    <!-- May be required by the settings and add printer activities of a
         print service if the developer wants only trusted system code to
         be able to launch these activities. -->
    <permission android:name="android.permission.START_PRINT_SERVICE_CONFIG_ACTIVITY"
        android:label="@string/permlab_startPrintServiceConfigActivity"
        android:description="@string/permdesc_startPrintServiceConfigActivity"
        android:protectionLevel="signature" />

    <uses-permission android:name="com.android.printspooler.permission.ACCESS_ALL_PRINT_JOBS"/>
    <uses-permission android:name="android.permission.ACCESS_ALL_PRINT_JOBS"/>
    <uses-permission android:name="android.permission.WAKE_LOCK"/>
    <uses-permission android:name="android.permission.START_PRINT_SERVICE_CONFIG_ACTIVITY"/>

    <uses-sdk android:minSdkVersion="18" android:targetSdkVersion="18"/>

+8 −0
Original line number Diff line number Diff line
@@ -145,4 +145,12 @@
    <string name="permdesc_accessAllPrintJobs">Allows the holder to access print jobs
        created by another app. Should never be needed for normal apps.</string>

    <!-- Title of an application permission, listed so the user can choose whether they want
         to allow the application to do this. -->
    <string name="permlab_startPrintServiceConfigActivity">start print service configuration activities</string>
    <!-- Description of an application permission, listed so the user can choose whether they
         want to allow the application to do this. -->
    <string name="permdesc_startPrintServiceConfigActivity">Allows the holder to start the
        configuration activities of a print service. Should never be needed for normal apps.</string>

</resources>
Loading