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

Unverified Commit 7e945c15 authored by Marten Gajda's avatar Marten Gajda Committed by GitHub
Browse files

Reduce size of ProviderChangedBroadcast, fixes #744 (#749)

This commit removes the changelog we've sent with the ProviderChanged Broadcast. It's never really been used so far but may blow the IPC buffer size limit.
We need to find a better way to communicate changes efficiently to plugins once we support them. It's not a pressing concern though.
parent cf251887
Loading
Loading
Loading
Loading
+0 −112
Original line number Diff line number Diff line
/*
 * Copyright 2017 dmfs GmbH
 *
 * 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.
 */

package org.dmfs.provider.tasks;

import android.net.Uri;
import android.os.Bundle;

import org.dmfs.tasks.contract.TaskContract;

import java.util.ArrayList;


/**
 * A log to track all content provider operations.
 *
 * @author Marten Gajda <marten@dmfs.org>
 */
public class ProviderOperationsLog
{
    private ArrayList<Uri> mUris = new ArrayList<Uri>(16);

    private ArrayList<Integer> mOperations = new ArrayList<Integer>(16);


    /**
     * Add an operation on the given {@link Uri} to the log.
     *
     * @param operation
     *         The {@link ProviderOperation} that was executed.
     * @param uri
     *         The {@link Uri} that the operation was executed on.
     */
    public void log(ProviderOperation operation, Uri uri)
    {
        synchronized (this)
        {
            mUris.add(uri);
            mOperations.add(operation.ordinal());
        }
    }


    /**
     * Adds the operations log to the given {@link Bundle}, creating one if the given bundle is <code>null</code>.
     *
     * @param bundle
     *         A {@link Bundle} or <code>null</code>.
     * @param clearLog
     *         <code>true</code> to clear the log afterwards, <code>false</code> to keep it.
     *
     * @return The {@link Bundle} that was passed or created.
     */
    public Bundle toBundle(Bundle bundle, boolean clearLog)
    {
        if (bundle == null)
        {
            bundle = new Bundle(2);
        }

        synchronized (this)
        {
            bundle.putParcelableArrayList(TaskContract.EXTRA_OPERATIONS_URIS, mUris);
            bundle.putIntegerArrayList(TaskContract.EXTRA_OPERATIONS, mOperations);
            if (clearLog)
            {
                // we can't just clear the ArrayLists, because the Bundle keeps a reference to them
                mUris = new ArrayList<Uri>(16);
                mOperations = new ArrayList<Integer>(16);
            }
        }
        return bundle;
    }


    /**
     * Returns a new {@link Bundle} containing the log.
     *
     * @param clearLog
     *         <code>true</code> to clear the log afterwards, <code>false</code> to keep it.
     *
     * @return The {@link Bundle} that was created.
     */
    public Bundle toBundle(boolean clearLog)
    {
        return toBundle(null, clearLog);
    }


    /**
     * Returns whether any operations have been logged or not.
     *
     * @return <code>true</code> if this log is empty, <code>false</code> if it contains any logs of operations.
     */
    public boolean isEmpty()
    {
        return mUris.size() == 0;
    }
}
 No newline at end of file
+1 −21
Original line number Diff line number Diff line
@@ -151,11 +151,6 @@ public final class TaskProvider extends SQLiteContentProvider implements OnAccou
     */
    Handler mAsyncHandler;

    /**
     * An {@link ProviderOperationsLog} to track all changes within a transaction.
     */
    private ProviderOperationsLog mOperationsLog = new ProviderOperationsLog();

    /**
     * This is a per transaction/thread flag which indicates whether new lists with an unknown account have been added.
     * If this holds true at the end of a transaction a window should be shown to ask the user for access to that account.
@@ -762,7 +757,6 @@ public final class TaskProvider extends SQLiteContentProvider implements OnAccou
                        final ListAdapter list = new CursorContentValuesListAdapter(ListAdapter._ID.getFrom(cursor), cursor, new ContentValues());

                        mListProcessorChain.delete(db, list, isSyncAdapter);
                        mOperationsLog.log(ProviderOperation.DELETE, list.uri(mAuthority));
                        count++;
                    }
                }
@@ -804,7 +798,6 @@ public final class TaskProvider extends SQLiteContentProvider implements OnAccou

                        mTaskProcessorChain.delete(db, task, isSyncAdapter);

                        mOperationsLog.log(ProviderOperation.DELETE, task.uri(mAuthority));
                        count++;
                    }
                }
@@ -923,7 +916,6 @@ public final class TaskProvider extends SQLiteContentProvider implements OnAccou
                list.set(ListAdapter.ACCOUNT_TYPE, accountType);

                mListProcessorChain.insert(db, list, isSyncAdapter);
                mOperationsLog.log(ProviderOperation.INSERT, list.uri(mAuthority));

                rowId = list.id();
                result_uri = TaskContract.TaskLists.getContentUri(mAuthority);
@@ -943,8 +935,6 @@ public final class TaskProvider extends SQLiteContentProvider implements OnAccou

                mTaskProcessorChain.insert(db, task, isSyncAdapter);

                mOperationsLog.log(ProviderOperation.INSERT, task.uri(mAuthority));

                rowId = task.id();
                result_uri = TaskContract.Tasks.getContentUri(mAuthority);

@@ -1069,7 +1059,6 @@ public final class TaskProvider extends SQLiteContentProvider implements OnAccou
                        final ListAdapter list = new CursorContentValuesListAdapter(listId, cursor, cursor.getCount() > 1 ? new ContentValues(values) : values);

                        mListProcessorChain.update(db, list, isSyncAdapter);
                        mOperationsLog.log(ProviderOperation.UPDATE, list.uri(mAuthority));
                        count++;
                    }
                }
@@ -1097,10 +1086,6 @@ public final class TaskProvider extends SQLiteContentProvider implements OnAccou
                        final TaskAdapter task = new CursorContentValuesTaskAdapter(cursor, cursor.getCount() > 1 ? new ContentValues(values) : values);

                        mTaskProcessorChain.update(db, task, isSyncAdapter);
                        if (task.hasUpdates())
                        {
                            mOperationsLog.log(ProviderOperation.UPDATE, task.uri(mAuthority));
                        }
                        count++;
                    }
                }
@@ -1313,12 +1298,7 @@ public final class TaskProvider extends SQLiteContentProvider implements OnAccou
    {
        super.onEndTransaction(callerIsSyncAdapter);
        Intent providerChangedIntent = new Intent(Intent.ACTION_PROVIDER_CHANGED, TaskContract.getContentUri(mAuthority));
        if (!mOperationsLog.isEmpty())
        {
        updateNotifications();
        }
        // add the change log to the broadcast
        providerChangedIntent.putExtras(mOperationsLog.toBundle(true));
        if (Build.VERSION.SDK_INT >= 26)
        {
            // for now we only notify our own package