Esempio n. 1
0
 public void set_values() {
   cur.setText(getString(R.string.prefcat_zram) + " " + String.valueOf(curcpu));
   t1.setText(Helpers.ReadableByteCount(0));
   t2.setText("0");
   t3.setText(Helpers.ReadableByteCount(0));
   t4.setText("0");
   t5.setText(Helpers.ReadableByteCount(0));
   Boolean ist1 = false;
   Boolean ist3 = false;
   Boolean ist5 = false;
   if (new File(ZRAM_COMPR_PATH.replace("zram0", "zram" + curcpu)).exists()) {
     t1.setText(
         Helpers.ReadableByteCount(
             parseInt(Helpers.readOneLine(ZRAM_COMPR_PATH.replace("zram0", "zram" + curcpu)))));
     ist1 = true;
   }
   if (new File(ZRAM_ORIG_PATH.replace("zram0", "zram" + curcpu)).exists()) {
     t3.setText(
         Helpers.ReadableByteCount(
             parseInt(Helpers.readOneLine(ZRAM_ORIG_PATH.replace("zram0", "zram" + curcpu)))));
     ist3 = true;
   }
   if (new File(ZRAM_MEMTOT_PATH.replace("zram0", "zram" + curcpu)).exists()) {
     t5.setText(
         Helpers.ReadableByteCount(
             parseInt(Helpers.readOneLine(ZRAM_MEMTOT_PATH.replace("zram0", "zram" + curcpu)))));
     ist5 = true;
   }
   if (ist1 && ist3 && ist5) {
     t2.setText(nf.format(getCompressionRatio()));
     t4.setText(nf.format(getUsedRatio()));
   }
 }
Esempio n. 2
0
 @Override
 protected String doInBackground(String... params) {
   final StringBuilder sb = new StringBuilder();
   sb.append("zramstop ").append(ncpus).append(";\n");
   Helpers.shExec(sb, context, true);
   return "";
 }
Esempio n. 3
0
 @Override
 protected String doInBackground(String... params) {
   long v = (long) (curdisk * 1024 * 1024);
   final StringBuilder sb = new StringBuilder();
   sb.append("zramstart \"").append(ncpus).append("\" \"").append(v).append("\";\n");
   Helpers.shExec(sb, context, true);
   return "";
 }
Esempio n. 4
0
 private boolean no_touchscreen() {
   return (!new File(SLIDE2WAKE).exists()
       && !new File(SWIPE2WAKE).exists()
       && !new File(HOME2WAKE).exists()
       && !new File(LOGO2WAKE).exists()
       && !new File(LOGO2MENU).exists()
       && !new File(POCKET_DETECT).exists()
       && !new File(PICK2WAKE).exists()
       && !new File(FLICK2SLEEP).exists()
       && Helpers.touch2wake_path() == null);
 }
Esempio n. 5
0
 @Override
 public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
   if (fromUser) {
     final int mb = Math.round((progress + min) * maxdisk / 100);
     tval1.setText(
         getString(R.string.zram_disk_size, Helpers.ReadableByteCount(mb * 1024 * 1024))
             + " ("
             + String.valueOf((progress + min))
             + "%)");
   }
 }
Esempio n. 6
0
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
   switch (item.getItemId()) {
     case R.id.tablist:
       Helpers.getTabList(
           getString(R.string.menu_tab), (ViewPager) getView().getParent(), getActivity());
       break;
     case R.id.app_settings:
       Intent intent = new Intent(context, PCSettings.class);
       startActivity(intent);
       break;
   }
   return true;
 }
Esempio n. 7
0
  @Override
  public void onStopTrackingTouch(SeekBar seekBar) {

    curdisk = Math.round((seekBar.getProgress() + min) * maxdisk / 100);
    tval1.setText(
        getString(R.string.zram_disk_size, Helpers.ReadableByteCount(curdisk * 1024 * 1024))
            + " ("
            + String.valueOf(seekBar.getProgress() + min)
            + "%)");

    mPreferences.edit().putInt(PREF_ZRAM, curdisk).commit();

    Intent returnIntent = new Intent();
    returnIntent.putExtra("result", 2);
    setResult(RESULT_OK, returnIntent);
  }
Esempio n. 8
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    context = getActivity();
    mPreferences = PreferenceManager.getDefaultSharedPreferences(context);
    mPreferences.registerOnSharedPreferenceChangeListener(this);
    addPreferencesFromResource(R.layout.advanced);

    sreadahead = getResources().getString(R.string.ps_read_ahead, "");

    mReadAhead = (ListPreference) findPreference(PREF_READ_AHEAD);
    mBltimeout = findPreference(PREF_BLTIMEOUT);
    mBltouch = (CheckBoxPreference) findPreference(PREF_BLTOUCH);
    mBln = (CheckBoxPreference) findPreference(PREF_BLN);
    mWifiPM = (CheckBoxPreference) findPreference("pref_wifi_pm");
    mTouchScr = findPreference("touchscr_settings");
    mViber = findPreference("pref_viber");
    mVM = findPreference("vm_settings");

    mDsync = (CheckBoxPreference) findPreference(PREF_DSYNC);

    mPFK = findPreference("pfk_settings");

    mDynamicWriteBackOn = (CheckBoxPreference) findPreference(PREF_DYNAMIC_DIRTY_WRITEBACK);
    mDynamicWriteBackActive = findPreference(PREF_DIRTY_WRITEBACK_ACTIVE);
    mDynamicWriteBackSuspend = findPreference(PREF_DIRTY_WRITEBACK_SUSPEND);

    if (!new File(DSYNC_PATH).exists()) {
      PreferenceCategory hideCat = (PreferenceCategory) findPreference("dsync");
      getPreferenceScreen().removePreference(hideCat);
    } else {
      mDsync.setChecked(Helpers.readOneLine(DSYNC_PATH).equals("1"));
    }
    if (!new File(PFK_HOME_ENABLED).exists() || !new File(PFK_MENUBACK_ENABLED).exists()) {
      PreferenceCategory hideCat = (PreferenceCategory) findPreference("pfk");
      getPreferenceScreen().removePreference(hideCat);
    }

    if (!new File(BL_TIMEOUT_PATH).exists()) {
      PreferenceCategory hideCat = (PreferenceCategory) findPreference("bltimeout");
      getPreferenceScreen().removePreference(hideCat);
    } else {
      mBltimeout.setSummary(Helpers.readOneLine(BL_TIMEOUT_PATH));
    }

    if (!new File(BL_TOUCH_ON_PATH).exists()) {
      PreferenceCategory hideCat = (PreferenceCategory) findPreference("bltouch");
      getPreferenceScreen().removePreference(hideCat);
    } else {
      mBltouch.setChecked(Helpers.readOneLine(BL_TOUCH_ON_PATH).equals("1"));
    }

    BLN_PATH = Helpers.bln_path();
    if (BLN_PATH == null) {
      PreferenceCategory hideCat = (PreferenceCategory) findPreference("bln");
      getPreferenceScreen().removePreference(hideCat);
    } else {
      mBln.setChecked(Helpers.readOneLine(BLN_PATH).equals("1"));
    }

    if (no_touchscreen()) {
      PreferenceCategory hideCat = (PreferenceCategory) findPreference("touch_scr");
      getPreferenceScreen().removePreference(hideCat);
    }

    VIBE_PATH = vib.get_path();

    if (VIBE_PATH == null) {
      PreferenceCategory hideCat = (PreferenceCategory) findPreference("viber");
      getPreferenceScreen().removePreference(hideCat);
    } else {
      mViber.setSummary(vib.get_val(VIBE_PATH));
    }

    if (!new File(DYNAMIC_DIRTY_WRITEBACK_PATH).exists()) {
      PreferenceCategory hideCat = (PreferenceCategory) findPreference("cat_dynamic_write_back");
      getPreferenceScreen().removePreference(hideCat);
    } else {
      boolean ison = Helpers.readOneLine(DYNAMIC_DIRTY_WRITEBACK_PATH).equals("1");
      mDynamicWriteBackOn.setChecked(ison);
      mDynamicWriteBackActive.setSummary(Helpers.readOneLine(DIRTY_WRITEBACK_ACTIVE_PATH));
      mDynamicWriteBackSuspend.setSummary(Helpers.readOneLine(DIRTY_WRITEBACK_SUSPEND_PATH));
    }
    WIFIPM_PATH = Helpers.wifipm_path();
    if (WIFIPM_PATH == null) {
      PreferenceCategory hideCat = (PreferenceCategory) findPreference("wifi_pm");
      getPreferenceScreen().removePreference(hideCat);
    } else {
      mWifiPM.setChecked(Helpers.readOneLine(WIFIPM_PATH).equals("1"));
    }
    final String readahead = Helpers.readOneLine(READ_AHEAD_PATH);
    mReadAhead.setValue(readahead);
    mReadAhead.setSummary(getString(R.string.ps_read_ahead, readahead + "  kb"));

    setHasOptionsMenu(true);
  }
Esempio n. 9
0
  public void openDialog(
      String title,
      final int min,
      final int max,
      final Preference pref,
      final String path,
      final String key) {
    Resources res = context.getResources();
    String cancel = res.getString(R.string.cancel);
    String ok = res.getString(R.string.ok);
    final EditText settingText;
    LayoutInflater factory = LayoutInflater.from(context);
    final View alphaDialog = factory.inflate(R.layout.seekbar_dialog, null);

    final SeekBar seekbar = (SeekBar) alphaDialog.findViewById(R.id.seek_bar);
    seekbar.setMax(max - min);

    int currentProgress = min;
    if (key.equals("pref_viber")) {
      currentProgress = Integer.parseInt(Helpers.readOneLine(path));
    } else {
      currentProgress = Integer.parseInt(vib.get_val(path));
    }
    if (currentProgress > max) currentProgress = max - min;
    else if (currentProgress < min) currentProgress = 0;
    else currentProgress = currentProgress - min;

    seekbar.setProgress(currentProgress);

    settingText = (EditText) alphaDialog.findViewById(R.id.setting_text);
    settingText.setText(Integer.toString(currentProgress + min));

    settingText.setOnEditorActionListener(
        new TextView.OnEditorActionListener() {
          @Override
          public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE) {
              int val = Integer.parseInt(settingText.getText().toString()) - min;
              seekbar.setProgress(val);
              return true;
            }
            return false;
          }
        });

    settingText.addTextChangedListener(
        new TextWatcher() {
          @Override
          public void onTextChanged(CharSequence s, int start, int before, int count) {}

          @Override
          public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

          @Override
          public void afterTextChanged(Editable s) {
            try {
              int val = Integer.parseInt(s.toString());
              if (val > max) {
                s.replace(0, s.length(), Integer.toString(max));
                val = max;
              }
              seekbar.setProgress(val - min);
            } catch (NumberFormatException ex) {
            }
          }
        });

    OnSeekBarChangeListener seekBarChangeListener =
        new OnSeekBarChangeListener() {
          @Override
          public void onProgressChanged(SeekBar seekbar, int progress, boolean fromUser) {
            final int mSeekbarProgress = seekbar.getProgress();
            if (fromUser) {
              settingText.setText(Integer.toString(mSeekbarProgress + min));
            }
          }

          @Override
          public void onStopTrackingTouch(SeekBar seekbar) {}

          @Override
          public void onStartTrackingTouch(SeekBar seekbar) {}
        };
    seekbar.setOnSeekBarChangeListener(seekBarChangeListener);

    new AlertDialog.Builder(context)
        .setTitle(title)
        .setView(alphaDialog)
        .setNegativeButton(
            cancel,
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                // nothing
              }
            })
        .setPositiveButton(
            ok,
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                int val = min;
                if (!settingText.getText().toString().equals(""))
                  val = Integer.parseInt(settingText.getText().toString());
                if (val < min) val = min;
                seekbar.setProgress(val - min);
                int newProgress = seekbar.getProgress() + min;
                new CMDProcessor()
                    .su.runWaitFor("busybox echo " + Integer.toString(newProgress) + " > " + path);
                String v;
                if (key.equals("pref_viber")) {
                  v = vib.get_val(path);
                  Vibrator vb = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
                  vb.vibrate(1000);
                } else {
                  v = Helpers.readOneLine(path);
                }
                final SharedPreferences.Editor editor = mPreferences.edit();
                editor.putInt(key, Integer.parseInt(v)).commit();
                pref.setSummary(v);
              }
            })
        .create()
        .show();
  }
Esempio n. 10
0
 @Override
 public void onSharedPreferenceChanged(final SharedPreferences sharedPreferences, String key) {
   final SharedPreferences.Editor editor = sharedPreferences.edit();
   if (key.equals(PREF_READ_AHEAD)) {
     final String values = mReadAhead.getValue();
     if (!values.equals(Helpers.readOneLine(READ_AHEAD_PATH))) {
       for (byte i = 0; i < 2; i++) {
         if (new File(READ_AHEAD_PATH.replace("mmcblk0", "mmcblk" + i)).exists())
           new CMDProcessor()
               .su.runWaitFor(
                   "busybox echo "
                       + values
                       + " > "
                       + READ_AHEAD_PATH.replace("mmcblk0", "mmcblk" + i));
       }
     }
     mReadAhead.setSummary(sreadahead + values + " kb");
   } else if (key.equals(PREF_BLTIMEOUT)) {
     mBltimeout.setSummary(Helpers.readOneLine(BL_TIMEOUT_PATH));
   } else if (key.equals(BLX_SOB)) {
     if (sharedPreferences.getBoolean(key, false)) {
       editor.putInt(PREF_BLX, Integer.parseInt(Helpers.readOneLine(BLX_PATH))).apply();
     } else {
       editor.remove(PREF_BLX).apply();
     }
   } else if (key.equals(BLTIMEOUT_SOB)) {
     if (sharedPreferences.getBoolean(key, false)) {
       editor
           .putInt(PREF_BLTIMEOUT, Integer.parseInt(Helpers.readOneLine(BL_TIMEOUT_PATH)))
           .apply();
     } else {
       editor.remove(PREF_BLTIMEOUT).apply();
     }
   } else if (key.equals(PFK_SOB)) {
     if (sharedPreferences.getBoolean(key, false)) {
       if (Helpers.readOneLine(PFK_HOME_ENABLED).equals("1")) {
         editor.putBoolean(PFK_HOME_ON, true);
       } else {
         editor.putBoolean(PFK_HOME_ON, false);
       }
       editor
           .putInt(
               PREF_HOME_ALLOWED_IRQ, Integer.parseInt(Helpers.readOneLine(PFK_HOME_ALLOWED_IRQ)))
           .putInt(
               PREF_HOME_REPORT_WAIT, Integer.parseInt(Helpers.readOneLine(PFK_HOME_REPORT_WAIT)));
       if (Helpers.readOneLine(PFK_MENUBACK_ENABLED).equals("1")) {
         editor.putBoolean(PFK_MENUBACK_ON, true);
       } else {
         editor.putBoolean(PFK_MENUBACK_ON, false);
       }
       editor
           .putInt(
               PREF_MENUBACK_INTERRUPT_CHECKS,
               Integer.parseInt(Helpers.readOneLine(PFK_MENUBACK_INTERRUPT_CHECKS)))
           .putInt(
               PREF_MENUBACK_FIRST_ERR_WAIT,
               Integer.parseInt(Helpers.readOneLine(PFK_MENUBACK_FIRST_ERR_WAIT)))
           .putInt(
               PREF_MENUBACK_LAST_ERR_WAIT,
               Integer.parseInt(Helpers.readOneLine(PFK_MENUBACK_LAST_ERR_WAIT)))
           .apply();
     } else {
       editor
           .remove(PFK_HOME_ON)
           .remove(PREF_HOME_ALLOWED_IRQ)
           .remove(PREF_HOME_REPORT_WAIT)
           .remove(PFK_MENUBACK_ON)
           .remove(PREF_MENUBACK_INTERRUPT_CHECKS)
           .remove(PREF_MENUBACK_FIRST_ERR_WAIT)
           .remove(PREF_MENUBACK_LAST_ERR_WAIT)
           .apply();
     }
   } else if (key.equals(DYNAMIC_DIRTY_WRITEBACK_SOB)) {
     if (sharedPreferences.getBoolean(key, false)) {
       if (Helpers.readOneLine(DYNAMIC_DIRTY_WRITEBACK_PATH).equals("1")) {
         editor.putBoolean(PREF_DYNAMIC_DIRTY_WRITEBACK, true);
       } else {
         editor.putBoolean(PREF_DYNAMIC_DIRTY_WRITEBACK, false);
       }
       editor
           .putInt(
               PREF_DIRTY_WRITEBACK_ACTIVE,
               Integer.parseInt(Helpers.readOneLine(DIRTY_WRITEBACK_ACTIVE_PATH)))
           .putInt(
               PREF_DIRTY_WRITEBACK_SUSPEND,
               Integer.parseInt(Helpers.readOneLine(DIRTY_WRITEBACK_SUSPEND_PATH)))
           .apply();
     } else {
       editor
           .remove(PREF_DYNAMIC_DIRTY_WRITEBACK)
           .remove(PREF_DIRTY_WRITEBACK_ACTIVE)
           .remove(PREF_DIRTY_WRITEBACK_SUSPEND)
           .apply();
     }
   }
 }
Esempio n. 11
0
  @Override
  public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {

    if (preference == mDsync) {
      if (Helpers.readOneLine(DSYNC_PATH).equals("0")) {
        new CMDProcessor().su.runWaitFor("busybox echo 1 > " + DSYNC_PATH);
      } else {
        new CMDProcessor().su.runWaitFor("busybox echo 0 > " + DSYNC_PATH);
      }
      return true;
    } else if (preference == mBltimeout) {
      openDialog(
          getString(R.string.bltimeout_title),
          0,
          5000,
          preference,
          BL_TIMEOUT_PATH,
          PREF_BLTIMEOUT);
      return true;
    } else if (preference == mBltouch) {
      if (Helpers.readOneLine(BL_TOUCH_ON_PATH).equals("0")) {
        new CMDProcessor().su.runWaitFor("busybox echo 1 > " + BL_TOUCH_ON_PATH);
      } else {
        new CMDProcessor().su.runWaitFor("busybox echo 0 > " + BL_TOUCH_ON_PATH);
      }
      return true;
    } else if (preference == mBln) {
      if (Helpers.readOneLine(BLN_PATH).equals("0")) {
        new CMDProcessor().su.runWaitFor("busybox echo 1 > " + BLN_PATH);
      } else {
        new CMDProcessor().su.runWaitFor("busybox echo 0 > " + BLN_PATH);
      }
      return true;
    } else if (preference == mTouchScr) {
      Intent intent = new Intent(context, TouchScreenSettings.class);
      startActivity(intent);
      return true;
    } else if (preference == mViber) {
      openDialog(
          getString(R.string.viber_title),
          vib.get_min(),
          vib.get_max(),
          preference,
          VIBE_PATH,
          "pref_viber");
      return true;
    } else if (preference == mPFK) {
      Intent intent = new Intent(context, PFKActivity.class);
      startActivity(intent);
      return true;
    } else if (preference == mDynamicWriteBackOn) {
      if (Helpers.readOneLine(DYNAMIC_DIRTY_WRITEBACK_PATH).equals("0")) {
        new CMDProcessor().su.runWaitFor("busybox echo 1 > " + DYNAMIC_DIRTY_WRITEBACK_PATH);
      } else {
        new CMDProcessor().su.runWaitFor("busybox echo 0 > " + DYNAMIC_DIRTY_WRITEBACK_PATH);
      }
      return true;
    } else if (preference == mDynamicWriteBackActive) {
      openDialog(
          getString(R.string.dynamic_writeback_active_title),
          0,
          5000,
          preference,
          DIRTY_WRITEBACK_ACTIVE_PATH,
          PREF_DIRTY_WRITEBACK_ACTIVE);
      return true;
    } else if (preference == mDynamicWriteBackSuspend) {
      openDialog(
          getString(R.string.dynamic_writeback_suspend_title),
          0,
          5000,
          preference,
          DIRTY_WRITEBACK_SUSPEND_PATH,
          PREF_DIRTY_WRITEBACK_SUSPEND);
      return true;
    } else if (preference == mVM) {
      Intent intent = new Intent(context, VMSettings.class);
      startActivity(intent);
      return true;
    } else if (preference == mWifiPM) {
      if (Helpers.readOneLine(WIFIPM_PATH).equals("0")) {
        new CMDProcessor().su.runWaitFor("busybox echo 1 > " + WIFIPM_PATH);
      } else {
        new CMDProcessor().su.runWaitFor("busybox echo 0 > " + WIFIPM_PATH);
      }
      return true;
    }
    return super.onPreferenceTreeClick(preferenceScreen, preference);
  }
Esempio n. 12
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    setTheme();
    setContentView(R.layout.zram_settings);

    if (savedInstanceState != null) {
      showinfo = savedInstanceState.getBoolean("showinfo");
    }

    nf = NumberFormat.getInstance();
    nf.setMaximumFractionDigits(2);

    Intent i = getIntent();
    curdisk =
        i.getIntExtra("curdisk", mPreferences.getInt(PREF_ZRAM, Math.round(maxdisk * 18 / 100)));

    mdisksize = (SeekBar) findViewById(R.id.val1);
    mdisksize.setOnSeekBarChangeListener(this);
    mdisksize.setMax(max - min);
    final int percent = Math.round(curdisk * 100 / maxdisk);
    mdisksize.setProgress(percent - min);
    tval1 = (TextView) findViewById(R.id.tval1);
    tval1.setText(
        getString(R.string.zram_disk_size, Helpers.ReadableByteCount(curdisk * 1024 * 1024))
            + " ("
            + String.valueOf(percent)
            + "%)");

    cur = (TextView) findViewById(R.id.cur);
    t1 = (TextView) findViewById(R.id.t1);
    t2 = (TextView) findViewById(R.id.t2);
    t3 = (TextView) findViewById(R.id.t3);
    t4 = (TextView) findViewById(R.id.t4);
    t5 = (TextView) findViewById(R.id.t5);

    set_values();

    start_btn = (Button) findViewById(R.id.apply);
    start_btn.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View arg0) {
            if (is_zram_on()) {
              new StopZramOperation().execute();
            } else {
              new StartZramOperation().execute();
            }
          }
        });
    LinearLayout prev = (LinearLayout) findViewById(R.id.preview);

    prev.setOnLongClickListener(
        new View.OnLongClickListener() {
          @Override
          public boolean onLongClick(View v) {
            if (curcpu >= (ncpus - 1)) curcpu = 0;
            else curcpu++;
            return true;
          }
        });

    if (is_zram_on()) {
      start_btn.setText(getString(R.string.mt_stop));
      mdisksize.setEnabled(false);
      if (showinfo) {
        Toast.makeText(context, getString(R.string.ps_zram_info), Toast.LENGTH_LONG).show();
        showinfo = false;
      }
    } else {
      start_btn.setText(getString(R.string.mt_start));
      mdisksize.setEnabled(true);
    }
  }
Esempio n. 13
0
public class ZramActivity extends Activity
    implements Constants, SeekBar.OnSeekBarChangeListener, ActivityThemeChangeInterface {
  SharedPreferences mPreferences;
  private boolean mIsLightTheme;
  final Context context = this;
  private CurThread mCurThread;
  private TextView t1, t2, t3, t4, t5, tval1, cur;
  private SeekBar mdisksize;
  private int ncpus = Helpers.getNumOfCpus();
  private int curcpu = 0;
  private int curdisk = 0;
  private float maxdisk = (Helpers.getMem("MemTotal") / 1024);
  private Button start_btn;
  private NumberFormat nf;
  private static ProgressDialog progressDialog = null;
  private boolean showinfo = true;
  private static boolean isdialog = false;
  private int max = 60;
  private int min = 10;

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    setTheme();
    setContentView(R.layout.zram_settings);

    if (savedInstanceState != null) {
      showinfo = savedInstanceState.getBoolean("showinfo");
    }

    nf = NumberFormat.getInstance();
    nf.setMaximumFractionDigits(2);

    Intent i = getIntent();
    curdisk =
        i.getIntExtra("curdisk", mPreferences.getInt(PREF_ZRAM, Math.round(maxdisk * 18 / 100)));

    mdisksize = (SeekBar) findViewById(R.id.val1);
    mdisksize.setOnSeekBarChangeListener(this);
    mdisksize.setMax(max - min);
    final int percent = Math.round(curdisk * 100 / maxdisk);
    mdisksize.setProgress(percent - min);
    tval1 = (TextView) findViewById(R.id.tval1);
    tval1.setText(
        getString(R.string.zram_disk_size, Helpers.ReadableByteCount(curdisk * 1024 * 1024))
            + " ("
            + String.valueOf(percent)
            + "%)");

    cur = (TextView) findViewById(R.id.cur);
    t1 = (TextView) findViewById(R.id.t1);
    t2 = (TextView) findViewById(R.id.t2);
    t3 = (TextView) findViewById(R.id.t3);
    t4 = (TextView) findViewById(R.id.t4);
    t5 = (TextView) findViewById(R.id.t5);

    set_values();

    start_btn = (Button) findViewById(R.id.apply);
    start_btn.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View arg0) {
            if (is_zram_on()) {
              new StopZramOperation().execute();
            } else {
              new StartZramOperation().execute();
            }
          }
        });
    LinearLayout prev = (LinearLayout) findViewById(R.id.preview);

    prev.setOnLongClickListener(
        new View.OnLongClickListener() {
          @Override
          public boolean onLongClick(View v) {
            if (curcpu >= (ncpus - 1)) curcpu = 0;
            else curcpu++;
            return true;
          }
        });

    if (is_zram_on()) {
      start_btn.setText(getString(R.string.mt_stop));
      mdisksize.setEnabled(false);
      if (showinfo) {
        Toast.makeText(context, getString(R.string.ps_zram_info), Toast.LENGTH_LONG).show();
        showinfo = false;
      }
    } else {
      start_btn.setText(getString(R.string.mt_start));
      mdisksize.setEnabled(true);
    }
  }

  @Override
  public void onSaveInstanceState(Bundle saveState) {
    super.onSaveInstanceState(saveState);
    saveState.putBoolean("showinfo", showinfo);
  }

  @Override
  public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
    if (fromUser) {
      final int mb = Math.round((progress + min) * maxdisk / 100);
      tval1.setText(
          getString(R.string.zram_disk_size, Helpers.ReadableByteCount(mb * 1024 * 1024))
              + " ("
              + String.valueOf((progress + min))
              + "%)");
    }
  }

  @Override
  public void onStartTrackingTouch(SeekBar seekBar) {}

  @Override
  public void onStopTrackingTouch(SeekBar seekBar) {

    curdisk = Math.round((seekBar.getProgress() + min) * maxdisk / 100);
    tval1.setText(
        getString(R.string.zram_disk_size, Helpers.ReadableByteCount(curdisk * 1024 * 1024))
            + " ("
            + String.valueOf(seekBar.getProgress() + min)
            + "%)");

    mPreferences.edit().putInt(PREF_ZRAM, curdisk).commit();

    Intent returnIntent = new Intent();
    returnIntent.putExtra("result", 2);
    setResult(RESULT_OK, returnIntent);
  }

  @Override
  public boolean isThemeChanged() {
    final boolean is_light_theme = mPreferences.getBoolean(PREF_USE_LIGHT_THEME, false);
    return is_light_theme != mIsLightTheme;
  }

  @Override
  public void setTheme() {
    final boolean is_light_theme = mPreferences.getBoolean(PREF_USE_LIGHT_THEME, false);
    mIsLightTheme = is_light_theme;
    setTheme(is_light_theme ? R.style.Theme_Light : R.style.Theme_Dark);
  }

  @Override
  public void onResume() {
    if (mCurThread == null) {
      mCurThread = new CurThread();
      mCurThread.start();
    }
    if (isdialog)
      progressDialog = ProgressDialog.show(ZramActivity.this, null, getString(R.string.wait));
    super.onResume();
  }

  @Override
  public void onDestroy() {
    if (mCurThread != null) {
      if (mCurThread.isAlive()) {
        mCurThread.interrupt();
        try {
          mCurThread.join();
        } catch (InterruptedException e) {
        }
      }
    }
    super.onDestroy();
  }

  protected class CurThread extends Thread {
    private boolean mInterrupt = false;

    public void interrupt() {
      mInterrupt = true;
    }

    @Override
    public void run() {
      try {
        while (!mInterrupt) {
          sleep(800);
          mCurHandler.sendMessage(mCurHandler.obtainMessage(0, null));
        }
      } catch (InterruptedException e) {
        // return;
      }
    }
  }

  protected Handler mCurHandler =
      new Handler() {
        public void handleMessage(Message msg) {
          set_values();
        }
      };

  public boolean is_zram_on() {
    CMDProcessor.CommandResult cr =
        new CMDProcessor()
            .sh.runWaitFor("busybox echo `busybox cat /proc/swaps | busybox grep zram`");
    return (cr.success() && cr.stdout.contains("zram"));
  }

  private int getDiskSize() {
    return parseInt(Helpers.readOneLine(ZRAM_SIZE_PATH.replace("zram0", "zram" + curcpu)));
  }

  private int getCompressedDataSize() {
    return parseInt(Helpers.readOneLine(ZRAM_COMPR_PATH.replace("zram0", "zram" + curcpu)));
  }

  private int getOriginalDataSize() {
    return parseInt(Helpers.readOneLine(ZRAM_ORIG_PATH.replace("zram0", "zram" + curcpu)));
  }

  public float getCompressionRatio() {
    if (getOriginalDataSize() == 0) return 0;
    return ((float) getCompressedDataSize() / (float) getOriginalDataSize());
  }

  public float getUsedRatio() {
    if (getDiskSize() == 0) return 0;
    return ((float) getOriginalDataSize() / (float) getDiskSize());
  }

  private class StopZramOperation extends AsyncTask<String, Void, String> {
    @Override
    protected String doInBackground(String... params) {
      final StringBuilder sb = new StringBuilder();
      sb.append("zramstop ").append(ncpus).append(";\n");
      Helpers.shExec(sb, context, true);
      return "";
    }

    @Override
    protected void onPostExecute(String result) {
      isdialog = false;
      if (progressDialog != null && progressDialog.isShowing()) {
        progressDialog.dismiss();
      }
      if (is_zram_on()) {
        start_btn.setText(getString(R.string.mt_stop));
        mdisksize.setEnabled(false);
        mPreferences.edit().putBoolean(ZRAM_ON, true).commit();
        if (showinfo) {
          Toast.makeText(context, getString(R.string.ps_zram_info), Toast.LENGTH_LONG).show();
          showinfo = false;
        }
      } else {
        start_btn.setText(getString(R.string.mt_start));
        mdisksize.setEnabled(true);
        mPreferences.edit().putBoolean(ZRAM_ON, false).commit();
      }
    }

    @Override
    protected void onPreExecute() {
      progressDialog = ProgressDialog.show(ZramActivity.this, null, getString(R.string.wait));
      isdialog = true;
    }

    @Override
    protected void onProgressUpdate(Void... values) {}
  }

  private class StartZramOperation extends AsyncTask<String, Void, String> {
    @Override
    protected String doInBackground(String... params) {
      long v = (long) (curdisk * 1024 * 1024);
      final StringBuilder sb = new StringBuilder();
      sb.append("zramstart \"").append(ncpus).append("\" \"").append(v).append("\";\n");
      Helpers.shExec(sb, context, true);
      return "";
    }

    @Override
    protected void onPostExecute(String result) {
      isdialog = false;
      if (progressDialog != null) {
        progressDialog.dismiss();
      }
      if (is_zram_on()) {
        start_btn.setText(getString(R.string.mt_stop));
        mdisksize.setEnabled(false);
        mPreferences.edit().putBoolean(ZRAM_ON, true).apply();
        if (showinfo) {
          Toast.makeText(context, getString(R.string.ps_zram_info), Toast.LENGTH_LONG).show();
          showinfo = false;
        }
        if (mCurThread == null) {
          mCurThread = new CurThread();
          mCurThread.start();
        }
      } else {
        start_btn.setText(getString(R.string.mt_start));
        mdisksize.setEnabled(true);
        mPreferences.edit().putBoolean(ZRAM_ON, false).apply();
      }
    }

    @Override
    protected void onPreExecute() {
      progressDialog = ProgressDialog.show(ZramActivity.this, null, getString(R.string.wait));
      isdialog = true;
    }

    @Override
    protected void onProgressUpdate(Void... values) {}
  }

  public void set_values() {
    cur.setText(getString(R.string.prefcat_zram) + " " + String.valueOf(curcpu));
    t1.setText(Helpers.ReadableByteCount(0));
    t2.setText("0");
    t3.setText(Helpers.ReadableByteCount(0));
    t4.setText("0");
    t5.setText(Helpers.ReadableByteCount(0));
    Boolean ist1 = false;
    Boolean ist3 = false;
    Boolean ist5 = false;
    if (new File(ZRAM_COMPR_PATH.replace("zram0", "zram" + curcpu)).exists()) {
      t1.setText(
          Helpers.ReadableByteCount(
              parseInt(Helpers.readOneLine(ZRAM_COMPR_PATH.replace("zram0", "zram" + curcpu)))));
      ist1 = true;
    }
    if (new File(ZRAM_ORIG_PATH.replace("zram0", "zram" + curcpu)).exists()) {
      t3.setText(
          Helpers.ReadableByteCount(
              parseInt(Helpers.readOneLine(ZRAM_ORIG_PATH.replace("zram0", "zram" + curcpu)))));
      ist3 = true;
    }
    if (new File(ZRAM_MEMTOT_PATH.replace("zram0", "zram" + curcpu)).exists()) {
      t5.setText(
          Helpers.ReadableByteCount(
              parseInt(Helpers.readOneLine(ZRAM_MEMTOT_PATH.replace("zram0", "zram" + curcpu)))));
      ist5 = true;
    }
    if (ist1 && ist3 && ist5) {
      t2.setText(nf.format(getCompressionRatio()));
      t4.setText(nf.format(getUsedRatio()));
    }
  }
}
Esempio n. 14
0
 private int getOriginalDataSize() {
   return parseInt(Helpers.readOneLine(ZRAM_ORIG_PATH.replace("zram0", "zram" + curcpu)));
 }
Esempio n. 15
0
 private int getCompressedDataSize() {
   return parseInt(Helpers.readOneLine(ZRAM_COMPR_PATH.replace("zram0", "zram" + curcpu)));
 }
Esempio n. 16
0
 private int getDiskSize() {
   return parseInt(Helpers.readOneLine(ZRAM_SIZE_PATH.replace("zram0", "zram" + curcpu)));
 }