Tel Test Script: Remove "xxxEvent+subEvent" style event from Telephony test code.

Replace subEvent String to Constants
b/22063774

Change-Id: Ib2487566dcd2f0febed536ab64b12ba15333f4eb
diff --git a/Common/src/com/googlecode/android_scripting/facade/tele/PhoneFacade.java b/Common/src/com/googlecode/android_scripting/facade/tele/PhoneFacade.java
index 47e176e..ca8aab5 100644
--- a/Common/src/com/googlecode/android_scripting/facade/tele/PhoneFacade.java
+++ b/Common/src/com/googlecode/android_scripting/facade/tele/PhoneFacade.java
@@ -376,11 +376,11 @@
                    Boolean listen,
                    @RpcParameter(name = "subId") Integer subId) {
         try {
-            if (type.equals("Foreground")) {
+            if (type.equals(TelephonyConstants.PRECISE_CALL_STATE_LISTEN_LEVEL_FOREGROUND)) {
                 StateChangeListeners.get(subId).mCallStateChangeListener.listenForeground = listen;
-            } else if (type.equals("Ringing")) {
+            } else if (type.equals(TelephonyConstants.PRECISE_CALL_STATE_LISTEN_LEVEL_RINGING)) {
                 StateChangeListeners.get(subId).mCallStateChangeListener.listenRinging = listen;
-            } else if (type.equals("Background")) {
+            } else if (type.equals(TelephonyConstants.PRECISE_CALL_STATE_LISTEN_LEVEL_BACKGROUND)) {
                 StateChangeListeners.get(subId).mCallStateChangeListener.listenBackground = listen;
             }
             return true;
diff --git a/Common/src/com/googlecode/android_scripting/facade/tele/TelephonyConstants.java b/Common/src/com/googlecode/android_scripting/facade/tele/TelephonyConstants.java
index ef265e5..f9ac7e7 100644
--- a/Common/src/com/googlecode/android_scripting/facade/tele/TelephonyConstants.java
+++ b/Common/src/com/googlecode/android_scripting/facade/tele/TelephonyConstants.java
@@ -48,6 +48,29 @@
     public static final String CALL_STATE_INVALID = "INVALID";
 
     /**
+     * Constant for PRECISE Call State (for call object)
+     * **/
+    public static final String PRECISE_CALL_STATE_ACTIVE = "ACTIVE";
+    public static final String PRECISE_CALL_STATE_ALERTING = "ALERTING";
+    public static final String PRECISE_CALL_STATE_DIALING = "DIALING";
+    public static final String PRECISE_CALL_STATE_INCOMING = "INCOMING";
+    public static final String PRECISE_CALL_STATE_HOLDING = "HOLDING";
+    public static final String PRECISE_CALL_STATE_DISCONNECTED = "DISCONNECTED";
+    public static final String PRECISE_CALL_STATE_WAITING = "WAITING";
+    public static final String PRECISE_CALL_STATE_DISCONNECTING = "DISCONNECTING";
+    public static final String PRECISE_CALL_STATE_IDLE = "IDLE";
+    public static final String PRECISE_CALL_STATE_UNKNOWN = "UNKNOWN";
+    public static final String PRECISE_CALL_STATE_INVALID = "INVALID";
+
+    /**
+     * Constant for DC POWER STATE
+     * **/
+    public static final String DC_POWER_STATE_LOW = "LOW";
+    public static final String DC_POWER_STATE_HIGH = "HIGH";
+    public static final String DC_POWER_STATE_MEDIUM = "MEDIUM";
+    public static final String DC_POWER_STATE_UNKNOWN = "UNKNOWN";
+
+    /**
      * Constant for Audio Route
      * **/
     public static final String AUDIO_ROUTE_EARPIECE = "EARPIECE";
@@ -192,6 +215,13 @@
     public static final String VOLTE_SERVICE_STATE_HANDOVER_UNKNOWN = "UNKNOWN";
 
     /**
+     * Constant for precise call state state listen level
+     * **/
+    public static final String PRECISE_CALL_STATE_LISTEN_LEVEL_FOREGROUND = "FOREGROUND";
+    public static final String PRECISE_CALL_STATE_LISTEN_LEVEL_RINGING = "RINGING";
+    public static final String PRECISE_CALL_STATE_LISTEN_LEVEL_BACKGROUND = "BACKGROUND";
+
+    /**
      * Constant for Messaging Event Name
      * **/
     public static final String EventSmsDeliverSuccess = "SmsDeliverSuccess";
diff --git a/Common/src/com/googlecode/android_scripting/facade/tele/TelephonyStateListeners.java b/Common/src/com/googlecode/android_scripting/facade/tele/TelephonyStateListeners.java
index caa4681..1c4bd1e 100644
--- a/Common/src/com/googlecode/android_scripting/facade/tele/TelephonyStateListeners.java
+++ b/Common/src/com/googlecode/android_scripting/facade/tele/TelephonyStateListeners.java
@@ -65,19 +65,18 @@
             }
             switch (state) {
                 case TelephonyManager.CALL_STATE_IDLE:
-                    subEvent = "Idle";
+                    subEvent = TelephonyConstants.TELEPHONY_STATE_IDLE;
                     break;
                 case TelephonyManager.CALL_STATE_OFFHOOK:
-                    subEvent = "Offhook";
+                    subEvent = TelephonyConstants.TELEPHONY_STATE_OFFHOOK;
                     break;
                 case TelephonyManager.CALL_STATE_RINGING:
-                    subEvent = "Ringing";
+                    subEvent = TelephonyConstants.TELEPHONY_STATE_RINGING;
                     break;
             }
             mCallStateEvent.putInt("subscriptionId", subscriptionId);
-            // TODO: b/22063774 remove "xxxEvent+subEvent" style event name.
-            mEventFacade.postEvent(TelephonyConstants.EventCallStateChanged+subEvent,
-                                   mCallStateEvent);
+            mCallStateEvent.putString("subEvent", subEvent);
+            mEventFacade.postEvent(TelephonyConstants.EventCallStateChanged, mCallStateEvent);
         }
 
         @Override
@@ -87,15 +86,21 @@
             int backgroundState = callState.getBackgroundCallState();
             if (listenForeground &&
                 foregroundState != PreciseCallState.PRECISE_CALL_STATE_NOT_VALID) {
-                processCallState(foregroundState, "Foreground", callState);
+                processCallState(foregroundState,
+                        TelephonyConstants.PRECISE_CALL_STATE_LISTEN_LEVEL_FOREGROUND,
+                        callState);
             }
             if (listenRinging &&
                 ringingState != PreciseCallState.PRECISE_CALL_STATE_NOT_VALID) {
-                processCallState(ringingState, "Ringing", callState);
+                processCallState(ringingState,
+                        TelephonyConstants.PRECISE_CALL_STATE_LISTEN_LEVEL_RINGING,
+                        callState);
             }
             if (listenBackground &&
                 backgroundState != PreciseCallState.PRECISE_CALL_STATE_NOT_VALID) {
-                processCallState(backgroundState, "Background", callState);
+                processCallState(backgroundState,
+                        TelephonyConstants.PRECISE_CALL_STATE_LISTEN_LEVEL_BACKGROUND,
+                        callState);
             }
         }
 
@@ -104,29 +109,30 @@
             String subEvent = null;
             EventMsg.putString("Type", which);
             if (newState == PreciseCallState.PRECISE_CALL_STATE_ACTIVE) {
-                subEvent = "Active";
+                subEvent = TelephonyConstants.PRECISE_CALL_STATE_ACTIVE;
             } else if (newState == PreciseCallState.PRECISE_CALL_STATE_HOLDING) {
-                subEvent = "Holding";
+                subEvent = TelephonyConstants.PRECISE_CALL_STATE_HOLDING;
             } else if (newState == PreciseCallState.PRECISE_CALL_STATE_DIALING) {
-                subEvent = "Dialing";
+                subEvent = TelephonyConstants.PRECISE_CALL_STATE_DIALING;
             } else if (newState == PreciseCallState.PRECISE_CALL_STATE_ALERTING) {
-                subEvent = "Alerting";
+                subEvent = TelephonyConstants.PRECISE_CALL_STATE_ALERTING;
             } else if (newState == PreciseCallState.PRECISE_CALL_STATE_INCOMING) {
-                subEvent = "Incoming";
+                subEvent = TelephonyConstants.PRECISE_CALL_STATE_INCOMING;
             } else if (newState == PreciseCallState.PRECISE_CALL_STATE_WAITING) {
-                subEvent = "Waiting";
+                subEvent = TelephonyConstants.PRECISE_CALL_STATE_WAITING;
             } else if (newState == PreciseCallState.PRECISE_CALL_STATE_DISCONNECTED) {
-                subEvent = "Disconnected";
+                subEvent = TelephonyConstants.PRECISE_CALL_STATE_DISCONNECTED;
                 EventMsg.putInt("Cause", callState.getPreciseDisconnectCause());
             } else if (newState == PreciseCallState.PRECISE_CALL_STATE_DISCONNECTING) {
-                subEvent = "Disconnecting";
+                subEvent = TelephonyConstants.PRECISE_CALL_STATE_DISCONNECTING;
             } else if (newState == PreciseCallState.PRECISE_CALL_STATE_IDLE) {
-                subEvent = "Idle";
+                subEvent = TelephonyConstants.PRECISE_CALL_STATE_IDLE;
+            } else if (newState == PreciseCallState.PRECISE_CALL_STATE_NOT_VALID) {
+                subEvent = TelephonyConstants.PRECISE_CALL_STATE_INVALID;
             }
             EventMsg.putInt("subscriptionId", subscriptionId);
-            // TODO: b/22063774 remove "xxxEvent+subEvent" style event name.
-            mEventFacade.postEvent(TelephonyConstants.EventPreciseStateChanged+subEvent,
-                                   EventMsg);
+            EventMsg.putString("subEvent", subEvent);
+            mEventFacade.postEvent(TelephonyConstants.EventPreciseStateChanged, EventMsg);
         }
     }
 
@@ -158,19 +164,17 @@
 
             int state = dcRtInfo.getDcPowerState();
             if (state == DataConnectionRealTimeInfo.DC_POWER_STATE_LOW) {
-                subEvent = "Low";
+                subEvent = TelephonyConstants.DC_POWER_STATE_LOW;
             } else if (state == DataConnectionRealTimeInfo.DC_POWER_STATE_HIGH) {
-                subEvent = "High";
+                subEvent = TelephonyConstants.DC_POWER_STATE_HIGH;
             } else if (state == DataConnectionRealTimeInfo.DC_POWER_STATE_MEDIUM) {
-                subEvent = "Medium";
+                subEvent = TelephonyConstants.DC_POWER_STATE_MEDIUM;
             } else if (state == DataConnectionRealTimeInfo.DC_POWER_STATE_UNKNOWN) {
-                subEvent = "Unknown";
+                subEvent = TelephonyConstants.DC_POWER_STATE_UNKNOWN;
             }
             event.putInt("subscriptionId", subscriptionId);
-            // TODO: b/22063774 remove "xxxEvent+subEvent" style event name.
-            mEventFacade.postEvent(TelephonyConstants.EventDataConnectionRealTimeInfoChanged+subEvent,
-                                   event);
-
+            event.putString("subEvent", subEvent);
+            mEventFacade.postEvent(TelephonyConstants.EventDataConnectionRealTimeInfoChanged, event);
         }
     }
 
@@ -202,25 +206,24 @@
             String subEvent = null;
             event.putString("Type", "DataConnectionState");
             if (state == TelephonyManager.DATA_DISCONNECTED) {
-                subEvent = "Disconnected";
+                subEvent = TelephonyConstants.DATA_STATE_DISCONNECTED;
             } else if (state == TelephonyManager.DATA_CONNECTING) {
-                subEvent = "Connecting";
+                subEvent = TelephonyConstants.DATA_STATE_CONNECTING;
             } else if (state == TelephonyManager.DATA_CONNECTED) {
-                subEvent = "Connected";
+                subEvent = TelephonyConstants.DATA_STATE_CONNECTED;
                 event.putString("DataNetworkType", TelephonyUtils.getNetworkTypeString(
                                  mTelephonyManager.getDataNetworkType()));
             } else if (state == TelephonyManager.DATA_SUSPENDED) {
-                subEvent = "Suspended";
+                subEvent = TelephonyConstants.DATA_STATE_SUSPENDED;
             } else if (state == TelephonyManager.DATA_UNKNOWN) {
-                subEvent = "Unknown";
+                subEvent = TelephonyConstants.DATA_STATE_UNKNOWN;
             } else {
                 subEvent = "UnknownStateCode";
                 event.putInt("UnknownStateCode", state);
             }
             event.putInt("subscriptionId", subscriptionId);
-            // TODO: b/22063774 remove "xxxEvent+subEvent" style event name.
-            mEventFacade.postEvent(TelephonyConstants.EventDataConnectionStateChanged+subEvent,
-                                   event);
+            event.putString("subEvent", subEvent);
+            mEventFacade.postEvent(TelephonyConstants.EventDataConnectionStateChanged, event);
         }
     }
 
@@ -246,20 +249,21 @@
         public void onServiceStateChanged(ServiceState serviceState) {
             Bundle event = new Bundle();
             String subEvent = null;
+            String networkRat = null;
             switch(serviceState.getState()) {
                 case ServiceState.STATE_EMERGENCY_ONLY:
-                    subEvent = "EmergencyOnly";
+                    subEvent = TelephonyConstants.SERVICE_STATE_EMERGENCY_ONLY;
                 break;
                 case ServiceState.STATE_IN_SERVICE:
-                    subEvent = "InService";
+                    subEvent = TelephonyConstants.SERVICE_STATE_IN_SERVICE;
                 break;
                 case ServiceState.STATE_OUT_OF_SERVICE:
-                    subEvent = "OutOfService";
+                    subEvent = TelephonyConstants.SERVICE_STATE_OUT_OF_SERVICE;
                     if(serviceState.isEmergencyOnly())
-                        subEvent = "EmergencyOnly";
+                        subEvent = TelephonyConstants.SERVICE_STATE_EMERGENCY_ONLY;
                 break;
                 case ServiceState.STATE_POWER_OFF:
-                    subEvent = "PowerOff";
+                    subEvent = TelephonyConstants.SERVICE_STATE_POWER_OFF;
                 break;
             }
             event.putString("VoiceRegState", TelephonyUtils.getNetworkStateString(
@@ -281,20 +285,22 @@
             if(subEvent.equals("InService")) {
                 switch(serviceState.getVoiceNetworkType()) {
                     case TelephonyManager.NETWORK_TYPE_LTE:
-                        subEvent = subEvent + TelephonyConstants.RAT_LTE;
+                        networkRat = TelephonyConstants.RAT_LTE;
                         break;
                     case TelephonyManager.NETWORK_TYPE_UMTS:
-                        subEvent = subEvent + TelephonyConstants.RAT_UMTS;
+                        networkRat = TelephonyConstants.RAT_UMTS;
                         break;
                     case TelephonyManager.NETWORK_TYPE_GSM:
-                        subEvent = subEvent + TelephonyConstants.RAT_GSM;
+                        networkRat = TelephonyConstants.RAT_GSM;
                         break;
                 }
+                if (networkRat != null) {
+                    event.putString("networkRat", networkRat);
+                }
             }
             event.putInt("subscriptionId", subscriptionId);
-            // TODO: b/22063774 remove "xxxEvent+subEvent" style event name.
-            mEventFacade.postEvent(TelephonyConstants.EventServiceStateChanged+subEvent,
-                                   event);
+            event.putString("subEvent", subEvent);
+            mEventFacade.postEvent(TelephonyConstants.EventServiceStateChanged, event);
         }
     }