Loading packages/PrintSpooler/jni/com_android_printspooler_util_BitmapSerializeUtils.cpp +9 −2 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; } Loading packages/PrintSpooler/res/drawable/print_warning.xml 0 → 100644 +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> packages/PrintSpooler/res/layout/preview_page_error.xml 0 → 100644 +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> packages/PrintSpooler/res/values/strings.xml +4 −0 Original line number Diff line number Diff line Loading @@ -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] --> Loading packages/PrintSpooler/src/com/android/printspooler/model/PageContentRepository.java +28 −21 Original line number Diff line number Diff line Loading @@ -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) { Loading Loading @@ -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) { Loading Loading @@ -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; Loading @@ -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 Loading
packages/PrintSpooler/jni/com_android_printspooler_util_BitmapSerializeUtils.cpp +9 −2 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; } Loading
packages/PrintSpooler/res/drawable/print_warning.xml 0 → 100644 +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>
packages/PrintSpooler/res/layout/preview_page_error.xml 0 → 100644 +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>
packages/PrintSpooler/res/values/strings.xml +4 −0 Original line number Diff line number Diff line Loading @@ -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] --> Loading
packages/PrintSpooler/src/com/android/printspooler/model/PageContentRepository.java +28 −21 Original line number Diff line number Diff line Loading @@ -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) { Loading Loading @@ -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) { Loading Loading @@ -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; Loading @@ -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