replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / service / notification / examples / android / NotiProviderExample / app / src / main / java / org / iotivity / service / ns / sample / provider / MainActivity.java
1 /*
2 //******************************************************************
3 //
4 // Copyright 2016 Samsung Electronics All Rights Reserved.
5 //
6 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 //
8 // Licensed under the Apache License, Version 2.0 (the "License");
9 // you may not use this file except in compliance with the License.
10 // You may obtain a copy of the License at
11 //
12 //      http://www.apache.org/licenses/LICENSE-2.0
13 //
14 // Unless required by applicable law or agreed to in writing, software
15 // distributed under the License is distributed on an "AS IS" BASIS,
16 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 // See the License for the specific language governing permissions and
18 // limitations under the License.
19 //
20 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21  */
22
23 package org.iotivity.service.ns.sample.provider;
24
25 import android.app.Dialog;
26 import android.app.Notification;
27 import android.app.NotificationManager;
28 import android.content.Context;
29 import android.content.Intent;
30 import android.os.Bundle;
31 import android.os.Handler;
32 import android.os.Message;
33 import android.util.Log;
34 import android.view.View;
35 import android.widget.Button;
36 import android.widget.EditText;
37 import android.widget.RadioButton;
38 import android.widget.TextView;
39 import android.widget.Toast;
40 import android.app.Activity;
41
42 import org.iotivity.base.ErrorCode;
43 import org.iotivity.base.OcAccountManager;
44 import org.iotivity.base.OcConnectivityType;
45 import org.iotivity.base.OcException;
46 import org.iotivity.base.OcHeaderOption;
47 import org.iotivity.base.OcPlatform;
48 import org.iotivity.base.OcRepresentation;
49 import org.iotivity.base.OcResource;
50
51 import java.util.Arrays;
52 import java.util.EnumSet;
53 import java.util.HashMap;
54 import java.util.List;
55 import java.util.Map;
56
57 public class MainActivity extends Activity
58         implements OcAccountManager.OnPostListener {
59
60     private final String        TAG                 = "NS_MAIN_ACTIVITY";
61     private static final int    CONSUMER_SUBSCRIBED = 1;
62     private static final int    MESSAGE_SYNC        = 2;
63     private final int           REQUEST_LOGIN       = 1;
64     private static final String CI_SERVER_PREFIX    = "coap+tcp://";
65     private final Context       context             = this;
66
67     public static String        deviceID            = null;
68     public static String        CIServer            = null;
69     public static String        RemoteAddress       = null;
70     public static String        MQCloudAddress      = null;
71     public static String        MQCloudTopic        = null;
72
73     private Button              btnTitle;
74     private Button              btnBody;
75     private Button              btnTopic;
76     private Button              btnSend;
77     private Button              btnStart;
78     private Button              btnRegister;
79     private Button              btnSet;
80     private Button              btnStop;
81     private Button              btnLog;
82     private Button              signUp, signIn, signOut;
83     private Button              remoteService, subscribeMQ;
84     private EditText            editTextTitle;
85     private EditText            editTextBody;
86     private EditText            editTextTopic;
87     private RadioButton         radioProvider;
88     private RadioButton         radioConsumer;
89     private static TextView     TvLog;
90
91     private OcAccountManager    mAccountManager;
92     String                      mAuthCode;
93     String                      mAuthProvider;
94     String                      mRefreshtoken;
95     String                      mUserID;
96     String                      mAccessToken;
97
98     private static int          notiId              = 100;
99     private boolean             isStarted           = false;
100     private boolean             gAcceptor           = true;
101     private boolean             gRemoteService      = true;
102
103     private NotiListener        mNotiListener       = null;
104     private ProviderSample      mProviderSample     = null;
105
106     public static Handler       mHandler            = new Handler() {
107         @Override
108         public void handleMessage(Message msg) {
109             switch (msg.what) {
110                 case CONSUMER_SUBSCRIBED:
111                     String ConsumerId = (String) msg.obj;
112                     if (ConsumerId != null)
113                         TvLog.append("Consumer Subscibed: " + ConsumerId + "\n");
114                     break;
115
116                 case MESSAGE_SYNC:
117                     String sync = (String) msg.obj;
118                     if (sync != null)
119                         TvLog.append("SyncInfo Received :" + sync + "\n");
120                     break;
121
122                 default:
123                     break;
124             }
125         }
126
127     };
128
129     public void showToast(final String toast) {
130         runOnUiThread(new Runnable() {
131             @Override
132             public void run() {
133                 Toast.makeText(getApplicationContext(), toast,
134                         Toast.LENGTH_SHORT).show();
135             }
136         });
137     }
138
139     @Override
140     protected void onCreate(Bundle savedInstanceState) {
141         super.onCreate(savedInstanceState);
142         setContentView(R.layout.activity_main);
143
144         btnTitle = (Button) findViewById(R.id.BtnTitle);
145         btnBody = (Button) findViewById(R.id.BtnBody);
146         btnTopic = (Button) findViewById(R.id.BtnTopic);
147         btnSend = (Button) findViewById(R.id.BtnCreateNoti);
148
149         btnStart = (Button) findViewById(R.id.BtnStart);
150         btnRegister = (Button) findViewById(R.id.BtnRegister);
151         btnSet = (Button) findViewById(R.id.BtnSet);
152         btnLog = (Button) findViewById(R.id.BtnLog);
153         btnStop = (Button) findViewById(R.id.BtnStop);
154
155         signUp = (Button) findViewById(R.id.signup);
156         signIn = (Button) findViewById(R.id.signin);
157         signOut = (Button) findViewById(R.id.signout);
158         remoteService = (Button) findViewById(R.id.remoteService);
159         subscribeMQ = (Button) findViewById(R.id.subscribeMQService);
160
161         editTextTitle = (EditText) findViewById(R.id.EditTextTitle);
162         editTextBody = (EditText) findViewById(R.id.EditTextBody);
163         editTextTopic = (EditText) findViewById(R.id.EditTextTopic);
164
165         radioProvider = (RadioButton) findViewById(R.id.RadioProvider);
166         radioConsumer = (RadioButton) findViewById(R.id.RadioConsumer);
167
168         TvLog = (TextView) findViewById(R.id.TvLog);
169
170         btnTitle.setEnabled(false);
171         btnBody.setEnabled(false);
172         btnTopic.setEnabled(false);
173
174         signIn.setEnabled(false);
175         signOut.setEnabled(false);
176         remoteService.setEnabled(false);
177
178         btnSend.setOnClickListener(mClickListener);
179         btnStart.setOnClickListener(mClickListener);
180         btnRegister.setOnClickListener(mClickListener);
181         btnSet.setOnClickListener(mClickListener);
182         btnLog.setOnClickListener(mClickListener);
183         btnStop.setOnClickListener(mClickListener);
184         radioProvider.setOnClickListener(mClickListener);
185         radioConsumer.setOnClickListener(mClickListener);
186
187         signUp.setOnClickListener(mClickListener);
188         signIn.setOnClickListener(mClickListener);
189         signOut.setOnClickListener(mClickListener);
190
191         remoteService.setOnClickListener(mClickListener);
192         subscribeMQ.setOnClickListener(mClickListener);
193
194         mProviderSample = new ProviderSample(getApplicationContext());
195         mProviderSample.setHandler(mHandler);
196
197         mNotiListener = new NotiListener(this);
198         Intent intent = new Intent(
199                 "android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS");
200         startActivity(intent);
201     }
202
203     @Override
204     protected void onDestroy() {
205         super.onDestroy();
206     }
207
208     public ProviderSample getProviderSample() {
209         return mProviderSample;
210     }
211
212     Button.OnClickListener mClickListener = new View.OnClickListener() {
213         public void onClick(View v) {
214             switch (v.getId()) {
215                 case R.id.RadioProvider: {
216                     if (isStarted == false) {
217                         gAcceptor = true;
218                         showToast("Provider as acceptor is " + gAcceptor);
219                     } else
220                         showToast(
221                                 "Start ProviderService again to change acceptor as provider");
222                 }
223                     break;
224
225                 case R.id.RadioConsumer: {
226                     if (isStarted == false) {
227                         gAcceptor = false;
228                         showToast("Provider as acceptor is " + gAcceptor);
229                     } else
230                         showToast(
231                                 "Start ProviderService again to change acceptor as consumer");
232                 }
233                     break;
234
235                 case R.id.BtnStart: {
236                     if (isStarted == false) {
237                         Log.i(TAG, "Start  Provider Service");
238                         TvLog.setText("Start Provider Service\n");
239                         mProviderSample.start(gAcceptor);
240                         isStarted = true;
241                         radioProvider.setEnabled(false);
242                         radioConsumer.setEnabled(false);
243                         // refreshToken();
244
245                     } else {
246                         Log.e(TAG, " Provider Service had already started");
247                         showToast(" Provider Service had already started");
248                     }
249                 }
250                     break;
251
252                 case R.id.BtnRegister: {
253                     if (isStarted == false) {
254                         Log.i(TAG, "Start  Provider Service");
255                         TvLog.append("Register Topic : OCF_TOPIC1\n");
256                         TvLog.append("Register Topic : OCF_TOPIC2\n");
257                         TvLog.append("Register Topic : OCF_TOPIC3\n");
258                         TvLog.append("Register Topic : OCF_TOPIC4\n");
259                         showToast("Start Provider Service First");
260                         break;
261                     }
262                     mProviderSample.registerTopic();
263
264                 }
265                     break;
266
267                 case R.id.BtnSet: {
268                     if (isStarted == false) {
269                         Log.i(TAG, "Start Provider Service");
270                         TvLog.append("Set Topic : OCF_TOPIC1\n");
271                         TvLog.append("Set Topic : OCF_TOPIC2\n");
272                         TvLog.append("Set Topic : OCF_TOPIC3\n");
273                         TvLog.append("Set Topic : OCF_TOPIC4\n");
274                         showToast("Start Provider Service First");
275                         break;
276                     }
277                     if (gAcceptor == false) {
278                         showToast(
279                                 "Operation Not Permitted: \nStart Provider Service with provider as acceptor");
280                         break;
281                     }
282                     mProviderSample.setTopic();
283
284                 }
285                     break;
286
287                 case R.id.BtnCreateNoti: {
288
289                     String id = Integer.toString(notiId); // generate
290                                                           // notificaion ID
291                     String title = editTextTitle.getText().toString();
292                     String body = editTextBody.getText().toString();
293                     String topic = editTextTopic.getText().toString();
294
295                     if (isStarted == false) {
296                         Log.e(TAG, "Fail to send NSMessage");
297                         showToast("Start ProviderService First");
298                         break;
299                     }
300
301                     // Build android noti object and send it to Notification
302                     // service receiver
303                     Notification.Builder notiBuilder = new Notification.Builder(
304                             getApplicationContext());
305                     notiBuilder.setContentTitle(title);
306                     notiBuilder.setContentText(body);
307                     notiBuilder.setSubText(topic);
308                     notiBuilder.setPriority(Notification.PRIORITY_MAX);
309                     notiBuilder.setDefaults(Notification.DEFAULT_ALL);
310                     notiBuilder.setSmallIcon(R.mipmap.ic_launcher);
311                     NotificationManager notiMgr = (NotificationManager) getSystemService(
312                             NOTIFICATION_SERVICE);
313                     notiMgr.notify(notiId, notiBuilder.build());
314
315                     Log.i(TAG, "#" + notiId + " notified ..");
316                     TvLog.append("Send Notitication(Msg ID: " + notiId + ")\n");
317                     notiId++;
318                 }
319                     break;
320
321                 case R.id.BtnStop: {
322                     if (isStarted == false) {
323                         Log.e(TAG, "Fail to stop service");
324                         showToast("Already Stopped");
325                         break;
326                     }
327
328                     mProviderSample.stop();
329                     isStarted = false;
330                     radioProvider.setEnabled(true);
331                     radioConsumer.setEnabled(true);
332                     showToast("Stopped ProviderService" + isStarted);
333                     TvLog.append("Stop Provider Service\n");
334                 }
335                     break;
336
337                 case R.id.BtnLog: {
338
339                     TvLog.setText("");
340                 }
341                     break;
342                 case R.id.signup: {
343                     if (isStarted == false) {
344                         Log.e(TAG, "Fail to Sign Up");
345                         showToast("Start ProviderService First");
346                         break;
347                     }
348                     TvLog.append("Initiating SignUp\n");
349                     signUp();
350                 }
351                     break;
352                 case R.id.signin: {
353                     if (isStarted == false) {
354                         Log.e(TAG, "Fail to Sign In");
355                         showToast("Start ProviderService First");
356                         break;
357                     }
358                     TvLog.append("Initiating SignIn\n");
359                     signIn();
360                 }
361                     break;
362                 case R.id.signout: {
363                     if (isStarted == false) {
364                         Log.e(TAG, "Fail to Sign out");
365                         showToast("Start ProviderService First");
366                         break;
367                     }
368                     TvLog.append("Initiating SignOut\n");
369                     signOut();
370                 }
371                     break;
372                 case R.id.remoteService: {
373                     remoteService.setEnabled(false);
374                     if (isStarted == false) {
375                         Log.e(TAG, "Fail to Enable/Disable RemoteService");
376                         showToast("Start ProviderService First");
377                         break;
378                     }
379                     if (gRemoteService) {
380                         TvLog.append("Enable Remote Service\n");
381                         mProviderSample.enableRemoteService(RemoteAddress);
382                         remoteService.setText(R.string.disableRemoteService);
383                         gRemoteService = false;
384                         remoteService.setEnabled(true);
385                         TvLog.append("EnableRemoteService success \n");
386                     } else {
387                         TvLog.append("Disable Remote Service\n");
388                         mProviderSample.disableRemoteService(RemoteAddress);
389                         remoteService.setText(R.string.enableRemoteService);
390                         gRemoteService = true;
391                         remoteService.setEnabled(true);
392                         TvLog.append("DisableRemoteService success\n");
393                     }
394                 }
395                     break;
396                 case R.id.subscribeMQService: {
397                     if (isStarted == false) {
398                         Log.e(TAG, "Fail to SubscribeMQService");
399                         showToast("Start ProviderService First");
400                         break;
401                     }
402                     final Dialog dialog = new Dialog(context);
403                     dialog.setContentView(R.layout.dialog_mq);
404                     dialog.setTitle("MQ Cloud Service Details");
405
406                     final EditText ip = (EditText) dialog
407                             .findViewById(R.id.EditTextIp);
408                     final EditText mqTopic = (EditText) dialog
409                             .findViewById(R.id.EditTextMqTopic);
410                     if (MQCloudAddress != null && MQCloudTopic != null) {
411                         ip.setText(MQCloudAddress);
412                         mqTopic.setText(MQCloudTopic);
413                     }
414
415                     Button dialogButton = (Button) dialog
416                             .findViewById(R.id.mqButtonOK);
417
418                     dialogButton.setOnClickListener(new View.OnClickListener() {
419                         @Override
420                         public void onClick(View v) {
421                             dialog.dismiss();
422                             MQCloudAddress = ip.getText().toString();
423                             MQCloudTopic = mqTopic.getText().toString();
424                             mProviderSample.subscribeMQService(
425                                     MQCloudAddress, MQCloudTopic);
426                             TvLog.append("SubscribeMQService success\n");
427                         }
428                     });
429                     dialog.show();
430                 }
431                     break;
432             }
433         }
434     };
435
436     public void logMessage(final String text) {
437         runOnUiThread(new Runnable() {
438             public void run() {
439                 Message msg = new Message();
440                 msg.obj = text;
441                 TvLog.append(text + "\n");
442             }
443         });
444         Log.i(TAG, text);
445     }
446
447     OcAccountManager.OnPostListener onSignUp  = new OcAccountManager.OnPostListener() {
448         @Override
449         public synchronized void onPostCompleted(List<OcHeaderOption> list,
450                 OcRepresentation ocRepresentation) {
451             logMessage("signUp was successful");
452             runOnUiThread(new Runnable() {
453                 public void run() {
454                     signIn.setEnabled(true);
455                     signUp.setEnabled(false);
456                 }
457             });
458             try {
459                 mUserID = ocRepresentation.getValue("uid");
460                 mAccessToken = ocRepresentation.getValue("accesstoken");
461                 mRefreshtoken = ocRepresentation.getValue("refreshtoken");
462
463                 logMessage("\tuserID: " + mUserID);
464                 logMessage("\taccessToken: " + mAccessToken);
465                 logMessage("\trefreshToken: " + mRefreshtoken);
466
467                 if (ocRepresentation.hasAttribute("expiresin")) {
468                     int expiresIn = ocRepresentation.getValue("expiresin");
469                     logMessage("\texpiresIn: " + expiresIn);
470                 }
471             } catch (OcException e) {
472                 Log.e(TAG, e.toString());
473             }
474         }
475
476         @Override
477         public synchronized void onPostFailed(Throwable throwable) {
478             logMessage("Failed to signUp");
479             if (throwable instanceof OcException) {
480                 OcException ocEx = (OcException) throwable;
481                 Log.e(TAG, ocEx.toString());
482                 ErrorCode errCode = ocEx.getErrorCode();
483                 logMessage("Error code: " + errCode);
484             }
485         }
486     };
487
488     OcAccountManager.OnPostListener onSignIn  = new OcAccountManager.OnPostListener() {
489         @Override
490         public synchronized void onPostCompleted(List<OcHeaderOption> list,
491                 OcRepresentation ocRepresentation) {
492             logMessage("signIn was successful");
493             runOnUiThread(new Runnable() {
494                 public void run() {
495                     signIn.setEnabled(false);
496                     signOut.setEnabled(true);
497                     remoteService.setEnabled(true);
498                 }
499             });
500         }
501
502         @Override
503         public synchronized void onPostFailed(Throwable throwable) {
504             logMessage("Failed to signIn");
505             if (throwable instanceof OcException) {
506                 OcException ocEx = (OcException) throwable;
507                 Log.e(TAG, ocEx.toString());
508                 ErrorCode errCode = ocEx.getErrorCode();
509                 logMessage("Error code: " + errCode);
510                 if (ErrorCode.UNAUTHORIZED_REQ != errCode) {
511                     refreshToken();
512                 }
513             }
514         }
515     };
516
517     OcAccountManager.OnPostListener onSignOut = new OcAccountManager.OnPostListener() {
518         @Override
519         public synchronized void onPostCompleted(List<OcHeaderOption> list,
520                 OcRepresentation ocRepresentation) {
521             logMessage("signOut was successful");
522             runOnUiThread(new Runnable() {
523                 public void run() {
524                     signIn.setEnabled(true);
525                     signOut.setEnabled(false);
526                     remoteService.setEnabled(false);
527                 }
528             });
529
530         }
531
532         @Override
533         public synchronized void onPostFailed(Throwable throwable) {
534             logMessage("Failed to signOut");
535             if (throwable instanceof OcException) {
536                 OcException ocEx = (OcException) throwable;
537                 Log.e(TAG, ocEx.toString());
538                 ErrorCode errCode = ocEx.getErrorCode();
539                 logMessage("Error code: " + errCode);
540                 if (ErrorCode.UNAUTHORIZED_REQ != errCode) {
541                     refreshToken();
542                 }
543             }
544         }
545     };
546
547     @Override
548     public void onPostCompleted(List<OcHeaderOption> ocHeaderOptions,
549             OcRepresentation ocRepresentation) {
550
551     }
552
553     @Override
554     public void onPostFailed(Throwable throwable) {
555
556     }
557
558     private void signIn() {
559         try {
560             if (mAccountManager == null) {
561                 mAccountManager = OcPlatform.constructAccountManagerObject(
562                         CIServer,
563                         EnumSet.of(OcConnectivityType.CT_ADAPTER_TCP));
564             }
565
566             mAccountManager.signIn(mUserID, mAccessToken, onSignIn);
567         } catch (OcException e) {
568             e.printStackTrace();
569         }
570     }
571
572     private void signOut() {
573         try {
574             logMessage("signOut");
575             if (mAccountManager == null) {
576                 try {
577                     mAccountManager = OcPlatform.constructAccountManagerObject(
578                             CIServer,
579                             EnumSet.of(OcConnectivityType.CT_ADAPTER_TCP));
580                 } catch (OcException e) {
581                     e.printStackTrace();
582                 }
583             }
584             mAccountManager.signOut(mAccessToken, onSignOut);
585             signIn.setEnabled(false);
586             signUp.setEnabled(true);
587             remoteService.setEnabled(false);
588             logMessage("signOut Successful");
589         } catch (OcException e) {
590             e.printStackTrace();
591         }
592     }
593
594     private void signUp() {
595         Intent intentLogin = new Intent(this, LoginActivity.class);
596         startActivityForResult(intentLogin, REQUEST_LOGIN);
597     }
598
599     @Override
600     public void onActivityResult(int requestCode, int resultCode, Intent data) {
601         super.onActivityResult(requestCode, resultCode, data);
602         if (resultCode == Activity.RESULT_OK && requestCode == REQUEST_LOGIN) {
603             mAuthCode = data.getStringExtra("authCode");
604             mAuthProvider = data.getStringExtra("authProvider");
605             logMessage("authCode: " + mAuthCode);
606             logMessage("authProvider: " + mAuthProvider);
607
608             final Dialog dialog = new Dialog(context);
609             dialog.setContentView(R.layout.dialog_entry);
610             dialog.setTitle("SignUp Acccount IP Address");
611             final EditText ip = (EditText) dialog
612                     .findViewById(R.id.EditTextEntry);
613             if (RemoteAddress != null) {
614                 ip.setText(RemoteAddress);
615             }
616             Button dialogButton = (Button) dialog
617                     .findViewById(R.id.entryButtonOK);
618             dialogButton.setOnClickListener(new View.OnClickListener() {
619                 @Override
620                 public void onClick(View v) {
621                     dialog.dismiss();
622                     RemoteAddress = ip.getText().toString();
623                     CIServer = CI_SERVER_PREFIX + RemoteAddress;
624                     logMessage("server address for signup is: \n" + CIServer);
625                     try {
626                         mAccountManager = OcPlatform
627                                 .constructAccountManagerObject(CIServer, EnumSet
628                                         .of(OcConnectivityType.CT_ADAPTER_TCP));
629                         logMessage("Calling signup API");
630
631                         if (mAuthProvider.equals("samsung")
632                                 || mAuthProvider.equals("samsung-us"))
633
634                         {
635                             logMessage("Auth provider is samsung");
636                             Map<String, String> options = new HashMap<>();
637                             options.put("auth_server_url",
638                                     "us-auth2.samsungosp.com");
639                             options.put("api_server_url",
640                                     "us-auth2.samsungosp.com");
641                             mAccountManager.signUp(mAuthProvider, mAuthCode,
642                                     options, onSignUp);
643                         } else {
644                             mAccountManager.signUp(mAuthProvider, mAuthCode,
645                                     onSignUp);
646                         }
647                     } catch (OcException e) {
648                         e.printStackTrace();
649                     }
650                 }
651             });
652             dialog.show();
653         }
654     }
655
656     OcResource.OnPostListener onRefreshTokenPost = new OcResource.OnPostListener() {
657         @Override
658         public void onPostCompleted(List<OcHeaderOption> list,
659                 OcRepresentation ocRepresentation) {
660             logMessage("RefreshToken Completed.");
661             try {
662                 mAccessToken = ocRepresentation.getValue("accesstoken");
663                 mRefreshtoken = ocRepresentation.getValue("refreshtoken");
664             } catch (OcException e) {
665                 e.printStackTrace();
666             }
667             signIn();
668         }
669
670         @Override
671         public void onPostFailed(Throwable throwable) {
672             logMessage("RefreshToken failed.");
673             Log.d(TAG, "onRefreshTokenPost failed.");
674         }
675     };
676
677     public void refreshToken() {
678
679         if (deviceID == null) {
680             final Dialog dialog = new Dialog(context);
681             dialog.setContentView(R.layout.dialog_entry);
682             dialog.setTitle("Enter Device Id");
683             dialog.setCanceledOnTouchOutside(false);
684             final EditText id = (EditText) dialog
685                     .findViewById(R.id.EditTextEntry);
686
687             Button dialogButton = (Button) dialog
688                     .findViewById(R.id.entryButtonOK);
689             dialogButton.setOnClickListener(new View.OnClickListener() {
690                 @Override
691                 public void onClick(View v) {
692                     dialog.dismiss();
693                     deviceID = id.getText().toString();
694                 }
695             });
696             dialog.show();
697         }
698         try {
699             OcResource authResource = OcPlatform.constructResourceObject(
700                     CIServer, "/.well-known/ocf/account/tokenrefresh",
701                     EnumSet.of(OcConnectivityType.CT_ADAPTER_TCP,
702                             OcConnectivityType.CT_IP_USE_V4),
703                     false, Arrays.asList("oic.wk.account"),
704                     Arrays.asList(OcPlatform.DEFAULT_INTERFACE));
705             OcRepresentation rep = new OcRepresentation();
706
707             showToast("RefreshToken in progress..");
708             logMessage("RefreshToken in progress..");
709             rep.setValue("di", deviceID);
710             rep.setValue("granttype", "refresh_token");
711             rep.setValue("refreshtoken", mRefreshtoken);
712             rep.setValue("uid", mUserID);
713             authResource.post(rep, new HashMap<String, String>(),
714                     onRefreshTokenPost);
715         } catch (OcException e) {
716             e.printStackTrace();
717         }
718
719         Log.d(TAG, "No error while executing login");
720     }
721 }