From 6838000fd90d4e4161873ee91845be5f22850234 Mon Sep 17 00:00:00 2001 From: Simon Urli Date: Thu, 28 Jun 2018 11:28:11 +0200 Subject: [PATCH 1/4] Start working on issue 2230 --- .../DefaultPrettyPrinterTest.java | 15 + .../prettyprinter/testclasses/LogService.java | 9 + .../resources/noclasspath/LogService.java | 371 ++++++++++++++++++ 3 files changed, 395 insertions(+) create mode 100644 src/test/java/spoon/test/prettyprinter/testclasses/LogService.java create mode 100644 src/test/resources/noclasspath/LogService.java diff --git a/src/test/java/spoon/test/prettyprinter/DefaultPrettyPrinterTest.java b/src/test/java/spoon/test/prettyprinter/DefaultPrettyPrinterTest.java index 84dc883b98a..32d0594fb71 100644 --- a/src/test/java/spoon/test/prettyprinter/DefaultPrettyPrinterTest.java +++ b/src/test/java/spoon/test/prettyprinter/DefaultPrettyPrinterTest.java @@ -303,4 +303,19 @@ public void testIssue1501() { assertFalse(launcher.getModel().getAllTypes().isEmpty()); } + @Test + public void testIssue2130() { + // contract: ... + + Launcher launcher = new Launcher(); + launcher.getEnvironment().setNoClasspath(true); + //launcher.addInputResource("./src/test/resources/noclasspath/LogService.java"); + launcher.addInputResource("./src/test/java/spoon/test/prettyprinter/testclasses/LogService.java"); + launcher.setSourceOutputDirectory("./target/issue2130"); + launcher.getEnvironment().setComplianceLevel(8); + launcher.run(); + + assertFalse(launcher.getModel().getAllTypes().isEmpty()); + } + } diff --git a/src/test/java/spoon/test/prettyprinter/testclasses/LogService.java b/src/test/java/spoon/test/prettyprinter/testclasses/LogService.java new file mode 100644 index 00000000000..1887829d6a9 --- /dev/null +++ b/src/test/java/spoon/test/prettyprinter/testclasses/LogService.java @@ -0,0 +1,9 @@ +package spoon.test.prettyprinter.testclasses; + +public class LogService { + + public Void myMethod(Void... voids) { + System.out.println("machin"); + return null; + } +} diff --git a/src/test/resources/noclasspath/LogService.java b/src/test/resources/noclasspath/LogService.java new file mode 100644 index 00000000000..4dceffeffc4 --- /dev/null +++ b/src/test/resources/noclasspath/LogService.java @@ -0,0 +1,371 @@ +/** + * Background service to spool /proc/kmesg command output using klogripper + *

+ * Copyright (C) 2014 Umakanthan Chandran + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * @author Umakanthan Chandran + * @version 1.0 + */ + +package dev.ukanth.ufirewall.service; + +import android.app.AlarmManager; +import android.app.PendingIntent; +import android.app.Service; +import android.content.Context; +import android.content.Intent; +import android.os.AsyncTask; +import android.os.Binder; +import android.os.Handler; +import android.os.IBinder; +import android.support.annotation.Nullable; +import android.view.Gravity; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.TextView; +import android.widget.Toast; + +import com.raizlabs.android.dbflow.config.FlowConfig; +import com.raizlabs.android.dbflow.config.FlowManager; + +import org.xbill.DNS.Address; + +import java.net.InetAddress; +import java.util.HashSet; +import java.util.Set; + +import dev.ukanth.ufirewall.Api; +import dev.ukanth.ufirewall.R; +import dev.ukanth.ufirewall.events.LogEvent; +import dev.ukanth.ufirewall.log.Log; +import dev.ukanth.ufirewall.log.LogData; +import dev.ukanth.ufirewall.log.LogDatabase; +import dev.ukanth.ufirewall.log.LogInfo; +import dev.ukanth.ufirewall.log.LogRxEvent; +import dev.ukanth.ufirewall.util.G; +import eu.chainfire.libsuperuser.Shell; +import eu.chainfire.libsuperuser.StreamGobbler; +import io.reactivex.disposables.Disposable; + +public class LogService extends Service { + + public static final String TAG = "AFWall"; + + public static String logPath; + private final IBinder mBinder = new Binder(); + + private Shell.Interactive rootSession; + static Handler handler; + + public static final int QUEUE_NUM = 40; + + public static Toast toast; + public static TextView toastTextView; + public static CharSequence toastText; + public static int toastDuration; + public static int toastDefaultYOffset; + public static int toastYOffset; + LogData data; + + private static Runnable showOnlyToastRunnable; + private static CancelableRunnable showToastRunnable; + private static View toastLayout; + + private Disposable disposable; + + private static abstract class CancelableRunnable implements Runnable { + public boolean cancel; + } + + @Nullable + @Override + public IBinder onBind(Intent intent) { + return null; + } + + public static void showToast(final Context context, final Handler handler, final CharSequence text, boolean cancel) { + if (showToastRunnable == null) { + showToastRunnable = new CancelableRunnable() { + public void run() { + if (cancel && toast != null) { + toast.cancel(); + } + + if (cancel || toast == null) { + toastLayout = ((LayoutInflater) context.getSystemService(LAYOUT_INFLATER_SERVICE)).inflate(R.layout.custom_toast, null); + toastTextView = (TextView) toastLayout.findViewById(R.id.toasttext); + if (toast == null) { + toast = new Toast(context); + } + toastDefaultYOffset = toast.getYOffset(); + toast.setView(toastLayout); + } + + switch (toastDuration) { + case 3500: + toast.setDuration(Toast.LENGTH_LONG); + break; + case 7000: + toast.setDuration(Toast.LENGTH_LONG); + + if (showOnlyToastRunnable == null) { + showOnlyToastRunnable = new Runnable() { + public void run() { + toast.show(); + } + }; + } + + handler.postDelayed(showOnlyToastRunnable, 3250); + break; + default: + toast.setDuration(Toast.LENGTH_SHORT); + } + + switch (G.toast_pos()) { + case "top": + toast.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.TOP, 0, toastYOffset); + break; + case "bottom": + toast.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM, 0, toastYOffset); + break; + case "center": + toast.setGravity(Gravity.CENTER, 0, 0); + break; + default: + toast.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM, 0, toastDefaultYOffset); + break; + } + + toastTextView.setText(android.text.Html.fromHtml(toastText.toString())); + toast.show(); + } + }; + } + + showToastRunnable.cancel = cancel; + toastText = text; + handler.post(showToastRunnable); + } + + @Override + public int onStartCommand(Intent intent, int flags, int startId) { + if (intent == null) { + Log.i(TAG, "Restarting LogService"); + startLogService(); + } + return START_STICKY; + } + + + @Override + public void onCreate() { + startLogService(); + } + + private void startLogService() { + disposable = LogRxEvent.subscribe((event -> { + if (event != null) { + new AsyncTask() { + @Override + protected Void doInBackground(Void... voids) { + store(event.logInfo,event.ctx); + return null; + } + + @Override + protected void onPostExecute(Void a) { + if (event != null && event.logInfo.uidString != null && event.logInfo.uidString.length() > 0) { + if (G.showLogToasts() && G.canShow(event.logInfo.uid)) { + showToast(event.ctx, handler, event.logInfo.uidString, false); + } + } + } + }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + } + }) + ); + if (G.enableLogService()) { + // this method is executed in a background thread + // no problem calling su here + if (G.logTarget() != null && G.logTarget().length() > 1) { + if (G.logDmsg().isEmpty()) { + G.logDmsg("OS"); + } + switch (G.logTarget()) { + case "LOG": + switch (G.logDmsg()) { + case "OS": + logPath = "echo PID=$$ & while true; do dmesg -c ; sleep 1 ; done"; + break; + case "BX": + logPath = "echo PID=$$ & while true; do busybox dmesg -c ; sleep 1 ; done"; + break; + default: + logPath = "echo PID=$$ & while true; do dmesg -c ; sleep 1 ; done"; + } + + break; + case "NFLOG": + logPath = Api.getNflogPath(getApplicationContext()); + logPath = "echo $$ & " + logPath + " " + QUEUE_NUM; + break; + } + + Log.i(TAG, "Starting Log Service: " + logPath + " for LogTarget: " + G.logTarget()); + Log.i(TAG, "rootSession " + rootSession != null ? "rootSession is not Null" : "Null rootSession"); + handler = new Handler(); + + closeSession(); + rootSession = new Shell.Builder() + .useSU() + .setMinimalLogging(true) + .setOnSTDOUTLineListener(new StreamGobbler.OnLineListener() { + @Override + public void onLine(String line) { + if (line != null && !line.isEmpty() && line.startsWith("PID=")) { + try { + String uid = line.split("=")[1]; + if (uid != null) { + Set data = G.storedPid(); + if (data == null || data.isEmpty()) { + data = new HashSet(); + data.add(uid); + G.storedPid(data); + } else if (!data.contains(uid)) { + Set data2 = new HashSet(); + data2.addAll(data); + data2.add(uid); + G.storedPid(data2); + } + } + } catch (Exception e) { + } + } else { + storeLogInfo(line, getApplicationContext()); + } + + } + }).addCommand(logPath).open(); + } else { + Log.i(TAG, "Unable to start log service. LogTarget is empty"); + Api.toast(getApplicationContext(), getApplicationContext().getString(R.string.error_log)); + G.enableLogService(false); + stopSelf(); + } + } else { + Log.i(Api.TAG, "Logservice is running.. skipping"); + } + } + + private void closeSession() { + new Thread(new Runnable() { + @Override + public void run() { + Log.i(Api.TAG, "Cleanup session"); + if (rootSession != null) { + rootSession.close(); + } + } + }).start(); + Api.cleanupUid(); + } + + + private void storeLogInfo(String line, Context context) { + if (G.enableLogService()) { + if (line != null && line.trim().length() > 0) { + if (line.contains("AFL")) { + new AsyncTask() { + @Override + protected LogInfo doInBackground(Void... voids) { + return LogInfo.parseLogs(line, context); + } + + @Override + protected void onPostExecute(LogInfo a) { + if (a != null) { + LogRxEvent.publish(new LogEvent(a, context)); + } + } + }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + } + } + } + } + + private void store(final LogInfo logInfo, Context context) { + try { + data = new LogData(); + data.setDst(logInfo.dst); + data.setOut(logInfo.out); + data.setSrc(logInfo.src); + data.setDpt(logInfo.dpt); + data.setIn(logInfo.in); + data.setLen(logInfo.len); + data.setProto(logInfo.proto); + data.setTimestamp(System.currentTimeMillis()); + data.setSpt(logInfo.spt); + data.setUid(logInfo.uid); + data.setAppName(logInfo.appName); + if(G.isDoKey(context) || G.isDonate()) { + data.setHostname(Address.getHostName(InetAddress.getByName(logInfo.dst))); + } + data.setType(0); + FlowManager.getDatabase(LogDatabase.class).beginTransactionAsync(databaseWrapper -> data.save(databaseWrapper)).build().execute(); + } catch (IllegalStateException e) { + if (e.getMessage().contains("connection pool has been closed")) { + //reconnect logic + try { + FlowManager.init(new FlowConfig.Builder(this).build()); + } catch (Exception de) { + Log.i(TAG, "Exception while saving log data:" + e.getLocalizedMessage()); + } + } + Log.i(TAG, "Exception while saving log data:" + e.getLocalizedMessage()); + } catch (Exception e) { + Log.i(TAG, "Exception while saving log data:" + e.getLocalizedMessage()); + } + + } + + @Override + public void onDestroy() { + closeSession(); + if (disposable != null) { + disposable.dispose(); + ; + } + super.onDestroy(); + } + + @Override + public void onTaskRemoved(Intent rootIntent) { + super.onTaskRemoved(rootIntent); + Log.d(TAG, "Log service removed"); + + PendingIntent service = PendingIntent.getService( + getApplicationContext(), + 1001, + new Intent(getApplicationContext(), LogService.class), + PendingIntent.FLAG_ONE_SHOT); + + AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); + alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, 1000, service); + } + + +} From 214a0bc999ec834d2b9695394e6824e3e088d4b5 Mon Sep 17 00:00:00 2001 From: Simon Urli Date: Thu, 28 Jun 2018 12:47:14 +0200 Subject: [PATCH 2/4] Isolate and reproduce the bug --- .../DefaultPrettyPrinterTest.java | 25 +- .../prettyprinter/testclasses/LogService.java | 9 - .../resources/noclasspath/LogService.java | 374 +----------------- 3 files changed, 29 insertions(+), 379 deletions(-) delete mode 100644 src/test/java/spoon/test/prettyprinter/testclasses/LogService.java diff --git a/src/test/java/spoon/test/prettyprinter/DefaultPrettyPrinterTest.java b/src/test/java/spoon/test/prettyprinter/DefaultPrettyPrinterTest.java index 32d0594fb71..e3022748559 100644 --- a/src/test/java/spoon/test/prettyprinter/DefaultPrettyPrinterTest.java +++ b/src/test/java/spoon/test/prettyprinter/DefaultPrettyPrinterTest.java @@ -7,16 +7,21 @@ import spoon.compiler.Environment; import spoon.compiler.SpoonResource; import spoon.compiler.SpoonResourceHelper; +import spoon.reflect.CtModel; import spoon.reflect.code.CtCodeSnippetStatement; import spoon.reflect.code.CtConstructorCall; import spoon.reflect.code.CtInvocation; import spoon.reflect.code.CtStatement; import spoon.reflect.declaration.CtClass; +import spoon.reflect.declaration.CtMethod; +import spoon.reflect.declaration.CtParameter; import spoon.reflect.declaration.CtType; import spoon.reflect.factory.Factory; +import spoon.reflect.reference.CtArrayTypeReference; import spoon.reflect.reference.CtTypeReference; import spoon.reflect.visitor.DefaultJavaPrettyPrinter; import spoon.reflect.visitor.Query; +import spoon.reflect.visitor.filter.NamedElementFilter; import spoon.reflect.visitor.filter.TypeFilter; import spoon.support.JavaOutputProcessor; import spoon.test.prettyprinter.testclasses.AClass; @@ -28,6 +33,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static spoon.testing.utils.ModelUtils.build; @@ -305,17 +311,26 @@ public void testIssue1501() { @Test public void testIssue2130() { - // contract: ... + // contract: varargs parameters should always be CtArrayTypeReference Launcher launcher = new Launcher(); launcher.getEnvironment().setNoClasspath(true); - //launcher.addInputResource("./src/test/resources/noclasspath/LogService.java"); - launcher.addInputResource("./src/test/java/spoon/test/prettyprinter/testclasses/LogService.java"); + launcher.addInputResource("./src/test/resources/noclasspath/LogService.java"); launcher.setSourceOutputDirectory("./target/issue2130"); launcher.getEnvironment().setComplianceLevel(8); - launcher.run(); + CtModel model = launcher.buildModel(); - assertFalse(launcher.getModel().getAllTypes().isEmpty()); + CtMethod machin = model.getElements(new NamedElementFilter(CtMethod.class, "machin")).get(0); + assertEquals("machin", machin.getSimpleName()); + + List> parameters = machin.getParameters(); + assertEquals(1, parameters.size()); + + CtParameter ctParameter = parameters.get(0); + assertTrue(ctParameter.isVarArgs()); + assertTrue(ctParameter.getType() instanceof CtArrayTypeReference); + + //launcher.prettyprint(); } } diff --git a/src/test/java/spoon/test/prettyprinter/testclasses/LogService.java b/src/test/java/spoon/test/prettyprinter/testclasses/LogService.java deleted file mode 100644 index 1887829d6a9..00000000000 --- a/src/test/java/spoon/test/prettyprinter/testclasses/LogService.java +++ /dev/null @@ -1,9 +0,0 @@ -package spoon.test.prettyprinter.testclasses; - -public class LogService { - - public Void myMethod(Void... voids) { - System.out.println("machin"); - return null; - } -} diff --git a/src/test/resources/noclasspath/LogService.java b/src/test/resources/noclasspath/LogService.java index 4dceffeffc4..bc7b3f54f37 100644 --- a/src/test/resources/noclasspath/LogService.java +++ b/src/test/resources/noclasspath/LogService.java @@ -1,371 +1,15 @@ -/** - * Background service to spool /proc/kmesg command output using klogripper - *

- * Copyright (C) 2014 Umakanthan Chandran - *

- * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - *

- * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - *

- * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * @author Umakanthan Chandran - * @version 1.0 - */ +package spoon.test.prettyprinter.testclasses; -package dev.ukanth.ufirewall.service; +public class LogService { -import android.app.AlarmManager; -import android.app.PendingIntent; -import android.app.Service; -import android.content.Context; -import android.content.Intent; -import android.os.AsyncTask; -import android.os.Binder; -import android.os.Handler; -import android.os.IBinder; -import android.support.annotation.Nullable; -import android.view.Gravity; -import android.view.LayoutInflater; -import android.view.View; -import android.widget.TextView; -import android.widget.Toast; + public void main() { + new ArrayList2().forEach(x -> { + new Machin() { -import com.raizlabs.android.dbflow.config.FlowConfig; -import com.raizlabs.android.dbflow.config.FlowManager; - -import org.xbill.DNS.Address; - -import java.net.InetAddress; -import java.util.HashSet; -import java.util.Set; - -import dev.ukanth.ufirewall.Api; -import dev.ukanth.ufirewall.R; -import dev.ukanth.ufirewall.events.LogEvent; -import dev.ukanth.ufirewall.log.Log; -import dev.ukanth.ufirewall.log.LogData; -import dev.ukanth.ufirewall.log.LogDatabase; -import dev.ukanth.ufirewall.log.LogInfo; -import dev.ukanth.ufirewall.log.LogRxEvent; -import dev.ukanth.ufirewall.util.G; -import eu.chainfire.libsuperuser.Shell; -import eu.chainfire.libsuperuser.StreamGobbler; -import io.reactivex.disposables.Disposable; - -public class LogService extends Service { - - public static final String TAG = "AFWall"; - - public static String logPath; - private final IBinder mBinder = new Binder(); - - private Shell.Interactive rootSession; - static Handler handler; - - public static final int QUEUE_NUM = 40; - - public static Toast toast; - public static TextView toastTextView; - public static CharSequence toastText; - public static int toastDuration; - public static int toastDefaultYOffset; - public static int toastYOffset; - LogData data; - - private static Runnable showOnlyToastRunnable; - private static CancelableRunnable showToastRunnable; - private static View toastLayout; - - private Disposable disposable; - - private static abstract class CancelableRunnable implements Runnable { - public boolean cancel; - } - - @Nullable - @Override - public IBinder onBind(Intent intent) { - return null; - } - - public static void showToast(final Context context, final Handler handler, final CharSequence text, boolean cancel) { - if (showToastRunnable == null) { - showToastRunnable = new CancelableRunnable() { - public void run() { - if (cancel && toast != null) { - toast.cancel(); - } - - if (cancel || toast == null) { - toastLayout = ((LayoutInflater) context.getSystemService(LAYOUT_INFLATER_SERVICE)).inflate(R.layout.custom_toast, null); - toastTextView = (TextView) toastLayout.findViewById(R.id.toasttext); - if (toast == null) { - toast = new Toast(context); - } - toastDefaultYOffset = toast.getYOffset(); - toast.setView(toastLayout); - } - - switch (toastDuration) { - case 3500: - toast.setDuration(Toast.LENGTH_LONG); - break; - case 7000: - toast.setDuration(Toast.LENGTH_LONG); - - if (showOnlyToastRunnable == null) { - showOnlyToastRunnable = new Runnable() { - public void run() { - toast.show(); - } - }; - } - - handler.postDelayed(showOnlyToastRunnable, 3250); - break; - default: - toast.setDuration(Toast.LENGTH_SHORT); - } - - switch (G.toast_pos()) { - case "top": - toast.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.TOP, 0, toastYOffset); - break; - case "bottom": - toast.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM, 0, toastYOffset); - break; - case "center": - toast.setGravity(Gravity.CENTER, 0, 0); - break; - default: - toast.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM, 0, toastDefaultYOffset); - break; - } - - toastTextView.setText(android.text.Html.fromHtml(toastText.toString())); - toast.show(); + public Void machin(Void... voids) { + return null; } - }; - } - - showToastRunnable.cancel = cancel; - toastText = text; - handler.post(showToastRunnable); - } - - @Override - public int onStartCommand(Intent intent, int flags, int startId) { - if (intent == null) { - Log.i(TAG, "Restarting LogService"); - startLogService(); - } - return START_STICKY; + }.machin(null); + }); } - - - @Override - public void onCreate() { - startLogService(); - } - - private void startLogService() { - disposable = LogRxEvent.subscribe((event -> { - if (event != null) { - new AsyncTask() { - @Override - protected Void doInBackground(Void... voids) { - store(event.logInfo,event.ctx); - return null; - } - - @Override - protected void onPostExecute(Void a) { - if (event != null && event.logInfo.uidString != null && event.logInfo.uidString.length() > 0) { - if (G.showLogToasts() && G.canShow(event.logInfo.uid)) { - showToast(event.ctx, handler, event.logInfo.uidString, false); - } - } - } - }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } - }) - ); - if (G.enableLogService()) { - // this method is executed in a background thread - // no problem calling su here - if (G.logTarget() != null && G.logTarget().length() > 1) { - if (G.logDmsg().isEmpty()) { - G.logDmsg("OS"); - } - switch (G.logTarget()) { - case "LOG": - switch (G.logDmsg()) { - case "OS": - logPath = "echo PID=$$ & while true; do dmesg -c ; sleep 1 ; done"; - break; - case "BX": - logPath = "echo PID=$$ & while true; do busybox dmesg -c ; sleep 1 ; done"; - break; - default: - logPath = "echo PID=$$ & while true; do dmesg -c ; sleep 1 ; done"; - } - - break; - case "NFLOG": - logPath = Api.getNflogPath(getApplicationContext()); - logPath = "echo $$ & " + logPath + " " + QUEUE_NUM; - break; - } - - Log.i(TAG, "Starting Log Service: " + logPath + " for LogTarget: " + G.logTarget()); - Log.i(TAG, "rootSession " + rootSession != null ? "rootSession is not Null" : "Null rootSession"); - handler = new Handler(); - - closeSession(); - rootSession = new Shell.Builder() - .useSU() - .setMinimalLogging(true) - .setOnSTDOUTLineListener(new StreamGobbler.OnLineListener() { - @Override - public void onLine(String line) { - if (line != null && !line.isEmpty() && line.startsWith("PID=")) { - try { - String uid = line.split("=")[1]; - if (uid != null) { - Set data = G.storedPid(); - if (data == null || data.isEmpty()) { - data = new HashSet(); - data.add(uid); - G.storedPid(data); - } else if (!data.contains(uid)) { - Set data2 = new HashSet(); - data2.addAll(data); - data2.add(uid); - G.storedPid(data2); - } - } - } catch (Exception e) { - } - } else { - storeLogInfo(line, getApplicationContext()); - } - - } - }).addCommand(logPath).open(); - } else { - Log.i(TAG, "Unable to start log service. LogTarget is empty"); - Api.toast(getApplicationContext(), getApplicationContext().getString(R.string.error_log)); - G.enableLogService(false); - stopSelf(); - } - } else { - Log.i(Api.TAG, "Logservice is running.. skipping"); - } - } - - private void closeSession() { - new Thread(new Runnable() { - @Override - public void run() { - Log.i(Api.TAG, "Cleanup session"); - if (rootSession != null) { - rootSession.close(); - } - } - }).start(); - Api.cleanupUid(); - } - - - private void storeLogInfo(String line, Context context) { - if (G.enableLogService()) { - if (line != null && line.trim().length() > 0) { - if (line.contains("AFL")) { - new AsyncTask() { - @Override - protected LogInfo doInBackground(Void... voids) { - return LogInfo.parseLogs(line, context); - } - - @Override - protected void onPostExecute(LogInfo a) { - if (a != null) { - LogRxEvent.publish(new LogEvent(a, context)); - } - } - }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } - } - } - } - - private void store(final LogInfo logInfo, Context context) { - try { - data = new LogData(); - data.setDst(logInfo.dst); - data.setOut(logInfo.out); - data.setSrc(logInfo.src); - data.setDpt(logInfo.dpt); - data.setIn(logInfo.in); - data.setLen(logInfo.len); - data.setProto(logInfo.proto); - data.setTimestamp(System.currentTimeMillis()); - data.setSpt(logInfo.spt); - data.setUid(logInfo.uid); - data.setAppName(logInfo.appName); - if(G.isDoKey(context) || G.isDonate()) { - data.setHostname(Address.getHostName(InetAddress.getByName(logInfo.dst))); - } - data.setType(0); - FlowManager.getDatabase(LogDatabase.class).beginTransactionAsync(databaseWrapper -> data.save(databaseWrapper)).build().execute(); - } catch (IllegalStateException e) { - if (e.getMessage().contains("connection pool has been closed")) { - //reconnect logic - try { - FlowManager.init(new FlowConfig.Builder(this).build()); - } catch (Exception de) { - Log.i(TAG, "Exception while saving log data:" + e.getLocalizedMessage()); - } - } - Log.i(TAG, "Exception while saving log data:" + e.getLocalizedMessage()); - } catch (Exception e) { - Log.i(TAG, "Exception while saving log data:" + e.getLocalizedMessage()); - } - - } - - @Override - public void onDestroy() { - closeSession(); - if (disposable != null) { - disposable.dispose(); - ; - } - super.onDestroy(); - } - - @Override - public void onTaskRemoved(Intent rootIntent) { - super.onTaskRemoved(rootIntent); - Log.d(TAG, "Log service removed"); - - PendingIntent service = PendingIntent.getService( - getApplicationContext(), - 1001, - new Intent(getApplicationContext(), LogService.class), - PendingIntent.FLAG_ONE_SHOT); - - AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); - alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, 1000, service); - } - - } From 0f7a7653e3146660325b8eb37920adbb604419e1 Mon Sep 17 00:00:00 2001 From: Simon Urli Date: Thu, 28 Jun 2018 13:17:22 +0200 Subject: [PATCH 3/4] Fix proposal --- .../java/spoon/support/compiler/jdt/JDTTreeBuilder.java | 3 ++- .../java/spoon/support/compiler/jdt/ReferenceBuilder.java | 8 +++++++- .../test/prettyprinter/DefaultPrettyPrinterTest.java | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main/java/spoon/support/compiler/jdt/JDTTreeBuilder.java b/src/main/java/spoon/support/compiler/jdt/JDTTreeBuilder.java index d22a89d8f5f..103517e79d3 100644 --- a/src/main/java/spoon/support/compiler/jdt/JDTTreeBuilder.java +++ b/src/main/java/spoon/support/compiler/jdt/JDTTreeBuilder.java @@ -858,7 +858,8 @@ public boolean visit(ArrayReference arrayReference, BlockScope scope) { @Override public boolean visit(ArrayTypeReference arrayTypeReference, BlockScope scope) { - final CtTypeAccess typeAccess = factory.Code().createTypeAccess(references.buildTypeReference(arrayTypeReference, scope)); + CtTypeReference objectCtTypeReference = references.buildTypeReference(arrayTypeReference, scope); + final CtTypeAccess typeAccess = factory.Code().createTypeAccess(objectCtTypeReference); if (typeAccess.getAccessedType() instanceof CtArrayTypeReference) { ((CtArrayTypeReference) typeAccess.getAccessedType()).getArrayType().setAnnotations(this.references.buildTypeReference(arrayTypeReference, scope).getAnnotations()); } diff --git a/src/main/java/spoon/support/compiler/jdt/ReferenceBuilder.java b/src/main/java/spoon/support/compiler/jdt/ReferenceBuilder.java index b1641afa723..b0f43660dad 100644 --- a/src/main/java/spoon/support/compiler/jdt/ReferenceBuilder.java +++ b/src/main/java/spoon/support/compiler/jdt/ReferenceBuilder.java @@ -625,7 +625,13 @@ private CtTypeReference getTypeReference(String name) { } } } else if (Character.isUpperCase(name.charAt(0))) { - main = this.jdtTreeBuilder.getFactory().Core().createTypeReference(); + if (name.endsWith("[]")) { + main = this.jdtTreeBuilder.getFactory().Core().createArrayTypeReference(); + name = name.substring(0, name.length()-2); + ((CtArrayTypeReference) main).setComponentType(this.getTypeReference(name)); + } else { + main = this.jdtTreeBuilder.getFactory().Core().createTypeReference(); + } main.setSimpleName(name); final CtReference declaring = this.getDeclaringReferenceFromImports(name.toCharArray()); setPackageOrDeclaringType(main, declaring); diff --git a/src/test/java/spoon/test/prettyprinter/DefaultPrettyPrinterTest.java b/src/test/java/spoon/test/prettyprinter/DefaultPrettyPrinterTest.java index e3022748559..2f3176ea211 100644 --- a/src/test/java/spoon/test/prettyprinter/DefaultPrettyPrinterTest.java +++ b/src/test/java/spoon/test/prettyprinter/DefaultPrettyPrinterTest.java @@ -330,7 +330,7 @@ public void testIssue2130() { assertTrue(ctParameter.isVarArgs()); assertTrue(ctParameter.getType() instanceof CtArrayTypeReference); - //launcher.prettyprint(); + launcher.prettyprint(); } } From 731e2ecac76a174ea81a84831a653ff2dfc53dfd Mon Sep 17 00:00:00 2001 From: Simon Urli Date: Thu, 28 Jun 2018 13:18:13 +0200 Subject: [PATCH 4/4] Fix checkstyle --- src/main/java/spoon/support/compiler/jdt/ReferenceBuilder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/spoon/support/compiler/jdt/ReferenceBuilder.java b/src/main/java/spoon/support/compiler/jdt/ReferenceBuilder.java index b0f43660dad..a42d8f38a23 100644 --- a/src/main/java/spoon/support/compiler/jdt/ReferenceBuilder.java +++ b/src/main/java/spoon/support/compiler/jdt/ReferenceBuilder.java @@ -627,7 +627,7 @@ private CtTypeReference getTypeReference(String name) { } else if (Character.isUpperCase(name.charAt(0))) { if (name.endsWith("[]")) { main = this.jdtTreeBuilder.getFactory().Core().createArrayTypeReference(); - name = name.substring(0, name.length()-2); + name = name.substring(0, name.length() - 2); ((CtArrayTypeReference) main).setComponentType(this.getTypeReference(name)); } else { main = this.jdtTreeBuilder.getFactory().Core().createTypeReference();