Search in sources :

Example 1 with Settings

use of com.moro.mtweaks.database.Settings 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);
    }
}
Also used : Profiles(com.moro.mtweaks.database.tools.profiles.Profiles) Controls(com.moro.mtweaks.database.tools.customcontrols.Controls) Settings(com.moro.mtweaks.database.Settings)

Example 2 with Settings

use of com.moro.mtweaks.database.Settings 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;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Profiles(com.moro.mtweaks.database.tools.profiles.Profiles) Controls(com.moro.mtweaks.database.tools.customcontrols.Controls) NotificationCompat(android.support.v4.app.NotificationCompat) Settings(com.moro.mtweaks.database.Settings) NotificationManager(android.app.NotificationManager) Handler(android.os.Handler) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) CPUFreq(com.moro.mtweaks.utils.kernel.cpu.CPUFreq) RootUtils(com.moro.mtweaks.utils.root.RootUtils) PendingIntent(android.app.PendingIntent) RootFile(com.moro.mtweaks.utils.root.RootFile)

Example 3 with Settings

use of com.moro.mtweaks.database.Settings in project MTweaks-KernelAdiutorMOD by morogoku.

the class Monitor method postCreate.

private void postCreate(final Long[] times) {
    if (mLevel < 15 || !Prefs.getBoolean("data_sharing", true, this))
        return;
    new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                JSONObject data = new JSONObject();
                data.put("android_id", Utils.getAndroidId(Monitor.this));
                data.put("android_version", Device.getVersion());
                data.put("kernel_version", Device.getKernelVersion(true, false));
                data.put("app_version", BuildConfig.VERSION_NAME);
                data.put("board", Device.getBoard(false));
                data.put("model", Device.getModel());
                data.put("vendor", Device.getVendor());
                data.put("cpuinfo", Utils.encodeString(Device.CPUInfo.getCpuInfo(false)));
                data.put("fingerprint", Device.getFingerprint());
                JSONArray commands = new JSONArray();
                Settings settings = new Settings(Monitor.this);
                for (Settings.SettingsItem item : settings.getAllSettings()) {
                    commands.put(item.getSetting());
                }
                data.put("commands", commands);
                JSONArray batteryTimes = new JSONArray();
                for (long time : times) {
                    batteryTimes.put(time);
                }
                data.put("times", batteryTimes);
                try {
                    long time = 0;
                    for (int i = 0; i < 100000; i++) {
                        time += Utils.computeSHAHash(Utils.getRandomString(16));
                    }
                    data.put("cpu", time);
                } catch (Exception ignored) {
                }
                mServerCreateDevice.postDeviceCreate(data);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }).start();
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) Settings(com.moro.mtweaks.database.Settings) RemoteException(android.os.RemoteException) JSONException(org.json.JSONException)

Example 4 with Settings

use of com.moro.mtweaks.database.Settings in project MTweaks-KernelAdiutorMOD by morogoku.

the class Control method apply.

private synchronized void apply(String command, String category, String id, final Context context) {
    if (context != null) {
        if (mProfileMode) {
            Log.i(TAG, "Added to profile: " + id);
            mProfileCommands.put(id, command);
        } else {
            Settings settings = new Settings(context);
            List<Settings.SettingsItem> items = settings.getAllSettings();
            for (int i = 0; i < items.size(); i++) {
                if (items.get(i).getId().equals(id) && items.get(i).getCategory().equals(category)) {
                    settings.delete(i);
                }
            }
            settings.putSetting(category, command, id);
            settings.commit();
            Log.i(TAG, "saved " + id);
        }
    }
    if (command.startsWith("#"))
        return;
    RootUtils.runCommand(command);
    Log.i(TAG, command);
    if (context != null) {
        context.bindService(new Intent(context, Monitor.class), new ServiceConnection() {

            @Override
            public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
                try {
                    IMonitor monitor = IMonitor.Stub.asInterface(iBinder);
                    monitor.onSettingsChange();
                    context.unbindService(this);
                } catch (RemoteException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onServiceDisconnected(ComponentName componentName) {
            }
        }, Context.BIND_AUTO_CREATE);
    }
}
Also used : ServiceConnection(android.content.ServiceConnection) IBinder(android.os.IBinder) IMonitor(mtweaks.services.monitor.IMonitor) Monitor(com.moro.mtweaks.services.monitor.Monitor) Intent(android.content.Intent) ComponentName(android.content.ComponentName) RemoteException(android.os.RemoteException) Settings(com.moro.mtweaks.database.Settings) IMonitor(mtweaks.services.monitor.IMonitor)

Aggregations

Settings (com.moro.mtweaks.database.Settings)4 Intent (android.content.Intent)2 RemoteException (android.os.RemoteException)2 Controls (com.moro.mtweaks.database.tools.customcontrols.Controls)2 Profiles (com.moro.mtweaks.database.tools.profiles.Profiles)2 NotificationManager (android.app.NotificationManager)1 PendingIntent (android.app.PendingIntent)1 ComponentName (android.content.ComponentName)1 ServiceConnection (android.content.ServiceConnection)1 Handler (android.os.Handler)1 IBinder (android.os.IBinder)1 NotificationCompat (android.support.v4.app.NotificationCompat)1 Monitor (com.moro.mtweaks.services.monitor.Monitor)1 CPUFreq (com.moro.mtweaks.utils.kernel.cpu.CPUFreq)1 RootFile (com.moro.mtweaks.utils.root.RootFile)1 RootUtils (com.moro.mtweaks.utils.root.RootUtils)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 IMonitor (mtweaks.services.monitor.IMonitor)1 JSONArray (org.json.JSONArray)1