2 * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.samsung.android.beyond.discovery;
19 import android.util.Log;
20 import android.content.Context;
22 import com.samsung.android.beyond.EventListener;
23 import com.samsung.android.beyond.EventObject;
24 import com.samsung.android.beyond.NativeInstance;
25 import com.samsung.android.beyond.ConfigType;
27 public class Discovery extends NativeInstance {
32 public static class Info {
39 public class DefaultEventObject extends EventObject {
42 private static final String TAG = "BEYOND_ANDROID_DISCOVERY";
44 public Discovery(Context context, String[] arguments) {
45 if (context == null || arguments == null || arguments.length == 0) {
46 throw new IllegalArgumentException("There is no argument");
49 registerNativeInstance(create(arguments), (Long instance) -> destroy(instance));
51 if (this.configure(ConfigType.CONTEXT_ANDROID, context) != 0) {
52 Log.e(TAG, "Failed to configure the android context");
56 public int activate() {
58 throw new IllegalStateException();
61 return activate(instance);
64 public int deactivate() {
66 throw new IllegalStateException();
69 return deactivate(instance);
72 public int setItem(String key, byte[] value) {
74 throw new IllegalStateException();
77 return setItem(instance, key, value);
80 public int removeItem(String key) {
82 throw new IllegalStateException();
85 return removeItem(instance, key);
88 public int configure(char type, Object obj) {
89 if (type == ConfigType.CONTEXT_ANDROID) {
90 if (obj.getClass().getName().equals("android.app.Application") == true) {
91 return this.configure(instance, type, obj);
95 // This function should generate a proper exception
102 public void setEventListener(EventListener eventListener) {
103 if (setEventListener(instance, eventListener) < 0) {
104 // TODO: throw an exception
108 private static native void initialize();
109 private native long create(String[] arguments);
110 private static native void destroy(long instance);
111 private native int activate(long instance);
112 private native int deactivate(long instance);
113 private native int setItem(long instance, String key, byte[] value);
114 private native int removeItem(long instance, String key);
115 private native int configure(long instance, char type, Object obj);
116 private native int setEventListener(long instance, EventListener eventListener);