From 319a2c129dad9feec3778444949bf7e30cbf0ecb Mon Sep 17 00:00:00 2001 From: Fahim Salam Chowdhury Date: Tue, 21 Feb 2023 13:05:03 +0600 Subject: [PATCH 1/3] 6684-Add_support_to_pick_account_directly issue: https://gitlab.e.foundation/e/backlog/-/issues/6684 we want to let apps to pass specific account to pick, so it can bypass the pick account dialog. --- .../android/sso/AccountImporter.java | 47 ++++++++++++++++--- 1 file changed, 41 insertions(+), 6 deletions(-) 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 dc5248d1..782fc2f8 100644 --- a/lib/src/main/java/com/nextcloud/android/sso/AccountImporter.java +++ b/lib/src/main/java/com/nextcloud/android/sso/AccountImporter.java @@ -107,6 +107,29 @@ public class AccountImporter { } } + public static void pickAccount(Activity activity, Account account) throws NextcloudFilesAppNotInstalledException, + AndroidGetAccountsPermissionNotGranted, NextcloudFilesAppNotSupportedException, NextcloudFilesAppAccountPermissionNotGrantedException { + checkAndroidAccountPermissions(activity); + + if (appInstalledOrNot(activity)) { + requestAuthToken(activity, account); + } else { + throw new NextcloudFilesAppNotInstalledException(); + } + } + + public static void pickAccount(Fragment fragment, Account account) throws NextcloudFilesAppNotInstalledException, + AndroidGetAccountsPermissionNotGranted, NextcloudFilesAppNotSupportedException, NextcloudFilesAppAccountPermissionNotGrantedException { + checkAndroidAccountPermissions(fragment.getContext()); + + if (appInstalledOrNot(fragment.requireContext())) { + requestAuthToken(fragment, account); + } else { + throw new NextcloudFilesAppNotInstalledException(); + } + } + + public static void requestAndroidAccountPermissionsAndPickAccount(Activity activity) { ActivityCompat.requestPermissions(activity, new String[]{Manifest.permission.GET_ACCOUNTS}, REQUEST_GET_ACCOUNTS_PERMISSION); @@ -346,7 +369,17 @@ public class AccountImporter { } public static void requestAuthToken(Fragment fragment, Intent intent) throws NextcloudFilesAppNotSupportedException, NextcloudFilesAppAccountPermissionNotGrantedException { - Intent authIntent = buildRequestAuthTokenIntent(fragment.getContext(), intent); + Account account = getAccount(fragment.getContext(), intent); + requestAuthToken(fragment, account); + } + + public static void requestAuthToken(Activity activity, Intent intent) throws NextcloudFilesAppNotSupportedException, NextcloudFilesAppAccountPermissionNotGrantedException { + Account account = getAccount(activity, intent); + requestAuthToken(activity, account); + } + + public static void requestAuthToken(Fragment fragment, Account account) throws NextcloudFilesAppNotSupportedException, NextcloudFilesAppAccountPermissionNotGrantedException { + Intent authIntent = buildRequestAuthTokenIntent(account); try { fragment.startActivityForResult(authIntent, REQUEST_AUTH_TOKEN_SSO); } catch (ActivityNotFoundException e) { @@ -354,18 +387,20 @@ public class AccountImporter { } } - public static void requestAuthToken(Activity activity, Intent intent) throws NextcloudFilesAppNotSupportedException, NextcloudFilesAppAccountPermissionNotGrantedException { - Intent authIntent = buildRequestAuthTokenIntent(activity, intent); + public static void requestAuthToken(Activity activity, Account account) throws NextcloudFilesAppNotSupportedException, NextcloudFilesAppAccountPermissionNotGrantedException { + Intent authIntent = buildRequestAuthTokenIntent(account); try { activity.startActivityForResult(authIntent, REQUEST_AUTH_TOKEN_SSO); } catch (ActivityNotFoundException e) { throw new NextcloudFilesAppNotSupportedException(); } } - - private static Intent buildRequestAuthTokenIntent(Context context, Intent intent) throws NextcloudFilesAppAccountPermissionNotGrantedException { + private static Account getAccount(Context context, Intent intent) { String accountName = intent.getStringExtra(AccountManager.KEY_ACCOUNT_NAME); - Account account = AccountImporter.getAccountForName(context, accountName); + return AccountImporter.getAccountForName(context, accountName); + } + + private static Intent buildRequestAuthTokenIntent(Account account) throws NextcloudFilesAppAccountPermissionNotGrantedException { if(account == null) { throw new NextcloudFilesAppAccountPermissionNotGrantedException(); } -- GitLab From 8089475c8e52af8eb0c614c3f756a7171a9381f2 Mon Sep 17 00:00:00 2001 From: Fahim Salam Chowdhury Date: Tue, 21 Feb 2023 13:07:42 +0600 Subject: [PATCH 2/3] bump the version code to 1.0.4-alpha --- lib/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/build.gradle b/lib/build.gradle index cb2b1577..eb0af0b3 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -18,7 +18,7 @@ group = 'foundation.e.lib' def versionMajor = 1 def versionMinor = 0 -def versionPatch = 3 +def versionPatch = 4 def releasePatch = "alpha" def libName = "Android-SingleSignOn" -- GitLab From 3aa173bd21e87e4a74e1a4f117adc1d186bc6641 Mon Sep 17 00:00:00 2001 From: Vincent Bourgmayer Date: Tue, 21 Feb 2023 08:18:39 +0000 Subject: [PATCH 3/3] Apply 5 suggestion(s) to 1 file(s) --- .../com/nextcloud/android/sso/AccountImporter.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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 782fc2f8..d00c96f3 100644 --- a/lib/src/main/java/com/nextcloud/android/sso/AccountImporter.java +++ b/lib/src/main/java/com/nextcloud/android/sso/AccountImporter.java @@ -369,17 +369,17 @@ public class AccountImporter { } public static void requestAuthToken(Fragment fragment, Intent intent) throws NextcloudFilesAppNotSupportedException, NextcloudFilesAppAccountPermissionNotGrantedException { - Account account = getAccount(fragment.getContext(), intent); + final Account account = getAccount(fragment.getContext(), intent); requestAuthToken(fragment, account); } public static void requestAuthToken(Activity activity, Intent intent) throws NextcloudFilesAppNotSupportedException, NextcloudFilesAppAccountPermissionNotGrantedException { - Account account = getAccount(activity, intent); + final Account account = getAccount(activity, intent); requestAuthToken(activity, account); } public static void requestAuthToken(Fragment fragment, Account account) throws NextcloudFilesAppNotSupportedException, NextcloudFilesAppAccountPermissionNotGrantedException { - Intent authIntent = buildRequestAuthTokenIntent(account); + final Intent authIntent = buildRequestAuthTokenIntent(account); try { fragment.startActivityForResult(authIntent, REQUEST_AUTH_TOKEN_SSO); } catch (ActivityNotFoundException e) { @@ -388,7 +388,7 @@ public class AccountImporter { } public static void requestAuthToken(Activity activity, Account account) throws NextcloudFilesAppNotSupportedException, NextcloudFilesAppAccountPermissionNotGrantedException { - Intent authIntent = buildRequestAuthTokenIntent(account); + final Intent authIntent = buildRequestAuthTokenIntent(account); try { activity.startActivityForResult(authIntent, REQUEST_AUTH_TOKEN_SSO); } catch (ActivityNotFoundException e) { @@ -396,7 +396,7 @@ public class AccountImporter { } } private static Account getAccount(Context context, Intent intent) { - String accountName = intent.getStringExtra(AccountManager.KEY_ACCOUNT_NAME); + final String accountName = intent.getStringExtra(AccountManager.KEY_ACCOUNT_NAME); return AccountImporter.getAccountForName(context, accountName); } -- GitLab