Merge branch 'master' into crashDueToEmptyString

This commit is contained in:
Tobias Kaminsky 2017-05-18 16:16:45 +02:00 committed by GitHub
commit 332d48abac
10 changed files with 127 additions and 209 deletions

View file

@ -22,4 +22,8 @@ package com.owncloud.android.utils;
public class PushUtils {
public static final String KEY_PUSH = "push";
public static void pushRegistrationToServer() {
// do nothing
}
}

View file

@ -33,17 +33,6 @@
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity
android:name=".ui.activity.ModifiedFileDisplayActivity"
android:label="@string/app_name"
android:theme="@style/Theme.ownCloud.Toolbar.Drawer">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".authentication.ModifiedAuthenticatorActivity"
android:exported="true"
@ -70,15 +59,6 @@
</intent-filter>
</activity>
<activity
android:name=".ui.activity.FileDisplayActivity"
tools:node="remove"/>
<activity-alias
android:name=".ui.activity.FileDisplayActivity"
android:targetActivity=".ui.activity.ModifiedFileDisplayActivity"
tools:replace="android:targetActivity"/>
<activity-alias
android:name=".authentication.AuthenticatorActivity"
android:targetActivity=".authentication.ModifiedAuthenticatorActivity"

View file

@ -1,46 +0,0 @@
/**
* Nextcloud Android client application
*
* @author Mario Danic
* Copyright (C) 2017 Mario Danic
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.owncloud.android.ui.activity;
import android.os.Bundle;
import com.owncloud.android.ui.events.TokenPushEvent;
import com.owncloud.android.utils.PushUtils;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
public class ModifiedFileDisplayActivity extends FileDisplayActivity {
@Subscribe(threadMode = ThreadMode.BACKGROUND)
public void onMessageEvent(TokenPushEvent event) {
PushUtils.pushRegistrationToServer();
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// see if there's stuff to push every time we start the app
EventBus.getDefault().post(new TokenPushEvent());
}
}

View file

@ -76,7 +76,7 @@ public class PushUtils {
private static ArbitraryDataProvider arbitraryDataProvider;
private static String generateSHA512Hash(String pushToken) {
public static String generateSHA512Hash(String pushToken) {
MessageDigest messageDigest = null;
try {
messageDigest = MessageDigest.getInstance("SHA-512");
@ -88,7 +88,7 @@ public class PushUtils {
return "";
}
private static String bytesToHex(byte[] bytes) {
public static String bytesToHex(byte[] bytes) {
StringBuilder result = new StringBuilder();
for (byte individualByte : bytes) {
result.append(Integer.toString((individualByte & 0xff) + 0x100, 16)
@ -202,12 +202,20 @@ public class PushUtils {
Context context = MainApp.getAppContext();
String providerValue;
PushConfigurationState accountPushData = null;
Gson gson = new Gson();
for (Account account : AccountUtils.getAccounts(context)) {
if (!TextUtils.isEmpty(providerValue = arbitraryDataProvider.getValue(account, KEY_PUSH))) {
PushConfigurationState accountPushData = gson.fromJson(providerValue,
providerValue = arbitraryDataProvider.getValue(account, KEY_PUSH);
if (!TextUtils.isEmpty(providerValue)) {
accountPushData = gson.fromJson(providerValue,
PushConfigurationState.class);
if (!accountPushData.getPushToken().equals(token) && !accountPushData.isShouldBeDeleted()) {
} else {
accountPushData = null;
}
if (accountPushData != null && !accountPushData.getPushToken().equals(token) &&
!accountPushData.isShouldBeDeleted() ||
TextUtils.isEmpty(providerValue)) {
try {
OwnCloudAccount ocAccount = new OwnCloudAccount(account, context);
OwnCloudClient mClient = OwnCloudClientManagerFactory.getDefaultSingleton().
@ -249,14 +257,13 @@ public class PushUtils {
} catch (OperationCanceledException e) {
Log_OC.d(TAG, "Failed via OperationCanceledException");
}
} else if (accountPushData.isShouldBeDeleted()) {
} else if (accountPushData != null && accountPushData.isShouldBeDeleted()) {
deleteRegistrationForAccount(account);
}
}
}
}
}
}
public static Key readKeyFromFile(boolean readPublicKey) {
String keyPath = MainApp.getStoragePath() + File.separator + MainApp.getDataFolder() + File.separator

View file

@ -100,8 +100,11 @@ import com.owncloud.android.utils.DisplayUtils;
import com.owncloud.android.utils.ErrorMessageAdapter;
import com.owncloud.android.utils.MimeTypeUtil;
import com.owncloud.android.utils.PermissionUtil;
import com.owncloud.android.utils.PushUtils;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.parceler.Parcels;
import java.io.File;
@ -2064,4 +2067,16 @@ public class FileDisplayActivity extends HookActivity
super.showFiles(onDeviceOnly);
getListOfFilesFragment().refreshDirectory();
}
@Subscribe(threadMode = ThreadMode.BACKGROUND)
public void onMessageEvent(TokenPushEvent event) {
PushUtils.pushRegistrationToServer();
}
@Override
public void onStart() {
super.onStart();
EventBus.getDefault().post(new TokenPushEvent());
}
}

View file

@ -66,6 +66,8 @@ import com.owncloud.android.utils.DisplayUtils;
import com.owncloud.android.utils.PushUtils;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.parceler.Parcels;
import butterknife.BindString;
@ -446,4 +448,9 @@ public class UserInfoActivity extends FileActivity {
outState.putParcelable(KEY_USER_DATA, Parcels.wrap(userInfo));
}
}
@Subscribe(threadMode = ThreadMode.BACKGROUND)
public void onMessageEvent(TokenPushEvent event) {
PushUtils.pushRegistrationToServer();
}
}

View file

@ -34,17 +34,6 @@
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity
android:name=".ui.activity.ModifiedFileDisplayActivity"
android:label="@string/app_name"
android:theme="@style/Theme.ownCloud.Toolbar.Drawer">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".authentication.ModifiedAuthenticatorActivity"
android:exported="true"
@ -71,15 +60,6 @@
</intent-filter>
</activity>
<activity
android:name=".ui.activity.FileDisplayActivity"
tools:node="remove"/>
<activity-alias
android:name=".ui.activity.FileDisplayActivity"
android:targetActivity=".ui.activity.ModifiedFileDisplayActivity"
tools:replace="android:targetActivity"/>
<activity-alias
android:name=".authentication.AuthenticatorActivity"
android:targetActivity=".authentication.ModifiedAuthenticatorActivity"

View file

@ -1,36 +0,0 @@
/**
* Nextcloud Android client application
*
* @author Mario Danic
* Copyright (C) 2017 Mario Danic
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.owncloud.android.ui.activity;
import com.owncloud.android.ui.events.TokenPushEvent;
import com.owncloud.android.utils.PushUtils;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
public class ModifiedFileDisplayActivity extends FileDisplayActivity {
@Subscribe(threadMode = ThreadMode.BACKGROUND)
public void onMessageEvent(TokenPushEvent event) {
PushUtils.pushRegistrationToServer();
}
}

View file

@ -76,7 +76,7 @@ public class PushUtils {
private static ArbitraryDataProvider arbitraryDataProvider;
private static String generateSHA512Hash(String pushToken) {
public static String generateSHA512Hash(String pushToken) {
MessageDigest messageDigest = null;
try {
messageDigest = MessageDigest.getInstance("SHA-512");
@ -88,7 +88,7 @@ public class PushUtils {
return "";
}
private static String bytesToHex(byte[] bytes) {
public static String bytesToHex(byte[] bytes) {
StringBuilder result = new StringBuilder();
for (byte individualByte : bytes) {
result.append(Integer.toString((individualByte & 0xff) + 0x100, 16)
@ -202,12 +202,20 @@ public class PushUtils {
Context context = MainApp.getAppContext();
String providerValue;
PushConfigurationState accountPushData = null;
Gson gson = new Gson();
for (Account account : AccountUtils.getAccounts(context)) {
if (!TextUtils.isEmpty(providerValue = arbitraryDataProvider.getValue(account, KEY_PUSH))) {
PushConfigurationState accountPushData = gson.fromJson(providerValue,
providerValue = arbitraryDataProvider.getValue(account, KEY_PUSH);
if (!TextUtils.isEmpty(providerValue)) {
accountPushData = gson.fromJson(providerValue,
PushConfigurationState.class);
if (!accountPushData.getPushToken().equals(token) && !accountPushData.isShouldBeDeleted()) {
} else {
accountPushData = null;
}
if (accountPushData != null && !accountPushData.getPushToken().equals(token) &&
!accountPushData.isShouldBeDeleted() ||
TextUtils.isEmpty(providerValue)) {
try {
OwnCloudAccount ocAccount = new OwnCloudAccount(account, context);
OwnCloudClient mClient = OwnCloudClientManagerFactory.getDefaultSingleton().
@ -249,14 +257,13 @@ public class PushUtils {
} catch (OperationCanceledException e) {
Log_OC.d(TAG, "Failed via OperationCanceledException");
}
} else if (accountPushData.isShouldBeDeleted()) {
} else if (accountPushData != null && accountPushData.isShouldBeDeleted()) {
deleteRegistrationForAccount(account);
}
}
}
}
}
}
public static Key readKeyFromFile(boolean readPublicKey) {
String keyPath = MainApp.getStoragePath() + File.separator + MainApp.getDataFolder() + File.separator