Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 80b9c95c authored by Android Build Merger (Role)'s avatar Android Build Merger (Role) Committed by Android (Google) Code Review
Browse files

Merge "Merge "Fix leak in ScrimView" into oc-dr1-dev am: 20b9b73e" into oc-dr1-dev-plus-aosp

parents 596a1298 8f526617
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -94,6 +94,11 @@ public class ScrimView extends View implements ConfigurationController.Configura
        mColors = new ColorExtractor.GradientColors();
        updateScreenSize();
        updateColorWithTint(false);
    }

    @Override
    protected void onAttachedToWindow() {
        super.onAttachedToWindow();

        // We need to know about configuration changes to update the gradient size
        // since it's independent from view bounds.
@@ -101,6 +106,14 @@ public class ScrimView extends View implements ConfigurationController.Configura
        config.addCallback(this);
    }

    @Override
    protected void onDetachedFromWindow() {
        super.onDetachedFromWindow();

        ConfigurationController config = Dependency.get(ConfigurationController.class);
        config.removeCallback(this);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        if (mDrawAsSrc || mDrawable.getAlpha() > 0) {
+17 −3
Original line number Diff line number Diff line
@@ -28,11 +28,15 @@ import android.graphics.Color;
import android.graphics.Rect;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.testing.AndroidTestingRunner;
import android.support.test.filters.SmallTest;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
import android.testing.TestableLooper.RunWithLooper;
import android.testing.ViewUtils;
import android.view.View;

import com.android.systemui.SysuiTestCase;
import com.android.systemui.statusbar.policy.ConfigurationController;
import com.android.systemui.utils.leaks.LeakCheckedTest;

import com.google.android.colorextraction.ColorExtractor;
import com.google.android.colorextraction.drawable.GradientDrawable;
@@ -43,17 +47,27 @@ import org.junit.runner.RunWith;

@RunWith(AndroidTestingRunner.class)
@SmallTest
public class ScrimViewTest extends SysuiTestCase {
public class ScrimViewTest extends LeakCheckedTest {

    ScrimView mView;

    @Before
    public void setUp() {
        injectLeakCheckedDependency(ConfigurationController.class);
        mView = new ScrimView(getContext());
        mView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
        mView.layout(0, 0, 1920, 1080);
    }

    @Test
    @RunWithLooper
    public void testAttachDetach() {
        ViewUtils.attachView(mView);
        TestableLooper.get(this).processAllMessages();
        ViewUtils.detachView(mView);
        TestableLooper.get(this).processAllMessages();
    }

    @Test
    public void testSetDrawable_UpdateDrawable() {
        Drawable drawable = new ColorDrawable(Color.GREEN);
+26 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 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.systemui.utils.leaks;

import com.android.systemui.statusbar.policy.ConfigurationController;

public class FakeConfigurationController
        extends BaseLeakChecker<ConfigurationController.ConfigurationListener>
        implements ConfigurationController {

    public FakeConfigurationController(LeakCheckedTest.SysuiLeakCheck sysuiLeakCheck) {
        super(sysuiLeakCheck, "config");
    }
}
+4 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import com.android.systemui.statusbar.phone.StatusBarIconController;
import com.android.systemui.statusbar.policy.BatteryController;
import com.android.systemui.statusbar.policy.BluetoothController;
import com.android.systemui.statusbar.policy.CastController;
import com.android.systemui.statusbar.policy.ConfigurationController;
import com.android.systemui.statusbar.policy.FlashlightController;
import com.android.systemui.statusbar.policy.HotspotController;
import com.android.systemui.statusbar.policy.KeyguardMonitor;
@@ -68,6 +69,7 @@ public abstract class LeakCheckedTest extends SysuiTestCase {
            PluginManager.class,
            TunerService.class,
            StatusBarIconController.class,
            ConfigurationController.class,
    };

    @Rule
@@ -134,6 +136,8 @@ public abstract class LeakCheckedTest extends SysuiTestCase {
                    obj = new FakeTunerService(this);
                } else if (cls == StatusBarIconController.class) {
                    obj = new FakeStatusBarIconController(this);
                } else if (cls == ConfigurationController.class) {
                    obj = new FakeConfigurationController(this);
                } else {
                    Assert.fail(cls.getName() + " is not supported by LeakCheckedTest yet");
                }