use of com.spazedog.lib.rootfw3.RootFW in project mounts2sd by SpazeDog.
the class FragmentTabConfigure method getEnabledSelectorValues.
private String[] getEnabledSelectorValues(Integer id) {
if (!oEnabledSelectorValues.containsKey(id)) {
RootFW rootfw;
switch(id) {
case R.id.option_immc_item_readahead:
oEnabledSelectorValues.put(id, new String[] { "4", "8", "16", "32", "64", "128" });
break;
case R.id.option_immc_item_scheduler:
case R.id.option_emmc_item_scheduler:
rootfw = Root.initiate();
String file = id == R.id.option_immc_item_scheduler ? mPreferences.deviceSetup.path_device_scheduler_immc() : mPreferences.deviceSetup.path_device_scheduler_emmc();
String content = rootfw.file(file).readOneLine();
String[] parts = null;
if (content != null) {
parts = content.split(" ");
for (int i = 0; i < parts.length; i++) {
if (parts[i].contains("[")) {
parts[i] = parts[i].substring(1, parts[i].length() - 1);
}
}
}
Root.release();
oEnabledSelectorValues.put(id, parts);
break;
case R.id.option_filesystem_item_fstype:
rootfw = Root.initiate();
FileData data = rootfw.file("/proc/filesystems").read();
ArrayList<String> filesystems = new ArrayList<String>();
if (data != null) {
String[] lines = data.getArray();
filesystems.add("auto");
for (int i = 0; i < lines.length; i++) {
if (!lines[i].contains("nodev ")) {
filesystems.add(lines[i].trim());
}
}
}
Root.release();
oEnabledSelectorValues.put(id, filesystems.size() > 0 ? filesystems.toArray(new String[filesystems.size()]) : null);
break;
default:
oEnabledSelectorValues.put(id, null);
}
}
return oEnabledSelectorValues.get(id);
}
use of com.spazedog.lib.rootfw3.RootFW in project mounts2sd by SpazeDog.
the class FragmentTabLog method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
ViewGroup view = (ViewGroup) inflater.inflate(R.layout.fragment_tab_log, container, false);
TableLayout table = (TableLayout) view.findViewById(R.id.log_table);
if (oLogEntry == null) {
RootFW rootfw = Root.initiate();
FileData data = rootfw.file(getResources().getString(R.string.config_dir_tmp) + "/log.txt").read();
if (data == null) {
data = rootfw.file("/data/m2sd.fallback.log").read();
if (data != null) {
oLogEntry = data.getArray();
}
} else {
oLogEntry = data.getArray();
}
if (oLogEntry == null || oLogEntry.length == 0) {
oLogEntry = new String[] { "I/" + getResources().getString(R.string.log_empty) };
}
Root.release();
}
Boolean bool = false;
Integer color1 = getResources().getColor(resolveAttr(R.attr.colorRef_logItemBackgroundFirst));
Integer color2 = getResources().getColor(resolveAttr(R.attr.colorRef_logItemBackgroundSecond));
for (int i = 0; i < oLogEntry.length; i++) {
TableRow row = (TableRow) inflater.inflate(R.layout.inflate_log_item, table, false);
String[] parts = oLogEntry[i].split("/", 2);
((TextView) row.getChildAt(0)).setText(parts.length > 1 ? parts[0] : "?");
((TextView) row.getChildAt(1)).setText(parts.length > 1 ? parts[1] : parts[0]);
if ((bool = !bool)) {
row.setBackgroundColor(color1);
} else {
row.setBackgroundColor(color2);
}
table.addView(row);
}
return (View) view;
}
use of com.spazedog.lib.rootfw3.RootFW in project mounts2sd by SpazeDog.
the class ReceiverBoot method onReceive.
@Override
public void onReceive(Context context, Intent intent) {
if ("android.intent.action.BOOT_COMPLETED".equals(intent.getAction())) {
new Thread() {
private Context mContext;
public Thread putContext(Context context) {
mContext = context;
return this;
}
@Override
public void run() {
String message = null;
RootFW root = Root.initiate();
if (root.isConnected()) {
Preferences preferences = Preferences.getInstance(mContext);
if (!preferences.deviceSetup.load(true) || !preferences.deviceConfig.load(true) || !preferences.deviceProperties.load(true)) {
message = mContext.getResources().getString(R.string.notify_no_config);
} else if (preferences.deviceSetup.log_level() > 1) {
message = mContext.getResources().getString(R.string.notify_log_details);
}
} else {
message = mContext.getResources().getString(R.string.notify_no_config);
}
if (message != null) {
NotificationManager manager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
NotificationCompat.Builder notification = new NotificationCompat.Builder(mContext).setContentIntent(PendingIntent.getActivity(mContext, 0, new Intent(mContext, ActivityTabController.class), 0)).setSmallIcon(R.drawable.ic_launcher).setWhen(System.currentTimeMillis()).setAutoCancel(true).setContentTitle(mContext.getApplicationInfo().name).setContentText(message);
manager.notify(1, notification.build());
}
Root.release();
}
}.putContext(context.getApplicationContext()).start();
}
}
use of com.spazedog.lib.rootfw3.RootFW in project mounts2sd by SpazeDog.
the class Preferences method getInstance.
public static Preferences getInstance(Context context) {
synchronized (oClassLock) {
Preferences tmpPreferences = oClassReference != null ? oClassReference.get() : null;
Context tmpContext = oContextReference != null ? oContextReference.get() : null;
if (tmpContext == null)
oContextReference = new WeakReference<Context>((tmpContext = context.getApplicationContext()));
if (tmpPreferences == null)
oClassReference = new WeakReference<Preferences>((tmpPreferences = new Preferences()));
if (tmpPreferences.mSharedPreferences.size() == 0) {
tmpPreferences.mSharedPreferences.put("cache", tmpContext.getSharedPreferences("cache", 0x00000000));
tmpPreferences.mSharedPreferences.put("persistent", tmpContext.getSharedPreferences("persistent", 0x00000000));
}
if (!oClassChecks.get("initiated.cache")) {
String appid = tmpContext.getResources().getString(R.string.config_application_id);
SharedPreferences sharedPreferences = tmpPreferences.mSharedPreferences.get("cache");
if (!appid.equals("" + sharedPreferences.getInt("android.appId", 0)) || !new java.io.File("/boot.chk").exists()) {
RootFW root = Root.initiate();
Editor edit = sharedPreferences.edit();
edit.clear();
edit.putInt("android.appId", Integer.parseInt(appid));
edit.commit();
if (root.isConnected()) {
root.filesystem("/").addMount(new String[] { "remount", "rw" });
root.file("/boot.chk").write("1");
root.filesystem("/").addMount(new String[] { "remount", "ro" });
} else {
((SharedRootFW) root).addInstanceListener(new ConnectionListener() {
@Override
public void onConnectionEstablished(RootFW instance) {
instance.filesystem("/").addMount(new String[] { "remount", "rw" });
instance.file("/boot.chk").write("1");
instance.filesystem("/").addMount(new String[] { "remount", "ro" });
((SharedRootFW) instance).removeInstanceListener(this);
}
@Override
public void onConnectionFailed(RootFW instance) {
}
@Override
public void onConnectionClosed(RootFW instance) {
}
});
}
Root.release();
}
oClassChecks.put("initiated.cache", true);
}
return tmpPreferences;
}
}
use of com.spazedog.lib.rootfw3.RootFW in project mounts2sd by SpazeDog.
the class FragmentTabConfigure method onDialogCreateView.
@Override
public View onDialogCreateView(String tag, LayoutInflater inflater, ViewGroup container, final Bundle extra) {
ViewGroup placeholder = (ViewGroup) inflater.inflate(R.layout.inflate_dialog_placeholder, container, false);
String selectorType = extra.getString("type");
String selectorValue = extra.getString("value");
String[] selectorEnabledValues = getEnabledSelectorValues(extra.getInt("viewId"));
Integer selectorNamesId = getResources().getIdentifier("selector_" + selectorType + "_names", "array", getActivity().getPackageName());
Integer selectorValuesId = getResources().getIdentifier("selector_" + selectorType + "_values", "array", getActivity().getPackageName());
Integer selectorCommentsId = getResources().getIdentifier("selector_" + selectorType + "_comments", "array", getActivity().getPackageName());
if (selectorNamesId != 0 && selectorValuesId != 0) {
String[] selectorNames = getResources().getStringArray(selectorNamesId);
String[] selectorValues = getResources().getStringArray(selectorValuesId);
String[] selectorComments = selectorCommentsId != 0 ? getResources().getStringArray(selectorCommentsId) : new String[selectorNames.length];
for (int i = 0; i < selectorNames.length; i++) {
ViewGroup itemView = (ViewGroup) inflater.inflate(R.layout.inflate_selector_item, (ViewGroup) placeholder, false);
Boolean enabled = true;
if (selectorEnabledValues != null) {
for (int x = 0; x < selectorEnabledValues.length; x++) {
if (selectorEnabledValues[x].equals(selectorValues[i])) {
enabled = true;
break;
}
enabled = false;
}
}
if (selectorType.equals("threshold")) {
selectorComments[i] = Common.convertPrifix((mPreferences.deviceConfig.size_storage_data() * (Double.parseDouble(selectorValues[i]) / 100)));
} else if (selectorType.equals("zram")) {
if (oMemoryUsage == null) {
RootFW rootfw = Root.initiate();
MemStat memstat = rootfw.memory().getUsage();
oMemoryUsage = memstat != null ? memstat.memTotal().doubleValue() : 0D;
Root.release();
}
selectorComments[i] = Common.convertPrifix((oMemoryUsage * (Double.parseDouble(selectorValues[i]) / 100)));
}
((TextView) itemView.findViewById(R.id.item_name)).setText(selectorNames[i]);
if (selectorComments[i] != null && !selectorComments[i].equals("")) {
((TextView) itemView.findViewById(R.id.item_description)).setText(selectorComments[i]);
}
itemView.setSelected(selectorValues[i].equals(selectorValue));
itemView.setEnabled(enabled);
itemView.setTag(selectorValues[i]);
itemView.setOnTouchListener(new ViewEventHandler(new ViewClickListener() {
@Override
public void onViewClick(View v) {
extra.putString("value", (String) v.getTag());
ViewGroup view = (ViewGroup) v.getParent();
for (int i = 0; i < view.getChildCount(); i++) {
View child = view.getChildAt(i);
if (child == v) {
child.setSelected(true);
} else {
child.setSelected(false);
}
}
}
}));
if (i > 0) {
inflater.inflate(R.layout.inflate_dialog_divider, placeholder);
}
placeholder.addView(itemView);
}
}
return placeholder;
}
Aggregations