コード例 #1
0
  private void updateGovernorFeatures() {
    IGovernorModel governorModel = getGovernorModel();
    GovernorConfig governorConfig = GovernorConfigHelper.getGovernorConfig(governorModel.getGov());

    int up = governorModel.getGovernorThresholdUp();
    int down = governorModel.getGovernorThresholdDown();
    boolean hasThreshholdUp = governorConfig.hasThreshholdUpFeature();
    boolean hasThreshholdDown = governorConfig.hasThreshholdDownFeature();

    if (hasThreshholdUp) {
      llGovernorThresholds.setVisibility(View.VISIBLE);
    } else {
      llGovernorThresholds.setVisibility(View.GONE);
    }

    if (hasThreshholdUp) {
      labelGovThreshUp.setVisibility(View.VISIBLE);
      etGovTreshUp.setVisibility(View.VISIBLE);
      if (up < 2) {
        up = Integer.parseInt(origThreshUp);
      }
      if (up < 2) {
        up = 90;
      }
      etGovTreshUp.setText(up + "");
    } else {
      governorModel.setGovernorThresholdUp(0);
      labelGovThreshUp.setVisibility(View.INVISIBLE);
      etGovTreshUp.setVisibility(View.INVISIBLE);
      etGovTreshUp.setText("-1");
    }

    if (hasThreshholdDown) {
      labelGovThreshDown.setVisibility(View.VISIBLE);
      etGovTreshDown.setVisibility(View.VISIBLE);
      if (down < 1) {
        down = Integer.parseInt(origThreshDown);
      }
      if (down >= up || down < 1) {
        if (up > 30) {
          down = up - 10;
        } else {
          down = up - 1;
        }
      }
      etGovTreshDown.setText(down + "");
    } else {
      governorModel.setGovernorThresholdDown(0);
      labelGovThreshDown.setVisibility(View.INVISIBLE);
      etGovTreshDown.setVisibility(View.INVISIBLE);
      etGovTreshDown.setText("-1");
    }

    if (governorConfig.hasPowersaveBias()) {
      llPowersaveBias.setVisibility(View.VISIBLE);
    } else {
      llPowersaveBias.setVisibility(View.GONE);
    }
  }
コード例 #2
0
 private void fixGovernors() {
   Cursor c = null;
   String[] availCpuGov = CpuHandler.getInstance().getAvailCpuGov();
   TreeMap<String, Boolean> availGovs = new TreeMap<String, Boolean>();
   for (String gov : availCpuGov) {
     availGovs.put(gov, Boolean.TRUE);
   }
   try {
     c =
         contentResolver.query(
             DB.VirtualGovernor.CONTENT_URI,
             DB.VirtualGovernor.PROJECTION_DEFAULT,
             null,
             null,
             null);
     while (c.moveToNext()) {
       String govs = c.getString(DB.VirtualGovernor.INDEX_REAL_GOVERNOR);
       String[] govitems = govs.split("\\|");
       boolean found = false;
       for (String gov : govitems) {
         Boolean avail = availGovs.get(gov);
         if (avail != null && avail) {
           Logger.i("Using " + gov);
           ContentValues values = new ContentValues(1);
           values.put(DB.VirtualGovernor.NAME_REAL_GOVERNOR, gov);
           // check for thresholds
           GovernorConfig governorConfig = GovernorConfigHelper.getGovernorConfig(gov);
           if (!governorConfig.hasThreshholdUpFeature()) {
             values.put(DB.VirtualGovernor.NAME_GOVERNOR_THRESHOLD_UP, -1);
           }
           if (!governorConfig.hasThreshholdDownFeature()) {
             values.put(DB.VirtualGovernor.NAME_GOVERNOR_THRESHOLD_DOWN, -1);
           }
           if (contentResolver.update(
                   DB.VirtualGovernor.CONTENT_URI,
                   values,
                   DB.SELECTION_BY_ID,
                   new String[] {Long.toString(c.getLong(DB.INDEX_ID))})
               > 0) {
             found = true;
             break;
           }
         }
       }
       if (!found) {
         // we did not find a compatible gov so use none
         ContentValues values = new ContentValues(1);
         values.put(DB.VirtualGovernor.NAME_REAL_GOVERNOR, RootHandler.NOT_AVAILABLE);
         contentResolver.update(
             DB.VirtualGovernor.CONTENT_URI,
             values,
             DB.SELECTION_BY_ID,
             new String[] {Long.toString(c.getLong(DB.INDEX_ID))});
       }
     }
   } finally {
     if (c != null) {
       c.close();
       c = null;
     }
   }
 }