From 34046cf12225c9c6e2933a1c1b2d9780c98543ee Mon Sep 17 00:00:00 2001 From: Alan Justino Date: Tue, 24 Dec 2013 18:05:37 -0200 Subject: [PATCH 01/46] AndroidManifest got some SL4A services --- .../alanjds/sl4acompat/DialogActivity.java | 71 ++++++ src/src/org/alanjds/sl4acompat/Script.java | 34 +++ .../alanjds/sl4acompat/ScriptActivity.java | 70 ++++++ .../alanjds/sl4acompat/ScriptApplication.java | 38 +++ .../org/alanjds/sl4acompat/ScriptService.java | 218 ++++++++++++++++++ src/templates/AndroidManifest.tmpl.xml | 15 ++ 6 files changed, 446 insertions(+) create mode 100644 src/src/org/alanjds/sl4acompat/DialogActivity.java create mode 100644 src/src/org/alanjds/sl4acompat/Script.java create mode 100644 src/src/org/alanjds/sl4acompat/ScriptActivity.java create mode 100644 src/src/org/alanjds/sl4acompat/ScriptApplication.java create mode 100644 src/src/org/alanjds/sl4acompat/ScriptService.java diff --git a/src/src/org/alanjds/sl4acompat/DialogActivity.java b/src/src/org/alanjds/sl4acompat/DialogActivity.java new file mode 100644 index 0000000000..1bb1a4defa --- /dev/null +++ b/src/src/org/alanjds/sl4acompat/DialogActivity.java @@ -0,0 +1,71 @@ +package com.dummy.fooforandroid; + +import android.app.Activity; +import android.app.AlertDialog; +import android.content.ComponentName; +import android.content.DialogInterface; +import android.content.Intent; +import android.content.pm.ActivityInfo; +import android.content.pm.ResolveInfo; +import android.net.Uri; +import android.os.Bundle; + +import com.googlecode.android_scripting.Constants; +import com.googlecode.android_scripting.FeaturedInterpreters; +import com.googlecode.android_scripting.Log; +import com.googlecode.android_scripting.interpreter.InterpreterConstants; + +import java.net.URL; +import java.util.List; + +public class DialogActivity extends Activity { + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + String scriptName = getIntent().getStringExtra(Constants.EXTRA_SCRIPT_PATH); + String interpreter = FeaturedInterpreters.getInterpreterNameForScript(scriptName); + + if (interpreter == null) { + Log.e("Cannot find interpreter for script " + scriptName); + finish(); + } + + final Intent activityIntent = new Intent(); + + Intent resolveIntent = new Intent(InterpreterConstants.ACTION_DISCOVER_INTERPRETERS); + resolveIntent.addCategory(Intent.CATEGORY_LAUNCHER); + resolveIntent.setType(InterpreterConstants.MIME + Script.getFileExtension(this)); + List resolveInfos = getPackageManager().queryIntentActivities(resolveIntent, 0); + + if (resolveInfos != null && resolveInfos.size() == 1) { + ActivityInfo info = resolveInfos.get(0).activityInfo; + activityIntent.setComponent(new ComponentName(info.packageName, info.name)); + activityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + } else { + final URL url = FeaturedInterpreters.getUrlForName(interpreter); + activityIntent.setAction(Intent.ACTION_VIEW); + activityIntent.setData(Uri.parse(url.toString())); + } + + AlertDialog.Builder dialog = new AlertDialog.Builder(this); + dialog.setTitle(String.format("%s is not installed.", interpreter)); + dialog.setMessage(String + .format("Do you want to download and install APK for %s ?", interpreter)); + + DialogInterface.OnClickListener buttonListener = new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + if (which == DialogInterface.BUTTON_POSITIVE) { + startActivity(activityIntent); + } + dialog.dismiss(); + finish(); + } + }; + dialog.setNegativeButton("No", buttonListener); + dialog.setPositiveButton("Yes", buttonListener); + dialog.show(); + } + +} diff --git a/src/src/org/alanjds/sl4acompat/Script.java b/src/src/org/alanjds/sl4acompat/Script.java new file mode 100644 index 0000000000..3b1c6ea66a --- /dev/null +++ b/src/src/org/alanjds/sl4acompat/Script.java @@ -0,0 +1,34 @@ +// Copyright 2010 Google Inc. All Rights Reserved. + +package com.dummy.fooforandroid; + +import android.content.Context; +import android.content.res.Resources; + +public class Script { + + public final static int ID = R.raw.script; + + public static String sFileName; + + public static String getFileName(Context context) { + if (sFileName == null) { + Resources resources = context.getResources(); + String name = resources.getText(ID).toString(); + sFileName = name.substring(name.lastIndexOf('/') + 1, name.length()); + } + return sFileName; + } + + public static String getFileExtension(Context context) { + if (sFileName == null) { + getFileName(context); + } + int dotIndex = sFileName.lastIndexOf('.'); + if (dotIndex == -1) { + return null; + } + return sFileName.substring(dotIndex); + } + +} diff --git a/src/src/org/alanjds/sl4acompat/ScriptActivity.java b/src/src/org/alanjds/sl4acompat/ScriptActivity.java new file mode 100644 index 0000000000..f4f130275d --- /dev/null +++ b/src/src/org/alanjds/sl4acompat/ScriptActivity.java @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2010 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package com.dummy.fooforandroid; + +import android.app.Activity; +import android.content.ComponentName; +import android.content.Context; +import android.content.Intent; +import android.content.ServiceConnection; +import android.os.Bundle; +import android.os.IBinder; + +import com.googlecode.android_scripting.Constants; +import com.googlecode.android_scripting.facade.ActivityResultFacade; +import com.googlecode.android_scripting.jsonrpc.RpcReceiverManager; + +/** + * @author Alexey Reznichenko (alexey.reznichenko@gmail.com) + */ +public class ScriptActivity extends Activity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + if (Constants.ACTION_LAUNCH_SCRIPT_FOR_RESULT.equals(getIntent().getAction())) { + setTheme(android.R.style.Theme_Dialog); + setContentView(R.layout.dialog); + ServiceConnection connection = new ServiceConnection() { + @Override + public void onServiceConnected(ComponentName name, IBinder service) { + ScriptService scriptService = ((ScriptService.LocalBinder) service).getService(); + try { + RpcReceiverManager manager = scriptService.getRpcReceiverManager(); + ActivityResultFacade resultFacade = manager.getReceiver(ActivityResultFacade.class); + resultFacade.setActivity(ScriptActivity.this); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } + + @Override + public void onServiceDisconnected(ComponentName name) { + // Ignore. + } + }; + bindService(new Intent(this, ScriptService.class), connection, Context.BIND_AUTO_CREATE); + startService(new Intent(this, ScriptService.class)); + } else { + ScriptApplication application = (ScriptApplication) getApplication(); + if (application.readyToStart()) { + startService(new Intent(this, ScriptService.class)); + } + finish(); + } + } +} diff --git a/src/src/org/alanjds/sl4acompat/ScriptApplication.java b/src/src/org/alanjds/sl4acompat/ScriptApplication.java new file mode 100644 index 0000000000..9f33199bb2 --- /dev/null +++ b/src/src/org/alanjds/sl4acompat/ScriptApplication.java @@ -0,0 +1,38 @@ +package com.dummy.fooforandroid; + +import com.googlecode.android_scripting.BaseApplication; +import com.googlecode.android_scripting.Log; +import com.googlecode.android_scripting.interpreter.InterpreterConfiguration; +import com.googlecode.android_scripting.interpreter.InterpreterConstants; +import com.googlecode.android_scripting.interpreter.InterpreterConfiguration.ConfigurationObserver; + +import java.util.concurrent.CountDownLatch; + +public class ScriptApplication extends BaseApplication implements ConfigurationObserver { + + private volatile boolean receivedConfigUpdate = false; + private final CountDownLatch mLatch = new CountDownLatch(1); + + @Override + public void onCreate() { + mConfiguration = new InterpreterConfiguration(this); + mConfiguration.registerObserver(this); + mConfiguration.startDiscovering(InterpreterConstants.MIME + Script.getFileExtension(this)); + } + + @Override + public void onConfigurationChanged() { + receivedConfigUpdate = true; + mLatch.countDown(); + } + + public boolean readyToStart() { + try { + mLatch.await(); + } catch (InterruptedException e) { + Log.e(e); + } + return receivedConfigUpdate; + } + +} diff --git a/src/src/org/alanjds/sl4acompat/ScriptService.java b/src/src/org/alanjds/sl4acompat/ScriptService.java new file mode 100644 index 0000000000..e2c2c62745 --- /dev/null +++ b/src/src/org/alanjds/sl4acompat/ScriptService.java @@ -0,0 +1,218 @@ +/* + * Copyright (C) 2010 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package com.dummy.fooforandroid; + +import android.app.Notification; +import android.app.PendingIntent; +import android.content.Intent; +import android.content.res.Resources; +import android.os.Binder; +import android.os.IBinder; + +import com.googlecode.android_scripting.AndroidProxy; +import com.googlecode.android_scripting.BaseApplication; +import com.googlecode.android_scripting.Constants; +import com.googlecode.android_scripting.FeaturedInterpreters; +import com.googlecode.android_scripting.FileUtils; +import com.googlecode.android_scripting.ForegroundService; +import com.googlecode.android_scripting.Log; +import com.googlecode.android_scripting.NotificationIdFactory; +import com.googlecode.android_scripting.ScriptLauncher; +import com.googlecode.android_scripting.interpreter.Interpreter; +import com.googlecode.android_scripting.interpreter.InterpreterConfiguration; +import com.googlecode.android_scripting.interpreter.InterpreterUtils; +import com.googlecode.android_scripting.interpreter.html.HtmlActivityTask; +import com.googlecode.android_scripting.interpreter.html.HtmlInterpreter; +import com.googlecode.android_scripting.jsonrpc.RpcReceiverManager; + +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStream; +import java.util.concurrent.CountDownLatch; + +/** + * A service that allows scripts and the RPC server to run in the background. + * + * @author Alexey Reznichenko (alexey.reznichenko@gmail.com) + * @author Manuel Naranjo (manuel@aircable.net) + */ +public class ScriptService extends ForegroundService { + private final static int NOTIFICATION_ID = NotificationIdFactory.create(); + private final CountDownLatch mLatch = new CountDownLatch(1); + private final IBinder mBinder; + + private InterpreterConfiguration mInterpreterConfiguration; + private RpcReceiverManager mFacadeManager; + private AndroidProxy mProxy; + + public class LocalBinder extends Binder { + public ScriptService getService() { + return ScriptService.this; + } + } + + public ScriptService() { + super(NOTIFICATION_ID); + mBinder = new LocalBinder(); + } + + @Override + public IBinder onBind(Intent intent) { + return mBinder; + } + + @Override + public void onCreate() { + super.onCreate(); + mInterpreterConfiguration = ((BaseApplication) getApplication()) + .getInterpreterConfiguration(); + } + + @Override + public void onStart(Intent intent, final int startId) { + super.onStart(intent, startId); + String fileName = Script.getFileName(this); + Interpreter interpreter = mInterpreterConfiguration + .getInterpreterForScript(fileName); + if (interpreter == null || !interpreter.isInstalled()) { + mLatch.countDown(); + if (FeaturedInterpreters.isSupported(fileName)) { + Intent i = new Intent(this, DialogActivity.class); + i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + i.putExtra(Constants.EXTRA_SCRIPT_PATH, fileName); + startActivity(i); + } else { + Log + .e(this, "Cannot find an interpreter for script " + + fileName); + } + stopSelf(startId); + return; + } + + // Copies script to internal memory. + fileName = InterpreterUtils.getInterpreterRoot(this).getAbsolutePath() + + "/" + fileName; + File script = new File(fileName); + // TODO(raaar): Check size here! + if (!script.exists()) { + script = FileUtils.copyFromStream(fileName, getResources() + .openRawResource(Script.ID)); + } + copyResourcesToLocal(); // Copy all resources + + if (Script.getFileExtension(this) + .equals(HtmlInterpreter.HTML_EXTENSION)) { + HtmlActivityTask htmlTask = ScriptLauncher.launchHtmlScript(script, + this, intent, mInterpreterConfiguration); + mFacadeManager = htmlTask.getRpcReceiverManager(); + mLatch.countDown(); + stopSelf(startId); + } else { + mProxy = new AndroidProxy(this, null, true); + mProxy.startLocal(); + mLatch.countDown(); + ScriptLauncher.launchScript(script, mInterpreterConfiguration, + mProxy, new Runnable() { + @Override + public void run() { + mProxy.shutdown(); + stopSelf(startId); + } + }); + } + } + + RpcReceiverManager getRpcReceiverManager() throws InterruptedException { + mLatch.await(); + if (mFacadeManager==null) { // Facade manage may not be available on startup. + mFacadeManager = mProxy.getRpcReceiverManagerFactory() + .getRpcReceiverManagers().get(0); + } + return mFacadeManager; + } + + @Override + protected Notification createNotification() { + Notification notification = + new Notification(R.drawable.script_logo_48, this.getString(R.string.loading), System.currentTimeMillis()); + // This contentIntent is a noop. + PendingIntent contentIntent = PendingIntent.getService(this, 0, new Intent(), 0); + notification.setLatestEventInfo(this, this.getString(R.string.app_name), this.getString(R.string.loading), contentIntent); + notification.flags = Notification.FLAG_AUTO_CANCEL; + return notification; + } + + private boolean needsToBeUpdated(String filename, InputStream content) { + File script = new File(filename); + FileInputStream fin; + Log.d("Checking if " + filename + " exists"); + + if (!script.exists()) { + Log.d("not found"); + return true; + } + + Log.d("Comparing file with content"); + try { + fin = new FileInputStream(filename); + int c; + while ((c = fin.read()) != -1) { + if (c != content.read()) { + Log.d("Something changed replacing"); + return true; + } + } + } catch (Exception e) { + Log.d("Something failed during comparing"); + Log.e(e); + return true; + } + Log.d("No need to update " + filename); + return false; + } + + private void copyResourcesToLocal() { + String name, sFileName; + InputStream content; + R.raw a = new R.raw(); + java.lang.reflect.Field[] t = R.raw.class.getFields(); + Resources resources = getResources(); + for (int i = 0; i < t.length; i++) { + try { + name = resources.getText(t[i].getInt(a)).toString(); + sFileName = name.substring(name.lastIndexOf('/') + 1, name + .length()); + content = getResources().openRawResource(t[i].getInt(a)); + + // Copies script to internal memory only if changes were made + sFileName = InterpreterUtils.getInterpreterRoot(this) + .getAbsolutePath() + + "/" + sFileName; + if (needsToBeUpdated(sFileName, content)) { + Log.d("Copying from stream " + sFileName); + content.reset(); + FileUtils.copyFromStream(sFileName, content); + } + FileUtils.chmod(new File(sFileName), 0755); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } +} diff --git a/src/templates/AndroidManifest.tmpl.xml b/src/templates/AndroidManifest.tmpl.xml index 1eafea4355..655a8734b7 100644 --- a/src/templates/AndroidManifest.tmpl.xml +++ b/src/templates/AndroidManifest.tmpl.xml @@ -70,6 +70,21 @@ android:process=":PythonService"/> {% endif %} + {% if sl4a %} + + + + + + + + {% endif %} + {% if args.billing_pubkey %} From 00a46f85ab063ca933cb7a5fe1b191ee58de801e Mon Sep 17 00:00:00 2001 From: Alan Justino Date: Tue, 24 Dec 2013 18:35:20 -0200 Subject: [PATCH 02/46] MinimalService added --- .../alanjds/sl4acompat/MinimalService.java | 219 ++++++++++++++++++ src/templates/AndroidManifest.tmpl.xml | 3 +- 2 files changed, 221 insertions(+), 1 deletion(-) create mode 100644 src/src/org/alanjds/sl4acompat/MinimalService.java diff --git a/src/src/org/alanjds/sl4acompat/MinimalService.java b/src/src/org/alanjds/sl4acompat/MinimalService.java new file mode 100644 index 0000000000..d9cdec70ad --- /dev/null +++ b/src/src/org/alanjds/sl4acompat/MinimalService.java @@ -0,0 +1,219 @@ +/* + * Copyright (C) 2014 Alan Justino + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package org.alanjds.sl4acompat; + +import android.app.Notification; +import android.app.PendingIntent; +import android.content.Intent; +//import android.content.res.Resources; +import android.os.Binder; +import android.os.IBinder; + +import com.googlecode.android_scripting.AndroidProxy; +//import com.googlecode.android_scripting.BaseApplication; +//import com.googlecode.android_scripting.Constants; +//import com.googlecode.android_scripting.FeaturedInterpreters; +//import com.googlecode.android_scripting.FileUtils; +import com.googlecode.android_scripting.ForegroundService; +import com.googlecode.android_scripting.Log; +import com.googlecode.android_scripting.NotificationIdFactory; +//import com.googlecode.android_scripting.ScriptLauncher; +//import com.googlecode.android_scripting.interpreter.Interpreter; +//import com.googlecode.android_scripting.interpreter.InterpreterConfiguration; +//import com.googlecode.android_scripting.interpreter.InterpreterUtils; +//import com.googlecode.android_scripting.interpreter.html.HtmlActivityTask; +//import com.googlecode.android_scripting.interpreter.html.HtmlInterpreter; +import com.googlecode.android_scripting.jsonrpc.RpcReceiverManager; + +import java.util.concurrent.CountDownLatch; + +/** + * A service that allows scripts and the RPC server to run in the background. + * + * @author Alexey Reznichenko (alexey.reznichenko@gmail.com) + * @author Manuel Naranjo (manuel@aircable.net) + * @author Alan Justino (alan.justino@yahoo.com.br) + */ +public class MinimalService extends ForegroundService { + private final static int NOTIFICATION_ID = NotificationIdFactory.create(); + private final CountDownLatch mLatch = new CountDownLatch(1); + private final IBinder mBinder; + + private InterpreterConfiguration mInterpreterConfiguration; + private RpcReceiverManager mFacadeManager; + private AndroidProxy mProxy; + + public class LocalBinder extends Binder { + public MinimalService getService() { + return MinimalService.this; + } + } + + public MinimalService() { + super(NOTIFICATION_ID); + mBinder = new LocalBinder(); + } + + @Override + public IBinder onBind(Intent intent) { + return mBinder; + } + + @Override + public void onCreate() { + super.onCreate(); + //mInterpreterConfiguration = ((BaseApplication) getApplication()) + // .getInterpreterConfiguration(); + } + + @Override + public void onStart(Intent intent, final int startId) { + super.onStart(intent, startId); + mProxy = new AndroidProxy(this, null, true); + mProxy.startLocal(); + mLatch.countDown(); + //String fileName = Script.getFileName(this); + //Interpreter interpreter = mInterpreterConfiguration + // .getInterpreterForScript(fileName); + //if (interpreter == null || !interpreter.isInstalled()) { + // mLatch.countDown(); + // if (FeaturedInterpreters.isSupported(fileName)) { + // Intent i = new Intent(this, DialogActivity.class); + // i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + // i.putExtra(Constants.EXTRA_SCRIPT_PATH, fileName); + // startActivity(i); + // } else { + // Log + // .e(this, "Cannot find an interpreter for script " + // + fileName); + // } + // stopSelf(startId); + // return; + //} + + //// Copies script to internal memory. + //fileName = InterpreterUtils.getInterpreterRoot(this).getAbsolutePath() + // + "/" + fileName; + //File script = new File(fileName); + //// TODO(raaar): Check size here! + //if (!script.exists()) { + // script = FileUtils.copyFromStream(fileName, getResources() + // .openRawResource(Script.ID)); + //} + //copyResourcesToLocal(); // Copy all resources + + //if (Script.getFileExtension(this) + // .equals(HtmlInterpreter.HTML_EXTENSION)) { + // HtmlActivityTask htmlTask = ScriptLauncher.launchHtmlScript(script, + // this, intent, mInterpreterConfiguration); + // mFacadeManager = htmlTask.getRpcReceiverManager(); + // mLatch.countDown(); + // stopSelf(startId); + //} else { + //mProxy = new AndroidProxy(this, null, true); + //mProxy.startLocal(); + //mLatch.countDown(); + //ScriptLauncher.launchScript(script, mInterpreterConfiguration, + // mProxy, new Runnable() { + // @Override + // public void run() { + // mProxy.shutdown(); + // stopSelf(startId); + // } + // }); + //} + } + + RpcReceiverManager getRpcReceiverManager() throws InterruptedException { + mLatch.await(); + if (mFacadeManager==null) { // Facade manage may not be available on startup. + mFacadeManager = mProxy.getRpcReceiverManagerFactory() + .getRpcReceiverManagers().get(0); + } + return mFacadeManager; + } + + //@Override + //protected Notification createNotification() { + // Notification notification = + // new Notification(R.drawable.script_logo_48, this.getString(R.string.loading), System.currentTimeMillis()); + // // This contentIntent is a noop. + // PendingIntent contentIntent = PendingIntent.getService(this, 0, new Intent(), 0); + // notification.setLatestEventInfo(this, this.getString(R.string.app_name), this.getString(R.string.loading), contentIntent); + // notification.flags = Notification.FLAG_AUTO_CANCEL; + // return notification; + //} + + //private boolean needsToBeUpdated(String filename, InputStream content) { + // File script = new File(filename); + // FileInputStream fin; + // Log.d("Checking if " + filename + " exists"); + // + // if (!script.exists()) { + // Log.d("not found"); + // return true; + // } + // + // Log.d("Comparing file with content"); + // try { + // fin = new FileInputStream(filename); + // int c; + // while ((c = fin.read()) != -1) { + // if (c != content.read()) { + // Log.d("Something changed replacing"); + // return true; + // } + // } + // } catch (Exception e) { + // Log.d("Something failed during comparing"); + // Log.e(e); + // return true; + // } + // Log.d("No need to update " + filename); + // return false; + //} + + //private void copyResourcesToLocal() { + // String name, sFileName; + // InputStream content; + // R.raw a = new R.raw(); + // java.lang.reflect.Field[] t = R.raw.class.getFields(); + // Resources resources = getResources(); + // for (int i = 0; i < t.length; i++) { + // try { + // name = resources.getText(t[i].getInt(a)).toString(); + // sFileName = name.substring(name.lastIndexOf('/') + 1, name + // .length()); + // content = getResources().openRawResource(t[i].getInt(a)); + // + // // Copies script to internal memory only if changes were made + // sFileName = InterpreterUtils.getInterpreterRoot(this) + // .getAbsolutePath() + // + "/" + sFileName; + // if (needsToBeUpdated(sFileName, content)) { + // Log.d("Copying from stream " + sFileName); + // content.reset(); + // FileUtils.copyFromStream(sFileName, content); + // } + // FileUtils.chmod(new File(sFileName), 0755); + // } catch (Exception e) { + // // TODO Auto-generated catch block + // e.printStackTrace(); + // } + // } + //} +} diff --git a/src/templates/AndroidManifest.tmpl.xml b/src/templates/AndroidManifest.tmpl.xml index 655a8734b7..45252b1b3a 100644 --- a/src/templates/AndroidManifest.tmpl.xml +++ b/src/templates/AndroidManifest.tmpl.xml @@ -71,7 +71,8 @@ {% endif %} {% if sl4a %} - + + From 852b5f7132c54fcb9fd4184c1e144b4dfda10519 Mon Sep 17 00:00:00 2001 From: Alan Justino Date: Tue, 24 Dec 2013 18:37:17 -0200 Subject: [PATCH 03/46] Forgot intent-filters from Google's APK script template --- src/templates/AndroidManifest.tmpl.xml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/templates/AndroidManifest.tmpl.xml b/src/templates/AndroidManifest.tmpl.xml index 45252b1b3a..46ece1c402 100644 --- a/src/templates/AndroidManifest.tmpl.xml +++ b/src/templates/AndroidManifest.tmpl.xml @@ -83,7 +83,12 @@ + android:theme="@android:style/Theme.Translucent.NoTitleBar"> + + + + + {% endif %} {% if args.billing_pubkey %} From 5f0dc28f4455bbf4087bcf2d13eb9303b78b604d Mon Sep 17 00:00:00 2001 From: Alan Justino Date: Tue, 24 Dec 2013 18:38:40 -0200 Subject: [PATCH 04/46] Proper attribution --- src/src/org/alanjds/sl4acompat/MinimalService.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/src/org/alanjds/sl4acompat/MinimalService.java b/src/src/org/alanjds/sl4acompat/MinimalService.java index d9cdec70ad..ab0e6b0f8a 100644 --- a/src/src/org/alanjds/sl4acompat/MinimalService.java +++ b/src/src/org/alanjds/sl4acompat/MinimalService.java @@ -1,4 +1,5 @@ /* + * Copyright (C) 2010 Google Inc. * Copyright (C) 2014 Alan Justino * * Licensed under the Apache License, Version 2.0 (the "License"); you may not From 4ce361c32d34dae4b0d42eb3385c85a1257a937f Mon Sep 17 00:00:00 2001 From: Alan Justino Date: Tue, 24 Dec 2013 18:41:07 -0200 Subject: [PATCH 05/46] MinimalService cleanup --- .../alanjds/sl4acompat/MinimalService.java | 122 ------------------ 1 file changed, 122 deletions(-) diff --git a/src/src/org/alanjds/sl4acompat/MinimalService.java b/src/src/org/alanjds/sl4acompat/MinimalService.java index ab0e6b0f8a..b4530c2b41 100644 --- a/src/src/org/alanjds/sl4acompat/MinimalService.java +++ b/src/src/org/alanjds/sl4acompat/MinimalService.java @@ -20,24 +20,13 @@ import android.app.Notification; import android.app.PendingIntent; import android.content.Intent; -//import android.content.res.Resources; import android.os.Binder; import android.os.IBinder; import com.googlecode.android_scripting.AndroidProxy; -//import com.googlecode.android_scripting.BaseApplication; -//import com.googlecode.android_scripting.Constants; -//import com.googlecode.android_scripting.FeaturedInterpreters; -//import com.googlecode.android_scripting.FileUtils; import com.googlecode.android_scripting.ForegroundService; import com.googlecode.android_scripting.Log; import com.googlecode.android_scripting.NotificationIdFactory; -//import com.googlecode.android_scripting.ScriptLauncher; -//import com.googlecode.android_scripting.interpreter.Interpreter; -//import com.googlecode.android_scripting.interpreter.InterpreterConfiguration; -//import com.googlecode.android_scripting.interpreter.InterpreterUtils; -//import com.googlecode.android_scripting.interpreter.html.HtmlActivityTask; -//import com.googlecode.android_scripting.interpreter.html.HtmlInterpreter; import com.googlecode.android_scripting.jsonrpc.RpcReceiverManager; import java.util.concurrent.CountDownLatch; @@ -77,8 +66,6 @@ public IBinder onBind(Intent intent) { @Override public void onCreate() { super.onCreate(); - //mInterpreterConfiguration = ((BaseApplication) getApplication()) - // .getInterpreterConfiguration(); } @Override @@ -87,56 +74,6 @@ public void onStart(Intent intent, final int startId) { mProxy = new AndroidProxy(this, null, true); mProxy.startLocal(); mLatch.countDown(); - //String fileName = Script.getFileName(this); - //Interpreter interpreter = mInterpreterConfiguration - // .getInterpreterForScript(fileName); - //if (interpreter == null || !interpreter.isInstalled()) { - // mLatch.countDown(); - // if (FeaturedInterpreters.isSupported(fileName)) { - // Intent i = new Intent(this, DialogActivity.class); - // i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - // i.putExtra(Constants.EXTRA_SCRIPT_PATH, fileName); - // startActivity(i); - // } else { - // Log - // .e(this, "Cannot find an interpreter for script " - // + fileName); - // } - // stopSelf(startId); - // return; - //} - - //// Copies script to internal memory. - //fileName = InterpreterUtils.getInterpreterRoot(this).getAbsolutePath() - // + "/" + fileName; - //File script = new File(fileName); - //// TODO(raaar): Check size here! - //if (!script.exists()) { - // script = FileUtils.copyFromStream(fileName, getResources() - // .openRawResource(Script.ID)); - //} - //copyResourcesToLocal(); // Copy all resources - - //if (Script.getFileExtension(this) - // .equals(HtmlInterpreter.HTML_EXTENSION)) { - // HtmlActivityTask htmlTask = ScriptLauncher.launchHtmlScript(script, - // this, intent, mInterpreterConfiguration); - // mFacadeManager = htmlTask.getRpcReceiverManager(); - // mLatch.countDown(); - // stopSelf(startId); - //} else { - //mProxy = new AndroidProxy(this, null, true); - //mProxy.startLocal(); - //mLatch.countDown(); - //ScriptLauncher.launchScript(script, mInterpreterConfiguration, - // mProxy, new Runnable() { - // @Override - // public void run() { - // mProxy.shutdown(); - // stopSelf(startId); - // } - // }); - //} } RpcReceiverManager getRpcReceiverManager() throws InterruptedException { @@ -158,63 +95,4 @@ RpcReceiverManager getRpcReceiverManager() throws InterruptedException { // notification.flags = Notification.FLAG_AUTO_CANCEL; // return notification; //} - - //private boolean needsToBeUpdated(String filename, InputStream content) { - // File script = new File(filename); - // FileInputStream fin; - // Log.d("Checking if " + filename + " exists"); - // - // if (!script.exists()) { - // Log.d("not found"); - // return true; - // } - // - // Log.d("Comparing file with content"); - // try { - // fin = new FileInputStream(filename); - // int c; - // while ((c = fin.read()) != -1) { - // if (c != content.read()) { - // Log.d("Something changed replacing"); - // return true; - // } - // } - // } catch (Exception e) { - // Log.d("Something failed during comparing"); - // Log.e(e); - // return true; - // } - // Log.d("No need to update " + filename); - // return false; - //} - - //private void copyResourcesToLocal() { - // String name, sFileName; - // InputStream content; - // R.raw a = new R.raw(); - // java.lang.reflect.Field[] t = R.raw.class.getFields(); - // Resources resources = getResources(); - // for (int i = 0; i < t.length; i++) { - // try { - // name = resources.getText(t[i].getInt(a)).toString(); - // sFileName = name.substring(name.lastIndexOf('/') + 1, name - // .length()); - // content = getResources().openRawResource(t[i].getInt(a)); - // - // // Copies script to internal memory only if changes were made - // sFileName = InterpreterUtils.getInterpreterRoot(this) - // .getAbsolutePath() - // + "/" + sFileName; - // if (needsToBeUpdated(sFileName, content)) { - // Log.d("Copying from stream " + sFileName); - // content.reset(); - // FileUtils.copyFromStream(sFileName, content); - // } - // FileUtils.chmod(new File(sFileName), 0755); - // } catch (Exception e) { - // // TODO Auto-generated catch block - // e.printStackTrace(); - // } - // } - //} } From c4e48c6e0ba676a80d5692a9d3277745c60b4cf1 Mon Sep 17 00:00:00 2001 From: Alan Justino Date: Thu, 26 Dec 2013 23:03:51 -0200 Subject: [PATCH 06/46] --sl4a option to build.py --- src/build.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/build.py b/src/build.py index 0915930a02..9f10f2f000 100755 --- a/src/build.py +++ b/src/build.py @@ -383,6 +383,8 @@ def make_package(args): ap.add_argument('--add-jar', dest='add_jar', action='append', help='Add a Java .jar to the libs, so you can access its classes with pyjnius. You can specify this argument more than once to include multiple jars') ap.add_argument('--meta-data', dest='meta_data', action='append', help='Custom key=value to add in application metadata') + ap.add_argument('--sl4a', dest='sl4a', action='store_true', + help='Provide this argument to include SL4A jars and RPC service into the app.') args = ap.parse_args() From 2c197c33c8b4cee9e201f9c485b83259e9836ebd Mon Sep 17 00:00:00 2001 From: Alan Justino Date: Thu, 26 Dec 2013 23:07:37 -0200 Subject: [PATCH 07/46] Renamed sl4a to sl4acompat --- src/build.py | 2 +- src/templates/AndroidManifest.tmpl.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/build.py b/src/build.py index 9f10f2f000..b92dcf8060 100755 --- a/src/build.py +++ b/src/build.py @@ -383,7 +383,7 @@ def make_package(args): ap.add_argument('--add-jar', dest='add_jar', action='append', help='Add a Java .jar to the libs, so you can access its classes with pyjnius. You can specify this argument more than once to include multiple jars') ap.add_argument('--meta-data', dest='meta_data', action='append', help='Custom key=value to add in application metadata') - ap.add_argument('--sl4a', dest='sl4a', action='store_true', + ap.add_argument('--sl4acompat', dest='sl4a', action='store_true', help='Provide this argument to include SL4A jars and RPC service into the app.') args = ap.parse_args() diff --git a/src/templates/AndroidManifest.tmpl.xml b/src/templates/AndroidManifest.tmpl.xml index 46ece1c402..99eff549e1 100644 --- a/src/templates/AndroidManifest.tmpl.xml +++ b/src/templates/AndroidManifest.tmpl.xml @@ -70,7 +70,7 @@ android:process=":PythonService"/> {% endif %} - {% if sl4a %} + {% if sl4acompat %} From 38dd4f2481e3467637ab4e40dbbcae1bb44c1140 Mon Sep 17 00:00:00 2001 From: Alan Justino Date: Thu, 26 Dec 2013 23:09:10 -0200 Subject: [PATCH 08/46] Minimal jar-copying recipe.sh --- recipes/sl4acompat/recipe.sh | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100755 recipes/sl4acompat/recipe.sh diff --git a/recipes/sl4acompat/recipe.sh b/recipes/sl4acompat/recipe.sh new file mode 100755 index 0000000000..0272a95cbc --- /dev/null +++ b/recipes/sl4acompat/recipe.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +URL_sl4acompat=https://github.com/damonkohler/sl4a/raw/dcfa832f80/android/script_for_android_template.zip +DEPS_sl4acompat=() +MD5_sl4acompat=eed6a34bdf63e57a94b3c61528b6a577 +BUILD_sl4acompat=$BUILD_PATH/sl4acompat/$(get_directory $URL_sl4acompat) +RECIPE_sl4acompat=$RECIPES_PATH/sl4acompat + +function prebuild_sl4acompat() { + true +} + +function shouldbuild_sl4acompat() { + true +} + +function build_sl4acompat() { + cd $BUILD_sl4acompat + cp -a libs/* $BUILD_PATH/libs/ +} + +function postbuild_sl4acompat() { + true +} From 18c6e7321c91e00b741ee7660a9237e2137dd89f Mon Sep 17 00:00:00 2001 From: Alan Justino Date: Fri, 27 Dec 2013 00:07:07 -0200 Subject: [PATCH 09/46] Clean libs/$ARCH folder from .jar files (dont ask.) --- distribute.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/distribute.sh b/distribute.sh index 3b898f6233..f34605d145 100755 --- a/distribute.sh +++ b/distribute.sh @@ -725,6 +725,7 @@ function run_distribute() { debug "Copy libs" try mkdir -p libs/$ARCH try cp -a $BUILD_PATH/libs/* libs/$ARCH/ + try rm "$DIST_PATH"/libs/$ARCH/*.jar || true debug "Copy java files from various libs" cp -a $BUILD_PATH/java/* src From 88a692d98f87b3f14e0e09005e16f2f20afa76d2 Mon Sep 17 00:00:00 2001 From: Alan Justino Date: Fri, 27 Dec 2013 00:08:28 -0200 Subject: [PATCH 10/46] Hack to copy pre-built jars via recipe --- recipes/sl4acompat/recipe.sh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/recipes/sl4acompat/recipe.sh b/recipes/sl4acompat/recipe.sh index 0272a95cbc..345ef73810 100755 --- a/recipes/sl4acompat/recipe.sh +++ b/recipes/sl4acompat/recipe.sh @@ -3,7 +3,7 @@ URL_sl4acompat=https://github.com/damonkohler/sl4a/raw/dcfa832f80/android/script_for_android_template.zip DEPS_sl4acompat=() MD5_sl4acompat=eed6a34bdf63e57a94b3c61528b6a577 -BUILD_sl4acompat=$BUILD_PATH/sl4acompat/$(get_directory $URL_sl4acompat) +BUILD_sl4acompat=$BUILD_PATH/sl4acompat/ RECIPE_sl4acompat=$RECIPES_PATH/sl4acompat function prebuild_sl4acompat() { @@ -15,10 +15,13 @@ function shouldbuild_sl4acompat() { } function build_sl4acompat() { - cd $BUILD_sl4acompat - cp -a libs/* $BUILD_PATH/libs/ + true } function postbuild_sl4acompat() { + cd $BUILD_sl4acompat + mkdir "$DIST_PATH"/libs + cp -av libs/* "$DIST_PATH"/libs/ + cd - true } From 1770e08a19b2e3d9f41efbfe2efed782af948ca1 Mon Sep 17 00:00:00 2001 From: Alan Justino Date: Fri, 27 Dec 2013 00:08:56 -0200 Subject: [PATCH 11/46] Fix ant build errors (hopefully) --- .../alanjds/sl4acompat/MinimalService.java | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/src/org/alanjds/sl4acompat/MinimalService.java b/src/src/org/alanjds/sl4acompat/MinimalService.java index b4530c2b41..6ccc6ee7c3 100644 --- a/src/src/org/alanjds/sl4acompat/MinimalService.java +++ b/src/src/org/alanjds/sl4acompat/MinimalService.java @@ -43,7 +43,7 @@ public class MinimalService extends ForegroundService { private final CountDownLatch mLatch = new CountDownLatch(1); private final IBinder mBinder; - private InterpreterConfiguration mInterpreterConfiguration; + //private InterpreterConfiguration mInterpreterConfiguration; private RpcReceiverManager mFacadeManager; private AndroidProxy mProxy; @@ -85,14 +85,14 @@ RpcReceiverManager getRpcReceiverManager() throws InterruptedException { return mFacadeManager; } - //@Override - //protected Notification createNotification() { - // Notification notification = - // new Notification(R.drawable.script_logo_48, this.getString(R.string.loading), System.currentTimeMillis()); - // // This contentIntent is a noop. - // PendingIntent contentIntent = PendingIntent.getService(this, 0, new Intent(), 0); - // notification.setLatestEventInfo(this, this.getString(R.string.app_name), this.getString(R.string.loading), contentIntent); - // notification.flags = Notification.FLAG_AUTO_CANCEL; - // return notification; - //} + @Override + protected Notification createNotification() { + Notification notification = + new Notification(R.drawable.script_logo_48, this.getString(R.string.loading), System.currentTimeMillis()); + // This contentIntent is a noop. + PendingIntent contentIntent = PendingIntent.getService(this, 0, new Intent(), 0); + notification.setLatestEventInfo(this, this.getString(R.string.app_name), this.getString(R.string.loading), contentIntent); + notification.flags = Notification.FLAG_AUTO_CANCEL; + return notification; + } } From 6bba82033e4d2be06843012e847586866795eded Mon Sep 17 00:00:00 2001 From: Alan Justino Date: Fri, 27 Dec 2013 00:11:08 -0200 Subject: [PATCH 12/46] Oops: forgot too much debug --- recipes/sl4acompat/recipe.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recipes/sl4acompat/recipe.sh b/recipes/sl4acompat/recipe.sh index 345ef73810..fabcd724de 100755 --- a/recipes/sl4acompat/recipe.sh +++ b/recipes/sl4acompat/recipe.sh @@ -21,7 +21,7 @@ function build_sl4acompat() { function postbuild_sl4acompat() { cd $BUILD_sl4acompat mkdir "$DIST_PATH"/libs - cp -av libs/* "$DIST_PATH"/libs/ + cp -a libs/* "$DIST_PATH"/libs/ cd - true } From be5c49beebab54817569a64f3ab4078435c401a4 Mon Sep 17 00:00:00 2001 From: Alan Justino Date: Fri, 27 Dec 2013 00:24:35 -0200 Subject: [PATCH 13/46] Fixed MinimalService again --- .../alanjds/sl4acompat/MinimalService.java | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/src/org/alanjds/sl4acompat/MinimalService.java b/src/src/org/alanjds/sl4acompat/MinimalService.java index 6ccc6ee7c3..fe8d1801a8 100644 --- a/src/src/org/alanjds/sl4acompat/MinimalService.java +++ b/src/src/org/alanjds/sl4acompat/MinimalService.java @@ -18,6 +18,7 @@ package org.alanjds.sl4acompat; import android.app.Notification; +import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Intent; import android.os.Binder; @@ -87,12 +88,19 @@ RpcReceiverManager getRpcReceiverManager() throws InterruptedException { @Override protected Notification createNotification() { - Notification notification = - new Notification(R.drawable.script_logo_48, this.getString(R.string.loading), System.currentTimeMillis()); - // This contentIntent is a noop. - PendingIntent contentIntent = PendingIntent.getService(this, 0, new Intent(), 0); - notification.setLatestEventInfo(this, this.getString(R.string.app_name), this.getString(R.string.loading), contentIntent); - notification.flags = Notification.FLAG_AUTO_CANCEL; + PendingIntent contentIntent = PendingIntent.getService(this, 0, new Intent(), 0); + // This contentIntent is a noop. + + Notification notification = new Notification.Builder(this) + .setContentTitle("SL4A Facade") + .setContentText("minimal SL4A facade running") + .setContentIntent(pIntent) + .build(); + + //NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); + notification.flags |= Notification.FLAG_AUTO_CANCEL; // hide the notification after its selected + + //notificationManager.notify(0, notification); return notification; } } From db9f92ccf24b5cd9a3aeb18103955f492b548ee2 Mon Sep 17 00:00:00 2001 From: Alan Justino Date: Fri, 27 Dec 2013 00:46:20 -0200 Subject: [PATCH 14/46] Replace ScriptService with MinimalService --- src/src/org/alanjds/sl4acompat/ScriptActivity.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/src/org/alanjds/sl4acompat/ScriptActivity.java b/src/src/org/alanjds/sl4acompat/ScriptActivity.java index f4f130275d..d9a85e34c0 100644 --- a/src/src/org/alanjds/sl4acompat/ScriptActivity.java +++ b/src/src/org/alanjds/sl4acompat/ScriptActivity.java @@ -14,7 +14,7 @@ * the License. */ -package com.dummy.fooforandroid; +package org.alanjds.sl4acompat; import android.app.Activity; import android.content.ComponentName; @@ -42,7 +42,7 @@ protected void onCreate(Bundle savedInstanceState) { ServiceConnection connection = new ServiceConnection() { @Override public void onServiceConnected(ComponentName name, IBinder service) { - ScriptService scriptService = ((ScriptService.LocalBinder) service).getService(); + MinimalService scriptService = ((MinimalService.LocalBinder) service).getService(); try { RpcReceiverManager manager = scriptService.getRpcReceiverManager(); ActivityResultFacade resultFacade = manager.getReceiver(ActivityResultFacade.class); @@ -57,12 +57,12 @@ public void onServiceDisconnected(ComponentName name) { // Ignore. } }; - bindService(new Intent(this, ScriptService.class), connection, Context.BIND_AUTO_CREATE); - startService(new Intent(this, ScriptService.class)); + bindService(new Intent(this, MinimalService.class), connection, Context.BIND_AUTO_CREATE); + startService(new Intent(this, MinimalService.class)); } else { ScriptApplication application = (ScriptApplication) getApplication(); if (application.readyToStart()) { - startService(new Intent(this, ScriptService.class)); + startService(new Intent(this, MinimalService.class)); } finish(); } From 47a9d9a68e2684413a9545c0df4cfce55b03ca5e Mon Sep 17 00:00:00 2001 From: Alan Justino Date: Fri, 27 Dec 2013 00:46:45 -0200 Subject: [PATCH 15/46] Able to build the MinimalService!! --- src/src/org/alanjds/sl4acompat/MinimalService.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/src/org/alanjds/sl4acompat/MinimalService.java b/src/src/org/alanjds/sl4acompat/MinimalService.java index fe8d1801a8..4aaa29ec6d 100644 --- a/src/src/org/alanjds/sl4acompat/MinimalService.java +++ b/src/src/org/alanjds/sl4acompat/MinimalService.java @@ -18,7 +18,6 @@ package org.alanjds.sl4acompat; import android.app.Notification; -import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Intent; import android.os.Binder; @@ -91,11 +90,11 @@ protected Notification createNotification() { PendingIntent contentIntent = PendingIntent.getService(this, 0, new Intent(), 0); // This contentIntent is a noop. - Notification notification = new Notification.Builder(this) - .setContentTitle("SL4A Facade") - .setContentText("minimal SL4A facade running") - .setContentIntent(pIntent) - .build(); + Notification notification = new Notification(); + //.setContentTitle("SL4A Facade") + //.setContentText("minimal SL4A facade running") + //.setContentIntent(contentIntent) + //.build(); //NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); notification.flags |= Notification.FLAG_AUTO_CANCEL; // hide the notification after its selected From 4c775106fb8d3688d6946a5c0b59f8d33966dd78 Mon Sep 17 00:00:00 2001 From: Alan Justino Date: Fri, 27 Dec 2013 00:54:51 -0200 Subject: [PATCH 16/46] Disable some stuff --- src/src/org/alanjds/sl4acompat/ScriptActivity.java | 2 +- src/src/org/alanjds/sl4acompat/ScriptApplication.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/src/org/alanjds/sl4acompat/ScriptActivity.java b/src/src/org/alanjds/sl4acompat/ScriptActivity.java index d9a85e34c0..7ac74e0233 100644 --- a/src/src/org/alanjds/sl4acompat/ScriptActivity.java +++ b/src/src/org/alanjds/sl4acompat/ScriptActivity.java @@ -38,7 +38,7 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (Constants.ACTION_LAUNCH_SCRIPT_FOR_RESULT.equals(getIntent().getAction())) { setTheme(android.R.style.Theme_Dialog); - setContentView(R.layout.dialog); + //setContentView(R.layout.dialog); ServiceConnection connection = new ServiceConnection() { @Override public void onServiceConnected(ComponentName name, IBinder service) { diff --git a/src/src/org/alanjds/sl4acompat/ScriptApplication.java b/src/src/org/alanjds/sl4acompat/ScriptApplication.java index 9f33199bb2..a645918505 100644 --- a/src/src/org/alanjds/sl4acompat/ScriptApplication.java +++ b/src/src/org/alanjds/sl4acompat/ScriptApplication.java @@ -17,7 +17,7 @@ public class ScriptApplication extends BaseApplication implements ConfigurationO public void onCreate() { mConfiguration = new InterpreterConfiguration(this); mConfiguration.registerObserver(this); - mConfiguration.startDiscovering(InterpreterConstants.MIME + Script.getFileExtension(this)); + //mConfiguration.startDiscovering(InterpreterConstants.MIME + Script.getFileExtension(this)); } @Override From eca29e4e669ac793a79bdcabe704c11a777b4262 Mon Sep 17 00:00:00 2001 From: Alan Justino Date: Fri, 27 Dec 2013 01:02:21 -0200 Subject: [PATCH 17/46] Cleanup unused .java files --- .../alanjds/sl4acompat/DialogActivity.java | 71 ------ src/src/org/alanjds/sl4acompat/Script.java | 34 --- .../alanjds/sl4acompat/ScriptApplication.java | 38 --- .../org/alanjds/sl4acompat/ScriptService.java | 218 ------------------ 4 files changed, 361 deletions(-) delete mode 100644 src/src/org/alanjds/sl4acompat/DialogActivity.java delete mode 100644 src/src/org/alanjds/sl4acompat/Script.java delete mode 100644 src/src/org/alanjds/sl4acompat/ScriptApplication.java delete mode 100644 src/src/org/alanjds/sl4acompat/ScriptService.java diff --git a/src/src/org/alanjds/sl4acompat/DialogActivity.java b/src/src/org/alanjds/sl4acompat/DialogActivity.java deleted file mode 100644 index 1bb1a4defa..0000000000 --- a/src/src/org/alanjds/sl4acompat/DialogActivity.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.dummy.fooforandroid; - -import android.app.Activity; -import android.app.AlertDialog; -import android.content.ComponentName; -import android.content.DialogInterface; -import android.content.Intent; -import android.content.pm.ActivityInfo; -import android.content.pm.ResolveInfo; -import android.net.Uri; -import android.os.Bundle; - -import com.googlecode.android_scripting.Constants; -import com.googlecode.android_scripting.FeaturedInterpreters; -import com.googlecode.android_scripting.Log; -import com.googlecode.android_scripting.interpreter.InterpreterConstants; - -import java.net.URL; -import java.util.List; - -public class DialogActivity extends Activity { - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - String scriptName = getIntent().getStringExtra(Constants.EXTRA_SCRIPT_PATH); - String interpreter = FeaturedInterpreters.getInterpreterNameForScript(scriptName); - - if (interpreter == null) { - Log.e("Cannot find interpreter for script " + scriptName); - finish(); - } - - final Intent activityIntent = new Intent(); - - Intent resolveIntent = new Intent(InterpreterConstants.ACTION_DISCOVER_INTERPRETERS); - resolveIntent.addCategory(Intent.CATEGORY_LAUNCHER); - resolveIntent.setType(InterpreterConstants.MIME + Script.getFileExtension(this)); - List resolveInfos = getPackageManager().queryIntentActivities(resolveIntent, 0); - - if (resolveInfos != null && resolveInfos.size() == 1) { - ActivityInfo info = resolveInfos.get(0).activityInfo; - activityIntent.setComponent(new ComponentName(info.packageName, info.name)); - activityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - } else { - final URL url = FeaturedInterpreters.getUrlForName(interpreter); - activityIntent.setAction(Intent.ACTION_VIEW); - activityIntent.setData(Uri.parse(url.toString())); - } - - AlertDialog.Builder dialog = new AlertDialog.Builder(this); - dialog.setTitle(String.format("%s is not installed.", interpreter)); - dialog.setMessage(String - .format("Do you want to download and install APK for %s ?", interpreter)); - - DialogInterface.OnClickListener buttonListener = new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - if (which == DialogInterface.BUTTON_POSITIVE) { - startActivity(activityIntent); - } - dialog.dismiss(); - finish(); - } - }; - dialog.setNegativeButton("No", buttonListener); - dialog.setPositiveButton("Yes", buttonListener); - dialog.show(); - } - -} diff --git a/src/src/org/alanjds/sl4acompat/Script.java b/src/src/org/alanjds/sl4acompat/Script.java deleted file mode 100644 index 3b1c6ea66a..0000000000 --- a/src/src/org/alanjds/sl4acompat/Script.java +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2010 Google Inc. All Rights Reserved. - -package com.dummy.fooforandroid; - -import android.content.Context; -import android.content.res.Resources; - -public class Script { - - public final static int ID = R.raw.script; - - public static String sFileName; - - public static String getFileName(Context context) { - if (sFileName == null) { - Resources resources = context.getResources(); - String name = resources.getText(ID).toString(); - sFileName = name.substring(name.lastIndexOf('/') + 1, name.length()); - } - return sFileName; - } - - public static String getFileExtension(Context context) { - if (sFileName == null) { - getFileName(context); - } - int dotIndex = sFileName.lastIndexOf('.'); - if (dotIndex == -1) { - return null; - } - return sFileName.substring(dotIndex); - } - -} diff --git a/src/src/org/alanjds/sl4acompat/ScriptApplication.java b/src/src/org/alanjds/sl4acompat/ScriptApplication.java deleted file mode 100644 index a645918505..0000000000 --- a/src/src/org/alanjds/sl4acompat/ScriptApplication.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.dummy.fooforandroid; - -import com.googlecode.android_scripting.BaseApplication; -import com.googlecode.android_scripting.Log; -import com.googlecode.android_scripting.interpreter.InterpreterConfiguration; -import com.googlecode.android_scripting.interpreter.InterpreterConstants; -import com.googlecode.android_scripting.interpreter.InterpreterConfiguration.ConfigurationObserver; - -import java.util.concurrent.CountDownLatch; - -public class ScriptApplication extends BaseApplication implements ConfigurationObserver { - - private volatile boolean receivedConfigUpdate = false; - private final CountDownLatch mLatch = new CountDownLatch(1); - - @Override - public void onCreate() { - mConfiguration = new InterpreterConfiguration(this); - mConfiguration.registerObserver(this); - //mConfiguration.startDiscovering(InterpreterConstants.MIME + Script.getFileExtension(this)); - } - - @Override - public void onConfigurationChanged() { - receivedConfigUpdate = true; - mLatch.countDown(); - } - - public boolean readyToStart() { - try { - mLatch.await(); - } catch (InterruptedException e) { - Log.e(e); - } - return receivedConfigUpdate; - } - -} diff --git a/src/src/org/alanjds/sl4acompat/ScriptService.java b/src/src/org/alanjds/sl4acompat/ScriptService.java deleted file mode 100644 index e2c2c62745..0000000000 --- a/src/src/org/alanjds/sl4acompat/ScriptService.java +++ /dev/null @@ -1,218 +0,0 @@ -/* - * Copyright (C) 2010 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -package com.dummy.fooforandroid; - -import android.app.Notification; -import android.app.PendingIntent; -import android.content.Intent; -import android.content.res.Resources; -import android.os.Binder; -import android.os.IBinder; - -import com.googlecode.android_scripting.AndroidProxy; -import com.googlecode.android_scripting.BaseApplication; -import com.googlecode.android_scripting.Constants; -import com.googlecode.android_scripting.FeaturedInterpreters; -import com.googlecode.android_scripting.FileUtils; -import com.googlecode.android_scripting.ForegroundService; -import com.googlecode.android_scripting.Log; -import com.googlecode.android_scripting.NotificationIdFactory; -import com.googlecode.android_scripting.ScriptLauncher; -import com.googlecode.android_scripting.interpreter.Interpreter; -import com.googlecode.android_scripting.interpreter.InterpreterConfiguration; -import com.googlecode.android_scripting.interpreter.InterpreterUtils; -import com.googlecode.android_scripting.interpreter.html.HtmlActivityTask; -import com.googlecode.android_scripting.interpreter.html.HtmlInterpreter; -import com.googlecode.android_scripting.jsonrpc.RpcReceiverManager; - -import java.io.File; -import java.io.FileInputStream; -import java.io.InputStream; -import java.util.concurrent.CountDownLatch; - -/** - * A service that allows scripts and the RPC server to run in the background. - * - * @author Alexey Reznichenko (alexey.reznichenko@gmail.com) - * @author Manuel Naranjo (manuel@aircable.net) - */ -public class ScriptService extends ForegroundService { - private final static int NOTIFICATION_ID = NotificationIdFactory.create(); - private final CountDownLatch mLatch = new CountDownLatch(1); - private final IBinder mBinder; - - private InterpreterConfiguration mInterpreterConfiguration; - private RpcReceiverManager mFacadeManager; - private AndroidProxy mProxy; - - public class LocalBinder extends Binder { - public ScriptService getService() { - return ScriptService.this; - } - } - - public ScriptService() { - super(NOTIFICATION_ID); - mBinder = new LocalBinder(); - } - - @Override - public IBinder onBind(Intent intent) { - return mBinder; - } - - @Override - public void onCreate() { - super.onCreate(); - mInterpreterConfiguration = ((BaseApplication) getApplication()) - .getInterpreterConfiguration(); - } - - @Override - public void onStart(Intent intent, final int startId) { - super.onStart(intent, startId); - String fileName = Script.getFileName(this); - Interpreter interpreter = mInterpreterConfiguration - .getInterpreterForScript(fileName); - if (interpreter == null || !interpreter.isInstalled()) { - mLatch.countDown(); - if (FeaturedInterpreters.isSupported(fileName)) { - Intent i = new Intent(this, DialogActivity.class); - i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - i.putExtra(Constants.EXTRA_SCRIPT_PATH, fileName); - startActivity(i); - } else { - Log - .e(this, "Cannot find an interpreter for script " - + fileName); - } - stopSelf(startId); - return; - } - - // Copies script to internal memory. - fileName = InterpreterUtils.getInterpreterRoot(this).getAbsolutePath() - + "/" + fileName; - File script = new File(fileName); - // TODO(raaar): Check size here! - if (!script.exists()) { - script = FileUtils.copyFromStream(fileName, getResources() - .openRawResource(Script.ID)); - } - copyResourcesToLocal(); // Copy all resources - - if (Script.getFileExtension(this) - .equals(HtmlInterpreter.HTML_EXTENSION)) { - HtmlActivityTask htmlTask = ScriptLauncher.launchHtmlScript(script, - this, intent, mInterpreterConfiguration); - mFacadeManager = htmlTask.getRpcReceiverManager(); - mLatch.countDown(); - stopSelf(startId); - } else { - mProxy = new AndroidProxy(this, null, true); - mProxy.startLocal(); - mLatch.countDown(); - ScriptLauncher.launchScript(script, mInterpreterConfiguration, - mProxy, new Runnable() { - @Override - public void run() { - mProxy.shutdown(); - stopSelf(startId); - } - }); - } - } - - RpcReceiverManager getRpcReceiverManager() throws InterruptedException { - mLatch.await(); - if (mFacadeManager==null) { // Facade manage may not be available on startup. - mFacadeManager = mProxy.getRpcReceiverManagerFactory() - .getRpcReceiverManagers().get(0); - } - return mFacadeManager; - } - - @Override - protected Notification createNotification() { - Notification notification = - new Notification(R.drawable.script_logo_48, this.getString(R.string.loading), System.currentTimeMillis()); - // This contentIntent is a noop. - PendingIntent contentIntent = PendingIntent.getService(this, 0, new Intent(), 0); - notification.setLatestEventInfo(this, this.getString(R.string.app_name), this.getString(R.string.loading), contentIntent); - notification.flags = Notification.FLAG_AUTO_CANCEL; - return notification; - } - - private boolean needsToBeUpdated(String filename, InputStream content) { - File script = new File(filename); - FileInputStream fin; - Log.d("Checking if " + filename + " exists"); - - if (!script.exists()) { - Log.d("not found"); - return true; - } - - Log.d("Comparing file with content"); - try { - fin = new FileInputStream(filename); - int c; - while ((c = fin.read()) != -1) { - if (c != content.read()) { - Log.d("Something changed replacing"); - return true; - } - } - } catch (Exception e) { - Log.d("Something failed during comparing"); - Log.e(e); - return true; - } - Log.d("No need to update " + filename); - return false; - } - - private void copyResourcesToLocal() { - String name, sFileName; - InputStream content; - R.raw a = new R.raw(); - java.lang.reflect.Field[] t = R.raw.class.getFields(); - Resources resources = getResources(); - for (int i = 0; i < t.length; i++) { - try { - name = resources.getText(t[i].getInt(a)).toString(); - sFileName = name.substring(name.lastIndexOf('/') + 1, name - .length()); - content = getResources().openRawResource(t[i].getInt(a)); - - // Copies script to internal memory only if changes were made - sFileName = InterpreterUtils.getInterpreterRoot(this) - .getAbsolutePath() - + "/" + sFileName; - if (needsToBeUpdated(sFileName, content)) { - Log.d("Copying from stream " + sFileName); - content.reset(); - FileUtils.copyFromStream(sFileName, content); - } - FileUtils.chmod(new File(sFileName), 0755); - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - } -} From 1585b27e6099219fe93b046889d2b476704ba8fd Mon Sep 17 00:00:00 2001 From: Alan Justino Date: Fri, 27 Dec 2013 01:05:59 -0200 Subject: [PATCH 18/46] Oops: forgot to remove references to ScriptApplication --- src/src/org/alanjds/sl4acompat/ScriptActivity.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/src/org/alanjds/sl4acompat/ScriptActivity.java b/src/src/org/alanjds/sl4acompat/ScriptActivity.java index 7ac74e0233..2d40b67af2 100644 --- a/src/src/org/alanjds/sl4acompat/ScriptActivity.java +++ b/src/src/org/alanjds/sl4acompat/ScriptActivity.java @@ -60,10 +60,10 @@ public void onServiceDisconnected(ComponentName name) { bindService(new Intent(this, MinimalService.class), connection, Context.BIND_AUTO_CREATE); startService(new Intent(this, MinimalService.class)); } else { - ScriptApplication application = (ScriptApplication) getApplication(); - if (application.readyToStart()) { + //ScriptApplication application = (ScriptApplication) getApplication(); + //if (application.readyToStart()) { startService(new Intent(this, MinimalService.class)); - } + //} finish(); } } From 520c7ed455fe5b9b995e7f79b8ae1a7dbaa2713b Mon Sep 17 00:00:00 2001 From: Alan Justino Date: Fri, 27 Dec 2013 03:14:47 -0200 Subject: [PATCH 19/46] Disable some activity --- src/templates/AndroidManifest.tmpl.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/templates/AndroidManifest.tmpl.xml b/src/templates/AndroidManifest.tmpl.xml index 99eff549e1..7b8e75d112 100644 --- a/src/templates/AndroidManifest.tmpl.xml +++ b/src/templates/AndroidManifest.tmpl.xml @@ -77,9 +77,9 @@ - + android:theme="@android:style/Theme.Translucent.NoTitleBar" />--> Date: Fri, 27 Dec 2013 03:15:27 -0200 Subject: [PATCH 20/46] intent-filter to allow start MinimalService with ease --- src/templates/AndroidManifest.tmpl.xml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/templates/AndroidManifest.tmpl.xml b/src/templates/AndroidManifest.tmpl.xml index 7b8e75d112..34b3f2a04e 100644 --- a/src/templates/AndroidManifest.tmpl.xml +++ b/src/templates/AndroidManifest.tmpl.xml @@ -72,7 +72,12 @@ {% if sl4acompat %} - + + + + + From 199f60d7c01ee50073d654cad7b5ec7f73e253c2 Mon Sep 17 00:00:00 2001 From: Alan Justino Date: Fri, 27 Dec 2013 03:48:21 -0200 Subject: [PATCH 21/46] MinimalServiceStarter to start MinimalService --- .../alanjds/sl4acompat/MinimalServiceStarter.java | 14 ++++++++++++++ src/templates/AndroidManifest.tmpl.xml | 6 +++--- 2 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 src/src/org/alanjds/sl4acompat/MinimalServiceStarter.java diff --git a/src/src/org/alanjds/sl4acompat/MinimalServiceStarter.java b/src/src/org/alanjds/sl4acompat/MinimalServiceStarter.java new file mode 100644 index 0000000000..08ea3e30ad --- /dev/null +++ b/src/src/org/alanjds/sl4acompat/MinimalServiceStarter.java @@ -0,0 +1,14 @@ +package org.alanjds.sl4acompat; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; + +public class MinimalServiceStarter extends BroadcastReceiver { + + @Override + public void onReceive(Context context, Intent intent) { + Intent service = new Intent(context, MinimalService.class); + context.startService(service); + } +} \ No newline at end of file diff --git a/src/templates/AndroidManifest.tmpl.xml b/src/templates/AndroidManifest.tmpl.xml index 34b3f2a04e..82955b803a 100644 --- a/src/templates/AndroidManifest.tmpl.xml +++ b/src/templates/AndroidManifest.tmpl.xml @@ -72,12 +72,12 @@ {% if sl4acompat %} - + + - + From 34ef8383a31122cfca46d9eca6e190b3a1f1429d Mon Sep 17 00:00:00 2001 From: Alan Justino Date: Fri, 27 Dec 2013 04:14:42 -0200 Subject: [PATCH 22/46] Try once again --- .../org/alanjds/sl4acompat/MinimalServiceStarter.java | 9 +++++++-- src/templates/AndroidManifest.tmpl.xml | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/src/org/alanjds/sl4acompat/MinimalServiceStarter.java b/src/src/org/alanjds/sl4acompat/MinimalServiceStarter.java index 08ea3e30ad..df7c803bbc 100644 --- a/src/src/org/alanjds/sl4acompat/MinimalServiceStarter.java +++ b/src/src/org/alanjds/sl4acompat/MinimalServiceStarter.java @@ -1,14 +1,19 @@ package org.alanjds.sl4acompat; +import com.googlecode.android_scripting.Log; + import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; + public class MinimalServiceStarter extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { - Intent service = new Intent(context, MinimalService.class); - context.startService(service); + Log.v('Received intent!') + Intent serviceIntent = new Intent(context, MinimalService.class); + context.startService(serviceIntent); + Log.v('Service started?') } } \ No newline at end of file diff --git a/src/templates/AndroidManifest.tmpl.xml b/src/templates/AndroidManifest.tmpl.xml index 82955b803a..70cb91c009 100644 --- a/src/templates/AndroidManifest.tmpl.xml +++ b/src/templates/AndroidManifest.tmpl.xml @@ -72,8 +72,8 @@ {% if sl4acompat %} - - + + From 5a6fa9e9300ffd30f6a83904bf63b738b6a8ad0c Mon Sep 17 00:00:00 2001 From: Alan Justino Date: Fri, 27 Dec 2013 04:16:49 -0200 Subject: [PATCH 23/46] Oops --- src/src/org/alanjds/sl4acompat/MinimalServiceStarter.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/src/org/alanjds/sl4acompat/MinimalServiceStarter.java b/src/src/org/alanjds/sl4acompat/MinimalServiceStarter.java index df7c803bbc..555130387f 100644 --- a/src/src/org/alanjds/sl4acompat/MinimalServiceStarter.java +++ b/src/src/org/alanjds/sl4acompat/MinimalServiceStarter.java @@ -11,9 +11,9 @@ public class MinimalServiceStarter extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { - Log.v('Received intent!') + Log.v("Received intent!"); Intent serviceIntent = new Intent(context, MinimalService.class); context.startService(serviceIntent); - Log.v('Service started?') + Log.v("Service started?"); } } \ No newline at end of file From 7fd415c71b67fdd39b39e58580fea2eded8d64f7 Mon Sep 17 00:00:00 2001 From: Alan Justino Date: Fri, 27 Dec 2013 10:25:59 -0200 Subject: [PATCH 24/46] Seems to need a category.. --- src/templates/AndroidManifest.tmpl.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/templates/AndroidManifest.tmpl.xml b/src/templates/AndroidManifest.tmpl.xml index 70cb91c009..883b92f45b 100644 --- a/src/templates/AndroidManifest.tmpl.xml +++ b/src/templates/AndroidManifest.tmpl.xml @@ -76,6 +76,7 @@ + From 3301ec503ad26488e19af76b92e77f89ed27411f Mon Sep 17 00:00:00 2001 From: Alan Justino Date: Fri, 27 Dec 2013 15:09:01 -0200 Subject: [PATCH 25/46] Oops. Stupid hours spent. --- src/build.py | 2 +- src/templates/AndroidManifest.tmpl.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/build.py b/src/build.py index b92dcf8060..add0aa7e4f 100755 --- a/src/build.py +++ b/src/build.py @@ -383,7 +383,7 @@ def make_package(args): ap.add_argument('--add-jar', dest='add_jar', action='append', help='Add a Java .jar to the libs, so you can access its classes with pyjnius. You can specify this argument more than once to include multiple jars') ap.add_argument('--meta-data', dest='meta_data', action='append', help='Custom key=value to add in application metadata') - ap.add_argument('--sl4acompat', dest='sl4a', action='store_true', + ap.add_argument('--sl4acompat', dest='sl4acompat', action='store_true', help='Provide this argument to include SL4A jars and RPC service into the app.') args = ap.parse_args() diff --git a/src/templates/AndroidManifest.tmpl.xml b/src/templates/AndroidManifest.tmpl.xml index 883b92f45b..11cb143e98 100644 --- a/src/templates/AndroidManifest.tmpl.xml +++ b/src/templates/AndroidManifest.tmpl.xml @@ -70,7 +70,7 @@ android:process=":PythonService"/> {% endif %} - {% if sl4acompat %} + {% if args.sl4acompat %} From 850ce97d4c48acb9be883b3af5bacecc38785de2 Mon Sep 17 00:00:00 2001 From: Alan Justino Date: Fri, 27 Dec 2013 23:24:00 -0200 Subject: [PATCH 26/46] [WIP] Logs on MinimalService started AndroidProxy? --- src/src/org/alanjds/sl4acompat/MinimalService.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/src/org/alanjds/sl4acompat/MinimalService.java b/src/src/org/alanjds/sl4acompat/MinimalService.java index 4aaa29ec6d..44fac5662a 100644 --- a/src/src/org/alanjds/sl4acompat/MinimalService.java +++ b/src/src/org/alanjds/sl4acompat/MinimalService.java @@ -72,7 +72,9 @@ public void onCreate() { public void onStart(Intent intent, final int startId) { super.onStart(intent, startId); mProxy = new AndroidProxy(this, null, true); + Log.v('Starting AndroidProxy'); mProxy.startLocal(); + Log.v(String.format("AndroidProxy at: %s @ %s[%s]", mProxy.getSecret(), mProxy.getAddress(), mProxy.getAddress.getPort())) mLatch.countDown(); } From ad030b2902b9e7fdb26817f43d7113ac60404f62 Mon Sep 17 00:00:00 2001 From: Alan Justino Date: Sat, 28 Dec 2013 13:02:12 -0200 Subject: [PATCH 27/46] Pass back the netaddress after AndroidProxy created --- .../org/alanjds/sl4acompat/MinimalService.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/src/org/alanjds/sl4acompat/MinimalService.java b/src/src/org/alanjds/sl4acompat/MinimalService.java index 44fac5662a..a60fa5e403 100644 --- a/src/src/org/alanjds/sl4acompat/MinimalService.java +++ b/src/src/org/alanjds/sl4acompat/MinimalService.java @@ -70,11 +70,24 @@ public void onCreate() { @Override public void onStart(Intent intent, final int startId) { + Log.v('Starting MinimalService'); super.onStart(intent, startId); - mProxy = new AndroidProxy(this, null, true); + Log.v('Starting AndroidProxy'); + mProxy = new AndroidProxy(this, intent, true); mProxy.startLocal(); - Log.v(String.format("AndroidProxy at: %s @ %s[%s]", mProxy.getSecret(), mProxy.getAddress(), mProxy.getAddress.getPort())) + + String host = mProxy.getAddress().getAddress(); + String port = mProxy.getAddress().getPort().toString(); + String handshake = mProxy.getSecret(); + Log.v(String.format("AndroidProxy at: %s @ %s:%s", handshake, host, port)); + + Intent netaddress = new Intent(this, "org.alanjds.sl4acompat.STORE_RPC_NETADDRESS"); + netaddress.putExtra("host", host); + netaddress.putExtra("port", port); + netaddress.putExtra("handshake", handshake); + sendBroadcast(netaddress); + mLatch.countDown(); } From 799ad19ddaab7439422107c28d2c83e0fb4390bd Mon Sep 17 00:00:00 2001 From: Alan Justino Date: Sat, 28 Dec 2013 13:06:49 -0200 Subject: [PATCH 28/46] Oops: ' -> " --- src/src/org/alanjds/sl4acompat/MinimalService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/src/org/alanjds/sl4acompat/MinimalService.java b/src/src/org/alanjds/sl4acompat/MinimalService.java index a60fa5e403..f3071e0395 100644 --- a/src/src/org/alanjds/sl4acompat/MinimalService.java +++ b/src/src/org/alanjds/sl4acompat/MinimalService.java @@ -70,10 +70,10 @@ public void onCreate() { @Override public void onStart(Intent intent, final int startId) { - Log.v('Starting MinimalService'); + Log.v("Starting MinimalService"); super.onStart(intent, startId); - Log.v('Starting AndroidProxy'); + Log.v("Starting AndroidProxy"); mProxy = new AndroidProxy(this, intent, true); mProxy.startLocal(); From 4d2559c0808aaea5e118bdc57f9a22b6a29fc2b5 Mon Sep 17 00:00:00 2001 From: Alan Justino Date: Sat, 28 Dec 2013 13:21:31 -0200 Subject: [PATCH 29/46] Bugfixes --- src/src/org/alanjds/sl4acompat/MinimalService.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/src/org/alanjds/sl4acompat/MinimalService.java b/src/src/org/alanjds/sl4acompat/MinimalService.java index f3071e0395..ade69f4c16 100644 --- a/src/src/org/alanjds/sl4acompat/MinimalService.java +++ b/src/src/org/alanjds/sl4acompat/MinimalService.java @@ -29,6 +29,7 @@ import com.googlecode.android_scripting.NotificationIdFactory; import com.googlecode.android_scripting.jsonrpc.RpcReceiverManager; +import java.net.InetSocketAddress; import java.util.concurrent.CountDownLatch; /** @@ -75,14 +76,14 @@ public void onStart(Intent intent, final int startId) { Log.v("Starting AndroidProxy"); mProxy = new AndroidProxy(this, intent, true); - mProxy.startLocal(); + InetSocketAddress addressWithPort = mProxy.startLocal(); - String host = mProxy.getAddress().getAddress(); - String port = mProxy.getAddress().getPort().toString(); + String host = mProxy.getAddress(); + String port = addressWithPort.getPort().toString(); String handshake = mProxy.getSecret(); Log.v(String.format("AndroidProxy at: %s @ %s:%s", handshake, host, port)); - Intent netaddress = new Intent(this, "org.alanjds.sl4acompat.STORE_RPC_NETADDRESS"); + Intent netaddress = new Intent("org.alanjds.sl4acompat.STORE_RPC_NETADDRESS"); netaddress.putExtra("host", host); netaddress.putExtra("port", port); netaddress.putExtra("handshake", handshake); From 0897e835e501bf1f88ceb63a7dbc64c66e4908bc Mon Sep 17 00:00:00 2001 From: Alan Justino Date: Sat, 28 Dec 2013 13:32:46 -0200 Subject: [PATCH 30/46] Compiling version. --- src/src/org/alanjds/sl4acompat/MinimalService.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/src/org/alanjds/sl4acompat/MinimalService.java b/src/src/org/alanjds/sl4acompat/MinimalService.java index ade69f4c16..65e7b83131 100644 --- a/src/src/org/alanjds/sl4acompat/MinimalService.java +++ b/src/src/org/alanjds/sl4acompat/MinimalService.java @@ -78,8 +78,9 @@ public void onStart(Intent intent, final int startId) { mProxy = new AndroidProxy(this, intent, true); InetSocketAddress addressWithPort = mProxy.startLocal(); - String host = mProxy.getAddress(); - String port = addressWithPort.getPort().toString(); + String host = addressWithPort.getAddress().getHostAddress(); + Integer iPort = addressWithPort.getPort(); + String port = iPort.toString(); String handshake = mProxy.getSecret(); Log.v(String.format("AndroidProxy at: %s @ %s:%s", handshake, host, port)); @@ -88,6 +89,7 @@ public void onStart(Intent intent, final int startId) { netaddress.putExtra("port", port); netaddress.putExtra("handshake", handshake); sendBroadcast(netaddress); + Log.v("Sent 'org.alanjds.sl4acompat.STORE_RPC_NETADDRESS'"); mLatch.countDown(); } From a74e7b76a47366b857479867c4c589801832e7cd Mon Sep 17 00:00:00 2001 From: Alan Justino Date: Sat, 4 Jan 2014 12:29:08 -0200 Subject: [PATCH 31/46] MinimalServiceStarter usage --- src/src/org/alanjds/sl4acompat/MinimalServiceStarter.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/src/org/alanjds/sl4acompat/MinimalServiceStarter.java b/src/src/org/alanjds/sl4acompat/MinimalServiceStarter.java index 555130387f..487fbbf798 100644 --- a/src/src/org/alanjds/sl4acompat/MinimalServiceStarter.java +++ b/src/src/org/alanjds/sl4acompat/MinimalServiceStarter.java @@ -7,6 +7,8 @@ import android.content.Intent; +// Usage: ./adb shell am broadcast -a org.alanjds.sl4acompat.START_MINIMAL_SERVICE + public class MinimalServiceStarter extends BroadcastReceiver { @Override From 4801ad1e1f27f72423fad14622600de9ec658b48 Mon Sep 17 00:00:00 2001 From: Alan Justino Date: Sat, 4 Jan 2014 12:29:27 -0200 Subject: [PATCH 32/46] Trying like http://stackoverflow.com/a/14153890/798575 --- src/src/org/alanjds/sl4acompat/MinimalService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/src/org/alanjds/sl4acompat/MinimalService.java b/src/src/org/alanjds/sl4acompat/MinimalService.java index 65e7b83131..d0cac0ffcd 100644 --- a/src/src/org/alanjds/sl4acompat/MinimalService.java +++ b/src/src/org/alanjds/sl4acompat/MinimalService.java @@ -75,7 +75,7 @@ public void onStart(Intent intent, final int startId) { super.onStart(intent, startId); Log.v("Starting AndroidProxy"); - mProxy = new AndroidProxy(this, intent, true); + mProxy = new AndroidProxy(MinimalService.this, intent, true); InetSocketAddress addressWithPort = mProxy.startLocal(); String host = addressWithPort.getAddress().getHostAddress(); From d33c6e8b81a27230f2c2c1fdd8964401e0e38306 Mon Sep 17 00:00:00 2001 From: Alan Justino Date: Sat, 4 Jan 2014 13:31:34 -0200 Subject: [PATCH 33/46] Start AndroiProxy on AsyncTask --- .../alanjds/sl4acompat/MinimalService.java | 62 ++++++++++++++----- 1 file changed, 47 insertions(+), 15 deletions(-) diff --git a/src/src/org/alanjds/sl4acompat/MinimalService.java b/src/src/org/alanjds/sl4acompat/MinimalService.java index d0cac0ffcd..bba28f5f0e 100644 --- a/src/src/org/alanjds/sl4acompat/MinimalService.java +++ b/src/src/org/alanjds/sl4acompat/MinimalService.java @@ -22,6 +22,7 @@ import android.content.Intent; import android.os.Binder; import android.os.IBinder; +import android.os.AsyncTask; import com.googlecode.android_scripting.AndroidProxy; import com.googlecode.android_scripting.ForegroundService; @@ -47,6 +48,8 @@ public class MinimalService extends ForegroundService { //private InterpreterConfiguration mInterpreterConfiguration; private RpcReceiverManager mFacadeManager; private AndroidProxy mProxy; + private InetSocketAddress mAddressWithPort; + private String mProxyAddress; public class LocalBinder extends Binder { public MinimalService getService() { @@ -74,26 +77,55 @@ public void onStart(Intent intent, final int startId) { Log.v("Starting MinimalService"); super.onStart(intent, startId); - Log.v("Starting AndroidProxy"); - mProxy = new AndroidProxy(MinimalService.this, intent, true); - InetSocketAddress addressWithPort = mProxy.startLocal(); + mProxy = new AndroidProxy(this, null, true); - String host = addressWithPort.getAddress().getHostAddress(); - Integer iPort = addressWithPort.getPort(); - String port = iPort.toString(); - String handshake = mProxy.getSecret(); - Log.v(String.format("AndroidProxy at: %s @ %s:%s", handshake, host, port)); - - Intent netaddress = new Intent("org.alanjds.sl4acompat.STORE_RPC_NETADDRESS"); - netaddress.putExtra("host", host); - netaddress.putExtra("port", port); - netaddress.putExtra("handshake", handshake); - sendBroadcast(netaddress); - Log.v("Sent 'org.alanjds.sl4acompat.STORE_RPC_NETADDRESS'"); + Log.v("Starting ProxyStarter"); + mProxyAddress = new ProxyStarter().execute(""); // Thread, as cannot be on UI thread + Log.v("Finished ProxyStarter"); mLatch.countDown(); } + private class ProxyStarter extends AsyncTask { + + @Override + protected String doInBackground(String... params) { + Log.v("Starting AndroidProxy"); + mAddressWithPort = mProxy.startLocal(); + Log.v("Started AndroidProxy"); + + String host = mAddressWithPort.getAddress().getHostAddress(); + Integer iPort = mAddressWithPort.getPort(); + String port = iPort.toString(); + String handshake = mProxy.getSecret(); + String proxyAddress = String.format("%s@%s:%s", handshake, host, port); + Log.v(String.format("AndroidProxy at: %s @ %s:%s", handshake, host, port)); + + Intent netaddress = new Intent("org.alanjds.sl4acompat.STORE_RPC_NETADDRESS"); + netaddress.putExtra("host", host); + netaddress.putExtra("port", port); + netaddress.putExtra("handshake", handshake); + sendBroadcast(netaddress); + Log.v("Sent 'org.alanjds.sl4acompat.STORE_RPC_NETADDRESS'"); + + return proxyAddress; + } + + @Override + protected void onPostExecute(String result) { + //TextView txt = (TextView) findViewById(R.id.output); + //txt.setText("Executed"); // txt.setText(result); + //// might want to change "executed" for the returned string passed + //// into onPostExecute() but that is upto you + } + + @Override + protected void onPreExecute() {} + + @Override + protected void onProgressUpdate(Void... values) {} + } + RpcReceiverManager getRpcReceiverManager() throws InterruptedException { mLatch.await(); if (mFacadeManager==null) { // Facade manage may not be available on startup. From 653d2c614229a1685695f85bac7e3da39facdc9b Mon Sep 17 00:00:00 2001 From: Alan Justino Date: Sat, 4 Jan 2014 13:42:49 -0200 Subject: [PATCH 34/46] Catch InterruptedException --- src/src/org/alanjds/sl4acompat/MinimalService.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/src/org/alanjds/sl4acompat/MinimalService.java b/src/src/org/alanjds/sl4acompat/MinimalService.java index bba28f5f0e..647e25c49c 100644 --- a/src/src/org/alanjds/sl4acompat/MinimalService.java +++ b/src/src/org/alanjds/sl4acompat/MinimalService.java @@ -80,8 +80,13 @@ public void onStart(Intent intent, final int startId) { mProxy = new AndroidProxy(this, null, true); Log.v("Starting ProxyStarter"); - mProxyAddress = new ProxyStarter().execute(""); // Thread, as cannot be on UI thread - Log.v("Finished ProxyStarter"); + try { + mProxyAddress = new ProxyStarter().execute("").get(); // Thread, as cannot be on UI thread + Log.v("Finished ProxyStarter"); + } catch (InterruptedException e) { + Log.v("Error on ProxyStarter"); + //Log.e(e); + } mLatch.countDown(); } From 54c25b603c32ad410a5ba8bdf6c7245d9412c259 Mon Sep 17 00:00:00 2001 From: Alan Justino Date: Mon, 6 Jan 2014 04:04:41 -0200 Subject: [PATCH 35/46] Tracking strange bug.. --- src/src/org/alanjds/sl4acompat/MinimalService.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/src/org/alanjds/sl4acompat/MinimalService.java b/src/src/org/alanjds/sl4acompat/MinimalService.java index 647e25c49c..5f7398b165 100644 --- a/src/src/org/alanjds/sl4acompat/MinimalService.java +++ b/src/src/org/alanjds/sl4acompat/MinimalService.java @@ -32,6 +32,7 @@ import java.net.InetSocketAddress; import java.util.concurrent.CountDownLatch; +import java.util.concurrent.ExecutionException; /** * A service that allows scripts and the RPC server to run in the background. @@ -83,10 +84,9 @@ public void onStart(Intent intent, final int startId) { try { mProxyAddress = new ProxyStarter().execute("").get(); // Thread, as cannot be on UI thread Log.v("Finished ProxyStarter"); - } catch (InterruptedException e) { - Log.v("Error on ProxyStarter"); - //Log.e(e); } + catch (InterruptedException e) { Log.v("Error on ProxyStarter: InterruptedException"); e.printStackTrace(); } + catch (ExecutionException e) { Log.v("Error on ProxyStarter: ExecutionException"); e.printStackTrace(); } mLatch.countDown(); } @@ -99,7 +99,13 @@ protected String doInBackground(String... params) { mAddressWithPort = mProxy.startLocal(); Log.v("Started AndroidProxy"); - String host = mAddressWithPort.getAddress().getHostAddress(); + Thread.sleep(1000); + + if (mAddressWithPort == null) { Log.v('Oops: mAddressWithPort == null'); } + if (mAddressWithPort.getAddress() == null) { Log.v('Oops: mAddressWithPort.getAddress() == null'); } + if (mAddressWithPort.getAddress().getHostAddress() == null) { Log.v('Oops: mAddressWithPort.getAddress().getHostAddress() == null'); } + + String host = mAddressWithPort.getAddress().getHostAddress();// NullPointerException Integer iPort = mAddressWithPort.getPort(); String port = iPort.toString(); String handshake = mProxy.getSecret(); From 9e80fab4b04725c4b848500b11ab7838ea639b46 Mon Sep 17 00:00:00 2001 From: Alan Justino Date: Mon, 6 Jan 2014 04:11:50 -0200 Subject: [PATCH 36/46] Oops: is ", not ' --- src/src/org/alanjds/sl4acompat/MinimalService.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/src/org/alanjds/sl4acompat/MinimalService.java b/src/src/org/alanjds/sl4acompat/MinimalService.java index 5f7398b165..12c4bae4f2 100644 --- a/src/src/org/alanjds/sl4acompat/MinimalService.java +++ b/src/src/org/alanjds/sl4acompat/MinimalService.java @@ -101,9 +101,9 @@ protected String doInBackground(String... params) { Thread.sleep(1000); - if (mAddressWithPort == null) { Log.v('Oops: mAddressWithPort == null'); } - if (mAddressWithPort.getAddress() == null) { Log.v('Oops: mAddressWithPort.getAddress() == null'); } - if (mAddressWithPort.getAddress().getHostAddress() == null) { Log.v('Oops: mAddressWithPort.getAddress().getHostAddress() == null'); } + if (mAddressWithPort == null) { Log.v("Oops: mAddressWithPort == null"); } + if (mAddressWithPort.getAddress() == null) { Log.v("Oops: mAddressWithPort.getAddress() == null"); } + if (mAddressWithPort.getAddress().getHostAddress() == null) { Log.v("Oops: mAddressWithPort.getAddress().getHostAddress() == null"); } String host = mAddressWithPort.getAddress().getHostAddress();// NullPointerException Integer iPort = mAddressWithPort.getPort(); From 6fab3e3437301623180080fd85e78073bf853f3a Mon Sep 17 00:00:00 2001 From: Alan Justino Date: Mon, 6 Jan 2014 04:12:08 -0200 Subject: [PATCH 37/46] Sleep for 1sec before the null pointer --- src/src/org/alanjds/sl4acompat/MinimalService.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/src/org/alanjds/sl4acompat/MinimalService.java b/src/src/org/alanjds/sl4acompat/MinimalService.java index 12c4bae4f2..59d7dd08fc 100644 --- a/src/src/org/alanjds/sl4acompat/MinimalService.java +++ b/src/src/org/alanjds/sl4acompat/MinimalService.java @@ -99,7 +99,8 @@ protected String doInBackground(String... params) { mAddressWithPort = mProxy.startLocal(); Log.v("Started AndroidProxy"); - Thread.sleep(1000); + try { Thread.sleep(1000); } + catch (InterruptedException e) {} if (mAddressWithPort == null) { Log.v("Oops: mAddressWithPort == null"); } if (mAddressWithPort.getAddress() == null) { Log.v("Oops: mAddressWithPort.getAddress() == null"); } From 3e11f2506b3e4e66809cf132ad015143bdb30020 Mon Sep 17 00:00:00 2001 From: Alan Justino Date: Mon, 6 Jan 2014 05:05:23 -0200 Subject: [PATCH 38/46] WORKING MinimalService --- src/src/org/alanjds/sl4acompat/MinimalService.java | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/src/org/alanjds/sl4acompat/MinimalService.java b/src/src/org/alanjds/sl4acompat/MinimalService.java index 59d7dd08fc..d0de3edb25 100644 --- a/src/src/org/alanjds/sl4acompat/MinimalService.java +++ b/src/src/org/alanjds/sl4acompat/MinimalService.java @@ -99,15 +99,10 @@ protected String doInBackground(String... params) { mAddressWithPort = mProxy.startLocal(); Log.v("Started AndroidProxy"); - try { Thread.sleep(1000); } - catch (InterruptedException e) {} + if (mAddressWithPort == null) { Log.w("Oops: mAddressWithPort == null"); } + Log.v(String.format("Started at %s", mAddressWithPort.toString())); - if (mAddressWithPort == null) { Log.v("Oops: mAddressWithPort == null"); } - if (mAddressWithPort.getAddress() == null) { Log.v("Oops: mAddressWithPort.getAddress() == null"); } - if (mAddressWithPort.getAddress().getHostAddress() == null) { Log.v("Oops: mAddressWithPort.getAddress().getHostAddress() == null"); } - - String host = mAddressWithPort.getAddress().getHostAddress();// NullPointerException - Integer iPort = mAddressWithPort.getPort(); + String host = mAddressWithPort.getHostName(); String port = iPort.toString(); String handshake = mProxy.getSecret(); String proxyAddress = String.format("%s@%s:%s", handshake, host, port); From 54b2479b27b7b32fc941ce0c24114393f095e351 Mon Sep 17 00:00:00 2001 From: Alan Justino Date: Mon, 6 Jan 2014 05:16:30 -0200 Subject: [PATCH 39/46] Simplify by taking out AsyncTask from service --- .../alanjds/sl4acompat/MinimalService.java | 64 ++++++------------- 1 file changed, 19 insertions(+), 45 deletions(-) diff --git a/src/src/org/alanjds/sl4acompat/MinimalService.java b/src/src/org/alanjds/sl4acompat/MinimalService.java index d0de3edb25..cf34da4062 100644 --- a/src/src/org/alanjds/sl4acompat/MinimalService.java +++ b/src/src/org/alanjds/sl4acompat/MinimalService.java @@ -79,58 +79,32 @@ public void onStart(Intent intent, final int startId) { super.onStart(intent, startId); mProxy = new AndroidProxy(this, null, true); - - Log.v("Starting ProxyStarter"); - try { - mProxyAddress = new ProxyStarter().execute("").get(); // Thread, as cannot be on UI thread - Log.v("Finished ProxyStarter"); - } - catch (InterruptedException e) { Log.v("Error on ProxyStarter: InterruptedException"); e.printStackTrace(); } - catch (ExecutionException e) { Log.v("Error on ProxyStarter: ExecutionException"); e.printStackTrace(); } - + mProxyAddress = startProxy(); mLatch.countDown(); } - private class ProxyStarter extends AsyncTask { - - @Override - protected String doInBackground(String... params) { - Log.v("Starting AndroidProxy"); - mAddressWithPort = mProxy.startLocal(); - Log.v("Started AndroidProxy"); - - if (mAddressWithPort == null) { Log.w("Oops: mAddressWithPort == null"); } - Log.v(String.format("Started at %s", mAddressWithPort.toString())); + private String startProxy() { + Log.v("Starting AndroidProxy"); + mAddressWithPort = mProxy.startLocal(); + Log.v("Started AndroidProxy"); - String host = mAddressWithPort.getHostName(); - String port = iPort.toString(); - String handshake = mProxy.getSecret(); - String proxyAddress = String.format("%s@%s:%s", handshake, host, port); - Log.v(String.format("AndroidProxy at: %s @ %s:%s", handshake, host, port)); + if (mAddressWithPort == null) { Log.w("Oops: mAddressWithPort == null"); } + Log.v(String.format("Started at %s", mAddressWithPort.toString())); - Intent netaddress = new Intent("org.alanjds.sl4acompat.STORE_RPC_NETADDRESS"); - netaddress.putExtra("host", host); - netaddress.putExtra("port", port); - netaddress.putExtra("handshake", handshake); - sendBroadcast(netaddress); - Log.v("Sent 'org.alanjds.sl4acompat.STORE_RPC_NETADDRESS'"); - - return proxyAddress; - } - - @Override - protected void onPostExecute(String result) { - //TextView txt = (TextView) findViewById(R.id.output); - //txt.setText("Executed"); // txt.setText(result); - //// might want to change "executed" for the returned string passed - //// into onPostExecute() but that is upto you - } + String host = mAddressWithPort.getHostName(); + String port = iPort.toString(); + String handshake = mProxy.getSecret(); + String proxyAddress = String.format("%s@%s:%s", handshake, host, port); + Log.d(String.format("AndroidProxy at: %s@%s:%s", handshake, host, port)); - @Override - protected void onPreExecute() {} + Intent netaddress = new Intent("org.alanjds.sl4acompat.STORE_RPC_NETADDRESS"); + netaddress.putExtra("host", host); + netaddress.putExtra("port", port); + netaddress.putExtra("handshake", handshake); + sendBroadcast(netaddress); + Log.v("Sent 'org.alanjds.sl4acompat.STORE_RPC_NETADDRESS'"); - @Override - protected void onProgressUpdate(Void... values) {} + return proxyAddress; } RpcReceiverManager getRpcReceiverManager() throws InterruptedException { From 6d9629c22f61238d8e7f589e5ecba773b54fe8c0 Mon Sep 17 00:00:00 2001 From: Alan Justino Date: Mon, 6 Jan 2014 05:20:39 -0200 Subject: [PATCH 40/46] Oops: Cleaned too much. --- src/src/org/alanjds/sl4acompat/MinimalService.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/src/org/alanjds/sl4acompat/MinimalService.java b/src/src/org/alanjds/sl4acompat/MinimalService.java index cf34da4062..8c162a0426 100644 --- a/src/src/org/alanjds/sl4acompat/MinimalService.java +++ b/src/src/org/alanjds/sl4acompat/MinimalService.java @@ -92,6 +92,7 @@ private String startProxy() { Log.v(String.format("Started at %s", mAddressWithPort.toString())); String host = mAddressWithPort.getHostName(); + Integer iPort = mAddressWithPort.getPort(); String port = iPort.toString(); String handshake = mProxy.getSecret(); String proxyAddress = String.format("%s@%s:%s", handshake, host, port); From 7eba72d010a7b05caf53a78d6654021c425bbd9f Mon Sep 17 00:00:00 2001 From: Alan Justino Date: Mon, 6 Jan 2014 06:01:40 -0200 Subject: [PATCH 41/46] Added needed Application scaffold --- .../sl4acompat/Sl4aCompatibleApplication.java | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/src/org/alanjds/sl4acompat/Sl4aCompatibleApplication.java diff --git a/src/src/org/alanjds/sl4acompat/Sl4aCompatibleApplication.java b/src/src/org/alanjds/sl4acompat/Sl4aCompatibleApplication.java new file mode 100644 index 0000000000..e343576ad4 --- /dev/null +++ b/src/src/org/alanjds/sl4acompat/Sl4aCompatibleApplication.java @@ -0,0 +1,38 @@ +package org.alanjds.sl4acompat; + +import com.googlecode.android_scripting.BaseApplication; +import com.googlecode.android_scripting.Log; +import com.googlecode.android_scripting.interpreter.InterpreterConfiguration; +import com.googlecode.android_scripting.interpreter.InterpreterConstants; +import com.googlecode.android_scripting.interpreter.InterpreterConfiguration.ConfigurationObserver; + +import java.util.concurrent.CountDownLatch; + +public class Sl4aCompatibleApplication extends BaseApplication implements ConfigurationObserver { + + private volatile boolean receivedConfigUpdate = false; + private final CountDownLatch mLatch = new CountDownLatch(1); + + @Override + public void onCreate() { + //mConfiguration = new InterpreterConfiguration(this); + //mConfiguration.registerObserver(this); + //mConfiguration.startDiscovering(InterpreterConstants.MIME + Script.getFileExtension(this)); + } + + @Override + public void onConfigurationChanged() { + receivedConfigUpdate = true; + mLatch.countDown(); + } + + public boolean readyToStart() { + try { + mLatch.await(); + } catch (InterruptedException e) { + Log.e(e); + } + return receivedConfigUpdate; + } + +} From 7ac9f72753972a098808bc343e43cc1c8d23045f Mon Sep 17 00:00:00 2001 From: Alan Justino Date: Mon, 6 Jan 2014 06:04:28 -0200 Subject: [PATCH 42/46] Our app starts in "ready" state already --- .../alanjds/sl4acompat/Sl4aCompatibleApplication.java | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/src/org/alanjds/sl4acompat/Sl4aCompatibleApplication.java b/src/src/org/alanjds/sl4acompat/Sl4aCompatibleApplication.java index e343576ad4..324b64108c 100644 --- a/src/src/org/alanjds/sl4acompat/Sl4aCompatibleApplication.java +++ b/src/src/org/alanjds/sl4acompat/Sl4aCompatibleApplication.java @@ -10,21 +10,16 @@ public class Sl4aCompatibleApplication extends BaseApplication implements ConfigurationObserver { - private volatile boolean receivedConfigUpdate = false; + private volatile boolean receivedConfigUpdate = true; private final CountDownLatch mLatch = new CountDownLatch(1); @Override public void onCreate() { - //mConfiguration = new InterpreterConfiguration(this); - //mConfiguration.registerObserver(this); - //mConfiguration.startDiscovering(InterpreterConstants.MIME + Script.getFileExtension(this)); + mLatch.countDown(); } @Override - public void onConfigurationChanged() { - receivedConfigUpdate = true; - mLatch.countDown(); - } + public void onConfigurationChanged() { } public boolean readyToStart() { try { From 628fdcc81cf9db50029013f4187d073d7424992e Mon Sep 17 00:00:00 2001 From: Alan Justino Date: Mon, 6 Jan 2014 06:15:44 -0200 Subject: [PATCH 43/46] Application can be Sl4aCompatibleApplication --- src/templates/AndroidManifest.tmpl.xml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/templates/AndroidManifest.tmpl.xml b/src/templates/AndroidManifest.tmpl.xml index 11cb143e98..b0b6c4574e 100644 --- a/src/templates/AndroidManifest.tmpl.xml +++ b/src/templates/AndroidManifest.tmpl.xml @@ -9,6 +9,10 @@ {% for m in args.meta_data %} From e6bd081930dad0419f7c1cb24b7b36e5c175804b Mon Sep 17 00:00:00 2001 From: Alan Justino Date: Tue, 7 Jan 2014 21:23:44 -0200 Subject: [PATCH 44/46] Identation fix --- recipes/sl4acompat/recipe.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/recipes/sl4acompat/recipe.sh b/recipes/sl4acompat/recipe.sh index fabcd724de..ed7b12d28b 100755 --- a/recipes/sl4acompat/recipe.sh +++ b/recipes/sl4acompat/recipe.sh @@ -7,21 +7,21 @@ BUILD_sl4acompat=$BUILD_PATH/sl4acompat/ RECIPE_sl4acompat=$RECIPES_PATH/sl4acompat function prebuild_sl4acompat() { - true + true } function shouldbuild_sl4acompat() { - true + true } function build_sl4acompat() { - true + true } function postbuild_sl4acompat() { - cd $BUILD_sl4acompat - mkdir "$DIST_PATH"/libs - cp -a libs/* "$DIST_PATH"/libs/ - cd - - true + cd $BUILD_sl4acompat + mkdir "$DIST_PATH"/libs + cp -a libs/* "$DIST_PATH"/libs/ + cd - + true } From c6b3ba7b97f67f8298ce5e81842e0f3173863a45 Mon Sep 17 00:00:00 2001 From: Alan Justino Date: Sat, 11 Jan 2014 11:39:31 -0200 Subject: [PATCH 45/46] Need no android:debuggable to build --- src/templates/AndroidManifest.tmpl.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/src/templates/AndroidManifest.tmpl.xml b/src/templates/AndroidManifest.tmpl.xml index b0b6c4574e..908a249795 100644 --- a/src/templates/AndroidManifest.tmpl.xml +++ b/src/templates/AndroidManifest.tmpl.xml @@ -11,7 +11,6 @@ android:hardwareAccelerated="true" {% if args.sl4acompat %} android:name="org.alanjds.sl4acompat.Sl4aCompatibleApplication" - android:debuggable="true" {% endif %} > From 28572df43eb25ee35125ebd6f5335ca8e55a301a Mon Sep 17 00:00:00 2001 From: Alan Justino Date: Sat, 11 Jan 2014 13:12:10 -0200 Subject: [PATCH 46/46] Oops: usually there is nothing to rm. --- distribute.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/distribute.sh b/distribute.sh index f34605d145..e5d3b4e49c 100755 --- a/distribute.sh +++ b/distribute.sh @@ -725,7 +725,7 @@ function run_distribute() { debug "Copy libs" try mkdir -p libs/$ARCH try cp -a $BUILD_PATH/libs/* libs/$ARCH/ - try rm "$DIST_PATH"/libs/$ARCH/*.jar || true + rm "$DIST_PATH"/libs/$ARCH/*.jar || true debug "Copy java files from various libs" cp -a $BUILD_PATH/java/* src