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

Commit 40af098e authored by Wenyi Wang's avatar Wenyi Wang Committed by android-build-merger
Browse files

Merge "Switch to BlockedNumberProvider in N SDK" into ub-contactsdialer-b-dev

am: 0bd21991

* commit '0bd21991':
  Switch to BlockedNumberProvider in N SDK
parents ae23161a 0bd21991
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -82,7 +82,7 @@ public class BlockNumberDialogFragment extends DialogFragment {
    private Callback mCallback;

    public static void show(
            Integer blockId,
            Long blockId,
            String number,
            String countryIso,
            String displayNumber,
@@ -97,7 +97,7 @@ public class BlockNumberDialogFragment extends DialogFragment {
    }

    private static BlockNumberDialogFragment newInstance(
            Integer blockId,
            Long blockId,
            String number,
            String countryIso,
            String displayNumber,
+5 −5
Original line number Diff line number Diff line
@@ -19,13 +19,13 @@ package com.android.contacts.callblocking;
import android.app.FragmentManager;
import android.content.Context;
import android.database.Cursor;
import android.provider.BlockedNumberContract.BlockedNumbers;
import android.telephony.PhoneNumberUtils;
import android.view.View;

import com.android.contacts.common.ContactPhotoManager;
import com.android.contacts.common.GeoUtil;
import com.android.contacts.R;
import com.android.contacts.callblocking.FilteredNumberContract.FilteredNumberColumns;

public class BlockedNumbersAdapter extends NumbersAdapter {
    private BlockedNumbersAdapter(
@@ -48,10 +48,10 @@ public class BlockedNumbersAdapter extends NumbersAdapter {
    @Override
    public void bindView(View view, final Context context, Cursor cursor) {
        super.bindView(view, context, cursor);
        final Integer id = cursor.getInt(cursor.getColumnIndex(FilteredNumberColumns._ID));
        final String countryIso = cursor.getString(cursor.getColumnIndex(
                FilteredNumberColumns.COUNTRY_ISO));
        final String number = cursor.getString(cursor.getColumnIndex(FilteredNumberColumns.NUMBER));
        final Long id = cursor.getLong(cursor.getColumnIndex(BlockedNumbers.COLUMN_ID));
        final String countryIso = GeoUtil.getCurrentCountryIso(context);
        final String number = cursor.getString(
                cursor.getColumnIndex(BlockedNumbers.COLUMN_ORIGINAL_NUMBER));

        final View deleteButton = view.findViewById(R.id.delete_button);
        deleteButton.setOnClickListener(new View.OnClickListener() {
+5 −8
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.content.Loader;
import android.database.Cursor;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.provider.BlockedNumberContract.BlockedNumbers;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
@@ -141,16 +142,12 @@ public class BlockedNumbersFragment extends ListFragment
    @Override
    public Loader<Cursor> onCreateLoader(int id, Bundle args) {
        final String[] projection = {
            FilteredNumberContract.FilteredNumberColumns._ID,
            FilteredNumberContract.FilteredNumberColumns.COUNTRY_ISO,
            FilteredNumberContract.FilteredNumberColumns.NUMBER,
            FilteredNumberContract.FilteredNumberColumns.NORMALIZED_NUMBER
            BlockedNumbers.COLUMN_ID,
            BlockedNumbers.COLUMN_ORIGINAL_NUMBER,
            BlockedNumbers.COLUMN_E164_NUMBER
        };
        final String selection = FilteredNumberContract.FilteredNumberColumns.TYPE
                + "=" + FilteredNumberContract.FilteredNumberTypes.BLOCKED_NUMBER;
        final CursorLoader cursorLoader = new CursorLoader(
                getContext(), FilteredNumberContract.FilteredNumber.CONTENT_URI, projection,
                selection, null, null);
                getContext(), BlockedNumbers.CONTENT_URI, projection, null, null, null);
        return cursorLoader;
    }

+12 −53
Original line number Diff line number Diff line
@@ -24,14 +24,10 @@ import android.database.Cursor;
import android.database.DatabaseUtils;
import android.database.sqlite.SQLiteDatabaseCorruptException;
import android.net.Uri;
import android.provider.BlockedNumberContract.BlockedNumbers;
import android.telephony.PhoneNumberUtils;
import android.text.TextUtils;

import com.android.contacts.callblocking.FilteredNumberContract.FilteredNumber;
import com.android.contacts.callblocking.FilteredNumberContract.FilteredNumberColumns;
import com.android.contacts.callblocking.FilteredNumberContract.FilteredNumberSources;
import com.android.contacts.callblocking.FilteredNumberContract.FilteredNumberTypes;

public class FilteredNumberAsyncQueryHandler extends AsyncQueryHandler {
    private static final int NO_TOKEN = 0;

@@ -58,7 +54,7 @@ public class FilteredNumberAsyncQueryHandler extends AsyncQueryHandler {
         * Invoked after querying if a number is blocked.
         * @param id The ID of the row if blocked, null otherwise.
         */
        void onCheckComplete(Integer id);
        void onCheckComplete(Long id);
    }

    public interface OnBlockNumberListener {
@@ -78,14 +74,6 @@ public class FilteredNumberAsyncQueryHandler extends AsyncQueryHandler {
        void onUnblockComplete(int rows, ContentValues values);
    }

    public interface OnHasBlockedNumbersListener {
        /**
         * @param hasBlockedNumbers {@code true} if any blocked numbers are stored.
         *     {@code false} otherwise.
         */
        void onHasBlockedNumbers(boolean hasBlockedNumbers);
    }

    @Override
    protected void onQueryComplete(int token, Object cookie, Cursor cursor) {
        if (cookie != null) {
@@ -114,27 +102,6 @@ public class FilteredNumberAsyncQueryHandler extends AsyncQueryHandler {
        }
    }

    public final void incrementFilteredCount(Integer id) {
        startUpdate(NO_TOKEN, null,
                ContentUris.withAppendedId(FilteredNumber.CONTENT_URI_INCREMENT_FILTERED_COUNT, id),
                null, null, null);
    }

    public final void hasBlockedNumbers(final OnHasBlockedNumbersListener listener) {
        startQuery(NO_TOKEN,
                new Listener() {
                    @Override
                    protected void onQueryComplete(int token, Object cookie, Cursor cursor) {
                        listener.onHasBlockedNumbers(cursor != null && cursor.getCount() > 0);
                    }
                },
                FilteredNumber.CONTENT_URI,
                new String[]{ FilteredNumberColumns._ID },
                FilteredNumberColumns.TYPE + "=" + FilteredNumberTypes.BLOCKED_NUMBER,
                null,
                null);
    }

    /**
     * Check if this number has been blocked.
     *
@@ -157,18 +124,13 @@ public class FilteredNumberAsyncQueryHandler extends AsyncQueryHandler {
                            return;
                        }
                        cursor.moveToFirst();
                        if (cursor.getInt(cursor.getColumnIndex(FilteredNumberColumns.TYPE))
                                != FilteredNumberTypes.BLOCKED_NUMBER) {
                            listener.onCheckComplete(null);
                            return;
                        }
                        listener.onCheckComplete(
                                cursor.getInt(cursor.getColumnIndex(FilteredNumberColumns._ID)));
                        listener.onCheckComplete(cursor.getLong(
                                        cursor.getColumnIndex(BlockedNumbers.COLUMN_ID)));
                    }
                },
                FilteredNumber.CONTENT_URI,
                new String[]{ FilteredNumberColumns._ID, FilteredNumberColumns.TYPE },
                FilteredNumberColumns.NORMALIZED_NUMBER + " = ?",
                BlockedNumbers.CONTENT_URI,
                new String[]{ BlockedNumbers.COLUMN_ID},
                BlockedNumbers.COLUMN_E164_NUMBER + " = ?",
                new String[]{ normalizedNumber },
                null);

@@ -192,11 +154,8 @@ public class FilteredNumberAsyncQueryHandler extends AsyncQueryHandler {
            normalizedNumber = PhoneNumberUtils.formatNumberToE164(number, countryIso);
        }
        ContentValues v = new ContentValues();
        v.put(FilteredNumberColumns.NORMALIZED_NUMBER, normalizedNumber);
        v.put(FilteredNumberColumns.NUMBER, number);
        v.put(FilteredNumberColumns.COUNTRY_ISO, countryIso);
        v.put(FilteredNumberColumns.TYPE, FilteredNumberTypes.BLOCKED_NUMBER);
        v.put(FilteredNumberColumns.SOURCE, FilteredNumberSources.USER);
        v.put(BlockedNumbers.COLUMN_ORIGINAL_NUMBER, number);
        v.put(BlockedNumbers.COLUMN_E164_NUMBER, normalizedNumber);
        blockNumber(listener, v);
    }

@@ -213,7 +172,7 @@ public class FilteredNumberAsyncQueryHandler extends AsyncQueryHandler {
                            listener.onBlockComplete(uri);
                        }
                    }
                }, FilteredNumber.CONTENT_URI, values);
                }, BlockedNumbers.CONTENT_URI, values);
    }

    /**
@@ -225,7 +184,7 @@ public class FilteredNumberAsyncQueryHandler extends AsyncQueryHandler {
        if (id == null) {
            throw new IllegalArgumentException("Null id passed into unblock");
        }
        unblock(listener, ContentUris.withAppendedId(FilteredNumber.CONTENT_URI, id));
        unblock(listener, ContentUris.withAppendedId(BlockedNumbers.CONTENT_URI, id));
    }

    /**
@@ -246,7 +205,7 @@ public class FilteredNumberAsyncQueryHandler extends AsyncQueryHandler {
                cursor.moveToFirst();
                final ContentValues values = new ContentValues();
                DatabaseUtils.cursorRowToContentValues(cursor, values);
                values.remove(FilteredNumberColumns._ID);
                values.remove(BlockedNumbers.COLUMN_ID);

                startDelete(NO_TOKEN, new Listener() {
                    @Override
+0 −162
Original line number Diff line number Diff line
/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * 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 com.android.contacts.callblocking;

import android.net.Uri;
import android.provider.BaseColumns;

/**
 * <p>
 * The contract between the filtered number provider and applications. Contains
 * definitions for the supported URIs and columns.
 * </p>
 */
public final class FilteredNumberContract {

    /** The authority for the filtered numbers provider
     *  Contacts should use this authority from GoogleDialer. */
    public static final String AUTHORITY =
            "com.google.android.dialer.provider.filterednumberprovider";

    /** A content:// style uri to the authority for the filtered numbers provider */
    public static final Uri AUTHORITY_URI = Uri.parse("content://" + AUTHORITY);

    /** The type of filtering to be applied, e.g. block the number or whitelist the number. */
    public interface FilteredNumberTypes {
        int UNDEFINED = 0;
        /**
         * Dialer will disconnect the call without sending the caller to voicemail.
         */
        int BLOCKED_NUMBER = 1;
    }

    /** The original source of the filtered number, e.g. the user manually added it. */
    public interface FilteredNumberSources {
        int UNDEFINED = 0;
        /**
         * The user manually added this number through Dialer (e.g. from the call log or InCallUI).
         */
        int USER = 1;
    }

    public interface FilteredNumberColumns {
        // TYPE: INTEGER
        String _ID = "_id";
        /**
         * Represents the number to be filtered, normalized to compare phone numbers for equality.
         *
         * TYPE: TEXT
         */
        String NORMALIZED_NUMBER = "normalized_number";
        /**
         * Represents the number to be filtered, for formatting and
         * used with country iso for contact lookups.
         *
         * TYPE: TEXT
         */
        String NUMBER = "number";
        /**
         * The country code representing the country detected when
         * the phone number was added to the database.
         * Most numbers don't have the country code, so a best guess is provided by
         * the country detector system. The country iso is also needed in order to format
         * phone numbers correctly.
         *
         * TYPE: TEXT
         */
        String COUNTRY_ISO = "country_iso";
        /**
         * The number of times the number has been filtered by Dialer.
         * When this number is incremented, LAST_TIME_FILTERED should also be updated to
         * the current time.
         *
         * TYPE: INTEGER
         */
        String TIMES_FILTERED = "times_filtered";
        /**
         * Set to the current time when the phone number is filtered.
         * When this is updated, TIMES_FILTERED should also be incremented.
         *
         * TYPE: LONG
         */
        String LAST_TIME_FILTERED = "last_time_filtered";
        // TYPE: LONG
        String CREATION_TIME = "creation_time";
        /**
         * Indicates the type of filtering to be applied.
         *
         * TYPE: INTEGER
         * See {@link FilteredNumberTypes}
         */
        String TYPE = "type";
        /**
         * Integer representing the original source of the filtered number.
         *
         * TYPE: INTEGER
         * See {@link FilteredNumberSources}
         */
        String SOURCE = "source";
    }

    /**
     * <p>
     * Constants for the table of filtered numbers.
     * </p>
     * <h3>Operations</h3>
     * <dl>
     * <dt><b>Insert</b></dt>
     * <dd>Required fields: NUMBER, NORMALIZED_NUMBER, TYPE, SOURCE.
     * A default value will be used for the other fields if left null.</dd>
     * <dt><b>Update</b></dt>
     * <dt><b>Delete</b></dt>
     * <dt><b>Query</b></dt>
     * <dd>{@link #CONTENT_URI} can be used for any query, append an ID to
     * retrieve a specific filtered number entry.</dd>
     * </dl>
     */
    public static class FilteredNumber implements BaseColumns {

        public static final String FILTERED_NUMBERS_TABLE = "filtered_numbers_table";
        public static final String FILTERED_NUMBERS_INCREMENT_FILTERED_COUNT =
                "filtered_numbers_increment_filtered_count";

        public static final Uri CONTENT_URI = Uri.withAppendedPath(
                AUTHORITY_URI,
                FILTERED_NUMBERS_TABLE);

        public static final Uri CONTENT_URI_INCREMENT_FILTERED_COUNT = Uri.withAppendedPath(
                AUTHORITY_URI,
                FILTERED_NUMBERS_INCREMENT_FILTERED_COUNT);

        /**
         * This utility class cannot be instantiated.
         */
        private FilteredNumber () {}

        /**
         * The MIME type of {@link #CONTENT_URI} providing a directory of
         * filtered numbers.
         */
        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/filtered_numbers_table";

        /**
         * The MIME type of a {@link #CONTENT_URI} single filtered number.
         */
        public static final String CONTENT_ITEM_TYPE =
                "vnd.android.cursor.item/filtered_numbers_table";
    }
}
 No newline at end of file
Loading