Add a CallServiceSelector base implementation
Add the base class for implementing CallServiceSelectors. Change-Id: I292d962f1b73d0966af0c484ebddc724f8e6c925
This commit is contained in:
99
telecomm/java/android/telecomm/CallServiceSelector.java
Normal file
99
telecomm/java/android/telecomm/CallServiceSelector.java
Normal file
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Copyright (C) 2014 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.telecomm;
|
||||
|
||||
import android.app.Service;
|
||||
import android.content.Intent;
|
||||
import android.os.Binder;
|
||||
import android.os.IBinder;
|
||||
import android.os.RemoteException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Allows for the organization of {@link CallService}s for outbound calls. Given a call and list of
|
||||
* {@link CallService} IDs, order the list in terms of priority and return it using
|
||||
* {@link #select(CallInfo, List)}. <br />
|
||||
* <br />
|
||||
* Also determine whether a call is switchable (can be moved between {@link CallService}s) or not
|
||||
* using {@link #isSwitchable(CallInfo)}.
|
||||
*/
|
||||
public abstract class CallServiceSelector extends Service {
|
||||
|
||||
/** Manages the binder calls so that the implementor does not need to deal it. */
|
||||
private final class CallServiceSelectorBinder extends ICallServiceSelector.Stub {
|
||||
@Override
|
||||
public void isSwitchable(CallInfo callInfo, ICallSwitchabilityResponse response)
|
||||
throws RemoteException {
|
||||
// Ensure that we're running with the app's normal permission level
|
||||
long ident = Binder.clearCallingIdentity();
|
||||
try {
|
||||
response.setIsSwitchable(CallServiceSelector.this.isSwitchable(callInfo));
|
||||
} finally {
|
||||
Binder.restoreCallingIdentity(ident);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void select(CallInfo callInfo, List<String> callServiceIds,
|
||||
ICallServiceSelectionResponse response) throws RemoteException {
|
||||
// Ensure that we're running with the app's normal permission level
|
||||
long ident = Binder.clearCallingIdentity();
|
||||
try {
|
||||
response.setSelectedCallServiceIds(
|
||||
CallServiceSelector.this.select(callInfo, callServiceIds));
|
||||
} finally {
|
||||
Binder.restoreCallingIdentity(ident);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final CallServiceSelectorBinder mBinder;
|
||||
|
||||
protected CallServiceSelector() {
|
||||
mBinder = new CallServiceSelectorBinder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final IBinder onBind(Intent intent) {
|
||||
return mBinder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines (and returns) whether the given call is switchable. That is, whether the call can
|
||||
* be moved to another {@link CallService} seamlessly.<br />
|
||||
* <br />
|
||||
* This method is not called on the UI thread and is safe to block.
|
||||
*
|
||||
* @param callInfo The call being potentially switched between {@link CallService}s.
|
||||
* @return Whether the given call is switchable or not.
|
||||
*/
|
||||
protected abstract boolean isSwitchable(CallInfo callInfo);
|
||||
|
||||
/**
|
||||
* Return a list of prioritized {@link CallService}s which should be used to complete the given
|
||||
* call.<br />
|
||||
* <br />
|
||||
* This method is not called on the UI thread and is safe to block.
|
||||
*
|
||||
* @param callInfo The call being placed using the {@link CallService}s.
|
||||
* @param callServiceIds The IDs of the {@link CallService}s to organize for the call.
|
||||
*
|
||||
* @return A list of prioritized {@link CallService} IDs to use to complete the given call.
|
||||
*/
|
||||
protected abstract List<String> select(CallInfo callInfo, List<String> callServiceIds);
|
||||
}
|
||||
Reference in New Issue
Block a user