replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / service / easy-setup / sampleapp / mediator / android-samsung / EasySetup / app / src / main / java / org / iotivity / service / easysetup / LoginActivity.java
1 /**
2  * ***************************************************************
3  * <p/>
4  * Copyright 2015 Samsung Electronics All Rights Reserved.
5  * <p/>
6  * <p/>
7  * <p/>
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  * <p/>
12  * http://www.apache.org/licenses/LICENSE-2.0
13  * <p/>
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  * <p/>
20  * ****************************************************************
21  */
22
23 package org.iotivity.service.easysetup;
24
25 import android.app.Activity;
26 import android.app.AlertDialog;
27 import android.content.DialogInterface;
28 import android.content.Intent;
29 import android.content.SharedPreferences;
30 import android.net.ConnectivityManager;
31 import android.net.NetworkInfo;
32 import android.net.UrlQuerySanitizer;
33 import android.net.wifi.WifiConfiguration;
34 import android.net.wifi.WifiManager;
35 import android.os.Bundle;
36 import android.os.Handler;
37 import android.os.Message;
38 import android.preference.PreferenceManager;
39 import android.util.Log;
40 import android.view.View;
41 import android.view.View.OnClickListener;
42 import android.webkit.WebView;
43 import android.webkit.WebViewClient;
44 import android.widget.Button;
45 import android.widget.EditText;
46 import android.widget.LinearLayout;
47 import android.widget.ProgressBar;
48 import android.widget.RadioButton;
49 import android.widget.RelativeLayout;
50 import android.widget.TextView;
51 import android.widget.Toast;
52
53 import org.iotivity.base.ModeType;
54 import org.iotivity.base.OcException;
55 import org.iotivity.base.OcPlatform;
56 import org.iotivity.base.OcProvisioning;
57 import org.iotivity.base.PlatformConfig;
58 import org.iotivity.base.QualityOfService;
59 import org.iotivity.base.ServiceType;
60
61 import java.io.File;
62 import java.io.FileNotFoundException;
63 import java.io.FileOutputStream;
64 import java.io.IOException;
65 import java.io.InputStream;
66 import java.io.OutputStream;
67
68
69 public class LoginActivity extends Activity {
70     private static final String TAG = "Easysetup Login: ";
71
72     /* Samsung account */
73     private WebView mWebView = null;
74
75     @Override
76     protected void onCreate(Bundle savedInstanceState) {
77         super.onCreate(savedInstanceState);
78         setContentView(R.layout.activity_login);
79
80         /* For Samsung account authentifaction */
81         mWebView = (WebView) findViewById(R.id.webView);
82         mWebView.setVisibility(View.VISIBLE);
83         mWebView.setInitialScale(200);
84         mWebView.getSettings().setJavaScriptEnabled(true);
85         //mWebView.getSettings().setSupportZoom(true);
86         mWebView.getSettings().setBuiltInZoomControls(true);
87         mWebView.setWebViewClient(new WebViewClientClass());
88
89         mWebView.loadUrl("https://account.samsung.com/account/check.do?actionID=StartAP&serviceID=85o501t021&countryCode=KR&languageCode=ko&serviceChannel=PC_APP");
90
91     }
92
93     public void onDestroy() {
94         super.onDestroy();
95     }
96
97     private class WebViewClientClass extends WebViewClient {
98
99         @Override
100         public void onPageFinished(WebView view, String url) {
101             Log.e(TAG, "called!!! url=" + url);
102
103             if(url.contains("https://account.samsung.com/account/hybridCommonClosed.do")){
104
105                 mWebView.setVisibility(View.INVISIBLE);
106
107                 //parsing url
108                 UrlQuerySanitizer sanitizer = new UrlQuerySanitizer();
109                 sanitizer.setAllowUnregisteredParamaters(true);
110                 sanitizer.parseUrl(url);
111
112                 String mAuthCode = null;
113                 mAuthCode = sanitizer.getValue("code");
114
115                 Intent intent = getIntent();
116                 intent.putExtra("authCode", mAuthCode);
117                 intent.putExtra("authProvider", "samsung");
118
119                 setResult(RESULT_OK, intent);
120
121                 finish();
122             }
123         }
124     }
125 }