|
36 | 36 | import sun.security.tools.JarSigner;
|
37 | 37 |
|
38 | 38 | import java.io.*;
|
| 39 | +import java.security.Permission; |
39 | 40 |
|
40 | 41 |
|
41 | 42 | class AndroidBuild extends JavaBuild {
|
@@ -304,7 +305,12 @@ private File signPackage(File projectFolder, String keyStorePassword) throws Exc
|
304 | 305 | };
|
305 | 306 |
|
306 | 307 | // TODO remove hardcoded tools.jar path from build.xml
|
307 |
| - JarSigner.main(args); |
| 308 | + |
| 309 | + SystemExitControl.forbidSystemExitCall(); |
| 310 | + try { |
| 311 | + JarSigner.main(args); |
| 312 | + } catch (SystemExitControl.ExitTrappedException ignored) { } |
| 313 | + SystemExitControl.enableSystemExitCall(); |
308 | 314 |
|
309 | 315 | if(verifySignedPackage(unsignedPackage)) {
|
310 | 316 | File signedPackage = new File(projectFolder, "bin/" + sketch.getName() + "-release-signed.apk");
|
@@ -907,3 +913,26 @@ public void cleanup() {
|
907 | 913 | tmpFolder.deleteOnExit();
|
908 | 914 | }
|
909 | 915 | }
|
| 916 | + |
| 917 | +// http://www.avanderw.co.za/preventing-calls-to-system-exit-in-java/ |
| 918 | +class SystemExitControl { |
| 919 | + |
| 920 | + public static class ExitTrappedException extends SecurityException { |
| 921 | + } |
| 922 | + |
| 923 | + public static void forbidSystemExitCall() { |
| 924 | + final SecurityManager securityManager = new SecurityManager() { |
| 925 | + @Override |
| 926 | + public void checkPermission(Permission permission) { |
| 927 | + if (permission.getName().contains("exitVM")) { |
| 928 | + throw new ExitTrappedException(); |
| 929 | + } |
| 930 | + } |
| 931 | + }; |
| 932 | + System.setSecurityManager(securityManager); |
| 933 | + } |
| 934 | + |
| 935 | + public static void enableSystemExitCall() { |
| 936 | + System.setSecurityManager(null); |
| 937 | + } |
| 938 | +} |
0 commit comments