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

Commit 6fd22297 authored by Abhijith Shastry's avatar Abhijith Shastry Committed by Android (Google) Code Review
Browse files

Merge "Suppress blocks after texting emergency services." into nyc-dev

parents 50a3cae8 5eccb26b
Loading
Loading
Loading
Loading
+48 −0
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.internal.telephony;

import android.content.Context;
import android.os.AsyncTask;
import android.provider.BlockedNumberContract;
import android.telephony.Rlog;

/**
 * An {@link AsyncTask} that notifies the Blocked number provider that emergency services were
 * contacted. See {@link BlockedNumberContract.SystemContract#notifyEmergencyContact(Context)}
 * for details.
 * {@hide}
 */
public class AsyncEmergencyContactNotifier extends AsyncTask<Void, Void, Void> {
    private static final String TAG = "AsyncEmergencyContactNotifier";

    private final Context mContext;

    public AsyncEmergencyContactNotifier(Context context) {
        mContext = context;
    }

    @Override
    protected Void doInBackground(Void... params) {
        try {
            BlockedNumberContract.SystemContract.notifyEmergencyContact(mContext);
        } catch (Exception e) {
            Rlog.e(TAG, "Exception notifying emergency contact: " + e);
        }
        return null;
    }
}
+4 −0
Original line number Diff line number Diff line
@@ -997,6 +997,10 @@ public abstract class SMSDispatcher extends Handler {

            sendSms(tracker);
        }

        if (PhoneNumberUtils.isLocalEmergencyNumber(mContext, tracker.mDestAddress)) {
            new AsyncEmergencyContactNotifier(mContext).execute();
        }
    }

    /**
+3 −1
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.provider.Telephony.Sms.Intents;
import android.telephony.Rlog;
import android.telephony.ServiceState;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.telephony.GsmAlphabet;
import com.android.internal.telephony.ImsSMSDispatcher;
import com.android.internal.telephony.InboundSmsHandler;
@@ -174,8 +175,9 @@ public final class GsmSMSDispatcher extends SMSDispatcher {
    }

    /** {@inheritDoc} */
    @VisibleForTesting
    @Override
    protected void sendText(String destAddr, String scAddr, String text, PendingIntent sentIntent,
    public void sendText(String destAddr, String scAddr, String text, PendingIntent sentIntent,
            PendingIntent deliveryIntent, Uri messageUri, String callingPkg,
            boolean persistMessage) {
        SmsMessage.SubmitPdu pdu = SmsMessage.getSubmitPdu(
+5 −1
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.telephony.BaseCommands;
import com.android.internal.telephony.CommandException;
import com.android.internal.telephony.CommandsInterface;
import com.android.internal.telephony.SmsResponse;
import com.android.internal.telephony.RadioCapability;
import com.android.internal.telephony.cdma.CdmaSmsBroadcastConfigInfo;
import com.android.internal.telephony.dataconnection.DataCallResponse;
@@ -1072,7 +1073,10 @@ public class SimulatedCommands extends BaseCommands
     *      less the SMSC address
     */
    @Override
    public void sendSMS (String smscPDU, String pdu, Message result) {unimplemented(result);}
    public void sendSMS (String smscPDU, String pdu, Message result) {
        SimulatedCommandsVerifier.getInstance().sendSMS(smscPDU, pdu, result);
        resultSuccess(result, new SmsResponse(0 /*messageRef*/, null, 0));
    }

    /**
     * Send an SMS message, Identical to sendSMS,
+15 −8
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@

package com.android.internal.telephony;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.anyBoolean;
import static org.mockito.Matchers.anyLong;
import static org.mockito.Matchers.anyString;
@@ -38,7 +38,6 @@ import android.os.IBinder;
import android.os.IDeviceIdleController;
import android.os.RegistrantList;
import android.provider.BlockedNumberContract;
import android.provider.Telephony;
import android.telephony.ServiceState;
import android.telephony.TelephonyManager;
import android.test.mock.MockContentProvider;
@@ -404,15 +403,23 @@ public abstract class TelephonyTest {

    public static class FakeBlockedNumberContentProvider extends MockContentProvider {
        public Set<String> mBlockedNumbers = new HashSet<>();
        public int mNumEmergencyContactNotifications = 0;

        @Override
        public Bundle call(String method, String arg, Bundle extras) {
            assertEquals(BlockedNumberContract.SystemContract.METHOD_SHOULD_SYSTEM_BLOCK_NUMBER,
                    method);
            switch (method) {
                case BlockedNumberContract.SystemContract.METHOD_SHOULD_SYSTEM_BLOCK_NUMBER:
                    Bundle bundle = new Bundle();
            bundle.putBoolean(
                    BlockedNumberContract.RES_NUMBER_IS_BLOCKED, mBlockedNumbers.contains(arg));
                    bundle.putBoolean(BlockedNumberContract.RES_NUMBER_IS_BLOCKED,
                            mBlockedNumbers.contains(arg));
                    return bundle;
                case BlockedNumberContract.SystemContract.METHOD_NOTIFY_EMERGENCY_CONTACT:
                    mNumEmergencyContactNotifications++;
                    return new Bundle();
                default:
                    fail("Method not expected: " + method);
            }
            return null;
        }
    }
}
 No newline at end of file
Loading