我正在尝试通过应用程序以编程方式运行 adb shell 命令来更改 rtt_calling_mode 变量值,但我遇到了这个错误。
Exception occurred while executing 'put':
java.lang.NullPointerException
at java.util.Objects.requireNonNull(Objects.java:220)
at com.android.server.appop.AppOpsService.checkPackage(AppOpsService.java:2969)
at android.app.AppOpsManager.checkPackage(AppOpsManager.java:7697)
at android.content.ContentProvider.getCallingPackage(ContentProvider.java:954)
at com.android.providers.settings.SettingsProvider.mutateSecureSetting(SettingsProvider.java:1732)
at com.android.providers.settings.SettingsProvider.insertSecureSetting(SettingsProvider.java:1652)
at com.android.providers.settings.SettingsProvider.call(SettingsProvider.java:412)
at android.content.ContentProvider.call(ContentProvider.java:2448)
at android.content.ContentProvider$Transport.call(ContentProvider.java:517)
at com.android.providers.settings.SettingsService$MyShellCommand.putForUser(SettingsService.java:375)
at com.android.providers.settings.SettingsService$MyShellCommand.onCommand(SettingsService.java:277)
at android.os.BasicShellCommandHandler.exec(BasicShellCommandHandler.java:98)
at android.os.ShellCommand.exec(ShellCommand.java:44)
at com.android.providers.settings.SettingsService.onShellCommand(SettingsService.java:49)
at android.os.Binder.shellCommand(Binder.java:929)
at android.os.Binder.onTransact(Binder.java:813)
at android.os.Binder.execTransactInternal(Binder.java:1159)
at android.os.Binder.execTransact(Binder.java:1123)
在 A10 上运行时,我能够完美地运行此命令,它会更改 RTT 变量,就好像我通过命令提示符运行命令“adb shell settings put secure rtt_calling_mode0 1”一样。但是现在在 A11 版本上我收到了这个错误。我不确定是什么导致了这个问题,以及为什么它现在与“put”有问题。也不确定 NullPointerException 来自哪里。有谁知道可能导致此问题的原因是什么?以下是运行时引发错误的代码。
public static String setRealTimeText(int simSlot, int enabled){
String command = "settings put secure rtt_calling_mode" + slot + " " + enabled;
try {
Process process = Runtime.getRuntime().exec(command);
BufferedReader output = new BufferedReader(new InputStreamReader(process.getInputStream()));
BufferedReader errorOutput = new BufferedReader(new InputStreamReader(process.getErrorStream()));
//get the error output
String s = "";
String outputString = "";
if (errorOutput.readLine() != null) {
while ((s = errorOutput.readLine()) != null) {
outputString += " " + s + "\n";
}
return outputString;
}
//get the console output
while ((s = output.readLine()) != null) {
outputString += "- " + s + "\n";
}
return "RTT was enabled"
} catch (Exception e) {
e.printStackTrace();
return e.toString();
}
}