Merge "Fix ResolverDrawerLayout child measurement" into tm-dev am: a834a9bd52
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/18625112 Change-Id: I75aa3ba5b1686de683b0ffd0f5a28a9e31512601 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -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,45 +430,60 @@ final class PersistentDataStore {
|
||||
}
|
||||
|
||||
private void load() {
|
||||
clearState();
|
||||
|
||||
final InputStream is;
|
||||
try {
|
||||
is = mInjector.openRead();
|
||||
} catch (FileNotFoundException ex) {
|
||||
return;
|
||||
}
|
||||
|
||||
TypedXmlPullParser parser;
|
||||
try {
|
||||
parser = Xml.resolvePullParser(is);
|
||||
loadFromXml(parser);
|
||||
} catch (IOException ex) {
|
||||
Slog.w(TAG, "Failed to load display manager persistent store data.", ex);
|
||||
synchronized (mFileAccessLock) {
|
||||
clearState();
|
||||
} catch (XmlPullParserException ex) {
|
||||
Slog.w(TAG, "Failed to load display manager persistent store data.", ex);
|
||||
clearState();
|
||||
} finally {
|
||||
IoUtils.closeQuietly(is);
|
||||
|
||||
final InputStream is;
|
||||
try {
|
||||
is = mInjector.openRead();
|
||||
} catch (FileNotFoundException ex) {
|
||||
return;
|
||||
}
|
||||
|
||||
TypedXmlPullParser parser;
|
||||
try {
|
||||
parser = Xml.resolvePullParser(is);
|
||||
loadFromXml(parser);
|
||||
} catch (IOException ex) {
|
||||
Slog.w(TAG, "Failed to load display manager persistent store data.", ex);
|
||||
clearState();
|
||||
} catch (XmlPullParserException ex) {
|
||||
Slog.w(TAG, "Failed to load display manager persistent store data.", ex);
|
||||
clearState();
|
||||
} finally {
|
||||
IoUtils.closeQuietly(is);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void save() {
|
||||
final OutputStream os;
|
||||
final ByteArrayOutputStream os;
|
||||
try {
|
||||
os = mInjector.startWrite();
|
||||
boolean success = false;
|
||||
try {
|
||||
TypedXmlSerializer serializer = Xml.resolveSerializer(os);
|
||||
saveToXml(serializer);
|
||||
serializer.flush();
|
||||
success = true;
|
||||
} finally {
|
||||
mInjector.finishWrite(os, success);
|
||||
}
|
||||
os = new ByteArrayOutputStream();
|
||||
|
||||
TypedXmlSerializer serializer = Xml.resolveSerializer(os);
|
||||
saveToXml(serializer);
|
||||
serializer.flush();
|
||||
|
||||
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 {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user