Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@
.externalNativeBuild
.cxx
local.properties

android.jar
2 changes: 2 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 23 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,36 @@ android {
namespace 'gay.nullby.carriername'
compileSdk 33

signingConfigs {
release {
if (project.properties['keyStore.release.storeFile'] != null) {
storeFile file(project.properties['keyStore.release.storeFile'])
storePassword project.properties['keyStore.release.storePassword']
keyAlias project.properties['keyStore.release.keyAlias']
keyPassword project.properties['keyStore.release.keyPassword']
}
}
}

defaultConfig {
applicationId "gay.nullby.carriername"
minSdk 28
targetSdk 33
versionCode 2
versionName "1.1"
versionName "1.1.1"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
minifyEnabled false
signingConfig signingConfigs.release
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
debug {
signingConfig signingConfigs.release
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
Expand All @@ -36,6 +51,12 @@ android {
}

dependencies {
// Download android.jar from the following url and put it in the root directory of the project
// https://github.com/Reginer/aosp-android-jar/raw/refs/heads/main/android-33/android.jar
final androidJar = file('../android.jar')
if (androidJar.exists()) {
compileOnly files(androidJar)
}

implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.6.0'
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/gay/nullby/carriername/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class MainActivity : AppCompatActivity() {
setSupportActionBar(binding.toolbar)

val navController = findNavController(R.id.nav_host_fragment_content_main)
appBarConfiguration = AppBarConfiguration(navController.graph)
appBarConfiguration = AppBarConfiguration(setOf(R.id.FirstFragment, R.id.TargetFragment))
setupActionBarWithNavController(navController, appBarConfiguration)
}

Expand Down
17 changes: 13 additions & 4 deletions app/src/main/java/gay/nullby/carriername/TargetFragment.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package gay.nullby.carriername

import android.content.Context
import android.os.Build
import android.os.Bundle
import android.os.PersistableBundle
import android.telephony.CarrierConfigManager
Expand All @@ -17,6 +18,7 @@ import android.widget.EditText
import android.widget.RadioButton
import android.widget.RadioGroup
import android.widget.Toast
import com.android.internal.R.attr.country
import com.android.internal.telephony.ICarrierConfigLoader
import gay.nullby.carriername.databinding.FragmentTargetBinding
import rikka.shizuku.ShizukuBinderWrapper
Expand Down Expand Up @@ -54,11 +56,11 @@ class TargetFragment : Fragment() {

if (_subId1 != null) {
subId1 = _subId1[0]
view.findViewById<RadioButton>(R.id.sub1_button).text = "Network 1 (carrier: ${getCarrierNameBySubId(subId1)})"
view.findViewById<RadioButton>(R.id.sub1_button).text = "Network 1 (carrier: ${getCarrierInfoBySubId(subId1)})"
}
if (_subId2 != null) {
subId2 = _subId2[0]
view.findViewById<RadioButton>(R.id.sub2_button).text = "Network 2 (carrier: ${getCarrierNameBySubId(subId2)})"
view.findViewById<RadioButton>(R.id.sub2_button).text = "Network 2 (carrier: ${getCarrierInfoBySubId(subId2)})"
}

if (subId2 == -1) {
Expand Down Expand Up @@ -132,10 +134,17 @@ class TargetFragment : Fragment() {
}
}

private fun getCarrierNameBySubId(subId: Int): String {
private fun getCarrierInfoBySubId(subId: Int): String {
val telephonyManager = context!!.getSystemService(Context.TELEPHONY_SERVICE) as? TelephonyManager
?: return ""
return telephonyManager.getNetworkOperatorName(subId)
val networkName = telephonyManager.getNetworkOperatorName(subId)
val networkCountry = (if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
SubscriptionManager.getSlotIndex(subId)
.takeIf { it != SubscriptionManager.SIM_NOT_INSERTED }
?.let { telephonyManager.getNetworkCountryIso(it) }
} else null) ?: "Unknown"
val simCountry = TelephonyManager.getSimCountryIso(subId)
return "$networkName - $simCountry"
}

private fun overrideCarrierConfig(subId: Int, p: PersistableBundle?) {
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/navigation/nav_graph.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

<action
android:id="@+id/action_setup_to_target"
app:popUpTo="@id/FirstFragment"
app:popUpToInclusive="true"
app:destination="@id/TargetFragment" />
</fragment>
<fragment
Expand Down