Browse Source

Fix push

Signed-off-by: Mario Danic <mario@lovelyhq.com>
Mario Danic 7 years ago
parent
commit
05425c0444

+ 4 - 0
src/generic/java/com/owncloud/android/utils/PushUtils.java

@@ -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
+    }
 }

+ 0 - 20
src/gplay/AndroidManifest.xml

@@ -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"

+ 0 - 46
src/gplay/java/com/owncloud/android/ui/activity/ModifiedFileDisplayActivity.java

@@ -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());
-    }
-
-}

+ 51 - 24
src/gplay/java/com/owncloud/android/utils/PushUtils.java

@@ -202,26 +202,46 @@ 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()) {
-                            try {
-                                OwnCloudAccount ocAccount = new OwnCloudAccount(account, context);
-                                OwnCloudClient mClient = OwnCloudClientManagerFactory.getDefaultSingleton().
-                                        getClientFor(ocAccount, context);
+                    } 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().
+                                    getClientFor(ocAccount, context);
+
+                            RemoteOperation registerAccountDeviceForNotificationsOperation =
+                                    new RegisterAccountDeviceForNotificationsOperation(pushTokenHash,
+                                            publicKey,
+                                            context.getResources().getString(R.string.push_server_url));
 
-                                RemoteOperation registerAccountDeviceForNotificationsOperation =
-                                        new RegisterAccountDeviceForNotificationsOperation(pushTokenHash,
-                                                publicKey,
-                                                context.getResources().getString(R.string.push_server_url));
+                            RemoteOperationResult remoteOperationResult = registerAccountDeviceForNotificationsOperation.
+                                    execute(mClient);
 
-                                RemoteOperationResult remoteOperationResult = registerAccountDeviceForNotificationsOperation.
-                                        execute(mClient);
+                            if (remoteOperationResult.isSuccess()) {
+                                PushResponse pushResponse = remoteOperationResult.getPushResponseData();
+
+                                RemoteOperation registerAccountDeviceForProxyOperation = new
+                                        RegisterAccountDeviceForProxyOperation(
+                                        context.getResources().getString(R.string.push_server_url),
+                                        token, pushResponse.getDeviceIdentifier(), pushResponse.getSignature(),
+                                        pushResponse.getPublicKey());
+
+                                remoteOperationResult = registerAccountDeviceForProxyOperation.execute(mClient);
 
                                 if (remoteOperationResult.isSuccess()) {
+<<<<<<< Updated upstream
                                     PushResponse pushResponse = remoteOperationResult.getPushResponseData();
 
                                     RemoteOperation registerAccountDeviceForProxyOperation = new
@@ -239,19 +259,26 @@ public class PushUtils {
                                         arbitraryDataProvider.storeOrUpdateKeyValue(account, KEY_PUSH,
                                                 gson.toJson(pushArbitraryData));
                                     }
+=======
+                                    PushConfigurationState pushArbitraryData = new PushConfigurationState(token,
+                                            pushResponse.getDeviceIdentifier(), pushResponse.getSignature(),
+                                            pushResponse.getPublicKey(), false);
+                                    arbitraryDataProvider.storeOrUpdateKeyValue(account.name, KEY_PUSH,
+                                            gson.toJson(pushArbitraryData));
+>>>>>>> Stashed changes
                                 }
-                            } catch (com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException e) {
-                                Log_OC.d(TAG, "Failed to find an account");
-                            } catch (AuthenticatorException e) {
-                                Log_OC.d(TAG, "Failed via AuthenticatorException");
-                            } catch (IOException e) {
-                                Log_OC.d(TAG, "Failed via IOException");
-                            } catch (OperationCanceledException e) {
-                                Log_OC.d(TAG, "Failed via OperationCanceledException");
                             }
-                        } else if (accountPushData.isShouldBeDeleted()) {
-                            deleteRegistrationForAccount(account);
+                        } catch (com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException e) {
+                            Log_OC.d(TAG, "Failed to find an account");
+                        } catch (AuthenticatorException e) {
+                            Log_OC.d(TAG, "Failed via AuthenticatorException");
+                        } catch (IOException e) {
+                            Log_OC.d(TAG, "Failed via IOException");
+                        } catch (OperationCanceledException e) {
+                            Log_OC.d(TAG, "Failed via OperationCanceledException");
                         }
+                    } else if (accountPushData != null && accountPushData.isShouldBeDeleted()) {
+                        deleteRegistrationForAccount(account);
                     }
                 }
             }
@@ -261,7 +288,7 @@ public class PushUtils {
     public static Key readKeyFromFile(boolean readPublicKey) {
         String keyPath = MainApp.getStoragePath() + File.separator + MainApp.getDataFolder() + File.separator
                 + KEYPAIR_FOLDER;
-        
+
         String privateKeyPath = keyPath + File.separator + KEYPAIR_FILE_NAME + KEYPAIR_PRIV_EXTENSION;
         String publicKeyPath = keyPath + File.separator + KEYPAIR_FILE_NAME + KEYPAIR_PUB_EXTENSION;
 

+ 16 - 1
src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java

@@ -83,12 +83,12 @@ import com.owncloud.android.services.observer.FileObserverService;
 import com.owncloud.android.syncadapter.FileSyncAdapter;
 import com.owncloud.android.ui.dialog.SortingOrderDialogFragment;
 import com.owncloud.android.ui.events.TokenPushEvent;
-import com.owncloud.android.ui.fragment.contactsbackup.ContactListFragment;
 import com.owncloud.android.ui.fragment.ExtendedListFragment;
 import com.owncloud.android.ui.fragment.FileDetailFragment;
 import com.owncloud.android.ui.fragment.FileFragment;
 import com.owncloud.android.ui.fragment.OCFileListFragment;
 import com.owncloud.android.ui.fragment.TaskRetainerFragment;
+import com.owncloud.android.ui.fragment.contactsbackup.ContactListFragment;
 import com.owncloud.android.ui.helpers.UriUploader;
 import com.owncloud.android.ui.preview.PreviewImageActivity;
 import com.owncloud.android.ui.preview.PreviewImageFragment;
@@ -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;
@@ -2051,4 +2054,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());
+    }
+
 }

+ 0 - 20
src/modified/AndroidManifest.xml

@@ -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"

+ 0 - 36
src/modified/java/com/owncloud/android/ui/activity/ModifiedFileDisplayActivity.java

@@ -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();
-    }
-
-}

+ 50 - 23
src/modified/java/com/owncloud/android/utils/PushUtils.java

@@ -202,26 +202,46 @@ 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()) {
-                            try {
-                                OwnCloudAccount ocAccount = new OwnCloudAccount(account, context);
-                                OwnCloudClient mClient = OwnCloudClientManagerFactory.getDefaultSingleton().
-                                        getClientFor(ocAccount, context);
+                    } 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().
+                                    getClientFor(ocAccount, context);
+
+                            RemoteOperation registerAccountDeviceForNotificationsOperation =
+                                    new RegisterAccountDeviceForNotificationsOperation(pushTokenHash,
+                                            publicKey,
+                                            context.getResources().getString(R.string.push_server_url));
+
+                            RemoteOperationResult remoteOperationResult = registerAccountDeviceForNotificationsOperation.
+                                    execute(mClient);
+
+                            if (remoteOperationResult.isSuccess()) {
+                                PushResponse pushResponse = remoteOperationResult.getPushResponseData();
 
-                                RemoteOperation registerAccountDeviceForNotificationsOperation =
-                                        new RegisterAccountDeviceForNotificationsOperation(pushTokenHash,
-                                                publicKey,
-                                                context.getResources().getString(R.string.push_server_url));
+                                RemoteOperation registerAccountDeviceForProxyOperation = new
+                                        RegisterAccountDeviceForProxyOperation(
+                                        context.getResources().getString(R.string.push_server_url),
+                                        token, pushResponse.getDeviceIdentifier(), pushResponse.getSignature(),
+                                        pushResponse.getPublicKey());
 
-                                RemoteOperationResult remoteOperationResult = registerAccountDeviceForNotificationsOperation.
-                                        execute(mClient);
+                                remoteOperationResult = registerAccountDeviceForProxyOperation.execute(mClient);
 
                                 if (remoteOperationResult.isSuccess()) {
+<<<<<<< Updated upstream
                                     PushResponse pushResponse = remoteOperationResult.getPushResponseData();
 
                                     RemoteOperation registerAccountDeviceForProxyOperation = new
@@ -239,19 +259,26 @@ public class PushUtils {
                                         arbitraryDataProvider.storeOrUpdateKeyValue(account, KEY_PUSH,
                                                 gson.toJson(pushArbitraryData));
                                     }
+=======
+                                    PushConfigurationState pushArbitraryData = new PushConfigurationState(token,
+                                            pushResponse.getDeviceIdentifier(), pushResponse.getSignature(),
+                                            pushResponse.getPublicKey(), false);
+                                    arbitraryDataProvider.storeOrUpdateKeyValue(account.name, KEY_PUSH,
+                                            gson.toJson(pushArbitraryData));
+>>>>>>> Stashed changes
                                 }
-                            } catch (com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException e) {
-                                Log_OC.d(TAG, "Failed to find an account");
-                            } catch (AuthenticatorException e) {
-                                Log_OC.d(TAG, "Failed via AuthenticatorException");
-                            } catch (IOException e) {
-                                Log_OC.d(TAG, "Failed via IOException");
-                            } catch (OperationCanceledException e) {
-                                Log_OC.d(TAG, "Failed via OperationCanceledException");
                             }
-                        } else if (accountPushData.isShouldBeDeleted()) {
-                            deleteRegistrationForAccount(account);
+                        } catch (com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException e) {
+                            Log_OC.d(TAG, "Failed to find an account");
+                        } catch (AuthenticatorException e) {
+                            Log_OC.d(TAG, "Failed via AuthenticatorException");
+                        } catch (IOException e) {
+                            Log_OC.d(TAG, "Failed via IOException");
+                        } catch (OperationCanceledException e) {
+                            Log_OC.d(TAG, "Failed via OperationCanceledException");
                         }
+                    } else if (accountPushData != null && accountPushData.isShouldBeDeleted()) {
+                        deleteRegistrationForAccount(account);
                     }
                 }
             }