diff options
author | android-build-team Robot <android-build-team-robot@google.com> | 2018-03-04 08:26:54 +0000 |
---|---|---|
committer | android-build-team Robot <android-build-team-robot@google.com> | 2018-03-04 08:26:54 +0000 |
commit | 41c959836bff7df86fc9af4e14d7cddc29707c7c (patch) | |
tree | 5504d798b55fb8f18542da531867dd9b27185b5e | |
parent | 77e0c4c7e8510bafc9716b11f3bdec9aaae3b49c (diff) | |
parent | bf0415d6a8f5f4c11da6c71b49753c26629e47f7 (diff) | |
download | setupwizard-41c959836bff7df86fc9af4e14d7cddc29707c7c.tar.gz |
Snap for 4632767 from bf0415d6a8f5f4c11da6c71b49753c26629e47f7 to pi-release
Change-Id: Icea18ba1ae6e70e737f56915b8ad69069e030b47
3 files changed, 85 insertions, 9 deletions
diff --git a/library/main/src/com/android/setupwizardlib/view/IllustrationVideoView.java b/library/main/src/com/android/setupwizardlib/view/IllustrationVideoView.java index 9c79eb5..e5c2fb1 100644 --- a/library/main/src/com/android/setupwizardlib/view/IllustrationVideoView.java +++ b/library/main/src/com/android/setupwizardlib/view/IllustrationVideoView.java @@ -23,9 +23,11 @@ import android.graphics.SurfaceTexture; import android.graphics.drawable.Animatable; import android.media.MediaPlayer; import android.os.Build.VERSION_CODES; +import android.support.annotation.Nullable; import android.support.annotation.RawRes; import android.support.annotation.VisibleForTesting; import android.util.AttributeSet; +import android.util.Log; import android.view.Surface; import android.view.TextureView; import android.view.View; @@ -51,8 +53,11 @@ public class IllustrationVideoView extends TextureView implements Animatable, MediaPlayer.OnSeekCompleteListener, MediaPlayer.OnInfoListener { + private static final String TAG = "IllustrationVideoView"; + protected float mAspectRatio = 1.0f; // initial guess until we know + @Nullable // Can be null when media player fails to initialize protected MediaPlayer mMediaPlayer; private @RawRes int mVideoResId = 0; @@ -129,15 +134,20 @@ public class IllustrationVideoView extends TextureView implements Animatable, mMediaPlayer = MediaPlayer.create(getContext(), mVideoResId); - mMediaPlayer.setSurface(mSurface); - mMediaPlayer.setOnPreparedListener(this); - mMediaPlayer.setOnSeekCompleteListener(this); - mMediaPlayer.setOnInfoListener(this); - - float aspectRatio = (float) mMediaPlayer.getVideoHeight() / mMediaPlayer.getVideoWidth(); - if (mAspectRatio != aspectRatio) { - mAspectRatio = aspectRatio; - requestLayout(); + if (mMediaPlayer != null) { + mMediaPlayer.setSurface(mSurface); + mMediaPlayer.setOnPreparedListener(this); + mMediaPlayer.setOnSeekCompleteListener(this); + mMediaPlayer.setOnInfoListener(this); + + float aspectRatio = + (float) mMediaPlayer.getVideoHeight() / mMediaPlayer.getVideoWidth(); + if (mAspectRatio != aspectRatio) { + mAspectRatio = aspectRatio; + requestLayout(); + } + } else { + Log.wtf(TAG, "Unable to initialize media player for video view"); } if (getWindowVisibility() == View.VISIBLE) { start(); diff --git a/library/test/robotest/src/com/android/setupwizardlib/shadow/ShadowLog.java b/library/test/robotest/src/com/android/setupwizardlib/shadow/ShadowLog.java new file mode 100644 index 0000000..f1d37c8 --- /dev/null +++ b/library/test/robotest/src/com/android/setupwizardlib/shadow/ShadowLog.java @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2018 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. + */ + +package com.android.setupwizardlib.shadow; + +import android.util.Log; + +import org.robolectric.annotation.Implementation; +import org.robolectric.annotation.Implements; + +@Implements(Log.class) +public class ShadowLog extends org.robolectric.shadows.ShadowLog { + + public static boolean sWtfIsFatal = true; + + public static class TerribleFailure extends RuntimeException { + + public TerribleFailure(String msg, Throwable cause) { + super(msg, cause); + } + } + + @Implementation + public static void wtf(String tag, String msg) { + org.robolectric.shadows.ShadowLog.wtf(tag, msg); + if (sWtfIsFatal) { + throw new TerribleFailure(msg, null); + } + } + + @Implementation + public static void wtf(String tag, String msg, Throwable throwable) { + org.robolectric.shadows.ShadowLog.wtf(tag, msg, throwable); + if (sWtfIsFatal) { + throw new TerribleFailure(msg, throwable); + } + } +} diff --git a/library/test/robotest/src/com/android/setupwizardlib/view/IllustrationVideoViewTest.java b/library/test/robotest/src/com/android/setupwizardlib/view/IllustrationVideoViewTest.java index 6db8852..21822a4 100644 --- a/library/test/robotest/src/com/android/setupwizardlib/view/IllustrationVideoViewTest.java +++ b/library/test/robotest/src/com/android/setupwizardlib/view/IllustrationVideoViewTest.java @@ -18,6 +18,7 @@ package com.android.setupwizardlib.view; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.reset; import static org.mockito.Mockito.verify; @@ -33,6 +34,8 @@ import android.view.Surface; import com.android.setupwizardlib.R; import com.android.setupwizardlib.robolectric.SuwLibRobolectricTestRunner; +import com.android.setupwizardlib.shadow.ShadowLog; +import com.android.setupwizardlib.shadow.ShadowLog.TerribleFailure; import com.android.setupwizardlib.view.IllustrationVideoViewTest.ShadowMockMediaPlayer; import com.android.setupwizardlib.view.IllustrationVideoViewTest.ShadowSurface; @@ -55,6 +58,7 @@ import org.robolectric.util.ReflectionHelpers; @Config( sdk = Config.NEWEST_SDK, shadows = { + ShadowLog.class, ShadowMockMediaPlayer.class, ShadowSurface.class }) @@ -76,6 +80,17 @@ public class IllustrationVideoViewTest { } @Test + public void nullMediaPlayer_shouldThrowWtf() { + ShadowMockMediaPlayer.sMediaPlayer = null; + try { + createDefaultView(); + fail("WTF should be thrown for null media player"); + } catch (TerribleFailure e) { + // pass + } + } + + @Test public void testPausedWhenWindowFocusLost() { createDefaultView(); mView.start(); |