import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.InputStreamReader;
import java.io.PrintStream;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ToggleButton;
public class SystemBarManagerActivity
extends Activity {
File systemUIapkFile =
new File("/system/app/SystemUI.apk");
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final ToggleButton systemBarToggleButton = (ToggleButton) findViewById(R.id.systemBarToggleButton);
systemBarToggleButton.setChecked(systemUIapkFile.exists());
systemBarToggleButton.setOnCheckedChangeListener(
new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
systemBarToggleButton.setChecked(isChecked);
switchSystemUI();
if (isChecked) {
Intent intent =
new Intent();
intent.setComponent(
new ComponentName(
"com.android.systemui",
"com.android.systemui.SystemUIService"));
startService(intent);
}
}
});
}
private void switchSystemUI() {
try {
Process p;
p = Runtime.getRuntime().exec("su");
// Attempt to write a file to a root-only DataOutputStream os =
new DataOutputStream(p.getOutputStream());
os.writeBytes("mount -o remount,rw /dev/block/stl6 /system\n");
if (systemUIapkFile.exists()) {
os.writeBytes("mv /system/app/SystemUI.apk /system/SystemUI.apk\n");
}
else {
os.writeBytes("mv /system/SystemUI.apk /system/app/SystemUI.apk\n");
}
os.writeBytes("mount -o remount,ro /dev/block/stl6 /system\n");
// Close the terminal os.writeBytes("exit\n");
os.flush();
p.waitFor();
}
catch (Exception e) {
ShowErrorGlobal(e);
}
}
protected void ShowErrorGlobal(Exception e) {
ByteArrayOutputStream baos =
new ByteArrayOutputStream();
PrintStream stream =
new PrintStream(baos);
e.printStackTrace(stream);
stream.flush();
new AlertDialog.Builder(
this)
.setIconAttribute(android.R.attr.alertDialogIcon)
.setTitle("Epic fail")
.setMessage("Error: " +
new String(baos.toByteArray())).show();
}
}