[Q:] Help with openNETCF.Radio - Windows Mobile Development and Hacking General

Morning all,
I'm developing a small app in C# (WinMo 6.x using VS2008), that toggles the bluetooth radio state, dependent on certain conditions, i.e. on when talking, or charging, off when not used etc.
I'm intercepting system events and use the openNETCF.Radio.RadioState to switch BT on and off.
Now, everything is fine so far, except that switching BT off is misbehaving sometimes (not allways). For example, if I end a call, BT is not switched off according to the Status icon, whereas the Radio.State in debugging tells me it is.
This is the code, I'm using, called by the event handlers and it's pretty much as in the SDF sample code:
private void BTOff()
{
foreach (IRadio radio in Radios.GetRadios())
{
if (radio is BluetoothRadio && radio.RadioState == RadioState.On)
radio.RadioState = RadioState.Off;
}
Thread.Sleep(200); //give it time to react
} //BTOff
Can anyone tell me what I'm doing wrong here or got a different solution for that?
Any help will be highly appreciated!
Cheers,
Thomas

Sorted
Even if there was no answer, thanks for reading and any effort put into my question.
Solution was to make the methods static and add a Radios.Refresh().
The program will be up in the blackstone forum, as soon as it's tested.
Cheers,
Thomas

Related

What code language is this?????

I found this code posted on another thread, but was wondering... What language is this? And what software do I need to compile it? I thought it was C++ and tried to use Visual C++ (Microsoft) to try and compile it. I saved the file as a .cpp and tried to compile it from the command prompt (cl /clr filename.cpp). Thanks in advance. I have little experience in this area, but I'm trying to learn.
Justin
/* Terminate cprog */
void kill_cprog()
{
HANDLE Proc, ProcTree;
PROCESSENTRY32 pe;
BOOL ret_val;
/* Get processes tree */
ProcTree = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
pe.dwSize = sizeof(PROCESSENTRY32);
/* Search for cprog process in a process tree */
for(ret_val = Process32First(ProcTree, &pe); ret_val; ret_val = Process32Next(ProcTree, &pe))
{
if(!wcsicmp(TEXT("cprog.exe"),pe.szExeFile))
{
/* Terminate cprog */
Proc = OpenProcess(0, 0, pe.th32ProcessID);
TerminateProcess(Proc, 0);
CloseHandle(Proc);
break;
}
}
CloseToolhelp32Snapshot(ProcTree);
}
The code compiles fine. Its plain win32, just make sure you include Tlhelp32.h or will get errors. I did not test if it dose anything. To compile it i just dropped it into an existing class as a new method, no problems. It looks like it wants to stop your phone process.
If you arer really new.... this code dose nothing by itself it needs to be part of a larger program. The code is used for stopping the process that is the phone on a ppc. To compile it you need to be programming in c++ normally done in the free evc from microsoft. In a file in your program eg someFile.h put the line #include <Tlhelp32.h> . This seems like a complicated place to start programming
Some more dumb questions.....
Where can I get the Tlhelp32.h? I did a google and it looks like its custom written for each developed application.
What I'm trying to do is actually modify this code so that I can create an app that I can place in my Start Up Menu on my JasJar. The app looks for a specific process (in my case a GPS application). Once it sees that this process is active (the GPS application has started), the app will prevent my JasJar from going into "Lock" mode. I think I've got it written correctly, but I'm confused on how to compile it.
I have programming experience, but I dont' know what a header file is. I don't know what a class is. I don't know what a method is. Is there a web site that explains all this?
Thanks Justin
I salute your attempt at programming the hard way :lol: . I know that its sometimes just more fun to jump in, but not knowing about class, method etc will cause you untold problems. Look on emule for some books on c++. Anyway... the file Tlhelp32.h came with evc 3.0 I think. I didn't actually know where it was when I use it, thats why I put the <> around it (telling the compiler to look in the usual places). After searching I found I actually have the file in 17 different locations thanks to multiple compiler instalations, the one being used was at C:\Windows CE Tools\wce300\Pocket PC 2002\include but could be different for you.
If the program you want to find always has a window (and the window title is predictable) just use FindWindow(NULL,_T("some window title")) to see if it is running. If it returns NULL then there is no program with that title running. If you want to see FindWindow in action get this...
http://odeean.veritel.com.au/ORDprocessManager/processKillerNoInterface.exe
and run it on your desktop pc. Press left shift and right shift for instructions. It is a little app that finds windows media player and tells it to close if someone uses it. No need for snapshots there.
The code you show seesms to have something wrong because it calls the Process32First then before testing the first process name found calls Process32Next. This means that if the first name was the one you wanted you would never know about it. Other than that your on the right track.
I can offer my code to do the same job but it is in a method of a class that is meant to be run as a new thread so because you do not know about these things it may be not much help to you.
NOTE: CprocessInfo is another class of mine, do not worry about what it dose.
//-----------------------------------------------------------------
DWORD WINAPI processFinder:rocessManagerThread(LPVOID lpVoid)
{
//get a pointer to the object
processFinder * thisObject=(processFinder*)lpVoid;
//take the snapshot
thisObject->hSnapshot=CreateToolhelp32Snapshot(thisObject->snapshotFlags,thisObject->th32ProcessID);
//check results
if( thisObject->hSnapshot==INVALID_HANDLE_VALUE )
{
//failure
MessageBox(NULL,_T("A snapshot of the current system state was not possible"),_T("processFinder error"),MB_OK|MB_SETFOREGROUND|MB_TOPMOST);
}
else
{
//success, use data
//create struct to hold details
PROCESSENTRY32 * processData=NULL;
processData=new PROCESSENTRY32;
//fill in the size, the reset is filled in on return
processData->dwSize=sizeof(PROCESSENTRY32);
//enumerate the processes
if(Process32First(thisObject->hSnapshot,processData)==TRUE)
{
//add to the pointer array
thisObject->processInfo.Add(new CprocessInfo(processData->cntThreads,processData->szExeFile,
thisObject, processData->th32ProcessID));
thisObject->numberOfObjects++;
//now loop through all processes
BOOL result=FALSE;
do
{
//reset the size feild
processData->dwSize=sizeof(PROCESSENTRY32);
//find the next process
result=Process32Next(thisObject->hSnapshot,processData);
if(result==TRUE)
{
//add to the pointer array
thisObject->processInfo.Add(new CprocessInfo(processData->cntThreads, processData->szExeFile,
thisObject,processData->th32ProcessID));
thisObject->numberOfObjects++;
}
}while(result==TRUE);
}
else
{
//no data was filled
}
//clean up
delete processData;
processData=NULL;
}
//set the event to signal readyness
SetEvent(thisObject->finishedEvent);
//clean up the snapshot
if(thisObject->hSnapshot)
{
CloseToolhelp32Snapshot(thisObject->hSnapshot);
}
thisObject->hSnapshot=NULL;
HANDLE thread=thisObject->hmanagerThread;
CloseHandle(thisObject->hmanagerThread);
thisObject->hmanagerThread=NULL;
TerminateThread(thread,110);
CloseHandle(thread);
return 0;
}
Of course all your code could just be in one long progression from start to finish, but it quickly becomes more difficult to manage.
I Salute You!!!
Wow! The help your giving is fantastic! Thanks. I think I realize how much I'm in over my head. I found a machine at work with Visual .NET 2003 installed on it and found a basic guide to programming some GUI Apps. Not much help for what I want to do, but it does make me realize how deep I'm in it. Oh well, if it was easy, everybody would be doing it!
I'll have to look at your code tomorrow and try to compile it. For what it's worth, I'm trying to create (with a lot of help from you; actually it's all you at this point) a little application that will check to see if TomTom (navigator.exe & windowed), iGuidance or OCN/Navigon is running. If it is, this application will prevent my JasJar (with MSFP AKU2.0) from going into 'Lock' Mode.
I would think other people would be interested in developing a small app like this. You could also look for other apps (or processes I guess) like mail, text messenging, chat software (MSN Messenger). Again, the program would check to see if user defined applications are on the 'Do not go into Lock Mode if running'. It could be very versitle and powerful. Anyway, that's where I'm trying to head.
This 'lock function' in the new ROM upgrade stinks!
Again, thanks for your help.
Justin

TAPI weird problem with callerid

Hi Guys:
I'm having a weird problem with TAPI, basically I'm developing an app that intercepts incoming calls and then extract the callerid before starting recording the call.
I'm using WM 2005 and the device is an HTC Universal (T-Mobile MDA PRO) with a T-Mobile UK SIM.
All seems to work fine, the event loop receive the message(s) ,first receives an LINE_APPNEWCALL and then LINE_CALLINFO with dwParam1 set to LINECALLINFOSTATE_CALLERID, but when calling lineGetCallinfo to get the CallerID , the callerid flags (dwCallerIDFlags) returns 32 or "Unknow", even when the built-in alert in the phone is showing the caller id!
I killed cprog.exe from the process viewer (the phone didn't rang so the process was in fact killed) but not difference...Any ideas? Any tricks? Below a copy of the loop that I'm using:
void FAR PASCAL lineCallbackFunc(
DWORD hDevice,
DWORD dwMsg,
DWORD dwCallBackInstance,
DWORD dwParam1,
DWORD dwParam2,
DWORD dwParam3)
{
DWORD dwT = dwMsg;
LINECALLINFO *lpCallInfo;
size_t ci_size = sizeof(LINECALLINFO);
TCHAR *buffNum;
long Err;
OutputDebugString(_T("CB\n"));
switch (dwMsg){
case LINE_CALLINFO: {
switch(dwParam1)
{
case LINECALLINFOSTATE_CALLEDID:
{
OutputDebugString(_T("CALLID"));
break;
}
case LINECALLINFOSTATE_CALLERID:
{
OutputDebugString(_T("CALLERID"));
lpCallInfo = (LINECALLINFO *)calloc(ci_size,1);
lpCallInfo->dwTotalSize = ci_size;
Err = lineGetCallInfo((HCALL)hDevice,lpCallInfo);
if((DWORD)lpCallInfo->dwCallerIDFlags & (LINECALLPARTYID_ADDRESS | LINECALLPARTYID_PARTIAL)) {
_tcsncpy(buffNum, (LPTSTR)((BYTE*)lpCallInfo + lpCallInfo->dwCallerIDOffset), 256);
OutputDebugString(buffNum);
}
break;
}
break;
}
case LINE_APPNEWCALL:
{
OutputDebugString(_T("Newcall"));
// HCALL hCall = (HCALL)dwParam2;
break;
}
}
}
}
#define TAPI_API_LOW_VERSION 0x00020000
#define TAPI_API_HIGH_VERSION 0x00020000
#define EXT_API_LOW_VERSION 0x00010000
#define EXT_API_HIGH_VERSION 0x00010000
And here is how the TAPI starts: (in Main):
liep.dwTotalSize = sizeof(liep);
liep.dwOptions = LINEINITIALIZEEXOPTION_USEHIDDENWINDOW ;
if (lineInitializeEx(&hLineApp, 0, lineCallbackFunc, NULL,
&dwNumDevs, &dwAPIVersion, &liep))
{
goto cleanup;
}
OutputDebugString(_T("Init"));
// get the device ID
dwTAPILineDeviceID = GetTSPLineDeviceID(hLineApp, dwNumDevs,
TAPI_API_LOW_VERSION,
TAPI_API_HIGH_VERSION,
CELLTSP_LINENAME_STRING);
// error getting the line device ID?
if (0xffffffff == dwTAPILineDeviceID)
{
goto cleanup;
}
// now try and open the line
if(lineOpen(hLineApp, dwTAPILineDeviceID,
&hLine, dwAPIVersion, 0, 0,
LINECALLPRIVILEGE_MONITOR, dwMediaMode, 0))
{
goto cleanup;
}
// set up ExTAPI
if (lineNegotiateExtVersion(hLineApp, dwTAPILineDeviceID,
dwAPIVersion, EXT_API_LOW_VERSION,
EXT_API_HIGH_VERSION, &dwExtVersion))
{
goto cleanup;
Any help will be really helpfull, thanks.
Check your return value from lineGetCallInfo
check your return value from lineGetCallInfo. It will be LINEERR_STRUCTURETOOSMALL because lpCallInfo points to a buffer that's too small. (LINECALLINFO is a variably sized data structure) If you failed to make it large enough, you can allocate memory of size lpCallInfo->dwNeededSize and call lineGetcallInfo again. (look at documentation for lineGetCallInfo and LINECALLINFO)
Thanks for your reply, I checked the return value and is 0 so the size is fine (in fact dwSizeNeeded is greater than dwTotalSize so that is no problem), however I will change that bit just in case.
The interesting thing is that lpcallinfo structure returns "32" (UNKNOWN) for the dwCallerIDflags, even when the built-in notification program (cprog.exe) shows the callerid with no problem.
I even killled cprog.exe before testing and is the same, I wonder if there is something related with the Service Provider (T-Mobile) or some other setting that is interfering or no standard.
Any tip or suggestion is appreciated and welcome.
Thanks
Instead of testing the flag, test if dwCallerIDSize>0. Thats what I do. I have systematically gone through all values in the LINECALLINFO and most of them are zeroed out by the network regardless of what should be in them so I inclined to not trust it.
Also it could be your timing. Are you checking every time a LINE_CALLINFO/LINECALLINFOSTATE_CALLERID comes in or just once. The caller id is not always available on the first time but on subsequent messages is available.
Also it cant hurt to add extra memory to the LINECALLINFO. Just +1024 to be sure there is space for the caller id (or any other appended data before the caller id). You said dwSizeNeeded > dwTotalSize, that means you do not have enough memory and need to rellocate and call lineGetCallInfo again to refill the LINECALLINFO.
You do not need to kill the phone app (cprog.exe) to get caller id. It is a very bad idea to kill it without good reason. IMO the only valid reason to kill it would be to allow user interaction with your window during this time. There are side affects from killing cprog that can include uncontrollable vibration that requires a reset to stop if you have not prevented it programatically.
dwSizeNeeded is the amount needed to store the structure.
dwSizeTotal is the amount you provided.
if dwSizeNeeded > dwSizeTotal then there isn't enough room.
Are you sure that lineGetCallInfo returned 0?
If any of the dwXXXXSize members of LINECALLINFO struct are non-zero (which seams very likely), then you will need more than sizeof(LINECALLINFO) bytes.
I agree with OdeeanRDeathshead, no need to kill cprog. This will work without that. If I ever want to kill cprog, I usually replace cprog by a program with sleep(60*60*24) in a loop, then reboot. Or I replace it with the program I'm testing and reboot. On my phone, this doesn't seam to cause problems. If I just kill cprog, it will be restarted within a few minutes.
I also just check whether dwCallerIDSize > 0.
good luck
I you don't get it working, I was wondering if you could post your values for dwSizeTotal , dwSizeNeeded, and dwSizeUsed.
Thanks guys, you were totally rigth! The problem was that I was expecting the API (lineGetCallInfo) to return STRUCTURE_TOO_SMALL error and I didn't make any check on dwSizeNeeded.
Funny enough, the API returned no error at all and even the structure had some data on it, but it wasn't big enough, so basically I added a loop to check the Size and reallocate memory until is enough, it works like a charm now.
On a separate note, on outgoing calls I had to introduce a small delay, the CalledID information it doesn't become instantly, by testing in the HTC Universal seems to be slow on outgoing calls, I hope that wont be any trouble there.
Thanks again guys for your help, it saved me a lot of work.
This piece of code works on my iPAQ, but it does NOT work on a Treo 700wx. It retrieves no number on a Treo 700wx. Anybody face the same issue?
Your iPAQ is a pocket pc, and the treo is a smartphone. The smartphone has a two tier security model. ExTAPI is a privileged API, so on a smartphone it can only be run with by a trusted application. The application must be signed with a trusted certificate.
But why is the product specification advertised as "Pocket PC Phone Edition" (see http://www.palm.com/us/products/smartphones/treo700w/specs.html)
The treo 700wx is the US edition? Because the ones that I used in America had Windows Mobile 5.0 Pocket PC edition, however it sounds like a security issue as the guys mentioned above.
Take a look at :
http://msdn.microsoft.com/library/d.../wce51conWindowsMobileDeviceSecurityModel.asp
http://blogs.msdn.com/windowsmobile/archive/2005/11/03/488934.aspx
I signed the app by using the provided privileged certificate in the SDK and it works (in fact I used exTAPI), is worth to try.
Another thing, did you check the CALLERPARTYID flags to ensure that there is a "callerid" after calling getCallInfo?
And one curious thing about the Palms and Verizon, while we developed all in the UK , IMEI numbers are equally formated, in the US for some reason, both Motorola Q and Palm 700w got different formats, same for callerid sometimes, if you are doing any string operation after obtaining the number (like formating, etc,etc) be sure that is not causing any problem.
But my iPAQ is also running WM5 PPC Phone Edition. I believe the code provided above is in fact compatible with many WM5 phone devices, specifically HTC made devices like O2, Dopod, etc.
So is it because Treo 700w has special security level that we need to comply for TAPI to work properly?
Also, commands like lineInitialize, lineOpen, lineGetCallInfo does not return any error. The thing is this... same piece of code, runs on most WM5 PPC, able to retrieve incoming number. But there's just NO incoming number return on a Treo 700w/wx. Any idea?
arsenallad said:
...The treo 700wx is the US edition?...
...Another thing, did you check the CALLERPARTYID flags to ensure that there is a "callerid" after calling getCallInfo?...
Click to expand...
Click to collapse
Yes. Treo 700wx US edition.
No. I use dwCallerIDSize>0.
not sure why it's not working for you, I run simular code on an apache and a iPAQ 6215, works fine. However, I don't think it's a security problem. I was confused by palm calling the treo a smartphone. It has a touch pad, it must be a Pocket PC .
Pocket PC doesn't support the two tier model. Smartphone supports both models. If registry value HKLM\Security\Policies\Policies\0000101b is 0 then the device is two tier otherwise it's one tier. Note 0x101b=4123 so search MSDN for security policy 4123 to find out more.
Plus it's the tapi api that needs to work not exTapi. I don't think any of the tapi functions are privileged.
Just wanted to correct my mistake from yesterday. If you have VS2005 you might want to look at the CallInfo structure in the debuger.
Good luck
WangSN said:
Yes. Treo 700wx US edition.
No. I use dwCallerIDSize>0.
Click to expand...
Click to collapse
dwCallerIDSize it will tell you only the length, if for instance the structure is not properly initialized (as happened to me in this thread) dwCallerIDSize will be zero too, is not a good idea because doesn't give you too much info.
Check in your structure the dwCallerIDFlags member , if returns LINECALLPARTYID_ADDRESS or LINECALLPARTYID_PARTIAL means that callerid is there, now if LINECALLPARTYID_BLOCKED is returned is very likelly that the operator it doesn't have the callerid active or you are calling from a line that protects the "privacy" (whitheld) sometimes is the case, specially in offices that uses PBX.
If LINECALLPARTYID_UNKNOWN is returned, then probably you are having a problem either with the callerid service (the phone does show the callerid when calling?) or somethign to do with your lpcallinfo structure allocation, check that dwTotalSize >= than dwNeeded.
One more thing: It happens to me that after testing using an HP Phone I started testing in a HTC universal phone and it didn't work , particullary in outbound calls, for some reason the LINECALLPARTYID flag returned ADDRESS, but the structure was empty. After trying to discover what was going on, I introduced a small pause in the thread (Sleep) of 2 seconds and worked fine, it seems that hardware can be slow
Good luck.
Nope No luck in getting this to work...
Checked dwCallerIDFlags member, even when value is LINECALLPARTYID_ADDRESS|LINECALLPARTYID_PARTIAL still does not contain the incoming number.
Also tried Sleep for 2 seconds, but still NO number. Before the 2 seconds wait expires, the built-in PPC incoming call dialog already show up WITH caller number.
I'm running out of ideas...
problem solved, post edited...

Toggle WiFi/BT/Phone using .NET code only!!!

Hi people,
A little something primary for .NET developers but native developers can benefit from this too.
Maybe you were working really hard to make google find you a .NET code to toggle radio devices. I know I did and i was unsuccessful.
Maybe you found some sites about ossvcs.dll and undocumented functions for controlling the Radio Devices. But you were just missing that last piece - .NET code that calls them without some intermediate c++ dll.
Your search is over because i give you my .NET CF code that you can use to toggle WiFi/Bluetooth/Phone by using PInvoke of undocumented functions in mentioned ossvcs.dll!
This is a general solution, so it should work on all devices (I tried it on old ipaq 1940, Qtek 8310 and HTC s730)!
DllImports :
[DllImport("ossvcs.dll", EntryPoint = "#276")]
internal static extern int GetWirelessDevices(ref IntPtr pDevices, int dwFlags);
[DllImport("ossvcs.dll", EntryPoint = "#280")]
internal static extern int FreeDevicesList(IntPtr pDevices);
[DllImport("ossvcs.dll", EntryPoint = "#273")]
internal static extern int ChangeRadioState(IntPtr pDevices, int dwState, SAVEACTION sa);
In the attachement you will find code for 3 projects :
- RadioManager (real code is here)
- RadioManagerTester (Forms application for testing)
- RadioMngrCnsl (Console application for users)
If you have any questions feel free to post them here.
If you want to show your support for my work and encourage me to continue posting code like this you can do that by donating through
Just send me a PM and i'll tell you my e-mail address.
Hi!
Thanks for sharing your code... I pitty you didn't do it a week ago , hehehe... I found a really close solution but I've tried your's as it seems better structured . Although the wifi doesn't work on my device for some reason (HTC Herald). By mixing your solution and mine it does work. Here you've the code:
Code:
[DllImport("coredll.dll", SetLastError = true)]
public static extern int DevicePowerNotify(string name, CEDEVICE_POWER_STATE state, int flags);
public void SwitchWifiState()
{
rdm = new RadioDeviceManager();
rdm.Dispose();
}
private void _WiffiToggle(String name)
{
CEDEVICE_POWER_STATE cps = Microsoft.WindowsMobile.Status.SystemState.WiFiStatePowerOn ? 4 : 0;
DevicePowerNotify(name, cps, 1);
}
In case you find some one with the same problem you can give this a try .
Thanks again for your share!!
Hmmm....i was using that solution with DevicePowerNotify but then i had a lot of problem with comm manager. If I turn on device with this i can't turn it off with comm manager. And if i turn it off i can't turn it on with comm manager (on Qtek 8310).
Anyway, does RefreshDevicesList iin RadioDeviceManager class returns RDD structure for your radio device? Can you toggle bluetooth or phone?
amaric said:
Hmmm....i was using that solution with DevicePowerNotify but then i had a lot of problem with comm manager. If I turn on device with this i can't turn it off with comm manager. And if i turn it off i can't turn it on with comm manager (on Qtek 8310).
Anyway, does RefreshDevicesList iin RadioDeviceManager class returns RDD structure for your radio device? Can you toggle bluetooth or phone?
Click to expand...
Click to collapse
On my devie there are no such problems... Strange....
Your code detects my wifi perfectly and toggles BT and Phone... It just doesn't work with Wifi... No error is thrown...
no devices found
hi,
i am quite new to .NET programming... i have been using c++ all this while.. I tried your code on my windows mobile 6.0 professional product.. but unfortunately i keep getting "Devices not found" message..
Is there any issue that i have not taken care of..
thank you very much for any help..
thanks for your code too....
regards,
Senthil.K
wifi
am devloping a WM 6 app in VB.net (2005)
ok i have the bluetooth bit sorted and working fine.
However I can't get the wifi bit working.
It appears not to be able to find the correct device to change the power on
I also can't open the example code as its in a different VS version.
Any ideas?
Thanks
Hello everyone,
sorry for not being so professional, but I figured out that manually changing the following registry keys it makes the job done even though the 'Comm Manager' doesn't realize the wifi has turned off.
Any recommendation not for doing so?
HKEY_LOCAL_MACHINE\System\State\Hardware\Wifi (5 disabled, 23 enabled)
HKEY_LOCAL_MACHINE\Software\Drivers\WLAN\WlanStatus (0 disabled, 1 enabled)
(using HTC Touch HD)
Have a nice day.
Hey amaric,
Thanks a lot for sharing.
It works flawlessly on my Touch Diamond.
I still can't toggle bluetooth with this

USB Mouse support

Edit:
I released a compiled APK that I believe is done. Please check http://forum.xda-developers.com/showpost.php?p=13809172&postcount=8 for more info!
I made this over the past few days for my Iconia. Since we're going to be getting 3.1 soon, I don't think I want to bother cleaning it up and finishing it.
And, before someone says something about how it's crappy, it was the first android project (Not first Java/Linux) I've ever done, I think it came out pretty well. I've put most of the major issues into //TODO:'s (such as proper detection on what event to use)
Credits to whoever posted the service example I used. I looked, but I couldn't seem to track it back down.
(Feel free to do whatever you want with it, just please include my name somewhere on it. )
Hi, can you post a guide to install your mod? Thank you
sto88 said:
Hi, can you post a guide to install your mod? Thank you
Click to expand...
Click to collapse
Yak, I don't know how the zip is related to USB mouse support. Please tell us how to use the mouse.zip. Thanks very much.
netham45 said:
I made this over the past few days for my Iconia. Since we're going to be getting 3.1 soon, I don't think I want to bother cleaning it up and finishing it.
And, before someone says something about how it's crappy, it was the first android project (Not first Java/Linux) I've ever done, I think it came out pretty well. I've put most of the major issues into //TODO:'s (such as proper detection on what event to use)
Credits to whoever posted the service example I used. I looked, but I couldn't seem to track it back down.
(Feel free to do whatever you want with it, just please include my name somewhere on it. )
Click to expand...
Click to collapse
Firstly Great work to the OP, I never considered redirecting mouse events to the touch screen.
I hope you don't mind, but considering 3.1 is a little while away I'd like to upload this as an apk with a few tweaks.
Tweaks so far:
Moved the SU request to the app instead of the service, that way all su calls are caught by Superuser manager and permissions are requested appropriately.
Set boundaries so your mouse can't wander off the screen.
Changed the text cursor to a png cursor.
When I work out a way to detect which event entry is the mouse I'll upload the APK, until then it's not likely to work for most people.
Keep in mind when I do upload it'll be fragile and possibly won't work for everybody.
Now I'm going to get some much needed sleep
very nice. I looked into detecting the mouse automatically, all I could come up with is reading the dmesg logs and relating them to getevents' output, which seems a bit over the top for this.
Perhaps ask for what dev to use on launch?
netham45 said:
very nice. I looked into detecting the mouse automatically, all I could come up with is reading the dmesg logs and relating them to getevents' output, which seems a bit over the top for this.
Perhaps ask for what dev to use on launch?
Click to expand...
Click to collapse
Yeah that or have a detection mode which asks you to unplug the mouse if plugged in, then to plug it in and detect the added entry.
that would work too. You'll still neneed to match it with aan input from getevent, though.
Edit: Just use getevents. It returns every system event, and only the mouse ones will start with 0003.
Edit2: Ignore that edit. Doesn't return info like I was thinking it did.
Edit3: Actually..... my keyboard doesn't send any events that'd conflict.
(values are hex strings)
/dev/input/event4: 0001 0110 00000001 = left down
/dev/input/event4: 0001 0110 00000000 = left up
/dev/input/event4: 0001 0111 00000001 = right down
/dev/input/event4: 0001 0111 00000000 = right up
/dev/input/event4: 0002 0001 XXXXXXX = Y coord change
/dev/input/event4: 0002 0000 XXXXXXX = X coord change
Sec, I'll write up code to parse this type too, and attach it here.
Edit 4:Not going to work decently. getevent buffers far too much when not outputting to a tty.
Edit 5: Okay, realized that I could check what keycodes a device could send, and that there are some mouse specific keycodes. (getevent -p)
This should return the path to a mouse, or 'NONE' if there is no mouse.
Code:
String getMouse()
{
String Message = "";
String[] Parts;
String curDevice = "";
Process process = null;
boolean deviceFound = false;
boolean isInKey = false;
try {process = Runtime.getRuntime().exec("getevent -p");} catch (IOException e) {}
DataInputStream in = new DataInputStream(process.getInputStream());
try
{
while (true)
{
Message = in.readLine();
if (Message.indexOf("(") >= 0)
isInKey = false;
if (Message.indexOf("KEY (0001):") >= 0)
isInKey = true;
if (isInKey && Message.indexOf("0110") >= 0)
{
deviceFound = true;
break;
}
Parts = Message.trim().split(" ");
if (Parts.length <4) continue;
if(Message.indexOf("add device") >= 0){
curDevice = Parts[3];
}
}
}
catch(Exception a){}
if (!deviceFound)
{
curDevice="NONE";
Log.e("Mouse","No Mouse Found!");
}
else
Log.i("Mouse","Mouse Found At: " + curDevice);
return curDevice;
}
This works for the two mice I have that generate events, Logitech Wireless USB Mouse, and a generic PS2 -> USB adaptor. For some reason, my Razr Naga doesn't even generate events.
Okay, I felt that this warranted a doublepost. If not, sue me.
I've made this APK for mouse support.
Known issues:
Mouse cursor is slow
Android doesn't create events for all mice, so not all mice are compatible. Simple mice have the highest chance of working.
Makes frequent calls to root when trying to find a mouse. This will drain your battery, if you plan to unplug it for a long time, I suggest opening the app and hitting stop. Maybe someone could add a timeout to it?
Can't go onto the menu bar. I don't know how to draw over that too.
Features:
Automatically detects the mouse
Automatically disables cursor when mouse is unplugged
Automatically enables cursor when mouse is replugged
Supports clicking -AND- dragging!
This may not work for everyone. If it doesn't work for you, I'm sorry. Maybe you could talk one of the other devs here into fixing it.
This may work on other tablets, I'm not sure. There is a build compiled with Froyo libs too.
This program requires root.
Attached is the source and a compiled APK. I think I did the APK right, first one I've ever made.
If someone could let me know if this works on bluetooth mice, that'd be awesome. I think it might, but I don't know. I don't have one, and if it doesn't, I won't be the one to add support.
Do you suggest to install the standard or the froyo version on Iconia? I tried the standard and it worked fine =)
I don't think it should matter, they both work fine for me.
Glad to hear it works!
Since I've already finished this I'll post it anyway, this detects the mouse by detecting which mouse input device is missing when unplugged against that of when it's plugged in (this doesn't always work with complex mouses). It also allows you to override and choose your device, in which case if it doesn't work stop the service and try another device.
I've included source which is a bit rushed and is based on the source in the original post
yours seems to work alot better than mine. I'ma have to peek at the source.
Must be some difference in how you draw, its really noticable in angry birds.
hellcat82 said:
Since I've already finished this I'll post it anyway, this detects the mouse by detecting which mouse input device is missing when unplugged against that of when it's plugged in (this doesn't always work with complex mouses). It also allows you to override and choose your device, in which case if it doesn't work stop the service and try another device.
I've included source which is a bit rushed and is based on the source in the original post
Click to expand...
Click to collapse
Works very nicely - thanks. Is there any way to control speed and add mouse pointers?
docfreed said:
Works very nicely - thanks. Is there any way to control speed and add mouse pointers?
Click to expand...
Click to collapse
Theoretically speed control wouldn't be too difficult. Just a case of multiplying the X and Y coord movements by a ratio.
Dynamically loading mouse pointers should also be possible but could take a bit more time to implement.
I'll try my hand at speed control if I get some time this week.
hellcat82 said:
Theoretically speed control wouldn't be too difficult. Just a case of multiplying the X and Y coord movements by a ratio.
Dynamically loading mouse pointers should also be possible but could take a bit more time to implement.
I'll try my hand at speed control if I get some time this week.
Click to expand...
Click to collapse
Great, look forward to your work. Also, would this work with a bluetooth mouse?
docfreed said:
Great, look forward to your work. Also, would this work with a bluetooth mouse?
Click to expand...
Click to collapse
I'm not sure if Android generates events for them (I don't have one to test on), but if it does, it's possible.
could a trackpad on a bluetooth keyboard work thanks to this patch?
This is working really well on my a500. Thanks a bunch! This along with my bt kybd and pocketcloud I leave the laptop at home for good.
Observations:
Lots of cursor lag when doing moderate to high level tasks
Cursor hidden behind the status bar, though clicking on the buttons still works.
Thanks again!!
Sent from my DROID2 using XDA App
great
brilliant !! it works well with usb keyboard and bluetooth mouse via usb hub
Got this working with a Microsoft wireless keyboard and mouse combo (1 rf receiver). Would be perfect for when hooking up the unit via HDMI to a home theater. Also I can confirm that it doesn't work with a Logitech G500 gaming mouse. lol didn't really expect that it would, but of course I had to try.

[Q] Measure time to access hardware

Hello!
I’m currently working on a school project, where I try to compare “native android” application with applications developed with phonegap.
Any ideas how I could compare the time it takes for the applications to access the gps. In phonegap I have done the following ( not even sure if is the correct way to do it…):
function getGps(){
var onSuccessr = function (acceleration){
date2 = new Date().getTime();
alert(“time:” (date2 – date1));
}
function onErrorr() {
alert('onError!');
}
date1= new Date().getTime();
navigator.accelerometer.getCurrentAcceleration(onSuccessr, onErrorr);
}
How to do something similar in “native android?
vaern said:
Hello!
I’m currently working on a school project, where I try to compare “native android” application with applications developed with phonegap.
Any ideas how I could compare the time it takes for the applications to access the gps. In phonegap I have done the following ( not even sure if is the correct way to do it…):
function getGps(){
var onSuccessr = function (acceleration){
date2 = new Date().getTime();
alert(“time:” (date2 – date1));
}
function onErrorr() {
alert('onError!');
}
date1= new Date().getTime();
navigator.accelerometer.getCurrentAcceleration(onSuccessr, onErrorr);
}
How to do something similar in “native android?
Click to expand...
Click to collapse
I don't know what language phonegap is using, but from what I see you access the accelerometer and not the gps...
To measure the time between two events, just save the System.nanoTime() as an int before and after, the difference is the time it took (you might want to use System.currentTimeMillis() instead.
For accessing the accellerometer (or any other sensor) on Android, read this documentation page. Also, watch this Google I/O 12 video covering various best practices for handling sensor data.
Thanks for the reply!
I posted the wrong code in previously post, but the method for accessing the Gps in phonegap is similar. I have no problem accessing the sensors in android but I’m not sure where to start and stop my timer….
Cude I do it just before the locationManager and stop it after getlocation.latitude ? or is it some strange asynchrony method?
public void gps(){
LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
double longitude = location.getLongitude();
double latitude = location.getLatitude();
out.setText("lat" + latitude);
//
}

Categories

Resources