Heart Sensor/Passive Wellness sensor - Moto 360

Hello dear forum members,
As far as I know , moto360 doesn't have a sensor of type : TYPE_HEART_RATE, it's called passive wellness sensor.
The problem is that this wellness sensor is not giving me any data, as opposed to every other sensor that I've tried (like gravity, accelerometer...)
I've been waiting for more than 5 min but this sensor gives me data only when I start the app.
I've tried sdk20,sdk21,sdk22,sdk23 ... still no result I also have the android.permission.BODY_SENSORS in my manifest
Question : How to get the sensor working, what can I do?
Code:
package com.x.firstapp;
import android.app.Activity;
import android.os.Bundle;
import android.support.wearable.view.WatchViewStub;
import android.util.Log;
import android.widget.Toast;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.view.WindowManager;
public class MainActivity extends Activity implements SensorEventListener {
private SensorManager mSensorManager;
private Sensor mHeartSensor;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final WatchViewStub stub = (WatchViewStub) findViewById(R.id.watch_view_stub);
stub.setOnLayoutInflatedListener(new WatchViewStub.OnLayoutInflatedListener() {
@Override
public void onLayoutInflated(WatchViewStub stub) {
}
});
// keep watch screen on
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
Toast.makeText(getApplicationContext(), "Hi Oleg", Toast.LENGTH_LONG).show();
mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
mHeartSensor = mSensorManager.getDefaultSensor(65538); //wellness sensor
mSensorManager.registerListener(this, mHeartSensor, SensorManager.SENSOR_DELAY_NORMAL);
}
public void onSensorChanged(SensorEvent event) {
if (event.sensor.getType() == 65538) {
String msg = "" + (int) event.values[0];
Log.d("Main Activity", msg);
}
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
Log.d("Main Activity", "accuracy : " + accuracy + " sensor : " + sensor.getName());
}
@Override
protected void onStop() {
super.onStop();
mSensorManager.unregisterListener(this);
}
only output out of this "wellness" sensor (only when app starts) :
D/Main Activity: accuracy : 3 sensor : Wellness Passive Sensor
D/Main Activity: 0​
I have also posted this question on stack overflow, but so far - no success.
As soon as I get an answer here I'll spread it on stack overflow as well.
Thank you

Did you ever solve this? This might help.
What version of OS is your device running. For me, on my moto360 gen 1, now running 6.0.1, I have the permission in the manifest, but I MUST request it from the user using the new android M request mechanism, as BODY_SENSORS is labelled as a dangerous permission. Under debug, you can see all the sensors in the list if you get all sensors, but the iteration through them checks granted permissions.
Apparently, if the app is installed as a companion to an on phone app, it inherits the permissions from the device, so you don't need to ask, but a side-loaded app needs to ask.
Having said that, I clearly got a null for the HEART_RATE sensor until I'd requested user permissions. You at least get something.

dazbys said:
Did you ever solve this? This might help.
What version of OS is your device running. For me, on my moto360 gen 1, now running 6.0.1, I have the permission in the manifest, but I MUST request it from the user using the new android M request mechanism, as BODY_SENSORS is labelled as a dangerous permission. Under debug, you can see all the sensors in the list if you get all sensors, but the iteration through them checks granted permissions.
Apparently, if the app is installed as a companion to an on phone app, it inherits the permissions from the device, so you don't need to ask, but a side-loaded app needs to ask.
Having said that, I clearly got a null for the HEART_RATE sensor until I'd requested user permissions. You at least get something.
Click to expand...
Click to collapse
Hello,
It's a year later. I have a 2nd gen Moto 360 Sport. The android version is 6.01.
I am having what sounds like the same problem. Did you ever solve this?
I am using software which I basically copied from the web. When I run the software I get onAccuracyChanged events with accuracy values somewhere between one and three – mostly two and three.
But, I never get onSensorChanged events. I have the BODY_SENSORS permission in the manifest. And on the watch, if I go into Settings-Permissions, I see that the Sensors permission is enabled.
You mention "I MUST request it from the user using the new android M request mechanism". I'm not familiar with this mechanism. Could you explain a little more? I will also search for more information about this.
Do you have any more suggestions? Did you ever get yours working? It seems strange that I get the onAccuracyChanged events, but no onSensorChanged events. Could it possibly be something like the accuracy has to be four or greater in order to get onSensorChanged events?
Thanks,
Barry.
To answer my own question…
Of course it turned out I had a software error - I had assumed one of the event fields was an integer, it was not.
As was stated in the original answer: Be sure to have the BODY_SENSORS permission in the manifest (for both the phone and wearable). Since I am using SDK platform 20 rather than 23, I don't need to follow the android M procedure of requesting permission, but on the watch I did make sure the Settings-Permissions for my app had Sensors enabled.

Related

Help me understand C++ code with notifications (beers offered)

Hi,
I need to use the C++ version of this. The code should gather information and show this in a notification.
The notification works but I want to receive the choice the user made in the html form.
I know I need to use the hwsink, a message map, and some events but cannot find info (book, example, etc.) how.
Could some one finish this code so I can test what has been chosen. If NOT, please give me an C++ example from which I can learn/copy. I have been searching on google for days now
Thx, for your help
BTW:
I started with this http://www.krvarma.com/?p=146 downloaded code but was a bit to complicated. In it is all I need but i would like it to be in 1 cpp file.
I'm offering 2 beers if you have the solution
Code:
#include "stdafx.h"
#include <stdlib.h>
#include "resource.h"
// {4E8A9888-D15C-4395-9C9A-B4B572F20081}
static const GUID NOTIFICATION_GUID =
{ 0x4e8a9888, 0xd15c, 0x4395, { 0x9c, 0x9a, 0xb4, 0xb5, 0x72, 0xf2, 0x0, 0x81 } };
int _tmain(int argc, _TCHAR* argv[])
{
SHNOTIFICATIONDATA stcNtData = {0};
stcNtData.cbStruct = sizeof(stcNtData);
stcNtData.dwID = 1;
stcNtData.npPriority = SHNP_INFORM;
stcNtData.csDuration = 15;
// stcNtData.hicon = LoadIcon((HINSTANCE)GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON2));
stcNtData.clsid = NOTIFICATION_GUID;
//What todo here... stcNtData.hwndSink = hWnd;
stcNtData.grfFlags = SHNF_SILENT | SHNF_TITLETIME | SHNF_CRITICAL | SHNF_FORCEMESSAGE;
stcNtData.pszTitle = L"ReRemind";
//stcNtData.pszHTML = TEXT("<html><body>This is a sample application to show the SHNotificationAdd API")
// TEXT("<p><b>This line should be bold</b>.<br><i>This one should be italics.</i><br>")
// TEXT("This is a line with a <a href='cmd:10000'>link</a></p>")
// TEXT("<p>This is a line with <input type='button' name='cmd:10001' value='Click'></p><br><br><br><br>");
stcNtData.pszHTML = TEXT("<form method='get' action='TestBubble://Test'>")
TEXT("<table width=100% cellspacing=0 cellpadding=0>")
TEXT("<tr><td colspan=2>")
TEXT("<b>Choose a fruit:</b><p>")
TEXT("<input type='radio' value='0' id='Apples' checked name='Fruit'><label for='Apples'>Apples</label><br>")
TEXT("<input type='radio' value='1' id='Oranges' name='Fruit'><label for='Oranges'>Oranges</label></p></td><td>")
TEXT("<input type='submit' value='Submit' name='Submit'>")
TEXT("</td></tr><tr><td width=42>")
TEXT("<a href='cmd:12288'>Settings</a></td></tr></table></form><br><br><br><br>");
SHNotificationAdd(&stcNtData);
Sleep(15000);
SHNotificationRemove(&NOTIFICATION_GUID, 1);
return 0;
}
I'm offering beers now. No need to finish it, just give me some hints
Hi,
as I understand your article (http://www.krvarma.com/?p=146)
you need to create window, then assign it's HWND
to SHNOTIFICATIONDATA member HWND hwndSink;
then "The system will send WM_COMMAND with wParam set to 1000 to the hwndSink window." so - you need to handle WM_COMMAND in your window and check wParam - if it is equal to your parameter, then this message means "system sends you user choice from your html".
serfer222 said:
Hi,
as I understand your article (http://www.krvarma.com/?p=146)
you need to create window, then assign it's HWND
to SHNOTIFICATIONDATA member HWND hwndSink;
then "The system will send WM_COMMAND with wParam set to 1000 to the hwndSink window." so - you need to handle WM_COMMAND in your window and check wParam - if it is equal to your parameter, then this message means "system sends you user choice from your html".
Click to expand...
Click to collapse
Exactly as i understand it.
So I tried copying code from that article into my code but got stuck with really not understandable compiler errors. I think I need to find a good book explaining this message map.
The first thing I do not understand is that I only want to show the notification bubble (is working). If I create a windows handle (how?) will this overwrite the current screen (this is something I do not want).
window can be invisible.
I'm Win32 programmer, and I don't know exactly about WinCE.
If you are using VisualC++, I think you should use MFC, it's very easy to create window and then create message handler for this window.
search google for some
"WinCE c++ tutorial" and you will find how to create window and setup message loop. (add "Hello world" phrase to your search - this is usually used as very first example)
for example: http://www.codeproject.com/KB/mobile/ltwtdlg.aspx
serfer222 said:
window can be invisible.
I'm Win32 programmer, and I don't know exactly about WinCE.
If you are using VisualC++, I think you should use MFC, it's very easy to create window and then create message handler for this window.
search google for some
"WinCE c++ tutorial" and you will find how to create window and setup message loop. (add "Hello world" phrase to your search - this is usually used as very first example)
for example: http://www.codeproject.com/KB/mobile/ltwtdlg.aspx
Click to expand...
Click to collapse
Can you switch between MFC, ATL, etc. ? I know they are some kind of libraries but thought "don't look at it, there too much to learn/understand anyway ".
I've search but somehow you think there is the solution and then you learn the hard way, it's very old code. Will search further offcourse and I am reading a chapter on classes and if I can find; messages.
it's already very easy to handle messages without any MFC overload. Just check the uMsg parameter in your DefWindowProc. If you create a new Win32 project in Visual C++ wizard then you see what it's looking like. This is mandatory knowledge. Usually first thing you learn after Hello World. If you didn't know about message processing in Windows/Wince then it's the same like sitting in a car and don't know how to turn the keys.
Do you know how to open dsm file in textbox???
RAMMANN said:
it's already very easy to handle messages without any MFC overload. Just check the uMsg parameter in your DefWindowProc. If you create a new Win32 project in Visual C++ wizard then you see what it's looking like. This is mandatory knowledge. Usually first thing you learn after Hello World. If you didn't know about message processing in Windows/Wince then it's the same like sitting in a car and don't know how to turn the keys.
Click to expand...
Click to collapse
Thats how I feel exactly. It's strange. I read quickly thru 3 books about C++ and no mention of these messages. C#/Basic are easier to understand because of all the examples.
Found these:
- http://www.youtube.com/watch?v=kWVGqV2Yklw
- http://www.youtube.com/watch?v=cbe6yxBHEiU
The video does explain that the linked example doesn't look so different. What a lot of source code Ms creates for you..
If created a WIN32 smart device project and DefWindowsProc is only called when to pass the message to other programs. I need the windows handle for the notification and NOT display the window.
But again it's a bit to much for me at this moment. I haven't got a solution yet..Could somebody help me with not displaying this window. I would still like to use the windows handle to make sure I get the callbakcs to the WM_COMMAND.
Yes - I think you only need at end of WinMain before SHNotificationRemove
to add:
Code:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hacc, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
Then a new function:
Code:
/* Redefine generic HANDLE_WM_ACTIVATE macro for Pocket PC */
#undef HANDLE_WM_ACTIVATE
#define HANDLE_WM_ACTIVATE(hwnd,wParam,lParam,fn) \
(SHHandleWMActivate((hwnd), (wParam), (lParam), &g_sai, 0), /*return*/ 0L)
/* Redefine generic HANDLE_WM_SETTINGCHANGE macro for Pocket PC */
#undef HANDLE_WM_SETTINGCHANGE
#define HANDLE_WM_SETTINGCHANGE(hwnd,wParam,lParam,fn) \
(SHHandleWMSettingChange((hwnd), (wParam), (lParam), &g_sai), /*return*/ 0L)
static LRESULT CALLBACK MainWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
HANDLE_MSG(hwnd, WM_CREATE, Main_OnCreate);
HANDLE_MSG(hwnd, WM_ACTIVATE, /* SHHandleWMActivate()*/ 0);
HANDLE_MSG(hwnd, WM_SETTINGCHANGE, /* SHHandleWMSettingChange() */ 0);
HANDLE_MSG(hwnd, WM_PAINT, Main_OnPaint);
HANDLE_MSG(hwnd, WM_COMMAND, Main_OnCommand);
HANDLE_MSG(hwnd, WM_DESTROY, Main_OnDestroy);
[B]// Remark: Here you can add more messages - also for what user has chosen.[/B]
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
}
and then the message handlers like this:
Code:
static BOOL Main_OnCreate(HWND hwnd, CREATESTRUCT *pcs)
{
SHMENUBARINFO mbi;
memset(&mbi, 0, sizeof(mbi));
mbi.cbSize = sizeof(mbi);
mbi.hwndParent = hwnd;
mbi.nToolBarId = IDR_MNU_MAIN;
mbi.hInstRes = g_hInstance;
if (!SHCreateMenuBar(&mbi)) /* create the menu bar */
return FALSE;
g_hwndMB = mbi.hwndMB;
return TRUE;
}
But your Compiler should already make such a project by default and you can simple add the code fom _tmain to WinMain, which you've posted above.
Greetz
Micha
Thank you, yesterday I debugged and and debugged trying to understand how this works but the debugger doesn't stop always in all source code.
If f.i. you click on the screen I expected this to be an event, but the debugger didn't stop at all. Is there a command to always stop when a line of code is processed? Now it only stops when I have set a break point. I want to see every line processed...
I will try to implement your suggestions. For a newby it still looks difficult I hope someday I will look back to this and say "wow, that was so easy".
ajhvdb said:
Thank you, yesterday I debugged and and debugged trying to understand how this works but the debugger doesn't stop always in all source code.
If f.i. you click on the screen I expected this to be an event, but the debugger didn't stop at all. Is there a command to always stop when a line of code is processed? Now it only stops when I have set a break point. I want to see every line processed...
I will try to implement your suggestions. For a newby it still looks difficult I hope someday I will look back to this and say "wow, that was so easy".
Click to expand...
Click to collapse
Well, actually that's the reason why breakpoints exist. To stop the debugger and allow you look at the running code..... or what else did you think??
RAMMANN said:
Well, actually that's the reason why breakpoints exist. To stop the debugger and allow you look at the running code..... or what else did you think??
Click to expand...
Click to collapse
I want to say "stop and show at the current code line".
For example you start your program, goto the appropiate window, type in some data and NOW before you click on SAVE. You say to your debugger "catch this/coming event".
Debugger would stop if you'd handle this event and set break point to 1st command of this function.
then yo can go step by step through each line of code.
and hey: it's not soo easy,which I posted.But your Compiler (vs2008 or PellesC or whatever) would make this automatically for you and you only have to copy your part of code into WinMain of this automatic processed code.
The "Managers" then can help you also to add eventhandlers automatically.
you only have to set Breakpoints to the automatic processed Event-Handle-Function - them you can see,if this event is triggered like you want it.
You only think from the wrong direction
Ok, I learned a lot.
(The VS2008 debugger has bugs. If I set a breakpoint on line 100, and start debug, line 109 has the breakpoint. It looks like only the original code can be debugged)
I did start a new project and used the tips from above. I can catch a click on a link ahref field in the notification bubble.
I have disabled the screen so only the bubble is shown
Now I need to catch the menu button and more important the data in the html form (input type radio) in the notification bubble. For this I need to convert the param to a structure...!
I also need to extend the "while getmessage" loop with a timer. If 15 seconds have passed, I need to step out of the loop and quit automatically.
A lot of searching again.
BTW.
Thx all for helping me. Not really one tip did it, you all guided me a bit. If you think your tip helped me a lot then send me a PM with your paypal code. You can also send me your address/or your businessaddress. I will send you a small present/surprise related to my country (Holland).
in Germany we have a good cheese, too and the sense of a community like this great one,is for helping each other-especially beneath developers.
And it's always a question of finding out,how to manage something new
All the best for your further development.
Micha
Attached is the code of my subproject. I will update it if those last points are done. Hope it helps others.
If someone has a link or example code for those points. (or improvements of my code) please let me know.

Background task completion in Windows Phone 7 (with video)

Guys, I wrote a multi-threaded app that is just a simple counter. When it reaches 30,000 the job is done. The counting thread which doesn't have to deal with the form, continues counting if I go back to start menu with the windows button. The app is surely there in the background cause I can see it in the task manager. There seem to be some complications though. Sometimes it's completely shut down after a while; this may be a problem with the emulator and of course I don't have a device to try it on.
Sorry if something like this was said before
a video I uploaded: http://www.youtube.com/watch?v=glzBui95tiY
Do a pastebin of the source code, if you want any serious input on this. Because I doubt it's running in the background (as it's not possible)
It looks like you're using an old emulator build. They've changed things more recently. Apps will no longer keep running.
It's not running in the foreground for sure
they're just two simple threads:
Code:
ThreadPool.QueueUserWorkItem(o =>
{
counter = 0;
complete = false;
while (true)
{
Dispatcher.BeginInvoke(() =>
{
textBlock1.Text = counter.ToString();
if (complete)
{
textBlock2.Text = "Counting Completed!";
}
});
Thread.Sleep(0);
}
});
ThreadPool.QueueUserWorkItem(o =>
{
while (true)
{
Dispatcher.BeginInvoke(() =>
{
if(!complete) counter++;
if (counter == 30000)
complete = true;
});
Thread.Sleep(0);
}
});
RustyGrom said:
It looks like you're using an old emulator build. They've changed things more recently. Apps will no longer keep running.
Click to expand...
Click to collapse
yeah, I think it's the April version. So this doesn't work anymore?
edit: yep! tested on the newest version and it looks like they've now completely killed multitasking, lol
I think that technically internal thread pools should be allowed, but just be killed when the application is closed.
So interesting - how will I be able to make a screenshot of any app?
Like maps or whatever else?
I use this function very open.
Most likely with a button combination, no information about it yet.
The API supports it though WriteableBitmap, which is available in the current WP7 API. So it's definitively possible.
Windcape said:
Most likely with a button combination, no information about it yet.
The API supports it though WriteableBitmap, which is available in the current WP7 API. So it's definitively possible.
Click to expand...
Click to collapse
So it will be build into the system without any 3rd party app needed?
doministry said:
So it will be build into the system without any 3rd party app needed?
Click to expand...
Click to collapse
Who knows, really hard to tell. I'm don't think this week's build have a dedicated screenshots functionality.
But it's definitively possible. As opposed to other functionality.

Successful TCP Connection via CoreCon

So during my break today I added a few more registry paths to check on my HTC Radar and I found HKCU\Software\Microsoft\ConMan\HostLauncher\HostData\. There I found a few Service entries:
Code:
7ABBE0D5-B437-42CA-B57B-CEED61680E4F
11EE50CA-6CD3-45BA-9D65-46E133CFF009
B2FC26AB-D6EC-4426-91FA-9E039F92A639
The first entry did not take me any where but the other two did.
Running those in my test application sent back:
Code:
Int32Type: 0
Int32Type: -2147024809
I know it isnt much and I am not sure what to send to the ConMan so if someone does please tell me:
Code:
private static void ExecutionTest()
{
#region Create Objects
ObjectId DeviceID = new ObjectId("30F105C9-681E-420b-A277-7C086EAD8A4E");
Platform platform = datastoremanager.GetPlatform(PlatformObjectID);
Device device = platform.GetDevice(DeviceID);
#endregion
try
{
//Connect to the device.
device.Connect();
if (device.IsConnected())
{
RemoteAgent ra = device.GetRemoteAgent(new ObjectId("910DCB1B-487B-452b-87FC-73852B5A239C"));
DevicePacketStream ps = ra.CreatePacketStream(new ObjectId(new Guid("11EE50CA-6CD3-45BA-9D65-46E133CFF009")));
// Create and write a packet of data.
Packet packet;
packet = new Packet();
for (int i = 0; i < 4; i++) packet.WriteInt32(i);
packet.WriteString("Hello Smart Device");
ps.Write(packet);
#region While stream is connected, try to read a packet.
while (ps.IsConnected())
{
if (ps.IsPacketAvailable())
{
packet = ps.Read();
while (!packet.IsEndOfPacket())
{
switch (packet.ReadDataType())
{
case DataType.BoolType: bool boolValue = packet.ReadBool(); break;
case DataType.ByteArrayType: byte[] buffer = packet.ReadBytes(); break;
case DataType.ByteType: byte byteValue = packet.ReadByte(); break;
case DataType.CharType: char charValue = packet.ReadChar(); break;
case DataType.Int32Type: Console.WriteLine("Int32Type: " + packet.ReadInt32().ToString()); break;
case DataType.StringType: Console.WriteLine("String: " + packet.ReadString()); break;
default: break;
}
}
break;
}
System.Threading.Thread.Sleep(1000);
}
#endregion
}
}
catch (Exception ex)
{
throw ex;
}
finally { device.Disconnect(); }
}
Huh, you got the remote "GetRemoteAgent" working. Right?
I think i might know how to resolve what to call in to the packet. VS2010 talks to wp7, and uses one of those GUID's; meaning one should be able do binary search all files (in a rom) to see who owns the GUID (what dll handler), disassemble that dll (to ASM/c), and extract "what it wants".
Or if MS has a hidden caller class somewhere
Ill look further into this, thanks
fiinix said:
Huh, you got the remote "GetRemoteAgent" working. Right?
I think i might know how to resolve what to call in to the packet. VS2010 talks to wp7, and uses one of those GUID's; meaning one should be able do binary search all files (in a rom) to see who owns the GUID (what dll handler), disassemble that dll (to ASM/c), and extract "what it wants".
Or if MS has a hidden caller class somewhere
Ill look further into this, thanks
Click to expand...
Click to collapse
Yes I did . Yeah I just need to know what to actually send to to the device. I know Visual Studio communicates this way.
MJCS said:
Yes I did . Yeah I just need to know what to actually send to to the device. I know Visual Studio communicates this way.
Click to expand...
Click to collapse
Great
I, myself tried 20+ GUID's once (from wp7 that _could_ be); all threw exceptions (aka not a remote agent handler).
It feels better now knowing what GUID's i can use.
Well the reg path was quite obvious; why did i not stumble upon that one earlier..
fiinix said:
Great
I, myself tried 20+ GUID's once (from wp7 that _could_ be); all threw exceptions (aka not a remote agent handler).
It feels better now knowing what GUID's i can use.
Well the reg path was quite obvious; why did i not stumble upon that one earlier..
Click to expand...
Click to collapse
Well I only found it since I know have an HTC Radar. My Dell venue pro requires you to manually enter in registry paths to see if they exist or not. I was able to decompile an older HTC registry viewer and then fix it so it didnt require interop unlock.
It should be possible to do registry browsing (but not editing) just fine on a DVP using the standard tools, unless there's a check that specifically blocks them. The browsing uses a native homebrew DLL that doesn't require ID_CAP_INTEROPSERVICES and has no device-specific dependencies. It's the editing that requires interop-unlock and device-specific DLLs.
GoodDayToDie said:
It should be possible to do registry browsing (but not editing) just fine on a DVP using the standard tools, unless there's a check that specifically blocks them. The browsing uses a native homebrew DLL that doesn't require ID_CAP_INTEROPSERVICES and has no device-specific dependencies. It's the editing that requires interop-unlock and device-specific DLLs.
Click to expand...
Click to collapse
There is no GetSubKeys method...anyways lets get back on topic.
I've been trying for weeks to get anything out of this. Nothing so far. I did find out that the Developer unlock is just a byte array of a cookie taken from Microsoft's auth server.
Has anyone had any success with this socket method yet? I really don't know enough about sockets to try.
BTW you have to have a core con connection to the device already open either from app debugging or some other method

Background App to monitor screen output

Can anyone help me with some advice. I want to create an App that is loaded and then left running while other apps are loaded. I then want it to monitor what is output to the smartphone screen and when it recognises a particular pattern or logo being displayed to do something?
Is this possible?
Anyone know how to do - hopefully with javascript?
Phil
Is it a keylogger. Of course you can record monitor all the time, but it's usually needn't. You can regularly check an app that you want to monitor wherether it's running or not, by using this code, as long as you know class name or service name.
public static boolean isMyServiceRunning(Class<?> serviceClass,Context ctx) {
ActivityManager manager = (ActivityManager)ctx.getSystemService(Context.ACTIVITY_SERVICE);
for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
if (serviceClass.getName().equals(service.service.getClassName())) {
return true;
}
}
return false;
}
Correct me if I'm wrong, but this sounds like a Keylogger + Screenlogger. What exactly are you trying to monitor? Your app of anything that is happening on the screen? If its the latter then I very much hope that it is not possible, otherwise that would be a big security hole if any app can simple record the screen of any other app.
Use the Accessibility Service
It requires a special permission from users but it will let you read all the content on the screen, including what users click on etc. I'm working on an app called Sesame Lock Screen that uses the Accessibility Service to make shortcuts for users based on their behavior.
B/c it's a sensitive permission we don't send any of the data back to our servers. You should probably do the same.
Let me know if I can answer more questions about this.

[HELP] Can we use native libs in a module? Mine dies as soon as a lib is added.

Hi,
First, a disclaimer.
I am a Java and xposed noob. My background is in embedded C development so I can get by with some simple Java code and thanks to the great tutorials online I have been able to put together an xposed module but I'm struggling with a problem that is beyond my abilities now and am reaching out to the community for help.
Next, the background.
I have an Android head unit in my car. There is an app that provides me with CarPlay functionality but none of the controls on the steering wheel work with the app. When I analysed the code I found that they handle all of their button inputs using proprietary methods that do not inject an event into any input streams. I wrote an xposed module to hook the button press methods and then inject a proper input into one of the event streams.
Initially I tried to use the command line 'input' command to do this but since it is a Java app and takes about 1s to load it was too slow. My only other option was to create a virtual device on an input stream that I could then use to inject keypresses through the hooked method. To create a virtual device I needed to write C code that my xposed module would be able to access through the JNI. Long story short, after some pain I was able to get the native library integrated into the project and compiling using the NDK.
Finally, the problem.
When I was using the module without the native library it worked but just with a large delay because of the time it takes to load the 'input' java app. I was able to see logs from the module in the logcat as I hooked the method and as I went through the various actions within the hook.
As soon as I introduce the native library though the entire xposed module just stops running completely. I do not get any logs from the module even though I have installed, activated and rebooted. It shows up in the xposed installer but it just does nothing. The funny thing is that this happens even if I make no reference whatsoever to any native functions within the library. All I need to do to kill the module is to build it with the System.loadlibrary line in the Main.java uncommented. As soon as I comment that piece of code out the module starts to hook the function and output logs again. Below is the code from the Main.Java that I am referring to. I am happy to make any manifest, C and gradle files available too. Looking for any ideas as to why the module dies completely as soon as I include this...
Code:
package projects.labs.spike.zlink_xposed_swc;
import de.robv.android.xposed.XposedBridge;
import static de.robv.android.xposed.XposedHelpers.findAndHookMethod;
import de.robv.android.xposed.IXposedHookLoadPackage;
import de.robv.android.xposed.IXposedHookZygoteInit;
import de.robv.android.xposed.XSharedPreferences;
import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.callbacks.XC_LoadPackage;
import de.robv.android.xposed.XposedHelpers;
import android.app.AndroidAppHelper;
import android.content.Intent;
import android.os.Bundle;
import android.content.Context;
/* shellExec and rootExec methods */
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ByteArrayOutputStream;
import android.view.KeyEvent;
import android.media.AudioManager;
public class Main implements IXposedHookLoadPackage {
public static final String TAG = "ZLINK_XPOSED ";
public static void log(String message) {
XposedBridge.log("[" + TAG + "] " + message);
}
//public native int CreateVirtualDevice();
//public native int SendPrev();
@Override
public void handleLoadPackage(final XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {
log("handleLoadPackage: Loaded app: " + lpparam.packageName);
if (lpparam.packageName.equals("com.syu.ms")) {
findAndHookMethod("module.main.HandlerMain", lpparam.classLoader, "mcuKeyRollLeft", new XC_MethodHook() {
@Override
protected void afterHookedMethod(XC_MethodHook.MethodHookParam param) throws Throwable {
// previous
log("PREVKEYHIT");
//rootExec("input keyevent 88");
log("EVENTSENT");
//Below was trying to use media keys which zlink never responded to...
/* Context context = (Context) AndroidAppHelper.currentApplication();
AudioManager mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
KeyEvent event = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PREVIOUS);
mAudioManager.dispatchMediaKeyEvent(event);
KeyEvent event2 = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_PREVIOUS);
mAudioManager.dispatchMediaKeyEvent(event2);*/
//Below is the failed broadcast intent method...
/*Context mcontext = (Context) AndroidAppHelper.currentApplication();
Intent i = new Intent("com.android.music.musicservicecommand");
i.putExtra("command", "pause");
mcontext.sendBroadcast(i);*/
}
});
}
}
public static String rootExec(String... strings) {
String res = "";
DataOutputStream outputStream = null;
InputStream response = null;
try {
Process su = Runtime.getRuntime().exec("su");
outputStream = new DataOutputStream(su.getOutputStream());
response = su.getInputStream();
for (String s : strings) {
s = s.trim();
outputStream.writeBytes(s + "\n");
outputStream.flush();
}
outputStream.writeBytes("exit\n");
outputStream.flush();
try {
su.waitFor();
} catch (InterruptedException e) {
e.printStackTrace();
}
res = readFully(response);
} catch (IOException e) {
e.printStackTrace();
} finally {
Closer.closeSilently(outputStream, response);
}
return res;
}
public static String readFully(InputStream is) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int length = 0;
while ((length = is.read(buffer)) != -1) {
baos.write(buffer, 0, length);
}
return baos.toString("UTF-8");
}
static {
System.loadLibrary("native-lib");
}
}
Have you tried capturing an ADB log _during the bootup_?
Xposed bugs in general are unfortunaley hard to identify and harder to fix, since the underlying code isn't well understood and/or maintained by many people.
Namnodorel said:
Have you tried capturing an ADB log _during the bootup_?
Xposed bugs in general are unfortunaley hard to identify and harder to fix, since the underlying code isn't well understood and/or maintained by many people.
Click to expand...
Click to collapse
Thanks for the response. I think that I have it figured out. The System.loadlibrary method looks for the native library within a path relative to the process that it is running within. The code within the apk ultimately does not run within that apk process, it runs within the xposed process. You therefore need to give xposed an absolute path to the library using the system.load method instead. Going to do some fiddling tonight and see if it works.
looxonline said:
Thanks for the response. I think that I have it figured out. The System.loadlibrary method looks for the native library within a path relative to the process that it is running within. The code within the apk ultimately does not run within that apk process, it runs within the xposed process. You therefore need to give xposed an absolute path to the library using the system.load method instead. Going to do some fiddling tonight and see if it works.
Click to expand...
Click to collapse
What about an alternative without using library we discussed earlier? Are you planning to test this as well?
If so, please let me know how it went.
C3C076 said:
What about an alternative without using library we discussed earlier? Are you planning to test this as well?
If so, please let me know how it went.
Click to expand...
Click to collapse
I didn't try it yet for two reasons.
1.) From the research I have done it seems as if my app would need the system INJECT_EVENTS permission in order to send keypress events outside of its own process. I cannot get this permission unless I sign my apk with the system cert that the ROM is compiled with. Maybe the method that you are using in the suggestion does not need this cert? Have you personally used this to inject key events across processes? I did see that you are getting the context of the system input service so maybe that solves this issue if the request appears to come from that PID...???
2.) The unit that I am working with has only two input devices and none of them have the keycodes I require. Does your method use a completely virtual device that is created on the fly? If so then it could work well without the need for me to create an HID input device.
I mostly was just on a role with the method that I was trying and I didn't want to turn back since I was so far down the road. I'm sure you understand how addictive certain challenges become and its quite fun to try to get them working even if they may not be the most optimal way.
In any case I managed to get the native library working last night and can successfully convince Android that I have a real HID keyboard plugged in and then send key events through that keyboard. Still not done though as there are a few hiccups that need solving. May still try your original suggestion. Thanks
looxonline said:
I didn't try it yet for two reasons.
1.) From the research I have done it seems as if my app would need the system INJECT_EVENTS permission in order to send keypress events outside of its own process. I cannot get this permission unless I sign my apk with the system cert that the ROM is compiled with. Maybe the method that you are using in the suggestion does not need this cert? Have you personally used this to inject key events across processes? I did see that you are getting the context of the system input service so maybe that solves this issue if the request appears to come from that PID...???
2.) The unit that I am working with has only two input devices and none of them have the keycodes I require. Does your method use a completely virtual device that is created on the fly? If so then it could work well without the need for me to create an HID input device.
I mostly was just on a role with the method that I was trying and I didn't want to turn back since I was so far down the road. I'm sure you understand how addictive certain challenges become and its quite fun to try to get them working even if they may not be the most optimal way.
In any case I managed to get the native library working last night and can successfully convince Android that I have a real HID keyboard plugged in and then send key events through that keyboard. Still not done though as there are a few hiccups that need solving. May still try your original suggestion. Thanks
Click to expand...
Click to collapse
I see.
1) Depends on in what process (package) your hooks are running within because permissions of this process apply of course, not the permissions you define in your module's manifest.
I am using key injecting method within "android" process (package) which means it works without me needing to worry about INJECT_EVENTS permission as "android" process already has it.
By the way, missing permissions are not of a big issue when developing with xposed as you can really do some magic with it.
E.g. I was adding some functionality to SystemUI that required some additional permissions that SystemUI typically lacks. So my module takes care of it.
https://github.com/GravityBox/Gravi...eco/pie/gravitybox/PermissionGranter.java#L75
C3C076 said:
I see.
1) Depends on in what process (package) your hooks are running within because permissions of this process apply of course, not the permissions you define in your module's manifest.
I am using key injecting method within "android" process (package) which means it works without me needing to worry about INJECT_EVENTS permission as "android" process already has it.
By the way, missing permissions are not of a big issue when developing with xposed as you can really do some magic with it.
E.g. I was adding some functionality to SystemUI that required some additional permissions that SystemUI typically lacks. So my module takes care of it.
https://github.com/GravityBox/Gravi...eco/pie/gravitybox/PermissionGranter.java#L75
Click to expand...
Click to collapse
Wow! I had no idea that you can use an xposed helper function to grant permissions to whatever process you are hooked within like that. That is VERY cool. Thanks so much for sharing

Categories

Resources