示例#1
0
int main (int argc, char **argv)
{
    ocConfig  conf;
    pid_t pid, sid;
    char input_buffer[9];

    __android_log_write(ANDROID_LOG_INFO, APPNAME, "Starting service.");

    if (load_config(&conf) == -1)
    {
        __android_log_write(ANDROID_LOG_ERROR, APPNAME, "Unable to load configuration. Stopping.");
        return 1;
    }

    input_buffer[0] = 0;

    pid = fork();
    if (pid < 0)
        exit(2);
    if (pid > 0)
        exit(0);
    umask(0);

    sid = setsid();
    if (sid < 0)
        exit(2);
    if ((chdir("/")) < 0)
        exit(2);
    close(STDIN_FILENO);
    close(STDOUT_FILENO);
    close(STDERR_FILENO);

    while (1)
    {
        if (read_from_file(SYS_WAKE, 6, input_buffer) == -1)
        {
            __android_log_write(ANDROID_LOG_ERROR, APPNAME, "Unable to get data from file. Cannot continue.");
            return 1;
        }

        if (strcmp(input_buffer, "awake") == 0)
        {
            __android_log_write(ANDROID_LOG_INFO, APPNAME, "Setting awake profile.");

            if (0 !=set_cpu1_online(1))
                __android_log_write(ANDROID_LOG_INFO, APPNAME, "Failed setting awake profile for cpu1.");

            set_cpu_params(conf.wake_governor, conf.wake_min_freq, conf.wake_max_freq);
        }

        input_buffer[0] = '\0';

        if (read_from_file(SYS_SLEEP, 9, input_buffer) == -1)
        {
            __android_log_write(ANDROID_LOG_ERROR, APPNAME, "Unable to get data from file. Cannot continue.");
            return 1;
        }

        if (strcmp(input_buffer, "sleeping") == 0)
        {
            __android_log_write(ANDROID_LOG_INFO, APPNAME, "Setting sleep profile.");

            set_cpu1_online(0);
            set_cpu_params(conf.sleep_governor, conf.sleep_min_freq, conf.sleep_max_freq);
        }

        input_buffer[0] = '\0';
    }

    return 0;
}
示例#2
0
int main (int argc, char **argv)
{
	if (argc == 2) {
		if (strncmp(argv[1], "-v", 2) == 0) {
			__android_log_write(ANDROID_LOG_ERROR, APPNAME, "Getting ILWT OCD version");
			printf(APPVERSION);
		}	
	}
	else {
	  ocConfig  conf;
	  pid_t pid, sid;
	  char input_buffer[9];
	  int asleep = 0;
	  int charging = 0;
	  int low_batt = 0;
	  int hot_batt = 0;
	  
	  __android_log_write(ANDROID_LOG_INFO, APPNAME, "Starting service.");
	  if (load_config(&conf) == -1){
		if (configFile == 0) {
			configFile = 1;
			if (load_config(&conf) == -1) {
				__android_log_write(ANDROID_LOG_ERROR, APPNAME, "Unable to load configuration. Stopping.");
				return 1;
			}
		}
		else {
			__android_log_write(ANDROID_LOG_ERROR, APPNAME, "Unable to load configuration. Stopping.");
			return 1;
		}
	  }

          //IOSCHED-CHANGE - start
          ioSchedConfig io_config;
          if(load_iosched_config(&io_config) == -1){
              if(io_configFile == 0) {
                  io_configFile = 1;
                  if(load_iosched_config(&io_config) == -1){
                      __android_log_write(ANDROID_LOG_ERROR, APPNAME, "Unable to load io configuration. Stopping.");
                      return 1;
                  }
              } else {
                  __android_log_write(ANDROID_LOG_ERROR, APPNAME, "Unable to load io configuration. Stopping.");
                  return 1;
              }
          }
          //IOSCHED-CHANGE - end

	  
	  input_buffer[0] = 0;
		
	  pid = fork();
	  if (pid < 0)
		exit(2);
	  if (pid > 0)
		exit(0);
	  umask(0);
	  
	  sid = setsid();
	  if (sid < 0)
		exit(2);
	  if ((chdir("/")) < 0)
		exit(2);
	  close(STDIN_FILENO);
	  close(STDOUT_FILENO);
	  close(STDERR_FILENO);

          //IOSCHED-CHANGE
          set_io_sched_params(io_config.io_scheduler);
	  
	  char* my_governor = conf.wake_governor;
	  char* my_min_freq = conf.wake_min_freq;
	  char* my_max_freq = conf.wake_max_freq;
	  
	  input_buffer[0] = '\0';
	  
	  if (read_from_file(SYS_WAKE, 6, input_buffer) == -1)
	  {                  
		__android_log_write(ANDROID_LOG_ERROR, APPNAME, "Unable to get data from file. Cannot continue.");
		return 1;
	  }
	  if (strcmp(input_buffer, "awake") == 0)
	  {
		__android_log_write(ANDROID_LOG_INFO, APPNAME, "Setting awake profile for boot sequence.");
		set_cpu_params(my_governor, my_min_freq, my_max_freq);
	  }

	  while (1)
	  {
		asleep = check_sleep();
		
		if (asleep == 2)
		{
		  __android_log_write(ANDROID_LOG_INFO, APPNAME, "Setting sleep profile.");
		  set_cpu_params(conf.sleep_governor, conf.sleep_min_freq, conf.sleep_max_freq);
		}
		else if (asleep == 1)
		{
			__android_log_write(ANDROID_LOG_ERROR, APPNAME, "Unable to get data from file. Cannot continue.");
			return 1;
		}
	  
		input_buffer[0] = '\0';
	  
		if (read_from_file(SYS_WAKE, 6, input_buffer) == -1) {                  
		  __android_log_write(ANDROID_LOG_ERROR, APPNAME, "Unable to get data from file. Cannot continue.");
		  return 1;
		}
		if (strcmp(input_buffer, "awake") == 0)
		{
			hot_batt = check_batt_temp(atoi(conf.battery_temp));
		
			if (hot_batt == 2) {
				__android_log_write(ANDROID_LOG_INFO, APPNAME, "Setting heat profile.");
				my_governor = conf.battery_temp_governor;
				my_min_freq = conf.battery_temp_min_freq;
				my_max_freq = conf.battery_temp_max_freq;
			}
			else {
				charging = check_charge();
				if (charging == 2) {
					__android_log_write(ANDROID_LOG_INFO, APPNAME, "Setting charge profile.");
					my_governor = conf.charge_governor;
					my_min_freq = conf.charge_min_freq;
					my_max_freq = conf.charge_max_freq;
				}
				else {
					low_batt = check_batt_cap(atoi(conf.battery_cap));
					
					if (low_batt == 2) {
						__android_log_write(ANDROID_LOG_INFO, APPNAME, "Setting capacity profile.");
						my_governor = conf.battery_cap_governor;
						my_min_freq = conf.battery_cap_min_freq;
						my_max_freq = conf.battery_cap_max_freq;
					}
					else {
						__android_log_write(ANDROID_LOG_INFO, APPNAME, "Setting awake profile.");
						my_governor = conf.wake_governor;
						my_min_freq = conf.wake_min_freq;
						my_max_freq = conf.wake_max_freq;
					}
				}
			}
				
			set_cpu_params(my_governor, my_min_freq, my_max_freq);
		}
	  }
  }
 
  return 0;
}