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

Commit eeb99728 authored by Jason Monk's avatar Jason Monk Committed by android-build-merger
Browse files

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

am: 80b9c95c

Change-Id: I765e0e7208d4e31a680c2ac2ece954334584f16f
parents f6f95eb7 80b9c95c
Loading
Loading
Loading
Loading
+13 −0
Original line number Original line Diff line number Diff line
@@ -94,6 +94,11 @@ public class ScrimView extends View implements ConfigurationController.Configura
        mColors = new ColorExtractor.GradientColors();
        mColors = new ColorExtractor.GradientColors();
        updateScreenSize();
        updateScreenSize();
        updateColorWithTint(false);
        updateColorWithTint(false);
    }

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


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


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

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

    @Override
    @Override
    protected void onDraw(Canvas canvas) {
    protected void onDraw(Canvas canvas) {
        if (mDrawAsSrc || mDrawable.getAlpha() > 0) {
        if (mDrawAsSrc || mDrawable.getAlpha() > 0) {
+17 −3
Original line number Original line Diff line number Diff line
@@ -28,11 +28,15 @@ import android.graphics.Color;
import android.graphics.Rect;
import android.graphics.Rect;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.Drawable;
import android.testing.AndroidTestingRunner;
import android.support.test.filters.SmallTest;
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 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.ColorExtractor;
import com.google.android.colorextraction.drawable.GradientDrawable;
import com.google.android.colorextraction.drawable.GradientDrawable;
@@ -43,17 +47,27 @@ import org.junit.runner.RunWith;


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


    ScrimView mView;
    ScrimView mView;


    @Before
    @Before
    public void setUp() {
    public void setUp() {
        injectLeakCheckedDependency(ConfigurationController.class);
        mView = new ScrimView(getContext());
        mView = new ScrimView(getContext());
        mView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
        mView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
        mView.layout(0, 0, 1920, 1080);
        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
    @Test
    public void testSetDrawable_UpdateDrawable() {
    public void testSetDrawable_UpdateDrawable() {
        Drawable drawable = new ColorDrawable(Color.GREEN);
        Drawable drawable = new ColorDrawable(Color.GREEN);
+26 −0
Original line number Original line 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 Original line 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.BatteryController;
import com.android.systemui.statusbar.policy.BluetoothController;
import com.android.systemui.statusbar.policy.BluetoothController;
import com.android.systemui.statusbar.policy.CastController;
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.FlashlightController;
import com.android.systemui.statusbar.policy.HotspotController;
import com.android.systemui.statusbar.policy.HotspotController;
import com.android.systemui.statusbar.policy.KeyguardMonitor;
import com.android.systemui.statusbar.policy.KeyguardMonitor;
@@ -68,6 +69,7 @@ public abstract class LeakCheckedTest extends SysuiTestCase {
            PluginManager.class,
            PluginManager.class,
            TunerService.class,
            TunerService.class,
            StatusBarIconController.class,
            StatusBarIconController.class,
            ConfigurationController.class,
    };
    };


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