commit 135dd8305eaa9b22f760f0e5f7a724eace37cb85 Author: wenyifan Date: Fri Aug 25 16:09:24 2023 +0800 init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..aa724b7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx +local.properties diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..b589d56 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..ae388c2 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,20 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..773fe0f --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..b9a972a --- /dev/null +++ b/app/.gitignore @@ -0,0 +1,2 @@ +build +release \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..3e8dd10 --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,40 @@ +plugins { + id 'com.android.application' +} + +android { + namespace 'run.evan.modemtool' + compileSdk 33 + + defaultConfig { + applicationId "run.evan.modemtool" + minSdk 31 + targetSdk 33 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } +} + +dependencies { + implementation 'androidx.appcompat:appcompat:1.6.1' + implementation 'com.google.android.material:material:1.5.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.4' + testImplementation 'junit:junit:4.13.2' + androidTestImplementation 'androidx.test.ext:junit:1.1.5' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' + implementation files('libs/qcrilhook.jar') + implementation files('libs/mirilhook.jar') +} \ No newline at end of file diff --git a/app/libs/mirilhook.jar b/app/libs/mirilhook.jar new file mode 100644 index 0000000..ae64bb8 Binary files /dev/null and b/app/libs/mirilhook.jar differ diff --git a/app/libs/qcrilhook.jar b/app/libs/qcrilhook.jar new file mode 100644 index 0000000..ebac26b Binary files /dev/null and b/app/libs/qcrilhook.jar differ diff --git a/app/libs/qti-telephony-utils.jar b/app/libs/qti-telephony-utils.jar new file mode 100644 index 0000000..54e1730 Binary files /dev/null and b/app/libs/qti-telephony-utils.jar differ diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/app/src/androidTest/java/run/evan/modemtool/ExampleInstrumentedTest.java b/app/src/androidTest/java/run/evan/modemtool/ExampleInstrumentedTest.java new file mode 100644 index 0000000..8b82dde --- /dev/null +++ b/app/src/androidTest/java/run/evan/modemtool/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package run.evan.modemtool; + +import android.content.Context; + +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.ext.junit.runners.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + assertEquals("run.evan.modemtool", appContext.getPackageName()); + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..b812e3f --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/run/evan/modemtool/MainActivity.java b/app/src/main/java/run/evan/modemtool/MainActivity.java new file mode 100644 index 0000000..2f13567 --- /dev/null +++ b/app/src/main/java/run/evan/modemtool/MainActivity.java @@ -0,0 +1,302 @@ +package run.evan.modemtool; + +import android.content.Context; +import android.os.Bundle; +import android.telephony.CellIdentityNr; +import android.telephony.CellInfo; +import android.telephony.CellInfoNr; +import android.telephony.CellSignalStrength; +import android.telephony.CellSignalStrengthNr; +import android.telephony.SubscriptionManager; +import android.telephony.TelephonyManager; +import android.util.Log; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.Spinner; +import android.widget.Toast; + +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; + +import com.qualcomm.qcrilhook.QcRilHook; +import com.qualcomm.qcrilhook.QcRilHookCallback; +import com.xiaomi.mirilhook.MiRilHook; + +import java.lang.reflect.Field; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.util.List; + +public class MainActivity extends AppCompatActivity { + + + private static final String TAG = "ModemTool"; + + TelephonyManager telephonyManager; + + Button btnApply; + + Button btnRead; + + Button btnWrite; + + Button btnDelete; + + Button btnRefresh; + + EditText editText; + + EditText editPci; + + EditText editArfcn; + + EditText editBand; + + + Spinner spinner; + + + private MiRilHook miRilHook = null; + + private boolean miRilHookReady = false; + + private QcRilHook mQcRilHook = null; + + private boolean mQcRilHookReady = false; + + TelephonyManager.CellInfoCallback cellInfoCallback; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + editText = findViewById(R.id.editTextTextMultiLine); + initEnv(); + + spinner = findViewById(R.id.spinner); + spinner.setSelection(1); + + + editPci = findViewById(R.id.edit_pci); + editArfcn = findViewById(R.id.edit_arfcn); + editBand = findViewById(R.id.edit_band); + + btnRead = findViewById(R.id.btn_read); + btnRead.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + query5GInfo(); + } + }); + + btnWrite = findViewById(R.id.btn_write); + btnWrite.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + writeUIToEFS(); + } + }); + + + btnDelete = findViewById(R.id.btn_delete); + btnDelete.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + delete(); + } + }); + + btnRefresh = findViewById(R.id.btn_refresh); + btnRefresh.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + readEFSToUI(); + } + }); + + btnApply = findViewById(R.id.btn_apply); + btnApply.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + refreshMbn(); + } + }); + + cellInfoCallback = new TelephonyManager.CellInfoCallback() { + @Override + public void onCellInfo(@NonNull List allCellInfo) { + for (CellInfo cellInfo : allCellInfo) { + if (cellInfo instanceof CellInfoNr) { + if(cellInfo.isRegistered()){ + CellInfoNr nrInfo = (CellInfoNr) cellInfo; + CellIdentityNr cellIdentity = (CellIdentityNr) nrInfo.getCellIdentity(); + CellSignalStrengthNr cellSignalStrength =(CellSignalStrengthNr) nrInfo.getCellSignalStrength(); + + editArfcn.setText(String.valueOf(cellIdentity.getNrarfcn())); + editPci.setText(String.valueOf(cellIdentity.getPci())); + editBand.setText(String.valueOf(cellIdentity.getBands()[0])); + editText.setText("RSRP="+cellSignalStrength.getSsRsrp()+",RSRQ="+cellSignalStrength.getSsRsrq()+",SINR="+cellSignalStrength.getSsSinr()); + return; + } + } + } + } + }; + } + + private void initEnv() { + try { + telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); + miRilHook = new MiRilHook(getApplicationContext(), new QcRilHookCallback() { + @Override + public void onQcRilHookDisconnected() { + Log.i(TAG, "onMiRilHookDisconnected"); + miRilHookReady = false; + } + + @Override + public void onQcRilHookReady() { + Log.i(TAG, "onQcRilHookReady"); + miRilHookReady = true; + } + }); + + mQcRilHook = new QcRilHook(getApplicationContext(), new QcRilHookCallback() { + @Override + public void onQcRilHookDisconnected() { + Log.i(TAG, "onMiRilHookDisconnected"); + mQcRilHookReady = false; + } + + @Override + public void onQcRilHookReady() { + Log.i(TAG, "onQcRilHookReady"); + mQcRilHookReady = true; + } + }); + + + + } catch (Exception e) { + editText.setText(e.toString()); + } + + } + + + private void modemSSR() { + try { + if (miRilHookReady) { + miRilHook.onHookCommonMsgSync(31, 4, -2147483647); + } else { + Toast.makeText(getApplicationContext(), "miRilHookReady = false", Toast.LENGTH_LONG).show(); + } + } catch (Exception e) { + + } + } + + private void refreshMbn() { + try { + if (mQcRilHookReady) { + int slotIndex = SubscriptionManager.getSlotIndex(getSub()); + mQcRilHook.qcRilRefreshMbn(slotIndex); + } else { + Toast.makeText(getApplicationContext(), "mQcRilHookReady = false", Toast.LENGTH_LONG).show(); + } + } catch (Exception e) { + + } + } + + + private void readEFSToUI() { + try { + int slotIndex = SubscriptionManager.getSlotIndex(getSub()); + ByteBuffer buf = miRilHook.onHookBigEfsReadSync(slotIndex, "/nv/item_files/modem/nr5g/RRC/pci_lock_info"); + if (null == buf) { + editText.setText("buf is null"); + } else { + int ret = buf.getInt(); + int len = buf.getInt(); + byte[] bytes = null; + if (len > 0 && ret == 0) { + if (len != 12) { + editText.setText("pci_lock_info len != 12"); + return; + } + bytes = new byte[len]; + buf.get(bytes); + } else if (ret != 0) { + editPci.setText(""); + editArfcn.setText(""); + editBand.setText(""); + return; + } + + ByteBuffer buffer = ByteBuffer.wrap(bytes); + buffer.order(ByteOrder.LITTLE_ENDIAN); + editPci.setText(String.valueOf(buffer.getInt())); + editArfcn.setText(String.valueOf(buffer.getInt())); + short scs = buffer.getShort(); + spinner.setSelection(scs); + editBand.setText(String.valueOf(buffer.getShort() + 1)); + } + } catch (Exception e) { + editText.setText(e.toString()); + } + } + + private void writeUIToEFS() { + try { + int pci = Integer.parseInt(editPci.getText().toString()); + int arfcn = Integer.parseInt(editArfcn.getText().toString()); + short band = (short) Integer.parseInt(editBand.getText().toString()); + band--; + short scs = (short) spinner.getSelectedItemPosition(); + ByteBuffer buffer = ByteBuffer.allocate(12); + buffer.order(ByteOrder.LITTLE_ENDIAN); + buffer.putInt(pci); + buffer.putInt(arfcn); + buffer.putShort(scs); + buffer.putShort(band); + int slotIndex = SubscriptionManager.getSlotIndex(getSub()); + miRilHook.onHookEfsWriteSync(slotIndex, "/nv/item_files/modem/nr5g/RRC/pci_lock_info", buffer.array()); + } catch (Exception e) { + editText.setText(e.toString()); + } + } + + private void delete() { + try { + miRilHook.onHookEfsOptSync(0, "/nv/item_files/modem/nr5g/RRC/pci_lock_info", 6); + miRilHook.onHookEfsOptSync(1, "/nv/item_files/modem/nr5g/RRC/pci_lock_info", 6); + } catch (Exception e) { + editText.setText(e.toString()); + } + } + + + private void query5GInfo() { + telephonyManager.createForSubscriptionId(getSub()).requestCellInfoUpdate(getMainExecutor(),cellInfoCallback ); + } + + + private String byteArrayToString(byte[] byteArray) { + StringBuilder sb = new StringBuilder(); + for (byte b : byteArray) { + sb.append(b).append(" "); + } + return sb.toString(); + } + + private int getSub() { + int subscriberId = 0; + subscriberId = SubscriptionManager.getDefaultDataSubscriptionId(); + return subscriberId; + } + + +} \ No newline at end of file diff --git a/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..2b068d1 --- /dev/null +++ b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..07d5da9 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..5937115 --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,164 @@ + + + + + + + + + + + + + + + + +