Loading src/com/android/server/connectivity/ipmemorystore/IpMemoryStoreDatabase.java +43 −12 Original line number Diff line number Diff line Loading @@ -72,6 +72,10 @@ public class IpMemoryStoreDatabase { public static final String COLNAME_ASSIGNEDV4ADDRESS = "assignedV4Address"; public static final String COLTYPE_ASSIGNEDV4ADDRESS = "INTEGER"; public static final String COLNAME_ASSIGNEDV4ADDRESSEXPIRY = "assignedV4AddressExpiry"; // The lease expiry timestamp in uint of milliseconds public static final String COLTYPE_ASSIGNEDV4ADDRESSEXPIRY = "BIGINT"; // Please note that the group hint is only a *hint*, hence its name. The client can offer // this information to nudge the grouping in the decision it thinks is right, but it can't // decide for the memory store what is the same L3 network. Loading @@ -90,6 +94,7 @@ public class IpMemoryStoreDatabase { + COLNAME_L2KEY + " " + COLTYPE_L2KEY + " PRIMARY KEY NOT NULL, " + COLNAME_EXPIRYDATE + " " + COLTYPE_EXPIRYDATE + ", " + COLNAME_ASSIGNEDV4ADDRESS + " " + COLTYPE_ASSIGNEDV4ADDRESS + ", " + COLNAME_ASSIGNEDV4ADDRESSEXPIRY + " " + COLTYPE_ASSIGNEDV4ADDRESSEXPIRY + ", " + COLNAME_GROUPHINT + " " + COLTYPE_GROUPHINT + ", " + COLNAME_DNSADDRESSES + " " + COLTYPE_DNSADDRESSES + ", " + COLNAME_MTU + " " + COLTYPE_MTU + ")"; Loading Loading @@ -134,7 +139,7 @@ public class IpMemoryStoreDatabase { /** The SQLite DB helper */ public static class DbHelper extends SQLiteOpenHelper { // Update this whenever changing the schema. private static final int SCHEMA_VERSION = 2; private static final int SCHEMA_VERSION = 3; private static final String DATABASE_FILENAME = "IpMemoryStore.db"; public DbHelper(@NonNull final Context context) { Loading @@ -153,11 +158,28 @@ public class IpMemoryStoreDatabase { @Override public void onUpgrade(@NonNull final SQLiteDatabase db, final int oldVersion, final int newVersion) { // No upgrade supported yet. try { if (oldVersion < 2) { // upgrade from version 1 to version 2 // since we starts from version 2, do nothing here } if (oldVersion < 3) { // upgrade from version 2 to version 3 final String sqlUpgradeAddressExpiry = "alter table" + " " + NetworkAttributesContract.TABLENAME + " ADD" + " " + NetworkAttributesContract.COLNAME_ASSIGNEDV4ADDRESSEXPIRY + " " + NetworkAttributesContract.COLTYPE_ASSIGNEDV4ADDRESSEXPIRY; db.execSQL(sqlUpgradeAddressExpiry); } } catch (SQLiteException e) { Log.e(TAG, "Could not upgrade to the new version", e); // create database with new version db.execSQL(NetworkAttributesContract.DROP_TABLE); db.execSQL(PrivateDataContract.DROP_TABLE); onCreate(db); } } /** Called when the database is downgraded */ @Override Loading Loading @@ -204,6 +226,10 @@ public class IpMemoryStoreDatabase { values.put(NetworkAttributesContract.COLNAME_ASSIGNEDV4ADDRESS, inet4AddressToIntHTH(attributes.assignedV4Address)); } if (null != attributes.assignedV4AddressExpiry) { values.put(NetworkAttributesContract.COLNAME_ASSIGNEDV4ADDRESSEXPIRY, attributes.assignedV4AddressExpiry); } if (null != attributes.groupHint) { values.put(NetworkAttributesContract.COLNAME_GROUPHINT, attributes.groupHint); } Loading Loading @@ -251,6 +277,8 @@ public class IpMemoryStoreDatabase { final NetworkAttributes.Builder builder = new NetworkAttributes.Builder(); final int assignedV4AddressInt = getInt(cursor, NetworkAttributesContract.COLNAME_ASSIGNEDV4ADDRESS, 0); final long assignedV4AddressExpiry = getLong(cursor, NetworkAttributesContract.COLNAME_ASSIGNEDV4ADDRESSEXPIRY, 0); final String groupHint = getString(cursor, NetworkAttributesContract.COLNAME_GROUPHINT); final byte[] dnsAddressesBlob = getBlob(cursor, NetworkAttributesContract.COLNAME_DNSADDRESSES); Loading @@ -258,6 +286,9 @@ public class IpMemoryStoreDatabase { if (0 != assignedV4AddressInt) { builder.setAssignedV4Address(intToInet4AddressHTH(assignedV4AddressInt)); } if (0 != assignedV4AddressExpiry) { builder.setAssignedV4AddressExpiry(assignedV4AddressExpiry); } builder.setGroupHint(groupHint); if (null != dnsAddressesBlob) { builder.setDnsAddresses(decodeAddressList(dnsAddressesBlob)); Loading tests/src/com/android/server/connectivity/ipmemorystore/IpMemoryStoreServiceTest.java +4 −1 Original line number Diff line number Diff line Loading @@ -228,6 +228,7 @@ public class IpMemoryStoreServiceTest { public void testNetworkAttributes() throws UnknownHostException { final NetworkAttributes.Builder na = new NetworkAttributes.Builder(); na.setAssignedV4Address((Inet4Address) Inet4Address.getByName("1.2.3.4")); na.setAssignedV4AddressExpiry(System.currentTimeMillis() + 7_200_000); na.setGroupHint("hint1"); na.setMtu(219); final String l2Key = FAKE_KEYS[0]; Loading Loading @@ -257,6 +258,8 @@ public class IpMemoryStoreServiceTest { + status.resultCode, status.isSuccess()); assertEquals(l2Key, key); assertEquals(attributes.assignedV4Address, attr.assignedV4Address); assertEquals(attributes.assignedV4AddressExpiry, attr.assignedV4AddressExpiry); assertEquals(attributes.groupHint, attr.groupHint); assertEquals(attributes.mtu, attr.mtu); assertEquals(attributes2.dnsAddresses, attr.dnsAddresses); Loading @@ -278,7 +281,7 @@ public class IpMemoryStoreServiceTest { // Verify that this test does not miss any new field added later. // If any field is added to NetworkAttributes it must be tested here for storing // and retrieving. assertEquals(4, Arrays.stream(NetworkAttributes.class.getDeclaredFields()) assertEquals(5, Arrays.stream(NetworkAttributes.class.getDeclaredFields()) .filter(f -> !Modifier.isStatic(f.getModifiers())).count()); } Loading Loading
src/com/android/server/connectivity/ipmemorystore/IpMemoryStoreDatabase.java +43 −12 Original line number Diff line number Diff line Loading @@ -72,6 +72,10 @@ public class IpMemoryStoreDatabase { public static final String COLNAME_ASSIGNEDV4ADDRESS = "assignedV4Address"; public static final String COLTYPE_ASSIGNEDV4ADDRESS = "INTEGER"; public static final String COLNAME_ASSIGNEDV4ADDRESSEXPIRY = "assignedV4AddressExpiry"; // The lease expiry timestamp in uint of milliseconds public static final String COLTYPE_ASSIGNEDV4ADDRESSEXPIRY = "BIGINT"; // Please note that the group hint is only a *hint*, hence its name. The client can offer // this information to nudge the grouping in the decision it thinks is right, but it can't // decide for the memory store what is the same L3 network. Loading @@ -90,6 +94,7 @@ public class IpMemoryStoreDatabase { + COLNAME_L2KEY + " " + COLTYPE_L2KEY + " PRIMARY KEY NOT NULL, " + COLNAME_EXPIRYDATE + " " + COLTYPE_EXPIRYDATE + ", " + COLNAME_ASSIGNEDV4ADDRESS + " " + COLTYPE_ASSIGNEDV4ADDRESS + ", " + COLNAME_ASSIGNEDV4ADDRESSEXPIRY + " " + COLTYPE_ASSIGNEDV4ADDRESSEXPIRY + ", " + COLNAME_GROUPHINT + " " + COLTYPE_GROUPHINT + ", " + COLNAME_DNSADDRESSES + " " + COLTYPE_DNSADDRESSES + ", " + COLNAME_MTU + " " + COLTYPE_MTU + ")"; Loading Loading @@ -134,7 +139,7 @@ public class IpMemoryStoreDatabase { /** The SQLite DB helper */ public static class DbHelper extends SQLiteOpenHelper { // Update this whenever changing the schema. private static final int SCHEMA_VERSION = 2; private static final int SCHEMA_VERSION = 3; private static final String DATABASE_FILENAME = "IpMemoryStore.db"; public DbHelper(@NonNull final Context context) { Loading @@ -153,11 +158,28 @@ public class IpMemoryStoreDatabase { @Override public void onUpgrade(@NonNull final SQLiteDatabase db, final int oldVersion, final int newVersion) { // No upgrade supported yet. try { if (oldVersion < 2) { // upgrade from version 1 to version 2 // since we starts from version 2, do nothing here } if (oldVersion < 3) { // upgrade from version 2 to version 3 final String sqlUpgradeAddressExpiry = "alter table" + " " + NetworkAttributesContract.TABLENAME + " ADD" + " " + NetworkAttributesContract.COLNAME_ASSIGNEDV4ADDRESSEXPIRY + " " + NetworkAttributesContract.COLTYPE_ASSIGNEDV4ADDRESSEXPIRY; db.execSQL(sqlUpgradeAddressExpiry); } } catch (SQLiteException e) { Log.e(TAG, "Could not upgrade to the new version", e); // create database with new version db.execSQL(NetworkAttributesContract.DROP_TABLE); db.execSQL(PrivateDataContract.DROP_TABLE); onCreate(db); } } /** Called when the database is downgraded */ @Override Loading Loading @@ -204,6 +226,10 @@ public class IpMemoryStoreDatabase { values.put(NetworkAttributesContract.COLNAME_ASSIGNEDV4ADDRESS, inet4AddressToIntHTH(attributes.assignedV4Address)); } if (null != attributes.assignedV4AddressExpiry) { values.put(NetworkAttributesContract.COLNAME_ASSIGNEDV4ADDRESSEXPIRY, attributes.assignedV4AddressExpiry); } if (null != attributes.groupHint) { values.put(NetworkAttributesContract.COLNAME_GROUPHINT, attributes.groupHint); } Loading Loading @@ -251,6 +277,8 @@ public class IpMemoryStoreDatabase { final NetworkAttributes.Builder builder = new NetworkAttributes.Builder(); final int assignedV4AddressInt = getInt(cursor, NetworkAttributesContract.COLNAME_ASSIGNEDV4ADDRESS, 0); final long assignedV4AddressExpiry = getLong(cursor, NetworkAttributesContract.COLNAME_ASSIGNEDV4ADDRESSEXPIRY, 0); final String groupHint = getString(cursor, NetworkAttributesContract.COLNAME_GROUPHINT); final byte[] dnsAddressesBlob = getBlob(cursor, NetworkAttributesContract.COLNAME_DNSADDRESSES); Loading @@ -258,6 +286,9 @@ public class IpMemoryStoreDatabase { if (0 != assignedV4AddressInt) { builder.setAssignedV4Address(intToInet4AddressHTH(assignedV4AddressInt)); } if (0 != assignedV4AddressExpiry) { builder.setAssignedV4AddressExpiry(assignedV4AddressExpiry); } builder.setGroupHint(groupHint); if (null != dnsAddressesBlob) { builder.setDnsAddresses(decodeAddressList(dnsAddressesBlob)); Loading
tests/src/com/android/server/connectivity/ipmemorystore/IpMemoryStoreServiceTest.java +4 −1 Original line number Diff line number Diff line Loading @@ -228,6 +228,7 @@ public class IpMemoryStoreServiceTest { public void testNetworkAttributes() throws UnknownHostException { final NetworkAttributes.Builder na = new NetworkAttributes.Builder(); na.setAssignedV4Address((Inet4Address) Inet4Address.getByName("1.2.3.4")); na.setAssignedV4AddressExpiry(System.currentTimeMillis() + 7_200_000); na.setGroupHint("hint1"); na.setMtu(219); final String l2Key = FAKE_KEYS[0]; Loading Loading @@ -257,6 +258,8 @@ public class IpMemoryStoreServiceTest { + status.resultCode, status.isSuccess()); assertEquals(l2Key, key); assertEquals(attributes.assignedV4Address, attr.assignedV4Address); assertEquals(attributes.assignedV4AddressExpiry, attr.assignedV4AddressExpiry); assertEquals(attributes.groupHint, attr.groupHint); assertEquals(attributes.mtu, attr.mtu); assertEquals(attributes2.dnsAddresses, attr.dnsAddresses); Loading @@ -278,7 +281,7 @@ public class IpMemoryStoreServiceTest { // Verify that this test does not miss any new field added later. // If any field is added to NetworkAttributes it must be tested here for storing // and retrieving. assertEquals(4, Arrays.stream(NetworkAttributes.class.getDeclaredFields()) assertEquals(5, Arrays.stream(NetworkAttributes.class.getDeclaredFields()) .filter(f -> !Modifier.isStatic(f.getModifiers())).count()); } Loading