Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ddd3c661 authored by Fahim Salam Chowdhury's avatar Fahim Salam Chowdhury 👽
Browse files

chore: merge 6287-Finalize_OIDC_support_for_murena_account into main

parents 1d4710d4 b38f4f1f
Loading
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -45,6 +45,10 @@ android {
        versionName "${versionMajor}.${versionMinor}.${versionPatch}"
        setProperty("archivesBaseName", "eDrive-$versionName")
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

        manifestPlaceholders = [
                'appAuthRedirectScheme':  applicationId,
        ]
    }

    signingConfigs {
@@ -94,7 +98,7 @@ android {
}

dependencies {
    implementation 'foundation.e:Nextcloud-Android-Library:1.0.6-release'
    implementation 'foundation.e:Nextcloud-Android-Library:1.0.7-u2.17-release'
    implementation "commons-httpclient:commons-httpclient:3.1@jar"
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    api 'androidx.annotation:annotation:1.6.0'
+3 −1
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ import foundation.e.drive.databinding.ActivityAccountsBinding;
import foundation.e.drive.utils.AccountUtils;
import foundation.e.drive.utils.CommonUtils;
import foundation.e.drive.utils.DavClientProvider;
import foundation.e.drive.utils.AccessTokenProvider;
import foundation.e.drive.widgets.EDriveWidget;
import timber.log.Timber;

@@ -78,6 +79,7 @@ public class AccountsActivity extends AppCompatActivity {
        final String totalQuota = accountManager.getUserData(account, ACCOUNT_DATA_TOTAL_QUOTA_KEY);
        final String email = accountManager.getUserData(account, ACCOUNT_DATA_EMAIL);
        String name = accountManager.getUserData(account, ACCOUNT_DATA_NAME);
        final String token = AccessTokenProvider.getToken(accountManager, account);

        // For some reason if we cant get name use email as name
        if (name == null || name.isEmpty()) {
@@ -139,7 +141,7 @@ public class AccountsActivity extends AppCompatActivity {
        binding.upgrade.setVisibility(View.VISIBLE);
        binding.upgrade.setOnClickListener(v -> {
            final Intent upgradeIntent = buildIntent(Intent.ACTION_VIEW,
                    String.format(EDriveWidget.WEBPAGE, email,
                    String.format(EDriveWidget.WEBPAGE, email, token,
                            dataForWeb(totalQuota)));
            startActivity(upgradeIntent);
        });
+52 −0
Original line number Diff line number Diff line
/*
 * Copyright MURENA SAS 2024
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

package foundation.e.drive.utils

import android.accounts.Account
import android.accounts.AccountManager
import com.owncloud.android.lib.common.accounts.AccountUtils
import net.openid.appauth.AuthState
import org.json.JSONException
import timber.log.Timber

object AccessTokenProvider {

    private const val PLACEHOLDER_TOKEN = "placeholder"

    @JvmStatic
    fun getToken(accountManager: AccountManager, account: Account?): String {
        getAuthState(accountManager, account)?.let { authState ->
            try {
                return AuthState.jsonDeserialize(authState).accessToken ?: PLACEHOLDER_TOKEN
            } catch (e: JSONException) {
                Timber.e(e)
            }
        }

        return PLACEHOLDER_TOKEN
    }

    private fun getAuthState(accountManager: AccountManager, account: Account?): String? {
        var authState: String? = null

        if (account != null) {
            authState = accountManager.getUserData(account, AccountUtils.Constants.KEY_AUTH_STATE)
        }

        return if (authState.isNullOrBlank()) null else authState
    }
}
+4 −2
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ import foundation.e.drive.R;
import foundation.e.drive.utils.AccountUtils;
import foundation.e.drive.utils.AppConstants;
import foundation.e.drive.utils.CommonUtils;
import foundation.e.drive.utils.AccessTokenProvider;
import timber.log.Timber;

/**
@@ -51,7 +52,7 @@ import timber.log.Timber;
public class EDriveWidget extends AppWidgetProvider {

    public static final String WEBPAGE =
            "https://murena.com/ecloud-subscriptions/?username=%s&token=placeholder&current-quota=%s&from=wp";
            "https://murena.com/ecloud-subscriptions/?username=%s&token=%s&current-quota=%s&from=wp";
    private static final String ADD_ACCOUNT_WEBPAGE = "https://murena.io/signup/e-email-invite";

    private static final String ACCOUNT_PROVIDER_EELO = "e.foundation.webdav.eelo";
@@ -211,6 +212,7 @@ public class EDriveWidget extends AppWidgetProvider {
        final String totalQuota = accountManager.getUserData(account, ACCOUNT_DATA_TOTAL_QUOTA_KEY);
        final String email = accountManager.getUserData(account, ACCOUNT_DATA_EMAIL);
        String name = accountManager.getUserData(account, ACCOUNT_DATA_NAME);
        final String token = AccessTokenProvider.getToken(accountManager, account);

        if (email == null || email.trim().isEmpty()) {
            noAccountView(context);
@@ -297,7 +299,7 @@ public class EDriveWidget extends AppWidgetProvider {
        views.setOnClickPendingIntent(R.id.settings, pendingIntentSettings);

        final PendingIntent pendingIntentUpgrade = PendingIntent.getActivity(context, 0,
                buildIntent(Intent.ACTION_VIEW, String.format(WEBPAGE, email,
                buildIntent(Intent.ACTION_VIEW, String.format(WEBPAGE, email, token,
                        dataForWeb(totalQuota))), PendingIntent.FLAG_IMMUTABLE);
        views.setOnClickPendingIntent(R.id.upgrade, pendingIntentUpgrade);
    }
+3 −1
Original line number Diff line number Diff line
@@ -30,6 +30,8 @@ import androidx.work.Configuration;
import androidx.work.testing.SynchronousExecutor;
import androidx.work.testing.WorkManagerTestInitHelper;

import okhttp3.CookieJar;

public abstract class TestUtils {
    public static final String TEST_LOCAL_ROOT_FOLDER_PATH = "/tmp/eDrive/test/"; //THis is where test file and folder for synchronisatio will be stored
    public static final String TEST_REMOTE_ROOT_FOLDER_PATH ="/eDrive-test/";
@@ -64,7 +66,7 @@ public abstract class TestUtils {

    public static NextcloudClient getNcClient(Context context) {
        final Uri serverUri = Uri.parse(TEST_SERVER_URI);
        return new NextcloudClient(serverUri, TEST_ACCOUNT_NAME, TEST_ACCOUNT_PASSWORD, context);
        return new NextcloudClient(serverUri, TEST_ACCOUNT_NAME, TEST_ACCOUNT_PASSWORD, context, CookieJar.NO_COOKIES);
    }

    /**
Loading