/* * 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 android.telecom; import android.annotation.NonNull; import android.annotation.SdkConstant; import android.app.Service; import android.content.ComponentName; import android.content.Intent; import android.os.Handler; import android.os.IBinder; import android.os.Looper; import android.os.Message; import android.os.RemoteException; import com.android.internal.os.SomeArgs; import com.android.internal.telecom.ICallScreeningAdapter; import com.android.internal.telecom.ICallScreeningService; /** * This service can be implemented by the default dialer (see * {@link TelecomManager#getDefaultDialerPackage()}) to allow or disallow incoming calls before * they are shown to a user. *
* Below is an example manifest registration for a {@code CallScreeningService}. *
* {@code
*
*
*
*
*
* }
*
* * A CallScreeningService performs two functions: *
* Note: Calls will still be logged with type * {@link android.provider.CallLog.Calls#BLOCKED_TYPE}, regardless of how this property * is set. */ public Builder setSkipCallLog(boolean shouldSkipCallLog) { mShouldSkipCallLog = shouldSkipCallLog; return this; } /** * Sets whether a missed call notification should not be shown for the incoming call. * This property should only be set to true if the call is disallowed. */ public Builder setSkipNotification(boolean shouldSkipNotification) { mShouldSkipNotification = shouldSkipNotification; return this; } public CallResponse build() { return new CallResponse( mShouldDisallowCall, mShouldRejectCall, mShouldSkipCallLog, mShouldSkipNotification); } } } public CallScreeningService() { } @Override public IBinder onBind(Intent intent) { Log.v(this, "onBind"); return new CallScreeningBinder(); } @Override public boolean onUnbind(Intent intent) { Log.v(this, "onUnbind"); return false; } /** * Called when a new incoming call is added. * {@link CallScreeningService#respondToCall(Call.Details, CallScreeningService.CallResponse)} * should be called to allow or disallow the call. *
* Note: The {@link Call.Details} instance provided to a call screening service will only have * the following properties set. The rest of the {@link Call.Details} properties will be set to * their default value or {@code null}. *
* The {@link CallScreeningService} calls this method to inform the system whether the call * should be silently blocked or not. * * @param callDetails The call to allow. *
* Must be the same {@link Call.Details call} which was provided to the * {@link CallScreeningService} via {@link #onScreenCall(Call.Details)}. * @param response The {@link CallScreeningService.CallResponse} which contains information * about how to respond to a call. */ public final void respondToCall(@NonNull Call.Details callDetails, @NonNull CallResponse response) { try { if (response.getDisallowCall()) { mCallScreeningAdapter.disallowCall( callDetails.getTelecomCallId(), response.getRejectCall(), !response.getSkipCallLog(), !response.getSkipNotification(), new ComponentName(getPackageName(), getClass().getName())); } else { mCallScreeningAdapter.allowCall(callDetails.getTelecomCallId()); } } catch (RemoteException e) { } } /** * Provide {@link CallIdentification} information about a {@link Call.Details call}. *
* The {@link CallScreeningService} calls this method to provide information it has identified * about a {@link Call.Details call}. This information will potentially be shown to the user * in the {@link InCallService dialer} app. It will be logged to the * {@link android.provider.CallLog}. *
* A {@link CallScreeningService} should only call this method for calls for which it is able to * provide some {@link CallIdentification} for. {@link CallIdentification} instances with no * fields set will be ignored by the system. * * @param callDetails The call to provide information for. *
* Must be the same {@link Call.Details call} which was provided to the * {@link CallScreeningService} via {@link #onScreenCall(Call.Details)}. * @param identification An instance of {@link CallIdentification} with information about the * {@link Call.Details call}. */ public final void provideCallIdentification(@NonNull Call.Details callDetails, @NonNull CallIdentification identification) { try { mCallScreeningAdapter.provideCallIdentification(callDetails.getTelecomCallId(), identification); } catch (RemoteException e) { } } }