1515import android .net .ConnectivityManager ;
1616import android .net .Uri ;
1717
18- import com .owncloud . android . lib . common .OwnCloudClient ;
19- import com .owncloud . android . lib . common . OwnCloudClientManagerFactory ;
18+ import com .nextcloud . common .NextcloudClient ;
19+ import com .nextcloud . operations . GetMethod ;
2020import com .owncloud .android .lib .common .accounts .AccountUtils ;
2121import com .owncloud .android .lib .common .operations .RemoteOperation ;
2222import com .owncloud .android .lib .common .operations .RemoteOperationResult ;
2323import com .owncloud .android .lib .common .utils .Log_OC ;
2424
2525import org .apache .commons .httpclient .HttpStatus ;
26- import org .apache .commons .httpclient .methods .GetMethod ;
27- import org .apache .commons .httpclient .params .HttpMethodParams ;
28- import org .apache .commons .httpclient .params .HttpParams ;
2926import org .json .JSONException ;
3027import org .json .JSONObject ;
3128
32- import java . util . ArrayList ;
29+ import kotlin . Pair ;
3330
3431/**
3532 * Checks if the server is valid and if the server supports the Share API
3633 *
3734 * @author David A. Velasco
3835 * @author masensio
3936 */
40- public class GetStatusRemoteOperation extends RemoteOperation {
41-
42- /**
43- * Maximum time to wait for a response from the server when the connection is being tested, in MILLISECONDs.
44- */
45- private static final int TRY_CONNECTION_TIMEOUT = 50000 ;
46-
37+ public class GetStatusRemoteOperation extends RemoteOperation <Pair <OwnCloudVersion , Boolean >> {
4738 private static final String TAG = GetStatusRemoteOperation .class .getSimpleName ();
4839
4940 private static final String NODE_INSTALLED = "installed" ;
@@ -53,28 +44,24 @@ public class GetStatusRemoteOperation extends RemoteOperation {
5344 private static final String PROTOCOL_HTTP = "http://" ;
5445 private static final int UNTRUSTED_DOMAIN_ERROR_CODE = 15 ;
5546
56- private RemoteOperationResult mLatestResult ;
57- private Context mContext ;
47+ private RemoteOperationResult < Pair < OwnCloudVersion , Boolean >> mLatestResult ;
48+ private final Context mContext ;
5849
5950 public GetStatusRemoteOperation (Context context ) {
6051 mContext = context ;
6152 }
6253
63- private boolean tryConnection (OwnCloudClient client ) {
54+ private boolean tryConnection (NextcloudClient client ) {
6455 boolean retval = false ;
65- GetMethod get = null ;
66- String baseUrlSt = client .getBaseUri (). toString ( );
56+ com . nextcloud . operations . GetMethod get = null ;
57+ String baseUrlSt = String . valueOf ( client .getBaseUri ());
6758 try {
68- get = new GetMethod (baseUrlSt + AccountUtils .STATUS_PATH );
69-
70- HttpParams params = HttpMethodParams .getDefaultParams ();
71- params .setParameter (HttpMethodParams .USER_AGENT , OwnCloudClientManagerFactory .getUserAgent ());
72- get .getParams ().setDefaults (params );
59+ get = new com .nextcloud .operations .GetMethod (baseUrlSt + AccountUtils .STATUS_PATH , false );
7360
7461 client .setFollowRedirects (false );
7562 boolean isRedirectToNonSecureConnection = false ;
76- int status = client .executeMethod (get , TRY_CONNECTION_TIMEOUT , TRY_CONNECTION_TIMEOUT );
77- mLatestResult = new RemoteOperationResult ((status == HttpStatus .SC_OK ), get );
63+ int status = client .execute (get );
64+ mLatestResult = new RemoteOperationResult <> ((status == HttpStatus .SC_OK ), get );
7865
7966 String redirectedLocation = mLatestResult .getRedirectedLocation ();
8067 while (redirectedLocation != null && redirectedLocation .length () > 0
@@ -85,9 +72,9 @@ private boolean tryConnection(OwnCloudClient client) {
8572 redirectedLocation .startsWith (PROTOCOL_HTTP )
8673 );
8774 get .releaseConnection ();
88- get = new GetMethod (redirectedLocation );
89- status = client .executeMethod (get , TRY_CONNECTION_TIMEOUT , TRY_CONNECTION_TIMEOUT );
90- mLatestResult = new RemoteOperationResult ((status == HttpStatus .SC_OK ), get );
75+ get = new GetMethod (redirectedLocation , false );
76+ status = client .execute (get );
77+ mLatestResult = new RemoteOperationResult <> ((status == HttpStatus .SC_OK ), get );
9178 redirectedLocation = mLatestResult .getRedirectedLocation ();
9279 }
9380
@@ -96,7 +83,7 @@ private boolean tryConnection(OwnCloudClient client) {
9683 if (status == HttpStatus .SC_OK ) {
9784 JSONObject json = new JSONObject (response );
9885 if (!json .getBoolean (NODE_INSTALLED )) {
99- mLatestResult = new RemoteOperationResult (
86+ mLatestResult = new RemoteOperationResult <> (
10087 RemoteOperationResult .ResultCode .INSTANCE_NOT_CONFIGURED );
10188 } else {
10289 boolean extendedSupport = false ;
@@ -108,24 +95,22 @@ private boolean tryConnection(OwnCloudClient client) {
10895 OwnCloudVersion ocVersion = new OwnCloudVersion (version );
10996
11097 if (!ocVersion .isVersionValid ()) {
111- mLatestResult = new RemoteOperationResult (RemoteOperationResult .ResultCode .BAD_OC_VERSION );
98+ mLatestResult = new RemoteOperationResult <> (RemoteOperationResult .ResultCode .BAD_OC_VERSION );
11299 } else {
113100 // success
114101 if (isRedirectToNonSecureConnection ) {
115- mLatestResult = new RemoteOperationResult (
102+ mLatestResult = new RemoteOperationResult <> (
116103 RemoteOperationResult .ResultCode .OK_REDIRECT_TO_NON_SECURE_CONNECTION );
117104 } else {
118- mLatestResult = new RemoteOperationResult (
105+ mLatestResult = new RemoteOperationResult <> (
119106 baseUrlSt .startsWith (PROTOCOL_HTTPS ) ?
120107 RemoteOperationResult .ResultCode .OK_SSL :
121108 RemoteOperationResult .ResultCode .OK_NO_SSL
122109 );
123110 }
124111
125- ArrayList <Object > data = new ArrayList <>();
126- data .add (ocVersion );
127- data .add (extendedSupport );
128- mLatestResult .setData (data );
112+ Pair <OwnCloudVersion , Boolean > data = new Pair <>(ocVersion , extendedSupport );
113+ mLatestResult .setResultData (data );
129114 retval = true ;
130115 }
131116 }
@@ -134,22 +119,22 @@ private boolean tryConnection(OwnCloudClient client) {
134119 JSONObject json = new JSONObject (response );
135120
136121 if (json .getInt ("code" ) == UNTRUSTED_DOMAIN_ERROR_CODE ) {
137- mLatestResult = new RemoteOperationResult (RemoteOperationResult .ResultCode .UNTRUSTED_DOMAIN );
122+ mLatestResult = new RemoteOperationResult <> (RemoteOperationResult .ResultCode .UNTRUSTED_DOMAIN );
138123 } else {
139- mLatestResult = new RemoteOperationResult (false , status , get . getResponseHeaders () );
124+ mLatestResult = new RemoteOperationResult <> (false , get );
140125 }
141126 } catch (JSONException e ) {
142- mLatestResult = new RemoteOperationResult (false , status , get . getResponseHeaders () );
127+ mLatestResult = new RemoteOperationResult <> (false , get );
143128 }
144129 } else {
145- mLatestResult = new RemoteOperationResult (false , status , get . getResponseHeaders () );
130+ mLatestResult = new RemoteOperationResult <> (false , get );
146131 }
147132
148133 } catch (JSONException e ) {
149- mLatestResult = new RemoteOperationResult (RemoteOperationResult .ResultCode .INSTANCE_NOT_CONFIGURED );
134+ mLatestResult = new RemoteOperationResult <> (RemoteOperationResult .ResultCode .INSTANCE_NOT_CONFIGURED );
150135
151136 } catch (Exception e ) {
152- mLatestResult = new RemoteOperationResult (e );
137+ mLatestResult = new RemoteOperationResult <> (e );
153138
154139 } finally {
155140 if (get != null )
@@ -171,18 +156,16 @@ private boolean tryConnection(OwnCloudClient client) {
171156 }
172157
173158 private boolean isOnline () {
174- ConnectivityManager cm = (ConnectivityManager ) mContext
175- .getSystemService (Context .CONNECTIVITY_SERVICE );
176- return cm != null && cm .getActiveNetworkInfo () != null
177- && cm .getActiveNetworkInfo ().isConnectedOrConnecting ();
159+ ConnectivityManager cm = (ConnectivityManager ) mContext .getSystemService (Context .CONNECTIVITY_SERVICE );
160+ return cm != null && cm .getActiveNetworkInfo () != null && cm .getActiveNetworkInfo ().isConnectedOrConnecting ();
178161 }
179162
180163 @ Override
181- protected RemoteOperationResult run (OwnCloudClient client ) {
164+ public RemoteOperationResult < Pair < OwnCloudVersion , Boolean >> run (NextcloudClient client ) {
182165 if (!isOnline ()) {
183- return new RemoteOperationResult (RemoteOperationResult .ResultCode .NO_NETWORK_CONNECTION );
166+ return new RemoteOperationResult <> (RemoteOperationResult .ResultCode .NO_NETWORK_CONNECTION );
184167 }
185- String baseUriStr = client .getBaseUri (). toString ( );
168+ String baseUriStr = String . valueOf ( client .getBaseUri ());
186169 if (baseUriStr .startsWith (PROTOCOL_HTTP ) || baseUriStr .startsWith (PROTOCOL_HTTPS )) {
187170 tryConnection (client );
188171
0 commit comments