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

Commit 581e960b authored by Linux Build Service Account's avatar Linux Build Service Account Committed by Gerrit - the friendly Code Review server
Browse files

Merge "Dialer:add black and white list menu"

parents 9a6bf8be a0c714b0
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ LOCAL_AAPT_FLAGS := \
    --extra-packages com.android.phone.common

LOCAL_JAVA_LIBRARIES := telephony-common
LOCAL_JAVA_LIBRARIES += rcs_service_api
LOCAL_STATIC_JAVA_LIBRARIES := \
    com.android.services.telephony.common \
    com.android.vcard \
+13 −1
Original line number Diff line number Diff line
@@ -57,6 +57,18 @@
    <uses-permission android:name="android.permission.STOP_APP_SWITCHES" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    <uses-permission android:name="com.qualcomm.permission.USE_PHONE_SERVICE" />
    <uses-permission android:name="com.android.firewall.READ_GRAVITY"/>
    <uses-permission android:name="com.android.firewall.WRITE_GRAVITY"/>
    <uses-permission android:name="android.permission.READ_SMS"/>
    <uses-permission android:name="android.permission.WRITE_SMS"/>
    <!-- RCS -->
    <uses-permission android:name="android.permission.INTERNET" />
    <!-- wifi -->
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
    <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

    <application
        android:name="DialerApplication"
@@ -70,7 +82,7 @@
            android:value="AEdPqrEAAAAIBXgtCEKQ6W0PXVnW-ZVia2KmlV2AxsTw3GjAeQ" />

        <uses-library android:name="com.qualcomm.qti.smartsearch" />

        <uses-library android:name="com.suntek.mway.rcs.client.api" android:required="false" />
        <!-- The entrance point for Phone UI.
             stateAlwaysHidden is set to suppress keyboard show up on
             dialpad screen. -->
+5 −0
Original line number Diff line number Diff line
@@ -221,4 +221,9 @@
    <string name="add_to_black_list">加入黑名单</string>
    <string name="video_call">视频电话</string>
    <string name="menu_add_to_4g_conference_call">加入4G电话会议</string>
    <string name="firewall_number_len_not_valid">号码错误</string>
    <string name="firewall_number_in_black">"该号码已在黑名单中"</string>
    <string name="firewall_number_in_white">"该号码已在白名单中"</string>
    <string name="firewall_save_success">保存成功</string>
    <string name="firewall_add_blacklist_wring">如果将该号码加入黑名单,你将不会再收到该号码的消息和来电</string>
</resources>
+5 −0
Original line number Diff line number Diff line
@@ -841,5 +841,10 @@
    <string name="add_to_white_list">Add to white list</string>
    <string name="add_to_black_list">Add to black list</string>
    <string name="dialog_title">Tip</string>
    <string name="firewall_number_len_not_valid">Number is wrong</string>
    <string name="firewall_number_in_black">"Number already in blacklist"</string>
    <string name="firewall_number_in_white">"Number already in whitelist"</string>
    <string name="firewall_save_success">Saved successfully</string>
    <string name="firewall_add_blacklist_wring">if you add this number to blacklsit, you will not receive the messages and calls from it</string>

</resources>
+73 −17
Original line number Diff line number Diff line
@@ -51,6 +51,10 @@ import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface.OnClickListener;
import android.content.DialogInterface;

import com.android.contacts.common.CallUtil;
import com.android.contacts.common.GeoUtil;
@@ -87,6 +91,11 @@ public class CallDetailActivity extends AnalyticsActivity implements ProximitySe
    private static final int LOADER_ID = 0;
    private static final String BUNDLE_CONTACT_URI_EXTRA = "contact_uri_extra";

    //add firewall menu
    private static final Uri WHITELIST_CONTENT_URI = Uri
                             .parse("content://com.android.firewall/whitelistitems");
    private static final Uri BLACKLIST_CONTENT_URI = Uri
                             .parse("content://com.android.firewall/blacklistitems");
    /** The time to wait before enabling the blank the screen due to the proximity sensor. */
    private static final long PROXIMITY_BLANK_DELAY_MILLIS = 100;
    /** The time to wait before disabling the blank the screen due to the proximity sensor. */
@@ -642,26 +651,73 @@ public class CallDetailActivity extends AnalyticsActivity implements ProximitySe

    public void onMenuAddToBlackList(MenuItem menuItem) {
        Bundle blackBundle = new Bundle();
        blackBundle.putString(NUMBER_KEY, mNumber);
        blackBundle.putString(MODE_KEY, "blacklist");
        new AlertDialog.Builder(this)
            .setMessage(getString(R.string.firewall_add_blacklist_wring))
            .setPositiveButton(android.R.string.ok, new OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    if(addNumberToFirewall(true , mNumber)){
                        Toast.makeText(CallDetailActivity.this,
                            getString(R.string.firewall_save_success),
                                Toast.LENGTH_SHORT).show();
                    }
                }
            })
            .setNegativeButton(android.R.string.cancel, null)
            .create().show();

        Intent blackIntent = new Intent();
        blackIntent.setClassName(FIREWALL_APK_NAME, FIREWALL_BLACK_WHITE_LIST);
        blackIntent.setAction(Intent.ACTION_INSERT);
        blackIntent.putExtras(blackBundle);
        startActivity(blackIntent);
    }

    public void onMenuAddToWhiteList(MenuItem menuItem) {
        Bundle whiteBundle = new Bundle();
        whiteBundle.putString(NUMBER_KEY, mNumber);
        whiteBundle.putString(MODE_KEY, "whitelist");

        Intent whiteIntent = new Intent();
        whiteIntent.setClassName(FIREWALL_APK_NAME, FIREWALL_BLACK_WHITE_LIST);
        whiteIntent.setAction(Intent.ACTION_INSERT);
        whiteIntent.putExtras(whiteBundle);
        startActivity(whiteIntent);
        if(addNumberToFirewall(false , mNumber)){
             Toast.makeText(CallDetailActivity.this,
                getString(R.string.firewall_save_success),
                    Toast.LENGTH_SHORT).show();
        }

    }

    private boolean addNumberToFirewall(boolean isBlacklist,String number){
        Log.d(TAG, "number: " + number);
         if (TextUtils.isEmpty(number)) {
            Toast.makeText(CallDetailActivity.this,
                getString(R.string.firewall_number_len_not_valid),
                    Toast.LENGTH_SHORT).show();
            return false;
        }
        boolean ret = true;
        ContentValues values = new ContentValues();
        String queryNumber = number.replaceAll("[\\-\\/ ]", "");
        int len = queryNumber.length();
        if (len > 11){
            queryNumber = number.substring(len - 11, len);
        }
        Uri firewallUri = isBlacklist? BLACKLIST_CONTENT_URI: WHITELIST_CONTENT_URI;
        Cursor fiewallCursor = getContentResolver().query(firewallUri,
                new String[] {
                        "_id", "number", "person_id", "name"
                },
                "number" + " LIKE '%" + queryNumber + "'",
                null,
                null);
        if (fiewallCursor != null){
            if (fiewallCursor.getCount() > 0) {
                fiewallCursor.close();
                fiewallCursor = null;
                 String Stoast = isBlacklist?getString(R.string.firewall_number_in_black)
                                     :getString(R.string.firewall_number_in_white);
                Toast.makeText(CallDetailActivity.this, Stoast,
                    Toast.LENGTH_SHORT).show();
                return false;
            }
            fiewallCursor.close();
            fiewallCursor = null;
        }
        values.put("number", queryNumber);
        values.put("name", "");
        // add new
        Uri mUri = getContentResolver().insert(firewallUri, values);
        return ret;
    }

    public void onMenuRemoveFromCallLog(MenuItem menuItem) {
Loading