mirror of
https://github.com/nextcloud/android.git
synced 2024-11-21 20:55:31 +03:00
Use context instead of static getAppContext
This commit is contained in:
parent
431386db85
commit
b4b1790ef6
15 changed files with 80 additions and 108 deletions
|
@ -6,4 +6,4 @@ if [ -z $3 ] ; then
|
|||
echo "master";
|
||||
else
|
||||
curl 2>/dev/null -u $1:$2 https://api.github.com/repos/nextcloud/android/pulls/$3 | grep \"ref\": | grep -v master | cut -d"\"" -f4
|
||||
fi
|
||||
fi
|
||||
|
|
|
@ -45,7 +45,7 @@ public abstract class AbstractIT extends ApplicationTestCase<MainApp> {
|
|||
try {
|
||||
context = MainApp.getAppContext();
|
||||
|
||||
Account temp = new Account(username + "@" + baseUrl, MainApp.getAccountType());
|
||||
Account temp = new Account(username + "@" + baseUrl, MainApp.getAccountType(context));
|
||||
|
||||
if (!com.owncloud.android.authentication.AccountUtils.exists(temp, context)) {
|
||||
AccountManager accountManager = AccountManager.get(context);
|
||||
|
|
|
@ -382,8 +382,8 @@ public class MainApp extends MultiDexApplication {
|
|||
// Methods to obtain Strings referring app_name
|
||||
// From AccountAuthenticator
|
||||
// public static final String ACCOUNT_TYPE = "owncloud";
|
||||
public static String getAccountType() {
|
||||
return getAppContext().getResources().getString(R.string.account_type);
|
||||
public static String getAccountType(Context context) {
|
||||
return context.getResources().getString(R.string.account_type);
|
||||
}
|
||||
|
||||
// Non gradle build systems do not provide BuildConfig.VERSION_CODE
|
||||
|
|
|
@ -83,7 +83,7 @@ public class AccountAuthenticator extends AbstractAccountAuthenticator {
|
|||
final Bundle bundle = new Bundle();
|
||||
|
||||
AccountManager accountManager = AccountManager.get(mContext);
|
||||
Account[] accounts = accountManager.getAccountsByType(MainApp.getAccountType());
|
||||
Account[] accounts = accountManager.getAccountsByType(MainApp.getAccountType(mContext));
|
||||
|
||||
if (mContext.getResources().getBoolean(R.bool.multiaccount_support) || accounts.length < 1) {
|
||||
try {
|
||||
|
@ -169,7 +169,7 @@ public class AccountAuthenticator extends AbstractAccountAuthenticator {
|
|||
/// check if required token is stored
|
||||
final AccountManager am = AccountManager.get(mContext);
|
||||
String accessToken;
|
||||
if (authTokenType.equals(AccountTypeUtils.getAuthTokenTypePass(MainApp.getAccountType()))) {
|
||||
if (authTokenType.equals(AccountTypeUtils.getAuthTokenTypePass(MainApp.getAccountType(mContext)))) {
|
||||
accessToken = am.getPassword(account);
|
||||
} else {
|
||||
accessToken = am.peekAuthToken(account, authTokenType);
|
||||
|
@ -177,7 +177,7 @@ public class AccountAuthenticator extends AbstractAccountAuthenticator {
|
|||
if (accessToken != null) {
|
||||
final Bundle result = new Bundle();
|
||||
result.putString(AccountManager.KEY_ACCOUNT_NAME, account.name);
|
||||
result.putString(AccountManager.KEY_ACCOUNT_TYPE, MainApp.getAccountType());
|
||||
result.putString(AccountManager.KEY_ACCOUNT_TYPE, MainApp.getAccountType(mContext));
|
||||
result.putString(AccountManager.KEY_AUTHTOKEN, accessToken);
|
||||
return result;
|
||||
}
|
||||
|
@ -239,17 +239,19 @@ public class AccountAuthenticator extends AbstractAccountAuthenticator {
|
|||
}
|
||||
|
||||
private void validateAccountType(String type) throws UnsupportedAccountTypeException {
|
||||
if (!type.equals(MainApp.getAccountType())) {
|
||||
if (!type.equals(MainApp.getAccountType(mContext))) {
|
||||
throw new UnsupportedAccountTypeException();
|
||||
}
|
||||
}
|
||||
|
||||
private void validateAuthTokenType(String authTokenType) throws UnsupportedAuthTokenTypeException {
|
||||
if (!authTokenType.equals(MainApp.getAuthTokenType()) &&
|
||||
!authTokenType.equals(AccountTypeUtils.getAuthTokenTypePass(MainApp.getAccountType())) &&
|
||||
!authTokenType.equals(AccountTypeUtils.getAuthTokenTypeAccessToken(MainApp.getAccountType())) &&
|
||||
!authTokenType.equals(AccountTypeUtils.getAuthTokenTypeRefreshToken(MainApp.getAccountType())) &&
|
||||
!authTokenType.equals(AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType()))) {
|
||||
String accountType = MainApp.getAccountType(mContext);
|
||||
|
||||
if (!authTokenType.equals(accountType) &&
|
||||
!authTokenType.equals(AccountTypeUtils.getAuthTokenTypePass(accountType)) &&
|
||||
!authTokenType.equals(AccountTypeUtils.getAuthTokenTypeAccessToken(accountType)) &&
|
||||
!authTokenType.equals(AccountTypeUtils.getAuthTokenTypeRefreshToken(accountType)) &&
|
||||
!authTokenType.equals(AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(accountType))) {
|
||||
throw new UnsupportedAuthTokenTypeException();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -97,7 +97,7 @@ public class AccountUtils {
|
|||
|
||||
public static Account[] getAccounts(Context context) {
|
||||
AccountManager accountManager = AccountManager.get(context);
|
||||
return accountManager.getAccountsByType(MainApp.getAccountType());
|
||||
return accountManager.getAccountsByType(MainApp.getAccountType(context));
|
||||
}
|
||||
|
||||
|
||||
|
@ -144,8 +144,7 @@ public class AccountUtils {
|
|||
* @return owncloud account named accountName
|
||||
*/
|
||||
public static Account getOwnCloudAccountByName(Context context, String accountName) {
|
||||
Account[] ocAccounts = AccountManager.get(context).getAccountsByType(
|
||||
MainApp.getAccountType());
|
||||
Account[] ocAccounts = AccountManager.get(context).getAccountsByType(MainApp.getAccountType(context));
|
||||
for (Account account : ocAccounts) {
|
||||
if(account.name.equals(accountName)) {
|
||||
return account;
|
||||
|
|
|
@ -242,9 +242,10 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
|
|||
/// Identifier of operation in progress which result shouldn't be lost
|
||||
private long mWaitingForOpId = Long.MAX_VALUE;
|
||||
|
||||
private final String BASIC_TOKEN_TYPE = AccountTypeUtils.getAuthTokenTypePass(MainApp.getAccountType());
|
||||
private final String OAUTH_TOKEN_TYPE = AccountTypeUtils.getAuthTokenTypeAccessToken(MainApp.getAccountType());
|
||||
private final String SAML_TOKEN_TYPE = AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType());
|
||||
private final String BASIC_TOKEN_TYPE = AccountTypeUtils.getAuthTokenTypePass(MainApp.getAccountType(this));
|
||||
private final String OAUTH_TOKEN_TYPE = AccountTypeUtils.getAuthTokenTypeAccessToken(MainApp.getAccountType(this));
|
||||
private final String SAML_TOKEN_TYPE = AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(
|
||||
MainApp.getAccountType(this));
|
||||
|
||||
private boolean webViewLoginMethod;
|
||||
private String webViewUser;
|
||||
|
@ -591,10 +592,10 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
|
|||
|
||||
String instructionsMessageText = null;
|
||||
if (mAction == ACTION_UPDATE_EXPIRED_TOKEN) {
|
||||
if (AccountTypeUtils.getAuthTokenTypeAccessToken(MainApp.getAccountType()).equals(mAuthTokenType)) {
|
||||
if (AccountTypeUtils.getAuthTokenTypeAccessToken(MainApp.getAccountType(this)).equals(mAuthTokenType)) {
|
||||
instructionsMessageText = getString(R.string.auth_expired_oauth_token_toast);
|
||||
|
||||
} else if (AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType())
|
||||
} else if (AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType(this))
|
||||
.equals(mAuthTokenType)) {
|
||||
instructionsMessageText = getString(R.string.auth_expired_saml_sso_token_toast);
|
||||
|
||||
|
@ -723,9 +724,8 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
|
|||
@Override
|
||||
public boolean onTouch(View view, MotionEvent event) {
|
||||
if (event.getAction() == MotionEvent.ACTION_DOWN &&
|
||||
AccountTypeUtils
|
||||
.getAuthTokenTypeSamlSessionCookie(MainApp
|
||||
.getAccountType()).equals(mAuthTokenType) &&
|
||||
AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(
|
||||
MainApp.getAccountType(getBaseContext())).equals(mAuthTokenType) &&
|
||||
mHostUrlInput.hasFocus()) {
|
||||
checkOcServer();
|
||||
}
|
||||
|
@ -765,8 +765,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
|
|||
|
||||
/// step 2 - set properties of UI elements (text, visibility, enabled...)
|
||||
mOAuth2Check.setChecked(
|
||||
AccountTypeUtils.getAuthTokenTypeAccessToken(MainApp.getAccountType())
|
||||
.equals(mAuthTokenType));
|
||||
AccountTypeUtils.getAuthTokenTypeAccessToken(MainApp.getAccountType(this)).equals(mAuthTokenType));
|
||||
if (presetUserName != null) {
|
||||
mUsernameInput.setText(presetUserName);
|
||||
}
|
||||
|
@ -806,8 +805,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
|
|||
* the current authorization method.
|
||||
*/
|
||||
private void updateAuthenticationPreFragmentVisibility() {
|
||||
if (AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType()).
|
||||
equals(mAuthTokenType)) {
|
||||
if (AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType(this)).equals(mAuthTokenType)) {
|
||||
// SAML-based web Single Sign On
|
||||
mOAuth2Check.setVisibility(View.GONE);
|
||||
mOAuthAuthEndpointText.setVisibility(View.GONE);
|
||||
|
@ -823,10 +821,8 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
|
|||
mOAuth2Check.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
if (AccountTypeUtils.getAuthTokenTypeAccessToken(MainApp.getAccountType()).
|
||||
equals(mAuthTokenType)) {
|
||||
if (AccountTypeUtils.getAuthTokenTypeAccessToken(MainApp.getAccountType(this)).equals(mAuthTokenType)) {
|
||||
// OAuth 2 authorization
|
||||
|
||||
mOAuthAuthEndpointText.setVisibility(View.VISIBLE);
|
||||
mOAuthTokenEndpointText.setVisibility(View.VISIBLE);
|
||||
mUsernameInput.setVisibility(View.GONE);
|
||||
|
@ -1226,16 +1222,14 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
|
|||
return;
|
||||
}
|
||||
|
||||
if (AccountTypeUtils.getAuthTokenTypeAccessToken(MainApp.getAccountType()).equals(mAuthTokenType)) {
|
||||
if (AccountTypeUtils.getAuthTokenTypeAccessToken(MainApp.getAccountType(this)).equals(mAuthTokenType)) {
|
||||
startOauthorization();
|
||||
} else if (AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType())
|
||||
} else if (AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType(this))
|
||||
.equals(mAuthTokenType)) {
|
||||
|
||||
startSamlBasedFederatedSingleSignOnAuthorization();
|
||||
} else {
|
||||
checkBasicAuthorization(null, null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -1316,7 +1310,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
|
|||
|
||||
/// Show SAML-based SSO web dialog
|
||||
String targetUrl = mServerInfo.mBaseUrl
|
||||
+ AuthenticatorUrlUtils.getWebdavPath(mServerInfo.mVersion, mAuthTokenType);
|
||||
+ AuthenticatorUrlUtils.getWebdavPath(mServerInfo.mVersion, mAuthTokenType, this);
|
||||
SamlWebViewDialog dialog = SamlWebViewDialog.newInstance(targetUrl, targetUrl);
|
||||
dialog.show(getSupportFragmentManager(), SAML_DIALOG_TAG);
|
||||
}
|
||||
|
@ -1795,22 +1789,19 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
|
|||
* the new credentials when needed.
|
||||
*/
|
||||
private void updateAccountAuthentication() throws AccountNotFoundException {
|
||||
|
||||
String accountType = MainApp.getAccountType(this);
|
||||
|
||||
Bundle response = new Bundle();
|
||||
response.putString(AccountManager.KEY_ACCOUNT_NAME, mAccount.name);
|
||||
response.putString(AccountManager.KEY_ACCOUNT_TYPE, mAccount.type);
|
||||
|
||||
if (AccountTypeUtils.getAuthTokenTypeAccessToken(MainApp.getAccountType()).
|
||||
equals(mAuthTokenType)) {
|
||||
if (AccountTypeUtils.getAuthTokenTypeAccessToken(accountType).equals(mAuthTokenType)) {
|
||||
response.putString(AccountManager.KEY_AUTHTOKEN, mAuthToken);
|
||||
// the next line is necessary, notifications are calling directly to the
|
||||
// AuthenticatorActivity to update, without AccountManager intervention
|
||||
mAccountMgr.setAuthToken(mAccount, mAuthTokenType, mAuthToken);
|
||||
|
||||
} else if (AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType()).
|
||||
equals(mAuthTokenType)) {
|
||||
|
||||
} else if (AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(accountType).equals(mAuthTokenType)) {
|
||||
response.putString(AccountManager.KEY_AUTHTOKEN, mAuthToken);
|
||||
// the next line is necessary; by now, notifications are calling directly to the
|
||||
// AuthenticatorActivity to update, without AccountManager intervention
|
||||
|
@ -1847,11 +1838,11 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
|
|||
*/
|
||||
@SuppressFBWarnings("DMI")
|
||||
private boolean createAccount(RemoteOperationResult authResult) {
|
||||
/// create and save new ownCloud account
|
||||
boolean isOAuth = AccountTypeUtils.
|
||||
getAuthTokenTypeAccessToken(MainApp.getAccountType()).equals(mAuthTokenType);
|
||||
boolean isSaml = AccountTypeUtils.
|
||||
getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType()).equals(mAuthTokenType);
|
||||
String accountType = MainApp.getAccountType(this);
|
||||
|
||||
// create and save new ownCloud account
|
||||
boolean isOAuth = AccountTypeUtils.getAuthTokenTypeAccessToken(accountType).equals(mAuthTokenType);
|
||||
boolean isSaml = AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(accountType).equals(mAuthTokenType);
|
||||
|
||||
String lastPermanentLocation = authResult.getLastPermanentLocation();
|
||||
if (lastPermanentLocation != null) {
|
||||
|
@ -1869,9 +1860,8 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
|
|||
username = "OAuth_user" + (new java.util.Random(System.currentTimeMillis())).nextLong();
|
||||
}
|
||||
|
||||
String accountName = com.owncloud.android.lib.common.accounts.AccountUtils.
|
||||
buildAccountName(uri, username);
|
||||
Account newAccount = new Account(accountName, MainApp.getAccountType());
|
||||
String accountName = com.owncloud.android.lib.common.accounts.AccountUtils.buildAccountName(uri, username);
|
||||
Account newAccount = new Account(accountName, accountType);
|
||||
if (AccountUtils.exists(newAccount, getApplicationContext())) {
|
||||
// fail - not a new account, but an existing one; disallow
|
||||
RemoteOperationResult result = new RemoteOperationResult(ResultCode.ACCOUNT_NOT_NEW);
|
||||
|
@ -1890,28 +1880,20 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
|
|||
mAccountMgr.addAccountExplicitly(mAccount, "", null);
|
||||
} else {
|
||||
if (!webViewLoginMethod) {
|
||||
mAccountMgr.addAccountExplicitly(
|
||||
mAccount, mPasswordInput.getText().toString(), null
|
||||
);
|
||||
mAccountMgr.addAccountExplicitly(mAccount, mPasswordInput.getText().toString(), null);
|
||||
} else {
|
||||
mAccountMgr.addAccountExplicitly(
|
||||
mAccount, webViewPassword, null
|
||||
);
|
||||
mAccountMgr.addAccountExplicitly(mAccount, webViewPassword, null);
|
||||
}
|
||||
}
|
||||
|
||||
// include account version with the new account
|
||||
mAccountMgr.setUserData(
|
||||
mAccount,
|
||||
Constants.KEY_OC_ACCOUNT_VERSION,
|
||||
Integer.toString(AccountUtils.ACCOUNT_VERSION)
|
||||
);
|
||||
mAccountMgr.setUserData(mAccount, Constants.KEY_OC_ACCOUNT_VERSION,
|
||||
Integer.toString(AccountUtils.ACCOUNT_VERSION));
|
||||
|
||||
/// add the new account as default in preferences, if there is none already
|
||||
Account defaultAccount = AccountUtils.getCurrentOwnCloudAccount(this);
|
||||
if (defaultAccount == null) {
|
||||
SharedPreferences.Editor editor = PreferenceManager
|
||||
.getDefaultSharedPreferences(this).edit();
|
||||
SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(this).edit();
|
||||
editor.putString("select_oc_account", accountName);
|
||||
editor.apply();
|
||||
}
|
||||
|
@ -1920,7 +1902,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
|
|||
// TODO check again what the Authenticator makes with it; probably has the same
|
||||
// effect as addAccountExplicitly, but it's not well done
|
||||
final Intent intent = new Intent();
|
||||
intent.putExtra(AccountManager.KEY_ACCOUNT_TYPE, MainApp.getAccountType());
|
||||
intent.putExtra(AccountManager.KEY_ACCOUNT_TYPE, accountType);
|
||||
intent.putExtra(AccountManager.KEY_ACCOUNT_NAME, mAccount.name);
|
||||
intent.putExtra(AccountManager.KEY_USERDATA, username);
|
||||
if (isOAuth || isSaml) {
|
||||
|
@ -1928,23 +1910,14 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
|
|||
}
|
||||
/// add user data to the new account; TODO probably can be done in the last parameter
|
||||
// addAccountExplicitly, or in KEY_USERDATA
|
||||
mAccountMgr.setUserData(
|
||||
mAccount, Constants.KEY_OC_VERSION, mServerInfo.mVersion.getVersion()
|
||||
);
|
||||
mAccountMgr.setUserData(
|
||||
mAccount, Constants.KEY_OC_BASE_URL, mServerInfo.mBaseUrl
|
||||
);
|
||||
mAccountMgr.setUserData(mAccount, Constants.KEY_OC_VERSION, mServerInfo.mVersion.getVersion());
|
||||
mAccountMgr.setUserData(mAccount, Constants.KEY_OC_BASE_URL, mServerInfo.mBaseUrl);
|
||||
|
||||
if (authResult.getData() != null) {
|
||||
try {
|
||||
UserInfo userInfo = (UserInfo) authResult.getData().get(0);
|
||||
mAccountMgr.setUserData(
|
||||
mAccount, Constants.KEY_DISPLAY_NAME, userInfo.getDisplayName()
|
||||
);
|
||||
|
||||
mAccountMgr.setUserData(
|
||||
mAccount, Constants.KEY_USER_ID, userInfo.getId()
|
||||
);
|
||||
mAccountMgr.setUserData(mAccount, Constants.KEY_DISPLAY_NAME, userInfo.getDisplayName());
|
||||
mAccountMgr.setUserData(mAccount, Constants.KEY_USER_ID, userInfo.getId());
|
||||
} catch (ClassCastException c) {
|
||||
Log_OC.w(TAG, "Couldn't get display name for " + username);
|
||||
}
|
||||
|
@ -2148,8 +2121,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
|
|||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
if (AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType()).
|
||||
equals(mAuthTokenType) &&
|
||||
if (AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType(this)).equals(mAuthTokenType) &&
|
||||
mHostUrlInput.hasFocus() && event.getAction() == MotionEvent.ACTION_DOWN) {
|
||||
checkOcServer();
|
||||
}
|
||||
|
@ -2160,16 +2132,13 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
|
|||
/**
|
||||
* Show untrusted cert dialog
|
||||
*/
|
||||
public void showUntrustedCertDialog(
|
||||
X509Certificate x509Certificate, SslError error, SslErrorHandler handler
|
||||
) {
|
||||
public void showUntrustedCertDialog(X509Certificate x509Certificate, SslError error, SslErrorHandler handler) {
|
||||
// Show a dialog with the certificate info
|
||||
SslUntrustedCertDialog dialog;
|
||||
if (x509Certificate == null) {
|
||||
dialog = SslUntrustedCertDialog.newInstanceForEmptySslError(error, handler);
|
||||
} else {
|
||||
dialog = SslUntrustedCertDialog.
|
||||
newInstanceForFullSslError(x509Certificate, error, handler);
|
||||
dialog = SslUntrustedCertDialog.newInstanceForFullSslError(x509Certificate, error, handler);
|
||||
}
|
||||
FragmentManager fm = getSupportFragmentManager();
|
||||
FragmentTransaction ft = fm.beginTransaction();
|
||||
|
|
|
@ -21,6 +21,8 @@
|
|||
|
||||
package com.owncloud.android.authentication;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.owncloud.android.MainApp;
|
||||
import com.owncloud.android.lib.common.accounts.AccountTypeUtils;
|
||||
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
|
||||
|
@ -49,12 +51,13 @@ public abstract class AuthenticatorUrlUtils {
|
|||
* @return WebDAV path for given OC version and authorization method, null if OC version
|
||||
* is unknown; versions prior to ownCloud 4 are not supported anymore
|
||||
*/
|
||||
public static String getWebdavPath(OwnCloudVersion version, String authTokenType) {
|
||||
public static String getWebdavPath(OwnCloudVersion version, String authTokenType, Context context) {
|
||||
if (version != null) {
|
||||
if (AccountTypeUtils.getAuthTokenTypeAccessToken(MainApp.getAccountType()).equals(authTokenType)) {
|
||||
String accountType = MainApp.getAccountType(context);
|
||||
if (AccountTypeUtils.getAuthTokenTypeAccessToken(accountType).equals(authTokenType)) {
|
||||
return ODAV_PATH;
|
||||
}
|
||||
if (AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType()).equals(authTokenType)) {
|
||||
if (AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(accountType).equals(authTokenType)) {
|
||||
return SAML_SSO_PATH;
|
||||
}
|
||||
|
||||
|
|
|
@ -93,7 +93,7 @@ public class OfflineSyncJob extends Job {
|
|||
accountName = cursorOnKeptInSync.getString(cursorOnKeptInSync
|
||||
.getColumnIndex(ProviderMeta.ProviderTableMeta.FILE_ACCOUNT_OWNER));
|
||||
|
||||
account = new Account(accountName, MainApp.getAccountType());
|
||||
account = new Account(accountName, MainApp.getAccountType(getContext()));
|
||||
if (!AccountUtils.exists(account, context) || localPath == null || localPath.length() <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -908,8 +908,7 @@ public class FileContentProvider extends ContentProvider {
|
|||
// get accounts from AccountManager ; we can't be sure if accounts in it are updated or not although
|
||||
// we know the update was previously done in {link @FileActivity#onCreate} because the changes through
|
||||
// AccountManager are not synchronous
|
||||
Account[] accounts = AccountManager.get(getContext()).getAccountsByType(
|
||||
MainApp.getAccountType());
|
||||
Account[] accounts = AccountManager.get(getContext()).getAccountsByType(MainApp.getAccountType(mContext));
|
||||
String serverUrl;
|
||||
String username;
|
||||
String oldAccountName;
|
||||
|
|
|
@ -212,7 +212,7 @@ public class OperationsService extends Service {
|
|||
// Saving cookies
|
||||
try {
|
||||
OwnCloudClientManagerFactory.getDefaultSingleton().
|
||||
saveAllClients(this, MainApp.getAccountType());
|
||||
saveAllClients(this, MainApp.getAccountType(getApplicationContext()));
|
||||
|
||||
// TODO - get rid of these exceptions
|
||||
} catch (AccountNotFoundException | IOException | OperationCanceledException | AuthenticatorException e) {
|
||||
|
|
|
@ -136,7 +136,7 @@ public abstract class BaseActivity extends AppCompatActivity {
|
|||
*/
|
||||
protected void createAccount(boolean mandatoryCreation) {
|
||||
AccountManager am = AccountManager.get(getApplicationContext());
|
||||
am.addAccount(MainApp.getAccountType(),
|
||||
am.addAccount(MainApp.getAccountType(this),
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
|
|
|
@ -616,7 +616,7 @@ public abstract class DrawerActivity extends ToolbarActivity implements DisplayU
|
|||
* updates the account list in the drawer.
|
||||
*/
|
||||
public void updateAccountList() {
|
||||
Account[] accounts = AccountManager.get(this).getAccountsByType(MainApp.getAccountType());
|
||||
Account[] accounts = AccountManager.get(this).getAccountsByType(MainApp.getAccountType(this));
|
||||
|
||||
ArrayList<Account> persistingAccounts = new ArrayList<>();
|
||||
|
||||
|
@ -1281,7 +1281,7 @@ public abstract class DrawerActivity extends ToolbarActivity implements DisplayU
|
|||
*/
|
||||
private void populateDrawerOwnCloudAccounts() {
|
||||
mAvatars = new Account[3];
|
||||
Account[] accountsAll = AccountManager.get(this).getAccountsByType(MainApp.getAccountType());
|
||||
Account[] accountsAll = AccountManager.get(this).getAccountsByType(MainApp.getAccountType(this));
|
||||
|
||||
ArrayList<Account> persistingAccounts = new ArrayList<>();
|
||||
|
||||
|
|
|
@ -109,7 +109,7 @@ public class ManageAccountsActivity extends FileActivity
|
|||
setupToolbar();
|
||||
updateActionBarTitleAndHomeButtonByString(getResources().getString(R.string.prefs_manage_accounts));
|
||||
|
||||
Account[] accountList = AccountManager.get(this).getAccountsByType(MainApp.getAccountType());
|
||||
Account[] accountList = AccountManager.get(this).getAccountsByType(MainApp.getAccountType(this));
|
||||
mOriginalAccounts = DisplayUtils.toAccountNameSet(Arrays.asList(accountList));
|
||||
mOriginalCurrentAccount = AccountUtils.getCurrentOwnCloudAccount(this).name;
|
||||
|
||||
|
@ -182,7 +182,7 @@ public class ManageAccountsActivity extends FileActivity
|
|||
* @return true if account list has changed, false if not
|
||||
*/
|
||||
private boolean hasAccountListChanged() {
|
||||
Account[] accountList = AccountManager.get(this).getAccountsByType(MainApp.getAccountType());
|
||||
Account[] accountList = AccountManager.get(this).getAccountsByType(MainApp.getAccountType(this));
|
||||
|
||||
ArrayList<Account> newList = new ArrayList<>();
|
||||
for (Account account : accountList) {
|
||||
|
@ -233,7 +233,7 @@ public class ManageAccountsActivity extends FileActivity
|
|||
* @return list of account list items
|
||||
*/
|
||||
private ArrayList<AccountListItem> getAccountListItems() {
|
||||
Account[] accountList = AccountManager.get(this).getAccountsByType(MainApp.getAccountType());
|
||||
Account[] accountList = AccountManager.get(this).getAccountsByType(MainApp.getAccountType(this));
|
||||
ArrayList<AccountListItem> adapterAccountList = new ArrayList<>(accountList.length);
|
||||
for (Account account : accountList) {
|
||||
boolean pendingForRemoval = arbitraryDataProvider.getBooleanValue(account, PENDING_FOR_REMOVAL);
|
||||
|
@ -265,7 +265,7 @@ public class ManageAccountsActivity extends FileActivity
|
|||
@Override
|
||||
public void createAccount() {
|
||||
AccountManager am = AccountManager.get(getApplicationContext());
|
||||
am.addAccount(MainApp.getAccountType(),
|
||||
am.addAccount(MainApp.getAccountType(this),
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
|
@ -312,7 +312,7 @@ public class ManageAccountsActivity extends FileActivity
|
|||
public void run(AccountManagerFuture<Boolean> future) {
|
||||
if (future.isDone()) {
|
||||
// after remove account
|
||||
Account account = new Account(mAccountName, MainApp.getAccountType());
|
||||
Account account = new Account(mAccountName, MainApp.getAccountType(this));
|
||||
if (!AccountUtils.exists(account, MainApp.getAppContext())) {
|
||||
// Cancel transfers of the removed account
|
||||
if (mUploaderBinder != null) {
|
||||
|
@ -325,7 +325,7 @@ public class ManageAccountsActivity extends FileActivity
|
|||
|
||||
if (AccountUtils.getCurrentOwnCloudAccount(this) == null) {
|
||||
String accountName = "";
|
||||
Account[] accounts = AccountManager.get(this).getAccountsByType(MainApp.getAccountType());
|
||||
Account[] accounts = AccountManager.get(this).getAccountsByType(MainApp.getAccountType(this));
|
||||
if (accounts.length != 0) {
|
||||
accountName = accounts[0].name;
|
||||
}
|
||||
|
@ -419,7 +419,7 @@ public class ManageAccountsActivity extends FileActivity
|
|||
.schedule();
|
||||
|
||||
// immediately select a new account
|
||||
Account[] accounts = AccountManager.get(this).getAccountsByType(MainApp.getAccountType());
|
||||
Account[] accounts = AccountManager.get(this).getAccountsByType(MainApp.getAccountType(this));
|
||||
|
||||
String newAccountName = "";
|
||||
for (Account acc: accounts) {
|
||||
|
|
|
@ -196,7 +196,7 @@ public class ReceiveExternalFilesActivity extends FileActivity
|
|||
protected void setAccount(Account account, boolean savedAccount) {
|
||||
mAccountManager = (AccountManager) getSystemService(Context.ACCOUNT_SERVICE);
|
||||
|
||||
Account[] accounts = mAccountManager.getAccountsByType(MainApp.getAccountType());
|
||||
Account[] accounts = mAccountManager.getAccountsByType(MainApp.getAccountType(this));
|
||||
if (accounts.length == 0) {
|
||||
Log_OC.i(TAG, "No ownCloud account is available");
|
||||
DialogNoAccount dialog = new DialogNoAccount();
|
||||
|
@ -291,8 +291,7 @@ public class ReceiveExternalFilesActivity extends FileActivity
|
|||
final ReceiveExternalFilesActivity parent = (ReceiveExternalFilesActivity) getActivity();
|
||||
AlertDialog.Builder builder = new Builder(parent);
|
||||
|
||||
mTintedCheck = DrawableCompat.wrap(ContextCompat.getDrawable(parent,
|
||||
R.drawable.account_circle_white));
|
||||
mTintedCheck = DrawableCompat.wrap(ContextCompat.getDrawable(parent, R.drawable.account_circle_white));
|
||||
int tint = ThemeUtils.primaryColor(getContext());
|
||||
DrawableCompat.setTint(mTintedCheck, tint);
|
||||
|
||||
|
@ -301,7 +300,8 @@ public class ReceiveExternalFilesActivity extends FileActivity
|
|||
builder.setTitle(R.string.common_choose_account);
|
||||
builder.setAdapter(mAccountListAdapter, (dialog, which) -> {
|
||||
final ReceiveExternalFilesActivity parent1 = (ReceiveExternalFilesActivity) getActivity();
|
||||
parent1.setAccount(parent1.mAccountManager.getAccountsByType(MainApp.getAccountType())[which], false);
|
||||
parent1.setAccount(parent1.mAccountManager.getAccountsByType(
|
||||
MainApp.getAccountType(getActivity()))[which], false);
|
||||
parent1.onAccountSet(parent1.mAccountWasRestored);
|
||||
dialog.dismiss();
|
||||
});
|
||||
|
@ -315,7 +315,7 @@ public class ReceiveExternalFilesActivity extends FileActivity
|
|||
* @return list of account list items
|
||||
*/
|
||||
private ArrayList<AccountListItem> getAccountListItems(ReceiveExternalFilesActivity activity) {
|
||||
Account[] accountList = activity.mAccountManager.getAccountsByType(MainApp.getAccountType());
|
||||
Account[] accountList = activity.mAccountManager.getAccountsByType(MainApp.getAccountType(getActivity()));
|
||||
ArrayList<AccountListItem> adapterAccountList = new ArrayList<>(accountList.length);
|
||||
for (Account account : accountList) {
|
||||
adapterAccountList.add(new AccountListItem(account));
|
||||
|
@ -1019,7 +1019,7 @@ public class ReceiveExternalFilesActivity extends FileActivity
|
|||
}
|
||||
|
||||
private boolean isHaveMultipleAccount() {
|
||||
return mAccountManager.getAccountsByType(MainApp.getAccountType()).length > 1;
|
||||
return mAccountManager.getAccountsByType(MainApp.getAccountType(this)).length > 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -183,7 +183,7 @@ public class StorageMigration {
|
|||
mListener = listener;
|
||||
|
||||
mAuthority = mContext.getString(R.string.authority);
|
||||
mOcAccounts = AccountManager.get(mContext).getAccountsByType(MainApp.getAccountType());
|
||||
mOcAccounts = AccountManager.get(mContext).getAccountsByType(MainApp.getAccountType(context));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue