Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.android.gaospconf;
- import java.io.BufferedReader;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.FileReader;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.io.PrintWriter;
- import android.app.Activity;
- import android.app.AlertDialog;
- import android.app.ProgressDialog;
- import android.content.Context;
- import android.content.pm.ActivityInfo;
- import android.os.Bundle;
- import android.os.PowerManager;
- import android.os.SystemClock;
- import android.util.Log;
- import android.view.Menu;
- import android.view.MenuInflater;
- import android.view.MenuItem;
- import android.view.View;
- import android.widget.ArrayAdapter;
- import android.widget.Button;
- import android.widget.CheckBox;
- import android.widget.CompoundButton;
- import android.widget.EditText;
- import android.widget.TextView;
- import android.widget.Toast;
- import android.widget.ToggleButton;
- import android.widget.CompoundButton.OnCheckedChangeListener;
- public class conf extends Activity {
- /** Called when the activity is first created. */
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- // Define variables
- String record = null;
- int recCount = 0;
- Boolean compcache = false;
- String compcache_disksize = null;
- int cpu_sampling = 0;
- Boolean swap = false;
- Boolean ssh = false;
- Boolean inadyn = false;
- Boolean renice = false;
- Boolean prov = false;
- Boolean vnc = false;
- Boolean overclocking = false;
- Boolean overclocking2 = false;
- int sensors_sampling = 0;
- // Define objects
- Button Default_Button = (Button) findViewById(R.id.defaults);
- Button Apply_Button = (Button) findViewById(R.id.apply);
- Button OK_Button = (Button) findViewById(R.id.Buttondesc);
- final ToggleButton Toggle_Compcache = (ToggleButton) findViewById(R.id.comp);
- final EditText compcache_disksize_edit = (EditText) findViewById(R.id.disksize);
- final CheckBox Check_sampling_eco = (CheckBox) findViewById(R.id.sampling01);
- final CheckBox Check_sampling_mix = (CheckBox) findViewById(R.id.sampling02);
- final CheckBox Check_sampling_perf = (CheckBox) findViewById(R.id.sampling03);
- final ToggleButton Toggle_SSH = (ToggleButton) findViewById(R.id.ssh);
- final ToggleButton Toggle_Renice = (ToggleButton) findViewById(R.id.renice);
- final ToggleButton Toggle_Prov = (ToggleButton) findViewById(R.id.Prov);
- final ToggleButton Toggle_VNC = (ToggleButton) findViewById(R.id.vnc);
- final ToggleButton Toggle_Swap = (ToggleButton) findViewById(R.id.swap);
- final ToggleButton Toggle_OverClocking = (ToggleButton) findViewById(R.id.oc1);
- final ToggleButton Toggle_OverClocking2 = (ToggleButton) findViewById(R.id.oc2);
- final CheckBox Check_sensors_sampling_eco = (CheckBox) findViewById(R.id.sensors04);
- final CheckBox Check_sensors_sampling_mix = (CheckBox) findViewById(R.id.sensors05);
- final CheckBox Check_sensors_sampling_perf = (CheckBox) findViewById(R.id.sensors06);
- // On ouvre le fichier de config
- FileReader FR = null;
- try {
- FR = new FileReader("/system/etc/gaosp.conf");
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- }
- BufferedReader BR = new BufferedReader(FR);
- // On stocke les varialbe du fichier de conf
- try {
- while ((record = BR.readLine()) != null) {
- recCount++;
- if (record.equals("compcache=yes")) {
- compcache = true;
- }
- if (record.equals("compcache=no")) {
- compcache = false;
- }
- if (record.startsWith("compcache_disksize=")) {
- compcache_disksize = record.substring(19);
- }
- if (record.startsWith("cpu_sampling=")) {
- cpu_sampling = Integer.parseInt(record.substring(13));
- }
- if (record.equals("sshd=no")) {
- ssh = false;
- }
- if (record.equals("sshd=yes")) {
- ssh = true;
- }
- if (record.equals("inadyn=no")) {
- inadyn = false;
- }
- if (record.equals("inadyn=yes")) {
- inadyn = true;
- }
- if (record.equals("renice=no")) {
- renice = false;
- }
- if (record.equals("renice=yes")) {
- renice = true;
- }
- if (record.equals("provisionned=no")) {
- prov = false;
- }
- if (record.equals("provisionned=yes")) {
- prov = true;
- }
- if (record.equals("vnc=no")) {
- vnc = false;
- }
- if (record.equals("vnc=yes")) {
- vnc = true;
- }
- if (record.equals("overclocking=yes")) {
- overclocking = true;
- }
- if (record.equals("overclocking=no")) {
- overclocking = false;
- }
- if (record.equals("overclocking2=yes")) {
- overclocking2 = true;
- }
- if (record.equals("overclocking2=no")) {
- overclocking2 = false;
- }
- if (record.startsWith("sensors_sampling=")) {
- sensors_sampling = Integer.parseInt(record.substring(17));
- }
- if (record.equals("swap=no")) {
- swap = false;
- }
- if (record.equals("swap=yes")) {
- swap = true;
- }
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- // On remplit et valide les champs et autres
- compcache_disksize_edit.setText(compcache_disksize);
- if (compcache == true) {
- Toggle_Compcache.setChecked(true);
- }
- if (cpu_sampling == 0) {
- Check_sampling_eco.setChecked(true);
- }
- if (cpu_sampling == 1) {
- Check_sampling_mix.setChecked(true);
- }
- if (cpu_sampling == 2) {
- Check_sampling_perf.setChecked(true);
- }
- if (ssh == true) {
- Toggle_SSH.setChecked(true);
- }
- if (renice == true) {
- Toggle_Renice.setChecked(true);
- }
- if (prov == true) {
- Toggle_Prov.setChecked(true);
- }
- if (vnc == true) {
- Toggle_VNC.setChecked(true);
- }
- // Enable Disk size if Compcache is enabled
- if (Toggle_Compcache.isChecked()) {
- compcache_disksize_edit.setEnabled(true);
- }
- if (! Toggle_Compcache.isChecked()) {
- compcache_disksize_edit.setEnabled(false);
- }
- if (overclocking == true) {
- Toggle_OverClocking.setChecked(true);
- }
- if (overclocking2 == true) {
- Toggle_OverClocking2.setChecked(true);
- }
- // Enable only 1 Overclocking option
- if (Toggle_OverClocking.isChecked()) {
- Toggle_OverClocking2.setChecked(false);
- }
- if (Toggle_OverClocking2.isChecked()) {
- Toggle_OverClocking.setChecked(false);
- }
- if (sensors_sampling == 0) {
- Check_sensors_sampling_eco.setChecked(true);
- }
- if (sensors_sampling == 1) {
- Check_sensors_sampling_mix.setChecked(true);
- }
- if (sensors_sampling == 2) {
- Check_sensors_sampling_perf.setChecked(true);
- }
- if (swap == true) {
- Toggle_Swap.setChecked(true);
- }
- // Disable Compcache if Swap only is enabled
- if (Toggle_Swap.isChecked()) {
- Toggle_Compcache.setEnabled(false);
- Toggle_Compcache.setChecked(false);
- }
- if (! Toggle_Swap.isChecked()) {
- Toggle_Compcache.setEnabled(true);
- }
- // Listener
- final onClick self = this;
- TextView comptext = (TextView) findViewById(R.id.comptext);
- comptext.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v){
- AlertDialog.Builder alertbox = new AlertDialog.Builder(this).create();
- alertbox.setTitle("Compcache");
- alertbox.setMessage("Description ....");
- public void onClick(DialogInterface dialog, int which) {
- return;
- }
- alertbox.show();
- }
- });
- Default_Button.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- Toggle_Compcache.setChecked(false);
- compcache_disksize_edit.setEnabled(false);
- compcache_disksize_edit.setText("25600");
- Check_sampling_eco.setChecked(false);
- Check_sampling_mix.setChecked(false);
- Check_sampling_perf.setChecked(true);
- Toggle_SSH.setChecked(false);
- Toggle_Renice.setChecked(true);
- Toggle_Prov.setChecked(true);
- Toggle_VNC.setChecked(false);
- Toggle_OverClocking.setChecked(false);
- Toggle_OverClocking2.setChecked(false);
- Check_sensors_sampling_eco.setChecked(true);
- Check_sensors_sampling_mix.setChecked(false);
- Check_sensors_sampling_perf.setChecked(false);
- Toggle_Swap.setChecked(false);
- }
- });
- Apply_Button.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- PrintWriter out = null;
- CharSequence str = "Applying parameters, please wait..";
- Toast.makeText(getBaseContext(), str,
- Toast.LENGTH_SHORT).show();
- if (Integer.parseInt(compcache_disksize_edit.getText().toString()) > 90000) {
- CharSequence strpre = "Compcache disksize is too big";
- Toast.makeText(getBaseContext(), strpre,
- Toast.LENGTH_SHORT).show();
- }
- else {
- // Remount en rw
- String[] commande = { "/system/xbin/su -c /system/xbin/remountrw", "echo done"};
- shell.doExec(commande, true);
- //NativeTask.runCommand("/system/xbin/su -c /system/xbin/remountrw");
- try {
- out = new PrintWriter(new FileWriter("/system/etc/gaosp.conf"));
- } catch (IOException e) {
- e.printStackTrace();
- }
- out.println("################################");
- out.println("##### Gaosp config file ########");
- out.println("################################");
- out.println(" ");
- out.println("# Compcache");
- // Ecriture de la conf compcache
- if (Toggle_Compcache.isChecked()) {
- out.println("compcache=yes");
- /* NativeTask.runCommand("/system/xbin/su -c 'swapoff /dev/block/ramzswap0'");
- NativeTask.runCommand("/system/xbin/su -c 'rmmod ramzswap'");
- NativeTask.runCommand("/system/xbin/su -c 'rmmod xvmalloc'");
- NativeTask.runCommand("/system/xbin/su -c 'insmod /system/libmodules/xvmalloc.ko'");
- NativeTask.runCommand("/system/xbin/su -c 'if [ -r /dev/block/mmcblk1p2 ]; then mkswap /dev/block/mmcblk1p2; insmod /system/libmodules/ramzswap.ko memlimit_kb= " + compcache_disksize_edit.getText() + " backing_swap=/dev/block/mmcblk1p2; else insmod /system/libmodules/ramzswap.ko disksize_kb=" + compcache_disksize_edit.getText() + "; fi; sleep 5'");
- NativeTask.runCommand("/system/xbin/su -c 'swapon /dev/block/ramzswap0 -p 100'");
- */
- }
- else {
- out.println("compcache=no");
- /*
- NativeTask.runCommand("/system/xbin/su -c 'swapoff /dev/block/ramzswap0'");
- NativeTask.runCommand("/system/xbin/su -c 'rmmod ramzswap'");
- NativeTask.runCommand("/system/xbin/su -c 'rmmod xvmalloc'");
- */
- }
- out.println("compcache_disksize=" + compcache_disksize_edit.getText());
- out.println(" ");
- // Ecriture de la conf cpufreq
- int final_sampling = 0;
- //NativeTask.runCommand("/system/xbin/su -c 'echo 2000000 > /sys/devices/system/cpu/cpu0/cpufreq/ondemand/sampling_rate'");
- if (Check_sampling_eco.isChecked()) {
- final_sampling = 0;
- // NativeTask.runCommand("/system/xbin/su -c 'echo 2000000 > /sys/devices/system/cpu/cpu0/cpufreq/ondemand/sampling_rate'");
- }
- if (Check_sampling_mix.isChecked()) {
- final_sampling = 1;
- // NativeTask.runCommand("/system/xbin/su -c 'echo 500000 > /sys/devices/system/cpu/cpu0/cpufreq/ondemand/sampling_rate'");
- }
- if (Check_sampling_perf.isChecked()) {
- final_sampling = 2;
- // NativeTask.runCommand("/system/xbin/su -c 'echo 100000 > /sys/devices/system/cpu/cpu0/cpufreq/ondemand/sampling_rate'");
- }
- out.println("# CpuFreq sampling rate");
- out.println("# Set to 0 to eco mode, 1 to mixte mode, 2 to Performance mode ");
- out.println("cpu_sampling=" + final_sampling);
- out.println(" ");
- // Ecriture de la conf sshd et execution
- out.println("# SSH server");
- if (Toggle_SSH.isChecked()) {
- out.println("sshd=yes");
- /*
- NativeTask.runCommand("/system/xbin/su -c 'kill -9 `pidof dropbear`'");
- NativeTask.runCommand("/system/xbin/su -c 'if [ ! -d /data/ssh/ ]; then /system/bin/mkdir /data/ssh/; fi'");
- NativeTask.runCommand("/system/xbin/su -c 'if [ ! -f /data/ssh/rsa_host_key ]; then /system/xbin/dropbearkey -t rsa -f /data/ssh/rsa_host_key; fi'");
- NativeTask.runCommand("/system/xbin/su -c 'if [ ! -f /data/ssh/dss_host_key ]; then /system/xbin/dropbearkey -t dss -f /data/ssh/dss_host_key; fi'");
- NativeTask.runCommand("/system/xbin/su -c '/system/bin/logwrapper /system/xbin/dropbear &'");
- */
- }
- else {
- out.println("sshd=no");
- /*
- NativeTask.runCommand("/system/xbin/su -c 'kill -9 `pidof dropbear`'");
- */
- }
- out.println(" ");
- // Ecriture de la conf inadyn
- out.println("# Inadyn");
- out.println("inadyn=no");
- out.println(" ");
- // Ecriture de la conf Renice
- out.println("# Renice");
- if (Toggle_Renice.isChecked()) {
- out.println("renice=yes");
- /*
- NativeTask.runCommand("/system/xbin/su -c 'renice -20 `pidof com.android.mms'");
- NativeTask.runCommand("/system/xbin/su -c 'renice -19 `pidof com.android.phone`'");
- NativeTask.runCommand("/system/xbin/su -c 'renice -18 `pidof mediaserver`");
- NativeTask.runCommand("/system/xbin/su -c 'renice 0 `pidof com.google.process.gapps`'");
- */
- }
- else {
- out.println("renice=no");
- /*
- NativeTask.runCommand("/system/xbin/su -c 'renice 0 `pidof com.android.mms'");
- NativeTask.runCommand("/system/xbin/su -c 'renice 0 `pidof com.android.phone`'");
- NativeTask.runCommand("/system/xbin/su -c 'renice 0 `pidof mediaserver`");
- NativeTask.runCommand("/system/xbin/su -c 'renice 0 `pidof com.google.process.gapps`'");
- */
- }
- out.println(" ");
- // Ecriture de la conf provisionned
- out.println("# Device provisionned");
- if (Toggle_Renice.isChecked()) {
- out.println("provisionned=yes");
- }
- else {
- out.println("provisionned=no");
- }
- out.println(" ");
- // Ecriture de la conf vnc et execution
- out.println("# VNC Server");
- if (Toggle_VNC.isChecked()) {
- out.println("vnc=yes");
- /*
- NativeTask.runCommand("/system/xbin/su -c 'kill -9 `pidof fbvncserver`'");
- NativeTask.runCommand("/system/xbin/su -c '/system/bin/logwrapper /system/xbin/fbvncserver &'");
- */
- }
- else {
- out.println("vnc=no");
- /*
- NativeTask.runCommand("/system/xbin/su -c 'kill -9 `pidof fbvncserver`'");
- */
- }
- out.println(" ");
- // Copying swap setting to conf file
- out.println("# Swap");
- if (Toggle_Swap.isChecked()) {
- out.println("swap=yes");
- }
- else {
- out.println("swap=no");
- }
- out.println(" ");
- // Ecriture de la conf overclocking et execution
- out.println("# Overclocking");
- if (Toggle_OverClocking.isChecked()) {
- out.println("overclocking=yes");
- /*
- NativeTask.runCommand("/system/xbin/su -c 'echo 614400 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq'");
- */
- }
- else {
- out.println("overclocking=no");
- /*
- NativeTask.runCommand("/system/xbin/su -c 'echo 528000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq'");
- */
- }
- out.println(" ");
- // Ecriture de la conf overclocking2 et execution
- out.println("# Overclocking2");
- if (Toggle_OverClocking2.isChecked()) {
- out.println("overclocking2=yes");
- /*
- NativeTask.runCommand("/system/xbin/su -c 'echo 614400 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq'");
- */
- }
- else {
- out.println("overclocking2=no");
- /*
- NativeTask.runCommand("/system/xbin/su -c 'echo 528000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq'");
- */
- }
- out.println(" ");
- // Ecriture de la conf cpufreq
- int final_sensors_sampling = 0;
- //NativeTask.runCommand("/system/xbin/su -c 'echo 2000000 > /sys/devices/system/cpu/cpu0/cpufreq/ondemand/sampling_rate'");
- if (Check_sensors_sampling_eco.isChecked()) {
- final_sensors_sampling = 0;
- // NativeTask.runCommand("/system/xbin/su -c 'echo 2000000 > /sys/devices/system/cpu/cpu0/cpufreq/ondemand/sampling_rate'");
- }
- if (Check_sensors_sampling_mix.isChecked()) {
- final_sensors_sampling = 1;
- // NativeTask.runCommand("/system/xbin/su -c 'echo 500000 > /sys/devices/system/cpu/cpu0/cpufreq/ondemand/sampling_rate'");
- }
- if (Check_sensors_sampling_perf.isChecked()) {
- final_sensors_sampling = 2;
- // NativeTask.runCommand("/system/xbin/su -c 'echo 100000 > /sys/devices/system/cpu/cpu0/cpufreq/ondemand/sampling_rate'");
- }
- out.println("# Sensors sampling rate");
- out.println("# Set to 0 to eco mode, 1 to mixte mode, 2 to Performance mode ");
- out.println("sensors_sampling=" + final_sensors_sampling);
- out.println(" ");
- // Execution du rc avec defilement
- new Task().execute();
- // Fermeture du fichier
- out.flush();
- out.close();
- // Remount en ro
- NativeTask.runCommand("/system/xbin/su -c /system/xbin/remountro");
- }
- }
- });
- Check_sampling_eco.setOnCheckedChangeListener(new OnCheckedChangeListener()
- {
- public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
- Check_sampling_mix.setChecked(false);
- Check_sampling_perf.setChecked(false);
- }
- });
- Check_sampling_mix.setOnCheckedChangeListener(new OnCheckedChangeListener()
- {
- public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
- Check_sampling_eco.setChecked(false);
- Check_sampling_perf.setChecked(false);
- }
- });
- Check_sampling_perf.setOnCheckedChangeListener(new OnCheckedChangeListener()
- {
- public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
- Check_sampling_mix.setChecked(false);
- Check_sampling_eco.setChecked(false);
- }
- });
- Check_sensors_sampling_eco.setOnCheckedChangeListener(new OnCheckedChangeListener()
- {
- public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
- Check_sensors_sampling_mix.setChecked(false);
- Check_sensors_sampling_perf.setChecked(false);
- }
- });
- Check_sensors_sampling_mix.setOnCheckedChangeListener(new OnCheckedChangeListener()
- {
- public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
- Check_sensors_sampling_eco.setChecked(false);
- Check_sensors_sampling_perf.setChecked(false);
- }
- });
- Check_sensors_sampling_perf.setOnCheckedChangeListener(new OnCheckedChangeListener()
- {
- public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
- Check_sensors_sampling_mix.setChecked(false);
- Check_sensors_sampling_eco.setChecked(false);
- }
- });
- Toggle_Swap.setOnCheckedChangeListener(new OnCheckedChangeListener()
- {
- public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
- if (Toggle_Swap.isChecked()) {
- Toggle_Compcache.setEnabled(false);
- Toggle_Compcache.setChecked(false);
- }
- if (! Toggle_Swap.isChecked()) {
- Toggle_Compcache.setEnabled(true);
- }
- }
- });
- Toggle_OverClocking.setOnCheckedChangeListener(new OnCheckedChangeListener()
- {
- public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
- if (Toggle_OverClocking.isChecked()) {
- Toggle_OverClocking2.setChecked(false);
- }
- }
- });
- Toggle_OverClocking2.setOnCheckedChangeListener(new OnCheckedChangeListener()
- {
- public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
- if (Toggle_OverClocking2.isChecked()) {
- Toggle_OverClocking.setChecked(false);
- }
- }
- });
- Toggle_Compcache.setOnCheckedChangeListener(new OnCheckedChangeListener()
- {
- public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
- if (Toggle_Compcache.isChecked()) {
- compcache_disksize_edit.setEnabled(true);
- }
- if (! Toggle_Compcache.isChecked()) {
- compcache_disksize_edit.setEnabled(false);
- }
- }
- });
- }
- public boolean onCreateOptionsMenu(Menu menu)
- {
- super.onCreateOptionsMenu(menu);
- MenuItem item = menu.add("About");
- item = menu.add("Exit");
- MenuInflater inflater = new MenuInflater(this);
- return true;
- }
- public boolean onOptionsItemSelected(MenuItem item)
- {
- if (item.hasSubMenu() == false)
- {
- if (item.getTitle() == "About") {
- // Print the about
- AlertDialog.Builder dialogBuilder = new
- AlertDialog.Builder(this);
- dialogBuilder.setMessage("GAOSP Configuration by drakaz and Obihoernchen");
- dialogBuilder.setCancelable(true);
- dialogBuilder.create().show();
- }
- if (item.getTitle() == "Exit") {
- this.finish();
- }
- }
- // Consume the selection event.
- return true;
- }
- final class Task extends UserTask<String, Void, Void> {
- ProgressDialog myProgressDialog;
- protected void onPreExecute() {
- myProgressDialog = ProgressDialog.show(conf.this,"", "Please wait..", true, true);
- }
- @Override
- protected Void doInBackground(String... params) {
- String[] commande = { "/system/xbin/su -c /system/bin/rc"};
- shell.doExec(commande, true);
- //NativeTask.runCommand("/system/xbin/su -c /system/bin/rc");
- return null;
- }
- protected void onPostExecute(Void unused) {
- if (myProgressDialog.isShowing()) {
- myProgressDialog.dismiss();
- CharSequence str2 = "New config saved and applied";
- Toast.makeText(getBaseContext(), str2,
- Toast.LENGTH_SHORT).show();
- try {
- Thread.sleep(5000);
- finish();
- } catch (Throwable e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement