@@ -47,6 +47,8 @@ public final class DeviceInfoUtil {
4747 private final @ Nullable ContextUtils .SideLoadedInfo sideLoadedInfo ;
4848 private final @ NotNull OperatingSystem os ;
4949
50+ private final @ Nullable Long totalMem ;
51+
5052 public DeviceInfoUtil (
5153 final @ NotNull Context context , final @ NotNull SentryAndroidOptions options ) {
5254 this .context = context ;
@@ -59,6 +61,13 @@ public DeviceInfoUtil(
5961 isEmulator = buildInfoProvider .isEmulator ();
6062 sideLoadedInfo =
6163 ContextUtils .retrieveSideLoadedInfo (context , options .getLogger (), buildInfoProvider );
64+ final @ Nullable ActivityManager .MemoryInfo memInfo =
65+ ContextUtils .getMemInfo (context , options .getLogger ());
66+ if (memInfo != null ) {
67+ totalMem = getMemorySize (memInfo );
68+ } else {
69+ totalMem = null ;
70+ }
6271 }
6372
6473 @ NotNull
@@ -132,6 +141,8 @@ public Device collectDeviceInformation(
132141 device .setProcessorCount (cpuFrequencies .size ());
133142 }
134143
144+ device .setMemorySize (totalMem );
145+
135146 // setting such values require IO hence we don't run for transactions
136147 if (collectDeviceIO && options .isCollectAdditionalContext ()) {
137148 setDeviceIO (device , collectDynamicData );
@@ -194,15 +205,10 @@ private void setDeviceIO(final @NotNull Device device, final boolean includeDyna
194205
195206 final @ Nullable ActivityManager .MemoryInfo memInfo =
196207 ContextUtils .getMemInfo (context , options .getLogger ());
197- if (memInfo != null ) {
208+ if (memInfo != null && includeDynamicData ) {
198209 // in bytes
199- device .setMemorySize (getMemorySize (memInfo ));
200- if (includeDynamicData ) {
201- device .setFreeMemory (memInfo .availMem );
202- device .setLowMemory (memInfo .lowMemory );
203- }
204- // there are runtime.totalMemory() and runtime.freeMemory(), but I kept the same for
205- // compatibility
210+ device .setFreeMemory (memInfo .availMem );
211+ device .setLowMemory (memInfo .lowMemory );
206212 }
207213
208214 // this way of getting the size of storage might be problematic for storages bigger than 2GB
0 commit comments