[Q] Problem to run the Torch from source - Android Software Development

Hello, i have downloaded the Torch source code from cyanogen repository and i have this problem:
1º I put the code in a empty project in Eclipse
2º I havent errors and the code compile correctly
3º I run the app in my device (Nexus One) and work well all buttons and options, but when i press in "On" button for active i get a error and the app crash.
Debugging i have seen the following:
For active flash i have put a "1" in file "/sys/devices/platform/flashlight.0/leds/flashlight/brightness" (If i put a "1" manually with terminal the flash is active correctly)
In code, we have this:
public class FlashDevice {
private static final String DEVICE = "/sys/devices/platform/flashlight.0/leds/flashlight/brightness";
...
public synchronized void setFlashMode(int mode) {
try {
if (mWriter == null) {
mWriter = new FileWriter(DEVICE);
}
int value = mode;
switch (mode) {
case STROBE:
value = OFF;
break;
case DEATH_RAY:
value = useDeathRay ? DEATH_RAY : HIGH;
break;
}
mWriter.write(String.valueOf(value));
mWriter.flush();
mFlashMode = mode;
if (mode == OFF) {
mWriter.close();
mWriter = null;
}
} catch (IOException e) {
throw new RuntimeException("Can't open flash device: " + DEVICE, e);
}
}
public synchronized int getFlashMode() {
return mFlashMode;
}
}
Click to expand...
Click to collapse
I get this error in line "mWriter = new FileWriter(DEVICE);":
java.io.FileNotFoundException: /sys/devices/platform/flashlight.0/leds/flashlight/brightness (Permission denied)
Someone know the cause????

Try using the original source code from the repository by
Code:
svn checkout http://n1torch.googlecode.com/svn/trunk/ n1torch-read-only
and importing it as a project into eclipse.

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

Problems running Unix commands in native Android Java...

Hello,
I've been trying to do some android stuff on java for some time now, and i've come across a problem here: i can't get the app to execute linux stuff, as there is no system() method like on other platforms... so i searched some code and found this:
Code:
protected void system(String[] Commands){
e Process process = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(process.getOutputStream());
DataInputStream osRes = new DataInputStream(process.getInputStream());
Vector<String> res = new Vector<String>();
for (String single : Commands) {
e os.writeBytes(single + "\n");
e os.flush();
e res.add(osRes.readLine());
// Log.e("CMDs", osRes.readLine());
}
e os.writeBytes("exit\n");
e os.flush();
process.waitFor();
}
However that won't work because of some errors i have in the marked lines:
"Unhandled exception type IOException"
and the process.waitFor(); line also gives me an error:
"Unhandled exception type InterruptedException"
Any ideas?
You need to add a try/catch block around that code which catches the IO exception and the interrupted exception.
deleted
So, first of all thanks to both of you it appears to be working now... i tried in on the emulator, and of course "su" didn't work there (broken pipe), so i replaced it by "sh", however this didn't seem to work well too. the application just locked up with a warning in android.... strange...
edit: tried using /system/bin/sh, didn't work, locked up again
What version of Android in the emulator? I've done it with 1.5 through 2.2 in the emulator, just by using "sh".
could you post the code you used please? would be AWESOME!
i'm trying to get this working on 2.1
Sure, I can post some more details later, but for now just the code.
Include the file in your project and use with:
Code:
ShellCommand cmd = new ShellCommand();
CommandResult r = cmd.sh.runWaitFor("ls -l");
if (!r.success()) {
Log.v(TAG, "Error " + r.stderr);
} else {
Log.v(TAG, "Success! " + r.stdout);
}
If you want su you can either use cmd.shOrSu().runWaitFor("..."); which will try su (by running "id", it just tests the status code but it's a nice entry in logcat for debugging) and fallback to sh. Or you can use cmd.su.runWaitFor("...");
Also at
teslacoilsw.com/files/ShellCommand.java
Code:
package com.teslacoilsw.quicksshd;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.InputStream;
import android.util.Log;
public class ShellCommand {
private static final String TAG = "ShellCommand.java";
private Boolean can_su;
public SH sh;
public SH su;
public ShellCommand() {
sh = new SH("sh");
su = new SH("su");
}
public boolean canSU() {
return canSU(false);
}
public boolean canSU(boolean force_check) {
if (can_su == null || force_check) {
CommandResult r = su.runWaitFor("id");
StringBuilder out = new StringBuilder();
if (r.stdout != null)
out.append(r.stdout).append(" ; ");
if (r.stderr != null)
out.append(r.stderr);
Log.v(TAG, "canSU() su[" + r.exit_value + "]: " + out);
can_su = r.success();
}
return can_su;
}
public SH suOrSH() {
return canSU() ? su : sh;
}
public class CommandResult {
public final String stdout;
public final String stderr;
public final Integer exit_value;
CommandResult(Integer exit_value_in, String stdout_in, String stderr_in)
{
exit_value = exit_value_in;
stdout = stdout_in;
stderr = stderr_in;
}
CommandResult(Integer exit_value_in) {
this(exit_value_in, null, null);
}
public boolean success() {
return exit_value != null && exit_value == 0;
}
}
public class SH {
private String SHELL = "sh";
public SH(String SHELL_in) {
SHELL = SHELL_in;
}
public Process run(String s) {
Process process = null;
try {
process = Runtime.getRuntime().exec(SHELL);
DataOutputStream toProcess = new DataOutputStream(process.getOutputStream());
toProcess.writeBytes("exec " + s + "\n");
toProcess.flush();
} catch(Exception e) {
Log.e(QuickSSHD.TAG, "Exception while trying to run: '" + s + "' " + e.getMessage());
process = null;
}
return process;
}
private String getStreamLines(InputStream is) {
String out = null;
StringBuffer buffer = null;
DataInputStream dis = new DataInputStream(is);
try {
if (dis.available() > 0) {
buffer = new StringBuffer(dis.readLine());
while(dis.available() > 0)
buffer.append("\n").append(dis.readLine());
}
dis.close();
} catch (Exception ex) {
Log.e(TAG, ex.getMessage());
}
if (buffer != null)
out = buffer.toString();
return out;
}
public CommandResult runWaitFor(String s) {
Process process = run(s);
Integer exit_value = null;
String stdout = null;
String stderr = null;
if (process != null) {
try {
exit_value = process.waitFor();
stdout = getStreamLines(process.getInputStream());
stderr = getStreamLines(process.getErrorStream());
} catch(InterruptedException e) {
Log.e(TAG, "runWaitFor " + e.toString());
} catch(NullPointerException e) {
Log.e(TAG, "runWaitFor " + e.toString());
}
}
return new CommandResult(exit_value, stdout, stderr);
}
}
}
Thanks kevin The code you are using there is awesome Looking good so far, however it keeps returning permission denied... is it some setting in the android manifest?
Actually "Permission denied" often also means "no such file or directory" on android :-/ . It's very frustrating.
Try running something simple to start with like:
cmd.sh.runWaitFor("echo foo");
[email protected] said:
Actually "Permission denied" often also means "no such file or directory" on android :-/ . It's very frustrating.
Try running something simple to start with like:
cmd.sh.runWaitFor("echo foo");
Click to expand...
Click to collapse
yep, i tried running echo as i was confused by the "permission denied" although i had already set write permissions for the sdcard... didn't work, for some odd reason

Java snippet to re-size your assets for you different drawable-dpi folders.

While working on an Android game I got to the point where I was concerned with sorting out different resolutions. There's no way I was going to manually change my asset sizes for all current and future assets and all screen sizes. Here is a quick piece of code to do it for you.
Code:
package resourceGenerator;
import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class ResourceGenerator {
public static void main(String[] args) {
if(args.length < 2 || args.length > 3 || (args.length == 3 && !args[2].equals("-overwrite"))){
System.out.println("Resource Generator will take resources from one of your ldpi, mdpi, hdpi, xhdpi, or xxhdpi resource folders and generate default resources of the correct size for any other of those folders.");
System.out.println("Usage: ResourceGenerator.java sourceFolder destinationFolder -overwrite");
}
else{
String source = args[0];
String destination = args[1];
boolean overwrite = false;
if(args.length == 3){
overwrite = true;
}
int sourceScalingValue = getScalingValue(source);
int destinationScalingValue = getScalingValue(destination);
if(sourceScalingValue == 0 || destinationScalingValue == 0){
System.out.println("Source Folder and/or Destination Folder was invalid, should end with one of drawable-ldpi, drawable-mdpi, drawable-hdpi, or drawable-xhdpi.");
}
else {
float scale = (float) destinationScalingValue / (float) sourceScalingValue;
copyFiles(source, destination, overwrite, scale);
}
}
}
private static void copyFiles(String source, String destination, boolean overwrite, float scale) {
File sourceFolder = new File(source);
for (File file : sourceFolder.listFiles()) {
if (file.isDirectory()) {
File destinationFile = new File(destination, file.getName());
copyFiles(file.getPath(), destinationFile.getPath(), overwrite, scale);
}
else if (file.isFile()){
String extension = file.getName().substring(file.getName().lastIndexOf(".")+1);
if(extension.equalsIgnoreCase("jpg") || extension.equalsIgnoreCase("png") || extension.equalsIgnoreCase("gif")){
try {
File outputFile = new File(destination, file.getName());
if(overwrite || !outputFile.exists()){
createFolderIfRequired(destination);
BufferedImage scaledImage = getScaledImage(ImageIO.read(file), scale);
ImageIO.write(scaledImage, extension, outputFile);
System.out.println("Completed " + outputFile.getPath());
}
else{
System.out.println("Skipped as file already exists " + file.getPath());
}
} catch (IOException e) {
System.out.println("Failed to read file " + file.getPath());
}
}
else{
System.out.println("Skipping as we only process jpg, png, and gif " + file.getPath());
}
}
}
}
private static void createFolderIfRequired(String folderPath) {
File folder = new File(folderPath);
if(!folder.exists()){
folder.mkdir();
}
}
public static BufferedImage getScaledImage(BufferedImage image, double scale) throws IOException {
AffineTransform scaleTransform = AffineTransform.getScaleInstance(scale, scale);
AffineTransformOp bilinearScaleOp = new AffineTransformOp(scaleTransform, AffineTransformOp.TYPE_BICUBIC);
return bilinearScaleOp.filter(image, new BufferedImage((int)(image.getWidth() * scale), (int)(image.getHeight() * scale), image.getType()));
}
private static int getScalingValue(String folderString) {
File file=new File(folderString);
if(!file.isDirectory()){
return 0;
}
if(file.getName().equals("drawable-ldpi")){
return 120;
}
else if(file.getName().equals("drawable-mdpi")){
return 160;
}
else if(file.getName().equals("drawable-hdpi")){
return 240;
}
else if(file.getName().equals("drawable-xhdpi")){
return 320;
}
else {
return 0;
}
}
}
(Also posted on my website, hernblog.com)
this is work aom s2?

[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.

Reading\Changing CANbus API for New Car

Hi,
I will get straight to point.I am trying to Understand\Make custom Protocol Setting for a car model.
currently I am using XY Auto 9270 Model and a custom CAN analyzer.
Even if not answered hope follolwing information , will give initial information to developers how are beginningsto reverse engineer in Chinese Android Head Units.
I have note that for my car model,door , stearing data is present at which address , now my challenge is to format the serial packet to be send to Android Head Unit.
I have read that some users have decompiled the CANbus.apk and CANbus2.apk( in my case ) but there is no proof whether after decompiling it worked.What's more important is where to change\look into APK.
Aim 1 - "Debug Canbox serial data input to Android Head Unit"
(Missing - 4th Point )
1) Decompile CANBUS apk.
2) Search for "baud" keyword inside folders.
3) Install Serial-USB-Terminal ( But Serial Port is not listed)
I checked in CanbusSerial.Java located in CanBus2_source_from_JADX\sources\com\canbus\data there is mention of baudrate.
4) I am unable to find a way to view serial data to Headunit inside an APK running on Head Unit.
Aim2 - " Modify APK - Change . Java or .json files of canbus.apk
(Missing - 5th Point )
1)Searched for keyword door.
2) Was able to idetify that there is a location CanBus2_source_from_JADX\sources\com\canbus\json\
this might be location for intializing functions and variables for all car features (doors, aircon, trajectory,key etc.)
For Eg: This is java code for door
CardoorSerial.java - CanBus2_source_from_JADX\sources\com\canbus\json\door
Java:
package com.canbus.json.door;
import com.canbus.json.p001rx.RxData;
import java.util.List;
import java.util.Set;
public class CarDoorSerial {
private List<CarDoor> carDoors;
private Set<RxData> rxDatas;
public Set<RxData> getRxDatas() {
return this.rxDatas;
}
public void setRxDatas(Set<RxData> rxDatas2) {
this.rxDatas = rxDatas2;
}
public List<CarDoor> getCarDoors() {
return this.carDoors;
}
public void setCarDoors(List<CarDoor> carDoors2) {
this.carDoors = carDoors2;
}
public String toString() {
return "CarDoorSerial{rxData=" + this.rxDatas + ", carDoors=" + this.carDoors + '}';
}
}
3. I was also able to identify a file , where most probably packet is being prepared for sending to Parsing Function which will further be send to display functions.
Jsonutils.java - CanBus2_source_from_JADX\sources\com\canbus\json\utils
Java:
public static CarDoorSerial getCarDoorSerial(String json) {
try {
CarDoorSerial carDoorSerial = new CarDoorSerial();
JSONObject carDoorSerialJsonObject = new JSONObject(json);
Set<RxData> rxDatas = new HashSet<>();
List<CarDoor> carDoors = new ArrayList<>();
JSONArray carDoorJsonArray = carDoorSerialJsonObject.getJSONArray("carDoors");
for (int i = 0; i < carDoorJsonArray.length(); i++) {
JSONObject carDoorJsonObject = carDoorJsonArray.getJSONObject(i);
CarDoor carDoor = new CarDoor();
carDoor.setName(carDoorJsonObject.getInt("name"));
carDoor.setDataIndex(carDoorJsonObject.getInt("dataIndex"));
carDoor.setBit(carDoorJsonObject.getInt("bit"));
RxData rxData = new RxData();
rxData.setDataType((byte) Integer.parseInt(carDoorJsonObject.getString("dataType"), 16));
rxData.setLength(Integer.parseInt(carDoorJsonObject.getString("length"), 16));
carDoor.setRxData(rxData);
rxDatas.add(rxData);
carDoors.add(carDoor);
}
carDoorSerial.setRxDatas(rxDatas);
carDoorSerial.setCarDoors(carDoors);
return carDoorSerial;
} catch (JSONException e) {
CatchUtils.catchException(e);
return null;
}
}
4)There is also Canbuserial.Java , In this function there are different serial handler algortihms for different CANbox for eg: Hi World.
Java:
public void RxData(byte[] data, int size) {
int baudRate = CanbusStatus.getBaudRate();
this.handler.removeCallbacks(this.delayOvertime);
this.handler.postDelayed(this.delayOvertime, 500);
for (int i = 0; i < size; i++) {
byte[] bArr = this.rx_save;
int i2 = this.rx_put;
this.rx_put = i2 + 1;
bArr[i2] = data[i];
if (this.rx_put >= MAX_SAVE_BYTES) {
this.rx_put = 0;
}
}
switch (baudRate) {
case 9601:
anyuan_rx_uart();
return;
case 9602:
foton_rx_uart();
return;
case 19200:
elysee_rx_uart();
return;
case 19201:
hyudnai_rx_uart();
return;
case 19202:
qiruiA3_rx_uart();
return;
case 19203:
tpms_rx_uart();
return;
case 19205:
case 38403:
hiWorld_rx_uart_aa55();
return;
case 38401:
hiWorld_rx_uart();
return;
case 38402:
X80_rx_uart();
return;
case 38405:
xp_rx_uart_fd();
return;
case 38406:
xp_rx_uart_aa55();
return;
case 38407:
hiWorld_rx_uart_key();
return;
default:
canbox_rx_uart();
return;
}
}
5) How can I find\change the information inside APK file (json \ Java ) for , changing the parsing array match string ( For EG: If there is any match string after parsing the information ) may be, I can send the information from my CAN device to the Android Unit in similar way.
According to the message on UART being recieved, or how can we know the Parsing algorithm (for EG: Array to which receive strings are being matched to get door data etc.)

Categories

Resources