[IOT-1679] Modify package name for notification consumer and provider sample.
authornikhil.a <nikhil.a7@samsung.com>
Fri, 16 Dec 2016 06:10:56 +0000 (11:40 +0530)
committerUze Choi <uzchoi@samsung.com>
Mon, 19 Dec 2016 10:24:17 +0000 (10:24 +0000)
Change-Id: I3501d0cf0cdf3f360b86836868dbf1b2243bdfcf
Signed-off-by: nikhil.a <nikhil.a7@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/15607
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
18 files changed:
service/notification/examples/android/NotiConsumerExample/SConscript
service/notification/examples/android/NotiConsumerExample/app/src/androidTest/java/org/iotivity/service/ns/sample/consumer/ExampleUnitTest.java [moved from service/notification/examples/android/NotiConsumerExample/app/src/androidTest/java/com/sec/noticonsumerexample/ExampleUnitTest.java with 99% similarity]
service/notification/examples/android/NotiConsumerExample/app/src/androidTest/java/org/iotivity/service/ns/sample/consumer/ProviderSimulator.java [moved from service/notification/examples/android/NotiConsumerExample/app/src/androidTest/java/com/sec/noticonsumerexample/ProviderSimulator.java with 97% similarity]
service/notification/examples/android/NotiConsumerExample/app/src/main/AndroidManifest.xml
service/notification/examples/android/NotiConsumerExample/app/src/main/java/org/iotivity/service/ns/sample/consumer/ConsumerSample.java [moved from service/notification/examples/android/NotiConsumerExample/app/src/main/java/com/sec/noticonsumerexample/ConsumerSample.java with 99% similarity, mode: 0644]
service/notification/examples/android/NotiConsumerExample/app/src/main/java/org/iotivity/service/ns/sample/consumer/LoginActivity.java [moved from service/notification/examples/android/NotiProviderExample/app/src/main/java/com/sec/notiproviderexample/LoginActivity.java with 98% similarity, mode: 0644]
service/notification/examples/android/NotiConsumerExample/app/src/main/java/org/iotivity/service/ns/sample/consumer/MainActivity.java [moved from service/notification/examples/android/NotiConsumerExample/app/src/main/java/com/sec/noticonsumerexample/MainActivity.java with 97% similarity, mode: 0644]
service/notification/examples/android/NotiConsumerExample/app/src/main/res/layout/activity_main.xml
service/notification/examples/android/NotiProviderExample/SConscript
service/notification/examples/android/NotiProviderExample/app/build.gradle
service/notification/examples/android/NotiProviderExample/app/src/androidTest/java/org/iotivity/service/ns/sample/provider/ConsumerSimulator.java [moved from service/notification/examples/android/NotiProviderExample/app/src/androidTest/java/com/sec/notiproviderexample/ConsumerSimulator.java with 98% similarity]
service/notification/examples/android/NotiProviderExample/app/src/androidTest/java/org/iotivity/service/ns/sample/provider/ExampleUnitTest.java [moved from service/notification/examples/android/NotiProviderExample/app/src/androidTest/java/com/sec/notiproviderexample/ExampleUnitTest.java with 99% similarity]
service/notification/examples/android/NotiProviderExample/app/src/main/AndroidManifest.xml
service/notification/examples/android/NotiProviderExample/app/src/main/java/org/iotivity/service/ns/sample/provider/LoginActivity.java [moved from service/notification/examples/android/NotiConsumerExample/app/src/main/java/com/sec/noticonsumerexample/LoginActivity.java with 98% similarity, mode: 0644]
service/notification/examples/android/NotiProviderExample/app/src/main/java/org/iotivity/service/ns/sample/provider/MainActivity.java [moved from service/notification/examples/android/NotiProviderExample/app/src/main/java/com/sec/notiproviderexample/MainActivity.java with 97% similarity, mode: 0644]
service/notification/examples/android/NotiProviderExample/app/src/main/java/org/iotivity/service/ns/sample/provider/NotiListener.java [moved from service/notification/examples/android/NotiProviderExample/app/src/main/java/com/sec/notiproviderexample/NotiListener.java with 96% similarity, mode: 0644]
service/notification/examples/android/NotiProviderExample/app/src/main/java/org/iotivity/service/ns/sample/provider/ProviderSample.java [moved from service/notification/examples/android/NotiProviderExample/app/src/main/java/com/sec/notiproviderexample/ProviderSample.java with 99% similarity, mode: 0644]
service/notification/examples/android/NotiProviderExample/app/src/main/res/layout/activity_main.xml

index 71cdcac..4d7890c 100644 (file)
@@ -77,7 +77,7 @@ jdk_env['BUILDERS']['Gradle'] = Builder(action = env.get('ANDROID_GRADLE') +
     emitter = ensure_libs)
 jdk_env['BUILD_DIR'] = env.get('BUILD_DIR')
 cmdBuildNotificationConsumerApp=jdk_env.Gradle(target="app/apk", 
-    source=["app/src/main/java/com/sec/noticonsumerexample/MainActivity.java",
-            "app/src/main/java/com/sec/noticonsumerexample/ConsumerSample.java"])
+    source=["app/src/main/java/org/iotivity/service/ns/sample/consumer/MainActivity.java",
+            "app/src/main/java/org/iotivity/service/ns/sample/consumer/ConsumerSample.java"])
 jdk_env.Clean(cmdBuildNotificationConsumerApp, '#/service/notification/examples/android/NotiConsumerExample/build')
 Depends(cmdBuildNotificationConsumerApp, env.get('notificationAAR'))
index 52373eb..788bdd8 100755 (executable)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>\r
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"\r
-    package="com.sec.noticonsumerexample">\r
+    package="org.iotivity.service.ns.sample.consumer">\r
 \r
     <uses-feature android:name="android.hardware.nfc" />\r
     <uses-permission android:name="android.permission.READ_PHONE_STATE" />\r
-/******************************************************************\r
- * Copyright 2016 Samsung Electronics All Rights Reserved.\r
- * <p>\r
- * <p>\r
- * <p>\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- * <p>\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- * <p>\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- ******************************************************************/\r
-\r
-package com.sec.noticonsumerexample;\r
-\r
-import android.content.Intent;\r
-import android.os.Bundle;\r
-import android.os.Handler;\r
-import android.os.Message;\r
-import android.app.Activity;\r
-import android.util.Log;\r
-import android.view.View;\r
-import android.widget.Button;\r
-import android.widget.TextView;\r
-import android.widget.Toast;\r
-\r
-import org.iotivity.base.ErrorCode;\r
-import org.iotivity.base.OcAccountManager;\r
-import org.iotivity.base.OcConnectivityType;\r
-import org.iotivity.base.OcException;\r
-import org.iotivity.base.OcHeaderOption;\r
-import org.iotivity.base.OcPlatform;\r
-import org.iotivity.base.OcRepresentation;\r
-import org.iotivity.base.OcResource;\r
-import org.iotivity.service.ns.common.TopicsList;\r
-import org.iotivity.service.ns.common.Topic;\r
-\r
-import java.util.Arrays;\r
-import java.util.EnumSet;\r
-import java.util.HashMap;\r
-import java.util.List;\r
-\r
-public class MainActivity extends Activity  implements OcAccountManager.OnPostListener\r
-{\r
-    private final String TAG = "NS_MAIN_ACTIVITY";\r
-    private final int REQUEST_LOGIN = 1;\r
-\r
-    public static final String deviceID = "9E09F4FE-978A-4BC3-B356-1F93BCA37829";\r
-    public static final String CIServer = "coap+tcp://52.40.216.160:5683";\r
-    public static final String RemoteAddress = "52.40.216.160:5683";\r
-    public static final String MQCloudAddress = "52.78.151.180:5683";\r
-    public static final String MQCloudTopic = "/oic/ps/notification";\r
-\r
-    private Button btnStart;\r
-    private Button btnStop;\r
-    private Button btnRescan;\r
-    private Button btnEnableRemoteService;\r
-    private Button btnGetTopicList;\r
-    private Button btnUpdateTopicList;\r
-    private Button btnClearLog;\r
-    private static TextView TvLog;\r
-    private Button signUp, signIn, signOut;\r
-    private Button subscribeMQ;\r
-\r
-    private boolean isStarted = false;\r
-\r
-    private ConsumerSample mConsumerSample = null;\r
-    private OcAccountManager mAccountManager;\r
-    String mAuthCode;\r
-    String mAuthProvider;\r
-    String mRefreshtoken;\r
-    String mUserID;\r
-    String mAccessToken;\r
-\r
-    private static final int PROVIDER_DISCOVERED = 1;\r
-    private static final int STATE_CHANGED = 2;\r
-    private static final int MESSAGE_RECEIVED = 3;\r
-    private static final int SYNCINFO_RECEIVED = 4;\r
-    private static final int TOPICS_RECEIVED = 5;\r
-\r
-    public static Handler mHandler = new Handler()\r
-    {\r
-        @Override\r
-        public void handleMessage(Message msg)\r
-        {\r
-            switch (msg.what)\r
-            {\r
-                case PROVIDER_DISCOVERED:\r
-                    {\r
-                        String providerId = (String) msg.obj;\r
-                        if (providerId != null)\r
-                        {\r
-                            TvLog.append( providerId + "\n");\r
-                        }\r
-                        break;\r
-                    }\r
-                case STATE_CHANGED:\r
-                    {\r
-                        String state = (String) msg.obj;\r
-                        if (state != null)\r
-                        {\r
-                            TvLog.append( state + "\n");\r
-                        }\r
-                        break;\r
-                    }\r
-                case MESSAGE_RECEIVED:\r
-                    {\r
-                        String message = (String) msg.obj;\r
-                        if (message != null)\r
-                        {\r
-                            TvLog.append( message + "\n");\r
-                        }\r
-                        break;\r
-                    }\r
-                case SYNCINFO_RECEIVED:\r
-                    {\r
-                        String sync = (String) msg.obj;\r
-                        if (sync != null)\r
-                        {\r
-                            TvLog.append( sync + "\n");\r
-                        }\r
-                        break;\r
-                    }\r
-                case TOPICS_RECEIVED:\r
-                    {\r
-                        String topicList = (String) msg.obj;\r
-                        if (topicList != null)\r
-                        {\r
-                            TvLog.append( topicList + "\n");\r
-                        }\r
-                        break;\r
-                    }\r
-                default:\r
-                    break;\r
-            }\r
-        }\r
-    };\r
-\r
-    public void showToast(final String toast)\r
-    {\r
-        runOnUiThread(new Runnable()\r
-        {\r
-            @Override\r
-            public void run()\r
-            {\r
-                Toast.makeText(getApplicationContext(), toast, Toast.LENGTH_SHORT).show();\r
-            }\r
-        });\r
-    }\r
-\r
-    @Override\r
-    protected void onCreate(Bundle savedInstanceState)\r
-    {\r
-        super.onCreate(savedInstanceState);\r
-        setContentView(R.layout.activity_main);\r
-\r
-        btnStart = (Button) findViewById(R.id.BtnStart);\r
-        btnStop = (Button) findViewById(R.id.BtnStop);\r
-        btnRescan = (Button) findViewById(R.id.BtnRescan);\r
-        btnEnableRemoteService = (Button) findViewById(R.id.BtnEnableRemoteService);\r
-        btnGetTopicList = (Button) findViewById(R.id.BtnGetTopicList);\r
-        btnUpdateTopicList = (Button) findViewById(R.id.BtnUpdateTopicList);\r
-        btnClearLog = (Button) findViewById(R.id.BtnClearLog);\r
-\r
-        signUp = (Button) findViewById(R.id.signup);\r
-        signIn = (Button) findViewById(R.id.signin);\r
-        signOut = (Button) findViewById(R.id.signout);\r
-        subscribeMQ = (Button) findViewById(R.id.subscribeMQService);\r
-        TvLog = (TextView) findViewById(R.id.TvLog);\r
-\r
-        btnStart.setOnClickListener(mClickListener);\r
-        btnStop.setOnClickListener(mClickListener);\r
-        btnRescan.setOnClickListener(mClickListener);\r
-        btnEnableRemoteService.setOnClickListener(mClickListener);\r
-        btnGetTopicList.setOnClickListener(mClickListener);\r
-        btnUpdateTopicList.setOnClickListener(mClickListener);\r
-        btnClearLog.setOnClickListener(mClickListener);\r
-\r
-        signIn.setEnabled(false);\r
-        signOut.setEnabled(false);\r
-        btnEnableRemoteService.setEnabled(false);\r
-\r
-        signUp.setOnClickListener(mClickListener);\r
-        signIn.setOnClickListener(mClickListener);\r
-        signOut.setOnClickListener(mClickListener);\r
-        subscribeMQ.setOnClickListener(mClickListener);\r
-\r
-        mConsumerSample = new ConsumerSample(getApplicationContext());\r
-        mConsumerSample.setHandler(mHandler);\r
-    }\r
-\r
-    @Override\r
-    protected void onDestroy()\r
-    {\r
-        if (isStarted)\r
-            mConsumerSample.stopNotificationConsumer();\r
-        super.onDestroy();\r
-    }\r
-\r
-    Button.OnClickListener mClickListener = new View.OnClickListener()\r
-    {\r
-        public void onClick(View v)\r
-        {\r
-            switch (v.getId())\r
-            {\r
-                case R.id.BtnStart:\r
-                    {\r
-                        if (!isStarted)\r
-                        {\r
-                            Log.i(TAG, "Start NS Consumer Service");\r
-\r
-                            TvLog.setText("Start NS-Consumer\n");\r
-                            mConsumerSample.startNotificationConsumer();\r
-                            isStarted = true;\r
-                        }\r
-                        else\r
-                        {\r
-                            Log.e(TAG, "NS Consumer Service has already started");\r
-                            showToast("Error : Service has already started");\r
-                        }\r
-                    }\r
-                    break;\r
-\r
-                case R.id.BtnStop:\r
-                    {\r
-                        if (!isStarted)\r
-                        {\r
-                            Log.e(TAG, "Fail to stop service. Service has not been started");\r
-                            showToast("Error : Service has not been started");\r
-                            break;\r
-                        }\r
-                        TvLog.append("Stop NS-Consumer\n");\r
-                        mConsumerSample.stopNotificationConsumer();\r
-                        isStarted = false;\r
-                    }\r
-                    break;\r
-                case R.id.BtnRescan:\r
-                    {\r
-                        if (!isStarted)\r
-                        {\r
-                            Log.e(TAG, "Fail to rescan. Service has not been started");\r
-                            showToast("Error : Service has not been started");\r
-                            break;\r
-                        }\r
-                        TvLog.append("Rescan NS-Consumer\n");\r
-                        mConsumerSample.rescanProvider();\r
-                    }\r
-                    break;\r
-                case R.id.BtnEnableRemoteService:\r
-                    {\r
-                        if (!isStarted)\r
-                        {\r
-                            Log.e(TAG, "Fail to Enable RemoteService. Service has not been started");\r
-                            showToast("Error : Service has not been started");\r
-                            break;\r
-                        }\r
-                        TvLog.append("EnableRemoteService NS-Consumer\n");\r
-                        mConsumerSample.enableRemoteService(RemoteAddress);\r
-                    }\r
-                    break;\r
-                case R.id.BtnGetTopicList:\r
-                    {\r
-                        if (!isStarted)\r
-                        {\r
-                            Log.e(TAG, "Fail to GetTopicList. Service has not been started");\r
-                            showToast("Error : Service has not been started");\r
-                            break;\r
-                        }\r
-                        TvLog.append("GetTopicList NS-Consumer\n");\r
-                        mConsumerSample.getTopicsList();\r
-                    }\r
-                    break;\r
-                case R.id.BtnUpdateTopicList:\r
-                    {\r
-                        if (!isStarted)\r
-                        {\r
-                            Log.e(TAG, "Fail to UpdateTopicList. Service has not been started");\r
-                            showToast("Error : Service has not been started");\r
-                            break;\r
-                        }\r
-                        if(mConsumerSample.getAcceptor())\r
-                        {\r
-                            Log.e(TAG, "Operation Not Allowed. ProviderService Acceptor is not Consumer");\r
-                            showToast("Operation Not Allowed. ProviderService Acceptor is not Consumer");\r
-                            break;\r
-                        }\r
-                        TvLog.append("UpdateTopicList NS-Consumer\n");\r
-\r
-                        TopicsList topicList = new TopicsList();\r
-                        topicList.addTopic("OCF_TOPIC1", Topic.TopicState.SUBSCRIBED);\r
-                        topicList.addTopic("OCF_TOPIC2", Topic.TopicState.SUBSCRIBED);\r
-                        topicList.addTopic("OCF_TOPIC3", Topic.TopicState.UNSUBSCRIBED);\r
-\r
-                        mConsumerSample.updateTopicList(topicList);\r
-                    }\r
-                    break;\r
-                case R.id.BtnClearLog:\r
-                {\r
-                    TvLog.setText("");\r
-                }\r
-                break;\r
-                case R.id.signup: {\r
-                    if(isStarted == false) {\r
-                        Log.e(TAG, "Fail to Sign Up");\r
-                        showToast("Start ConsumerService First");\r
-                        break;\r
-                    }\r
-                    TvLog.append("Initiating SignUp\n");\r
-                    signUp();\r
-                }\r
-                break;\r
-                case R.id.signin: {\r
-                    if(isStarted == false) {\r
-                        Log.e(TAG, "Fail to Sign In");\r
-                        showToast("Start ConsumerService First");\r
-                        break;\r
-                    }\r
-                    TvLog.append("Initiating SignIn\n");\r
-                    signIn();\r
-                }\r
-                break;\r
-                case R.id.signout: {\r
-                    if(isStarted == false) {\r
-                        Log.e(TAG, "Fail to Sign out");\r
-                        showToast("Start ConsumerService First");\r
-                        break;\r
-                    }\r
-                    TvLog.append("Initiating SignOut\n");\r
-                    signOut();\r
-                }\r
-                break;\r
-                case R.id.subscribeMQService: {\r
-                    if(isStarted == false) {\r
-                        Log.e(TAG, "Fail to SubscribeMQService");\r
-                        showToast("Start ProviderService First");\r
-                        break;\r
-                    }\r
-                    int result = mConsumerSample.subscribeMQService(MQCloudAddress, MQCloudTopic);\r
-                    TvLog.append("SubscribeMQService Result : " + result + "\n");\r
-                }\r
-                break;\r
-            }\r
-        }\r
-    };\r
-    public void logMessage(final String text) {\r
-        runOnUiThread(new Runnable() {\r
-            public void run() {\r
-                Message msg = new Message();\r
-                msg.obj = text;\r
-                TvLog.append(text + "\n");\r
-            }\r
-        });\r
-        Log.i(TAG, text);\r
-    }\r
-    OcAccountManager.OnPostListener onSignUp = new OcAccountManager.OnPostListener() {\r
-        @Override\r
-        public synchronized void onPostCompleted(List<OcHeaderOption> list,\r
-                                                 OcRepresentation ocRepresentation) {\r
-            logMessage("signUp was successful");\r
-            runOnUiThread(new Runnable() {\r
-                public void run() {\r
-                    signIn.setEnabled(true);\r
-                    signUp.setEnabled(false);\r
-                }\r
-            });\r
-            try {\r
-                mUserID = ocRepresentation.getValue("uid");\r
-                mAccessToken = ocRepresentation.getValue("accesstoken");\r
-                mRefreshtoken = ocRepresentation.getValue("refreshtoken");\r
-\r
-                logMessage("\tuserID: " + mUserID);\r
-                logMessage("\taccessToken: " + mAccessToken);\r
-                logMessage("\trefreshToken: " + mRefreshtoken);\r
-\r
-                if (ocRepresentation.hasAttribute("expiresin")) {\r
-                    int expiresIn = ocRepresentation.getValue("expiresin");\r
-                    logMessage("\texpiresIn: " + expiresIn);\r
-                }\r
-            } catch (OcException e) {\r
-                Log.e(TAG, e.toString());\r
-            }\r
-        }\r
-\r
-\r
-        @Override\r
-        public synchronized void onPostFailed(Throwable throwable) {\r
-            logMessage("Failed to signUp");\r
-            if (throwable instanceof OcException) {\r
-                OcException ocEx = (OcException) throwable;\r
-                Log.e(TAG, ocEx.toString());\r
-                ErrorCode errCode = ocEx.getErrorCode();\r
-                logMessage("Error code: " + errCode);\r
-            }\r
-        }\r
-    };\r
-    OcAccountManager.OnPostListener onSignIn = new OcAccountManager.OnPostListener() {\r
-        @Override\r
-        public synchronized void onPostCompleted(List<OcHeaderOption> list,\r
-                                                 OcRepresentation ocRepresentation) {\r
-            logMessage("signIn was successful");\r
-            runOnUiThread(new Runnable() {\r
-                public void run() {\r
-                    signIn.setEnabled(false);\r
-                    signOut.setEnabled(true);\r
-                    btnEnableRemoteService.setEnabled(true);\r
-                }\r
-            });\r
-\r
-        }\r
-\r
-        @Override\r
-        public synchronized void onPostFailed(Throwable throwable) {\r
-            logMessage("Failed to signIn");\r
-            if (throwable instanceof OcException) {\r
-                OcException ocEx = (OcException) throwable;\r
-                Log.e(TAG, ocEx.toString());\r
-                ErrorCode errCode = ocEx.getErrorCode();\r
-                logMessage("Error code: " + errCode);\r
-                if (ErrorCode.UNAUTHORIZED_REQ != errCode) {\r
-                    RefreshToken();\r
-                }\r
-            }\r
-        }\r
-    };\r
-    OcAccountManager.OnPostListener onSignOut = new OcAccountManager.OnPostListener() {\r
-        @Override\r
-        public synchronized void onPostCompleted(List<OcHeaderOption> list,\r
-                                                 OcRepresentation ocRepresentation) {\r
-            logMessage("signOut was successful");\r
-            runOnUiThread(new Runnable() {\r
-                public void run() {\r
-                    signIn.setEnabled(true);\r
-                    signOut.setEnabled(false);\r
-                    btnEnableRemoteService.setEnabled(false);\r
-                }\r
-            });\r
-\r
-        }\r
-\r
-        @Override\r
-        public synchronized void onPostFailed(Throwable throwable) {\r
-            logMessage("Failed to signOut");\r
-            if (throwable instanceof OcException) {\r
-                OcException ocEx = (OcException) throwable;\r
-                Log.e(TAG, ocEx.toString());\r
-                ErrorCode errCode = ocEx.getErrorCode();\r
-                logMessage("Error code: " + errCode);\r
-                if (ErrorCode.UNAUTHORIZED_REQ != errCode) {\r
-                    RefreshToken();\r
-                }\r
-            }\r
-        }\r
-    };\r
-    @Override\r
-    public void onPostCompleted(List<OcHeaderOption> ocHeaderOptions, OcRepresentation ocRepresentation) {\r
-\r
-    }\r
-\r
-    @Override\r
-    public void onPostFailed(Throwable throwable) {\r
-\r
-    }\r
-    private void signIn() {\r
-        try {\r
-            if(mAccountManager==null)\r
-            {\r
-                mAccountManager = OcPlatform.constructAccountManagerObject(CIServer,\r
-                        EnumSet.of(OcConnectivityType.CT_ADAPTER_TCP));\r
-            }\r
-\r
-            mAccountManager.signIn(mUserID, mAccessToken, onSignIn);\r
-        } catch (OcException e) {\r
-            e.printStackTrace();\r
-        }\r
-    }\r
-\r
-    private void signOut() {\r
-        try {\r
-            logMessage("signOut");\r
-            if(mAccountManager==null)\r
-            {\r
-                try {\r
-                    mAccountManager = OcPlatform.constructAccountManagerObject(CIServer,\r
-                            EnumSet.of(OcConnectivityType.CT_ADAPTER_TCP));\r
-                } catch (OcException e) {\r
-                    e.printStackTrace();\r
-                }\r
-            }\r
-            mAccountManager.signOut(mAccessToken, onSignOut);\r
-            signIn.setEnabled(false);\r
-            signUp.setEnabled(true);\r
-            btnEnableRemoteService.setEnabled(false);\r
-            logMessage("signOut Successful");\r
-        } catch (OcException e) {\r
-            e.printStackTrace();\r
-        }\r
-    }\r
-\r
-    private void signUp() {\r
-        try {\r
-            mAccountManager = OcPlatform.constructAccountManagerObject(CIServer,\r
-                    EnumSet.of(OcConnectivityType.CT_ADAPTER_TCP));\r
-        } catch (OcException e) {\r
-            e.printStackTrace();\r
-        }\r
-\r
-        Intent intentLogin = new Intent(this,LoginActivity.class);\r
-        startActivityForResult(intentLogin, REQUEST_LOGIN);\r
-    }\r
-    @Override\r
-    public void onActivityResult(int requestCode, int resultCode, Intent data) {\r
-        super.onActivityResult(requestCode, resultCode, data);\r
-        if (resultCode == Activity.RESULT_OK && requestCode == REQUEST_LOGIN) {\r
-            mAuthCode = data.getStringExtra("authCode");\r
-            mAuthProvider = data.getStringExtra("authProvider");\r
-            logMessage("authCode: " + mAuthCode);\r
-            logMessage("authProvider: " + mAuthProvider);\r
-\r
-            try {\r
-                mAccountManager = OcPlatform.constructAccountManagerObject(CIServer,\r
-                        EnumSet.of(OcConnectivityType.CT_ADAPTER_TCP));\r
-                logMessage("Calling signup API");\r
-\r
-                mAccountManager.signUp(mAuthProvider, mAuthCode, onSignUp);\r
-            } catch (OcException e) {\r
-                e.printStackTrace();\r
-            }\r
-        }\r
-    }\r
-\r
-    OcResource.OnPostListener onRefreshTokenPost = new OcResource.OnPostListener() {\r
-        @Override\r
-        public void onPostCompleted(List<OcHeaderOption> list, OcRepresentation ocRepresentation) {\r
-            logMessage("RefreshToken Completed.");\r
-            try {\r
-                mAccessToken = ocRepresentation.getValue("accesstoken");\r
-                mRefreshtoken = ocRepresentation.getValue("refreshtoken");\r
-            }\r
-            catch (OcException e)\r
-            {\r
-                e.printStackTrace();\r
-            }\r
-            signIn();\r
-        }\r
-\r
-        @Override\r
-        public void onPostFailed(Throwable throwable) {\r
-            logMessage("RefreshToken failed.");\r
-            Log.d(TAG, "onRefreshTokenPost failed..");\r
-        }\r
-    };\r
-    public void RefreshToken() {\r
-        try {\r
-            OcResource authResource = OcPlatform.constructResourceObject(CIServer, "/.well-known/ocf/account/tokenrefresh",\r
-                    EnumSet.of(OcConnectivityType.CT_ADAPTER_TCP, OcConnectivityType.CT_IP_USE_V4),\r
-                    false, Arrays.asList("oic.wk.account"), Arrays.asList(OcPlatform.DEFAULT_INTERFACE));\r
-            OcRepresentation rep = new OcRepresentation();\r
-\r
-            showToast("RefreshToken in progress..");\r
-            logMessage("RefreshToken in progress..");\r
-            rep.setValue("di", deviceID);\r
-            rep.setValue("granttype", "refresh_token");\r
-            rep.setValue("refreshtoken", mRefreshtoken);\r
-            rep.setValue("uid", mUserID);\r
-            authResource.post(rep, new HashMap<String, String>(), onRefreshTokenPost);\r
-        }\r
-        catch(OcException e)\r
-        {\r
-            e.printStackTrace();\r
-        }\r
-\r
-        Log.d(TAG, "No error while executing login");\r
-    }\r
-}\r
+/******************************************************************
+ * Copyright 2016 Samsung Electronics All Rights Reserved.
+ * <p>
+ * <p>
+ * <p>
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************/
+
+package org.iotivity.service.ns.sample.consumer;
+
+import android.content.Intent;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Message;
+import android.app.Activity;
+import android.util.Log;
+import android.view.View;
+import android.widget.Button;
+import android.widget.TextView;
+import android.widget.Toast;
+
+import org.iotivity.base.ErrorCode;
+import org.iotivity.base.OcAccountManager;
+import org.iotivity.base.OcConnectivityType;
+import org.iotivity.base.OcException;
+import org.iotivity.base.OcHeaderOption;
+import org.iotivity.base.OcPlatform;
+import org.iotivity.base.OcRepresentation;
+import org.iotivity.base.OcResource;
+import org.iotivity.service.ns.common.TopicsList;
+import org.iotivity.service.ns.common.Topic;
+
+import java.util.Arrays;
+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()
+    {
+        @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;
+                    }
+                case STATE_CHANGED:
+                    {
+                        String state = (String) msg.obj;
+                        if (state != null)
+                        {
+                            TvLog.append( state + "\n");
+                        }
+                        break;
+                    }
+                case MESSAGE_RECEIVED:
+                    {
+                        String message = (String) msg.obj;
+                        if (message != null)
+                        {
+                            TvLog.append( message + "\n");
+                        }
+                        break;
+                    }
+                case SYNCINFO_RECEIVED:
+                    {
+                        String sync = (String) msg.obj;
+                        if (sync != null)
+                        {
+                            TvLog.append( sync + "\n");
+                        }
+                        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()
+        {
+            @Override
+            public void run()
+            {
+                Toast.makeText(getApplicationContext(), toast, Toast.LENGTH_SHORT).show();
+            }
+        });
+    }
+
+    @Override
+    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);
+        btnGetTopicList = (Button) findViewById(R.id.BtnGetTopicList);
+        btnUpdateTopicList = (Button) findViewById(R.id.BtnUpdateTopicList);
+        btnClearLog = (Button) findViewById(R.id.BtnClearLog);
+
+        signUp = (Button) findViewById(R.id.signup);
+        signIn = (Button) findViewById(R.id.signin);
+        signOut = (Button) findViewById(R.id.signout);
+        subscribeMQ = (Button) findViewById(R.id.subscribeMQService);
+        TvLog = (TextView) findViewById(R.id.TvLog);
+
+        btnStart.setOnClickListener(mClickListener);
+        btnStop.setOnClickListener(mClickListener);
+        btnRescan.setOnClickListener(mClickListener);
+        btnEnableRemoteService.setOnClickListener(mClickListener);
+        btnGetTopicList.setOnClickListener(mClickListener);
+        btnUpdateTopicList.setOnClickListener(mClickListener);
+        btnClearLog.setOnClickListener(mClickListener);
+
+        signIn.setEnabled(false);
+        signOut.setEnabled(false);
+        btnEnableRemoteService.setEnabled(false);
+
+        signUp.setOnClickListener(mClickListener);
+        signIn.setOnClickListener(mClickListener);
+        signOut.setOnClickListener(mClickListener);
+        subscribeMQ.setOnClickListener(mClickListener);
+
+        mConsumerSample = new ConsumerSample(getApplicationContext());
+        mConsumerSample.setHandler(mHandler);
+    }
+
+    @Override
+    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");
+                        }
+                    }
+                    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;
+                    }
+                    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();
+                    }
+                    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);
+                    }
+                    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();
+                    }
+                    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");
+
+                        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);
+                    }
+                    break;
+                case R.id.BtnClearLog:
+                {
+                    TvLog.setText("");
+                }
+                break;
+                case R.id.signup: {
+                    if(isStarted == false) {
+                        Log.e(TAG, "Fail to Sign Up");
+                        showToast("Start ConsumerService First");
+                        break;
+                    }
+                    TvLog.append("Initiating SignUp\n");
+                    signUp();
+                }
+                break;
+                case R.id.signin: {
+                    if(isStarted == false) {
+                        Log.e(TAG, "Fail to Sign In");
+                        showToast("Start ConsumerService First");
+                        break;
+                    }
+                    TvLog.append("Initiating SignIn\n");
+                    signIn();
+                }
+                break;
+                case R.id.signout: {
+                    if(isStarted == false) {
+                        Log.e(TAG, "Fail to Sign out");
+                        showToast("Start ConsumerService First");
+                        break;
+                    }
+                    TvLog.append("Initiating SignOut\n");
+                    signOut();
+                }
+                break;
+                case R.id.subscribeMQService: {
+                    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");
+                }
+                break;
+            }
+        }
+    };
+    public void logMessage(final String text) {
+        runOnUiThread(new Runnable() {
+            public void run() {
+                Message msg = new Message();
+                msg.obj = text;
+                TvLog.append(text + "\n");
+            }
+        });
+        Log.i(TAG, text);
+    }
+    OcAccountManager.OnPostListener onSignUp = new OcAccountManager.OnPostListener() {
+        @Override
+        public synchronized void onPostCompleted(List<OcHeaderOption> list,
+                                                 OcRepresentation ocRepresentation) {
+            logMessage("signUp was successful");
+            runOnUiThread(new Runnable() {
+                public void run() {
+                    signIn.setEnabled(true);
+                    signUp.setEnabled(false);
+                }
+            });
+            try {
+                mUserID = ocRepresentation.getValue("uid");
+                mAccessToken = ocRepresentation.getValue("accesstoken");
+                mRefreshtoken = ocRepresentation.getValue("refreshtoken");
+
+                logMessage("\tuserID: " + mUserID);
+                logMessage("\taccessToken: " + mAccessToken);
+                logMessage("\trefreshToken: " + mRefreshtoken);
+
+                if (ocRepresentation.hasAttribute("expiresin")) {
+                    int expiresIn = ocRepresentation.getValue("expiresin");
+                    logMessage("\texpiresIn: " + expiresIn);
+                }
+            } catch (OcException e) {
+                Log.e(TAG, e.toString());
+            }
+        }
+
+
+        @Override
+        public synchronized void onPostFailed(Throwable throwable) {
+            logMessage("Failed to signUp");
+            if (throwable instanceof OcException) {
+                OcException ocEx = (OcException) throwable;
+                Log.e(TAG, ocEx.toString());
+                ErrorCode errCode = ocEx.getErrorCode();
+                logMessage("Error code: " + errCode);
+            }
+        }
+    };
+    OcAccountManager.OnPostListener onSignIn = new OcAccountManager.OnPostListener() {
+        @Override
+        public synchronized void onPostCompleted(List<OcHeaderOption> list,
+                                                 OcRepresentation ocRepresentation) {
+            logMessage("signIn was successful");
+            runOnUiThread(new Runnable() {
+                public void run() {
+                    signIn.setEnabled(false);
+                    signOut.setEnabled(true);
+                    btnEnableRemoteService.setEnabled(true);
+                }
+            });
+
+        }
+
+        @Override
+        public synchronized void onPostFailed(Throwable throwable) {
+            logMessage("Failed to signIn");
+            if (throwable instanceof OcException) {
+                OcException ocEx = (OcException) throwable;
+                Log.e(TAG, ocEx.toString());
+                ErrorCode errCode = ocEx.getErrorCode();
+                logMessage("Error code: " + errCode);
+                if (ErrorCode.UNAUTHORIZED_REQ != errCode) {
+                    RefreshToken();
+                }
+            }
+        }
+    };
+    OcAccountManager.OnPostListener onSignOut = new OcAccountManager.OnPostListener() {
+        @Override
+        public synchronized void onPostCompleted(List<OcHeaderOption> list,
+                                                 OcRepresentation ocRepresentation) {
+            logMessage("signOut was successful");
+            runOnUiThread(new Runnable() {
+                public void run() {
+                    signIn.setEnabled(true);
+                    signOut.setEnabled(false);
+                    btnEnableRemoteService.setEnabled(false);
+                }
+            });
+
+        }
+
+        @Override
+        public synchronized void onPostFailed(Throwable throwable) {
+            logMessage("Failed to signOut");
+            if (throwable instanceof OcException) {
+                OcException ocEx = (OcException) throwable;
+                Log.e(TAG, ocEx.toString());
+                ErrorCode errCode = ocEx.getErrorCode();
+                logMessage("Error code: " + errCode);
+                if (ErrorCode.UNAUTHORIZED_REQ != errCode) {
+                    RefreshToken();
+                }
+            }
+        }
+    };
+    @Override
+    public void onPostCompleted(List<OcHeaderOption> ocHeaderOptions, OcRepresentation ocRepresentation) {
+
+    }
+
+    @Override
+    public void onPostFailed(Throwable throwable) {
+
+    }
+    private void signIn() {
+        try {
+            if(mAccountManager==null)
+            {
+                mAccountManager = OcPlatform.constructAccountManagerObject(CIServer,
+                        EnumSet.of(OcConnectivityType.CT_ADAPTER_TCP));
+            }
+
+            mAccountManager.signIn(mUserID, mAccessToken, onSignIn);
+        } catch (OcException e) {
+            e.printStackTrace();
+        }
+    }
+
+    private void signOut() {
+        try {
+            logMessage("signOut");
+            if(mAccountManager==null)
+            {
+                try {
+                    mAccountManager = OcPlatform.constructAccountManagerObject(CIServer,
+                            EnumSet.of(OcConnectivityType.CT_ADAPTER_TCP));
+                } catch (OcException e) {
+                    e.printStackTrace();
+                }
+            }
+            mAccountManager.signOut(mAccessToken, onSignOut);
+            signIn.setEnabled(false);
+            signUp.setEnabled(true);
+            btnEnableRemoteService.setEnabled(false);
+            logMessage("signOut Successful");
+        } 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);
+        if (resultCode == Activity.RESULT_OK && requestCode == REQUEST_LOGIN) {
+            mAuthCode = data.getStringExtra("authCode");
+            mAuthProvider = data.getStringExtra("authProvider");
+            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();
+            }
+        }
+    }
+
+    OcResource.OnPostListener onRefreshTokenPost = new OcResource.OnPostListener() {
+        @Override
+        public void onPostCompleted(List<OcHeaderOption> list, OcRepresentation ocRepresentation) {
+            logMessage("RefreshToken Completed.");
+            try {
+                mAccessToken = ocRepresentation.getValue("accesstoken");
+                mRefreshtoken = ocRepresentation.getValue("refreshtoken");
+            }
+            catch (OcException e)
+            {
+                e.printStackTrace();
+            }
+            signIn();
+        }
+
+        @Override
+        public void onPostFailed(Throwable throwable) {
+            logMessage("RefreshToken failed.");
+            Log.d(TAG, "onRefreshTokenPost failed..");
+        }
+    };
+    public void RefreshToken() {
+        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));
+            OcRepresentation rep = new OcRepresentation();
+
+            showToast("RefreshToken in progress..");
+            logMessage("RefreshToken in progress..");
+            rep.setValue("di", deviceID);
+            rep.setValue("granttype", "refresh_token");
+            rep.setValue("refreshtoken", mRefreshtoken);
+            rep.setValue("uid", mUserID);
+            authResource.post(rep, new HashMap<String, String>(), onRefreshTokenPost);
+        }
+        catch(OcException e)
+        {
+            e.printStackTrace();
+        }
+
+        Log.d(TAG, "No error while executing login");
+    }
+}
index 3ca4861..cdede23 100755 (executable)
@@ -7,7 +7,7 @@
     android:paddingLeft="@dimen/activity_horizontal_margin"\r
     android:paddingRight="@dimen/activity_horizontal_margin"\r
     android:paddingTop="@dimen/activity_vertical_margin"\r
-    tools:context="com.sec.noticonsumerexample.MainActivity">\r
+    tools:context=".MainActivity">\r
 \r
     <ScrollView\r
         android:layout_width="match_parent"\r
index 1990a5a..fa506be 100644 (file)
@@ -77,8 +77,8 @@ jdk_env['BUILDERS']['Gradle'] = Builder(action = env.get('ANDROID_GRADLE') +
     emitter = ensure_libs)
 jdk_env['BUILD_DIR'] = env.get('BUILD_DIR')
 cmdBuildNotificationProviderApp=jdk_env.Gradle(target="app/apk", 
-    source=["app/src/main/java/com/sec/notiproviderexample/MainActivity.java",
-            "app/src/main/java/com/sec/notiproviderexample/NotiListener.java",
-            "app/src/main/java/com/sec/notiproviderexample/ProviderSample.java"])
+    source=["app/src/main/java/org/iotivity/service/ns/sample/provider/MainActivity.java",
+            "app/src/main/java/org/iotivity/service/ns/sample/provider/NotiListener.java",
+            "app/src/main/java/org/iotivity/service/ns/sample/provider/ProviderSample.java"])
 jdk_env.Clean(cmdBuildNotificationProviderApp, '#/service/notification/examples/android/NotiProviderExample/build')
 Depends(cmdBuildNotificationProviderApp, env.get('notificationAAR'))
index e4f0d31..a1ae6e2 100755 (executable)
@@ -13,7 +13,7 @@ android {
     }
 
     defaultConfig {
-        applicationId "sample.notification.service.iotivity.org.notificationsample"
+        applicationId "sample.notification.service.iotivity.org.notificationprovidersample"
         minSdkVersion 21
         targetSdkVersion 21
         versionCode 1
index be52da1..7134850 100755 (executable)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>\r
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"\r
-    package="com.sec.notiproviderexample">\r
+    package="org.iotivity.service.ns.sample.provider">\r
 \r
     <uses-feature android:name="android.hardware.nfc" />\r
     <uses-permission android:name="android.permission.READ_PHONE_STATE" />\r
@@ -31,7 +31,7 @@
         </activity>\r
         <activity android:name=".LoginActivity" />\r
         <service\r
-            android:name="com.sec.notiproviderexample.NotiListener"\r
+            android:name=".NotiListener"\r
             android:label="@string/app_name"\r
             android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">\r
 \r
-/*\r
-//******************************************************************\r
-//\r
-// Copyright 2016 Samsung Electronics All Rights Reserved.\r
-//\r
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
-//\r
-// Licensed under the Apache License, Version 2.0 (the "License");\r
-// you may not use this file except in compliance with the License.\r
-// You may obtain a copy of the License at\r
-//\r
-//      http://www.apache.org/licenses/LICENSE-2.0\r
-//\r
-// Unless required by applicable law or agreed to in writing, software\r
-// distributed under the License is distributed on an "AS IS" BASIS,\r
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
-// See the License for the specific language governing permissions and\r
-// limitations under the License.\r
-//\r
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
- */\r
-\r
-package com.sec.notiproviderexample;\r
-\r
-import android.app.Notification;\r
-import android.app.NotificationManager;\r
-import android.content.Intent;\r
-import android.os.Bundle;\r
-import android.os.Handler;\r
-import android.os.Message;\r
-import android.util.Log;\r
-import android.view.View;\r
-import android.widget.Button;\r
-import android.widget.EditText;\r
-import android.widget.RadioButton;\r
-import android.widget.TextView;\r
-import android.widget.Toast;\r
-import android.app.Activity;\r
-\r
-import org.iotivity.base.ErrorCode;\r
-import org.iotivity.base.OcAccountManager;\r
-import org.iotivity.base.OcConnectivityType;\r
-import org.iotivity.base.OcException;\r
-import org.iotivity.base.OcHeaderOption;\r
-import org.iotivity.base.OcPlatform;\r
-import org.iotivity.base.OcRepresentation;\r
-import org.iotivity.base.OcResource;\r
-\r
-import java.util.Arrays;\r
-import java.util.EnumSet;\r
-import java.util.HashMap;\r
-import java.util.List;\r
-\r
-public class MainActivity extends Activity  implements OcAccountManager.OnPostListener {\r
-\r
-    private final String TAG = "NS_MAIN_ACTIVITY";\r
-    private static final int CONSUMER_SUBSCRIBED = 1;\r
-    private static final int MESSAGE_SYNC = 2;\r
-    private final int REQUEST_LOGIN = 1;\r
-\r
-    public static final String deviceID = "9E09F4FE-978A-4BC3-B356-1F93BCA37829";\r
-    public static final String CIServer = "coap+tcp://52.40.216.160:5683";\r
-    public static final String RemoteAddress = "52.40.216.160:5683";\r
-    public static final String MQCloudAddress = "52.78.151.180:5683";\r
-    public static final String MQCloudTopic = "/oic/ps/notification";\r
-\r
-    private Button btnTitle;\r
-    private Button btnBody;\r
-    private Button btnTopic;\r
-    private Button btnSend;\r
-    private Button btnStart;\r
-    private Button btnRegister;\r
-    private Button btnSet;\r
-    private Button btnStop;\r
-    private Button btnLog;\r
-    private Button signUp, signIn, signOut;\r
-    private Button remoteService, subscribeMQ;\r
-    private EditText editTextTitle;\r
-    private EditText editTextBody;\r
-    private EditText editTextTopic;\r
-    private RadioButton radioProvider;\r
-    private RadioButton radioConsumer;\r
-    private static TextView TvLog;\r
-\r
-    private OcAccountManager mAccountManager;\r
-    String mAuthCode;\r
-    String mAuthProvider;\r
-    String mRefreshtoken;\r
-    String mUserID;\r
-    String mAccessToken;\r
-\r
-    private static int notiId = 100;\r
-    private boolean isStarted = false;\r
-    private boolean gAcceptor = true;\r
-    private boolean gRemoteService = true;\r
-\r
-    private NotiListener mNotiListener = null;\r
-    private ProviderSample mProviderSample = null;\r
-\r
-    public static Handler mHandler = new Handler() {\r
-        @Override\r
-        public void handleMessage(Message msg) {\r
-            switch (msg.what) {\r
-                case CONSUMER_SUBSCRIBED:\r
-                    String ConsumerId = (String) msg.obj;\r
-                    if(ConsumerId != null)\r
-                        TvLog.append("Consumer Subscibed: " + ConsumerId + "\n");\r
-                    break;\r
-\r
-                case MESSAGE_SYNC:\r
-                    String sync = (String) msg.obj;\r
-                    if(sync != null)\r
-                        TvLog.append("SyncInfo Received :" + sync + "\n");\r
-                    break;\r
-\r
-                default:\r
-                    break;\r
-            }\r
-        }\r
-    };\r
-\r
-    public void showToast(final String toast)\r
-    {\r
-        runOnUiThread(new Runnable() {\r
-            @Override\r
-            public void run() {\r
-                Toast.makeText(getApplicationContext(), toast, Toast.LENGTH_SHORT).show();\r
-            }\r
-        });\r
-    }\r
-\r
-    @Override\r
-    protected void onCreate(Bundle savedInstanceState) {\r
-        super.onCreate(savedInstanceState);\r
-        setContentView(R.layout.activity_main);\r
-\r
-        btnTitle = (Button) findViewById(R.id.BtnTitle);\r
-        btnBody = (Button) findViewById(R.id.BtnBody);\r
-        btnTopic = (Button) findViewById(R.id.BtnTopic);\r
-        btnSend = (Button) findViewById(R.id.BtnCreateNoti);\r
-\r
-        btnStart = (Button) findViewById(R.id.BtnStart);\r
-        btnRegister = (Button) findViewById(R.id.BtnRegister);\r
-        btnSet = (Button) findViewById(R.id.BtnSet);\r
-        btnLog = (Button) findViewById(R.id.BtnLog);\r
-        btnStop = (Button) findViewById(R.id.BtnStop);\r
-\r
-        signUp = (Button) findViewById(R.id.signup);\r
-        signIn = (Button) findViewById(R.id.signin);\r
-        signOut = (Button) findViewById(R.id.signout);\r
-        remoteService = (Button) findViewById(R.id.remoteService);\r
-        subscribeMQ = (Button) findViewById(R.id.subscribeMQService);\r
-\r
-        editTextTitle = (EditText) findViewById(R.id.EditTextTitle);\r
-        editTextBody = (EditText) findViewById(R.id.EditTextBody);\r
-        editTextTopic = (EditText) findViewById(R.id.EditTextTopic);\r
-\r
-        radioProvider = (RadioButton) findViewById(R.id.RadioProvider);\r
-        radioConsumer = (RadioButton) findViewById(R.id.RadioConsumer);\r
-\r
-        TvLog = (TextView) findViewById(R.id.TvLog);\r
-\r
-        btnTitle.setEnabled(false);\r
-        btnBody.setEnabled(false);\r
-        btnTopic.setEnabled(false);\r
-\r
-        signIn.setEnabled(false);\r
-        signOut.setEnabled(false);\r
-        remoteService.setEnabled(false);\r
-\r
-        btnSend.setOnClickListener(mClickListener);\r
-        btnStart.setOnClickListener(mClickListener);\r
-        btnRegister.setOnClickListener(mClickListener);\r
-        btnSet.setOnClickListener(mClickListener);\r
-        btnLog.setOnClickListener(mClickListener);\r
-        btnStop.setOnClickListener(mClickListener);\r
-        radioProvider.setOnClickListener(mClickListener);\r
-        radioConsumer.setOnClickListener(mClickListener);\r
-\r
-        signUp.setOnClickListener(mClickListener);\r
-        signIn.setOnClickListener(mClickListener);\r
-        signOut.setOnClickListener(mClickListener);\r
-\r
-        remoteService.setOnClickListener(mClickListener);\r
-        subscribeMQ.setOnClickListener(mClickListener);\r
-\r
-        mProviderSample = new ProviderSample(getApplicationContext());\r
-        mProviderSample.setHandler(mHandler);\r
-\r
-        mNotiListener = new NotiListener(this);\r
-        Intent intent = new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS");\r
-        startActivity(intent);\r
-    }\r
-\r
-    @Override\r
-    protected void onDestroy() {\r
-        super.onDestroy();\r
-    }\r
-\r
-    public ProviderSample getProviderSample()\r
-    {\r
-        return mProviderSample;\r
-    }\r
-\r
-    Button.OnClickListener mClickListener = new View.OnClickListener() {\r
-        public void onClick(View v) {\r
-            switch (v.getId()) {\r
-                case R.id.RadioProvider: {\r
-                    if (isStarted == false) {\r
-                        gAcceptor = true;\r
-                        showToast("Provider as acceptor is " + gAcceptor);\r
-                    }\r
-                    else\r
-                        showToast("Start ProviderService again to change acceptor as provider");\r
-                }\r
-                break;\r
-\r
-                case R.id.RadioConsumer: {\r
-                    if (isStarted == false) {\r
-                        gAcceptor = false;\r
-                        showToast("Provider as acceptor is "+ gAcceptor);\r
-                    }\r
-                    else\r
-                        showToast("Start ProviderService again to change acceptor as consumer");\r
-                }\r
-                break;\r
-\r
-                case R.id.BtnStart: {\r
-                    if (isStarted == false) {\r
-                        Log.i(TAG, "Start  Provider Service");\r
-                        TvLog.setText("Start Provider Service\n");\r
-                        mProviderSample.Start(gAcceptor);\r
-                        isStarted = true;\r
-                        radioProvider.setEnabled(false);\r
-                        radioConsumer.setEnabled(false);\r
-                    } else {\r
-                        Log.e(TAG, " Provider Service had already started");\r
-                        showToast(" Provider Service had already started");\r
-                    }\r
-                }\r
-                break;\r
-\r
-                case R.id.BtnRegister: {\r
-                    if (isStarted == false) {\r
-                        Log.i(TAG, "Start  Provider Service");\r
-                        TvLog.append("Register Topic : OCF_TOPIC1\n");\r
-                        TvLog.append("Register Topic : OCF_TOPIC2\n");\r
-                        TvLog.append("Register Topic : OCF_TOPIC3\n");\r
-                        TvLog.append("Register Topic : OCF_TOPIC4\n");\r
-                        showToast("Start Provider Service First");\r
-                        break;\r
-                    }\r
-                    mProviderSample.RegisterTopic();\r
-\r
-                }\r
-                break;\r
-\r
-                case R.id.BtnSet: {\r
-                    if (isStarted == false) {\r
-                        Log.i(TAG, "Start Provider Service");\r
-                        TvLog.append("Set Topic : OCF_TOPIC1\n");\r
-                        TvLog.append("Set Topic : OCF_TOPIC2\n");\r
-                        TvLog.append("Set Topic : OCF_TOPIC3\n");\r
-                        TvLog.append("Set Topic : OCF_TOPIC4\n");\r
-                        showToast("Start Provider Service First");\r
-                        break;\r
-                    }\r
-                    if(gAcceptor == false){\r
-                        showToast("Operation Not Permitted: \nStart Provider Service with provider as acceptor");\r
-                        break;\r
-                    }\r
-                    mProviderSample.SetTopic();\r
-\r
-                }\r
-                break;\r
-\r
-                case R.id.BtnCreateNoti: {\r
-\r
-                    String id = Integer.toString(notiId); // generate notificaion ID\r
-                    String title = editTextTitle.getText().toString();\r
-                    String body = editTextBody.getText().toString();\r
-                    String topic  = editTextTopic.getText().toString();\r
-\r
-                    if(isStarted == false)\r
-                    {\r
-                        Log.e(TAG, "Fail to send NSMessage");\r
-                        showToast("Start ProviderService First");\r
-                        break;\r
-                    }\r
-\r
-                    // Build android noti object and send it to Notification service receiver\r
-                    Notification.Builder notiBuilder = new Notification.Builder(getApplicationContext());\r
-                    notiBuilder.setContentTitle(title);\r
-                    notiBuilder.setContentText(body);\r
-                    notiBuilder.setPriority(Notification.PRIORITY_MAX);\r
-                    notiBuilder.setDefaults(Notification.DEFAULT_ALL);\r
-                    notiBuilder.setSmallIcon(R.mipmap.ic_launcher);\r
-                    NotificationManager notiMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);\r
-                    notiMgr.notify(notiId, notiBuilder.build());\r
-\r
-                    Log.i(TAG, "#" + notiId + " notified ..");\r
-                    TvLog.append("Send Notitication(Msg ID: " + notiId + ")\n");\r
-                    notiId++;\r
-                }\r
-                break;\r
-\r
-                case R.id.BtnStop: {\r
-                    if(isStarted == false) {\r
-                        Log.e(TAG, "Fail to stop service");\r
-                        showToast("Already Stopped");\r
-                        break;\r
-                    }\r
-\r
-                    mProviderSample.Stop();\r
-                    isStarted = false;\r
-                    radioProvider.setEnabled(true);\r
-                    radioConsumer.setEnabled(true);\r
-                    showToast("Stopped ProviderService"+ isStarted);\r
-                    TvLog.append("Stop Provider Service\n");\r
-                }\r
-                break;\r
-\r
-                case R.id.BtnLog: {\r
-\r
-                    TvLog.setText("");\r
-                }\r
-                break;\r
-                case R.id.signup: {\r
-                    if(isStarted == false) {\r
-                        Log.e(TAG, "Fail to Sign Up");\r
-                        showToast("Start ProviderService First");\r
-                        break;\r
-                    }\r
-                    TvLog.append("Initiating SignUp\n");\r
-                    signUp();\r
-                }\r
-                break;\r
-                case R.id.signin: {\r
-                    if(isStarted == false) {\r
-                        Log.e(TAG, "Fail to Sign In");\r
-                        showToast("Start ProviderService First");\r
-                        break;\r
-                    }\r
-                    TvLog.append("Initiating SignIn\n");\r
-                    signIn();\r
-                }\r
-                break;\r
-                case R.id.signout: {\r
-                    if(isStarted == false) {\r
-                        Log.e(TAG, "Fail to Sign out");\r
-                        showToast("Start ProviderService First");\r
-                        break;\r
-                    }\r
-                    TvLog.append("Initiating SignOut\n");\r
-                    signOut();\r
-                }\r
-                break;\r
-                case R.id.remoteService: {\r
-                    remoteService.setEnabled(false);\r
-                    if(isStarted == false) {\r
-                        Log.e(TAG, "Fail to Enable/Disable RemoteService");\r
-                        showToast("Start ProviderService First");\r
-                        break;\r
-                    }\r
-                    if(gRemoteService){\r
-                        TvLog.append("Enable Remote Service\n");\r
-                        int result = mProviderSample.EnableRemoteService(RemoteAddress);\r
-                        remoteService.setText(R.string.disableRemoteService);\r
-                        gRemoteService = false;\r
-                        remoteService.setEnabled(true);\r
-                        TvLog.append("EnableRemoteService Result : " + result + "\n");\r
-                    }\r
-                    else {\r
-                        TvLog.append("Disable Remote Service\n");\r
-                        int result = mProviderSample.DisableRemoteService(RemoteAddress);\r
-                        remoteService.setText(R.string.enableRemoteService);\r
-                        gRemoteService = true;\r
-                        remoteService.setEnabled(true);\r
-                        TvLog.append("DisableRemoteService Result : " + result + "\n");\r
-                    }\r
-                }\r
-                break;\r
-                case R.id.subscribeMQService: {\r
-                    if(isStarted == false) {\r
-                        Log.e(TAG, "Fail to SubscribeMQService");\r
-                        showToast("Start ProviderService First");\r
-                        break;\r
-                    }\r
-                    int result = mProviderSample.subscribeMQService(MQCloudAddress, MQCloudTopic);\r
-                    TvLog.append("SubscribeMQService Result : " + result + "\n");\r
-                }\r
-                break;\r
-            }\r
-        }\r
-    };\r
-    public void logMessage(final String text) {\r
-        runOnUiThread(new Runnable() {\r
-            public void run() {\r
-                Message msg = new Message();\r
-                msg.obj = text;\r
-                TvLog.append(text + "\n");\r
-            }\r
-        });\r
-        Log.i(TAG, text);\r
-    }\r
-    OcAccountManager.OnPostListener onSignUp = new OcAccountManager.OnPostListener() {\r
-        @Override\r
-        public synchronized void onPostCompleted(List<OcHeaderOption> list,\r
-                                                 OcRepresentation ocRepresentation) {\r
-            logMessage("signUp was successful");\r
-            runOnUiThread(new Runnable() {\r
-                public void run() {\r
-                    signIn.setEnabled(true);\r
-                    signUp.setEnabled(false);\r
-                }\r
-            });\r
-            try {\r
-                mUserID = ocRepresentation.getValue("uid");\r
-                mAccessToken = ocRepresentation.getValue("accesstoken");\r
-                mRefreshtoken = ocRepresentation.getValue("refreshtoken");\r
-\r
-                logMessage("\tuserID: " + mUserID);\r
-                logMessage("\taccessToken: " + mAccessToken);\r
-                logMessage("\trefreshToken: " + mRefreshtoken);\r
-\r
-                if (ocRepresentation.hasAttribute("expiresin")) {\r
-                    int expiresIn = ocRepresentation.getValue("expiresin");\r
-                    logMessage("\texpiresIn: " + expiresIn);\r
-                }\r
-            } catch (OcException e) {\r
-                Log.e(TAG, e.toString());\r
-            }\r
-        }\r
-\r
-\r
-        @Override\r
-        public synchronized void onPostFailed(Throwable throwable) {\r
-            logMessage("Failed to signUp");\r
-            if (throwable instanceof OcException) {\r
-                OcException ocEx = (OcException) throwable;\r
-                Log.e(TAG, ocEx.toString());\r
-                ErrorCode errCode = ocEx.getErrorCode();\r
-                logMessage("Error code: " + errCode);\r
-            }\r
-        }\r
-    };\r
-    OcAccountManager.OnPostListener onSignIn = new OcAccountManager.OnPostListener() {\r
-        @Override\r
-        public synchronized void onPostCompleted(List<OcHeaderOption> list,\r
-                                                 OcRepresentation ocRepresentation) {\r
-            logMessage("signIn was successful");\r
-            runOnUiThread(new Runnable() {\r
-                public void run() {\r
-                    signIn.setEnabled(false);\r
-                    signOut.setEnabled(true);\r
-                    remoteService.setEnabled(true);\r
-                }\r
-            });\r
-\r
-        }\r
-\r
-        @Override\r
-        public synchronized void onPostFailed(Throwable throwable) {\r
-            logMessage("Failed to signIn");\r
-            if (throwable instanceof OcException) {\r
-                OcException ocEx = (OcException) throwable;\r
-                Log.e(TAG, ocEx.toString());\r
-                ErrorCode errCode = ocEx.getErrorCode();\r
-                logMessage("Error code: " + errCode);\r
-                if (ErrorCode.UNAUTHORIZED_REQ != errCode) {\r
-                    RefreshToken();\r
-                }\r
-            }\r
-        }\r
-    };\r
-    OcAccountManager.OnPostListener onSignOut = new OcAccountManager.OnPostListener() {\r
-        @Override\r
-        public synchronized void onPostCompleted(List<OcHeaderOption> list,\r
-                                                 OcRepresentation ocRepresentation) {\r
-            logMessage("signOut was successful");\r
-            runOnUiThread(new Runnable() {\r
-                public void run() {\r
-                    signIn.setEnabled(true);\r
-                    signOut.setEnabled(false);\r
-                    remoteService.setEnabled(false);\r
-                }\r
-            });\r
-\r
-        }\r
-\r
-        @Override\r
-        public synchronized void onPostFailed(Throwable throwable) {\r
-            logMessage("Failed to signOut");\r
-            if (throwable instanceof OcException) {\r
-                OcException ocEx = (OcException) throwable;\r
-                Log.e(TAG, ocEx.toString());\r
-                ErrorCode errCode = ocEx.getErrorCode();\r
-                logMessage("Error code: " + errCode);\r
-                if (ErrorCode.UNAUTHORIZED_REQ != errCode) {\r
-                    RefreshToken();\r
-                }\r
-            }\r
-        }\r
-    };\r
-    @Override\r
-    public void onPostCompleted(List<OcHeaderOption> ocHeaderOptions, OcRepresentation ocRepresentation) {\r
-\r
-    }\r
-\r
-    @Override\r
-    public void onPostFailed(Throwable throwable) {\r
-\r
-    }\r
-    private void signIn() {\r
-        try {\r
-            if(mAccountManager==null)\r
-            {\r
-                mAccountManager = OcPlatform.constructAccountManagerObject(CIServer,\r
-                        EnumSet.of(OcConnectivityType.CT_ADAPTER_TCP));\r
-            }\r
-\r
-            mAccountManager.signIn(mUserID, mAccessToken, onSignIn);\r
-        } catch (OcException e) {\r
-            e.printStackTrace();\r
-        }\r
-    }\r
-\r
-    private void signOut() {\r
-        try {\r
-            logMessage("signOut");\r
-            if(mAccountManager==null)\r
-            {\r
-                try {\r
-                    mAccountManager = OcPlatform.constructAccountManagerObject(CIServer,\r
-                            EnumSet.of(OcConnectivityType.CT_ADAPTER_TCP));\r
-                } catch (OcException e) {\r
-                    e.printStackTrace();\r
-                }\r
-            }\r
-            mAccountManager.signOut(mAccessToken, onSignOut);\r
-            signIn.setEnabled(false);\r
-            signUp.setEnabled(true);\r
-            remoteService.setEnabled(false);\r
-            logMessage("signOut Successful");\r
-        } catch (OcException e) {\r
-            e.printStackTrace();\r
-        }\r
-    }\r
-\r
-    private void signUp() {\r
-        try {\r
-            mAccountManager = OcPlatform.constructAccountManagerObject(CIServer,\r
-                    EnumSet.of(OcConnectivityType.CT_ADAPTER_TCP));\r
-        } catch (OcException e) {\r
-            e.printStackTrace();\r
-        }\r
-\r
-        Intent intentLogin = new Intent(this, LoginActivity.class);\r
-        startActivityForResult(intentLogin, REQUEST_LOGIN);\r
-    }\r
-    @Override\r
-    public void onActivityResult(int requestCode, int resultCode, Intent data) {\r
-        super.onActivityResult(requestCode, resultCode, data);\r
-        if (resultCode == Activity.RESULT_OK && requestCode == REQUEST_LOGIN) {\r
-            mAuthCode = data.getStringExtra("authCode");\r
-            mAuthProvider = data.getStringExtra("authProvider");\r
-            logMessage("authCode: " + mAuthCode);\r
-            logMessage("authProvider: " + mAuthProvider);\r
-\r
-            try {\r
-                mAccountManager = OcPlatform.constructAccountManagerObject(CIServer,\r
-                        EnumSet.of(OcConnectivityType.CT_ADAPTER_TCP));\r
-                logMessage("Calling signup API");\r
-\r
-                mAccountManager.signUp(mAuthProvider, mAuthCode, onSignUp);\r
-            } catch (OcException e) {\r
-                e.printStackTrace();\r
-            }\r
-        }\r
-    }\r
-\r
-    OcResource.OnPostListener onRefreshTokenPost = new OcResource.OnPostListener() {\r
-        @Override\r
-        public void onPostCompleted(List<OcHeaderOption> list, OcRepresentation ocRepresentation) {\r
-            logMessage("RefreshToken Completed.");\r
-            try {\r
-                mAccessToken = ocRepresentation.getValue("accesstoken");\r
-                mRefreshtoken = ocRepresentation.getValue("refreshtoken");\r
-            }\r
-            catch (OcException e)\r
-            {\r
-                e.printStackTrace();\r
-            }\r
-            signIn();\r
-        }\r
-\r
-        @Override\r
-        public void onPostFailed(Throwable throwable) {\r
-            logMessage("RefreshToken failed.");\r
-            Log.d(TAG, "onRefreshTokenPost failed..");\r
-        }\r
-    };\r
-    public void RefreshToken() {\r
-        try {\r
-            OcResource authResource = OcPlatform.constructResourceObject(CIServer, "/.well-known/ocf/account/tokenrefresh",\r
-                    EnumSet.of(OcConnectivityType.CT_ADAPTER_TCP, OcConnectivityType.CT_IP_USE_V4),\r
-                    false, Arrays.asList("oic.wk.account"), Arrays.asList(OcPlatform.DEFAULT_INTERFACE));\r
-            OcRepresentation rep = new OcRepresentation();\r
-\r
-            showToast("RefreshToken in progress..");\r
-            logMessage("RefreshToken in progress..");\r
-            rep.setValue("di", deviceID);\r
-            rep.setValue("granttype", "refresh_token");\r
-            rep.setValue("refreshtoken", mRefreshtoken);\r
-            rep.setValue("uid", mUserID);\r
-            authResource.post(rep, new HashMap<String, String>(), onRefreshTokenPost);\r
-        }\r
-        catch(OcException e)\r
-        {\r
-            e.printStackTrace();\r
-        }\r
-\r
-        Log.d(TAG, "No error while executing login");\r
-    }\r
-}\r
-\r
+/*
+//******************************************************************
+//
+// Copyright 2016 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+ */
+
+package org.iotivity.service.ns.sample.provider;
+
+import android.app.Notification;
+import android.app.NotificationManager;
+import android.content.Intent;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Message;
+import android.util.Log;
+import android.view.View;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.RadioButton;
+import android.widget.TextView;
+import android.widget.Toast;
+import android.app.Activity;
+
+import org.iotivity.base.ErrorCode;
+import org.iotivity.base.OcAccountManager;
+import org.iotivity.base.OcConnectivityType;
+import org.iotivity.base.OcException;
+import org.iotivity.base.OcHeaderOption;
+import org.iotivity.base.OcPlatform;
+import org.iotivity.base.OcRepresentation;
+import org.iotivity.base.OcResource;
+
+import java.util.Arrays;
+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() {
+        @Override
+        public void handleMessage(Message msg) {
+            switch (msg.what) {
+                case CONSUMER_SUBSCRIBED:
+                    String ConsumerId = (String) msg.obj;
+                    if(ConsumerId != null)
+                        TvLog.append("Consumer Subscibed: " + ConsumerId + "\n");
+                    break;
+
+                case MESSAGE_SYNC:
+                    String sync = (String) msg.obj;
+                    if(sync != null)
+                        TvLog.append("SyncInfo Received :" + sync + "\n");
+                    break;
+
+                default:
+                    break;
+            }
+        }
+    };
+
+    public void showToast(final String toast)
+    {
+        runOnUiThread(new Runnable() {
+            @Override
+            public void run() {
+                Toast.makeText(getApplicationContext(), toast, Toast.LENGTH_SHORT).show();
+            }
+        });
+    }
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.activity_main);
+
+        btnTitle = (Button) findViewById(R.id.BtnTitle);
+        btnBody = (Button) findViewById(R.id.BtnBody);
+        btnTopic = (Button) findViewById(R.id.BtnTopic);
+        btnSend = (Button) findViewById(R.id.BtnCreateNoti);
+
+        btnStart = (Button) findViewById(R.id.BtnStart);
+        btnRegister = (Button) findViewById(R.id.BtnRegister);
+        btnSet = (Button) findViewById(R.id.BtnSet);
+        btnLog = (Button) findViewById(R.id.BtnLog);
+        btnStop = (Button) findViewById(R.id.BtnStop);
+
+        signUp = (Button) findViewById(R.id.signup);
+        signIn = (Button) findViewById(R.id.signin);
+        signOut = (Button) findViewById(R.id.signout);
+        remoteService = (Button) findViewById(R.id.remoteService);
+        subscribeMQ = (Button) findViewById(R.id.subscribeMQService);
+
+        editTextTitle = (EditText) findViewById(R.id.EditTextTitle);
+        editTextBody = (EditText) findViewById(R.id.EditTextBody);
+        editTextTopic = (EditText) findViewById(R.id.EditTextTopic);
+
+        radioProvider = (RadioButton) findViewById(R.id.RadioProvider);
+        radioConsumer = (RadioButton) findViewById(R.id.RadioConsumer);
+
+        TvLog = (TextView) findViewById(R.id.TvLog);
+
+        btnTitle.setEnabled(false);
+        btnBody.setEnabled(false);
+        btnTopic.setEnabled(false);
+
+        signIn.setEnabled(false);
+        signOut.setEnabled(false);
+        remoteService.setEnabled(false);
+
+        btnSend.setOnClickListener(mClickListener);
+        btnStart.setOnClickListener(mClickListener);
+        btnRegister.setOnClickListener(mClickListener);
+        btnSet.setOnClickListener(mClickListener);
+        btnLog.setOnClickListener(mClickListener);
+        btnStop.setOnClickListener(mClickListener);
+        radioProvider.setOnClickListener(mClickListener);
+        radioConsumer.setOnClickListener(mClickListener);
+
+        signUp.setOnClickListener(mClickListener);
+        signIn.setOnClickListener(mClickListener);
+        signOut.setOnClickListener(mClickListener);
+
+        remoteService.setOnClickListener(mClickListener);
+        subscribeMQ.setOnClickListener(mClickListener);
+
+        mProviderSample = new ProviderSample(getApplicationContext());
+        mProviderSample.setHandler(mHandler);
+
+        mNotiListener = new NotiListener(this);
+        Intent intent = new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS");
+        startActivity(intent);
+    }
+
+    @Override
+    protected void onDestroy() {
+        super.onDestroy();
+    }
+
+    public ProviderSample getProviderSample()
+    {
+        return mProviderSample;
+    }
+
+    Button.OnClickListener mClickListener = new View.OnClickListener() {
+        public void onClick(View v) {
+            switch (v.getId()) {
+                case R.id.RadioProvider: {
+                    if (isStarted == false) {
+                        gAcceptor = true;
+                        showToast("Provider as acceptor is " + gAcceptor);
+                    }
+                    else
+                        showToast("Start ProviderService again to change acceptor as provider");
+                }
+                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");
+                }
+                break;
+
+                case R.id.BtnStart: {
+                    if (isStarted == false) {
+                        Log.i(TAG, "Start  Provider Service");
+                        TvLog.setText("Start Provider Service\n");
+                        mProviderSample.Start(gAcceptor);
+                        isStarted = true;
+                        radioProvider.setEnabled(false);
+                        radioConsumer.setEnabled(false);
+                    } else {
+                        Log.e(TAG, " Provider Service had already started");
+                        showToast(" Provider Service had already started");
+                    }
+                }
+                break;
+
+                case R.id.BtnRegister: {
+                    if (isStarted == false) {
+                        Log.i(TAG, "Start  Provider Service");
+                        TvLog.append("Register Topic : OCF_TOPIC1\n");
+                        TvLog.append("Register Topic : OCF_TOPIC2\n");
+                        TvLog.append("Register Topic : OCF_TOPIC3\n");
+                        TvLog.append("Register Topic : OCF_TOPIC4\n");
+                        showToast("Start Provider Service First");
+                        break;
+                    }
+                    mProviderSample.RegisterTopic();
+
+                }
+                break;
+
+                case R.id.BtnSet: {
+                    if (isStarted == false) {
+                        Log.i(TAG, "Start Provider Service");
+                        TvLog.append("Set Topic : OCF_TOPIC1\n");
+                        TvLog.append("Set Topic : OCF_TOPIC2\n");
+                        TvLog.append("Set Topic : OCF_TOPIC3\n");
+                        TvLog.append("Set Topic : OCF_TOPIC4\n");
+                        showToast("Start Provider Service First");
+                        break;
+                    }
+                    if(gAcceptor == false){
+                        showToast("Operation Not Permitted: \nStart Provider Service with provider as acceptor");
+                        break;
+                    }
+                    mProviderSample.SetTopic();
+
+                }
+                break;
+
+                case R.id.BtnCreateNoti: {
+
+                    String id = Integer.toString(notiId); // generate notificaion ID
+                    String title = editTextTitle.getText().toString();
+                    String body = editTextBody.getText().toString();
+                    String topic  = editTextTopic.getText().toString();
+
+                    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());
+                    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);
+                    notiMgr.notify(notiId, notiBuilder.build());
+
+                    Log.i(TAG, "#" + notiId + " notified ..");
+                    TvLog.append("Send Notitication(Msg ID: " + notiId + ")\n");
+                    notiId++;
+                }
+                break;
+
+                case R.id.BtnStop: {
+                    if(isStarted == false) {
+                        Log.e(TAG, "Fail to stop service");
+                        showToast("Already Stopped");
+                        break;
+                    }
+
+                    mProviderSample.Stop();
+                    isStarted = false;
+                    radioProvider.setEnabled(true);
+                    radioConsumer.setEnabled(true);
+                    showToast("Stopped ProviderService"+ isStarted);
+                    TvLog.append("Stop Provider Service\n");
+                }
+                break;
+
+                case R.id.BtnLog: {
+
+                    TvLog.setText("");
+                }
+                break;
+                case R.id.signup: {
+                    if(isStarted == false) {
+                        Log.e(TAG, "Fail to Sign Up");
+                        showToast("Start ProviderService First");
+                        break;
+                    }
+                    TvLog.append("Initiating SignUp\n");
+                    signUp();
+                }
+                break;
+                case R.id.signin: {
+                    if(isStarted == false) {
+                        Log.e(TAG, "Fail to Sign In");
+                        showToast("Start ProviderService First");
+                        break;
+                    }
+                    TvLog.append("Initiating SignIn\n");
+                    signIn();
+                }
+                break;
+                case R.id.signout: {
+                    if(isStarted == false) {
+                        Log.e(TAG, "Fail to Sign out");
+                        showToast("Start ProviderService First");
+                        break;
+                    }
+                    TvLog.append("Initiating SignOut\n");
+                    signOut();
+                }
+                break;
+                case R.id.remoteService: {
+                    remoteService.setEnabled(false);
+                    if(isStarted == false) {
+                        Log.e(TAG, "Fail to Enable/Disable RemoteService");
+                        showToast("Start ProviderService First");
+                        break;
+                    }
+                    if(gRemoteService){
+                        TvLog.append("Enable Remote Service\n");
+                        int result = mProviderSample.EnableRemoteService(RemoteAddress);
+                        remoteService.setText(R.string.disableRemoteService);
+                        gRemoteService = false;
+                        remoteService.setEnabled(true);
+                        TvLog.append("EnableRemoteService Result : " + result + "\n");
+                    }
+                    else {
+                        TvLog.append("Disable Remote Service\n");
+                        int result = mProviderSample.DisableRemoteService(RemoteAddress);
+                        remoteService.setText(R.string.enableRemoteService);
+                        gRemoteService = true;
+                        remoteService.setEnabled(true);
+                        TvLog.append("DisableRemoteService Result : " + result + "\n");
+                    }
+                }
+                break;
+                case R.id.subscribeMQService: {
+                    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");
+                }
+                break;
+            }
+        }
+    };
+    public void logMessage(final String text) {
+        runOnUiThread(new Runnable() {
+            public void run() {
+                Message msg = new Message();
+                msg.obj = text;
+                TvLog.append(text + "\n");
+            }
+        });
+        Log.i(TAG, text);
+    }
+    OcAccountManager.OnPostListener onSignUp = new OcAccountManager.OnPostListener() {
+        @Override
+        public synchronized void onPostCompleted(List<OcHeaderOption> list,
+                                                 OcRepresentation ocRepresentation) {
+            logMessage("signUp was successful");
+            runOnUiThread(new Runnable() {
+                public void run() {
+                    signIn.setEnabled(true);
+                    signUp.setEnabled(false);
+                }
+            });
+            try {
+                mUserID = ocRepresentation.getValue("uid");
+                mAccessToken = ocRepresentation.getValue("accesstoken");
+                mRefreshtoken = ocRepresentation.getValue("refreshtoken");
+
+                logMessage("\tuserID: " + mUserID);
+                logMessage("\taccessToken: " + mAccessToken);
+                logMessage("\trefreshToken: " + mRefreshtoken);
+
+                if (ocRepresentation.hasAttribute("expiresin")) {
+                    int expiresIn = ocRepresentation.getValue("expiresin");
+                    logMessage("\texpiresIn: " + expiresIn);
+                }
+            } catch (OcException e) {
+                Log.e(TAG, e.toString());
+            }
+        }
+
+
+        @Override
+        public synchronized void onPostFailed(Throwable throwable) {
+            logMessage("Failed to signUp");
+            if (throwable instanceof OcException) {
+                OcException ocEx = (OcException) throwable;
+                Log.e(TAG, ocEx.toString());
+                ErrorCode errCode = ocEx.getErrorCode();
+                logMessage("Error code: " + errCode);
+            }
+        }
+    };
+    OcAccountManager.OnPostListener onSignIn = new OcAccountManager.OnPostListener() {
+        @Override
+        public synchronized void onPostCompleted(List<OcHeaderOption> list,
+                                                 OcRepresentation ocRepresentation) {
+            logMessage("signIn was successful");
+            runOnUiThread(new Runnable() {
+                public void run() {
+                    signIn.setEnabled(false);
+                    signOut.setEnabled(true);
+                    remoteService.setEnabled(true);
+                }
+            });
+
+        }
+
+        @Override
+        public synchronized void onPostFailed(Throwable throwable) {
+            logMessage("Failed to signIn");
+            if (throwable instanceof OcException) {
+                OcException ocEx = (OcException) throwable;
+                Log.e(TAG, ocEx.toString());
+                ErrorCode errCode = ocEx.getErrorCode();
+                logMessage("Error code: " + errCode);
+                if (ErrorCode.UNAUTHORIZED_REQ != errCode) {
+                    RefreshToken();
+                }
+            }
+        }
+    };
+    OcAccountManager.OnPostListener onSignOut = new OcAccountManager.OnPostListener() {
+        @Override
+        public synchronized void onPostCompleted(List<OcHeaderOption> list,
+                                                 OcRepresentation ocRepresentation) {
+            logMessage("signOut was successful");
+            runOnUiThread(new Runnable() {
+                public void run() {
+                    signIn.setEnabled(true);
+                    signOut.setEnabled(false);
+                    remoteService.setEnabled(false);
+                }
+            });
+
+        }
+
+        @Override
+        public synchronized void onPostFailed(Throwable throwable) {
+            logMessage("Failed to signOut");
+            if (throwable instanceof OcException) {
+                OcException ocEx = (OcException) throwable;
+                Log.e(TAG, ocEx.toString());
+                ErrorCode errCode = ocEx.getErrorCode();
+                logMessage("Error code: " + errCode);
+                if (ErrorCode.UNAUTHORIZED_REQ != errCode) {
+                    RefreshToken();
+                }
+            }
+        }
+    };
+    @Override
+    public void onPostCompleted(List<OcHeaderOption> ocHeaderOptions, OcRepresentation ocRepresentation) {
+
+    }
+
+    @Override
+    public void onPostFailed(Throwable throwable) {
+
+    }
+    private void signIn() {
+        try {
+            if(mAccountManager==null)
+            {
+                mAccountManager = OcPlatform.constructAccountManagerObject(CIServer,
+                        EnumSet.of(OcConnectivityType.CT_ADAPTER_TCP));
+            }
+
+            mAccountManager.signIn(mUserID, mAccessToken, onSignIn);
+        } catch (OcException e) {
+            e.printStackTrace();
+        }
+    }
+
+    private void signOut() {
+        try {
+            logMessage("signOut");
+            if(mAccountManager==null)
+            {
+                try {
+                    mAccountManager = OcPlatform.constructAccountManagerObject(CIServer,
+                            EnumSet.of(OcConnectivityType.CT_ADAPTER_TCP));
+                } catch (OcException e) {
+                    e.printStackTrace();
+                }
+            }
+            mAccountManager.signOut(mAccessToken, onSignOut);
+            signIn.setEnabled(false);
+            signUp.setEnabled(true);
+            remoteService.setEnabled(false);
+            logMessage("signOut Successful");
+        } 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);
+        if (resultCode == Activity.RESULT_OK && requestCode == REQUEST_LOGIN) {
+            mAuthCode = data.getStringExtra("authCode");
+            mAuthProvider = data.getStringExtra("authProvider");
+            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();
+            }
+        }
+    }
+
+    OcResource.OnPostListener onRefreshTokenPost = new OcResource.OnPostListener() {
+        @Override
+        public void onPostCompleted(List<OcHeaderOption> list, OcRepresentation ocRepresentation) {
+            logMessage("RefreshToken Completed.");
+            try {
+                mAccessToken = ocRepresentation.getValue("accesstoken");
+                mRefreshtoken = ocRepresentation.getValue("refreshtoken");
+            }
+            catch (OcException e)
+            {
+                e.printStackTrace();
+            }
+            signIn();
+        }
+
+        @Override
+        public void onPostFailed(Throwable throwable) {
+            logMessage("RefreshToken failed.");
+            Log.d(TAG, "onRefreshTokenPost failed.");
+        }
+    };
+    public void RefreshToken() {
+        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));
+            OcRepresentation rep = new OcRepresentation();
+
+            showToast("RefreshToken in progress..");
+            logMessage("RefreshToken in progress..");
+            rep.setValue("di", deviceID);
+            rep.setValue("granttype", "refresh_token");
+            rep.setValue("refreshtoken", mRefreshtoken);
+            rep.setValue("uid", mUserID);
+            authResource.post(rep, new HashMap<String, String>(), onRefreshTokenPost);
+        }
+        catch(OcException e)
+        {
+            e.printStackTrace();
+        }
+
+        Log.d(TAG, "No error while executing login");
+    }
+}
+
-/*\r
-//******************************************************************\r
-//\r
-// Copyright 2016 Samsung Electronics All Rights Reserved.\r
-//\r
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
-//\r
-// Licensed under the Apache License, Version 2.0 (the "License");\r
-// you may not use this file except in compliance with the License.\r
-// You may obtain a copy of the License at\r
-//\r
-//      http://www.apache.org/licenses/LICENSE-2.0\r
-//\r
-// Unless required by applicable law or agreed to in writing, software\r
-// distributed under the License is distributed on an "AS IS" BASIS,\r
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
-// See the License for the specific language governing permissions and\r
-// limitations under the License.\r
-//\r
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
- */\r
-\r
-package com.sec.notiproviderexample;\r
-\r
-import android.app.Notification;\r
-import android.os.Bundle;\r
-import android.service.notification.NotificationListenerService;\r
-import android.service.notification.StatusBarNotification;\r
-import android.util.Log;\r
-import org.iotivity.service.ns.common.MediaContents;\r
-import org.iotivity.service.ns.common.Message;\r
-import java.util.ArrayList;\r
-\r
-public class NotiListener extends NotificationListenerService {\r
-\r
-    private final String TAG = "NS_JNI_NOTI_LISTENER";\r
-    private static ProviderSample mProviderSample = null;\r
-    private MainActivity mActivity = null;\r
-    ArrayList mBlackSourceList = new ArrayList<String>();\r
-\r
-    public NotiListener() {\r
-\r
-        Log.i(TAG, "Create NotiListener");\r
-    }\r
-\r
-    public NotiListener(MainActivity activity) {\r
-\r
-        Log.i(TAG, "Create NotiListener with MainActivity");\r
-\r
-        this.mActivity = activity;\r
-        this.mProviderSample = mActivity.getProviderSample();\r
-\r
-        setBlackSourceList();\r
-\r
-        if(mProviderSample == null) {\r
-            Log.i(TAG, "Fail to get providerProxy instance");\r
-        }\r
-    }\r
-\r
-    public void setBlackSourceList() {\r
-\r
-        // set blacklist of app package name not to receive notification\r
-        mBlackSourceList.add("android");\r
-        mBlackSourceList.add("com.android.systemui");\r
-    }\r
-\r
-    @Override\r
-    public void onNotificationPosted(StatusBarNotification sbn) {\r
-        super.onNotificationPosted(sbn);\r
-\r
-        Bundle bundle = sbn.getNotification().extras;\r
-        String source = null;\r
-\r
-        // prevent not to send notification\r
-        for(int i = 0; i < mBlackSourceList.size(); ++i)\r
-        {\r
-            if (sbn.getPackageName().equals(mBlackSourceList.get(i)))\r
-            {\r
-                return;\r
-            }\r
-        }\r
-\r
-        // filter exception case : Some notification are generated twice\r
-        if(sbn.getId() > 10000 || sbn.getId() < 0)\r
-            return;\r
-\r
-        // Temporary protocol code to display ICON on consumer app.\r
-        // For example, consumer app shows KAKAOTALK Icon when receiving Notification with SOURCE\r
-        // that is set to KAKAO, otherwise it displays OCF Icon on current sample app.\r
-        if(sbn.getPackageName().equals("com.kakao.talk"))\r
-            source = "KAKAO";\r
-        else\r
-            source = "OCF";\r
-\r
-        Log.i(TAG, "Noti. Package Name : " + sbn.getPackageName());\r
-        Log.i(TAG, "Noti. ID : " + sbn.getId());\r
-\r
-        String id = Integer.toString(sbn.getId());\r
-        String title = bundle.getString(Notification.EXTRA_TITLE, "");\r
-        String body = bundle.getString(Notification.EXTRA_TEXT, "");\r
-\r
-        Log.i(TAG, "onNotificationPosted .. ");\r
-        Log.i(TAG, "source : " + source);\r
-        Log.i(TAG, "Id : " + id);\r
-        Log.i(TAG, "Title : " + title);\r
-        Log.i(TAG, "Body : " + body);\r
-\r
-        Message notiMessage = new Message(title,body,source);\r
-        notiMessage.setTTL(10);\r
-        notiMessage.setTime("12:10");\r
-        MediaContents media = new MediaContents("daasd");\r
-        notiMessage.setMediaContents(media);\r
-        if (mProviderSample != null) {\r
-            mProviderSample.SendMessage(notiMessage);\r
-        } else {\r
-            Log.i(TAG, "providerExample is NULL");\r
-        }\r
-    }\r
-\r
-    @Override\r
-    public void onNotificationRemoved(StatusBarNotification sbn) {\r
-        super.onNotificationRemoved(sbn);\r
-\r
-        Bundle bundle = sbn.getNotification().extras;\r
-\r
-        if (sbn.getPackageName().equals("android"))\r
-            return;\r
-\r
-        Log.i(TAG, "Noti. Package Name : " + sbn.getPackageName());\r
-        Log.i(TAG, "Noti. ID : " + sbn.getId());\r
-\r
-        if(mProviderSample.getMsgMap().containsKey(sbn.getId()))\r
-        {\r
-            if(mProviderSample.getMsgMap().get(sbn.getId()) == 2)\r
-            {\r
-                org.iotivity.service.ns.common.SyncInfo.SyncType type = org.iotivity.service.ns.common.SyncInfo.SyncType.READ;\r
-                mProviderSample.SendSyncInfo(1,type);\r
-            }\r
-        }\r
-    }\r
-}\r
+/*
+//******************************************************************
+//
+// Copyright 2016 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+ */
+
+package org.iotivity.service.ns.sample.provider;
+
+import android.app.Notification;
+import android.os.Bundle;
+import android.service.notification.NotificationListenerService;
+import android.service.notification.StatusBarNotification;
+import android.util.Log;
+import org.iotivity.service.ns.common.MediaContents;
+import org.iotivity.service.ns.common.Message;
+import java.util.ArrayList;
+
+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>();
+
+    public NotiListener() {
+
+        Log.i(TAG, "Create NotiListener");
+    }
+
+    public NotiListener(MainActivity activity) {
+
+        Log.i(TAG, "Create NotiListener with MainActivity");
+
+        this.mActivity = activity;
+        this.mProviderSample = mActivity.getProviderSample();
+
+        setBlackSourceList();
+
+        if(mProviderSample == null) {
+            Log.i(TAG, "Fail to get providerProxy instance");
+        }
+    }
+
+    public void setBlackSourceList() {
+
+        // set blacklist of app package name not to receive notification
+        mBlackSourceList.add("android");
+        mBlackSourceList.add("com.android.systemui");
+    }
+
+    @Override
+    public void onNotificationPosted(StatusBarNotification sbn) {
+        super.onNotificationPosted(sbn);
+
+        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)))
+            {
+                return;
+            }
+        }
+
+        // filter exception case : Some notification are generated twice
+        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"))
+            source = "KAKAO";
+        else
+            source = "OCF";
+
+        Log.i(TAG, "Noti. Package Name : " + sbn.getPackageName());
+        Log.i(TAG, "Noti. ID : " + sbn.getId());
+
+        String id = Integer.toString(sbn.getId());
+        String title = bundle.getString(Notification.EXTRA_TITLE, "");
+        String body = bundle.getString(Notification.EXTRA_TEXT, "");
+
+        Log.i(TAG, "onNotificationPosted .. ");
+        Log.i(TAG, "source : " + source);
+        Log.i(TAG, "Id : " + id);
+        Log.i(TAG, "Title : " + title);
+        Log.i(TAG, "Body : " + body);
+
+        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);
+        } else {
+            Log.i(TAG, "providerExample is NULL");
+        }
+    }
+
+    @Override
+    public void onNotificationRemoved(StatusBarNotification sbn) {
+        super.onNotificationRemoved(sbn);
+
+        Bundle bundle = sbn.getNotification().extras;
+
+        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)
+            {
+                org.iotivity.service.ns.common.SyncInfo.SyncType type = org.iotivity.service.ns.common.SyncInfo.SyncType.READ;
+                mProviderSample.SendSyncInfo(1,type);
+            }
+        }
+    }
+}
index 45cfebc..036ab7f 100755 (executable)
@@ -7,7 +7,7 @@
     android:paddingLeft="@dimen/activity_horizontal_margin"\r
     android:paddingRight="@dimen/activity_horizontal_margin"\r
     android:paddingTop="@dimen/activity_vertical_margin"\r
-    tools:context="com.sec.notificationexample.MainActivity">\r
+    tools:context=".MainActivity">\r
 \r
     <ScrollView\r
         android:layout_width="match_parent"\r