From acc0748fce28b7cc1ff95a47d73ad77a49806cfd Mon Sep 17 00:00:00 2001 From: Alexander Dorokhine Date: Tue, 6 Dec 2016 19:26:41 -0800 Subject: Remove the 'facade' package and FacadeManager. Merge the sdk checking code into SnippetManager. Move the main Snippet interface to the root package. --- .../com/google/android/mobly/snippet/Snippet.java | 22 +++++ .../mobly/snippet/facade/FacadeManager.java | 53 ---------- .../facade/ReflectionFacadeManagerFactory.java | 97 ------------------ .../manager/ReflectionSnippetManagerFactory.java | 95 ++++++++++++++++++ .../mobly/snippet/manager/SnippetManager.java | 108 +++++++++++++++++++++ .../snippet/manager/SnippetManagerFactory.java | 24 +++++ .../android/mobly/snippet/rpc/AndroidProxy.java | 9 +- .../android/mobly/snippet/rpc/JsonRpcServer.java | 5 +- .../mobly/snippet/rpc/MethodDescriptor.java | 9 +- .../google/android/mobly/snippet/rpc/Snippet.java | 22 ----- .../android/mobly/snippet/rpc/SnippetManager.java | 102 ------------------- .../mobly/snippet/rpc/SnippetManagerFactory.java | 24 ----- 12 files changed, 259 insertions(+), 311 deletions(-) create mode 100644 third_party/sl4a/src/main/java/com/google/android/mobly/snippet/Snippet.java delete mode 100644 third_party/sl4a/src/main/java/com/google/android/mobly/snippet/facade/FacadeManager.java delete mode 100644 third_party/sl4a/src/main/java/com/google/android/mobly/snippet/facade/ReflectionFacadeManagerFactory.java create mode 100644 third_party/sl4a/src/main/java/com/google/android/mobly/snippet/manager/ReflectionSnippetManagerFactory.java create mode 100644 third_party/sl4a/src/main/java/com/google/android/mobly/snippet/manager/SnippetManager.java create mode 100644 third_party/sl4a/src/main/java/com/google/android/mobly/snippet/manager/SnippetManagerFactory.java delete mode 100644 third_party/sl4a/src/main/java/com/google/android/mobly/snippet/rpc/Snippet.java delete mode 100644 third_party/sl4a/src/main/java/com/google/android/mobly/snippet/rpc/SnippetManager.java delete mode 100644 third_party/sl4a/src/main/java/com/google/android/mobly/snippet/rpc/SnippetManagerFactory.java (limited to 'third_party/sl4a/src') diff --git a/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/Snippet.java b/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/Snippet.java new file mode 100644 index 0000000..fb3a1b9 --- /dev/null +++ b/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/Snippet.java @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2016 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.google.android.mobly.snippet; + +public interface Snippet { + /** Invoked when the receiver is shut down. */ + void shutdown(); +} diff --git a/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/facade/FacadeManager.java b/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/facade/FacadeManager.java deleted file mode 100644 index a3160c7..0000000 --- a/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/facade/FacadeManager.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (C) 2016 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.google.android.mobly.snippet.facade; - -import android.content.Context; - -import com.google.android.mobly.snippet.rpc.RpcMinSdk; -import com.google.android.mobly.snippet.rpc.Snippet; -import com.google.android.mobly.snippet.rpc.SnippetManager; -import com.google.android.mobly.snippet.util.SnippetLibException; -import com.google.android.mobly.snippet.util.Log; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.Collection; - -public class FacadeManager extends SnippetManager { - - private int mSdkLevel; - - public FacadeManager(int sdkLevel, Collection> classList) { - super(classList); - mSdkLevel = sdkLevel; - } - - @Override - public Object invoke(Class clazz, Method method, Object[] args) - throws Exception { - if (method.isAnnotationPresent(RpcMinSdk.class)) { - int requiredSdkLevel = method.getAnnotation(RpcMinSdk.class).value(); - if (mSdkLevel < requiredSdkLevel) { - throw new SnippetLibException( - String.format("%s requires API level %d, current level is %d", - method.getName(), requiredSdkLevel, mSdkLevel)); - } - } - return super.invoke(clazz, method, args); - } -} diff --git a/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/facade/ReflectionFacadeManagerFactory.java b/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/facade/ReflectionFacadeManagerFactory.java deleted file mode 100644 index 1b626b5..0000000 --- a/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/facade/ReflectionFacadeManagerFactory.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (C) 2016 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.google.android.mobly.snippet.facade; - -import android.content.Context; -import android.content.pm.ApplicationInfo; -import android.content.pm.PackageManager; -import android.os.Build; -import android.os.Bundle; - -import com.google.android.mobly.snippet.rpc.Snippet; -import com.google.android.mobly.snippet.rpc.SnippetManager; -import com.google.android.mobly.snippet.rpc.SnippetManagerFactory; -import com.google.android.mobly.snippet.util.Log; - -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -public class ReflectionFacadeManagerFactory implements SnippetManagerFactory { - private static final String METADATA_TAG_NAME = "mobly-snippets"; - - private final Context mContext; - private final Set> mClasses; - private final Map mSnippetManagers; - - public ReflectionFacadeManagerFactory(Context context) { - mContext = context; - mClasses = loadSnippets(); - mSnippetManagers = new HashMap<>(); - } - - @Override - public FacadeManager create(Integer UID) { - int sdkLevel = Build.VERSION.SDK_INT; - FacadeManager facadeManager = new FacadeManager(sdkLevel, mClasses); - mSnippetManagers.put(UID, facadeManager); - return facadeManager; - } - - @Override - public Map getSnippetManagers() { - return Collections.unmodifiableMap(mSnippetManagers); - } - - private Set> loadSnippets() { - ApplicationInfo appInfo; - try { - appInfo = mContext - .getPackageManager() - .getApplicationInfo(mContext.getPackageName(), PackageManager.GET_META_DATA); - } catch (PackageManager.NameNotFoundException e) { - throw new IllegalStateException( - "Failed to find ApplicationInfo with package name: " - + mContext.getPackageName()); - } - Bundle metadata = appInfo.metaData; - String snippets = metadata.getString(METADATA_TAG_NAME); - if (snippets == null) { - throw new IllegalStateException( - "AndroidManifest.xml does not contain a tag with " - + "name=\"" + METADATA_TAG_NAME + "\""); - } - String[] snippetClassNames = snippets.split("\\s*,\\s*"); - Set> receiverSet = new HashSet<>(); - for (String snippetClassName : snippetClassNames) { - try { - Log.i("Trying to load Snippet class: " + snippetClassName); - Class snippetClass = Class.forName(snippetClassName); - receiverSet.add((Class) snippetClass); - } catch (ClassNotFoundException e) { - Log.e("Failed to find class " + snippetClassName); - throw new RuntimeException(e); - } - } - if (receiverSet.isEmpty()) { - throw new IllegalStateException("Found no subclasses of Snippet."); - } - return receiverSet; - } -} diff --git a/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/manager/ReflectionSnippetManagerFactory.java b/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/manager/ReflectionSnippetManagerFactory.java new file mode 100644 index 0000000..eb97481 --- /dev/null +++ b/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/manager/ReflectionSnippetManagerFactory.java @@ -0,0 +1,95 @@ +/* + * Copyright (C) 2016 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.google.android.mobly.snippet.manager; + +import android.content.Context; +import android.content.pm.ApplicationInfo; +import android.content.pm.PackageManager; +import android.os.Build; +import android.os.Bundle; + +import com.google.android.mobly.snippet.Snippet; +import com.google.android.mobly.snippet.util.Log; + +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +public class ReflectionSnippetManagerFactory implements SnippetManagerFactory { + private static final String METADATA_TAG_NAME = "mobly-snippets"; + + private final Context mContext; + private final Set> mClasses; + private final Map mSnippetManagers; + + public ReflectionSnippetManagerFactory(Context context) { + mContext = context; + mClasses = loadSnippets(); + mSnippetManagers = new HashMap<>(); + } + + @Override + public SnippetManager create(Integer UID) { + int sdkLevel = Build.VERSION.SDK_INT; + SnippetManager manager = new SnippetManager(mClasses); + mSnippetManagers.put(UID, manager); + return manager; + } + + @Override + public Map getSnippetManagers() { + return Collections.unmodifiableMap(mSnippetManagers); + } + + private Set> loadSnippets() { + ApplicationInfo appInfo; + try { + appInfo = mContext + .getPackageManager() + .getApplicationInfo(mContext.getPackageName(), PackageManager.GET_META_DATA); + } catch (PackageManager.NameNotFoundException e) { + throw new IllegalStateException( + "Failed to find ApplicationInfo with package name: " + + mContext.getPackageName()); + } + Bundle metadata = appInfo.metaData; + String snippets = metadata.getString(METADATA_TAG_NAME); + if (snippets == null) { + throw new IllegalStateException( + "AndroidManifest.xml does not contain a tag with " + + "name=\"" + METADATA_TAG_NAME + "\""); + } + String[] snippetClassNames = snippets.split("\\s*,\\s*"); + Set> receiverSet = new HashSet<>(); + for (String snippetClassName : snippetClassNames) { + try { + Log.i("Trying to load Snippet class: " + snippetClassName); + Class snippetClass = Class.forName(snippetClassName); + receiverSet.add((Class) snippetClass); + } catch (ClassNotFoundException e) { + Log.e("Failed to find class " + snippetClassName); + throw new RuntimeException(e); + } + } + if (receiverSet.isEmpty()) { + throw new IllegalStateException("Found no subclasses of Snippet."); + } + return receiverSet; + } +} diff --git a/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/manager/SnippetManager.java b/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/manager/SnippetManager.java new file mode 100644 index 0000000..edb872b --- /dev/null +++ b/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/manager/SnippetManager.java @@ -0,0 +1,108 @@ +/* + * Copyright (C) 2016 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.google.android.mobly.snippet.manager; + +import android.os.Build; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.SortedSet; +import java.util.TreeSet; + +import com.google.android.mobly.snippet.Snippet; +import com.google.android.mobly.snippet.rpc.MethodDescriptor; +import com.google.android.mobly.snippet.rpc.RpcMinSdk; +import com.google.android.mobly.snippet.util.Log; +import com.google.android.mobly.snippet.util.SnippetLibException; + +public class SnippetManager { + private final Map, Snippet> mReceivers; + /** A map of strings to known RPCs. */ + private final Map mKnownRpcs = new HashMap(); + + public SnippetManager(Collection> classList) { + mReceivers = new HashMap<>(); + for (Class receiverClass : classList) { + mReceivers.put(receiverClass, null); + Collection methodList = MethodDescriptor.collectFrom(receiverClass); + for (MethodDescriptor m : methodList) { + if (mKnownRpcs.containsKey(m.getName())) { + // We already know an RPC of the same name. We don't catch this anywhere because + // this is a programming error. + throw new RuntimeException("An RPC with the name " + m.getName() + + " is already known."); + } + mKnownRpcs.put(m.getName(), m); + } + } + } + + public MethodDescriptor getMethodDescriptor(String methodName) { + return mKnownRpcs.get(methodName); + } + + public SortedSet getMethodNames() { + return new TreeSet<>(mKnownRpcs.keySet()); + } + + public Object invoke(Class clazz, Method method, Object[] args) + throws Exception { + if (method.isAnnotationPresent(RpcMinSdk.class)) { + int requiredSdkLevel = method.getAnnotation(RpcMinSdk.class).value(); + if (Build.VERSION.SDK_INT < requiredSdkLevel) { + throw new SnippetLibException( + String.format("%s requires API level %d, current level is %d", + method.getName(), requiredSdkLevel, Build.VERSION.SDK_INT)); + } + } + Snippet object = get(clazz); + return method.invoke(object, args); + } + + public void shutdown() { + for (Snippet receiver : mReceivers.values()) { + try { + if (receiver != null) { + receiver.shutdown(); + } + } catch (Exception e) { + Log.e("Failed to shut down an Snippet", e); + } + } + } + + private Snippet get(Class clazz) { + Snippet object = mReceivers.get(clazz); + if (object != null) { + return object; + } + + Constructor constructor; + try { + constructor = clazz.getConstructor(); + object = constructor.newInstance(); + mReceivers.put(clazz, object); + } catch (Exception e) { + Log.e(e); + } + + return object; + } +} diff --git a/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/manager/SnippetManagerFactory.java b/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/manager/SnippetManagerFactory.java new file mode 100644 index 0000000..9acb273 --- /dev/null +++ b/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/manager/SnippetManagerFactory.java @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2016 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.google.android.mobly.snippet.manager; + +import java.util.Map; + +public interface SnippetManagerFactory { + SnippetManager create(Integer UID); + Map getSnippetManagers(); +} diff --git a/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/rpc/AndroidProxy.java b/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/rpc/AndroidProxy.java index fd13b3f..0ae764f 100644 --- a/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/rpc/AndroidProxy.java +++ b/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/rpc/AndroidProxy.java @@ -18,7 +18,8 @@ package com.google.android.mobly.snippet.rpc; import android.content.Context; -import com.google.android.mobly.snippet.facade.ReflectionFacadeManagerFactory; +import com.google.android.mobly.snippet.manager.ReflectionSnippetManagerFactory; +import com.google.android.mobly.snippet.manager.SnippetManagerFactory; import java.net.InetSocketAddress; @@ -26,11 +27,11 @@ public class AndroidProxy { private InetSocketAddress mAddress; private final JsonRpcServer mJsonRpcServer; - private final SnippetManagerFactory mFacadeManagerFactory; + private final SnippetManagerFactory mSnippetManagerFactory; public AndroidProxy(Context context) { - mFacadeManagerFactory = new ReflectionFacadeManagerFactory(context); - mJsonRpcServer = new JsonRpcServer(mFacadeManagerFactory); + mSnippetManagerFactory = new ReflectionSnippetManagerFactory(context); + mJsonRpcServer = new JsonRpcServer(mSnippetManagerFactory); } public InetSocketAddress startLocal(int port) { diff --git a/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/rpc/JsonRpcServer.java b/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/rpc/JsonRpcServer.java index 6834507..398dc3f 100644 --- a/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/rpc/JsonRpcServer.java +++ b/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/rpc/JsonRpcServer.java @@ -16,6 +16,8 @@ package com.google.android.mobly.snippet.rpc; +import com.google.android.mobly.snippet.manager.SnippetManager; +import com.google.android.mobly.snippet.manager.SnippetManagerFactory; import com.google.android.mobly.snippet.util.Log; import java.io.BufferedReader; @@ -49,8 +51,7 @@ public class JsonRpcServer extends SimpleServer { public void shutdown() { super.shutdown(); // Notify all RPC receiving objects. They may have to clean up some of their state. - for (SnippetManager manager : mSnippetManagerFactory.getSnippetManagers() - .values()) { + for (SnippetManager manager : mSnippetManagerFactory.getSnippetManagers().values()) { manager.shutdown(); } } diff --git a/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/rpc/MethodDescriptor.java b/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/rpc/MethodDescriptor.java index c110da0..8d18582 100644 --- a/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/rpc/MethodDescriptor.java +++ b/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/rpc/MethodDescriptor.java @@ -18,21 +18,16 @@ package com.google.android.mobly.snippet.rpc; import android.content.Intent; import android.net.Uri; -import android.os.Bundle; -import android.os.Parcelable; +import com.google.android.mobly.snippet.Snippet; +import com.google.android.mobly.snippet.manager.SnippetManager; import com.google.android.mobly.snippet.util.AndroidUtil; -import java.lang.annotation.Annotation; -import java.lang.reflect.Constructor; import java.lang.reflect.Method; -import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; import java.util.ArrayList; import java.util.Collection; -import java.util.HashMap; import java.util.List; -import java.util.Map; import org.json.JSONArray; import org.json.JSONException; diff --git a/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/rpc/Snippet.java b/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/rpc/Snippet.java deleted file mode 100644 index a6286a0..0000000 --- a/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/rpc/Snippet.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (C) 2016 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.google.android.mobly.snippet.rpc; - -public interface Snippet { - /** Invoked when the receiver is shut down. */ - void shutdown(); -} diff --git a/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/rpc/SnippetManager.java b/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/rpc/SnippetManager.java deleted file mode 100644 index d118707..0000000 --- a/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/rpc/SnippetManager.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (C) 2016 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.google.android.mobly.snippet.rpc; - -import android.content.Context; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Method; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; -import java.util.SortedSet; -import java.util.TreeSet; - -import com.google.android.mobly.snippet.util.Log; - -public abstract class SnippetManager { - - private final Map, Snippet> mReceivers; - - /** - * A map of strings to known RPCs. - */ - private final Map mKnownRpcs = new HashMap(); - - public SnippetManager(Collection> classList) { - mReceivers = new HashMap<>(); - for (Class receiverClass : classList) { - mReceivers.put(receiverClass, null); - Collection methodList = MethodDescriptor.collectFrom(receiverClass); - for (MethodDescriptor m : methodList) { - if (mKnownRpcs.containsKey(m.getName())) { - // We already know an RPC of the same name. We don't catch this anywhere because - // this is a programming error. - throw new RuntimeException("An RPC with the name " + m.getName() - + " is already known."); - } - mKnownRpcs.put(m.getName(), m); - } - } - } - - private Snippet get(Class clazz) { - Snippet object = mReceivers.get(clazz); - if (object != null) { - return object; - } - - Constructor constructor; - try { - constructor = clazz.getConstructor(); - object = constructor.newInstance(); - mReceivers.put(clazz, object); - } catch (Exception e) { - Log.e(e); - } - - return object; - } - - public MethodDescriptor getMethodDescriptor(String methodName) { - return mKnownRpcs.get(methodName); - } - - public SortedSet getMethodNames() { - return new TreeSet<>(mKnownRpcs.keySet()); - } - - public Object invoke(Class clazz, Method method, Object[] args) - throws Exception { - Snippet object = get(clazz); - return method.invoke(object, args); - } - - public void shutdown() { - for (Snippet receiver : mReceivers.values()) { - try { - if (receiver != null) { - receiver.shutdown(); - } - } catch (Exception e) { - Log.e("Failed to shut down an Snippet", e); - } - } - } -} diff --git a/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/rpc/SnippetManagerFactory.java b/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/rpc/SnippetManagerFactory.java deleted file mode 100644 index f1d16b2..0000000 --- a/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/rpc/SnippetManagerFactory.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (C) 2016 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.google.android.mobly.snippet.rpc; - -import java.util.Map; - -public interface SnippetManagerFactory { - SnippetManager create(Integer UID); - Map getSnippetManagers(); -} -- cgit v1.2.3