我正在开发一个简单的应用程序,它通过执行 shell 命令在 build.prop 上注入行。我的主要问题是,每次我检查创建函数的切换时,都会出现显示 shell 字符串的 toast。有没有办法避免这种情况?另外,如果您有任何建议清理一下代码,我们将不胜感激!(我的第一个应用程序)。
代码:
public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState) {
// fragment not when container null
if (container == null) {
return null;
}
// inflate view from layout
View v = (LinearLayout)inflater.inflate(R.layout.performance,container,false);
final CheckBox hwdebug = (CheckBox) v.findViewById(R.id.hwDebug);
final String[] mountrw = {"su","-c","mount -o remount,rw /system"};
final String[] enhwdebug1 = {"su","-c","sed -i '/debug.sf.hw=*/d' /system/build.prop"};
final String[] enhwdebug2 = {"su","-c","echo '## Rendering GPU Enabled ##' >> /system/build.prop"};
final String[] enhwdebug3 = {"su","-c","echo debug.sf.hw=1 >> /system/build.prop"};
final String[] dishwdebug1 = {"su","-c","sed -i '/debug.sf.hw=1/d' /system/build.prop"};
final String[] dishwdebug2 = {"su","-c","sed -i '/## Rendering GPU Enabled ##/d' /system/build.prop"};
final SharedPreferences hwdebugpref = this.getActivity().getSharedPreferences("hwdebugck",0);
// GPU Rendering Checkbox
boolean hwdebugck = hwdebugpref.getBoolean("hwdebugck", false);
if (hwdebugck) {
hwdebug.setChecked(true);
} else {
hwdebug.setChecked(false);
}
hwdebug.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if((hwdebug.isChecked())) {
SharedPreferences.Editor editor = hwdebugpref.edit();
editor.putBoolean("hwdebugck", true); // value to store
editor.commit();
ArrayList<String[]> enhwdebug = new ArrayList<String[]>();
enhwdebug.add(mountrw);
enhwdebug.add(enhwdebug1);
enhwdebug.add(enhwdebug2);
enhwdebug.add(enhwdebug3);
for(String[] cmd:enhwdebug){
try {
Runtime.getRuntime().exec(cmd);
} catch (IOException e) {
e.fillInStackTrace();
}
}
} else {
SharedPreferences.Editor editor = hwdebugpref.edit();
editor.putBoolean("hwdebugck", false); // value to store
editor.commit();
ArrayList<String[]> diswdebug = new ArrayList<String[]>();
diswdebug.add(mountrw);
diswdebug.add(dishwdebug1);
diswdebug.add(dishwdebug2);
for(String[] cmd:diswdebug){
try {
Runtime.getRuntime().exec(cmd);
} catch (IOException e) {
e.fillInStackTrace();
}
}
}
}
});
所以,我的主要问题是su -c
显示令人讨厌的吐司。我试图将它传递给busybox或工具箱但没有成功,因为它们需要与su
.
谢谢!