summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Vadim Caen <caen@google.com> 2019-07-09 14:26:00 +0200
committer Vadim Caen <caen@google.com> 2019-07-15 11:55:05 +0200
commite664c705df6d20d217c9aaac90bc59b697165d3a (patch)
treef64820e6169471a6f44e31cc01574d7a0eb6a6d0
parent03ab1711c40a8df0232f94912a7577cb0e075b55 (diff)
Delegate setBackgroundDrawable to setWindowDrawable
Bug: 132232241 Test: DevoreViewTest#setBackgroundDrawableSameAsSetWindowBackground Change-Id: Ic5961dd1d08d8cff7eb6bb72f475df579541b1d2
-rw-r--r--core/java/com/android/internal/policy/DecorView.java9
-rw-r--r--core/tests/coretests/src/com/android/internal/policy/DecorViewTest.java79
2 files changed, 80 insertions, 8 deletions
diff --git a/core/java/com/android/internal/policy/DecorView.java b/core/java/com/android/internal/policy/DecorView.java
index fe66cf9aab7d..480ff4d528f0 100644
--- a/core/java/com/android/internal/policy/DecorView.java
+++ b/core/java/com/android/internal/policy/DecorView.java
@@ -983,14 +983,7 @@ public class DecorView extends FrameLayout implements RootViewSurfaceTaker, Wind
@Override
public void setBackgroundDrawable(Drawable background) {
-
- // TODO: This should route through setWindowBackground, but late in the release to make this
- // change.
- if (mOriginalBackgroundDrawable != background) {
- mOriginalBackgroundDrawable = background;
- updateBackgroundDrawable();
- drawableChanged();
- }
+ setWindowBackground(background);
}
public void setWindowFrame(Drawable drawable) {
diff --git a/core/tests/coretests/src/com/android/internal/policy/DecorViewTest.java b/core/tests/coretests/src/com/android/internal/policy/DecorViewTest.java
new file mode 100644
index 000000000000..f66717e9066c
--- /dev/null
+++ b/core/tests/coretests/src/com/android/internal/policy/DecorViewTest.java
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2019 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.internal.policy;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.content.Context;
+import android.graphics.Bitmap;
+import android.graphics.Canvas;
+import android.graphics.drawable.Drawable;
+
+import androidx.test.platform.app.InstrumentationRegistry;
+
+import com.android.frameworks.coretests.R;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.Arrays;
+
+public class DecorViewTest {
+
+ private Context mContext;
+ private DecorView mDecorView;
+
+ @Before
+ public void setUp() {
+ mContext = InstrumentationRegistry.getInstrumentation().getContext();
+ PhoneWindow phoneWindow = new PhoneWindow(mContext);
+ mDecorView = (DecorView) phoneWindow.getDecorView();
+ }
+
+ @Test
+ public void setBackgroundDrawableSameAsSetWindowBackground() {
+ Drawable bitmapDrawable = mContext.getResources()
+ .getDrawable(R.drawable.test16x12, mContext.getTheme());
+ int w = 16;
+ int h = 12;
+ Bitmap expectedBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
+
+ mDecorView.setWindowBackground(bitmapDrawable);
+ Canvas testCanvas = new Canvas(expectedBitmap);
+ mDecorView.draw(testCanvas);
+ testCanvas.release();
+
+ Drawable expectedBackground = mDecorView.getBackground();
+
+ mDecorView.setBackgroundDrawable(bitmapDrawable);
+ Bitmap resultBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
+ Canvas resCanvas = new Canvas(resultBitmap);
+ mDecorView.draw(resCanvas);
+ resCanvas.release();
+
+ // Check that the drawable is the same.
+ assertThat(mDecorView.getBackground()).isEqualTo(expectedBackground);
+ assertThat(mDecorView.getBackground()).isEqualTo(bitmapDrawable);
+
+ // Check that canvas is the same.
+ int[] expPixels = new int[w * h];
+ int[] resPixels = new int[w * h];
+ resultBitmap.getPixels(resPixels, 0, w, 0, 0, w, h);
+ expectedBitmap.getPixels(expPixels, 0, w, 0, 0, w, h);
+ assertThat(Arrays.toString(expPixels)).isEqualTo(Arrays.toString(resPixels));
+ }
+}