Background task completion in Windows Phone 7 (with video) - Windows Phone 7 Development and Hacking

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.

Related

WM 6.1 Simple App Error

I am learning to program for windows mobile. I am working on making a small app, and when I test it with virtually nothing in the program (just a main menu, form, and 2 labels), I get a error when testing on my phone.
The error is:
An unhandled exception of type 'System.ObjectDisposedException' occurred in System.Drawing.dll
This happens no matter what I do, but does not happen in the emulator.
jexmex said:
I am learning to program for windows mobile. I am working on making a small app, and when I test it with virtually nothing in the program (just a main menu, form, and 2 labels), I get a error when testing on my phone.
The error is:
An unhandled exception of type 'System.ObjectDisposedException' occurred in System.Drawing.dll
This happens no matter what I do, but does not happen in the emulator.
Click to expand...
Click to collapse
There has to be some code that is causing this issue. Are you saying that your app does not have any code in it at all? If that's the case then it's probably one of the controls that you're using. Are they standard windows .Net controls, or are you using 3rd party controls?
The error message basically means that an object has been created and then disposed and you're trying to do something with it after that. That obviously isn't gonna work
Give us some more information, or even better, give us the code that causes the error.
Yeah I have not added any custom code, just added standard toolkit items (main menu was already there when I made the new project, and 2 labels).
I am going to try just making a new project, and not doing anything to it, and just running it, to see if that works, but I dont think it will.
This is the complete code from the new project that I did nothing to, and it still errored out.
namespace SmartDeviceProject4
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
private System.Windows.Forms.MainMenu mainMenu1;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.Menu = this.mainMenu1;
this.components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
this.Text = "Form1";
this.AutoScroll = true;
}
#endregion
}
}
Click to expand...
Click to collapse
Some other information:
using Windows Standard SDK 6
Phone is running Windows Mobile 6.1 with Compact framework of 3.5
jexmex said:
This is the complete code from the new project that I did nothing to, and it still errored out.
Some other information:
using Windows Standard SDK 6
Phone is running Windows Mobile 6.1 with Compact framework of 3.5
Click to expand...
Click to collapse
To be perfectly honest with you mate, I'm at a bit of a loss. Do you have another device you could try it on? It's clutching at straws a bit, but there could possibly be a problem with the installation of .Net 3.5 on your phone. That would obviously explain why it works on the emulator but not your phone, but it really is a bit far fetched.
If you don't have another device, maybe try re-installing .Net and see if that helps.
johncmolyneux said:
To be perfectly honest with you mate, I'm at a bit of a loss. Do you have another device you could try it on? It's clutching at straws a bit, but there could possibly be a problem with the installation of .Net 3.5 on your phone. That would obviously explain why it works on the emulator but not your phone, but it really is a bit far fetched.
If you don't have another device, maybe try re-installing .Net and see if that helps.
Click to expand...
Click to collapse
I have already tried reinstalling .net (on the phone), with no luck, and I dont have any other device to test on.
Really sucks, cause I really wanted to get into mobile app development.

[Q] How to implement Transparent Labels and other controls [vb.net]

I've been banging my head against this one all morning and now i have a head ache so i decided to stick it out to you lot.
I want to make all my user controls (labels, checkbox's etc) transparent - well the text at least. I found this thread on MSDN but i'll be honest and say i'm not entirely sure what i'm supposed to do with it.
Thanks for your thoughts.
Works a treat. Lifted the code from the site and dropped it straight into the form class.
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.WindowsCE.Forms;
namespace TestDevApp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
forum.xda-developers.com/search.php?searchid=90851847
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
DrawLabel(label1,e.Graphics);
DrawLabel(label2, e.Graphics);
DrawLabel(label3, e.Graphics);
DrawLabel(label4, e.Graphics);
}
private void DrawLabel(Label label, Graphics gfx)
{
if (label.TextAlign == ContentAlignment.TopLeft)
{
gfx.DrawString(label.Text, label.Font, new SolidBrush(label.ForeColor), label.Bounds);
}
else if (label.TextAlign == ContentAlignment.TopCenter)
{
SizeF size = gfx.MeasureString(label.Text, label.Font);
float left = ((float)this.Width + label.Left) / 2 - size.Width / 2;
RectangleF rect = new RectangleF(left, (float)label.Top, size.Width, label.Height);
gfx.DrawString(label.Text, label.Font, new SolidBrush(label.ForeColor), rect);
}
else //is aligned at TopRight
{
SizeF size = gfx.MeasureString(label.Text, label.Font);
float left = (float)label.Width - size.Width + label.Left;
RectangleF rect = new RectangleF(left, (float)label.Top, size.Width, label.Height);
gfx.DrawString(label.Text, label.Font, new SolidBrush(label.ForeColor), rect);
}
}
}
}
Devtrans is the view in VS
Transparent is the actual running code.
Cool thanks.
I did try using DrawString but the drawn text doesn't scroll with the form when you... well.... scroll the form.
I'm gonna have the afternoon off but i will check it out properly later. Would this also work for check boxes? If so what are the changes that would need to be made?
Checkboxes might be a different matter. The above method does not work, it only deals with the text caption. There is is an article on The Code Project at
http://www.codeproject.com/KB/dotnet/TransparentControl.aspx
It appears like they have almost created a control from scratch. You may have to take control/override that much of the object, to get it to work, that you have almost created a new control.
stephj said:
Checkboxes might be a different matter. The above method does not work, it only deals with the text caption. There is is an article on The Code Project at
http://www.codeproject.com/KB/dotnet/TransparentControl.aspx
It appears like they have almost created a control from scratch. You may have to take control/override that much of the object, to get it to work, that you have almost created a new control.
Click to expand...
Click to collapse
I did see that page but i couldn't figure out how the hell to use it
Ok, so now you have found one of the BIGGEST challenges to WM development.
I spent 4+ months trying to get the same thing you are looking for (well, what I assume you are looking for), that is: A transparent label that you can use your finger to scroll.
If that is what you are looking for, I can tell you right now that you need to either look into custom controls that already do this or decide how much time you are willing to invest into something as simple as that.
Here is the basic components that you will need to code to get DrawString to properly scroll with your finger:
You will need to code up some kind of container or panel that holds the current virtual x,y coordinates.
You will need to code up some kind of custom control that can be added to the previously made container
Create logic in the container to take the current virtual x,y coords and determine which custom controls are visible and should be drawn on the screen, pass them their offset coords, and draw the control
Override the OnMouse*ACTION* events on the container to manipulate the virtual x,y coords and then refresh the screen
You also will need to know about double buffering so you don't get any flickering.
It's a very very hard thing to do on WinMo, something that other platforms take for granted. This is one of the reasons that some custom WinMo programs have UIs that are either really terrible, or take tons of resources.
If you want to give it a go (and I would highly recommend doing it, I can't tell you how much I learned about software development by creating my own custom controls) I can help point you in the right directions. Feel free to take a look at the code I've written for my Facebook app (specifically the XFControls and SenseUI projects). I'm not on XDA as often as I'd like, but send me a PM with your questions and I'll respond when I log in.
Good Luck!

[Q] Database question

Hi guys,
We are currently developing an app which stores the users contacts for a quick search.
Any tip on which DB to use (SQL CE, WP7DB, Ninja DB, Rapid Repository and so on)?
My primary and most important requirement is that the database should be quick to load and search on application startup.
We are currently using IsolatedStorageFile together with ObservableCollection which is taking too long to load (~6 seconds to load and search 600 contacts from startup).
Any tip would be much appreciated!!
take a look on CodePlex, this is an example:
http://winphone7db.codeplex.com/
or in general...
http://www.codeplex.com/site/search?query=windows phone database&ac=8
namiran said:
We are currently using IsolatedStorageFile together with ObservableCollection which is taking too long to load (~6 seconds to load and search 600 contacts from startup).
Any tip would be much appreciated!!
Click to expand...
Click to collapse
I believe you have serious problems in design or implementation (or both ). What is the total size of your contact collection? How you serializing that collection? 600 contacts - it's just nothing for ISF file operations...
andreacorti said:
take a look on CodePlex, this is an example:
http://winphone7db.codeplex.com/
or in general...
http://www.codeplex.com/site/search?query=windows phone database&ac=8
Click to expand...
Click to collapse
Thanks!
Do you have any experience with winphone7db performance?
I know there are several solutions out there, I guess i would need the one with the fastest loading time. Don't need any advanced performance or query operations though.
sensboston said:
I believe you have serious problems in design or implementation (or both ). What is the total size of your contact collection? How you serializing that collection? 600 contacts - it's just nothing for ISF file operations...
Click to expand...
Click to collapse
I think you are more advanced developer than I am since I really don't even know how to check the size of the collection.
However this is basically the operation I am performing
on application firststart:
this.contactListOld = new ObservableCollection<Person>();
contacts.SearchAsync(string.Empty, FilterKind.None, "");
foreach contact
contactListOld.Add(b);
when application exits:
save contactListOld
on application load:
load contactListOld
[DataContract]
public class Person
{
...
}
public class IsoStoreHelper
{
public static void SaveList<T>(string folderName, string dataName, ObservableCollection<T> dataList) where T : class
{
if (!IsoStore.DirectoryExists(folderName))
{
IsoStore.CreateDirectory(folderName);
}
string fileStreamName = string.Format("{0}\\{1}.dat", folderName, dataName);
using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream(fileStreamName, FileMode.Create, IsoStore))
{
DataContractSerializer dcs = new DataContractSerializer(typeof(ObservableCollection<T>));
dcs.WriteObject(stream, dataList);
}
}
public static ObservableCollection<T> LoadList<T>(string folderName, string dataName) where T : class
{
ObservableCollection<T> retval = new ObservableCollection<T>();
string fileStreamName = string.Format("{0}\\{1}.dat", folderName, dataName);
try
{
using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream(fileStreamName, FileMode.OpenOrCreate, IsoStore))
{
if (stream.Length > 0)
{
DataContractSerializer dcs = new DataContractSerializer(typeof(ObservableCollection<T>));
retval = dcs.ReadObject(stream) as ObservableCollection<T>;
}
}
}
catch (Exception es)
{
es.ToString();
}
return retval;
}
}
Personally I've made the switch to the built in Mango SQL CE database, seams performant enough and it's much more pleasant to work with than dealing with serializing data directly to isolated storage. Not to mention u can use LINQ to SQL.
Nudua said:
Personally I've made the switch to the built in Mango SQL CE database, seams performant enough and it's much more pleasant to work with than dealing with serializing data directly to isolated storage. Not to mention u can use LINQ to SQL.
Click to expand...
Click to collapse
But doesn't the loading of the database take a lot of time? How many objects/rows do you store in your database?
Thanks for your input!
namiran said:
I think you are more advanced developer than I am since I really don't even know how to check the size of the collection.
Click to expand...
Click to collapse
I created small project for you to demonstrate simple binary serialization to ISF. I hope you will be happy with timing
P.S. You may also reduce serialization time by using MemoryStream.
sensboston said:
I created small project for you to demonstrate simple binary serialization to ISF. I hope you will be happy with timing
P.S. You may also reduce serialization time by using MemoryStream.
Click to expand...
Click to collapse
Just tried it and it was Really quick!
Gonna see if I can transfer this to my code, thanks so far!
namiran said:
Gonna see if I can transfer this to my code, thanks so far!
Click to expand...
Click to collapse
You are welcome!
P.S. You may also press "thanks" button on my post

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

[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