|
1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include <e32base.h> |
|
17 #include <e32std.h> |
|
18 #include <e32test.h> |
|
19 #include <bt_subscribe.h> |
|
20 #include <bt_sock.h> |
|
21 #include "Discoverability.h" |
|
22 |
|
23 |
|
24 |
|
25 _LIT(KInstructions, "Press I to be invisible, V to be visible\nL to be limited, G to be general\nC to change CoD\n"); |
|
26 |
|
27 GLDEF_D RTest test(_L("Discoverability App")); |
|
28 |
|
29 void TestL() |
|
30 { |
|
31 test.Printf(_L("%S\n"), &KInstructions); |
|
32 |
|
33 CDiscoverability* discoverability = CDiscoverability::NewL(test); |
|
34 |
|
35 CActiveScheduler::Start(); |
|
36 |
|
37 delete discoverability; |
|
38 } |
|
39 |
|
40 |
|
41 CDiscoverability* CDiscoverability::NewL(RTest& aTest) |
|
42 { |
|
43 CDiscoverability* s = new(ELeave) CDiscoverability(aTest); |
|
44 CleanupStack::PushL(s); |
|
45 s->ConstructL(); |
|
46 CleanupStack::Pop(s); |
|
47 return s; |
|
48 } |
|
49 |
|
50 CDiscoverability::CDiscoverability(RTest& aTest) |
|
51 : CActive(EPriorityStandard), iTest(aTest) |
|
52 { |
|
53 CActiveScheduler::Add(this); |
|
54 } |
|
55 |
|
56 CDiscoverability::~CDiscoverability() |
|
57 { |
|
58 Cancel(); |
|
59 } |
|
60 |
|
61 void CDiscoverability::ConstructL() |
|
62 { |
|
63 TInt err; |
|
64 |
|
65 |
|
66 _LIT_SECURITY_POLICY_PASS(KPassPolicy); |
|
67 err=iProperty.Define(KPropertyUidBluetoothCategory, |
|
68 KPropertyKeyBluetoothSetScanningStatus, |
|
69 RProperty::EInt, |
|
70 KPassPolicy, // Read policy |
|
71 KPassPolicy); // Write policy |
|
72 if (err) test.Printf(_L("Error %d defining property, continuing anyway\n"),err); |
|
73 err=iProperty.Define(KPropertyUidBluetoothCategory, |
|
74 KPropertyKeyBluetoothSetLimitedDiscoverableStatus, |
|
75 RProperty::EInt, |
|
76 KPassPolicy, // Read policy |
|
77 KPassPolicy); // Write policy |
|
78 if (err) test.Printf(_L("Error %d defining property, continuing anyway\n"),err); |
|
79 err=iProperty.Define(KPropertyUidBluetoothCategory, |
|
80 KPropertyKeyBluetoothSetDeviceClass, |
|
81 RProperty::EInt, |
|
82 KPassPolicy, // Read policy |
|
83 KPassPolicy); // Write policy |
|
84 |
|
85 if (err) test.Printf(_L("Error %d defining property, continuing anyway\n"),err); |
|
86 |
|
87 Start(); |
|
88 } |
|
89 |
|
90 void CDiscoverability::Start() |
|
91 { |
|
92 iTest.Console()->Read(iStatus); |
|
93 SetActive(); |
|
94 } |
|
95 |
|
96 |
|
97 void CDiscoverability::RunL() |
|
98 { |
|
99 Start(); |
|
100 |
|
101 TChar ch = iTest.Console()->KeyCode(); |
|
102 TInt err = KErrNone; |
|
103 |
|
104 switch (ch) |
|
105 { |
|
106 case 'i': case 'I': |
|
107 err=iProperty.Set(KPropertyUidBluetoothCategory, KPropertyKeyBluetoothSetScanningStatus, EPageScanOnly); |
|
108 test.Printf(_L("Set Page Scan mode with result %d\n"),err); |
|
109 break; |
|
110 |
|
111 case 'v': case 'V': |
|
112 err=iProperty.Set(KPropertyUidBluetoothCategory, KPropertyKeyBluetoothSetScanningStatus, EInquiryAndPageScan); |
|
113 test.Printf(_L("Set InquiryAndPage Scan mode with result %d\n"),err); |
|
114 break; |
|
115 |
|
116 case 'l': case 'L': |
|
117 err=iProperty.Set(KPropertyUidBluetoothCategory, KPropertyKeyBluetoothSetLimitedDiscoverableStatus, ETrue); |
|
118 test.Printf(_L("Set Limited Discoverable mode ON with result %d\n"),err); |
|
119 break; |
|
120 |
|
121 case 'g': case 'G': |
|
122 err=iProperty.Set(KPropertyUidBluetoothCategory, KPropertyKeyBluetoothSetLimitedDiscoverableStatus, EFalse); |
|
123 test.Printf(_L("Set Limited Discoverable mode OFF with result %d\n"),err); |
|
124 break; |
|
125 |
|
126 case 'c': case 'C': |
|
127 { |
|
128 TUint8 majorDeviceClass = User::TickCount() % 8; |
|
129 TBTDeviceClass cod(0,majorDeviceClass,0); |
|
130 err=iProperty.Set(KPropertyUidBluetoothCategory, KPropertyKeyBluetoothSetDeviceClass, cod.DeviceClass()); |
|
131 test.Printf(_L("Changed COD with result %d\n"),err); |
|
132 break; |
|
133 } |
|
134 |
|
135 default: |
|
136 break; // do nothing |
|
137 } |
|
138 } |
|
139 |
|
140 void CDiscoverability::DoCancel() |
|
141 { |
|
142 iTest.Console()->ReadCancel(); |
|
143 } |
|
144 |
|
145 |
|
146 TInt E32Main() |
|
147 { |
|
148 CTrapCleanup* cleanupStack=CTrapCleanup::New(); |
|
149 CActiveScheduler::Install(new CActiveScheduler); |
|
150 |
|
151 TRAPD(err,TestL()); // Ignore err |
|
152 |
|
153 if (err != KErrNone) |
|
154 { |
|
155 test.Printf(_L("Error %d"), err); |
|
156 test.Getch(); |
|
157 } |
|
158 |
|
159 delete cleanupStack; |
|
160 return err; |
|
161 } |