Skip to content

Commit 05b6124

Browse files
Update DeviceInfo.java
1 parent b01c13a commit 05b6124

1 file changed

Lines changed: 33 additions & 1 deletion

File tree

sdk/src/main/java/ly/count/android/sdk/DeviceInfo.java

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,19 @@ public String getManufacturer() {
101101
return Build.MANUFACTURER;
102102
}
103103

104+
/**
105+
* Returns the non-scaled pixel resolution of the current default display being used by the
106+
* WindowManager in the specified context.
107+
*
108+
* @param context context to use to retrieve the current WindowManager
109+
* @return a string in the format "WxH", or the empty string "" if resolution cannot be determined
110+
*/
104111
@NonNull
105112
@Override
106113
public String getResolution(@NonNull final Context context) {
114+
// user reported NPE in this method; that means either getSystemService or getDefaultDisplay
115+
// were returning null, even though the documentation doesn't say they should do so; so now
116+
// we catch Throwable and return empty string if that happens
107117
String ov = DeviceInfo.this.mpOverride.getResolution(context);
108118
if (ov != null) return ov;
109119
String resolution = "";
@@ -204,6 +214,11 @@ public String getLocale() {
204214
return locale.getLanguage() + "_" + locale.getCountry();
205215
}
206216

217+
/**
218+
* Returns the application version string stored in the specified
219+
* context's package info versionName field, or "1.0" if versionName
220+
* is not present.
221+
*/
207222
@NonNull
208223
@Override
209224
public String getAppVersion(@NonNull final Context context) {
@@ -221,6 +236,9 @@ public String getAppVersion(@NonNull final Context context) {
221236
return result;
222237
}
223238

239+
/**
240+
* Returns the package name of the app that installed this app
241+
*/
224242
@NonNull
225243
@Override
226244
public String getStore(@NonNull final Context context) {
@@ -239,6 +257,11 @@ public String getStore(@NonNull final Context context) {
239257
return result;
240258
}
241259

260+
/**
261+
* Returns what kind of device this is. The potential values are:
262+
* ["console", "mobile", "tablet", "smarttv", "wearable", "embedded", "desktop"]
263+
* Currently the Android SDK differentiates between ["mobile", "tablet", "smarttv"]
264+
*/
242265
@NonNull
243266
@Override
244267
public String getDeviceType(@NonNull final Context context) {
@@ -260,6 +283,10 @@ public String getTotalRAM() {
260283
return Long.toString(getTotalRAMInternal());
261284
}
262285

286+
287+
/**
288+
* Returns the current device RAM amount.
289+
*/
263290
@NonNull
264291
@Override
265292
public String getRamCurrent(Context context) {
@@ -271,6 +298,9 @@ public String getRamCurrent(Context context) {
271298
return Long.toString(getTotalRAMInternal() - (mi.availMem / 1_048_576L));
272299
}
273300

301+
/**
302+
* Returns the total device RAM amount.
303+
*/
274304
@NonNull
275305
@Override
276306
public String getRamTotal() {
@@ -296,11 +326,12 @@ public String getOpenGL(Context context) {
296326
FeatureInfo[] featureInfos = packageManager.getSystemAvailableFeatures();
297327
if (featureInfos != null && featureInfos.length > 0) {
298328
for (FeatureInfo featureInfo : featureInfos) {
329+
// Null feature name means this feature is the open gl es version feature.
299330
if (featureInfo.name == null) {
300331
if (featureInfo.reqGlEsVersion != FeatureInfo.GL_ES_VERSION_UNDEFINED) {
301332
return Integer.toString((featureInfo.reqGlEsVersion & 0xffff0000) >> 16);
302333
} else {
303-
return "1";
334+
return "1"; // Lack of property means OpenGL ES version 1
304335
}
305336
}
306337
}
@@ -369,6 +400,7 @@ public String getBatteryLevel(Context context) {
369400
if (batteryIntent != null) {
370401
int level = batteryIntent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
371402
int scale = batteryIntent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
403+
// Error checking that probably isn't needed but I added just in case.
372404
if (level > -1 && scale > 0) {
373405
return Float.toString(((float) level / (float) scale) * 100.0f);
374406
}

0 commit comments

Comments
 (0)