Skip to content

Commit 9fa9938

Browse files
Add screen brightness attribute
1 parent 1858ee6 commit 9fa9938

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

backtrace-library/src/main/java/backtraceio/library/models/json/BacktraceAttributes.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import android.content.pm.PackageManager;
55
import android.content.res.Configuration;
66
import android.os.Build;
7+
import android.provider.Settings;
78
import android.util.DisplayMetrics;
89
import android.view.Display;
910
import android.view.WindowManager;
@@ -64,7 +65,7 @@ public Map<String, Object> getComplexAttributes() {
6465
private void setDeviceInformation() {
6566
this.attributes.put("uname.version", Build.VERSION.RELEASE);
6667
this.attributes.put("culture", Locale.getDefault().getDisplayLanguage());
67-
this.attributes.put("build.type", BuildConfig.DEBUG ? "Debug": "Release");
68+
this.attributes.put("build.type", BuildConfig.DEBUG ? "Debug" : "Release");
6869
this.attributes.put("device.model", Build.MODEL);
6970
this.attributes.put("device.brand", Build.BRAND);
7071
this.attributes.put("device.product", Build.PRODUCT);
@@ -101,10 +102,9 @@ private void setScreenInformation() {
101102
this.attributes.put("screen.height", metrics.heightPixels);
102103
this.attributes.put("screen.dpi", metrics.densityDpi);
103104
this.attributes.put("screen.orientation", getScreenOrientation().toString());
105+
this.attributes.put("screen.brightness", getScreenBrightness());
104106
}
105107

106-
107-
108108
/**
109109
* Set information about exception (message and classifier)
110110
*
@@ -138,6 +138,18 @@ private ScreenOrientation getScreenOrientation() {
138138
return ScreenOrientation.UNDEFINED;
139139
}
140140

141+
/**
142+
* Get screen brightness value
143+
*
144+
* @return screen backlight brightness between 0 and 255
145+
*/
146+
private int getScreenBrightness() {
147+
return Settings.System.getInt(
148+
this.context.getContentResolver(),
149+
Settings.System.SCREEN_BRIGHTNESS,
150+
0);
151+
}
152+
141153
/**
142154
* Divide custom user attributes into primitive and complex attributes and add to this object
143155
*

0 commit comments

Comments
 (0)