Skip to content

Commit 98cfbce

Browse files
committed
Merge pull request #446 from NativeScript/pete/move-debugger-implementation
Move debugger implementation
2 parents 347e9bf + 8e67a83 commit 98cfbce

14 files changed

Lines changed: 1041 additions & 521 deletions

File tree

build/project-template-gradle/src/main/java/com/tns/AndroidJsDebugger.java

Lines changed: 470 additions & 0 deletions
Large diffs are not rendered by default.

build/project-template-gradle/src/main/java/com/tns/ErrorReport.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,14 @@ static Intent getIntent(Context context)
114114
{
115115
Class<?> errorActivityClass = ErrorReportActivity.class;
116116

117-
if (JsDebugger.isDebuggableApp(context))
117+
if (AndroidJsDebugger.isDebuggableApp(context))
118118
{
119119
errorActivityClass = ErrorReportActivity.class;
120120
}
121121
else {
122122
return null;
123123
}
124-
124+
125125
Intent intent = new Intent(context, errorActivityClass);
126126

127127
intent.putExtra(EXTRA_NATIVESCRIPT_ERROR_REPORT, EXTRA_ERROR_REPORT_VALUE);

build/project-template-gradle/src/main/java/com/tns/LogcatLogger.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
public final class LogcatLogger implements Logger
77
{
88
private final static String DEFAULT_LOG_TAG = "TNS.Java";
9-
9+
1010
private boolean enabled;
1111

1212
public LogcatLogger(boolean isEnabled, Context context)
@@ -41,8 +41,7 @@ public final void write(String tag, String msg)
4141

4242
private void initLogging(Context context)
4343
{
44-
boolean isDebuggableApp = JsDebugger.isDebuggableApp(context);
45-
44+
boolean isDebuggableApp = AndroidJsDebugger.isDebuggableApp(context);
4645
if (isDebuggableApp)
4746
{
4847
String verboseLoggingProp = Util.readSystemProperty("nativescript.verbose.logging");

build/project-template-gradle/src/main/java/com/tns/RuntimeHelper.java

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ public void initRuntime()
4646
{
4747
System.loadLibrary("NativeScript");
4848

49-
Logger logger = new LogcatLogger(false, app);
49+
Logger logger = new LogcatLogger(true, app);
50+
Debugger debugger = new AndroidJsDebugger(app, logger);
5051

5152
boolean showErrorIntent = hasErrorIntent();
5253
if (!showErrorIntent)
@@ -89,7 +90,7 @@ public void initRuntime()
8990
e.printStackTrace();
9091
}
9192
ThreadScheduler workThreadScheduler = new WorkThreadScheduler(new Handler(Looper.getMainLooper()));
92-
Configuration config = new Configuration(this.app, workThreadScheduler, logger, appName, null, rootDir, appDir, classLoader, dexDir, dexThumb);
93+
Configuration config = new Configuration(workThreadScheduler, logger, debugger, appName, null, rootDir, appDir, classLoader, dexDir, dexThumb);
9394
Runtime runtime = new Runtime(config);
9495

9596
exHandler.setRuntime(runtime);
@@ -114,21 +115,29 @@ public void initRuntime()
114115
}
115116
}
116117

117-
118-
119-
120118
runtime.init();
121119
runtime.runScript(new File(appDir, "internal/ts_helpers.js"));
122-
123-
File javaClassesModule = new File(appDir, "app/tns-java-classes.js");
124-
if (javaClassesModule.exists()) {
125-
runtime.runModule(javaClassesModule);
126-
}
127-
128120
Runtime.initInstance(this.app);
129121
runtime.run();
130122
}
131123
}
132124

125+
/* public static boolean isDebuggableApp(Context context)
126+
{
127+
int flags;
128+
try
129+
{
130+
flags = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).applicationInfo.flags;
131+
}
132+
catch (NameNotFoundException e)
133+
{
134+
flags = 0;
135+
e.printStackTrace();
136+
}
137+
138+
boolean isDebuggableApp = ((flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0);
139+
return isDebuggableApp;
140+
}*/
141+
133142
private final String logTag = "MyApp";
134143
}

src/jni/Application.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ APP_CFLAGS += -Wno-error=format-security
1212
APP_CFLAGS += -g
1313

1414
#Turn on C++ exceptions
15-
APP_CPPFLAGS += -fexceptions
15+
APP_CPPFLAGS += -fexceptions

src/src/com/tns/Configuration.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
public class Configuration
88
{
9-
public final Application application;
109
public final ThreadScheduler threadScheduler;
1110
public final Logger logger;
11+
public final Debugger debugger;
1212
public final String appName;
1313
public final File runtimeLibPath;
1414
public final File rootDir;
@@ -17,13 +17,13 @@ public class Configuration
1717
public final File dexDir;
1818
public final String dexThumb;
1919

20-
public Configuration(Application application, ThreadScheduler threadScheduler, Logger logger,
20+
public Configuration(ThreadScheduler threadScheduler, Logger logger, Debugger debugger,
2121
String appName, File runtimeLibPath, File rootDir, File appDir, ClassLoader classLoader,
2222
File dexDir, String dexThumb)
2323
{
24-
this.application = application;
2524
this.threadScheduler = threadScheduler;
2625
this.logger = logger;
26+
this.debugger = debugger;
2727
this.appName = appName;
2828
this.runtimeLibPath = runtimeLibPath;
2929
this.rootDir = rootDir;

src/src/com/tns/Debugger.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.tns;
2+
3+
public interface Debugger
4+
{
5+
void start();
6+
7+
void disableAgent();
8+
9+
void enableAgent();
10+
11+
void onConnect(JsDebugger context);
12+
}

0 commit comments

Comments
 (0)