1 /* |
|
2 * Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <e32base.h> |
|
19 #include <e32debug.h> |
|
20 #include <AknCapServerDefs.h> |
|
21 #include <apgtask.h> |
|
22 #include "AutolockGripStatusObserver.h" |
|
23 #include "AutolockApp.h" |
|
24 #include "AutolockAppUiInterface.h" |
|
25 #include <aknkeylock.h> |
|
26 |
|
27 |
|
28 EXPORT_C CAutolockGripStatusObserver* CAutolockGripStatusObserver::NewL( MAutolockAppUiInterface* aObserver, RWsSession& aSession ) |
|
29 { |
|
30 CAutolockGripStatusObserver* self = new (ELeave) CAutolockGripStatusObserver( aSession ); |
|
31 CleanupStack::PushL( self ); |
|
32 self->ConstructL( aObserver ); |
|
33 CleanupStack::Pop( self ); |
|
34 return self; |
|
35 } |
|
36 |
|
37 void CAutolockGripStatusObserver::ConstructL( MAutolockAppUiInterface* aObserver ) |
|
38 { |
|
39 #if defined(_DEBUG) |
|
40 RDebug::Print(_L("(AUTOLOCK)CAutolockGripStatusObserver::ConstructL") ); |
|
41 #endif |
|
42 TInt err = iGripStatus.Attach( KPSUidHWRM, KHWRMGripStatus ); |
|
43 if ( err ) |
|
44 { |
|
45 #if defined(_DEBUG) |
|
46 RDebug::Print(_L("(AUTOLOCK)ERROR: Attach failed, err %d"), err ); |
|
47 #endif |
|
48 } |
|
49 iObserver = aObserver; |
|
50 CActiveScheduler::Add( this ); |
|
51 iGripStatus.Subscribe( iStatus ); |
|
52 SetActive(); |
|
53 } |
|
54 |
|
55 CAutolockGripStatusObserver::CAutolockGripStatusObserver( RWsSession& aSession ) : CActive( EPriorityIdle ), iSession( aSession ) |
|
56 { |
|
57 } |
|
58 |
|
59 CAutolockGripStatusObserver::~CAutolockGripStatusObserver() |
|
60 { |
|
61 #if defined(_DEBUG) |
|
62 RDebug::Print(_L("(AUTOLOCK)CAutolockGripStatusObserver::~CAutolockGripStatusObserver") ); |
|
63 #endif |
|
64 Cancel(); |
|
65 iGripStatus.Close(); |
|
66 } |
|
67 |
|
68 void CAutolockGripStatusObserver::DoCancel() |
|
69 { |
|
70 #if defined(_DEBUG) |
|
71 RDebug::Print(_L("(AUTOLOCK)CAutolockGripStatusObserver::DoCancel") ); |
|
72 #endif |
|
73 iGripStatus.Cancel(); |
|
74 } |
|
75 |
|
76 void CAutolockGripStatusObserver::RunL() |
|
77 { |
|
78 #if defined(_DEBUG) |
|
79 RDebug::Print(_L("(AUTOLOCK)CAutolockGripStatusObserver::RunL") ); |
|
80 #endif |
|
81 iGripStatus.Subscribe( iStatus ); |
|
82 SetActive(); |
|
83 |
|
84 TInt gripStatus; |
|
85 TInt err = iGripStatus.Get( gripStatus ); |
|
86 if( !err ) |
|
87 { |
|
88 GripStatusChangedL( gripStatus ); |
|
89 } |
|
90 } |
|
91 |
|
92 void CAutolockGripStatusObserver::GripStatusChangedL( TInt aGripStatus ) |
|
93 { |
|
94 #if defined(_DEBUG) |
|
95 RDebug::Print(_L("(AUTOLOCK)CAutolockGripStatusObserver::::GripStatusChangedL")); |
|
96 #endif |
|
97 if( aGripStatus == EPSHWRMGripOpen ) |
|
98 { |
|
99 #if defined(_DEBUG) |
|
100 RDebug::Print(_L("(AUTOLOCK)CAutolockGripStatusObserver::::GripStatusChangedL => Grip opened")); |
|
101 #endif |
|
102 iObserver->ForceOrientation(0); |
|
103 if( !iObserver->DeviceLockQueryStatus() && iObserver->DeviceLockStatus() ) |
|
104 { |
|
105 #if defined(_DEBUG) |
|
106 RDebug::Print(_L("(AUTOLOCK)CAutolockGripStatusObserver::::GripStatusChangedL => send command")); |
|
107 #endif |
|
108 //Grip opened |
|
109 TApaTaskList tasklist( iSession ); |
|
110 /* this is old code. It was changed to a new one, following a suggestion from the Slide-handling team |
|
111 TApaTask capserver = tasklist.FindApp( KAknCapServerUid ); |
|
112 if( capserver.Exists() ) |
|
113 { |
|
114 TKeyEvent key; |
|
115 key.iCode = EKeyDevice0; |
|
116 key.iModifiers = 0; |
|
117 key.iRepeats = 0; |
|
118 key.iScanCode = EStdKeyDevice0; |
|
119 capserver.SendKey( key ); |
|
120 } |
|
121 */ |
|
122 TApaTask capserver = tasklist.FindApp( KUidAutolock ); |
|
123 if( capserver.Exists() ) |
|
124 { |
|
125 TKeyEvent key; |
|
126 key.iCode = EKeyBell; |
|
127 capserver.SendKey( key ); |
|
128 } |
|
129 RAknKeylock2 keylock; |
|
130 TInt error( keylock.Connect() ); |
|
131 if ( !error ) |
|
132 { |
|
133 keylock.DisableWithoutNote(); |
|
134 keylock.Close(); |
|
135 } |
|
136 } |
|
137 } |
|
138 else |
|
139 { |
|
140 #if defined(_DEBUG) |
|
141 RDebug::Print(_L("(AUTOLOCK)CAutolockGripStatusObserver::::GripStatusChangedL => Grip closed")); |
|
142 #endif |
|
143 iObserver->ForceOrientation(1); |
|
144 |
|
145 //Grip closed |
|
146 if( iObserver->DeviceLockQueryStatus() ) |
|
147 { |
|
148 #if defined(_DEBUG) |
|
149 RDebug::Print(_L("(AUTOLOCK)CAutolockGripStatusObserver::::GripStatusChangedL => send key event")); |
|
150 #endif |
|
151 //the device lock query is on top |
|
152 //generate cancel key event |
|
153 iObserver->CancelDeviceLockQuery(); |
|
154 } |
|
155 } |
|
156 } |
|
157 |
|
158 // End of File |
|