-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add carrier information to spans (#358)
* overload constructor for null * Add CarrierFinder and add Carrier to CurrentNetwork. * spotless * relax Q to P * add builder for CurrentNetwork * change type and eliminate double null check * rename class to match version 28 * set NET_HOST_CONNECTION_TYPE in common method * change optional to null * regen tostring * address review suggestions * fix test NPE * remove unused constructor
- Loading branch information
1 parent
c6bbbf4
commit d237fc1
Showing
19 changed files
with
585 additions
and
235 deletions.
There are no files selected for viewing
123 changes: 123 additions & 0 deletions
123
splunk-otel-android/src/main/java/com/splunk/rum/Carrier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
/* | ||
* Copyright Splunk Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.splunk.rum; | ||
|
||
import android.os.Build; | ||
import android.telephony.TelephonyManager; | ||
import androidx.annotation.Nullable; | ||
import androidx.annotation.RequiresApi; | ||
import java.util.Objects; | ||
|
||
@RequiresApi(api = Build.VERSION_CODES.P) | ||
class Carrier { | ||
|
||
private final int id; | ||
private final @Nullable String name; | ||
private final @Nullable String mobileCountryCode; // 3 digits | ||
private final @Nullable String mobileNetworkCode; // 2 or 3 digits | ||
private final @Nullable String isoCountryCode; | ||
|
||
static Builder builder() { | ||
return new Builder(); | ||
} | ||
|
||
Carrier(Builder builder) { | ||
this.id = builder.id; | ||
this.name = builder.name; | ||
this.mobileCountryCode = builder.mobileCountryCode; | ||
this.mobileNetworkCode = builder.mobileNetworkCode; | ||
this.isoCountryCode = builder.isoCountryCode; | ||
} | ||
|
||
int getId() { | ||
return id; | ||
} | ||
|
||
@Nullable | ||
String getName() { | ||
return name; | ||
} | ||
|
||
@Nullable | ||
String getMobileCountryCode() { | ||
return mobileCountryCode; | ||
} | ||
|
||
@Nullable | ||
String getMobileNetworkCode() { | ||
return mobileNetworkCode; | ||
} | ||
|
||
@Nullable | ||
String getIsoCountryCode() { | ||
return isoCountryCode; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
Carrier carrier = (Carrier) o; | ||
return id == carrier.id | ||
&& Objects.equals(name, carrier.name) | ||
&& Objects.equals(mobileCountryCode, carrier.mobileCountryCode) | ||
&& Objects.equals(mobileNetworkCode, carrier.mobileNetworkCode) | ||
&& Objects.equals(isoCountryCode, carrier.isoCountryCode); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(id, name, mobileCountryCode, mobileNetworkCode, isoCountryCode); | ||
} | ||
|
||
static class Builder { | ||
private int id = TelephonyManager.UNKNOWN_CARRIER_ID; | ||
private @Nullable String name = null; | ||
private @Nullable String mobileCountryCode = null; | ||
private @Nullable String mobileNetworkCode = null; | ||
private @Nullable String isoCountryCode = null; | ||
|
||
Carrier build() { | ||
return new Carrier(this); | ||
} | ||
|
||
Builder id(int id) { | ||
this.id = id; | ||
return this; | ||
} | ||
|
||
Builder name(String name) { | ||
this.name = name; | ||
return this; | ||
} | ||
|
||
Builder mobileCountryCode(String countryCode) { | ||
this.mobileCountryCode = countryCode; | ||
return this; | ||
} | ||
|
||
Builder mobileNetworkCode(String networkCode) { | ||
this.mobileNetworkCode = networkCode; | ||
return this; | ||
} | ||
|
||
Builder isoCountryCode(String isoCountryCode) { | ||
this.isoCountryCode = isoCountryCode; | ||
return this; | ||
} | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
splunk-otel-android/src/main/java/com/splunk/rum/CarrierFinder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright Splunk Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.splunk.rum; | ||
|
||
import android.os.Build; | ||
import android.telephony.TelephonyManager; | ||
import androidx.annotation.RequiresApi; | ||
|
||
@RequiresApi(api = Build.VERSION_CODES.P) | ||
class CarrierFinder { | ||
|
||
private final TelephonyManager telephonyManager; | ||
|
||
CarrierFinder(TelephonyManager telephonyManager) { | ||
this.telephonyManager = telephonyManager; | ||
} | ||
|
||
Carrier get() { | ||
Carrier.Builder builder = Carrier.builder(); | ||
int id = telephonyManager.getSimCarrierId(); | ||
builder.id(id); | ||
CharSequence name = telephonyManager.getSimCarrierIdName(); | ||
if (validString(name)) { | ||
builder.name(name.toString()); | ||
} | ||
String simOperator = telephonyManager.getSimOperator(); | ||
if (validString(simOperator) && simOperator.length() >= 5) { | ||
String countryCode = simOperator.substring(0, 3); | ||
String networkCode = simOperator.substring(3); | ||
builder.mobileCountryCode(countryCode).mobileNetworkCode(networkCode); | ||
} | ||
String isoCountryCode = telephonyManager.getSimCountryIso(); | ||
if (validString(isoCountryCode)) { | ||
builder.isoCountryCode(isoCountryCode); | ||
} | ||
return builder.build(); | ||
} | ||
|
||
private boolean validString(CharSequence str) { | ||
return !(str == null || str.length() == 0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.