summaryrefslogtreecommitdiff
path: root/SDL_Android/SmartDeviceLinkTester/src
diff options
context:
space:
mode:
Diffstat (limited to 'SDL_Android/SmartDeviceLinkTester/src')
-rw-r--r--SDL_Android/SmartDeviceLinkTester/src/com/smartdevicelink/android/activity/IntentHelper.java35
-rw-r--r--SDL_Android/SmartDeviceLinkTester/src/com/smartdevicelink/android/activity/SmartDeviceLinkTester.java1297
-rw-r--r--SDL_Android/SmartDeviceLinkTester/src/com/smartdevicelink/android/adapters/MessageAdapter.java96
-rw-r--r--SDL_Android/SmartDeviceLinkTester/src/com/smartdevicelink/android/adapters/logAdapter.java125
-rw-r--r--SDL_Android/SmartDeviceLinkTester/src/com/smartdevicelink/android/constants/AcceptedRPC.java49
-rw-r--r--SDL_Android/SmartDeviceLinkTester/src/com/smartdevicelink/android/constants/Const.java37
-rw-r--r--SDL_Android/SmartDeviceLinkTester/src/com/smartdevicelink/android/constants/SmartDeviceLinkSubMenu.java27
-rw-r--r--SDL_Android/SmartDeviceLinkTester/src/com/smartdevicelink/android/module/ModuleTest.java631
-rw-r--r--SDL_Android/SmartDeviceLinkTester/src/com/smartdevicelink/android/receivers/SmartDeviceLinkReceiver.java78
-rw-r--r--SDL_Android/SmartDeviceLinkTester/src/com/smartdevicelink/android/service/ProxyService.java720
10 files changed, 3095 insertions, 0 deletions
diff --git a/SDL_Android/SmartDeviceLinkTester/src/com/smartdevicelink/android/activity/IntentHelper.java b/SDL_Android/SmartDeviceLinkTester/src/com/smartdevicelink/android/activity/IntentHelper.java
new file mode 100644
index 000000000..427f07c78
--- /dev/null
+++ b/SDL_Android/SmartDeviceLinkTester/src/com/smartdevicelink/android/activity/IntentHelper.java
@@ -0,0 +1,35 @@
+//
+// Copyright (c) 2013 Ford Motor Company
+//
+package com.smartdevicelink.android.activity;
+
+import java.util.Hashtable;
+import java.util.Map;
+
+public class IntentHelper {
+ private static IntentHelper _instance;
+ private Map<String, Object> _map;
+
+ private IntentHelper() {
+ _map = new Hashtable<String, Object>();
+ }
+
+ private static IntentHelper getInstance() {
+ if (_instance == null) {
+ _instance = new IntentHelper();
+ }
+ return _instance;
+ }
+
+ public static void addObjectForKey(Object obj, String key) {
+ getInstance()._map.put(key, obj);
+ }
+
+ public static Object getObjectForKey(String key) {
+ return getInstance()._map.get(key);
+ }
+
+ public static void removeObjectForKey(String key) {
+ getInstance()._map.remove(key);
+ }
+}
diff --git a/SDL_Android/SmartDeviceLinkTester/src/com/smartdevicelink/android/activity/SmartDeviceLinkTester.java b/SDL_Android/SmartDeviceLinkTester/src/com/smartdevicelink/android/activity/SmartDeviceLinkTester.java
new file mode 100644
index 000000000..612b62a00
--- /dev/null
+++ b/SDL_Android/SmartDeviceLinkTester/src/com/smartdevicelink/android/activity/SmartDeviceLinkTester.java
@@ -0,0 +1,1297 @@
+//
+// Copyright (c) 2013 Ford Motor Company
+//
+package com.smartdevicelink.android.activity;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Timer;
+import java.util.TimerTask;
+import java.util.Vector;
+
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.app.Dialog;
+import android.bluetooth.BluetoothAdapter;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.Menu;
+import android.view.MenuItem;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.view.ViewGroup;
+import android.widget.AdapterView;
+import android.widget.AdapterView.OnItemClickListener;
+import android.widget.ArrayAdapter;
+import android.widget.Button;
+import android.widget.CheckBox;
+import android.widget.CheckedTextView;
+import android.widget.EditText;
+import android.widget.ListView;
+import android.widget.RadioGroup;
+import android.widget.ScrollView;
+import android.widget.Spinner;
+import android.widget.Toast;
+
+import com.smartdevicelink.android.R;
+import com.smartdevicelink.android.adapters.logAdapter;
+import com.smartdevicelink.android.constants.Const;
+import com.smartdevicelink.android.constants.SmartDeviceLinkSubMenu;
+import com.smartdevicelink.android.module.ModuleTest;
+import com.smartdevicelink.android.service.ProxyService;
+import com.smartdevicelink.exception.SmartDeviceLinkException;
+import com.smartdevicelink.proxy.RPCMessage;
+import com.smartdevicelink.proxy.RPCRequest;
+import com.smartdevicelink.proxy.RPCResponse;
+import com.smartdevicelink.proxy.SmartDeviceLinkProxyALM;
+import com.smartdevicelink.proxy.TTSChunkFactory;
+import com.smartdevicelink.proxy.constants.Names;
+import com.smartdevicelink.proxy.rpc.AddCommand;
+import com.smartdevicelink.proxy.rpc.AddSubMenu;
+import com.smartdevicelink.proxy.rpc.Alert;
+import com.smartdevicelink.proxy.rpc.Choice;
+import com.smartdevicelink.proxy.rpc.CreateInteractionChoiceSet;
+import com.smartdevicelink.proxy.rpc.DeleteCommand;
+import com.smartdevicelink.proxy.rpc.DeleteInteractionChoiceSet;
+import com.smartdevicelink.proxy.rpc.DeleteSubMenu;
+import com.smartdevicelink.proxy.rpc.EncodedSyncPData;
+import com.smartdevicelink.proxy.rpc.MenuParams;
+import com.smartdevicelink.proxy.rpc.PerformInteraction;
+import com.smartdevicelink.proxy.rpc.ResetGlobalProperties;
+import com.smartdevicelink.proxy.rpc.SetGlobalProperties;
+import com.smartdevicelink.proxy.rpc.SetMediaClockTimer;
+import com.smartdevicelink.proxy.rpc.Show;
+import com.smartdevicelink.proxy.rpc.Speak;
+import com.smartdevicelink.proxy.rpc.StartTime;
+import com.smartdevicelink.proxy.rpc.SubscribeButton;
+import com.smartdevicelink.proxy.rpc.TTSChunk;
+import com.smartdevicelink.proxy.rpc.UnsubscribeButton;
+import com.smartdevicelink.proxy.rpc.enums.ButtonName;
+import com.smartdevicelink.proxy.rpc.enums.GlobalProperty;
+import com.smartdevicelink.proxy.rpc.enums.InteractionMode;
+import com.smartdevicelink.proxy.rpc.enums.Language;
+import com.smartdevicelink.proxy.rpc.enums.SpeechCapabilities;
+import com.smartdevicelink.proxy.rpc.enums.UpdateMode;
+import com.smartdevicelink.transport.TransportType;
+
+public class SmartDeviceLinkTester extends Activity implements OnClickListener {
+ private static final String logTag = "SmartDeviceLinkTester";
+
+ private static final String ButtonSubscriptions = "ButtonSubscriptions";
+
+ private static SmartDeviceLinkTester _activity;
+ private static ArrayList<Object> _logMessages = new ArrayList<Object>();
+ private static logAdapter _msgAdapter;
+ private ModuleTest _testerMain;
+
+ private ScrollView _scroller = null;
+ private ListView _listview = null;
+
+ private ArrayAdapter<SmartDeviceLinkSubMenu> _submenuAdapter = null;
+ private ArrayAdapter<Integer> _commandAdapter = null;
+ private ArrayAdapter<Integer> _choiceSetAdapter = null;
+
+ private static final int CHOICESETID_UNSET = -1;
+ /**
+ * Latest choiceSetId, required to add it to the adapter when a successful
+ * CreateInteractionChoiceSetResponse comes.
+ */
+ private int _latestChoiceSetId = CHOICESETID_UNSET;
+
+ private int autoIncCorrId = 101;
+ private int autoIncChoiceSetId = 1;
+ private int autoIncChoiceSetIdCmdId = 1;
+ private int itemcmdID = 1;
+ private int submenucmdID = 1000;
+
+ private ArrayAdapter<ButtonName> _buttonAdapter = null;
+ private boolean[] isButtonSubscribed = null;
+
+ /**
+ * In onCreate() specifies if it is the first time the activity is created
+ * during this app launch.
+ */
+ private static boolean isFirstActivityRun = true;
+
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ _activity = this;
+
+ setContentView(R.layout.main);
+ _scroller = (ScrollView) findViewById(R.id.scrollConsole);
+
+ ((Button) findViewById(R.id.btnSendMessage)).setOnClickListener(this);
+ ((Button) findViewById(R.id.btnPlayPause)).setOnClickListener(this);
+
+ resetAdapters();
+
+ _listview = (ListView) findViewById(R.id.messageList);
+ _msgAdapter = new logAdapter(logTag, false, this, R.layout.row, _logMessages);
+
+ _listview.setClickable(true);
+ _listview.setAdapter(_msgAdapter);
+ _listview.setTranscriptMode(ListView.TRANSCRIPT_MODE_ALWAYS_SCROLL);
+ _listview.setOnItemClickListener(new OnItemClickListener() {
+ public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
+ Object listObj = parent.getItemAtPosition(position);
+ if (listObj instanceof RPCMessage) {
+ AlertDialog.Builder builder = new AlertDialog.Builder(SmartDeviceLinkTester.this);
+ String rawJSON = "";
+
+ Integer corrId = -1;
+ if (listObj instanceof RPCRequest) {
+ corrId = ((RPCRequest) listObj).getCorrelationID();
+ } else if (listObj instanceof RPCResponse) {
+ corrId = ((RPCResponse) listObj).getCorrelationID();
+ }
+
+ try {
+ rawJSON = ((RPCMessage) listObj).serializeJSON().toString(2);
+ builder.setTitle("Raw JSON" + (corrId != -1 ? " (Corr ID " + corrId + ")" : ""));
+ } catch (Exception e) {
+ try {rawJSON = ((RPCMessage) listObj).getFunctionName() +
+ " (" + ((RPCMessage) listObj).getMessageType() + ")";
+ } catch (Exception e1) {rawJSON = "Undefined";}
+ }
+ builder.setMessage(rawJSON);
+ builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int id) {
+ dialog.cancel();
+ }
+ });
+ AlertDialog ad = builder.create();
+ ad.show();
+ } else if (listObj instanceof String){
+ AlertDialog.Builder builder = new AlertDialog.Builder(SmartDeviceLinkTester.this);
+ builder.setMessage(listObj.toString());
+ builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int id) {
+ dialog.cancel();
+ }
+ });
+ AlertDialog ad = builder.create();
+ ad.show();
+ }
+ }
+ });
+
+ if (isFirstActivityRun) {
+ propertiesUI();
+ } else {
+ showPropertiesInTitle();
+ startSmartDeviceLinkProxy();
+ }
+
+ isFirstActivityRun = false;
+ }
+
+ /**
+ * Shows a dialog where the user can select connection features (protocol
+ * version, media flag, app name, language, HMI language, and transport
+ * settings). Starts the proxy after selecting.
+ */
+ private void propertiesUI() {
+ Context context = this;
+ LayoutInflater inflater = (LayoutInflater) context
+ .getSystemService(LAYOUT_INFLATER_SERVICE);
+ View view = inflater.inflate(R.layout.properties,
+ (ViewGroup) findViewById(R.id.properties_Root));
+
+ ArrayAdapter<Language> langAdapter = new ArrayAdapter<Language>(this,
+ android.R.layout.simple_spinner_item, Language.values());
+ langAdapter
+ .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+
+ final CheckBox mediaCheckBox = (CheckBox) view
+ .findViewById(R.id.properties_checkMedia);
+ final EditText appNameEditText = (EditText) view
+ .findViewById(R.id.properties_appName);
+ final RadioGroup transportGroup = (RadioGroup) view
+ .findViewById(R.id.properties_radioGroupTransport);
+ final EditText ipAddressEditText = (EditText) view
+ .findViewById(R.id.properties_ipAddr);
+ final EditText tcpPortEditText = (EditText) view
+ .findViewById(R.id.properties_tcpPort);
+ final CheckBox autoReconnectCheckBox = (CheckBox) view
+ .findViewById(R.id.properties_checkAutoReconnect);
+
+ ipAddressEditText.setEnabled(false);
+ tcpPortEditText.setEnabled(false);
+ autoReconnectCheckBox.setEnabled(false);
+
+ transportGroup
+ .setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
+ @Override
+ public void onCheckedChanged(RadioGroup group, int checkedId) {
+ boolean transportOptionsEnabled = checkedId == R.id.properties_radioWiFi;
+ ipAddressEditText.setEnabled(transportOptionsEnabled);
+ tcpPortEditText.setEnabled(transportOptionsEnabled);
+ autoReconnectCheckBox
+ .setEnabled(transportOptionsEnabled);
+ }
+ });
+
+ // display current configs
+ final SharedPreferences prefs = getSharedPreferences(Const.PREFS_NAME,
+ 0);
+ boolean isMedia = prefs.getBoolean(Const.PREFS_KEY_ISMEDIAAPP,
+ Const.PREFS_DEFAULT_ISMEDIAAPP);
+ String appName = prefs.getString(Const.PREFS_KEY_APPNAME,
+ Const.PREFS_DEFAULT_APPNAME);
+ int transportType = prefs.getInt(
+ Const.Transport.PREFS_KEY_TRANSPORT_TYPE,
+ Const.Transport.PREFS_DEFAULT_TRANSPORT_TYPE);
+ String ipAddress = prefs.getString(
+ Const.Transport.PREFS_KEY_TRANSPORT_IP,
+ Const.Transport.PREFS_DEFAULT_TRANSPORT_IP);
+ int tcpPort = prefs.getInt(Const.Transport.PREFS_KEY_TRANSPORT_PORT,
+ Const.Transport.PREFS_DEFAULT_TRANSPORT_PORT);
+ boolean autoReconnect = prefs.getBoolean(
+ Const.Transport.PREFS_KEY_TRANSPORT_RECONNECT,
+ Const.Transport.PREFS_DEFAULT_TRANSPORT_RECONNECT_DEFAULT);
+
+ mediaCheckBox.setChecked(isMedia);
+ appNameEditText.setText(appName);
+ transportGroup
+ .check(transportType == Const.Transport.KEY_TCP ? R.id.properties_radioWiFi
+ : R.id.properties_radioBT);
+ ipAddressEditText.setText(ipAddress);
+ tcpPortEditText.setText(String.valueOf(tcpPort));
+ autoReconnectCheckBox.setChecked(autoReconnect);
+
+ new AlertDialog.Builder(context)
+ .setTitle("Please select properties")
+ .setCancelable(false)
+ .setPositiveButton("OK", new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+
+ String appName = appNameEditText.getText().toString();
+ boolean isMedia = mediaCheckBox.isChecked();
+ int transportType = transportGroup
+ .getCheckedRadioButtonId() == R.id.properties_radioWiFi ? Const.Transport.KEY_TCP
+ : Const.Transport.KEY_BLUETOOTH;
+ String ipAddress = ipAddressEditText.getText()
+ .toString();
+ int tcpPort = Integer.parseInt(tcpPortEditText
+ .getText().toString());
+ boolean autoReconnect = autoReconnectCheckBox
+ .isChecked();
+
+ // save the configs
+ boolean success = prefs
+ .edit()
+ .putBoolean(Const.PREFS_KEY_ISMEDIAAPP, isMedia)
+ .putString(Const.PREFS_KEY_APPNAME, appName)
+ .putInt(Const.Transport.PREFS_KEY_TRANSPORT_TYPE,
+ transportType)
+ .putString(
+ Const.Transport.PREFS_KEY_TRANSPORT_IP,
+ ipAddress)
+ .putInt(Const.Transport.PREFS_KEY_TRANSPORT_PORT,
+ tcpPort)
+ .putBoolean(
+ Const.Transport.PREFS_KEY_TRANSPORT_RECONNECT,
+ autoReconnect).commit();
+ if (!success) {
+ Log.w(logTag,
+ "Can't save properties");
+ }
+
+ showPropertiesInTitle();
+ startSmartDeviceLinkProxy();
+ }
+ }).setView(view).show();
+ }
+
+ /** Starts the SmartDeviceLink proxy at startup after selecting protocol features. */
+ private void startSmartDeviceLinkProxy() {
+ if (ProxyService.getInstance() == null) {
+ Intent startIntent = new Intent(SmartDeviceLinkTester._activity, ProxyService.class);
+ startService(startIntent);
+ } else {
+ ProxyService.getInstance().setCurrentActivity(SmartDeviceLinkTester._activity);
+ }
+ }
+
+ /**
+ * Initializes/resets the adapters keeping created submenus, interaction
+ * choice set ids, etc.
+ */
+ private void resetAdapters() {
+ List<ButtonName> subscribableButtonNames = Arrays.asList(ButtonName.values()).
+ subList(0, ButtonName.values().length - 1);
+ isButtonSubscribed = new boolean[subscribableButtonNames.size()];
+ _buttonAdapter = new ArrayAdapter<ButtonName>(this,
+ android.R.layout.select_dialog_multichoice, subscribableButtonNames) {
+ public View getView(int position, View convertView, ViewGroup parent) {
+ CheckedTextView ret = (CheckedTextView) super.getView(position,
+ convertView, parent);
+ ret.setChecked(isButtonSubscribed[position]);
+ return ret;
+ }
+ };
+
+ _submenuAdapter = new ArrayAdapter<SmartDeviceLinkSubMenu>(this,
+ android.R.layout.select_dialog_item);
+ _submenuAdapter
+ .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+
+ // Add top level menu with parent ID zero
+ SmartDeviceLinkSubMenu sm = new SmartDeviceLinkSubMenu();
+ sm.setName("Top Level Menu");
+ sm.setSubMenuId(0);
+ addSubMenuToList(sm);
+
+ _commandAdapter = new ArrayAdapter<Integer>(this,
+ android.R.layout.select_dialog_item);
+ _commandAdapter
+ .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+
+ _choiceSetAdapter = new ArrayAdapter<Integer>(this,
+ android.R.layout.select_dialog_item);
+ _choiceSetAdapter
+ .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+ }
+
+ /** Displays the current protocol properties in the activity's title. */
+ private void showPropertiesInTitle() {
+ final SharedPreferences prefs = getSharedPreferences(Const.PREFS_NAME,
+ 0);
+ boolean isMedia = prefs.getBoolean(Const.PREFS_KEY_ISMEDIAAPP,
+ Const.PREFS_DEFAULT_ISMEDIAAPP);
+ String transportType = prefs.getInt(
+ Const.Transport.PREFS_KEY_TRANSPORT_TYPE,
+ Const.Transport.PREFS_DEFAULT_TRANSPORT_TYPE) == Const.Transport.KEY_TCP ? "WiFi"
+ : "BT";
+ setTitle(getResources().getString(R.string.app_name) + " ("
+ + (isMedia ? "" : "non-") + "media, "
+ + transportType + ")");
+ }
+
+ protected void onDestroy() {
+ super.onDestroy();
+ endSmartDeviceLinkProxyInstance();
+ _activity = null;
+ ProxyService service = ProxyService.getInstance();
+ if (service != null) {
+ service.setCurrentActivity(null);
+ }
+ }
+
+ public Dialog onCreateDialog(int id) {
+ Dialog dialog = null;
+ AlertDialog.Builder builder = new AlertDialog.Builder(this);
+ switch (id) {
+ case 1:
+ builder.setTitle("Raw JSON");
+ builder.setMessage("This is the raw JSON message here");
+ builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int id) {
+ dialog.cancel();
+ }
+ });
+ AlertDialog dialog1 = builder.create();
+ dialog = dialog1;
+ break;
+ case 2:
+ break;
+ default:
+ dialog = null;
+ }
+ return dialog;
+ }
+ private final int PROXY_START = 5;
+ private final int XML_TEST = 7;
+ private final int MNU_TOGGLE_CONSOLE = 9;
+ private final int MNU_CLEAR = 10;
+ private final int MNU_EXIT = 11;
+ private final int MNU_TOGGLE_MEDIA = 12;
+ private final int MNU_UNREGISTER = 14;
+
+
+ /* Creates the menu items */
+ public boolean onCreateOptionsMenu(Menu menu) {
+ boolean result = super.onCreateOptionsMenu(menu);
+ if (result) {
+ menu.add(0, PROXY_START, 0, "Proxy Start");
+ menu.add(0, MNU_TOGGLE_CONSOLE, 0, "Toggle Console");
+ menu.add(0, MNU_CLEAR, 0, "Clear Messages");
+ menu.add(0, MNU_EXIT, 0, "Exit");
+ menu.add(0, MNU_UNREGISTER, 0, "Unregister");
+ menu.add(0, XML_TEST, 0, "XML Test");
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ private boolean getIsMedia() {
+ return getSharedPreferences(Const.PREFS_NAME, 0).getBoolean(
+ Const.PREFS_KEY_ISMEDIAAPP, Const.PREFS_DEFAULT_ISMEDIAAPP);
+ }
+
+ /* Handles item selections */
+ public boolean onOptionsItemSelected(MenuItem item) {
+
+ switch (item.getItemId()) {
+ case PROXY_START:
+ BluetoothAdapter mBtAdapter = BluetoothAdapter.getDefaultAdapter();
+ if (!mBtAdapter.isEnabled()) mBtAdapter.enable();
+
+ if (ProxyService.getInstance() == null) {
+ Intent startIntent = new Intent(this, ProxyService.class);
+ startService(startIntent);
+ } else {
+ ProxyService.getInstance().setCurrentActivity(this);
+ }
+
+ if (ProxyService.getInstance().getProxyInstance() != null) {
+ try {
+ ProxyService.getInstance().getProxyInstance().resetProxy();
+ } catch (SmartDeviceLinkException e) {}
+ }
+
+ if (!mBtAdapter.isDiscovering()) {
+ Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
+ discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 300);
+ startActivity(discoverableIntent);
+ }
+ return true;
+
+ case XML_TEST:
+ if (_testerMain != null) {
+ _testerMain.restart();
+ Toast.makeText(getApplicationContext(), "start your engines", Toast.LENGTH_SHORT).show();
+ }else {
+ ProxyService.getInstance().startModuleTest();
+ _testerMain.restart();
+ Toast.makeText(getApplicationContext(), "Start the app on SmartDeviceLink first", Toast.LENGTH_LONG).show();
+ }
+ break;
+ case MNU_EXIT:
+ exitApp();
+ break;
+ case MNU_TOGGLE_CONSOLE:
+ if (_scroller.getVisibility() == ScrollView.VISIBLE) {
+ _scroller.setVisibility(ScrollView.GONE);
+ _listview.setVisibility(ListView.VISIBLE);
+ } else {
+ _scroller.setVisibility(ScrollView.VISIBLE);
+ _listview.setVisibility(ListView.GONE);
+ }
+ return true;
+ case MNU_CLEAR:
+ _msgAdapter.clear();
+ return true;
+ case MNU_TOGGLE_MEDIA:
+ SharedPreferences settings = getSharedPreferences(Const.PREFS_NAME, 0);
+ boolean isMediaApp = settings.getBoolean(Const.PREFS_KEY_ISMEDIAAPP, Const.PREFS_DEFAULT_ISMEDIAAPP);
+ SharedPreferences.Editor editor = settings.edit();
+ editor.putBoolean(Const.PREFS_KEY_ISMEDIAAPP, !isMediaApp);
+ editor.commit();
+ return true;
+ case MNU_UNREGISTER:
+ endSmartDeviceLinkProxyInstance();
+ startSmartDeviceLinkProxy();
+ return true;
+ }
+
+ return false;
+ }
+
+ /** Closes the activity and stops the proxy service. */
+ private void exitApp() {
+ stopService(new Intent(this, ProxyService.class));
+ finish();
+ new Timer().schedule(new TimerTask() {
+ @Override
+ public void run() {
+ android.os.Process.killProcess(android.os.Process.myPid());
+ }
+ }, 1000);
+ }
+
+ public void onClick(View v) {
+ if (v == findViewById(R.id.btnSendMessage)) {
+ final ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.select_dialog_item);
+ adapter.add(Names.Alert);
+ adapter.add(Names.Speak);
+ adapter.add(Names.Show);
+ adapter.add(ButtonSubscriptions);
+ adapter.add(Names.AddCommand);
+ adapter.add(Names.DeleteCommand);
+ adapter.add(Names.AddSubMenu);
+ adapter.add(Names.DeleteSubMenu);
+ adapter.add(Names.SetGlobalProperties);
+ adapter.add(Names.ResetGlobalProperties);
+ adapter.add(Names.SetMediaClockTimer);
+ adapter.add(Names.CreateInteractionChoiceSet);
+ adapter.add(Names.DeleteInteractionChoiceSet);
+ adapter.add(Names.PerformInteraction);
+ adapter.add(Names.EncodedSyncPData);
+
+ new AlertDialog.Builder(this)
+ .setTitle("Pick a Function")
+ .setAdapter(adapter, new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int which) {
+ if(adapter.getItem(which) == Names.Alert){
+ AlertDialog.Builder builder;
+ AlertDialog dlg;
+
+ final Context mContext = adapter.getContext();
+ LayoutInflater inflater = (LayoutInflater) mContext
+ .getSystemService(LAYOUT_INFLATER_SERVICE);
+ View layout = inflater.inflate(R.layout.alert, null);
+ final EditText txtSpeak = (EditText) layout.findViewById(R.id.txtSpeak);
+ final EditText txtAlertField1 = (EditText) layout.findViewById(R.id.txtAlertField1);
+ final EditText txtAlertField2 = (EditText) layout.findViewById(R.id.txtAlertField2);
+ final EditText txtDuration = (EditText) layout.findViewById(R.id.txtDuration);
+ final CheckBox chkPlayTone = (CheckBox) layout.findViewById(R.id.chkPlayTone);
+
+ builder = new AlertDialog.Builder(mContext);
+ builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int id) {
+ String toSpeak = txtSpeak.getText().toString();
+ try {
+ Alert msg = new Alert();
+ msg.setCorrelationID(autoIncCorrId++);
+ msg.setAlertText1(txtAlertField1.getText().toString());
+ msg.setAlertText2(txtAlertField2.getText().toString());
+ msg.setDuration(Integer.parseInt(txtDuration.getText().toString()));
+ msg.setPlayTone(chkPlayTone.isChecked());
+ if (toSpeak.length() > 0) {
+ Vector<TTSChunk> ttsChunks = TTSChunkFactory.createSimpleTTSChunks(toSpeak);
+ msg.setTtsChunks(ttsChunks);
+ }
+ _msgAdapter.logMessage(msg, true);
+ ProxyService.getInstance().getProxyInstance().sendRPCRequest(msg);
+ } catch (SmartDeviceLinkException e) {
+ _msgAdapter.logMessage("Error sending message: " + e, Log.ERROR, e);
+ }
+ }
+ });
+ builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int id) {
+ dialog.cancel();
+ }
+ });
+ builder.setView(layout);
+ dlg = builder.create();
+ dlg.show();
+ } else if (adapter.getItem(which) == Names.Speak) {
+ //something
+ AlertDialog.Builder builder;
+ AlertDialog dlg;
+
+ Context mContext = adapter.getContext();
+ LayoutInflater inflater = (LayoutInflater) mContext
+ .getSystemService(LAYOUT_INFLATER_SERVICE);
+ View layout = inflater.inflate(R.layout.speak, null);
+ final EditText txtSpeakText1 = (EditText) layout.findViewById(R.id.txtSpeakText1);
+ final EditText txtSpeakText2 = (EditText) layout.findViewById(R.id.txtSpeakText2);
+ final EditText txtSpeakText3 = (EditText) layout.findViewById(R.id.txtSpeakText3);
+ final EditText txtSpeakText4 = (EditText) layout.findViewById(R.id.txtSpeakText4);
+
+ final Spinner spnSpeakType1 = (Spinner) layout.findViewById(R.id.spnSpeakType1);
+ final Spinner spnSpeakType2 = (Spinner) layout.findViewById(R.id.spnSpeakType2);
+ final Spinner spnSpeakType3 = (Spinner) layout.findViewById(R.id.spnSpeakType3);
+ final Spinner spnSpeakType4 = (Spinner) layout.findViewById(R.id.spnSpeakType4);
+
+ ArrayAdapter<SpeechCapabilities> speechSpinnerAdapter = new ArrayAdapter<SpeechCapabilities>(adapter.getContext(), android.R.layout.simple_spinner_item, SpeechCapabilities.values());
+ spnSpeakType1.setAdapter(speechSpinnerAdapter);
+ spnSpeakType2.setAdapter(speechSpinnerAdapter);
+ spnSpeakType2.setSelection(3);
+ spnSpeakType3.setAdapter(speechSpinnerAdapter);
+ spnSpeakType4.setAdapter(speechSpinnerAdapter);
+ spnSpeakType4.setSelection(1);
+ spnSpeakType4.setEnabled(false);
+
+ builder = new AlertDialog.Builder(mContext);
+ builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int id) {
+ Speak msg = new Speak();
+ msg.setCorrelationID(autoIncCorrId++);
+ String speak1 = txtSpeakText1.getText().toString();
+ String speak2 = txtSpeakText2.getText().toString();
+ String speak3 = txtSpeakText3.getText().toString();
+ String speak4 = txtSpeakText4.getText().toString();
+ Vector<TTSChunk> chunks = new Vector<TTSChunk>();
+
+ if (speak1.length() > 0) {
+ chunks.add(TTSChunkFactory.createChunk((SpeechCapabilities)spnSpeakType1.getSelectedItem(), speak1));
+
+ }
+ if (speak2.length() > 0) {
+ chunks.add(TTSChunkFactory.createChunk((SpeechCapabilities)spnSpeakType2.getSelectedItem(), speak2));
+
+ }
+ if (speak3.length() > 0) {
+ chunks.add(TTSChunkFactory.createChunk((SpeechCapabilities)spnSpeakType3.getSelectedItem(), speak3));
+
+ }
+ if (speak4.length() > 0) {
+ chunks.add(TTSChunkFactory.createChunk(SpeechCapabilities.SAPI_PHONEMES, speak4));
+
+ }
+ msg.setTtsChunks(chunks);
+ try {
+ _msgAdapter.logMessage(msg, true);
+ ProxyService.getInstance().getProxyInstance().sendRPCRequest(msg);
+ } catch (SmartDeviceLinkException e) {
+ _msgAdapter.logMessage("Error sending message: " + e, Log.ERROR, e);
+ }
+ }
+ });
+ builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int id) {
+ dialog.cancel();
+ }
+ });
+ builder.setView(layout);
+ dlg = builder.create();
+ dlg.show();
+ } else if (adapter.getItem(which) == Names.Show) {
+ //something
+ AlertDialog.Builder builder;
+ AlertDialog dlg;
+
+ final Context mContext = adapter.getContext();
+ LayoutInflater inflater = (LayoutInflater) mContext
+ .getSystemService(LAYOUT_INFLATER_SERVICE);
+ View layout = inflater.inflate(R.layout.show, null);
+ final EditText txtShowField1 = (EditText) layout.findViewById(R.id.txtShowField1);
+ final EditText txtShowField2 = (EditText) layout.findViewById(R.id.txtShowField2);
+ final EditText statusBar = (EditText) layout.findViewById(R.id.txtStatusBar);
+ final EditText mediaClock = (EditText) layout.findViewById(R.id.txtMediaClock);
+ final EditText mediaTrack = (EditText) layout.findViewById(R.id.txtMediaTrack);
+
+ if (!getIsMedia()) {
+ int visibility = android.view.View.GONE;
+ mediaClock.setVisibility(visibility);
+ mediaTrack.setVisibility(visibility);
+ layout.findViewById(R.id.lblMediaTrack).setVisibility(visibility);
+ layout.findViewById(R.id.lblMediaClock).setVisibility(visibility);
+ }
+
+ builder = new AlertDialog.Builder(mContext);
+ builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int id) {
+ try {
+ Show msg = new Show();
+ msg.setCorrelationID(autoIncCorrId++);
+ msg.setMainField1(txtShowField1.getText().toString());
+ msg.setMainField2(txtShowField2.getText().toString());
+ msg.setStatusBar(statusBar.getText().toString());
+ if (getIsMedia()) {
+ msg.setMediaClock(mediaClock.getText().toString());
+ msg.setMediaTrack(mediaTrack.getText().toString());
+ }
+ _msgAdapter.logMessage(msg, true);
+ ProxyService.getInstance().getProxyInstance().sendRPCRequest(msg);
+ } catch (SmartDeviceLinkException e) {
+ _msgAdapter.logMessage("Error sending message: " + e, Log.ERROR, e);
+ }
+ }
+ });
+ builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int id) {
+ dialog.cancel();
+ }
+ });
+ builder.setView(layout);
+ dlg = builder.create();
+ dlg.show();
+ } else if (adapter.getItem(which) == ButtonSubscriptions) {
+ //something
+ AlertDialog.Builder builder = new AlertDialog.Builder(adapter.getContext());
+ builder.setAdapter(_buttonAdapter, new DialogInterface.OnClickListener() {
+
+ public void onClick(DialogInterface dialog, int which) {
+ boolean needToSubscribe = !isButtonSubscribed[which];
+ try {
+ ButtonName buttonName = ButtonName.values()[which];
+ int corrId = autoIncCorrId++;
+ if (needToSubscribe) {
+ SubscribeButton msg = new SubscribeButton();
+ msg.setCorrelationID(corrId);
+ msg.setButtonName(buttonName);
+ _msgAdapter.logMessage(msg, true);
+ ProxyService.getInstance().getProxyInstance().sendRPCRequest(msg);
+ } else {
+ UnsubscribeButton msg = new UnsubscribeButton();
+ msg.setCorrelationID(corrId);
+ msg.setButtonName(buttonName);
+ _msgAdapter.logMessage(msg, true);
+ ProxyService.getInstance().getProxyInstance().sendRPCRequest(msg);
+ }
+ } catch (SmartDeviceLinkException e) {
+ _msgAdapter.logMessage("Error sending message: " + e, Log.ERROR, e);
+ }
+ isButtonSubscribed[which] = !isButtonSubscribed[which];
+ }
+ });
+ AlertDialog dlg = builder.create();
+ dlg.show();
+ } else if (adapter.getItem(which) == Names.AddCommand) {
+ //something
+ AlertDialog.Builder builder;
+ AlertDialog addCommandDialog;
+
+ Context mContext = adapter.getContext();
+ LayoutInflater inflater = (LayoutInflater) mContext
+ .getSystemService(LAYOUT_INFLATER_SERVICE);
+ View layout = inflater.inflate(R.layout.addcommand,
+ (ViewGroup) findViewById(R.id.itemRoot));
+
+ final EditText er = (EditText) layout.findViewById(R.id.command);
+ final EditText editVrSynonym = (EditText) layout.findViewById(R.id.command2);
+ final Spinner s = (Spinner) layout.findViewById(R.id.availableSubmenus);
+ s.setAdapter(_submenuAdapter);
+
+ builder = new AlertDialog.Builder(mContext);
+ builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int id) {
+ AddCommand msg = new AddCommand();
+ msg.setCorrelationID(autoIncCorrId++);
+ String itemText = er.getText().toString();
+ SmartDeviceLinkSubMenu sm = new SmartDeviceLinkSubMenu();
+ sm = (SmartDeviceLinkSubMenu) s.getSelectedItem();
+ MenuParams menuParams = new MenuParams();
+ menuParams.setMenuName(itemText);
+ menuParams.setPosition(0);
+ menuParams.setParentID(sm.getSubMenuId());
+ msg.setMenuParams(menuParams);
+
+ String vrSynonym = editVrSynonym.getText().toString();
+ if (vrSynonym.length() > 0) {
+ Vector<String> vrCommands = new Vector<String>();
+ vrCommands.add(vrSynonym);
+ msg.setVrCommands(vrCommands);
+ }
+
+ int cmdID = itemcmdID++;
+ msg.setCmdID(cmdID);
+
+ try {
+ _msgAdapter.logMessage(msg, true);
+ ProxyService.getInstance().getProxyInstance().sendRPCRequest(msg);
+ } catch (SmartDeviceLinkException e) {
+ _msgAdapter.logMessage("Error sending message: " + e, Log.ERROR, e);
+ }
+ _commandAdapter.add(cmdID);
+ }
+ });
+ builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int id) {
+ dialog.cancel();
+ }
+ });
+ builder.setView(layout);
+ addCommandDialog = builder.create();
+ addCommandDialog.show();
+ } else if (adapter.getItem(which) == Names.DeleteCommand) {
+ //something
+ AlertDialog.Builder builder = new AlertDialog.Builder(adapter.getContext());
+ builder.setAdapter(_commandAdapter, new DialogInterface.OnClickListener() {
+
+ public void onClick(DialogInterface dialog, int which) {
+ DeleteCommand msg = new DeleteCommand();
+ msg.setCorrelationID(autoIncCorrId++);
+ int cmdID = _commandAdapter.getItem(which);
+ msg.setCmdID(cmdID);
+ try {
+ _msgAdapter.logMessage(msg, true);
+ ProxyService.getInstance().getProxyInstance().sendRPCRequest(msg);
+ } catch (SmartDeviceLinkException e) {
+ _msgAdapter.logMessage("Error sending message: " + e, Log.ERROR, e);
+ }
+ _commandAdapter.remove(cmdID);
+ }
+ });
+ AlertDialog dlg = builder.create();
+ dlg.show();
+ } else if (adapter.getItem(which) == Names.AddSubMenu) {
+ //something
+ AlertDialog.Builder builder;
+ AlertDialog addSubMenuDialog;
+
+ Context mContext = adapter.getContext();
+ LayoutInflater inflater = (LayoutInflater) mContext
+ .getSystemService(LAYOUT_INFLATER_SERVICE);
+ View layout = inflater.inflate(R.layout.addsubmenu,
+ (ViewGroup) findViewById(R.id.submenu_Root));
+
+ final EditText subMenu = (EditText) layout.findViewById(R.id.submenu_item);
+
+ builder = new AlertDialog.Builder(mContext);
+ builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int id) {
+ AddSubMenu msg = new AddSubMenu();
+ msg.setCorrelationID(autoIncCorrId++);
+ SmartDeviceLinkSubMenu sm = new SmartDeviceLinkSubMenu();
+ sm.setName(subMenu.getText().toString());
+ sm.setSubMenuId(submenucmdID++);
+ addSubMenuToList(sm);
+ msg.setMenuID(sm.getSubMenuId());
+ msg.setMenuName(sm.getName());
+ msg.setPosition(null);
+ try {
+ _msgAdapter.logMessage(msg, true);
+ ProxyService.getInstance().getProxyInstance().sendRPCRequest(msg);
+ } catch (SmartDeviceLinkException e) {
+ _msgAdapter.logMessage("Error sending message: " + e, Log.ERROR, e);
+ }
+ }
+ });
+ builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int id) {
+ dialog.cancel();
+ }
+ });
+ builder.setView(layout);
+ addSubMenuDialog = builder.create();
+ addSubMenuDialog.show();
+ } else if (adapter.getItem(which) == Names.DeleteSubMenu) {
+ //something
+ AlertDialog.Builder builder = new AlertDialog.Builder(adapter.getContext());
+ builder.setAdapter(_submenuAdapter, new DialogInterface.OnClickListener() {
+
+ public void onClick(DialogInterface dialog, int which) {
+ SmartDeviceLinkSubMenu menu = _submenuAdapter.getItem(which);
+ if (menu.getSubMenuId() != 0) {
+ DeleteSubMenu msg = new DeleteSubMenu();
+ msg.setCorrelationID(autoIncCorrId++);
+ msg.setMenuID(menu.getSubMenuId());
+ try {
+ _msgAdapter.logMessage(msg, true);
+ ProxyService.getInstance().getProxyInstance().sendRPCRequest(msg);
+ } catch (SmartDeviceLinkException e) {
+ _msgAdapter.logMessage("Error sending message: " + e, Log.ERROR, e);
+ }
+
+ _submenuAdapter.remove(menu);
+ } else {
+ Toast.makeText(getApplicationContext(),
+ "Sorry, can't delete top-level menu",
+ Toast.LENGTH_LONG).show();
+ }
+ }
+ });
+ AlertDialog dlg = builder.create();
+ dlg.show();
+ } else if (adapter.getItem(which) == Names.SetGlobalProperties) {
+ sendSetGlobalProperties();
+ } else if (adapter.getItem(which) == Names.ResetGlobalProperties) {
+ sendResetGlobalProperties();
+ } else if (adapter.getItem(which) == Names.SetMediaClockTimer) {
+ //something
+ AlertDialog.Builder builder;
+ AlertDialog dlg;
+
+ Context mContext = adapter.getContext();
+ LayoutInflater inflater = (LayoutInflater) mContext
+ .getSystemService(LAYOUT_INFLATER_SERVICE);
+ View layout = inflater.inflate(R.layout.setmediaclock, null);
+ final EditText txtHours = (EditText) layout.findViewById(R.id.txtHours);
+ final EditText txtMinutes = (EditText) layout.findViewById(R.id.txtMinutes);
+ final EditText txtSeconds = (EditText) layout.findViewById(R.id.txtSeconds);
+ final Spinner spnUpdateMode = (Spinner) layout.findViewById(R.id.spnUpdateMode);
+ ArrayAdapter<UpdateMode> spinnerAdapter = new ArrayAdapter<UpdateMode>(adapter.getContext(),
+ android.R.layout.simple_spinner_item, UpdateMode.values());
+ spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+ spnUpdateMode.setAdapter(spinnerAdapter);
+ builder = new AlertDialog.Builder(mContext);
+ builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int id) {
+ SetMediaClockTimer msg = new SetMediaClockTimer();
+ msg.setCorrelationID(autoIncCorrId++);
+ UpdateMode updateMode = (UpdateMode)spnUpdateMode.getSelectedItem();
+ msg.setUpdateMode(updateMode);
+ try {
+ Integer hours = Integer.parseInt(txtHours.getText().toString());
+ Integer minutes = Integer.parseInt(txtMinutes.getText().toString());
+ Integer seconds = Integer.parseInt(txtSeconds.getText().toString());
+ StartTime startTime = new StartTime();
+ startTime.setHours(hours);
+ startTime.setMinutes(minutes);
+ startTime.setSeconds(seconds);
+ msg.setStartTime(startTime);
+ } catch (NumberFormatException e) {
+ // skip setting start time if parsing failed
+ }
+
+ try {
+ _msgAdapter.logMessage(msg, true);
+ ProxyService.getInstance().getProxyInstance().sendRPCRequest(msg);
+ } catch (SmartDeviceLinkException e) {
+ _msgAdapter.logMessage("Error sending message: " + e, Log.ERROR, e);
+ }
+ }
+ });
+ builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int id) {
+ dialog.cancel();
+ }
+ });
+ builder.setView(layout);
+ dlg = builder.create();
+ dlg.show();
+ } else if (adapter.getItem(which) == Names.CreateInteractionChoiceSet) {
+ //something
+ AlertDialog.Builder builder;
+ AlertDialog createCommandSet;
+
+ Context mContext = adapter.getContext();
+ LayoutInflater inflater = (LayoutInflater) mContext
+ .getSystemService(LAYOUT_INFLATER_SERVICE);
+ View layout = inflater.inflate(R.layout.createinteractionchoices,
+ (ViewGroup) findViewById(R.id.createcommands_Root));
+
+ final EditText command1 = (EditText) layout.findViewById(R.id.createcommands_command1);
+ final EditText command2 = (EditText) layout.findViewById(R.id.createcommands_command2);
+ final EditText command3 = (EditText) layout.findViewById(R.id.createcommands_command3);
+ final EditText vr1 = (EditText) layout.findViewById(R.id.createcommands_vr1);
+ final EditText vr2 = (EditText) layout.findViewById(R.id.createcommands_vr2);
+ final EditText vr3 = (EditText) layout.findViewById(R.id.createcommands_vr3);
+ final CheckBox choice1 = (CheckBox) layout.findViewById(R.id.createcommands_choice1);
+ final CheckBox choice2 = (CheckBox) layout.findViewById(R.id.createcommands_choice2);
+ final CheckBox choice3 = (CheckBox) layout.findViewById(R.id.createcommands_choice3);
+
+ builder = new AlertDialog.Builder(mContext);
+ builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int id) {
+ Vector<Choice> commands = new Vector<Choice>();
+
+ if (choice1.isChecked()) {
+ Choice one = new Choice();
+ one.setChoiceID(autoIncChoiceSetIdCmdId++);
+ one.setMenuName(command1.getText().toString());
+ one.setVrCommands(new Vector<String>(Arrays.asList(new String[] { command1.getText().toString(),
+ vr1.getText().toString() })));
+ commands.add(one);
+ }
+
+ if (choice2.isChecked()) {
+ Choice two = new Choice();
+ two.setChoiceID(autoIncChoiceSetIdCmdId++);
+ two.setMenuName(command2.getText().toString());
+ two.setVrCommands(new Vector<String>(Arrays.asList(new String[] { command2.getText().toString(),
+ vr2.getText().toString() })));
+ commands.add(two);
+ }
+
+ if (choice3.isChecked()) {
+ Choice three = new Choice();
+ three.setChoiceID(autoIncChoiceSetIdCmdId++);
+ three.setMenuName(command3.getText().toString());
+ three.setVrCommands(new Vector<String>(Arrays.asList(new String[] { command3.getText().toString(),
+ vr3.getText().toString() })));
+ commands.add(three);
+ }
+
+ if (!commands.isEmpty()) {
+ CreateInteractionChoiceSet msg = new CreateInteractionChoiceSet();
+ msg.setCorrelationID(autoIncCorrId++);
+ int choiceSetID = autoIncChoiceSetId++;
+ msg.setInteractionChoiceSetID(choiceSetID);
+ msg.setChoiceSet(commands);
+ try {
+ _msgAdapter.logMessage(msg, true);
+ ProxyService.getInstance().getProxyInstance().sendRPCRequest(msg);
+ if (_latestChoiceSetId != CHOICESETID_UNSET) {
+ Log.w(logTag, "Latest choiceSetId should be unset, but equals to " + _latestChoiceSetId);
+ }
+ _latestChoiceSetId = choiceSetID;
+ } catch (SmartDeviceLinkException e) {
+ _msgAdapter.logMessage("Error sending message: " + e, Log.ERROR, e);
+ }
+ } else {
+ Toast.makeText(getApplicationContext(), "No commands to set", Toast.LENGTH_SHORT).show();
+ }
+ }
+ });
+ builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int id) {
+ dialog.cancel();
+ }
+ });
+ builder.setView(layout);
+ createCommandSet = builder.create();
+ createCommandSet.show();
+ } else if (adapter.getItem(which) == Names.DeleteInteractionChoiceSet) {
+ //something
+ AlertDialog.Builder builder = new AlertDialog.Builder(adapter.getContext());
+ builder.setAdapter(_choiceSetAdapter, new DialogInterface.OnClickListener() {
+
+ public void onClick(DialogInterface dialog, int which) {
+ DeleteInteractionChoiceSet msg = new DeleteInteractionChoiceSet();
+ msg.setCorrelationID(autoIncCorrId++);
+ int commandSetID = _choiceSetAdapter.getItem(which);
+ msg.setInteractionChoiceSetID(commandSetID);
+ try {
+ _msgAdapter.logMessage(msg, true);
+ ProxyService.getInstance().getProxyInstance().sendRPCRequest(msg);
+ } catch (SmartDeviceLinkException e) {
+ _msgAdapter.logMessage("Error sending message: " + e, Log.ERROR, e);
+ }
+
+ _choiceSetAdapter.remove(commandSetID);
+ }
+ });
+ AlertDialog dlg = builder.create();
+ dlg.show();
+ } else if (adapter.getItem(which) == Names.PerformInteraction) {
+ //something
+ AlertDialog.Builder builder = new AlertDialog.Builder(adapter.getContext());
+ builder.setAdapter(_choiceSetAdapter, new DialogInterface.OnClickListener() {
+
+ public void onClick(DialogInterface dialog, int which) {
+ PerformInteraction msg = new PerformInteraction();
+ msg.setCorrelationID(autoIncCorrId++);
+ Vector<Integer> interactionChoiceSetIDs = new Vector<Integer>();
+ interactionChoiceSetIDs.add(_choiceSetAdapter.getItem(which));
+ Vector<TTSChunk> initChunks = TTSChunkFactory
+ .createSimpleTTSChunks("Pick a command");
+ Vector<TTSChunk> helpChunks = TTSChunkFactory
+ .createSimpleTTSChunks("help me, I'm melting");
+ Vector<TTSChunk> timeoutChunks = TTSChunkFactory
+ .createSimpleTTSChunks("hurry it up");
+ msg.setInitialPrompt(initChunks);
+ msg.setInitialText("Pick number:");
+ msg.setInteractionChoiceSetIDList(interactionChoiceSetIDs);
+ msg.setInteractionMode(InteractionMode.BOTH);
+ msg.setTimeout(10000);
+ msg.setHelpPrompt(helpChunks);
+ msg.setTimeoutPrompt(timeoutChunks);
+ try {
+ _msgAdapter.logMessage(msg, true);
+ ProxyService.getInstance().getProxyInstance().sendRPCRequest(msg);
+ } catch (SmartDeviceLinkException e) {
+ _msgAdapter.logMessage("Error sending message: " + e, Log.ERROR, e);
+ }
+ }
+ });
+ AlertDialog dlg = builder.create();
+ dlg.show();
+ } else if (adapter.getItem(which) == Names.EncodedSyncPData) {
+ //EncodedSyncPData
+ EncodedSyncPData msg = new EncodedSyncPData();
+ Vector<String> SmartDeviceLinkPData = new Vector<String>();
+ SmartDeviceLinkPData.add("AAM4AAkAAAAAAAAAAAA=");
+ msg.setData(SmartDeviceLinkPData);
+ msg.setCorrelationID(autoIncCorrId++);
+
+ _msgAdapter.logMessage(msg, true);
+
+ try {
+ ProxyService.getInstance().getProxyInstance().sendRPCRequest(msg);
+ } catch (SmartDeviceLinkException e) {
+ _msgAdapter.logMessage("Error sending message: " + e, Log.ERROR, e);
+ }
+ }
+ }
+
+ private void sendSetGlobalProperties() {
+ AlertDialog.Builder builder;
+
+ Context mContext = adapter.getContext();
+ LayoutInflater inflater = (LayoutInflater) mContext
+ .getSystemService(LAYOUT_INFLATER_SERVICE);
+ View layout = inflater.inflate(R.layout.setglobalproperties,
+ (ViewGroup) findViewById(R.id.setglobalproperties_Root));
+
+ final EditText helpPrompt = (EditText) layout.findViewById(R.id.setglobalproperties_helpPrompt);
+ final EditText timeoutPrompt = (EditText) layout.findViewById(R.id.setglobalproperties_timeoutPrompt);
+ final CheckBox choiceHelpPrompt = (CheckBox) layout.findViewById(R.id.setglobalproperties_choiceHelpPrompt);
+ final CheckBox choiceTimeoutPrompt = (CheckBox) layout.findViewById(R.id.setglobalproperties_choiceTimeoutPrompt);
+
+ builder = new AlertDialog.Builder(mContext);
+ builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int id) {
+ SetGlobalProperties msg = new SetGlobalProperties();
+ int numberOfChoices = 0;
+
+ if (choiceHelpPrompt.isChecked()) {
+ Vector<TTSChunk> help = new Vector<TTSChunk>();
+ help.add(TTSChunkFactory.createChunk(SpeechCapabilities.TEXT, helpPrompt.getText().toString()));
+ msg.setHelpPrompt(help);
+ ++numberOfChoices;
+ }
+
+ if (choiceTimeoutPrompt.isChecked()) {
+ Vector<TTSChunk> timeout = new Vector<TTSChunk>();
+ timeout.add(TTSChunkFactory.createChunk(SpeechCapabilities.TEXT, timeoutPrompt.getText().toString()));
+ msg.setTimeoutPrompt(timeout);
+ ++numberOfChoices;
+ }
+
+ if (numberOfChoices > 0) {
+ msg.setCorrelationID(autoIncCorrId++);
+ _msgAdapter.logMessage(msg, true);
+ try {
+ ProxyService.getInstance().getProxyInstance().sendRPCRequest(msg);
+ } catch (SmartDeviceLinkException e) {
+ _msgAdapter.logMessage("Error sending message: " + e, Log.ERROR, e);
+ }
+ } else {
+ Toast.makeText(getApplicationContext(), "No items selected", Toast.LENGTH_LONG).show();
+ }
+ }
+ });
+ builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int id) {
+ dialog.cancel();
+ }
+ });
+ builder.setView(layout);
+ builder.create().show();
+ }
+
+ private void sendResetGlobalProperties() {
+ AlertDialog.Builder builder;
+
+ Context mContext = adapter.getContext();
+ LayoutInflater inflater = (LayoutInflater) mContext
+ .getSystemService(LAYOUT_INFLATER_SERVICE);
+ View layout = inflater.inflate(R.layout.resetglobalproperties,
+ (ViewGroup) findViewById(R.id.resetglobalproperties_Root));
+
+ final CheckBox choiceHelpPrompt = (CheckBox) layout.findViewById(R.id.resetglobalproperties_choiceHelpPrompt);
+ final CheckBox choiceTimeoutPrompt = (CheckBox) layout.findViewById(R.id.resetglobalproperties_choiceTimeoutPrompt);
+
+ builder = new AlertDialog.Builder(mContext);
+ builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int id) {
+ ResetGlobalProperties msg = new ResetGlobalProperties();
+ Vector<GlobalProperty> properties = new Vector<GlobalProperty>();
+
+ if (choiceHelpPrompt.isChecked()) {
+ properties.add(GlobalProperty.HELPPROMPT);
+ }
+
+ if (choiceTimeoutPrompt.isChecked()) {
+ properties.add(GlobalProperty.TIMEOUTPROMPT);
+ }
+
+ if (!properties.isEmpty()) {
+ msg.setProperties(properties);
+ msg.setCorrelationID(autoIncCorrId++);
+ _msgAdapter.logMessage(msg, true);
+ try {
+ ProxyService.getInstance().getProxyInstance().sendRPCRequest(msg);
+ } catch (SmartDeviceLinkException e) {
+ _msgAdapter.logMessage("Error sending message: " + e, Log.ERROR, e);
+ }
+ } else {
+ Toast.makeText(getApplicationContext(), "No items selected", Toast.LENGTH_LONG).show();
+ }
+ }
+ });
+ builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int id) {
+ dialog.cancel();
+ }
+ });
+ builder.setView(layout);
+ builder.create().show();
+ }
+ })
+ .setNegativeButton("Close", null)
+ .show();
+ } else if (v == findViewById(R.id.btnPlayPause)) {
+ ProxyService.getInstance().playPauseAnnoyingRepetitiveAudio();
+ }
+ }
+
+ public void addSubMenuToList(final SmartDeviceLinkSubMenu sm) {
+ runOnUiThread(new Runnable() {
+ public void run() {
+ _submenuAdapter.add(sm);
+ }
+ });
+ }
+
+ //upon onDestroy(), dispose current proxy and create a new one to enable auto-start
+ //call resetProxy() to do so
+ public void endSmartDeviceLinkProxyInstance() {
+ ProxyService serviceInstance = ProxyService.getInstance();
+ if (serviceInstance != null){
+ SmartDeviceLinkProxyALM proxyInstance = serviceInstance.getProxyInstance();
+ //if proxy exists, reset it
+ if(proxyInstance != null){
+ if (proxyInstance.getCurrentTransportType() == TransportType.BLUETOOTH) {
+ serviceInstance.reset();
+ } else {
+ Log.e(logTag, "endSmartDeviceLinkProxyInstance. No reset required if transport is TCP");
+ }
+ //if proxy == null create proxy
+ } else {
+ serviceInstance.startProxy();
+ }
+ }
+ }
+
+ public static SmartDeviceLinkTester getInstance() {
+ return _activity;
+ }
+
+ public static logAdapter getMessageAdapter() {
+ return _msgAdapter;
+ }
+
+ public void setTesterMain(ModuleTest _instance) {
+ this._testerMain = _instance;
+ }
+
+ @Override
+ public void onBackPressed() {
+ moveTaskToBack(true);
+ }
+
+ @Override
+ public void onPause() {
+ super.onPause();
+ }
+
+ /**
+ * Called when a CreateChoiceSetResponse comes. If successful, add it to the
+ * adapter. In any case, remove the key from the map.
+ */
+ public void onCreateChoiceSetResponse(boolean success) {
+ if (_latestChoiceSetId != CHOICESETID_UNSET) {
+ if (success) {
+ _choiceSetAdapter.add(_latestChoiceSetId);
+ }
+ _latestChoiceSetId = CHOICESETID_UNSET;
+ } else {
+ Log.w(logTag, "Latest choiceSetId is unset");
+ }
+ }
+
+ /** Called when a connection to a SmartDeviceLink device has been closed. */
+ public void onProxyClosed() {
+ resetAdapters();
+ _msgAdapter.logMessage("Disconnected", true);
+ }
+
+ /**
+ * Called when the app is acivated from HMI for the first time. ProxyService
+ * automatically subscribes to buttons, so we reflect that in the
+ * subscription list.
+ */
+ public void buttonsSubscribed(Vector<ButtonName> buttons) {
+ List<ButtonName> buttonNames = Arrays.asList(ButtonName.values());
+ for (ButtonName buttonName : buttons) {
+ isButtonSubscribed[buttonNames.indexOf(buttonName)] = true;
+ }
+ }
+}
+
diff --git a/SDL_Android/SmartDeviceLinkTester/src/com/smartdevicelink/android/adapters/MessageAdapter.java b/SDL_Android/SmartDeviceLinkTester/src/com/smartdevicelink/android/adapters/MessageAdapter.java
new file mode 100644
index 000000000..56f41cc40
--- /dev/null
+++ b/SDL_Android/SmartDeviceLinkTester/src/com/smartdevicelink/android/adapters/MessageAdapter.java
@@ -0,0 +1,96 @@
+//
+// Copyright (c) 2013 Ford Motor Company
+//
+package com.smartdevicelink.android.adapters;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+
+import android.content.Context;
+import android.graphics.Color;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ArrayAdapter;
+import android.widget.TextView;
+
+import com.smartdevicelink.android.R;
+import com.smartdevicelink.proxy.RPCMessage;
+import com.smartdevicelink.proxy.constants.Names;
+import com.smartdevicelink.proxy.rpc.enums.Result;
+
+public class MessageAdapter extends ArrayAdapter<Object> {
+ private LayoutInflater vi;
+
+ public MessageAdapter(Context context, int textViewResourceId, ArrayList<Object> items) {
+ super(context, textViewResourceId, items);
+ this.vi = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+ }
+
+ /** Adds the specified message to the items list and notifies of the change. */
+ public void addMessage(Object m) {
+ add(m);
+ }
+
+ public View getView(int position, View convertView, ViewGroup parent) {
+ ViewGroup rowView = (ViewGroup)convertView;
+ Object rpcObj = getItem(position);
+ rowView = (ViewGroup)vi.inflate(R.layout.row, null);
+ if (rpcObj != null) {
+ TextView lblTop = (TextView) rowView.findViewById(R.id.toptext);
+ TextView lblBottom = (TextView) rowView.findViewById(R.id.bottomtext);
+
+ if (rpcObj instanceof String) {
+ lblTop.setText((String)rpcObj);
+ }
+ else if (rpcObj instanceof RPCMessage) {
+ RPCMessage func = (RPCMessage)rpcObj;
+ if (func.getMessageType().equals(Names.request)) {
+ lblTop.setTextColor(Color.CYAN);
+ } else if (func.getMessageType().equals(Names.notification)) {
+ lblTop.setTextColor(Color.YELLOW);
+ } else if (func.getMessageType().equals(Names.response)) {
+ lblTop.setTextColor(Color.argb(255, 32, 161, 32));
+ }
+
+ lblTop.setText(func.getFunctionName() + " (" + func.getMessageType() + ")");
+
+ try {
+ Method getSuccessMethod = rpcObj.getClass().getDeclaredMethod("getSuccess");
+ boolean isSuccess = (Boolean)getSuccessMethod.invoke(func);
+ if (isSuccess) {
+ lblTop.setTextColor(Color.GREEN);
+ }
+ else {
+ lblTop.setTextColor(Color.RED);
+ }
+ Method getInfoMethod = rpcObj.getClass().getDeclaredMethod("getInfo");
+ Method getResultCodeMethod = rpcObj.getClass().getDeclaredMethod("getResultCode");
+
+ String info = (String)getInfoMethod.invoke(rpcObj);
+ Result result = (Result)getResultCodeMethod.invoke(rpcObj);
+
+ lblBottom.setText(result + ": " + info);
+
+ } catch (NoSuchMethodException e) {
+ rowView.removeView(lblBottom);
+ } catch (SecurityException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IllegalArgumentException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IllegalAccessException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (InvocationTargetException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
+
+ return rowView;
+ }
+}
diff --git a/SDL_Android/SmartDeviceLinkTester/src/com/smartdevicelink/android/adapters/logAdapter.java b/SDL_Android/SmartDeviceLinkTester/src/com/smartdevicelink/android/adapters/logAdapter.java
new file mode 100644
index 000000000..bcae7517e
--- /dev/null
+++ b/SDL_Android/SmartDeviceLinkTester/src/com/smartdevicelink/android/adapters/logAdapter.java
@@ -0,0 +1,125 @@
+//
+// Copyright (c) 2013 Ford Motor Company
+//
+package com.smartdevicelink.android.adapters;
+
+import java.util.ArrayList;
+
+import android.app.Activity;
+import android.util.Log;
+
+public class logAdapter extends MessageAdapter {
+ private String logTag;
+ boolean fullUIDebug;
+ Activity activity;
+
+ public logAdapter(String logTag, boolean fullUIDebug, Activity activity, int textViewResourceId, ArrayList<Object> items) {
+ super(activity, textViewResourceId, items);
+ this.activity = activity;
+ this.logTag = logTag;
+ this.fullUIDebug = fullUIDebug;
+ }
+
+ private void addMessageToUI(final Object m) {
+ activity.runOnUiThread(new Runnable() {
+ public void run() { addMessage(m); }
+ });
+ }
+
+ public void logMessage (final Object m) {
+ Log.i(logTag, m.toString());
+ if(fullUIDebug) addMessageToUI(m);
+ }
+ public void logMessage (final Object m, Boolean addToUI) {
+ Log.i(logTag, m.toString());
+ addMessageToUI(m);
+ }
+ public void logMessage (final Object m, Integer type) {
+ if (m instanceof String) {
+ switch(type) {
+ case Log.DEBUG:
+ Log.d(logTag, m.toString());
+ break;
+ case Log.ERROR:
+ Log.e(logTag, m.toString());
+ break;
+ case Log.VERBOSE:
+ Log.v(logTag, m.toString());
+ break;
+ case Log.WARN:
+ Log.w(logTag, m.toString());
+ break;
+ default:
+ Log.i(logTag, m.toString());
+ break;
+ }
+ }
+ if (fullUIDebug) addMessageToUI(m);
+ }
+ public void logMessage (final Object m, Integer type, Boolean addToUI) {
+ if (m instanceof String) {
+ switch(type) {
+ case Log.DEBUG:
+ Log.d(logTag, m.toString());
+ break;
+ case Log.ERROR:
+ Log.e(logTag, m.toString());
+ break;
+ case Log.VERBOSE:
+ Log.v(logTag, m.toString());
+ break;
+ case Log.WARN:
+ Log.w(logTag, m.toString());
+ break;
+ default:
+ Log.i(logTag, m.toString());
+ break;
+ }
+ }
+ if (addToUI) addMessageToUI(m);
+ }
+ public void logMessage (final Object m, Integer type, Throwable tr) {
+ if (m instanceof String) {
+ switch(type) {
+ case Log.DEBUG:
+ Log.d(logTag, m.toString());
+ break;
+ case Log.ERROR:
+ Log.e(logTag, m.toString(), tr);
+ break;
+ case Log.VERBOSE:
+ Log.v(logTag, m.toString());
+ break;
+ case Log.WARN:
+ Log.w(logTag, m.toString());
+ break;
+ default:
+ Log.i(logTag, m.toString());
+ break;
+ }
+ }
+ if (fullUIDebug) addMessageToUI(m);
+ }
+ public void logMessage (final Object m, Integer type, Throwable tr, Boolean addToUI) {
+ if (m instanceof String) {
+ switch(type) {
+ case Log.DEBUG:
+ Log.d(logTag, m.toString());
+ break;
+ case Log.ERROR:
+ Log.e(logTag, m.toString(), tr);
+ break;
+ case Log.VERBOSE:
+ Log.v(logTag, m.toString());
+ break;
+ case Log.WARN:
+ Log.w(logTag, m.toString());
+ break;
+ default:
+ Log.i(logTag, m.toString());
+ break;
+ }
+ }
+ if (addToUI) addMessageToUI(m);
+ }
+}
diff --git a/SDL_Android/SmartDeviceLinkTester/src/com/smartdevicelink/android/constants/AcceptedRPC.java b/SDL_Android/SmartDeviceLinkTester/src/com/smartdevicelink/android/constants/AcceptedRPC.java
new file mode 100644
index 000000000..c73c97d5d
--- /dev/null
+++ b/SDL_Android/SmartDeviceLinkTester/src/com/smartdevicelink/android/constants/AcceptedRPC.java
@@ -0,0 +1,49 @@
+//
+// Copyright (c) 2013 Ford Motor Company
+//
+package com.smartdevicelink.android.constants;
+
+import java.util.ArrayList;
+
+import com.smartdevicelink.proxy.constants.Names;
+
+public class AcceptedRPC {
+ ArrayList<String> acceptedRPC = new ArrayList<String>();
+
+ public AcceptedRPC() {
+ acceptedRPC.add(Names.RegisterAppInterface);
+ acceptedRPC.add(Names.UnregisterAppInterface);
+ acceptedRPC.add(Names.SetGlobalProperties);
+ acceptedRPC.add(Names.ResetGlobalProperties);
+ acceptedRPC.add(Names.AddCommand);
+ acceptedRPC.add(Names.DeleteCommand);
+ acceptedRPC.add(Names.AddSubMenu);
+ acceptedRPC.add(Names.DeleteSubMenu);
+ acceptedRPC.add(Names.CreateInteractionChoiceSet);
+ acceptedRPC.add(Names.PerformInteraction);
+ acceptedRPC.add(Names.DeleteInteractionChoiceSet);
+ acceptedRPC.add(Names.Alert);
+ acceptedRPC.add(Names.Show);
+ acceptedRPC.add(Names.Speak);
+ acceptedRPC.add(Names.SetMediaClockTimer);
+ acceptedRPC.add(Names.EncodedSyncPData);
+ acceptedRPC.add(Names.SubscribeButton);
+ acceptedRPC.add(Names.UnsubscribeButton);
+
+ acceptedRPC.add("ClearMediaClockTimer");
+ acceptedRPC.add("PauseMediaClockTimer");
+ acceptedRPC.add("ResumeMediaClockTimer");
+ }
+
+ public String getFunctionName(int i) {
+ return acceptedRPC.get(i);
+ }
+
+ public int getFunctionID(String functionName) {
+ return acceptedRPC.indexOf(functionName);
+ }
+
+ public boolean isAcceptedRPC(String rpc) {
+ return acceptedRPC.contains(rpc);
+ }
+}
diff --git a/SDL_Android/SmartDeviceLinkTester/src/com/smartdevicelink/android/constants/Const.java b/SDL_Android/SmartDeviceLinkTester/src/com/smartdevicelink/android/constants/Const.java
new file mode 100644
index 000000000..5e264c261
--- /dev/null
+++ b/SDL_Android/SmartDeviceLinkTester/src/com/smartdevicelink/android/constants/Const.java
@@ -0,0 +1,37 @@
+//
+// Copyright (c) 2013 Ford Motor Company
+//
+package com.smartdevicelink.android.constants;
+
+/** Stores application-wide constants. */
+public class Const {
+ // Shared preference name for properties
+ public static final String PREFS_NAME = "SmartDeviceLinkTesterPrefs";
+
+ // Properties
+ public static final String PREFS_KEY_APPNAME = "appName";
+ public static final String PREFS_KEY_ISMEDIAAPP = "isMediaApp";
+
+ // Default values
+ public static final String PREFS_DEFAULT_APPNAME = "SmartDeviceLinkTester";
+ public static final boolean PREFS_DEFAULT_ISMEDIAAPP = true;
+
+ // Transport properties
+ public static final class Transport {
+ // Properties
+ public static final String PREFS_KEY_TRANSPORT_TYPE = "TransportType";
+ public static final String PREFS_KEY_TRANSPORT_PORT = "TCPPort";
+ public static final String PREFS_KEY_TRANSPORT_IP = "IPAddress";
+ public static final String PREFS_KEY_TRANSPORT_RECONNECT = "AutoReconnect";
+
+ public static final String TCP = "WiFi";
+ public static final String BLUETOOTH = "Bluetooth";
+ public static final int KEY_TCP = 1;
+ public static final int KEY_BLUETOOTH = 2;
+
+ public static final int PREFS_DEFAULT_TRANSPORT_TYPE = KEY_BLUETOOTH;
+ public static final int PREFS_DEFAULT_TRANSPORT_PORT = 50007;
+ public static final String PREFS_DEFAULT_TRANSPORT_IP = "10.0.2.2";
+ public static final boolean PREFS_DEFAULT_TRANSPORT_RECONNECT_DEFAULT = true;
+ }
+}
diff --git a/SDL_Android/SmartDeviceLinkTester/src/com/smartdevicelink/android/constants/SmartDeviceLinkSubMenu.java b/SDL_Android/SmartDeviceLinkTester/src/com/smartdevicelink/android/constants/SmartDeviceLinkSubMenu.java
new file mode 100644
index 000000000..6c003097f
--- /dev/null
+++ b/SDL_Android/SmartDeviceLinkTester/src/com/smartdevicelink/android/constants/SmartDeviceLinkSubMenu.java
@@ -0,0 +1,27 @@
+//
+// Copyright (c) 2013 Ford Motor Company
+//
+package com.smartdevicelink.android.constants;
+
+public class SmartDeviceLinkSubMenu {
+ private String menuName;
+ private int id;
+
+ public void setSubMenuId(int parentID){
+ this.id = parentID;
+ }
+ public int getSubMenuId(){
+ return this.id;
+ }
+ public void setName(String name){
+ this.menuName = name;
+ }
+ public String getName(){
+ return this.menuName;
+ }
+
+ public String toString(){
+ return "(" + getSubMenuId() + ") " + getName();
+ }
+
+}
diff --git a/SDL_Android/SmartDeviceLinkTester/src/com/smartdevicelink/android/module/ModuleTest.java b/SDL_Android/SmartDeviceLinkTester/src/com/smartdevicelink/android/module/ModuleTest.java
new file mode 100644
index 000000000..3915321ba
--- /dev/null
+++ b/SDL_Android/SmartDeviceLinkTester/src/com/smartdevicelink/android/module/ModuleTest.java
@@ -0,0 +1,631 @@
+//
+// Copyright (c) 2013 Ford Motor Company
+//
+package com.smartdevicelink.android.module;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileWriter;
+import java.io.FilenameFilter;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.Vector;
+
+import org.xmlpull.v1.XmlPullParser;
+import com.smartdevicelink.exception.SmartDeviceLinkException;
+import com.smartdevicelink.proxy.RPCRequest;
+import com.smartdevicelink.proxy.constants.Names;
+import com.smartdevicelink.proxy.rpc.AddCommand;
+import com.smartdevicelink.proxy.rpc.AddSubMenu;
+import com.smartdevicelink.proxy.rpc.Alert;
+import com.smartdevicelink.proxy.rpc.CreateInteractionChoiceSet;
+import com.smartdevicelink.proxy.rpc.DeleteCommand;
+import com.smartdevicelink.proxy.rpc.DeleteInteractionChoiceSet;
+import com.smartdevicelink.proxy.rpc.DeleteSubMenu;
+import com.smartdevicelink.proxy.rpc.EncodedSyncPData;
+import com.smartdevicelink.proxy.rpc.PerformInteraction;
+import com.smartdevicelink.proxy.rpc.RegisterAppInterface;
+import com.smartdevicelink.proxy.rpc.ResetGlobalProperties;
+import com.smartdevicelink.proxy.rpc.SetGlobalProperties;
+import com.smartdevicelink.proxy.rpc.SetMediaClockTimer;
+import com.smartdevicelink.proxy.rpc.Show;
+import com.smartdevicelink.proxy.rpc.Speak;
+import com.smartdevicelink.proxy.rpc.StartTime;
+import com.smartdevicelink.proxy.rpc.SubscribeButton;
+import com.smartdevicelink.proxy.rpc.UnregisterAppInterface;
+import com.smartdevicelink.proxy.rpc.UnsubscribeButton;
+import com.smartdevicelink.proxy.rpc.enums.Result;
+import com.smartdevicelink.proxy.rpc.enums.UpdateMode;
+import com.smartdevicelink.android.activity.SmartDeviceLinkTester;
+import com.smartdevicelink.android.adapters.logAdapter;
+import com.smartdevicelink.android.constants.AcceptedRPC;
+import com.smartdevicelink.android.service.ProxyService;
+
+import android.app.AlertDialog;
+import android.app.AlertDialog.Builder;
+import android.app.Dialog;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.net.Uri;
+import android.os.Environment;
+import android.util.Log;
+import android.util.Pair;
+import android.util.Xml;
+
+public class ModuleTest {
+ private static ModuleTest _instance;
+ private SmartDeviceLinkTester _mainInstance;
+ private logAdapter _msgAdapter;
+ private static Runnable threadContext;
+ private static ModuleTest DialogThreadContext;
+ private Thread mainThread;
+
+ private boolean pass;
+ private boolean integration;
+ private String userPrompt;
+
+ private int numIterations;
+
+ private ArrayList<Pair<Integer, Result>> expecting = new ArrayList<Pair<Integer, Result>>();
+ private ArrayList<Pair<String, ArrayList<RPCRequest>>> testList = new ArrayList<Pair<String, ArrayList<RPCRequest>>> ();
+
+ public static ArrayList<Pair<Integer, Result>> responses = new ArrayList<Pair<Integer, Result>>();
+
+ public ModuleTest() {
+ this._mainInstance = SmartDeviceLinkTester.getInstance();
+ this._msgAdapter = SmartDeviceLinkTester.getMessageAdapter();
+
+ // Set this's instance
+ _instance = this;
+ _mainInstance.setTesterMain(_instance);
+
+ mainThread = makeThread();
+ }
+
+ public void runTests() {
+ mainThread.start();
+ }
+
+ public void restart() {
+ mainThread.interrupt();
+ mainThread = null;
+ mainThread = makeThread();
+ mainThread.start();
+ }
+
+ private String[] mFileList;
+ private File mPath = new File(Environment.getExternalStorageDirectory() + "");
+ private String mChosenFile;
+ private static final String FTYPE = ".xml";
+ private static final int DIALOG_LOAD_FILE = 1000;
+
+ private void loadFileList(){
+ try{
+ mPath.mkdirs();
+ } catch(SecurityException e) {
+ Log.e("ModuleTest", "unable to write on the sd card " + e.toString());
+ }
+ if (mPath.exists()) {
+ FilenameFilter filter = new FilenameFilter() {
+ public boolean accept(File dir, String filename) {
+ File sel = new File(dir, filename);
+ return filename.contains(FTYPE);
+ }
+ };
+ mFileList = mPath.list(filter);
+ } else {
+ mFileList= new String[0];
+ }
+ }
+
+ Dialog dialog;
+
+ protected Dialog onCreateDialog(final int id) {
+ DialogThreadContext = this;
+ _mainInstance.runOnUiThread(new Runnable() {
+ public void run() {
+ dialog = null;
+ AlertDialog.Builder builder = new Builder(_mainInstance);
+
+ switch(id) {
+ case DIALOG_LOAD_FILE:
+ builder.setTitle("Choose your file");
+ if (mFileList == null) {
+ Log.e("ModuleTest", "Showing file picker before loading the file list");
+ dialog = builder.create();
+ //return dialog;
+ synchronized (DialogThreadContext) { DialogThreadContext.notify();}
+ Thread.currentThread().interrupt();
+ }
+ builder.setItems(mFileList, new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int which) {
+ mChosenFile = mFileList[which];
+ //you can do stuff with the file here too
+ synchronized (DialogThreadContext) { DialogThreadContext.notify();}
+ Thread.currentThread().interrupt();
+ }
+ });
+ break;
+ }
+ dialog = builder.show();
+ }
+ });
+
+ try {
+ synchronized (this) { this.wait();}
+ } catch (InterruptedException e) {
+ _msgAdapter.logMessage("InterruptedException", true);
+ }
+ return dialog;
+ }
+
+ public Thread makeThread () {
+ return new Thread (new Runnable () {
+ public void run () {
+ mChosenFile = null;
+ loadFileList();
+ onCreateDialog(DIALOG_LOAD_FILE);
+ if (mChosenFile != null) {
+ AcceptedRPC acceptedRPC = new AcceptedRPC();
+ XmlPullParser parser = Xml.newPullParser();
+ RPCRequest rpc;
+ try {
+ FileInputStream fin = new FileInputStream("/sdcard/" + mChosenFile);
+ InputStreamReader isr = new InputStreamReader(fin);
+
+ String outFile = "/sdcard/" + mChosenFile.substring(0, mChosenFile.length() - 4) + ".csv";
+ File out = new File(outFile);
+ FileWriter writer = new FileWriter(out);
+ writer.flush();
+
+ parser.setInput(isr);
+ int eventType = parser.getEventType();
+ String name;
+ boolean done = false;
+ while (eventType != XmlPullParser.END_DOCUMENT && !done) {
+ name = parser.getName();
+
+ switch (eventType) {
+ case XmlPullParser.START_DOCUMENT:
+ Log.e("TESTING", "START_DOCUMENT, name: " + name);
+ break;
+ case XmlPullParser.END_DOCUMENT:
+ Log.e("TESTING", "END_DOCUMENT, name: " + name);
+ break;
+ case XmlPullParser.START_TAG:
+ name = parser.getName();
+ if (name.equalsIgnoreCase("test")) {
+ _msgAdapter.logMessage("test " + parser.getAttributeValue(0), true);
+ testList.add(new Pair<String, ArrayList<RPCRequest>> (parser.getAttributeValue(0), new ArrayList<RPCRequest> ()));
+ expecting.clear();
+ responses.clear();
+ try {
+ if (parser.getAttributeName(1) != null) {
+ if (parser.getAttributeName(1).equalsIgnoreCase("iterations")) {
+ try {numIterations = Integer.parseInt(parser.getAttributeValue(1));}
+ catch (Exception e) {Log.e("parser", "Unable to parse number of iterations");}
+ } else numIterations = 1;
+ } else numIterations = 1;
+ } catch (Exception e) {
+ numIterations = 1;
+ }
+ } else if (name.equalsIgnoreCase("type")) {
+ if (parser.getAttributeValue(0).equalsIgnoreCase("integration")) integration = true;
+ else if (parser.getAttributeValue(0).equalsIgnoreCase("unit")) integration = false;
+ } else if (acceptedRPC.isAcceptedRPC(name)) {
+ //Create correct object
+ if (name.equalsIgnoreCase(Names.RegisterAppInterface)) {
+ rpc = new RegisterAppInterface();
+ } else if (name.equalsIgnoreCase(Names.UnregisterAppInterface)) {
+ rpc = new UnregisterAppInterface();
+ } else if (name.equalsIgnoreCase(Names.SetGlobalProperties)) {
+ rpc = new SetGlobalProperties();
+ } else if (name.equalsIgnoreCase(Names.ResetGlobalProperties)) {
+ rpc = new ResetGlobalProperties();
+ } else if (name.equalsIgnoreCase(Names.AddCommand)) {
+ rpc = new AddCommand();
+ } else if (name.equalsIgnoreCase(Names.DeleteCommand)) {
+ rpc = new DeleteCommand();
+ } else if (name.equalsIgnoreCase(Names.AddSubMenu)) {
+ rpc = new AddSubMenu();
+ } else if (name.equalsIgnoreCase(Names.DeleteSubMenu)) {
+ rpc = new DeleteSubMenu();
+ } else if (name.equalsIgnoreCase(Names.CreateInteractionChoiceSet)) {
+ rpc = new CreateInteractionChoiceSet();
+ } else if (name.equalsIgnoreCase(Names.PerformInteraction)) {
+ rpc = new PerformInteraction();
+ } else if (name.equalsIgnoreCase(Names.DeleteInteractionChoiceSet)) {
+ rpc = new DeleteInteractionChoiceSet();
+ } else if (name.equalsIgnoreCase(Names.Alert)) {
+ rpc = new Alert();
+ } else if (name.equalsIgnoreCase(Names.Show)) {
+ rpc = new Show();
+ } else if (name.equalsIgnoreCase(Names.Speak)) {
+ rpc = new Speak();
+ } else if (name.equalsIgnoreCase(Names.SetMediaClockTimer)) {
+ rpc = new SetMediaClockTimer();
+ } else if (name.equalsIgnoreCase(Names.EncodedSyncPData)) {
+ rpc = new EncodedSyncPData();
+ } else if (name.equalsIgnoreCase(Names.SubscribeButton)) {
+ rpc = new SubscribeButton();
+ } else if (name.equalsIgnoreCase(Names.UnsubscribeButton)) {
+ rpc = new UnsubscribeButton();
+ } else if (name.equalsIgnoreCase("ClearMediaClockTimer")) {
+ rpc = new Show();
+ ((Show) rpc).setMainField1(null);
+ ((Show) rpc).setMainField2(null);
+ ((Show) rpc).setStatusBar(null);
+ ((Show) rpc).setMediaClock(" ");
+ ((Show) rpc).setMediaTrack(null);
+ ((Show) rpc).setAlignment(null);
+ } else if (name.equalsIgnoreCase("PauseMediaClockTimer")) {
+ rpc = new SetMediaClockTimer();
+ StartTime startTime = new StartTime();
+ startTime.setHours(0);
+ startTime.setMinutes(0);
+ startTime.setSeconds(0);
+ ((SetMediaClockTimer) rpc).setStartTime(startTime);
+ ((SetMediaClockTimer) rpc).setUpdateMode(UpdateMode.PAUSE);
+ } else if (name.equalsIgnoreCase("ResumeMediaClockTimer")) {
+ rpc = new SetMediaClockTimer();
+ StartTime startTime = new StartTime();
+ startTime.setHours(0);
+ startTime.setMinutes(0);
+ startTime.setSeconds(0);
+ ((SetMediaClockTimer) rpc).setStartTime(startTime);
+ ((SetMediaClockTimer) rpc).setUpdateMode(UpdateMode.RESUME);
+ } else {
+ rpc = new SetGlobalProperties();
+ }
+
+ if (parser.getAttributeName(0) != null &&
+ parser.getAttributeName(0).equalsIgnoreCase("correlationID")) {
+ try {rpc.setCorrelationID(Integer.parseInt(parser.getAttributeValue(0)));}
+ catch (Exception e) {Log.e("parser", "Unable to parse Integer");}
+ }
+
+ Hashtable hash = setParams(name, parser);
+ Log.e("TESTING", "" + hash);
+ for (Object key : hash.keySet()) {
+ rpc.setParameters((String) key, hash.get(key));
+ }
+
+ Iterator it = hash.entrySet().iterator();
+ while (it.hasNext()) {
+ Hashtable.Entry pairs = (Hashtable.Entry)it.next();
+ System.out.println(pairs.getKey() + " = " + pairs.getValue());
+ }
+
+ Pair<String, ArrayList<RPCRequest>> temp = testList.get(testList.size()-1);
+ temp.second.add(rpc);
+ testList.set(testList.size()-1, temp);
+ } else if (name.equalsIgnoreCase("result")) {
+ expecting.add(new Pair<Integer, Result>(Integer.parseInt(parser.getAttributeValue(0)), (Result.valueForString(parser.getAttributeValue(1)))));
+ } else if (name.equalsIgnoreCase("userPrompt") && integration) {
+ userPrompt = parser.getAttributeValue(0);
+ }
+ break;
+ case XmlPullParser.END_TAG:
+ name = parser.getName();
+ if (name.equalsIgnoreCase("test")) {
+ try {
+ boolean localPass = true;
+ int i = numIterations;
+ int numPass = 0;
+ while (i > 0) {
+ xmlTest();
+ if (pass) numPass++;
+ else localPass = false;
+ i--;
+ }
+ if (localPass) writer.write("" + testList.get(testList.size()-1).first + ", Pass, " + numPass + ", " + numIterations + "\n");
+ if (!localPass) writer.write("" + testList.get(testList.size()-1).first + ", Fail, " + numPass + ", " + numIterations + "\n");
+ Log.i("Test App Result", "" + testList.get(testList.size()-1).first + ", " + localPass + ", " + numPass + ", " + numIterations);
+ _msgAdapter.logMessage("" + testList.get(testList.size()-1).first + ", " + localPass + ", " + numPass + ", " + numIterations, true);
+ } catch (Exception e) {
+ _msgAdapter.logMessage("Test " + testList.get(testList.size()-1).first + " Failed! ", Log.ERROR, e);
+ }
+ }
+ break;
+ case XmlPullParser.TEXT:
+ //Log.e("TESTING", "TEXT, name: " + name);
+ break;
+ case XmlPullParser.CDSECT:
+ Log.e("TESTING", "CDSECT, name: " + name);
+ break;
+ case XmlPullParser.ENTITY_REF:
+ Log.e("TESTING", "ENTITY_REF, name: " + name);
+ break;
+ case XmlPullParser.IGNORABLE_WHITESPACE:
+ Log.e("TESTING", "IGNORABLE_WHITESPACE, name: " + name);
+ break;
+ case XmlPullParser.PROCESSING_INSTRUCTION:
+ Log.e("TESTING", "PROCESSING_INSTRUCTION, name: " + name);
+ break;
+ case XmlPullParser.COMMENT:
+ Log.e("TESTING", "COMMENT, name: " + name);
+ break;
+ case XmlPullParser.DOCDECL:
+ Log.e("TESTING", "DOCDECL, name: " + name);
+ break;
+ default:
+ break;
+ }
+ eventType = parser.next();
+ }
+ writer.close();
+
+ Intent email = new Intent(Intent.ACTION_SEND);
+ email.setType("plain/text");
+ email.putExtra(Intent.EXTRA_EMAIL, new String[]{"youremail@company.com"});
+ email.putExtra(Intent.EXTRA_SUBJECT, "Unit Test Export");
+ email.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(out));
+
+ _mainInstance.startActivity(Intent.createChooser(email, "Choose an Email client :"));
+
+ } catch (Exception e) {
+ _msgAdapter.logMessage("Parser Failed!!", Log.ERROR, e);
+ }
+ }
+ }
+ });
+ }
+
+ private Hashtable setParams(String name, XmlPullParser parser) {
+
+ Log.e("TESTING", "setParams start name: " + name);
+
+ Hashtable hash = new Hashtable();
+
+ int eventType = 0;
+ Boolean done = false;
+ String tempName = null;
+ String vectorName = null;
+
+ try {
+ while (eventType != XmlPullParser.END_DOCUMENT && !done) {
+ tempName = parser.getName();
+
+ switch (eventType) {
+ case XmlPullParser.START_DOCUMENT:
+ Log.e("TESTING", "START_DOCUMENT, tempName: " + tempName);
+ break;
+ case XmlPullParser.END_DOCUMENT:
+ Log.e("TESTING", "END_DOCUMENT, tempName: " + tempName);
+ break;
+ case XmlPullParser.START_TAG:
+ if (tempName.equalsIgnoreCase("Vector")) {
+ Log.e("TESTING", "In Vector");
+ Vector<Object> vector = new Vector<Object>();
+
+ if (parser.getAttributeName(0) != null) vectorName = parser.getAttributeValue(0);
+
+ Boolean nestedWhileDone = false;
+
+ eventType = parser.next();
+ while (eventType != XmlPullParser.START_TAG && !nestedWhileDone) {
+ if (eventType == XmlPullParser.END_TAG) {
+ if (parser.getName().equalsIgnoreCase("Vector")) {
+ Log.e("TESTING", "In Vector Loop, nestedWhileDone == true, END_TAG, name: " + name);
+ nestedWhileDone = true;
+ }
+ } else eventType = parser.next();
+ }
+
+ while (eventType != XmlPullParser.END_DOCUMENT && !nestedWhileDone) {
+ tempName = parser.getName();
+ Log.e("TESTING", "In Vector Loop, tempName: " + tempName);
+
+ switch (eventType) {
+ case XmlPullParser.START_DOCUMENT:
+ Log.e("TESTING", "In Vector Loop, START_DOCUMENT, name: " + name);
+ break;
+ case XmlPullParser.END_DOCUMENT:
+ Log.e("TESTING", "In Vector Loop, END_DOCUMENT, name: " + name);
+ break;
+ case XmlPullParser.START_TAG:
+ if (tempName.equalsIgnoreCase("Integer")) {
+ Log.e("TESTING", "In Nested Vector Integer");
+ if (parser.getAttributeName(0) != null) {
+ try {vector.add(Double.parseDouble(parser.getAttributeValue(0)));}
+ catch (Exception e) {Log.e("parser", "Unable to parse Integer");}
+ }
+ } else if (tempName.equalsIgnoreCase("String")) {
+ Log.e("TESTING", "In Nested Vector String");
+ if (parser.getAttributeName(0) != null) {
+ vector.add(parser.getAttributeValue(0));
+ }
+ } else {
+ vector.add(setParams(tempName, parser));
+ }
+ break;
+ case XmlPullParser.END_TAG:
+ Log.e("TESTING", "In Vector Loop, END_TAG, name: " + name);
+ if (tempName.equalsIgnoreCase("Vector")) {
+ Log.e("TESTING", "In Vector Loop, nestedWhileDone == true, END_TAG, name: " + name);
+ nestedWhileDone = true;
+ }
+ break;
+ case XmlPullParser.TEXT:
+ //Log.e("TESTING", "TEXT, name: " + name);
+ break;
+ case XmlPullParser.CDSECT:
+ Log.e("TESTING", "In Vector Loop, CDSECT, name: " + name);
+ break;
+ case XmlPullParser.ENTITY_REF:
+ Log.e("TESTING", "In Vector Loop, ENTITY_REF, name: " + name);
+ break;
+ case XmlPullParser.IGNORABLE_WHITESPACE:
+ Log.e("TESTING", "In Vector Loop, IGNORABLE_WHITESPACE, name: " + name);
+ break;
+ case XmlPullParser.PROCESSING_INSTRUCTION:
+ Log.e("TESTING", "In Vector Loop, PROCESSING_INSTRUCTION, name: " + name);
+ break;
+ case XmlPullParser.COMMENT:
+ Log.e("TESTING", "In Vector Loop, COMMENT, name: " + name);
+ break;
+ case XmlPullParser.DOCDECL:
+ Log.e("TESTING", "In Vector Loop, DOCDECL, name: " + name);
+ break;
+ default:
+ break;
+ }
+ eventType = parser.next();
+ }
+ Log.e("TESTING", "out of Vector loop");
+ hash.put(vectorName, vector);
+ } else if (tempName.equalsIgnoreCase("Integer")) {
+ Log.e("TESTING", "In Integer");
+ if (parser.getAttributeName(0) != null) {
+ try {hash.put(parser.getAttributeName(0), Double.parseDouble(parser.getAttributeValue(0)));}
+ catch (Exception e) {Log.e("parser", "Unable to parse Integer");}
+ }
+ } else if (tempName.equalsIgnoreCase("Boolean")) {
+ Log.e("TESTING", "In Boolean");
+ if (parser.getAttributeName(0) != null) {
+ if (parser.getAttributeValue(0).equalsIgnoreCase("true")) hash.put(parser.getAttributeName(0), true);
+ else if (parser.getAttributeValue(0).equalsIgnoreCase("false")) hash.put(parser.getAttributeName(0), false);
+ }
+ } else if (tempName.equalsIgnoreCase("String")) {
+ Log.e("TESTING", "In String");
+ if (parser.getAttributeName(0) != null) {
+ hash.put(parser.getAttributeName(0), parser.getAttributeValue(0));
+ }
+ } else {
+ Log.e("TESTING", "Returning in else statement");
+ hash.put(tempName, setParams(tempName, parser));
+ }
+ break;
+ case XmlPullParser.END_TAG:
+ if (tempName.equalsIgnoreCase(name)) {
+ done = true;
+ }
+ break;
+ case XmlPullParser.TEXT:
+ //Log.e("TESTING", "TEXT, tempName: " + tempName);
+ break;
+ case XmlPullParser.CDSECT:
+ Log.e("TESTING", "CDSECT, tempName: " + tempName);
+ break;
+ case XmlPullParser.ENTITY_REF:
+ Log.e("TESTING", "ENTITY_REF, tempName: " + tempName);
+ break;
+ case XmlPullParser.IGNORABLE_WHITESPACE:
+ Log.e("TESTING", "IGNORABLE_WHITESPACE, tempName: " + tempName);
+ break;
+ case XmlPullParser.PROCESSING_INSTRUCTION:
+ Log.e("TESTING", "PROCESSING_INSTRUCTION, tempName: " + tempName);
+ break;
+ case XmlPullParser.COMMENT:
+ Log.e("TESTING", "COMMENT, tempName: " + tempName);
+ break;
+ case XmlPullParser.DOCDECL:
+ Log.e("TESTING", "DOCDECL, tempName: " + tempName);
+ break;
+ default:
+ break;
+ }
+ eventType = parser.next();
+ }
+ } catch (Exception e) {
+ _msgAdapter.logMessage("Parser Failed!!", Log.ERROR, e);
+ }
+
+ Log.e("TESTING", "Returning at end of setParams function");
+ return hash;
+ }
+
+ private Boolean xmlTest() {
+ pass = false;
+
+ Thread newThread = new Thread(new Runnable() {
+ public void run () {
+ threadContext = this;
+
+ int numResponses = expecting.size();
+ if (numResponses > 0) ProxyService.waiting(true);
+
+ for (RPCRequest rpc : testList.get(testList.size()-1).second) {
+ _msgAdapter.logMessage(rpc, true);
+ try {
+ ProxyService.getProxyInstance().sendRPCRequest(rpc);
+ } catch (SmartDeviceLinkException e) {
+ _msgAdapter.logMessage("Error sending RPC", Log.ERROR, e, true);
+ }
+ }
+
+ try {
+ for (int i = 0; i < numResponses; i++) synchronized (this) { this.wait(10000);}
+ } catch (InterruptedException e) {
+ _msgAdapter.logMessage("InterruptedException", true);
+ }
+
+ ProxyService.waiting(false);
+
+ try {
+ synchronized (this) { this.wait(5000);}
+ } catch (InterruptedException e) {
+ _msgAdapter.logMessage("InterruptedException", true);
+ }
+
+ if (expecting.equals(responses)) {
+ pass = true;
+ if (integration) {
+ _mainInstance.runOnUiThread(new Runnable() {
+ public void run() {
+ AlertDialog.Builder alert = new AlertDialog.Builder(_mainInstance);
+ alert.setMessage(userPrompt);
+ alert.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ pass = true;
+ synchronized (threadContext) { threadContext.notify();}
+ }
+ });
+ alert.setNegativeButton("No", new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ pass = false;
+ synchronized (threadContext) { threadContext.notify();}
+ }
+ });
+ alert.show();
+ }
+ });
+
+ try {
+ synchronized (this) { this.wait();}
+ } catch (InterruptedException e) {
+ _msgAdapter.logMessage("InterruptedException", true);
+ }
+ }
+ }
+
+ synchronized (_instance) { _instance.notify();}
+
+ Thread.currentThread().interrupt();
+ }
+ });
+ newThread.start();
+
+ try {
+ synchronized (this) { this.wait();}
+ } catch (InterruptedException e) {
+ _msgAdapter.logMessage("InterruptedException", true);
+ }
+
+ newThread.interrupt();
+ newThread = null;
+ return pass;
+ }
+
+ public static ModuleTest getModuleTestInstance() {
+ return _instance;
+ }
+
+ public Runnable getThreadContext() {
+ return threadContext;
+ }
+}
diff --git a/SDL_Android/SmartDeviceLinkTester/src/com/smartdevicelink/android/receivers/SmartDeviceLinkReceiver.java b/SDL_Android/SmartDeviceLinkTester/src/com/smartdevicelink/android/receivers/SmartDeviceLinkReceiver.java
new file mode 100644
index 000000000..deaba4ed1
--- /dev/null
+++ b/SDL_Android/SmartDeviceLinkTester/src/com/smartdevicelink/android/receivers/SmartDeviceLinkReceiver.java
@@ -0,0 +1,78 @@
+//
+// Copyright (c) 2013 Ford Motor Company
+//
+package com.smartdevicelink.android.receivers;
+
+import android.bluetooth.BluetoothAdapter;
+import android.bluetooth.BluetoothDevice;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.util.Log;
+import android.view.KeyEvent;
+
+import com.smartdevicelink.android.service.ProxyService;
+import com.smartdevicelink.util.DebugTool;
+
+public class SmartDeviceLinkReceiver extends BroadcastReceiver {
+ static final String TAG = "SmartDeviceLinkTester";
+
+ public void onReceive(Context context, Intent intent) {
+ DebugTool.logInfo("SmartDeviceLinkReceiver.onReceive()");
+ DebugTool.logInfo("Received Intent with action: " + intent.getAction());
+ Log.i(TAG, "Received Intent with action: " + intent.getAction());
+ final BluetoothDevice bluetoothDevice = (BluetoothDevice) intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
+ BluetoothAdapter mBtAdapter;
+ ProxyService serviceInstance = ProxyService.getInstance();
+
+ //open proxy when BT is on. Dispose and shutdown service when BT is off
+ if (intent.getAction().equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
+ if ((intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, -1) == (BluetoothAdapter.STATE_TURNING_OFF))){
+ if (serviceInstance != null){
+ Log.i(TAG, "Bt off stop service");
+ Intent stopIntent = new Intent(context, ProxyService.class);
+ stopIntent.putExtras(intent);
+ context.stopService(stopIntent);
+ }
+ } else if ((intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, -1) == (BluetoothAdapter.STATE_TURNING_ON))){
+ Log.i(TAG, "Bt on");
+ if (serviceInstance == null){
+ Log.i(TAG, "Bt on start service");
+ Intent startIntent = new Intent(context, ProxyService.class);
+ startIntent.putExtras(intent);
+ context.startService(startIntent);
+ }
+ //if the service was already running when BT turned back on
+ else {
+ serviceInstance.reset();
+ }
+ }
+ //Listen for phone reboot and start service
+ } else if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
+ mBtAdapter = BluetoothAdapter.getDefaultAdapter();
+ if (mBtAdapter != null)
+ {
+ if (mBtAdapter.isEnabled()){
+ Intent startIntent = new Intent(context, ProxyService.class);
+ startIntent.putExtras(intent);
+ context.startService(startIntent);
+ }
+ }
+ }
+
+ if (intent.getAction().compareTo(Intent.ACTION_MEDIA_BUTTON) == 0) {
+ KeyEvent event = (KeyEvent) intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
+ if (event.getKeyCode() == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE) {
+ abortBroadcast();
+ }
+
+ }
+
+ if (intent.getAction().equals(android.media.AudioManager.ACTION_AUDIO_BECOMING_NOISY)) {
+ // signal your service to stop playback
+ if (serviceInstance != null){
+ serviceInstance.pauseAnnoyingRepetitiveAudio();
+ }
+ }
+ }
+}
diff --git a/SDL_Android/SmartDeviceLinkTester/src/com/smartdevicelink/android/service/ProxyService.java b/SDL_Android/SmartDeviceLinkTester/src/com/smartdevicelink/android/service/ProxyService.java
new file mode 100644
index 000000000..e51a7c6e3
--- /dev/null
+++ b/SDL_Android/SmartDeviceLinkTester/src/com/smartdevicelink/android/service/ProxyService.java
@@ -0,0 +1,720 @@
+//
+// Copyright (c) 2013 Ford Motor Company
+//
+package com.smartdevicelink.android.service;
+
+import java.util.Arrays;
+import java.util.Vector;
+
+import android.app.Service;
+import android.bluetooth.BluetoothAdapter;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.SharedPreferences;
+import android.media.MediaPlayer;
+import android.os.Binder;
+import android.os.IBinder;
+import android.util.Log;
+import android.util.Pair;
+
+import com.smartdevicelink.android.R;
+import com.smartdevicelink.android.activity.SmartDeviceLinkTester;
+import com.smartdevicelink.android.adapters.logAdapter;
+import com.smartdevicelink.android.constants.Const;
+import com.smartdevicelink.android.module.ModuleTest;
+import com.smartdevicelink.android.receivers.SmartDeviceLinkReceiver;
+import com.smartdevicelink.exception.SmartDeviceLinkException;
+import com.smartdevicelink.exception.SmartDeviceLinkExceptionCause;
+import com.smartdevicelink.proxy.SmartDeviceLinkProxyALM;
+import com.smartdevicelink.proxy.interfaces.IProxyListenerALM;
+import com.smartdevicelink.proxy.rpc.AddCommandResponse;
+import com.smartdevicelink.proxy.rpc.AddSubMenuResponse;
+import com.smartdevicelink.proxy.rpc.AlertResponse;
+import com.smartdevicelink.proxy.rpc.CreateInteractionChoiceSetResponse;
+import com.smartdevicelink.proxy.rpc.DeleteCommandResponse;
+import com.smartdevicelink.proxy.rpc.DeleteInteractionChoiceSetResponse;
+import com.smartdevicelink.proxy.rpc.DeleteSubMenuResponse;
+import com.smartdevicelink.proxy.rpc.EncodedSyncPDataResponse;
+import com.smartdevicelink.proxy.rpc.GenericResponse;
+import com.smartdevicelink.proxy.rpc.OnButtonEvent;
+import com.smartdevicelink.proxy.rpc.OnButtonPress;
+import com.smartdevicelink.proxy.rpc.OnCommand;
+import com.smartdevicelink.proxy.rpc.OnDriverDistraction;
+import com.smartdevicelink.proxy.rpc.OnEncodedSyncPData;
+import com.smartdevicelink.proxy.rpc.OnHMIStatus;
+import com.smartdevicelink.proxy.rpc.OnPermissionsChange;
+import com.smartdevicelink.proxy.rpc.OnTBTClientState;
+import com.smartdevicelink.proxy.rpc.PerformInteractionResponse;
+import com.smartdevicelink.proxy.rpc.ResetGlobalPropertiesResponse;
+import com.smartdevicelink.proxy.rpc.SetGlobalPropertiesResponse;
+import com.smartdevicelink.proxy.rpc.SetMediaClockTimerResponse;
+import com.smartdevicelink.proxy.rpc.ShowResponse;
+import com.smartdevicelink.proxy.rpc.SpeakResponse;
+import com.smartdevicelink.proxy.rpc.SubscribeButtonResponse;
+import com.smartdevicelink.proxy.rpc.UnsubscribeButtonResponse;
+import com.smartdevicelink.proxy.rpc.enums.ButtonName;
+import com.smartdevicelink.proxy.rpc.enums.Result;
+import com.smartdevicelink.transport.TCPTransportConfig;
+
+public class ProxyService extends Service implements IProxyListenerALM {
+ static final String TAG = "SmartDeviceLinkTester";
+ private Integer autoIncCorrId = 1;
+
+ private static SmartDeviceLinkTester _mainInstance;
+ private static ProxyService _instance;
+ private static SmartDeviceLinkProxyALM _SmartDeviceLinkProxy;
+ private static logAdapter _msgAdapter;
+ private ModuleTest _testerMain;
+ private BluetoothAdapter mBtAdapter;
+ private MediaPlayer embeddedAudioPlayer;
+ private Boolean playingAudio = false;
+ protected SmartDeviceLinkReceiver mediaButtonReceiver;
+
+ private boolean firstHMIStatusChange = true;
+
+ private static boolean waitingForResponse = false;
+
+ public void onCreate() {
+ super.onCreate();
+
+ IntentFilter mediaIntentFilter = new IntentFilter();
+ mediaIntentFilter.addAction(Intent.ACTION_MEDIA_BUTTON);
+
+ mediaButtonReceiver = new SmartDeviceLinkReceiver();
+ registerReceiver(mediaButtonReceiver, mediaIntentFilter);
+
+ if (_msgAdapter == null) _msgAdapter = SmartDeviceLinkTester.getMessageAdapter();
+ if (_msgAdapter != null) _msgAdapter.logMessage("ProxyService.onCreate()", Log.INFO);
+ else Log.i(TAG, "ProxyService.onCreate()");
+
+ _instance = this;
+ }
+
+ public void showLockMain() {
+ if(SmartDeviceLinkTester.getInstance() == null) {
+ Intent i = new Intent(this, SmartDeviceLinkTester.class);
+ i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ startActivity(i);
+ }
+ }
+
+ public int onStartCommand(Intent intent, int flags, int startId) {
+ if (_msgAdapter == null) _msgAdapter = SmartDeviceLinkTester.getMessageAdapter();
+ if (_msgAdapter != null) _msgAdapter.logMessage("ProxyService.onStartCommand()", Log.INFO);
+ else Log.i(TAG, "ProxyService.onStartCommand()");
+
+ startProxyIfNetworkConnected();
+
+ setCurrentActivity(SmartDeviceLinkTester.getInstance());
+
+ return START_STICKY;
+ }
+
+ private void startProxyIfNetworkConnected() {
+ final SharedPreferences prefs = getSharedPreferences(Const.PREFS_NAME,
+ MODE_PRIVATE);
+ final int transportType = prefs.getInt(
+ Const.Transport.PREFS_KEY_TRANSPORT_TYPE,
+ Const.Transport.PREFS_DEFAULT_TRANSPORT_TYPE);
+
+ if (transportType == Const.Transport.KEY_BLUETOOTH) {
+ Log.d(TAG, "ProxyService. onStartCommand(). Transport = Bluetooth.");
+ mBtAdapter = BluetoothAdapter.getDefaultAdapter();
+ if (mBtAdapter != null) {
+ if (mBtAdapter.isEnabled()) {
+ startProxy();
+ }
+ }
+ } else {
+ startProxy();
+ }
+ }
+
+ public void startProxy() {
+ if (_msgAdapter == null) _msgAdapter = SmartDeviceLinkTester.getMessageAdapter();
+ if (_msgAdapter != null) _msgAdapter.logMessage("ProxyService.startProxy()", true);
+ else Log.i(TAG, "ProxyService.startProxy()");
+
+ if (_SmartDeviceLinkProxy == null) {
+ try {
+ SharedPreferences settings = getSharedPreferences(
+ Const.PREFS_NAME, 0);
+ boolean isMediaApp = settings.getBoolean(
+ Const.PREFS_KEY_ISMEDIAAPP,
+ Const.PREFS_DEFAULT_ISMEDIAAPP);
+ String appName = settings.getString(Const.PREFS_KEY_APPNAME,
+ Const.PREFS_DEFAULT_APPNAME);
+ int transportType = settings.getInt(
+ Const.Transport.PREFS_KEY_TRANSPORT_TYPE,
+ Const.Transport.PREFS_DEFAULT_TRANSPORT_TYPE);
+ String ipAddress = settings.getString(
+ Const.Transport.PREFS_KEY_TRANSPORT_IP,
+ Const.Transport.PREFS_DEFAULT_TRANSPORT_IP);
+ int tcpPort = settings.getInt(
+ Const.Transport.PREFS_KEY_TRANSPORT_PORT,
+ Const.Transport.PREFS_DEFAULT_TRANSPORT_PORT);
+ boolean autoReconnect = settings
+ .getBoolean(
+ Const.Transport.PREFS_KEY_TRANSPORT_RECONNECT,
+ Const.Transport.PREFS_DEFAULT_TRANSPORT_RECONNECT_DEFAULT);
+
+ if (transportType == Const.Transport.KEY_BLUETOOTH) {
+ _SmartDeviceLinkProxy = new SmartDeviceLinkProxyALM(this, appName, isMediaApp);
+ } else {
+ _SmartDeviceLinkProxy = new SmartDeviceLinkProxyALM(this, appName, isMediaApp,
+ new TCPTransportConfig(tcpPort, ipAddress, autoReconnect));
+ }
+ } catch (SmartDeviceLinkException e) {
+ e.printStackTrace();
+ //error creating proxy, returned proxy = null
+ if (_SmartDeviceLinkProxy == null){
+ stopSelf();
+ }
+ }
+ }
+ if (_msgAdapter == null) _msgAdapter = SmartDeviceLinkTester.getMessageAdapter();
+ if (_msgAdapter != null) _msgAdapter.logMessage("ProxyService.startProxy() returning", Log.INFO);
+ else Log.i(TAG, "ProxyService.startProxy() returning");
+ }
+
+ public void onDestroy() {
+ if (_msgAdapter == null) _msgAdapter = SmartDeviceLinkTester.getMessageAdapter();
+ if (_msgAdapter != null) _msgAdapter.logMessage("ProxyService.onDestroy()", Log.INFO);
+ else Log.i(TAG, "ProxyService.onDestroy()");
+
+ disposeSmartDeviceLinkProxy();
+ _instance = null;
+ if (embeddedAudioPlayer != null) embeddedAudioPlayer.release();
+ unregisterReceiver(mediaButtonReceiver);
+ super.onDestroy();
+ }
+
+ public void disposeSmartDeviceLinkProxy() {
+ if (_msgAdapter == null) _msgAdapter = SmartDeviceLinkTester.getMessageAdapter();
+ if (_msgAdapter != null) _msgAdapter.logMessage("ProxyService.disposeSmartDeviceLinkProxy()", Log.INFO);
+ else Log.i(TAG, "ProxyService.disposeSmartDeviceLinkProxy()");
+
+ if (_SmartDeviceLinkProxy != null) {
+ try {
+ _SmartDeviceLinkProxy.dispose();
+ } catch (SmartDeviceLinkException e) {
+ e.printStackTrace();
+ }
+ _SmartDeviceLinkProxy = null;
+ }
+ }
+
+ private void initialize() {
+ playingAudio = true;
+ playAnnoyingRepetitiveAudio();
+
+ try {
+ _SmartDeviceLinkProxy.show("SmartDeviceLink", "Tester", null, null, null, null, nextCorrID());
+ } catch (SmartDeviceLinkException e) {
+ if (_msgAdapter == null) _msgAdapter = SmartDeviceLinkTester.getMessageAdapter();
+ if (_msgAdapter != null) _msgAdapter.logMessage("Error sending show", Log.ERROR, e, true);
+ else Log.e(TAG, "Error sending show", e);
+ }
+
+ try {
+ _SmartDeviceLinkProxy.subscribeButton(ButtonName.OK, nextCorrID());
+ _SmartDeviceLinkProxy.subscribeButton(ButtonName.SEEKLEFT, nextCorrID());
+ _SmartDeviceLinkProxy.subscribeButton(ButtonName.SEEKRIGHT, nextCorrID());
+ _SmartDeviceLinkProxy.subscribeButton(ButtonName.TUNEUP, nextCorrID());
+ _SmartDeviceLinkProxy.subscribeButton(ButtonName.TUNEDOWN, nextCorrID());
+ Vector<ButtonName> buttons = new Vector<ButtonName>(Arrays.asList(new ButtonName[] {
+ ButtonName.OK, ButtonName.SEEKLEFT, ButtonName.SEEKRIGHT, ButtonName.TUNEUP,
+ ButtonName.TUNEDOWN }));
+ SmartDeviceLinkTester.getInstance().buttonsSubscribed(buttons);
+ } catch (SmartDeviceLinkException e) {
+ if (_msgAdapter == null) _msgAdapter = SmartDeviceLinkTester.getMessageAdapter();
+ if (_msgAdapter != null) _msgAdapter.logMessage("Error subscribing to buttons", Log.ERROR, e, true);
+ else Log.e(TAG, "Error subscribing to buttons", e);
+ }
+
+
+ try {
+ _SmartDeviceLinkProxy.addCommand(100, "XML Test", new Vector<String>(Arrays.asList(new String[] {"XML Test", "XML"})), nextCorrID());
+ } catch (SmartDeviceLinkException e) {
+ if (_msgAdapter == null) _msgAdapter = SmartDeviceLinkTester.getMessageAdapter();
+ if (_msgAdapter != null) _msgAdapter.logMessage("Error adding AddCommands", Log.ERROR, e, true);
+ else Log.e(TAG, "Error adding AddCommands", e);
+ }
+ }
+
+ public void playPauseAnnoyingRepetitiveAudio() {
+ if (embeddedAudioPlayer != null && embeddedAudioPlayer.isPlaying()) {
+ playingAudio = false;
+ pauseAnnoyingRepetitiveAudio();
+ } else {
+ playingAudio = true;
+ playAnnoyingRepetitiveAudio();
+ }
+ }
+
+ private void playAnnoyingRepetitiveAudio() {
+ if (embeddedAudioPlayer == null) {
+ embeddedAudioPlayer = MediaPlayer.create(this, R.raw.arco);
+ embeddedAudioPlayer.setLooping(true);
+ }
+ embeddedAudioPlayer.start();
+
+ if (_msgAdapter == null) _msgAdapter = SmartDeviceLinkTester.getMessageAdapter();
+ if (_msgAdapter != null) _msgAdapter.logMessage("Playing audio", true);
+ else Log.i(TAG, "Playing audio");
+ }
+
+ public void pauseAnnoyingRepetitiveAudio() {
+ if (embeddedAudioPlayer != null && embeddedAudioPlayer.isPlaying()) {
+ embeddedAudioPlayer.pause();
+
+ if (_msgAdapter == null) _msgAdapter = SmartDeviceLinkTester.getMessageAdapter();
+ if (_msgAdapter != null) _msgAdapter.logMessage("Paused audio", true);
+ else Log.i(TAG, "Paused audio");
+ }
+ }
+
+ public static SmartDeviceLinkProxyALM getProxyInstance() {
+ return _SmartDeviceLinkProxy;
+ }
+
+ public static ProxyService getInstance() {
+ return _instance;
+ }
+
+ public SmartDeviceLinkTester getCurrentActivity() {
+ return _mainInstance;
+ }
+
+ public void startModuleTest() {
+ _testerMain = new ModuleTest();
+ }
+
+ public static void waiting(boolean waiting) {
+ waitingForResponse = waiting;
+ }
+
+ public void setCurrentActivity(SmartDeviceLinkTester currentActivity) {
+ if (this._mainInstance != null) {
+ this._mainInstance.finish();
+ this._mainInstance = null;
+ }
+
+ this._mainInstance = currentActivity;
+ // update the _msgAdapter
+ _msgAdapter = SmartDeviceLinkTester.getMessageAdapter();
+ }
+
+ protected int nextCorrID() {
+ autoIncCorrId++;
+ return autoIncCorrId;
+ }
+
+ @Override
+ public void onOnHMIStatus(OnHMIStatus notification) {
+ if (_msgAdapter == null) _msgAdapter = SmartDeviceLinkTester.getMessageAdapter();
+ if (_msgAdapter != null) _msgAdapter.logMessage(notification, true);
+ else Log.i(TAG, "" + notification);
+
+ switch(notification.getSystemContext()) {
+ case SYSCTXT_MAIN:
+ break;
+ case SYSCTXT_VRSESSION:
+ break;
+ case SYSCTXT_MENU:
+ break;
+ default:
+ return;
+ }
+
+ switch(notification.getAudioStreamingState()) {
+ case AUDIBLE:
+ if (playingAudio) playAnnoyingRepetitiveAudio();
+ break;
+ case NOT_AUDIBLE:
+ pauseAnnoyingRepetitiveAudio();
+ break;
+ default:
+ return;
+ }
+
+ switch(notification.getHmiLevel()) {
+ case HMI_FULL:
+ if (notification.getFirstRun()) {
+ showLockMain();
+ _testerMain = new ModuleTest();
+ _testerMain = ModuleTest.getModuleTestInstance();
+ initialize();
+ }
+ else {
+ try {
+ if (!waitingForResponse && _testerMain.getThreadContext() != null) {
+ _SmartDeviceLinkProxy.show("SmartDeviceLink Proxy", "Tester Ready", null, null, null, null, nextCorrID());
+ }
+ } catch (SmartDeviceLinkException e) {
+ if (_msgAdapter == null) _msgAdapter = SmartDeviceLinkTester.getMessageAdapter();
+ if (_msgAdapter != null) _msgAdapter.logMessage("Error sending show", Log.ERROR, e, true);
+ else Log.e(TAG, "Error sending show", e);
+ }
+ }
+ break;
+ case HMI_LIMITED:
+ break;
+ case HMI_BACKGROUND:
+ break;
+ case HMI_NONE:
+ break;
+ default:
+ return;
+ }
+ }
+
+ @Override
+ public void onOnCommand(OnCommand notification) {
+ if (_msgAdapter == null) _msgAdapter = SmartDeviceLinkTester.getMessageAdapter();
+ if (_msgAdapter != null) _msgAdapter.logMessage(notification, true);
+ else Log.i(TAG, "" + notification);
+
+ switch(notification.getCmdID())
+ {
+ case 100: //XML Test
+ _testerMain.restart();
+ break;
+ default:
+ break;
+ }
+ }
+
+ @Override
+ public void onProxyClosed(String info, Exception e) {
+ if (_msgAdapter == null) _msgAdapter = SmartDeviceLinkTester.getMessageAdapter();
+ if (_msgAdapter != null) _msgAdapter.logMessage("onProxyClosed: " + info, Log.ERROR, e);
+ else Log.e(TAG, "onProxyClosed: " + info, e);
+
+ boolean wasConnected = !firstHMIStatusChange;
+ firstHMIStatusChange = true;
+
+ if (wasConnected) {
+ final SmartDeviceLinkTester mainActivity = SmartDeviceLinkTester.getInstance();
+ if (mainActivity != null) {
+ mainActivity.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ mainActivity.onProxyClosed();
+ }
+ });
+ } else {
+ Log.w(TAG, "mainActivity not found");
+ }
+ }
+
+ if(((SmartDeviceLinkException) e).getSmartDeviceLinkExceptionCause() != SmartDeviceLinkExceptionCause.SMARTDEVICELINK_PROXY_CYCLED
+ && ((SmartDeviceLinkException) e).getSmartDeviceLinkExceptionCause() != SmartDeviceLinkExceptionCause.BLUETOOTH_DISABLED) {
+ reset();
+ }
+ }
+
+ public void reset(){
+ try {
+ if (_SmartDeviceLinkProxy != null) _SmartDeviceLinkProxy.resetProxy();
+ else startProxyIfNetworkConnected();
+ } catch (SmartDeviceLinkException e1) {
+ e1.printStackTrace();
+ //something goes wrong, & the proxy returns as null, stop the service.
+ //do not want a running service with a null proxy
+ if (_SmartDeviceLinkProxy == null){
+ stopSelf();
+ }
+ }
+ }
+
+ /**
+ * Restarting SmartDeviceLinkProxyALM. For example after changing transport type
+ */
+ public void restart() {
+ Log.i(TAG, "ProxyService.Restart SmartDeviceLinkProxyALM.");
+ disposeSmartDeviceLinkProxy();
+ startProxyIfNetworkConnected();
+ }
+
+ @Override
+ public void onError(String info, Exception e) {
+ if (_msgAdapter == null) _msgAdapter = SmartDeviceLinkTester.getMessageAdapter();
+ if (_msgAdapter != null) {
+ _msgAdapter.logMessage("******onProxyError******", Log.ERROR);
+ _msgAdapter.logMessage("ERROR: " + info, Log.ERROR, e);
+ } else {
+ Log.e(TAG, "******onProxyError******");
+ Log.e(TAG, "ERROR: " + info, e);
+ }
+ }
+
+ /*********************************
+ ** SmartDeviceLink SmartDeviceLink Base Callback's **
+ *********************************/
+ @Override
+ public void onAddSubMenuResponse(AddSubMenuResponse response) {
+ if (_msgAdapter == null) _msgAdapter = SmartDeviceLinkTester.getMessageAdapter();
+ if (_msgAdapter != null) _msgAdapter.logMessage(response, true);
+ else Log.i(TAG, "" + response);
+
+ if (waitingForResponse && _testerMain.getThreadContext() != null) {
+ ModuleTest.responses.add(new Pair<Integer, Result>(response.getCorrelationID(), response.getResultCode()));
+ synchronized (_testerMain.getThreadContext()) { _testerMain.getThreadContext().notify();};
+ }
+ }
+ @Override
+ public void onCreateInteractionChoiceSetResponse(CreateInteractionChoiceSetResponse response) {
+ if (_msgAdapter == null) _msgAdapter = SmartDeviceLinkTester.getMessageAdapter();
+ if (_msgAdapter != null) _msgAdapter.logMessage(response, true);
+ else Log.i(TAG, "" + response);
+
+ final SmartDeviceLinkTester mainActivity = SmartDeviceLinkTester.getInstance();
+ final boolean success = response.getSuccess();
+ mainActivity.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ mainActivity.onCreateChoiceSetResponse(success);
+ }
+ });
+
+ if (waitingForResponse && _testerMain.getThreadContext() != null) {
+ ModuleTest.responses.add(new Pair<Integer, Result>(response.getCorrelationID(), response.getResultCode()));
+ synchronized (_testerMain.getThreadContext()) { _testerMain.getThreadContext().notify();};
+ }
+ }
+ @Override
+ public void onDeleteCommandResponse(DeleteCommandResponse response) {
+ if (_msgAdapter == null) _msgAdapter = SmartDeviceLinkTester.getMessageAdapter();
+ if (_msgAdapter != null) _msgAdapter.logMessage(response, true);
+ else Log.i(TAG, "" + response);
+
+ if (waitingForResponse && _testerMain.getThreadContext() != null) {
+ ModuleTest.responses.add(new Pair<Integer, Result>(response.getCorrelationID(), response.getResultCode()));
+ synchronized (_testerMain.getThreadContext()) { _testerMain.getThreadContext().notify();};
+ }
+ }
+ @Override
+ public void onDeleteInteractionChoiceSetResponse(DeleteInteractionChoiceSetResponse response) {
+ if (_msgAdapter == null) _msgAdapter = SmartDeviceLinkTester.getMessageAdapter();
+ if (_msgAdapter != null) _msgAdapter.logMessage(response, true);
+ else Log.i(TAG, "" + response);
+
+ if (waitingForResponse && _testerMain.getThreadContext() != null) {
+ ModuleTest.responses.add(new Pair<Integer, Result>(response.getCorrelationID(), response.getResultCode()));
+ synchronized (_testerMain.getThreadContext()) { _testerMain.getThreadContext().notify();};
+ }
+ }
+ @Override
+ public void onDeleteSubMenuResponse(DeleteSubMenuResponse response) {
+ if (_msgAdapter == null) _msgAdapter = SmartDeviceLinkTester.getMessageAdapter();
+ if (_msgAdapter != null) _msgAdapter.logMessage(response, true);
+ else Log.i(TAG, "" + response);
+
+ if (waitingForResponse && _testerMain.getThreadContext() != null) {
+ ModuleTest.responses.add(new Pair<Integer, Result>(response.getCorrelationID(), response.getResultCode()));
+ synchronized (_testerMain.getThreadContext()) { _testerMain.getThreadContext().notify();};
+ }
+ }
+ @Override
+ public void onEncodedSyncPDataResponse(EncodedSyncPDataResponse response) {
+ Log.i("SmartDeviceLinkp", response.getInfo() + response.getResultCode() + response.getSuccess());
+ if (_msgAdapter == null) _msgAdapter = SmartDeviceLinkTester.getMessageAdapter();
+ if (_msgAdapter != null) _msgAdapter.logMessage(response, true);
+ else Log.i(TAG, "" + response);
+
+ if (waitingForResponse && _testerMain.getThreadContext() != null) {
+ ModuleTest.responses.add(new Pair<Integer, Result>(response.getCorrelationID(), response.getResultCode()));
+ synchronized (_testerMain.getThreadContext()) { _testerMain.getThreadContext().notify();};
+ }
+ }
+ @Override
+ public void onResetGlobalPropertiesResponse(ResetGlobalPropertiesResponse response) {
+ if (_msgAdapter == null) _msgAdapter = SmartDeviceLinkTester.getMessageAdapter();
+ if (_msgAdapter != null) _msgAdapter.logMessage(response, true);
+ else Log.i(TAG, "" + response);
+
+ if (waitingForResponse && _testerMain.getThreadContext() != null) {
+ ModuleTest.responses.add(new Pair<Integer, Result>(response.getCorrelationID(), response.getResultCode()));
+ synchronized (_testerMain.getThreadContext()) { _testerMain.getThreadContext().notify();};
+ }
+ }
+ @Override
+ public void onSetMediaClockTimerResponse(SetMediaClockTimerResponse response) {
+ if (_msgAdapter == null) _msgAdapter = SmartDeviceLinkTester.getMessageAdapter();
+ if (_msgAdapter != null) _msgAdapter.logMessage(response, true);
+ else Log.i(TAG, "" + response);
+
+ if (waitingForResponse && _testerMain.getThreadContext() != null) {
+ ModuleTest.responses.add(new Pair<Integer, Result>(response.getCorrelationID(), response.getResultCode()));
+ synchronized (_testerMain.getThreadContext()) { _testerMain.getThreadContext().notify();};
+ }
+ }
+ @Override
+ public void onSpeakResponse(SpeakResponse response) {
+ if (_msgAdapter == null) _msgAdapter = SmartDeviceLinkTester.getMessageAdapter();
+ if (_msgAdapter != null) _msgAdapter.logMessage(response, true);
+ else Log.i(TAG, "" + response);
+
+ if (waitingForResponse && _testerMain.getThreadContext() != null) {
+ ModuleTest.responses.add(new Pair<Integer, Result>(response.getCorrelationID(), response.getResultCode()));
+ synchronized (_testerMain.getThreadContext()) { _testerMain.getThreadContext().notify();};
+ }
+ }
+ @Override
+ public void onSubscribeButtonResponse(SubscribeButtonResponse response) {
+ if (_msgAdapter == null) _msgAdapter = SmartDeviceLinkTester.getMessageAdapter();
+ if (_msgAdapter != null) _msgAdapter.logMessage(response, true);
+ else Log.i(TAG, "" + response);
+
+ if (waitingForResponse && _testerMain.getThreadContext() != null) {
+ ModuleTest.responses.add(new Pair<Integer, Result>(response.getCorrelationID(), response.getResultCode()));
+ synchronized (_testerMain.getThreadContext()) { _testerMain.getThreadContext().notify();};
+ }
+ }
+ @Override
+ public void onUnsubscribeButtonResponse(UnsubscribeButtonResponse response) {
+ if (_msgAdapter == null) _msgAdapter = SmartDeviceLinkTester.getMessageAdapter();
+ if (_msgAdapter != null) _msgAdapter.logMessage(response, true);
+ else Log.i(TAG, "" + response);
+
+ if (waitingForResponse && _testerMain.getThreadContext() != null) {
+ ModuleTest.responses.add(new Pair<Integer, Result>(response.getCorrelationID(), response.getResultCode()));
+ synchronized (_testerMain.getThreadContext()) { _testerMain.getThreadContext().notify();};
+ }
+ }
+ @Override
+ public void onOnDriverDistraction(OnDriverDistraction notification) {
+ if (_msgAdapter == null) _msgAdapter = SmartDeviceLinkTester.getMessageAdapter();
+ if (_msgAdapter != null) _msgAdapter.logMessage(notification, true);
+ else Log.i(TAG, "" + notification);
+ }
+ @Override
+ public void onGenericResponse(GenericResponse response) {
+ if (_msgAdapter == null) _msgAdapter = SmartDeviceLinkTester.getMessageAdapter();
+ if (_msgAdapter != null) _msgAdapter.logMessage(response, true);
+ else Log.i(TAG, "" + response);
+
+ if (waitingForResponse && _testerMain.getThreadContext() != null) {
+ ModuleTest.responses.add(new Pair<Integer, Result>(response.getCorrelationID(), response.getResultCode()));
+ synchronized (_testerMain.getThreadContext()) { _testerMain.getThreadContext().notify();};
+ }
+ }
+ @Override
+ public void onOnButtonEvent(OnButtonEvent notification) {
+ if (_msgAdapter == null) _msgAdapter = SmartDeviceLinkTester.getMessageAdapter();
+ if (_msgAdapter != null) _msgAdapter.logMessage(notification, true);
+ else Log.i(TAG, "" + notification);
+ }
+ @Override
+ public void onOnButtonPress(OnButtonPress notification) {
+ if (_msgAdapter == null) _msgAdapter = SmartDeviceLinkTester.getMessageAdapter();
+ if (_msgAdapter != null) _msgAdapter.logMessage(notification, true);
+ else Log.i(TAG, "" + notification);
+
+ switch(notification.getButtonName())
+ {
+ case OK:
+ playPauseAnnoyingRepetitiveAudio();
+ break;
+ case SEEKLEFT:
+ break;
+ case SEEKRIGHT:
+ break;
+ case TUNEUP:
+ break;
+ case TUNEDOWN:
+ break;
+ default:
+ break;
+ }
+ }
+
+ /*********************************
+ ** SmartDeviceLink SmartDeviceLink Updated Callback's **
+ *********************************/
+ @Override
+ public void onAddCommandResponse(AddCommandResponse response) {
+ if (_msgAdapter == null) _msgAdapter = SmartDeviceLinkTester.getMessageAdapter();
+ if (_msgAdapter != null) _msgAdapter.logMessage(response, true);
+ else Log.i(TAG, "" + response);
+
+ if (waitingForResponse && _testerMain.getThreadContext() != null) {
+ ModuleTest.responses.add(new Pair<Integer, Result>(response.getCorrelationID(), response.getResultCode()));
+ synchronized (_testerMain.getThreadContext()) { _testerMain.getThreadContext().notify();};
+ }
+ }
+ @Override
+ public void onAlertResponse(AlertResponse response) {
+ if (_msgAdapter == null) _msgAdapter = SmartDeviceLinkTester.getMessageAdapter();
+ if (_msgAdapter != null) _msgAdapter.logMessage(response, true);
+ else Log.i(TAG, "" + response);
+
+ if (waitingForResponse && _testerMain.getThreadContext() != null) {
+ ModuleTest.responses.add(new Pair<Integer, Result>(response.getCorrelationID(), response.getResultCode()));
+ synchronized (_testerMain.getThreadContext()) { _testerMain.getThreadContext().notify();};
+ }
+ }
+ @Override
+ public void onPerformInteractionResponse(PerformInteractionResponse response) {
+ if (_msgAdapter == null) _msgAdapter = SmartDeviceLinkTester.getMessageAdapter();
+ if (_msgAdapter != null) _msgAdapter.logMessage(response, true);
+ else Log.i(TAG, "" + response);
+
+ if (waitingForResponse && _testerMain.getThreadContext() != null) {
+ ModuleTest.responses.add(new Pair<Integer, Result>(response.getCorrelationID(), response.getResultCode()));
+ synchronized (_testerMain.getThreadContext()) { _testerMain.getThreadContext().notify();};
+ }
+ }
+ @Override
+ public void onSetGlobalPropertiesResponse(SetGlobalPropertiesResponse response) {
+ if (_msgAdapter == null) _msgAdapter = SmartDeviceLinkTester.getMessageAdapter();
+ if (_msgAdapter != null) _msgAdapter.logMessage(response, true);
+ else Log.i(TAG, "" + response);
+
+ if (waitingForResponse && _testerMain.getThreadContext() != null) {
+ ModuleTest.responses.add(new Pair<Integer, Result>(response.getCorrelationID(), response.getResultCode()));
+ synchronized (_testerMain.getThreadContext()) { _testerMain.getThreadContext().notify();};
+ }
+ }
+ @Override
+ public void onShowResponse(ShowResponse response) {
+ if (_msgAdapter == null) _msgAdapter = SmartDeviceLinkTester.getMessageAdapter();
+ if (_msgAdapter != null) _msgAdapter.logMessage(response, true);
+ else Log.i(TAG, "" + response);
+
+ if (waitingForResponse && _testerMain.getThreadContext() != null) {
+ ModuleTest.responses.add(new Pair<Integer, Result>(response.getCorrelationID(), response.getResultCode()));
+ synchronized (_testerMain.getThreadContext()) { _testerMain.getThreadContext().notify();};
+ }
+ }
+ @Override
+ public void onOnTBTClientState(OnTBTClientState notification) {
+ if (_msgAdapter == null) _msgAdapter = SmartDeviceLinkTester.getMessageAdapter();
+ if (_msgAdapter != null) _msgAdapter.logMessage(notification, true);
+ else Log.i(TAG, "" + notification);
+ }
+
+ /*********************************
+ ** SmartDeviceLink SmartDeviceLink Policies Callback's **
+ *********************************/
+ @Override
+ public void onOnPermissionsChange(OnPermissionsChange notification) {
+ if (_msgAdapter == null) _msgAdapter = SmartDeviceLinkTester.getMessageAdapter();
+ if (_msgAdapter != null) _msgAdapter.logMessage(notification, true);
+ else Log.i(TAG, "" + notification);
+ }
+ @Override
+ public void onOnEncodedSyncPData(OnEncodedSyncPData notification) {
+ if (_msgAdapter == null) _msgAdapter = SmartDeviceLinkTester.getMessageAdapter();
+ if (_msgAdapter != null) _msgAdapter.logMessage(notification, true);
+ else Log.i(TAG, "" + notification);
+ }
+ @Override
+ public IBinder onBind(Intent intent) {
+ if (_msgAdapter == null) _msgAdapter = SmartDeviceLinkTester.getMessageAdapter();
+ if (_msgAdapter != null) _msgAdapter.logMessage("Service on Bind");
+ else Log.i(TAG, "Service on Bind");
+ return new Binder();
+ }
+}