Compare commits
109
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
16afbeb3eb | ||
|
|
8b0a4ca09c | ||
|
|
d8ba6f3c3a | ||
|
|
1ccccb1ffe | ||
|
|
a0698feb96 | ||
|
|
c1ee0fbbb0 | ||
|
|
77af543b48 | ||
|
|
ec6b1aa37d | ||
|
|
ae256ad13a | ||
|
|
67e1cf39e9 | ||
|
|
98ebd9b8c8 | ||
|
|
dfca74b1e8 | ||
|
|
63f2d407a4 | ||
|
|
df18d6eccc | ||
|
|
eafa49c822 | ||
|
|
54c36092c2 | ||
|
|
10eb9d3920 | ||
|
|
0275b81c7b | ||
|
|
4170370f63 | ||
|
|
06039a9e01 | ||
|
|
d5fba307d7 | ||
|
|
caaf13d678 | ||
|
|
681be2bad5 | ||
|
|
37c974f871 | ||
|
|
bbd942c122 | ||
|
|
25704d19a6 | ||
|
|
cc21e815d8 | ||
|
|
ce4a4d3652 | ||
|
|
051345a647 | ||
|
|
c83356cd40 | ||
|
|
625810803f | ||
|
|
e329809802 | ||
|
|
2a64998555 | ||
|
|
79fdf11512 | ||
|
|
b9998c74f0 | ||
|
|
b26f5dc5d2 | ||
|
|
5ed69587e2 | ||
|
|
e765cc8306 | ||
|
|
6ae79355b5 | ||
|
|
b9bc9bc84b | ||
|
|
16836ad119 | ||
|
|
4577084517 | ||
|
|
d969bc816c | ||
|
|
506acd0bbb | ||
|
|
056dc6ece1 | ||
|
|
030d697d85 | ||
|
|
b607d8d176 | ||
|
|
a9027218f5 | ||
|
|
a09b983209 | ||
|
|
ea74122370 | ||
|
|
3da5db1646 | ||
|
|
8585208249 | ||
|
|
7358c3dd09 | ||
|
|
e9d4a31f18 | ||
|
|
322aee0454 | ||
|
|
e3c708c87f | ||
|
|
6a33b72654 | ||
|
|
537e896e57 | ||
|
|
c73ffe0e0c | ||
|
|
31c795faa5 | ||
|
|
cd5c360155 | ||
|
|
415afeb4e3 | ||
|
|
f077a7ef33 | ||
|
|
6978fd35d1 | ||
|
|
65dde41927 | ||
|
|
c1d4d3d484 | ||
|
|
e360ce456a | ||
|
|
96e79e71fb | ||
|
|
614982a642 | ||
|
|
0234e8097f | ||
|
|
57e7eee9ff | ||
|
|
97b924d545 | ||
|
|
e84be102ff | ||
|
|
e387edc696 | ||
|
|
dbef39c436 | ||
|
|
8133875769 | ||
|
|
f97b7e4ea1 | ||
|
|
ba89fcba8b | ||
|
|
7948876041 | ||
|
|
07a9e8c55f | ||
|
|
cdf3ec2680 | ||
|
|
767ca18e5e | ||
|
|
89684052b8 | ||
|
|
e08cb4dec4 | ||
|
|
da79ca4afa | ||
|
|
6eec0a3a1c | ||
|
|
12c86d721d | ||
|
|
f41bd34407 | ||
|
|
2eece7aa33 | ||
|
|
c2d18556c3 | ||
|
|
b2d099c39f | ||
|
|
fb2bd16d4b | ||
|
|
27970e77ed | ||
|
|
45cf8af64f | ||
|
|
0547a0974d | ||
|
|
b810a59167 | ||
|
|
9cd3b6cbae | ||
|
|
09dbb43d74 | ||
|
|
c102b9552a | ||
|
|
347c0edef2 | ||
|
|
ebc50d44b6 | ||
|
|
73e41885c6 | ||
|
|
b6593f783e | ||
|
|
b7712e7580 | ||
|
|
294d23bfb6 | ||
|
|
0435448727 | ||
|
|
68d8499049 | ||
|
|
f52eb08606 | ||
|
|
bdfabd70e9 |
No files matched your search
@@ -1,3 +1,12 @@
|
||||
## 3.2.4 (Sept, 04, 2018)
|
||||
fix push notification on gplay release
|
||||
|
||||
## 3.2.3 (Aug, 21, 2018)
|
||||
- Fix crash on Android Android 4.x
|
||||
|
||||
## 3.2.2 (Aug, 20, 2018)
|
||||
- New simple signup screen
|
||||
|
||||
## 3.2.1 (June, 11, 2018)
|
||||
- Enhanced file detail/sharing screen for mail-shares
|
||||
- Fix local sorting and file selection
|
||||
|
||||
+3
-3
@@ -57,7 +57,7 @@ repositories {
|
||||
|
||||
// semantic versioning for version code
|
||||
def versionMajor = 3
|
||||
def versionMinor = 3
|
||||
def versionMinor = 4
|
||||
def versionPatch = 0
|
||||
def versionBuild = 0 // 0-49=Alpha / 50-98=RC / 99=stable
|
||||
|
||||
@@ -129,8 +129,8 @@ android {
|
||||
versionDev {
|
||||
applicationId "com.nextcloud.android.beta"
|
||||
dimension "default"
|
||||
versionCode 20180903
|
||||
versionName "20180903"
|
||||
versionCode 20180907
|
||||
versionName "20180907"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewbox="0 0 16 16" width="16" height="16">
|
||||
<path
|
||||
d="m9.025 1.08c-3.95 0-6.535 3.447-6.364 6.72h-2.161l3.904 3.92 4.08-3.874h-2.147c-0.237-1.7 1.163-3.114 2.689-3.092 1.595 0.024 2.8 1.23 2.8 2.734 0.09 1.594-1.63 3.428-3.966 2.53 0 1.23 0.003 2.545 0 3.765 4.19 0.83 7.64-2.51 7.64-6.25 0-3.563-2.92-6.453-6.475-6.453z"/>
|
||||
<path style="fill:#757575"
|
||||
d="m9.025 1.08c-3.95 0-6.535 3.447-6.364 6.72h-2.161l3.904 3.92 4.08-3.874h-2.147c-0.237-1.7 1.163-3.114 2.689-3.092 1.595 0.024 2.8 1.23 2.8 2.734 0.09 1.594-1.63 3.428-3.966 2.53 0 1.23 0.003 2.545 0 3.765 4.19 0.83 7.64-2.51 7.64-6.25 0-3.563-2.92-6.453-6.475-6.453z"/>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 396 B After Width: | Height: | Size: 419 B |
@@ -21,14 +21,14 @@ lintValue=$?
|
||||
echo "Branch: $3"
|
||||
|
||||
if [ $3 = "master" ]; then
|
||||
echo "New findbugs result for master at: https://nextcloud.kaminsky.me/index.php/s/fYZa7NeBsnmFZQD"
|
||||
echo "New findbugs result for master at: https://www.kaminsky.me/nc-dev/client-findbugs/master.html"
|
||||
curl -u $4:$5 -X PUT https://nextcloud.kaminsky.me/remote.php/webdav/findbugs/master.html --upload-file build/reports/findbugs/findbugs.html
|
||||
|
||||
summary=$(sed -n "/<h1>Summary<\/h1>/,/<h1>Warnings<\/h1>/p" build/reports/findbugs/findbugs.html | head -n-1 | sed s'/<\/a>//'g | sed s'/<a.*>//'g | sed s'/Summary/FindBugs (master)/' | tr "\"" "\'" | tr -d "\r\n")
|
||||
curl -u $4:$5 -X PUT -d "$summary" https://nextcloud.kaminsky.me/remote.php/webdav/findbugs/findbugs.html
|
||||
|
||||
if [ $lintValue -ne 1 ]; then
|
||||
echo "New lint result for master at: https://nextcloud.kaminsky.me/index.php/s/tXwtChzyqMj6I8v"
|
||||
echo "New lint result for master at: https://www.kaminsky.me/nc-dev/client-lint/master.html"
|
||||
curl -u $4:$5 -X PUT https://nextcloud.kaminsky.me/remote.php/webdav/droneLogs/master.html --upload-file build/reports/lint/lint.html
|
||||
exit 0
|
||||
fi
|
||||
@@ -36,10 +36,10 @@ else
|
||||
if [ -e $6 ]; then
|
||||
6="master-"$(date +%F)
|
||||
fi
|
||||
echo "New lint results at https://nextcloud.kaminsky.me/index.php/s/tXwtChzyqMj6I8v ->" $6.html
|
||||
echo "New lint results at https://www.kaminsky.me/nc-dev/client-lint/$6.html"
|
||||
curl 2>/dev/null -u $4:$5 -X PUT https://nextcloud.kaminsky.me/remote.php/webdav/droneLogs/$6.html --upload-file build/reports/lint/lint.html
|
||||
|
||||
echo "New findbugs results at https://nextcloud.kaminsky.me/index.php/s/fYZa7NeBsnmFZQD ->" $6.html
|
||||
echo "New findbugs results at https://www.kaminsky.me/nc-dev/client-findbugs/$6.html"
|
||||
curl 2>/dev/null -u $4:$5 -X PUT https://nextcloud.kaminsky.me/remote.php/webdav/findbugs/$6.html --upload-file build/reports/findbugs/findbugs.html
|
||||
|
||||
# delete all old comments
|
||||
@@ -64,9 +64,9 @@ else
|
||||
lintWarningNew=$(echo $lintResultNew | grep "[0-9]* warning" -o | cut -f1 -d" ")
|
||||
lintErrorOld=$(grep "[0-9]* error" scripts/analysis/lint-results.txt -o | cut -f1 -d" ")
|
||||
lintWarningOld=$(grep "[0-9]* warning" scripts/analysis/lint-results.txt -o | cut -f1 -d" ")
|
||||
lintResult="<h1>Lint</h1><table width='500' cellpadding='5' cellspacing='2'><tr class='tablerow0'><td>Type</td><td>Master</td><td>PR</td></tr><tr class='tablerow1'><td>Warnings</td><td>"$lintWarningOld"</td><td>"$lintWarningNew"</td></tr><tr class='tablerow0'><td>Errors</td><td>"$lintErrorOld"</td><td>"$lintErrorNew"</td></tr></table>"
|
||||
findbugsResultNew=$(sed -n "/<h1>Summary<\/h1>/,/<h1>Warnings<\/h1>/p" build/reports/findbugs/findbugs.html |head -n-1 | sed s'/<\/a>//'g | sed s'/<a.*>//'g | sed s'/Summary/FindBugs (new)/' | tr "\"" "\'" | tr -d "\n")
|
||||
findbugsResultOld=$(curl 2>/dev/null https://nextcloud.kaminsky.me/index.php/s/YaHngKMM6ERmBeg/download | tr "\"" "\'" | tr -d "\r\n")
|
||||
lintResult="<h1>Lint</h1><table width='500' cellpadding='5' cellspacing='2'><tr class='tablerow0'><td>Type</td><td><a href='https://www.kaminsky.me/nc-dev/client-lint/master.html'>Master</a></td><td><a href='https://www.kaminsky.me/nc-dev/client-lint/"$6".html'>PR</a></td></tr><tr class='tablerow1'><td>Warnings</td><td>"$lintWarningOld"</td><td>"$lintWarningNew"</td></tr><tr class='tablerow0'><td>Errors</td><td>"$lintErrorOld"</td><td>"$lintErrorNew"</td></tr></table>"
|
||||
findbugsResultNew=$(sed -n "/<h1>Summary<\/h1>/,/<h1>Warnings<\/h1>/p" build/reports/findbugs/findbugs.html |head -n-1 | sed s'/<\/a>//'g | sed s'/<a.*>//'g | sed s"#Summary#<a href=\"https://www.kaminsky.me/nc-dev/client-findbugs/$6.html\">FindBugs</a> (new)#" | tr "\"" "\'" | tr -d "\n")
|
||||
findbugsResultOld=$(curl 2>/dev/null https://nextcloud.kaminsky.me/index.php/s/YaHngKMM6ERmBeg/download | tr "\"" "\'" | tr -d "\r\n" | sed s'#FindBugs#<a href=\"https://www.kaminsky.me/nc-dev/client-findbugs/master.html">FindBugs</a>#'| tr "\"" "\'" | tr -d "\n")
|
||||
curl -u $1:$2 -X POST https://api.github.com/repos/nextcloud/android/issues/$7/comments -d "{ \"body\" : \"$lintResult $findbugsResultNew $findbugsResultOld $checkLibraryMessage \" }"
|
||||
|
||||
if [ $checkLibrary -eq 1 ]; then
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
DO NOT TOUCH; GENERATED BY DRONE
|
||||
<span class="mdl-layout-title">Lint Report: 93 warnings</span>
|
||||
<span class="mdl-layout-title">Lint Report: 94 warnings</span>
|
||||
@@ -258,6 +258,19 @@ public class EncryptionTestIT {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSHA512() {
|
||||
// sent to 3rd party app in cleartext
|
||||
String token = "4ae5978bf5354cd284b539015d442141";
|
||||
String salt = EncryptionUtils.encodeBytesToBase64String(EncryptionUtils.randomBytes(EncryptionUtils.saltLength));
|
||||
|
||||
// stored in database
|
||||
String hashedToken = EncryptionUtils.generateSHA512(token, salt);
|
||||
|
||||
// check: use passed cleartext and salt to verify hashed token
|
||||
assertTrue(EncryptionUtils.verifySHA512(hashedToken, token));
|
||||
}
|
||||
|
||||
|
||||
// Helper
|
||||
private boolean compareJsonStrings(String expected, String actual) {
|
||||
@@ -362,4 +375,4 @@ public class EncryptionTestIT {
|
||||
|
||||
return temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -66,6 +66,7 @@
|
||||
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
|
||||
|
||||
|
||||
|
||||
<application
|
||||
android:name=".MainApp"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
@@ -295,6 +296,14 @@
|
||||
<activity android:name=".ui.activity.ManageSpaceActivity"
|
||||
android:label="@string/manage_space_title"
|
||||
android:theme="@style/Theme.ownCloud" />
|
||||
|
||||
|
||||
<service
|
||||
android:name=".services.AccountManagerService"
|
||||
android:enabled="true"
|
||||
android:exported="true" >
|
||||
</service>
|
||||
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
@@ -0,0 +1,25 @@
|
||||
/***
|
||||
Copyright (c) 2008-2011 CommonsWare, LLC
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
use this file except in compliance with the License. You may obtain a copy
|
||||
of the License at http://www.apache.org/licenses/LICENSE-2.0. Unless required
|
||||
by applicable law or agreed to in writing, software distributed under the
|
||||
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
|
||||
OF ANY KIND, either express or implied. See the License for the specific
|
||||
language governing permissions and limitations under the License.
|
||||
|
||||
From _The Busy Coder's Guide to Advanced Android Development_
|
||||
http://commonsware.com/AdvAndroid
|
||||
|
||||
|
||||
More information here: https://github.com/abeluck/android-streams-ipc
|
||||
*/
|
||||
|
||||
package com.nextcloud.android.sso.aidl;
|
||||
|
||||
// Declare the interface.
|
||||
interface IInputStreamService {
|
||||
|
||||
ParcelFileDescriptor performNextcloudRequest(in ParcelFileDescriptor input);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.nextcloud.android.sso;
|
||||
|
||||
public class Constants {
|
||||
|
||||
// Authenticator related constants
|
||||
public final static String SSO_USERNAME = "username";
|
||||
public final static String SSO_TOKEN = "token";
|
||||
public final static String SSO_SERVER_URL = "server_url";
|
||||
|
||||
// Custom Exceptions
|
||||
static final String EXCEPTION_INVALID_TOKEN = "CE_1";
|
||||
static final String EXCEPTION_ACCOUNT_NOT_FOUND = "CE_2";
|
||||
static final String EXCEPTION_UNSUPPORTED_METHOD = "CE_3";
|
||||
static final String EXCEPTION_INVALID_REQUEST_URL = "CE_4";
|
||||
static final String EXCEPTION_HTTP_REQUEST_FAILED = "CE_5";
|
||||
}
|
||||
@@ -0,0 +1,251 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*
|
||||
* More information here: https://github.com/abeluck/android-streams-ipc
|
||||
*/
|
||||
|
||||
package com.nextcloud.android.sso;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.accounts.AuthenticatorException;
|
||||
import android.accounts.OperationCanceledException;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Binder;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.util.Log;
|
||||
|
||||
import com.nextcloud.android.sso.aidl.IInputStreamService;
|
||||
import com.nextcloud.android.sso.aidl.NextcloudRequest;
|
||||
import com.nextcloud.android.sso.aidl.ParcelFileDescriptorUtil;
|
||||
import com.owncloud.android.authentication.AccountAuthenticator;
|
||||
import com.owncloud.android.authentication.AccountUtils;
|
||||
import com.owncloud.android.lib.common.OwnCloudAccount;
|
||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||
import com.owncloud.android.lib.common.OwnCloudClientManager;
|
||||
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
import com.owncloud.android.utils.EncryptionUtils;
|
||||
|
||||
import org.apache.commons.httpclient.HttpMethodBase;
|
||||
import org.apache.commons.httpclient.NameValuePair;
|
||||
import org.apache.commons.httpclient.methods.DeleteMethod;
|
||||
import org.apache.commons.httpclient.methods.GetMethod;
|
||||
import org.apache.commons.httpclient.methods.PostMethod;
|
||||
import org.apache.commons.httpclient.methods.PutMethod;
|
||||
import org.apache.commons.httpclient.methods.StringRequestEntity;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.Serializable;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.nextcloud.android.sso.Constants.EXCEPTION_ACCOUNT_NOT_FOUND;
|
||||
import static com.nextcloud.android.sso.Constants.EXCEPTION_HTTP_REQUEST_FAILED;
|
||||
import static com.nextcloud.android.sso.Constants.EXCEPTION_INVALID_REQUEST_URL;
|
||||
import static com.nextcloud.android.sso.Constants.EXCEPTION_INVALID_TOKEN;
|
||||
import static com.nextcloud.android.sso.Constants.EXCEPTION_UNSUPPORTED_METHOD;
|
||||
|
||||
|
||||
/**
|
||||
* Stream binder to pass usable InputStreams across the process boundary in Android.
|
||||
*/
|
||||
public class InputStreamBinder extends IInputStreamService.Stub {
|
||||
|
||||
private final static String TAG = "InputStreamBinder";
|
||||
private static final String CONTENT_TYPE_APPLICATION_JSON = "application/json";
|
||||
private static final String CHARSET_UTF8 = "UTF-8";
|
||||
|
||||
private static final int HTTP_STATUS_CODE_OK = 200;
|
||||
private static final int HTTP_STATUS_CODE_MULTIPLE_CHOICES = 300;
|
||||
|
||||
private static final char PATH_SEPARATOR = '/';
|
||||
private Context context;
|
||||
|
||||
public InputStreamBinder(Context context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
private NameValuePair[] convertMapToNVP(Map<String, String> map) {
|
||||
NameValuePair[] nvp = new NameValuePair[map.size()];
|
||||
int i = 0;
|
||||
for (String key : map.keySet()) {
|
||||
nvp[i] = new NameValuePair(key, map.get(key));
|
||||
i++;
|
||||
}
|
||||
return nvp;
|
||||
}
|
||||
|
||||
public ParcelFileDescriptor performNextcloudRequest(ParcelFileDescriptor input) {
|
||||
// read the input
|
||||
final InputStream is = new ParcelFileDescriptor.AutoCloseInputStream(input);
|
||||
|
||||
Exception exception = null;
|
||||
InputStream httpStream = new InputStream() {
|
||||
@Override
|
||||
public int read() {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
try {
|
||||
// Start request and catch exceptions
|
||||
NextcloudRequest request = deserializeObjectAndCloseStream(is);
|
||||
httpStream = processRequest(request);
|
||||
} catch (Exception e) {
|
||||
Log_OC.e(TAG, e.getMessage());
|
||||
exception = e;
|
||||
}
|
||||
|
||||
try {
|
||||
// Write exception to the stream followed by the actual network stream
|
||||
InputStream exceptionStream = serializeObjectToInputStream(exception);
|
||||
InputStream resultStream = new java.io.SequenceInputStream(exceptionStream, httpStream);
|
||||
return ParcelFileDescriptorUtil.pipeFrom(resultStream, thread -> Log.d(TAG, "Done sending result"));
|
||||
} catch (IOException e) {
|
||||
Log_OC.e(TAG, e.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private <T extends Serializable> ByteArrayInputStream serializeObjectToInputStream(T obj) throws IOException {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ObjectOutputStream oos = new ObjectOutputStream(baos);
|
||||
oos.writeObject(obj);
|
||||
oos.flush();
|
||||
oos.close();
|
||||
return new ByteArrayInputStream(baos.toByteArray());
|
||||
}
|
||||
|
||||
private <T extends Serializable> T deserializeObjectAndCloseStream(InputStream is) throws IOException, ClassNotFoundException {
|
||||
ObjectInputStream ois = new ObjectInputStream(is);
|
||||
T result = (T) ois.readObject();
|
||||
is.close();
|
||||
ois.close();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
private InputStream processRequest(final NextcloudRequest request) throws UnsupportedOperationException, com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException, OperationCanceledException, AuthenticatorException, IOException {
|
||||
Account account = AccountUtils.getOwnCloudAccountByName(context, request.getAccountName()); // TODO handle case that account is not found!
|
||||
if(account == null) {
|
||||
throw new IllegalStateException(EXCEPTION_ACCOUNT_NOT_FOUND);
|
||||
}
|
||||
|
||||
// Validate token
|
||||
if (!isValid(request)) {
|
||||
throw new IllegalStateException(EXCEPTION_INVALID_TOKEN);
|
||||
}
|
||||
|
||||
// Validate URL
|
||||
if(request.getUrl().length() == 0 || request.getUrl().charAt(0) != PATH_SEPARATOR) {
|
||||
throw new IllegalStateException(EXCEPTION_INVALID_REQUEST_URL, new IllegalStateException("URL need to start with a /"));
|
||||
}
|
||||
|
||||
OwnCloudClientManager ownCloudClientManager = OwnCloudClientManagerFactory.getDefaultSingleton();
|
||||
OwnCloudAccount ocAccount = new OwnCloudAccount(account, context);
|
||||
OwnCloudClient client = ownCloudClientManager.getClientFor(ocAccount, context);
|
||||
|
||||
String requestUrl = client.getBaseUri() + request.getUrl();
|
||||
HttpMethodBase method;
|
||||
|
||||
switch (request.getMethod()) {
|
||||
case "GET":
|
||||
method = new GetMethod(requestUrl);
|
||||
break;
|
||||
|
||||
case "POST":
|
||||
method = new PostMethod(requestUrl);
|
||||
if (request.getRequestBody() != null) {
|
||||
StringRequestEntity requestEntity = new StringRequestEntity(
|
||||
request.getRequestBody(),
|
||||
CONTENT_TYPE_APPLICATION_JSON,
|
||||
CHARSET_UTF8);
|
||||
((PostMethod) method).setRequestEntity(requestEntity);
|
||||
}
|
||||
break;
|
||||
|
||||
case "PUT":
|
||||
method = new PutMethod(requestUrl);
|
||||
if (request.getRequestBody() != null) {
|
||||
StringRequestEntity requestEntity = new StringRequestEntity(
|
||||
request.getRequestBody(),
|
||||
CONTENT_TYPE_APPLICATION_JSON,
|
||||
CHARSET_UTF8);
|
||||
((PutMethod) method).setRequestEntity(requestEntity);
|
||||
}
|
||||
break;
|
||||
|
||||
case "DELETE":
|
||||
method = new DeleteMethod(requestUrl);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new UnsupportedOperationException(EXCEPTION_UNSUPPORTED_METHOD);
|
||||
|
||||
}
|
||||
|
||||
method.setQueryString(convertMapToNVP(request.getParameter()));
|
||||
method.addRequestHeader("OCS-APIREQUEST", "true");
|
||||
|
||||
client.setFollowRedirects(request.isFollowRedirects());
|
||||
int status = client.executeMethod(method);
|
||||
|
||||
// Check if status code is 2xx --> https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#2xx_Success
|
||||
if (status >= HTTP_STATUS_CODE_OK && status < HTTP_STATUS_CODE_MULTIPLE_CHOICES) {
|
||||
return method.getResponseBodyAsStream();
|
||||
} else {
|
||||
throw new IllegalStateException(EXCEPTION_HTTP_REQUEST_FAILED, new IllegalStateException(String.valueOf(status)));
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isValid(NextcloudRequest request) {
|
||||
String callingPackageName = context.getPackageManager().getNameForUid(Binder.getCallingUid());
|
||||
|
||||
SharedPreferences sharedPreferences = context.getSharedPreferences(AccountAuthenticator.SSO_SHARED_PREFERENCE,
|
||||
Context.MODE_PRIVATE);
|
||||
String hash = sharedPreferences.getString(callingPackageName, "");
|
||||
return validateToken(hash, request.getToken());
|
||||
}
|
||||
|
||||
private boolean validateToken(String hash, String token) {
|
||||
String salt = hash.split("\\$")[1]; // TODO extract "$"
|
||||
|
||||
String newHash = EncryptionUtils.generateSHA512(token, salt);
|
||||
|
||||
// As discussed with Lukas R. at the Nextcloud Conf 2018, always compare whole strings
|
||||
// and don't exit prematurely if the string does not match anymore to prevent timing-attacks
|
||||
return isEqual(hash.getBytes(), newHash.getBytes());
|
||||
}
|
||||
|
||||
// Taken from http://codahale.com/a-lesson-in-timing-attacks/
|
||||
private static boolean isEqual(byte[] a, byte[] b) {
|
||||
if (a.length != b.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int result = 0;
|
||||
for (int i = 0; i < a.length; i++) {
|
||||
result |= a[i] ^ b[i];
|
||||
}
|
||||
return result == 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
package com.nextcloud.android.sso.aidl;
|
||||
|
||||
public interface IThreadListener {
|
||||
|
||||
void onThreadFinished(final Thread thread);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
package com.nextcloud.android.sso.aidl;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class NextcloudRequest implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 215521212534240L; //assign a long value
|
||||
|
||||
private String method;
|
||||
private Map<String, List<String>> header = new HashMap<>();
|
||||
private Map<String, String> parameter = new HashMap<>();
|
||||
private String requestBody;
|
||||
private String url;
|
||||
private String token;
|
||||
private String packageName;
|
||||
private String accountName;
|
||||
private boolean followRedirects;
|
||||
|
||||
private NextcloudRequest() { }
|
||||
|
||||
public static class Builder {
|
||||
private NextcloudRequest ncr;
|
||||
|
||||
public Builder() {
|
||||
ncr = new NextcloudRequest();
|
||||
}
|
||||
|
||||
public NextcloudRequest build() {
|
||||
return ncr;
|
||||
}
|
||||
|
||||
public Builder setMethod(String method) {
|
||||
ncr.method = method;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setHeader(Map<String, List<String>> header) {
|
||||
ncr.header = header;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setParameter(Map<String, String> parameter) {
|
||||
ncr.parameter = parameter;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setRequestBody(String requestBody) {
|
||||
ncr.requestBody = requestBody;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setUrl(String url) {
|
||||
ncr.url = url;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setToken(String token) {
|
||||
ncr.token = token;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setAccountName(String accountName) {
|
||||
ncr.accountName = accountName;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default value: true
|
||||
* @param followRedirects
|
||||
* @return
|
||||
*/
|
||||
public Builder setFollowRedirects(boolean followRedirects) {
|
||||
ncr.followRedirects = followRedirects;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
public String getMethod() {
|
||||
return this.method;
|
||||
}
|
||||
|
||||
public Map<String, List<String>> getHeader() {
|
||||
return this.header;
|
||||
}
|
||||
|
||||
public Map<String, String> getParameter() {
|
||||
return this.parameter;
|
||||
}
|
||||
|
||||
public String getRequestBody() {
|
||||
return this.requestBody;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return this.url;
|
||||
}
|
||||
|
||||
public String getToken() {
|
||||
return this.token;
|
||||
}
|
||||
|
||||
public void setToken(String token) {
|
||||
this.token = token;
|
||||
}
|
||||
|
||||
public String getPackageName() {
|
||||
return this.packageName;
|
||||
}
|
||||
|
||||
public void setPackageName(String packageName) {
|
||||
this.packageName = packageName;
|
||||
}
|
||||
|
||||
public String getAccountName() {
|
||||
return this.accountName;
|
||||
}
|
||||
|
||||
public void setAccountName(String accountName) {
|
||||
this.accountName = accountName;
|
||||
}
|
||||
|
||||
public boolean isFollowRedirects() {
|
||||
return this.followRedirects;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
package com.nextcloud.android.sso.aidl;
|
||||
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.util.Log;
|
||||
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
public final class ParcelFileDescriptorUtil {
|
||||
|
||||
private ParcelFileDescriptorUtil() { }
|
||||
|
||||
public static ParcelFileDescriptor pipeFrom(InputStream inputStream, IThreadListener listener)
|
||||
throws IOException {
|
||||
ParcelFileDescriptor[] pipe = ParcelFileDescriptor.createPipe();
|
||||
ParcelFileDescriptor readSide = pipe[0];
|
||||
ParcelFileDescriptor writeSide = pipe[1];
|
||||
|
||||
// start the transfer thread
|
||||
new TransferThread(inputStream, new ParcelFileDescriptor.AutoCloseOutputStream(writeSide),
|
||||
listener)
|
||||
.start();
|
||||
|
||||
return readSide;
|
||||
}
|
||||
|
||||
public static ParcelFileDescriptor pipeTo(OutputStream outputStream, IThreadListener listener)
|
||||
throws IOException {
|
||||
ParcelFileDescriptor[] pipe = ParcelFileDescriptor.createPipe();
|
||||
ParcelFileDescriptor readSide = pipe[0];
|
||||
ParcelFileDescriptor writeSide = pipe[1];
|
||||
|
||||
// start the transfer thread
|
||||
new TransferThread(new ParcelFileDescriptor.AutoCloseInputStream(readSide), outputStream,
|
||||
listener)
|
||||
.start();
|
||||
|
||||
return writeSide;
|
||||
}
|
||||
|
||||
public static class TransferThread extends Thread {
|
||||
private static final String TAG = TransferThread.class.getCanonicalName();
|
||||
private final InputStream mIn;
|
||||
private final OutputStream mOut;
|
||||
private final IThreadListener mListener;
|
||||
|
||||
TransferThread(InputStream in, OutputStream out, IThreadListener listener) {
|
||||
super("ParcelFileDescriptor Transfer Thread");
|
||||
mIn = in;
|
||||
mOut = out;
|
||||
mListener = listener;
|
||||
setDaemon(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
byte[] buf = new byte[1024];
|
||||
int len;
|
||||
|
||||
try {
|
||||
while ((len = mIn.read(buf)) > 0) {
|
||||
mOut.write(buf, 0, len);
|
||||
}
|
||||
mOut.flush(); // just to be safe
|
||||
} catch (IOException e) {
|
||||
Log.e("TransferThread", "writing failed");
|
||||
} finally {
|
||||
try {
|
||||
mIn.close();
|
||||
} catch (IOException e) {
|
||||
Log_OC.e(TAG, e.getMessage());
|
||||
}
|
||||
try {
|
||||
mOut.close();
|
||||
} catch (IOException e) {
|
||||
Log_OC.e(TAG, e.getMessage());
|
||||
}
|
||||
}
|
||||
if (mListener != null) {
|
||||
mListener.onThreadFinished(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -109,7 +109,7 @@ public class MainApp extends MultiDexApplication {
|
||||
|
||||
private static String storagePath;
|
||||
|
||||
private static boolean mOnlyOnDevice = false;
|
||||
private static boolean mOnlyOnDevice;
|
||||
|
||||
private SharedPreferences appPrefs;
|
||||
@SuppressWarnings("unused")
|
||||
@@ -154,7 +154,7 @@ public class MainApp extends MultiDexApplication {
|
||||
Log_OC.d("Debug", "start logging");
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 24) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
try {
|
||||
Method m = StrictMode.class.getMethod("disableDeathOnFileUriExposure");
|
||||
m.invoke(null);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/**
|
||||
/*
|
||||
* ownCloud Android client application
|
||||
*
|
||||
* @author David A. Velasco
|
||||
@@ -28,14 +28,21 @@ import android.accounts.AccountManager;
|
||||
import android.accounts.NetworkErrorException;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.nextcloud.android.sso.Constants;
|
||||
import com.owncloud.android.MainApp;
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.lib.common.OwnCloudAccount;
|
||||
import com.owncloud.android.lib.common.accounts.AccountTypeUtils;
|
||||
import com.owncloud.android.lib.common.accounts.AccountUtils;
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
import com.owncloud.android.utils.EncryptionUtils;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
|
||||
/**
|
||||
@@ -57,6 +64,9 @@ public class AccountAuthenticator extends AbstractAccountAuthenticator {
|
||||
public static final String KEY_REQUIRED_FEATURES = "requiredFeatures";
|
||||
public static final String KEY_LOGIN_OPTIONS = "loginOptions";
|
||||
public static final String KEY_ACCOUNT = "account";
|
||||
public static final String SSO_SHARED_PREFERENCE = "sso";
|
||||
|
||||
private static final String NEXTCLOUD_SSO = "NextcloudSSO";
|
||||
|
||||
private static final String TAG = AccountAuthenticator.class.getSimpleName();
|
||||
|
||||
@@ -75,16 +85,15 @@ public class AccountAuthenticator extends AbstractAccountAuthenticator {
|
||||
*/
|
||||
@Override
|
||||
public Bundle addAccount(AccountAuthenticatorResponse response,
|
||||
String accountType, String authTokenType,
|
||||
String[] requiredFeatures, Bundle options)
|
||||
throws NetworkErrorException {
|
||||
String accountType, String authTokenType,
|
||||
String[] requiredFeatures, Bundle options) {
|
||||
Log_OC.i(TAG, "Adding account with type " + accountType + " and auth token " + authTokenType);
|
||||
|
||||
final Bundle bundle = new Bundle();
|
||||
|
||||
|
||||
AccountManager accountManager = AccountManager.get(mContext);
|
||||
Account[] accounts = accountManager.getAccountsByType(MainApp.getAccountType(mContext));
|
||||
|
||||
|
||||
final Bundle bundle = new Bundle();
|
||||
|
||||
if (mContext.getResources().getBoolean(R.bool.multiaccount_support) || accounts.length < 1) {
|
||||
try {
|
||||
validateAccountType(accountType);
|
||||
@@ -104,16 +113,13 @@ public class AccountAuthenticator extends AbstractAccountAuthenticator {
|
||||
setIntentFlags(intent);
|
||||
|
||||
bundle.putParcelable(AccountManager.KEY_INTENT, intent);
|
||||
|
||||
} else {
|
||||
|
||||
// Return an error
|
||||
bundle.putInt(AccountManager.KEY_ERROR_CODE, AccountManager.ERROR_CODE_UNSUPPORTED_OPERATION);
|
||||
final String message = String.format(mContext.getString(R.string.auth_unsupported_multiaccount), mContext.getString(R.string.app_name));
|
||||
bundle.putString(AccountManager.KEY_ERROR_MESSAGE, message);
|
||||
|
||||
mHandler.post(() -> Toast.makeText(mContext, message, Toast.LENGTH_SHORT).show());
|
||||
|
||||
}
|
||||
|
||||
return bundle;
|
||||
@@ -124,7 +130,7 @@ public class AccountAuthenticator extends AbstractAccountAuthenticator {
|
||||
*/
|
||||
@Override
|
||||
public Bundle confirmCredentials(AccountAuthenticatorResponse response,
|
||||
Account account, Bundle options) throws NetworkErrorException {
|
||||
Account account, Bundle options) {
|
||||
try {
|
||||
validateAccountType(account.type);
|
||||
} catch (AuthenticatorException e) {
|
||||
@@ -155,9 +161,53 @@ public class AccountAuthenticator extends AbstractAccountAuthenticator {
|
||||
*/
|
||||
@Override
|
||||
public Bundle getAuthToken(AccountAuthenticatorResponse response,
|
||||
Account account, String authTokenType, Bundle options)
|
||||
throws NetworkErrorException {
|
||||
/// validate parameters
|
||||
Account account, String authTokenType, Bundle options) {
|
||||
|
||||
if (NEXTCLOUD_SSO.equals(authTokenType)) {
|
||||
final Bundle result = new Bundle();
|
||||
|
||||
String packageName = options.getString("androidPackageName");
|
||||
|
||||
if (packageName == null) {
|
||||
Log_OC.e(TAG, "No calling package, exit.");
|
||||
return result;
|
||||
}
|
||||
|
||||
// create token
|
||||
SharedPreferences sharedPreferences = mContext.getSharedPreferences(SSO_SHARED_PREFERENCE,
|
||||
Context.MODE_PRIVATE);
|
||||
String token = UUID.randomUUID().toString().replaceAll("-", "");
|
||||
|
||||
String hashedTokenWithSalt = EncryptionUtils.generateSHA512(token);
|
||||
|
||||
SharedPreferences.Editor editor = sharedPreferences.edit();
|
||||
editor.putString(packageName, hashedTokenWithSalt);
|
||||
editor.apply();
|
||||
|
||||
String serverUrl;
|
||||
String userId;
|
||||
try {
|
||||
OwnCloudAccount ocAccount = new OwnCloudAccount(account, mContext);
|
||||
serverUrl = ocAccount.getBaseUri().toString();
|
||||
AccountManager accountManager = AccountManager.get(mContext);
|
||||
userId = accountManager.getUserData(account,
|
||||
com.owncloud.android.lib.common.accounts.AccountUtils.Constants.KEY_USER_ID);
|
||||
} catch (AccountUtils.AccountNotFoundException e) {
|
||||
Log_OC.e(TAG, "Account not found");
|
||||
return new Bundle();
|
||||
}
|
||||
|
||||
result.putString(AccountManager.KEY_ACCOUNT_NAME, account.name);
|
||||
result.putString(AccountManager.KEY_ACCOUNT_TYPE, MainApp.getAccountType(mContext));
|
||||
result.putString(AccountManager.KEY_AUTHTOKEN, NEXTCLOUD_SSO);
|
||||
result.putString(Constants.SSO_USERNAME, userId);
|
||||
result.putString(Constants.SSO_TOKEN, token);
|
||||
result.putString(Constants.SSO_SERVER_URL, serverUrl);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// validate parameters
|
||||
try {
|
||||
validateAccountType(account.type);
|
||||
validateAuthTokenType(authTokenType);
|
||||
@@ -203,7 +253,7 @@ public class AccountAuthenticator extends AbstractAccountAuthenticator {
|
||||
|
||||
@Override
|
||||
public Bundle hasFeatures(AccountAuthenticatorResponse response,
|
||||
Account account, String[] features) throws NetworkErrorException {
|
||||
Account account, String[] features) {
|
||||
final Bundle result = new Bundle();
|
||||
result.putBoolean(AccountManager.KEY_BOOLEAN_RESULT, true);
|
||||
return result;
|
||||
@@ -211,8 +261,7 @@ public class AccountAuthenticator extends AbstractAccountAuthenticator {
|
||||
|
||||
@Override
|
||||
public Bundle updateCredentials(AccountAuthenticatorResponse response,
|
||||
Account account, String authTokenType, Bundle options)
|
||||
throws NetworkErrorException {
|
||||
Account account, String authTokenType, Bundle options) {
|
||||
|
||||
Intent intent = new Intent(mContext, AuthenticatorActivity.class);
|
||||
intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response);
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.owncloud.android.authentication;
|
||||
@@ -34,12 +33,14 @@ import com.owncloud.android.lib.common.accounts.AccountUtils.Constants;
|
||||
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
|
||||
import com.owncloud.android.ui.activity.ManageAccountsActivity;
|
||||
|
||||
|
||||
public class AccountUtils {
|
||||
/**
|
||||
* Helper class for dealing with accounts.
|
||||
*/
|
||||
public final class AccountUtils {
|
||||
private static final String PREF_SELECT_OC_ACCOUNT = "select_oc_account";
|
||||
|
||||
public static final int ACCOUNT_VERSION = 1;
|
||||
public static final int ACCOUNT_VERSION_WITH_PROPER_ID = 2;
|
||||
//public static final int ACCOUNT_VERSION_WITH_PROPER_ID = 2;
|
||||
public static final String ACCOUNT_USES_STANDARD_PASSWORD = "ACCOUNT_USES_STANDARD_PASSWORD";
|
||||
|
||||
private AccountUtils() {
|
||||
@@ -152,10 +153,8 @@ public class AccountUtils {
|
||||
public static boolean setCurrentOwnCloudAccount(final Context context, String accountName) {
|
||||
boolean result = false;
|
||||
if (accountName != null) {
|
||||
boolean found;
|
||||
for (final Account account : getAccounts(context)) {
|
||||
found = (account.name.equals(accountName));
|
||||
if (found) {
|
||||
if (accountName.equals(account.name)) {
|
||||
SharedPreferences.Editor appPrefs = PreferenceManager.getDefaultSharedPreferences(context).edit();
|
||||
appPrefs.putString(PREF_SELECT_OC_ACCOUNT, accountName);
|
||||
appPrefs.apply();
|
||||
|
||||
@@ -188,6 +188,8 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
|
||||
public static final String REGULAR_SERVER_INPUT_TYPE = "regular";
|
||||
public static final String SUBDOMAIN_SERVER_INPUT_TYPE = "prefix";
|
||||
public static final String DIRECTORY_SERVER_INPUT_TYPE = "suffix";
|
||||
public static final int NO_ICON = 0;
|
||||
public static final String EMPTY_STRING = "";
|
||||
|
||||
/// parameters from EXTRAs in starter Intent
|
||||
private byte mAction;
|
||||
@@ -196,8 +198,8 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
|
||||
|
||||
/// activity-level references / state
|
||||
private final Handler mHandler = new Handler();
|
||||
private ServiceConnection mOperationsServiceConnection = null;
|
||||
private OperationsServiceBinder mOperationsServiceBinder = null;
|
||||
private ServiceConnection mOperationsServiceConnection;
|
||||
private OperationsServiceBinder mOperationsServiceBinder;
|
||||
private AccountManager mAccountMgr;
|
||||
private Uri mNewCapturedUriFromOAuth2Redirection;
|
||||
|
||||
@@ -207,7 +209,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
|
||||
private TextView mServerStatusView;
|
||||
|
||||
private TextWatcher mHostUrlInputWatcher;
|
||||
private String mServerStatusText = "";
|
||||
private String mServerStatusText = EMPTY_STRING;
|
||||
private int mServerStatusIcon;
|
||||
|
||||
private boolean mServerIsChecked;
|
||||
@@ -227,10 +229,10 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
|
||||
|
||||
private WebView mLoginWebView;
|
||||
|
||||
private String mAuthStatusText = "";
|
||||
private String mAuthStatusText = EMPTY_STRING;
|
||||
private int mAuthStatusIcon;
|
||||
|
||||
private String mAuthToken = "";
|
||||
private String mAuthToken = EMPTY_STRING;
|
||||
private AuthenticatorAsyncTask mAsyncTask;
|
||||
|
||||
private boolean mIsFirstAuthAttempt;
|
||||
@@ -547,7 +549,6 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
|
||||
if (dataString.length() < prefix.length()) {
|
||||
throw new IllegalArgumentException("Invalid login URL detected");
|
||||
}
|
||||
LoginUrlInfo loginUrlInfo = new LoginUrlInfo();
|
||||
|
||||
// format is basically xxx://login/server:xxx&user:xxx&password while all variables are optional
|
||||
String data = dataString.substring(prefix.length());
|
||||
@@ -560,6 +561,8 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
|
||||
throw new IllegalArgumentException("Illegal number of login URL elements detected: " + values.length);
|
||||
}
|
||||
|
||||
LoginUrlInfo loginUrlInfo = new LoginUrlInfo();
|
||||
|
||||
for (String value : values) {
|
||||
if (value.startsWith("user" + LOGIN_URL_DATA_KEY_VALUE_SEPARATOR)) {
|
||||
loginUrlInfo.username = URLDecoder.decode(
|
||||
@@ -754,7 +757,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
|
||||
if (mAuthStatusIcon != 0) {
|
||||
Log_OC.d(TAG, "onTextChanged: hiding authentication status");
|
||||
mAuthStatusIcon = 0;
|
||||
mAuthStatusText = "";
|
||||
mAuthStatusText = EMPTY_STRING;
|
||||
showAuthStatus();
|
||||
}
|
||||
}
|
||||
@@ -815,7 +818,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
|
||||
mUsernameInput.setEnabled(false);
|
||||
mUsernameInput.setFocusable(false);
|
||||
}
|
||||
mPasswordInput.setText(""); // clean password to avoid social hacking
|
||||
mPasswordInput.setText(EMPTY_STRING); // clean password to avoid social hacking
|
||||
if (isPasswordExposed) {
|
||||
showPassword();
|
||||
}
|
||||
@@ -1179,7 +1182,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
|
||||
}
|
||||
|
||||
} else {
|
||||
mServerStatusText = "";
|
||||
mServerStatusText = EMPTY_STRING;
|
||||
mServerStatusIcon = 0;
|
||||
if (!webViewLoginMethod) {
|
||||
showServerStatus();
|
||||
@@ -1403,7 +1406,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
|
||||
if (!webViewLoginMethod && !mUsernameInput.getText().toString().trim().equals(username)) {
|
||||
// fail - not a new account, but an existing one; disallow
|
||||
result = new RemoteOperationResult(ResultCode.ACCOUNT_NOT_THE_SAME);
|
||||
mAuthToken = "";
|
||||
mAuthToken = EMPTY_STRING;
|
||||
updateAuthStatusIconAndText(result);
|
||||
showAuthStatus();
|
||||
Log_OC.d(TAG, result.getLogMessage());
|
||||
@@ -1622,7 +1625,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
|
||||
mServerStatusText = getResources().getString(R.string.untrusted_domain);
|
||||
break;
|
||||
default:
|
||||
mServerStatusText = "";
|
||||
mServerStatusText = EMPTY_STRING;
|
||||
mServerStatusIcon = 0;
|
||||
break;
|
||||
}
|
||||
@@ -1718,7 +1721,6 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Processes the result of the access check performed to try the user credentials.
|
||||
*
|
||||
@@ -1790,7 +1792,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
|
||||
updateServerStatusIconAndText(result);
|
||||
showServerStatus();
|
||||
mAuthStatusIcon = 0;
|
||||
mAuthStatusText = "";
|
||||
mAuthStatusText = EMPTY_STRING;
|
||||
if (!webViewLoginMethod) {
|
||||
showAuthStatus();
|
||||
|
||||
@@ -1823,7 +1825,6 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Updates the authentication token.
|
||||
*
|
||||
@@ -1873,7 +1874,6 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new account through the Account Authenticator that started this activity.
|
||||
*
|
||||
@@ -1922,7 +1922,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
|
||||
|
||||
if (isOAuth || isSaml) {
|
||||
// with external authorizations, the password is never input in the app
|
||||
mAccountMgr.addAccountExplicitly(mAccount, "", null);
|
||||
mAccountMgr.addAccountExplicitly(mAccount, EMPTY_STRING, null);
|
||||
} else {
|
||||
if (!webViewLoginMethod) {
|
||||
mAccountMgr.addAccountExplicitly(mAccount, mPasswordInput.getText().toString(), null);
|
||||
@@ -1983,12 +1983,13 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Updates the content and visibility state of the icon and text associated
|
||||
* to the last check on the ownCloud server.
|
||||
*/
|
||||
private void showServerStatus() {
|
||||
if (mServerStatusIcon == 0 && "".equals(mServerStatusText)) {
|
||||
if (mServerStatusIcon == NO_ICON && EMPTY_STRING.equals(mServerStatusText)) {
|
||||
mServerStatusView.setVisibility(View.INVISIBLE);
|
||||
} else {
|
||||
mServerStatusView.setText(mServerStatusText);
|
||||
@@ -1997,13 +1998,12 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Updates the content and visibility state of the icon and text associated
|
||||
* to the interactions with the OAuth authorization server.
|
||||
*/
|
||||
private void showAuthStatus() {
|
||||
if (mAuthStatusIcon == 0 && "".equals(mAuthStatusText)) {
|
||||
if (mAuthStatusIcon == NO_ICON && EMPTY_STRING.equals(mAuthStatusText)) {
|
||||
mAuthStatusView.setVisibility(View.INVISIBLE);
|
||||
} else {
|
||||
mAuthStatusView.setText(mAuthStatusText);
|
||||
@@ -2012,7 +2012,6 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void showRefreshButton(boolean show) {
|
||||
if (webViewLoginMethod && mRefreshButton != null) {
|
||||
if (show) {
|
||||
|
||||
@@ -53,10 +53,10 @@ public class PassCodeManager {
|
||||
private static final int PASS_CODE_TIMEOUT = 1000;
|
||||
// keeping a "low" positive value is the easiest way to prevent the pass code is requested on rotations
|
||||
|
||||
private static PassCodeManager passCodeManagerInstance = null;
|
||||
private static PassCodeManager passCodeManagerInstance;
|
||||
|
||||
private Long timestamp = 0L;
|
||||
private int visibleActivitiesCounter = 0;
|
||||
private int visibleActivitiesCounter;
|
||||
|
||||
public static PassCodeManager getPassCodeManager() {
|
||||
if (passCodeManagerInstance == null) {
|
||||
|
||||
@@ -44,7 +44,7 @@ import javax.annotation.Nullable;
|
||||
/**
|
||||
* Media queries to gain access to media lists for the device.
|
||||
*/
|
||||
public class MediaProvider {
|
||||
public final class MediaProvider {
|
||||
private static final String TAG = MediaProvider.class.getSimpleName();
|
||||
|
||||
// fixed query parameters
|
||||
@@ -58,6 +58,10 @@ public class MediaProvider {
|
||||
private static final String[] VIDEOS_FOLDER_PROJECTION = {"Distinct " + MediaStore.Video.Media.BUCKET_ID,
|
||||
MediaStore.Video.Media.BUCKET_DISPLAY_NAME};
|
||||
|
||||
private MediaProvider() {
|
||||
// utility class -> private constructor
|
||||
}
|
||||
|
||||
/**
|
||||
* Getting All Images Paths.
|
||||
*
|
||||
|
||||
@@ -466,8 +466,8 @@ public class OCFile implements Parcelable, Comparable<OCFile>, ServerFileInterfa
|
||||
Log_OC.d(TAG, "OCFile name changing from " + mRemotePath);
|
||||
if (name != null && name.length() > 0 && !name.contains(PATH_SEPARATOR) &&
|
||||
!mRemotePath.equals(ROOT_PATH)) {
|
||||
String parent = (new File(this.getRemotePath())).getParent();
|
||||
parent = (parent.endsWith(PATH_SEPARATOR)) ? parent : parent + PATH_SEPARATOR;
|
||||
String parent = new File(this.getRemotePath()).getParent();
|
||||
parent = parent.endsWith(PATH_SEPARATOR) ? parent : parent + PATH_SEPARATOR;
|
||||
mRemotePath = parent + name;
|
||||
if (isFolder()) {
|
||||
mRemotePath += PATH_SEPARATOR;
|
||||
|
||||
@@ -275,7 +275,7 @@ public class UploadsStorageManager extends Observable {
|
||||
return getUploads(null, null);
|
||||
}
|
||||
|
||||
private OCUpload[] getUploads(@Nullable String selection, @Nullable String[] selectionArgs) {
|
||||
private OCUpload[] getUploads(@Nullable String selection, @Nullable String... selectionArgs) {
|
||||
OCUpload[] list;
|
||||
|
||||
Cursor c = getDB().query(
|
||||
|
||||
@@ -353,7 +353,7 @@ public class OCUpload implements Parcelable {
|
||||
(getLastResult() == null ? "null" : getLastResult().getValue());
|
||||
} catch (NullPointerException e) {
|
||||
Log_OC.d(TAG, "Exception " + e.toString());
|
||||
return (e.toString());
|
||||
return e.toString();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -363,11 +363,9 @@ public class FileMenuFilter {
|
||||
OperationsServiceBinder opsBinder = mComponentsGetter.getOperationsServiceBinder();
|
||||
FileUploaderBinder uploaderBinder = mComponentsGetter.getFileUploaderBinder();
|
||||
FileDownloaderBinder downloaderBinder = mComponentsGetter.getFileDownloaderBinder();
|
||||
synchronizing = (
|
||||
anyFileSynchronizing(opsBinder) || // comparing local and remote
|
||||
synchronizing = anyFileSynchronizing(opsBinder) || // comparing local and remote
|
||||
anyFileDownloading(downloaderBinder) ||
|
||||
anyFileUploading(uploaderBinder)
|
||||
);
|
||||
anyFileUploading(uploaderBinder);
|
||||
}
|
||||
return synchronizing;
|
||||
}
|
||||
|
||||
@@ -399,11 +399,10 @@ public class FileUploader extends Service
|
||||
boolean isPowerSaving = PowerUtils.isPowerSaveMode(context);
|
||||
|
||||
for ( OCUpload failedUpload: failedUploads) {
|
||||
accountMatch = (account == null || account.name.equals(failedUpload.getAccountName()));
|
||||
resultMatch = ((uploadResult == null || uploadResult.equals(failedUpload.getLastResult())));
|
||||
accountMatch = account == null || account.name.equals(failedUpload.getAccountName());
|
||||
resultMatch = uploadResult == null || uploadResult.equals(failedUpload.getLastResult());
|
||||
if (accountMatch && resultMatch) {
|
||||
if (currentAccount == null ||
|
||||
!currentAccount.name.equals(failedUpload.getAccountName())) {
|
||||
if (currentAccount == null || !currentAccount.name.equals(failedUpload.getAccountName())) {
|
||||
currentAccount = failedUpload.getAccount(context);
|
||||
}
|
||||
|
||||
@@ -572,12 +571,6 @@ public class FileUploader extends Service
|
||||
mimeTypes = intent.getStringArrayExtra(KEY_MIME_TYPE);
|
||||
}
|
||||
|
||||
boolean forceOverwrite = intent.getBooleanExtra(KEY_FORCE_OVERWRITE, false);
|
||||
int localAction = intent.getIntExtra(KEY_LOCAL_BEHAVIOUR, LOCAL_BEHAVIOUR_FORGET);
|
||||
|
||||
boolean isCreateRemoteFolder = intent.getBooleanExtra(KEY_CREATE_REMOTE_FOLDER, false);
|
||||
int createdBy = intent.getIntExtra(KEY_CREATED_BY, UploadFileOperation.CREATED_BY_USER);
|
||||
|
||||
if (intent.hasExtra(KEY_FILE) && files == null) {
|
||||
Log_OC.e(TAG, "Incorrect array for OCFiles provided in upload intent");
|
||||
return Service.START_NOT_STICKY;
|
||||
@@ -612,6 +605,10 @@ public class FileUploader extends Service
|
||||
}
|
||||
// at this point variable "OCFile[] files" is loaded correctly.
|
||||
|
||||
boolean forceOverwrite = intent.getBooleanExtra(KEY_FORCE_OVERWRITE, false);
|
||||
int localAction = intent.getIntExtra(KEY_LOCAL_BEHAVIOUR, LOCAL_BEHAVIOUR_FORGET);
|
||||
boolean isCreateRemoteFolder = intent.getBooleanExtra(KEY_CREATE_REMOTE_FOLDER, false);
|
||||
int createdBy = intent.getIntExtra(KEY_CREATED_BY, UploadFileOperation.CREATED_BY_USER);
|
||||
String uploadKey;
|
||||
UploadFileOperation newUpload;
|
||||
try {
|
||||
@@ -1217,15 +1214,14 @@ public class FileUploader extends Service
|
||||
!uploadResult.getCode().equals(ResultCode.DELAYED_IN_POWER_SAVE_MODE) &&
|
||||
!uploadResult.getCode().equals(ResultCode.LOCK_FAILED) ) {
|
||||
|
||||
int tickerId = (uploadResult.isSuccess()) ? R.string.uploader_upload_succeeded_ticker :
|
||||
int tickerId = uploadResult.isSuccess() ? R.string.uploader_upload_succeeded_ticker :
|
||||
R.string.uploader_upload_failed_ticker;
|
||||
|
||||
String content;
|
||||
|
||||
// check credentials error
|
||||
boolean needsToUpdateCredentials = ResultCode.UNAUTHORIZED.equals(uploadResult.getCode());
|
||||
tickerId = (needsToUpdateCredentials) ?
|
||||
R.string.uploader_upload_failed_credentials_error : tickerId;
|
||||
tickerId = needsToUpdateCredentials ? R.string.uploader_upload_failed_credentials_error : tickerId;
|
||||
|
||||
mNotificationBuilder
|
||||
.setTicker(getString(tickerId))
|
||||
|
||||
@@ -47,6 +47,7 @@ import com.owncloud.android.operations.UploadFileOperation;
|
||||
import com.owncloud.android.ui.activity.Preferences;
|
||||
import com.owncloud.android.utils.FileStorageUtils;
|
||||
import com.owncloud.android.utils.FilesSyncHelper;
|
||||
import com.owncloud.android.utils.MimeType;
|
||||
import com.owncloud.android.utils.MimeTypeUtil;
|
||||
import com.owncloud.android.utils.PowerUtils;
|
||||
|
||||
@@ -65,7 +66,6 @@ import java.util.TimeZone;
|
||||
*/
|
||||
public class FilesSyncJob extends Job {
|
||||
public static final String TAG = "FilesSyncJob";
|
||||
|
||||
public static final String SKIP_CUSTOM = "skipCustom";
|
||||
public static final String OVERRIDE_POWER_SAVING = "overridePowerSaving";
|
||||
|
||||
@@ -73,8 +73,6 @@ public class FilesSyncJob extends Job {
|
||||
@Override
|
||||
protected Result onRunJob(@NonNull Params params) {
|
||||
final Context context = MainApp.getAppContext();
|
||||
final ContentResolver contentResolver = context.getContentResolver();
|
||||
FileUploader.UploadRequester requester = new FileUploader.UploadRequester();
|
||||
PowerManager.WakeLock wakeLock = null;
|
||||
|
||||
if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
|
||||
@@ -84,7 +82,6 @@ public class FilesSyncJob extends Job {
|
||||
}
|
||||
|
||||
PersistableBundleCompat bundle = params.getExtras();
|
||||
final boolean skipCustom = bundle.getBoolean(SKIP_CUSTOM, false);
|
||||
final boolean overridePowerSaving = bundle.getBoolean(OVERRIDE_POWER_SAVING, false);
|
||||
|
||||
// If we are in power save mode, better to postpone upload
|
||||
@@ -96,102 +93,24 @@ public class FilesSyncJob extends Job {
|
||||
Resources resources = MainApp.getAppContext().getResources();
|
||||
boolean lightVersion = resources.getBoolean(R.bool.syncedFolder_light);
|
||||
|
||||
final boolean skipCustom = bundle.getBoolean(SKIP_CUSTOM, false);
|
||||
FilesSyncHelper.restartJobsIfNeeded();
|
||||
FilesSyncHelper.insertAllDBEntries(skipCustom);
|
||||
|
||||
// Create all the providers we'll need
|
||||
final ContentResolver contentResolver = context.getContentResolver();
|
||||
final FilesystemDataProvider filesystemDataProvider = new FilesystemDataProvider(contentResolver);
|
||||
SyncedFolderProvider syncedFolderProvider = new SyncedFolderProvider(contentResolver);
|
||||
|
||||
Locale currentLocale = context.getResources().getConfiguration().locale;
|
||||
SimpleDateFormat sFormatter = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss", currentLocale);
|
||||
sFormatter.setTimeZone(TimeZone.getTimeZone(TimeZone.getDefault().getID()));
|
||||
FileUploader.UploadRequester requester = new FileUploader.UploadRequester();
|
||||
|
||||
for (SyncedFolder syncedFolder : syncedFolderProvider.getSyncedFolders()) {
|
||||
if ((syncedFolder.isEnabled()) && (!skipCustom || MediaFolderType.CUSTOM != syncedFolder.getType())) {
|
||||
for (String path : filesystemDataProvider.getFilesForUpload(syncedFolder.getLocalPath(),
|
||||
Long.toString(syncedFolder.getId()))) {
|
||||
File file = new File(path);
|
||||
|
||||
Long lastModificationTime = file.lastModified();
|
||||
final Locale currentLocale = context.getResources().getConfiguration().locale;
|
||||
|
||||
if (MediaFolderType.IMAGE == syncedFolder.getType()) {
|
||||
String mimeTypeString = FileStorageUtils.getMimeTypeFromName(file.getAbsolutePath());
|
||||
if ("image/jpeg".equalsIgnoreCase(mimeTypeString) || "image/tiff".
|
||||
equalsIgnoreCase(mimeTypeString)) {
|
||||
try {
|
||||
ExifInterface exifInterface = new ExifInterface(file.getAbsolutePath());
|
||||
String exifDate = exifInterface.getAttribute(ExifInterface.TAG_DATETIME);
|
||||
if (!TextUtils.isEmpty(exifDate)) {
|
||||
ParsePosition pos = new ParsePosition(0);
|
||||
SimpleDateFormat sFormatter = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss",
|
||||
currentLocale);
|
||||
sFormatter.setTimeZone(TimeZone.getTimeZone(TimeZone.getDefault().getID()));
|
||||
Date dateTime = sFormatter.parse(exifDate, pos);
|
||||
lastModificationTime = dateTime.getTime();
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
Log_OC.d(TAG, "Failed to get the proper time " + e.getLocalizedMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String mimeType = MimeTypeUtil.getBestMimeTypeByFilename(file.getAbsolutePath());
|
||||
|
||||
Account account = AccountUtils.getOwnCloudAccountByName(context, syncedFolder.getAccount());
|
||||
|
||||
String remotePath;
|
||||
boolean subfolderByDate;
|
||||
Integer uploadAction;
|
||||
boolean needsCharging;
|
||||
boolean needsWifi;
|
||||
|
||||
if (lightVersion) {
|
||||
ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(
|
||||
context.getContentResolver());
|
||||
|
||||
needsCharging = resources.getBoolean(R.bool.syncedFolder_light_on_charging);
|
||||
needsWifi = account == null || arbitraryDataProvider.getBooleanValue(account.name,
|
||||
Preferences.SYNCED_FOLDER_LIGHT_UPLOAD_ON_WIFI);
|
||||
String uploadActionString = resources.getString(R.string.syncedFolder_light_upload_behaviour);
|
||||
uploadAction = getUploadAction(uploadActionString);
|
||||
|
||||
subfolderByDate = resources.getBoolean(R.bool.syncedFolder_light_use_subfolders);
|
||||
|
||||
remotePath = resources.getString(R.string.syncedFolder_remote_folder);
|
||||
} else {
|
||||
needsCharging = syncedFolder.getChargingOnly();
|
||||
needsWifi = syncedFolder.getWifiOnly();
|
||||
uploadAction = syncedFolder.getUploadAction();
|
||||
subfolderByDate = syncedFolder.getSubfolderByDate();
|
||||
remotePath = syncedFolder.getRemotePath();
|
||||
}
|
||||
|
||||
if (!subfolderByDate) {
|
||||
String adaptedPath = file.getAbsolutePath()
|
||||
.replace(syncedFolder.getLocalPath(), "")
|
||||
.replace("/" + file.getName(), "");
|
||||
remotePath += adaptedPath;
|
||||
}
|
||||
|
||||
requester.uploadFileWithOverwrite(
|
||||
context,
|
||||
account,
|
||||
file.getAbsolutePath(),
|
||||
FileStorageUtils.getInstantUploadFilePath(
|
||||
currentLocale,
|
||||
remotePath, file.getName(),
|
||||
lastModificationTime, subfolderByDate),
|
||||
uploadAction,
|
||||
mimeType,
|
||||
true, // create parent folder if not existent
|
||||
UploadFileOperation.CREATED_AS_INSTANT_PICTURE,
|
||||
needsWifi,
|
||||
needsCharging,
|
||||
true
|
||||
);
|
||||
|
||||
filesystemDataProvider.updateFilesystemFileAsSentForUpload(path,
|
||||
Long.toString(syncedFolder.getId()));
|
||||
}
|
||||
syncFolder(context, resources, lightVersion, filesystemDataProvider, currentLocale, sFormatter,
|
||||
requester, syncedFolder);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -202,6 +121,97 @@ public class FilesSyncJob extends Job {
|
||||
return Result.SUCCESS;
|
||||
}
|
||||
|
||||
private void syncFolder(Context context, Resources resources, boolean lightVersion,
|
||||
FilesystemDataProvider filesystemDataProvider, Locale currentLocale,
|
||||
SimpleDateFormat sFormatter, FileUploader.UploadRequester requester,
|
||||
SyncedFolder syncedFolder) {
|
||||
String remotePath;
|
||||
boolean subfolderByDate;
|
||||
Integer uploadAction;
|
||||
boolean needsCharging;
|
||||
boolean needsWifi;
|
||||
Account account = AccountUtils.getOwnCloudAccountByName(context, syncedFolder.getAccount());
|
||||
|
||||
for (String path : filesystemDataProvider.getFilesForUpload(syncedFolder.getLocalPath(),
|
||||
Long.toString(syncedFolder.getId()))) {
|
||||
File file = new File(path);
|
||||
Long lastModificationTime = calculateLastModificationTime(file, syncedFolder, sFormatter);
|
||||
String mimeType = MimeTypeUtil.getBestMimeTypeByFilename(file.getAbsolutePath());
|
||||
|
||||
if (lightVersion) {
|
||||
ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(
|
||||
context.getContentResolver());
|
||||
|
||||
needsCharging = resources.getBoolean(R.bool.syncedFolder_light_on_charging);
|
||||
needsWifi = account == null || arbitraryDataProvider.getBooleanValue(account.name,
|
||||
Preferences.SYNCED_FOLDER_LIGHT_UPLOAD_ON_WIFI);
|
||||
String uploadActionString = resources.getString(R.string.syncedFolder_light_upload_behaviour);
|
||||
uploadAction = getUploadAction(uploadActionString);
|
||||
|
||||
subfolderByDate = resources.getBoolean(R.bool.syncedFolder_light_use_subfolders);
|
||||
|
||||
remotePath = resources.getString(R.string.syncedFolder_remote_folder);
|
||||
} else {
|
||||
needsCharging = syncedFolder.getChargingOnly();
|
||||
needsWifi = syncedFolder.getWifiOnly();
|
||||
uploadAction = syncedFolder.getUploadAction();
|
||||
subfolderByDate = syncedFolder.getSubfolderByDate();
|
||||
remotePath = syncedFolder.getRemotePath();
|
||||
}
|
||||
|
||||
if (!subfolderByDate) {
|
||||
String adaptedPath = file.getAbsolutePath()
|
||||
.replace(syncedFolder.getLocalPath(), "")
|
||||
.replace("/" + file.getName(), "");
|
||||
remotePath += adaptedPath;
|
||||
}
|
||||
|
||||
requester.uploadFileWithOverwrite(
|
||||
context,
|
||||
account,
|
||||
file.getAbsolutePath(),
|
||||
FileStorageUtils.getInstantUploadFilePath(
|
||||
currentLocale,
|
||||
remotePath, file.getName(),
|
||||
lastModificationTime, subfolderByDate),
|
||||
uploadAction,
|
||||
mimeType,
|
||||
true, // create parent folder if not existent
|
||||
UploadFileOperation.CREATED_AS_INSTANT_PICTURE,
|
||||
needsWifi,
|
||||
needsCharging,
|
||||
true
|
||||
);
|
||||
|
||||
filesystemDataProvider.updateFilesystemFileAsSentForUpload(path,
|
||||
Long.toString(syncedFolder.getId()));
|
||||
}
|
||||
}
|
||||
|
||||
private Long calculateLastModificationTime(File file, SyncedFolder syncedFolder, SimpleDateFormat formatter) {
|
||||
Long lastModificationTime = file.lastModified();
|
||||
|
||||
if (MediaFolderType.IMAGE == syncedFolder.getType()) {
|
||||
String mimeTypeString = FileStorageUtils.getMimeTypeFromName(file.getAbsolutePath());
|
||||
if (MimeType.JPEG.equalsIgnoreCase(mimeTypeString)
|
||||
|| MimeType.TIFF.equalsIgnoreCase(mimeTypeString)) {
|
||||
try {
|
||||
ExifInterface exifInterface = new ExifInterface(file.getAbsolutePath());
|
||||
String exifDate = exifInterface.getAttribute(ExifInterface.TAG_DATETIME);
|
||||
if (!TextUtils.isEmpty(exifDate)) {
|
||||
ParsePosition pos = new ParsePosition(0);
|
||||
Date dateTime = formatter.parse(exifDate, pos);
|
||||
lastModificationTime = dateTime.getTime();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log_OC.d(TAG, "Failed to get the proper time " + e.getLocalizedMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return lastModificationTime;
|
||||
}
|
||||
|
||||
private Integer getUploadAction(String action) {
|
||||
switch (action) {
|
||||
case "LOCAL_BEHAVIOUR_FORGET":
|
||||
|
||||
@@ -100,10 +100,10 @@ public class MediaService extends Service implements OnCompletionListener, OnPre
|
||||
private static final float DUCK_VOLUME = 0.1f;
|
||||
|
||||
/** Media player instance */
|
||||
private MediaPlayer mPlayer = null;
|
||||
private MediaPlayer mPlayer;
|
||||
|
||||
/** Reference to the system AudioManager */
|
||||
private AudioManager mAudioManager = null;
|
||||
private AudioManager mAudioManager;
|
||||
|
||||
|
||||
/** Values to indicate the state of the service */
|
||||
@@ -426,9 +426,9 @@ public class MediaService extends Service implements OnCompletionListener, OnPre
|
||||
private void tryToGetAudioFocus() {
|
||||
if (mAudioFocus != AudioFocus.FOCUS
|
||||
&& mAudioManager != null
|
||||
&& (AudioManager.AUDIOFOCUS_REQUEST_GRANTED == mAudioManager.requestAudioFocus(this,
|
||||
&& AudioManager.AUDIOFOCUS_REQUEST_GRANTED == mAudioManager.requestAudioFocus(this,
|
||||
AudioManager.STREAM_MUSIC,
|
||||
AudioManager.AUDIOFOCUS_GAIN))
|
||||
AudioManager.AUDIOFOCUS_GAIN)
|
||||
) {
|
||||
mAudioFocus = AudioFocus.FOCUS;
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ public class MediaServiceBinder extends Binder implements MediaController.MediaP
|
||||
@Override
|
||||
public boolean isPlaying() {
|
||||
MediaService.State currentState = mService.getState();
|
||||
return (currentState == State.PLAYING || (currentState == State.PREPARING && mService.mPlayOnPrepared));
|
||||
return currentState == State.PLAYING || (currentState == State.PREPARING && mService.mPlayOnPrepared);
|
||||
}
|
||||
|
||||
|
||||
@@ -169,15 +169,13 @@ public class MediaServiceBinder extends Binder implements MediaController.MediaP
|
||||
|
||||
public boolean isInPlaybackState() {
|
||||
MediaService.State currentState = mService.getState();
|
||||
return (currentState == MediaService.State.PLAYING || currentState == MediaService.State.PAUSED);
|
||||
return currentState == MediaService.State.PLAYING || currentState == MediaService.State.PAUSED;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getAudioSessionId() {
|
||||
return 1; // not really used
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* ownCloud Android client application
|
||||
/* ownCloud Android client application
|
||||
* Copyright (C) 2012-2014 ownCloud Inc.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
@@ -12,7 +12,6 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.owncloud.android.operations;
|
||||
@@ -36,10 +35,8 @@ public class CopyFileOperation extends SyncOperation {
|
||||
|
||||
private String mSrcPath;
|
||||
private String mTargetParentPath;
|
||||
|
||||
private OCFile mFile;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
@@ -63,8 +60,6 @@ public class CopyFileOperation extends SyncOperation {
|
||||
*/
|
||||
@Override
|
||||
protected RemoteOperationResult run(OwnCloudClient client) {
|
||||
RemoteOperationResult result;
|
||||
|
||||
/// 1. check copy validity
|
||||
if (mTargetParentPath.startsWith(mSrcPath)) {
|
||||
return new RemoteOperationResult(ResultCode.INVALID_COPY_INTO_DESCENDANT);
|
||||
@@ -84,7 +79,8 @@ public class CopyFileOperation extends SyncOperation {
|
||||
targetPath,
|
||||
false
|
||||
);
|
||||
result = operation.execute(client);
|
||||
|
||||
RemoteOperationResult result = operation.execute(client);
|
||||
|
||||
/// 3. local copy
|
||||
if (result.isSuccess()) {
|
||||
@@ -94,6 +90,4 @@ public class CopyFileOperation extends SyncOperation {
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -154,21 +154,21 @@ public class DownloadFileOperation extends RemoteOperation {
|
||||
|
||||
@Override
|
||||
protected RemoteOperationResult run(OwnCloudClient client) {
|
||||
RemoteOperationResult result;
|
||||
File newFile;
|
||||
boolean moved;
|
||||
|
||||
/// download will be performed to a temporal file, then moved to the final location
|
||||
File tmpFile = new File(getTmpPath());
|
||||
|
||||
String tmpFolder = getTmpFolder();
|
||||
|
||||
/// perform the download
|
||||
synchronized(mCancellationRequested) {
|
||||
if (mCancellationRequested.get()) {
|
||||
return new RemoteOperationResult(new OperationCancelledException());
|
||||
}
|
||||
}
|
||||
|
||||
RemoteOperationResult result;
|
||||
File newFile;
|
||||
boolean moved;
|
||||
|
||||
/// download will be performed to a temporal file, then moved to the final location
|
||||
File tmpFile = new File(getTmpPath());
|
||||
|
||||
String tmpFolder = getTmpFolder();
|
||||
|
||||
mDownloadOperation = new DownloadRemoteFileOperation(mFile.getRemotePath(), tmpFolder);
|
||||
Iterator<OnDatatransferProgressListener> listener = mDataTransferListeners.iterator();
|
||||
|
||||
@@ -49,7 +49,6 @@ public class GetServerInfoOperation extends RemoteOperation {
|
||||
|
||||
private String mUrl;
|
||||
private Context mContext;
|
||||
|
||||
private ServerInfo mResultData;
|
||||
|
||||
/**
|
||||
@@ -62,11 +61,9 @@ public class GetServerInfoOperation extends RemoteOperation {
|
||||
public GetServerInfoOperation(String url, Context context) {
|
||||
mUrl = trimWebdavSuffix(url);
|
||||
mContext = context;
|
||||
|
||||
mResultData = new ServerInfo();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Performs the operation
|
||||
*
|
||||
@@ -143,10 +140,10 @@ public class GetServerInfoOperation extends RemoteOperation {
|
||||
|
||||
|
||||
public static class ServerInfo {
|
||||
public OwnCloudVersion mVersion = null;
|
||||
public OwnCloudVersion mVersion;
|
||||
public String mBaseUrl = "";
|
||||
public AuthenticationMethod mAuthMethod = AuthenticationMethod.UNKNOWN;
|
||||
public boolean mIsSslConn = false;
|
||||
public boolean mIsSslConn;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
/**
|
||||
/*
|
||||
* ownCloud Android client application
|
||||
*
|
||||
* @author David A. Velasco
|
||||
@@ -15,7 +15,6 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.owncloud.android.operations;
|
||||
@@ -37,7 +36,6 @@ public class MoveFileOperation extends SyncOperation {
|
||||
|
||||
private String mSrcPath;
|
||||
private String mTargetParentPath;
|
||||
|
||||
private OCFile mFile;
|
||||
|
||||
/**
|
||||
@@ -63,8 +61,6 @@ public class MoveFileOperation extends SyncOperation {
|
||||
*/
|
||||
@Override
|
||||
protected RemoteOperationResult run(OwnCloudClient client) {
|
||||
RemoteOperationResult result;
|
||||
|
||||
/// 1. check move validity
|
||||
if (mTargetParentPath.startsWith(mSrcPath)) {
|
||||
return new RemoteOperationResult(ResultCode.INVALID_MOVE_INTO_DESCENDANT);
|
||||
@@ -84,7 +80,7 @@ public class MoveFileOperation extends SyncOperation {
|
||||
targetPath,
|
||||
false
|
||||
);
|
||||
result = operation.execute(client);
|
||||
RemoteOperationResult result = operation.execute(client);
|
||||
|
||||
/// 3. local move
|
||||
if (result.isSuccess()) {
|
||||
|
||||
@@ -82,8 +82,7 @@ public class RenameFileOperation extends SyncOperation {
|
||||
return new RemoteOperationResult(ResultCode.INVALID_LOCAL_FILE_NAME);
|
||||
}
|
||||
String parent = (new File(mFile.getRemotePath())).getParent();
|
||||
parent = (parent.endsWith(OCFile.PATH_SEPARATOR)) ? parent : parent +
|
||||
OCFile.PATH_SEPARATOR;
|
||||
parent = parent.endsWith(OCFile.PATH_SEPARATOR) ? parent : parent + OCFile.PATH_SEPARATOR;
|
||||
mNewRemotePath = parent + mNewName;
|
||||
if (mFile.isFolder()) {
|
||||
mNewRemotePath += OCFile.PATH_SEPARATOR;
|
||||
|
||||
@@ -50,8 +50,7 @@ public class SynchronizeFileOperation extends SyncOperation {
|
||||
private Account mAccount;
|
||||
private boolean mSyncFileContents;
|
||||
private Context mContext;
|
||||
|
||||
private boolean mTransferWasRequested = false;
|
||||
private boolean mTransferWasRequested;
|
||||
|
||||
/**
|
||||
* When 'false', uploads to the server are not done; only downloads or conflict detection.
|
||||
|
||||
@@ -172,7 +172,6 @@ public class SynchronizeFolderOperation extends SyncOperation {
|
||||
Log_OC.d(TAG, "Checking changes in " + mAccount.name + mRemotePath);
|
||||
|
||||
mRemoteFolderChanged = true;
|
||||
RemoteOperationResult result;
|
||||
|
||||
if (mCancellationRequested.get()) {
|
||||
throw new OperationCancelledException();
|
||||
@@ -180,7 +179,7 @@ public class SynchronizeFolderOperation extends SyncOperation {
|
||||
|
||||
// remote request
|
||||
ReadRemoteFileOperation operation = new ReadRemoteFileOperation(mRemotePath);
|
||||
result = operation.execute(client);
|
||||
RemoteOperationResult result = operation.execute(client);
|
||||
if (result.isSuccess()) {
|
||||
OCFile remoteFolder = FileStorageUtils.fillOCFile((RemoteFile) result.getData().get(0));
|
||||
|
||||
@@ -261,8 +260,6 @@ public class SynchronizeFolderOperation extends SyncOperation {
|
||||
* @param folderAndFiles Remote folder and children files in Folder
|
||||
*/
|
||||
private void synchronizeData(List<Object> folderAndFiles) throws OperationCancelledException {
|
||||
FileDataStorageManager storageManager = getStorageManager();
|
||||
|
||||
// parse data from remote folder
|
||||
OCFile remoteFolder = FileStorageUtils.fillOCFile((RemoteFile) folderAndFiles.get(0));
|
||||
remoteFolder.setParentId(mLocalFolder.getParentId());
|
||||
@@ -271,7 +268,6 @@ public class SynchronizeFolderOperation extends SyncOperation {
|
||||
Log_OC.d(TAG, "Remote folder " + mLocalFolder.getRemotePath()
|
||||
+ " changed - starting update of local data ");
|
||||
|
||||
List<OCFile> updatedFiles = new Vector<>(folderAndFiles.size() - 1);
|
||||
mFilesForDirectDownload.clear();
|
||||
mFilesToSyncContents.clear();
|
||||
|
||||
@@ -279,6 +275,9 @@ public class SynchronizeFolderOperation extends SyncOperation {
|
||||
throw new OperationCancelledException();
|
||||
}
|
||||
|
||||
FileDataStorageManager storageManager = getStorageManager();
|
||||
List<OCFile> updatedFiles = new Vector<>(folderAndFiles.size() - 1);
|
||||
|
||||
// get current data about local contents of the folder to synchronize
|
||||
List<OCFile> localFiles = storageManager.getFolderContent(mLocalFolder, false);
|
||||
Map<String, OCFile> localFilesMap = new HashMap<>(localFiles.size());
|
||||
|
||||
@@ -48,14 +48,10 @@ public class UpdateShareViaLinkOperation extends SyncOperation {
|
||||
* @param path Full path of the file/folder being shared. Mandatory argument
|
||||
*/
|
||||
public UpdateShareViaLinkOperation(String path) {
|
||||
|
||||
mPath = path;
|
||||
mPassword = null;
|
||||
mExpirationDateInMillis = 0;
|
||||
mPublicUpload = null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set password to update in public link.
|
||||
*
|
||||
@@ -67,7 +63,6 @@ public class UpdateShareViaLinkOperation extends SyncOperation {
|
||||
mPassword = password;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set expiration date to update in Share resource.
|
||||
*
|
||||
@@ -90,7 +85,6 @@ public class UpdateShareViaLinkOperation extends SyncOperation {
|
||||
mPublicUpload = publicUpload;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected RemoteOperationResult run(OwnCloudClient client) {
|
||||
|
||||
@@ -157,6 +151,5 @@ public class UpdateShareViaLinkOperation extends SyncOperation {
|
||||
getStorageManager().saveFile(file);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ public class UploadFileOperation extends SyncOperation {
|
||||
/**
|
||||
* Local path to file which is to be uploaded (before any possible renaming or moving).
|
||||
*/
|
||||
private String mOriginalStoragePath = null;
|
||||
private String mOriginalStoragePath;
|
||||
private Set<OnDatatransferProgressListener> mDataTransferListeners = new HashSet<>();
|
||||
private OnRenameListener mRenameUploadListener;
|
||||
|
||||
@@ -138,7 +138,7 @@ public class UploadFileOperation extends SyncOperation {
|
||||
|
||||
private UploadRemoteFileOperation mUploadOperation;
|
||||
|
||||
protected RequestEntity mEntity = null;
|
||||
protected RequestEntity mEntity;
|
||||
|
||||
private Account mAccount;
|
||||
private OCUpload mUpload;
|
||||
|
||||
@@ -92,12 +92,11 @@ public class FileContentProvider extends ContentProvider {
|
||||
|
||||
@Override
|
||||
public int delete(@NonNull Uri uri, String where, String[] whereArgs) {
|
||||
int count;
|
||||
|
||||
if (isCallerNotAllowed()) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int count;
|
||||
SQLiteDatabase db = mDbHelper.getWritableDatabase();
|
||||
db.beginTransaction();
|
||||
try {
|
||||
@@ -110,95 +109,20 @@ public class FileContentProvider extends ContentProvider {
|
||||
return count;
|
||||
}
|
||||
|
||||
private int delete(SQLiteDatabase db, Uri uri, String where, String[] whereArgs) {
|
||||
private int delete(SQLiteDatabase db, Uri uri, String where, String... whereArgs) {
|
||||
if (isCallerNotAllowed()) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int count = 0;
|
||||
int count;
|
||||
switch (mUriMatcher.match(uri)) {
|
||||
case SINGLE_FILE:
|
||||
Cursor c = query(db, uri, null, where, whereArgs, null);
|
||||
String remoteId = "";
|
||||
try {
|
||||
if (c != null && c.moveToFirst()) {
|
||||
remoteId = c.getString(c.getColumnIndex(ProviderTableMeta.FILE_REMOTE_ID));
|
||||
//ThumbnailsCacheManager.removeFileFromCache(remoteId);
|
||||
}
|
||||
Log_OC.d(TAG, "Removing FILE " + remoteId);
|
||||
|
||||
count = db.delete(ProviderTableMeta.FILE_TABLE_NAME,
|
||||
ProviderTableMeta._ID
|
||||
+ "="
|
||||
+ uri.getPathSegments().get(1)
|
||||
+ (!TextUtils.isEmpty(where) ? " AND (" + where + ")" : ""),
|
||||
whereArgs);
|
||||
} catch (Exception e) {
|
||||
Log_OC.d(TAG, "DB-Error removing file!", e);
|
||||
} finally {
|
||||
if (c != null) {
|
||||
c.close();
|
||||
}
|
||||
}
|
||||
count = deleteSingleFile(db, uri, where, whereArgs);
|
||||
break;
|
||||
case DIRECTORY:
|
||||
// deletion of folder is recursive
|
||||
/*
|
||||
Uri folderUri = ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_FILE, Long.parseLong(uri.getPathSegments().get(1)));
|
||||
Cursor folder = query(db, folderUri, null, null, null, null);
|
||||
String folderName = "(unknown)";
|
||||
if (folder != null && folder.moveToFirst()) {
|
||||
folderName = folder.getString(folder.getColumnIndex(ProviderTableMeta.FILE_PATH));
|
||||
}
|
||||
*/
|
||||
Cursor children = query(uri, null, null, null, null);
|
||||
if (children != null) {
|
||||
if (children.moveToFirst()) {
|
||||
long childId;
|
||||
boolean isDir;
|
||||
while (!children.isAfterLast()) {
|
||||
childId = children.getLong(children.getColumnIndex(ProviderTableMeta._ID));
|
||||
isDir = MimeType.DIRECTORY.equals(children.getString(
|
||||
children.getColumnIndex(ProviderTableMeta.FILE_CONTENT_TYPE)
|
||||
));
|
||||
//remotePath = children.getString(children.getColumnIndex(ProviderTableMeta.FILE_PATH));
|
||||
if (isDir) {
|
||||
count += delete(
|
||||
db,
|
||||
ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_DIR, childId),
|
||||
null,
|
||||
null
|
||||
);
|
||||
} else {
|
||||
count += delete(
|
||||
db,
|
||||
ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_FILE, childId),
|
||||
null,
|
||||
null
|
||||
);
|
||||
}
|
||||
children.moveToNext();
|
||||
}
|
||||
}
|
||||
children.close();
|
||||
} /*else {
|
||||
Log_OC.d(TAG, "No child to remove in DIRECTORY " + folderName);
|
||||
}
|
||||
Log_OC.d(TAG, "Removing DIRECTORY " + folderName + " (or maybe not) ");
|
||||
*/
|
||||
count += db.delete(ProviderTableMeta.FILE_TABLE_NAME,
|
||||
ProviderTableMeta._ID
|
||||
+ "="
|
||||
+ uri.getPathSegments().get(1)
|
||||
+ (!TextUtils.isEmpty(where) ? " AND (" + where
|
||||
+ ")" : ""), whereArgs);
|
||||
/* Just for log
|
||||
if (folder != null) {
|
||||
folder.close();
|
||||
}*/
|
||||
count = deleteDirectory(db, uri, where, whereArgs);
|
||||
break;
|
||||
case ROOT_DIRECTORY:
|
||||
//Log_OC.d(TAG, "Removing ROOT!");
|
||||
count = db.delete(ProviderTableMeta.FILE_TABLE_NAME, where, whereArgs);
|
||||
break;
|
||||
case SHARES:
|
||||
@@ -226,9 +150,82 @@ public class FileContentProvider extends ContentProvider {
|
||||
count = db.delete(ProviderTableMeta.FILESYSTEM_TABLE_NAME, where, whereArgs);
|
||||
break;
|
||||
default:
|
||||
//Log_OC.e(TAG, "Unknown uri " + uri);
|
||||
throw new IllegalArgumentException("Unknown uri: " + uri.toString());
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
private int deleteDirectory(SQLiteDatabase db, Uri uri, String where, String... whereArgs) {
|
||||
int count = 0;
|
||||
|
||||
Cursor children = query(uri, null, null, null, null);
|
||||
if (children != null) {
|
||||
if (children.moveToFirst()) {
|
||||
long childId;
|
||||
boolean isDir;
|
||||
while (!children.isAfterLast()) {
|
||||
childId = children.getLong(children.getColumnIndex(ProviderTableMeta._ID));
|
||||
isDir = MimeType.DIRECTORY.equals(children.getString(
|
||||
children.getColumnIndex(ProviderTableMeta.FILE_CONTENT_TYPE)
|
||||
));
|
||||
//remotePath = children.getString(children.getColumnIndex(ProviderTableMeta.FILE_PATH));
|
||||
if (isDir) {
|
||||
count += delete(
|
||||
db,
|
||||
ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_DIR, childId),
|
||||
null,
|
||||
null
|
||||
);
|
||||
} else {
|
||||
count += delete(
|
||||
db,
|
||||
ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_FILE, childId),
|
||||
null,
|
||||
null
|
||||
);
|
||||
}
|
||||
children.moveToNext();
|
||||
}
|
||||
}
|
||||
children.close();
|
||||
}
|
||||
|
||||
count += db.delete(ProviderTableMeta.FILE_TABLE_NAME,
|
||||
ProviderTableMeta._ID
|
||||
+ "="
|
||||
+ uri.getPathSegments().get(1)
|
||||
+ (!TextUtils.isEmpty(where) ? " AND (" + where
|
||||
+ ")" : ""), whereArgs);
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
private int deleteSingleFile(SQLiteDatabase db, Uri uri, String where, String... whereArgs) {
|
||||
int count = 0;
|
||||
Cursor c = query(db, uri, null, where, whereArgs, null);
|
||||
String remoteId = "";
|
||||
try {
|
||||
if (c != null && c.moveToFirst()) {
|
||||
remoteId = c.getString(c.getColumnIndex(ProviderTableMeta.FILE_REMOTE_ID));
|
||||
//ThumbnailsCacheManager.removeFileFromCache(remoteId);
|
||||
}
|
||||
Log_OC.d(TAG, "Removing FILE " + remoteId);
|
||||
|
||||
count = db.delete(ProviderTableMeta.FILE_TABLE_NAME,
|
||||
ProviderTableMeta._ID
|
||||
+ "="
|
||||
+ uri.getPathSegments().get(1)
|
||||
+ (!TextUtils.isEmpty(where) ? " AND (" + where + ")" : ""),
|
||||
whereArgs);
|
||||
} catch (Exception e) {
|
||||
Log_OC.d(TAG, "DB-Error removing file!", e);
|
||||
} finally {
|
||||
if (c != null) {
|
||||
c.close();
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
@@ -654,13 +651,12 @@ public class FileContentProvider extends ContentProvider {
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
private int update(
|
||||
SQLiteDatabase db,
|
||||
Uri uri,
|
||||
ContentValues values,
|
||||
String selection,
|
||||
String[] selectionArgs
|
||||
String... selectionArgs
|
||||
) {
|
||||
switch (mUriMatcher.match(uri)) {
|
||||
case DIRECTORY:
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
package com.owncloud.android.services;
|
||||
|
||||
import android.app.Service;
|
||||
import android.content.Intent;
|
||||
import android.os.IBinder;
|
||||
|
||||
import com.nextcloud.android.sso.InputStreamBinder;
|
||||
|
||||
public class AccountManagerService extends Service {
|
||||
|
||||
private InputStreamBinder mBinder;
|
||||
|
||||
@Override
|
||||
public IBinder onBind(Intent intent) {
|
||||
if(mBinder == null) {
|
||||
mBinder = new InputStreamBinder(this);
|
||||
}
|
||||
return mBinder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onUnbind(Intent intent) {
|
||||
return super.onUnbind(intent);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -269,10 +269,9 @@ public class OperationsService extends Service {
|
||||
* Map of listeners that will be reported about the end of operations from a
|
||||
* {@link OperationsServiceBinder} instance
|
||||
*/
|
||||
private final ConcurrentMap<OnRemoteOperationListener, Handler> mBoundListeners =
|
||||
new ConcurrentHashMap<OnRemoteOperationListener, Handler>();
|
||||
private final ConcurrentMap<OnRemoteOperationListener, Handler> mBoundListeners = new ConcurrentHashMap<>();
|
||||
|
||||
private ServiceHandler mServiceHandler = null;
|
||||
private ServiceHandler mServiceHandler;
|
||||
|
||||
public OperationsServiceBinder(ServiceHandler serviceHandler) {
|
||||
mServiceHandler = serviceHandler;
|
||||
@@ -355,7 +354,6 @@ public class OperationsService extends Service {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public boolean dispatchResultIfFinished(int operationId,
|
||||
OnRemoteOperationListener listener) {
|
||||
Pair<RemoteOperation, RemoteOperationResult> undispatched =
|
||||
@@ -363,13 +361,11 @@ public class OperationsService extends Service {
|
||||
if (undispatched != null) {
|
||||
listener.onRemoteOperationFinish(undispatched.first, undispatched.second);
|
||||
return true;
|
||||
//Log_OC.e(TAG, "Sending callback later");
|
||||
} else {
|
||||
return (!mServiceHandler.mPendingOperations.isEmpty());
|
||||
return !mServiceHandler.mPendingOperations.isEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns True when the file described by 'file' in the ownCloud account 'account' is
|
||||
* downloading or waiting to download.
|
||||
@@ -402,10 +398,10 @@ public class OperationsService extends Service {
|
||||
|
||||
|
||||
private ConcurrentLinkedQueue<Pair<Target, RemoteOperation>> mPendingOperations =
|
||||
new ConcurrentLinkedQueue<Pair<Target, RemoteOperation>>();
|
||||
private RemoteOperation mCurrentOperation = null;
|
||||
private Target mLastTarget = null;
|
||||
private OwnCloudClient mOwnCloudClient = null;
|
||||
new ConcurrentLinkedQueue<>();
|
||||
private RemoteOperation mCurrentOperation;
|
||||
private Target mLastTarget;
|
||||
private OwnCloudClient mOwnCloudClient;
|
||||
private FileDataStorageManager mStorageManager;
|
||||
|
||||
|
||||
@@ -423,7 +419,6 @@ public class OperationsService extends Service {
|
||||
Log_OC.d(TAG, "Stopping after command with id " + msg.arg1);
|
||||
mService.stopSelf(msg.arg1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Performs the next operation in the queue
|
||||
|
||||
@@ -141,9 +141,6 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
|
||||
SyncResult syncResult) {
|
||||
|
||||
mCancellation = false;
|
||||
/* When 'true' the process was requested by the user through the user interface;
|
||||
when 'false', it was requested automatically by the system */
|
||||
boolean mIsManualSync = extras.getBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, false);
|
||||
mFailedResultsCounter = 0;
|
||||
mLastFailedResult = null;
|
||||
mConflictsFound = 0;
|
||||
@@ -170,7 +167,10 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
|
||||
Log_OC.d(TAG, "Synchronization of ownCloud account " + account.name + " starting");
|
||||
sendLocalBroadcast(EVENT_FULL_SYNC_START, null, null); // message to signal the start
|
||||
// of the synchronization to the UI
|
||||
|
||||
|
||||
/* When 'true' the process was requested by the user through the user interface;
|
||||
when 'false', it was requested automatically by the system */
|
||||
boolean mIsManualSync = extras.getBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, false);
|
||||
try {
|
||||
updateOCVersion();
|
||||
mCurrentSyncTime = System.currentTimeMillis();
|
||||
@@ -182,7 +182,6 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
|
||||
"because cancellation request");
|
||||
}
|
||||
|
||||
|
||||
} finally {
|
||||
// it's important making this although very unexpected errors occur;
|
||||
// that's the reason for the finally
|
||||
@@ -316,12 +315,12 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
|
||||
* synchronization
|
||||
*/
|
||||
private boolean isFinisher(RemoteOperationResult failedResult) {
|
||||
if (failedResult != null) {
|
||||
if (failedResult != null) {
|
||||
RemoteOperationResult.ResultCode code = failedResult.getCode();
|
||||
return (code.equals(RemoteOperationResult.ResultCode.SSL_ERROR) ||
|
||||
code.equals(RemoteOperationResult.ResultCode.SSL_RECOVERABLE_PEER_UNVERIFIED) ||
|
||||
code.equals(RemoteOperationResult.ResultCode.BAD_OC_VERSION) ||
|
||||
code.equals(RemoteOperationResult.ResultCode.INSTANCE_NOT_CONFIGURED));
|
||||
return code.equals(RemoteOperationResult.ResultCode.SSL_ERROR)
|
||||
|| code.equals(RemoteOperationResult.ResultCode.SSL_RECOVERABLE_PEER_UNVERIFIED)
|
||||
|| code.equals(RemoteOperationResult.ResultCode.BAD_OC_VERSION)
|
||||
|| code.equals(RemoteOperationResult.ResultCode.INSTANCE_NOT_CONFIGURED);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -522,8 +521,8 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
|
||||
* @param builder
|
||||
*/
|
||||
private void showNotification(int id, NotificationCompat.Builder builder) {
|
||||
NotificationManager notificationManager = ((NotificationManager) getContext().
|
||||
getSystemService(Context.NOTIFICATION_SERVICE));
|
||||
NotificationManager notificationManager = (NotificationManager) getContext().
|
||||
getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
|
||||
builder.setChannelId(NotificationUtils.NOTIFICATION_CHANNEL_FILE_SYNC);
|
||||
|
||||
@@ -36,7 +36,7 @@ public class ExtendedListView extends ListView {
|
||||
|
||||
private static final String TAG = ExtendedListView.class.getSimpleName();
|
||||
|
||||
private int mPositionToSetAndCenter = 0;
|
||||
private int mPositionToSetAndCenter;
|
||||
|
||||
public ExtendedListView(Context context) {
|
||||
super(context);
|
||||
|
||||
@@ -38,7 +38,6 @@ import com.owncloud.android.utils.ThemeUtils;
|
||||
/**
|
||||
* Themeable switch preference
|
||||
*/
|
||||
|
||||
public class ThemeableSwitchPreference extends SwitchPreference {
|
||||
|
||||
public ThemeableSwitchPreference(Context context) {
|
||||
@@ -64,24 +63,31 @@ public class ThemeableSwitchPreference extends SwitchPreference {
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.JELLY_BEAN)
|
||||
private void findSwitch(ViewGroup viewGroup) {
|
||||
ColorStateList thumbColorStateList = null;
|
||||
ColorStateList trackColorStateList = null;
|
||||
|
||||
for (int i = 0; i < viewGroup.getChildCount(); i++) {
|
||||
View child = viewGroup.getChildAt(i);
|
||||
|
||||
if (child instanceof Switch) {
|
||||
Switch switchView = (Switch) child;
|
||||
|
||||
int color = ThemeUtils.primaryAccentColor(getContext());
|
||||
int trackColor = Color.argb(77, Color.red(color), Color.green(color), Color.blue(color));
|
||||
if(thumbColorStateList == null && trackColorStateList == null) {
|
||||
int color = ThemeUtils.primaryAccentColor(getContext());
|
||||
int trackColor = Color.argb(77, Color.red(color), Color.green(color), Color.blue(color));
|
||||
thumbColorStateList = new ColorStateList(
|
||||
new int[][]{new int[]{android.R.attr.state_checked}, new int[]{}},
|
||||
new int[]{color, Color.WHITE});
|
||||
trackColorStateList = new ColorStateList(
|
||||
new int[][]{new int[]{android.R.attr.state_checked}, new int[]{}},
|
||||
new int[]{trackColor, Color.parseColor("#4D000000")});
|
||||
}
|
||||
|
||||
// setting the thumb color
|
||||
DrawableCompat.setTintList(switchView.getThumbDrawable(), new ColorStateList(
|
||||
new int[][]{new int[]{android.R.attr.state_checked}, new int[]{}},
|
||||
new int[]{color, Color.WHITE}));
|
||||
DrawableCompat.setTintList(switchView.getThumbDrawable(), thumbColorStateList);
|
||||
|
||||
// setting the track color
|
||||
DrawableCompat.setTintList(switchView.getTrackDrawable(), new ColorStateList(
|
||||
new int[][]{new int[]{android.R.attr.state_checked}, new int[]{}},
|
||||
new int[]{trackColor, Color.parseColor("#4D000000")}));
|
||||
DrawableCompat.setTintList(switchView.getTrackDrawable(), trackColorStateList);
|
||||
|
||||
break;
|
||||
} else if (child instanceof ViewGroup) {
|
||||
|
||||
@@ -946,13 +946,13 @@ public abstract class DrawerActivity extends ToolbarActivity implements DisplayU
|
||||
Thread t = new Thread(new Runnable() {
|
||||
public void run() {
|
||||
Context context = MainApp.getAppContext();
|
||||
AccountManager mAccountMgr = AccountManager.get(context);
|
||||
Account account = AccountUtils.getCurrentOwnCloudAccount(context);
|
||||
|
||||
if (account == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
AccountManager mAccountMgr = AccountManager.get(context);
|
||||
String userId = mAccountMgr.getUserData(account,
|
||||
com.owncloud.android.lib.common.accounts.AccountUtils.Constants.KEY_USER_ID);
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ package com.owncloud.android.ui.activity;
|
||||
import android.accounts.Account;
|
||||
import android.accounts.AccountManager;
|
||||
import android.accounts.AuthenticatorException;
|
||||
import android.app.Activity;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@@ -77,14 +78,13 @@ import com.owncloud.android.utils.ErrorMessageAdapter;
|
||||
import com.owncloud.android.utils.FilesSyncHelper;
|
||||
import com.owncloud.android.utils.ThemeUtils;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
|
||||
/**
|
||||
* Activity with common behaviour for activities handling {@link OCFile}s in ownCloud {@link Account}s .
|
||||
*/
|
||||
public abstract class FileActivity extends DrawerActivity
|
||||
implements OnRemoteOperationListener, ComponentsGetter, SslUntrustedCertDialog.OnSslUntrustedCertListener {
|
||||
implements OnRemoteOperationListener, ComponentsGetter, SslUntrustedCertDialog.OnSslUntrustedCertListener,
|
||||
LoadingVersionNumberTask.VersionDevInterface {
|
||||
|
||||
public static final String EXTRA_FILE = "com.owncloud.android.ui.activity.FILE";
|
||||
public static final String EXTRA_ACCOUNT = "com.owncloud.android.ui.activity.ACCOUNT";
|
||||
@@ -596,45 +596,51 @@ public abstract class FileActivity extends DrawerActivity
|
||||
int count = arbitraryDataProvider.getIntegerValue(FilesSyncHelper.GLOBAL, APP_OPENED_COUNT);
|
||||
|
||||
if (count > 10 || count == -1) {
|
||||
checkForNewDevVersion(view, context, false);
|
||||
checkForNewDevVersion(this, context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void checkForNewDevVersion(View view, Context context, boolean openDirectly) {
|
||||
Integer latestVersion = -1;
|
||||
@Override
|
||||
public void returnVersion(Integer latestVersion) {
|
||||
showDevSnackbar(this, latestVersion, false);
|
||||
}
|
||||
|
||||
public static void checkForNewDevVersion(LoadingVersionNumberTask.VersionDevInterface callback, Context context) {
|
||||
String url = context.getString(R.string.dev_latest);
|
||||
LoadingVersionNumberTask loadTask = new LoadingVersionNumberTask(callback);
|
||||
loadTask.execute(url);
|
||||
}
|
||||
|
||||
public static void showDevSnackbar(Activity activity, Integer latestVersion, boolean openDirectly) {
|
||||
Integer currentVersion = -1;
|
||||
try {
|
||||
currentVersion = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionCode;
|
||||
String url = context.getString(R.string.dev_latest);
|
||||
LoadingVersionNumberTask loadTask = new LoadingVersionNumberTask();
|
||||
loadTask.execute(url);
|
||||
latestVersion = loadTask.get();
|
||||
} catch (InterruptedException | ExecutionException | PackageManager.NameNotFoundException e) {
|
||||
Log_OC.e(TAG, "Error detecting app version", e);
|
||||
currentVersion = activity.getPackageManager().getPackageInfo(activity.getPackageName(), 0).versionCode;
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
Log_OC.e(TAG, "Package not found", e);
|
||||
}
|
||||
|
||||
if (latestVersion == -1 || currentVersion == -1) {
|
||||
Snackbar.make(view, R.string.dev_version_no_information_available, Snackbar.LENGTH_LONG).show();
|
||||
DisplayUtils.showSnackMessage(activity, R.string.dev_version_no_information_available, Snackbar.LENGTH_LONG);
|
||||
}
|
||||
if (latestVersion > currentVersion) {
|
||||
if (openDirectly) {
|
||||
String devApkLink = (String) context.getText(R.string.dev_link) + latestVersion + ".apk";
|
||||
String devApkLink = (String) activity.getText(R.string.dev_link) + latestVersion + ".apk";
|
||||
Uri uriUrl = Uri.parse(devApkLink);
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW, uriUrl);
|
||||
context.startActivity(intent);
|
||||
activity.startActivity(intent);
|
||||
} else {
|
||||
Integer finalLatestVersion = latestVersion;
|
||||
Snackbar.make(view, R.string.dev_version_new_version_available, Snackbar.LENGTH_LONG)
|
||||
.setAction(context.getString(R.string.version_dev_download), v -> {
|
||||
String devApkLink = (String) context.getText(R.string.dev_link)
|
||||
+ finalLatestVersion + ".apk";
|
||||
Snackbar.make(activity.findViewById(android.R.id.content), R.string.dev_version_new_version_available,
|
||||
Snackbar.LENGTH_LONG)
|
||||
.setAction(activity.getString(R.string.version_dev_download), v -> {
|
||||
String devApkLink = (String) activity.getText(R.string.dev_link) + latestVersion + ".apk";
|
||||
Uri uriUrl = Uri.parse(devApkLink);
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW, uriUrl);
|
||||
context.startActivity(intent);
|
||||
activity.startActivity(intent);
|
||||
}).show();
|
||||
}
|
||||
} else {
|
||||
Snackbar.make(view, R.string.dev_version_no_new_version_available, Snackbar.LENGTH_LONG).show();
|
||||
DisplayUtils.showSnackMessage(activity, R.string.dev_version_no_new_version_available, Snackbar.LENGTH_LONG);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -123,6 +123,7 @@ import com.owncloud.android.ui.preview.PreviewImageFragment;
|
||||
import com.owncloud.android.ui.preview.PreviewMediaFragment;
|
||||
import com.owncloud.android.ui.preview.PreviewTextFragment;
|
||||
import com.owncloud.android.ui.preview.PreviewVideoActivity;
|
||||
import com.owncloud.android.utils.ClipboardUtil;
|
||||
import com.owncloud.android.utils.DataHolderUtil;
|
||||
import com.owncloud.android.utils.DisplayUtils;
|
||||
import com.owncloud.android.utils.ErrorMessageAdapter;
|
||||
@@ -276,9 +277,7 @@ public class FileDisplayActivity extends HookActivity
|
||||
PermissionUtil.requestWriteExternalStoreagePermission(FileDisplayActivity.this);
|
||||
}
|
||||
});
|
||||
|
||||
ThemeUtils.colorSnackbar(this, snackbar);
|
||||
|
||||
snackbar.show();
|
||||
} else {
|
||||
// No explanation needed, request the permission.
|
||||
@@ -705,8 +704,8 @@ public class FileDisplayActivity extends HookActivity
|
||||
protected void refreshSecondFragment(String downloadEvent, String downloadedRemotePath,
|
||||
boolean success) {
|
||||
FileFragment secondFragment = getSecondFragment();
|
||||
boolean waitedPreview = (mWaitingToPreview != null &&
|
||||
mWaitingToPreview.getRemotePath().equals(downloadedRemotePath));
|
||||
boolean waitedPreview = mWaitingToPreview != null
|
||||
&& mWaitingToPreview.getRemotePath().equals(downloadedRemotePath);
|
||||
if (secondFragment instanceof FileDetailFragment) {
|
||||
FileDetailFragment detailsFragment = (FileDetailFragment) secondFragment;
|
||||
OCFile fileInFragment = detailsFragment.getFile();
|
||||
@@ -746,7 +745,7 @@ public class FileDisplayActivity extends HookActivity
|
||||
mWaitingToPreview = null;
|
||||
}
|
||||
if (!detailsFragmentChanged) {
|
||||
detailsFragment.updateFileDetails(false, (success));
|
||||
detailsFragment.updateFileDetails(false, success);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1498,12 +1497,8 @@ public class FileDisplayActivity extends HookActivity
|
||||
// TODO refactor this receiver, and maybe DownloadFinishReceiver; this method is duplicated :S
|
||||
private boolean isAscendant(String linkedToRemotePath) {
|
||||
OCFile currentDir = getCurrentDir();
|
||||
return (
|
||||
currentDir != null &&
|
||||
currentDir.getRemotePath().startsWith(linkedToRemotePath)
|
||||
);
|
||||
return currentDir != null && currentDir.getRemotePath().startsWith(linkedToRemotePath);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1907,9 +1902,6 @@ public class FileDisplayActivity extends HookActivity
|
||||
if (result.isSuccess()) {
|
||||
updateFileFromDB();
|
||||
|
||||
// Create dialog to allow the user choose an app to send the link
|
||||
Intent intentToShareLink = new Intent(Intent.ACTION_SEND);
|
||||
|
||||
// if share to user and share via link multiple ocshares are returned,
|
||||
// therefore filtering for public_link
|
||||
String link = "";
|
||||
@@ -1921,43 +1913,7 @@ public class FileDisplayActivity extends HookActivity
|
||||
}
|
||||
}
|
||||
|
||||
intentToShareLink.putExtra(Intent.EXTRA_TEXT, link);
|
||||
intentToShareLink.setType("text/plain");
|
||||
|
||||
String username;
|
||||
try {
|
||||
OwnCloudAccount oca = new OwnCloudAccount(getAccount(), this);
|
||||
if (oca.getDisplayName() != null && !oca.getDisplayName().isEmpty()) {
|
||||
username = oca.getDisplayName();
|
||||
} else {
|
||||
username = AccountUtils.getUsernameForAccount(getAccount());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
username = AccountUtils.getUsernameForAccount(getAccount());
|
||||
}
|
||||
|
||||
if (username != null) {
|
||||
intentToShareLink.putExtra(
|
||||
Intent.EXTRA_SUBJECT,
|
||||
getString(
|
||||
R.string.subject_user_shared_with_you,
|
||||
username,
|
||||
getFile().getFileName()
|
||||
)
|
||||
);
|
||||
} else {
|
||||
intentToShareLink.putExtra(
|
||||
Intent.EXTRA_SUBJECT,
|
||||
getString(
|
||||
R.string.subject_shared_with_you,
|
||||
getFile().getFileName()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
String[] packagesToExclude = new String[]{getPackageName()};
|
||||
DialogFragment chooserDialog = ShareLinkToDialog.newInstance(intentToShareLink, packagesToExclude);
|
||||
chooserDialog.show(getSupportFragmentManager(), FTAG_CHOOSER_DIALOG);
|
||||
copyAndShareFileLink(link);
|
||||
|
||||
if (fileDetailFragment != null && fileDetailFragment.getFileDetailSharingFragment() != null) {
|
||||
fileDetailFragment.getFileDetailSharingFragment().refreshPublicShareFromDB();
|
||||
@@ -1983,15 +1939,71 @@ public class FileDisplayActivity extends HookActivity
|
||||
if (fileDetailFragment != null && fileDetailFragment.getFileDetailSharingFragment() != null) {
|
||||
fileDetailFragment.getFileDetailSharingFragment().refreshPublicShareFromDB();
|
||||
}
|
||||
Snackbar.make(
|
||||
Snackbar snackbar = Snackbar.make(
|
||||
findViewById(android.R.id.content),
|
||||
ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()),
|
||||
Snackbar.LENGTH_LONG
|
||||
).show();
|
||||
);
|
||||
ThemeUtils.colorSnackbar(this, snackbar);
|
||||
snackbar.show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void copyAndShareFileLink(String link) {
|
||||
ClipboardUtil.copyToClipboard(this, link, false);
|
||||
Snackbar snackbar = Snackbar.make(
|
||||
findViewById(android.R.id.content),
|
||||
R.string.clipboard_text_copied,
|
||||
Snackbar.LENGTH_LONG
|
||||
).setAction(R.string.share, v -> showShareLinkDialog(link));
|
||||
ThemeUtils.colorSnackbar(this, snackbar);
|
||||
snackbar.show();
|
||||
}
|
||||
|
||||
public void showShareLinkDialog(String link) {
|
||||
// Create dialog to allow the user choose an app to send the link
|
||||
Intent intentToShareLink = new Intent(Intent.ACTION_SEND);
|
||||
|
||||
intentToShareLink.putExtra(Intent.EXTRA_TEXT, link);
|
||||
intentToShareLink.setType("text/plain");
|
||||
|
||||
String username;
|
||||
try {
|
||||
OwnCloudAccount oca = new OwnCloudAccount(getAccount(), this);
|
||||
if (oca.getDisplayName() != null && !oca.getDisplayName().isEmpty()) {
|
||||
username = oca.getDisplayName();
|
||||
} else {
|
||||
username = AccountUtils.getUsernameForAccount(getAccount());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
username = AccountUtils.getUsernameForAccount(getAccount());
|
||||
}
|
||||
|
||||
if (username != null) {
|
||||
intentToShareLink.putExtra(
|
||||
Intent.EXTRA_SUBJECT,
|
||||
getString(
|
||||
R.string.subject_user_shared_with_you,
|
||||
username,
|
||||
getFile().getFileName()
|
||||
)
|
||||
);
|
||||
} else {
|
||||
intentToShareLink.putExtra(
|
||||
Intent.EXTRA_SUBJECT,
|
||||
getString(
|
||||
R.string.subject_shared_with_you,
|
||||
getFile().getFileName()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
String[] packagesToExclude = new String[]{getPackageName()};
|
||||
DialogFragment chooserDialog = ShareLinkToDialog.newInstance(intentToShareLink, packagesToExclude);
|
||||
chooserDialog.show(getSupportFragmentManager(), FTAG_CHOOSER_DIALOG);
|
||||
}
|
||||
|
||||
private void onUpdateShareInformation(RemoteOperationResult result, @StringRes int errorString) {
|
||||
Fragment fileDetailFragment = getSecondFragment();
|
||||
|
||||
@@ -1999,7 +2011,9 @@ public class FileDisplayActivity extends HookActivity
|
||||
updateFileFromDB();
|
||||
refreshListOfFilesFragment(false);
|
||||
} else if (fileDetailFragment.getView() != null) {
|
||||
Snackbar.make(fileDetailFragment.getView(), errorString, Snackbar.LENGTH_LONG).show();
|
||||
Snackbar snackbar = Snackbar.make(fileDetailFragment.getView(), errorString, Snackbar.LENGTH_LONG);
|
||||
ThemeUtils.colorSnackbar(this, snackbar);
|
||||
snackbar.show();
|
||||
}
|
||||
|
||||
if (fileDetailFragment != null && fileDetailFragment instanceof FileDetailFragment) {
|
||||
|
||||
@@ -163,6 +163,13 @@ public class FirstRunActivity extends BaseActivity implements ViewPager.OnPageCh
|
||||
PreferenceManager.setLastSeenVersionCode(this, MainApp.getVersionCode());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
onFinish();
|
||||
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
private static boolean isFirstRun(Context context) {
|
||||
return AccountUtils.getCurrentOwnCloudAccount(context) == null;
|
||||
}
|
||||
|
||||
@@ -249,10 +249,8 @@ public class NotificationsActivity extends FileActivity {
|
||||
recyclerView.setAdapter(adapter);
|
||||
|
||||
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
|
||||
DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(this, layoutManager.getOrientation());
|
||||
|
||||
recyclerView.setLayoutManager(layoutManager);
|
||||
recyclerView.addItemDecoration(dividerItemDecoration);
|
||||
|
||||
BottomNavigationView bottomNavigationView = findViewById(R.id.bottom_navigation_view);
|
||||
|
||||
|
||||
@@ -315,8 +315,7 @@ public class PassCodeActivity extends AppCompatActivity {
|
||||
|
||||
boolean result = true;
|
||||
for (int i = 0; i < mPassCodeDigits.length && result; i++) {
|
||||
result = (mPassCodeDigits[i] != null) &&
|
||||
mPassCodeDigits[i].equals(savedPassCodeDigits[i]);
|
||||
result = mPassCodeDigits[i] != null && mPassCodeDigits[i].equals(savedPassCodeDigits[i]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -332,7 +331,7 @@ public class PassCodeActivity extends AppCompatActivity {
|
||||
|
||||
boolean result = true;
|
||||
for (int i = 0; i < mPassCodeEditTexts.length && result; i++) {
|
||||
result = ((mPassCodeEditTexts[i].getText().toString()).equals(mPassCodeDigits[i]));
|
||||
result = mPassCodeEditTexts[i].getText().toString().equals(mPassCodeDigits[i]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -71,6 +71,7 @@ import com.owncloud.android.lib.common.ExternalLinkType;
|
||||
import com.owncloud.android.lib.common.OwnCloudAccount;
|
||||
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
import com.owncloud.android.ui.asynctasks.LoadingVersionNumberTask;
|
||||
import com.owncloud.android.utils.DeviceCredentialUtils;
|
||||
import com.owncloud.android.utils.DisplayUtils;
|
||||
import com.owncloud.android.utils.EncryptionUtils;
|
||||
@@ -85,7 +86,7 @@ import java.util.ArrayList;
|
||||
* It proxies the necessary calls via {@link android.support.v7.app.AppCompatDelegate} to be used with AppCompat.
|
||||
*/
|
||||
public class Preferences extends PreferenceActivity
|
||||
implements StorageMigration.StorageMigrationProgressListener {
|
||||
implements StorageMigration.StorageMigrationProgressListener, LoadingVersionNumberTask.VersionDevInterface {
|
||||
|
||||
private static final String TAG = Preferences.class.getSimpleName();
|
||||
|
||||
@@ -191,7 +192,7 @@ public class Preferences extends PreferenceActivity
|
||||
if (pDevLink != null) {
|
||||
if (getResources().getBoolean(R.bool.dev_version_direct_download_enabled)) {
|
||||
pDevLink.setOnPreferenceClickListener(preference -> {
|
||||
FileActivity.checkForNewDevVersion(getListView(), getApplicationContext(), true);
|
||||
FileActivity.checkForNewDevVersion(this, getApplicationContext());
|
||||
return true;
|
||||
});
|
||||
} else {
|
||||
@@ -1096,4 +1097,10 @@ public class Preferences extends PreferenceActivity
|
||||
public void onCancelMigration() {
|
||||
// Migration was canceled so we don't do anything
|
||||
}
|
||||
|
||||
@Override
|
||||
public void returnVersion(Integer latestVersion) {
|
||||
FileActivity.showDevSnackbar(this, latestVersion, true);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -98,6 +98,7 @@ import com.owncloud.android.utils.DataHolderUtil;
|
||||
import com.owncloud.android.utils.DisplayUtils;
|
||||
import com.owncloud.android.utils.ErrorMessageAdapter;
|
||||
import com.owncloud.android.utils.FileSortOrder;
|
||||
import com.owncloud.android.utils.MimeType;
|
||||
import com.owncloud.android.utils.ThemeUtils;
|
||||
|
||||
import java.io.File;
|
||||
@@ -131,6 +132,7 @@ public class ReceiveExternalFilesActivity extends FileActivity
|
||||
public static final String URL_FILE_SUFFIX = ".url";
|
||||
public static final String WEBLOC_FILE_SUFFIX = ".webloc";
|
||||
public static final String DESKTOP_FILE_SUFFIX = ".desktop";
|
||||
public static final int SINGLE_PARENT = 1;
|
||||
|
||||
private AccountManager mAccountManager;
|
||||
private Stack<String> mParents = new Stack<>();
|
||||
@@ -526,7 +528,7 @@ public class ReceiveExternalFilesActivity extends FileActivity
|
||||
inputText.setText(filename);
|
||||
int selectionStart = 0;
|
||||
int extensionStart = filename.lastIndexOf(".");
|
||||
int selectionEnd = (extensionStart >= 0) ? extensionStart : filename.length();
|
||||
int selectionEnd = extensionStart >= 0 ? extensionStart : filename.length();
|
||||
if (selectionEnd >= 0) {
|
||||
inputText.setSelection(
|
||||
Math.min(selectionStart, selectionEnd),
|
||||
@@ -544,7 +546,7 @@ public class ReceiveExternalFilesActivity extends FileActivity
|
||||
}
|
||||
|
||||
private boolean isIntentStartWithUrl(String extraText) {
|
||||
return (extraText.startsWith("http://") || extraText.startsWith("https://"));
|
||||
return extraText.startsWith("http://") || extraText.startsWith("https://");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -728,7 +730,7 @@ public class ReceiveExternalFilesActivity extends FileActivity
|
||||
ListView mListView = findViewById(android.R.id.list);
|
||||
|
||||
String current_dir = mParents.peek();
|
||||
boolean notRoot = (mParents.size() > 1);
|
||||
boolean notRoot = mParents.size() > 1;
|
||||
|
||||
if (actionBar != null) {
|
||||
if ("".equals(current_dir)) {
|
||||
@@ -880,7 +882,7 @@ public class ReceiveExternalFilesActivity extends FileActivity
|
||||
}
|
||||
|
||||
private void saveTextsFromIntent(Intent intent) {
|
||||
if (!"text/plain".equals(intent.getType())) {
|
||||
if (!MimeType.TEXT_PLAIN.equals(intent.getType())) {
|
||||
return;
|
||||
}
|
||||
mUploadFromTmpFile = true;
|
||||
@@ -1063,7 +1065,7 @@ public class ReceiveExternalFilesActivity extends FileActivity
|
||||
dialog.show(getSupportFragmentManager(), CreateFolderDialogFragment.CREATE_FOLDER_FRAGMENT);
|
||||
break;
|
||||
case android.R.id.home:
|
||||
if ((mParents.size() > 1)) {
|
||||
if (mParents.size() > SINGLE_PARENT) {
|
||||
onBackPressed();
|
||||
}
|
||||
break;
|
||||
@@ -1115,8 +1117,8 @@ public class ReceiveExternalFilesActivity extends FileActivity
|
||||
String syncFolderRemotePath = intent.getStringExtra(FileSyncAdapter.EXTRA_FOLDER_PATH);
|
||||
RemoteOperationResult syncResult = (RemoteOperationResult)
|
||||
DataHolderUtil.getInstance().retrieve(intent.getStringExtra(FileSyncAdapter.EXTRA_RESULT));
|
||||
boolean sameAccount = (getAccount() != null &&
|
||||
accountName.equals(getAccount().name) && getStorageManager() != null);
|
||||
boolean sameAccount = getAccount() != null && accountName.equals(getAccount().name)
|
||||
&& getStorageManager() != null;
|
||||
|
||||
if (sameAccount) {
|
||||
|
||||
@@ -1150,13 +1152,12 @@ public class ReceiveExternalFilesActivity extends FileActivity
|
||||
mFile = currentFile;
|
||||
}
|
||||
|
||||
mSyncInProgress = (!FileSyncAdapter.EVENT_FULL_SYNC_END.equals(event) &&
|
||||
!RefreshFolderOperation.EVENT_SINGLE_FOLDER_SHARES_SYNCED.equals(event));
|
||||
mSyncInProgress = !FileSyncAdapter.EVENT_FULL_SYNC_END.equals(event) &&
|
||||
!RefreshFolderOperation.EVENT_SINGLE_FOLDER_SHARES_SYNCED.equals(event);
|
||||
|
||||
if (RefreshFolderOperation.EVENT_SINGLE_FOLDER_CONTENTS_SYNCED.
|
||||
equals(event) &&
|
||||
if (RefreshFolderOperation.EVENT_SINGLE_FOLDER_CONTENTS_SYNCED.equals(event)
|
||||
/// TODO refactor and make common
|
||||
syncResult != null && !syncResult.isSuccess()) {
|
||||
&& syncResult != null && !syncResult.isSuccess()) {
|
||||
|
||||
if (syncResult.getCode() == ResultCode.UNAUTHORIZED ||
|
||||
(syncResult.isException() && syncResult.getException()
|
||||
|
||||
@@ -148,8 +148,8 @@ public class ShareActivity extends FileActivity implements ShareFragmentListener
|
||||
return OCShare.READ_PERMISSION_FLAG; // minimum permissions
|
||||
|
||||
} else if (isFederated) {
|
||||
return (getFile().isFolder() ? OCShare.FEDERATED_PERMISSIONS_FOR_FOLDER_AFTER_OC9 :
|
||||
OCShare.FEDERATED_PERMISSIONS_FOR_FILE_AFTER_OC9);
|
||||
return getFile().isFolder() ? OCShare.FEDERATED_PERMISSIONS_FOR_FOLDER_AFTER_OC9 :
|
||||
OCShare.FEDERATED_PERMISSIONS_FOR_FILE_AFTER_OC9;
|
||||
} else {
|
||||
return (getFile().isFolder() ? OCShare.MAXIMUM_PERMISSIONS_FOR_FOLDER :
|
||||
OCShare.MAXIMUM_PERMISSIONS_FOR_FILE);
|
||||
|
||||
@@ -269,7 +269,7 @@ public class StorageMigration {
|
||||
}
|
||||
}
|
||||
|
||||
protected void restoreAccountsSyncStatus(boolean oldSync[]) {
|
||||
protected void restoreAccountsSyncStatus(boolean... oldSync) {
|
||||
// If we don't have the old sync statuses, then
|
||||
// probably migration failed even before saving states,
|
||||
// which is weird and should be investigated.
|
||||
|
||||
@@ -423,7 +423,7 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA
|
||||
return files;
|
||||
}
|
||||
|
||||
private List<String> getDisplayFilePathList(File[] files) {
|
||||
private List<String> getDisplayFilePathList(File... files) {
|
||||
List<String> filePaths = null;
|
||||
|
||||
if (files != null && files.length > 0) {
|
||||
|
||||
@@ -84,9 +84,9 @@ public class UploadFilesActivity extends FileActivity implements
|
||||
private static final String SORT_ORDER_DIALOG_TAG = "SORT_ORDER_DIALOG";
|
||||
|
||||
private ArrayAdapter<String> mDirectories;
|
||||
private File mCurrentDir = null;
|
||||
private boolean mSelectAll = false;
|
||||
private boolean mLocalFolderPickerMode = false;
|
||||
private File mCurrentDir;
|
||||
private boolean mSelectAll;
|
||||
private boolean mLocalFolderPickerMode;
|
||||
private LocalFileListFragment mFileListFragment;
|
||||
protected Button mUploadBtn;
|
||||
private Spinner mBehaviourSpinner;
|
||||
|
||||
@@ -148,7 +148,6 @@ public class UserInfoActivity extends FileActivity {
|
||||
updateActionBarTitleAndHomeButtonByString("");
|
||||
|
||||
mUserInfoList.setAdapter(new UserInfoAdapter(null, ThemeUtils.primaryColor(getAccount(), true, this)));
|
||||
mUserInfoList.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
|
||||
|
||||
if (userInfo != null) {
|
||||
populateUserInfoUi(userInfo);
|
||||
|
||||
@@ -139,8 +139,7 @@ public class WhatsNewActivity extends FragmentActivity implements ViewPager.OnPa
|
||||
}
|
||||
|
||||
public static void runIfNeeded(Context context) {
|
||||
if (!context.getResources().getBoolean(R.bool.show_whats_new)
|
||||
|| context instanceof WhatsNewActivity) {
|
||||
if (!context.getResources().getBoolean(R.bool.show_whats_new) || context instanceof WhatsNewActivity) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -174,7 +173,7 @@ public class WhatsNewActivity extends FragmentActivity implements ViewPager.OnPa
|
||||
}
|
||||
|
||||
static private FeatureItem[] getWhatsNew(Context context) {
|
||||
int itemVersionCode = 30030000;
|
||||
int itemVersionCode = 30030099;
|
||||
|
||||
if (!isFirstRun(context) && MainApp.getVersionCode() >= itemVersionCode
|
||||
&& PreferenceManager.getLastSeenVersionCode(context) < itemVersionCode) {
|
||||
|
||||
@@ -239,7 +239,7 @@ public class ActivityListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
||||
private void setBitmap(OCFile file, ImageView fileIcon, boolean isDetailView) {
|
||||
// No Folder
|
||||
if (!file.isFolder()) {
|
||||
if ((MimeTypeUtil.isImage(file) || MimeTypeUtil.isVideo(file))) {
|
||||
if (MimeTypeUtil.isImage(file) || MimeTypeUtil.isVideo(file)) {
|
||||
int placeholder;
|
||||
|
||||
if (MimeTypeUtil.isImage(file)) {
|
||||
|
||||
@@ -68,7 +68,7 @@ public class LocalFileListAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
private List<File> mFiles = new ArrayList<>();
|
||||
private List<File> mFilesAll = new ArrayList<>();
|
||||
private boolean mLocalFolderPicker;
|
||||
private boolean gridView = false;
|
||||
private boolean gridView;
|
||||
private LocalFileListFragmentInterface localFileListFragmentInterface;
|
||||
private Set<File> checkedFiles;
|
||||
|
||||
|
||||
@@ -54,7 +54,6 @@ import butterknife.ButterKnife;
|
||||
/**
|
||||
* Adapter for the trashbin view
|
||||
*/
|
||||
|
||||
public class TrashbinListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
|
||||
private static final int TRASHBIN_ITEM = 100;
|
||||
|
||||
@@ -605,7 +605,7 @@ public class UploadListAdapter extends SectionedRecyclerViewAdapter<SectionedVie
|
||||
return items[position];
|
||||
}
|
||||
|
||||
public void setItems(OCUpload[] items) {
|
||||
public void setItems(OCUpload... items) {
|
||||
this.items = items;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.owncloud.android.ui.adapter;
|
||||
|
||||
|
||||
@@ -37,6 +37,12 @@ import java.net.URL;
|
||||
public class LoadingVersionNumberTask extends AsyncTask<String, Void, Integer> {
|
||||
private static final String TAG = LoadingVersionNumberTask.class.getSimpleName();
|
||||
|
||||
private VersionDevInterface callback;
|
||||
|
||||
public LoadingVersionNumberTask(VersionDevInterface callback) {
|
||||
this.callback = callback;
|
||||
}
|
||||
|
||||
protected Integer doInBackground(String... args) {
|
||||
try {
|
||||
URL url = new URL(args[0]);
|
||||
@@ -51,4 +57,13 @@ public class LoadingVersionNumberTask extends AsyncTask<String, Void, Integer> {
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Integer latestVersion) {
|
||||
callback.returnVersion(latestVersion);
|
||||
}
|
||||
|
||||
public interface VersionDevInterface {
|
||||
void returnVersion(Integer latestVersion);
|
||||
}
|
||||
}
|
||||
@@ -194,7 +194,7 @@ public class SamlWebViewDialog extends DialogFragment {
|
||||
|
||||
// Work around bug: http://code.google.com/p/android/issues/detail?id=17423
|
||||
Dialog dialog = getDialog();
|
||||
if ((dialog != null)) {
|
||||
if (dialog != null) {
|
||||
dialog.setOnDismissListener(null);
|
||||
}
|
||||
|
||||
|
||||
@@ -89,8 +89,6 @@ public class SendShareDialog extends BottomSheetDialogFragment {
|
||||
// keep the state of the fragment on configuration changes
|
||||
setRetainInstance(true);
|
||||
|
||||
view = null;
|
||||
|
||||
file = getArguments().getParcelable(KEY_OCFILE);
|
||||
hideNcSharingOptions = getArguments().getBoolean(KEY_HIDE_NCSHARING_OPTIONS, false);
|
||||
sharingPublicPasswordEnforced = getArguments().getBoolean(KEY_SHARING_PUBLIC_PASSWORD_ENFORCED, false);
|
||||
|
||||
@@ -345,7 +345,6 @@ public class SetupEncryptionDialogFragment extends DialogFragment {
|
||||
|
||||
// Create public/private key pair
|
||||
KeyPair keyPair = EncryptionUtils.generateKeyPair();
|
||||
PrivateKey privateKey = keyPair.getPrivate();
|
||||
|
||||
// get user id
|
||||
String userID;
|
||||
@@ -369,13 +368,13 @@ public class SetupEncryptionDialogFragment extends DialogFragment {
|
||||
|
||||
if (result.isSuccess()) {
|
||||
Log_OC.d(TAG, "public key success");
|
||||
|
||||
publicKey = (String) result.getData().get(0);
|
||||
} else {
|
||||
keyResult = KEY_FAILED;
|
||||
return "";
|
||||
}
|
||||
|
||||
PrivateKey privateKey = keyPair.getPrivate();
|
||||
String privateKeyString = EncryptionUtils.encodeBytesToBase64String(privateKey.getEncoded());
|
||||
String privatePemKeyString = EncryptionUtils.privateKeyToPEM(privateKey);
|
||||
String encryptedPrivateKey = EncryptionUtils.encryptPrivateKey(privatePemKeyString,
|
||||
|
||||
@@ -65,7 +65,7 @@ public class ShareLinkToDialog extends DialogFragment {
|
||||
private ActivityAdapter mAdapter;
|
||||
private Intent mIntent;
|
||||
|
||||
public static ShareLinkToDialog newInstance(Intent intent, String[] packagesToExclude) {
|
||||
public static ShareLinkToDialog newInstance(Intent intent, String... packagesToExclude) {
|
||||
ShareLinkToDialog f = new ShareLinkToDialog();
|
||||
Bundle args = new Bundle();
|
||||
args.putParcelable(ARG_INTENT, intent);
|
||||
@@ -165,8 +165,8 @@ public class ShareLinkToDialog extends DialogFragment {
|
||||
}
|
||||
|
||||
private View newView(ViewGroup parent) {
|
||||
return(((LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE)).
|
||||
inflate(R.layout.activity_row, parent, false));
|
||||
return((LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE)).
|
||||
inflate(R.layout.activity_row, parent, false);
|
||||
}
|
||||
|
||||
private void bindView(int position, View row) {
|
||||
@@ -176,5 +176,4 @@ public class ShareLinkToDialog extends DialogFragment {
|
||||
icon.setImageDrawable(getItem(position).loadIcon(mPackageManager));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -48,7 +48,7 @@ public class SortingOrderDialogFragment extends DialogFragment {
|
||||
public static final String SORTING_ORDER_FRAGMENT = "SORTING_ORDER_FRAGMENT";
|
||||
private static final String KEY_SORT_ORDER = "SORT_ORDER";
|
||||
|
||||
private View mView = null;
|
||||
private View mView;
|
||||
private View[] mTaggedViews;
|
||||
private AppCompatButton mCancel;
|
||||
private String mCurrentSortOrderName;
|
||||
|
||||
@@ -54,7 +54,7 @@ public class SslValidatorDialog extends Dialog {
|
||||
private final static String TAG = SslValidatorDialog.class.getSimpleName();
|
||||
|
||||
private OnSslValidatorListener mListener;
|
||||
private CertificateCombinedException mException = null;
|
||||
private CertificateCombinedException mException;
|
||||
private View mView;
|
||||
|
||||
|
||||
|
||||
+2
-2
@@ -83,14 +83,14 @@ public class SyncedFolderPreferencesDialogFragment extends DialogFragment {
|
||||
private AlertDialog behaviourDialog;
|
||||
|
||||
public static SyncedFolderPreferencesDialogFragment newInstance(SyncedFolderDisplayItem syncedFolder, int section) {
|
||||
SyncedFolderPreferencesDialogFragment dialogFragment = new SyncedFolderPreferencesDialogFragment();
|
||||
|
||||
if (syncedFolder == null) {
|
||||
throw new IllegalArgumentException("SyncedFolder is mandatory but NULL!");
|
||||
}
|
||||
|
||||
Bundle args = new Bundle();
|
||||
args.putParcelable(SYNCED_FOLDER_PARCELABLE, new SyncedFolderParcelable(syncedFolder, section));
|
||||
|
||||
SyncedFolderPreferencesDialogFragment dialogFragment = new SyncedFolderPreferencesDialogFragment();
|
||||
dialogFragment.setArguments(args);
|
||||
dialogFragment.setStyle(STYLE_NORMAL, R.style.Theme_ownCloud_Dialog);
|
||||
|
||||
|
||||
@@ -101,7 +101,7 @@ public class ExtendedListFragment extends Fragment
|
||||
private int maxColumnSizePortrait = 5;
|
||||
private int maxColumnSizeLandscape = 10;
|
||||
|
||||
private ScaleGestureDetector mScaleGestureDetector = null;
|
||||
private ScaleGestureDetector mScaleGestureDetector;
|
||||
protected SwipeRefreshLayout mRefreshListLayout;
|
||||
protected LinearLayout mEmptyListContainer;
|
||||
protected TextView mEmptyListMessage;
|
||||
@@ -115,9 +115,9 @@ public class ExtendedListFragment extends Fragment
|
||||
private ArrayList<Integer> mIndexes;
|
||||
private ArrayList<Integer> mFirstPositions;
|
||||
private ArrayList<Integer> mTops;
|
||||
private int mHeightCell = 0;
|
||||
private int mHeightCell;
|
||||
|
||||
private SwipeRefreshLayout.OnRefreshListener mOnRefreshListener = null;
|
||||
private SwipeRefreshLayout.OnRefreshListener mOnRefreshListener;
|
||||
|
||||
private EmptyRecyclerView mRecyclerView;
|
||||
|
||||
|
||||
@@ -508,10 +508,9 @@ public class FileDetailFragment extends FileFragment implements OnClickListener
|
||||
// configure UI for depending upon local state of the file
|
||||
FileDownloaderBinder downloaderBinder = mContainerActivity.getFileDownloaderBinder();
|
||||
FileUploaderBinder uploaderBinder = mContainerActivity.getFileUploaderBinder();
|
||||
if (transferring ||
|
||||
(downloaderBinder != null && downloaderBinder.isDownloading(account, file)) ||
|
||||
(uploaderBinder != null && uploaderBinder.isUploading(account, file))
|
||||
) {
|
||||
if (transferring
|
||||
|| (downloaderBinder != null && downloaderBinder.isDownloading(account, file))
|
||||
|| (uploaderBinder != null && uploaderBinder.isUploading(account, file))) {
|
||||
setButtonsForTransferring();
|
||||
|
||||
} else if (file.isDown()) {
|
||||
@@ -544,7 +543,7 @@ public class FileDetailFragment extends FileFragment implements OnClickListener
|
||||
* @return 'True' when the fragment is ready to show details of a file
|
||||
*/
|
||||
private boolean readyToShow() {
|
||||
return (getFile() != null && account != null && layout == R.layout.file_details_fragment);
|
||||
return getFile() != null && account != null && layout == R.layout.file_details_fragment;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -677,7 +676,7 @@ public class FileDetailFragment extends FileFragment implements OnClickListener
|
||||
* Helper class responsible for updating the progress bar shown for file downloading.
|
||||
*/
|
||||
private class ProgressListener implements OnDatatransferProgressListener {
|
||||
private int lastPercent = 0;
|
||||
private int lastPercent;
|
||||
private WeakReference<ProgressBar> progressBarReference;
|
||||
|
||||
ProgressListener(ProgressBar progressBar) {
|
||||
|
||||
@@ -54,6 +54,7 @@ import com.owncloud.android.lib.resources.shares.SharePermissionsBuilder;
|
||||
import com.owncloud.android.lib.resources.shares.ShareType;
|
||||
import com.owncloud.android.lib.resources.status.OCCapability;
|
||||
import com.owncloud.android.ui.activity.FileActivity;
|
||||
import com.owncloud.android.ui.activity.FileDisplayActivity;
|
||||
import com.owncloud.android.ui.adapter.UserListAdapter;
|
||||
import com.owncloud.android.ui.decoration.SimpleListItemDividerDecoration;
|
||||
import com.owncloud.android.ui.dialog.ExpirationDatePickerDialogFragment;
|
||||
@@ -235,24 +236,31 @@ public class FileDetailSharingFragment extends Fragment implements UserListAdapt
|
||||
@OnClick(R.id.share_by_link)
|
||||
public void toggleShareByLink() {
|
||||
if (shareByLink.isChecked()) {
|
||||
if (capabilities != null &&
|
||||
capabilities.getFilesSharingPublicPasswordEnforced().isTrue()) {
|
||||
// password enforced by server, request to the user before trying to create
|
||||
requestPasswordForShareViaLink(true);
|
||||
|
||||
} else {
|
||||
// create without password if not enforced by server or we don't know if enforced;
|
||||
((FileActivity) getActivity()).getFileOperationsHelper().shareFileViaLink(file, null);
|
||||
}
|
||||
|
||||
createShareLink();
|
||||
} else {
|
||||
((FileActivity) getActivity()).getFileOperationsHelper().unshareFileViaLink(file);
|
||||
}
|
||||
}
|
||||
|
||||
private void createShareLink() {
|
||||
if (capabilities != null &&
|
||||
capabilities.getFilesSharingPublicPasswordEnforced().isTrue()) {
|
||||
// password enforced by server, request to the user before trying to create
|
||||
requestPasswordForShareViaLink(true);
|
||||
|
||||
} else {
|
||||
// create without password if not enforced by server or we don't know if enforced;
|
||||
((FileActivity) getActivity()).getFileOperationsHelper().shareFileViaLink(file, null);
|
||||
}
|
||||
}
|
||||
|
||||
private void showSendLinkTo() {
|
||||
if (file.isSharedViaLink()) {
|
||||
((FileActivity) getActivity()).getFileOperationsHelper().getFileWithLink(file);
|
||||
if (TextUtils.isEmpty(file.getPublicLink())) {
|
||||
((FileActivity) getActivity()).getFileOperationsHelper().getFileWithLink(file);
|
||||
} else {
|
||||
((FileDisplayActivity) getActivity()).showShareLinkDialog(file.getPublicLink());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -260,7 +268,7 @@ public class FileDetailSharingFragment extends Fragment implements UserListAdapt
|
||||
public void copyLinkToClipboard() {
|
||||
if (file.isSharedViaLink()) {
|
||||
if (TextUtils.isEmpty(file.getPublicLink())) {
|
||||
showSendLinkTo();
|
||||
((FileActivity) getActivity()).getFileOperationsHelper().getFileWithLink(file);
|
||||
} else {
|
||||
ClipboardUtil.copyToClipboard(getActivity(), file.getPublicLink());
|
||||
}
|
||||
@@ -336,7 +344,11 @@ public class FileDetailSharingFragment extends Fragment implements UserListAdapt
|
||||
return true;
|
||||
}
|
||||
case R.id.action_share_send_link: {
|
||||
showSendLinkTo();
|
||||
if(shareByLink.isChecked() && file.isSharedViaLink() && !TextUtils.isEmpty(file.getPublicLink())) {
|
||||
((FileDisplayActivity) getActivity()).showShareLinkDialog(file.getPublicLink());
|
||||
} else {
|
||||
showSendLinkTo();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
default:
|
||||
|
||||
@@ -306,14 +306,14 @@ public class OCFileListFragment extends ExtendedListFragment implements
|
||||
}
|
||||
|
||||
Bundle args = getArguments();
|
||||
mOnlyFoldersClickable = (args != null) && args.getBoolean(ARG_ONLY_FOLDERS_CLICKABLE, false);
|
||||
boolean hideItemOptions = (args != null) && args.getBoolean(ARG_HIDE_ITEM_OPTIONS, false);
|
||||
mOnlyFoldersClickable = args != null && args.getBoolean(ARG_ONLY_FOLDERS_CLICKABLE, false);
|
||||
boolean hideItemOptions = args != null && args.getBoolean(ARG_HIDE_ITEM_OPTIONS, false);
|
||||
|
||||
mAdapter = new OCFileListAdapter(getActivity(), mContainerActivity, this, hideItemOptions,
|
||||
isGridViewPreferred(mFile));
|
||||
setRecyclerViewAdapter(mAdapter);
|
||||
|
||||
mHideFab = (args != null) && args.getBoolean(ARG_HIDE_FAB, false);
|
||||
mHideFab = args != null && args.getBoolean(ARG_HIDE_FAB, false);
|
||||
|
||||
if (mHideFab) {
|
||||
setFabEnabled(false);
|
||||
@@ -434,7 +434,7 @@ public class OCFileListFragment extends ExtendedListFragment implements
|
||||
/**
|
||||
* True when action mode is finished because the drawer was opened
|
||||
*/
|
||||
private boolean mActionModeClosedByDrawer = false;
|
||||
private boolean mActionModeClosedByDrawer;
|
||||
|
||||
/**
|
||||
* Selected items in list when action mode is closed by drawer
|
||||
@@ -1587,6 +1587,8 @@ public class OCFileListFragment extends ExtendedListFragment implements
|
||||
* Exits the multi file selection mode.
|
||||
*/
|
||||
public void exitSelectionMode() {
|
||||
mActiveActionMode.finish();
|
||||
if (mActiveActionMode != null) {
|
||||
mActiveActionMode.finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -32,7 +32,11 @@ import java.util.Date;
|
||||
/**
|
||||
* Helper calls for visibility logic of the sharing menu.
|
||||
*/
|
||||
public class SharingMenuHelper {
|
||||
public final class SharingMenuHelper {
|
||||
|
||||
private SharingMenuHelper() {
|
||||
// utility class -> private constructor
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets checked/visiblity state on the given {@link MenuItem} based on the given criteria.
|
||||
|
||||
@@ -343,7 +343,7 @@ public class FileOperationsHelper {
|
||||
return openFileWithIntent;
|
||||
}
|
||||
|
||||
private Uri getFileUri(OCFile file, String[] officeExtensions) {
|
||||
private Uri getFileUri(OCFile file, String... officeExtensions) {
|
||||
if (file.getFileName().contains(".") &&
|
||||
Arrays.asList(officeExtensions).contains(file.getFileName().substring(file.getFileName().
|
||||
lastIndexOf(".") + 1, file.getFileName().length())) &&
|
||||
|
||||
@@ -177,7 +177,7 @@ public class UriUploader {
|
||||
* @param sourceUris Array of content:// URIs to the files to upload
|
||||
* @param remotePaths Array of absolute paths to set to the uploaded files
|
||||
*/
|
||||
private void copyThenUpload(Uri[] sourceUris, String[] remotePaths) {
|
||||
private void copyThenUpload(Uri[] sourceUris, String... remotePaths) {
|
||||
if (mShowWaitingDialog) {
|
||||
mActivity.showLoadingDialog(mActivity.getResources().
|
||||
getString(R.string.wait_for_tmp_copy_from_private_storage));
|
||||
|
||||
@@ -32,7 +32,7 @@ import java.util.Random;
|
||||
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
|
||||
public class NotificationUtils {
|
||||
public final class NotificationUtils {
|
||||
|
||||
public static final String NOTIFICATION_CHANNEL_GENERAL = "NOTIFICATION_CHANNEL_GENERAL";
|
||||
public static final String NOTIFICATION_CHANNEL_DOWNLOAD = "NOTIFICATION_CHANNEL_DOWNLOAD";
|
||||
@@ -42,6 +42,10 @@ public class NotificationUtils {
|
||||
public static final String NOTIFICATION_CHANNEL_FILE_OBSERVER = "NOTIFICATION_CHANNEL_FILE_OBSERVER";
|
||||
public static final String NOTIFICATION_CHANNEL_PUSH = "NOTIFICATION_CHANNEL_PUSH";
|
||||
|
||||
private NotificationUtils() {
|
||||
// utility class -> private constructor
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method for {@link android.support.v4.app.NotificationCompat.Builder} instances.
|
||||
*
|
||||
|
||||
@@ -283,8 +283,8 @@ public class FileDownloadFragment extends FileFragment implements OnClickListene
|
||||
* Helper class responsible for updating the progress bar shown for file uploading or downloading
|
||||
*/
|
||||
private class ProgressListener implements OnDatatransferProgressListener {
|
||||
int mLastPercent = 0;
|
||||
WeakReference<ProgressBar> mProgressBar = null;
|
||||
int mLastPercent;
|
||||
WeakReference<ProgressBar> mProgressBar;
|
||||
|
||||
ProgressListener(ProgressBar progressBar) {
|
||||
mProgressBar = new WeakReference<>(progressBar);
|
||||
|
||||
@@ -145,7 +145,7 @@ public class PreviewImageActivity extends FileActivity implements
|
||||
mViewPager = findViewById(R.id.fragmentPager);
|
||||
|
||||
int position = mHasSavedPosition ? mSavedPosition : mPreviewImagePagerAdapter.getFilePosition(getFile());
|
||||
position = (position >= 0) ? position : 0;
|
||||
position = position >= 0 ? position : 0;
|
||||
|
||||
mViewPager.setAdapter(mPreviewImagePagerAdapter);
|
||||
mViewPager.addOnPageChangeListener(this);
|
||||
|
||||
@@ -65,6 +65,7 @@ import com.owncloud.android.ui.dialog.RemoveFilesDialogFragment;
|
||||
import com.owncloud.android.ui.fragment.FileFragment;
|
||||
import com.owncloud.android.utils.BitmapUtils;
|
||||
import com.owncloud.android.utils.DisplayUtils;
|
||||
import com.owncloud.android.utils.MimeType;
|
||||
import com.owncloud.android.utils.MimeTypeUtil;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
@@ -113,7 +114,7 @@ public class PreviewImageFragment extends FileFragment {
|
||||
|
||||
private boolean mIgnoreFirstSavedState;
|
||||
|
||||
private LoadBitmapTask mLoadBitmapTask = null;
|
||||
private LoadBitmapTask mLoadBitmapTask;
|
||||
|
||||
/**
|
||||
* Public factory method to create a new fragment that previews an image.
|
||||
@@ -439,12 +440,12 @@ public class PreviewImageFragment extends FileFragment {
|
||||
protected LoadImage doInBackground(OCFile... params) {
|
||||
Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND + Process.THREAD_PRIORITY_MORE_FAVORABLE);
|
||||
|
||||
Bitmap bitmapResult = null;
|
||||
Drawable drawableResult = null;
|
||||
|
||||
if (params.length != 1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Bitmap bitmapResult = null;
|
||||
Drawable drawableResult = null;
|
||||
OCFile ocFile = params[0];
|
||||
String storagePath = ocFile.getStoragePath();
|
||||
try {
|
||||
@@ -492,7 +493,7 @@ public class PreviewImageFragment extends FileFragment {
|
||||
Log_OC.e(TAG, "File could not be loaded as a bitmap: " + storagePath);
|
||||
break;
|
||||
} else {
|
||||
if ("image/jpeg".equalsIgnoreCase(ocFile.getMimeType())) {
|
||||
if (MimeType.JPEG.equalsIgnoreCase(ocFile.getMimeType())) {
|
||||
// Rotate image, obeying exif tag.
|
||||
bitmapResult = BitmapUtils.rotateImage(bitmapResult, storagePath);
|
||||
}
|
||||
|
||||
@@ -804,7 +804,7 @@ public class PreviewMediaFragment extends FileFragment implements
|
||||
* @return 'True' if the file can be handled by the fragment.
|
||||
*/
|
||||
public static boolean canBePreviewed(OCFile file) {
|
||||
return (file != null && (MimeTypeUtil.isAudio(file) || MimeTypeUtil.isVideo(file)));
|
||||
return file != null && (MimeTypeUtil.isAudio(file) || MimeTypeUtil.isVideo(file));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -41,9 +41,12 @@ import java.util.Locale;
|
||||
/**
|
||||
* Utility class with methods for decoding Bitmaps.
|
||||
*/
|
||||
public class BitmapUtils {
|
||||
public final class BitmapUtils {
|
||||
public static final String TAG = BitmapUtils.class.getSimpleName();
|
||||
|
||||
private BitmapUtils() {
|
||||
// utility class -> private constructor
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes a bitmap from a file containing it minimizing the memory use, known that the bitmap
|
||||
@@ -257,7 +260,7 @@ public class BitmapUtils {
|
||||
}
|
||||
|
||||
if (3 * h < 2) {
|
||||
return p + ((q - p) * 6 * ((2.0f / 3.0f) - h));
|
||||
return p + ((q - p) * 6 * (2.0f / 3.0f - h));
|
||||
}
|
||||
|
||||
return p;
|
||||
@@ -376,8 +379,6 @@ public class BitmapUtils {
|
||||
}
|
||||
|
||||
public static Bitmap drawableToBitmap(Drawable drawable) {
|
||||
Bitmap bitmap;
|
||||
|
||||
if (drawable instanceof BitmapDrawable) {
|
||||
BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
|
||||
if (bitmapDrawable.getBitmap() != null) {
|
||||
@@ -385,6 +386,7 @@ public class BitmapUtils {
|
||||
}
|
||||
}
|
||||
|
||||
Bitmap bitmap;
|
||||
if (drawable.getIntrinsicWidth() <= 0 || drawable.getIntrinsicHeight() <= 0) {
|
||||
bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
|
||||
} else {
|
||||
|
||||
@@ -39,6 +39,10 @@ public class ClipboardUtil {
|
||||
}
|
||||
|
||||
public static void copyToClipboard(Activity activity, String text) {
|
||||
copyToClipboard(activity, text, true);
|
||||
}
|
||||
|
||||
public static void copyToClipboard(Activity activity, String text, boolean showToast) {
|
||||
if (text != null && text.length() > 0) {
|
||||
try {
|
||||
ClipData clip = ClipData.newPlainText(
|
||||
@@ -48,7 +52,9 @@ public class ClipboardUtil {
|
||||
);
|
||||
((ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE)).setPrimaryClip(clip);
|
||||
|
||||
Toast.makeText(activity, R.string.clipboard_text_copied, Toast.LENGTH_SHORT).show();
|
||||
if (showToast) {
|
||||
Toast.makeText(activity, R.string.clipboard_text_copied, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Toast.makeText(activity, R.string.clipboard_unexpected_error, Toast.LENGTH_SHORT).show();
|
||||
Log_OC.e(TAG, "Exception caught while copying to clipboard", e);
|
||||
|
||||
@@ -44,10 +44,14 @@ import org.json.JSONObject;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class ConnectivityUtils {
|
||||
public final class ConnectivityUtils {
|
||||
|
||||
private final static String TAG = ConnectivityUtils.class.getName();
|
||||
|
||||
private ConnectivityUtils() {
|
||||
// utility class -> private constructor
|
||||
}
|
||||
|
||||
public static boolean isInternetWalled(Context context) {
|
||||
if (isOnlineWithWifi(context)) {
|
||||
try {
|
||||
|
||||
@@ -28,7 +28,11 @@ import java.security.KeyPair;
|
||||
* Own parts are licensed unter GPLv3+.
|
||||
*/
|
||||
|
||||
public class CsrHelper {
|
||||
public final class CsrHelper {
|
||||
|
||||
private CsrHelper() {
|
||||
// utility class -> private constructor
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate CSR with PEM encoding
|
||||
|
||||
@@ -53,7 +53,7 @@ import javax.crypto.SecretKey;
|
||||
* Utility class with methods for handling device credentials.
|
||||
*/
|
||||
@RequiresApi(Build.VERSION_CODES.M)
|
||||
public class DeviceCredentialUtils {
|
||||
public final class DeviceCredentialUtils {
|
||||
|
||||
private static final String TAG = DeviceCredentialUtils.class.getSimpleName();
|
||||
|
||||
@@ -61,6 +61,10 @@ public class DeviceCredentialUtils {
|
||||
|
||||
private static final String ANDROID_KEY_STORE = "AndroidKeyStore";
|
||||
|
||||
private DeviceCredentialUtils() {
|
||||
// utility class -> private constructor
|
||||
}
|
||||
|
||||
public static boolean areCredentialsAvailable(Context context) {
|
||||
KeyguardManager keyguardManager = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
|
||||
|
||||
|
||||
@@ -27,7 +27,6 @@ package com.owncloud.android.utils;
|
||||
import android.accounts.Account;
|
||||
import android.accounts.AccountManager;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@@ -103,7 +102,7 @@ import java.util.Set;
|
||||
/**
|
||||
* A helper class for UI/display related operations.
|
||||
*/
|
||||
public class DisplayUtils {
|
||||
public final class DisplayUtils {
|
||||
private static final String TAG = DisplayUtils.class.getSimpleName();
|
||||
|
||||
private static final String[] sizeSuffixes = {"B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"};
|
||||
@@ -132,6 +131,10 @@ public class DisplayUtils {
|
||||
mimeType2HumanReadable.put("application/ogg", "OGG music file");
|
||||
}
|
||||
|
||||
private DisplayUtils() {
|
||||
// utility class -> private constructor
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the file size in bytes to human readable output.
|
||||
* <ul>
|
||||
@@ -241,7 +244,6 @@ public class DisplayUtils {
|
||||
* @param toASCII if true converts from Unicode to ASCII, if false converts from ASCII to Unicode
|
||||
* @return the URL containing the converted domain name
|
||||
*/
|
||||
@TargetApi(Build.VERSION_CODES.GINGERBREAD)
|
||||
public static String convertIdn(String url, boolean toASCII) {
|
||||
|
||||
String urlNoDots = url;
|
||||
@@ -261,7 +263,7 @@ public class DisplayUtils {
|
||||
|
||||
int hostEnd = url.substring(hostStart).indexOf("/");
|
||||
// Handle URL which doesn't have a path (path is implicitly '/')
|
||||
hostEnd = (hostEnd == -1 ? urlNoDots.length() : hostStart + hostEnd);
|
||||
hostEnd = hostEnd == -1 ? urlNoDots.length() : hostStart + hostEnd;
|
||||
|
||||
String host = urlNoDots.substring(hostStart, hostEnd);
|
||||
host = toASCII ? IDN.toASCII(host) : IDN.toUnicode(host);
|
||||
@@ -733,7 +735,7 @@ public class DisplayUtils {
|
||||
// Copied from https://raw.githubusercontent.com/nextcloud/talk-android/8ec8606bc61878e87e3ac8ad32c8b72d4680013c/app/src/main/java/com/nextcloud/talk/utils/DisplayUtils.java
|
||||
// under GPL3
|
||||
public static void useCompatVectorIfNeeded() {
|
||||
if (Build.VERSION.SDK_INT < 23) {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
|
||||
try {
|
||||
@SuppressLint("RestrictedApi") AppCompatDrawableManager drawableManager = AppCompatDrawableManager.get();
|
||||
Class<?> inflateDelegateClass = Class.forName("android.support.v7.widget.AppCompatDrawableManager$InflateDelegate");
|
||||
|
||||
@@ -57,7 +57,6 @@ import java.security.KeyPair;
|
||||
import java.security.KeyPairGenerator;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.NoSuchProviderException;
|
||||
import java.security.PrivateKey;
|
||||
import java.security.PublicKey;
|
||||
import java.security.SecureRandom;
|
||||
@@ -65,7 +64,6 @@ import java.security.cert.CertificateException;
|
||||
import java.security.cert.CertificateFactory;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.security.spec.InvalidKeySpecException;
|
||||
import java.security.spec.InvalidParameterSpecException;
|
||||
import java.security.spec.KeySpec;
|
||||
import java.security.spec.PKCS8EncodedKeySpec;
|
||||
import java.util.ArrayList;
|
||||
@@ -80,7 +78,6 @@ import javax.crypto.KeyGenerator;
|
||||
import javax.crypto.NoSuchPaddingException;
|
||||
import javax.crypto.SecretKey;
|
||||
import javax.crypto.SecretKeyFactory;
|
||||
import javax.crypto.ShortBufferException;
|
||||
import javax.crypto.spec.GCMParameterSpec;
|
||||
import javax.crypto.spec.IvParameterSpec;
|
||||
import javax.crypto.spec.PBEKeySpec;
|
||||
@@ -90,7 +87,7 @@ import javax.crypto.spec.SecretKeySpec;
|
||||
* Utils for encryption
|
||||
*/
|
||||
|
||||
public class EncryptionUtils {
|
||||
public final class EncryptionUtils {
|
||||
private static String TAG = EncryptionUtils.class.getSimpleName();
|
||||
|
||||
public static final String PUBLIC_KEY = "PUBLIC_KEY";
|
||||
@@ -98,6 +95,7 @@ public class EncryptionUtils {
|
||||
public static final String MNEMONIC = "MNEMONIC";
|
||||
public static final int ivLength = 16;
|
||||
public static final int saltLength = 40;
|
||||
public static final String HASH_DELIMITER = "$";
|
||||
|
||||
private static final String ivDelimiter = "fA=="; // "|" base64 encoded
|
||||
private static final int iterationCount = 1024;
|
||||
@@ -107,6 +105,10 @@ public class EncryptionUtils {
|
||||
private static final String RSA_CIPHER = "RSA/ECB/OAEPWithSHA-256AndMGF1Padding";
|
||||
private static final String RSA = "RSA";
|
||||
|
||||
private EncryptionUtils() {
|
||||
// utility class -> private constructor
|
||||
}
|
||||
|
||||
/*
|
||||
JSON
|
||||
*/
|
||||
@@ -132,9 +134,9 @@ public class EncryptionUtils {
|
||||
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
|
||||
public static EncryptedFolderMetadata encryptFolderMetadata(DecryptedFolderMetadata decryptedFolderMetadata,
|
||||
String privateKey)
|
||||
throws IOException, NoSuchAlgorithmException, ShortBufferException, InvalidKeyException,
|
||||
throws NoSuchAlgorithmException, InvalidKeyException,
|
||||
InvalidAlgorithmParameterException, NoSuchPaddingException, BadPaddingException,
|
||||
NoSuchProviderException, IllegalBlockSizeException, InvalidKeySpecException, CertificateException {
|
||||
IllegalBlockSizeException, InvalidKeySpecException {
|
||||
|
||||
HashMap<String, EncryptedFolderMetadata.EncryptedFile> files = new HashMap<>();
|
||||
EncryptedFolderMetadata encryptedFolderMetadata = new EncryptedFolderMetadata(decryptedFolderMetadata
|
||||
@@ -171,9 +173,9 @@ public class EncryptionUtils {
|
||||
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
|
||||
public static DecryptedFolderMetadata decryptFolderMetaData(EncryptedFolderMetadata encryptedFolderMetadata,
|
||||
String privateKey)
|
||||
throws IOException, NoSuchAlgorithmException, ShortBufferException, InvalidKeyException,
|
||||
throws NoSuchAlgorithmException, InvalidKeyException,
|
||||
InvalidAlgorithmParameterException, NoSuchPaddingException, BadPaddingException,
|
||||
NoSuchProviderException, IllegalBlockSizeException, CertificateException, InvalidKeySpecException {
|
||||
IllegalBlockSizeException, InvalidKeySpecException {
|
||||
|
||||
HashMap<String, DecryptedFolderMetadata.DecryptedFile> files = new HashMap<>();
|
||||
DecryptedFolderMetadata decryptedFolderMetadata = new DecryptedFolderMetadata(
|
||||
@@ -278,9 +280,9 @@ public class EncryptionUtils {
|
||||
*/
|
||||
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
|
||||
public static EncryptedFile encryptFile(OCFile ocFile, byte[] encryptionKeyBytes, byte[] iv)
|
||||
throws NoSuchProviderException, NoSuchAlgorithmException,
|
||||
throws NoSuchAlgorithmException,
|
||||
InvalidAlgorithmParameterException, NoSuchPaddingException, InvalidKeyException,
|
||||
BadPaddingException, IllegalBlockSizeException, IOException, ShortBufferException {
|
||||
BadPaddingException, IllegalBlockSizeException, IOException {
|
||||
File file = new File(ocFile.getStoragePath());
|
||||
|
||||
return encryptFile(file, encryptionKeyBytes, iv);
|
||||
@@ -294,9 +296,9 @@ public class EncryptionUtils {
|
||||
*/
|
||||
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
|
||||
public static EncryptedFile encryptFile(File file, byte[] encryptionKeyBytes, byte[] iv)
|
||||
throws NoSuchProviderException, NoSuchAlgorithmException,
|
||||
throws NoSuchAlgorithmException,
|
||||
InvalidAlgorithmParameterException, NoSuchPaddingException, InvalidKeyException,
|
||||
BadPaddingException, IllegalBlockSizeException, IOException, ShortBufferException {
|
||||
BadPaddingException, IllegalBlockSizeException, IOException {
|
||||
|
||||
Cipher cipher = Cipher.getInstance(AES_CIPHER);
|
||||
|
||||
@@ -325,9 +327,9 @@ public class EncryptionUtils {
|
||||
*/
|
||||
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
|
||||
public static byte[] decryptFile(File file, byte[] encryptionKeyBytes, byte[] iv, byte[] authenticationTag)
|
||||
throws NoSuchProviderException, NoSuchAlgorithmException,
|
||||
throws NoSuchAlgorithmException,
|
||||
InvalidAlgorithmParameterException, NoSuchPaddingException, InvalidKeyException,
|
||||
BadPaddingException, IllegalBlockSizeException, IOException, ShortBufferException {
|
||||
BadPaddingException, IllegalBlockSizeException, IOException {
|
||||
|
||||
|
||||
Cipher cipher = Cipher.getInstance(AES_CIPHER);
|
||||
@@ -370,9 +372,9 @@ public class EncryptionUtils {
|
||||
*/
|
||||
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
|
||||
public static String encryptStringAsymmetric(String string, String cert)
|
||||
throws NoSuchProviderException, NoSuchAlgorithmException,
|
||||
InvalidAlgorithmParameterException, NoSuchPaddingException, InvalidKeyException,
|
||||
BadPaddingException, IllegalBlockSizeException, IOException, ShortBufferException, InvalidKeySpecException,
|
||||
throws NoSuchAlgorithmException,
|
||||
NoSuchPaddingException, InvalidKeyException,
|
||||
BadPaddingException, IllegalBlockSizeException, IOException,
|
||||
CertificateException {
|
||||
|
||||
Cipher cipher = Cipher.getInstance(RSA_CIPHER);
|
||||
@@ -406,9 +408,9 @@ public class EncryptionUtils {
|
||||
*/
|
||||
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
|
||||
public static String decryptStringAsymmetric(String string, String privateKeyString)
|
||||
throws NoSuchProviderException, NoSuchAlgorithmException,
|
||||
InvalidAlgorithmParameterException, NoSuchPaddingException, InvalidKeyException,
|
||||
BadPaddingException, IllegalBlockSizeException, IOException, ShortBufferException, CertificateException,
|
||||
throws NoSuchAlgorithmException,
|
||||
NoSuchPaddingException, InvalidKeyException,
|
||||
BadPaddingException, IllegalBlockSizeException,
|
||||
InvalidKeySpecException {
|
||||
|
||||
Cipher cipher = Cipher.getInstance(RSA_CIPHER);
|
||||
@@ -437,10 +439,9 @@ public class EncryptionUtils {
|
||||
*/
|
||||
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
|
||||
public static String encryptStringSymmetric(String string, byte[] encryptionKeyBytes)
|
||||
throws NoSuchProviderException, NoSuchAlgorithmException,
|
||||
throws NoSuchAlgorithmException,
|
||||
InvalidAlgorithmParameterException, NoSuchPaddingException, InvalidKeyException,
|
||||
BadPaddingException, IllegalBlockSizeException, IOException, ShortBufferException, InvalidKeySpecException,
|
||||
CertificateException {
|
||||
BadPaddingException, IllegalBlockSizeException {
|
||||
|
||||
Cipher cipher = Cipher.getInstance(AES_CIPHER);
|
||||
byte[] iv = randomBytes(ivLength);
|
||||
@@ -469,10 +470,9 @@ public class EncryptionUtils {
|
||||
*/
|
||||
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
|
||||
public static String decryptStringSymmetric(String string, byte[] encryptionKeyBytes)
|
||||
throws NoSuchProviderException, NoSuchAlgorithmException,
|
||||
throws NoSuchAlgorithmException,
|
||||
InvalidAlgorithmParameterException, NoSuchPaddingException, InvalidKeyException,
|
||||
BadPaddingException, IllegalBlockSizeException, IOException, ShortBufferException, CertificateException,
|
||||
InvalidKeySpecException {
|
||||
BadPaddingException, IllegalBlockSizeException {
|
||||
|
||||
Cipher cipher = Cipher.getInstance(AES_CIPHER);
|
||||
|
||||
@@ -502,8 +502,8 @@ public class EncryptionUtils {
|
||||
* @return encrypted string, bytes first encoded base64, IV separated with "|", then to string
|
||||
*/
|
||||
public static String encryptPrivateKey(String privateKey, String keyPhrase) throws NoSuchPaddingException,
|
||||
NoSuchAlgorithmException, NoSuchProviderException, InvalidKeyException, BadPaddingException,
|
||||
IllegalBlockSizeException, InvalidKeySpecException, InvalidParameterSpecException {
|
||||
NoSuchAlgorithmException, InvalidKeyException, BadPaddingException,
|
||||
IllegalBlockSizeException, InvalidKeySpecException {
|
||||
Cipher cipher = Cipher.getInstance(AES_CIPHER);
|
||||
|
||||
SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
|
||||
@@ -533,7 +533,7 @@ public class EncryptionUtils {
|
||||
* @return decrypted string
|
||||
*/
|
||||
public static String decryptPrivateKey(String privateKey, String keyPhrase) throws NoSuchPaddingException,
|
||||
NoSuchAlgorithmException, NoSuchProviderException, InvalidKeyException, BadPaddingException,
|
||||
NoSuchAlgorithmException, InvalidKeyException, BadPaddingException,
|
||||
IllegalBlockSizeException, InvalidKeySpecException, InvalidAlgorithmParameterException {
|
||||
|
||||
// split up iv, salt
|
||||
@@ -559,7 +559,7 @@ public class EncryptionUtils {
|
||||
.replace("-----END PRIVATE KEY-----", "");
|
||||
}
|
||||
|
||||
public static String privateKeyToPEM(PrivateKey privateKey) throws IOException {
|
||||
public static String privateKeyToPEM(PrivateKey privateKey) {
|
||||
String privateKeyString = encodeBytesToBase64String(privateKey.getEncoded());
|
||||
|
||||
return "-----BEGIN PRIVATE KEY-----\n" + privateKeyString.replaceAll("(.{65})", "$1\n")
|
||||
@@ -642,4 +642,55 @@ public class EncryptionUtils {
|
||||
|
||||
return iv;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a SHA512 with appended salt
|
||||
*
|
||||
* @param token token to be hashed
|
||||
* @return SHA512 with appended salt, delimiter HASH_DELIMITER
|
||||
*/
|
||||
public static String generateSHA512(String token) {
|
||||
String salt = EncryptionUtils.encodeBytesToBase64String(EncryptionUtils.randomBytes(EncryptionUtils.saltLength));
|
||||
|
||||
return generateSHA512(token, salt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a SHA512 with appended salt
|
||||
*
|
||||
* @param token token to be hashed
|
||||
* @return SHA512 with appended salt, delimiter HASH_DELIMITER
|
||||
*/
|
||||
public static String generateSHA512(String token, String salt) {
|
||||
MessageDigest digest;
|
||||
String hashedToken = "";
|
||||
byte[] hash;
|
||||
try {
|
||||
digest = MessageDigest.getInstance("SHA-512");
|
||||
digest.update(salt.getBytes());
|
||||
hash = digest.digest(token.getBytes());
|
||||
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
for (byte hashByte : hash) {
|
||||
stringBuilder.append(Integer.toString((hashByte & 0xff) + 0x100, 16).substring(1));
|
||||
}
|
||||
|
||||
stringBuilder.append(HASH_DELIMITER).append(salt);
|
||||
|
||||
hashedToken = stringBuilder.toString();
|
||||
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
Log_OC.e(TAG, "Generating SHA512 failed", e);
|
||||
}
|
||||
|
||||
return hashedToken;
|
||||
}
|
||||
|
||||
public static boolean verifySHA512(String hashWithSalt, String compareToken) {
|
||||
String salt = hashWithSalt.split("\\" + HASH_DELIMITER)[1];
|
||||
|
||||
String newHash = generateSHA512(compareToken, salt);
|
||||
|
||||
return hashWithSalt.equals(newHash);
|
||||
}
|
||||
}
|
||||
@@ -53,7 +53,12 @@ import java.net.SocketTimeoutException;
|
||||
* Class to choose proper error messages to show to the user depending on the results of operations,
|
||||
* always following the same policy
|
||||
*/
|
||||
public class ErrorMessageAdapter {
|
||||
public final class ErrorMessageAdapter {
|
||||
|
||||
private ErrorMessageAdapter() {
|
||||
// utility class -> private constructor
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an internationalized user message corresponding to an operation result
|
||||
* and the operation performed.
|
||||
|
||||
@@ -50,11 +50,15 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
/**
|
||||
* Static methods to help in access to local file system.
|
||||
*/
|
||||
public class FileStorageUtils {
|
||||
public final class FileStorageUtils {
|
||||
private static final String TAG = FileStorageUtils.class.getSimpleName();
|
||||
|
||||
public static final String PATTERN_YYYY_MM = "yyyy/MM/";
|
||||
|
||||
private FileStorageUtils() {
|
||||
// utility class -> private constructor
|
||||
}
|
||||
|
||||
/**
|
||||
* Get local owncloud storage path for accountName.
|
||||
*/
|
||||
|
||||
@@ -63,10 +63,10 @@ import java.io.IOException;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/*
|
||||
Various utilities that make auto upload tick
|
||||
/**
|
||||
* Various utilities that make auto upload tick
|
||||
*/
|
||||
public class FilesSyncHelper {
|
||||
public final class FilesSyncHelper {
|
||||
public static final String TAG = "FileSyncHelper";
|
||||
|
||||
public static final String GLOBAL = "global";
|
||||
@@ -74,6 +74,10 @@ public class FilesSyncHelper {
|
||||
|
||||
public static final int ContentSyncJobId = 315;
|
||||
|
||||
private FilesSyncHelper() {
|
||||
// utility class -> private constructor
|
||||
}
|
||||
|
||||
public static void insertAllDBEntriesForSyncedFolder(SyncedFolder syncedFolder) {
|
||||
final Context context = MainApp.getAppContext();
|
||||
final ContentResolver contentResolver = context.getContentResolver();
|
||||
|
||||
@@ -22,4 +22,7 @@ package com.owncloud.android.utils;
|
||||
*/
|
||||
public class MimeType {
|
||||
public static final String DIRECTORY = "DIR";
|
||||
public static final String JPEG = "image/jpeg";
|
||||
public static final String TIFF = "image/tiff";
|
||||
public static final String TEXT_PLAIN = "text/plain";
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
/**
|
||||
/*
|
||||
* ownCloud Android client application
|
||||
* <p>
|
||||
* Copyright (C) 2016 ownCloud Inc.
|
||||
@@ -64,7 +64,7 @@ import javax.annotation.Nullable;
|
||||
* </ol>
|
||||
*/
|
||||
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
|
||||
public class MimeTypeUtil {
|
||||
public final class MimeTypeUtil {
|
||||
/** Mapping: icon for mime type */
|
||||
private static final Map<String, Integer> MIMETYPE_TO_ICON_MAPPING = new HashMap<>();
|
||||
/** Mapping: icon for main mime type (first part of a mime type declaration). */
|
||||
@@ -78,6 +78,10 @@ public class MimeTypeUtil {
|
||||
populateMainMimeTypeMapping();
|
||||
}
|
||||
|
||||
private MimeTypeUtil() {
|
||||
// utility class -> private constructor
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Drawable of an image to use as icon associated to a known MIME type.
|
||||
*
|
||||
@@ -196,29 +200,29 @@ public class MimeTypeUtil {
|
||||
* @return 'True' if the mime type defines image
|
||||
*/
|
||||
public static boolean isImage(String mimeType) {
|
||||
return (mimeType != null && mimeType.toLowerCase(Locale.ROOT).startsWith("image/") &&
|
||||
!mimeType.toLowerCase(Locale.ROOT).contains("djvu"));
|
||||
return mimeType != null && mimeType.toLowerCase(Locale.ROOT).startsWith("image/") &&
|
||||
!mimeType.toLowerCase(Locale.ROOT).contains("djvu");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 'True' the mime type defines video
|
||||
*/
|
||||
public static boolean isVideo(String mimeType) {
|
||||
return (mimeType != null && mimeType.toLowerCase(Locale.ROOT).startsWith("video/"));
|
||||
return mimeType != null && mimeType.toLowerCase(Locale.ROOT).startsWith("video/");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 'True' the mime type defines audio
|
||||
*/
|
||||
public static boolean isAudio(String mimeType) {
|
||||
return (mimeType != null && mimeType.toLowerCase(Locale.ROOT).startsWith("audio/"));
|
||||
return mimeType != null && mimeType.toLowerCase(Locale.ROOT).startsWith("audio/");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 'True' if mime type defines text
|
||||
*/
|
||||
public static boolean isText(String mimeType) {
|
||||
return (mimeType != null && mimeType.toLowerCase(Locale.ROOT).startsWith("text/"));
|
||||
return mimeType != null && mimeType.toLowerCase(Locale.ROOT).startsWith("text/");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -273,8 +277,8 @@ public class MimeTypeUtil {
|
||||
* @return 'True' if the file contains an image
|
||||
*/
|
||||
public static boolean isImage(ServerFileInterface file) {
|
||||
return (MimeTypeUtil.isImage(file.getMimeType())
|
||||
|| MimeTypeUtil.isImage(getMimeTypeFromPath(file.getRemotePath())));
|
||||
return MimeTypeUtil.isImage(file.getMimeType())
|
||||
|| MimeTypeUtil.isImage(getMimeTypeFromPath(file.getRemotePath()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -9,12 +9,16 @@ import android.support.v4.content.ContextCompat;
|
||||
/**
|
||||
* Created by scherzia on 29.12.2015.
|
||||
*/
|
||||
public class PermissionUtil {
|
||||
public final class PermissionUtil {
|
||||
public static final int PERMISSIONS_WRITE_EXTERNAL_STORAGE = 1;
|
||||
public static final int PERMISSIONS_READ_CONTACTS_AUTOMATIC = 2;
|
||||
public static final int PERMISSIONS_READ_CONTACTS_MANUALLY = 3;
|
||||
public static final int PERMISSIONS_WRITE_CONTACTS = 4;
|
||||
|
||||
private PermissionUtil() {
|
||||
// utility class -> private constructor
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper method for ContextCompat.checkSelfPermission().
|
||||
* Determine whether <em>the app</em> has been granted a particular permission.
|
||||
|
||||
@@ -5,7 +5,11 @@ import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.os.PowerManager;
|
||||
|
||||
public class PowerUtils {
|
||||
public final class PowerUtils {
|
||||
|
||||
private PowerUtils() {
|
||||
// utility class -> private constructor
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if device is in power save mode. For older devices that do not support this API, returns false.
|
||||
|
||||
@@ -29,10 +29,14 @@ import com.evernote.android.job.JobRequest;
|
||||
import com.evernote.android.job.util.Device;
|
||||
import com.owncloud.android.MainApp;
|
||||
|
||||
/*
|
||||
Helper for setting up network and power receivers
|
||||
/**
|
||||
* Helper for setting up network and power receivers
|
||||
*/
|
||||
public class ReceiversHelper {
|
||||
public final class ReceiversHelper {
|
||||
|
||||
private ReceiversHelper() {
|
||||
// utility class -> private constructor
|
||||
}
|
||||
|
||||
public static void registerNetworkChangeReceiver() {
|
||||
Context context = MainApp.getAppContext();
|
||||
|
||||
@@ -62,7 +62,11 @@ import com.owncloud.android.ui.activity.ToolbarActivity;
|
||||
/**
|
||||
* Utility class with methods for client side theming.
|
||||
*/
|
||||
public class ThemeUtils {
|
||||
public final class ThemeUtils {
|
||||
|
||||
private ThemeUtils() {
|
||||
// utility class -> private constructor
|
||||
}
|
||||
|
||||
public static int primaryAccentColor(Context context) {
|
||||
OCCapability capability = getCapability(context);
|
||||
|
||||
@@ -40,12 +40,15 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
/**
|
||||
* A helper class for some Uri operations.
|
||||
*/
|
||||
public class UriUtils {
|
||||
public final class UriUtils {
|
||||
|
||||
public static final String TAG = UriUtils.class.getSimpleName();
|
||||
|
||||
public static final String URI_CONTENT_SCHEME = "content://";
|
||||
|
||||
private UriUtils() {
|
||||
// utility class -> private constructor
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of the data column for this Uri. This is useful for
|
||||
@@ -57,7 +60,7 @@ public class UriUtils {
|
||||
* @param selectionArgs (Optional) Selection arguments used in the query.
|
||||
* @return The value of the _data column, which is typically a file path.
|
||||
*/
|
||||
public static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) {
|
||||
public static String getDataColumn(Context context, Uri uri, String selection, String... selectionArgs) {
|
||||
|
||||
Cursor cursor = null;
|
||||
final String column = "_data";
|
||||
@@ -150,7 +153,7 @@ public class UriUtils {
|
||||
final Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"),
|
||||
Long.valueOf(id));
|
||||
|
||||
return UriUtils.getDataColumn(context, contentUri, null, null);
|
||||
return UriUtils.getDataColumn(context, contentUri, null, (String) null);
|
||||
}
|
||||
// MediaProvider
|
||||
else if (UriUtils.isMediaDocument(uri)) {
|
||||
@@ -185,7 +188,7 @@ public class UriUtils {
|
||||
return uri.getLastPathSegment();
|
||||
}
|
||||
|
||||
return UriUtils.getDataColumn(context, uri, null, null);
|
||||
return UriUtils.getDataColumn(context, uri, null, (String) null);
|
||||
}
|
||||
// File
|
||||
else if ("file".equalsIgnoreCase(uri.getScheme())) {
|
||||
|
||||
@@ -37,7 +37,7 @@ public class FileCursor extends MatrixCursor {
|
||||
Document.COLUMN_FLAGS, Document.COLUMN_LAST_MODIFIED
|
||||
};
|
||||
|
||||
public FileCursor(String[] projection) {
|
||||
public FileCursor(String... projection) {
|
||||
super(projection != null ? projection : DEFAULT_DOCUMENT_PROJECTION);
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ public class RootCursor extends MatrixCursor {
|
||||
Root.COLUMN_FLAGS
|
||||
};
|
||||
|
||||
public RootCursor(String[] projection) {
|
||||
public RootCursor(String... projection) {
|
||||
super(projection != null ? projection : DEFAULT_ROOT_PROJECTION);
|
||||
}
|
||||
|
||||
|
||||
Loaded 100 of 117 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user