Set up cross-device InCallService

Bug: 261885804
Test: atest
FrameworksServicesTests:com.android.server.companion.datatransfer.contextsync
Change-Id: I3e7501536fb20bb96fd2798c186e3dfa2a4f67fa
This commit is contained in:
Christine Franks
2022-12-16 11:41:33 -08:00
parent 8987f02fdc
commit 05a124901c
2 changed files with 83 additions and 0 deletions

View File

@@ -7424,6 +7424,14 @@
android:permission="android.permission.BIND_JOB_SERVICE" >
</service>
<service android:name="com.android.server.companion.datatransfer.contextsync.CallMetadataSyncInCallService"
android:permission="android.permission.BIND_INCALL_SERVICE"
android:exported="true">
<intent-filter>
<action android:name="android.telecom.InCallService"/>
</intent-filter>
</service>
<provider
android:name="com.android.server.textclassifier.IconsContentProvider"
android:authorities="com.android.textclassifier.icons"

View File

@@ -0,0 +1,75 @@
/*
* Copyright (C) 2022 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.server.companion.datatransfer.contextsync;
import android.telecom.Call;
import android.telecom.InCallService;
import com.android.internal.annotations.VisibleForTesting;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.atomic.AtomicLong;
/** In-call service to sync call metadata across a user's devices. */
public class CallMetadataSyncInCallService extends InCallService {
@VisibleForTesting
final Set<CrossDeviceCall> mCurrentCalls = new HashSet<>();
@Override
public void onCreate() {
super.onCreate();
mCurrentCalls.addAll(getCalls().stream().map(CrossDeviceCall::new).toList());
}
@Override
public void onCallAdded(Call call) {
onCallAdded(new CrossDeviceCall(call));
}
@VisibleForTesting
void onCallAdded(CrossDeviceCall call) {
mCurrentCalls.add(call);
}
@Override
public void onCallRemoved(Call call) {
mCurrentCalls.removeIf(crossDeviceCall -> crossDeviceCall.getCall().equals(call));
}
/** Data holder for a telecom call and additional metadata. */
public static final class CrossDeviceCall {
private static final AtomicLong sNextId = new AtomicLong(1);
private final Call mCall;
private final long mId;
public CrossDeviceCall(Call call) {
mCall = call;
mId = sNextId.getAndIncrement();
}
public Call getCall() {
return mCall;
}
public long getId() {
return mId;
}
}
}