mirror of
				https://github.com/owncloud/android-library.git
				synced 2025-10-28 00:48:50 +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 { | ||||
|         AccountManager ama = AccountManager.get(context); | ||||
|         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 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); | ||||
| 
 | ||||
|         if (baseurl == null || webdavpath == null)  | ||||
|  | ||||
| @ -52,6 +52,10 @@ public class OwnCloudAccount extends Account { | ||||
| 	     * {@link com.owncloud.android.lib.utils.utils.OwnCloudVersion} | ||||
| 	     */ | ||||
| 	    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: | ||||
| 	     * 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. | ||||
| 	     */ | ||||
| 	    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; | ||||
|  | ||||
| @ -55,8 +55,6 @@ public class OwnCloudServerCheckOperation extends RemoteOperation { | ||||
|      | ||||
|     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_VERSION = "version"; | ||||
|     private static final String NODE_VERSIONSTRING = "versionstring"; | ||||
| @ -65,27 +63,16 @@ public class OwnCloudServerCheckOperation extends RemoteOperation { | ||||
|     private RemoteOperationResult mLatestResult; | ||||
|     private Context mContext; | ||||
|     private OwnCloudVersion mOCVersion; | ||||
|     private OwnCloudVersion mOCVersionString; | ||||
| 
 | ||||
|     public OwnCloudServerCheckOperation(String url, Context context) { | ||||
|         mUrl = url; | ||||
|         mContext = context; | ||||
|         mOCVersion = null; | ||||
|         mOCVersionString = null; | ||||
|     } | ||||
|      | ||||
|     public OwnCloudVersion getDiscoveredVersion() { | ||||
|         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) { | ||||
|         boolean retval = false; | ||||
| @ -99,8 +86,9 @@ public class OwnCloudServerCheckOperation extends RemoteOperation { | ||||
|                 if (!json.getBoolean(NODE_INSTALLED)) { | ||||
|                     mLatestResult = new RemoteOperationResult(RemoteOperationResult.ResultCode.INSTANCE_NOT_CONFIGURED); | ||||
|                 } else { | ||||
|                     mOCVersion = new OwnCloudVersion(json.getString(NODE_VERSION)); | ||||
|                     mOCVersionString = new OwnCloudVersion(json.getString(NODE_VERSIONSTRING), true); | ||||
|                     String version = json.getString(NODE_VERSION); | ||||
|                     String versionString = json.getString(NODE_VERSIONSTRING); | ||||
|                     mOCVersion = new OwnCloudVersion(version, versionString); | ||||
|                     if (!mOCVersion.isVersionValid()) { | ||||
|                         mLatestResult = new RemoteOperationResult(RemoteOperationResult.ResultCode.BAD_OC_VERSION); | ||||
|                          | ||||
|  | ||||
| @ -36,40 +36,48 @@ public class OwnCloudVersion implements Comparable<OwnCloudVersion> { | ||||
|             0x040000); | ||||
|     public static final OwnCloudVersion owncloud_v4_5 = new OwnCloudVersion( | ||||
|             0x040500); | ||||
| 
 | ||||
|      | ||||
|     public static final int MINIMUM_VERSION_STRING_FOR_SHARING_API = 0x05000D; | ||||
|      | ||||
|     // format is in version | ||||
|     // 0xAABBCC | ||||
|     // 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 boolean mIsValid; | ||||
|     // not parsed, saved same value offered by the server | ||||
|     private String mVersionString; | ||||
| 
 | ||||
|     public OwnCloudVersion(int version) { | ||||
|     protected OwnCloudVersion(int version) { | ||||
|         mVersion = version; | ||||
|         mIsValid = true; | ||||
|         mVersionString = ""; | ||||
|     } | ||||
| 
 | ||||
|     public OwnCloudVersion(String version) { | ||||
|     public OwnCloudVersion(String version, String versionString) { | ||||
|         mVersion = 0; | ||||
|         mIsValid = false; | ||||
|         parseVersionString(version); | ||||
|         if (versionString != null && versionString.length() > 0) { | ||||
|         	mVersionString = versionString; | ||||
|         	 | ||||
|         } else if (mIsValid) { | ||||
|         	mVersionString = version; | ||||
|         } | ||||
|     } | ||||
|      | ||||
|     public OwnCloudVersion(String versionstring, boolean isVersionString) { | ||||
|     	mVersion = 0; | ||||
|     	mIsValid = false; | ||||
|     	if (isVersionString) { | ||||
|     		parseVersionString(versionstring); | ||||
|     	} else { | ||||
|             parseVersion(versionstring); | ||||
|     	} | ||||
|     		 | ||||
|     } | ||||
| 
 | ||||
|     public String toString() { | ||||
|         return ((mVersion >> 16) % 256) + "." + ((mVersion >> 8) % 256) + "." | ||||
|                 + ((mVersion) % 256); | ||||
|     } | ||||
|      | ||||
|     public String getVersion() { | ||||
|     	return toString(); | ||||
|     } | ||||
|      | ||||
|     public String getVersionString() { | ||||
|     	return mVersionString; | ||||
|     } | ||||
| 
 | ||||
|     public boolean isVersionValid() { | ||||
|         return mIsValid; | ||||
| @ -81,45 +89,48 @@ public class OwnCloudVersion implements Comparable<OwnCloudVersion> { | ||||
|                 : another.mVersion < mVersion ? 1 : -1; | ||||
|     } | ||||
| 
 | ||||
|     private void parseVersion(String version) { | ||||
|         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) { | ||||
|     private void parseVersionString(String versionString) { | ||||
|     	try { | ||||
|     		versionstring = versionstring.replaceAll("[^\\d.]", ""); | ||||
|     		 | ||||
|     		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]); | ||||
|     		} | ||||
|     		mVersion = getParsedVersionString(versionString); | ||||
|     		mIsValid = true; | ||||
|     		 | ||||
|     	} catch (Exception e) { | ||||
|     		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