Merge "Store the source ID in InsetsFrameProvider" into udc-dev
This commit is contained in:
@@ -62,9 +62,7 @@ public class InsetsFrameProvider implements Parcelable {
|
|||||||
*/
|
*/
|
||||||
public static final int SOURCE_ARBITRARY_RECTANGLE = 3;
|
public static final int SOURCE_ARBITRARY_RECTANGLE = 3;
|
||||||
|
|
||||||
private final IBinder mOwner;
|
private final int mId;
|
||||||
private final int mIndex;
|
|
||||||
private final @InsetsType int mType;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The selection of the starting rectangle to be converted into source frame.
|
* The selection of the starting rectangle to be converted into source frame.
|
||||||
@@ -122,30 +120,30 @@ public class InsetsFrameProvider implements Parcelable {
|
|||||||
* @param type the {@link InsetsType}.
|
* @param type the {@link InsetsType}.
|
||||||
* @see InsetsSource#createId(Object, int, int)
|
* @see InsetsSource#createId(Object, int, int)
|
||||||
*/
|
*/
|
||||||
public InsetsFrameProvider(IBinder owner, @IntRange(from = 0, to = 2047) int index,
|
public InsetsFrameProvider(Object owner, @IntRange(from = 0, to = 2047) int index,
|
||||||
@InsetsType int type) {
|
@InsetsType int type) {
|
||||||
if (index < 0 || index >= 2048) {
|
mId = InsetsSource.createId(owner, index, type);
|
||||||
throw new IllegalArgumentException();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// This throws IllegalArgumentException if the type is not valid.
|
/**
|
||||||
WindowInsets.Type.indexOf(type);
|
* Returns an unique integer which identifies the insets source.
|
||||||
|
*/
|
||||||
mOwner = owner;
|
public int getId() {
|
||||||
mIndex = index;
|
return mId;
|
||||||
mType = type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IBinder getOwner() {
|
|
||||||
return mOwner;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the index specified in {@link #InsetsFrameProvider(IBinder, int, int)}.
|
||||||
|
*/
|
||||||
public int getIndex() {
|
public int getIndex() {
|
||||||
return mIndex;
|
return InsetsSource.getIndex(mId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the {@link InsetsType} specified in {@link #InsetsFrameProvider(IBinder, int, int)}.
|
||||||
|
*/
|
||||||
public int getType() {
|
public int getType() {
|
||||||
return mType;
|
return InsetsSource.getType(mId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public InsetsFrameProvider setSource(int source) {
|
public InsetsFrameProvider setSource(int source) {
|
||||||
@@ -211,9 +209,9 @@ public class InsetsFrameProvider implements Parcelable {
|
|||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
final StringBuilder sb = new StringBuilder("InsetsFrameProvider: {");
|
final StringBuilder sb = new StringBuilder("InsetsFrameProvider: {");
|
||||||
sb.append("owner=").append(mOwner);
|
sb.append("id=#").append(Integer.toHexString(mId));
|
||||||
sb.append(", index=").append(mIndex);
|
sb.append(", index=").append(getIndex());
|
||||||
sb.append(", type=").append(WindowInsets.Type.toString(mType));
|
sb.append(", type=").append(WindowInsets.Type.toString(getType()));
|
||||||
sb.append(", source=").append(sourceToString(mSource));
|
sb.append(", source=").append(sourceToString(mSource));
|
||||||
sb.append(", flags=[").append(InsetsSource.flagsToString(mFlags)).append("]");
|
sb.append(", flags=[").append(InsetsSource.flagsToString(mFlags)).append("]");
|
||||||
if (mInsetsSize != null) {
|
if (mInsetsSize != null) {
|
||||||
@@ -244,9 +242,7 @@ public class InsetsFrameProvider implements Parcelable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public InsetsFrameProvider(Parcel in) {
|
public InsetsFrameProvider(Parcel in) {
|
||||||
mOwner = in.readStrongBinder();
|
mId = in.readInt();
|
||||||
mIndex = in.readInt();
|
|
||||||
mType = in.readInt();
|
|
||||||
mSource = in.readInt();
|
mSource = in.readInt();
|
||||||
mFlags = in.readInt();
|
mFlags = in.readInt();
|
||||||
mInsetsSize = in.readTypedObject(Insets.CREATOR);
|
mInsetsSize = in.readTypedObject(Insets.CREATOR);
|
||||||
@@ -256,9 +252,7 @@ public class InsetsFrameProvider implements Parcelable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeToParcel(Parcel out, int flags) {
|
public void writeToParcel(Parcel out, int flags) {
|
||||||
out.writeStrongBinder(mOwner);
|
out.writeInt(mId);
|
||||||
out.writeInt(mIndex);
|
|
||||||
out.writeInt(mType);
|
|
||||||
out.writeInt(mSource);
|
out.writeInt(mSource);
|
||||||
out.writeInt(mFlags);
|
out.writeInt(mFlags);
|
||||||
out.writeTypedObject(mInsetsSize, flags);
|
out.writeTypedObject(mInsetsSize, flags);
|
||||||
@@ -267,7 +261,7 @@ public class InsetsFrameProvider implements Parcelable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean idEquals(InsetsFrameProvider o) {
|
public boolean idEquals(InsetsFrameProvider o) {
|
||||||
return Objects.equals(mOwner, o.mOwner) && mIndex == o.mIndex && mType == o.mType;
|
return mId == o.mId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -279,8 +273,7 @@ public class InsetsFrameProvider implements Parcelable {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final InsetsFrameProvider other = (InsetsFrameProvider) o;
|
final InsetsFrameProvider other = (InsetsFrameProvider) o;
|
||||||
return Objects.equals(mOwner, other.mOwner) && mIndex == other.mIndex
|
return mId == other.mId && mSource == other.mSource && mFlags == other.mFlags
|
||||||
&& mType == other.mType && mSource == other.mSource && mFlags == other.mFlags
|
|
||||||
&& Objects.equals(mInsetsSize, other.mInsetsSize)
|
&& Objects.equals(mInsetsSize, other.mInsetsSize)
|
||||||
&& Arrays.equals(mInsetsSizeOverrides, other.mInsetsSizeOverrides)
|
&& Arrays.equals(mInsetsSizeOverrides, other.mInsetsSizeOverrides)
|
||||||
&& Objects.equals(mArbitraryRectangle, other.mArbitraryRectangle);
|
&& Objects.equals(mArbitraryRectangle, other.mArbitraryRectangle);
|
||||||
@@ -288,7 +281,7 @@ public class InsetsFrameProvider implements Parcelable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hash(mOwner, mIndex, mType, mSource, mFlags, mInsetsSize,
|
return Objects.hash(mId, mSource, mFlags, mInsetsSize,
|
||||||
Arrays.hashCode(mInsetsSizeOverrides), mArbitraryRectangle);
|
Arrays.hashCode(mInsetsSizeOverrides), mArbitraryRectangle);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -319,7 +312,7 @@ public class InsetsFrameProvider implements Parcelable {
|
|||||||
|
|
||||||
protected InsetsSizeOverride(Parcel in) {
|
protected InsetsSizeOverride(Parcel in) {
|
||||||
mWindowType = in.readInt();
|
mWindowType = in.readInt();
|
||||||
mInsetsSize = in.readParcelable(null, Insets.class);
|
mInsetsSize = in.readTypedObject(Insets.CREATOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
public InsetsSizeOverride(int windowType, Insets insetsSize) {
|
public InsetsSizeOverride(int windowType, Insets insetsSize) {
|
||||||
@@ -354,7 +347,7 @@ public class InsetsFrameProvider implements Parcelable {
|
|||||||
@Override
|
@Override
|
||||||
public void writeToParcel(Parcel out, int flags) {
|
public void writeToParcel(Parcel out, int flags) {
|
||||||
out.writeInt(mWindowType);
|
out.writeInt(mWindowType);
|
||||||
out.writeParcelable(mInsetsSize, flags);
|
out.writeTypedObject(mInsetsSize, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -271,7 +271,7 @@ public class InsetsSource implements Parcelable {
|
|||||||
* @param index An owner may have multiple sources with the same type. For example, the system
|
* @param index An owner may have multiple sources with the same type. For example, the system
|
||||||
* server might have multiple display cutout sources. This is used to identify
|
* server might have multiple display cutout sources. This is used to identify
|
||||||
* which one is which. The value must be in a range of [0, 2047].
|
* which one is which. The value must be in a range of [0, 2047].
|
||||||
* @param type The {@link WindowInsets.Type.InsetsType type} of the source.
|
* @param type The {@link InsetsType type} of the source.
|
||||||
* @return a unique integer as the identifier.
|
* @return a unique integer as the identifier.
|
||||||
*/
|
*/
|
||||||
public static int createId(Object owner, @IntRange(from = 0, to = 2047) int index,
|
public static int createId(Object owner, @IntRange(from = 0, to = 2047) int index,
|
||||||
@@ -282,11 +282,29 @@ public class InsetsSource implements Parcelable {
|
|||||||
// owner takes top 16 bits;
|
// owner takes top 16 bits;
|
||||||
// index takes 11 bits since the 6th bit;
|
// index takes 11 bits since the 6th bit;
|
||||||
// type takes bottom 5 bits.
|
// type takes bottom 5 bits.
|
||||||
return (((owner != null ? owner.hashCode() : 1) % (1 << 16)) << 16)
|
return ((System.identityHashCode(owner) % (1 << 16)) << 16)
|
||||||
+ (index << 5)
|
+ (index << 5)
|
||||||
+ WindowInsets.Type.indexOf(type);
|
+ WindowInsets.Type.indexOf(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the index from the ID.
|
||||||
|
*
|
||||||
|
* @see #createId(Object, int, int)
|
||||||
|
*/
|
||||||
|
public static int getIndex(int id) {
|
||||||
|
return (id % (1 << 16)) >> 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the {@link InsetsType} from the ID.
|
||||||
|
*
|
||||||
|
* @see #createId(Object, int, int)
|
||||||
|
*/
|
||||||
|
public static int getType(int id) {
|
||||||
|
return 1 << (id % 32);
|
||||||
|
}
|
||||||
|
|
||||||
public static String flagsToString(@Flags int flags) {
|
public static String flagsToString(@Flags int flags) {
|
||||||
final StringJoiner joiner = new StringJoiner(" ");
|
final StringJoiner joiner = new StringJoiner(" ");
|
||||||
if ((flags & FLAG_SUPPRESS_SCRIM) != 0) {
|
if ((flags & FLAG_SUPPRESS_SCRIM) != 0) {
|
||||||
|
|||||||
@@ -227,5 +227,25 @@ public class InsetsSourceTest {
|
|||||||
assertEquals(numTotalSources, sources.size());
|
assertEquals(numTotalSources, sources.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetIndex() {
|
||||||
|
for (int index = 0; index < 2048; index++) {
|
||||||
|
for (int type = FIRST; type <= LAST; type = type << 1) {
|
||||||
|
final int id = InsetsSource.createId(null, index, type);
|
||||||
|
assertEquals(index, InsetsSource.getIndex(id));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetType() {
|
||||||
|
for (int index = 0; index < 2048; index++) {
|
||||||
|
for (int type = FIRST; type <= LAST; type = type << 1) {
|
||||||
|
final int id = InsetsSource.createId(null, index, type);
|
||||||
|
assertEquals(type, InsetsSource.getType(id));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Parcel and equals already tested via InsetsStateTest
|
// Parcel and equals already tested via InsetsStateTest
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1095,11 +1095,9 @@ public class DisplayPolicy {
|
|||||||
} else {
|
} else {
|
||||||
overrideProviders = null;
|
overrideProviders = null;
|
||||||
}
|
}
|
||||||
final @InsetsType int type = provider.getType();
|
mDisplayContent.getInsetsStateController().getOrCreateSourceProvider(
|
||||||
final int id = InsetsSource.createId(
|
provider.getId(), provider.getType()).setWindowContainer(
|
||||||
provider.getOwner(), provider.getIndex(), type);
|
win, frameProvider, overrideProviders);
|
||||||
mDisplayContent.getInsetsStateController().getOrCreateSourceProvider(id, type)
|
|
||||||
.setWindowContainer(win, frameProvider, overrideProviders);
|
|
||||||
mInsetsSourceWindowsExceptIme.add(win);
|
mInsetsSourceWindowsExceptIme.add(win);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -311,16 +311,13 @@ class InsetsPolicy {
|
|||||||
state.removeSource(ID_IME);
|
state.removeSource(ID_IME);
|
||||||
} else if (attrs.providedInsets != null) {
|
} else if (attrs.providedInsets != null) {
|
||||||
for (InsetsFrameProvider provider : attrs.providedInsets) {
|
for (InsetsFrameProvider provider : attrs.providedInsets) {
|
||||||
final int id = InsetsSource.createId(
|
if ((provider.getType() & WindowInsets.Type.systemBars()) == 0) {
|
||||||
provider.getOwner(), provider.getIndex(), provider.getType());
|
|
||||||
final @InsetsType int type = provider.getType();
|
|
||||||
if ((type & WindowInsets.Type.systemBars()) == 0) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (state == originalState) {
|
if (state == originalState) {
|
||||||
state = new InsetsState(state);
|
state = new InsetsState(state);
|
||||||
}
|
}
|
||||||
state.removeSource(id);
|
state.removeSource(provider.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -435,8 +435,7 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer<
|
|||||||
if (mLocalInsetsSources == null) {
|
if (mLocalInsetsSources == null) {
|
||||||
mLocalInsetsSources = new SparseArray<>();
|
mLocalInsetsSources = new SparseArray<>();
|
||||||
}
|
}
|
||||||
final int id = InsetsSource.createId(
|
final int id = provider.getId();
|
||||||
provider.getOwner(), provider.getIndex(), provider.getType());
|
|
||||||
if (mLocalInsetsSources.get(id) != null) {
|
if (mLocalInsetsSources.get(id) != null) {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Slog.d(TAG, "The local insets source for this " + provider
|
Slog.d(TAG, "The local insets source for this " + provider
|
||||||
@@ -457,8 +456,7 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer<
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final int id = InsetsSource.createId(
|
final int id = provider.getId();
|
||||||
provider.getOwner(), provider.getIndex(), provider.getType());
|
|
||||||
if (mLocalInsetsSources.get(id) == null) {
|
if (mLocalInsetsSources.get(id) == null) {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Slog.d(TAG, "Given " + provider + " doesn't have a local insets source.");
|
Slog.d(TAG, "Given " + provider + " doesn't have a local insets source.");
|
||||||
|
|||||||
@@ -1443,10 +1443,8 @@ public class WindowContainerTests extends WindowTestsBase {
|
|||||||
final InsetsFrameProvider provider2 =
|
final InsetsFrameProvider provider2 =
|
||||||
new InsetsFrameProvider(null, 2, WindowInsets.Type.systemOverlays())
|
new InsetsFrameProvider(null, 2, WindowInsets.Type.systemOverlays())
|
||||||
.setArbitraryRectangle(genericOverlayInsetsRect2);
|
.setArbitraryRectangle(genericOverlayInsetsRect2);
|
||||||
final int sourceId1 = InsetsSource.createId(
|
final int sourceId1 = provider1.getId();
|
||||||
provider1.getOwner(), provider1.getIndex(), provider1.getType());
|
final int sourceId2 = provider2.getId();
|
||||||
final int sourceId2 = InsetsSource.createId(
|
|
||||||
provider2.getOwner(), provider2.getIndex(), provider2.getType());
|
|
||||||
|
|
||||||
rootTask.addLocalInsetsFrameProvider(provider1);
|
rootTask.addLocalInsetsFrameProvider(provider1);
|
||||||
container.addLocalInsetsFrameProvider(provider2);
|
container.addLocalInsetsFrameProvider(provider2);
|
||||||
@@ -1504,10 +1502,8 @@ public class WindowContainerTests extends WindowTestsBase {
|
|||||||
final InsetsFrameProvider provider2 =
|
final InsetsFrameProvider provider2 =
|
||||||
new InsetsFrameProvider(null, 1, WindowInsets.Type.systemOverlays())
|
new InsetsFrameProvider(null, 1, WindowInsets.Type.systemOverlays())
|
||||||
.setArbitraryRectangle(genericOverlayInsetsRect2);
|
.setArbitraryRectangle(genericOverlayInsetsRect2);
|
||||||
final int sourceId1 = InsetsSource.createId(
|
final int sourceId1 = provider1.getId();
|
||||||
provider1.getOwner(), provider1.getIndex(), provider1.getType());
|
final int sourceId2 = provider2.getId();
|
||||||
final int sourceId2 = InsetsSource.createId(
|
|
||||||
provider2.getOwner(), provider2.getIndex(), provider2.getType());
|
|
||||||
|
|
||||||
rootTask.addLocalInsetsFrameProvider(provider1);
|
rootTask.addLocalInsetsFrameProvider(provider1);
|
||||||
activity0.forAllWindows(window -> {
|
activity0.forAllWindows(window -> {
|
||||||
@@ -1566,10 +1562,8 @@ public class WindowContainerTests extends WindowTestsBase {
|
|||||||
final InsetsFrameProvider provider2 =
|
final InsetsFrameProvider provider2 =
|
||||||
new InsetsFrameProvider(null, 2, WindowInsets.Type.systemOverlays())
|
new InsetsFrameProvider(null, 2, WindowInsets.Type.systemOverlays())
|
||||||
.setArbitraryRectangle(navigationBarInsetsRect2);
|
.setArbitraryRectangle(navigationBarInsetsRect2);
|
||||||
final int sourceId1 = InsetsSource.createId(
|
final int sourceId1 = provider1.getId();
|
||||||
provider1.getOwner(), provider1.getIndex(), provider1.getType());
|
final int sourceId2 = provider2.getId();
|
||||||
final int sourceId2 = InsetsSource.createId(
|
|
||||||
provider2.getOwner(), provider2.getIndex(), provider2.getType());
|
|
||||||
|
|
||||||
rootTask.addLocalInsetsFrameProvider(provider1);
|
rootTask.addLocalInsetsFrameProvider(provider1);
|
||||||
container.addLocalInsetsFrameProvider(provider2);
|
container.addLocalInsetsFrameProvider(provider2);
|
||||||
|
|||||||
Reference in New Issue
Block a user