Search in sources :

Example 1 with IMonitor

use of mtweaks.services.monitor.IMonitor 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

ComponentName (android.content.ComponentName)1 Intent (android.content.Intent)1 ServiceConnection (android.content.ServiceConnection)1 IBinder (android.os.IBinder)1 RemoteException (android.os.RemoteException)1 Settings (com.moro.mtweaks.database.Settings)1 Monitor (com.moro.mtweaks.services.monitor.Monitor)1 IMonitor (mtweaks.services.monitor.IMonitor)1