mirror of
				https://github.com/owncloud/android-library.git
				synced 2025-10-31 10:27:45 +00:00 
			
		
		
		
	Updated server check operation and OwnCloudVersion to retrieve both remote version and versionstring values
This commit is contained in:
		
							parent
							
								
									1f6f9bcf84
								
							
						
					
					
						commit
						c3f4382200
					
				| @ -80,10 +80,11 @@ public class AccountUtils { | |||||||
|     public static String constructFullURLForAccount(Context context, Account account) throws AccountNotFoundException { |     public static String constructFullURLForAccount(Context context, Account account) throws AccountNotFoundException { | ||||||
|         AccountManager ama = AccountManager.get(context); |         AccountManager ama = AccountManager.get(context); | ||||||
|         String baseurl = ama.getUserData(account, OwnCloudAccount.Constants.KEY_OC_BASE_URL); |         String baseurl = ama.getUserData(account, OwnCloudAccount.Constants.KEY_OC_BASE_URL); | ||||||
|         String strver  = ama.getUserData(account, OwnCloudAccount.Constants.KEY_OC_VERSION); |         String version  = ama.getUserData(account, OwnCloudAccount.Constants.KEY_OC_VERSION); | ||||||
|  |         String versionString  = ama.getUserData(account, OwnCloudAccount.Constants.KEY_OC_VERSION_STRING); | ||||||
|         boolean supportsOAuth = (ama.getUserData(account, OwnCloudAccount.Constants.KEY_SUPPORTS_OAUTH2) != null); |         boolean supportsOAuth = (ama.getUserData(account, OwnCloudAccount.Constants.KEY_SUPPORTS_OAUTH2) != null); | ||||||
|         boolean supportsSamlSso = (ama.getUserData(account, OwnCloudAccount.Constants.KEY_SUPPORTS_SAML_WEB_SSO) != null); |         boolean supportsSamlSso = (ama.getUserData(account, OwnCloudAccount.Constants.KEY_SUPPORTS_SAML_WEB_SSO) != null); | ||||||
|         OwnCloudVersion ver = new OwnCloudVersion(strver); |         OwnCloudVersion ver = new OwnCloudVersion(version, versionString); | ||||||
|         String webdavpath = getWebdavPath(ver, supportsOAuth, supportsSamlSso); |         String webdavpath = getWebdavPath(ver, supportsOAuth, supportsSamlSso); | ||||||
| 
 | 
 | ||||||
|         if (baseurl == null || webdavpath == null)  |         if (baseurl == null || webdavpath == null)  | ||||||
|  | |||||||
| @ -52,6 +52,10 @@ public class OwnCloudAccount extends Account { | |||||||
| 	     * {@link com.owncloud.android.lib.utils.utils.OwnCloudVersion} | 	     * {@link com.owncloud.android.lib.utils.utils.OwnCloudVersion} | ||||||
| 	     */ | 	     */ | ||||||
| 	    public static final String KEY_OC_VERSION = "oc_version"; | 	    public static final String KEY_OC_VERSION = "oc_version"; | ||||||
|  | 	    /** | ||||||
|  | 	     * Version string as shown in the status.php resource in the server side | ||||||
|  | 	     */ | ||||||
|  | 		public static final String KEY_OC_VERSION_STRING = "oc_version_string"; | ||||||
| 	    /** | 	    /** | ||||||
| 	     * Base url should point to owncloud installation without trailing / ie: | 	     * Base url should point to owncloud installation without trailing / ie: | ||||||
| 	     * http://server/path or https://owncloud.server | 	     * http://server/path or https://owncloud.server | ||||||
| @ -65,10 +69,7 @@ public class OwnCloudAccount extends Account { | |||||||
| 	     * Flag signaling if the ownCloud server can be accessed with session cookies from SAML-based web single-sign-on. | 	     * Flag signaling if the ownCloud server can be accessed with session cookies from SAML-based web single-sign-on. | ||||||
| 	     */ | 	     */ | ||||||
| 	    public static final String KEY_SUPPORTS_SAML_WEB_SSO = "oc_supports_saml_web_sso"; | 	    public static final String KEY_SUPPORTS_SAML_WEB_SSO = "oc_supports_saml_web_sso"; | ||||||
| 	    /** | 	     | ||||||
| 	    * Flag signaling if the ownCloud server supports Share API" |  | ||||||
| 	    */ |  | ||||||
| 	    public static final String KEY_SUPPORTS_SHARE_API = "oc_supports_share_api"; |  | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| 	private String mAuthTokenType; | 	private String mAuthTokenType; | ||||||
|  | |||||||
| @ -55,8 +55,6 @@ public class OwnCloudServerCheckOperation extends RemoteOperation { | |||||||
|      |      | ||||||
|     private static final String TAG = OwnCloudServerCheckOperation.class.getSimpleName(); |     private static final String TAG = OwnCloudServerCheckOperation.class.getSimpleName(); | ||||||
|      |      | ||||||
|     private static final String OCVERSION_SHARED_SUPPORTED = "5.0.13"; |  | ||||||
|      |  | ||||||
|     private static final String NODE_INSTALLED = "installed"; |     private static final String NODE_INSTALLED = "installed"; | ||||||
|     private static final String NODE_VERSION = "version"; |     private static final String NODE_VERSION = "version"; | ||||||
|     private static final String NODE_VERSIONSTRING = "versionstring"; |     private static final String NODE_VERSIONSTRING = "versionstring"; | ||||||
| @ -65,27 +63,16 @@ public class OwnCloudServerCheckOperation extends RemoteOperation { | |||||||
|     private RemoteOperationResult mLatestResult; |     private RemoteOperationResult mLatestResult; | ||||||
|     private Context mContext; |     private Context mContext; | ||||||
|     private OwnCloudVersion mOCVersion; |     private OwnCloudVersion mOCVersion; | ||||||
|     private OwnCloudVersion mOCVersionString; |  | ||||||
| 
 | 
 | ||||||
|     public OwnCloudServerCheckOperation(String url, Context context) { |     public OwnCloudServerCheckOperation(String url, Context context) { | ||||||
|         mUrl = url; |         mUrl = url; | ||||||
|         mContext = context; |         mContext = context; | ||||||
|         mOCVersion = null; |         mOCVersion = null; | ||||||
|         mOCVersionString = null; |  | ||||||
|     } |     } | ||||||
|      |      | ||||||
|     public OwnCloudVersion getDiscoveredVersion() { |     public OwnCloudVersion getDiscoveredVersion() { | ||||||
|         return mOCVersion; |         return mOCVersion; | ||||||
|     } |     } | ||||||
|     public boolean isSharedSupported() { |  | ||||||
|         OwnCloudVersion shareServer = new OwnCloudVersion(OCVERSION_SHARED_SUPPORTED); |  | ||||||
|         if (mOCVersionString != null) { |  | ||||||
|         	return mOCVersionString.compareTo(shareServer) >= 0; |  | ||||||
|         }  |  | ||||||
| 
 |  | ||||||
|         return false; |  | ||||||
| 
 |  | ||||||
|     } |  | ||||||
| 
 | 
 | ||||||
|     private boolean tryConnection(OwnCloudClient wc, String urlSt) { |     private boolean tryConnection(OwnCloudClient wc, String urlSt) { | ||||||
|         boolean retval = false; |         boolean retval = false; | ||||||
| @ -99,8 +86,9 @@ public class OwnCloudServerCheckOperation extends RemoteOperation { | |||||||
|                 if (!json.getBoolean(NODE_INSTALLED)) { |                 if (!json.getBoolean(NODE_INSTALLED)) { | ||||||
|                     mLatestResult = new RemoteOperationResult(RemoteOperationResult.ResultCode.INSTANCE_NOT_CONFIGURED); |                     mLatestResult = new RemoteOperationResult(RemoteOperationResult.ResultCode.INSTANCE_NOT_CONFIGURED); | ||||||
|                 } else { |                 } else { | ||||||
|                     mOCVersion = new OwnCloudVersion(json.getString(NODE_VERSION)); |                     String version = json.getString(NODE_VERSION); | ||||||
|                     mOCVersionString = new OwnCloudVersion(json.getString(NODE_VERSIONSTRING), true); |                     String versionString = json.getString(NODE_VERSIONSTRING); | ||||||
|  |                     mOCVersion = new OwnCloudVersion(version, versionString); | ||||||
|                     if (!mOCVersion.isVersionValid()) { |                     if (!mOCVersion.isVersionValid()) { | ||||||
|                         mLatestResult = new RemoteOperationResult(RemoteOperationResult.ResultCode.BAD_OC_VERSION); |                         mLatestResult = new RemoteOperationResult(RemoteOperationResult.ResultCode.BAD_OC_VERSION); | ||||||
|                          |                          | ||||||
|  | |||||||
| @ -37,33 +37,33 @@ public class OwnCloudVersion implements Comparable<OwnCloudVersion> { | |||||||
|     public static final OwnCloudVersion owncloud_v4_5 = new OwnCloudVersion( |     public static final OwnCloudVersion owncloud_v4_5 = new OwnCloudVersion( | ||||||
|             0x040500); |             0x040500); | ||||||
|      |      | ||||||
|  |     public static final int MINIMUM_VERSION_STRING_FOR_SHARING_API = 0x05000D; | ||||||
|  |      | ||||||
|     // format is in version |     // format is in version | ||||||
|     // 0xAABBCC |     // 0xAABBCC | ||||||
|     // for version AA.BB.CC |     // for version AA.BB.CC | ||||||
|     // ie version 2.0.3 will be stored as 0x030003 |     // ie version 2.0.3 will be stored as 0x020003 | ||||||
|     private int mVersion; |     private int mVersion; | ||||||
|     private boolean mIsValid; |     private boolean mIsValid; | ||||||
|  |     // not parsed, saved same value offered by the server | ||||||
|  |     private String mVersionString; | ||||||
| 
 | 
 | ||||||
|     public OwnCloudVersion(int version) { |     protected OwnCloudVersion(int version) { | ||||||
|         mVersion = version; |         mVersion = version; | ||||||
|         mIsValid = true; |         mIsValid = true; | ||||||
|  |         mVersionString = ""; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public OwnCloudVersion(String version) { |     public OwnCloudVersion(String version, String versionString) { | ||||||
|         mVersion = 0; |         mVersion = 0; | ||||||
|         mIsValid = false; |         mIsValid = false; | ||||||
|         parseVersionString(version); |         parseVersionString(version); | ||||||
|     } |         if (versionString != null && versionString.length() > 0) { | ||||||
|      |         	mVersionString = versionString; | ||||||
|     public OwnCloudVersion(String versionstring, boolean isVersionString) { |  | ||||||
|     	mVersion = 0; |  | ||||||
|     	mIsValid = false; |  | ||||||
|     	if (isVersionString) { |  | ||||||
|     		parseVersionString(versionstring); |  | ||||||
|     	} else { |  | ||||||
|             parseVersion(versionstring); |  | ||||||
|     	} |  | ||||||
|         	 |         	 | ||||||
|  |         } else if (mIsValid) { | ||||||
|  |         	mVersionString = version; | ||||||
|  |         } | ||||||
|     } |     } | ||||||
|      |      | ||||||
|     public String toString() { |     public String toString() { | ||||||
| @ -71,6 +71,14 @@ public class OwnCloudVersion implements Comparable<OwnCloudVersion> { | |||||||
|                 + ((mVersion) % 256); |                 + ((mVersion) % 256); | ||||||
|     } |     } | ||||||
|      |      | ||||||
|  |     public String getVersion() { | ||||||
|  |     	return toString(); | ||||||
|  |     } | ||||||
|  |      | ||||||
|  |     public String getVersionString() { | ||||||
|  |     	return mVersionString; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     public boolean isVersionValid() { |     public boolean isVersionValid() { | ||||||
|         return mIsValid; |         return mIsValid; | ||||||
|     } |     } | ||||||
| @ -81,45 +89,48 @@ public class OwnCloudVersion implements Comparable<OwnCloudVersion> { | |||||||
|                 : another.mVersion < mVersion ? 1 : -1; |                 : another.mVersion < mVersion ? 1 : -1; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     private void parseVersion(String version) { |     private void parseVersionString(String versionString) { | ||||||
|         try { |  | ||||||
|             String[] nums = version.split("\\."); |  | ||||||
|             if (nums.length > 0) { |  | ||||||
|                 mVersion += Integer.parseInt(nums[0]); |  | ||||||
|             } |  | ||||||
|             mVersion = mVersion << 8; |  | ||||||
|             if (nums.length > 1) { |  | ||||||
|                 mVersion += Integer.parseInt(nums[1]); |  | ||||||
|             } |  | ||||||
|             mVersion = mVersion << 8; |  | ||||||
|             if (nums.length > 2) { |  | ||||||
|                 mVersion += Integer.parseInt(nums[2]); |  | ||||||
|             } |  | ||||||
|             mIsValid = true; |  | ||||||
|         } catch (Exception e) { |  | ||||||
|             mIsValid = false; |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
|      |  | ||||||
|     private void parseVersionString(String versionstring) { |  | ||||||
|     	try { |     	try { | ||||||
|     		versionstring = versionstring.replaceAll("[^\\d.]", ""); |     		mVersion = getParsedVersionString(versionString); | ||||||
|     		 |  | ||||||
|     		String[] nums = versionstring.split("\\."); |  | ||||||
|     		if (nums.length > 0) { |  | ||||||
|     			mVersion += Integer.parseInt(nums[0]); |  | ||||||
|     		} |  | ||||||
|     		mVersion = mVersion << 8; |  | ||||||
|     		if (nums.length > 1) { |  | ||||||
|     			mVersion += Integer.parseInt(nums[1]); |  | ||||||
|     		} |  | ||||||
|     		mVersion = mVersion << 8; |  | ||||||
|     		if (nums.length > 2) { |  | ||||||
|     			mVersion += Integer.parseInt(nums[2]); |  | ||||||
|     		} |  | ||||||
|     		mIsValid = true; |     		mIsValid = true; | ||||||
|  |     		 | ||||||
|     	} catch (Exception e) { |     	} catch (Exception e) { | ||||||
|     		mIsValid = false; |     		mIsValid = false; | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |      | ||||||
|  |     private int getParsedVersionString(String versionString) throws NumberFormatException { | ||||||
|  | 		int version = 0; | ||||||
|  | 		 | ||||||
|  |     	// get only numeric part  | ||||||
|  | 		versionString = versionString.replaceAll("[^\\d.]", ""); | ||||||
|  | 		 | ||||||
|  | 		String[] nums = versionString.split("\\."); | ||||||
|  | 		if (nums.length > 0) { | ||||||
|  | 			version += Integer.parseInt(nums[0]); | ||||||
|  | 		} | ||||||
|  | 		version = version << 8; | ||||||
|  | 		if (nums.length > 1) { | ||||||
|  | 			version += Integer.parseInt(nums[1]); | ||||||
|  | 		} | ||||||
|  | 		version = version << 8; | ||||||
|  | 		if (nums.length > 2) { | ||||||
|  | 			version += Integer.parseInt(nums[2]); | ||||||
|  | 		} | ||||||
|  | 		return version;  | ||||||
|  |     } | ||||||
|  |      | ||||||
|  |      | ||||||
|  |     public boolean isSharedSupported() { | ||||||
|  |     	int versionString = 0; | ||||||
|  |     	try { | ||||||
|  |     		versionString = getParsedVersionString(mVersionString); | ||||||
|  |     		 | ||||||
|  |     	} catch (Exception e) { | ||||||
|  |     		// nothing to do here | ||||||
|  |     	} | ||||||
|  |     	return (versionString >= MINIMUM_VERSION_STRING_FOR_SHARING_API); | ||||||
|  |     } | ||||||
|  |      | ||||||
|  |      | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user