@Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.preferences);

    settings = SettingsStorage.getInstance();
    cputunerActionBar = (CputunerActionBar) findViewById(R.id.abCpuTuner);
    if (SettingsStorage.getInstance(this).hasHoloTheme()) {
      getActionBar().setTitle(R.string.app_name);
      cputunerActionBar.setVisibility(View.GONE);
    } else {
      cputunerActionBar.setHomeAction(
          new ActionBar.Action() {

            @Override
            public void performAction(View view) {
              onBackPressed();
            }

            @Override
            public int getDrawable() {
              return R.drawable.cputuner_back;
            }
          });
    }
  }
 private void fixProfiles() {
   SettingsStorage settings = SettingsStorage.getInstance();
   ContentValues values = new ContentValues(2);
   int maxFreq = settings.getMaxFrequencyDefault();
   values.put(DB.CpuProfile.NAME_FREQUENCY_MAX, maxFreq);
   int minFreq = settings.getMinFrequencyDefault();
   values.put(DB.CpuProfile.NAME_FREQUENCY_MIN, minFreq);
   Logger.i("Changing frequencies of default profile to min " + minFreq + " and max " + maxFreq);
   Cursor c = null;
   try {
     c =
         contentResolver.query(
             DB.CpuProfile.CONTENT_URI, DB.CpuProfile.PROJECTION_DEFAULT, null, null, null);
     while (c.moveToNext()) {
       contentResolver.update(
           DB.CpuProfile.CONTENT_URI,
           values,
           DB.SELECTION_BY_ID,
           new String[] {Long.toString(c.getLong(DB.INDEX_ID))});
     }
   } finally {
     if (c != null) {
       c.close();
       c = null;
     }
   }
 }
  @Override
  public void updateView() {
    if (spinnerSetGov == null) {
      // we have no been created yet
      return;
    }
    IGovernorModel governorModel = getGovernorModel();
    String curGov = governorModel.getGov();
    if (spinnerSetGov == null) {
      // we have no been created yet
      return;
    }
    for (int i = 0; i < availCpuGovs.length; i++) {
      if (curGov.equals(availCpuGovs[i])) {
        spinnerSetGov.setSelection(i);
      }
    }
    tvExplainGov.setText(GuiUtils.getExplainGovernor(getActivity(), curGov));
    if (SettingsStorage.getInstance().isPowerUser()) {
      etScript.setText(governorModel.getScript());
    }
    sbPowersaveBias.setProgress(governorModel.getPowersaveBias());
    updateGovernorFeatures();

    int position = numberOfCpus - governorModel.getUseNumberOfCpus();
    if (spUseCpus != null && position < spUseCpus.getAdapter().getCount()) {
      spUseCpus.setSelection(position);
    }
  }
Exemple #4
0
  @Override
  public void onReceive(Context context, Intent intent) {
    if (!SettingsStorage.getInstance().isEnableLogProfileSwitches()) {
      return;
    }
    if (intent == null) {
      return;
    }
    if (ACTION_FLUSH_LOG.equals(intent.getAction())
        || intent.getBooleanExtra(ACTION_FLUSH_LOG, false)) {
      flushLogToDB(context);
      return;
    }
    ContentValues values = new ContentValues();
    values.put(DB.SwitchLogDB.NAME_TIME, System.currentTimeMillis());
    values.put(DB.SwitchLogDB.NAME_MESSAGE, intent.getStringExtra(EXTRA_LOG_ENTRY));
    values.put(DB.SwitchLogDB.NAME_TRIGGER, intent.getStringExtra(DB.SwitchLogDB.NAME_TRIGGER));
    values.put(DB.SwitchLogDB.NAME_PROFILE, intent.getStringExtra(DB.SwitchLogDB.NAME_PROFILE));
    values.put(DB.SwitchLogDB.NAME_VIRTGOV, intent.getStringExtra(DB.SwitchLogDB.NAME_VIRTGOV));
    values.put(DB.SwitchLogDB.NAME_AC, intent.getIntExtra(DB.SwitchLogDB.NAME_AC, -1));
    values.put(DB.SwitchLogDB.NAME_BATTERY, intent.getIntExtra(DB.SwitchLogDB.NAME_BATTERY, -1));
    values.put(DB.SwitchLogDB.NAME_CALL, intent.getIntExtra(DB.SwitchLogDB.NAME_CALL, -1));
    values.put(DB.SwitchLogDB.NAME_HOT, intent.getIntExtra(DB.SwitchLogDB.NAME_HOT, -1));
    values.put(DB.SwitchLogDB.NAME_LOCKED, intent.getIntExtra(DB.SwitchLogDB.NAME_LOCKED, -1));

    Builder opp = ContentProviderOperation.newInsert(DB.SwitchLogDB.CONTENT_URI);
    opp.withValues(values);
    operations.add(opp.build());
    if (operations.size() > 10 || intent.getBooleanExtra(EXTRA_FLUSH_LOG, false)) {
      flushLogToDB(context);
    }
  }
 @Override
 public void updateModel() {
   IGovernorModel governorModel = getGovernorModel();
   governorModel.setGovernorThresholdUp(etGovTreshUp.getText().toString());
   governorModel.setGovernorThresholdDown(etGovTreshDown.getText().toString());
   if (SettingsStorage.getInstance().isEnableScriptOnProfileChange()) {
     governorModel.setScript(etScript.getText().toString());
   } else {
     governorModel.setScript("");
   }
   governorModel.setPowersaveBias(sbPowersaveBias.getProgress());
 }
Exemple #6
0
  private void flushLogToDB(Context context) {
    try {
      int logSize = SettingsStorage.getInstance().getProfileSwitchLogSize();
      if (logSize > -1) {
        Builder opp = ContentProviderOperation.newDelete(DB.SwitchLogDB.CONTENT_URI);
        String time = Long.toString(System.currentTimeMillis() - (logSize * HOURS_IN_MILLIES));
        opp.withSelection(DB.SwitchLogDB.SELECTION_BY_TIME, new String[] {time});
        operations.add(opp.build());
      }

      context.getContentResolver().applyBatch(CpuTunerProvider.AUTHORITY, operations);
      operations.clear();
    } catch (Exception e) {
      Logger.w("Cannot flush to switch log");
    }
  }
 @Override
 public View onCreateView(
     LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
   // Inflate the layout for this fragment
   View v = inflater.inflate(R.layout.governor_fragment, container, false);
   llFragmentTop = (LinearLayout) v.findViewById(R.id.llGovernorFragment);
   tvExplainGov = (TextView) v.findViewById(R.id.tvExplainGov);
   llGovernorThresholds = (LinearLayout) v.findViewById(R.id.llGovernorThresholds);
   labelGovThreshUp = (TextView) v.findViewById(R.id.labelGovThreshUp);
   labelGovThreshDown = (TextView) v.findViewById(R.id.labelGovThreshDown);
   etGovTreshUp = (EditText) v.findViewById(R.id.etGovTreshUp);
   etGovTreshDown = (EditText) v.findViewById(R.id.etGovTreshDown);
   spinnerSetGov = (Spinner) v.findViewById(R.id.SpinnerCpuGov);
   etScript = (EditText) v.findViewById(R.id.etScript);
   llPowersaveBias = (LinearLayout) v.findViewById(R.id.llPowersaveBias);
   sbPowersaveBias = (SeekBar) v.findViewById(R.id.sbPowersaveBias);
   spUseCpus = (Spinner) v.findViewById(R.id.spUseCpus);
   if (disableScript || !SettingsStorage.getInstance().isEnableScriptOnProfileChange()) {
     llFragmentTop.removeView(v.findViewById(R.id.llScript));
   }
   return v;
 }
 @Override
 protected void onPause() {
   super.onPause();
   SettingsStorage.getInstance().forgetValues();
   CpuHandler.resetInstance(this);
 }