Skip to content

Commit d1b9a2e

Browse files
authored
Add more warning logs in Network detection (#1205)
* Add warning logs when permission or feature check fails * Make slightly less verbose as possible
1 parent 560dc3b commit d1b9a2e

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

services/src/main/java/io/opentelemetry/android/internal/services/network/CarrierFinder.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,22 @@ public CarrierFinder(@NonNull Context context, @NonNull TelephonyManager telepho
3535
@Nullable
3636
public Carrier get() {
3737
if (!hasTelephonyFeature(context)) {
38+
Log.w(
39+
RumConstants.OTEL_RUM_LOG_TAG,
40+
"Cannot determine carrier details: telephony feature missing.");
3841
return null;
3942
}
4043

4144
try {
42-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P
43-
&& hasPhoneStatePermission(context)) {
44-
return getCarrierPostApi28();
45+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
46+
if (hasPhoneStatePermission(context)) {
47+
return getCarrierPostApi28();
48+
} else {
49+
Log.w(
50+
RumConstants.OTEL_RUM_LOG_TAG,
51+
"Missing read phone state permission, using legacy carrier methods.");
52+
return getCarrierPreApi28();
53+
}
4554
} else {
4655
return getCarrierPreApi28();
4756
}

services/src/main/java/io/opentelemetry/android/internal/services/network/detector/NetworkDetectorImpl.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ internal class NetworkDetectorImpl(
108108
@Suppress("MissingPermission")
109109
private fun findSubtype(): String? {
110110
if (!(hasTelephonyFeature(context) && hasPhoneStatePermission(context))) {
111+
Log.w(
112+
RumConstants.OTEL_RUM_LOG_TAG,
113+
"Cannot determine network subtype: missing telephony feature or read phone state permission.",
114+
)
111115
return null
112116
}
113117

0 commit comments

Comments
 (0)