<!-- 
/* ************************************************************************
 * FILENAME: proximityaction.rul
 * Copyright Sony Ericsson Mobile Communications AB/LTD/INC 2008/2009. All rights reserved.
 *
 * The program(s) may be used and/or copied only with the written permission
 * from Sony Ericsson Mobile Communications AB or in accordance with the terms
 * and conditions stipulated in the agreement/contract under which the
 * program(s) have been supplied.
 ************************************************************************ */
-->

<script xmlns="http://www.nokia.com/ns/cep/script/1.0/" xmlns:cep="http://www.nokia.com/ns/cep/1.0/">

<!-- Disable touch and turn off system target when close proximity is detected during a call-->
    <if>
        <and>
            <!-- Check that we receive Proximity Sensor context changes -->
            <contextChanged>
                <contextRef source='Sensor' type='Event.Proximity'/>
            </contextChanged>
            <!-- Check that close proximity is detected -->
            <equals>
                <contextRef source='Sensor' type='Event.Proximity'/>
                <string>Discernible</string>
            </equals>
            <or>
                <equals>
                    <contextRef source='Call' type='State'/>
                    <string>Dialling</string>
                </equals>
                <equals>
                    <contextRef source='Call' type='State'/>
                    <string>Connecting</string>
                </equals>
                <equals>
                    <contextRef source='Call' type='State'/>
                    <string>Ringing</string>
                </equals>
                <equals>
                    <contextRef source='Call' type='State'/>
                    <string>Answering</string>
                </equals>
                <equals>
                    <contextRef source='Call' type='State'/>
                    <string>Alerting</string>
                </equals>
                <equals>
                    <contextRef source='Call' type='State'/>
                    <string>Connected</string>
                </equals>
                <equals>
                    <contextRef source='Call' type='State'/>
                    <string>Hold</string>
                </equals>
            </or>
        </and>        
        <actions>
            <!-- Trigger action plug in to disable touch func and turn of backlight -->
            <Proximity Mode='Disable'/>
        </actions>
    </if>

<!-- Enable touch and turn on system target when no close proximity is detected during a call -->
    <elseIf>
        <and>
            <!-- Check that we receive Proximity Sensor context changes -->
            <contextChanged>
                <contextRef source='Sensor' type='Event.Proximity'/>
            </contextChanged>
            <!-- Check that no close proximity is detected -->
            <equals>
                <contextRef source='Sensor' type='Event.Proximity'/>
                <string>Indiscernible</string>
            </equals>
            <or>
                <equals>
                    <contextRef source='Call' type='State'/>
                    <string>Dialling</string>
                </equals>
                <equals>
                    <contextRef source='Call' type='State'/>
                    <string>Connecting</string>
                </equals>
                <equals>
                    <contextRef source='Call' type='State'/>
                    <string>Ringing</string>
                </equals>
                <equals>
                    <contextRef source='Call' type='State'/>
                    <string>Answering</string>
                </equals>
                <equals>
                    <contextRef source='Call' type='State'/>
                    <string>Alerting</string>
                </equals>
                <equals>
                    <contextRef source='Call' type='State'/>
                    <string>Connected</string>
                </equals>
                <equals>
                    <contextRef source='Call' type='State'/>
                    <string>Hold</string>
                </equals>
            </or>
        </and>
        <actions>
            <!-- Trigger action plug in to disable touch func and turn of backlight -->
            <Proximity Mode='Enable'/>
        </actions>
    </elseIf>
    
<!-- Activate the proximity sensor when call state is 'Ringing' or 'Dialing' -->
    <elseIf>
        <or>
            <and>
                <!-- New call state event received from call state source with value 'Answering' -->
                <contextChanged>
                    <contextRef source='Call' type='State'/>
                </contextChanged>
                <equals>
                    <contextRef source='Call' type='State'/>
                    <string>Ringing</string>
                </equals>
            </and>
            <and>
                <!-- New call state event received from call state source with value 'Dialling' -->
                <contextChanged>
                    <contextRef source='Call' type='State'/>
                </contextChanged>
                <equals>
                    <contextRef source='Call' type='State'/>
                    <string>Dialling</string>
                </equals>
            </and>
        </or>
        <actions>
            <!-- Activate proximity sensor -->
            <publishContext>
                <contextRef source='Sensor'
                            type='Event'
                            value='Proximity.Activate'/>
            </publishContext>
        </actions>
    </elseIf>

<!-- Deactivate proximity sensor and re-enable touch and backlight when call state is disconnecting -->
    <elseIf>
        <!-- Check that call state is 'Disconnecting' -->
        <equals>
            <contextRef source='Call' type='State'/>
            <string>Disconnecting</string>
        </equals>
        <actions>
            <!-- Trigger action plug in to enable touch/backlight -->
            <Proximity Mode='Enable'/>
            <!-- Deactivate proximity sensor -->
            <publishContext>
                <contextRef source='Sensor'
                            type='Event'
                            value='Proximity.Deactivate'/>
            </publishContext>
        </actions>
    </elseIf>

<!-- Deactivate proximity sensor if call state is 'None' -->
    <elseIf>
        <!-- Check that call state is 'None' -->
        <equals>
            <contextRef source='Call' type='State'/>
            <string>None</string>
        </equals>
        <actions>
            <!-- Trigger action plug in to enable touch/backlight -->
            <Proximity Mode='Enable'/>
            <!-- Deactivate proximity sensor -->
            <publishContext>
                <contextRef source='Sensor'
                            type='Event'
                            value='Proximity.Deactivate'/>
            </publishContext>
        </actions>
    </elseIf>
    
</script>