java - 如何获得icc认证?
问题描述
我在 telephonyManager 类中发现了一些有趣的方法,例如关闭/打开移动数据,但是当尝试使用它们时,它显然会引发安全异常。(“无运营商特权”)。我用谷歌搜索了它,但没有找到任何有用的解决方案。因为它是运营商特权,所以我认为可能可以获得它的许可,telephonyManager.getIccAuthentication(int appType, int authType, String data)
但是我在输入参数方面遇到问题,因为我不知道应该传递什么才能使其工作。
从文档到第一个参数将通过TelephonyManager.APPTYPE_SIM
或/和TelephonyManager.APPTYPE_USIM
取决于它在使用setDataEnabled(boolean)
. 如果我将TelephonyManager.APPTYPE_SIM
作为第一个参数传递,我认为我应该TelephonyManager.AUTHTYPE_EAP_SIM
作为第二个参数传递(如果我错了,请纠正我),反之亦然,当TelephonyManager.APPTYPE_USIM
第一个参数作为第二个参数时TelephonyManager.AUTHTYPE_EAP_AKA
。
然后是第三个论点。必须有 Base64 编码为字符串。我在 TelephonyProvider 中找到了这行代码:
String base64Challenge = Base64.encodeToString(byteParam, Base64.NO_WRAP);
其中 byteParam 是来自另一个方法的输入字节,它在数千个其他方法之前。如果我将 "" 作为第三个参数传递给 getIccAuthentication 方法,我会再次得到 securityException(这显然是错误的参数),但它让我缺乏getIccSimChallengeResponse
. 我担心它可能是无限循环的方法,但也许有人有任何想法或帮助我突破这一点?
我的示例代码:
public class MainActivity extends AppCompatActivity {
private static final String TAG = MainActivity.class.getSimpleName();
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = (Button) findViewById(R.id.buttonPanel);
button.setOnClickListener(new View.OnClickListener() {
@RequiresApi(api = Build.VERSION_CODES.O)
@Override
public void onClick(View view) {
try {
Process p = Runtime.getRuntime().exec("su");
tel();
} catch (IOException e) {
e.printStackTrace();
}
}
});
}
@RequiresApi(api = Build.VERSION_CODES.O)
private void tel(){
// String base64Challenge = Base64.encodeToString(,
Base64.NO_WRAP);
TelephonyManager telephonyManager = (TelephonyManager)
getSystemService(Context.TELEPHONY_SERVICE);
boolean isCarrier = telephonyManager.hasCarrierPrivileges();
String authentication =
telephonyManager.getIccAuthentication(TelephonyManager.APPTYPE_SIM,
TelephonyManager.AUTHTYPE_EAP_SIM, "");
Log.v(TAG, authentication);
if (isCarrier) {
Log.v(TAG, "privs granted");
telephonyManager.setDataEnabled(false);
} else {
Log.v(TAG, "no privilegies");
}
}
}
解决方案
从文档:
需要权限:READ_PRIVILEGED_PHONE_STATE 或调用应用程序具有运营商权限(请参阅 hasCarrierPrivileges())。
其中第一个要求您安装为特权系统应用程序(需要根或拥有系统证书)。第二个要求您的 UID 是运营商的。没有它,任何参数组合都不会起作用。
推荐阅读
- c++ - 在 Qt3D 中进行碰撞检测的预期方法(或好方法)是什么?
- sql-server - 通过 HTTPS 从 SQL Server 存储过程调用的 WCF 服务
- amazon-web-services - Amazon Redshift - 加入表并找出不匹配的行
- java - java.lang.IllegalStateException: org.hibernate.TransientObjectException(更新记录时)
- r - 无法在 R 中创建具有动态名称的非反应性 RenderPlot 对象
- android - 如何设置灯光弹出主题?
- javascript - 使用 Firebase 数据库规则禁用特定子项的写入
- postgresql - 使用 psycopg2 使用 ACCESS EXCLUSIVE 锁定表
- azure - MS Azure:无法将 Azure 云文件复制到另一个目录
- hyperledger-fabric - Hyperledger Composer - 错误 8:RESOURCE_EXHAUSTED