Loading core/java/android/util/MemoryIntArray.java +11 −9 Original line number Diff line number Diff line Loading @@ -58,6 +58,7 @@ public final class MemoryIntArray implements Parcelable, Closeable { private final boolean mIsOwner; private final long mMemoryAddr; private final int mSize; private int mFd = -1; /** Loading @@ -75,6 +76,9 @@ public final class MemoryIntArray implements Parcelable, Closeable { final String name = UUID.randomUUID().toString(); mFd = nativeCreate(name, size); mMemoryAddr = nativeOpen(mFd, mIsOwner); // Note that we use the effective size after allocation, rather than the provided size, // preserving compat with the original behavior. In practice these should be equivalent. mSize = nativeSize(mFd); mCloseGuard.open("MemoryIntArray.close"); } Loading @@ -86,6 +90,7 @@ public final class MemoryIntArray implements Parcelable, Closeable { } mFd = pfd.detachFd(); mMemoryAddr = nativeOpen(mFd, mIsOwner); mSize = nativeSize(mFd); mCloseGuard.open("MemoryIntArray.close"); } Loading Loading @@ -127,13 +132,11 @@ public final class MemoryIntArray implements Parcelable, Closeable { } /** * Gets the array size. * * @throws IOException If an error occurs while accessing the shared memory. * @return Gets the array size. */ public int size() throws IOException { public int size() { enforceNotClosed(); return nativeSize(mFd); return mSize; } /** Loading Loading @@ -210,11 +213,10 @@ public final class MemoryIntArray implements Parcelable, Closeable { } } private void enforceValidIndex(int index) throws IOException { final int size = size(); if (index < 0 || index > size - 1) { private void enforceValidIndex(int index) { if (index < 0 || index > mSize - 1) { throw new IndexOutOfBoundsException( index + " not between 0 and " + (size - 1)); index + " not between 0 and " + (mSize - 1)); } } Loading core/tests/utiltests/src/android/util/MemoryIntArrayTest.java +1 −1 Original line number Diff line number Diff line Loading @@ -123,7 +123,7 @@ public class MemoryIntArrayTest { parcel.recycle(); assertNotNull("Should marshall file descriptor", secondArray); assertEquals("Marshalled size must be three", 3, secondArray.size()); assertEquals("First element should be 1", 1, secondArray.get(0)); assertEquals("First element should be 2", 2, secondArray.get(1)); assertEquals("First element should be 3", 3, secondArray.get(2)); Loading core/tests/utiltests/src/android/util/RemoteMemoryIntArrayService.java +1 −5 Original line number Diff line number Diff line Loading @@ -84,11 +84,7 @@ public class RemoteMemoryIntArrayService extends Service { @Override public int size() { synchronized (mLock) { try { return mArray.size(); } catch (IOException e) { throw new IllegalStateException(e); } } } Loading packages/SettingsProvider/src/com/android/providers/settings/GenerationRegistry.java +3 −9 Original line number Diff line number Diff line Loading @@ -308,11 +308,8 @@ final class GenerationRegistry { final long token = proto.start(GenerationRegistryProto.BACKING_STORES); final int key = mKeyToBackingStoreMap.keyAt(i); proto.write(BackingStoreProto.KEY, key); try { proto.write(BackingStoreProto.BACKING_STORE_SIZE, mKeyToBackingStoreMap.valueAt(i).size()); } catch (IOException ignore) { } proto.write(BackingStoreProto.NUM_CACHED_ENTRIES, mKeyToIndexMapMap.get(key).size()); final ArrayMap<String, Integer> indexMap = mKeyToIndexMapMap.get(key); Loading Loading @@ -357,10 +354,7 @@ final class GenerationRegistry { pw.print("_Backing store for type:"); pw.print(SettingsState.settingTypeToString( SettingsState.getTypeFromKey(key))); pw.print(" user:"); pw.print(SettingsState.getUserIdFromKey(key)); try { pw.print(" size:" + mKeyToBackingStoreMap.valueAt(i).size()); } catch (IOException ignore) { } pw.println(" cachedEntries:" + mKeyToIndexMapMap.get(key).size()); final ArrayMap<String, Integer> indexMap = mKeyToIndexMapMap.get(key); final MemoryIntArray backingStore = getBackingStoreLocked(key, Loading Loading
core/java/android/util/MemoryIntArray.java +11 −9 Original line number Diff line number Diff line Loading @@ -58,6 +58,7 @@ public final class MemoryIntArray implements Parcelable, Closeable { private final boolean mIsOwner; private final long mMemoryAddr; private final int mSize; private int mFd = -1; /** Loading @@ -75,6 +76,9 @@ public final class MemoryIntArray implements Parcelable, Closeable { final String name = UUID.randomUUID().toString(); mFd = nativeCreate(name, size); mMemoryAddr = nativeOpen(mFd, mIsOwner); // Note that we use the effective size after allocation, rather than the provided size, // preserving compat with the original behavior. In practice these should be equivalent. mSize = nativeSize(mFd); mCloseGuard.open("MemoryIntArray.close"); } Loading @@ -86,6 +90,7 @@ public final class MemoryIntArray implements Parcelable, Closeable { } mFd = pfd.detachFd(); mMemoryAddr = nativeOpen(mFd, mIsOwner); mSize = nativeSize(mFd); mCloseGuard.open("MemoryIntArray.close"); } Loading Loading @@ -127,13 +132,11 @@ public final class MemoryIntArray implements Parcelable, Closeable { } /** * Gets the array size. * * @throws IOException If an error occurs while accessing the shared memory. * @return Gets the array size. */ public int size() throws IOException { public int size() { enforceNotClosed(); return nativeSize(mFd); return mSize; } /** Loading Loading @@ -210,11 +213,10 @@ public final class MemoryIntArray implements Parcelable, Closeable { } } private void enforceValidIndex(int index) throws IOException { final int size = size(); if (index < 0 || index > size - 1) { private void enforceValidIndex(int index) { if (index < 0 || index > mSize - 1) { throw new IndexOutOfBoundsException( index + " not between 0 and " + (size - 1)); index + " not between 0 and " + (mSize - 1)); } } Loading
core/tests/utiltests/src/android/util/MemoryIntArrayTest.java +1 −1 Original line number Diff line number Diff line Loading @@ -123,7 +123,7 @@ public class MemoryIntArrayTest { parcel.recycle(); assertNotNull("Should marshall file descriptor", secondArray); assertEquals("Marshalled size must be three", 3, secondArray.size()); assertEquals("First element should be 1", 1, secondArray.get(0)); assertEquals("First element should be 2", 2, secondArray.get(1)); assertEquals("First element should be 3", 3, secondArray.get(2)); Loading
core/tests/utiltests/src/android/util/RemoteMemoryIntArrayService.java +1 −5 Original line number Diff line number Diff line Loading @@ -84,11 +84,7 @@ public class RemoteMemoryIntArrayService extends Service { @Override public int size() { synchronized (mLock) { try { return mArray.size(); } catch (IOException e) { throw new IllegalStateException(e); } } } Loading
packages/SettingsProvider/src/com/android/providers/settings/GenerationRegistry.java +3 −9 Original line number Diff line number Diff line Loading @@ -308,11 +308,8 @@ final class GenerationRegistry { final long token = proto.start(GenerationRegistryProto.BACKING_STORES); final int key = mKeyToBackingStoreMap.keyAt(i); proto.write(BackingStoreProto.KEY, key); try { proto.write(BackingStoreProto.BACKING_STORE_SIZE, mKeyToBackingStoreMap.valueAt(i).size()); } catch (IOException ignore) { } proto.write(BackingStoreProto.NUM_CACHED_ENTRIES, mKeyToIndexMapMap.get(key).size()); final ArrayMap<String, Integer> indexMap = mKeyToIndexMapMap.get(key); Loading Loading @@ -357,10 +354,7 @@ final class GenerationRegistry { pw.print("_Backing store for type:"); pw.print(SettingsState.settingTypeToString( SettingsState.getTypeFromKey(key))); pw.print(" user:"); pw.print(SettingsState.getUserIdFromKey(key)); try { pw.print(" size:" + mKeyToBackingStoreMap.valueAt(i).size()); } catch (IOException ignore) { } pw.println(" cachedEntries:" + mKeyToIndexMapMap.get(key).size()); final ArrayMap<String, Integer> indexMap = mKeyToIndexMapMap.get(key); final MemoryIntArray backingStore = getBackingStoreLocked(key, Loading