diff --git a/lib/src/main/java/com/nextcloud/android/sso/AccountImporter.java b/lib/src/main/java/com/nextcloud/android/sso/AccountImporter.java
index ca6b8c59e..f5067241c 100644
--- a/lib/src/main/java/com/nextcloud/android/sso/AccountImporter.java
+++ b/lib/src/main/java/com/nextcloud/android/sso/AccountImporter.java
@@ -11,10 +11,10 @@
import static android.app.Activity.RESULT_CANCELED;
import static android.app.Activity.RESULT_OK;
-import static com.nextcloud.android.sso.Constants.NEXTCLOUD_FILES_ACCOUNT;
-import static com.nextcloud.android.sso.Constants.NEXTCLOUD_SSO;
-import static com.nextcloud.android.sso.Constants.NEXTCLOUD_SSO_EXCEPTION;
-import static com.nextcloud.android.sso.Constants.SSO_SHARED_PREFERENCE;
+import static com.nextcloud.android.sso.Constants.INTERNAL_NEXTCLOUD_FILES_ACCOUNT;
+import static com.nextcloud.android.sso.Constants.INTERNAL_NEXTCLOUD_SSO;
+import static com.nextcloud.android.sso.Constants.INTERNAL_NEXTCLOUD_SSO_EXCEPTION;
+import static com.nextcloud.android.sso.Constants.INTERNAL_SSO_SHARED_PREFERENCE;
import android.Manifest;
import android.accounts.Account;
@@ -51,6 +51,7 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
+import java.util.Optional;
import java.util.function.Consumer;
import io.reactivex.annotations.Nullable;
@@ -68,7 +69,7 @@ public class AccountImporter {
private static SharedPreferences SHARED_PREFERENCES;
public static boolean accountsToImportAvailable(Context context) {
- return findAccounts(context).size() > 0;
+ return !findAccounts(context).isEmpty();
}
/**
@@ -78,15 +79,14 @@ public static boolean accountsToImportAvailable(Context context) {
* In real live applications, you won't import an account on each app start, but remember the imported account via SingleAccountHelper.
*
* @see ActivityResultContract
- * @deprecated Use {@link ImportSsoAccount} - this method will be private in the future
*/
- @Deprecated(forRemoval = true)
+ @RestrictTo(RestrictTo.Scope.LIBRARY)
public static void pickNewAccount(Activity activity) throws NextcloudFilesAppNotInstalledException,
AndroidGetAccountsPermissionNotGranted {
checkAndroidAccountPermissions(activity);
if (appInstalledOrNot(activity)) {
- Intent intent = AccountManager.newChooseAccountIntent(null, null, FilesAppTypeRegistry.getInstance().getAccountTypes(),
+ Intent intent = AccountManager.newChooseAccountIntent(null, null, FilesAppTypeRegistry.getInstance().getAccountTypes(),
true, null, AUTH_TOKEN_SSO, null, null);
activity.startActivityForResult(intent, CHOOSE_ACCOUNT_SSO);
} else {
@@ -94,37 +94,13 @@ public static void pickNewAccount(Activity activity) throws NextcloudFilesAppNot
}
}
- /**
- * Prompt dialog to select existing or create a new account
- * As soon as an account has been imported, we will continue in #onActivityResult()
- *
- * In real live applications, you won't import an account on each app start, but remember the imported account via SingleAccountHelper.
- *
- * @see ActivityResultContract
- * @deprecated Use {@link ImportSsoAccount}
- */
- @Deprecated(forRemoval = true)
- public static void pickNewAccount(Fragment fragment) throws NextcloudFilesAppNotInstalledException,
- AndroidGetAccountsPermissionNotGranted {
- checkAndroidAccountPermissions(fragment.getContext());
-
- if (appInstalledOrNot(fragment.requireContext())) {
- Intent intent = AccountManager.newChooseAccountIntent(null, null, FilesAppTypeRegistry.getInstance().getAccountTypes(),
- true, null, AUTH_TOKEN_SSO, null, null);
- fragment.startActivityForResult(intent, CHOOSE_ACCOUNT_SSO);
- } else {
- throw new NextcloudFilesAppNotInstalledException(fragment.requireContext());
- }
- }
-
/**
* @see ActivityResultContract
- * @deprecated Use {@link ImportSsoAccount}
*/
- @Deprecated(forRemoval = true)
+ @RestrictTo(RestrictTo.Scope.LIBRARY)
public static void requestAndroidAccountPermissionsAndPickAccount(Activity activity) {
ActivityCompat.requestPermissions(activity, new String[]{Manifest.permission.GET_ACCOUNTS},
- REQUEST_GET_ACCOUNTS_PERMISSION);
+ REQUEST_GET_ACCOUNTS_PERMISSION);
}
@RestrictTo(RestrictTo.Scope.LIBRARY)
@@ -153,7 +129,7 @@ private static boolean appInstalledOrNot(Context context) {
returnValue = true;
break;
} catch (PackageManager.NameNotFoundException e) {
- Log.v(TAG, e.getMessage());
+ Log.v(TAG, Optional.ofNullable(e.getMessage()).orElse(e.toString()));
}
}
return returnValue;
@@ -210,21 +186,17 @@ public static SingleSignOnAccount getSingleSignOnAccount(Context context, final
throw new NextcloudFilesAppAccountNotFoundException(context, accountName);
}
- /**
- * @deprecated Visibility will be private in the future
- */
- @Deprecated(forRemoval = true)
- public static SingleSignOnAccount extractSingleSignOnAccountFromResponse(Intent intent, Context context) {
- Bundle future = intent.getBundleExtra(NEXTCLOUD_SSO);
+ private static SingleSignOnAccount extractSingleSignOnAccountFromResponse(Intent intent, Context context) {
+ Bundle future = intent.getBundleExtra(INTERNAL_NEXTCLOUD_SSO);
String accountName = future.getString(AccountManager.KEY_ACCOUNT_NAME);
- String userId = future.getString(Constants.SSO_USER_ID);
+ String userId = future.getString(Constants.INTERNAL_SSO_USER_ID);
if (userId == null) {
// backwards compatibility
userId = future.getString("username");
}
- String token = future.getString(Constants.SSO_TOKEN);
- String serverUrl = future.getString(Constants.SSO_SERVER_URL);
+ String token = future.getString(Constants.INTERNAL_SSO_TOKEN);
+ String serverUrl = future.getString(Constants.INTERNAL_SSO_SERVER_URL);
String type = future.getString("accountType");
SharedPreferences mPrefs = getSharedPreferences(context);
@@ -238,69 +210,35 @@ public static SingleSignOnAccount extractSingleSignOnAccountFromResponse(Intent
return ssoAccount;
}
- /**
- * @see ActivityResultContract
- * @deprecated Use {@link ImportSsoAccount} - Visibility will be private in the future.
- */
- @Deprecated
+ @RestrictTo(RestrictTo.Scope.LIBRARY)
public interface IAccountAccessGranted {
void accountAccessGranted(SingleSignOnAccount singleSignOnAccount);
}
- /**
- * @see ActivityResultContract
- * @deprecated Use {@link ImportSsoAccount}
- */
- @Deprecated
- public static void onActivityResult(int requestCode, int resultCode, Intent data, Activity activity,
- IAccountAccessGranted callback) throws AccountImportCancelledException {
- onActivityResult(requestCode, resultCode, data, activity, null, callback, t -> {});
- }
-
- /**
- * @see ActivityResultContract
- * @deprecated Use {@link ImportSsoAccount}
- */
- @Deprecated
- public static void onActivityResult(int requestCode, int resultCode, Intent data, Fragment fragment,
- IAccountAccessGranted callback) throws AccountImportCancelledException {
- onActivityResult(requestCode, resultCode, data, null, fragment, callback, t -> {});
- }
-
@RestrictTo(RestrictTo.Scope.LIBRARY)
- public static void onActivityResult(int requestCode, int resultCode, Intent data, Activity activity,
- Fragment fragment, IAccountAccessGranted successCallback, Consumer failureCallback)
+ public static void onActivityResult(int requestCode, int resultCode, Intent data, Activity activity, IAccountAccessGranted successCallback, Consumer failureCallback)
throws AccountImportCancelledException {
- Context context = (activity != null) ? activity : fragment.getContext();
if (resultCode == RESULT_OK) {
switch (requestCode) {
case CHOOSE_ACCOUNT_SSO:
try {
- if (activity != null) {
- requestAuthToken(activity, data);
- } else {
- requestAuthToken(fragment, data);
- }
+ requestAuthToken(activity, data);
} catch (NextcloudFilesAppNotSupportedException |
NextcloudFilesAppAccountPermissionNotGrantedException e) {
- UiExceptionManager.showDialogForException(context, e, failureCallback::accept);
+ UiExceptionManager.showDialogForException(activity, e, failureCallback::accept);
}
break;
case REQUEST_AUTH_TOKEN_SSO:
- SingleSignOnAccount singleSignOnAccount = extractSingleSignOnAccountFromResponse(data, context);
+ SingleSignOnAccount singleSignOnAccount = extractSingleSignOnAccountFromResponse(data, activity);
successCallback.accountAccessGranted(singleSignOnAccount);
break;
case REQUEST_GET_ACCOUNTS_PERMISSION:
try {
- if (activity != null) {
- pickNewAccount(activity);
- } else {
- pickNewAccount(fragment);
- }
+ pickNewAccount(activity);
} catch (NextcloudFilesAppNotInstalledException |
AndroidGetAccountsPermissionNotGranted e) {
- UiExceptionManager.showDialogForException(context, e, failureCallback::accept);
+ UiExceptionManager.showDialogForException(activity, e, failureCallback::accept);
}
break;
default:
@@ -310,21 +248,20 @@ public static void onActivityResult(int requestCode, int resultCode, Intent data
switch (requestCode) {
case CHOOSE_ACCOUNT_SSO:
// nothing to do here
- throw new AccountImportCancelledException(context);
+ throw new AccountImportCancelledException(activity);
case REQUEST_AUTH_TOKEN_SSO:
try {
- handleFailedAuthRequest(context, data);
+ handleFailedAuthRequest(activity, data);
} catch (SSOException e) {
- UiExceptionManager.showDialogForException(context, e, failureCallback::accept);
+ UiExceptionManager.showDialogForException(activity, e, failureCallback::accept);
} catch (Exception e) {
- Toast.makeText(context, e.getMessage(), Toast.LENGTH_LONG).show();
- //e.printStackTrace();
- Log.e(TAG, e.getMessage());
+ Toast.makeText(activity, e.getMessage(), Toast.LENGTH_LONG).show();
+ Log.e(TAG, e.getMessage(), e);
failureCallback.accept(e);
}
break;
case REQUEST_GET_ACCOUNTS_PERMISSION:
- UiExceptionManager.showDialogForException(context, new AndroidGetAccountsPermissionNotGranted(context), failureCallback::accept);
+ UiExceptionManager.showDialogForException(activity, new AndroidGetAccountsPermissionNotGranted(activity), failureCallback::accept);
break;
default:
break;
@@ -332,45 +269,22 @@ public static void onActivityResult(int requestCode, int resultCode, Intent data
}
}
- /**
- * @see ActivityResultContract
- * @deprecated Use {@link ImportSsoAccount}
- */
- @Deprecated
- public static void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults, Activity activity) {
- onRequestPermissionsResult(requestCode, permissions, grantResults, activity, null, t -> {});
- }
-
- /**
- * @see ActivityResultContract
- * @deprecated Use {@link ImportSsoAccount}
- */
- @Deprecated
- public static void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults, Fragment fragment) {
- onRequestPermissionsResult(requestCode, permissions, grantResults, null, fragment, t -> {});
- }
-
@RestrictTo(RestrictTo.Scope.LIBRARY)
public static void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults, Activity activity, Fragment fragment, Consumer failureCallback) {
- Context context = (activity != null) ? activity : fragment.getContext();
-
+ //noinspection SwitchStatementWithTooFewBranches
switch (requestCode) {
case REQUEST_GET_ACCOUNTS_PERMISSION:
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
- // Permissions have been granted.. start pick account dialog
+ // Permissions have been granted… start pick account dialog
try {
- if (activity != null) {
- pickNewAccount(activity);
- } else {
- pickNewAccount(fragment);
- }
+ pickNewAccount(activity);
} catch (NextcloudFilesAppNotInstalledException |
AndroidGetAccountsPermissionNotGranted e) {
- UiExceptionManager.showDialogForException(context, e, failureCallback::accept);
+ UiExceptionManager.showDialogForException(activity, e, failureCallback::accept);
}
} else {
- // user declined the permission request..
- UiExceptionManager.showDialogForException(context, new AndroidGetAccountsPermissionNotGranted(context), failureCallback::accept);
+ // user declined the permission request…
+ UiExceptionManager.showDialogForException(activity, new AndroidGetAccountsPermissionNotGranted(activity), failureCallback::accept);
}
break;
default:
@@ -379,13 +293,9 @@ public static void onRequestPermissionsResult(int requestCode, @NonNull String[]
}
- /**
- * @deprecated Will be private in the future
- */
- @Deprecated
- public static void handleFailedAuthRequest(@NonNull Context context, @Nullable Intent data) throws SSOException {
+ private static void handleFailedAuthRequest(@NonNull Context context, @Nullable Intent data) throws SSOException {
if (data != null) {
- String exception = data.getStringExtra(NEXTCLOUD_SSO_EXCEPTION);
+ String exception = data.getStringExtra(INTERNAL_NEXTCLOUD_SSO_EXCEPTION);
throw SSOException.parseNextcloudCustomException(context, new Exception(exception));
} else {
Log.e(TAG, "handleFailedAuthRequest failed - data is null");
@@ -435,7 +345,7 @@ private static Intent buildRequestAuthTokenIntent(Context context, Intent intent
Intent authIntent = new Intent();
authIntent.setComponent(new ComponentName(componentName,
"com.owncloud.android.ui.activity.SsoGrantPermissionActivity"));
- authIntent.putExtra(NEXTCLOUD_FILES_ACCOUNT, account);
+ authIntent.putExtra(INTERNAL_NEXTCLOUD_FILES_ACCOUNT, account);
return authIntent;
}
@@ -443,7 +353,7 @@ public static SharedPreferences getSharedPreferences(Context context) {
if (SHARED_PREFERENCES != null) {
return SHARED_PREFERENCES;
} else {
- return context.getSharedPreferences(SSO_SHARED_PREFERENCE, Context.MODE_PRIVATE);
+ return context.getSharedPreferences(INTERNAL_SSO_SHARED_PREFERENCE, Context.MODE_PRIVATE);
}
}
diff --git a/lib/src/main/java/com/nextcloud/android/sso/Constants.java b/lib/src/main/java/com/nextcloud/android/sso/Constants.java
index 7f58bf43f..210b7ceef 100644
--- a/lib/src/main/java/com/nextcloud/android/sso/Constants.java
+++ b/lib/src/main/java/com/nextcloud/android/sso/Constants.java
@@ -7,22 +7,92 @@
*/
package com.nextcloud.android.sso;
+import androidx.annotation.RestrictTo;
+
public class Constants {
// Authenticator related constants
- public static final String SSO_USER_ID = "user_id";
- public static final String SSO_TOKEN = "token";
- public static final String SSO_SERVER_URL = "server_url";
- public static final String SSO_SHARED_PREFERENCE = "single-sign-on";
- public static final String NEXTCLOUD_SSO_EXCEPTION = "NextcloudSsoException";
- public static final String NEXTCLOUD_SSO = "NextcloudSSO";
- public static final String NEXTCLOUD_FILES_ACCOUNT = "NextcloudFilesAccount";
+
+ @RestrictTo(RestrictTo.Scope.LIBRARY)
+ public static final String INTERNAL_SSO_USER_ID = "user_id";
+
+ @RestrictTo(RestrictTo.Scope.LIBRARY)
+ public static final String INTERNAL_SSO_TOKEN = "token";
+
+ @RestrictTo(RestrictTo.Scope.LIBRARY)
+ public static final String INTERNAL_SSO_SERVER_URL = "server_url";
+
+ @RestrictTo(RestrictTo.Scope.LIBRARY)
+ public static final String INTERNAL_SSO_SHARED_PREFERENCE = "single-sign-on";
+
+ @RestrictTo(RestrictTo.Scope.LIBRARY)
+ public static final String INTERNAL_NEXTCLOUD_SSO_EXCEPTION = "NextcloudSsoException";
+
+ @RestrictTo(RestrictTo.Scope.LIBRARY)
+ public static final String INTERNAL_NEXTCLOUD_SSO = "NextcloudSSO";
+
+ @RestrictTo(RestrictTo.Scope.LIBRARY)
+ public static final String INTERNAL_NEXTCLOUD_FILES_ACCOUNT = "NextcloudFilesAccount";
+
// Custom Exceptions
- public static final String EXCEPTION_INVALID_TOKEN = "CE_1";
- public static final String EXCEPTION_ACCOUNT_NOT_FOUND = "CE_2";
- public static final String EXCEPTION_UNSUPPORTED_METHOD = "CE_3";
- public static final String EXCEPTION_INVALID_REQUEST_URL = "CE_4";
- public static final String EXCEPTION_HTTP_REQUEST_FAILED = "CE_5";
- public static final String EXCEPTION_ACCOUNT_ACCESS_DECLINED = "CE_6";
+
+ @RestrictTo(RestrictTo.Scope.LIBRARY)
+ public static final String INTERNAL_EXCEPTION_INVALID_TOKEN = "CE_1";
+
+ @RestrictTo(RestrictTo.Scope.LIBRARY)
+ public static final String INTERNAL_EXCEPTION_ACCOUNT_NOT_FOUND = "CE_2";
+
+ @RestrictTo(RestrictTo.Scope.LIBRARY)
+ public static final String INTERNAL_EXCEPTION_UNSUPPORTED_METHOD = "CE_3";
+
+ @RestrictTo(RestrictTo.Scope.LIBRARY)
+ public static final String INTERNAL_EXCEPTION_INVALID_REQUEST_URL = "CE_4";
+
+ @RestrictTo(RestrictTo.Scope.LIBRARY)
+ public static final String INTERNAL_EXCEPTION_HTTP_REQUEST_FAILED = "CE_5";
+
+ @RestrictTo(RestrictTo.Scope.LIBRARY)
+ public static final String INTERNAL_EXCEPTION_ACCOUNT_ACCESS_DECLINED = "CE_6";
+
+
+ /// @deprecated will be library private in the future
+ @Deprecated(forRemoval = true)
+ public static final String SSO_USER_ID = INTERNAL_SSO_USER_ID;
+ /// @deprecated will be library private in the future
+ @Deprecated(forRemoval = true)
+ public static final String SSO_TOKEN = INTERNAL_SSO_TOKEN;
+ /// @deprecated will be library private in the future
+ @Deprecated(forRemoval = true)
+ public static final String SSO_SERVER_URL = INTERNAL_SSO_SERVER_URL;
+ /// @deprecated will be library private in the future
+ @Deprecated(forRemoval = true)
+ public static final String SSO_SHARED_PREFERENCE = INTERNAL_SSO_SHARED_PREFERENCE;
+ /// @deprecated will be library private in the future
+ @Deprecated(forRemoval = true)
+ public static final String NEXTCLOUD_SSO_EXCEPTION = INTERNAL_NEXTCLOUD_SSO_EXCEPTION;
+ /// @deprecated will be library private in the future
+ @Deprecated(forRemoval = true)
+ public static final String NEXTCLOUD_SSO = INTERNAL_NEXTCLOUD_SSO;
+ /// @deprecated will be library private in the future
+ @Deprecated(forRemoval = true)
+ public static final String NEXTCLOUD_FILES_ACCOUNT = INTERNAL_NEXTCLOUD_FILES_ACCOUNT;
+ /// @deprecated will be library private in the future
+ @Deprecated(forRemoval = true)
+ public static final String EXCEPTION_INVALID_TOKEN = INTERNAL_EXCEPTION_INVALID_TOKEN;
+ /// @deprecated will be library private in the future
+ @Deprecated(forRemoval = true)
+ public static final String EXCEPTION_ACCOUNT_NOT_FOUND = INTERNAL_EXCEPTION_ACCOUNT_NOT_FOUND;
+ /// @deprecated will be library private in the future
+ @Deprecated(forRemoval = true)
+ public static final String EXCEPTION_UNSUPPORTED_METHOD = INTERNAL_EXCEPTION_UNSUPPORTED_METHOD;
+ /// @deprecated will be library private in the future
+ @Deprecated(forRemoval = true)
+ public static final String EXCEPTION_INVALID_REQUEST_URL = INTERNAL_EXCEPTION_INVALID_REQUEST_URL;
+ /// @deprecated will be library private in the future
+ @Deprecated(forRemoval = true)
+ public static final String EXCEPTION_HTTP_REQUEST_FAILED = INTERNAL_EXCEPTION_HTTP_REQUEST_FAILED;
+ /// @deprecated will be library private in the future
+ @Deprecated(forRemoval = true)
+ public static final String EXCEPTION_ACCOUNT_ACCESS_DECLINED = INTERNAL_EXCEPTION_ACCOUNT_ACCESS_DECLINED;
}
diff --git a/lib/src/main/java/com/nextcloud/android/sso/ImportSsoAccount.java b/lib/src/main/java/com/nextcloud/android/sso/ImportSsoAccount.java
index d384666bb..8a826be8b 100644
--- a/lib/src/main/java/com/nextcloud/android/sso/ImportSsoAccount.java
+++ b/lib/src/main/java/com/nextcloud/android/sso/ImportSsoAccount.java
@@ -6,7 +6,7 @@
*/
package com.nextcloud.android.sso;
-import static com.nextcloud.android.sso.Constants.NEXTCLOUD_SSO;
+import static com.nextcloud.android.sso.Constants.INTERNAL_NEXTCLOUD_SSO;
import android.app.Activity;
import android.content.Context;
@@ -35,7 +35,7 @@ public Intent createIntent(@NonNull Context context, Void input) {
@Override
public SingleSignOnAccount parseResult(int resultCode, @Nullable Intent intent) {
if (resultCode == Activity.RESULT_OK && intent != null) {
- return (SingleSignOnAccount) intent.getSerializableExtra(NEXTCLOUD_SSO);
+ return (SingleSignOnAccount) intent.getSerializableExtra(INTERNAL_NEXTCLOUD_SSO);
}
return null;
diff --git a/lib/src/main/java/com/nextcloud/android/sso/ImportSsoAccountActivity.java b/lib/src/main/java/com/nextcloud/android/sso/ImportSsoAccountActivity.java
index 903432c67..5a834b13e 100644
--- a/lib/src/main/java/com/nextcloud/android/sso/ImportSsoAccountActivity.java
+++ b/lib/src/main/java/com/nextcloud/android/sso/ImportSsoAccountActivity.java
@@ -12,6 +12,7 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
+import androidx.annotation.RestrictTo;
import androidx.appcompat.app.AppCompatActivity;
import com.nextcloud.android.sso.exceptions.AccountImportCancelledException;
@@ -21,6 +22,7 @@
/// This is a Trampoline Activity that takes care about requesting all necessary permissions and guiding the user through the complete import flow.
/// It is extremely important to catch *any* error and finish this activity because otherwise, the Trampoline Activity will stay on top but transparent, so users can't see it and users can't interact with their (visible) 3rd party app anymore.
+@RestrictTo(RestrictTo.Scope.LIBRARY)
public class ImportSsoAccountActivity extends AppCompatActivity {
private static final String TAG = ImportSsoAccountActivity.class.getSimpleName();
@@ -35,18 +37,16 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
try {
AccountImporter.checkAndroidAccountPermissions(this);
- //noinspection removal
AccountImporter.pickNewAccount(this);
} catch (AndroidGetAccountsPermissionNotGranted e) {
- //noinspection removal
AccountImporter.requestAndroidAccountPermissionsAndPickAccount(this);
} catch (SSOException ssoException) {
UiExceptionManager.showDialogForException(this, ssoException, t -> finish());
- } catch (Throwable throwable) {
- Log.e(TAG, throwable.getMessage(), throwable);
+ } catch (Exception exception) {
+ Log.e(TAG, exception.getMessage(), exception);
finish();
}
}
@@ -70,9 +70,9 @@ protected void onActivityResult(int requestCode, int resultCode, @Nullable Inten
super.onActivityResult(requestCode, resultCode, data);
try {
- AccountImporter.onActivityResult(requestCode, resultCode, data, this, null, ssoAccount -> {
+ AccountImporter.onActivityResult(requestCode, resultCode, data, this, ssoAccount -> {
final var result = new Intent();
- result.putExtra(Constants.NEXTCLOUD_SSO, ssoAccount);
+ result.putExtra(Constants.INTERNAL_NEXTCLOUD_SSO, ssoAccount);
setResult(RESULT_OK, result);
finish();
}, t -> finish());
diff --git a/lib/src/main/java/com/nextcloud/android/sso/QueryParam.java b/lib/src/main/java/com/nextcloud/android/sso/QueryParam.java
index 76215bd6b..d8bf8b02f 100644
--- a/lib/src/main/java/com/nextcloud/android/sso/QueryParam.java
+++ b/lib/src/main/java/com/nextcloud/android/sso/QueryParam.java
@@ -7,10 +7,10 @@
*/
package com.nextcloud.android.sso;
-import java.io.Serializable;
-
import androidx.annotation.Nullable;
+import java.io.Serializable;
+
public class QueryParam implements Serializable {
private static final long serialVersionUID = 21523240203234211L; //assign a long value
@@ -29,8 +29,7 @@ public boolean equals(@Nullable Object obj) {
return false;
}
- if (obj instanceof QueryParam) {
- QueryParam other = (QueryParam) obj;
+ if (obj instanceof QueryParam other) {
return this.key.equals(other.key) && this.value.equals(other.value);
} else {
return false;
diff --git a/lib/src/main/java/com/nextcloud/android/sso/exceptions/SSOException.java b/lib/src/main/java/com/nextcloud/android/sso/exceptions/SSOException.java
index e49c68d7f..3246a8983 100644
--- a/lib/src/main/java/com/nextcloud/android/sso/exceptions/SSOException.java
+++ b/lib/src/main/java/com/nextcloud/android/sso/exceptions/SSOException.java
@@ -89,12 +89,12 @@ public static SSOException parseNextcloudCustomException(@NonNull Context contex
}
return switch (message) {
- case Constants.EXCEPTION_INVALID_TOKEN -> new TokenMismatchException(context);
- case Constants.EXCEPTION_ACCOUNT_NOT_FOUND -> new NextcloudFilesAppAccountNotFoundException(context);
- case Constants.EXCEPTION_UNSUPPORTED_METHOD -> new NextcloudUnsupportedMethodException(context);
- case Constants.EXCEPTION_INVALID_REQUEST_URL ->
+ case Constants.INTERNAL_EXCEPTION_INVALID_TOKEN -> new TokenMismatchException(context);
+ case Constants.INTERNAL_EXCEPTION_ACCOUNT_NOT_FOUND -> new NextcloudFilesAppAccountNotFoundException(context);
+ case Constants.INTERNAL_EXCEPTION_UNSUPPORTED_METHOD -> new NextcloudUnsupportedMethodException(context);
+ case Constants.INTERNAL_EXCEPTION_INVALID_REQUEST_URL ->
new NextcloudInvalidRequestUrlException(context, exception.getCause());
- case Constants.EXCEPTION_HTTP_REQUEST_FAILED -> {
+ case Constants.INTERNAL_EXCEPTION_HTTP_REQUEST_FAILED -> {
Throwable rootCause = exception.getCause();
if (rootCause != null && rootCause.getMessage() != null) {
int statusCode = Integer.parseInt(rootCause.getMessage());
@@ -104,7 +104,7 @@ public static SSOException parseNextcloudCustomException(@NonNull Context contex
yield new UnknownErrorException(message);
}
}
- case Constants.EXCEPTION_ACCOUNT_ACCESS_DECLINED ->
+ case Constants.INTERNAL_EXCEPTION_ACCOUNT_ACCESS_DECLINED ->
new NextcloudFilesAppAccountPermissionNotGrantedException(context);
default -> {
if (isNetworkConnectivityError(exception)) {
diff --git a/sample/src/main/java/com/nextcloud/android/sso/sample/MainActivity.java b/sample/src/main/java/com/nextcloud/android/sso/sample/MainActivity.java
index 2667249d9..73384d549 100644
--- a/sample/src/main/java/com/nextcloud/android/sso/sample/MainActivity.java
+++ b/sample/src/main/java/com/nextcloud/android/sso/sample/MainActivity.java
@@ -88,14 +88,14 @@ private void handleResult(SingleSignOnAccount ssoAccount) {
);
} catch (Exception e) {
runOnUiThread(() -> ((TextView) findViewById(R.id.result)).setText(e.getMessage()));
- e.printStackTrace();
+ Log.e(TAG, e.getMessage(), e);
}
/*
* If you need to make multiple calls, keep the NextcloudAPI open as long as you
* can. This way the services will stay active and the connection between the
* files app and your app is already established when you make subsequent requests.
- * Otherwise you'll have to bind to the service again and again for each request.
+ * Otherwise, you'll have to bind to the service again and again for each request.
*
* @see https://github.com/nextcloud/Android-SingleSignOn/issues/120#issuecomment-540069990
*/