Java tutorial
package com.sentaroh.android.TaskAutomation; /* The MIT License (MIT) Copyright (c) 2011-2013 Sentaroh Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ import static com.sentaroh.android.TaskAutomation.Common.CommonConstants.*; import java.io.File; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Locale; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; import android.bluetooth.BluetoothAdapter; import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; import android.location.Location; import android.media.AudioManager; import android.media.MediaPlayer; import android.media.RingtoneManager; import android.net.Uri; import android.net.wifi.WifiManager; import android.os.Build; import android.os.PowerManager; import android.os.PowerManager.WakeLock; import android.os.Vibrator; import android.support.v4.app.NotificationCompat; import android.telephony.TelephonyManager; import bsh.EvalError; import bsh.Interpreter; import bsh.ParseException; import com.sentaroh.android.TaskAutomation.Common.ActionResponse; import com.sentaroh.android.TaskAutomation.Common.ActivityExtraDataItem; import com.sentaroh.android.TaskAutomation.Common.EnvironmentParms; import com.sentaroh.android.TaskAutomation.Common.TaskActionItem; import com.sentaroh.android.TaskAutomation.Common.TaskHistoryItem; import com.sentaroh.android.TaskAutomation.Common.TaskListItem; import com.sentaroh.android.TaskAutomation.Common.TaskManagerParms; import com.sentaroh.android.TaskAutomation.Common.TaskResponse; import com.sentaroh.android.Utilities.DateUtil; import com.sentaroh.android.Utilities.LocalMountPoint; import com.sentaroh.android.Utilities.ThreadCtrl; //public class TaskExecutor extends Thread { public class TaskExecutor implements Runnable { private TaskListItem taskListItem = null; private CommonUtilities util = null; private EnvironmentParms envParms = null; private TaskResponse taskResponse = null; private TaskManagerParms taskMgrParms = null; private WakeLock mWakelockTask = null; // @Override public TaskExecutor(TaskResponse tr, TaskManagerParms tmp, TaskListItem tai, EnvironmentParms sdv) { taskListItem = tai; envParms = sdv; taskResponse = tr; taskMgrParms = tmp; taskResponse.active_group_name = tai.group_name; taskResponse.active_task_name = tai.task_name; taskResponse.active_event_name = tai.event_name; taskResponse.prof_notification = tai.prof_notification; taskResponse.task_action_notification = tai.task_action_notification; mWakelockTask = ((PowerManager) taskMgrParms.context.getSystemService(Context.POWER_SERVICE)) .newWakeLock(PowerManager.PARTIAL_WAKE_LOCK // | PowerManager.ON_AFTER_RELEASE , "TaskAutomation-TaskExecutor"); mWakelockTask.acquire(); }; final public String toSting() { return new String("Group=" + taskListItem.group_name + ", Task=" + taskListItem.task_name + ", Event=" + taskListItem.event_name); }; @Override final public void run() { try { long b_time = System.currentTimeMillis(); String log_ident = "" + Thread.currentThread().getId(); util = new CommonUtilities(taskMgrParms.context, "Executor", envParms); util.setLogId(Thread.currentThread().getName()); ArrayList<TaskActionItem> taskActionList = taskListItem.taskActionList; taskResponse.active_thread_id = log_ident; util.addLogMsg("I", String.format(taskMgrParms.teMsgs.msgs_thread_task_started, taskResponse.active_group_name, taskResponse.active_event_name, taskResponse.active_task_name)); taskResponse.resp_time = DateUtil.convDateTimeTo_HourMinSecMili(System.currentTimeMillis()); TaskManager.callBackToActivity(taskMgrParms, envParms, util, taskResponse.resp_time, NTFY_TO_ACTV_TASK_STARTED, taskResponse.active_group_name, taskResponse.active_task_name, null, null, TaskResponse.RESP_CODE_SUCCESS, null); int alsz = taskActionList.size(); TaskActionItem tai; for (int i = 0; i < alsz; i++) { taskResponse.active_thread_ctrl.setThreadMessage(""); tai = taskActionList.get(i); ActionResponse ar = new ActionResponse(); taskResponse.active_action_name = ar.current_action = tai.action_name; taskResponse.active_dialog_id = tai.action_dialog_id; if (taskResponse.task_action_notification) { taskResponse.resp_time = DateUtil.convDateTimeTo_HourMinSecMili(System.currentTimeMillis()); TaskManager.callBackToActivity(taskMgrParms, envParms, util, taskResponse.resp_time, NTFY_TO_ACTV_ACTION_STARTED, taskResponse.active_group_name, taskResponse.active_task_name, taskResponse.active_action_name, taskResponse.active_dialog_id, taskResponse.resp_code, taskResponse.resp_msg_text); } executeAction(taskMgrParms, envParms, util, taskResponse, ar, tai); if (ar.resp_msg_text != null && ar.resp_msg_text.length() > 0) util.addLogMsg("I", ar.resp_msg_text); if (ar.action_resp == ActionResponse.ACTION_ABORT) { // util.addLogMsg("I",ar.resp_msg_text); if (taskResponse.task_action_notification) { taskResponse.resp_time = DateUtil.convDateTimeTo_HourMinSecMili(System.currentTimeMillis()); TaskManager.callBackToActivity(taskMgrParms, envParms, util, taskResponse.resp_time, NTFY_TO_ACTV_ACTION_ENDED, taskResponse.active_group_name, taskResponse.active_task_name, taskResponse.active_action_name, taskResponse.active_dialog_id, ar.action_resp, ar.resp_msg_text); } break; } else if (ar.action_resp == ActionResponse.ACTION_CANCELLED || ar.action_resp == ActionResponse.ACTION_WARNING || ar.action_resp == ActionResponse.ACTION_SUCCESS) { if (taskResponse.task_action_notification) { taskResponse.resp_time = DateUtil.convDateTimeTo_HourMinSecMili(System.currentTimeMillis()); TaskManager.callBackToActivity(taskMgrParms, envParms, util, taskResponse.resp_time, NTFY_TO_ACTV_ACTION_ENDED, taskResponse.active_group_name, taskResponse.active_task_name, taskResponse.active_action_name, taskResponse.active_dialog_id, ar.action_resp, ar.resp_msg_text); } } else if (ar.action_resp == ActionResponse.ACTION_SKIP) { if (taskResponse.task_action_notification) { taskResponse.resp_time = DateUtil.convDateTimeTo_HourMinSecMili(System.currentTimeMillis()); TaskManager.callBackToActivity(taskMgrParms, envParms, util, taskResponse.resp_time, NTFY_TO_ACTV_ACTION_ENDED, taskResponse.active_group_name, taskResponse.active_task_name, taskResponse.active_action_name, taskResponse.active_dialog_id, ActionResponse.ACTION_SUCCESS, ar.resp_msg_text); } i++; if (i < taskActionList.size()) { taskResponse.active_action_name = ar.current_action = tai.action_name; if (taskResponse.task_action_notification) { taskResponse.resp_time = DateUtil .convDateTimeTo_HourMinSecMili(System.currentTimeMillis()); TaskManager.callBackToActivity(taskMgrParms, envParms, util, taskResponse.resp_time, NTFY_TO_ACTV_ACTION_ENDED, taskResponse.active_group_name, taskResponse.active_task_name, taskResponse.active_action_name, taskResponse.active_dialog_id, ActionResponse.ACTION_SUCCESS, "Action was skipped"); } } } else if (ar.action_resp == ActionResponse.ACTION_ERROR) { if (taskResponse.task_action_notification) { taskResponse.resp_time = DateUtil.convDateTimeTo_HourMinSecMili(System.currentTimeMillis()); TaskManager.callBackToActivity(taskMgrParms, envParms, util, taskResponse.resp_time, NTFY_TO_ACTV_ACTION_ENDED, taskResponse.active_group_name, taskResponse.active_task_name, taskResponse.active_action_name, taskResponse.active_dialog_id, ar.action_resp, ar.resp_msg_text); } taskResponse.active_thread_ctrl.setThreadMessage(ar.resp_msg_text); taskResponse.active_thread_ctrl.setThreadResultError(); break; } if (!taskResponse.active_thread_ctrl.isEnable()) { taskResponse.active_thread_ctrl.setThreadResultCancelled(); taskResponse.active_thread_ctrl.setThreadMessage("Task was cancelled"); break; } } taskResponse.active_action_name = ""; taskResponse.active_dialog_id = ""; if (taskMgrParms.schedulerEnabled) processTaskEnd(taskMgrParms, envParms, util, taskResponse); long e_time = System.currentTimeMillis() - b_time; if (envParms.settingDebugLevel >= 1) { util.addDebugMsg(1, "I", "Task execution elapsed time=" + e_time); if (taskResponse.active_task_name.equals("#QT-Screen-Proximity-undetected")) { if (e_time > 11000) { util.addDebugMsg(1, "E", "Overtime is detected"); } } } } finally { taskListItem = null; util = null; envParms = null; taskResponse = null; taskMgrParms = null; mWakelockTask.release(); } }; final static private void processTaskEnd(TaskManagerParms taskMgrParms, EnvironmentParms envParms, CommonUtilities util, TaskResponse taskResponse) { TaskListItem ati = TaskManager.removeActiveTaskListItem(taskMgrParms, envParms, util, taskResponse.active_group_name, taskResponse.active_task_name); if (ati != null) { String th_result = taskResponse.active_thread_ctrl.getThreadResult(); if (th_result.equals(ThreadCtrl.THREAD_RESULT_SUCCESS)) { util.addLogMsg("I", String.format(taskMgrParms.teMsgs.msgs_thread_task_end_success, taskResponse.active_group_name, taskResponse.active_event_name, taskResponse.active_task_name)); taskResponse.resp_msg_text = taskResponse.active_thread_ctrl.getThreadMessage(); taskResponse.resp_code = TaskResponse.RESP_CODE_SUCCESS; taskResponse.resp_time = DateUtil.convDateTimeTo_HourMinSecMili(System.currentTimeMillis()); } else if (th_result.equals(ThreadCtrl.THREAD_RESULT_CANCELLED)) { util.addLogMsg("W", String.format(taskMgrParms.teMsgs.msgs_thread_task_end_cancelled, taskResponse.active_group_name, taskResponse.active_event_name, taskResponse.active_task_name)); taskResponse.resp_msg_text = taskResponse.active_thread_ctrl.getThreadMessage(); taskResponse.resp_code = TaskResponse.RESP_CODE_CANCELLED; taskResponse.resp_time = DateUtil.convDateTimeTo_HourMinSecMili(System.currentTimeMillis()); } else if (th_result.equals(ThreadCtrl.THREAD_RESULT_ERROR)) { taskResponse.resp_msg_text = taskResponse.active_thread_ctrl.getThreadMessage(); taskResponse.resp_code = TaskResponse.RESP_CODE_ERROR; taskResponse.resp_time = DateUtil.convDateTimeTo_HourMinSecMili(System.currentTimeMillis()); util.addLogMsg("E", taskResponse.resp_msg_text); util.addLogMsg("E", String.format(taskMgrParms.teMsgs.msgs_thread_task_end_error, taskResponse.active_group_name, taskResponse.active_event_name, taskResponse.active_task_name)); if (ati.prof_notification) { TaskManager.showErrorNotificationMessage(taskMgrParms, "task=" + taskResponse.active_task_name + ", " + taskResponse.resp_msg_text); } } TaskManager.updateTaskHistoryListItem(taskMgrParms, envParms, util, taskResponse.resp_time, taskResponse.active_group_name, taskResponse.active_event_name, taskResponse.active_task_name, TaskHistoryItem.TASK_HISTORY_TASK_STATUS_ENDED, taskResponse.resp_code, ""); TaskManager.showNotification(envParms, taskMgrParms, util); TaskManager.callBackToActivity(taskMgrParms, envParms, util, taskResponse.resp_time, NTFY_TO_ACTV_TASK_ENDED, taskResponse.active_group_name, taskResponse.active_task_name, taskResponse.active_action_name, taskResponse.active_dialog_id, taskResponse.resp_code, taskResponse.resp_msg_text); TaskManager.rescheduleTask(taskMgrParms, envParms, util); if (taskMgrParms.activeTaskList.size() == 0 && taskMgrParms.taskQueueList.size() == 0) { taskMgrParms.locationUtil.deactivateLocationProvider(); } // TaskManager.resourceCleanup(taskMgrParms,envParms,util); } else { TaskManager.acqLock(TaskManager.LOCK_ID_TASK_CONTROL, TaskManager.LOCK_MODE_WRITE, envParms, taskMgrParms, util); taskMgrParms.schedulerEnabled = false; String msg = "Internal error: Active task list was corrupted. activeTaskList size=" + taskMgrParms.activeTaskList.size() + ", group=" + taskResponse.active_group_name + ", task=" + taskResponse.active_task_name; util.addLogMsg("E", msg); for (int i = 0; i < taskMgrParms.activeTaskList.size(); i++) { util.addLogMsg("E", " ", String.valueOf(i), ", group=", taskMgrParms.activeTaskList.get(i).group_name, ", task=", taskMgrParms.activeTaskList.get(i).task_name); } TaskManager.showMessageDialog(taskMgrParms, envParms, util, "*Syetm", "*System", "*System", "1", MESSAGE_DIALOG_MESSAGE_TYPE_DIALOG, msg + "\n" + "Scheduler has been restarted."); sendCmdToService(taskResponse, "*System", "1", CMD_THREAD_TO_SVC_FORCE_RESTART_SCHEDULER, "*Interbal error"); // TaskManager.relLock(TaskManager.LOCK_ID_TASK_CONTROL, TaskManager.LOCK_MODE_WRITE,envParms,taskMgrParms,util); } }; final static private void executeAction(TaskManagerParms taskMgrParms, EnvironmentParms envParms, CommonUtilities util, TaskResponse task_response, ActionResponse ar, TaskActionItem tai) { String action_type = tai.action_type; if (action_type.equals(PROFILE_ACTION_TYPE_ACTIVITY)) { executeAndroidActivity(taskMgrParms, envParms, util, task_response, ar, tai.action_activity_name, tai.action_activity_pkgname, tai); } else if (action_type.equals(PROFILE_ACTION_TYPE_MUSIC)) { executePlayBackMusic(taskMgrParms, envParms, util, task_response, ar, tai.action_name, tai.action_dialog_id, tai.action_sound_file_name, tai.action_sound_vol_left, tai.action_sound_vol_left); } else if (action_type.equals(PROFILE_ACTION_TYPE_RINGTONE)) { executePlayBackRingtone(taskMgrParms, envParms, util, task_response, ar, tai.action_name, tai.action_dialog_id, tai.action_ringtone_type, tai.action_ringtone_name, tai.action_ringtone_path, tai.action_ringtone_vol_left, tai.action_ringtone_vol_left); } else if (action_type.equals(PROFILE_ACTION_TYPE_COMPARE)) { executeCompareAction(taskMgrParms, envParms, util, task_response, ar, tai.action_name, tai.action_dialog_id, tai.action_compare_target, tai.action_compare_type, tai.action_compare_value, tai.action_compare_result_action); } else if (action_type.equals(PROFILE_ACTION_TYPE_MESSAGE)) { executeMessageAction(taskMgrParms, envParms, util, task_response, ar, tai.action_name, tai.action_dialog_id, tai.action_message_type, tai.action_message_text, tai.action_message_use_vib, tai.action_message_use_led, tai.action_message_led_color); } else if (action_type.equals(PROFILE_ACTION_TYPE_TIME)) { executeTimeAction(taskMgrParms, envParms, util, task_response, ar, tai.action_name, tai.action_dialog_id, tai.action_time_type, tai.action_time_target); } else if (action_type.equals(PROFILE_ACTION_TYPE_TASK)) { executeTaskAction(taskMgrParms, envParms, util, task_response, ar, tai.action_name, tai.action_dialog_id, tai.action_task_type, tai.action_task_target); } else if (action_type.equals(PROFILE_ACTION_TYPE_WAIT)) { executeWaitAction(taskMgrParms, envParms, util, task_response, ar, tai.action_name, tai.action_dialog_id, tai.action_wait_target, tai.action_wait_timeout_value, tai.action_wait_timeout_units); } else if (action_type.equals(PROFILE_ACTION_TYPE_BSH_SCRIPT)) { executeBeanShellScriptAction(taskMgrParms, envParms, util, task_response, ar, tai); } else if (action_type.equals(PROFILE_ACTION_TYPE_BUILTIN)) { util.addLogMsg("I", String.format(taskMgrParms.teMsgs.msgs_thread_task_exec_builtin, tai.action_builtin_action)); executeBuiltinAction(taskMgrParms, envParms, util, task_response, ar, tai.action_builtin_action, tai.action_dialog_id, task_response.active_event_name, task_response.active_task_name); } else { ar.action_resp = ActionResponse.ACTION_ERROR; String tmsg = String.format(taskMgrParms.teMsgs.msgs_thread_task_unknoww_action, action_type); util.addLogMsg("E", tmsg); ar.resp_msg_text = tmsg; } }; final static private void executeAndroidActivity(TaskManagerParms taskMgrParms, EnvironmentParms envParms, CommonUtilities util, TaskResponse task_response, ActionResponse ar, String task, String pkg, TaskActionItem eali) { util.addLogMsg("I", String.format(taskMgrParms.teMsgs.msgs_thread_task_exec_android, task, pkg)); final PackageManager pm = taskMgrParms.context.getPackageManager(); Intent in = pm.getLaunchIntentForPackage(pkg); ar.action_resp = ActionResponse.ACTION_SUCCESS; if (in != null) { in.setAction(Intent.ACTION_MAIN); in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); if (eali.action_activity_data_type.equals(PROFILE_ACTION_TYPE_ACTIVITY_DATA_TYPE_URI)) { in.setData(Uri.parse(eali.action_activity_data_uri)); if (envParms.settingDebugLevel >= 1) util.addDebugMsg(1, "I", " Uri data added : Uri=", eali.action_activity_data_uri); } else if (eali.action_activity_data_type.equals(PROFILE_ACTION_TYPE_ACTIVITY_DATA_TYPE_EXTRA)) { ArrayList<ActivityExtraDataItem> aed_list = eali.action_activity_data_extra_list; for (int i = 0; i < aed_list.size(); i++) { ActivityExtraDataItem aedi = aed_list.get(i); if (aedi.data_value_array.equals(PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_ARRAY_NO)) { String d_val_string = ""; boolean d_val_boolean = false; int d_val_int = 0; if (aedi.data_type.equals(PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_STRING)) { d_val_string = aedi.data_value; in.putExtra(aedi.key_value, d_val_string); if (envParms.settingDebugLevel >= 1) util.addDebugMsg(1, "I", " Extra String data added : key=", aedi.key_value, ", value=", d_val_string); } else if (aedi.data_type.equals(PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_INT)) { d_val_int = Integer.valueOf(aedi.data_value); in.putExtra(aedi.key_value, d_val_int); if (envParms.settingDebugLevel >= 1) util.addDebugMsg(1, "I", " Extra Int data added : key=", aedi.key_value, ", value=", String.valueOf(d_val_int)); } else if (aedi.data_type.equals(PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_BOOLEAN)) { if (aedi.data_value.equals("true")) d_val_boolean = true; in.putExtra(aedi.key_value, d_val_boolean); if (envParms.settingDebugLevel >= 1) util.addDebugMsg(1, "I", " Extra Boolean data added : key=", aedi.key_value, ", value=", String.valueOf(d_val_boolean)); } } else if (aedi.data_value_array .equals(PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_ARRAY_YES)) { if (aedi.data_type.equals(PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_STRING)) { String[] d_val_array = aedi.data_value.split("\u0003"); String[] d_val_extra = new String[d_val_array.length]; for (int ai = 0; ai < d_val_array.length; ai++) { d_val_extra[ai] = d_val_array[ai]; if (envParms.settingDebugLevel >= 1) util.addDebugMsg(1, "I", " Extra array String data added : key=", aedi.key_value, ", value=", d_val_extra[ai]); } in.putExtra(aedi.key_value, d_val_extra); } else if (aedi.data_type.equals(PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_INT)) { String[] d_val_array = aedi.data_value.split("\u0003"); int[] d_val_extra = new int[d_val_array.length]; for (int ai = 0; ai < d_val_array.length; ai++) { d_val_extra[ai] = Integer.valueOf(d_val_array[ai]); if (envParms.settingDebugLevel >= 1) util.addDebugMsg(1, "I", " Extra array Int data added : key=", aedi.key_value, ", value=", String.valueOf(d_val_extra[ai])); } in.putExtra(aedi.key_value, d_val_extra); } else if (aedi.data_type.equals(PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_BOOLEAN)) { String[] d_val_array = aedi.data_value.split("\u0003"); boolean[] d_val_extra = new boolean[d_val_array.length]; for (int ai = 0; ai < d_val_array.length; ai++) { if (d_val_array[ai].equals("true")) d_val_extra[ai] = true; else d_val_extra[ai] = false; if (envParms.settingDebugLevel >= 1) util.addDebugMsg(1, "I", " Extra array Boolean data added : key=", aedi.key_value, ", value=", String.valueOf(d_val_extra[ai])); } in.putExtra(aedi.key_value, d_val_extra); } } } } else { if (envParms.settingDebugLevel >= 1) util.addDebugMsg(1, "I", " No data was supplied"); } taskMgrParms.context.startActivity(in); task_response.active_thread_ctrl.setThreadResultSuccess(); waitTimeTc(task_response, 100); } else { String msg = String.format(taskMgrParms.teMsgs.msgs_thread_task_intent_notfound, pkg); util.addLogMsg("E", msg); ar.action_resp = ActionResponse.ACTION_ERROR; ar.resp_msg_text = msg; } } final static private void executeBuiltinAction(TaskManagerParms taskMgrParms, EnvironmentParms envParms, CommonUtilities util, TaskResponse taskResponse, ActionResponse ar, String bia, String dlg_id, String en, String tn) { ar.action_resp = ActionResponse.ACTION_SUCCESS; if (bia.startsWith(BUILTIN_ACTION_PRIMITIVE_PREFIX)) { executeBuiltinActionPrimitive(taskMgrParms, envParms, util, taskResponse, ar, bia, dlg_id, en, tn); } else if (bia.startsWith(BUILTIN_ACTION_CONDITIONAL_PREFIX)) { executeBuiltinActionConditional(taskMgrParms, envParms, util, taskResponse, ar, bia, en, tn); } else if (bia.startsWith(BUILTIN_ACTION_CANCEL_PREFIX)) { executeBuiltinActionCancel(taskMgrParms, envParms, util, taskResponse, ar, bia, dlg_id, en, tn); } else if (bia.startsWith(BUILTIN_ACTION_BLOCK_PREFIX)) { executeBuiltinActionBlockAction(taskMgrParms, envParms, util, taskResponse, ar, bia, dlg_id, en, tn); } else { ar.action_resp = ActionResponse.ACTION_ERROR; ar.resp_msg_text = String.format(taskMgrParms.teMsgs.msgs_thread_task_unknoww_action, bia); } } final static private void executeBuiltinActionPrimitive(TaskManagerParms taskMgrParms, EnvironmentParms envParms, CommonUtilities util, TaskResponse taskResponse, ActionResponse ar, String bia, String dlg_id, String en, String tn) { if (bia.equals(BUILTIN_ACTION_WIFI_ON)) { taskResponse.active_thread_ctrl.setThreadMessage(BUILTIN_ACTION_WIFI_ON); setWifiOn(taskMgrParms, envParms, util, taskResponse, ar); } else if (bia.equals(BUILTIN_ACTION_WIFI_OFF)) { taskResponse.active_thread_ctrl.setThreadMessage(BUILTIN_ACTION_WIFI_OFF); setWifiOff(taskMgrParms, envParms, util, taskResponse, ar); } else if (bia.equals(BUILTIN_ACTION_WIFI_DISABLE_CONNECTED_SSID)) { taskResponse.active_thread_ctrl.setThreadMessage(BUILTIN_ACTION_WIFI_DISABLE_CONNECTED_SSID); setWifiDisableSsid(taskMgrParms, envParms, util, taskResponse, ar); } else if (bia.equals(BUILTIN_ACTION_WIFI_REMOVE_CONNECTED_SSID)) { taskResponse.active_thread_ctrl.setThreadMessage(BUILTIN_ACTION_WIFI_REMOVE_CONNECTED_SSID); setWifiRemoveSsid(taskMgrParms, envParms, util, taskResponse, ar); } else if (bia.equals(BUILTIN_ACTION_BLUETOOTH_ON)) { taskResponse.active_thread_ctrl.setThreadMessage(BUILTIN_ACTION_BLUETOOTH_ON); setBluetoothOn(taskMgrParms, envParms, util, taskResponse, ar); } else if (bia.equals(BUILTIN_ACTION_BLUETOOTH_OFF)) { taskResponse.active_thread_ctrl.setThreadMessage(BUILTIN_ACTION_BLUETOOTH_OFF); setBluetoothOff(taskMgrParms, envParms, util, taskResponse, ar); } else if (bia.equals(BUILTIN_ACTION_WAIT_1_SEC)) { waitTimeTc(taskResponse, 1 * 1000); if (!taskResponse.active_thread_ctrl.isEnable()) { ar.action_resp = ActionResponse.ACTION_CANCELLED; ar.resp_msg_text = "Action was cancelled"; } } else if (bia.equals(BUILTIN_ACTION_WAIT_5_SEC)) { waitTimeTc(taskResponse, 5 * 1000); if (!taskResponse.active_thread_ctrl.isEnable()) { ar.action_resp = ActionResponse.ACTION_CANCELLED; ar.resp_msg_text = "Action was cancelled"; } } else if (bia.equals(BUILTIN_ACTION_WAIT_1_MIN)) { waitTimeTc(taskResponse, 1 * 60 * 1000); if (!taskResponse.active_thread_ctrl.isEnable()) { ar.action_resp = ActionResponse.ACTION_CANCELLED; ar.resp_msg_text = "Action was cancelled"; } } else if (bia.equals(BUILTIN_ACTION_WAIT_5_MIN)) { waitTimeTc(taskResponse, 5 * 60 * 1000); if (!taskResponse.active_thread_ctrl.isEnable()) { ar.action_resp = ActionResponse.ACTION_CANCELLED; ar.resp_msg_text = "Action was cancelled"; } } else if (bia.equals(BUILTIN_ACTION_SWITCH_TO_HOME)) { setScreenSwitchToHome(taskMgrParms, envParms, util, taskResponse, ar); } else if (bia.equals(BUILTIN_ACTION_SCREEN_LOCK)) { setScreenLocked(taskMgrParms, util, taskResponse, ar); } else if (bia.equals(BUILTIN_ACTION_SCREEN_ON)) { screenOnSync(taskMgrParms, taskResponse, ar); } else if (bia.equals(BUILTIN_ACTION_SCREEN_ON_ASYNC)) { screenOnAsync(taskMgrParms, taskResponse, ar); } else if (bia.equals(BUILTIN_ACTION_PLAYBACK_DEFAULT_ALARM)) { playBackDefaultAlarm(taskMgrParms, envParms, util, taskResponse, ar); } else if (bia.equals(BUILTIN_ACTION_PLAYBACK_DEFAULT_NOTIFICATION)) { playBackDefaultNotification(taskMgrParms, envParms, util, taskResponse, ar); } else if (bia.equals(BUILTIN_ACTION_PLAYBACK_DEFAULT_RINGTONE)) { playBackDefaultRingtone(taskMgrParms, envParms, util, taskResponse, ar); } else if (bia.equals(BUILTIN_ACTION_VIBRATE)) { vibrateDefaultPattern(taskMgrParms.context, ar); } else if (bia.equals(BUILTIN_ACTION_RESTART_SCHEDULER)) { sendCmdToService(taskResponse, BUILTIN_ACTION_RESTART_SCHEDULER, dlg_id, CMD_THREAD_TO_SVC_RESTART_SCHEDULER, BUILTIN_ACTION_RESTART_SCHEDULER); } else if (bia.equals(BUILTIN_ACTION_RINGER_NORMAL)) { AudioManager am = (AudioManager) taskMgrParms.context.getSystemService(Context.AUDIO_SERVICE); am.setRingerMode(AudioManager.RINGER_MODE_NORMAL); // am.setStreamMute(AudioManager.STREAM_MUSIC, false); // am.setStreamMute(AudioManager.STREAM_RING, false); // am.setStreamMute(AudioManager.STREAM_NOTIFICATION, false); // am.setStreamMute(AudioManager.STREAM_SYSTEM, false); // am.setStreamMute(AudioManager.STREAM_ALARM, false); } else if (bia.equals(BUILTIN_ACTION_RINGER_SILENT)) { AudioManager am = (AudioManager) taskMgrParms.context.getSystemService(Context.AUDIO_SERVICE); am.setRingerMode(AudioManager.RINGER_MODE_SILENT); // am.setStreamMute(AudioManager.STREAM_MUSIC, true); // am.setStreamMute(AudioManager.STREAM_RING, true); // am.setStreamMute(AudioManager.STREAM_NOTIFICATION, true); // am.setStreamMute(AudioManager.STREAM_SYSTEM, true); // am.setStreamMute(AudioManager.STREAM_ALARM, true); } else if (bia.equals(BUILTIN_ACTION_RINGER_VIBRATE)) { AudioManager am = (AudioManager) taskMgrParms.context.getSystemService(Context.AUDIO_SERVICE); am.setRingerMode(AudioManager.RINGER_MODE_VIBRATE); // am.setStreamMute(AudioManager.STREAM_MUSIC, true); // am.setStreamMute(AudioManager.STREAM_RING, true); // am.setStreamMute(AudioManager.STREAM_NOTIFICATION, true); // am.setStreamMute(AudioManager.STREAM_SYSTEM, true); // am.setStreamMute(AudioManager.STREAM_ALARM, true); } else if (bia.equals(BUILTIN_ACTION_AUTO_SYNC_ENABLED)) { setAutoSyncEnabled(taskMgrParms, envParms, util, taskResponse, ar); } else if (bia.equals(BUILTIN_ACTION_AUTO_SYNC_DISABLED)) { setAutoSyncDisabled(taskMgrParms, envParms, util, taskResponse, ar); } else if (bia.equals(BUILTIN_ACTION_ABORT)) { ar.action_resp = ActionResponse.ACTION_ABORT; ar.resp_msg_text = "Task was aborted"; } else { ar.action_resp = ActionResponse.ACTION_ERROR; ar.resp_msg_text = String.format(taskMgrParms.teMsgs.msgs_thread_task_unknoww_action, bia); } } final static private void executeBuiltinActionConditional(TaskManagerParms taskMgrParms, EnvironmentParms envParms, CommonUtilities util, TaskResponse taskResponse, ActionResponse ar, String bia, String en, String tn) { if (bia.equals(BUILTIN_ACTION_IF_WIFI_ON_ABORT)) { if (envParms.wifiIsActive) ar.action_resp = ActionResponse.ACTION_ABORT; } else if (bia.equals(BUILTIN_ACTION_IF_WIFI_CONNECTED_ABORT)) { if (envParms.isWifiConnected()) ar.action_resp = ActionResponse.ACTION_ABORT; } else if (bia.equals(BUILTIN_ACTION_IF_WIFI_DISCONNECTED_ABORT)) { if (!envParms.isWifiConnected()) ar.action_resp = ActionResponse.ACTION_ABORT; } else if (bia.equals(BUILTIN_ACTION_IF_WIFI_OFF_ABORT)) { if (!envParms.wifiIsActive) ar.action_resp = ActionResponse.ACTION_ABORT; } else if (bia.equals(BUILTIN_ACTION_IF_BLUETOOTH_ON_ABORT)) { if (envParms.bluetoothIsActive) ar.action_resp = ActionResponse.ACTION_ABORT; } else if (bia.equals(BUILTIN_ACTION_IF_BLUETOOTH_CONNECTED_ABORT)) { if (envParms.isBluetoothConnected()) ar.action_resp = ActionResponse.ACTION_ABORT; } else if (bia.equals(BUILTIN_ACTION_IF_BLUETOOTH_DISCONNECTED_ABORT)) { if (!envParms.isBluetoothConnected()) ar.action_resp = ActionResponse.ACTION_ABORT; } else if (bia.equals(BUILTIN_ACTION_IF_BLUETOOTH_OFF_ABORT)) { if (!envParms.bluetoothIsActive) ar.action_resp = ActionResponse.ACTION_ABORT; } else if (bia.equals(BUILTIN_ACTION_IF_SCREEN_UNLOCKED_ABORT)) { if (!envParms.screenIsLocked) ar.action_resp = ActionResponse.ACTION_ABORT; } else if (bia.equals(BUILTIN_ACTION_IF_SCREEN_LOCKED_ABORT)) { if (envParms.screenIsLocked) ar.action_resp = ActionResponse.ACTION_ABORT; } else if (bia.equals(BUILTIN_ACTION_IF_PROXIMITY_DETECTED_ABORT)) { if (envParms.proximitySensorAvailable) { if (envParms.proximitySensorValue == 0) ar.action_resp = ActionResponse.ACTION_ABORT; } else { ar.action_resp = ActionResponse.ACTION_ERROR; ar.resp_msg_text = taskMgrParms.teMsgs.msgs_thread_task_exec_proximity_not_available; return; } } else if (bia.equals(BUILTIN_ACTION_IF_PROXIMITY_UNDETECTED_ABORT)) { if (envParms.proximitySensorAvailable) { if (envParms.proximitySensorValue == 1) ar.action_resp = ActionResponse.ACTION_ABORT; } else { ar.action_resp = ActionResponse.ACTION_ERROR; ar.resp_msg_text = taskMgrParms.teMsgs.msgs_thread_task_exec_proximity_not_available; return; } } else if (bia.equals(BUILTIN_ACTION_IF_LIGHT_DETECTED_ABORT)) { if (envParms.lightSensorAvailable) { if (envParms.lightSensorValue == 1) ar.action_resp = ActionResponse.ACTION_ABORT; } else { ar.action_resp = ActionResponse.ACTION_ERROR; ar.resp_msg_text = taskMgrParms.teMsgs.msgs_thread_task_exec_light_not_available; return; } } else if (bia.equals(BUILTIN_ACTION_IF_LIGHT_UNDETECTED_ABORT)) { if (envParms.lightSensorAvailable) { if (envParms.lightSensorValue == 0) ar.action_resp = ActionResponse.ACTION_ABORT; } else { ar.action_resp = ActionResponse.ACTION_ERROR; ar.resp_msg_text = taskMgrParms.teMsgs.msgs_thread_task_exec_light_not_available; return; } } else if (bia.equals(BUILTIN_ACTION_IF_POWER_IS_AC_OR_CHRAGE_ABORT)) { if (envParms.batteryPowerSource.equals(CURRENT_POWER_SOURCE_AC)) ar.action_resp = ActionResponse.ACTION_ABORT; } else if (bia.equals(BUILTIN_ACTION_IF_POWER_IS_BATTERY_ABORT)) { if (envParms.batteryPowerSource.equals(CURRENT_POWER_SOURCE_BATTERY)) ar.action_resp = ActionResponse.ACTION_ABORT; } else if (bia.equals(BUILTIN_ACTION_IF_CALL_STATE_IDLE_ABORT)) { if (envParms.telephonyStatus == TelephonyManager.CALL_STATE_IDLE) ar.action_resp = ActionResponse.ACTION_ABORT; } else if (bia.equals(BUILTIN_ACTION_IF_CALL_STATE_OFF_HOOK_ABORT)) { if (envParms.telephonyStatus == TelephonyManager.CALL_STATE_OFFHOOK) ar.action_resp = ActionResponse.ACTION_ABORT; } else if (bia.equals(BUILTIN_ACTION_IF_CALL_STATE_RINGING_ABORT)) { if (envParms.telephonyStatus == TelephonyManager.CALL_STATE_RINGING) ar.action_resp = ActionResponse.ACTION_ABORT; } else if (bia.equals(BUILTIN_ACTION_IF_AIRPLANE_MODE_ON_ABORT)) { if (envParms.airplane_mode_on == 1) ar.action_resp = ActionResponse.ACTION_ABORT; } else if (bia.equals(BUILTIN_ACTION_IF_AIRPLANE_MODE_OFF_ABORT)) { if (envParms.airplane_mode_on == 0) ar.action_resp = ActionResponse.ACTION_ABORT; } else if (bia.equals(BUILTIN_ACTION_IF_MOBILE_NETWORK_CONNECTED_ABORT)) { if (envParms.mobileNetworkIsConnected) ar.action_resp = ActionResponse.ACTION_ABORT; } else if (bia.equals(BUILTIN_ACTION_IF_MOBILE_NETWORK_DISCONNECTED_ABORT)) { if (!envParms.mobileNetworkIsConnected) ar.action_resp = ActionResponse.ACTION_ABORT; // } else if (bia.equals(BUILTIN_ACTION_IF_NETWORK_CONNECTED_ABORT)) { // if (envParms.networkIsConnected) ar.action_resp=ActionResponse.ACTION_ABORT; // } else if (bia.equals(BUILTIN_ACTION_IF_NETWORK_DISCONNECTED_ABORT)) { // if (!envParms.networkIsConnected) ar.action_resp=ActionResponse.ACTION_ABORT; } else if (bia.equals(BUILTIN_ACTION_IF_ORIENTATION_LANDSCAPE_ABORT)) { if (envParms.isOrientationLanscape()) ar.action_resp = ActionResponse.ACTION_ABORT; } else if (bia.equals(BUILTIN_ACTION_IF_ORIENTATION_PORTRAIT_ABORT)) { if (!envParms.isOrientationLanscape()) ar.action_resp = ActionResponse.ACTION_ABORT; } else { ar.action_resp = ActionResponse.ACTION_ERROR; ar.resp_msg_text = String.format(taskMgrParms.teMsgs.msgs_thread_task_unknoww_action, bia); } if (ar.action_resp == ActionResponse.ACTION_ABORT) { ar.resp_msg_text = String.format(taskMgrParms.teMsgs.msgs_thread_task_exec_builtin_abort, bia); } } final static private void executeBuiltinActionCancel(TaskManagerParms taskMgrParms, EnvironmentParms envParms, CommonUtilities util, TaskResponse taskResponse, ActionResponse ar, String bia, String dlg_id, String en, String tn) { try { TaskManager.acqLock(TaskManager.LOCK_ID_TASK_CONTROL, TaskManager.LOCK_MODE_WRITE, envParms, taskMgrParms, util); if (bia.equals(BUILTIN_ACTION_CANCEL_EVENT_BOOT_COMPLETED)) { taskResponse.cmd_tgt_event_name = BUILTIN_EVENT_BOOT_COMPLETED; TaskManager.cancelTaskByEventId(taskMgrParms, envParms, util, taskResponse); } else if (bia.equals(BUILTIN_ACTION_CANCEL_EVENT_WIFI_ON)) { taskResponse.cmd_tgt_event_name = BUILTIN_EVENT_WIFI_ON; TaskManager.cancelTaskByEventId(taskMgrParms, envParms, util, taskResponse); } else if (bia.equals(BUILTIN_ACTION_CANCEL_EVENT_WIFI_CONNECTED)) { taskResponse.cmd_tgt_event_name = BUILTIN_EVENT_WIFI_CONNECTED; TaskManager.cancelTaskByEventId(taskMgrParms, envParms, util, taskResponse); } else if (bia.equals(BUILTIN_ACTION_CANCEL_EVENT_WIFI_DISCONNECTED)) { taskResponse.cmd_tgt_event_name = BUILTIN_EVENT_WIFI_DISCONNECTED; TaskManager.cancelTaskByEventId(taskMgrParms, envParms, util, taskResponse); } else if (bia.equals(BUILTIN_ACTION_CANCEL_EVENT_WIFI_OFF)) { taskResponse.cmd_tgt_event_name = BUILTIN_EVENT_WIFI_OFF; TaskManager.cancelTaskByEventId(taskMgrParms, envParms, util, taskResponse); } else if (bia.equals(BUILTIN_ACTION_CANCEL_EVENT_BLUETOOTH_ON)) { taskResponse.cmd_tgt_event_name = BUILTIN_EVENT_BLUETOOTH_ON; TaskManager.cancelTaskByEventId(taskMgrParms, envParms, util, taskResponse); } else if (bia.equals(BUILTIN_ACTION_CANCEL_EVENT_BLUETOOTH_CONNECTED)) { taskResponse.cmd_tgt_event_name = BUILTIN_EVENT_BLUETOOTH_CONNECTED; TaskManager.cancelTaskByEventId(taskMgrParms, envParms, util, taskResponse); } else if (bia.equals(BUILTIN_ACTION_CANCEL_EVENT_BLUETOOTH_DISCONNECTED)) { taskResponse.cmd_tgt_event_name = BUILTIN_EVENT_BLUETOOTH_DISCONNECTED; TaskManager.cancelTaskByEventId(taskMgrParms, envParms, util, taskResponse); } else if (bia.equals(BUILTIN_ACTION_CANCEL_EVENT_BLUETOOTH_OFF)) { taskResponse.cmd_tgt_event_name = BUILTIN_EVENT_BLUETOOTH_OFF; TaskManager.cancelTaskByEventId(taskMgrParms, envParms, util, taskResponse); } else if (bia.equals(BUILTIN_ACTION_CANCEL_EVENT_PROXIMITY_DETECTED)) { taskResponse.cmd_tgt_event_name = BUILTIN_EVENT_PROXIMITY_DETECTED; TaskManager.cancelTaskByEventId(taskMgrParms, envParms, util, taskResponse); } else if (bia.equals(BUILTIN_ACTION_CANCEL_EVENT_PROXIMITY_UNDETECTED)) { taskResponse.cmd_tgt_event_name = BUILTIN_EVENT_PROXIMITY_UNDETECTED; TaskManager.cancelTaskByEventId(taskMgrParms, envParms, util, taskResponse); } else if (bia.equals(BUILTIN_ACTION_CANCEL_EVENT_LIGHT_DETECTED)) { taskResponse.cmd_tgt_event_name = BUILTIN_EVENT_LIGHT_DETECTED; TaskManager.cancelTaskByEventId(taskMgrParms, envParms, util, taskResponse); } else if (bia.equals(BUILTIN_ACTION_CANCEL_EVENT_LIGHT_UNDETECTED)) { taskResponse.cmd_tgt_event_name = BUILTIN_EVENT_LIGHT_UNDETECTED; TaskManager.cancelTaskByEventId(taskMgrParms, envParms, util, taskResponse); } else if (bia.equals(BUILTIN_ACTION_CANCEL_EVENT_SCREEN_LOCKED)) { taskResponse.cmd_tgt_event_name = BUILTIN_EVENT_SCREEN_LOCKED; TaskManager.cancelTaskByEventId(taskMgrParms, envParms, util, taskResponse); } else if (bia.equals(BUILTIN_ACTION_CANCEL_EVENT_SCREEN_UNLOCKED)) { taskResponse.cmd_tgt_event_name = BUILTIN_EVENT_SCREEN_UNLOCKED; TaskManager.cancelTaskByEventId(taskMgrParms, envParms, util, taskResponse); } else if (bia.equals(BUILTIN_ACTION_CANCEL_EVENT_POWER_SOURCE_CHANGED_AC)) { taskResponse.cmd_tgt_event_name = BUILTIN_EVENT_POWER_SOURCE_CHANGED_AC; TaskManager.cancelTaskByEventId(taskMgrParms, envParms, util, taskResponse); } else if (bia.equals(BUILTIN_ACTION_CANCEL_EVENT_POWER_SOURCE_CHANGED_BATTERY)) { taskResponse.cmd_tgt_event_name = BUILTIN_EVENT_POWER_SOURCE_CHANGED_BATTERY; TaskManager.cancelTaskByEventId(taskMgrParms, envParms, util, taskResponse); } else if (bia.equals(BUILTIN_ACTION_CANCEL_EVENT_PHONE_CALL_STATE_IDLE)) { taskResponse.cmd_tgt_event_name = BUILTIN_EVENT_PHONE_CALL_STATE_IDLE; TaskManager.cancelTaskByEventId(taskMgrParms, envParms, util, taskResponse); } else if (bia.equals(BUILTIN_ACTION_CANCEL_EVENT_PHONE_CALL_STATE_OFF_HOOK)) { taskResponse.cmd_tgt_event_name = BUILTIN_EVENT_PHONE_CALL_STATE_OFF_HOOK; TaskManager.cancelTaskByEventId(taskMgrParms, envParms, util, taskResponse); } else if (bia.equals(BUILTIN_ACTION_CANCEL_EVENT_PHONE_CALL_STATE_RINGING)) { taskResponse.cmd_tgt_event_name = BUILTIN_EVENT_PHONE_CALL_STATE_RINGING; TaskManager.cancelTaskByEventId(taskMgrParms, envParms, util, taskResponse); } else if (bia.equals(BUILTIN_ACTION_CANCEL_EVENT_AIRPLANE_MODE_ON)) { taskResponse.cmd_tgt_event_name = BUILTIN_EVENT_AIRPLANE_MODE_ON; TaskManager.cancelTaskByEventId(taskMgrParms, envParms, util, taskResponse); } else if (bia.equals(BUILTIN_ACTION_CANCEL_EVENT_AIRPLANE_MODE_OFF)) { taskResponse.cmd_tgt_event_name = BUILTIN_EVENT_AIRPLANE_MODE_OFF; TaskManager.cancelTaskByEventId(taskMgrParms, envParms, util, taskResponse); } else if (bia.equals(BUILTIN_ACTION_CANCEL_EVENT_MOBILE_NETWORK_CONNECTED)) { taskResponse.cmd_tgt_event_name = BUILTIN_EVENT_MOBILE_NETWORK_CONNECTED; TaskManager.cancelTaskByEventId(taskMgrParms, envParms, util, taskResponse); } else if (bia.equals(BUILTIN_ACTION_CANCEL_EVENT_MOBILE_NETWORK_DISCONNECTED)) { taskResponse.cmd_tgt_event_name = BUILTIN_EVENT_MOBILE_NETWORK_DISCONNECTED; TaskManager.cancelTaskByEventId(taskMgrParms, envParms, util, taskResponse); // } else if (bia.equals(BUILTIN_ACTION_CANCEL_EVENT_NETWORK_CONNECTED)) { // taskResponse.cmd_tgt_event_name=BUILTIN_EVENT_NETWORK_CONNECTED; // TaskManager.cancelTaskByEventId(taskMgrParms, envParms, util, taskResponse); // } else if (bia.equals(BUILTIN_ACTION_CANCEL_EVENT_NETWORK_DISCONNECTED)) { // taskResponse.cmd_tgt_event_name=BUILTIN_EVENT_NETWORK_DISCONNECTED; // TaskManager.cancelTaskByEventId(taskMgrParms, envParms, util, taskResponse); } else { ar.action_resp = ActionResponse.ACTION_ERROR; ar.resp_msg_text = String.format(taskMgrParms.teMsgs.msgs_thread_task_unknoww_action, bia); } } finally { TaskManager.relLock(TaskManager.LOCK_ID_TASK_CONTROL, TaskManager.LOCK_MODE_WRITE, envParms, taskMgrParms, util); } } final static private void executeBuiltinActionBlockAction(TaskManagerParms taskMgrParms, EnvironmentParms envParms, CommonUtilities util, TaskResponse taskResponse, ActionResponse ar, String bia, String dlg_id, String en, String tn) { try { TaskManager.acqLock(TaskManager.LOCK_ID_TASK_CONTROL, TaskManager.LOCK_MODE_WRITE, envParms, taskMgrParms, util); if (bia.equals(BUILTIN_ACTION_BLOCK_EVENT_CLEAR)) { TaskManager.clearBlockActionList(taskMgrParms, envParms, util); } else if (bia.equals(BUILTIN_ACTION_BLOCK_EVENT_BLOCK_ALL)) { taskResponse.cmd_tgt_event_name = BUILTIN_EVENT_ALL; TaskManager.addBlockActionListItem(taskMgrParms, envParms, util, taskResponse); } else if (bia.equals(BUILTIN_ACTION_BLOCK_EVENT_BOOT_COMPLETED)) { taskResponse.cmd_tgt_event_name = BUILTIN_EVENT_BOOT_COMPLETED; TaskManager.addBlockActionListItem(taskMgrParms, envParms, util, taskResponse); } else if (bia.equals(BUILTIN_ACTION_BLOCK_EVENT_WIFI_ON)) { taskResponse.cmd_tgt_event_name = BUILTIN_EVENT_WIFI_ON; TaskManager.addBlockActionListItem(taskMgrParms, envParms, util, taskResponse); } else if (bia.equals(BUILTIN_ACTION_BLOCK_EVENT_WIFI_CONNECTED)) { taskResponse.cmd_tgt_event_name = BUILTIN_EVENT_WIFI_CONNECTED; TaskManager.addBlockActionListItem(taskMgrParms, envParms, util, taskResponse); } else if (bia.equals(BUILTIN_ACTION_BLOCK_EVENT_WIFI_DISCONNECT)) { taskResponse.cmd_tgt_event_name = BUILTIN_EVENT_WIFI_DISCONNECTED; TaskManager.addBlockActionListItem(taskMgrParms, envParms, util, taskResponse); } else if (bia.equals(BUILTIN_ACTION_BLOCK_EVENT_WIFI_OFF)) { taskResponse.cmd_tgt_event_name = BUILTIN_EVENT_WIFI_OFF; TaskManager.addBlockActionListItem(taskMgrParms, envParms, util, taskResponse); } else if (bia.equals(BUILTIN_ACTION_BLOCK_EVENT_BLUETOOTH_ON)) { taskResponse.cmd_tgt_event_name = BUILTIN_EVENT_BLUETOOTH_ON; TaskManager.addBlockActionListItem(taskMgrParms, envParms, util, taskResponse); } else if (bia.equals(BUILTIN_ACTION_BLOCK_EVENT_BLUETOOTH_CONNECTED)) { taskResponse.cmd_tgt_event_name = BUILTIN_EVENT_BLUETOOTH_CONNECTED; TaskManager.addBlockActionListItem(taskMgrParms, envParms, util, taskResponse); } else if (bia.equals(BUILTIN_ACTION_BLOCK_EVENT_BLUETOOTH_DISCONNECTED)) { taskResponse.cmd_tgt_event_name = BUILTIN_EVENT_BLUETOOTH_DISCONNECTED; TaskManager.addBlockActionListItem(taskMgrParms, envParms, util, taskResponse); } else if (bia.equals(BUILTIN_ACTION_BLOCK_EVENT_BLUETOOTH_OFF)) { taskResponse.cmd_tgt_event_name = BUILTIN_EVENT_BLUETOOTH_OFF; TaskManager.addBlockActionListItem(taskMgrParms, envParms, util, taskResponse); } else if (bia.equals(BUILTIN_ACTION_BLOCK_EVENT_PROXIMITY_DETECTED)) { taskResponse.cmd_tgt_event_name = BUILTIN_EVENT_PROXIMITY_DETECTED; TaskManager.addBlockActionListItem(taskMgrParms, envParms, util, taskResponse); } else if (bia.equals(BUILTIN_ACTION_BLOCK_EVENT_PROXIMITY_UNDETECTED)) { taskResponse.cmd_tgt_event_name = BUILTIN_EVENT_PROXIMITY_UNDETECTED; TaskManager.addBlockActionListItem(taskMgrParms, envParms, util, taskResponse); } else if (bia.equals(BUILTIN_ACTION_BLOCK_EVENT_LIGHT_DETECTED)) { taskResponse.cmd_tgt_event_name = BUILTIN_EVENT_LIGHT_DETECTED; TaskManager.addBlockActionListItem(taskMgrParms, envParms, util, taskResponse); } else if (bia.equals(BUILTIN_ACTION_BLOCK_EVENT_LIGHT_UNDETECTED)) { taskResponse.cmd_tgt_event_name = BUILTIN_EVENT_LIGHT_UNDETECTED; TaskManager.addBlockActionListItem(taskMgrParms, envParms, util, taskResponse); } else if (bia.equals(BUILTIN_ACTION_BLOCK_EVENT_PHONE_CALL_STATE_IDLE)) { taskResponse.cmd_tgt_event_name = BUILTIN_EVENT_PHONE_CALL_STATE_IDLE; TaskManager.addBlockActionListItem(taskMgrParms, envParms, util, taskResponse); } else if (bia.equals(BUILTIN_ACTION_BLOCK_EVENT_PHONE_CALL_STATE_OFF_HOOK)) { taskResponse.cmd_tgt_event_name = BUILTIN_EVENT_PHONE_CALL_STATE_OFF_HOOK; TaskManager.addBlockActionListItem(taskMgrParms, envParms, util, taskResponse); } else if (bia.equals(BUILTIN_ACTION_BLOCK_EVENT_PHONE_CALL_STATE_RINGING)) { taskResponse.cmd_tgt_event_name = BUILTIN_EVENT_PHONE_CALL_STATE_RINGING; TaskManager.addBlockActionListItem(taskMgrParms, envParms, util, taskResponse); } else if (bia.equals(BUILTIN_ACTION_BLOCK_EVENT_AIRPLANE_MODE_ON)) { taskResponse.cmd_tgt_event_name = BUILTIN_EVENT_AIRPLANE_MODE_ON; TaskManager.addBlockActionListItem(taskMgrParms, envParms, util, taskResponse); } else if (bia.equals(BUILTIN_ACTION_BLOCK_EVENT_AIRPLANE_MODE_OFF)) { taskResponse.cmd_tgt_event_name = BUILTIN_EVENT_AIRPLANE_MODE_OFF; TaskManager.addBlockActionListItem(taskMgrParms, envParms, util, taskResponse); } else if (bia.equals(BUILTIN_ACTION_BLOCK_EVENT_MOBILE_NETWORK_CONNECTED)) { taskResponse.cmd_tgt_event_name = BUILTIN_EVENT_MOBILE_NETWORK_CONNECTED; TaskManager.addBlockActionListItem(taskMgrParms, envParms, util, taskResponse); } else if (bia.equals(BUILTIN_ACTION_BLOCK_EVENT_MOBILE_NETWORK_DISCONNECTED)) { taskResponse.cmd_tgt_event_name = BUILTIN_EVENT_MOBILE_NETWORK_DISCONNECTED; TaskManager.addBlockActionListItem(taskMgrParms, envParms, util, taskResponse); // } else if (bia.equals(BUILTIN_ACTION_BLOCK_EVENT_NETWORK_CONNECTED)) { // taskResponse.cmd_tgt_event_name=BUILTIN_EVENT_NETWORK_CONNECTED; // TaskManager.addBlockActionItem(taskMgrParms, envParms, util, taskResponse); // } else if (bia.equals(BUILTIN_ACTION_BLOCK_EVENT_NETWORK_DISCONNECTED)) { // taskResponse.cmd_tgt_event_name=BUILTIN_EVENT_NETWORK_DISCONNECTED; // TaskManager.addBlockActionItem(taskMgrParms, envParms, util, taskResponse); } else { ar.action_resp = ActionResponse.ACTION_ERROR; ar.resp_msg_text = String.format(taskMgrParms.teMsgs.msgs_thread_task_unknoww_action, bia); } } finally { TaskManager.relLock(TaskManager.LOCK_ID_TASK_CONTROL, TaskManager.LOCK_MODE_WRITE, envParms, taskMgrParms, util); } } final static private void executeBeanShellScriptAction(final TaskManagerParms taskMgrParms, final EnvironmentParms envParms, final CommonUtilities util, final TaskResponse tr, final ActionResponse ar, final TaskActionItem tai) { // Log.v("","bsh init start"); Interpreter bsh_interpreter = new Interpreter(); // Construct an interpreter // Log.v("","bsh driver start"); BeanShellMethod bsh_driver = new BeanShellMethod(taskMgrParms, envParms, util, tr, ar, tai); tr.active_thread_ctrl.setExtraDataObject(new Object[] { Thread.currentThread(), bsh_interpreter }); String script_text = "cd(\"" + LocalMountPoint.getExternalStorageDir() + "\");\n" + tai.action_bsh_script; try { // Log.v("","bsh start"); bsh_interpreter.set("TaCmd", bsh_driver); // Log.v("","bsh execute"); bsh_interpreter.eval(script_text); ar.action_resp = ActionResponse.ACTION_SUCCESS; ar.resp_msg_text = ""; // Log.v("","bsh end"); } catch (ParseException e) { ar.action_resp = ActionResponse.ACTION_ERROR; ar.resp_msg_text = "BeanShell Parser error :\n" + e.getMessage() + "\n" + "Script text:\n" + "123456789012345678901234567890123456789012345678901234567890\n" + script_text; } catch (EvalError e) { if (e.getErrorText() != null && e.getErrorText().startsWith("TaCmd .abort ( )")) { ar.action_resp = ActionResponse.ACTION_ABORT; ar.resp_msg_text = "BeanShell Task was aborted"; } else { if (tr.active_thread_ctrl.isEnable()) { ar.action_resp = ActionResponse.ACTION_ERROR; ar.resp_msg_text = "BeanShell Script error :\n" + e.getMessage() + "\n" + "Script text:\n" + "123456789012345678901234567890123456789012345678901234567890\n" + script_text; } else { ar.action_resp = ActionResponse.ACTION_CANCELLED; ar.resp_msg_text = "BeanShell Task was cancelled"; } } } try { bsh_interpreter.unset("TaCmd"); // Log.v("","clear start"); bsh_interpreter.eval("clear();"); // Log.v("","clear ended"); } catch (EvalError e) { e.printStackTrace(); } bsh_interpreter = null; bsh_driver = null; }; final static private void executeMessageAction(TaskManagerParms taskMgrParms, EnvironmentParms envParms, CommonUtilities util, TaskResponse tr, ActionResponse ar, String actionnm, String dlg_id, String msg_type, String msg_text, boolean use_vib, boolean use_led, String led_color) { util.addLogMsg("I", String.format(taskMgrParms.teMsgs.msgs_thread_task_exec_message, actionnm, msg_type, use_vib, use_led, led_color)); showMessage(taskMgrParms, envParms, util, tr, ar, actionnm, dlg_id, msg_type, msg_text, use_vib, use_led, led_color); } final static private void executePlayBackMusic(TaskManagerParms taskMgrParms, EnvironmentParms envParms, CommonUtilities util, TaskResponse taskResponse, ActionResponse ar, String action, String dlg_id, String fp, String vol_left, String vol_right) { util.addLogMsg("I", String.format(taskMgrParms.teMsgs.msgs_thread_task_exec_play_sound, fp)); playBackMusic(taskMgrParms, envParms, util, taskResponse, ar, action, dlg_id, fp, vol_left, vol_right); } final static private void executePlayBackRingtone(TaskManagerParms taskMgrParms, EnvironmentParms envParms, CommonUtilities util, TaskResponse taskResponse, ActionResponse ar, String action, String dlg_id, String rt, String rn, String rp, String vol_left, String vol_right) { util.addLogMsg("I", String.format(taskMgrParms.teMsgs.msgs_thread_task_exec_play_ringtone, rt, rn)); taskResponse.active_action_name = action; playBackRingtone(taskMgrParms, envParms, util, taskResponse, ar, dlg_id, rt, rn, rp, vol_left, vol_right); } final static private void executeTaskAction(TaskManagerParms taskMgrParms, EnvironmentParms envParms, CommonUtilities util, TaskResponse tr, ActionResponse ar, String action_nm, String dlg_id, String task_type, String task_target) { util.addLogMsg("I", String.format(taskMgrParms.teMsgs.msgs_thread_task_exec_task, action_nm, task_type, task_target)); taskTriggerTaskControl(taskMgrParms, envParms, util, tr, ar, action_nm, dlg_id, task_type, task_target); } final static private void executeTimeAction(TaskManagerParms taskMgrParms, EnvironmentParms envParms, CommonUtilities util, TaskResponse tr, ActionResponse ar, String action_name, String dlg_id, String time_type, String time_target) { util.addLogMsg("I", String.format(taskMgrParms.teMsgs.msgs_thread_task_exec_time, action_name, time_type, time_target)); resetIntervalTimer(taskMgrParms, envParms, util, tr, ar, action_name, dlg_id, time_type, time_target); }; final static private void executeWaitAction(TaskManagerParms taskMgrParms, EnvironmentParms envParms, CommonUtilities util, TaskResponse tr, ActionResponse ar, String action_nm, String dlg_id, String wait_target, String wait_timeout_value, String wait_timeout_units) { util.addLogMsg("I", String.format(taskMgrParms.teMsgs.msgs_thread_task_exec_wait, action_nm, wait_target, wait_timeout_value, wait_timeout_units)); tr.active_action_name = action_nm; tr.active_dialog_id = dlg_id; tr.resp_time = DateUtil.convDateTimeTo_HourMinSecMili(System.currentTimeMillis()); ar.action_resp = ActionResponse.ACTION_SUCCESS; ar.resp_msg_text = ""; int timeout_val = 0; long timeout_millis = 0; if (!wait_timeout_value.equals("")) timeout_val = Integer.valueOf(wait_timeout_value); if (wait_timeout_units.equals(PROFILE_ACTION_TYPE_WAIT_TIMEOUT_UNITS_MIN)) timeout_millis = timeout_val * 60 * 1000; else timeout_millis = timeout_val * 1000; if (wait_target.equals(PROFILE_ACTION_TYPE_WAIT_TARGET_WIFI_CONNECTED)) { if (envParms.wifiIsActive) { if (envParms.wifiSsid.equals("")) { TaskManager.addNotifyEventListItem(taskMgrParms.wifiNotifyEventList, tr.active_thread_ctrl); waitDeviceEvent(tr, ar, timeout_millis); TaskManager.removeNotifyEventListItem(taskMgrParms.wifiNotifyEventList, tr.active_thread_ctrl); } else { ar.action_resp = ActionResponse.ACTION_WARNING; ar.resp_msg_text = "Wifi is already connected"; } } else { ar.action_resp = ActionResponse.ACTION_WARNING; ar.resp_msg_text = "Wifi is inactive(Off)"; } } else if (wait_target.equals(PROFILE_ACTION_TYPE_WAIT_TARGET_BLUETOOTH_CONNECTED)) { if (envParms.bluetoothIsActive) { if (envParms.blutoothDeviceName.equals("")) { TaskManager.addNotifyEventListItem(taskMgrParms.bluetoothNotifyEventList, tr.active_thread_ctrl); waitDeviceEvent(tr, ar, timeout_millis); TaskManager.removeNotifyEventListItem(taskMgrParms.bluetoothNotifyEventList, tr.active_thread_ctrl); } else { ar.action_resp = ActionResponse.ACTION_WARNING; ar.resp_msg_text = "Bluetooth is already connected"; } } else { ar.action_resp = ActionResponse.ACTION_WARNING; ar.resp_msg_text = "Bluetooth is inactive(Off)"; } } } final static public void resetIntervalTimer(TaskManagerParms taskMgrParms, EnvironmentParms envParms, CommonUtilities util, TaskResponse tr, ActionResponse ar, String action_name, String dlg_id, String time_type, String time_target) { tr.resp_id = CMD_THREAD_TO_SVC_RESET_INTERVAL_TIMER; tr.active_action_name = action_name; tr.active_dialog_id = dlg_id; tr.cmd_tgt_event_name = time_target; tr.resp_time = DateUtil.convDateTimeTo_HourMinSecMili(System.currentTimeMillis()); tr.active_notify_event.notifyToListener(true, new Object[] { tr }); ar.action_resp = ActionResponse.ACTION_SUCCESS; }; final static public void taskTriggerTaskControl(TaskManagerParms taskMgrParms, EnvironmentParms envParms, CommonUtilities util, TaskResponse tr, ActionResponse ar, String action_nm, String dlg_id, String task_type, String task_target) { tr.active_action_name = action_nm; tr.active_dialog_id = dlg_id; tr.cmd_tgt_task_name = task_target; tr.resp_time = DateUtil.convDateTimeTo_HourMinSecMili(System.currentTimeMillis()); if (task_type.equals(PROFILE_ACTION_TYPE_TASK_START_TASK)) { tr.resp_id = CMD_THREAD_TO_SVC_START_TASK; tr.active_notify_event.notifyToListener(true, new Object[] { tr }); } else { try { TaskManager.acqLock(TaskManager.LOCK_ID_TASK_CONTROL, TaskManager.LOCK_MODE_WRITE, envParms, taskMgrParms, util); TaskManager.cancelSpecificTask(taskMgrParms, envParms, util, tr.active_group_name, tr.cmd_tgt_task_name); } finally { TaskManager.relLock(TaskManager.LOCK_ID_TASK_CONTROL, TaskManager.LOCK_MODE_WRITE, envParms, taskMgrParms, util); } } ar.action_resp = ActionResponse.ACTION_SUCCESS; }; final static public boolean waitDeviceEvent(TaskResponse tr, ActionResponse ar, long timeout_millis) { long timeout_to_val = System.currentTimeMillis() + timeout_millis; while (timeout_millis == 0 || System.currentTimeMillis() < timeout_to_val) { synchronized (tr.active_thread_ctrl) { try { tr.active_thread_ctrl.wait(200); } catch (InterruptedException e) { e.printStackTrace(); } } if (tr.active_thread_ctrl.isEnable()) { if (tr.active_thread_ctrl.getExtraDataInt() == EXTRA_DEVICE_EVENT_DEVICE_CONNECTED) { ar.action_resp = ActionResponse.ACTION_SUCCESS; ar.resp_msg_text = ""; return true; } else { ar.action_resp = ActionResponse.ACTION_WARNING; ar.resp_msg_text = "Device off"; } } else { ar.action_resp = ActionResponse.ACTION_CANCELLED; ar.resp_msg_text = ""; return false; } } ar.action_resp = ActionResponse.ACTION_WARNING; ar.resp_msg_text = "Timeout"; return false; } final static public void sendCmdToService(TaskResponse tr, String action, String dlg_id, String resp_cat, String tgt_event) { tr.resp_id = resp_cat; tr.active_action_name = action; tr.active_dialog_id = dlg_id; tr.cmd_tgt_event_name = tgt_event; tr.resp_time = DateUtil.convDateTimeTo_HourMinSecMili(System.currentTimeMillis()); // Thread th=new Thread() { // @Override // public void run() { // ntfy.notifyToListener(true, new Object[] {tr}); // }; // }; // th.start(); tr.active_notify_event.notifyToListener(true, new Object[] { tr }); }; final static public void playBackMusic(TaskManagerParms taskMgrParms, EnvironmentParms envParms, CommonUtilities util, TaskResponse taskResponse, ActionResponse ar, String action, String dlg_id, String fp, String vol_left, String vol_right) { ar.action_resp = ActionResponse.ACTION_SUCCESS; File lf = new File(fp); if (!lf.exists()) { ar.action_resp = ActionResponse.ACTION_ERROR; ar.resp_msg_text = String.format(taskMgrParms.teMsgs.msgs_thread_task_play_sound_notfound, fp); return; } if (!isRingerModeNormal(envParms)) { ar.action_resp = ActionResponse.ACTION_WARNING; ar.resp_msg_text = taskMgrParms.teMsgs.msgs_thread_task_exec_ignore_sound_ringer_not_normal; return; } MediaPlayer player = MediaPlayer.create(taskMgrParms.context, Uri.parse(fp)); taskResponse.active_action_name = action; if (player != null) { int duration = player.getDuration(); TaskManager.showMessageDialog(taskMgrParms, envParms, util, taskResponse.active_group_name, taskResponse.active_task_name, taskResponse.active_action_name, taskResponse.active_dialog_id, MESSAGE_DIALOG_MESSAGE_TYPE_SOUND, fp); if (!vol_left.equals("-1") && !vol_left.equals("")) player.setVolume(Float.valueOf(vol_left) / 100, Float.valueOf(vol_right) / 100); player.start(); waitTimeTc(taskResponse, duration + 10); if (!taskResponse.active_thread_ctrl.isEnable()) { ar.action_resp = ActionResponse.ACTION_CANCELLED; ar.resp_msg_text = "Action was cancelled"; } player.stop(); player.release(); TaskManager.closeMessageDialog(taskMgrParms, envParms, util, taskResponse); } else { ar.action_resp = ActionResponse.ACTION_ERROR; ar.resp_msg_text = String.format(taskMgrParms.teMsgs.msgs_thread_task_play_sound_error, fp); } }; final static public boolean isRingerModeNormal(EnvironmentParms env_parms) { boolean result = false; if (env_parms.currentRingerMode == AudioManager.RINGER_MODE_NORMAL) result = true; return result; } final static private void waitTimeTc(TaskResponse task_response, long wt) { if (task_response.active_thread_ctrl.isEnable()) { synchronized (task_response.active_thread_ctrl) { try { task_response.active_thread_ctrl.wait(wt); } catch (InterruptedException e) { e.printStackTrace(); } } } }; final static public boolean isLocationProviderAvailable(TaskManagerParms taskMgrParms, EnvironmentParms envParms, CommonUtilities util) { return taskMgrParms.locationUtil.isLocationProviderAvailable(); }; final static public boolean isGpsLocationProviderAvailable(TaskManagerParms taskMgrParms, EnvironmentParms envParms, CommonUtilities util) { return taskMgrParms.locationUtil.isGpsLocationProviderAvailable(); }; final static public boolean isNetworkLocationProviderAvailable(TaskManagerParms taskMgrParms, EnvironmentParms envParms, CommonUtilities util) { return taskMgrParms.locationUtil.isNetworkLocationProviderAvailable(); }; final static public boolean activateNetworkLocationProvider(TaskManagerParms taskMgrParms, EnvironmentParms envParms, CommonUtilities util) { return taskMgrParms.locationUtil.activateNetworkLocationProvider(); }; final static public boolean activateGpsLocationProvider(TaskManagerParms taskMgrParms, EnvironmentParms envParms, CommonUtilities util) { return taskMgrParms.locationUtil.activateGpsLocationProvider(); }; final static public boolean activateAvailableLocationProvider(TaskManagerParms taskMgrParms, EnvironmentParms envParms, CommonUtilities util) { return taskMgrParms.locationUtil.activateAvailableLocationProvider(); }; final static public void deactivateLocationProvider(TaskManagerParms taskMgrParms, EnvironmentParms envParms, CommonUtilities util) { taskMgrParms.locationUtil.deactivateLocationProvider(); }; final static public Location getCurrentLocation(TaskManagerParms taskMgrParms, EnvironmentParms envParms, CommonUtilities util) { return taskMgrParms.locationUtil.getCurrentLocation(); }; final static public Location getLastKnownLocation(TaskManagerParms taskMgrParms, EnvironmentParms envParms, CommonUtilities util) { return taskMgrParms.locationUtil.getLastKnownLocation(); }; final static public Location getLastKnownLocationGpsProvider(TaskManagerParms taskMgrParms, EnvironmentParms envParms, CommonUtilities util) { return taskMgrParms.locationUtil.getLastKnownLocationGpsProvider(); }; final static public Location getLastKnownLocationNetworkProvider(TaskManagerParms taskMgrParms, EnvironmentParms envParms, CommonUtilities util) { return taskMgrParms.locationUtil.getLastKnownLocationNetworkProvider(); }; final static public boolean setWifiDisableSsid(TaskManagerParms taskMgrParms, EnvironmentParms envParms, CommonUtilities util, TaskResponse taskResponse, ActionResponse ar) { WifiManager wm = (WifiManager) taskMgrParms.context.getSystemService(Context.WIFI_SERVICE); int nwid = wm.getConnectionInfo().getNetworkId(); if (envParms.isWifiConnected()) { if (!envParms.wifiSsid.equals(EnvironmentParms.WIFI_DIRECT_SSID)) { wm.disableNetwork(nwid); ar.action_resp = ActionResponse.ACTION_SUCCESS; ar.resp_msg_text = ""; return true; } else { ar.action_resp = ActionResponse.ACTION_WARNING; ar.resp_msg_text = "Can not disabled, WiFi is connected to WiFi-Direct"; return false; } } ar.action_resp = ActionResponse.ACTION_WARNING; ar.resp_msg_text = "Wifi not connected"; return false; } final static public boolean setWifiRemoveSsid(TaskManagerParms taskMgrParms, EnvironmentParms envParms, CommonUtilities util, TaskResponse taskResponse, ActionResponse ar) { WifiManager wm = (WifiManager) taskMgrParms.context.getSystemService(Context.WIFI_SERVICE); int nwid = wm.getConnectionInfo().getNetworkId(); if (envParms.isWifiConnected()) { if (!envParms.wifiSsid.equals(EnvironmentParms.WIFI_DIRECT_SSID)) { wm.removeNetwork(nwid); ar.action_resp = ActionResponse.ACTION_SUCCESS; ar.resp_msg_text = ""; return true; } else { ar.action_resp = ActionResponse.ACTION_WARNING; ar.resp_msg_text = "Can not removed, WiFi is connected to WiFi-Direct"; return false; } } ar.action_resp = ActionResponse.ACTION_WARNING; ar.resp_msg_text = "Wifi not connected"; return false; } final static public boolean setScreenSwitchToHome(TaskManagerParms taskMgrParms, EnvironmentParms envParms, CommonUtilities util, TaskResponse taskResponse, ActionResponse ar) { Intent in = new Intent(); in.setAction(Intent.ACTION_MAIN); in.addCategory(Intent.CATEGORY_HOME); in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); taskMgrParms.context.startActivity(in); return true; } final static public boolean setScreenLocked(TaskManagerParms taskMgrParms, final CommonUtilities util, TaskResponse taskResponse, ActionResponse ar) { if (!util.screenLockNow()) { String msg = String.format(taskMgrParms.teMsgs.msgs_thread_task_screen_lock_ignored, taskResponse.active_event_name, taskResponse.active_task_name); util.addLogMsg("W", msg); ar.action_resp = ActionResponse.ACTION_WARNING; ar.resp_msg_text = msg; return true; } else { if (Build.VERSION.SDK_INT > 10) { taskMgrParms.svcHandler.postDelayed(new Runnable() { @Override public void run() { util.screenLockNow(); } }, 500); } } return false; } final static public boolean playBackDefaultAlarm(TaskManagerParms taskMgrParms, EnvironmentParms envParms, CommonUtilities util, TaskResponse tr, ActionResponse ar) { if (!isRingerModeNormal(envParms)) { ar.action_resp = ActionResponse.ACTION_WARNING; ar.resp_msg_text = taskMgrParms.teMsgs.msgs_thread_task_exec_ignore_sound_ringer_not_normal; return false; } Uri uri = RingtoneManager.getActualDefaultRingtoneUri(taskMgrParms.context, RingtoneManager.TYPE_ALARM); // Uri uri=RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM); if (uri != null) { playBackRingtone(taskMgrParms, envParms, util, tr, ar, tr.active_dialog_id, PROFILE_ACTION_RINGTONE_TYPE_ALARM, "", uri.getEncodedPath(), "-1", "-1"); } else { ar.action_resp = ActionResponse.ACTION_WARNING; ar.resp_msg_text = "Default alarm does not exists"; } return true; } final static public boolean playBackDefaultNotification(TaskManagerParms taskMgrParms, EnvironmentParms envParms, CommonUtilities util, TaskResponse tr, ActionResponse ar) { if (!isRingerModeNormal(envParms)) { ar.action_resp = ActionResponse.ACTION_WARNING; ar.resp_msg_text = taskMgrParms.teMsgs.msgs_thread_task_exec_ignore_sound_ringer_not_normal; return false; } Uri uri = RingtoneManager.getActualDefaultRingtoneUri(taskMgrParms.context, RingtoneManager.TYPE_NOTIFICATION); // Uri uri=RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); if (uri != null) { playBackRingtone(taskMgrParms, envParms, util, tr, ar, tr.active_dialog_id, PROFILE_ACTION_RINGTONE_TYPE_NOTIFICATION, "", uri.getEncodedPath(), "-1", "-1"); } else { ar.action_resp = ActionResponse.ACTION_WARNING; ar.resp_msg_text = "Default notification does not exists"; } return true; } final static public boolean playBackDefaultRingtone(TaskManagerParms taskMgrParms, EnvironmentParms envParms, CommonUtilities util, TaskResponse tr, ActionResponse ar) { if (!isRingerModeNormal(envParms)) { ar.action_resp = ActionResponse.ACTION_WARNING; ar.resp_msg_text = taskMgrParms.teMsgs.msgs_thread_task_exec_ignore_sound_ringer_not_normal; return false; } Uri uri = RingtoneManager.getActualDefaultRingtoneUri(taskMgrParms.context, RingtoneManager.TYPE_RINGTONE); // Uri uri=RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE); if (uri != null) { playBackRingtone(taskMgrParms, envParms, util, tr, ar, tr.active_dialog_id, PROFILE_ACTION_RINGTONE_TYPE_RINGTONE, "", uri.getEncodedPath(), "-1", "-1"); } else { ar.action_resp = ActionResponse.ACTION_WARNING; ar.resp_msg_text = "Default ringtone does not exists"; } return true; } final static public boolean setAutoSyncEnabled(TaskManagerParms taskMgrParms, EnvironmentParms envParms, CommonUtilities util, TaskResponse taskResponse, ActionResponse ar) { if (!ContentResolver.getMasterSyncAutomatically()) { ContentResolver.setMasterSyncAutomatically(true); return true; } else { ar.action_resp = ActionResponse.ACTION_WARNING; ar.resp_msg_text = "AutoSync was already enabled, action ignored"; return false; } } final static public boolean setAutoSyncDisabled(TaskManagerParms taskMgrParms, EnvironmentParms envParms, CommonUtilities util, TaskResponse taskResponse, ActionResponse ar) { if (ContentResolver.getMasterSyncAutomatically()) { ContentResolver.setMasterSyncAutomatically(false); return true; } else { ar.action_resp = ActionResponse.ACTION_WARNING; ar.resp_msg_text = "AutoSync was already disabled, action ignored"; return false; } } final static public void playBackRingtone(TaskManagerParms taskMgrParms, EnvironmentParms envParms, CommonUtilities util, TaskResponse taskResponse, ActionResponse ar, String dlg_id, String rt, String rn, String rp, String vol_left, String vol_right) { ar.action_resp = ActionResponse.ACTION_SUCCESS; if (!isRingerModeNormal(envParms)) { ar.action_resp = ActionResponse.ACTION_WARNING; ar.resp_msg_text = taskMgrParms.teMsgs.msgs_thread_task_exec_ignore_sound_ringer_not_normal; return; } MediaPlayer player = MediaPlayer.create(taskMgrParms.context, Uri.parse("content://media" + rp)); // taskResponse.active_action_name=action; if (player != null) { int duration = 0; if (!rt.equals(PROFILE_ACTION_RINGTONE_TYPE_NOTIFICATION)) duration = RINGTONE_PLAYBACK_TIME; else duration = player.getDuration(); if (duration >= 5000) { TaskManager.showMessageDialog(taskMgrParms, envParms, util, taskResponse.active_group_name, taskResponse.active_task_name, taskResponse.active_action_name, taskResponse.active_dialog_id, MESSAGE_DIALOG_MESSAGE_TYPE_SOUND, rt + " " + rn); } if (!vol_left.equals("-1") && !vol_left.equals("")) player.setVolume(Float.valueOf(vol_left) / 100, Float.valueOf(vol_right) / 100); player.start(); waitTimeTc(taskResponse, duration + 10); if (!taskResponse.active_thread_ctrl.isEnable()) { ar.action_resp = ActionResponse.ACTION_CANCELLED; ar.resp_msg_text = "Action was cancelled"; } player.stop(); player.release(); if (duration >= 5000) { TaskManager.closeMessageDialog(taskMgrParms, envParms, util, taskResponse); } } else { ar.action_resp = ActionResponse.ACTION_ERROR; ar.resp_msg_text = String.format(taskMgrParms.teMsgs.msgs_thread_task_play_sound_error, rp); } } final static public void showMessage(TaskManagerParms taskMgrParms, EnvironmentParms envParms, CommonUtilities util, TaskResponse tr, ActionResponse ar, String actionnm, String dlg_id, String msg_type, String msg_text, boolean use_vib, boolean use_led, String led_color) { if (msg_type.equals(PROFILE_ACTION_TYPE_MESSAGE_DIALOG)) { tr.active_action_name = actionnm; tr.active_dialog_id = dlg_id; tr.cmd_message_type = msg_type; tr.cmd_message_text = msg_text; tr.resp_time = DateUtil.convDateTimeTo_HourMinSecMili(System.currentTimeMillis()); TaskManager.showMessageDialog(taskMgrParms, envParms, util, tr.active_group_name, tr.active_task_name, tr.active_action_name, tr.active_dialog_id, MESSAGE_DIALOG_MESSAGE_TYPE_DIALOG, tr.cmd_message_text); } else if (msg_type.equals(PROFILE_ACTION_TYPE_MESSAGE_NOTIFICATION)) { if (use_led) { if (led_color.equals(PROFILE_ACTION_TYPE_MESSAGE_LED_BLUE)) { showMessageNotification(taskMgrParms, envParms, util, tr, msg_text, 0xff0000ff, 300, 600); } else if (led_color.equals(PROFILE_ACTION_TYPE_MESSAGE_LED_RED)) { showMessageNotification(taskMgrParms, envParms, util, tr, msg_text, 0xffff0000, 300, 600); } else { showMessageNotification(taskMgrParms, envParms, util, tr, msg_text, 0xff00ff00, 300, 600); } } else showMessageNotification(taskMgrParms, envParms, util, tr, msg_text, 00, 0, 0); } if (use_vib) vibrateDefaultPattern(taskMgrParms.context, ar); ar.action_resp = ActionResponse.ACTION_SUCCESS; ar.resp_msg_text = ""; }; final static private void showMessageNotification(TaskManagerParms taskMgrParms, EnvironmentParms envParms, CommonUtilities util, TaskResponse tr, String m_text, int led_color, int led_on, int led_off) { NotificationManager nm = (NotificationManager) taskMgrParms.context .getSystemService(Context.NOTIFICATION_SERVICE); NotificationCompat.Builder nb = new NotificationCompat.Builder(taskMgrParms.context); nm.cancel("MSG", taskMgrParms.msgNotificationId); Intent in = new Intent(); PendingIntent pi = PendingIntent.getActivity(taskMgrParms.context, 0, in, PendingIntent.FLAG_CANCEL_CURRENT); pi.cancel(); nb.setContentIntent(pi).setDefaults(Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND) .setOngoing(false).setAutoCancel(true).setSmallIcon(R.drawable.action) .setContentTitle(taskMgrParms.context.getString(R.string.app_name)).setContentText(m_text) .setWhen(System.currentTimeMillis()); if (led_color != 0) nb.setLights(led_color, led_on, led_off); Notification nf = nb.build(); nm.notify("MSG", taskMgrParms.msgNotificationId, nf); synchronized (envParms) { if (taskMgrParms.msgNotificationId >= MAX_NOTIFICATION_COUNT) taskMgrParms.msgNotificationId = 1; else taskMgrParms.msgNotificationId++; } }; final static public void vibrateDefaultPattern(Context context, ActionResponse ar) { Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); vibrator.vibrate(new long[] { 0, 200, 400, 200, 400, 200 }, -1); // vibrator.vibrate(1000); ar.action_resp = ActionResponse.ACTION_SUCCESS; ar.resp_msg_text = ""; }; final static private void executeCompareAction(TaskManagerParms taskMgrParms, EnvironmentParms envParms, CommonUtilities util, TaskResponse task_response, ActionResponse ar, String tasknm, String dlg_id, String comp_target, String comp_type, String[] comp_val, String result_action) { String clv_str = ""; int clv = 0; int tlv1 = 0, tlv2 = 0; String c_v = "", sep = ""; String[] c_v_a = comp_val; for (int c_i = 0; c_i < c_v_a.length; c_i++) { if (c_v_a[c_i] != null && !c_v_a[c_i].equals("")) { c_v += sep + c_v_a[c_i]; sep = ", "; } } if (comp_target.equals(PROFILE_ACTION_TYPE_COMPARE_TARGET_BATTERY)) { clv_str = String.valueOf(envParms.batteryLevel); clv = envParms.batteryLevel; if (!comp_val[0].equals("")) tlv1 = Integer.valueOf(comp_val[0]); if (comp_val.length > 1 && !comp_val[1].equals("")) tlv2 = Integer.valueOf(comp_val[1]); else tlv2 = -1; } else if (comp_target.equals(PROFILE_ACTION_TYPE_COMPARE_TARGET_BLUETOOTH)) { clv_str = envParms.blutoothDeviceName; } else if (comp_target.equals(PROFILE_ACTION_TYPE_COMPARE_TARGET_LIGHT)) { clv_str = String.valueOf(envParms.lightSensorValue); clv = envParms.lightSensorValue; if (!comp_val[0].equals("")) tlv1 = Integer.valueOf(comp_val[0]); if (comp_val.length > 1 && !comp_val[1].equals("")) tlv2 = Integer.valueOf(comp_val[1]); else tlv2 = -1; } else if (comp_target.equals(PROFILE_ACTION_TYPE_COMPARE_TARGET_WIFI)) { clv_str = envParms.wifiSsid; } else if (comp_target.equals(PROFILE_ACTION_TYPE_COMPARE_TARGET_TIME)) { SimpleDateFormat sdf = new SimpleDateFormat("HH", Locale.getDefault()); clv_str = sdf.format(System.currentTimeMillis()); clv = Integer.valueOf(clv_str); if (!comp_val[0].equals("")) tlv1 = Integer.valueOf(comp_val[0]); if (comp_val.length > 1 && !comp_val[1].equals("")) tlv2 = Integer.valueOf(comp_val[1]); else tlv2 = -1; } util.addLogMsg("I", String.format(taskMgrParms.teMsgs.msgs_thread_task_exec_compare, tasknm, clv_str, comp_target, comp_type, c_v, result_action)); if (comp_target.equals(PROFILE_ACTION_TYPE_COMPARE_TARGET_LIGHT)) { if (!envParms.lightSensorAvailable) { // util.addLogMsg("W",taskMgrParms.teMsgs.msgs_thread_task_exec_compare_light_not_available); ar.action_resp = ActionResponse.ACTION_ERROR; ar.resp_msg_text = taskMgrParms.teMsgs.msgs_thread_task_exec_light_not_available; return; } } int comp_result = 0; if (comp_target.equals(PROFILE_ACTION_TYPE_COMPARE_TARGET_BATTERY)) { comp_result = executeCompareActionNumeric(comp_type, clv, tlv1, tlv2, result_action); } else if (comp_target.equals(PROFILE_ACTION_TYPE_COMPARE_TARGET_BLUETOOTH)) { comp_result = executeCompareActionString(comp_type, clv_str, comp_val, result_action); } else if (comp_target.equals(PROFILE_ACTION_TYPE_COMPARE_TARGET_LIGHT)) { comp_result = executeCompareActionNumeric(comp_type, clv, tlv1, tlv2, result_action); } else if (comp_target.equals(PROFILE_ACTION_TYPE_COMPARE_TARGET_WIFI)) { comp_result = executeCompareActionString(comp_type, clv_str, comp_val, result_action); } else if (comp_target.equals(PROFILE_ACTION_TYPE_COMPARE_TARGET_TIME)) { comp_result = executeCompareActionTime(comp_type, clv, tlv1, tlv2, result_action); } if (comp_result == ActionResponse.ACTION_ABORT) { ar.action_resp = ActionResponse.ACTION_ABORT; ar.resp_msg_text = taskMgrParms.teMsgs.msgs_thread_task_exec_compare_abort; } else if (comp_result == ActionResponse.ACTION_SKIP) { ar.action_resp = ActionResponse.ACTION_SKIP; ar.resp_msg_text = taskMgrParms.teMsgs.msgs_thread_task_exec_compare_skip; } }; final static private int executeCompareActionString(String comp_type, String clv, String[] tlv, String result_action) { if (comp_type.equals(PROFILE_ACTION_TYPE_COMPARE_COMPARE_EQ)) { for (int i = 0; i < tlv.length; i++) { if (clv.equals(tlv[i])) { if (result_action.equals(PROFILE_ACTION_TYPE_COMPARE_RESULT_ABORT)) { return ActionResponse.ACTION_ABORT; } else if (result_action.equals(PROFILE_ACTION_TYPE_COMPARE_RESULT_SKIP)) { return ActionResponse.ACTION_SKIP; } } } } else if (comp_type.equals(PROFILE_ACTION_TYPE_COMPARE_CPMPARE_NE)) { boolean cond_unsatisfied = false; for (int i = 0; i < tlv.length; i++) { if (clv.equals(tlv[i])) { cond_unsatisfied = true; break; } } if (!cond_unsatisfied) { if (result_action.equals(PROFILE_ACTION_TYPE_COMPARE_RESULT_ABORT)) { return ActionResponse.ACTION_ABORT; } else if (result_action.equals(PROFILE_ACTION_TYPE_COMPARE_RESULT_SKIP)) { return ActionResponse.ACTION_SKIP; } } } return ActionResponse.ACTION_SUCCESS; }; final static private int executeCompareActionNumeric(String comp_type, int clv, int tlv1, int tlv2, String result_action) { if (comp_type.equals(PROFILE_ACTION_TYPE_COMPARE_COMPARE_EQ)) { if (clv == tlv1) { if (result_action.equals(PROFILE_ACTION_TYPE_COMPARE_RESULT_ABORT)) { return ActionResponse.ACTION_ABORT; } else if (result_action.equals(PROFILE_ACTION_TYPE_COMPARE_RESULT_SKIP)) { return ActionResponse.ACTION_SKIP; } } } else if (comp_type.equals(PROFILE_ACTION_TYPE_COMPARE_CPMPARE_NE)) { if (clv != tlv1) { if (result_action.equals(PROFILE_ACTION_TYPE_COMPARE_RESULT_ABORT)) { return ActionResponse.ACTION_ABORT; } else if (result_action.equals(PROFILE_ACTION_TYPE_COMPARE_RESULT_SKIP)) { return ActionResponse.ACTION_SKIP; } } } else if (comp_type.equals(PROFILE_ACTION_TYPE_COMPARE_COMPARE_GT)) { if (clv > tlv1) { if (result_action.equals(PROFILE_ACTION_TYPE_COMPARE_RESULT_ABORT)) { return ActionResponse.ACTION_ABORT; } else if (result_action.equals(PROFILE_ACTION_TYPE_COMPARE_RESULT_SKIP)) { return ActionResponse.ACTION_SKIP; } } } else if (comp_type.equals(PROFILE_ACTION_TYPE_COMPARE_COMPARE_LT)) { if (clv < tlv1) { if (result_action.equals(PROFILE_ACTION_TYPE_COMPARE_RESULT_ABORT)) { return ActionResponse.ACTION_ABORT; } else if (result_action.equals(PROFILE_ACTION_TYPE_COMPARE_RESULT_SKIP)) { return ActionResponse.ACTION_SKIP; } } } else if (comp_type.equals(PROFILE_ACTION_TYPE_COMPARE_COMPARE_BETWEEN)) { if (clv >= tlv1 && clv <= tlv2) { if (result_action.equals(PROFILE_ACTION_TYPE_COMPARE_RESULT_ABORT)) { return ActionResponse.ACTION_ABORT; } else if (result_action.equals(PROFILE_ACTION_TYPE_COMPARE_RESULT_SKIP)) { return ActionResponse.ACTION_SKIP; } } } return ActionResponse.ACTION_SUCCESS; }; final static private int executeCompareActionTime(String comp_type, int clv, int tlv1, int tlv2, String result_action) { if (comp_type.equals(PROFILE_ACTION_TYPE_COMPARE_COMPARE_EQ)) { if (clv == tlv1) { if (result_action.equals(PROFILE_ACTION_TYPE_COMPARE_RESULT_ABORT)) { return ActionResponse.ACTION_ABORT; } else if (result_action.equals(PROFILE_ACTION_TYPE_COMPARE_RESULT_SKIP)) { return ActionResponse.ACTION_SKIP; } } } else if (comp_type.equals(PROFILE_ACTION_TYPE_COMPARE_CPMPARE_NE)) { if (clv != tlv1) { if (result_action.equals(PROFILE_ACTION_TYPE_COMPARE_RESULT_ABORT)) { return ActionResponse.ACTION_ABORT; } else if (result_action.equals(PROFILE_ACTION_TYPE_COMPARE_RESULT_SKIP)) { return ActionResponse.ACTION_SKIP; } } } else if (comp_type.equals(PROFILE_ACTION_TYPE_COMPARE_COMPARE_GT)) { if (clv > tlv1) { if (result_action.equals(PROFILE_ACTION_TYPE_COMPARE_RESULT_ABORT)) { return ActionResponse.ACTION_ABORT; } else if (result_action.equals(PROFILE_ACTION_TYPE_COMPARE_RESULT_SKIP)) { return ActionResponse.ACTION_SKIP; } } } else if (comp_type.equals(PROFILE_ACTION_TYPE_COMPARE_COMPARE_LT)) { if (clv < tlv1) { if (result_action.equals(PROFILE_ACTION_TYPE_COMPARE_RESULT_ABORT)) { return ActionResponse.ACTION_ABORT; } else if (result_action.equals(PROFILE_ACTION_TYPE_COMPARE_RESULT_SKIP)) { return ActionResponse.ACTION_SKIP; } } } else if (comp_type.equals(PROFILE_ACTION_TYPE_COMPARE_COMPARE_BETWEEN)) { if (tlv2 > 23) { int t_clv = clv; if (clv > 23) t_clv = (clv + 24); if (clv >= tlv1 && t_clv <= tlv2) { if (result_action.equals(PROFILE_ACTION_TYPE_COMPARE_RESULT_ABORT)) { return ActionResponse.ACTION_ABORT; } else if (result_action.equals(PROFILE_ACTION_TYPE_COMPARE_RESULT_SKIP)) { return ActionResponse.ACTION_SKIP; } } } else { if (clv >= tlv1 && clv <= tlv2) { if (result_action.equals(PROFILE_ACTION_TYPE_COMPARE_RESULT_ABORT)) { return ActionResponse.ACTION_ABORT; } else if (result_action.equals(PROFILE_ACTION_TYPE_COMPARE_RESULT_SKIP)) { return ActionResponse.ACTION_SKIP; } } } } return ActionResponse.ACTION_SUCCESS; }; @SuppressWarnings("deprecation") final static public void screenOnAsync(TaskManagerParms taskMgrParms, TaskResponse tr, ActionResponse ar) { WakeLock wakelock = ((PowerManager) taskMgrParms.context.getSystemService(Context.POWER_SERVICE)) .newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP // | PowerManager.ON_AFTER_RELEASE , "Scheduler-ScreenOn"); wakelock.acquire(10 * 1 * 1000); // if (Build.VERSION.SDK_INT>=13) { // screenOnByActivity(taskMgrParms,tr,ar); // } else { // wakelock.acquire(10*1*1000); // } ar.action_resp = ActionResponse.ACTION_SUCCESS; ar.resp_msg_text = ""; }; @SuppressWarnings("deprecation") final static public void screenOnSync(TaskManagerParms taskMgrParms, TaskResponse tr, ActionResponse ar) { WakeLock wakelock = ((PowerManager) taskMgrParms.context.getSystemService(Context.POWER_SERVICE)) .newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP // | PowerManager.ON_AFTER_RELEASE , "Scheduler-ScreenOn"); try { wakelock.acquire(); // if (Build.VERSION.SDK_INT>=13) { // screenOnByActivity(taskMgrParms,tr,ar); // } else { // wakelock.acquire(); // } waitTimeTc(tr, 10 * 1 * 1000); ar.action_resp = ActionResponse.ACTION_SUCCESS; ar.resp_msg_text = ""; } finally { if (wakelock.isHeld()) wakelock.release(); } }; final static public void setBluetoothOff(TaskManagerParms taskMgrParms, EnvironmentParms envParms, CommonUtilities util, TaskResponse task_response, ActionResponse ar) { if (BluetoothAdapter.getDefaultAdapter() != null) { if (BluetoothAdapter.getDefaultAdapter().isEnabled()) { if (envParms.settingDebugLevel >= 1) util.addDebugMsg(1, "I", "setBluetoothOff Bluetooth off"); BluetoothAdapter.getDefaultAdapter().disable(); ar.action_resp = ActionResponse.ACTION_SUCCESS; ar.resp_msg_text = ""; } else { ar.action_resp = ActionResponse.ACTION_WARNING; ar.resp_msg_text = "Bluetooth already off"; } } else { if (envParms.settingDebugLevel >= 1) util.addDebugMsg(1, "I", "setBluetoothOff BluetoothAdapter not available, Bluetooth off ignored"); ar.action_resp = ActionResponse.ACTION_WARNING; ar.resp_msg_text = "Bluetooth not available"; } }; final static public void setBluetoothOn(TaskManagerParms taskMgrParms, EnvironmentParms envParms, CommonUtilities util, TaskResponse task_response, ActionResponse ar) { if (BluetoothAdapter.getDefaultAdapter() != null) { if (!BluetoothAdapter.getDefaultAdapter().isEnabled()) { if (envParms.settingDebugLevel >= 1) util.addDebugMsg(1, "I", "setBluetoothOn Bluetooth on"); BluetoothAdapter.getDefaultAdapter().enable(); ar.action_resp = ActionResponse.ACTION_SUCCESS; ar.resp_msg_text = ""; } else { ar.action_resp = ActionResponse.ACTION_WARNING; ar.resp_msg_text = "Bluetooth already on"; } } else { if (envParms.settingDebugLevel >= 1) util.addDebugMsg(1, "I", "setBluetoothOn BluetoothAdapter not available, Bluetooth on ignored"); ar.action_resp = ActionResponse.ACTION_WARNING; ar.resp_msg_text = "Bluetooth not available"; } }; final static public void setWifiOn(TaskManagerParms taskMgrParms, EnvironmentParms envParms, CommonUtilities util, TaskResponse task_response, ActionResponse ar) { WifiManager wm = (WifiManager) taskMgrParms.context.getSystemService(Context.WIFI_SERVICE); int ws = -1; if (wm != null) ws = wm.getWifiState(); if (envParms.settingDebugLevel >= 1) util.addDebugMsg(1, "I", "setWifiOn WIFI On entered, wifiIsActive=" + envParms.wifiIsActive + ", wifiMgrStatus=" + ws); if (!envParms.wifiIsActive) { if (wm != null) { if (wm.setWifiEnabled(true)) { ar.action_resp = ActionResponse.ACTION_SUCCESS; ar.resp_msg_text = "setWifiOn WIFI On Success"; } else { if (envParms.settingDebugLevel >= 1) util.addDebugMsg(1, "I", "setWifiOn WifiManager error, WIFI On ignored"); ar.action_resp = ActionResponse.ACTION_WARNING; ar.resp_msg_text = "setWifiOn WifiManager error"; } } else { if (envParms.settingDebugLevel >= 1) util.addDebugMsg(1, "I", "setWifiOn WifiManager not available, WIFI On ignored"); ar.action_resp = ActionResponse.ACTION_WARNING; ar.resp_msg_text = "setWifiOn WIFI not available"; } } else { ar.action_resp = ActionResponse.ACTION_WARNING; ar.resp_msg_text = "setWifiOn WIFI already on"; } }; final static public void setWifiOff(TaskManagerParms taskMgrParms, EnvironmentParms envParms, CommonUtilities util, TaskResponse task_response, ActionResponse ar) { WifiManager wm = (WifiManager) taskMgrParms.context.getSystemService(Context.WIFI_SERVICE); int ws = -1; if (wm != null) ws = wm.getWifiState(); if (envParms.settingDebugLevel >= 1) util.addDebugMsg(1, "I", "setWifiOff WIFI Off entered, wifiIsActive=" + envParms.wifiIsActive + ", wifiMgrStatus=" + ws); if (envParms.wifiIsActive) { if (wm != null) { wm.setWifiEnabled(false); ar.action_resp = ActionResponse.ACTION_SUCCESS; ar.resp_msg_text = "setWifiOff WIFI Off Success"; } else { if (envParms.settingDebugLevel >= 1) util.addDebugMsg(1, "I", "setWifiOff WifiManager not available, WIFI Off ignored"); ar.action_resp = ActionResponse.ACTION_WARNING; ar.resp_msg_text = "setWifiOff WIFI not available"; } } else { ar.action_resp = ActionResponse.ACTION_WARNING; ar.resp_msg_text = "setWifiOff WIFI already off"; } }; }