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

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

Merge branch 'master' into packageRenaming

# Conflicts:
#	src/main/java/com/nextcloud/android/sso/AccountImporter.java
#	src/main/java/com/nextcloud/android/sso/aidl/ParcelFileDescriptorUtil.java
#	src/main/java/com/nextcloud/android/sso/api/NextcloudAPI.java
parents 9e6cd4c3 365434d2
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -49,4 +49,7 @@ dependencies {
    implementation 'io.reactivex.rxjava2:rxjava:2.1.4'

    implementation 'commons-io:commons-io:2.6'

    implementation 'com.squareup.retrofit2:retrofit:2.3.0'
    implementation 'com.squareup.okhttp3:okhttp:3.8.0'
}
+268 −0
Original line number Diff line number Diff line
package de.luhmer.owncloud.accountimporter.helper;

import android.support.annotation.Nullable;

import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;

import okio.Buffer;
import okio.BufferedSource;
import okio.ByteString;
import okio.Options;
import okio.Sink;
import okio.Timeout;

/**
 *  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 BufferedSourceSSO implements BufferedSource {

    private InputStream mInputStream;

    public BufferedSourceSSO(InputStream inputStream) {
        this.mInputStream = inputStream;
    }

    @Override
    public Buffer buffer() {
        throw new UnsupportedOperationException("Not implemented");
    }

    @Override
    public boolean exhausted() throws IOException {
        throw new UnsupportedOperationException("Not implemented");
    }

    @Override
    public void require(long byteCount) throws IOException {
        throw new UnsupportedOperationException("Not implemented");
    }

    @Override
    public boolean request(long byteCount) throws IOException {
        throw new UnsupportedOperationException("Not implemented");
    }

    @Override
    public byte readByte() throws IOException {
        throw new UnsupportedOperationException("Not implemented");
    }

    @Override
    public short readShort() throws IOException {
        throw new UnsupportedOperationException("Not implemented");
    }

    @Override
    public short readShortLe() throws IOException {
        throw new UnsupportedOperationException("Not implemented");
    }

    @Override
    public int readInt() throws IOException {
        throw new UnsupportedOperationException("Not implemented");
    }

    @Override
    public int readIntLe() throws IOException {
        throw new UnsupportedOperationException("Not implemented");
    }

    @Override
    public long readLong() throws IOException {
        throw new UnsupportedOperationException("Not implemented");
    }

    @Override
    public long readLongLe() throws IOException {
        throw new UnsupportedOperationException("Not implemented");
    }

    @Override
    public long readDecimalLong() throws IOException {
        throw new UnsupportedOperationException("Not implemented");
    }

    @Override
    public long readHexadecimalUnsignedLong() throws IOException {
        throw new UnsupportedOperationException("Not implemented");
    }

    @Override
    public void skip(long byteCount) throws IOException {
        throw new UnsupportedOperationException("Not implemented");
    }

    @Override
    public ByteString readByteString() throws IOException {
        throw new UnsupportedOperationException("Not implemented");
    }

    @Override
    public ByteString readByteString(long byteCount) throws IOException {
        throw new UnsupportedOperationException("Not implemented");
    }

    @Override
    public int select(Options options) throws IOException {
        throw new UnsupportedOperationException("Not implemented");
    }

    @Override
    public byte[] readByteArray() throws IOException {
        throw new UnsupportedOperationException("Not implemented");
    }

    @Override
    public byte[] readByteArray(long byteCount) throws IOException {
        throw new UnsupportedOperationException("Not implemented");
    }

    @Override
    public int read(byte[] sink) throws IOException {
        throw new UnsupportedOperationException("Not implemented");
    }

    @Override
    public void readFully(byte[] sink) throws IOException {
        throw new UnsupportedOperationException("Not implemented");
    }

    @Override
    public int read(byte[] sink, int offset, int byteCount) throws IOException {
        throw new UnsupportedOperationException("Not implemented");
    }

    @Override
    public void readFully(Buffer sink, long byteCount) throws IOException {
        throw new UnsupportedOperationException("Not implemented");
    }

    @Override
    public long readAll(Sink sink) throws IOException {
        throw new UnsupportedOperationException("Not implemented");
    }

    @Override
    public String readUtf8() throws IOException {
        throw new UnsupportedOperationException("Not implemented");
    }

    @Override
    public String readUtf8(long byteCount) throws IOException {
        throw new UnsupportedOperationException("Not implemented");
    }

    @Nullable
    @Override
    public String readUtf8Line() throws IOException {
        throw new UnsupportedOperationException("Not implemented");
    }

    @Override
    public String readUtf8LineStrict() throws IOException {
        throw new UnsupportedOperationException("Not implemented");
    }

    @Override
    public String readUtf8LineStrict(long limit) throws IOException {
        throw new UnsupportedOperationException("Not implemented");
    }

    @Override
    public int readUtf8CodePoint() throws IOException {
        throw new UnsupportedOperationException("Not implemented");
    }

    @Override
    public String readString(Charset charset) throws IOException {
        throw new UnsupportedOperationException("Not implemented");
    }

    @Override
    public String readString(long byteCount, Charset charset) throws IOException {
        throw new UnsupportedOperationException("Not implemented");
    }

    @Override
    public long indexOf(byte b) throws IOException {
        throw new UnsupportedOperationException("Not implemented");
    }

    @Override
    public long indexOf(byte b, long fromIndex) throws IOException {
        throw new UnsupportedOperationException("Not implemented");
    }

    @Override
    public long indexOf(byte b, long fromIndex, long toIndex) throws IOException {
        throw new UnsupportedOperationException("Not implemented");
    }

    @Override
    public long indexOf(ByteString bytes) throws IOException {
        throw new UnsupportedOperationException("Not implemented");
    }

    @Override
    public long indexOf(ByteString bytes, long fromIndex) throws IOException {
        throw new UnsupportedOperationException("Not implemented");
    }

    @Override
    public long indexOfElement(ByteString targetBytes) throws IOException {
        throw new UnsupportedOperationException("Not implemented");
    }

    @Override
    public long indexOfElement(ByteString targetBytes, long fromIndex) throws IOException {
        throw new UnsupportedOperationException("Not implemented");
    }

    @Override
    public boolean rangeEquals(long offset, ByteString bytes) throws IOException {
        throw new UnsupportedOperationException("Not implemented");
    }

    @Override
    public boolean rangeEquals(long offset, ByteString bytes, int bytesOffset, int byteCount) throws IOException {
        throw new UnsupportedOperationException("Not implemented");
    }

    @Override
    public InputStream inputStream() {
        return mInputStream;
    }

    @Override
    public long read(Buffer sink, long byteCount) throws IOException {
        throw new UnsupportedOperationException("Not implemented");
    }

    @Override
    public Timeout timeout() {
        throw new UnsupportedOperationException("Not implemented");
    }

    @Override
    public void close() throws IOException {
        throw new UnsupportedOperationException("Not implemented");
    }
}
+40 −0
Original line number Diff line number Diff line
package de.luhmer.owncloud.accountimporter.helper;

import java.io.InputStream;

import de.luhmer.owncloud.accountimporter.aidl.NextcloudRequest;
import de.luhmer.owncloud.accountimporter.api.NextcloudAPI;
import okhttp3.ResponseBody;

/**
 *  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 Okhttp3Helper {

    public static ResponseBody getResponseBodyFromRequest(NextcloudAPI nextcloudAPI, NextcloudRequest request) {
        try {
            InputStream os = nextcloudAPI.performNetworkRequest(request);
            return ResponseBody.create(null, 0, new BufferedSourceSSO(os));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseBody.create(null, "");
    }

}
+39 −0
Original line number Diff line number Diff line
package de.luhmer.owncloud.accountimporter.helper;

import de.luhmer.owncloud.accountimporter.aidl.NextcloudRequest;
import de.luhmer.owncloud.accountimporter.api.NextcloudAPI;
import io.reactivex.Completable;
import io.reactivex.functions.Action;

/**
 *  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 ReactivexHelper {

    public static Completable WrapInCompletable(final NextcloudAPI nextcloudAPI, final NextcloudRequest request) {
        return Completable.fromAction(new Action() {
            @Override
            public void run() throws Exception {
                nextcloudAPI.performRequest(Void.class, request);
            }
        });
    }

}
+130 −0
Original line number Diff line number Diff line
package de.luhmer.owncloud.accountimporter.helper;

import java.lang.reflect.Type;

import de.luhmer.owncloud.accountimporter.aidl.NextcloudRequest;
import de.luhmer.owncloud.accountimporter.api.NextcloudAPI;
import okhttp3.Request;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 *  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 Retrofit2Helper {

    public static <T> Call<T> WrapInCall(final NextcloudAPI nextcloudAPI, final NextcloudRequest nextcloudRequest, final Type resType) {
        return new Call<T>() {
            @Override
            public Response<T> execute() {
                try {
                    T body = nextcloudAPI.performRequest(resType, nextcloudRequest);
                    return Response.success(body);
                } catch (Exception e) {
                    return Response.error(520, ResponseBody.create(null, e.toString()));
                }
            }

            @Override
            public void enqueue(Callback<T> callback) {
                callback.onResponse(null, execute());
            }

            @Override
            public boolean isExecuted() {
                throw new UnsupportedOperationException("Not implemented");
            }

            @Override
            public void cancel() {
                throw new UnsupportedOperationException("Not implemented");
            }

            @Override
            public boolean isCanceled() {
                throw new UnsupportedOperationException("Not implemented");
            }

            @Override
            public Call<T> clone() {
                throw new UnsupportedOperationException("Not implemented");
            }

            @Override
            public Request request() {
                throw new UnsupportedOperationException("Not implemented");
            }
        };
    }


    /**
     *
     * @param success if true, a Response.success will be returned, otherwise Response.error(520)
     * @return
     */
    public static Call<Void> WrapVoidCall(final boolean success) {
        return new Call<Void>() {
            @Override
            public Response<Void> execute() {
                if(success) {
                    return Response.success(null);
                } else {
                    return Response.error(520, null);
                }
            }

            @Override
            public void enqueue(Callback callback) {
                if(success) {
                    callback.onResponse(null, Response.success(null));
                } else {
                    callback.onResponse(null, Response.error(520, null));
                }
            }

            @Override
            public boolean isExecuted() {
                return true;
            }

            @Override
            public void cancel() { }

            @Override
            public boolean isCanceled() {
                return false;
            }

            @Override
            public Call<Void> clone() {
                return null;
            }

            @Override
            public Request request() {
                throw new UnsupportedOperationException("Not implemented");
            }
        };

    }

}