What is this, guys? - Optimus L3, L5, L7 Q&A, Help & Troubleshooting

I installed CWM 6.0.3.6. But it show this message when I enter recovery. I tried to disregard. But it is annoying.
So what does mean that, guys?
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}

It happens to me too... duuno why is that...
Have you tried to wipe dalvik cache? Sometimes FAIL's to me ._.

DevastatingTech said:
I installed CWM 6.0.3.6. But it show this message when I enter recovery. I tried to disregard. But it is annoying.
So what does mean that, guys?
Click to expand...
Click to collapse
found this on github
This is not a bug, it's a simple warning after some CM SELinux changes. Nothing should break by this message
Click to expand...
Click to collapse
and this on xda
_alp1ne said:
This happened to me also, but it has nothing to do with flashing or anything. It is best to ignore as it only means some file it is reading has no context.
Click to expand...
Click to collapse
and it started after flashing CWM 6.0.3.6 from CM10.1 thread ...(for me)
so basically we're safe....

is nothing to worry about, but , if you want to be 100% sure, add a durex

copy from CyanogenMod Forum:
it looks like the error is related to SELinux. But it seems safe to ignore.
------------------------------------------------------------------------------
/*
* Copyright (C) 2009 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include "edify/expr.h"
#include "updater.h"
#include "install.h"
#include "minzip/Zip.h"
// Generated by the makefile, this function defines the
// RegisterDeviceExtensions() function, which calls all the
// registration functions for device-specific extensions.
#include "register.inc"
// Where in the package we expect to find the edify script to execute.
// (Note it's "updateR-script", not the older "update-script".)
#define SCRIPT_NAME "META-INF/com/google/android/updater-script"
struct selabel_handle *sehandle;
int main(int argc, char** argv) {
// Various things log information to stdout or stderr more or less
// at random. The log file makes more sense if buffering is
// turned off so things appear in the right order.
setbuf(stdout, NULL);
setbuf(stderr, NULL);
if (argc != 4) {
fprintf(stderr, "unexpected number of arguments (%d)\n", argc);
return 1;
}
char* version = argv[1];
if ((version[0] != '1' && version[0] != '2' && version[0] != '3') ||
version[1] != '\0') {
// We support version 1, 2, or 3.
fprintf(stderr, "wrong updater binary API; expected 1, 2, or 3; "
"got %s\n",
argv[1]);
return 2;
}
// Set up the pipe for sending commands back to the parent process.
int fd = atoi(argv[2]);
FILE* cmd_pipe = fdopen(fd, "wb");
setlinebuf(cmd_pipe);
// Extract the script from the package.
char* package_data = argv[3];
ZipArchive za;
int err;
err = mzOpenZipArchive(package_data, &za);
if (err != 0) {
fprintf(stderr, "failed to open package %s: %s\n",
package_data, strerror(err));
return 3;
}
const ZipEntry* script_entry = mzFindZipEntry(&za, SCRIPT_NAME);
if (script_entry == NULL) {
fprintf(stderr, "failed to find %s in %s\n", SCRIPT_NAME, package_data);
return 4;
}
char* script = malloc(script_entry->uncompLen+1);
if (!mzReadZipEntry(&za, script_entry, script, script_entry->uncompLen)) {
fprintf(stderr, "failed to read script from package\n");
return 5;
}
script[script_entry->uncompLen] = '\0';
// Configure edify's functions.
RegisterBuiltins();
RegisterInstallFunctions();
RegisterDeviceExtensions();
FinishRegistration();
// Parse the script.
Expr* root;
int error_count = 0;
yy_scan_string(script);
int error = yyparse(&root, &error_count);
if (error != 0 || error_count > 0) {
fprintf(stderr, "%d parse errors\n", error_count);
return 6;
}
struct selinux_opt seopts[] = {
{ SELABEL_OPT_PATH, "/file_contexts" }
};
sehandle = selabel_open(SELABEL_CTX_FILE, seopts, 1);
if (!sehandle) {
fprintf(stderr, "Warning: No file_contexts\n");
fprintf(cmd_pipe, "ui_print Warning: No file_contexts\n");
}
// Evaluate the parsed script.
UpdaterInfo updater_info;
updater_info.cmd_pipe = cmd_pipe;
updater_info.package_zip = &za;
updater_info.version = atoi(version);
State state;
state.cookie = &updater_info;
state.script = script;
state.errmsg = NULL;
char* result = Evaluate(&state, root);
if (result == NULL) {
if (state.errmsg == NULL) {
fprintf(stderr, "script aborted (no error message)\n");
fprintf(cmd_pipe, "ui_print script aborted (no error message)\n");
} else {
fprintf(stderr, "script aborted: %s\n", state.errmsg);
char* line = strtok(state.errmsg, "\n");
while (line) {
fprintf(cmd_pipe, "ui_print %s\n", line);
line = strtok(NULL, "\n");
}
fprintf(cmd_pipe, "ui_print\n");
}
free(state.errmsg);
return 7;
} else {
fprintf(stderr, "script result was [%s]\n", result);
free(result);
}
if (updater_info.package_zip) {
mzCloseZipArchive(updater_info.package_zip);
}
free(script);
return 0;
}
http://forum.cyanogenmod.com/topic/75956-cwm-on-nexus-4-after-43-update/

Okay guys, I will ignore this. Already, I hadn't any error. Thanks.

Related

Porting / Converting Windows .exe to Windows Mobile .cab/exe

Ive looked but havnt managed to find a windows .exe convertor to windows mobile. Ive found a program which can shutdown remote pcs on the same network and want to port it to my windows mobile (6.1) - HTC Kaiser.
Ive installed the visual studio and the sdk aswell as the 2.0 mobile framework.
Any ideas where to go from here?
Thanks
Source code to Windows App...
Code:
//-----------------------------------------------------------
// Remote Shutdown v1.0 Console Mode
// Copyright (C) 2002, MATCODE Software
// http://www.matcode.com
// Author: Vitaly Evseenko
//-----------------------------------------------------------
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#pragma hdrstop
int RemoteShutdown(LPSTR lpMachineName, LPSTR lpMessage,
DWORD dwTimeout, BOOL bForceAppsClosed,
BOOL bRebootAfterShutdown )
{
HANDLE hToken;
TOKEN_PRIVILEGES TokenPrivileges;
OpenProcessToken( GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken ) ;
LookupPrivilegeValue( NULL, SE_REMOTE_SHUTDOWN_NAME, &(TokenPrivileges.Privileges[0].Luid));
TokenPrivileges.PrivilegeCount = 1;
TokenPrivileges.Privileges[0].Attributes = 2;
AdjustTokenPrivileges( hToken, FALSE, &TokenPrivileges,
sizeof(TOKEN_PRIVILEGES), NULL, NULL );
if(!InitiateSystemShutdown(
lpMachineName, // name of computer to shut down
lpMessage, // address of message to display
dwTimeout, // time to display dialog box
bForceAppsClosed, // force applications with unsaved changes flag
bRebootAfterShutdown ))
{
return GetLastError();
}
return 0;
}
void OutUsage(void)
{
printf("\nUsage: RSD-CON ComputerName [Message] [/tnn] [/f] [/s]\n");
printf("\tComputerName - remote computer name\n");
printf("\tMessage - specify message to display\n");
printf("\t/t - time to display message (nn seconds)\n");
printf("\t/f - do not force applications with unsaved changes flag\n");
printf("\t/s - the computer is to shut down.\n");
printf("Example: RSD-CON PC_LARRY This computer will be restarted now. /t20\n");
}
void main( int argc, char *argv[] )
{
char szMachineName[100];
char szMessage[200];
DWORD dwTimeout;
BOOL bForceAppsClosed;
BOOL bRebootAfterShutdown;
int i, Err;
printf("Remote Shutdown v1.0, Console\n");
printf("Copyright (C) 2002, MATCODE Software\n");
printf("http://www.matcode.com\n");
if (GetVersion() & 0x80000000) // Not Windows NT/2000/XP
{
printf("\n\tThis is a Windows NT/2000/XP application.\n"
"This program will not work on Windows 95/98/ME !\n");
return;
}
if(argc<2)
{
OutUsage();
return;
}
strcpy(szMachineName, argv[1]);
dwTimeout = 0;
bForceAppsClosed = TRUE;
bRebootAfterShutdown = TRUE;
szMessage[0] = '\0';
for( i = 2; i < argc; i++ )
{
// if not started with / then message ;-)
if( argv[i][0] != '/')
{
strcat(szMessage, argv[i]);
strcat(szMessage, " ");
continue;
}
// parse option type
if(argv[i][1]=='t' || argv[i][1]=='T')
{
dwTimeout = atol(&argv[i][2]);
}
else if(argv[i][1]=='f' || argv[i][1]=='F')
{
bForceAppsClosed = FALSE;
}
else if(argv[i][1]=='s' || argv[i][1]=='S')
{
bRebootAfterShutdown = FALSE;
}
}
if (dwTimeout == 0 && szMessage[0])
{
dwTimeout = 5;
}
Err = RemoteShutdown(szMachineName, szMessage,
dwTimeout, bForceAppsClosed,
bRebootAfterShutdown );
if(Err)
{
LPSTR lpstErr = "\0";
if(Err == 53)
{
lpstErr = "The network path was not found.\n"
"Invalid computer name or is not Windows NT/2000/XP machine.\n";
}
else if(Err == 5)
{
lpstErr = "Access is denied. You have no administrative rights on the specified computer.\n";
}
printf("\nUnable to shutdown computer %s, Error: %d.\n%s",
szMachineName, Err, lpstErr);
OutUsage();
}
else
{
printf("\nComputer %s is shut down.\n", szMachineName);
}
}
Hi
This is not that easy. While a lot API calls exists in both Windows and WinMo I doubt that the ones used in this tool are available.
cool this is one development many people is waiting for, especially me
wish you good luck
Hi..interesting topics anyway.
As long as the APIs used in Windows app are also available in Windows Mobile, that will be possible IMO.
The one I'm sure about, the Windows Mobile apps built using .net, will also be available to run in Windows

[TOOL] SBCalc - Generate your SBK (v1.1)

Hey there,
Since i had many requests about SBK because i had to stop my webserver, i decided to write a small Windows tool to generate easilly your SBK if you already have your CPUID. (Infos about getting your CPUID -> http://forum.xda-developers.com/showthread.php?t=1624645)
Easy to use :
Extract both exe and dll in the same folder.
Launch SBCalc.exe, type your CPUID, clic "Generate", and it will return your SBK.
Update :
v1.1 : Support 15 or 16 digits for CPUID
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
vache said:
Hey there,
Since i had many requests about SBK because i had to stop my webserver, i decided to write a small Windows tool to generate easilly your SBK if you already have your CPUID. (Infos about getting your CPUID -> http://forum.xda-developers.com/showthread.php?t=1624645)]
Click to expand...
Click to collapse
You're the man (or woman, sorry, I don't actually know you)! TY much!
Hi Guy,
Thanks for this great tool !
Cheers.
vache said:
Hey there,
Since i had many requests about SBK because i had to stop my webserver, i decided to write a small Windows tool to generate easilly your SBK if you already have your CPUID. (Infos about getting your CPUID -> http://forum.xda-developers.com/showthread.php?t=1624645)
Easy to use :
Extract both exe and dll in the same folder.
Launch SBCalc.exe, type your CPUID, clic "Generate", and it will return your SBK.
Click to expand...
Click to collapse
For Linux fans, the following piece of code (adapted from Skrilax_CZ's boot menu) seems to work too:
Code:
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <arpa/inet.h>
int
main (int argc, char *argv[])
{
char uid[16], *p;
uint32_t sbk[4];
int i, j, mult;
while (--argc)
{
p = argv[argc];
if (p[0] == '0' && p[1] == 'x')
p += 2;
if (strlen (p) != 16)
continue;
strncpy (uid, p + 8, 8);
strncpy (uid + 8, p, 8);
for (i = 0; i < 16; i++)
uid[i] = toupper (uid[i]);
memset (sbk, 0, sizeof (sbk));
for (i = 0; i < 4; i++)
{
sbk[i] = 0;
mult = 1;
for (j = 3; j >= 0; j--)
{
sbk[i] += uid[4*i+j] * mult;
mult *= 100;
}
}
for (i = 0; i < 4; i++)
sbk[i] ^= sbk[3 - i];
printf ("0x%08X 0x%08X 0x%08X 0x%08X\n",
htonl (sbk[0]), htonl (sbk[1]), htonl (sbk[2]), htonl (sbk[3]));
}
exit (0);
}
Same thing in Perl:
Code:
#! /usr/bin/perl
sub chunk
{
my ($mult, $res);
$mult = 1;
$res = 0;
for (reverse unpack 'C4', uc shift)
{
$res += $_ * $mult;
$mult *= 100;
}
$res;
}
for (@ARGV)
{
my (@sbk, $i);
s/^0x//;
next
if (! m/^[[:xdigit:]]{16}$/);
@sbk = map { chunk $_ } unpack 'x8 (A4)4', $_ . $_;
for ($i = 0; $i < @sbk; $i++)
{ $sbk[$i] ^= $sbk[-$i-1]; }
@sbk = map { unpack 'N', pack 'L', $_ } @sbk;
print +(join ' ', map { sprintf '0x%08X', $_ } @sbk), "\n";
}
Yes, I reverse engineered the SBK generating function in Pica_Func.dll, no need to use it anymore.
lcd047 said:
For Linux fans, the following piece of code (adapted from Skrilax_CZ's boot menu) seems to work too:
Code:
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
uint32_t
swab32 (uint32_t src)
{
uint32_t dst;
int i;
dst = 0;
for (i = 0; i < 4; i++)
{
dst = (dst << 8) + (src & 0xFF);
src >>= 8;
}
return dst;
}
int
main (int argc, char *argv[])
{
char uid[16], *p;
uint32_t sbk[4];
int i, j, mult;
while (--argc)
{
p = argv[argc];
if (p[0] == '0' && p[1] == 'x')
p += 2;
if (strlen (p) != 16)
continue;
strncpy (uid, p + 8, 8);
strncpy (uid + 8, p, 8);
for (i = 0; i < 16; i++)
uid[i] = toupper (uid[i]);
memset (sbk, 0, sizeof (sbk));
for (i = 0; i < 4; i++)
{
sbk[i] = 0;
mult = 1;
for (j = 3; j >= 0; j--)
{
sbk[i] += uid[4*i+j] * mult;
mult *= 100;
}
}
for (i = 0; i < 4; i++)
sbk[i] ^= sbk[3 - i];
printf ("0x%08X 0x%08X 0x%08X 0x%08X\n",
swab32 (sbk[0]), swab32 (sbk[1]), swab32 (sbk[2]), swab32 (sbk[3]));
}
exit (0);
}
Same thing in Perl:
Code:
#! /usr/bin/perl
sub chunk
{
my ($mult, $res);
$mult = 1;
$res = 0;
for (reverse unpack 'C4', uc shift)
{
$res += $_ * $mult;
$mult *= 100;
}
$res;
}
for (@ARGV)
{
my (@sbk, $i);
s/^0x//;
next
if (! m/^[[:xdigit:]]{16}$/);
@sbk = map { chunk $_ } unpack 'x8 (A4)4', $_ . $_;
for ($i = 0; $i < @sbk; $i++)
{ $sbk[$i] ^= $sbk[-$i-1]; }
@sbk = map { unpack 'N', pack 'V', $_ } @sbk;
print +(join ' ', map { sprintf '0x%08X', $_ } @sbk), "\n";
}
Click to expand...
Click to collapse
Thanks so much for the Perl code! You can see it in action at my new SBK Calculator site: http://a500bootloaderflash.tk/sbkcalc/
I hope you don't mind me using it in the true spirit of Open Source!
blackthund3r said:
Thanks so much for the Perl code! You can see it in action at my new SBK Calculator site: http://a500bootloaderflash.tk/sbkcalc/
I hope you don't mind me using it in the true spirit of Open Source!
Click to expand...
Click to collapse
By all means, I posted it for people to use it.
lcd047 said:
By all means, I posted it for people to use it.
Click to expand...
Click to collapse
Thank you!
Thank you Vache! Works great!
vache said:
Hey there,
Since i had many requests about SBK because i had to stop my webserver, i decided to write a small Windows tool to generate easilly your SBK if you already have your CPUID. (Infos about getting your CPUID -> http://forum.xda-developers.com/showthread.php?t=1624645)
Easy to use :
Extract both exe and dll in the same folder.
Launch SBCalc.exe, type your CPUID, clic "Generate", and it will return your SBK.
Click to expand...
Click to collapse
Thank you Vache, works great!
:good:
Hello vache,
great tool, but i've got a problem...
if i get my cpuid with "adb devices" it is just 11 digits long...
your tool said that it have to be 15 digits.
and if i use your a500 manager there are 16 digits and characters in my serial number
IncredibleHero said:
Hello vache,
great tool, but i've got a problem...
if i get my cpuid with "adb devices" it is just 11 digits long...
your tool said that it have to be 15 digits.
and if i use your a500 manager there are 16 digits and characters in my serial number
Click to expand...
Click to collapse
Remove the 1st digit if it's a zero.
vache said:
Remove the 1st digit if it's a zero.
Click to expand...
Click to collapse
CPUID can be 16 digits long - mine is and it generates valid SBKs. In fact I usually add a zero to the beginning if it's only 15 to make it 16, although my CPUID starts with a 1
Mine is 16 char long - extracted via backup from cwm. But SBCalc, http://a500bootloaderflash.tk/sbkcalc/ and A500Manager1.1 all says my cpuid is invalid any ideas
can u help me sir
i have my cpuid but when i use this tool i got the warning "please check your cpuid"....can u help get sbk code from my cpuid???here my cpuid no (0xa74420244808057)
cyclone77 said:
i have my cpuid but when i use this tool i got the warning "please check your cpuid"....can u help get sbk code from my cpuid???here my cpuid no (0xa74420244808057)
Click to expand...
Click to collapse
not sure if it is correct but try: 0x42530000 0x2B89BB01 0xEBE55D03 0x507A2103
cyclone77 said:
i have my cpuid but when i use this tool i got the warning "please check your cpuid"....can u help get sbk code from my cpuid???here my cpuid no (0xa74420244808057)
Click to expand...
Click to collapse
Try this: 0xA0ABC201 0x1B34BE01 0xEBE55D03 0x507A2103

[MOD/GUIDE] X-Recents

Hey Guys!
After a few requests I decided to share my X-Recents mod with you, so that other developers get the ability to add it to their Rom. This is just for Developers building Roms from Source! Also, medium skills on java coding are recommended!
What is X-Recents mod?
It's a mod improving the stock android recents, to make them more user-friendly and feature-rich. It was already implemented in my X-Bean Rom for i9000
Please note:
- you can use this for all ICS/JB Roms and for all devices
- just add me to the credits, if you want to use it, and notify me: [email protected]
- The swype FC Bug (occurs when swyping over the Button) still exists, to fix it just add try/catch blocks at all points that cause the FC it (use adb/logcat for analysis)
- If you like my work and want to support me, the Thanks & the Donate button are always appreciated!
Okay, so let's get started: You can find all files in: system/frameworks/base/packages/SystemUI/src/com/android/systemui/recent (in your working directory, or whereever you're SystemUI sourcecode is)
At first, we modify the RecentTasksLoader.java:
l.260: final int first = 1;
to : final int first = 0;
This loads the current activity into the recents list.. Only problem: The launcher shall not be shown in the recents list, so we have to make a exeption for it:
l.270: if (item != null) {
to : if (item != null && item.packageName!="com.cyanogenmod.trebuchet") { // You can add as many exeptions for apps as you want
Next point: Adding the Taskmanager button:
At first, open RecentsVerticalScrollView.java:
Insert this at line 95:
Code:
private void opentaskmanager() {
PackageManager pm = getContext().getPackageManager();
Intent appStartIntent = pm.getLaunchIntentForPackage("your.taskmanager.packagename.here");
if (null != appStartIntent)
{
getContext().startActivity(appStartIntent);
}
}
Remember to change the "your.taskmanager.packagename.here" to the package name of your taskmanager!
Now, wrap a try/catch block around the loop content in line 107:
Code:
for (int i = 0; i < mLinearLayout.getChildCount(); i++) {
try {
View v = mLinearLayout.getChildAt(i);
addToRecycledViews(v);
mAdapter.recycleView(v);
} catch (Exception ex) {
}
}
Also add a try here (I can't give you a line, because you inserted something before) :
Code:
for (int i = 0; i < mAdapter.getCount(); i++) {
try {
View old = null;
And a catch here:
Code:
calloutLine.setOnTouchListener(noOpListener);
mLinearLayout.addView(view);
} catch (Exception ex) {
}
}
To add the button, insert this:
Code:
Button bt_taskmanager = new Button(getContext());
bt_taskmanager.setText("Task Manager");
bt_taskmanager.setWidth(mLinearLayout.getWidth());
bt_taskmanager.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
opentaskmanager();
}
});
mLinearLayout.addView(bt_taskmanager);
Between these two lines:
setLayoutTransition(transitioner);
// Scroll to end after layout.
Okay, now we've got the button!
At last I want to give you something you can experiment with:
Code:
private void clearalltasks() {
final ActivityManager am = (ActivityManager)
mContext.getSystemService(Context.ACTIVITY_SERVICE);
final List<ActivityManager.RecentTaskInfo> recentTasks =
am.getRecentTasks(50, ActivityManager.RECENT_IGNORE_UNAVAILABLE);
for (int i = 0; i >= recentTasks.size(); i++) {
RecentTaskInfo item = recentTasks.get(i);
if (am != null && item!=null) {
try {
am.removeTask(item.persistentId, ActivityManager.REMOVE_TASK_KILL_PROCESS);
} catch (Exception ex) {
}
try {
am.killBackgroundProcesses(item.origActivity.getPackageName());
} catch (Exception ex) {
}
}
}
mLinearLayout.removeAllViews();
try {
update();
} catch (Exception ex) {
ex.printStackTrace();
}
}
This is my first attempt to add a clear all button.. Do with it what you want, I tried it and it works half-ways.. But not perfectly. I will add some more things later, for example how to add several more Buttons!
Screenshot:
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
Very good ...
Awesome post!

[Q] Why does this code not work in CE 6.0?

I want to add to HKLM\init an all purpose application launcher (CE 6.0 device has persistent registry):
Code:
[HKEY_LOCAL_MACHINE\Init]
"Depend199"=hex:00,14,00,1e,00,60
[HKEY_LOCAL_MACHINE\Init]
"Launch199"="\NandFlash\CeLaunchAppsAtBootTime.exe"
[HKEY_CURRENT_USER\Startup]
"Process1"="\NandFlash\SetBackLight.exe"
"Process1Delay"=dword:0
The launcher's code is
Code:
#include <Windows.h>
#if defined(OutputDebugString)
#undef OutputDebugString
void OutputDebugString(LPTSTR lpText)
{}
#endif
BOOL IsAPIReady(DWORD hAPI);
void WalkStartupKeys(void);
DWORD WINAPI ProcessThread(LPVOID lpParameter);
#define MAX_APPSTART_KEYNAME 256
typedef struct _ProcessStruct {
WCHAR szName[MAX_APPSTART_KEYNAME];
DWORD dwDelay;
} PROCESS_STRUCT,*LPPROCESS_STRUCT;
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
int nLaunchCode = -1;
// Quick check to see whether we were called from within HKLM\init -> by default HKLM\init passes the lauch code
if(lpCmdLine && *lpCmdLine)
{
// MessageBox(NULL, lpCmdLine ,NULL,MB_OK);
nLaunchCode = _ttoi( (const TCHAR *) lpCmdLine);
}
else
{
// MessageBox(NULL, _T("No argumets passed"),NULL,MB_OK);
}
//Wait for system has completely initialized
BOOL success = FALSE;
int i = 0;
while((!IsAPIReady(SH_FILESYS_APIS)) && (i++ < 50))
{
Sleep(200);
}
success = (i < 50);
if(success)
{
i = 0;
while((!IsAPIReady(SH_DEVMGR_APIS))&& (i++ < 50))
{
Sleep(200);
}
success = (i < 50);
if(success)
{
i = 0;
while((!IsAPIReady(SH_SHELL))&& (i++ < 50))
{
Sleep(200);
}
success = (i < 50);
if(success)
{
i = 0;
while((!IsAPIReady(SH_WMGR))&& (i++ < 50))
{
Sleep(200);
}
success = (i < 50);
if(success)
{
i = 0;
while((!IsAPIReady(SH_GDI))&& (i++ < 50))
{
Sleep(200);
}
success = (i < 50);
}
}
}
}
if(nLaunchCode != -1)
{
// Since this is application is launched through the registry HKLM\Init we need to call SignalStarted passing in the command line parameter
SignalStarted((DWORD) nLaunchCode);
}
//If system has completely initialized
if( success)
{
WalkStartupKeys();
}
return (0);
}
void WalkStartupKeys(void)
{
HKEY hKey;
WCHAR szName[MAX_APPSTART_KEYNAME];
WCHAR szVal[MAX_APPSTART_KEYNAME];
WCHAR szDelay[MAX_APPSTART_KEYNAME];
DWORD dwType, dwNameSize, dwValSize, i,dwDelay;
DWORD dwMaxTimeout=0;
HANDLE hWaitThread=NULL;
HANDLE ThreadHandles[100];
int iThreadCount=0;
if (RegOpenKeyEx(HKEY_CURRENT_USER, TEXT("Startup"), 0, KEY_READ, &hKey) != ERROR_SUCCESS) {
return;
}
dwNameSize = MAX_APPSTART_KEYNAME;
dwValSize = MAX_APPSTART_KEYNAME * sizeof(WCHAR);
i = 0;
while (RegEnumValue(hKey, i, szName, &dwNameSize, 0, &dwType,(LPBYTE)szVal, &dwValSize) == ERROR_SUCCESS) {
if ((dwType == REG_SZ) && !wcsncmp(szName, TEXT("Process"), 7)) { // 7 for "Process"
// szval
wsprintf(szDelay,L"%sDelay",szName);
dwValSize=sizeof(dwDelay);
if (ERROR_SUCCESS == RegQueryValueEx(hKey,szDelay,0,&dwType,(LPBYTE)&dwDelay,&dwValSize)) {
// we now have the process name and the process delay - spawn a thread to "Sleep" and then create the process.
LPPROCESS_STRUCT ps=(LPPROCESS_STRUCT) LocalAlloc( LMEM_FIXED , sizeof( PROCESS_STRUCT));
ps->dwDelay=dwDelay;
wcscpy(ps->szName,szVal);
DWORD dwThreadID;
OutputDebugString(L"Creating Thread...\n");
HANDLE hThread=CreateThread(NULL,0,ProcessThread,(LPVOID)ps,0,&dwThreadID);
ThreadHandles[iThreadCount++]=hThread;
if (dwDelay > dwMaxTimeout) {
hWaitThread=hThread;
dwMaxTimeout=dwDelay;
}
LocalFree((HLOCAL) ps);
}
}
dwNameSize = MAX_APPSTART_KEYNAME;
dwValSize = MAX_APPSTART_KEYNAME * sizeof(WCHAR);
i++;
}
// wait on the thread with the longest delay.
DWORD dwWait=WaitForSingleObject(hWaitThread,INFINITE);
if (WAIT_FAILED == dwWait) {
OutputDebugString(L"Wait Failed!\n");
}
for(int x=0;x < iThreadCount;x++) {
CloseHandle(ThreadHandles[x]);
}
RegCloseKey(hKey);
}
DWORD WINAPI ProcessThread(LPVOID lpParameter)
{
TCHAR tcModuleName[MAX_APPSTART_KEYNAME];
OutputDebugString(L"Thread Created... Sleeping\n");
LPPROCESS_STRUCT ps=(LPPROCESS_STRUCT)lpParameter;
Sleep(ps->dwDelay); // Wait for delay period
OutputDebugString(L"Done Sleeping...\n");
PROCESS_INFORMATION pi;
STARTUPINFO si;
si.cb=sizeof(si);
OutputDebugString(L"Creating Process ");
OutputDebugString(ps->szName);
OutputDebugString(L"\n");
wcscpy(tcModuleName,ps->szName);
TCHAR *tcPtrSpace=wcsrchr(ps->szName,L' '); // Launch command has a space, assume command line.
if (NULL != tcPtrSpace) {
tcModuleName[lstrlen(ps->szName)-lstrlen(tcPtrSpace)]=0x00; // overwrite the space with null, break the app and cmd line.
tcPtrSpace++; // move past space character.
}
CreateProcess( tcModuleName, // Module Name
tcPtrSpace, // Command line -- NULL or PTR to command line
NULL, // Process handle not inheritable
NULL, // Thread handle not inheritable
FALSE, // Set handle inheritance to FALSE
0, // No creation flags
NULL, // Use parent's environment block
NULL, // Use parent's starting directory
&si, // Pointer to STARTUPINFO structure
&pi ); // Pointer to PROCESS_INFORMATION structure
OutputDebugString(L"Thread Exiting...\n");
return 0;
}
which compiled errorfree
Added the registry entries as shown above, copied the launcher's exe in default location, rebootet device. Nothing happened, means executable defined as
Code:
[HKEY_CURRENT_USER\Startup]
"Process1"="\NandFlash\SetBackLight.exe"
wasn't run at all.
Does anybody have an idea, where the error is? Any help appreciated. Thanks for reading.

[Q] Can I register a listener on process state?

I'm an experienced developer but new to Android development. I have an app that runs some native binaries, and I provide a status indicator to show when the native process is running and when it's not. Currently I poll the device to figure this out, using the ActivityManager API to determine if specific processes are running or not.
I'm hoping there is some way to register a listener on process state changes, so I can get notified when my process starts or stops. I looked through the API, and there doesn't seem to be such a thing. Does anyone know how I can keep track of process start and stop other than polling via ActivityManager?
MidnightJava said:
I'm an experienced developer but new to Android development. I have an app that runs some native binaries, and I provide a status indicator to show when the native process is running and when it's not. Currently I poll the device to figure this out, using the ActivityManager API to determine if specific processes are running or not.
I'm hoping there is some way to register a listener on process state changes, so I can get notified when my process starts or stops. I looked through the API, and there doesn't seem to be such a thing. Does anyone know how I can keep track of process start and stop other than polling via ActivityManager?
Click to expand...
Click to collapse
Afaik there's no way to accomplish that other than your way or being system/root app. See this similar question here for reference.
Can you show how you start the process?
EmptinessFiller said:
Can you show how you start the process?
Click to expand...
Click to collapse
Sure. Here's the class that manages starting, stopping, and statusing (running or not) the binary executable. In this case, it's the omniNames service of the omni ORB (CORBA broker).
Code:
public class RHManager {
private TimerTask task = new TimerTask() {
@Override
public void run() {
if (RHManager.this.listener != null) {
listener.running(isOmniNamesRunning());
}
}
};
private IStatusListener listener;
public RHManager() {
}
public void startOmniNames() {
final Exec exec = new Exec();
final String[] args = new String[]
{RhMgrConstants.INSTALL_LOCATION_OMNI_NAMES_SCRIPTS + "/" + RhMgrConstants.OMNI_NAMES_SCRIPT_FILE,
"start"};
final String[] env = new String[] {"LD_LIBRARY_PATH=/sdcard/data/com.axiosengineering.rhmanager/omniORB/lib"};
Thread t = new Thread() {
public void run() {
try {
int res = exec.doExec(args, env);
logMsg("omniNames start return code " + res);
} catch (IOException e) {
logMsg("Failed to start omniNames");
e.printStackTrace();
}
String std = exec.getOutResult();
logMsg("omniNames start: std out==> " + std );
String err = exec.getErrResult();
logMsg("omniNames start: err out==> " + err );
};
};
t.start();
logMsg("omniNames started");
}
private boolean isOmniNamesRunning() {
String pid_s = getOmniNamesPid();
Integer pid = null;
if (pid_s != null) {
try {
pid = Integer.parseInt(pid_s);
} catch (NumberFormatException e) {
return false;
}
}
if (pid != null) {
RunningAppProcessInfo activityMgr = new ActivityManager.RunningAppProcessInfo("omniNames", pid, null);
return activityMgr.processName != null ;
}
return false;
}
public void stopOmniNames() {
String pid = getOmniNamesPid();
android.os.Process.killProcess(Integer.parseInt(pid));
android.os.Process.sendSignal(Integer.parseInt(pid), android.os.Process.SIGNAL_KILL);
}
private String getOmniNamesPid() {
Exec exec = new Exec();
final String[] args = new String[]
{RhMgrConstants.INSTALL_LOCATION_OMNI_NAMES_SCRIPTS + "/" + RhMgrConstants.OMNI_NAMES_SCRIPT_FILE,
"pid"};
String pid = "";
try {
int res = exec.doExec(args, null);
logMsg("oniNames pid return code: " + res);
} catch (IOException e) {
logMsg("Failed to start omniNames");
e.printStackTrace();
return pid;
}
String std = exec.getOutResult();
logMsg("omniNames pid: std out ==> " + std);
String err = exec.getErrResult();
logMsg("omniNames pid: err out ==> " + err);
String[] parts = std.split("\\s+");
if (parts.length >= 2) {
pid = parts[1];
}
return pid;
}
//monitor omniNames status and report status periodically to an IStatusListener
public void startMonitorProcess(IStatusListener listener, String string) {
this.listener = listener;
Timer t = new Timer();
t.schedule(task, 0, 1000);
}
private void logMsg(String msg) {
if (RhMgrConstants.DEBUG) {
System.err.println(msg);
}
}
}
Here's the Exec class that handles invocation of Runtime#exec(), consumes std and err out, and reports those and process return status to the caller.
Code:
public class Exec {
private String outResult;
private String errResult;
private Process process;
private boolean failed = false;
StreamReader outReader;
StreamReader errReader;
public int doExec(String[] cmd, String[] envp) throws IOException{
Timer t = null;
try {
process = Runtime.getRuntime().exec(cmd, envp);
outReader = new StreamReader(process.getInputStream());
outReader.setPriority(10);
errReader = new StreamReader(process.getErrorStream());
outReader.start();
errReader.start();
t = new Timer();
t.schedule(task, 10000);
int status = process.waitFor();
outReader.join();
errReader.join();
StringWriter outWriter = outReader.getResult();
outResult = outWriter.toString();
outWriter.close();
StringWriter errWriter = errReader.getResult();
errResult = errWriter.toString();
errWriter.close();
return (failed ? -1: status);
} catch (InterruptedException e) {
return -1;
} finally {
if (t != null) {
t.cancel();
}
}
}
public int doExec(String[] cmd) throws IOException{
return doExec(cmd, null);
}
public String getOutResult(){
return outResult;
}
public String getErrResult(){
return errResult;
}
private static class StreamReader extends Thread {
private InputStream is;
private StringWriter sw;
StreamReader(InputStream is) {
this.is = is;
sw = new StringWriter(30000);
}
public void run() {
try {
int c;
while ((c = is.read()) != -1){
sw.write(c);
}
}
catch (IOException e) { ; }
}
StringWriter getResult() {
try {
is.close();
} catch (IOException e) {
System.err.println("Unable to close input stream in StreamReader");
}
return sw;
}
}
private TimerTask task = new TimerTask() {
@Override
public void run() {
failed = true;
process.destroy();
}
};
}
Here's the script that startOminNames() invokes. It's the shell script installed with omniORB with functions other than start and get_pid removed, since those are handled by Android classes. You can invoke any executable in place of the script, or wrap your executable in a script.
Code:
#
# omniNames init file for starting up the OMNI Naming service
#
# chkconfig: - 20 80
# description: Starts and stops the OMNI Naming service
#
exec="/sdcard/data/com.axiosengineering.rhmanager/omniORB/bin/omniNames"
prog="omniNames"
logdir="/sdcard/data/com.axiosengineering.rhmanager/omniORB/logs"
logfile="/sdcard/data/com.axiosengineering.rhmanager/omniORB/logs/omninames-localhost.err.log"
options=" -start -always -logdir $logdir -errlog $logfile"
start() {
#[ -x $exec ] || exit 5
echo -n $"Starting $prog: "
$exec $options
}
get_pid() {
ps | grep omniNames
}
case "$1" in
start)
start && exit 0
$1
;;
pid)
get_pid
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
exit 2
esac
exit $?
And here's the IStatusListener interface
Code:
public interface IStatusListener {
public void running(boolean running);
}
Runtime.exec() has some pitfalls. See this helpful Runtime.exec tutorial for a nice explanation.
And you may also want to check out this post on loading native binaries in Android.

Categories

Resources