-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Moving network provider tools to services * Moving network service related tests * Moving network attr init feature to the agent * Making network instrumentation depend on the agent * Initializing CurrentNetworkProvider as service * Clean up config * Created NetworkChangeInstrumentation * Updated network monitor tests * Clean up * Renaming installOn by start * Adding internal class docs * Fixing visible for tests comment * Rename .java to .kt * Removing Carrier.Builder
- Loading branch information
1 parent
a14dcaf
commit 42635e1
Showing
35 changed files
with
330 additions
and
417 deletions.
There are no files selected for viewing
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
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
50 changes: 50 additions & 0 deletions
50
...agent/src/main/java/io/opentelemetry/android/internal/services/network/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,50 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.android.internal.services.network; | ||
|
||
import android.os.Build; | ||
import android.telephony.TelephonyManager; | ||
import androidx.annotation.RequiresApi; | ||
import io.opentelemetry.android.internal.services.network.data.Carrier; | ||
|
||
/** | ||
* This class is internal and not for public use. Its APIs are unstable and can change at any time. | ||
*/ | ||
@RequiresApi(api = Build.VERSION_CODES.P) | ||
public class CarrierFinder { | ||
|
||
private final TelephonyManager telephonyManager; | ||
|
||
public CarrierFinder(TelephonyManager telephonyManager) { | ||
this.telephonyManager = telephonyManager; | ||
} | ||
|
||
public Carrier get() { | ||
int id = telephonyManager.getSimCarrierId(); | ||
String name = null; | ||
String mobileCountryCode = null; | ||
String mobileNetworkCode = null; | ||
String isoCountryCode = null; | ||
CharSequence simCarrierIdName = telephonyManager.getSimCarrierIdName(); | ||
if (validString(simCarrierIdName)) { | ||
name = simCarrierIdName.toString(); | ||
} | ||
String simOperator = telephonyManager.getSimOperator(); | ||
if (validString(simOperator) && simOperator.length() >= 5) { | ||
mobileCountryCode = simOperator.substring(0, 3); | ||
mobileNetworkCode = simOperator.substring(3); | ||
} | ||
String providedIsoCountryCode = telephonyManager.getSimCountryIso(); | ||
if (validString(providedIsoCountryCode)) { | ||
isoCountryCode = providedIsoCountryCode; | ||
} | ||
return new Carrier(id, name, mobileCountryCode, mobileNetworkCode, isoCountryCode); | ||
} | ||
|
||
private boolean validString(CharSequence str) { | ||
return !(str == null || str.length() == 0); | ||
} | ||
} |
Oops, something went wrong.