Loading services/core/java/com/android/server/wm/AppTransition.java +16 −4 Original line number Diff line number Diff line Loading @@ -86,6 +86,7 @@ import android.content.Context; import android.content.res.Configuration; import android.content.res.ResourceId; import android.content.res.Resources; import android.content.res.Resources.NotFoundException; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; Loading Loading @@ -123,6 +124,7 @@ import android.view.animation.ScaleAnimation; import android.view.animation.TranslateAnimation; import com.android.internal.R; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.util.DumpUtils.Dump; import com.android.internal.util.function.pooled.PooledLambda; import com.android.server.AttributeCache; Loading Loading @@ -558,19 +560,19 @@ public class AppTransition implements Dump { } resId = updateToTranslucentAnimIfNeeded(resId, transit); if (ResourceId.isValid(resId)) { return AnimationUtils.loadAnimation(context, resId); return loadAnimationSafely(context, resId); } return null; } Animation loadAnimationRes(LayoutParams lp, int resId) { private Animation loadAnimationRes(LayoutParams lp, int resId) { Context context = mContext; if (ResourceId.isValid(resId)) { AttributeCache.Entry ent = getCachedAnimations(lp); if (ent != null) { context = ent.context; } return AnimationUtils.loadAnimation(context, resId); return loadAnimationSafely(context, resId); } return null; } Loading @@ -579,12 +581,22 @@ public class AppTransition implements Dump { if (ResourceId.isValid(resId)) { AttributeCache.Entry ent = getCachedAnimations(packageName, resId); if (ent != null) { return AnimationUtils.loadAnimation(ent.context, resId); return loadAnimationSafely(ent.context, resId); } } return null; } @VisibleForTesting Animation loadAnimationSafely(Context context, int resId) { try { return AnimationUtils.loadAnimation(context, resId); } catch (NotFoundException e) { Slog.w(TAG, "Unable to load animation resource", e); return null; } } private int updateToTranslucentAnimIfNeeded(int anim, int transit) { if (transit == TRANSIT_TRANSLUCENT_ACTIVITY_OPEN && anim == R.anim.activity_open_enter) { return R.anim.activity_translucent_open_enter; Loading services/tests/wmtests/src/com/android/server/wm/AppTransitionTests.java +12 −5 Original line number Diff line number Diff line Loading @@ -23,29 +23,29 @@ import static android.view.WindowManager.TRANSIT_ACTIVITY_OPEN; import static android.view.WindowManager.TRANSIT_CRASHING_ACTIVITY_CLOSE; import static android.view.WindowManager.TRANSIT_KEYGUARD_GOING_AWAY; import static android.view.WindowManager.TRANSIT_KEYGUARD_UNOCCLUDE; import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation; import static com.android.dx.mockito.inline.extended.ExtendedMockito.anyBoolean; import static com.android.dx.mockito.inline.extended.ExtendedMockito.doNothing; import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import android.graphics.Rect; import android.platform.test.annotations.Presubmit; import android.view.Display; import androidx.test.filters.SmallTest; import org.junit.Before; import org.junit.Test; import androidx.test.filters.SmallTest; /** * Test class for {@link AppTransition}. * * Build/Install/Run: * atest FrameworksServicesTests:AppTransitionTests * atest WmTests:AppTransitionTests */ @SmallTest @Presubmit Loading Loading @@ -167,4 +167,11 @@ public class AppTransitionTests extends WindowTestsBase { assertFalse(dc1.mOpeningApps.contains(token1)); } @Test public void testLoadAnimationSafely() { DisplayContent dc = createNewDisplay(Display.STATE_ON); assertNull(dc.mAppTransition.loadAnimationSafely( getInstrumentation().getTargetContext(), -1)); } } Loading
services/core/java/com/android/server/wm/AppTransition.java +16 −4 Original line number Diff line number Diff line Loading @@ -86,6 +86,7 @@ import android.content.Context; import android.content.res.Configuration; import android.content.res.ResourceId; import android.content.res.Resources; import android.content.res.Resources.NotFoundException; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; Loading Loading @@ -123,6 +124,7 @@ import android.view.animation.ScaleAnimation; import android.view.animation.TranslateAnimation; import com.android.internal.R; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.util.DumpUtils.Dump; import com.android.internal.util.function.pooled.PooledLambda; import com.android.server.AttributeCache; Loading Loading @@ -558,19 +560,19 @@ public class AppTransition implements Dump { } resId = updateToTranslucentAnimIfNeeded(resId, transit); if (ResourceId.isValid(resId)) { return AnimationUtils.loadAnimation(context, resId); return loadAnimationSafely(context, resId); } return null; } Animation loadAnimationRes(LayoutParams lp, int resId) { private Animation loadAnimationRes(LayoutParams lp, int resId) { Context context = mContext; if (ResourceId.isValid(resId)) { AttributeCache.Entry ent = getCachedAnimations(lp); if (ent != null) { context = ent.context; } return AnimationUtils.loadAnimation(context, resId); return loadAnimationSafely(context, resId); } return null; } Loading @@ -579,12 +581,22 @@ public class AppTransition implements Dump { if (ResourceId.isValid(resId)) { AttributeCache.Entry ent = getCachedAnimations(packageName, resId); if (ent != null) { return AnimationUtils.loadAnimation(ent.context, resId); return loadAnimationSafely(ent.context, resId); } } return null; } @VisibleForTesting Animation loadAnimationSafely(Context context, int resId) { try { return AnimationUtils.loadAnimation(context, resId); } catch (NotFoundException e) { Slog.w(TAG, "Unable to load animation resource", e); return null; } } private int updateToTranslucentAnimIfNeeded(int anim, int transit) { if (transit == TRANSIT_TRANSLUCENT_ACTIVITY_OPEN && anim == R.anim.activity_open_enter) { return R.anim.activity_translucent_open_enter; Loading
services/tests/wmtests/src/com/android/server/wm/AppTransitionTests.java +12 −5 Original line number Diff line number Diff line Loading @@ -23,29 +23,29 @@ import static android.view.WindowManager.TRANSIT_ACTIVITY_OPEN; import static android.view.WindowManager.TRANSIT_CRASHING_ACTIVITY_CLOSE; import static android.view.WindowManager.TRANSIT_KEYGUARD_GOING_AWAY; import static android.view.WindowManager.TRANSIT_KEYGUARD_UNOCCLUDE; import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation; import static com.android.dx.mockito.inline.extended.ExtendedMockito.anyBoolean; import static com.android.dx.mockito.inline.extended.ExtendedMockito.doNothing; import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import android.graphics.Rect; import android.platform.test.annotations.Presubmit; import android.view.Display; import androidx.test.filters.SmallTest; import org.junit.Before; import org.junit.Test; import androidx.test.filters.SmallTest; /** * Test class for {@link AppTransition}. * * Build/Install/Run: * atest FrameworksServicesTests:AppTransitionTests * atest WmTests:AppTransitionTests */ @SmallTest @Presubmit Loading Loading @@ -167,4 +167,11 @@ public class AppTransitionTests extends WindowTestsBase { assertFalse(dc1.mOpeningApps.contains(token1)); } @Test public void testLoadAnimationSafely() { DisplayContent dc = createNewDisplay(Display.STATE_ON); assertNull(dc.mAppTransition.loadAnimationSafely( getInstrumentation().getTargetContext(), -1)); } }