- Added dialog box support to take cloud signUp , signIn and other details from UI.
- Proper allignment of braces and other minor formatting.
Patch-3 : Removed fixed strings
Patch-4 : Modified callback listener name
Change-Id: I75d292c4236dc1da7e7c822a5cd6340b8bb77b44
Signed-off-by: nikhil.a <nikhil.a7@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/15877
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: jaesick shin <jaesick.shin@samsung.com>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
* OnSyncInfoReceivedListner callback Interface
*/
public void setListener(OnProviderStateListener onProviderStateListener,
- OnMessageReceivedListner onMessageReceivedListner,
- OnSyncInfoReceivedListner onSyncInfoReceivedListner)
+ OnMessageReceivedListener onMessageReceivedListener,
+ OnSyncInfoReceivedListener onSyncInfoReceivedListener)
throws NSException {
- nativeSetListener(onProviderStateListener, onMessageReceivedListner,
- onSyncInfoReceivedListner);
+ nativeSetListener(onProviderStateListener, onMessageReceivedListener,
+ onSyncInfoReceivedListener);
}
/**
/**
* Interface to implement callback function to receive Notification Message
*/
- public interface OnMessageReceivedListner {
+ public interface OnMessageReceivedListener {
/**
* Callback function to receive Notification Message.
* Interface to implement callback function to receive message read
* synchronization
*/
- public interface OnSyncInfoReceivedListner {
+ public interface OnSyncInfoReceivedListener {
/**
* Callback function to receive message read synchronization
private native void nativeSetListener(
OnProviderStateListener onProviderStateListener,
- OnMessageReceivedListner onMessageReceivedListner,
- OnSyncInfoReceivedListner onSyncInfoReceivedListner)
+ OnMessageReceivedListener onMessageReceivedListener,
+ OnSyncInfoReceivedListener onSyncInfoReceivedListener)
throws NSException;
public native TopicsList nativeGetTopicList() throws NSException;
/*\r
* Class: org_iotivity_service_ns_consumer_Provider\r
* Method: nativeSetListener\r
- * Signature: (Lorg/iotivity/service/ns/consumer/Provider/OnProviderStateListener;Lorg/iotivity/service/ns/consumer/Provider/OnMessageReceivedListner;Lorg/iotivity/service/ns/consumer/Provider/OnSyncInfoReceivedListner;)V\r
+ * Signature: (Lorg/iotivity/service/ns/consumer/Provider/OnProviderStateListener;Lorg/iotivity/service/ns/consumer/Provider/OnMessageReceivedListener;Lorg/iotivity/service/ns/consumer/Provider/OnSyncInfoReceivedListener;)V\r
*/\r
JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_Provider_nativeSetListener\r
(JNIEnv *, jobject, jobject, jobject, jobject);\r
* To work on unit tests, switch the Test Artifact in the Build Variants view.
*/
@RunWith(AndroidJUnit4.class)
-public class ExampleUnitTest extends ApplicationTestCase<Application>
-{
- public ExampleUnitTest()
- {
+public class ExampleUnitTest extends ApplicationTestCase<Application> {
+ public ExampleUnitTest() {
super(Application.class);
}
- private static Context mContext = null;
- private ProviderService gProviderRes;
- private ProviderSimulator gProviderSimul;
- private static ConsumerService gConsumerRes;
- private static DiscoveryCallbackListener disCb ;
- private static ProviderCallbackListener provCb ;
- CountDownLatch lockObject;
- Response response;
- private static String TAG = "ConsumerExample UnitTest";
-
- public void startBefore(boolean subControllability)
- {
- try
- {
+ private static Context mContext = null;
+ private ProviderService gProviderRes;
+ private ProviderSimulator gProviderSimul;
+ private static ConsumerService gConsumerRes;
+ private static DiscoveryCallbackListener disCb;
+ private static ProviderCallbackListener provCb;
+ CountDownLatch lockObject;
+ Response response;
+ private static String TAG = "ConsumerExample UnitTest";
+
+ public void startBefore(boolean subControllability) {
+ Log.i(TAG, "startConsumerBefore - IN");
+ try {
gConsumerRes.start(disCb);
- gProviderRes.start(gProviderSimul, gProviderSimul, subControllability, "nothing", false);
+ gProviderRes.start(gProviderSimul, gProviderSimul,
+ subControllability, "nothing", false);
lockObject.await(4000, TimeUnit.MILLISECONDS);
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
e.printStackTrace();
}
+ Log.i(TAG, "startConsumerBefore - OUT");
}
- public void startAfter(boolean subControllability)
- {
- try
- {
- gProviderRes.start(gProviderSimul, gProviderSimul, subControllability, "nothing", false);
+ public void startAfter(boolean subControllability) {
+ Log.i(TAG, "startConsumerAfter - IN");
+ try {
+ gProviderRes.start(gProviderSimul, gProviderSimul,
+ subControllability, "nothing", false);
gConsumerRes.start(disCb);
lockObject.await(4000, TimeUnit.MILLISECONDS);
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
e.printStackTrace();
}
+ Log.i(TAG, "startConsumerAfter - OUT");
}
- public void setListener(Provider mProvider)
- {
- try
- {
+ public void setListener(Provider mProvider) {
+ try {
mProvider.setListener(provCb, provCb, provCb);
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
e.printStackTrace();
}
}
- public void subscribe(Provider.ProviderState state)
- {
+ public void subscribe(Provider.ProviderState state) {
lockObject = new CountDownLatch(1);
response = new Response();
provCb.set(lockObject, response);
provCb.setState(state);
Provider mProvider = disCb.getProvider();
setListener(mProvider);
- try
- {
- if (!mProvider.isSubscribed())
- {
+ try {
+ if (!mProvider.isSubscribed()) {
Log.i(TAG, "not subscribed");
mProvider.subscribe();
}
lockObject.await(4000, TimeUnit.MILLISECONDS);
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
e.printStackTrace();
}
}
- public long sendMessage()
- {
+ public long sendMessage() {
lockObject = new CountDownLatch(1);
response = new Response();
provCb.set(lockObject, response);
- org.iotivity.service.ns.common.Message msg = gProviderSimul.getMessage();
+ org.iotivity.service.ns.common.Message msg = gProviderSimul
+ .getMessage();
long Id = msg.getMessageId();
provCb.setId(Id);
- try
- {
+ try {
gProviderRes.sendMessage(msg);
- lockObject.await(4000, TimeUnit.SECONDS);
- }
- catch (Exception e)
- {
+ lockObject.await(4000, TimeUnit.MILLISECONDS);
+ } catch (Exception e) {
e.printStackTrace();
}
return Id;
}
- public void sendSyncInfo(long id, SyncInfo.SyncType type)
- {
- try
- {
+ public void sendSyncInfo(long id, SyncInfo.SyncType type) {
+ try {
lockObject = new CountDownLatch(1);
response = new Response();
provCb.set(lockObject, response);
provCb.setType(type);
gProviderRes.sendSyncInfo(id, type);
- lockObject.await(4000, TimeUnit.SECONDS);
- }
- catch (Exception e)
- {
+ lockObject.await(4000, TimeUnit.MILLISECONDS);
+ } catch (Exception e) {
e.printStackTrace();
}
}
- public void providerSendSyncInfo(Provider provider, long id, SyncInfo.SyncType type)
- {
- try
- {
+ public void providerSendSyncInfo(Provider provider, long id,
+ SyncInfo.SyncType type) {
+ try {
lockObject = new CountDownLatch(1);
response = new Response();
provCb.set(lockObject, response);
provCb.setType(type);
provider.sendSyncInfo(id, type);
- lockObject.await(4000, TimeUnit.SECONDS);
- }
- catch (Exception e)
- {
+ lockObject.await(4000, TimeUnit.MILLISECONDS);
+ } catch (Exception e) {
e.printStackTrace();
}
}
- public void registerTopic(String topic)
- {
+ public void registerTopic(String topic) {
lockObject = new CountDownLatch(1);
response = new Response();
provCb.set(lockObject, response);
provCb.setState(Provider.ProviderState.TOPIC);
- try
- {
+ try {
gProviderRes.registerTopic(topic);
- lockObject.await(4000, TimeUnit.SECONDS);
- }
- catch (Exception e)
- {
+ lockObject.await(4000, TimeUnit.MILLISECONDS);
+ } catch (Exception e) {
e.printStackTrace();
}
}
+
@BeforeClass
- public static void Initialize()
- {
- PlatformConfig platformConfig = new PlatformConfig(
- mContext,
- ServiceType.IN_PROC,
- ModeType.CLIENT_SERVER,
- "0.0.0.0", // By setting to "0.0.0.0", it binds to all available interfaces
- 0, // Uses randomly available port
- QualityOfService.LOW
- );
+ public static void Initialize() {
+ PlatformConfig platformConfig = new PlatformConfig(mContext,
+ ServiceType.IN_PROC, ModeType.CLIENT_SERVER, "0.0.0.0",
+ 0, // Uses randomly available port
+ QualityOfService.LOW);
OcPlatform.Configure(platformConfig);
- try
- {
+ try {
OcPlatform.stopPresence(); // Initialize OcPlatform
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
e.printStackTrace();
}
}
@Before
- public void SetUp()
- {
+ public void SetUp() {
+ Log.i(TAG, "SetUp - IN");
disCb = new DiscoveryCallbackListener();
provCb = new ProviderCallbackListener();
- gConsumerRes = ConsumerService.getInstance();
- gProviderRes = ProviderService.getInstance();
+ gConsumerRes = ConsumerService.getInstance();
+ gProviderRes = ProviderService.getInstance();
gProviderSimul = new ProviderSimulator();
lockObject = new CountDownLatch(1);
response = new Response();
disCb.set(lockObject, response);
+ Log.i(TAG, "SetUp - OUT");
}
@After
- public void TearDown()
- {
- try
- {
+ public void TearDown() {
+ Log.i(TAG, "TearDown - IN");
+ try {
gConsumerRes.stop();
gProviderRes.stop();
lockObject = new CountDownLatch(1);
lockObject.await(2000, TimeUnit.MILLISECONDS);
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
e.printStackTrace();
}
-
+ Log.i(TAG, "TearDown - OUT");
}
@Test
- public void DiscoverProviderWithNonAccepterWhenStartedConsumerFirst()
- {
+ public void DiscoverProviderWithNonAccepterWhenStartedConsumerFirst() {
startBefore(false);
assertEquals(true, response.get());
}
@Test
- public void DiscoverProviderWithNonAccepterWhenStartedConsumerAfter()
- {
+ public void DiscoverProviderWithNonAccepterWhenStartedConsumerAfter() {
startAfter(false);
assertEquals(true, response.get());
}
@Test
- public void DiscoverProviderWithNonAccepterWhenRescan()
- {
+ public void DiscoverProviderWithNonAccepterWhenRescan() {
startAfter(false);
assertEquals(true, response.get());
- try
- {
+ try {
gConsumerRes.rescanProvider();
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
e.printStackTrace();
}
}
@Test
- public void ExpectSubscribeSuccess()
- {
+ public void ExpectSubscribeSuccess() {
startAfter(false);
assertEquals(true, response.get());
}
@Test
- public void ExpectReceiveNotification()
- {
+ public void ExpectReceiveNotification() {
startAfter(false);
assertEquals(true, response.get());
}
@Test
- public void DiscoverProviderWithAccepterisProvider()
- {
+ public void DiscoverProviderWithAccepterisProvider() {
startAfter(true);
assertEquals(true, response.get());
}
@Test
- public void ExpectReceiveNotificationWithAccepterisProvider()
- {
+ public void ExpectReceiveNotificationWithAccepterisProvider() {
startAfter(true);
assertEquals(true, response.get());
}
@Test
- public void ExpectCallbackReadCheckWhenProviderNotifySync()
- {
+ public void ExpectCallbackReadCheckWhenProviderNotifySync() {
startAfter(true);
assertEquals(true, response.get());
}
@Test
- public void ExpectCallbackDismissCheckWhenProviderNotifySync()
- {
+ public void ExpectCallbackDismissCheckWhenProviderNotifySync() {
startAfter(true);
assertEquals(true, response.get());
}
@Test
- public void ExpectCallbackReadCheckWhenConsumerPostSync()
- {
+ public void ExpectCallbackReadCheckWhenConsumerPostSync() {
startAfter(true);
assertEquals(true, response.get());
}
@Test
- public void ExpectCallbackDismissCheckWhenConsumerPostSync()
- {
+ public void ExpectCallbackDismissCheckWhenConsumerPostSync() {
startAfter(true);
assertEquals(true, response.get());
}
@Test
- public void ExpectCallbackTopicUpdated()
- {
+ public void ExpectCallbackTopicUpdated() {
startAfter(true);
assertEquals(true, response.get());
}
@Test
- public void ExpectEQTopicList()
- {
+ public void ExpectEQTopicList() {
startAfter(true);
assertEquals(true, response.get());
Provider mProvider = disCb.getProvider();
setListener(mProvider);
- try
- {
+ try {
registerTopic("OIC_TOPIC1");
assertEquals(true, response.get());
registerTopic("OIC_TOPIC2");
assertEquals(true, response.get());
response = new Response();
- Iterator<Topic> it = mProvider.getTopicList().getTopicsList().iterator();
- Iterator<Topic> it2 = gProviderRes.getRegisteredTopicList().getTopicsList().iterator();
- while (it.hasNext())
- {
+ Iterator<Topic> it = mProvider.getTopicList().getTopicsList()
+ .iterator();
+ Iterator<Topic> it2 = gProviderRes.getRegisteredTopicList()
+ .getTopicsList().iterator();
+ while (it.hasNext()) {
Topic element = it.next();
Topic element2 = it2.next();
Log.i(TAG, element2.getTopicName());
- if (!element.getTopicName().equals(element2.getTopicName()))
- {
+ if (!element.getTopicName().equals(element2.getTopicName())) {
response.set(false);
break;
}
response.set(true);
}
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
e.printStackTrace();
}
assertEquals(true, response.get());
}
@Test
- public void ExpectFailUpdateTopicOnConsumer()
- {
+ public void ExpectFailUpdateTopicOnConsumer() {
startAfter(true);
assertEquals(true, response.get());
int result = 0;
- try
- {
+ try {
TopicsList list = mProvider.getTopicList();
Iterator<Topic> it = list.getTopicsList().iterator();
- while (it.hasNext())
- {
+ while (it.hasNext()) {
Topic element = it.next();
element.setState(Topic.TopicState.SUBSCRIBED);
}
result = mProvider.updateTopicList(list);
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
e.printStackTrace();
}
assertEquals(200, result);
}
@Test
- public void ExpectCallbackStoppedProvider()
- {
+ public void ExpectCallbackStoppedProvider() {
startAfter(true);
assertEquals(true, response.get());
provCb.set(lockObject, response);
provCb.setState(Provider.ProviderState.STOPPED);
- try
- {
+ try {
gProviderRes.stop();
lockObject.await(4000, TimeUnit.MILLISECONDS);
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
e.printStackTrace();
}
}
class DiscoveryCallbackListener
- implements ConsumerService.OnProviderDiscoveredListener
-{
+ implements ConsumerService.OnProviderDiscoveredListener {
private CountDownLatch mLockObject;
- private Response mResponse;
- private Provider mProvider;
- private static String TAG = "UnitTest DiscoveryCallbackListener";
+ private Response mResponse;
+ private Provider mProvider;
+ private static String TAG = "UnitTest DiscoveryCallbackListener";
- public void set(CountDownLatch lockObject , Response response)
- {
+ public void set(CountDownLatch lockObject, Response response) {
mLockObject = lockObject;
mResponse = response;
}
- public Provider getProvider()
- {
+ public Provider getProvider() {
return mProvider;
}
+
@Override
- public void onProviderDiscovered(Provider provider)
- {
+ public void onProviderDiscovered(Provider provider) {
Log.i(TAG, provider.getProviderId());
mProvider = provider;
- if (mResponse != null)
- {
+ if (mResponse != null) {
+ Log.i(TAG, "onProviderDiscovered: Lock released");
mResponse.set(true);
mLockObject.countDown();
}
}
}
-class ProviderCallbackListener
- implements Provider.OnProviderStateListener,
- Provider.OnMessageReceivedListner, Provider.OnSyncInfoReceivedListner
-{
+class ProviderCallbackListener implements Provider.OnProviderStateListener,
+ Provider.OnMessageReceivedListener, Provider.OnSyncInfoReceivedListener {
- private CountDownLatch mLockObject;
- private Response mResponse;
+ private CountDownLatch mLockObject;
+ private Response mResponse;
private Provider.ProviderState mState;
- private SyncInfo.SyncType mType;
- private long mId;
- private static String TAG = "UnitTest ProviderCallbackListener";
+ private SyncInfo.SyncType mType;
+ private long mId;
+ private static String TAG = "UnitTest ProviderCallbackListener";
- public void set(CountDownLatch lockObject , Response response)
- {
+ public void set(CountDownLatch lockObject, Response response) {
mLockObject = lockObject;
mResponse = response;
}
- public void setState(Provider.ProviderState state)
- {
+ public void setState(Provider.ProviderState state) {
mState = state;
}
- public void setId(long id)
- {
+
+ public void setId(long id) {
mId = id;
}
- void setType(SyncInfo.SyncType type)
- {
+
+ void setType(SyncInfo.SyncType type) {
mType = type;
}
+
@Override
- public void onProviderStateReceived(Provider.ProviderState state)
- {
+ public void onProviderStateReceived(Provider.ProviderState state) {
Log.i(TAG, "onProviderStateReceived: " + state);
- if (mState == state) mResponse.set(true);
- mLockObject.countDown();
+ if (mState == state) {
+ Log.i(TAG, "onProviderStateReceived: Lock released");
+ mResponse.set(true);
+ mLockObject.countDown();
+ }
+
}
@Override
- public void onMessageReceived(org.iotivity.service.ns.common.Message msg)
- {
+ public void onMessageReceived(org.iotivity.service.ns.common.Message msg) {
Log.i(TAG, "onMessageReceived: " + msg.getMessageId());
- if (mId == msg.getMessageId()) mResponse.set(true);
- mLockObject.countDown();
+ if (mId == msg.getMessageId()) {
+ Log.i(TAG, "onMessageReceived: Lock released");
+ mResponse.set(true);
+ mLockObject.countDown();
+ }
}
@Override
- public void onSyncInfoReceived(SyncInfo syncInfo)
- {
+ public void onSyncInfoReceived(SyncInfo syncInfo) {
Log.i(TAG, "onSyncInfoReceived: " + syncInfo.getState());
- if (mType == syncInfo.getState()) mResponse.set(true);
- mLockObject.countDown();
+ if (mType == syncInfo.getState()) {
+ Log.i(TAG, "onSyncInfoReceived: Lock released");
+ mResponse.set(true);
+ mLockObject.countDown();
+ }
}
}
-class Response
-{
+class Response {
private boolean state;
- Response()
- {
+
+ Response() {
state = false;
}
- public void set(boolean val)
- {
+
+ public void set(boolean val) {
state = val;
}
- public boolean get()
- {
+ public boolean get() {
return state;
}
}
-
import org.iotivity.service.ns.provider.Consumer;
import org.iotivity.service.ns.provider.ProviderService;
-
-class ProviderSimulator implements ProviderService.OnMessageSynchronizedListener,
- ProviderService.OnConsumerSubscribedListener
-{
- private String TAG = "Provider Simulator" ;
+class ProviderSimulator
+ implements ProviderService.OnMessageSynchronizedListener,
+ ProviderService.OnConsumerSubscribedListener {
+ private String TAG = "Provider Simulator";
private Consumer gConsumer;
@Override
- public void onMessageSynchronized(SyncInfo syncInfo)
- {
- Log.i(TAG, "Notification onMessageSynchronized: " );
+ public void onMessageSynchronized(SyncInfo syncInfo) {
+ Log.i(TAG, "Notification onMessageSynchronized: ");
}
@Override
- public void onConsumerSubscribed(Consumer consumer)
- {
+ public void onConsumerSubscribed(Consumer consumer) {
gConsumer = consumer;
- try
- {
+ try {
int result = gConsumer.acceptSubscription(true);
Log.i(TAG, "Notification AcceptSubscription: " + result);
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
}
}
- public Message getMessage()
- {
- try
- {
+ public Message getMessage() {
+ try {
Message msg = ProviderService.getInstance().createMessage();
msg.setTitle("Title");
msg.setSourceName("provider");
MediaContents media = new MediaContents("new");
msg.setMediaContents(media);
return msg;
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
e.printStackTrace();
}
return null;
import org.iotivity.service.ns.consumer.Provider;
public class ConsumerSample
- implements ConsumerService.OnProviderDiscoveredListener,
- Provider.OnProviderStateListener,
- Provider.OnMessageReceivedListner, Provider.OnSyncInfoReceivedListner
-{
- private static final String TAG = "NS_CONSUMER_SAMPLE";
+ implements ConsumerService.OnProviderDiscoveredListener,
+ Provider.OnProviderStateListener, Provider.OnMessageReceivedListener,
+ Provider.OnSyncInfoReceivedListener {
+ private static final String TAG = "NS_CONSUMER_SAMPLE";
- private Context mContext = null;
- private ConsumerService consumerService = null;
- private boolean mAcceptor = true;
- private Provider mProvider = null;
+ private Context mContext = null;
+ private ConsumerService consumerService = null;
+ private boolean mAcceptor = true;
+ private Provider mProvider = null;
- private Handler mHandler = null;
+ private Handler mHandler = null;
- private static final int PROVIDER_DISCOVERED = 1;
- private static final int STATE_CHANGED = 2;
- private static final int MESSAGE_RECEIVED = 3;
- private static final int SYNCINFO_RECEIVED = 4;
- private static final int TOPICS_RECEIVED = 5;
+ private static final int PROVIDER_DISCOVERED = 1;
+ private static final int STATE_CHANGED = 2;
+ private static final int MESSAGE_RECEIVED = 3;
+ private static final int SYNCINFO_RECEIVED = 4;
+ private static final int TOPICS_RECEIVED = 5;
- public ConsumerSample(Context context)
- {
+ public ConsumerSample(Context context) {
Log.i(TAG, "Create consumer sample Instance");
this.mContext = context;
consumerService = new ConsumerService();
}
- public void setHandler(Handler handler)
- {
+ public void setHandler(Handler handler) {
this.mHandler = handler;
}
- public boolean getAcceptor()
- {
+ public boolean getAcceptor() {
return mAcceptor;
}
- private void configurePlatform()
- {
+ private void configurePlatform() {
- PlatformConfig platformConfig = new PlatformConfig(
- mContext,
- ServiceType.IN_PROC,
- ModeType.CLIENT_SERVER,
- "0.0.0.0", // By setting to "0.0.0.0", it binds to all available interfaces
- 0, // Uses randomly available port
- QualityOfService.LOW
- );
+ PlatformConfig platformConfig = new PlatformConfig(mContext,
+ ServiceType.IN_PROC, ModeType.CLIENT_SERVER, "0.0.0.0",
+ 0, // Uses randomly available port
+ QualityOfService.LOW);
Log.i(TAG, "Configuring platform.");
OcPlatform.Configure(platformConfig);
- try
- {
+ try {
OcPlatform.stopPresence(); // Initialize OcPlatform
- }
- catch (Exception e)
- {
- Log.e(TAG, "Exception: stopping presence when configuration step: " + e);
+ } catch (Exception e) {
+ Log.e(TAG, "Exception: stopping presence when configuration step: "
+ + e);
}
Log.i(TAG, "Configuration done Successfully");
}
- public void startNotificationConsumer()
- {
+ public void startNotificationConsumer() {
configurePlatform();
- try
- {
+ try {
consumerService.start(this);
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
Log.e(TAG, "Exception: startNotificationConsumer : " + e);
}
}
- public void stopNotificationConsumer()
- {
- try
- {
+ public void stopNotificationConsumer() {
+ try {
consumerService.stop();
mProvider = null;
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
Log.e(TAG, "Exception: stopNotificationConsumer : " + e);
}
}
- public void enableRemoteService(String serverAddress)
- {
- try
- {
+ public void enableRemoteService(String serverAddress) {
+ try {
consumerService.enableRemoteService(serverAddress);
- }
- catch (NSException e)
- {
+ } catch (NSException e) {
Log.e(TAG, "NSException: enableRemoteService : " + e);
}
}
+
public int subscribeMQService(String servAdd, String topicName) {
Log.i(TAG, "SubscribeMQService - IN");
int result = 0;
- try{
+ try {
result = consumerService.subscribeMQService(servAdd, topicName);
- Log.i(TAG, "Notification SubscribeMQService: "+ result );
- }
- catch(Exception e) {
-
+ Log.i(TAG, "Notification SubscribeMQService: " + result);
+ } catch (Exception e) {
+ Log.e(TAG, "Exception: subscribeMQService : " + e);
}
Log.i(TAG, "SubscribeMQService - OUT");
return result;
}
- public void rescanProvider()
- {
- try
- {
+
+ public void rescanProvider() {
+ try {
consumerService.rescanProvider();
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
Log.e(TAG, "Exception: rescanProvider : " + e);
}
}
- public void getTopicsList()
- {
- if (mProvider != null)
- {
- try
- {
+
+ public void getTopicsList() {
+ if (mProvider != null) {
+ try {
TopicsList topicsList = mProvider.getTopicList();
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("TopicList Received :");
- for(Topic topic : topicsList.getTopicsList())
- {
- Log.i(TAG, "Topic Name : " + topic.getTopicName() );
- Log.i(TAG, "Topic State : " + topic.getState() );
- stringBuilder.append("\nTopic Name : " + topic.getTopicName());
+ for (Topic topic : topicsList.getTopicsList()) {
+ Log.i(TAG, "Topic Name : " + topic.getTopicName());
+ Log.i(TAG, "Topic State : " + topic.getState());
+ stringBuilder
+ .append("\nTopic Name : " + topic.getTopicName());
stringBuilder.append("\nTopic State : " + topic.getState());
}
- Message msg = mHandler.obtainMessage(TOPICS_RECEIVED, stringBuilder.toString());
+ Message msg = mHandler.obtainMessage(TOPICS_RECEIVED,
+ stringBuilder.toString());
mHandler.sendMessage(msg);
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
Log.e(TAG, "Exception: getTopicsList : " + e);
}
- }
- else
- {
+ } else {
Log.e(TAG, "getTopicsList Provider NULL");
}
}
- public void updateTopicList(TopicsList topicsList)
- {
- if (mProvider != null)
- {
- try
- {
+
+ public void updateTopicList(TopicsList topicsList) {
+ if (mProvider != null) {
+ try {
mProvider.updateTopicList(topicsList);
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
Log.e(TAG, "Exception: updateTopicList : " + e);
}
- }
- else
- {
+ } else {
Log.e(TAG, "updateTopicList Provider NULL");
}
}
+
@Override
- public void onProviderDiscovered(Provider provider)
- {
+ public void onProviderDiscovered(Provider provider) {
Log.i(TAG, "onProviderDiscovered");
- if (provider == null)
- {
+ if (provider == null) {
Log.e(TAG, "providerID is Null ");
return;
}
mProvider = provider;
- Log.i(TAG, "Provider ID: " + provider.getProviderId() );
+ Log.i(TAG, "Provider ID: " + provider.getProviderId());
Message msg = mHandler.obtainMessage(PROVIDER_DISCOVERED,
- "Provider Discovered Id: " + provider.getProviderId());
+ "Provider Discovered Id: " + provider.getProviderId());
mHandler.sendMessage(msg);
- try
- {
+ try {
Log.i(TAG, "setListeners to Discovered Provider");
provider.setListener(this, this, this);
Log.i(TAG, "setListeners done");
- if (! provider.isSubscribed())
- {
+ if (!provider.isSubscribed()) {
Log.i(TAG, "Provider not subscribed. Acceptor is Consumer");
mAcceptor = false;
provider.subscribe();
- }
- else
- {
- Log.i(TAG, "Provider is already subscribed. Acceptor is Provider");
+ } else {
+ Log.i(TAG,
+ "Provider is already subscribed. Acceptor is Provider");
mAcceptor = true;
}
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
Log.e(TAG, "Exception : " + e);
}
}
@Override
- public void onProviderStateReceived(Provider.ProviderState state)
- {
+ public void onProviderStateReceived(Provider.ProviderState state) {
Log.i(TAG, "onProviderStateReceived");
- Log.i(TAG, "ProviderState Received : " + state );
- Message msg = mHandler.obtainMessage(STATE_CHANGED, "ProviderState Received : " + state);
+ Log.i(TAG, "ProviderState Received : " + state);
+ Message msg = mHandler.obtainMessage(STATE_CHANGED,
+ "ProviderState Received : " + state);
mHandler.sendMessage(msg);
}
@Override
- public void onMessageReceived(org.iotivity.service.ns.common.Message message)
- {
+ public void onMessageReceived(
+ org.iotivity.service.ns.common.Message message) {
Log.i(TAG, "onMessageReceived");
Log.i(TAG, "Message Id: " + message.getMessageId());
Log.i(TAG, "Message Source: " + message.getSourceName());
Message msg = mHandler.obtainMessage(MESSAGE_RECEIVED,
- "Message Id: " + message.getMessageId() + "\n" +
- "Message title: " + message.getTitle() + "\n" +
- "Message Content: " + message.getContentText() + "\n" +
- "Message Topic: " + message.getTopic() + "\n" +
- "Message Source: " + message.getSourceName() );
+ "Message Id: " + message.getMessageId() + "\n"
+ + "Message title: " + message.getTitle() + "\n"
+ + "Message Content: " + message.getContentText() + "\n"
+ + "Message Topic: " + message.getTopic() + "\n"
+ + "Message Source: " + message.getSourceName());
mHandler.sendMessage(msg);
- try
- {
+ try {
Log.i(TAG, "send READ syncInfo");
- mProvider.sendSyncInfo(message.getMessageId(), SyncInfo.SyncType.READ);
- }
- catch (Exception e)
- {
+ mProvider.sendSyncInfo(message.getMessageId(),
+ SyncInfo.SyncType.READ);
+ } catch (Exception e) {
Log.e(TAG, "Exception : " + e);
}
}
@Override
- public void onSyncInfoReceived(SyncInfo sync)
- {
+ public void onSyncInfoReceived(SyncInfo sync) {
Log.i(TAG, "onSyncInfoReceived");
Log.i(TAG, "Sync Id: " + sync.getMessageId());
Log.i(TAG, "Sync STATE: " + sync.getState());
Message msg = mHandler.obtainMessage(SYNCINFO_RECEIVED,
- "Sync Id: " + sync.getMessageId() + "\n" +
- "Sync STATE: " + sync.getState());
+ "Sync Id: " + sync.getMessageId() + "\n" + "Sync STATE: "
+ + sync.getState());
mHandler.sendMessage(msg);
}
}
*/
package org.iotivity.service.ns.sample.consumer;
+
import android.app.Activity;
+import android.app.Dialog;
+import android.content.Context;
import android.content.Intent;
import android.net.UrlQuerySanitizer;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
-
+import android.widget.Button;
+import android.widget.EditText;
/**
- * This class is for login to the provider.
- * Can be get auth code via web page.
+ * This class is for login to the provider. Can be get auth code via web page.
*/
public class LoginActivity extends Activity {
- private static final String TAG = "OIC_SIMPLE_LOGIN";
-
- private WebView mWebView = null;
- private final String samsungAccount = "https://account.samsung.com/mobile/account/check.do?serviceID=166135d296&actionID=StartOAuth2&countryCode="+ "US" + "&languageCode=" + "en";
- private final String mAuthProvider = "samsung-us";
-
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_login);
+ private static final String TAG = "OIC_SIMPLE_LOGIN";
+
+ private final Context context = this;
+ private WebView mWebView = null;
+ private static String loginAccount = null;
+ private static String mAuthProvider = null;
+
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_login);
+
+ final Dialog dialog = new Dialog(context);
+ dialog.setContentView(R.layout.dialog_auth);
+ dialog.setTitle("Login Details");
+ final EditText auth = (EditText) dialog.findViewById(R.id.EditTextAuth);
+ final EditText url = (EditText) dialog.findViewById(R.id.EditTextUrl);
+ if (loginAccount != null && mAuthProvider != null) {
+ url.setText(loginAccount);
+ auth.setText(mAuthProvider);
+ }
- mWebView = (WebView) findViewById(R.id.webView);
- mWebView.setInitialScale(200);
- mWebView.getSettings().setJavaScriptEnabled(true);
- mWebView.getSettings().setBuiltInZoomControls(true);
- mWebView.setWebViewClient(new WebViewClientClass());
+ Button dialogButton = (Button) dialog.findViewById(R.id.dialogButtonOK);
+ dialog.setCanceledOnTouchOutside(false);
+ dialogButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ dialog.dismiss();
+ loginAccount = url.getText().toString();
+ mAuthProvider = auth.getText().toString();
+
+ mWebView = (WebView) findViewById(R.id.webView);
+ mWebView.setInitialScale(200);
+ mWebView.getSettings().setJavaScriptEnabled(true);
+ mWebView.getSettings().setBuiltInZoomControls(true);
+ mWebView.setWebViewClient(new WebViewClientClass());
+
+ mWebView.loadUrl(loginAccount);
+ }
+ });
+ dialog.show();
+ }
- mWebView.loadUrl(samsungAccount);
- }
public void onDestroy() {
super.onDestroy();
}
private class WebViewClientClass extends WebViewClient {
@Override
- public void onPageFinished(WebView view, String url) {
- Log.i(TAG, "onPageFinished!!! Response received: called url=" + url);
+ public void onPageFinished(WebView view, String url) {
+ Log.i(TAG,
+ "onPageFinished!!! Response received: called url=" + url);
- if (url.contains("code") && url.contains("code_expires_in")) {
+ if (url.contains("code") && url.contains("code_expires_in")) {
- mWebView.setVisibility(View.INVISIBLE);
+ mWebView.setVisibility(View.INVISIBLE);
- // parsing url
- UrlQuerySanitizer sanitizer = new UrlQuerySanitizer();
- sanitizer.setAllowUnregisteredParamaters(true);
- sanitizer.parseUrl(url);
+ // parsing url
+ UrlQuerySanitizer sanitizer = new UrlQuerySanitizer();
+ sanitizer.setAllowUnregisteredParamaters(true);
+ sanitizer.parseUrl(url);
- String mAuthCode = sanitizer.getValue("code");
- Log.i(TAG, "onPageFinished!!! authCode=" + mAuthCode);
+ String mAuthCode = sanitizer.getValue("code");
+ Log.i(TAG, "onPageFinished!!! authCode=" + mAuthCode);
- Intent intent = getIntent();
- intent.putExtra("authCode", mAuthCode);
- intent.putExtra("authProvider", mAuthProvider);
- setResult(RESULT_OK, intent);
+ Intent intent = getIntent();
+ intent.putExtra("authCode", mAuthCode);
+ intent.putExtra("authProvider", mAuthProvider);
+ setResult(RESULT_OK, intent);
- finish();
- }
+ finish();
}
+ }
}
}
package org.iotivity.service.ns.sample.consumer;
+import android.app.Dialog;
+import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.widget.Button;
+import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.List;
-
-public class MainActivity extends Activity implements OcAccountManager.OnPostListener
-{
- private final String TAG = "NS_MAIN_ACTIVITY";
- private final int REQUEST_LOGIN = 1;
-
- public static final String deviceID = "9E09F4FE-978A-4BC3-B356-1F93BCA37829";
- public static final String CIServer = "coap+tcp://52.40.216.160:5683";
- public static final String RemoteAddress = "52.40.216.160:5683";
- public static final String MQCloudAddress = "52.78.151.180:5683";
- public static final String MQCloudTopic = "/oic/ps/notification";
-
- private Button btnStart;
- private Button btnStop;
- private Button btnRescan;
- private Button btnEnableRemoteService;
- private Button btnGetTopicList;
- private Button btnUpdateTopicList;
- private Button btnClearLog;
- private static TextView TvLog;
- private Button signUp, signIn, signOut;
- private Button subscribeMQ;
-
- private boolean isStarted = false;
-
- private ConsumerSample mConsumerSample = null;
- private OcAccountManager mAccountManager;
- String mAuthCode;
- String mAuthProvider;
- String mRefreshtoken;
- String mUserID;
- String mAccessToken;
-
- private static final int PROVIDER_DISCOVERED = 1;
- private static final int STATE_CHANGED = 2;
- private static final int MESSAGE_RECEIVED = 3;
- private static final int SYNCINFO_RECEIVED = 4;
- private static final int TOPICS_RECEIVED = 5;
-
- public static Handler mHandler = new Handler()
- {
+import java.util.Map;
+
+public class MainActivity extends Activity
+ implements OcAccountManager.OnPostListener {
+ private final String TAG = "NS_MAIN_ACTIVITY";
+ private final int REQUEST_LOGIN = 1;
+ private static final String CI_SERVER_PREFIX = "coap+tcp://";
+ private final Context context = this;
+
+ public static String deviceID = null;
+ public static String CIServer = null;
+ public static String RemoteAddress = null;
+ public static String MQCloudAddress = null;
+ public static String MQCloudTopic = null;
+
+ private Button btnStart;
+ private Button btnStop;
+ private Button btnRescan;
+ private Button btnEnableRemoteService;
+ private Button btnGetTopicList;
+ private Button btnUpdateTopicList;
+ private Button btnClearLog;
+ private static TextView TvLog;
+ private Button signUp, signIn, signOut;
+ private Button subscribeMQ;
+
+ private boolean isStarted = false;
+
+ private ConsumerSample mConsumerSample = null;
+ private OcAccountManager mAccountManager;
+ String mAuthCode;
+ String mAuthProvider;
+ String mRefreshtoken;
+ String mUserID;
+ String mAccessToken;
+
+ private static final int PROVIDER_DISCOVERED = 1;
+ private static final int STATE_CHANGED = 2;
+ private static final int MESSAGE_RECEIVED = 3;
+ private static final int SYNCINFO_RECEIVED = 4;
+ private static final int TOPICS_RECEIVED = 5;
+
+ public static Handler mHandler = new Handler() {
@Override
- public void handleMessage(Message msg)
- {
- switch (msg.what)
- {
- case PROVIDER_DISCOVERED:
- {
- String providerId = (String) msg.obj;
- if (providerId != null)
- {
- TvLog.append( providerId + "\n");
- }
- break;
+ public void handleMessage(Message msg) {
+ switch (msg.what) {
+ case PROVIDER_DISCOVERED: {
+ String providerId = (String) msg.obj;
+ if (providerId != null) {
+ TvLog.append(providerId + "\n");
}
- case STATE_CHANGED:
- {
- String state = (String) msg.obj;
- if (state != null)
- {
- TvLog.append( state + "\n");
- }
- break;
+ break;
+ }
+ case STATE_CHANGED: {
+ String state = (String) msg.obj;
+ if (state != null) {
+ TvLog.append(state + "\n");
}
- case MESSAGE_RECEIVED:
- {
- String message = (String) msg.obj;
- if (message != null)
- {
- TvLog.append( message + "\n");
- }
- break;
+ break;
+ }
+ case MESSAGE_RECEIVED: {
+ String message = (String) msg.obj;
+ if (message != null) {
+ TvLog.append(message + "\n");
}
- case SYNCINFO_RECEIVED:
- {
- String sync = (String) msg.obj;
- if (sync != null)
- {
- TvLog.append( sync + "\n");
- }
- break;
+ break;
+ }
+ case SYNCINFO_RECEIVED: {
+ String sync = (String) msg.obj;
+ if (sync != null) {
+ TvLog.append(sync + "\n");
}
- case TOPICS_RECEIVED:
- {
- String topicList = (String) msg.obj;
- if (topicList != null)
- {
- TvLog.append( topicList + "\n");
- }
- break;
+ break;
+ }
+ case TOPICS_RECEIVED: {
+ String topicList = (String) msg.obj;
+ if (topicList != null) {
+ TvLog.append(topicList + "\n");
}
+ break;
+ }
default:
break;
}
}
};
- public void showToast(final String toast)
- {
- runOnUiThread(new Runnable()
- {
+ public void showToast(final String toast) {
+ runOnUiThread(new Runnable() {
@Override
- public void run()
- {
- Toast.makeText(getApplicationContext(), toast, Toast.LENGTH_SHORT).show();
+ public void run() {
+ Toast.makeText(getApplicationContext(), toast,
+ Toast.LENGTH_SHORT).show();
}
});
}
@Override
- protected void onCreate(Bundle savedInstanceState)
- {
+ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnStart = (Button) findViewById(R.id.BtnStart);
btnStop = (Button) findViewById(R.id.BtnStop);
btnRescan = (Button) findViewById(R.id.BtnRescan);
- btnEnableRemoteService = (Button) findViewById(R.id.BtnEnableRemoteService);
+ btnEnableRemoteService = (Button) findViewById(
+ R.id.BtnEnableRemoteService);
btnGetTopicList = (Button) findViewById(R.id.BtnGetTopicList);
btnUpdateTopicList = (Button) findViewById(R.id.BtnUpdateTopicList);
btnClearLog = (Button) findViewById(R.id.BtnClearLog);
}
@Override
- protected void onDestroy()
- {
+ protected void onDestroy() {
if (isStarted)
mConsumerSample.stopNotificationConsumer();
super.onDestroy();
}
- Button.OnClickListener mClickListener = new View.OnClickListener()
- {
- public void onClick(View v)
- {
- switch (v.getId())
- {
- case R.id.BtnStart:
- {
- if (!isStarted)
- {
- Log.i(TAG, "Start NS Consumer Service");
-
- TvLog.setText("Start NS-Consumer\n");
- mConsumerSample.startNotificationConsumer();
- isStarted = true;
- }
- else
- {
- Log.e(TAG, "NS Consumer Service has already started");
- showToast("Error : Service has already started");
- }
+ Button.OnClickListener mClickListener = new View.OnClickListener() {
+ public void onClick(View v) {
+ switch (v.getId()) {
+ case R.id.BtnStart: {
+ if (!isStarted) {
+ Log.i(TAG, "Start NS Consumer Service");
+
+ TvLog.setText("Start NS-Consumer\n");
+ mConsumerSample.startNotificationConsumer();
+ isStarted = true;
+ } else {
+ Log.e(TAG, "NS Consumer Service has already started");
+ showToast("Error : Service has already started");
}
+ }
break;
- case R.id.BtnStop:
- {
- if (!isStarted)
- {
- Log.e(TAG, "Fail to stop service. Service has not been started");
- showToast("Error : Service has not been started");
- break;
- }
- TvLog.append("Stop NS-Consumer\n");
- mConsumerSample.stopNotificationConsumer();
- isStarted = false;
+ case R.id.BtnStop: {
+ if (!isStarted) {
+ Log.e(TAG,
+ "Fail to stop service. Service has not been started");
+ showToast("Error : Service has not been started");
+ break;
}
+ TvLog.append("Stop NS-Consumer\n");
+ mConsumerSample.stopNotificationConsumer();
+ isStarted = false;
+ }
break;
- case R.id.BtnRescan:
- {
- if (!isStarted)
- {
- Log.e(TAG, "Fail to rescan. Service has not been started");
- showToast("Error : Service has not been started");
- break;
- }
- TvLog.append("Rescan NS-Consumer\n");
- mConsumerSample.rescanProvider();
+ case R.id.BtnRescan: {
+ if (!isStarted) {
+ Log.e(TAG,
+ "Fail to rescan. Service has not been started");
+ showToast("Error : Service has not been started");
+ break;
}
+ TvLog.append("Rescan NS-Consumer\n");
+ mConsumerSample.rescanProvider();
+ }
break;
- case R.id.BtnEnableRemoteService:
- {
- if (!isStarted)
- {
- Log.e(TAG, "Fail to Enable RemoteService. Service has not been started");
- showToast("Error : Service has not been started");
- break;
- }
- TvLog.append("EnableRemoteService NS-Consumer\n");
- mConsumerSample.enableRemoteService(RemoteAddress);
+ case R.id.BtnEnableRemoteService: {
+ if (!isStarted) {
+ Log.e(TAG,
+ "Fail to Enable RemoteService. Service has not been started");
+ showToast("Error : Service has not been started");
+ break;
}
+ TvLog.append("EnableRemoteService NS-Consumer\n");
+ mConsumerSample.enableRemoteService(RemoteAddress);
+ }
break;
- case R.id.BtnGetTopicList:
- {
- if (!isStarted)
- {
- Log.e(TAG, "Fail to GetTopicList. Service has not been started");
- showToast("Error : Service has not been started");
- break;
- }
- TvLog.append("GetTopicList NS-Consumer\n");
- mConsumerSample.getTopicsList();
+ case R.id.BtnGetTopicList: {
+ if (!isStarted) {
+ Log.e(TAG,
+ "Fail to GetTopicList. Service has not been started");
+ showToast("Error : Service has not been started");
+ break;
}
+ TvLog.append("GetTopicList NS-Consumer\n");
+ mConsumerSample.getTopicsList();
+ }
break;
- case R.id.BtnUpdateTopicList:
- {
- if (!isStarted)
- {
- Log.e(TAG, "Fail to UpdateTopicList. Service has not been started");
- showToast("Error : Service has not been started");
- break;
- }
- if(mConsumerSample.getAcceptor())
- {
- Log.e(TAG, "Operation Not Allowed. ProviderService Acceptor is not Consumer");
- showToast("Operation Not Allowed. ProviderService Acceptor is not Consumer");
- break;
- }
- TvLog.append("UpdateTopicList NS-Consumer\n");
+ case R.id.BtnUpdateTopicList: {
+ if (!isStarted) {
+ Log.e(TAG,
+ "Fail to UpdateTopicList. Service has not been started");
+ showToast("Error : Service has not been started");
+ break;
+ }
+ if (mConsumerSample.getAcceptor()) {
+ Log.e(TAG,
+ "Operation Not Allowed. ProviderService Acceptor is not Consumer");
+ showToast(
+ "Operation Not Allowed. ProviderService Acceptor is not Consumer");
+ break;
+ }
+ TvLog.append("UpdateTopicList NS-Consumer\n");
- TopicsList topicList = new TopicsList();
- topicList.addTopic("OCF_TOPIC1", Topic.TopicState.SUBSCRIBED);
- topicList.addTopic("OCF_TOPIC2", Topic.TopicState.SUBSCRIBED);
- topicList.addTopic("OCF_TOPIC3", Topic.TopicState.UNSUBSCRIBED);
+ TopicsList topicList = new TopicsList();
+ topicList.addTopic("OCF_TOPIC1",
+ Topic.TopicState.SUBSCRIBED);
+ topicList.addTopic("OCF_TOPIC2",
+ Topic.TopicState.SUBSCRIBED);
+ topicList.addTopic("OCF_TOPIC3",
+ Topic.TopicState.UNSUBSCRIBED);
- mConsumerSample.updateTopicList(topicList);
- }
+ mConsumerSample.updateTopicList(topicList);
+ }
break;
- case R.id.BtnClearLog:
- {
+ case R.id.BtnClearLog: {
TvLog.setText("");
}
- break;
+ break;
case R.id.signup: {
- if(isStarted == false) {
+ if (isStarted == false) {
Log.e(TAG, "Fail to Sign Up");
showToast("Start ConsumerService First");
break;
TvLog.append("Initiating SignUp\n");
signUp();
}
- break;
+ break;
case R.id.signin: {
- if(isStarted == false) {
+ if (isStarted == false) {
Log.e(TAG, "Fail to Sign In");
showToast("Start ConsumerService First");
break;
TvLog.append("Initiating SignIn\n");
signIn();
}
- break;
+ break;
case R.id.signout: {
- if(isStarted == false) {
+ if (isStarted == false) {
Log.e(TAG, "Fail to Sign out");
showToast("Start ConsumerService First");
break;
TvLog.append("Initiating SignOut\n");
signOut();
}
- break;
+ break;
case R.id.subscribeMQService: {
- if(isStarted == false) {
+ if (isStarted == false) {
Log.e(TAG, "Fail to SubscribeMQService");
showToast("Start ProviderService First");
break;
}
- int result = mConsumerSample.subscribeMQService(MQCloudAddress, MQCloudTopic);
- TvLog.append("SubscribeMQService Result : " + result + "\n");
+ final Dialog dialog = new Dialog(context);
+ dialog.setContentView(R.layout.dialog_mq);
+ dialog.setTitle("MQ Cloud Service Details");
+
+ final EditText ip = (EditText) dialog
+ .findViewById(R.id.EditTextIp);
+ final EditText mqTopic = (EditText) dialog
+ .findViewById(R.id.EditTextMqTopic);
+ if (MQCloudAddress != null && MQCloudTopic != null) {
+ ip.setText(MQCloudAddress);
+ mqTopic.setText(MQCloudTopic);
+ }
+
+ Button dialogButton = (Button) dialog
+ .findViewById(R.id.mqButtonOK);
+
+ dialogButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ dialog.dismiss();
+ MQCloudAddress = ip.getText().toString();
+ MQCloudTopic = mqTopic.getText().toString();
+ int result = mConsumerSample.subscribeMQService(
+ MQCloudAddress, MQCloudTopic);
+ TvLog.append("SubscribeMQService Result : " + result
+ + "\n");
+ }
+ });
+ dialog.show();
}
- break;
+ break;
}
}
};
+
public void logMessage(final String text) {
runOnUiThread(new Runnable() {
public void run() {
});
Log.i(TAG, text);
}
- OcAccountManager.OnPostListener onSignUp = new OcAccountManager.OnPostListener() {
+
+ OcAccountManager.OnPostListener onSignUp = new OcAccountManager.OnPostListener() {
@Override
public synchronized void onPostCompleted(List<OcHeaderOption> list,
- OcRepresentation ocRepresentation) {
+ OcRepresentation ocRepresentation) {
logMessage("signUp was successful");
runOnUiThread(new Runnable() {
public void run() {
}
}
-
@Override
public synchronized void onPostFailed(Throwable throwable) {
logMessage("Failed to signUp");
}
}
};
- OcAccountManager.OnPostListener onSignIn = new OcAccountManager.OnPostListener() {
+
+ OcAccountManager.OnPostListener onSignIn = new OcAccountManager.OnPostListener() {
@Override
public synchronized void onPostCompleted(List<OcHeaderOption> list,
- OcRepresentation ocRepresentation) {
+ OcRepresentation ocRepresentation) {
logMessage("signIn was successful");
runOnUiThread(new Runnable() {
public void run() {
ErrorCode errCode = ocEx.getErrorCode();
logMessage("Error code: " + errCode);
if (ErrorCode.UNAUTHORIZED_REQ != errCode) {
- RefreshToken();
+ refreshToken();
}
}
}
};
+
OcAccountManager.OnPostListener onSignOut = new OcAccountManager.OnPostListener() {
@Override
public synchronized void onPostCompleted(List<OcHeaderOption> list,
- OcRepresentation ocRepresentation) {
+ OcRepresentation ocRepresentation) {
logMessage("signOut was successful");
runOnUiThread(new Runnable() {
public void run() {
ErrorCode errCode = ocEx.getErrorCode();
logMessage("Error code: " + errCode);
if (ErrorCode.UNAUTHORIZED_REQ != errCode) {
- RefreshToken();
+ refreshToken();
}
}
}
};
+
+
@Override
- public void onPostCompleted(List<OcHeaderOption> ocHeaderOptions, OcRepresentation ocRepresentation) {
+ public void onPostCompleted(List<OcHeaderOption> ocHeaderOptions,
+ OcRepresentation ocRepresentation) {
}
public void onPostFailed(Throwable throwable) {
}
+
private void signIn() {
try {
- if(mAccountManager==null)
- {
- mAccountManager = OcPlatform.constructAccountManagerObject(CIServer,
+ if (mAccountManager == null) {
+ mAccountManager = OcPlatform.constructAccountManagerObject(
+ CIServer,
EnumSet.of(OcConnectivityType.CT_ADAPTER_TCP));
}
private void signOut() {
try {
logMessage("signOut");
- if(mAccountManager==null)
- {
+ if (mAccountManager == null) {
try {
- mAccountManager = OcPlatform.constructAccountManagerObject(CIServer,
+ mAccountManager = OcPlatform.constructAccountManagerObject(
+ CIServer,
EnumSet.of(OcConnectivityType.CT_ADAPTER_TCP));
} catch (OcException e) {
e.printStackTrace();
}
private void signUp() {
- try {
- mAccountManager = OcPlatform.constructAccountManagerObject(CIServer,
- EnumSet.of(OcConnectivityType.CT_ADAPTER_TCP));
- } catch (OcException e) {
- e.printStackTrace();
- }
-
- Intent intentLogin = new Intent(this,LoginActivity.class);
+ Intent intentLogin = new Intent(this, LoginActivity.class);
startActivityForResult(intentLogin, REQUEST_LOGIN);
}
+
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
logMessage("authCode: " + mAuthCode);
logMessage("authProvider: " + mAuthProvider);
- try {
- mAccountManager = OcPlatform.constructAccountManagerObject(CIServer,
- EnumSet.of(OcConnectivityType.CT_ADAPTER_TCP));
- logMessage("Calling signup API");
-
- mAccountManager.signUp(mAuthProvider, mAuthCode, onSignUp);
- } catch (OcException e) {
- e.printStackTrace();
+ final Dialog dialog = new Dialog(context);
+ dialog.setContentView(R.layout.dialog_entry);
+ dialog.setTitle("SignUp Acccount IP Address");
+ final EditText ip = (EditText) dialog
+ .findViewById(R.id.EditTextEntry);
+ if (RemoteAddress != null) {
+ ip.setText(RemoteAddress);
}
+ Button dialogButton = (Button) dialog
+ .findViewById(R.id.entryButtonOK);
+ dialogButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ dialog.dismiss();
+ RemoteAddress = ip.getText().toString();
+ CIServer = CI_SERVER_PREFIX + RemoteAddress;
+ logMessage("server address for signup is: \n" + CIServer);
+ try {
+ mAccountManager = OcPlatform
+ .constructAccountManagerObject(CIServer, EnumSet
+ .of(OcConnectivityType.CT_ADAPTER_TCP));
+ logMessage("Calling signup API");
+
+ if (mAuthProvider.equals("samsung")
+ || mAuthProvider.equals("samsung-us")) {
+ logMessage("Auth provider is samsung");
+ Map<String, String> options = new HashMap<>();
+ options.put("auth_server_url",
+ "us-auth2.samsungosp.com");
+ options.put("api_server_url",
+ "us-auth2.samsungosp.com");
+ mAccountManager.signUp(mAuthProvider, mAuthCode,
+ options, onSignUp);
+ } else {
+ mAccountManager.signUp(mAuthProvider, mAuthCode,
+ onSignUp);
+ }
+ } catch (OcException e) {
+ e.printStackTrace();
+ }
+ }
+ });
+ dialog.show();
}
}
OcResource.OnPostListener onRefreshTokenPost = new OcResource.OnPostListener() {
@Override
- public void onPostCompleted(List<OcHeaderOption> list, OcRepresentation ocRepresentation) {
+ public void onPostCompleted(List<OcHeaderOption> list,
+ OcRepresentation ocRepresentation) {
logMessage("RefreshToken Completed.");
try {
mAccessToken = ocRepresentation.getValue("accesstoken");
mRefreshtoken = ocRepresentation.getValue("refreshtoken");
- }
- catch (OcException e)
- {
+ } catch (OcException e) {
e.printStackTrace();
}
signIn();
Log.d(TAG, "onRefreshTokenPost failed..");
}
};
- public void RefreshToken() {
+
+ public void refreshToken() {
+
+ if (deviceID == null) {
+ final Dialog dialog = new Dialog(context);
+ dialog.setContentView(R.layout.dialog_entry);
+ dialog.setTitle("Enter Device Id");
+ dialog.setCanceledOnTouchOutside(false);
+ final EditText id = (EditText) dialog
+ .findViewById(R.id.EditTextEntry);
+
+ Button dialogButton = (Button) dialog
+ .findViewById(R.id.entryButtonOK);
+ dialogButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ dialog.dismiss();
+ deviceID = id.getText().toString();
+ }
+ });
+ dialog.show();
+ }
try {
- OcResource authResource = OcPlatform.constructResourceObject(CIServer, "/.well-known/ocf/account/tokenrefresh",
- EnumSet.of(OcConnectivityType.CT_ADAPTER_TCP, OcConnectivityType.CT_IP_USE_V4),
- false, Arrays.asList("oic.wk.account"), Arrays.asList(OcPlatform.DEFAULT_INTERFACE));
+ OcResource authResource = OcPlatform.constructResourceObject(
+ CIServer, "/.well-known/ocf/account/tokenrefresh",
+ EnumSet.of(OcConnectivityType.CT_ADAPTER_TCP,
+ OcConnectivityType.CT_IP_USE_V4),
+ false, Arrays.asList("oic.wk.account"),
+ Arrays.asList(OcPlatform.DEFAULT_INTERFACE));
OcRepresentation rep = new OcRepresentation();
showToast("RefreshToken in progress..");
rep.setValue("granttype", "refresh_token");
rep.setValue("refreshtoken", mRefreshtoken);
rep.setValue("uid", mUserID);
- authResource.post(rep, new HashMap<String, String>(), onRefreshTokenPost);
- }
- catch(OcException e)
- {
+ authResource.post(rep, new HashMap<String, String>(),
+ onRefreshTokenPost);
+ } catch (OcException e) {
e.printStackTrace();
}
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent" >
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:paddingLeft="1dp"
+ android:paddingRight="1dp"
+ android:orientation="vertical" >
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:paddingLeft="5dp"
+ android:paddingRight="5dp"
+ android:orientation="horizontal" >
+
+ <Button
+ android:layout_height="wrap_content"
+ android:layout_width="wrap_content"
+ android:id="@+id/BtnAuth"
+ android:text="@string/btn_auth"
+ android:onClick="selfDestruct" />
+
+ <EditText
+ android:id="@+id/EditTextAuth"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:windowSoftInputMode="stateHidden"
+ android:hint="Add Auth Provider Name" />
+ </LinearLayout>
+
+ <LinearLayout
+ android:id="@+id/LinearBody"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:paddingLeft="5dp"
+ android:paddingRight="5dp"
+ android:orientation="horizontal" >
+
+ <Button
+ android:layout_height="wrap_content"
+ android:layout_width="wrap_content"
+ android:id="@+id/BtnUrl"
+ android:text="@string/btn_url"
+ android:onClick="selfDestruct" />
+
+ <EditText
+ android:id="@+id/EditTextUrl"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:windowSoftInputMode="stateHidden"
+ android:hint="Add Login Account URL" />
+ </LinearLayout>
+
+ <Button
+ android:layout_gravity="center_vertical|center_horizontal"
+ android:layout_height="wrap_content"
+ android:layout_width="match_parent"
+ android:id="@+id/dialogButtonOK"
+ android:text="@string/btn_ok"
+ />
+ </LinearLayout>
+
+
+</RelativeLayout>
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent" >
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:paddingLeft="1dp"
+ android:paddingRight="1dp"
+ android:orientation="vertical" >
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:paddingLeft="5dp"
+ android:paddingRight="5dp"
+ android:orientation="horizontal" >
+
+ <EditText
+ android:id="@+id/EditTextEntry"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:windowSoftInputMode="stateHidden"
+ android:hint="Add Required Details" />
+ </LinearLayout>
+
+
+ <Button
+ android:layout_gravity="center_vertical|center_horizontal"
+ android:layout_height="wrap_content"
+ android:layout_width="match_parent"
+ android:id="@+id/entryButtonOK"
+ android:text="@string/btn_ok"
+ />
+ </LinearLayout>
+
+
+</RelativeLayout>
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent" >
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:paddingLeft="1dp"
+ android:paddingRight="1dp"
+ android:orientation="vertical" >
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:paddingLeft="5dp"
+ android:paddingRight="5dp"
+ android:orientation="horizontal" >
+
+ <Button
+ android:layout_height="wrap_content"
+ android:layout_width="wrap_content"
+ android:id="@+id/BtnAuth"
+ android:text="@string/btn_addr"
+ android:onClick="selfDestruct" />
+
+ <EditText
+ android:id="@+id/EditTextIp"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:windowSoftInputMode="stateHidden"
+ android:hint="Add MQ Server IP Address" />
+ </LinearLayout>
+
+ <LinearLayout
+ android:id="@+id/LinearBody"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:paddingLeft="5dp"
+ android:paddingRight="5dp"
+ android:orientation="horizontal" >
+
+ <Button
+ android:layout_height="wrap_content"
+ android:layout_width="wrap_content"
+ android:id="@+id/BtnTopic"
+ android:text="@string/btn_topic"
+ android:onClick="selfDestruct" />
+
+ <EditText
+ android:id="@+id/EditTextMqTopic"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:windowSoftInputMode="stateHidden"
+ android:hint="Add MQ Topic name" />
+ </LinearLayout>
+
+ <Button
+ android:layout_gravity="center_vertical|center_horizontal"
+ android:layout_height="wrap_content"
+ android:layout_width="match_parent"
+ android:id="@+id/mqButtonOK"
+ android:text="@string/btn_ok"
+ />
+ </LinearLayout>
+
+
+</RelativeLayout>
\ No newline at end of file
<resources>\r
<string name="app_name">NotificationConsumerExample</string>\r
- <string name="btn_title">Title</string>\r
- <string name="btn_body">Body</string>\r
- <string name="btn_send">Send Notification</string>\r
- <string name="btn_create_noti">Create Notification</string>\r
+ <string name="btn_auth">Auth</string>\r
+ <string name="btn_url"> URL</string>\r
+ <string name="btn_ok">Enter Details</string>\r
+ <string name="btn_addr"> Addr. </string>\r
+ <string name="btn_topic">Topic</string>\r
</resources>\r
import java.util.concurrent.CountDownLatch;
class ConsumerSimulator implements ConsumerService.OnProviderDiscoveredListener,
- Provider.OnProviderStateListener , Provider.OnMessageReceivedListner,
- Provider.OnSyncInfoReceivedListner
-{
- private String TAG = "Consumer Simulator" ;
- private Provider mProvider;
+ Provider.OnProviderStateListener, Provider.OnMessageReceivedListener,
+ Provider.OnSyncInfoReceivedListener {
+ private String TAG = "Consumer Simulator";
+ private Provider mProvider;
private CountDownLatch mLockObject;
- private Response mResponse;
- private String mExpectCb;
+ private Response mResponse;
+ private String mExpectCb;
- public void set(CountDownLatch lockObject , Response response , String name)
- {
+ public void set(CountDownLatch lockObject, Response response, String name) {
Log.i(TAG, "Setting lock Simulator: ");
mLockObject = lockObject;
mResponse = response;
}
@Override
- public void onProviderDiscovered(Provider provider)
- {
+ public void onProviderDiscovered(Provider provider) {
mProvider = provider;
- try
- {
+ try {
provider.setListener(this, this, this);
- if (!provider.isSubscribed()) provider.subscribe();
- }
- catch (Exception e)
- {
+ if (!provider.isSubscribed()) {
+ provider.subscribe();
+ }
+ } catch (Exception e) {
e.printStackTrace();
}
}
@Override
- public void onProviderStateReceived(Provider.ProviderState providerState)
- {
+ public void onProviderStateReceived(Provider.ProviderState providerState) {
}
@Override
- public void onMessageReceived(Message message)
- {
- if (mExpectCb == "msg")
- {
+ public void onMessageReceived(Message message) {
+ if (mExpectCb == "msg") {
mResponse.set(true);
mLockObject.countDown();
}
}
@Override
- public void onSyncInfoReceived(SyncInfo syncInfo)
- {
- if (mExpectCb == "sync")
- {
+ public void onSyncInfoReceived(SyncInfo syncInfo) {
+ if (mExpectCb == "sync") {
mResponse.set(true);
mLockObject.countDown();
}
}
- public void sendSyncInfo(long id , SyncInfo.SyncType type)
- {
- try
- {
+ public void sendSyncInfo(long id, SyncInfo.SyncType type) {
+ try {
mProvider.sendSyncInfo(id, type);
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
e.printStackTrace();
}
}
import org.iotivity.service.ns.common.SyncInfo;
import org.iotivity.service.ns.common.Topic;
-
import android.support.test.runner.AndroidJUnit4;
import org.iotivity.service.ns.consumer.ConsumerService;
import java.util.concurrent.TimeUnit;
-
/**
* To work on unit tests, switch the Test Artifact in the Build Variants view.
*/
@RunWith(AndroidJUnit4.class)
-public class ExampleUnitTest extends ApplicationTestCase<Application>
-{
- public ExampleUnitTest()
- {
+public class ExampleUnitTest extends ApplicationTestCase<Application> {
+ public ExampleUnitTest() {
super(Application.class);
}
- private static Context mContext = null;
+ private static Context mContext = null;
private static SubscriptionCallbackListener subCb;
- private static SyncCallbackListener syncCb;
- private CountDownLatch lockObject;
- private Response response;
- private static ProviderService gProviderRes;
- private static ConsumerService gConsumerRes;
- private static ConsumerSimulator gConsumerSim;
- private static String TAG = "UnitTest ProviderService";
-
- public void start(boolean subControllability)
- {
- try
- {
+ private static SyncCallbackListener syncCb;
+ private CountDownLatch lockObject;
+ private Response response;
+ private static ProviderService gProviderRes;
+ private static ConsumerService gConsumerRes;
+ private static ConsumerSimulator gConsumerSim;
+ private static String TAG = "UnitTest ProviderService";
+
+ public void start(boolean subControllability) {
+ try {
gProviderRes.start(subCb, syncCb, subControllability, "ok", false);
gConsumerRes.start(gConsumerSim);
lockObject.await(4000, TimeUnit.MILLISECONDS);
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
e.printStackTrace();
}
}
- public org.iotivity.service.ns.common.Message createMessage()
- {
+ public org.iotivity.service.ns.common.Message createMessage() {
org.iotivity.service.ns.common.Message msg = null;
- try
- {
+ try {
msg = gProviderRes.createMessage();
msg.setTitle("Title");
msg.setSourceName("Source");
msg.setContentText("ContentText");
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
e.printStackTrace();
}
- return msg;
+ return msg;
}
- public org.iotivity.service.ns.common.Message sendMessage(boolean accepted)
- {
+ public org.iotivity.service.ns.common.Message sendMessage(
+ boolean accepted) {
lockObject = new CountDownLatch(1);
response = new Response();
org.iotivity.service.ns.common.Message msg = null;
gConsumerSim.set(lockObject, response, "msg");
- try
- {
+ try {
subCb.get().acceptSubscription(accepted);
CountDownLatch waitLock = new CountDownLatch(1);
waitLock.await(400, TimeUnit.MILLISECONDS);
- msg = createMessage();
+ msg = createMessage();
gProviderRes.sendMessage(msg);
lockObject.await(4000, TimeUnit.MILLISECONDS);
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
e.printStackTrace();
}
return msg;
}
@BeforeClass
- public static void Initialize()
- {
- PlatformConfig platformConfig = new PlatformConfig(
- mContext,
- ServiceType.IN_PROC,
- ModeType.CLIENT_SERVER,
- "0.0.0.0", // By setting to "0.0.0.0", it binds to all available interfaces
- 0, // Uses randomly available port
- QualityOfService.LOW
- );
+ public static void Initialize() {
+ PlatformConfig platformConfig = new PlatformConfig(mContext,
+ ServiceType.IN_PROC, ModeType.CLIENT_SERVER, "0.0.0.0",
+ 0, // Uses randomly available port
+ QualityOfService.LOW);
OcPlatform.Configure(platformConfig);
- try
- {
+ try {
OcPlatform.stopPresence(); // Initialize OcPlatform
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
e.printStackTrace();
}
}
@Before
- public void SetUp()
- {
+ public void SetUp() {
+ Log.i(TAG, "SetUp - IN");
subCb = new SubscriptionCallbackListener();
syncCb = new SyncCallbackListener();
- gConsumerRes = ConsumerService.getInstance();
- gProviderRes = ProviderService.getInstance();
+ gConsumerRes = ConsumerService.getInstance();
+ gProviderRes = ProviderService.getInstance();
gConsumerSim = new ConsumerSimulator();
lockObject = new CountDownLatch(1);
response = new Response();
subCb.set(lockObject, response);
-
+ Log.i(TAG, "SetUp - OUT");
}
@After
- public void TearDown()
- {
- try
- {
+ public void TearDown() {
+ Log.i(TAG, "TearDown - IN");
+ try {
gProviderRes.stop();
gConsumerRes.stop();
lockObject = new CountDownLatch(1);
lockObject.await(2000, TimeUnit.MILLISECONDS);
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
e.printStackTrace();
}
-
+ Log.i(TAG, "TearDown - OUT");
}
@Test
- public void StartProviderPositiveWithPolicyTrue()
- {
+ public void StartProviderPositiveWithPolicyTrue() {
int result = 0;
- try
- {
+ try {
result = gProviderRes.start(subCb, syncCb, true, "ok", false);
gProviderRes.stop();
- } catch (Exception e)
- {
+ } catch (Exception e) {
e.printStackTrace();
}
assertEquals(100, result);
}
@Test
- public void StartProviderPositiveWithPolicyFalse()
- {
+ public void StartProviderPositiveWithPolicyFalse() {
int result = 0;
- try
- {
+ try {
result = gProviderRes.start(subCb, syncCb, false, "ok", false);
gProviderRes.stop();
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
e.printStackTrace();
}
assertEquals(100, result);
}
@Test
- public void StopProviderPositive()
- {
+ public void StopProviderPositive() {
int result = 0;
- try
- {
+ try {
gProviderRes.start(subCb, syncCb, true, "ok", false);
result = gProviderRes.stop();
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
e.printStackTrace();
}
assertEquals(100, result);
}
@Test
- public void ExpectCallbackWhenReceiveSubscribeRequestWithAccepterProvider()
- {
+ public void ExpectCallbackWhenReceiveSubscribeRequestWithAccepterProvider() {
start(true);
assertEquals(true, response.get());
}
@Test
- public void NeverCallNotifyOnConsumerByAcceptIsFalse()
- {
+ public void NeverCallNotifyOnConsumerByAcceptIsFalse() {
start(true);
assertEquals(true, response.get());
sendMessage(false);
}
@Test
- public void ExpectCallNotifyOnConsumerByAcceptIsTrue()
- {
+ public void ExpectCallNotifyOnConsumerByAcceptIsTrue() {
start(true);
assertEquals(true, response.get());
}
@Test
- public void ExpectCallbackSyncOnReadToConsumer()
- {
+ public void ExpectCallbackSyncOnReadToConsumer() {
start(true);
assertEquals(true, response.get());
org.iotivity.service.ns.common.Message msg = sendMessage(true);
assertEquals(true, response.get());
- try
- {
+ try {
lockObject = new CountDownLatch(1);
response = new Response();
gConsumerSim.set(lockObject, response, "sync");
- gProviderRes.sendSyncInfo(msg.getMessageId(), SyncInfo.SyncType.READ);
+ gProviderRes.sendSyncInfo(msg.getMessageId(),
+ SyncInfo.SyncType.READ);
lockObject.await(4000, TimeUnit.MILLISECONDS);
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
e.printStackTrace();
}
assertEquals(true, response.get());
}
@Test
- public void ExpectCallbackSyncOnReadFromConsumer()
- {
+ public void ExpectCallbackSyncOnReadFromConsumer() {
start(true);
assertEquals(true, response.get());
org.iotivity.service.ns.common.Message msg = sendMessage(true);
assertEquals(true, response.get());
- try
- {
+ try {
lockObject = new CountDownLatch(1);
response = new Response();
syncCb.set(lockObject, response);
- gConsumerSim.sendSyncInfo(msg.getMessageId(), SyncInfo.SyncType.READ);
+ gConsumerSim.sendSyncInfo(msg.getMessageId(),
+ SyncInfo.SyncType.READ);
lockObject.await(4000, TimeUnit.MILLISECONDS);
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
e.printStackTrace();
}
}
@Test
- public void ExpectEqualAddedTopicsAndRegisteredTopics()
- {
+ public void ExpectEqualAddedTopicsAndRegisteredTopics() {
boolean isSame = true;
- String str[] = {"TOPIC1", "TOPIC2"};
- try
- {
+ String str[] = { "TOPIC1", "TOPIC2" };
+ try {
gProviderRes.start(subCb, syncCb, true, "ok", false);
gProviderRes.registerTopic(str[0]);
gProviderRes.registerTopic(str[1]);
- Vector<Topic> list = gProviderRes.getRegisteredTopicList().getTopicsList();
+ Vector<Topic> list = gProviderRes.getRegisteredTopicList()
+ .getTopicsList();
Iterator<Topic> it = list.iterator();
- if (list.size() != 2)
- {
+ if (list.size() != 2) {
isSame = false;
Log.i(TAG, "Size is " + list.size());
}
int count = 0;
- while (it.hasNext())
- {
+ while (it.hasNext()) {
Topic element = it.next();
Log.i(TAG, "element is " + element.getTopicName());
- if (! str[count].equals(element.getTopicName()))
- {
+ if (!str[count].equals(element.getTopicName())) {
isSame = false;
}
count++;
}
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
e.printStackTrace();
}
assertEquals(true, isSame);
}
@Test
- public void ExpectEqualUnregisteredTopicsAndRegisteredTopics()
- {
+ public void ExpectEqualUnregisteredTopicsAndRegisteredTopics() {
boolean isSame = true;
- String str[] = {"TOPIC1", "TOPIC2"};
- try
- {
+ String str[] = { "TOPIC1", "TOPIC2" };
+ try {
gProviderRes.start(subCb, syncCb, true, "ok", false);
gProviderRes.registerTopic(str[0]);
gProviderRes.registerTopic(str[1]);
gProviderRes.unregisterTopic(str[0]);
- Vector<Topic> list = gProviderRes.getRegisteredTopicList().getTopicsList();
+ Vector<Topic> list = gProviderRes.getRegisteredTopicList()
+ .getTopicsList();
Iterator<Topic> it = list.iterator();
- if (list.size() != 1)
- {
+ if (list.size() != 1) {
isSame = false;
Log.i(TAG, "Size is " + list.size());
}
int count = 1;
- while (it.hasNext())
- {
+ while (it.hasNext()) {
Topic element = it.next();
Log.i(TAG, "element is " + element.getTopicName());
- if (! str[count].equals(element.getTopicName()))
- {
+ if (!str[count].equals(element.getTopicName())) {
isSame = false;
}
}
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
e.printStackTrace();
}
assertEquals(true, isSame);
}
@Test
- public void ExpectEqualSetConsumerTopicsAndGetConsumerTopics()
- {
+ public void ExpectEqualSetConsumerTopicsAndGetConsumerTopics() {
boolean isSame = false;
start(true);
assertEquals(true, response.get());
- String str[] = {"TOPIC1", "TOPIC2"};
- try
- {
+ String str[] = { "TOPIC1", "TOPIC2" };
+ try {
gProviderRes.registerTopic(str[0]);
gProviderRes.registerTopic(str[1]);
subCb.get().setTopic(str[0]);
- Vector<Topic> list = subCb.get().getConsumerTopicList().getTopicsList();
+ Vector<Topic> list = subCb.get().getConsumerTopicList()
+ .getTopicsList();
Iterator<Topic> it = list.iterator();
int count = 0;
- String [] compStr = new String[10];
- Topic.TopicState [] state = new Topic.TopicState[10];
- while (it.hasNext())
- {
+ String[] compStr = new String[10];
+ Topic.TopicState[] state = new Topic.TopicState[10];
+ while (it.hasNext()) {
Topic element = it.next();
Log.i(TAG, "element is " + element.getTopicName());
compStr[count] = element.getTopicName();
state[count++] = element.getState();
}
- if (compStr[0].compareTo(str[0]) == 0 && compStr[1].compareTo(str[1]) == 0
- && state[0] == Topic.TopicState.SUBSCRIBED && state[1] == Topic.TopicState.UNSUBSCRIBED)
- {
+ if (compStr[0].compareTo(str[0]) == 0
+ && compStr[1].compareTo(str[1]) == 0
+ && state[0] == Topic.TopicState.SUBSCRIBED
+ && state[1] == Topic.TopicState.UNSUBSCRIBED) {
isSame = true;
}
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
e.printStackTrace();
}
assertEquals(true, isSame);
}
@Test
- public void ExpectEqualUnSetConsumerTopicsAndGetConsumerTopics()
- {
+ public void ExpectEqualUnSetConsumerTopicsAndGetConsumerTopics() {
boolean isSame = false;
start(true);
assertEquals(true, response.get());
- String str[] = {"TOPIC1", "TOPIC2"};
- try
- {
+ String str[] = { "TOPIC1", "TOPIC2" };
+ try {
gProviderRes.registerTopic(str[0]);
gProviderRes.registerTopic(str[1]);
subCb.get().setTopic(str[0]);
subCb.get().setTopic(str[1]);
subCb.get().unsetTopic(str[0]);
- Vector<Topic> list = subCb.get().getConsumerTopicList().getTopicsList();
+ Vector<Topic> list = subCb.get().getConsumerTopicList()
+ .getTopicsList();
Iterator<Topic> it = list.iterator();
int count = 0;
- String [] compStr = new String[10];
- Topic.TopicState [] state = new Topic.TopicState[10];
- while (it.hasNext())
- {
+ String[] compStr = new String[10];
+ Topic.TopicState[] state = new Topic.TopicState[10];
+ while (it.hasNext()) {
Topic element = it.next();
Log.i(TAG, "element is " + element.getTopicName());
compStr[count] = element.getTopicName();
state[count++] = element.getState();
}
- if (compStr[0].compareTo(str[0]) == 0 && compStr[1].compareTo(str[1]) == 0
- && state[0] == Topic.TopicState.UNSUBSCRIBED && state[1] == Topic.TopicState.SUBSCRIBED)
- {
+ if (compStr[0].compareTo(str[0]) == 0
+ && compStr[1].compareTo(str[1]) == 0
+ && state[0] == Topic.TopicState.UNSUBSCRIBED
+ && state[1] == Topic.TopicState.SUBSCRIBED) {
isSame = true;
}
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
e.printStackTrace();
}
assertEquals(true, isSame);
}
class SubscriptionCallbackListener
- implements ProviderService.OnConsumerSubscribedListener
-{
+ implements ProviderService.OnConsumerSubscribedListener {
private CountDownLatch mLockObject;
- private Response mResponse;
- private Consumer mConsumer;
- private static String TAG = "UnitTest SubscriptionCallbackListener";
+ private Response mResponse;
+ private Consumer mConsumer;
+ private static String TAG = "UnitTest SubscriptionCallbackListener";
+
@Override
- public void onConsumerSubscribed(Consumer consumer)
- {
+ public void onConsumerSubscribed(Consumer consumer) {
Log.i(TAG, "onConsumerSubscribed");
mConsumer = consumer;
- if (mResponse != null)
- {
+ if (mResponse != null) {
mResponse.set(true);
mLockObject.countDown();
}
}
- public void set(CountDownLatch lockObject,
- Response response)
- {
+
+ public void set(CountDownLatch lockObject, Response response) {
mLockObject = lockObject;
mResponse = response;
}
- public Consumer get()
- {
+
+ public Consumer get() {
return mConsumer;
}
}
class SyncCallbackListener
- implements ProviderService.OnMessageSynchronizedListener
-{
+ implements ProviderService.OnMessageSynchronizedListener {
private CountDownLatch mLockObject;
- private Response mResponse;
- private static String TAG = "UnitTest SyncCallbackListener";
+ private Response mResponse;
+ private static String TAG = "UnitTest SyncCallbackListener";
+
@Override
- public void onMessageSynchronized(SyncInfo syncInfo)
- {
+ public void onMessageSynchronized(SyncInfo syncInfo) {
Log.i(TAG, "onMessageSynchronized");
- if (mResponse != null)
- {
+ if (mResponse != null) {
mResponse.set(true);
mLockObject.countDown();
}
}
- public void set(CountDownLatch lockObject,
- Response response)
- {
+
+ public void set(CountDownLatch lockObject, Response response) {
mLockObject = lockObject;
mResponse = response;
}
}
-class Response
-{
+class Response {
private boolean state;
- Response()
- {
+
+ Response() {
state = false;
}
- public void set(boolean val)
- {
+
+ public void set(boolean val) {
state = val;
}
- public boolean get()
- {
+ public boolean get() {
return state;
}
}
*/
package org.iotivity.service.ns.sample.provider;
+
import android.app.Activity;
+import android.app.Dialog;
+import android.content.Context;
import android.content.Intent;
import android.net.UrlQuerySanitizer;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
-
+import android.widget.Button;
+import android.widget.EditText;
/**
- * This class is for login to the provider.
- * Can be get auth code via web page.
+ * This class is for login to the provider. Can be get auth code via web page.
*/
public class LoginActivity extends Activity {
- private static final String TAG = "OIC_SIMPLE_LOGIN";
-
- private WebView mWebView = null;
- private final String samsungAccount = "https://account.samsung.com/mobile/account/check.do?serviceID=166135d296&actionID=StartOAuth2&countryCode="+ "US" + "&languageCode=" + "en";
- private final String mAuthProvider = "samsung-us";
+ private static final String TAG = "OIC_SIMPLE_LOGIN";
+ private final Context context = this;
+ private WebView mWebView = null;
+ private static String loginAccount = null;
+ private static String mAuthProvider = null;
@Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_login);
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_login);
+
+ final Dialog dialog = new Dialog(context);
+ dialog.setContentView(R.layout.dialog_auth);
+ dialog.setTitle("Login Details");
+ final EditText auth = (EditText) dialog.findViewById(R.id.EditTextAuth);
+ final EditText url = (EditText) dialog.findViewById(R.id.EditTextUrl);
+ if (loginAccount != null && mAuthProvider != null) {
+ url.setText(loginAccount);
+ auth.setText(mAuthProvider);
+ }
- mWebView = (WebView) findViewById(R.id.webView);
- mWebView.setInitialScale(200);
- mWebView.getSettings().setJavaScriptEnabled(true);
- mWebView.getSettings().setBuiltInZoomControls(true);
- mWebView.setWebViewClient(new WebViewClientClass());
+ Button dialogButton = (Button) dialog.findViewById(R.id.dialogButtonOK);
+ dialog.setCanceledOnTouchOutside(false);
+ dialogButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ dialog.dismiss();
+ loginAccount = url.getText().toString();
+ mAuthProvider = auth.getText().toString();
+
+ mWebView = (WebView) findViewById(R.id.webView);
+ mWebView.setInitialScale(200);
+ mWebView.getSettings().setJavaScriptEnabled(true);
+ mWebView.getSettings().setBuiltInZoomControls(true);
+ mWebView.setWebViewClient(new WebViewClientClass());
+
+ mWebView.loadUrl(loginAccount);
+ }
+ });
+ dialog.show();
+ }
- mWebView.loadUrl(samsungAccount);
- }
public void onDestroy() {
super.onDestroy();
}
private class WebViewClientClass extends WebViewClient {
@Override
- public void onPageFinished(WebView view, String url) {
- Log.i(TAG, "onPageFinished!!! Response received: called url=" + url);
+ public void onPageFinished(WebView view, String url) {
+ Log.i(TAG,
+ "onPageFinished!!! Response received: called url=" + url);
- if (url.contains("code") && url.contains("code_expires_in")) {
+ if (url.contains("code") && url.contains("code_expires_in")) {
- mWebView.setVisibility(View.INVISIBLE);
+ mWebView.setVisibility(View.INVISIBLE);
- // parsing url
- UrlQuerySanitizer sanitizer = new UrlQuerySanitizer();
- sanitizer.setAllowUnregisteredParamaters(true);
- sanitizer.parseUrl(url);
+ // parsing url
+ UrlQuerySanitizer sanitizer = new UrlQuerySanitizer();
+ sanitizer.setAllowUnregisteredParamaters(true);
+ sanitizer.parseUrl(url);
- String mAuthCode = sanitizer.getValue("code");
- Log.i(TAG, "onPageFinished!!! authCode=" + mAuthCode);
+ String mAuthCode = sanitizer.getValue("code");
+ Log.i(TAG, "onPageFinished!!! authCode=" + mAuthCode);
- Intent intent = getIntent();
- intent.putExtra("authCode", mAuthCode);
- intent.putExtra("authProvider", mAuthProvider);
- setResult(RESULT_OK, intent);
+ Intent intent = getIntent();
+ intent.putExtra("authCode", mAuthCode);
+ intent.putExtra("authProvider", mAuthProvider);
+ setResult(RESULT_OK, intent);
- finish();
- }
+ finish();
}
+ }
}
}
package org.iotivity.service.ns.sample.provider;
+import android.app.Dialog;
import android.app.Notification;
import android.app.NotificationManager;
+import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.List;
-
-public class MainActivity extends Activity implements OcAccountManager.OnPostListener {
-
- private final String TAG = "NS_MAIN_ACTIVITY";
- private static final int CONSUMER_SUBSCRIBED = 1;
- private static final int MESSAGE_SYNC = 2;
- private final int REQUEST_LOGIN = 1;
-
- public static final String deviceID = "9E09F4FE-978A-4BC3-B356-1F93BCA37829";
- public static final String CIServer = "coap+tcp://52.40.216.160:5683";
- public static final String RemoteAddress = "52.40.216.160:5683";
- public static final String MQCloudAddress = "52.78.151.180:5683";
- public static final String MQCloudTopic = "/oic/ps/notification";
-
- private Button btnTitle;
- private Button btnBody;
- private Button btnTopic;
- private Button btnSend;
- private Button btnStart;
- private Button btnRegister;
- private Button btnSet;
- private Button btnStop;
- private Button btnLog;
- private Button signUp, signIn, signOut;
- private Button remoteService, subscribeMQ;
- private EditText editTextTitle;
- private EditText editTextBody;
- private EditText editTextTopic;
- private RadioButton radioProvider;
- private RadioButton radioConsumer;
- private static TextView TvLog;
-
- private OcAccountManager mAccountManager;
- String mAuthCode;
- String mAuthProvider;
- String mRefreshtoken;
- String mUserID;
- String mAccessToken;
-
- private static int notiId = 100;
- private boolean isStarted = false;
- private boolean gAcceptor = true;
- private boolean gRemoteService = true;
-
- private NotiListener mNotiListener = null;
- private ProviderSample mProviderSample = null;
-
- public static Handler mHandler = new Handler() {
+import java.util.Map;
+
+public class MainActivity extends Activity
+ implements OcAccountManager.OnPostListener {
+
+ private final String TAG = "NS_MAIN_ACTIVITY";
+ private static final int CONSUMER_SUBSCRIBED = 1;
+ private static final int MESSAGE_SYNC = 2;
+ private final int REQUEST_LOGIN = 1;
+ private static final String CI_SERVER_PREFIX = "coap+tcp://";
+ private final Context context = this;
+
+ public static String deviceID = null;
+ public static String CIServer = null;
+ public static String RemoteAddress = null;
+ public static String MQCloudAddress = null;
+ public static String MQCloudTopic = null;
+
+ private Button btnTitle;
+ private Button btnBody;
+ private Button btnTopic;
+ private Button btnSend;
+ private Button btnStart;
+ private Button btnRegister;
+ private Button btnSet;
+ private Button btnStop;
+ private Button btnLog;
+ private Button signUp, signIn, signOut;
+ private Button remoteService, subscribeMQ;
+ private EditText editTextTitle;
+ private EditText editTextBody;
+ private EditText editTextTopic;
+ private RadioButton radioProvider;
+ private RadioButton radioConsumer;
+ private static TextView TvLog;
+
+ private OcAccountManager mAccountManager;
+ String mAuthCode;
+ String mAuthProvider;
+ String mRefreshtoken;
+ String mUserID;
+ String mAccessToken;
+
+ private static int notiId = 100;
+ private boolean isStarted = false;
+ private boolean gAcceptor = true;
+ private boolean gRemoteService = true;
+
+ private NotiListener mNotiListener = null;
+ private ProviderSample mProviderSample = null;
+
+ public static Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case CONSUMER_SUBSCRIBED:
String ConsumerId = (String) msg.obj;
- if(ConsumerId != null)
+ if (ConsumerId != null)
TvLog.append("Consumer Subscibed: " + ConsumerId + "\n");
break;
case MESSAGE_SYNC:
String sync = (String) msg.obj;
- if(sync != null)
+ if (sync != null)
TvLog.append("SyncInfo Received :" + sync + "\n");
break;
break;
}
}
+
};
- public void showToast(final String toast)
- {
+ public void showToast(final String toast) {
runOnUiThread(new Runnable() {
@Override
public void run() {
- Toast.makeText(getApplicationContext(), toast, Toast.LENGTH_SHORT).show();
+ Toast.makeText(getApplicationContext(), toast,
+ Toast.LENGTH_SHORT).show();
}
});
}
mProviderSample.setHandler(mHandler);
mNotiListener = new NotiListener(this);
- Intent intent = new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS");
+ Intent intent = new Intent(
+ "android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS");
startActivity(intent);
}
super.onDestroy();
}
- public ProviderSample getProviderSample()
- {
+ public ProviderSample getProviderSample() {
return mProviderSample;
}
if (isStarted == false) {
gAcceptor = true;
showToast("Provider as acceptor is " + gAcceptor);
- }
- else
- showToast("Start ProviderService again to change acceptor as provider");
+ } else
+ showToast(
+ "Start ProviderService again to change acceptor as provider");
}
- break;
+ break;
case R.id.RadioConsumer: {
if (isStarted == false) {
gAcceptor = false;
- showToast("Provider as acceptor is "+ gAcceptor);
- }
- else
- showToast("Start ProviderService again to change acceptor as consumer");
+ showToast("Provider as acceptor is " + gAcceptor);
+ } else
+ showToast(
+ "Start ProviderService again to change acceptor as consumer");
}
- break;
+ break;
case R.id.BtnStart: {
if (isStarted == false) {
Log.i(TAG, "Start Provider Service");
TvLog.setText("Start Provider Service\n");
- mProviderSample.Start(gAcceptor);
+ mProviderSample.start(gAcceptor);
isStarted = true;
radioProvider.setEnabled(false);
radioConsumer.setEnabled(false);
+ // refreshToken();
+
} else {
Log.e(TAG, " Provider Service had already started");
showToast(" Provider Service had already started");
}
}
- break;
+ break;
case R.id.BtnRegister: {
if (isStarted == false) {
showToast("Start Provider Service First");
break;
}
- mProviderSample.RegisterTopic();
+ mProviderSample.registerTopic();
}
- break;
+ break;
case R.id.BtnSet: {
if (isStarted == false) {
showToast("Start Provider Service First");
break;
}
- if(gAcceptor == false){
- showToast("Operation Not Permitted: \nStart Provider Service with provider as acceptor");
+ if (gAcceptor == false) {
+ showToast(
+ "Operation Not Permitted: \nStart Provider Service with provider as acceptor");
break;
}
- mProviderSample.SetTopic();
+ mProviderSample.setTopic();
}
- break;
+ break;
case R.id.BtnCreateNoti: {
- String id = Integer.toString(notiId); // generate notificaion ID
+ String id = Integer.toString(notiId); // generate
+ // notificaion ID
String title = editTextTitle.getText().toString();
String body = editTextBody.getText().toString();
- String topic = editTextTopic.getText().toString();
+ String topic = editTextTopic.getText().toString();
- if(isStarted == false)
- {
+ if (isStarted == false) {
Log.e(TAG, "Fail to send NSMessage");
showToast("Start ProviderService First");
break;
}
- // Build android noti object and send it to Notification service receiver
- Notification.Builder notiBuilder = new Notification.Builder(getApplicationContext());
+ // Build android noti object and send it to Notification
+ // service receiver
+ Notification.Builder notiBuilder = new Notification.Builder(
+ getApplicationContext());
notiBuilder.setContentTitle(title);
notiBuilder.setContentText(body);
notiBuilder.setPriority(Notification.PRIORITY_MAX);
notiBuilder.setDefaults(Notification.DEFAULT_ALL);
notiBuilder.setSmallIcon(R.mipmap.ic_launcher);
- NotificationManager notiMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
+ NotificationManager notiMgr = (NotificationManager) getSystemService(
+ NOTIFICATION_SERVICE);
notiMgr.notify(notiId, notiBuilder.build());
Log.i(TAG, "#" + notiId + " notified ..");
TvLog.append("Send Notitication(Msg ID: " + notiId + ")\n");
notiId++;
}
- break;
+ break;
case R.id.BtnStop: {
- if(isStarted == false) {
+ if (isStarted == false) {
Log.e(TAG, "Fail to stop service");
showToast("Already Stopped");
break;
}
- mProviderSample.Stop();
+ mProviderSample.stop();
isStarted = false;
radioProvider.setEnabled(true);
radioConsumer.setEnabled(true);
- showToast("Stopped ProviderService"+ isStarted);
+ showToast("Stopped ProviderService" + isStarted);
TvLog.append("Stop Provider Service\n");
}
- break;
+ break;
case R.id.BtnLog: {
TvLog.setText("");
}
- break;
+ break;
case R.id.signup: {
- if(isStarted == false) {
+ if (isStarted == false) {
Log.e(TAG, "Fail to Sign Up");
showToast("Start ProviderService First");
break;
TvLog.append("Initiating SignUp\n");
signUp();
}
- break;
+ break;
case R.id.signin: {
- if(isStarted == false) {
+ if (isStarted == false) {
Log.e(TAG, "Fail to Sign In");
showToast("Start ProviderService First");
break;
TvLog.append("Initiating SignIn\n");
signIn();
}
- break;
+ break;
case R.id.signout: {
- if(isStarted == false) {
+ if (isStarted == false) {
Log.e(TAG, "Fail to Sign out");
showToast("Start ProviderService First");
break;
TvLog.append("Initiating SignOut\n");
signOut();
}
- break;
+ break;
case R.id.remoteService: {
remoteService.setEnabled(false);
- if(isStarted == false) {
+ if (isStarted == false) {
Log.e(TAG, "Fail to Enable/Disable RemoteService");
showToast("Start ProviderService First");
break;
}
- if(gRemoteService){
+ if (gRemoteService) {
TvLog.append("Enable Remote Service\n");
- int result = mProviderSample.EnableRemoteService(RemoteAddress);
+ int result = mProviderSample
+ .enableRemoteService(RemoteAddress);
remoteService.setText(R.string.disableRemoteService);
gRemoteService = false;
remoteService.setEnabled(true);
- TvLog.append("EnableRemoteService Result : " + result + "\n");
- }
- else {
+ TvLog.append("EnableRemoteService Result : " + result
+ + "\n");
+ } else {
TvLog.append("Disable Remote Service\n");
- int result = mProviderSample.DisableRemoteService(RemoteAddress);
+ int result = mProviderSample
+ .disableRemoteService(RemoteAddress);
remoteService.setText(R.string.enableRemoteService);
gRemoteService = true;
remoteService.setEnabled(true);
- TvLog.append("DisableRemoteService Result : " + result + "\n");
+ TvLog.append("DisableRemoteService Result : " + result
+ + "\n");
}
}
- break;
+ break;
case R.id.subscribeMQService: {
- if(isStarted == false) {
+ if (isStarted == false) {
Log.e(TAG, "Fail to SubscribeMQService");
showToast("Start ProviderService First");
break;
}
- int result = mProviderSample.subscribeMQService(MQCloudAddress, MQCloudTopic);
- TvLog.append("SubscribeMQService Result : " + result + "\n");
+ final Dialog dialog = new Dialog(context);
+ dialog.setContentView(R.layout.dialog_mq);
+ dialog.setTitle("MQ Cloud Service Details");
+
+ final EditText ip = (EditText) dialog
+ .findViewById(R.id.EditTextIp);
+ final EditText mqTopic = (EditText) dialog
+ .findViewById(R.id.EditTextMqTopic);
+ if (MQCloudAddress != null && MQCloudTopic != null) {
+ ip.setText(MQCloudAddress);
+ mqTopic.setText(MQCloudTopic);
+ }
+
+ Button dialogButton = (Button) dialog
+ .findViewById(R.id.mqButtonOK);
+
+ dialogButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ dialog.dismiss();
+ MQCloudAddress = ip.getText().toString();
+ MQCloudTopic = mqTopic.getText().toString();
+ int result = mProviderSample.subscribeMQService(
+ MQCloudAddress, MQCloudTopic);
+ TvLog.append("SubscribeMQService Result : " + result
+ + "\n");
+ }
+ });
+ dialog.show();
}
- break;
+ break;
}
}
};
+
public void logMessage(final String text) {
runOnUiThread(new Runnable() {
public void run() {
});
Log.i(TAG, text);
}
- OcAccountManager.OnPostListener onSignUp = new OcAccountManager.OnPostListener() {
+
+ OcAccountManager.OnPostListener onSignUp = new OcAccountManager.OnPostListener() {
@Override
public synchronized void onPostCompleted(List<OcHeaderOption> list,
- OcRepresentation ocRepresentation) {
+ OcRepresentation ocRepresentation) {
logMessage("signUp was successful");
runOnUiThread(new Runnable() {
public void run() {
}
}
-
@Override
public synchronized void onPostFailed(Throwable throwable) {
logMessage("Failed to signUp");
}
}
};
- OcAccountManager.OnPostListener onSignIn = new OcAccountManager.OnPostListener() {
+
+ OcAccountManager.OnPostListener onSignIn = new OcAccountManager.OnPostListener() {
@Override
public synchronized void onPostCompleted(List<OcHeaderOption> list,
- OcRepresentation ocRepresentation) {
+ OcRepresentation ocRepresentation) {
logMessage("signIn was successful");
runOnUiThread(new Runnable() {
public void run() {
remoteService.setEnabled(true);
}
});
-
}
@Override
ErrorCode errCode = ocEx.getErrorCode();
logMessage("Error code: " + errCode);
if (ErrorCode.UNAUTHORIZED_REQ != errCode) {
- RefreshToken();
+ refreshToken();
}
}
}
};
+
OcAccountManager.OnPostListener onSignOut = new OcAccountManager.OnPostListener() {
@Override
public synchronized void onPostCompleted(List<OcHeaderOption> list,
- OcRepresentation ocRepresentation) {
+ OcRepresentation ocRepresentation) {
logMessage("signOut was successful");
runOnUiThread(new Runnable() {
public void run() {
ErrorCode errCode = ocEx.getErrorCode();
logMessage("Error code: " + errCode);
if (ErrorCode.UNAUTHORIZED_REQ != errCode) {
- RefreshToken();
+ refreshToken();
}
}
}
};
+
@Override
- public void onPostCompleted(List<OcHeaderOption> ocHeaderOptions, OcRepresentation ocRepresentation) {
+ public void onPostCompleted(List<OcHeaderOption> ocHeaderOptions,
+ OcRepresentation ocRepresentation) {
}
public void onPostFailed(Throwable throwable) {
}
+
private void signIn() {
try {
- if(mAccountManager==null)
- {
- mAccountManager = OcPlatform.constructAccountManagerObject(CIServer,
+ if (mAccountManager == null) {
+ mAccountManager = OcPlatform.constructAccountManagerObject(
+ CIServer,
EnumSet.of(OcConnectivityType.CT_ADAPTER_TCP));
}
private void signOut() {
try {
logMessage("signOut");
- if(mAccountManager==null)
- {
+ if (mAccountManager == null) {
try {
- mAccountManager = OcPlatform.constructAccountManagerObject(CIServer,
+ mAccountManager = OcPlatform.constructAccountManagerObject(
+ CIServer,
EnumSet.of(OcConnectivityType.CT_ADAPTER_TCP));
} catch (OcException e) {
e.printStackTrace();
}
private void signUp() {
- try {
- mAccountManager = OcPlatform.constructAccountManagerObject(CIServer,
- EnumSet.of(OcConnectivityType.CT_ADAPTER_TCP));
- } catch (OcException e) {
- e.printStackTrace();
- }
-
Intent intentLogin = new Intent(this, LoginActivity.class);
startActivityForResult(intentLogin, REQUEST_LOGIN);
}
+
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
logMessage("authCode: " + mAuthCode);
logMessage("authProvider: " + mAuthProvider);
- try {
- mAccountManager = OcPlatform.constructAccountManagerObject(CIServer,
- EnumSet.of(OcConnectivityType.CT_ADAPTER_TCP));
- logMessage("Calling signup API");
-
- mAccountManager.signUp(mAuthProvider, mAuthCode, onSignUp);
- } catch (OcException e) {
- e.printStackTrace();
+ final Dialog dialog = new Dialog(context);
+ dialog.setContentView(R.layout.dialog_entry);
+ dialog.setTitle("SignUp Acccount IP Address");
+ final EditText ip = (EditText) dialog
+ .findViewById(R.id.EditTextEntry);
+ if (RemoteAddress != null) {
+ ip.setText(RemoteAddress);
}
+ Button dialogButton = (Button) dialog
+ .findViewById(R.id.entryButtonOK);
+ dialogButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ dialog.dismiss();
+ RemoteAddress = ip.getText().toString();
+ CIServer = CI_SERVER_PREFIX + RemoteAddress;
+ logMessage("server address for signup is: \n" + CIServer);
+ try {
+ mAccountManager = OcPlatform
+ .constructAccountManagerObject(CIServer, EnumSet
+ .of(OcConnectivityType.CT_ADAPTER_TCP));
+ logMessage("Calling signup API");
+
+ if (mAuthProvider.equals("samsung")
+ || mAuthProvider.equals("samsung-us"))
+
+ {
+ logMessage("Auth provider is samsung");
+ Map<String, String> options = new HashMap<>();
+ options.put("auth_server_url",
+ "us-auth2.samsungosp.com");
+ options.put("api_server_url",
+ "us-auth2.samsungosp.com");
+ mAccountManager.signUp(mAuthProvider, mAuthCode,
+ options, onSignUp);
+ } else {
+ mAccountManager.signUp(mAuthProvider, mAuthCode,
+ onSignUp);
+ }
+ } catch (OcException e) {
+ e.printStackTrace();
+ }
+ }
+ });
+ dialog.show();
}
}
OcResource.OnPostListener onRefreshTokenPost = new OcResource.OnPostListener() {
@Override
- public void onPostCompleted(List<OcHeaderOption> list, OcRepresentation ocRepresentation) {
+ public void onPostCompleted(List<OcHeaderOption> list,
+ OcRepresentation ocRepresentation) {
logMessage("RefreshToken Completed.");
try {
mAccessToken = ocRepresentation.getValue("accesstoken");
mRefreshtoken = ocRepresentation.getValue("refreshtoken");
- }
- catch (OcException e)
- {
+ } catch (OcException e) {
e.printStackTrace();
}
signIn();
Log.d(TAG, "onRefreshTokenPost failed.");
}
};
- public void RefreshToken() {
+
+ public void refreshToken() {
+
+ if (deviceID == null) {
+ final Dialog dialog = new Dialog(context);
+ dialog.setContentView(R.layout.dialog_entry);
+ dialog.setTitle("Enter Device Id");
+ dialog.setCanceledOnTouchOutside(false);
+ final EditText id = (EditText) dialog
+ .findViewById(R.id.EditTextEntry);
+
+ Button dialogButton = (Button) dialog
+ .findViewById(R.id.entryButtonOK);
+ dialogButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ dialog.dismiss();
+ deviceID = id.getText().toString();
+ }
+ });
+ dialog.show();
+ }
try {
- OcResource authResource = OcPlatform.constructResourceObject(CIServer, "/.well-known/ocf/account/tokenrefresh",
- EnumSet.of(OcConnectivityType.CT_ADAPTER_TCP, OcConnectivityType.CT_IP_USE_V4),
- false, Arrays.asList("oic.wk.account"), Arrays.asList(OcPlatform.DEFAULT_INTERFACE));
+ OcResource authResource = OcPlatform.constructResourceObject(
+ CIServer, "/.well-known/ocf/account/tokenrefresh",
+ EnumSet.of(OcConnectivityType.CT_ADAPTER_TCP,
+ OcConnectivityType.CT_IP_USE_V4),
+ false, Arrays.asList("oic.wk.account"),
+ Arrays.asList(OcPlatform.DEFAULT_INTERFACE));
OcRepresentation rep = new OcRepresentation();
showToast("RefreshToken in progress..");
rep.setValue("granttype", "refresh_token");
rep.setValue("refreshtoken", mRefreshtoken);
rep.setValue("uid", mUserID);
- authResource.post(rep, new HashMap<String, String>(), onRefreshTokenPost);
- }
- catch(OcException e)
- {
+ authResource.post(rep, new HashMap<String, String>(),
+ onRefreshTokenPost);
+ } catch (OcException e) {
e.printStackTrace();
}
Log.d(TAG, "No error while executing login");
}
}
-
public class NotiListener extends NotificationListenerService {
- private final String TAG = "NS_JNI_NOTI_LISTENER";
- private static ProviderSample mProviderSample = null;
- private MainActivity mActivity = null;
- ArrayList mBlackSourceList = new ArrayList<String>();
+ private final String TAG = "NS_JNI_NOTI_LISTENER";
+ private static ProviderSample mProviderSample = null;
+ private MainActivity mActivity = null;
+ ArrayList mBlackSourceList = new ArrayList<String>();
public NotiListener() {
setBlackSourceList();
- if(mProviderSample == null) {
+ if (mProviderSample == null) {
Log.i(TAG, "Fail to get providerProxy instance");
}
}
@Override
public void onNotificationPosted(StatusBarNotification sbn) {
super.onNotificationPosted(sbn);
+ Log.i(TAG, "Notification posted By package" + sbn.getPackageName());
Bundle bundle = sbn.getNotification().extras;
String source = null;
// prevent not to send notification
- for(int i = 0; i < mBlackSourceList.size(); ++i)
- {
- if (sbn.getPackageName().equals(mBlackSourceList.get(i)))
- {
+ for (int i = 0; i < mBlackSourceList.size(); ++i) {
+ if (sbn.getPackageName().equals(mBlackSourceList.get(i))) {
return;
}
}
// filter exception case : Some notification are generated twice
- if(sbn.getId() > 10000 || sbn.getId() < 0)
+ if (sbn.getId() > 10000 || sbn.getId() < 0) {
return;
+ }
// Temporary protocol code to display ICON on consumer app.
- // For example, consumer app shows KAKAOTALK Icon when receiving Notification with SOURCE
- // that is set to KAKAO, otherwise it displays OCF Icon on current sample app.
- if(sbn.getPackageName().equals("com.kakao.talk"))
+ // For example, consumer app shows KAKAOTALK Icon when receiving
+ // Notification with SOURCE
+ // that is set to KAKAO, otherwise it displays OCF Icon on current
+ // sample app.
+ if (sbn.getPackageName().equals("com.kakao.talk")) {
source = "KAKAO";
- else
+ }
+ else {
source = "OCF";
+ }
Log.i(TAG, "Noti. Package Name : " + sbn.getPackageName());
Log.i(TAG, "Noti. ID : " + sbn.getId());
Log.i(TAG, "Title : " + title);
Log.i(TAG, "Body : " + body);
- Message notiMessage = new Message(title,body,source);
+ Message notiMessage = new Message(title, body, source);
notiMessage.setTTL(10);
notiMessage.setTime("12:10");
MediaContents media = new MediaContents("daasd");
notiMessage.setMediaContents(media);
if (mProviderSample != null) {
- mProviderSample.SendMessage(notiMessage);
+ mProviderSample.sendMessage(notiMessage);
} else {
Log.i(TAG, "providerExample is NULL");
}
Bundle bundle = sbn.getNotification().extras;
- if (sbn.getPackageName().equals("android"))
+ if (sbn.getPackageName().equals("android")) {
return;
+ }
Log.i(TAG, "Noti. Package Name : " + sbn.getPackageName());
Log.i(TAG, "Noti. ID : " + sbn.getId());
- if(mProviderSample.getMsgMap().containsKey(sbn.getId()))
- {
- if(mProviderSample.getMsgMap().get(sbn.getId()) == 2)
- {
+ if (mProviderSample.getMsgMap().containsKey(sbn.getId())) {
+ if (mProviderSample.getMsgMap().get(sbn.getId()) == 2) {
org.iotivity.service.ns.common.SyncInfo.SyncType type = org.iotivity.service.ns.common.SyncInfo.SyncType.READ;
- mProviderSample.SendSyncInfo(1,type);
+ mProviderSample.sendSyncInfo(1, type);
}
}
}
import org.iotivity.service.ns.provider.*;
import org.iotivity.service.ns.common.*;
-
import java.util.HashMap;
public class ProviderSample
- implements ProviderService.OnConsumerSubscribedListener, ProviderService.OnMessageSynchronizedListener{
+ implements ProviderService.OnConsumerSubscribedListener,
+ ProviderService.OnMessageSynchronizedListener {
- private static final String TAG = "NS_PROVIDER_PROXY";
+ private static final String TAG = "NS_PROVIDER_SAMPLE";
- private Context mContext = null;
- private OcResourceHandle mResourceHandle; //resource handle
- private ProviderService ioTNotification = null;
+ private Context mContext = null;
+ private OcResourceHandle mResourceHandle;
+ private ProviderService ioTNotification = null;
private HashMap<String, Integer> msgMap;
- private Handler mHandler = null;
+ private Handler mHandler = null;
- private static final int CONSUMER_SUBSCRIBED = 1;
- private static final int MESSAGE_SYNC = 2;
+ private static final int CONSUMER_SUBSCRIBED = 1;
+ private static final int MESSAGE_SYNC = 2;
- private static final int SYNC_READ = 0;
- private static final int SYNC_DISMISS = 1;
- private static final int SYNC_UNREAD = 2;
- private boolean gAcceptor;
- private Consumer gConsumer;
+ private static final int SYNC_READ = 0;
+ private static final int SYNC_DISMISS = 1;
+ private static final int SYNC_UNREAD = 2;
+ private boolean gAcceptor;
+ private Consumer gConsumer;
public ProviderSample(Context context) {
Log.i(TAG, "Create providerSample Instance");
this.msgMap = new HashMap<>();
this.mContext = context;
- ioTNotification = ProviderService.getInstance();
+ ioTNotification = ProviderService.getInstance();
}
- public void setHandler(Handler handler)
- {
+ public void setHandler(Handler handler) {
this.mHandler = handler;
}
private void configurePlatform() {
- PlatformConfig platformConfig = new PlatformConfig(
- mContext,
- ServiceType.IN_PROC,
- ModeType.CLIENT_SERVER,
- "0.0.0.0", // By setting to "0.0.0.0", it binds to all available interfaces
- 0, // Uses randomly available port
- QualityOfService.LOW
- );
+ PlatformConfig platformConfig = new PlatformConfig(mContext,
+ ServiceType.IN_PROC, ModeType.CLIENT_SERVER, "0.0.0.0",
+ 0, // Uses randomly available port
+ QualityOfService.LOW);
Log.i(TAG, "Configuring platform.");
OcPlatform.Configure(platformConfig);
try {
OcPlatform.stopPresence(); // Initialize OcPlatform
- } catch(Exception e) {
- Log.e(TAG, "Exception: stopping presence when configuration step: " + e);
+ } catch (Exception e) {
+ Log.e(TAG, "Exception: stopping presence when configuration step: "
+ + e);
}
Log.i(TAG, "Configuration done Successfully");
}
- public void Start(boolean policy)
- {
+ public void start(boolean policy) {
Log.i(TAG, "Start ProviderService -IN");
configurePlatform();
gAcceptor = policy;
- try{
- int result = ioTNotification.start(this, this, policy, "Info", false);
+ try {
+ int result = ioTNotification.start(this, this, policy, "Info",
+ false);
Log.i(TAG, "Notification Start: " + result);
- }
- catch(Exception e){
+ } catch (Exception e) {
}
Log.i(TAG, "Start ProviderService - OUT");
}
- public void RegisterTopic()
- {
+ public void registerTopic() {
Log.i(TAG, "Register Topics -IN");
- try{
- int result = ioTNotification.registerTopic("OCF_TOPIC1");
+ try {
+ int result = ioTNotification.registerTopic("OCF_TOPIC1");
Log.i(TAG, " RegisterTopic: " + result);
- result = ioTNotification.registerTopic("OCF_TOPIC2");
+ result = ioTNotification.registerTopic("OCF_TOPIC2");
Log.i(TAG, " RegisterTopic: " + result);
- result = ioTNotification.registerTopic("OCF_TOPIC3");
+ result = ioTNotification.registerTopic("OCF_TOPIC3");
Log.i(TAG, " RegisterTopic: " + result);
- result = ioTNotification.registerTopic("OCF_TOPIC4");
+ result = ioTNotification.registerTopic("OCF_TOPIC4");
Log.i(TAG, " RegisterTopic: " + result);
- }
- catch(Exception e){
+ } catch (Exception e) {
}
Log.i(TAG, "Start ProviderService - OUT");
}
- public int SetTopic()
- {
+ public int setTopic() {
Log.i(TAG, "Set Topic -IN");
- if(gConsumer == null){
+ if (gConsumer == null) {
return 0;
}
- try{
- int result = gConsumer.setTopic("OCF_TOPIC1");
+ try {
+ int result = gConsumer.setTopic("OCF_TOPIC1");
Log.i(TAG, " Set Topic : " + result);
- result = gConsumer.setTopic("OCF_TOPIC2");
+ result = gConsumer.setTopic("OCF_TOPIC2");
Log.i(TAG, " Set Topic : " + result);
- result = gConsumer.setTopic("OCF_TOPIC3");
+ result = gConsumer.setTopic("OCF_TOPIC3");
Log.i(TAG, " Set Topic : " + result);
- result = gConsumer.setTopic("OCF_TOPIC4");
+ result = gConsumer.setTopic("OCF_TOPIC4");
Log.i(TAG, " Set Topic : " + result);
- }
- catch(Exception e){
+ } catch (Exception e) {
}
return 1;
}
- public void Stop() {
+ public void stop() {
Log.i(TAG, "Stop ProviderService - IN");
try {
OcPlatform.stopPresence();
} catch (Exception e) {
- Log.e(TAG, "Exception: stopping presence when terminating NS server: " + e);
+ Log.e(TAG,
+ "Exception: stopping presence when terminating NS server: "
+ + e);
}
- try{
- int result = ioTNotification.stop();
+ try {
+ int result = ioTNotification.stop();
Log.i(TAG, "Notification Stop: " + result);
- }
- catch(Exception e){
+ } catch (Exception e) {
}
Log.i(TAG, "Stop ProviderService - OUT");
}
-
- public void SendMessage(Message notiMessage) {
+ public void sendMessage(Message notiMessage) {
Log.i(TAG, "SendMessage ProviderService - IN");
- try{
- int result = ioTNotification.sendMessage(notiMessage);
+ try {
+ int result = ioTNotification.sendMessage(notiMessage);
Log.i(TAG, "Notification Send Message: " + result);
- }
- catch(Exception e){
+ } catch (Exception e) {
}
mHandler.post(new Runnable() {
@Override
public void run() {
- Toast.makeText(mContext, "Notification sent", Toast.LENGTH_SHORT).show();
+ Toast.makeText(mContext, "Notification sent",
+ Toast.LENGTH_SHORT).show();
}
});
}
- public void SendSyncInfo(long messageId, SyncInfo.SyncType syncType) {
+ public void sendSyncInfo(long messageId, SyncInfo.SyncType syncType) {
Log.i(TAG, "SendSyncInfo ProviderService - IN");
- if(msgMap.containsKey(messageId)) {
- if(msgMap.get(messageId) == SYNC_UNREAD)
- {
- try{
+ if (msgMap.containsKey(messageId)) {
+ if (msgMap.get(messageId) == SYNC_UNREAD) {
+ try {
ioTNotification.sendSyncInfo(messageId, syncType);
- Log.i(TAG, "Notification Sync " );
- }
- catch(Exception e) {
+ Log.i(TAG, "Notification Sync ");
+ } catch (Exception e) {
}
Log.i(TAG, "SendSyncInfo ProviderService - OUT");
- msgMap.put("ID: "+messageId, SYNC_READ);
+ msgMap.put("ID: " + messageId, SYNC_READ);
}
}
}
- public int EnableRemoteService(String servAdd) {
+ public int enableRemoteService(String servAdd) {
Log.i(TAG, "EnableRemoteService ProviderService - IN");
int result = 0;
- try{
+ try {
result = ioTNotification.enableRemoteService(servAdd);
- Log.i(TAG, "Notification EnableRemoteService: "+ result );
- }
- catch(Exception e) {
+ Log.i(TAG, "Notification EnableRemoteService: " + result);
+ } catch (Exception e) {
}
Log.i(TAG, "EnableRemoteService ProviderService - OUT");
return result;
}
- public int DisableRemoteService(String servAdd) {
+ public int disableRemoteService(String servAdd) {
Log.i(TAG, "DisableRemoteService ProviderService - IN");
int result = 0;
- try{
+ try {
result = ioTNotification.disableRemoteService(servAdd);
- Log.i(TAG, "Notification DisableRemoteService: "+ result );
- }
- catch(Exception e) {
+ Log.i(TAG, "Notification DisableRemoteService: " + result);
+ } catch (Exception e) {
}
Log.i(TAG, "DisableRemoteService ProviderService - OUT");
return result;
}
+
public int subscribeMQService(String servAdd, String topicName) {
Log.i(TAG, "SubscribeMQService ProviderService - IN");
int result = 0;
- try{
+ try {
result = ioTNotification.subscribeMQService(servAdd, topicName);
- Log.i(TAG, "Notification SubscribeMQService: "+ result );
- }
- catch(Exception e) {
-
+ Log.i(TAG, "Notification SubscribeMQService: " + result);
+ } catch (Exception e) {
+ Log.e(TAG, "Exception: subscribeMQService : " + e);
}
Log.i(TAG, "SubscribeMQService ProviderService - OUT");
return result;
}
- public void AcceptSubscription(Consumer consumer, boolean accepted)
- {
- Log.i(TAG,"AcceptSubscription ProviderService - IN");
- try{
+
+ public void acceptSubscription(Consumer consumer, boolean accepted) {
+ Log.i(TAG, "AcceptSubscription ProviderService - IN");
+ try {
int result = consumer.acceptSubscription(accepted);
- Log.i(TAG, "Notification AcceptSubscription: "+result );
- }
- catch(Exception e) {
+ Log.i(TAG, "Notification AcceptSubscription: " + result);
+ } catch (Exception e) {
}
Log.i(TAG, "AcceptSubscription ProviderService - OUT");
public void onConsumerSubscribed(Consumer consumer) {
Log.i(TAG, "onConsumerSubscribed - IN");
gConsumer = consumer;
- AcceptSubscription(consumer, true);
+ acceptSubscription(consumer, true);
android.os.Message msg = mHandler.obtainMessage(CONSUMER_SUBSCRIBED,
- "Consumer Id: " + consumer.getConsumerId() );
+ "Consumer Id: " + consumer.getConsumerId());
mHandler.sendMessage(msg);
Log.i(TAG, "onConsumerSubscribed - OUT");
}
@Override
public void onMessageSynchronized(SyncInfo syncInfo) {
- Log.i(TAG, "Received SyncInfo with messageID: "+syncInfo.getMessageId());
+ Log.i(TAG,
+ "Received SyncInfo with messageID: " + syncInfo.getMessageId());
android.os.Message msg = mHandler.obtainMessage(MESSAGE_SYNC,
- "Message Id: " + syncInfo.getMessageId() );
+ "Message Id: " + syncInfo.getMessageId());
mHandler.sendMessage(msg);
}
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent" >
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:paddingLeft="1dp"
+ android:paddingRight="1dp"
+ android:orientation="vertical" >
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:paddingLeft="5dp"
+ android:paddingRight="5dp"
+ android:orientation="horizontal" >
+
+ <Button
+ android:layout_height="wrap_content"
+ android:layout_width="wrap_content"
+ android:id="@+id/BtnAuth"
+ android:text="@string/btn_auth"
+ android:onClick="selfDestruct" />
+
+ <EditText
+ android:id="@+id/EditTextAuth"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:windowSoftInputMode="stateHidden"
+ android:hint="Add Auth Provider Name" />
+ </LinearLayout>
+
+ <LinearLayout
+ android:id="@+id/LinearBody"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:paddingLeft="5dp"
+ android:paddingRight="5dp"
+ android:orientation="horizontal" >
+
+ <Button
+ android:layout_height="wrap_content"
+ android:layout_width="wrap_content"
+ android:id="@+id/BtnUrl"
+ android:text="@string/btn_url"
+ android:onClick="selfDestruct" />
+
+ <EditText
+ android:id="@+id/EditTextUrl"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:windowSoftInputMode="stateHidden"
+ android:hint="Add Login Account URL" />
+ </LinearLayout>
+
+ <Button
+ android:layout_gravity="center_vertical|center_horizontal"
+ android:layout_height="wrap_content"
+ android:layout_width="match_parent"
+ android:id="@+id/dialogButtonOK"
+ android:text="@string/btn_ok"
+ />
+ </LinearLayout>
+
+
+</RelativeLayout>
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent" >
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:paddingLeft="1dp"
+ android:paddingRight="1dp"
+ android:orientation="vertical" >
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:paddingLeft="5dp"
+ android:paddingRight="5dp"
+ android:orientation="horizontal" >
+
+ <EditText
+ android:id="@+id/EditTextEntry"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:windowSoftInputMode="stateHidden"
+ android:hint="Add Required Details" />
+ </LinearLayout>
+
+
+ <Button
+ android:layout_gravity="center_vertical|center_horizontal"
+ android:layout_height="wrap_content"
+ android:layout_width="match_parent"
+ android:id="@+id/entryButtonOK"
+ android:text="@string/btn_ok"
+ />
+ </LinearLayout>
+
+
+</RelativeLayout>
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent" >
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:paddingLeft="1dp"
+ android:paddingRight="1dp"
+ android:orientation="vertical" >
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:paddingLeft="5dp"
+ android:paddingRight="5dp"
+ android:orientation="horizontal" >
+
+ <Button
+ android:layout_height="wrap_content"
+ android:layout_width="wrap_content"
+ android:id="@+id/BtnAuth"
+ android:text="@string/btn_addr"
+ android:onClick="selfDestruct" />
+
+ <EditText
+ android:id="@+id/EditTextIp"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:windowSoftInputMode="stateHidden"
+ android:hint="Add MQ Server IP Address" />
+ </LinearLayout>
+
+ <LinearLayout
+ android:id="@+id/LinearBody"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:paddingLeft="5dp"
+ android:paddingRight="5dp"
+ android:orientation="horizontal" >
+
+ <Button
+ android:layout_height="wrap_content"
+ android:layout_width="wrap_content"
+ android:id="@+id/BtnTopic"
+ android:text="@string/btn_topic"
+ android:onClick="selfDestruct" />
+
+ <EditText
+ android:id="@+id/EditTextMqTopic"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:windowSoftInputMode="stateHidden"
+ android:hint="Add MQ Topic name" />
+ </LinearLayout>
+
+ <Button
+ android:layout_gravity="center_vertical|center_horizontal"
+ android:layout_height="wrap_content"
+ android:layout_width="match_parent"
+ android:id="@+id/mqButtonOK"
+ android:text="@string/btn_ok"
+ />
+ </LinearLayout>
+
+
+</RelativeLayout>
\ No newline at end of file
<string name="btn_log">Clear Logs</string>\r
<string name="enableRemoteService">Enable Remote Service</string>\r
<string name="disableRemoteService">Disable Remote Service</string>\r
+ <string name="btn_auth">Auth</string>\r
+ <string name="btn_url"> URL</string>\r
+ <string name="btn_addr"> Addr. </string>\r
+ <string name="btn_ok">Enter Details</string>\r
</resources>\r