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

Commit 78444656 authored by Matt Casey's avatar Matt Casey Committed by Automerger Merge Worker
Browse files

Merge "Fix ResolverDrawerLayout child measurement" into tm-dev am: a834a9bd

parents 4e5923b7 a834a9bd
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -929,7 +929,7 @@ public class ResolverDrawerLayout extends ViewGroup {
        // Single-use layout; just ignore the mode and use available space.
        // Clamp to maxWidth.
        if (mMaxWidth >= 0) {
            widthSize = Math.min(widthSize, mMaxWidth);
            widthSize = Math.min(widthSize, mMaxWidth + getPaddingLeft() + getPaddingRight());
        }

        final int widthSpec = MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY);
@@ -1008,8 +1008,9 @@ public class ResolverDrawerLayout extends ViewGroup {
        View indicatorHost = null;

        int ypos = mTopOffset;
        int leftEdge = getPaddingLeft();
        int rightEdge = width - getPaddingRight();
        final int leftEdge = getPaddingLeft();
        final int rightEdge = width - getPaddingRight();
        final int widthAvailable = rightEdge - leftEdge;

        final int childCount = getChildCount();
        for (int i = 0; i < childCount; i++) {
@@ -1030,7 +1031,6 @@ public class ResolverDrawerLayout extends ViewGroup {
            final int bottom = top + child.getMeasuredHeight();

            final int childWidth = child.getMeasuredWidth();
            final int widthAvailable = rightEdge - leftEdge;
            final int left = leftEdge + (widthAvailable - childWidth) / 2;
            final int right = left + childWidth;

+58 −31
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.annotation.Nullable;
import android.graphics.Point;
import android.hardware.display.BrightnessConfiguration;
import android.hardware.display.WifiDisplay;
import android.os.Handler;
import android.util.AtomicFile;
import android.util.Slog;
import android.util.SparseArray;
@@ -31,12 +32,14 @@ import android.util.Xml;
import android.view.Display;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.os.BackgroundThread;
import com.android.internal.util.XmlUtils;

import libcore.io.IoUtils;

import org.xmlpull.v1.XmlPullParserException;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
@@ -141,13 +144,22 @@ final class PersistentDataStore {
    // The interface for methods which should be replaced by the test harness.
    private Injector mInjector;

    private final Handler mHandler;
    private final Object mFileAccessLock = new Object();

    public PersistentDataStore() {
        this(new Injector());
    }

    @VisibleForTesting
    PersistentDataStore(Injector injector) {
        this(injector, BackgroundThread.getHandler());
    }

    @VisibleForTesting
    PersistentDataStore(Injector injector, Handler handler) {
        mInjector = injector;
        mHandler = handler;
    }

    public void saveIfNeeded() {
@@ -418,6 +430,7 @@ final class PersistentDataStore {
    }

    private void load() {
        synchronized (mFileAccessLock) {
            clearState();

            final InputStream is;
@@ -441,22 +454,36 @@ final class PersistentDataStore {
                IoUtils.closeQuietly(is);
            }
        }
    }

    private void save() {
        final OutputStream os;
        try {
            os = mInjector.startWrite();
            boolean success = false;
        final ByteArrayOutputStream os;
        try {
            os = new ByteArrayOutputStream();

            TypedXmlSerializer serializer = Xml.resolveSerializer(os);
            saveToXml(serializer);
            serializer.flush();
                success = true;

            mHandler.removeCallbacksAndMessages(/* token */ null);
            mHandler.post(() -> {
                synchronized (mFileAccessLock) {
                    OutputStream fileOutput = null;
                    try {
                        fileOutput = mInjector.startWrite();
                        os.writeTo(fileOutput);
                        fileOutput.flush();
                    } catch (IOException ex) {
                        Slog.w(TAG, "Failed to save display manager persistent store data.", ex);
                    } finally {
                mInjector.finishWrite(os, success);
                        if (fileOutput != null) {
                            mInjector.finishWrite(fileOutput, true);
                        }
                    }
                }
            });
        } catch (IOException ex) {
            Slog.w(TAG, "Failed to save display manager persistent store data.", ex);
            Slog.w(TAG, "Failed to process the XML serializer.", ex);
        }
    }

+10 −3
Original line number Diff line number Diff line
@@ -24,6 +24,8 @@ import static org.junit.Assert.assertTrue;

import android.content.Context;
import android.hardware.display.BrightnessConfiguration;
import android.os.Handler;
import android.os.test.TestLooper;
import android.util.Pair;

import androidx.test.InstrumentationRegistry;
@@ -47,11 +49,14 @@ import java.nio.charset.StandardCharsets;
public class PersistentDataStoreTest {
    private PersistentDataStore mDataStore;
    private TestInjector mInjector;
    private TestLooper mTestLooper;

    @Before
    public void setUp() {
        mInjector = new TestInjector();
        mDataStore = new PersistentDataStore(mInjector);
        mTestLooper = new TestLooper();
        Handler handler = new Handler(mTestLooper.getLooper());
        mDataStore = new PersistentDataStore(mInjector, handler);
    }

    @Test
@@ -147,7 +152,7 @@ public class PersistentDataStoreTest {
    }

    @Test
    public void testStoreAndReloadOfDisplayBrightnessConfigurations() {
    public void testStoreAndReloadOfDisplayBrightnessConfigurations() throws InterruptedException {
        final String uniqueDisplayId = "test:123";
        int userSerial = 0;
        String packageName = "pdsTestPackage";
@@ -178,6 +183,7 @@ public class PersistentDataStoreTest {
        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        mInjector.setWriteStream(baos);
        mDataStore.saveIfNeeded();
        mTestLooper.dispatchAll();
        assertTrue(mInjector.wasWriteSuccessful());
        TestInjector newInjector = new TestInjector();
        PersistentDataStore newDataStore = new PersistentDataStore(newInjector);
@@ -222,7 +228,7 @@ public class PersistentDataStoreTest {
    }

    @Test
    public void testStoreAndReloadOfBrightnessConfigurations() {
    public void testStoreAndReloadOfBrightnessConfigurations() throws InterruptedException {
        final float[] lux = { 0f, 10f };
        final float[] nits = {1f, 100f };
        final BrightnessConfiguration config = new BrightnessConfiguration.Builder(lux, nits)
@@ -238,6 +244,7 @@ public class PersistentDataStoreTest {
        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        mInjector.setWriteStream(baos);
        mDataStore.saveIfNeeded();
        mTestLooper.dispatchAll();
        assertTrue(mInjector.wasWriteSuccessful());

        TestInjector newInjector = new TestInjector();