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

Commit 0831bdd3 authored by Hall Liu's avatar Hall Liu Committed by Gerrit Code Review
Browse files

Merge "Remove hidden Telephony API usages from Telecom"

parents a96f8a59 d98f0924
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ import android.os.SystemVibrator;
import android.os.Trace;
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.BlockedNumberContract;
import android.provider.BlockedNumberContract.SystemContract;
import android.provider.CallLog.Calls;
import android.provider.Settings;
@@ -112,6 +113,7 @@ import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
@@ -2000,7 +2002,9 @@ public class CallsManager extends Call.ListenerBase
        }

        if (call.isEmergencyCall()) {
            new AsyncEmergencyContactNotifier(mContext).execute();
            Executors.defaultThreadFactory().newThread(() ->
                    BlockedNumberContract.SystemContract.notifyEmergencyContact(mContext))
                    .start();
        }

        final boolean requireCallCapableAccountByHandle = mContext.getResources().getBoolean(
@@ -4738,6 +4742,10 @@ public class CallsManager extends Call.ListenerBase
        }
    }

    public Context getContext() {
        return mContext;
    }

    /**
     * Determines if there is an ongoing emergency call. This can be either an outgoing emergency
     * call, or a number which has been identified by the number as an emergency call.
+6 −14
Original line number Diff line number Diff line
@@ -16,12 +16,9 @@

package com.android.server.telecom;

import android.os.RemoteException;
import android.os.ServiceManager;
import android.telecom.Log;
import android.telephony.TelephonyManager;

import com.android.internal.telephony.ITelephonyRegistry;
import android.telephony.TelephonyRegistryManager;

/**
 * Send a {@link TelephonyManager#ACTION_PHONE_STATE_CHANGED} broadcast when the call state
@@ -30,13 +27,12 @@ import com.android.internal.telephony.ITelephonyRegistry;
final class PhoneStateBroadcaster extends CallsManagerListenerBase {

    private final CallsManager mCallsManager;
    private final ITelephonyRegistry mRegistry;
    private final TelephonyRegistryManager mRegistry;
    private int mCurrentState = TelephonyManager.CALL_STATE_IDLE;

    public PhoneStateBroadcaster(CallsManager callsManager) {
        mCallsManager = callsManager;
        mRegistry = ITelephonyRegistry.Stub.asInterface(ServiceManager.getService(
                "telephony.registry"));
        mRegistry = callsManager.getContext().getSystemService(TelephonyRegistryManager.class);
        if (mRegistry == null) {
            Log.w(this, "TelephonyRegistry is null");
        }
@@ -112,13 +108,9 @@ final class PhoneStateBroadcaster extends CallsManagerListenerBase {
            callHandle = call.getHandle().getSchemeSpecificPart();
        }

        try {
        if (mRegistry != null) {
                mRegistry.notifyCallStateForAllSubs(phoneState, callHandle);
            mRegistry.notifyCallStateChangedForAllSubscriptions(phoneState, callHandle);
            Log.i(this, "Broadcasted state change: %s", mCurrentState);
        }
        } catch (RemoteException e) {
            Log.w(this, "RemoteException when notifying TelephonyRegistry of call state change.");
        }
    }
}
+34 −10
Original line number Diff line number Diff line
@@ -18,27 +18,51 @@ package com.android.server.telecom.callfiltering;

import android.content.Context;
import android.os.Bundle;
import android.provider.BlockedNumberContract;
import android.telecom.Log;

import com.android.internal.telephony.BlockChecker;

public class BlockCheckerAdapter {
    private static final String TAG = BlockCheckerAdapter.class.getSimpleName();

    public BlockCheckerAdapter() { }

    /**
     * Check whether the number is blocked.
     * Returns the call blocking status for the {@code phoneNumber}.
     * <p>
     * This method catches all underlying exceptions to ensure that this method never throws any
     * exception.
     *
     * @param context the context of the caller.
     * @param number the number to check.
     * @param phoneNumber the number to check.
     * @param extras the extra attribute of the number.
     * @return result code indicating if the number should be blocked, and if so why.
     *         Valid values are: {@link android.provider.BlockedNumberContract#STATUS_NOT_BLOCKED},
     *         {@link android.provider.BlockedNumberContract#STATUS_BLOCKED_IN_LIST},
     *         {@link android.provider.BlockedNumberContract#STATUS_BLOCKED_NOT_IN_CONTACTS},
     *         {@link android.provider.BlockedNumberContract#STATUS_BLOCKED_PAYPHONE},
     *         {@link android.provider.BlockedNumberContract#STATUS_BLOCKED_RESTRICTED},
     *         {@link android.provider.BlockedNumberContract#STATUS_BLOCKED_UNKNOWN_NUMBER}.
     *         Valid values are: {@link BlockedNumberContract#STATUS_NOT_BLOCKED},
     *         {@link BlockedNumberContract#STATUS_BLOCKED_IN_LIST},
     *         {@link BlockedNumberContract#STATUS_BLOCKED_NOT_IN_CONTACTS},
     *         {@link BlockedNumberContract#STATUS_BLOCKED_PAYPHONE},
     *         {@link BlockedNumberContract#STATUS_BLOCKED_RESTRICTED},
     *         {@link BlockedNumberContract#STATUS_BLOCKED_UNKNOWN_NUMBER}.
     */
    public int getBlockStatus(Context context, String number, Bundle extras) {
        return BlockChecker.getBlockStatus(context, number, extras);
    public int getBlockStatus(Context context, String phoneNumber, Bundle extras) {
        int blockStatus = BlockedNumberContract.STATUS_NOT_BLOCKED;
        long startTimeNano = System.nanoTime();

        try {
            blockStatus = BlockedNumberContract.SystemContract.shouldSystemBlockNumber(
                    context, phoneNumber, extras);
            if (blockStatus != BlockedNumberContract.STATUS_NOT_BLOCKED) {
                Log.d(TAG, phoneNumber + " is blocked.");
            }
        } catch (Exception e) {
            Log.e(TAG, e, "Exception checking for blocked number");
        }

        int durationMillis = (int) ((System.nanoTime() - startTimeNano) / 1000000);
        if (durationMillis > 500 || Log.isLoggable(android.util.Log.DEBUG)) {
            Log.d(TAG, "Blocked number lookup took: " + durationMillis + " ms.");
        }
        return blockStatus;
    }
}
+5 −2
Original line number Diff line number Diff line
@@ -378,10 +378,13 @@ public class BasicCallTests extends TelecomSystemTest {
        waitForHandlerAction(mConnectionServiceFixtureA.mConnectionServiceDelegate.getHandler(),
                TEST_TIMEOUT);
        assertEquals(1, mCallerInfoAsyncQueryFactoryFixture.mRequests.size());
        for (CallerInfoAsyncQueryFactoryFixture.Request request :
                mCallerInfoAsyncQueryFactoryFixture.mRequests) {

        CallerInfo sendToVoicemailCallerInfo = new CallerInfo();
        sendToVoicemailCallerInfo.shouldSendToVoicemail = true;
        sendToVoicemailCallerInfo.contactExists = true;
        mCallerInfoAsyncQueryFactoryFixture.setResponse(sendToVoicemailCallerInfo);
        for (CallerInfoAsyncQueryFactoryFixture.Request request :
                mCallerInfoAsyncQueryFactoryFixture.mRequests) {
            request.replyWithCallerInfo(sendToVoicemailCallerInfo);
        }

+10 −0
Original line number Diff line number Diff line
@@ -27,7 +27,9 @@ import org.mockito.Mockito;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Controls a test {@link CallerInfoAsyncQueryFactory} to abstract away the asynchronous retrieval
@@ -58,16 +60,24 @@ public class CallerInfoAsyncQueryFactoryFixture implements
            r.mCookie = cookie;
            r.mListener = listener;
            mRequests.add(r);
            if (mStoredResponse != null) {
                listener.onQueryComplete(token, cookie, mStoredResponse);
            }
            return Mockito.mock(CallerInfoAsyncQuery.class);
        }
    };

    final List<Request> mRequests = Collections.synchronizedList(new ArrayList<Request>());
    private CallerInfo mStoredResponse;

    public CallerInfoAsyncQueryFactoryFixture() throws Exception {
        Log.i(this, "Creating ...");
    }

    public void setResponse(CallerInfo callerInfo) {
        mStoredResponse = callerInfo;
    }

    @Override
    public CallerInfoAsyncQueryFactory getTestDouble() {
        return mCallerInfoAsyncQueryFactory;
Loading