diff --git a/.idea/misc.xml b/.idea/misc.xml index 773fe0f..8978d23 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,6 @@ - + diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 3e8dd10..eb5806a 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -36,5 +36,5 @@ dependencies { 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') + implementation files('libs/qti-telephony-utils.jar') } \ No newline at end of file diff --git a/app/libs/mirilhook.jar b/app/libs/mirilhook.jar deleted file mode 100644 index ae64bb8..0000000 Binary files a/app/libs/mirilhook.jar and /dev/null differ diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index b812e3f..7278bf6 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,13 +1,9 @@ - - - - @@ -21,20 +17,15 @@ - - - diff --git a/app/src/main/java/run/evan/modemtool/MainActivity.java b/app/src/main/java/run/evan/modemtool/MainActivity.java index 2f13567..b14365a 100644 --- a/app/src/main/java/run/evan/modemtool/MainActivity.java +++ b/app/src/main/java/run/evan/modemtool/MainActivity.java @@ -5,7 +5,6 @@ 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; @@ -19,11 +18,8 @@ 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; @@ -61,9 +57,6 @@ public class MainActivity extends AppCompatActivity { private boolean miRilHookReady = false; - private QcRilHook mQcRilHook = null; - - private boolean mQcRilHookReady = false; TelephonyManager.CellInfoCallback cellInfoCallback; @@ -163,20 +156,6 @@ public class MainActivity extends AppCompatActivity { } }); - 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) { @@ -186,23 +165,12 @@ public class MainActivity extends AppCompatActivity { } - 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) { + if (miRilHookReady) { int slotIndex = SubscriptionManager.getSlotIndex(getSub()); - mQcRilHook.qcRilRefreshMbn(slotIndex); + miRilHook.qcRilRefreshMbn(slotIndex); } else { Toast.makeText(getApplicationContext(), "mQcRilHookReady = false", Toast.LENGTH_LONG).show(); } @@ -299,4 +267,7 @@ public class MainActivity extends AppCompatActivity { } + + + } \ No newline at end of file diff --git a/app/src/main/java/run/evan/modemtool/MiRilHook.java b/app/src/main/java/run/evan/modemtool/MiRilHook.java new file mode 100644 index 0000000..87c4a9c --- /dev/null +++ b/app/src/main/java/run/evan/modemtool/MiRilHook.java @@ -0,0 +1,238 @@ +package run.evan.modemtool; + +import android.content.Context; +import android.os.RemoteException; + +import com.qualcomm.qcrilhook.QcRilHook; +import com.qualcomm.qcrilhook.QcRilHookCallback; + +import org.codeaurora.telephony.utils.CommandException; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.util.Arrays; + +public class MiRilHook extends QcRilHook { + + + private final int mHeaderSize; + + private static final int HOOK_HEAD_SIZE = "QOEMHOOK".length() + 8; + + + public MiRilHook(Context context) { + super(context); + this.mHeaderSize = "QOEMHOOK".length() + 8; + + } + + public MiRilHook(Context context, QcRilHookCallback qcRilHookCallback) { + super(context, qcRilHookCallback); + this.mHeaderSize = "QOEMHOOK".length() + 8; + + } + + + public ByteBuffer onHookBigEfsReadSync(int sub, String path, int responseSize) { + return onHookSendSync(onPkHookEfsOpt(sub, path, 4), responseSize, 0); + } + + public ByteBuffer onHookBigEfsReadSync(int sub, String path) { + return onHookSendSync(onPkHookEfsOpt(sub, path, 4), 102400, 0); + } + + private ByteBuffer onHookSendSync(byte[] requestBytes, int responseSize, int phoneId) { + if (requestBytes == null) { + return null; + } else if (responseSize <= 0) { + return null; + } else { + return sendQcRilHookMsgSync(524970, requestBytes, responseSize, phoneId); + } + } + public ByteBuffer sendQcRilHookMsgSync(int requestId, byte[] request, int responseSize, int phoneId) { + org.codeaurora.telephony.utils.AsyncResult ar = sendQcRilHookMsg(requestId, request, responseSize, phoneId); + if (ar == null) { + return null; + } else if (ar.exception != null) { + return null; + } else if (ar.result == null) { + return null; + } else { + byte[] response = (byte[]) ar.result; + ByteBuffer byteBuf = ByteBuffer.wrap(response); + byteBuf.order(ByteOrder.nativeOrder()); + return byteBuf; + } + } + + + public org.codeaurora.telephony.utils.AsyncResult sendQcRilHookMsg(int requestId, byte[] request, int responseSize, int phoneId) { + validateInternalState(); + int mHeaderSize = "QOEMHOOK".length() + 8; + byte[] request_new = new byte[mHeaderSize + request.length]; + ByteBuffer reqBuffer = createBufferWithNativeByteOrder(request_new); + addQcRilHookHeader(reqBuffer, requestId, request.length); + reqBuffer.put(request); + return sendRilOemHookMsg(requestId, request_new, responseSize, phoneId); + } + + public ByteBuffer onHookEfsWriteSync(int sub, String path, byte[] data) { + if (data == null) { + return null; + } + return onHookEfsWriteSync(sub, path, data, data.length); + } + public ByteBuffer onHookEfsWriteSync(int sub, String path, byte[] data, int dataLen) { + return onHookSendSync(onPkHookEfsWrite(sub, path, data, dataLen)); + } + + public ByteBuffer sendQcRilHookMsgSync(int requestId, byte[] request, int phoneId) { + org.codeaurora.telephony.utils.AsyncResult ar = sendQcRilHookMsg(requestId, request, phoneId); + if (ar == null) { + return null; + } else if (ar.exception != null) { + return null; + } else if (ar.result == null) { + return null; + } else { + byte[] response = (byte[]) ar.result; + ByteBuffer byteBuf = ByteBuffer.wrap(response); + byteBuf.order(ByteOrder.nativeOrder()); + return byteBuf; + } + } + public ByteBuffer onHookEfsOptSync(int sub, String path, int hook_id) { + return onHookSendSync(onPkHookEfsOpt(sub, path, hook_id)); + } + + + public static boolean putByteToBuffer(ByteBuffer buf, byte[] value, int len) { + if (value == null) { + return false; + } else if (buf == null) { + return false; + } else if (len <= 0) { + return false; + } else { + for (int i = 0; i < len; i++) { + buf.put(value[i]); + } + return true; + } + } + private ByteBuffer onHookSendSync(byte[] requestBytes) { + return onHookSendSync(requestBytes, 0); + } + + private ByteBuffer onHookSendSync(byte[] requestBytes, int phoneId) { + if (requestBytes == null) { + return null; + } else { + return sendQcRilHookMsgSync(524970, requestBytes, phoneId); + } + } + + + private void validateInternalState() { + if (isDisposed()) { + throw new IllegalStateException("QcRilHook is in disposed state"); + } + } + + private org.codeaurora.telephony.utils.AsyncResult sendRilOemHookMsg(int requestId, byte[] request, int responseSize, int phoneId) { + if (responseSize <= 0) { + return null; + } + byte[] response = new byte[responseSize]; + try { + int retVal = this.mService.sendOemRilRequestRaw(request, response, phoneId); + if (retVal >= 0) { + byte[] validResponseBytes = null; + if (retVal > 0) { + validResponseBytes = Arrays.copyOf(response, retVal); + } + org.codeaurora.telephony.utils.AsyncResult ar = new org.codeaurora.telephony.utils.AsyncResult(Integer.valueOf(retVal), validResponseBytes, (Throwable) null); + return ar; + } + byte[] validResponseBytes2 = Arrays.copyOf(response, response.length); + CommandException ex = CommandException.fromRilErrno(retVal * (-1)); + org.codeaurora.telephony.utils.AsyncResult ar2 = new org.codeaurora.telephony.utils.AsyncResult(request, validResponseBytes2, ex); + return ar2; + } catch (RemoteException e) { + org.codeaurora.telephony.utils.AsyncResult ar3 = new org.codeaurora.telephony.utils.AsyncResult(Integer.valueOf(requestId), (Object) null, e); + return ar3; + } catch (NullPointerException e2) { + org.codeaurora.telephony.utils.AsyncResult ar4 = new org.codeaurora.telephony.utils.AsyncResult(Integer.valueOf(requestId), (Object) null, e2); + return ar4; + } + } + + + private byte[] onPkHookEfsOpt(int sub, String path, int hook_id) { + if (path == null) { + return null; + } else if (4 != hook_id && 6 != hook_id && 110 != hook_id && 51 != hook_id) {; + return null; + } else { + int msg_len = path.length() + 12; + byte[] hookBytes = onGetHookMsgBytes(msg_len); + ByteBuffer reqBuffer = onGetHookMsgBuffer(hookBytes); + if (reqBuffer == null) { + return null; + } + reqBuffer.putInt(hook_id); + reqBuffer.putInt(sub); + reqBuffer.putInt(path.length()); + reqBuffer.put(path.getBytes()); + return hookBytes; + } + } + + private byte[] onGetHookMsgBytes(int msg_len) { + int i = HOOK_HEAD_SIZE; + byte[] hookBytes = new byte[i + msg_len]; + return hookBytes; + } + + private ByteBuffer onGetHookMsgBuffer(byte[] hookBytes) { + if (hookBytes == null) { + return null; + } + ByteBuffer reqBuffer = createBufferWithNativeByteOrder(hookBytes); + return reqBuffer; + } + + + + + + + private byte[] onPkHookEfsWrite(int sub, String path, byte[] data, int dataLen) { + if (sub != 0 && 1 != sub) { + return null; + } else if (path == null) { + return null; + } else if (data == null) { + return null; + } else if (dataLen <= 0) { + return null; + } else { + int msg_len = path.length() + 12 + 4 + dataLen; + byte[] hookBytes = onGetHookMsgBytes(msg_len); + ByteBuffer reqBuffer = onGetHookMsgBuffer(hookBytes); + if (reqBuffer == null) { + return null; + } + reqBuffer.putInt(5); + reqBuffer.putInt(sub); + reqBuffer.putInt(path.length()); + reqBuffer.put(path.getBytes()); + reqBuffer.putInt(dataLen); + putByteToBuffer(reqBuffer, data, dataLen); + return hookBytes; + } + } + + +}