I need to turn off the phone (radio?) in my application
The only thing I found is by using lineSetEquipmentState but I couldn't find how to work with it.
Another option is with the openNetCf.tapi but this dll isn't free.
Any ides?
Someone? something?
Other option will be if possible to call flight mode
You can do this via RIL:
Code:
RIL_SetEquipmentState(FHandle,RIL_EQSTATE_MINIMUM);
Here FHandle is handle to opened RIL.
TrashKalmar said:
You can do this via RIL:
Code:
RIL_SetEquipmentState(FHandle,RIL_EQSTATE_MINIMUM);
Here FHandle is handle to opened RIL.
Click to expand...
Click to collapse
Thanks for the info, seems the right way.
However something doesn't work, every thing looks ok, the hRes is 0 but nothing happens.
Any ideas?
Code:
[DllImport("ril.dll")]
private static extern IntPtr RIL_SetEquipmentState(IntPtr hRil);
public static bool SetAirplaneState()
{
IntPtr hRil = IntPtr.Zero;
IntPtr hRes = IntPtr.Zero;
hRes = RIL_Initialize(1, // RIL port 1
new RILRESULTCALLBACK(SetEquipmentStateCallback), // function to call with result
null, // function to call with notify
0, // classes of notification to enable
0x00000001, // RIL parameters
out hRil); // RIL handle returned
if (hRes != IntPtr.Zero)
{
return false;
}
hRes = RIL_GetCellTowerInfo(hRil);
waithandle.WaitOne();
RIL_Deinitialize(hRil);
return true;
}
private static void SetEquipmentStateCallback(uint dwCode, IntPtr hrCmdID, IntPtr lpData, uint cbData, uint dwParam)
{
waithandle.Set();
}
private static AutoResetEvent waithandle = new AutoResetEvent(false);
public delegate void RILNOTIFYCALLBACK(uint dwCode,
IntPtr lpData,
uint cbData,
uint dwParam);
public delegate void RILRESULTCALLBACK(uint dwCode,
IntPtr hrCmdID,
IntPtr lpData,
uint cbData,
uint dwParam);
alto said:
Code:
...
hRes = RIL_Initialize(1, // RIL port 1
new RILRESULTCALLBACK(SetEquipmentStateCallback), // function to call with result
null, // function to call with notify
0, // classes of notification to enable
0x00000001, // RIL parameters
out hRil); // RIL handle returned
if (hRes != IntPtr.Zero)
{
return false;
}
hRes = RIL_GetCellTowerInfo(hRil);
...
Click to expand...
Click to collapse
What do you want to achieve? If you want to turn off the phone, you should use RIL_SetEquipmentState. But in your code you obtain Cell Tower info via RIL_GetCellTowerInfo.
Also, if I remember rightly, you must specify RILNOTIFYCALLBACK in RIL_Initialize.
TrashKalmar said:
What do you want to achieve? If you want to turn off the phone, you should use RIL_SetEquipmentState. But in your code you obtain Cell Tower info via RIL_GetCellTowerInfo.
Also, if I remember rightly, you must specify RILNOTIFYCALLBACK in RIL_Initialize.
Click to expand...
Click to collapse
Correct, sorry I made mish-mash in the code I copied here.
My error was that I forgot to pass the second parameter to the SetEquipmentState function.
Works great now, Thanks!
Any chance of publishing this code?
Am I right in that it takes some time for the application to quit?
Thanks,
ajhvdb, this code works quite fine. And yes, it may take a while to quit app.
TrashKalmar said:
ajhvdb, this code works quite fine. And yes, it may take a while to quit app.
Click to expand...
Click to collapse
If I past your code into my code I'm missing RIL_Initialize, RIL_GetCellTowerInfo.
Sorry for being slow with this but I never used delegates and RIL before
If I past your code into my code I'm missing RIL_Initialize, RIL_GetCellTowerInfo.
Sorry for being slow with this but I never used delegates and RIL before
Bump
Related
Hi,
I'm using the the RIL_Initialize-Call from the stril.zip.
(The programm works well - thank you for your great work!!! ;o)
Now I'd tried to implement the RIL in an own project with more Classes and now, there's a problem:
I've got a class KKsmsIn. doRIL, resultCallback, notifyCallback (KKsmsIn::doRil a.s.o.) are implemented as public (tried also private). Whenn I trie to compile the programm then line
RIL_Initialize(1, resultCallback, notifyCallback...
generates an error: Cannot vonvert parameter 2 from 'void (unsingned long...' to 'void (__cdecl *)(insigned long...'
I'd implemented the RIL.h and RIL.lib, If I mark the resultCallback the description is 'void __cdecl resultCallback(...'
Pse help, think it's a little sign or command which is missing,
but I work since 12 hours on this line and have no idea, how the solution could be :-(
Greetings from hannovre,
andreas
PS: And now I'm going to donate some money ;o)
-> is there a chance do donate without a creditcard? *hope*
Try following....
it is part of my code :
Code:
CRadio g_radio;
//////////////////////////////////////////////////////////////////////
// Callback functions
//////////////////////////////////////////////////////////////////////
void CALLBACK NotifyCallback(DWORD dwCode, const void *lpData, DWORD cbData, DWORD dwParam)
{
g_radio.OnNotifyCallback(dwCode, lpData, cbData, dwParam);
}
void CALLBACK ResultCallback(DWORD dwCode, HRESULT hrCmdID, const void *lpData, DWORD cbData, DWORD dwParam)
{
g_radio.OnResultCallback(dwCode, hrCmdID, lpData, cbData, dwParam);
}
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CRadio::CRadio()
{
dwParam = 0x55AA55AA;
dwNotificationClasses = 0xFF0000;
}
CRadio::~CRadio()
{
}
bool CRadio::InitializeRIL()
{
HRESULT result;
result = RIL_Initialize(1, ResultCallback, NotifyCallback, dwNotificationClasses, dwParam, &hRil);
return hRil!=NULL;
}
void CRadio::OnNotifyCallback(DWORD dwCode, const void *lpData, DWORD cbData, DWORD dwParam)
{
// ...
}
void CRadio::OnResultCallback(DWORD dwCode, HRESULT hrCmdID, const void *lpData, DWORD cbData, DWORD dwParam)
{
// ...
}
It works! Many thanks
Greetings from hannovre and anymore good speed,
andreas
you can do without the global variable, if you pas 'this' for the dwParam in RIL_Initialize, and then cast the dwParam in notify and result back to CRadio*.
I just got my Treo and noting the lack of a software reset (the need to use the stylus on the reset button really annoys me), I decided to build my own.
The Reset and Suspend part of my little program works like a charm and then I decided to improve a little more and add a Hard Reset feature, which would restore the device to its factory settings.
Searching high and low on the net I found two possible ways. The first one involved calling SetCleanRebootFlag() and then reset the device.
Code:
[DllImport("coredll.dll", SetLastError=true)]
public static extern void SetCleanRebootFlag();
[DllImport("coredll.dll", SetLastError=true)]
private static extern int SetSystemPowerState(IntPtr psState, PowerStateFlags flags, uint Options);
[DllImport("coredll.dll", SetLastError=true)]
private static extern bool KernelIoControl(int dwIoControlCode, IntPtr inBuf, int inBufSize, IntPtr outBuf, int outBufSize, ref int bytesReturned);
public static void SoftReset()
{
if (SetSystemPowerState(IntPtr.Zero, PowerStateFlags.Reset, 0x1000) != 0)
{
int bytesReturned = 0;
if (!KernelIoControl(0x101003c, IntPtr.Zero, 0, IntPtr.Zero, 0, ref bytesReturned))
{
throw new Win32Exception(Marshal.GetLastWin32Error());
}
}
}
public static void HardReset()
{
SetCleanRebootFlag();
SoftReset();
}
The other involved using the ConfigurationManager to process a XML that would perform a "RemoteWipe".
Code:
public static void HardReset()
{
XmlDocument doc = new XmlDocument();
doc.LoadXml("<wap-provisioningdoc><characteristic type='RemoteWipe'><parm name='doWipe' value='1'/></characteristic></wap-provisioningdoc>");
ConfigurationManager.ProcessConfiguration(doc, true);
}
The first method didn't work because after Windows Mobile 5 it ignores the CleanBootFlag; the second method worked... too much.
It corrupted the microSD on the device to the point that it needed to be reformatted in order to be recognized again.
Does anyone had any experience with that?
Dear сolleagues and development guru!
I have some stopper in Power Management. I hope somebody will help me to understand.
Technologies: C#, .NET 3.5
The main point of application:
Make beep periodically.
Main problem is:
When PocketPC in active mode application running correct, but when PocketPC went to sleep mode it does not make a beep. As I understood speaker is turned off in sleep mode (like all other devices in PocketPC).
Question:
How can I turn on speaker in sleep mode?
Simply what I need is turn on speaker, make beep and back speaker to previous mode without wake up all device.
I tried code like this:
Code:
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Media;
using System.Threading;
using System.Runtime.InteropServices;
namespace TestProject
{
static class Program
{
public const int POWER_NAME = 0x00000001;
public enum DevicePowerState : int
{
Unspecified = -1,
D0 = 0,
D1,
D2,
D3,
D4,
}
[DllImport("coredll.dll", SetLastError = true)]
public static extern int SetDevicePower(
string pvDevice,
int dwDeviceFlags,
DevicePowerState DeviceState
);
[DllImport("coredll.dll", SetLastError = true)]
public static extern IntPtr SetPowerRequirement(
string device,
DevicePowerState state,
uint deviceFlags,
IntPtr systemState,
ulong stateFlags
);
[DllImport("coredll.dll", SetLastError = true)]
public static extern int ReleasePowerRequirement(IntPtr handle);
[MTAThread]
static void Main()
{
MessageBox.Show("Application is running...", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Asterisk,MessageBoxDefaultButton.Button1);
string deviceName = "WAV1:"; // speaker
for (; ; )
{
// set D0 power value
IntPtr handle = SetPowerRequirement(deviceName, DevicePowerState.D0, 1, IntPtr.Zero, 0);
// make a beep
SystemSounds.Beep.Play();
// set default power value
ReleasePowerRequirement(handle);
Thread.Sleep(10000);
}
}
}
}
And like this:
Code:
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Media;
using System.Threading;
using System.Runtime.InteropServices;
namespace TestProject
{
static class Program
{
public const int POWER_NAME = 0x00000001;
public enum DevicePowerState : int
{
Unspecified = -1,
D0 = 0,
D1,
D2,
D3,
D4,
}
[DllImport("coredll.dll", SetLastError = true)]
public static extern int SetDevicePower(
string pvDevice,
int dwDeviceFlags,
DevicePowerState DeviceState
);
[DllImport("coredll.dll", SetLastError = true)]
public static extern IntPtr SetPowerRequirement(
string device,
DevicePowerState state,
uint deviceFlags,
IntPtr systemState,
ulong stateFlags
);
[DllImport("coredll.dll", SetLastError = true)]
public static extern int ReleasePowerRequirement(IntPtr handle);
[MTAThread]
static void Main()
{
MessageBox.Show("Application is running...", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Asterisk,MessageBoxDefaultButton.Button1);
string deviceName = "WAV1:"; // speaker
int resDevicePowerOn = SetDevicePower(deviceName, POWER_NAME, DevicePowerState.D0);
for (; ; )
{
// make a beep
SystemSounds.Beep.Play();
Thread.Sleep(10000);
}
}
}
}
But any of these codes does not work - there are no beep in sleep mode.
Hi, I just happened to find an article from codeproject.
You may want to take a look at it.
http://www.codeproject.com/KB/mobile/WiMoPower1.aspx
I think what you need is cerunappattime.
It seems you are enabling the audio device to run in low-power mode, but you are not actually telling the CPU to keep running ("unattended mode").
Lookup PowerPolicyNotify, specifically PPN_UNATTENDEDMODE.
You may also need to periodically call SHIdleTimerResetEx and/or SystemIdleTimerReset to keep the device active in unattended mode or it will still truely suspend.
Prevent the system enter sleep mode
The system will stop all activitis when the system enter sleep mode.So you must prevent the system enter sleep mode.
The system sleep mode:
on -> unattended -> suspend
You can run:
on -> unattended -> resuming
my code:time up is system on
ex file:screenblack.rar
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using Microsoft.Win32;
namespace ScreenBlack
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//取得系統狀態 Get system state
[DllImport("Coredll.dll", SetLastError = true)]
public static extern int GetSystemPowerState(StringBuilder PowerState, int length, ref int Flags);
//設定系統電源狀態
[DllImport("Coredll.dll")]
public static extern int SetSystemPowerState(int psState, int StateFlags, int Options);
public const int POWER_STATE_ON = 0x12010000;
public const int NULL = 0;
public const int POWER_FORCE = 0x00001000;
private void Form1_Load(object sender, EventArgs e)
{
//設定 timer1 的設定值 0.5 秒 Set timer1 activie in 0.5 second
timer1.Interval = 500;
//啟動定時器 Start timer1
timer1.Enabled = true;
}
//宣告變數判斷是否有改變 suspend 0:沒有改變 1:有改變
int change = 0;
//宣告變數判斷執行秒數 10
int second = 20;
private void timer1_Tick(object sender, EventArgs e)
{
//設定其標為 0
int flags = 0;
//取得系統狀態名稱 on、suspend、unattended、resuming
StringBuilder stb = new StringBuilder(260);
//取得系統狀態 Get Current system state
GetSystemPowerState(stb, stb.Capacity, ref flags);
//判斷目前系統狀態
if (flags.ToString() == "4194304")
{
//改變 unattended 為 resuming Chang unattended into resuming
RegistryKey reg = Registry.LocalMachine.OpenSubKey(@"System\CurrentControlSet\Control\Power\State\Suspend", true);
reg.SetValue("Flags", "268435456", RegistryValueKind.DWord);
reg.Close();
//設定 reg 有改變
change = 1;
}
else if (flags.ToString() == "268435456")
{
//秒數減一
second--;
//判斷 second 是否等於零
if (second == 0)
{
//************
// your code
//************
//system on
SetSystemPowerState(NULL, POWER_STATE_ON, POWER_FORCE);
//設定秒數
second = 20;
}
}
else
{
//判斷是否有改變
if (change == 1)
{
//改變 unattended 為 resuming Chang unattended into resuming
RegistryKey reg = Registry.LocalMachine.OpenSubKey(@"System\CurrentControlSet\Control\Power\State\Suspend", true);
reg.SetValue("Flags", "2097152", RegistryValueKind.DWord);
reg.Close();
//設定 reg 有改變
change = 0;
//設定秒數
second = 20;
}
}
}
}
}
I'm looking for a way to turn off the data (GRPS)
Search didn't brought me anything usefull, I'm sure there is somwhere the data but can't find it.
I'm especially need it for WM 6.5 (HD2)
Search around for Modaco's NoData program. It's late and I'm too tired to search it up for you right now.
kekkle said:
Search around for Modaco's NoData program. It's late and I'm too tired to search it up for you right now.
Click to expand...
Click to collapse
Thanks for the replay but it’s not what I meant, sorry for not be clarify.
I know the NoData app and actually i just finish writing something similar but more user friendly, hope to release it asap (Now I have problem with the icon )
What I’m looking is a way to turn off programmatically the data connection of the device, what the CommManager in the HTC sense do.
I tried to use the RAS api but it didn't work
look for jmlcomm.exe here at xda and use it in your app.simple command line call.and free to use.
MichelDiamond said:
look for jmlcomm.exe here at xda and use it in your app.simple command line call.and free to use.
Click to expand...
Click to collapse
Thanks for the idea, I'll try it.
But I prefer to do it directly from my app. without calling external tool.
I found a solution!
Its from few posts in the net, don't remember where exactly with some modification of me.
here is the code I use, if someone else will need it:
Code:
using System;
using System.Text;
using System.Runtime.InteropServices;
namespace RasHelper
{
class RasHelper
{
private const int SUCCESS = 0;
private const int ERROR_NOT_ENOUGH_MEMORY = 8;
private const int RASBASE = 600;
private const int ERROR_BUFFER_TOO_SMALL = RASBASE + 3;
private const int ERROR_INVALID_SIZE = RASBASE + 32;
// --- RASCONN data structure definition (refer to ras.h) --
private const int RAS_MaxEntryName = 20;
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct RASCONN
{
public int dwSize;
public IntPtr hrasconn;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = RAS_MaxEntryName + 1)]
public string szEntryName;
}
// --------------------------------------------
[DllImport("coredll.dll", SetLastError = true, CharSet = CharSet.Auto)]
private static extern uint RasEnumConnections(
[In, Out] RASCONN[] rasconn,
[In, Out] ref int cb,
[Out] out int connections);
[DllImport("coredll.dll")]
private static extern uint RasHangUp(IntPtr pRasConn);
/// <summary>
/// Returns all active RAS connections as an array of data structure RASCONN
/// </summary>
/// <returns></returns>
public static RASCONN[] GetAllConnections()
{
RASCONN[] tempConn = new RASCONN[1];
RASCONN[] allConnections = tempConn;
tempConn[0].dwSize = Marshal.SizeOf(typeof(RASCONN));
int lpcb = tempConn[0].dwSize;
int lpcConnections = 0;
uint ret = RasEnumConnections(tempConn, ref lpcb, out lpcConnections);
if (ret == ERROR_INVALID_SIZE)
{
throw new Exception("RAS: RASCONN data structure has invalid format");
}
else if (ret == ERROR_BUFFER_TOO_SMALL && lpcb != 0)
{
// first call returned that there are more than one connections
// and more memory is required
allConnections = new RASCONN[lpcb / Marshal.SizeOf(typeof(RASCONN))];
allConnections[0] = tempConn[0];
ret = RasEnumConnections(allConnections, ref lpcb, out lpcConnections);
}
// Check errors
if (ret != SUCCESS)
{
throw new Exception("RAS returns error: " + ret);
}
if (lpcConnections > allConnections.Length)
{
throw new Exception("RAS: error retrieving correct connection count");
}
else if (lpcConnections == 0)
{
// if there are no connections resize the data structure
allConnections = new RASCONN[0];
}
return allConnections;
}
/// <summary>
/// Closes all active RAS connections
/// </summary>
/// <returns></returns>
public static void CloseAllConnections()
{
RASCONN[] connections = GetAllConnections();
for (int i = 0; i < connections.Length; ++i)
{
//MessageBox.Show(connections[i].ToString());
RasHangUp(connections[i].hrasconn);
}
}
/// <summary>
/// Check if there are open data connections
/// </summary>
/// <returns></returns>
public static bool IsConnectionsOpen()
{
RASCONN[] connections = GetAllConnections();
if (connections.Length > 0)
return true;
else
return false;
}
}
}
I'm a noob when it comes to both java and xposed, although I can more or less "read" java. I'm trying to create my first xposed plugin.
This is in the source (via jadx) from my original apk:
Code:
private void onHandle(byte[] data, int start, int length) {
byte b = data[start];
I wrote in my plugin:
Code:
findAndHookMethod("com.syu.ms.dev.ReceiverMcu", lpparam.classLoader, "onHandle", byte[].class, int.class, int.class, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(XC_MethodHook.MethodHookParam param) throws Throwable {
[B]byte[] data = assetAsByteArray(param.thisObject, "byte[].class");[/B]
int start = getIntField(param.thisObject, "start");
int length = getIntField(param.thisObject, "length");
byte b = data[start];
....... etcetera .................
The bold part is what I need. I know that this line of code is wrong, but I'm already trying (monkey like) all kinds of constructions, but I always get an error.
How can I access that "byte[] data" from my original apk in my plugin?
The arguments are in 'param.args'. Since you want to access the first one, what you need is 'byte[] data = (byte[]) param.args[0];'
JoseRebelo said:
The arguments are in 'param.args'. Since you want to access the first one, what you need is 'byte[] data = (byte[]) param.args[0];'
Click to expand...
Click to collapse
Thanks a lot. It compiles fine now.
Now see if it really works