Loading core/java/android/util/proto/ProtoInputStream.java +5 −3 Original line number Diff line number Diff line Loading @@ -253,12 +253,14 @@ public final class ProtoInputStream extends ProtoStream { } /** * Attempt to guess the next field. If there is a match, the field data will be ready to read. * If there is no match, nextField will need to be called to get the field number * Reads the tag of the next field from the stream. If previous field value was not read, its * data will be skipped over. If {@code fieldId} matches the next field ID, the field data will * be ready to read. If it does not match, {@link #nextField()} or {@link #nextField(long)} will * need to be called again before the field data can be read. * * @return true if fieldId matches the next field, false if not */ public boolean isNextField(long fieldId) throws IOException { public boolean nextField(long fieldId) throws IOException { if (nextField() == (int) fieldId) { return true; } Loading services/usage/java/com/android/server/usage/UsageStatsProto.java +5 −5 Original line number Diff line number Diff line Loading @@ -44,7 +44,7 @@ final class UsageStatsProto { final long token = proto.start(IntervalStatsProto.STRINGPOOL); List<String> stringPool; if (proto.isNextField(IntervalStatsProto.StringPool.SIZE)) { if (proto.nextField(IntervalStatsProto.StringPool.SIZE)) { stringPool = new ArrayList(proto.readInt(IntervalStatsProto.StringPool.SIZE)); } else { stringPool = new ArrayList(); Loading @@ -66,12 +66,12 @@ final class UsageStatsProto { final long token = proto.start(fieldId); UsageStats stats; if (proto.isNextField(IntervalStatsProto.UsageStats.PACKAGE_INDEX)) { if (proto.nextField(IntervalStatsProto.UsageStats.PACKAGE_INDEX)) { // Fast path reading the package name index. Most cases this should work since it is // written first stats = statsOut.getOrCreateUsageStats( stringPool.get(proto.readInt(IntervalStatsProto.UsageStats.PACKAGE_INDEX) - 1)); } else if (proto.isNextField(IntervalStatsProto.UsageStats.PACKAGE)) { } else if (proto.nextField(IntervalStatsProto.UsageStats.PACKAGE)) { // No package index, try package name instead stats = statsOut.getOrCreateUsageStats( proto.readString(IntervalStatsProto.UsageStats.PACKAGE)); Loading Loading @@ -177,7 +177,7 @@ final class UsageStatsProto { } String action = null; ArrayMap<String, Integer> counts; if (proto.isNextField(IntervalStatsProto.UsageStats.ChooserAction.NAME)) { if (proto.nextField(IntervalStatsProto.UsageStats.ChooserAction.NAME)) { // Fast path reading the action name. Most cases this should work since it is written // first action = proto.readString(IntervalStatsProto.UsageStats.ChooserAction.NAME); Loading Loading @@ -244,7 +244,7 @@ final class UsageStatsProto { boolean configActive = false; final Configuration config = new Configuration(); ConfigurationStats configStats; if (proto.isNextField(IntervalStatsProto.Configuration.CONFIG)) { if (proto.nextField(IntervalStatsProto.Configuration.CONFIG)) { // Fast path reading the configuration. Most cases this should work since it is // written first config.readFromProto(proto, IntervalStatsProto.Configuration.CONFIG); Loading tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamBoolTest.java +12 −12 Original line number Diff line number Diff line Loading @@ -384,55 +384,55 @@ public class ProtoInputStreamBoolTest extends TestCase { }; ProtoInputStream pi = new ProtoInputStream(protobuf); pi.isNextField(fieldId1); pi.nextField(); try { pi.readFloat(fieldId1); fail("Should have throw IllegalArgumentException"); fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); pi.isNextField(fieldId1); pi.nextField(); try { pi.readDouble(fieldId1); fail("Should have throw IllegalArgumentException"); fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); pi.isNextField(fieldId1); pi.nextField(); try { pi.readInt(fieldId1); fail("Should have throw IllegalArgumentException"); fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); pi.isNextField(fieldId1); pi.nextField(); try { pi.readLong(fieldId1); fail("Should have throw IllegalArgumentException"); fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); pi.isNextField(fieldId1); pi.nextField(); try { pi.readBytes(fieldId1); fail("Should have throw IllegalArgumentException"); fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); pi.isNextField(fieldId1); pi.nextField(); try { pi.readString(fieldId1); fail("Should have throw IllegalArgumentException"); fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } Loading tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamBytesTest.java +12 −12 Original line number Diff line number Diff line Loading @@ -306,55 +306,55 @@ public class ProtoInputStreamBytesTest extends TestCase { }; ProtoInputStream pi = new ProtoInputStream(protobuf); pi.isNextField(fieldId1); pi.nextField(); try { pi.readFloat(fieldId1); fail("Should have throw IllegalArgumentException"); fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); pi.isNextField(fieldId1); pi.nextField(); try { pi.readDouble(fieldId1); fail("Should have throw IllegalArgumentException"); fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); pi.isNextField(fieldId1); pi.nextField(); try { pi.readInt(fieldId1); fail("Should have throw IllegalArgumentException"); fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); pi.isNextField(fieldId1); pi.nextField(); try { pi.readLong(fieldId1); fail("Should have throw IllegalArgumentException"); fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); pi.isNextField(fieldId1); pi.nextField(); try { pi.readBoolean(fieldId1); fail("Should have throw IllegalArgumentException"); fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); pi.isNextField(fieldId1); pi.nextField(); try { pi.readString(fieldId1); fail("Should have throw IllegalArgumentException"); fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } Loading tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamDoubleTest.java +12 −12 Original line number Diff line number Diff line Loading @@ -611,55 +611,55 @@ public class ProtoInputStreamDoubleTest extends TestCase { }; ProtoInputStream pi = new ProtoInputStream(protobuf); pi.isNextField(fieldId1); pi.nextField(); try { pi.readFloat(fieldId1); fail("Should have throw IllegalArgumentException"); fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); pi.isNextField(fieldId1); pi.nextField(); try { pi.readBoolean(fieldId1); fail("Should have throw IllegalArgumentException"); fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); pi.isNextField(fieldId1); pi.nextField(); try { pi.readInt(fieldId1); fail("Should have throw IllegalArgumentException"); fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); pi.isNextField(fieldId1); pi.nextField(); try { pi.readLong(fieldId1); fail("Should have throw IllegalArgumentException"); fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); pi.isNextField(fieldId1); pi.nextField(); try { pi.readBytes(fieldId1); fail("Should have throw IllegalArgumentException"); fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); pi.isNextField(fieldId1); pi.nextField(); try { pi.readString(fieldId1); fail("Should have throw IllegalArgumentException"); fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } Loading Loading
core/java/android/util/proto/ProtoInputStream.java +5 −3 Original line number Diff line number Diff line Loading @@ -253,12 +253,14 @@ public final class ProtoInputStream extends ProtoStream { } /** * Attempt to guess the next field. If there is a match, the field data will be ready to read. * If there is no match, nextField will need to be called to get the field number * Reads the tag of the next field from the stream. If previous field value was not read, its * data will be skipped over. If {@code fieldId} matches the next field ID, the field data will * be ready to read. If it does not match, {@link #nextField()} or {@link #nextField(long)} will * need to be called again before the field data can be read. * * @return true if fieldId matches the next field, false if not */ public boolean isNextField(long fieldId) throws IOException { public boolean nextField(long fieldId) throws IOException { if (nextField() == (int) fieldId) { return true; } Loading
services/usage/java/com/android/server/usage/UsageStatsProto.java +5 −5 Original line number Diff line number Diff line Loading @@ -44,7 +44,7 @@ final class UsageStatsProto { final long token = proto.start(IntervalStatsProto.STRINGPOOL); List<String> stringPool; if (proto.isNextField(IntervalStatsProto.StringPool.SIZE)) { if (proto.nextField(IntervalStatsProto.StringPool.SIZE)) { stringPool = new ArrayList(proto.readInt(IntervalStatsProto.StringPool.SIZE)); } else { stringPool = new ArrayList(); Loading @@ -66,12 +66,12 @@ final class UsageStatsProto { final long token = proto.start(fieldId); UsageStats stats; if (proto.isNextField(IntervalStatsProto.UsageStats.PACKAGE_INDEX)) { if (proto.nextField(IntervalStatsProto.UsageStats.PACKAGE_INDEX)) { // Fast path reading the package name index. Most cases this should work since it is // written first stats = statsOut.getOrCreateUsageStats( stringPool.get(proto.readInt(IntervalStatsProto.UsageStats.PACKAGE_INDEX) - 1)); } else if (proto.isNextField(IntervalStatsProto.UsageStats.PACKAGE)) { } else if (proto.nextField(IntervalStatsProto.UsageStats.PACKAGE)) { // No package index, try package name instead stats = statsOut.getOrCreateUsageStats( proto.readString(IntervalStatsProto.UsageStats.PACKAGE)); Loading Loading @@ -177,7 +177,7 @@ final class UsageStatsProto { } String action = null; ArrayMap<String, Integer> counts; if (proto.isNextField(IntervalStatsProto.UsageStats.ChooserAction.NAME)) { if (proto.nextField(IntervalStatsProto.UsageStats.ChooserAction.NAME)) { // Fast path reading the action name. Most cases this should work since it is written // first action = proto.readString(IntervalStatsProto.UsageStats.ChooserAction.NAME); Loading Loading @@ -244,7 +244,7 @@ final class UsageStatsProto { boolean configActive = false; final Configuration config = new Configuration(); ConfigurationStats configStats; if (proto.isNextField(IntervalStatsProto.Configuration.CONFIG)) { if (proto.nextField(IntervalStatsProto.Configuration.CONFIG)) { // Fast path reading the configuration. Most cases this should work since it is // written first config.readFromProto(proto, IntervalStatsProto.Configuration.CONFIG); Loading
tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamBoolTest.java +12 −12 Original line number Diff line number Diff line Loading @@ -384,55 +384,55 @@ public class ProtoInputStreamBoolTest extends TestCase { }; ProtoInputStream pi = new ProtoInputStream(protobuf); pi.isNextField(fieldId1); pi.nextField(); try { pi.readFloat(fieldId1); fail("Should have throw IllegalArgumentException"); fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); pi.isNextField(fieldId1); pi.nextField(); try { pi.readDouble(fieldId1); fail("Should have throw IllegalArgumentException"); fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); pi.isNextField(fieldId1); pi.nextField(); try { pi.readInt(fieldId1); fail("Should have throw IllegalArgumentException"); fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); pi.isNextField(fieldId1); pi.nextField(); try { pi.readLong(fieldId1); fail("Should have throw IllegalArgumentException"); fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); pi.isNextField(fieldId1); pi.nextField(); try { pi.readBytes(fieldId1); fail("Should have throw IllegalArgumentException"); fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); pi.isNextField(fieldId1); pi.nextField(); try { pi.readString(fieldId1); fail("Should have throw IllegalArgumentException"); fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } Loading
tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamBytesTest.java +12 −12 Original line number Diff line number Diff line Loading @@ -306,55 +306,55 @@ public class ProtoInputStreamBytesTest extends TestCase { }; ProtoInputStream pi = new ProtoInputStream(protobuf); pi.isNextField(fieldId1); pi.nextField(); try { pi.readFloat(fieldId1); fail("Should have throw IllegalArgumentException"); fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); pi.isNextField(fieldId1); pi.nextField(); try { pi.readDouble(fieldId1); fail("Should have throw IllegalArgumentException"); fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); pi.isNextField(fieldId1); pi.nextField(); try { pi.readInt(fieldId1); fail("Should have throw IllegalArgumentException"); fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); pi.isNextField(fieldId1); pi.nextField(); try { pi.readLong(fieldId1); fail("Should have throw IllegalArgumentException"); fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); pi.isNextField(fieldId1); pi.nextField(); try { pi.readBoolean(fieldId1); fail("Should have throw IllegalArgumentException"); fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); pi.isNextField(fieldId1); pi.nextField(); try { pi.readString(fieldId1); fail("Should have throw IllegalArgumentException"); fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } Loading
tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamDoubleTest.java +12 −12 Original line number Diff line number Diff line Loading @@ -611,55 +611,55 @@ public class ProtoInputStreamDoubleTest extends TestCase { }; ProtoInputStream pi = new ProtoInputStream(protobuf); pi.isNextField(fieldId1); pi.nextField(); try { pi.readFloat(fieldId1); fail("Should have throw IllegalArgumentException"); fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); pi.isNextField(fieldId1); pi.nextField(); try { pi.readBoolean(fieldId1); fail("Should have throw IllegalArgumentException"); fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); pi.isNextField(fieldId1); pi.nextField(); try { pi.readInt(fieldId1); fail("Should have throw IllegalArgumentException"); fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); pi.isNextField(fieldId1); pi.nextField(); try { pi.readLong(fieldId1); fail("Should have throw IllegalArgumentException"); fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); pi.isNextField(fieldId1); pi.nextField(); try { pi.readBytes(fieldId1); fail("Should have throw IllegalArgumentException"); fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); pi.isNextField(fieldId1); pi.nextField(); try { pi.readString(fieldId1); fail("Should have throw IllegalArgumentException"); fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } Loading