Skip to content

Commit

Permalink
Include screen size details in debuglogs.
Browse files Browse the repository at this point in the history
  • Loading branch information
greyson-signal committed Apr 21, 2020
1 parent 37a35e8 commit fb16370
Showing 1 changed file with 44 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import android.content.pm.PackageManager;
import android.os.Build;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.view.WindowManager;

import androidx.annotation.NonNull;

Expand All @@ -14,9 +16,10 @@
import org.thoughtcrime.securesms.util.Util;

import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;

public class LogSectionSystemInfo implements LogSection {

Expand All @@ -34,6 +37,10 @@ public class LogSectionSystemInfo implements LogSection {
builder.append("Manufacturer : ").append(Build.MANUFACTURER).append("\n");
builder.append("Model : ").append(Build.MODEL).append("\n");
builder.append("Product : ").append(Build.PRODUCT).append("\n");
builder.append("Screen : ").append(getScreenResolution(context)).append(", ")
.append(getScreenDensityClass(context)).append(", ")
.append(getScreenRefreshRate(context)).append("\n");
builder.append("Font Scale : ").append(context.getResources().getConfiguration().fontScale).append("\n");
builder.append("Android : ").append(Build.VERSION.RELEASE).append(" (")
.append(Build.VERSION.INCREMENTAL).append(", ")
.append(Build.DISPLAY).append(")\n");
Expand Down Expand Up @@ -91,4 +98,40 @@ public class LogSectionSystemInfo implements LogSection {
return abis;
}
}

private static @NonNull String getScreenResolution(@NonNull Context context) {
DisplayMetrics displayMetrics = new DisplayMetrics();
WindowManager windowManager = ServiceUtil.getWindowManager(context);

windowManager.getDefaultDisplay().getMetrics(displayMetrics);
return displayMetrics.widthPixels + "x" + displayMetrics.heightPixels;
}

private static @NonNull String getScreenDensityClass(@NonNull Context context) {
int density = context.getResources().getDisplayMetrics().densityDpi;

LinkedHashMap<Integer, String> levels = new LinkedHashMap<Integer, String>() {{
put(DisplayMetrics.DENSITY_LOW, "ldpi");
put(DisplayMetrics.DENSITY_MEDIUM, "mdpi");
put(DisplayMetrics.DENSITY_HIGH, "hdpi");
put(DisplayMetrics.DENSITY_XHIGH, "xhdpi");
put(DisplayMetrics.DENSITY_XXHIGH, "xxhdpi");
put(DisplayMetrics.DENSITY_XXXHIGH, "xxxhdpi");
}};

String densityString = "unknown";

for (Map.Entry<Integer, String> entry : levels.entrySet()) {
densityString = entry.getValue();
if (entry.getKey() > density) {
break;
}
}

return densityString + " (" + density + ")";
}

private static @NonNull String getScreenRefreshRate(@NonNull Context context) {
return String.format(Locale.ENGLISH, "%.2f hz", ServiceUtil.getWindowManager(context).getDefaultDisplay().getRefreshRate());
}
}

0 comments on commit fb16370

Please sign in to comment.