Problem with system() call - android

I am using a system() call in a program , that is in c library. For 1st 9 calls it returns '0'(zero) after 10th call it returns 256. I do not know what does it mean. Please anybody help me. Following is the line of code
int returnValue= system("/system/bin/cat /dev/graphics/fb0 > /tmpdata/Screenshot/screenshot.bin");

According to this man page dealing with the general unix cat command, an error code >0 simply means an error occurred.
The following exit values shall be returned:
0
All input files were output successfully.
>0
An error occurred.
Your system() call is attempting to concatentate two files, so perhaps there is a space issue or maybe the source file does not exist.
You may also wish to take a look at some recent source code for Android cat (cat.c) which gives some indicatations of the kind of things that trigger errors within cat.

Related

How to use user_ops in Tensorflow Android APP

I want to transplantation Faster RCNN to Android device, and I meet some problems.
I build my Android project by Bazel, just like the tensorflow demo. I add the op roi_pooling_op.cc and proposal_op.cc to user_ops, but I seems Android does build user_ops, the logcat shows as following:
tensorflow_inference_jni.cc:146 Could not create TensorFlow graph: Not found: Op type not registered 'RoiPooling'
I try to solve this problem, and I move roi_pooling_op.cc and proposal_op.cc to jni folder(maybe it is a bad ideal), the previous error is disappeared, but I meet another problem, outputs are all not found, I do not know why, logcat as following:
tensorflow_inference_jni.cc:170 Output [rois] not found, aborting!
tensorflow_inference_jni.cc:170 Output [bbox_pred/bbox_pred] not found, aborting!
tensorflow_inference_jni.cc:170 Output [cls_prob] not found, aborting!
I do not know how to solve them and I to debug, could you help me.
Thanks in advance!
Is there an output index on these nodes, perhaps? E.G. "rois:0" or "rois:1".
If you add a log line for node names/types to stat_summarizer.cc in the constructor you can see what nodes are defined in your graph which might illuminate the problem.
Adding the ops to the jni directory as you've done should work fine as a quick and dirty solution, and it seems to have done so if it got you past your initial problem.

syntax error, unexpected tCONSTANT, expecting end-of-input

I'm having some issues defining my own steps using Calabash-Android and Cucumber.
My step definition file contains
require 'calabash-android/calabash_steps'
Given /^I wait for obb download$/ do
pending
end
And the error message I am getting is
Calabash-Android/features/step_definitions/calabash_steps.rb:1: syntax error, unexpected tCONSTANT, expecting end-of-input
Given /^I wait for obb download$/ ...
... ^ (SyntaxError)
I have tried using the Given and When prepositions and no matter what I put inside the do block, I get the same error. When I comment out requires, it will run, but crash when I get to that step. It also works when I comment out my step definition and remove my step.
I have also tried every combination of / /^, /, $/, and "" and I still get the same error.
Any assistance would be appreciated. Thanks.

Why shouldn't I use System.out.println() in android

In the Android Open Source Project's code style, it states that we shouldn't use System.out.println() but I don't understand why. Can anyone explain? What should I use to trace my app's log?
Here's the line for reference:
System.out.println() (or printf() for native code) should never be used. System.out and System.err get redirected to /dev/null, so your print statements will have no visible effects. However, all the string building that happens for these calls still gets executed.
You should use the android.util.Log class.
Here's a description of what the Log class does:
API for sending log output.
Generally, you should use the Log.v(), Log.d(), Log.i(), Log.w(), and Log.e() methods to write logs. You can then view the logs in logcat.
The order in terms of verbosity, from least to most is ERROR, WARN, INFO, DEBUG, VERBOSE. Verbose should never be compiled into an application except during development. Debug logs are compiled in but stripped at runtime. Error, warning and info logs are always kept.
These are the available methods of the Log class:
Log.d() - Send a DEBUG log message.
Log.e() - Send an ERROR log message.
Log.i() - Send an INFO log message.
Log.v() - Send a VERBOSE log message.
Log.w() - Send a WARN log message.
Log.wtf() - What a Terrible Failure: Report an exception that should never happen.
The methods above (with the exception of Log.w and Log.wtf which have 3 possible patterns of arguments) require the following arguments:
String tag, String msg:
tag: Used to identify the source of a log message. This value may be null.
msg: The message you would like logged. This value may be null.
String tag, String msg, Throwable tr - Similar to the first pattern, but allows for an exception to be specified. This pattern should be used if you want to log an exception to the log output.
(For Log.w and Log.wtf) String tag, Throwable tr Similar to the third pattern, but does not allow for a message to be specified. Note that you can still pass a message but it should be in the second arrangement of arguments.
EDIT: Going straight to answer your question: println() of System.out and System.err will still be displayed in logcat but with limitations.
You can't log VERBOSE, ERROR, or DEBUG using System.out or System.err.
You can't define your own tag, it will display System.err or System.out with your text. For instance:
System.out.println("Hello!") is equivalent to Log.i("System.out","Hello!")
System.err.println("Hello!") is equivalent to Log.w("System.err","Hello!")
System.out.println("") in android will not run well because there is no Terminal that the app is corrected to.
You would be better off using Log.(d)(v)(e)(i)(w), because there is something actively monitoring LogCat.
System.out.println() will print to LogCat, but only after an additional set of System instuctions, making it not as efficient, however, as i said, it still works.
if we want to trace the android project
we can do it using Log class
there is some methods like
Log.e(TAG,MESSAGE)
Log.v(TAG,MESSAGE)
Log.w(TAG,MESSAGE)
Log.d(TAG,MESSAGE)
Log.i(TAG,MESSAGE)
its a static method of Utils package. put it line by line and u can watch it in the LogCat..
thats at enjoy with android
From your own link:
System.out.println() (or printf() for native code) should never be
used. System.out and System.err get redirected to /dev/null, so your
print statements will have no visible effects. However, all the string
building that happens for these calls still gets executed.
In addition, at the beginning of that page, it says:
The rules below are not guidelines or recommendations, but strict
rules. Contributions to Android generally will not be accepted if they
do not adhere to these rules.
So DON'T do it!
You can use the built in Log utility that will print right out to the LogCat.
You can use Log.e(String, String) for errors which will appear in red. There is also v, d, i, and w for verbose, debug, info, and warning respectively.
The following should do the trick to print the exception
1. Log.d("myapp", Log.getStackTraceString(new Exception()));
or
2. You can get longer stack traces by digging deeper. For example:
Log.getStackTraceString(e.getCause().getCause());
Log is the best way to trace our android project
like following code...
it will help u...
just look in DDMS logCat that how exactly project is build...
requirement... android.utils.Log; package is used..
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
for(int i=0;i
{
Log.e("i = ",""+i);
Log.v("i = ",""+i);
Log.i("i = ",""+i);
Log.w("i = ",""+i);
Log.d("i = ",""+i);
}
}
i hope it will help u

Android NDK: diagnose log log function error

How to diagnose log log function error, that is when negative value is returned:
/*
* Send a formatted string to the log, used like printf(fmt,...)
*/
int __android_log_print(int prio, const char *tag, const char *fmt, ...);
Thank you!
Short answer: check errno.
Long answer: There appear two reasons __android_log_print can return a negative value. The first is if it's unable to open any of the log files for writing (/dev/log/main, /dev/log/radio, or /dev/log/events). The second is if the write() system call returns a negative number.
After __android_log_print returns a negative value, is errno set? If so, its value should give you some information about what went wrong. If errno is zero, your log call probably wound up in __write_to_log_null and you should investigate your program's ability to open those /dev/log files.
If errno is set, it's possible that it was set when trying to open the log files. You should be able to isolate this case by setting errno = 0, then calling __android_log_bug_write with a bad log_id (first argument). For this to be useful, it'll need to be the first call to any of the logging functions - otherwise the file opening stage will have been and gone. Obviously this is only necessary if errno is set to something that could have been at write time or at open time.
This answer comes to you courtesy of system/core/liblog/logd_write.c.

In OPENSSL , After SSL_Connect() i am getting SSL_ERROR_WANT_READ

I am using SSL_Connect() and return code is "-1" , with SSL_get_error() i can see that error is SSL_ERROR_WANT_READ.
As per suggestion on one forum, where it suggested to keep calling SSL_connect() until this error goes. With this modification for first call i am getting error WANT_READ and for second call i am getting SSL_ERROR_SSL. After that for all subsequent calls it is SSL_ERROR_SSL only and as per description of this error it looks something went wrong in SSL library.
Can some one who resolved SSL_connect successfully provide some help.
My code is a plain sequence of calling :
1. SSL_library_init()
2. Creating methods(v23) and context using this meth
3. context has not been modified and it plain as created.
4. SSL object is created using this plain ctx and ssl_connect is called on this ssl after calling SSL_set_fd()
Please let me know if i am doing some thing wrong in this sequence or if i am missing something ?
Is it required to load various things to ctx like certificates and verify locations before using it , if yes what are the bare minimum things required.
Thanks in advance for help.
If it wants a read you have to do a read, or block in select() until OP_READ fires if non-blocking, and then call SSL_Connect() again.
If it wants a write you have to do a write, or block in select() until OP_WRITE fires if non-blocking, and then call SSL_Connect() again.
See here.

Categories

Resources