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

Commit 49435a72 authored by Philip P. Moltmann's avatar Philip P. Moltmann Committed by Android (Google) Code Review
Browse files

Merge "Deal with print-preview renderings that do not match the correct number...

Merge "Deal with print-preview renderings that do not match the correct number of pages." into nyc-dev
parents 8aa976b6 066bf81b
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
@@ -50,6 +50,10 @@ static bool readAllBytes(const int fd, void* buffer, const size_t byteCount) {
    size_t remainingBytes = byteCount;
    while (remainingBytes > 0) {
        ssize_t readByteCount = read(fd, readBuffer, remainingBytes);

        remainingBytes -= readByteCount;
        readBuffer += readByteCount;

        if (readByteCount == -1) {
            if (errno == EINTR) {
                continue;
@@ -57,9 +61,12 @@ static bool readAllBytes(const int fd, void* buffer, const size_t byteCount) {
            __android_log_print(ANDROID_LOG_ERROR, LOG_TAG,
                    "Error reading from buffer: %d", errno);
            return false;
        } else if (readByteCount == 0 && remainingBytes > 0) {
            __android_log_print(ANDROID_LOG_ERROR, LOG_TAG,
                    "File closed before all bytes were read. %zu/%zu remaining", remainingBytes,
                    byteCount);
            return false;
        }
        remainingBytes -= readByteCount;
        readBuffer += readByteCount;
    }
    return true;
}
+25 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2016 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->

<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="96dp"
        android:height="96dp"
        android:viewportWidth="96.0"
        android:viewportHeight="96.0">
    <path
        android:fillColor="#C8CCCE"
        android:pathData="M4,84H92L48,8 4,84zM52,72h-8v-8h8v8zM52,56H44V40h8v16z"/>
</vector>
+39 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2016 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        android:gravity="center">

    <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="12dip"
            android:src="@drawable/print_warning"
            android:contentDescription="@null" />

    <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="16dip"
            android:layout_marginEnd="16dip"
            android:gravity="center_horizontal"
            android:textColor="@android:color/black"
            android:text="@string/print_cannot_load_page" />

</LinearLayout>
+4 −0
Original line number Diff line number Diff line
@@ -288,6 +288,10 @@
    <!-- Message for the currently selected printer being unavailable. [CHAR LIMIT=100] -->
    <string name="print_error_printer_unavailable">This printer isn\'t available right now.</string>

    <!-- Message for the case when a preview of a page cannot be loaded because the printing app
         provided a broken print preview rendering for this page. [CHAR LIMIT=50] -->
    <string name="print_cannot_load_page">Can\'t display preview</string>

    <!-- Long running operations -->

    <!-- Message long running operation when preparing print preview. [CHAR LIMIT=50] -->
+28 −21
Original line number Diff line number Diff line
@@ -75,7 +75,7 @@ public final class PageContentRepository {
    private int mState;

    public interface OnPageContentAvailableCallback {
        public void onPageContentAvailable(BitmapDrawable content);
        void onPageContentAvailable(BitmapDrawable content);
    }

    public PageContentRepository(Context context) {
@@ -741,6 +741,7 @@ public final class PageContentRepository {
            final RenderSpec mRenderSpec;
            OnPageContentAvailableCallback mCallback;
            RenderedPage mRenderedPage;
            private boolean mIsFailed;

            public RenderPageTask(int pageIndex, RenderSpec renderSpec,
                    OnPageContentAvailableCallback callback) {
@@ -826,25 +827,24 @@ public final class PageContentRepository {

                Bitmap bitmap = mRenderedPage.content.getBitmap();

                ParcelFileDescriptor[] pipe = null;
                ParcelFileDescriptor[] pipe;
                try {
                    pipe = ParcelFileDescriptor.createPipe();
                    ParcelFileDescriptor source = pipe[0];
                    ParcelFileDescriptor destination = pipe[1];

                    try (ParcelFileDescriptor source = pipe[0]) {
                        try (ParcelFileDescriptor destination = pipe[1]) {

                            mRenderer.renderPage(mPageIndex, bitmap.getWidth(), bitmap.getHeight(),
                                    mRenderSpec.printAttributes, destination);

                    // We passed the file descriptor to the other side which took
                    // ownership, so close our copy for the write to complete.
                    destination.close();
                        }

                        BitmapSerializeUtils.readBitmapPixels(bitmap, source);
                } catch (IOException|RemoteException e) {
                    Log.e(LOG_TAG, "Error rendering page:" + mPageIndex, e);
                } finally {
                    IoUtils.closeQuietly(pipe[0]);
                    IoUtils.closeQuietly(pipe[1]);
                    }

                    mIsFailed = false;
                } catch (IOException|RemoteException|IllegalStateException e) {
                    Log.e(LOG_TAG, "Error rendering page " + mPageIndex, e);
                    mIsFailed = true;
                }

                return mRenderedPage;
@@ -859,17 +859,24 @@ public final class PageContentRepository {
                // This task is done.
                mPageToRenderTaskMap.remove(mPageIndex);

                // Take a note that the content is rendered.
                if (mIsFailed) {
                    renderedPage.state = RenderedPage.STATE_SCRAP;
                } else {
                    renderedPage.state = RenderedPage.STATE_RENDERED;
                }

                // Invalidate all caches of the old state of the bitmap
                mRenderedPage.content.invalidateSelf();

                // Announce success if needed.
                if (mCallback != null) {
                    if (mIsFailed) {
                        mCallback.onPageContentAvailable(null);
                    } else {
                        mCallback.onPageContentAvailable(renderedPage.content);
                    }
                }
            }

            @Override
            protected void onCancelled(RenderedPage renderedPage) {
Loading