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

Commit cb598c2c authored by David Luhmer's avatar David Luhmer
Browse files

Add support to check for min-version of nextcloud-files-app

parent 755b3b19
Loading
Loading
Loading
Loading
+12 −6
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@ import android.os.Bundle;
import android.support.annotation.RequiresApi;

import com.nextcloud.android.sso.exceptions.NextcloudFilesAppNotInstalledException;
import com.nextcloud.android.sso.exceptions.NextcloudFilesAppNotSupportedException;
import com.nextcloud.android.sso.helper.AsyncTaskHelper;
import com.nextcloud.android.sso.model.SingleSignOnAccount;

@@ -117,7 +118,7 @@ public class AccountImporter {
    }

    // Get the AuthToken (Password) for a selected account
    public static SingleSignOnAccount GetAuthToken(Context context, Account account) throws AuthenticatorException, OperationCanceledException, IOException {
    public static SingleSignOnAccount GetAuthToken(Context context, Account account) throws AuthenticatorException, OperationCanceledException, IOException, NextcloudFilesAppNotSupportedException {
        final AccountManager accMgr = AccountManager.get(context);
        Bundle options = new Bundle();
        accMgr.invalidateAuthToken(account.type, AUTH_TOKEN);
@@ -126,11 +127,16 @@ public class AccountImporter {

        // Synchronously access auth token
        Bundle future;

        try {
            if (context instanceof Activity) {
                future = accMgr.getAuthToken(account, AUTH_TOKEN, options, (Activity) context, null, null).getResult(); // Show activity
            } else {
                future = accMgr.getAuthToken(account, AUTH_TOKEN, options, true, null, null).getResult(); // Show notification instead
            }
        } catch (AuthenticatorException ex) {
            throw new NextcloudFilesAppNotSupportedException();
        }

        String auth_token = future.getString(AccountManager.KEY_AUTHTOKEN);
        String auth_account_type = future.getString(AccountManager.KEY_ACCOUNT_TYPE);
@@ -151,7 +157,7 @@ public class AccountImporter {
        ExecutorService executor = Executors.newSingleThreadExecutor();
        Callable<SingleSignOnAccount> callable = new Callable<SingleSignOnAccount>() {
            @Override
            public SingleSignOnAccount call() throws AuthenticatorException, OperationCanceledException, IOException {
            public SingleSignOnAccount call() throws NextcloudFilesAppNotSupportedException, AuthenticatorException, OperationCanceledException, IOException {
                return AccountImporter.GetAuthToken(context, account);

            }
+23 −0
Original line number Diff line number Diff line
package com.nextcloud.android.sso.exceptions;

/**
 *  Nextcloud SingleSignOn
 *
 *  @author David Luhmer
 *
 * 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 <http://www.gnu.org/licenses/>.
 */

public class NextcloudFilesAppNotSupportedException extends SSOException {
}
+3 −0
Original line number Diff line number Diff line
@@ -53,6 +53,9 @@ public class SSOException extends Exception {
        } else if(this instanceof NextcloudFilesAppAccountNotFoundException) {
            em.title   = context.getString(R.string.nextcloud_files_app_account_not_found_title);
            em.message = context.getString(R.string.nextcloud_files_app_account_not_found_message);
        } else if(this instanceof NextcloudFilesAppNotSupportedException) {
            em.title   = context.getString(R.string.nextcloud_files_app_not_supported_title);
            em.message = context.getString(R.string.nextcloud_files_app_not_supported_message);
        } else {
            em.title = "Unknown error";
            em.message = "Unknown error..";
+2 −1
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@ import java.io.IOException;

import com.nextcloud.android.sso.AccountImporter;
import com.nextcloud.android.sso.exceptions.CurrentAccountNotFoundException;
import com.nextcloud.android.sso.exceptions.NextcloudFilesAppNotSupportedException;
import com.nextcloud.android.sso.exceptions.NoCurrentAccountSelectedException;
import com.nextcloud.android.sso.model.SingleSignOnAccount;

@@ -53,7 +54,7 @@ public class SingleAccountHelper {
        return account;
    }

    public static SingleSignOnAccount GetCurrentSingleAccount(Context context) throws AuthenticatorException, OperationCanceledException, IOException, NoCurrentAccountSelectedException, CurrentAccountNotFoundException {
    public static SingleSignOnAccount GetCurrentSingleAccount(Context context) throws AuthenticatorException, OperationCanceledException, IOException, NoCurrentAccountSelectedException, CurrentAccountNotFoundException, NextcloudFilesAppNotSupportedException {
        return AccountImporter.GetAuthToken(context, GetCurrentAccount(context));
    }

+40 −0
Original line number Diff line number Diff line
package com.nextcloud.android.sso.helper;

import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.util.Log;

import com.nextcloud.android.sso.exceptions.NextcloudFilesAppNotInstalledException;
import com.nextcloud.android.sso.exceptions.NextcloudFilesAppNotSupportedException;
import com.nextcloud.android.sso.ui.UiExceptionManager;

public class VersionCheckHelper {

    public static boolean VerifyMinVersion(Activity activity, int minVersion) {
        try {
            int verCode = GetNextcloudFilesVersionCode(activity);

            if (verCode < minVersion) {
                UiExceptionManager.ShowDialogForException(activity, new NextcloudFilesAppNotSupportedException());
                return false;
            }
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
            UiExceptionManager.ShowDialogForException(activity, new NextcloudFilesAppNotInstalledException());
            return false;
        }

        return true;
    }

    public static int GetNextcloudFilesVersionCode(Activity activity) throws PackageManager.NameNotFoundException {
        PackageInfo pinfo;
        pinfo = activity.getPackageManager().getPackageInfo("com.nextcloud.client", 0);
        int verCode = pinfo.versionCode;
        Log.e("VersionCheckHelper", "Version Code: " + verCode);

        return verCode;
    }
}
Loading