Provides the highest level of abstraction for Decoders. 22 | * This is the sister interface of {@link Encoder}. All 23 | * Decoders implement this common generic interface.
24 | * 25 | *Allows a user to pass a generic Object to any Decoder 26 | * implementation in the codec package.
27 | * 28 | *One of the two interfaces at the center of the codec package.
29 | * 30 | * @author Apache Software Foundation 31 | * @version $Id: Decoder.java 797690 2009-07-24 23:28:35Z ggregory $ 32 | */ 33 | public interface Decoder { 34 | 35 | /** 36 | * Decodes an "encoded" Object and returns a "decoded" 37 | * Object. Note that the implementation of this 38 | * interface will try to cast the Object parameter 39 | * to the specific type expected by a particular Decoder 40 | * implementation. If a {@link ClassCastException} occurs 41 | * this decode method will throw a DecoderException. 42 | * 43 | * @param pObject an object to "decode" 44 | * 45 | * @return a 'decoded" object 46 | * 47 | * @throws DecoderException a decoder exception can 48 | * be thrown for any number of reasons. Some good 49 | * candidates are that the parameter passed to this 50 | * method is null, a param cannot be cast to the 51 | * appropriate type for a specific encoder. 52 | */ 53 | Object decode(Object pObject) throws DecoderException; 54 | } 55 | 56 | -------------------------------------------------------------------------------- /src/main/java/org/qpython/qsl4a/codec/DecoderException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.qpython.qsl4a.codec; 19 | 20 | /** 21 | * Thrown when a Decoder has encountered a failure condition during a decode. 22 | * 23 | * @author Apache Software Foundation 24 | * @version $Id: DecoderException.java 797804 2009-07-25 17:27:04Z ggregory $ 25 | */ 26 | public class DecoderException extends Exception { 27 | 28 | /** 29 | * Declares the Serial Version Uid. 30 | * 31 | * @see Always Declare Serial Version Uid 32 | */ 33 | private static final long serialVersionUID = 1L; 34 | 35 | /** 36 | * Constructs a new exception withnull
as its detail message. The cause is not initialized, and may
37 | * subsequently be initialized by a call to {@link #initCause}.
38 | *
39 | * @since 1.4
40 | */
41 | public DecoderException() {
42 | super();
43 | }
44 |
45 | /**
46 | * Constructs a new exception with the specified detail message. The cause is not initialized, and may subsequently
47 | * be initialized by a call to {@link #initCause}.
48 | *
49 | * @param message
50 | * The detail message which is saved for later retrieval by the {@link #getMessage()} method.
51 | */
52 | public DecoderException(String message) {
53 | super(message);
54 | }
55 |
56 | /**
57 | * Constructsa new exception with the specified detail message and cause.
58 | *
59 | *
60 | * Note that the detail message associated with cause
is not automatically incorporated into this
61 | * exception's detail message.
62 | *
null
68 | * value is permitted, and indicates that the cause is nonexistent or unknown.
69 | * @since 1.4
70 | */
71 | public DecoderException(String message, Throwable cause) {
72 | super(message, cause);
73 | }
74 |
75 | /**
76 | * Constructs a new exception with the specified cause and a detail message of (cause==null ?
77 | * null : cause.toString())
(which typically contains the class and detail message of cause
).
78 | * This constructor is useful for exceptions that are little more than wrappers for other throwables.
79 | *
80 | * @param cause
81 | * The cause which is saved for later retrieval by the {@link #getCause()} method. A null
82 | * value is permitted, and indicates that the cause is nonexistent or unknown.
83 | * @since 1.4
84 | */
85 | public DecoderException(Throwable cause) {
86 | super(cause);
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/src/main/java/org/qpython/qsl4a/codec/Encoder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package org.qpython.qsl4a.codec;
19 |
20 | /**
21 | * Provides the highest level of abstraction for Encoders. 22 | * This is the sister interface of {@link Decoder}. Every implementation of 23 | * Encoder provides this common generic interface whic allows a user to pass a 24 | * generic Object to any Encoder implementation in the codec package.
25 | * 26 | * @author Apache Software Foundation 27 | * @version $Id: Encoder.java 634915 2008-03-08 09:30:25Z bayard $ 28 | */ 29 | public interface Encoder { 30 | 31 | /** 32 | * Encodes an "Object" and returns the encoded content 33 | * as an Object. The Objects here may just bebyte[]
34 | * or String
s depending on the implementation used.
35 | *
36 | * @param pObject An object ot encode
37 | *
38 | * @return An "encoded" Object
39 | *
40 | * @throws EncoderException an encoder exception is
41 | * thrown if the encoder experiences a failure
42 | * condition during the encoding process.
43 | */
44 | Object encode(Object pObject) throws EncoderException;
45 | }
46 |
47 |
--------------------------------------------------------------------------------
/src/main/java/org/qpython/qsl4a/codec/EncoderException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package org.qpython.qsl4a.codec;
19 |
20 | /**
21 | * Thrown when there is a failure condition during the encoding process. This exception is thrown when an Encoder
22 | * encounters a encoding specific exception such as invalid data, inability to calculate a checksum, characters outside
23 | * of the expected range.
24 | *
25 | * @author Apache Software Foundation
26 | * @version $Id: EncoderException.java 797804 2009-07-25 17:27:04Z ggregory $
27 | */
28 | public class EncoderException extends Exception {
29 |
30 | /**
31 | * Declares the Serial Version Uid.
32 | *
33 | * @see Always Declare Serial Version Uid
34 | */
35 | private static final long serialVersionUID = 1L;
36 |
37 | /**
38 | * Constructs a new exception with null
as its detail message. The cause is not initialized, and may
39 | * subsequently be initialized by a call to {@link #initCause}.
40 | *
41 | * @since 1.4
42 | */
43 | public EncoderException() {
44 | super();
45 | }
46 |
47 | /**
48 | * Constructs a new exception with the specified detail message. The cause is not initialized, and may subsequently
49 | * be initialized by a call to {@link #initCause}.
50 | *
51 | * @param message
52 | * a useful message relating to the encoder specific error.
53 | */
54 | public EncoderException(String message) {
55 | super(message);
56 | }
57 |
58 | /**
59 | * Constructs a new exception with the specified detail message and cause.
60 | *
61 | *
62 | * Note that the detail message associated with cause
is not automatically incorporated into this
63 | * exception's detail message.
64 | *
null
70 | * value is permitted, and indicates that the cause is nonexistent or unknown.
71 | * @since 1.4
72 | */
73 | public EncoderException(String message, Throwable cause) {
74 | super(message, cause);
75 | }
76 |
77 | /**
78 | * Constructs a new exception with the specified cause and a detail message of (cause==null ?
79 | * null : cause.toString())
(which typically contains the class and detail message of cause
).
80 | * This constructor is useful for exceptions that are little more than wrappers for other throwables.
81 | *
82 | * @param cause
83 | * The cause which is saved for later retrieval by the {@link #getCause()} method. A null
84 | * value is permitted, and indicates that the cause is nonexistent or unknown.
85 | * @since 1.4
86 | */
87 | public EncoderException(Throwable cause) {
88 | super(cause);
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/src/main/java/org/qpython/qsl4a/qsl4a/Analytics.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2009 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package org.qpython.qsl4a.qsl4a;
18 |
19 | import android.app.Activity;
20 | import android.content.Context;
21 | import android.content.SharedPreferences;
22 | import android.preference.PreferenceManager;
23 |
24 |
25 | import java.util.concurrent.ExecutorService;
26 | import java.util.concurrent.Executors;
27 |
28 | public class Analytics {
29 | private static SharedPreferences mPrefs;
30 | private static String mSl4aVersion;
31 | private static ExecutorService mWorkPool;
32 | private static volatile boolean mStarted = false;
33 |
34 | private Analytics() {
35 | // Utility class.
36 | }
37 |
38 | // TODO(Alexey): Add Javadoc. "Also, it would be cool to wrap up the Analytics API into a facade."
39 | @SuppressWarnings("deprecation")
40 | public static synchronized void start(Context context, String analyticsAccountId) {
41 | if (context == null || analyticsAccountId == null) {
42 | return;
43 | }
44 | mSl4aVersion = Version.getVersion(context);
45 | mPrefs = PreferenceManager.getDefaultSharedPreferences(context);
46 | mWorkPool = Executors.newSingleThreadExecutor();
47 | mStarted = true;
48 | }
49 |
50 | private static class PageNameBuilder {
51 | private final StringBuilder mmName = new StringBuilder();
52 |
53 | void add(String pathPart) {
54 | mmName.append("/");
55 | mmName.append(pathPart);
56 | }
57 |
58 | String build() {
59 | return mmName.toString();
60 | }
61 | }
62 |
63 | public static void track(final String... nameParts) {
64 | if (mStarted && mPrefs.getBoolean("usagetracking", false)) {
65 | mWorkPool.submit(new Runnable() {
66 | public void run() {
67 | PageNameBuilder builder = new PageNameBuilder();
68 | builder.add(mSl4aVersion);
69 | for (String part : nameParts) {
70 | builder.add(part);
71 | }
72 | String name = builder.build();
73 | }
74 | });
75 | }
76 | }
77 |
78 | public static void trackActivity(Activity activity) {
79 | String name = activity.getClass().getSimpleName();
80 | track(name);
81 | }
82 |
83 | @SuppressWarnings("deprecation")
84 | public static synchronized void stop() {
85 | if (mStarted) {
86 | mStarted = false;
87 | mWorkPool.shutdownNow();
88 | }
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/src/main/java/org/qpython/qsl4a/qsl4a/AndroidProxy.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2009 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package org.qpython.qsl4a.qsl4a;
18 |
19 | import android.app.Service;
20 | import android.content.Intent;
21 |
22 | import org.qpython.qsl4a.qsl4a.facade.FacadeConfiguration;
23 | import org.qpython.qsl4a.qsl4a.facade.FacadeManagerFactory;
24 | import org.qpython.qsl4a.qsl4a.jsonrpc.JsonRpcServer;
25 | import org.qpython.qsl4a.qsl4a.jsonrpc.RpcReceiverManagerFactory;
26 |
27 | import java.net.InetSocketAddress;
28 | import java.util.UUID;
29 |
30 | public class AndroidProxy {
31 |
32 | private InetSocketAddress mAddress;
33 | private final JsonRpcServer mJsonRpcServer;
34 | private final UUID mSecret;
35 | private final RpcReceiverManagerFactory mFacadeManagerFactory;
36 |
37 | /**
38 | *
39 | * @param service
40 | * Android service (required to build facades).
41 | * @param intent
42 | * the intent that launched the proxy/script.
43 | * @param requiresHandshake
44 | * indicates whether RPC security protocol should be enabled.
45 | */
46 | public AndroidProxy(Service service, Intent intent, boolean requiresHandshake) {
47 | if (requiresHandshake) {
48 | mSecret = UUID.randomUUID();
49 | } else {
50 | mSecret = null;
51 | }
52 | mFacadeManagerFactory =
53 | new FacadeManagerFactory(FacadeConfiguration.getSdkLevel(), service, intent,
54 | FacadeConfiguration.getFacadeClasses());
55 | mJsonRpcServer = new JsonRpcServer(mFacadeManagerFactory, getSecret());
56 | }
57 |
58 | public InetSocketAddress getAddress() {
59 | return mAddress;
60 | }
61 |
62 | public InetSocketAddress startLocal() {
63 | return startLocal(0);
64 | }
65 |
66 | public InetSocketAddress startLocal(int port) {
67 | mAddress = mJsonRpcServer.startLocal(port);
68 | return mAddress;
69 | }
70 |
71 | public InetSocketAddress startPublic() {
72 | return startPublic(0);
73 | }
74 |
75 | public InetSocketAddress startPublic(int port) {
76 | mAddress = mJsonRpcServer.startPublic(port);
77 | return mAddress;
78 | }
79 |
80 | public void shutdown() {
81 | if (mJsonRpcServer!=null) {
82 | mJsonRpcServer.shutdown();
83 | }
84 | }
85 |
86 | public String getSecret() {
87 | if (mSecret == null) {
88 | return null;
89 | }
90 | return mSecret.toString();
91 | }
92 |
93 | public RpcReceiverManagerFactory getRpcReceiverManagerFactory() {
94 | return mFacadeManagerFactory;
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/src/main/java/org/qpython/qsl4a/qsl4a/BaseApplication.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2009 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package org.qpython.qsl4a.qsl4a;
18 |
19 | import android.app.Application;
20 |
21 | import org.qpython.qsl4a.qsl4a.interpreter.InterpreterConfiguration;
22 | import org.qpython.qsl4a.qsl4a.trigger.TriggerRepository;
23 |
24 | public class BaseApplication extends Application {
25 |
26 | private final FutureActivityTaskExecutor mTaskExecutor = new FutureActivityTaskExecutor(this);
27 | private TriggerRepository mTriggerRepository;
28 |
29 | protected InterpreterConfiguration mConfiguration;
30 |
31 | public FutureActivityTaskExecutor getTaskExecutor() {
32 | return mTaskExecutor;
33 | }
34 |
35 | @Override
36 | public void onCreate() {
37 | super.onCreate();
38 | mConfiguration = new InterpreterConfiguration(this);
39 | mConfiguration.startDiscovering();
40 | mTriggerRepository = new TriggerRepository(this);
41 | }
42 |
43 | public InterpreterConfiguration getInterpreterConfiguration() {
44 | return mConfiguration;
45 | }
46 |
47 | public TriggerRepository getTriggerRepository() {
48 | return mTriggerRepository;
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/src/main/java/org/qpython/qsl4a/qsl4a/Exec.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2007 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.qpython.qsl4a.qsl4a;
18 |
19 | import java.io.FileDescriptor;
20 |
21 | /**
22 | * Tools for executing commands.
23 | */
24 | public class Exec {
25 | /**
26 | * @param cmd
27 | * The command to execute
28 | * @param arg0
29 | * The first argument to the command, may be null
30 | * @param arg1
31 | * the second argument to the command, may be null
32 | * @return the file descriptor of the started process.
33 | *
34 | */
35 | public static FileDescriptor createSubprocess(String command, String[] arguments,
36 | String[] environmentVariables, String workingDirectory) {
37 | return createSubprocess(command, arguments, environmentVariables, workingDirectory, null);
38 | }
39 |
40 | /**
41 | * @param cmd
42 | * The command to execute
43 | * @param arguments
44 | * Array of arguments, may be null
45 | * @param environmentVariables
46 | * Array of environment variables, may be null
47 | * @param processId
48 | * A one-element array to which the process ID of the started process will be written.
49 | * @return the file descriptor of the opened process's psuedo-terminal.
50 | *
51 | */
52 | public static native FileDescriptor createSubprocess(String command, String[] arguments,
53 | String[] environmentVariables, String workingDirectory, int[] processId);
54 |
55 | public static native void setPtyWindowSize(FileDescriptor fd, int row, int col, int xpixel,
56 | int ypixel);
57 |
58 | /**
59 | * Causes the calling thread to wait for the process associated with the receiver to finish
60 | * executing.
61 | *
62 | * @return The exit value of the Process being waited on
63 | *
64 | */
65 | public static native int waitFor(int processId);
66 |
67 | static {
68 | System.loadLibrary("com_googlecode_android_scripting_Exec");
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/src/main/java/org/qpython/qsl4a/qsl4a/FeaturedInterpreters.java:
--------------------------------------------------------------------------------
1 | // Copyright 2010 Google Inc. All Rights Reserved.
2 |
3 | package org.qpython.qsl4a.qsl4a;
4 |
5 | import android.content.Context;
6 |
7 | import java.net.MalformedURLException;
8 | import java.net.URL;
9 | import java.util.ArrayList;
10 | import java.util.Collections;
11 | import java.util.HashMap;
12 | import java.util.List;
13 | import java.util.Map;
14 |
15 | public class FeaturedInterpreters {
16 | private static final Map