diff options
| author | 2016-04-29 15:40:23 -0700 | |
|---|---|---|
| committer | 2016-04-29 15:40:23 -0700 | |
| commit | 172d840cd133969a5d6c9e9657927ffdbcd44093 (patch) | |
| tree | 3d34aec2e0150db380803de492dc5ef7cac7c805 | |
| parent | a5d3e91cefe3dff8ffe85fa10cc1f65be9693500 (diff) | |
Handle more config changes and handle onDestroy
- The PrintActivity has to handle all config changes to not loose track
close the connection to the printing app
- In the case where onDestroy is called we need to make sure to
- not do any more UI operation
- on async calls after destroy is already called, handle failure to
unbind services.
Change-Id: If21335543fbfa16ecfe77d1965b2e8a13dfa14b8
3 files changed, 28 insertions, 9 deletions
diff --git a/packages/PrintSpooler/AndroidManifest.xml b/packages/PrintSpooler/AndroidManifest.xml index ed6fdb7ce4d8..2da4d6a25dd3 100644 --- a/packages/PrintSpooler/AndroidManifest.xml +++ b/packages/PrintSpooler/AndroidManifest.xml @@ -57,7 +57,7 @@ <activity android:name=".ui.PrintActivity" - android:configChanges="screenSize|smallestScreenSize|orientation|locale|keyboard|keyboardHidden|fontScale|uiMode|layoutDirection" + android:configChanges="mnc|mnc|touchscreen|navigation|screenLayout|screenSize|smallestScreenSize|orientation|locale|keyboard|keyboardHidden|fontScale|uiMode|layoutDirection|density" android:permission="android.permission.BIND_PRINT_SPOOLER_SERVICE" android:theme="@style/Theme.PrintActivity"> <intent-filter> diff --git a/packages/PrintSpooler/src/com/android/printspooler/model/PageContentRepository.java b/packages/PrintSpooler/src/com/android/printspooler/model/PageContentRepository.java index bb359176bdf1..999d82d592ea 100644 --- a/packages/PrintSpooler/src/com/android/printspooler/model/PageContentRepository.java +++ b/packages/PrintSpooler/src/com/android/printspooler/model/PageContentRepository.java @@ -510,7 +510,12 @@ public final class PageContentRepository { public void destroy() { if (mBoundToService) { mBoundToService = false; - mContext.unbindService(AsyncRenderer.this); + try { + mContext.unbindService(AsyncRenderer.this); + } catch (IllegalArgumentException e) { + // Service might have been forcefully unbound in onDestroy() + Log.e(LOG_TAG, "Cannot unbind service", e); + } } mPageContentCache.invalidate(); diff --git a/packages/PrintSpooler/src/com/android/printspooler/ui/PrintActivity.java b/packages/PrintSpooler/src/com/android/printspooler/ui/PrintActivity.java index c4111864ba2d..1c26f1285852 100644 --- a/packages/PrintSpooler/src/com/android/printspooler/ui/PrintActivity.java +++ b/packages/PrintSpooler/src/com/android/printspooler/ui/PrintActivity.java @@ -268,7 +268,7 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat new Runnable() { @Override public void run() { - if (isFinishing()) { + if (isFinishing() || isDestroyed()) { // onPause might have not been able to cancel the job, see PrintActivity#onPause // To be sure, cancel the job again. Double canceling does no harm. mSpoolerProvider.getSpooler().setPrintJobState(mPrintJob.getId(), @@ -324,7 +324,8 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat // If we are finishing or we are in a state that we do not need any // data from the printing app, then no need to finish. - if (isFinishing() || (isFinalState(mState) && !mPrintedDocument.isUpdating())) { + if (isFinishing() || isDestroyed() || + (isFinalState(mState) && !mPrintedDocument.isUpdating())) { return; } setState(STATE_PRINT_CANCELED); @@ -622,6 +623,17 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat } @Override + protected void onDestroy() { + if (mPrintedDocument != null) { + mPrintedDocument.cancel(true); + } + + doFinish(); + + super.onDestroy(); + } + + @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case ACTIVITY_REQUEST_CREATE_FILE: { @@ -964,7 +976,7 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat } private void ensureProgressUiShown() { - if (isFinishing()) { + if (isFinishing() || isDestroyed()) { return; } if (mUiState != UI_STATE_PROGRESS) { @@ -976,7 +988,7 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat } private void ensurePreviewUiShown() { - if (isFinishing()) { + if (isFinishing() || isDestroyed()) { return; } if (mUiState != UI_STATE_PREVIEW) { @@ -987,7 +999,7 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat } private void ensureErrorUiShown(CharSequence message, int action) { - if (isFinishing()) { + if (isFinishing() || isDestroyed()) { return; } if (mUiState != UI_STATE_ERROR) { @@ -1353,7 +1365,7 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat @Override public void onLoaderReset(Loader<List<PrintServiceInfo>> loader) { - if (!isFinishing()) { + if (!(isFinishing() || isDestroyed())) { onLoadFinished(loader, null); } } @@ -2036,7 +2048,9 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat mSpoolerProvider.destroy(); } - setState(mProgressMessageController.cancel()); + if (mProgressMessageController != null) { + setState(mProgressMessageController.cancel()); + } if (mState != STATE_INITIALIZING) { mPrintedDocument.finish(); |