<!--
........................................................................................................................
Description:
    This rule script defines when to activate and deactivate orientation channel.

Feature:
    autorotateui

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

<!--
........................................................................................................................
Description:
    Activate orientation channel from sensor source.
........................................................................................................................
-->
    <if>
        <and>
            <!-- Sensor setting is enabled -->
            <equals>
                <contextRef source='Sensor' type='Setting.Active' value='On'/>
            </equals>
            <!-- Turning interaction is enabled -->
            <equals>
                <contextRef source='Sensor' type='Setting.TurningInteraction.AutoRotation' value='On'/>
            </equals>
            <!-- Lights are on -->
            <equals>
                <contextRef source='Device' type='Display.Status.Light' value='On'/>
            </equals>
            <!-- Device lock is disabled -->
            <equals>
                <contextRef source='Device' type='DeviceLock.Status' value='EDeviceLockOff'/>
            </equals>
            <!-- Key lock is disabled -->
            <equals>
                <contextRef source='System' type='Keyguard.Status' value='EKeyguardNotActive'/>
            </equals>
        </and>
        <actions>
            <!-- Activate orientation channel (0x01) from sensor source (0x10282DF0) -->
            <sourceCommand uid='0x10282DF0'>
                <sensorCommand channelId='0x01' id='activate' featureId='fea.autorotateui'/>
            </sourceCommand>
            
           <!-- publish context telling that rotation is now enabled -->
            <publishContext define='true'>
                <contextRef source='Device' type='Orientation.Active' value='true'/>
            </publishContext>
        </actions>
    </if>

<!--
........................................................................................................................
Description:
    Deactivate orientation channel from sensor source.
........................................................................................................................
-->
    <elseIf>
        <or>
            <!-- Sensor setting is disabled -->
            <equals>
                <contextRef source='Sensor' type='Setting.Active' value='Off'/>
            </equals>
            <!-- Turning interaction is disabled -->
            <equals>
                <contextRef source='Sensor' type='Setting.TurningInteraction.AutoRotation' value='Off'/>
            </equals>
            <!-- Lights are off -->
            <equals>
                <contextRef source='Device' type='Display.Status.Light' value='Off'/>
            </equals>
            <!-- Device lock is enabled -->
            <notEqual>
                <contextRef source='Device' type='DeviceLock.Status' value='EDeviceLockOff'/>
            </notEqual>
            <!-- Key lock is enabled -->
            <notEqual>
                <contextRef source='System' type='Keyguard.Status' value='EKeyguardNotActive'/>
            </notEqual>
        </or>
        <actions>
            <!-- Deactivate orientation channel (0x01) from sensor source (0x10282DF0) -->
            <sourceCommand uid='0x10282DF0'>
                <sensorCommand channelId='0x01' id='deactivate' featureId='fea.autorotateui'/>
            </sourceCommand>
            
            <!-- publish context telling that rotation is now disabled -->
            <publishContext define='true'>
                <contextRef source='Device' type='Orientation.Active' value='false'/>
            </publishContext>
        </actions>
    </elseIf>

</script>
