24
24
import android .content .ServiceConnection ;
25
25
import android .content .SharedPreferences ;
26
26
import android .content .pm .PackageManager ;
27
- import android .graphics .Bitmap ;
28
- import android .graphics .Color ;
29
27
import android .net .Uri ;
30
- import android .os .Build ;
31
28
import android .os .Bundle ;
32
29
import android .os .Handler ;
33
30
import android .os .IBinder ;
34
31
import android .preference .PreferenceManager ;
35
32
import android .text .TextUtils ;
36
- import android .util .AndroidRuntimeException ;
37
33
import android .view .KeyEvent ;
38
34
import android .view .View ;
39
35
import android .view .inputmethod .EditorInfo ;
40
36
import android .webkit .CookieManager ;
41
- import android .webkit .CookieSyncManager ;
42
37
import android .webkit .URLUtil ;
43
- import android .webkit .WebResourceRequest ;
44
- import android .webkit .WebResourceResponse ;
45
- import android .webkit .WebView ;
46
38
import android .widget .AdapterView ;
47
39
import android .widget .ArrayAdapter ;
48
40
import android .widget .LinearLayout ;
77
69
import com .owncloud .android .databinding .AccountSetupWebviewBinding ;
78
70
import com .owncloud .android .datamodel .FileDataStorageManager ;
79
71
import com .owncloud .android .lib .common .OwnCloudAccount ;
80
- import com .owncloud .android .lib .common .OwnCloudClient ;
81
- import com .owncloud .android .lib .common .OwnCloudClientFactory ;
82
72
import com .owncloud .android .lib .common .OwnCloudClientManagerFactory ;
83
73
import com .owncloud .android .lib .common .OwnCloudCredentials ;
84
74
import com .owncloud .android .lib .common .OwnCloudCredentialsFactory ;
92
82
import com .owncloud .android .lib .common .operations .RemoteOperationResult ;
93
83
import com .owncloud .android .lib .common .operations .RemoteOperationResult .ResultCode ;
94
84
import com .owncloud .android .lib .common .utils .Log_OC ;
95
- import com .owncloud .android .lib .resources .status .GetCapabilitiesRemoteOperation ;
96
- import com .owncloud .android .lib .resources .status .NextcloudVersion ;
97
- import com .owncloud .android .lib .resources .status .OCCapability ;
98
85
import com .owncloud .android .lib .resources .status .OwnCloudVersion ;
99
86
import com .owncloud .android .lib .resources .users .GetUserInfoRemoteOperation ;
100
87
import com .owncloud .android .operations .DetectAuthenticationMethodOperation .AuthenticationMethod ;
103
90
import com .owncloud .android .providers .DocumentsStorageProvider ;
104
91
import com .owncloud .android .services .OperationsService ;
105
92
import com .owncloud .android .services .OperationsService .OperationsServiceBinder ;
106
- import com .owncloud .android .ui .NextcloudWebViewClient ;
107
93
import com .owncloud .android .ui .activity .FileDisplayActivity ;
108
94
import com .owncloud .android .ui .activity .SettingsActivity ;
109
95
import com .owncloud .android .ui .dialog .IndeterminateProgressDialog ;
112
98
import com .owncloud .android .utils .DisplayUtils ;
113
99
import com .owncloud .android .utils .ErrorMessageAdapter ;
114
100
import com .owncloud .android .utils .PermissionUtil ;
115
- import com .owncloud .android .utils .WebViewUtil ;
116
101
import com .owncloud .android .utils .theme .CapabilityUtils ;
117
102
import com .owncloud .android .utils .theme .ViewThemeUtils ;
118
103
119
104
import org .json .JSONObject ;
120
105
121
- import java .io .InputStream ;
122
106
import java .net .URLDecoder ;
123
107
import java .util .ArrayList ;
124
- import java .util .HashMap ;
125
108
import java .util .Locale ;
126
- import java .util .Map ;
127
109
import java .util .Objects ;
128
110
import java .util .Optional ;
129
111
import java .util .concurrent .Executors ;
134
116
135
117
import androidx .activity .result .ActivityResultLauncher ;
136
118
import androidx .activity .result .contract .ActivityResultContracts ;
137
- import androidx .annotation .ColorInt ;
138
119
import androidx .annotation .NonNull ;
139
120
import androidx .annotation .Nullable ;
140
121
import androidx .annotation .VisibleForTesting ;
141
122
import androidx .appcompat .app .ActionBar ;
142
- import androidx .core .content .ContextCompat ;
143
123
import androidx .fragment .app .DialogFragment ;
144
124
import androidx .fragment .app .Fragment ;
145
125
import androidx .fragment .app .FragmentManager ;
@@ -188,14 +168,6 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
188
168
private static final String KEY_PASSWORD = "PASSWORD" ;
189
169
private static final String KEY_ASYNC_TASK_IN_PROGRESS = "AUTH_IN_PROGRESS" ;
190
170
191
- /**
192
- * Login Flow v1
193
- */
194
- // public static final String WEB_LOGIN = "/index.php/login/flow";
195
-
196
- /**
197
- * Login Flow v2
198
- */
199
171
public static final String WEB_LOGIN = "/index.php/login/v2" ;
200
172
201
173
public static final String PROTOCOL_SUFFIX = "://" ;
@@ -253,9 +225,6 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
253
225
private String token ;
254
226
255
227
private boolean onlyAdd = false ;
256
- @ SuppressLint ("ResourceAsColor" ) @ ColorInt
257
- private int primaryColor = R .color .primary ;
258
- private boolean strictMode = false ;
259
228
260
229
private ViewThemeUtils viewThemeUtils ;
261
230
@@ -275,8 +244,6 @@ protected void onCreate(Bundle savedInstanceState) {
275
244
viewThemeUtils = viewThemeUtilsFactory .withPrimaryAsBackground ();
276
245
viewThemeUtils .platform .colorStatusBar (this , getResources ().getColor (R .color .primary ));
277
246
278
- // WebViewUtil webViewUtil = new WebViewUtil(this);
279
-
280
247
Uri data = getIntent ().getData ();
281
248
boolean directLogin = data != null && data .toString ().startsWith (getString (R .string .login_data_own_scheme ));
282
249
if (savedInstanceState == null && !directLogin ) {
@@ -343,7 +310,6 @@ protected void onCreate(Bundle savedInstanceState) {
343
310
accountSetupWebviewBinding = AccountSetupWebviewBinding .inflate (getLayoutInflater ());
344
311
setContentView (accountSetupWebviewBinding .getRoot ());
345
312
anonymouslyPostLoginRequest (webloginUrl );
346
- // initWebViewLogin(webloginUrl, false);
347
313
} else {
348
314
accountSetupBinding = AccountSetupBinding .inflate (getLayoutInflater ());
349
315
setContentView (accountSetupBinding .getRoot ());
@@ -362,13 +328,10 @@ protected void onCreate(Bundle savedInstanceState) {
362
328
363
329
initServerPreFragment (savedInstanceState );
364
330
ProcessLifecycleOwner .get ().getLifecycle ().addObserver (lifecycleEventObserver );
365
-
366
- // webViewUtil.checkWebViewVersion();
367
331
}
368
332
}
369
333
370
334
private void showEnforcedServers () {
371
-
372
335
showAuthStatus ();
373
336
accountSetupBinding .hostUrlFrame .setVisibility (View .GONE );
374
337
accountSetupBinding .hostUrlInputHelperText .setVisibility (View .GONE );
@@ -421,9 +384,8 @@ public void onNothingSelected(AdapterView<?> parent) {
421
384
422
385
private void deleteCookies () {
423
386
try {
424
- CookieSyncManager .createInstance (this );
425
387
CookieManager .getInstance ().removeAllCookies (null );
426
- } catch (AndroidRuntimeException e ) {
388
+ } catch (Exception e ) {
427
389
Log_OC .e (TAG , e .getMessage ());
428
390
}
429
391
}
@@ -485,124 +447,15 @@ private void launchDefaultWebBrowser(String url) {
485
447
startActivity (intent );
486
448
}
487
449
488
- private static String getWebLoginUserAgent () {
489
- return Build .MANUFACTURER .substring (0 , 1 ).toUpperCase (Locale .getDefault ()) +
490
- Build .MANUFACTURER .substring (1 ).toLowerCase (Locale .getDefault ()) + " " + Build .MODEL + " (Android)" ;
491
- }
492
-
493
- /**
494
- * @Deprecated This function is deprecated. Please use the {@link #anonymouslyPostLoginRequest(String)} method instead, which utilizes the improved login flow v2.
495
- */
496
- @ Deprecated
497
- @ SuppressFBWarnings ("ANDROID_WEB_VIEW_JAVASCRIPT" )
498
- @ SuppressLint ("SetJavaScriptEnabled" )
499
- private void initWebViewLogin (String baseURL , boolean useGenericUserAgent ) {
500
- viewThemeUtils .platform .colorCircularProgressBar (accountSetupWebviewBinding .loginWebviewProgressBar , ColorRole .ON_PRIMARY_CONTAINER );
501
- accountSetupWebviewBinding .loginWebview .setVisibility (View .GONE );
502
- new WebViewUtil (this ).setProxyKKPlus (accountSetupWebviewBinding .loginWebview );
503
-
504
- accountSetupWebviewBinding .loginWebview .getSettings ().setAllowFileAccess (false );
505
- accountSetupWebviewBinding .loginWebview .getSettings ().setJavaScriptEnabled (true );
506
- accountSetupWebviewBinding .loginWebview .getSettings ().setDomStorageEnabled (true );
507
-
508
- if (useGenericUserAgent ) {
509
- accountSetupWebviewBinding .loginWebview .getSettings ().setUserAgentString (MainApp .getUserAgent ());
510
- } else {
511
- accountSetupWebviewBinding .loginWebview .getSettings ().setUserAgentString (getWebLoginUserAgent ());
512
- }
513
- accountSetupWebviewBinding .loginWebview .getSettings ().setSaveFormData (false );
514
- accountSetupWebviewBinding .loginWebview .getSettings ().setSavePassword (false );
515
-
516
- Map <String , String > headers = new HashMap <>();
517
- headers .put (RemoteOperation .OCS_API_HEADER , RemoteOperation .OCS_API_HEADER_VALUE );
518
-
519
- String url ;
520
- if (baseURL != null && !baseURL .isEmpty ()) {
521
- url = baseURL ;
522
- } else {
523
- url = getResources ().getString (R .string .webview_login_url );
524
- }
525
-
526
- new WebViewUtil (this ).setProxyKKPlus (accountSetupWebviewBinding .loginWebview );
527
- if (url .startsWith (HTTPS_PROTOCOL )) {
528
- strictMode = true ;
529
- }
530
-
531
- accountSetupWebviewBinding .loginWebview .loadUrl (url , headers );
532
-
533
- setClient ();
534
- }
535
-
536
450
@ Override
537
451
public boolean onKeyDown (int keyCode , KeyEvent event ) {
538
452
if (accountSetupWebviewBinding != null && event .getAction () == KeyEvent .ACTION_DOWN &&
539
453
keyCode == KeyEvent .KEYCODE_BACK ) {
540
- if (accountSetupWebviewBinding .loginWebview .canGoBack ()) {
541
- accountSetupWebviewBinding .loginWebview .goBack ();
542
- } else {
543
- finish ();
544
- }
545
454
return true ;
546
455
}
547
456
return super .onKeyDown (keyCode , event );
548
457
}
549
458
550
- private void setClient () {
551
- accountSetupWebviewBinding .loginWebview .setWebViewClient (new NextcloudWebViewClient (getSupportFragmentManager ()) {
552
- @ Override
553
- public WebResourceResponse shouldInterceptRequest (WebView view , WebResourceRequest request ) {
554
- return super .shouldInterceptRequest (view , request );
555
- }
556
-
557
- @ Override
558
- public void onPageStarted (WebView view , String url , Bitmap favicon ) {
559
- super .onPageStarted (view , url , favicon );
560
- }
561
-
562
- @ Override
563
- public boolean shouldOverrideUrlLoading (WebView view , String url ) {
564
- if (url .startsWith (getString (R .string .login_data_own_scheme ) + PROTOCOL_SUFFIX + "login/" )) {
565
- parseAndLoginFromWebView (url );
566
- return true ;
567
- }
568
- if (strictMode && url .startsWith (HTTP_PROTOCOL )) {
569
- Snackbar .make (view , R .string .strict_mode , Snackbar .LENGTH_LONG ).show ();
570
- return true ;
571
- }
572
- return false ;
573
- }
574
-
575
- @ Override
576
- public void onPageFinished (WebView view , String url ) {
577
- super .onPageFinished (view , url );
578
-
579
- accountSetupWebviewBinding .loginWebviewProgressBar .setVisibility (View .GONE );
580
- accountSetupWebviewBinding .loginWebview .setVisibility (View .VISIBLE );
581
-
582
- if (mServerInfo .mVersion != null && mServerInfo .mVersion .isOlderThan (NextcloudVersion .nextcloud_25 )) {
583
- viewThemeUtils .platform .colorStatusBar (AuthenticatorActivity .this , primaryColor );
584
- getWindow ().setNavigationBarColor (primaryColor );
585
- } else {
586
- viewThemeUtils .platform .resetStatusBar (AuthenticatorActivity .this );
587
- getWindow ().setNavigationBarColor (ContextCompat .getColor (AuthenticatorActivity .this , R .color .bg_default ));
588
- }
589
- }
590
-
591
- @ Override
592
- public void onReceivedError (WebView view , int errorCode , String description , String failingUrl ) {
593
- accountSetupWebviewBinding .loginWebviewProgressBar .setVisibility (View .GONE );
594
- accountSetupWebviewBinding .loginWebview .setVisibility (View .VISIBLE );
595
-
596
- InputStream resources = getResources ().openRawResource (R .raw .custom_error );
597
- String customError = DisplayUtils .getData (resources );
598
-
599
- if (!customError .isEmpty ()) {
600
- accountSetupWebviewBinding .loginWebview .loadData (customError , "text/html; charset=UTF-8" , null );
601
- }
602
- }
603
- });
604
- }
605
-
606
459
private void parseAndLoginFromWebView (String dataString ) {
607
460
try {
608
461
String prefix = getString (R .string .login_data_own_scheme ) + PROTOCOL_SUFFIX + "login/" ;
@@ -826,7 +679,6 @@ protected void onNewIntent(Intent intent) {
826
679
accountSetupWebviewBinding = AccountSetupWebviewBinding .inflate (getLayoutInflater ());
827
680
setContentView (accountSetupWebviewBinding .getRoot ());
828
681
anonymouslyPostLoginRequest (getString (R .string .provider_registration_server ));
829
- // initWebViewLogin(getString(R.string.provider_registration_server), true);
830
682
}
831
683
}
832
684
@@ -900,7 +752,7 @@ private void checkOcServer() {
900
752
901
753
mServerInfo = new GetServerInfoOperation .ServerInfo ();
902
754
903
- if (uri .length () != 0 ) {
755
+ if (! uri .isEmpty () ) {
904
756
if (accountSetupBinding != null ) {
905
757
uri = AuthenticatorUrlUtils .INSTANCE .stripIndexPhpOrAppsFiles (uri );
906
758
accountSetupBinding .hostUrlInput .setText (uri );
@@ -1043,24 +895,6 @@ private void onGetServerInfoFinish(RemoteOperationResult result) {
1043
895
webViewPassword != null && !webViewPassword .isEmpty ()) {
1044
896
checkBasicAuthorization (webViewUser , webViewPassword );
1045
897
} else {
1046
- new Thread (() -> {
1047
- OwnCloudClient client = OwnCloudClientFactory .createOwnCloudClient (Uri .parse (mServerInfo .mBaseUrl ),
1048
- this ,
1049
- true );
1050
- RemoteOperationResult remoteOperationResult = new GetCapabilitiesRemoteOperation ().execute (client );
1051
-
1052
- if (remoteOperationResult .isSuccess () &&
1053
- remoteOperationResult .getData () != null &&
1054
- remoteOperationResult .getData ().size () > 0 ) {
1055
- OCCapability capability = (OCCapability ) remoteOperationResult .getData ().get (0 );
1056
- try {
1057
- primaryColor = Color .parseColor (capability .getServerColor ());
1058
- } catch (Exception e ) {
1059
- // falls back to primary color
1060
- }
1061
- }
1062
- }).start ();
1063
-
1064
898
accountSetupWebviewBinding = AccountSetupWebviewBinding .inflate (getLayoutInflater ());
1065
899
setContentView (accountSetupWebviewBinding .getRoot ());
1066
900
@@ -1071,7 +905,6 @@ private void onGetServerInfoFinish(RemoteOperationResult result) {
1071
905
} else {
1072
906
initLoginInfoView ();
1073
907
}
1074
- // initWebViewLogin(mServerInfo.mBaseUrl + WEB_LOGIN, false);
1075
908
}
1076
909
}
1077
910
} else {
@@ -1310,10 +1143,6 @@ public void onAuthenticatorTaskCallback(RemoteOperationResult<UserInfo> result)
1310
1143
accountManager .setCurrentOwnCloudAccount (mAccount .name );
1311
1144
getUserCapabilitiesAndFinish ();
1312
1145
} else {
1313
- // init webView again
1314
- if (accountSetupWebviewBinding != null ) {
1315
- accountSetupWebviewBinding .loginWebview .setVisibility (View .GONE );
1316
- }
1317
1146
accountSetupBinding = AccountSetupBinding .inflate (getLayoutInflater ());
1318
1147
setContentView (accountSetupBinding .getRoot ());
1319
1148
initOverallUi ();
@@ -1341,10 +1170,6 @@ public void onAuthenticatorTaskCallback(RemoteOperationResult<UserInfo> result)
1341
1170
} else { // authorization fail due to client side - probably wrong credentials
1342
1171
if (accountSetupWebviewBinding != null ) {
1343
1172
anonymouslyPostLoginRequest (mServerInfo .mBaseUrl + WEB_LOGIN );
1344
- // initWebViewLogin(mServerInfo.mBaseUrl + WEB_LOGIN, false);
1345
- DisplayUtils .showSnackMessage (this ,
1346
- accountSetupWebviewBinding .loginWebview , R .string .auth_access_failed ,
1347
- result .getLogMessage ());
1348
1173
} else {
1349
1174
DisplayUtils .showSnackMessage (this , R .string .auth_access_failed , result .getLogMessage ());
1350
1175
0 commit comments