Permalink
Browse files

Android: moved logger initialization code to RhodesApplication. Renam…

…ed JNI methods in logger.
  • Loading branch information...
1 parent a0becba commit be4ace552f118b87739266593244b9a6780d71d1 @alex-epifanoff alex-epifanoff committed Apr 11, 2012
@@ -9,42 +9,42 @@ extern "C" {
#endif
/*
* Class: com_rhomobile_rhodes_Logger
- * Method: e
+ * Method: eNative
* Signature: (Ljava/lang/String;Ljava/lang/String;)V
*/
-JNIEXPORT void JNICALL Java_com_rhomobile_rhodes_Logger_e
+JNIEXPORT void JNICALL Java_com_rhomobile_rhodes_Logger_eNative
(JNIEnv *, jclass, jstring, jstring);
/*
* Class: com_rhomobile_rhodes_Logger
- * Method: w
+ * Method: wNative
* Signature: (Ljava/lang/String;Ljava/lang/String;)V
*/
-JNIEXPORT void JNICALL Java_com_rhomobile_rhodes_Logger_w
+JNIEXPORT void JNICALL Java_com_rhomobile_rhodes_Logger_wNative
(JNIEnv *, jclass, jstring, jstring);
/*
* Class: com_rhomobile_rhodes_Logger
- * Method: i
+ * Method: iNative
* Signature: (Ljava/lang/String;Ljava/lang/String;)V
*/
-JNIEXPORT void JNICALL Java_com_rhomobile_rhodes_Logger_i
+JNIEXPORT void JNICALL Java_com_rhomobile_rhodes_Logger_iNative
(JNIEnv *, jclass, jstring, jstring);
/*
* Class: com_rhomobile_rhodes_Logger
- * Method: d
+ * Method: dNative
* Signature: (Ljava/lang/String;Ljava/lang/String;)V
*/
-JNIEXPORT void JNICALL Java_com_rhomobile_rhodes_Logger_d
+JNIEXPORT void JNICALL Java_com_rhomobile_rhodes_Logger_dNative
(JNIEnv *, jclass, jstring, jstring);
/*
* Class: com_rhomobile_rhodes_Logger
- * Method: t
+ * Method: tNative
* Signature: (Ljava/lang/String;Ljava/lang/String;)V
*/
-JNIEXPORT void JNICALL Java_com_rhomobile_rhodes_Logger_t
+JNIEXPORT void JNICALL Java_com_rhomobile_rhodes_Logger_tNative
(JNIEnv *, jclass, jstring, jstring);
#ifdef __cplusplus
@@ -31,31 +31,31 @@
#undef DEFAULT_LOGCATEGORY
#define DEFAULT_LOGCATEGORY "Logger"
-RHO_GLOBAL void JNICALL Java_com_rhomobile_rhodes_Logger_e
+RHO_GLOBAL void JNICALL Java_com_rhomobile_rhodes_Logger_eNative
(JNIEnv *env, jclass, jstring tag, jstring msg)
{
RAWLOGC_ERROR(rho_cast<std::string>(env, tag).c_str(), rho_cast<std::string>(env, msg).c_str());
}
-RHO_GLOBAL void JNICALL Java_com_rhomobile_rhodes_Logger_w
+RHO_GLOBAL void JNICALL Java_com_rhomobile_rhodes_Logger_wNative
(JNIEnv *env, jclass, jstring tag, jstring msg)
{
RAWLOGC_ERROR(rho_cast<std::string>(env, tag).c_str(), rho_cast<std::string>(env, msg).c_str());
}
-RHO_GLOBAL void JNICALL Java_com_rhomobile_rhodes_Logger_i
+RHO_GLOBAL void JNICALL Java_com_rhomobile_rhodes_Logger_iNative
(JNIEnv *env, jclass, jstring tag, jstring msg)
{
RAWLOGC_INFO(rho_cast<std::string>(env, tag).c_str(), rho_cast<std::string>(env, msg).c_str());
}
-RHO_GLOBAL void JNICALL Java_com_rhomobile_rhodes_Logger_d
+RHO_GLOBAL void JNICALL Java_com_rhomobile_rhodes_Logger_dNative
(JNIEnv *env, jclass, jstring tag, jstring msg)
{
RAWLOGC_INFO(rho_cast<std::string>(env, tag).c_str(), rho_cast<std::string>(env, msg).c_str());
}
-RHO_GLOBAL void JNICALL Java_com_rhomobile_rhodes_Logger_t
+RHO_GLOBAL void JNICALL Java_com_rhomobile_rhodes_Logger_tNative
(JNIEnv *env, jclass, jstring tag, jstring msg)
{
RAWTRACEC(rho_cast<std::string>(env, tag).c_str(), rho_cast<std::string>(env, msg).c_str());
@@ -42,23 +42,23 @@
// Errors
public static void E(String tag, String msg) {
- e(tag,appendMemoryDumpIfNeeded(msg));
+ eNative(tag, appendMemoryDumpIfNeeded(msg));
}
// Warnings
public static void W(String tag, String msg) {
- w(tag, appendMemoryDumpIfNeeded(msg));
+ wNative(tag, appendMemoryDumpIfNeeded(msg));
}
// Info
public static void I(String tag, String msg) {
- i(tag, appendMemoryDumpIfNeeded(msg));
+ iNative(tag, appendMemoryDumpIfNeeded(msg));
}
// Debug
public static void D(String tag, String msg) {
- d(tag, appendMemoryDumpIfNeeded(msg));
+ dNative(tag, appendMemoryDumpIfNeeded(msg));
}
// Trace
public static void T(String tag, String msg) {
- t(tag, appendMemoryDumpIfNeeded(msg));
+ tNative(tag, appendMemoryDumpIfNeeded(msg));
}
public static void E(String tag, Throwable e) {
@@ -147,28 +147,34 @@ private static String getProcMeminfoContents() {
}
private static String getActivitiManagerMemInfo() {
- Context context = RhodesService.getContext();
- ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
- ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo();
- activityManager.getMemoryInfo(memoryInfo);
+ try {
+ Context context = RhodesService.getContext();
+ ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
+ ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo();
+ activityManager.getMemoryInfo(memoryInfo);
- StringBuilder builder = new StringBuilder();
+ StringBuilder builder = new StringBuilder();
+
+ builder.append("memoryInfo.availMem ").append(memoryInfo.availMem).append("\n");
+ builder.append("memoryInfo.lowMemory ").append(memoryInfo.lowMemory).append("\n");
+ builder.append("memoryInfo.threshold ").append(memoryInfo.threshold).append("\n");
+
+ return builder.toString();
+ } catch ( IllegalStateException e ) {
+ return "Can't get memory info from ActivityManager";
+ }
- builder.append("memoryInfo.availMem ").append(memoryInfo.availMem).append("\n");
- builder.append("memoryInfo.lowMemory ").append(memoryInfo.lowMemory).append("\n");
- builder.append("memoryInfo.threshold ").append(memoryInfo.threshold).append("\n");
- return builder.toString();
}
// Errors
- private native static void e(String tag, String msg);
+ private native static void eNative(String tag, String msg);
// Warnings
- private native static void w(String tag, String msg);
+ private native static void wNative(String tag, String msg);
// Info
- private native static void i(String tag, String msg);
+ private native static void iNative(String tag, String msg);
// Debug
- private native static void d(String tag, String msg);
+ private native static void dNative(String tag, String msg);
// Trace
- private native static void t(String tag, String msg);
+ private native static void tNative(String tag, String msg);
}
@@ -49,6 +49,8 @@
private static final String TAG = RhodesApplication.class.getSimpleName();
private static Handler mHandler;
+ private final static String CONF_MEMORY_INFO_DUMP_INTERVAL = "memory_info_dump_interval";
+
static AppEventObserver sRhodesAppActiveWatcher;
static {
NativeLibraries.load();
@@ -180,6 +182,10 @@ public void run() {
RhoFileApi.setFsModeTransparrent(true);
+ if ( RhoConf.isExist(CONF_MEMORY_INFO_DUMP_INTERVAL) ) {
+ Logger.enableMemoryInfoDump(RhoConf.getInt(CONF_MEMORY_INFO_DUMP_INTERVAL));
+ }
+
Logger.I(TAG, "Initialized");
}
private static boolean sRhodesActivityStarted = false;
@@ -285,8 +285,6 @@ public IBinder onBind(Intent intent) {
public void onCreate() {
Logger.D(TAG, "onCreate");
- initLogger();
-
sInstance = this;
Context context = this;
@@ -347,13 +345,6 @@ public void onCreate() {
handleAppActivation();
}
- private final static String CONF_MEMORY_INFO_DUMP_INTERVAL = "memory_info_dump_interval";
- private void initLogger() {
- if ( RhoConf.isExist(CONF_MEMORY_INFO_DUMP_INTERVAL) ) {
- Logger.enableMemoryInfoDump(RhoConf.getInt(CONF_MEMORY_INFO_DUMP_INTERVAL));
- }
- }
-
public static void handleAppStarted()
{
RhodesApplication.handleAppStarted();

0 comments on commit be4ace5

Please sign in to comment.