use of com.moro.mtweaks.database.tools.customcontrols.Controls in project MTweaks-KernelAdiutorMOD by morogoku.
the class OnBootFragment method addItems.
@Override
protected void addItems(List<RecyclerViewItem> items) {
if (mSettings == null) {
mSettings = new Settings(getActivity());
}
if (mControls == null) {
mControls = new Controls(getActivity());
}
if (mProfiles == null) {
mProfiles = new Profiles(getActivity());
}
if (!mLoaded) {
mLoaded = true;
load(items);
}
}
use of com.moro.mtweaks.database.tools.customcontrols.Controls in project MTweaks-KernelAdiutorMOD by morogoku.
the class ApplyOnBoot method apply.
public static boolean apply(final Context context, final ApplyOnBootListener listener) {
// Initialize AppUpdate check
AppUpdaterTask.appCheckNotification(context);
// Initialize Boeffla Wakelock Blocker Files
if (BoefflaWakelock.supported()) {
BoefflaWakelock.CopyWakelockBlockerDefault();
}
// Check if kernel is changed
String kernel_old = Prefs.getString("kernel_version_old", "", context);
String kernel_new = Device.getKernelVersion(true);
// If is changed save voltage files
if (!kernel_old.equals(kernel_new)) {
// Save backup of Cluster0 stock voltages
if (VoltageCl0.supported()) {
RootUtils.runCommand("cp " + VoltageCl0.CL0_VOLTAGE + " " + VoltageCl0.BACKUP);
Prefs.saveBoolean("cl0_voltage_saved", true, context);
}
// Save backup of Cluster1 stock voltages
if (VoltageCl1.supported()) {
RootUtils.runCommand("cp " + VoltageCl1.CL1_VOLTAGE + " " + VoltageCl1.BACKUP);
Prefs.saveBoolean("cl1_voltage_saved", true, context);
}
// Save backup of GPU stock voltages
if (GPUFreq.supported() && GPUFreq.hasVoltage()) {
RootUtils.runCommand("cp " + GPUFreq.AVAILABLE_VOLTS + " " + GPUFreq.BACKUP);
Prefs.saveBoolean("gpu_voltage_saved", true, context);
}
RootUtils.runCommand("setprop mtweaks.voltage_saved 1");
}
if (!Prefs.getBoolean(ApplyOnBootFragment.getAssignment(CPUHotplugFragment.class), false, context)) {
Prefs.remove("core_ctl_min_cpus_big", context);
}
boolean enabled = false;
final Settings settings = new Settings(context);
Controls controls = new Controls(context);
final HashMap<String, Boolean> mCategoryEnabled = new HashMap<>();
final HashMap<String, String> mCustomControls = new HashMap<>();
final List<String> mProfiles = new ArrayList<>();
List<Profiles.ProfileItem> profiles = new Profiles(context).getAllProfiles();
Tile.publishProfileTile(profiles, context);
for (Settings.SettingsItem item : settings.getAllSettings()) {
if (!mCategoryEnabled.containsKey(item.getCategory())) {
boolean categoryEnabled = Prefs.getBoolean(item.getCategory(), false, context);
mCategoryEnabled.put(item.getCategory(), categoryEnabled);
if (!enabled && categoryEnabled) {
enabled = true;
}
}
}
for (Controls.ControlItem item : controls.getAllControls()) {
if (item.isOnBootEnabled() && item.getArguments() != null) {
mCustomControls.put(item.getApply(), item.getArguments());
}
}
for (Profiles.ProfileItem profileItem : profiles) {
if (profileItem.isOnBootEnabled()) {
for (Profiles.ProfileItem.CommandItem commandItem : profileItem.getCommands()) {
mProfiles.add(commandItem.getCommand());
}
}
}
final boolean initdEnabled = Prefs.getBoolean("initd_onboot", false, context);
enabled = enabled || mCustomControls.size() > 0 || mProfiles.size() > 0 || initdEnabled;
if (!enabled) {
return false;
}
final int seconds = Utils.strToInt(Prefs.getString("applyonbootdelay", "10", context));
final boolean hideNotification = Prefs.getBoolean("applyonboothide", false, context);
final boolean confirmationNotification = Prefs.getBoolean("applyonbootconfirmationnotification", true, context);
final boolean toast = Prefs.getBoolean("applyonboottoast", false, context);
final boolean script = Prefs.getBoolean("applyonbootscript", false, context);
PendingIntent cancelIntent = PendingIntent.getBroadcast(context, 1, new Intent(context, CancelReceiver.class), PendingIntent.FLAG_UPDATE_CURRENT);
Intent launchIntent = new Intent(context, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, launchIntent, 0);
final NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
final NotificationCompat.Builder builder = new NotificationCompat.Builder(context, ApplyOnBootService.CHANNEL_ID);
if (!hideNotification) {
builder.setContentTitle(context.getString(R.string.app_name)).setContentText(context.getString(R.string.apply_on_boot_text, seconds)).setSmallIcon(R.mipmap.ic_launcher).addAction(0, context.getString(R.string.cancel), cancelIntent).setOngoing(true).setWhen(0);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
builder.setPriority(Notification.PRIORITY_MAX);
}
}
final NotificationCompat.Builder builderComplete = new NotificationCompat.Builder(context, ApplyOnBootService.CHANNEL_ID);
if (!hideNotification) {
builderComplete.setContentTitle(context.getString(R.string.app_name)).setSmallIcon(R.mipmap.ic_launcher).setContentIntent(contentIntent).setAutoCancel(true);
}
final Handler handler = new Handler();
new Thread(new Runnable() {
@Override
public void run() {
sCancel = false;
for (int i = 0; i < seconds; i++) {
if (!hideNotification) {
if (sCancel) {
break;
}
builder.setContentText(context.getString(R.string.apply_on_boot_text, seconds - i));
builder.setProgress(seconds, i, false);
notificationManager.notify(NotificationId.APPLY_ON_BOOT, builder.build());
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
if (!hideNotification) {
notificationManager.cancel(NotificationId.APPLY_ON_BOOT);
if (confirmationNotification) {
builderComplete.setContentText(context.getString(sCancel ? R.string.apply_on_boot_canceled : R.string.apply_on_boot_complete));
notificationManager.notify(NotificationId.APPLY_ON_BOOT_CONFIRMATION, builderComplete.build());
}
if (sCancel) {
sCancel = false;
listener.onFinish();
return;
}
}
RootUtils.SU su = new RootUtils.SU(true, TAG);
if (initdEnabled) {
RootUtils.mount(true, "/system", su);
su.runCommand("for i in `ls /system/etc/init.d`;do chmod 755 $i;done");
su.runCommand("[ -d /system/etc/init.d ] && run-parts /system/etc/init.d");
RootUtils.mount(false, "/system", su);
}
List<String> commands = new ArrayList<>();
for (Settings.SettingsItem item : settings.getAllSettings()) {
String category = item.getCategory();
String setting = item.getSetting();
String id = item.getId();
CPUFreq.ApplyCpu applyCpu;
if (mCategoryEnabled.get(category)) {
if (category.equals(ApplyOnBootFragment.CPU) && id.contains("%d") && setting.startsWith("#") && ((applyCpu = new CPUFreq.ApplyCpu(setting.substring(1))).toString() != null)) {
synchronized (this) {
commands.addAll(getApplyCpu(applyCpu, su, context));
}
} else {
commands.add(setting);
}
}
}
if (script) {
StringBuilder s = new StringBuilder("#!/system/bin/sh\n\n");
for (String command : commands) {
s.append(command).append("\n");
}
RootFile file = new RootFile("/data/local/tmp/kerneladiutortmp.sh", su);
file.mkdir();
file.write(s.toString(), false);
file.execute();
} else {
for (String command : commands) {
synchronized (this) {
su.runCommand(command);
}
}
}
for (String script : mCustomControls.keySet()) {
RootFile file = new RootFile("/data/local/tmp/kerneladiutortmp.sh", su);
file.mkdir();
file.write(script, false);
file.execute(mCustomControls.get(script));
}
List<String> profileCommands = new ArrayList<>();
for (String command : mProfiles) {
CPUFreq.ApplyCpu applyCpu;
if (command.startsWith("#") && ((applyCpu = new CPUFreq.ApplyCpu(command.substring(1))).toString() != null)) {
synchronized (this) {
profileCommands.addAll(getApplyCpu(applyCpu, su, context));
}
}
profileCommands.add(command);
}
if (script) {
StringBuilder s = new StringBuilder("#!/system/bin/sh\n\n");
for (String command : profileCommands) {
s.append(command).append("\n");
}
RootFile file = new RootFile("/data/local/tmp/kerneladiutortmp.sh", su);
file.mkdir();
file.write(s.toString(), false);
file.execute();
} else {
for (String command : profileCommands) {
synchronized (this) {
su.runCommand(command);
}
}
}
su.close();
if (toast) {
handler.post(new Runnable() {
@Override
public void run() {
Utils.toast(R.string.apply_on_boot_complete, context);
}
});
}
listener.onFinish();
}
}).start();
return true;
}
use of com.moro.mtweaks.database.tools.customcontrols.Controls in project MTweaks-KernelAdiutorMOD by morogoku.
the class CustomControlsFragment method load.
private void load(List<RecyclerViewItem> items) {
mControlsProvider = new Controls(getActivity());
for (final Controls.ControlItem item : mControlsProvider.getAllControls()) {
CardView cardView = getCard(item);
cardView.clearItems();
try {
String title = item.getTitle();
String description = item.getDescription();
if (item.getControl() == Items.Control.SWITCH) {
SwitchView switchView = new SwitchView();
if (description != null) {
switchView.setTitle(title);
switchView.setSummary(description);
} else {
switchView.setSummary(title);
}
switchView.setChecked(Values.getBool(item.getString("enable")));
switchView.addOnSwitchListener(new SwitchView.OnSwitchListener() {
@Override
public void onChanged(SwitchView switchView, boolean isChecked) {
Values.run(item.getApply(), item, isChecked ? "1" : "0");
mControlsProvider.commit();
}
});
cardView.addItem(switchView);
} else if (item.getControl() == Items.Control.SEEKBAR) {
SeekBarView seekBarView = new SeekBarView();
seekBarView.setTitle(title);
if (description != null) {
seekBarView.setSummary(description);
}
seekBarView.setMax(item.getInt("max"));
seekBarView.setMin(item.getInt("min"));
seekBarView.setProgress(Values.getInt(item.getString("progress")));
seekBarView.setOnSeekBarListener(new SeekBarView.OnSeekBarListener() {
@Override
public void onStop(SeekBarView seekBarView, int position, String value) {
Values.run(item.getApply(), item, String.valueOf(position));
mControlsProvider.commit();
}
@Override
public void onMove(SeekBarView seekBarView, int position, String value) {
}
});
cardView.addItem(seekBarView);
} else if (item.getControl() == Items.Control.GENERIC) {
GenericSelectView genericSelectView = new GenericSelectView();
if (description != null) {
genericSelectView.setTitle(title);
genericSelectView.setSummary(description);
} else {
genericSelectView.setSummary(title);
}
genericSelectView.setValue(Values.getString(item.getString("value")));
genericSelectView.setValueRaw(genericSelectView.getValue());
genericSelectView.setOnGenericValueListener(new GenericSelectView.OnGenericValueListener() {
@Override
public void onGenericValueSelected(GenericSelectView genericSelectView, String value) {
Values.run(item.getApply(), item, value);
genericSelectView.setValue(value);
mControlsProvider.commit();
}
});
cardView.addItem(genericSelectView);
}
} catch (CustomControlException e) {
ErrorView errorView = new ErrorView();
errorView.setException(e);
cardView.addItem(errorView);
}
items.add(cardView);
}
}
Aggregations