Search in sources :

Example 1 with Server

use of com.nextcloud.client.account.Server in project android by nextcloud.

the class ConnectivityServiceImpl method isInternetWalled.

@Override
public boolean isInternetWalled() {
    Connectivity c = getConnectivity();
    if (c.isConnected() && c.isWifi() && !c.isMetered()) {
        Server server = accountManager.getUser().getServer();
        String baseServerAddress = server.getUri().toString();
        if (baseServerAddress.isEmpty()) {
            return true;
        }
        GetMethod get = requestBuilder.invoke(baseServerAddress + "/index.php/204");
        PlainClient client = clientFactory.createPlainClient();
        int status = get.execute(client);
        // Content-Length is not available when using chunked transfer encoding, so check for -1 as well
        boolean result = !(status == HttpStatus.SC_NO_CONTENT && get.getResponseContentLength() <= 0);
        get.releaseConnection();
        return result;
    } else {
        return !c.isConnected();
    }
}
Also used : Server(com.nextcloud.client.account.Server) PlainClient(com.nextcloud.common.PlainClient) GetMethod(com.nextcloud.operations.GetMethod)

Example 2 with Server

use of com.nextcloud.client.account.Server in project android by nextcloud.

the class DialogFragmentIT method testAccountChooserDialogWithStatusDisabled.

@Test
@ScreenshotTest
public void testAccountChooserDialogWithStatusDisabled() throws AccountUtils.AccountNotFoundException {
    AccountManager accountManager = AccountManager.get(targetContext);
    for (Account account : accountManager.getAccounts()) {
        accountManager.removeAccountExplicitly(account);
    }
    Account newAccount = new Account("test@https://nextcloud.localhost", MainApp.getAccountType(targetContext));
    accountManager.addAccountExplicitly(newAccount, "password", null);
    accountManager.setUserData(newAccount, AccountUtils.Constants.KEY_OC_BASE_URL, SERVER_URL);
    accountManager.setUserData(newAccount, AccountUtils.Constants.KEY_USER_ID, "test");
    accountManager.setAuthToken(newAccount, AccountTypeUtils.getAuthTokenTypePass(newAccount.type), "password");
    FileDisplayActivity fda = getFileDisplayActivity();
    UserAccountManager userAccountManager = fda.getUserAccountManager();
    User newUser = userAccountManager.getUser(newAccount.name).get();
    FileDataStorageManager fileDataStorageManager = new FileDataStorageManager(newUser, targetContext.getContentResolver());
    OCCapability capability = new OCCapability();
    capability.setUserStatus(CapabilityBooleanType.FALSE);
    fileDataStorageManager.saveCapabilities(capability);
    ChooseAccountDialogFragment sut = ChooseAccountDialogFragment.newInstance(new RegisteredUser(newAccount, new OwnCloudAccount(newAccount, targetContext), new Server(URI.create(SERVER_URL), OwnCloudVersion.nextcloud_20)));
    showDialog(fda, sut);
}
Also used : UserAccountManager(com.nextcloud.client.account.UserAccountManager) Account(android.accounts.Account) OwnCloudAccount(com.owncloud.android.lib.common.OwnCloudAccount) FileDisplayActivity(com.owncloud.android.ui.activity.FileDisplayActivity) User(com.nextcloud.client.account.User) RegisteredUser(com.nextcloud.client.account.RegisteredUser) OCCapability(com.owncloud.android.lib.resources.status.OCCapability) Server(com.nextcloud.client.account.Server) FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager) ChooseAccountDialogFragment(com.nextcloud.ui.ChooseAccountDialogFragment) UserAccountManager(com.nextcloud.client.account.UserAccountManager) AccountManager(android.accounts.AccountManager) OwnCloudAccount(com.owncloud.android.lib.common.OwnCloudAccount) RegisteredUser(com.nextcloud.client.account.RegisteredUser) ScreenshotTest(com.owncloud.android.utils.ScreenshotTest) Test(org.junit.Test) ScreenshotTest(com.owncloud.android.utils.ScreenshotTest)

Example 3 with Server

use of com.nextcloud.client.account.Server in project android by nextcloud.

the class DialogFragmentIT method testAccountChooserDialog.

@Test
@ScreenshotTest
public void testAccountChooserDialog() throws AccountUtils.AccountNotFoundException {
    FileDisplayActivity activity = getFileDisplayActivity();
    UserAccountManager userAccountManager = activity.getUserAccountManager();
    AccountManager accountManager = AccountManager.get(targetContext);
    for (Account account : accountManager.getAccountsByType(MainApp.getAccountType(targetContext))) {
        accountManager.removeAccountExplicitly(account);
    }
    Account newAccount = new Account("test@https://nextcloud.localhost", MainApp.getAccountType(targetContext));
    accountManager.addAccountExplicitly(newAccount, "password", null);
    accountManager.setUserData(newAccount, AccountUtils.Constants.KEY_OC_BASE_URL, SERVER_URL);
    accountManager.setUserData(newAccount, AccountUtils.Constants.KEY_USER_ID, "test");
    accountManager.setAuthToken(newAccount, AccountTypeUtils.getAuthTokenTypePass(newAccount.type), "password");
    User newUser = userAccountManager.getUser(newAccount.name).orElseThrow(RuntimeException::new);
    Account newAccount2 = new Account("user1@nextcloud.localhost", MainApp.getAccountType(targetContext));
    accountManager.addAccountExplicitly(newAccount2, "password", null);
    accountManager.setUserData(newAccount2, AccountUtils.Constants.KEY_OC_BASE_URL, SERVER_URL);
    accountManager.setUserData(newAccount2, AccountUtils.Constants.KEY_USER_ID, "user1");
    accountManager.setUserData(newAccount2, AccountUtils.Constants.KEY_OC_VERSION, "20.0.0");
    accountManager.setAuthToken(newAccount2, AccountTypeUtils.getAuthTokenTypePass(newAccount.type), "password");
    FileDataStorageManager fileDataStorageManager = new FileDataStorageManager(newUser, targetContext.getContentResolver());
    OCCapability capability = new OCCapability();
    capability.setUserStatus(CapabilityBooleanType.TRUE);
    capability.setUserStatusSupportsEmoji(CapabilityBooleanType.TRUE);
    fileDataStorageManager.saveCapabilities(capability);
    ChooseAccountDialogFragment sut = ChooseAccountDialogFragment.newInstance(new RegisteredUser(newAccount, new OwnCloudAccount(newAccount, targetContext), new Server(URI.create(SERVER_URL), OwnCloudVersion.nextcloud_20)));
    showDialog(activity, sut);
    activity.runOnUiThread(() -> sut.setStatus(new Status(StatusType.DND, "Busy fixing 🐛…", "", -1), targetContext));
    waitForIdleSync();
    shortSleep();
    screenshot(sut, "dnd");
    activity.runOnUiThread(() -> sut.setStatus(new Status(StatusType.ONLINE, "", "", -1), targetContext));
    waitForIdleSync();
    shortSleep();
    screenshot(sut, "online");
    activity.runOnUiThread(() -> sut.setStatus(new Status(StatusType.ONLINE, "Let's have some fun", "🎉", -1), targetContext));
    waitForIdleSync();
    shortSleep();
    screenshot(sut, "fun");
    activity.runOnUiThread(() -> sut.setStatus(new Status(StatusType.OFFLINE, "", "", -1), targetContext));
    waitForIdleSync();
    shortSleep();
    screenshot(sut, "offline");
    activity.runOnUiThread(() -> sut.setStatus(new Status(StatusType.AWAY, "Vacation", "🌴", -1), targetContext));
    waitForIdleSync();
    shortSleep();
    screenshot(sut, "away");
}
Also used : Status(com.owncloud.android.lib.resources.users.Status) Account(android.accounts.Account) OwnCloudAccount(com.owncloud.android.lib.common.OwnCloudAccount) User(com.nextcloud.client.account.User) RegisteredUser(com.nextcloud.client.account.RegisteredUser) OCCapability(com.owncloud.android.lib.resources.status.OCCapability) Server(com.nextcloud.client.account.Server) ChooseAccountDialogFragment(com.nextcloud.ui.ChooseAccountDialogFragment) OwnCloudAccount(com.owncloud.android.lib.common.OwnCloudAccount) RegisteredUser(com.nextcloud.client.account.RegisteredUser) UserAccountManager(com.nextcloud.client.account.UserAccountManager) FileDisplayActivity(com.owncloud.android.ui.activity.FileDisplayActivity) FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager) UserAccountManager(com.nextcloud.client.account.UserAccountManager) AccountManager(android.accounts.AccountManager) ScreenshotTest(com.owncloud.android.utils.ScreenshotTest) Test(org.junit.Test) ScreenshotTest(com.owncloud.android.utils.ScreenshotTest)

Aggregations

Server (com.nextcloud.client.account.Server)3 Account (android.accounts.Account)2 AccountManager (android.accounts.AccountManager)2 RegisteredUser (com.nextcloud.client.account.RegisteredUser)2 User (com.nextcloud.client.account.User)2 UserAccountManager (com.nextcloud.client.account.UserAccountManager)2 ChooseAccountDialogFragment (com.nextcloud.ui.ChooseAccountDialogFragment)2 FileDataStorageManager (com.owncloud.android.datamodel.FileDataStorageManager)2 OwnCloudAccount (com.owncloud.android.lib.common.OwnCloudAccount)2 OCCapability (com.owncloud.android.lib.resources.status.OCCapability)2 FileDisplayActivity (com.owncloud.android.ui.activity.FileDisplayActivity)2 ScreenshotTest (com.owncloud.android.utils.ScreenshotTest)2 Test (org.junit.Test)2 PlainClient (com.nextcloud.common.PlainClient)1 GetMethod (com.nextcloud.operations.GetMethod)1 Status (com.owncloud.android.lib.resources.users.Status)1