Merge "Make call of CrossDeviceCall constructor nonnull" into udc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
6ea7367eb5
@@ -16,12 +16,14 @@
|
||||
|
||||
package com.android.server.companion.datatransfer.contextsync;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.telecom.Call;
|
||||
import android.telecom.CallAudioState;
|
||||
import android.telecom.VideoProfile;
|
||||
@@ -46,7 +48,7 @@ public class CrossDeviceCall {
|
||||
private static final AtomicLong sNextId = new AtomicLong(1);
|
||||
|
||||
private final long mId;
|
||||
private final Call mCall;
|
||||
private Call mCall;
|
||||
@VisibleForTesting boolean mIsEnterprise;
|
||||
@VisibleForTesting boolean mIsOtt;
|
||||
private final String mCallingAppPackageName;
|
||||
@@ -58,17 +60,23 @@ public class CrossDeviceCall {
|
||||
private boolean mIsMuted;
|
||||
private final Set<Integer> mControls = new HashSet<>();
|
||||
|
||||
public CrossDeviceCall(PackageManager packageManager, Call call,
|
||||
public CrossDeviceCall(PackageManager packageManager, @NonNull Call call,
|
||||
CallAudioState callAudioState) {
|
||||
this(packageManager, call.getDetails(), callAudioState);
|
||||
mCall = call;
|
||||
final Bundle extras = new Bundle();
|
||||
extras.putLong(EXTRA_CALL_ID, mId);
|
||||
call.putExtras(extras);
|
||||
}
|
||||
|
||||
CrossDeviceCall(PackageManager packageManager, Call.Details callDetails,
|
||||
CallAudioState callAudioState) {
|
||||
mId = sNextId.getAndIncrement();
|
||||
mCall = call;
|
||||
mCallingAppPackageName = call != null
|
||||
? call.getDetails().getAccountHandle().getComponentName().getPackageName() : null;
|
||||
mIsOtt = call != null
|
||||
&& (call.getDetails().getCallCapabilities() & Call.Details.PROPERTY_SELF_MANAGED)
|
||||
mCallingAppPackageName =
|
||||
callDetails.getAccountHandle().getComponentName().getPackageName();
|
||||
mIsOtt = (callDetails.getCallCapabilities() & Call.Details.PROPERTY_SELF_MANAGED)
|
||||
== Call.Details.PROPERTY_SELF_MANAGED;
|
||||
mIsEnterprise = call != null
|
||||
&& (call.getDetails().getCallProperties() & Call.Details.PROPERTY_ENTERPRISE_CALL)
|
||||
mIsEnterprise = (callDetails.getCallProperties() & Call.Details.PROPERTY_ENTERPRISE_CALL)
|
||||
== Call.Details.PROPERTY_ENTERPRISE_CALL;
|
||||
try {
|
||||
final ApplicationInfo applicationInfo = packageManager
|
||||
@@ -81,9 +89,7 @@ public class CrossDeviceCall {
|
||||
Slog.e(TAG, "Could not get application info for package " + mCallingAppPackageName, e);
|
||||
}
|
||||
mIsMuted = callAudioState != null && callAudioState.isMuted();
|
||||
if (call != null) {
|
||||
updateCallDetails(call.getDetails());
|
||||
}
|
||||
updateCallDetails(callDetails);
|
||||
}
|
||||
|
||||
private byte[] renderDrawableToByteArray(Drawable drawable) {
|
||||
@@ -108,10 +114,10 @@ public class CrossDeviceCall {
|
||||
final Canvas canvas = new Canvas(bitmap);
|
||||
drawable.setBounds(0, 0, bitmap.getWidth(), bitmap.getHeight());
|
||||
drawable.draw(canvas);
|
||||
return renderBitmapToByteArray(bitmap);
|
||||
} finally {
|
||||
bitmap.recycle();
|
||||
}
|
||||
return renderBitmapToByteArray(bitmap);
|
||||
}
|
||||
|
||||
private byte[] renderBitmapToByteArray(Bitmap bitmap) {
|
||||
|
||||
@@ -18,9 +18,11 @@ package com.android.server.companion.datatransfer.contextsync;
|
||||
|
||||
import static com.google.common.truth.Truth.assertWithMessage;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.platform.test.annotations.Presubmit;
|
||||
import android.telecom.Call;
|
||||
import android.telecom.ParcelableCall;
|
||||
import android.telecom.PhoneAccountHandle;
|
||||
import android.testing.AndroidTestingRunner;
|
||||
|
||||
import androidx.test.InstrumentationRegistry;
|
||||
@@ -37,12 +39,14 @@ public class CrossDeviceCallTest {
|
||||
|
||||
private static final String CALLER_DISPLAY_NAME = "name";
|
||||
private static final String CONTACT_DISPLAY_NAME = "contact";
|
||||
private final Call.Details mUninitializedCallDetails = createCallDetails(
|
||||
/* state= */ -1, /* capabilities= */ 0);
|
||||
|
||||
@Test
|
||||
public void updateCallDetails_uninitialized() {
|
||||
final CrossDeviceCall crossDeviceCall = new CrossDeviceCall(
|
||||
InstrumentationRegistry.getTargetContext().getPackageManager(), /* call= */
|
||||
null, /* callAudioState= */ null);
|
||||
InstrumentationRegistry.getTargetContext().getPackageManager(),
|
||||
mUninitializedCallDetails, /* callAudioState= */ null);
|
||||
assertWithMessage("Wrong status").that(crossDeviceCall.getStatus())
|
||||
.isEqualTo(android.companion.Telecom.Call.UNKNOWN_STATUS);
|
||||
assertWithMessage("Wrong controls").that(crossDeviceCall.getControls()).isEmpty();
|
||||
@@ -51,8 +55,8 @@ public class CrossDeviceCallTest {
|
||||
@Test
|
||||
public void updateCallDetails_ringing() {
|
||||
final CrossDeviceCall crossDeviceCall = new CrossDeviceCall(
|
||||
InstrumentationRegistry.getTargetContext().getPackageManager(), /* call= */
|
||||
null, /* callAudioState= */ null);
|
||||
InstrumentationRegistry.getTargetContext().getPackageManager(),
|
||||
mUninitializedCallDetails, /* callAudioState= */ null);
|
||||
crossDeviceCall.updateCallDetails(createCallDetails(Call.STATE_RINGING,
|
||||
Call.Details.CAPABILITY_HOLD | Call.Details.CAPABILITY_MUTE));
|
||||
assertWithMessage("Wrong status").that(crossDeviceCall.getStatus())
|
||||
@@ -66,8 +70,8 @@ public class CrossDeviceCallTest {
|
||||
@Test
|
||||
public void updateCallDetails_ongoing() {
|
||||
final CrossDeviceCall crossDeviceCall = new CrossDeviceCall(
|
||||
InstrumentationRegistry.getTargetContext().getPackageManager(), /* call= */
|
||||
null, /* callAudioState= */ null);
|
||||
InstrumentationRegistry.getTargetContext().getPackageManager(),
|
||||
mUninitializedCallDetails, /* callAudioState= */ null);
|
||||
crossDeviceCall.updateCallDetails(createCallDetails(Call.STATE_ACTIVE,
|
||||
Call.Details.CAPABILITY_HOLD | Call.Details.CAPABILITY_MUTE));
|
||||
assertWithMessage("Wrong status").that(crossDeviceCall.getStatus())
|
||||
@@ -81,8 +85,8 @@ public class CrossDeviceCallTest {
|
||||
@Test
|
||||
public void updateCallDetails_holding() {
|
||||
final CrossDeviceCall crossDeviceCall = new CrossDeviceCall(
|
||||
InstrumentationRegistry.getTargetContext().getPackageManager(), /* call= */
|
||||
null, /* callAudioState= */ null);
|
||||
InstrumentationRegistry.getTargetContext().getPackageManager(),
|
||||
mUninitializedCallDetails, /* callAudioState= */ null);
|
||||
crossDeviceCall.updateCallDetails(createCallDetails(Call.STATE_HOLDING,
|
||||
Call.Details.CAPABILITY_HOLD | Call.Details.CAPABILITY_MUTE));
|
||||
assertWithMessage("Wrong status").that(crossDeviceCall.getStatus())
|
||||
@@ -95,8 +99,8 @@ public class CrossDeviceCallTest {
|
||||
@Test
|
||||
public void updateCallDetails_cannotHold() {
|
||||
final CrossDeviceCall crossDeviceCall = new CrossDeviceCall(
|
||||
InstrumentationRegistry.getTargetContext().getPackageManager(), /* call= */
|
||||
null, /* callAudioState= */ null);
|
||||
InstrumentationRegistry.getTargetContext().getPackageManager(),
|
||||
mUninitializedCallDetails, /* callAudioState= */ null);
|
||||
crossDeviceCall.updateCallDetails(
|
||||
createCallDetails(Call.STATE_ACTIVE, Call.Details.CAPABILITY_MUTE));
|
||||
assertWithMessage("Wrong status").that(crossDeviceCall.getStatus())
|
||||
@@ -109,8 +113,8 @@ public class CrossDeviceCallTest {
|
||||
@Test
|
||||
public void updateCallDetails_cannotMute() {
|
||||
final CrossDeviceCall crossDeviceCall = new CrossDeviceCall(
|
||||
InstrumentationRegistry.getTargetContext().getPackageManager(), /* call= */
|
||||
null, /* callAudioState= */ null);
|
||||
InstrumentationRegistry.getTargetContext().getPackageManager(),
|
||||
mUninitializedCallDetails, /* callAudioState= */ null);
|
||||
crossDeviceCall.updateCallDetails(
|
||||
createCallDetails(Call.STATE_ACTIVE, Call.Details.CAPABILITY_HOLD));
|
||||
assertWithMessage("Wrong status").that(crossDeviceCall.getStatus())
|
||||
@@ -123,8 +127,8 @@ public class CrossDeviceCallTest {
|
||||
@Test
|
||||
public void updateCallDetails_transitionRingingToOngoing() {
|
||||
final CrossDeviceCall crossDeviceCall = new CrossDeviceCall(
|
||||
InstrumentationRegistry.getTargetContext().getPackageManager(), /* call= */
|
||||
null, /* callAudioState= */ null);
|
||||
InstrumentationRegistry.getTargetContext().getPackageManager(),
|
||||
mUninitializedCallDetails, /* callAudioState= */ null);
|
||||
crossDeviceCall.updateCallDetails(createCallDetails(Call.STATE_RINGING,
|
||||
Call.Details.CAPABILITY_HOLD | Call.Details.CAPABILITY_MUTE));
|
||||
assertWithMessage("Wrong status for ringing state").that(crossDeviceCall.getStatus())
|
||||
@@ -146,8 +150,8 @@ public class CrossDeviceCallTest {
|
||||
@Test
|
||||
public void updateSilencedIfRinging_ringing_silenced() {
|
||||
final CrossDeviceCall crossDeviceCall = new CrossDeviceCall(
|
||||
InstrumentationRegistry.getTargetContext().getPackageManager(), /* call= */
|
||||
null, /* callAudioState= */ null);
|
||||
InstrumentationRegistry.getTargetContext().getPackageManager(),
|
||||
mUninitializedCallDetails, /* callAudioState= */ null);
|
||||
crossDeviceCall.updateCallDetails(createCallDetails(Call.STATE_RINGING,
|
||||
Call.Details.CAPABILITY_HOLD | Call.Details.CAPABILITY_MUTE));
|
||||
crossDeviceCall.updateSilencedIfRinging();
|
||||
@@ -161,8 +165,8 @@ public class CrossDeviceCallTest {
|
||||
@Test
|
||||
public void updateSilencedIfRinging_notRinging_notSilenced() {
|
||||
final CrossDeviceCall crossDeviceCall = new CrossDeviceCall(
|
||||
InstrumentationRegistry.getTargetContext().getPackageManager(), /* call= */
|
||||
null, /* callAudioState= */ null);
|
||||
InstrumentationRegistry.getTargetContext().getPackageManager(),
|
||||
mUninitializedCallDetails, /* callAudioState= */ null);
|
||||
crossDeviceCall.updateCallDetails(createCallDetails(Call.STATE_ACTIVE,
|
||||
Call.Details.CAPABILITY_HOLD | Call.Details.CAPABILITY_MUTE));
|
||||
crossDeviceCall.updateSilencedIfRinging();
|
||||
@@ -177,8 +181,8 @@ public class CrossDeviceCallTest {
|
||||
@Test
|
||||
public void getReadableCallerId_enterpriseCall_adminBlocked_ott() {
|
||||
final CrossDeviceCall crossDeviceCall = new CrossDeviceCall(
|
||||
InstrumentationRegistry.getTargetContext().getPackageManager(), /* call= */
|
||||
null, /* callAudioState= */ null);
|
||||
InstrumentationRegistry.getTargetContext().getPackageManager(),
|
||||
mUninitializedCallDetails, /* callAudioState= */ null);
|
||||
crossDeviceCall.mIsEnterprise = true;
|
||||
crossDeviceCall.mIsOtt = true;
|
||||
crossDeviceCall.updateCallDetails(
|
||||
@@ -193,8 +197,8 @@ public class CrossDeviceCallTest {
|
||||
@Test
|
||||
public void getReadableCallerId_enterpriseCall_adminUnblocked_ott() {
|
||||
final CrossDeviceCall crossDeviceCall = new CrossDeviceCall(
|
||||
InstrumentationRegistry.getTargetContext().getPackageManager(), /* call= */
|
||||
null, /* callAudioState= */ null);
|
||||
InstrumentationRegistry.getTargetContext().getPackageManager(),
|
||||
mUninitializedCallDetails, /* callAudioState= */ null);
|
||||
crossDeviceCall.mIsEnterprise = true;
|
||||
crossDeviceCall.mIsOtt = true;
|
||||
crossDeviceCall.updateCallDetails(
|
||||
@@ -209,8 +213,8 @@ public class CrossDeviceCallTest {
|
||||
@Test
|
||||
public void getReadableCallerId_enterpriseCall_adminBlocked_pstn() {
|
||||
final CrossDeviceCall crossDeviceCall = new CrossDeviceCall(
|
||||
InstrumentationRegistry.getTargetContext().getPackageManager(), /* call= */
|
||||
null, /* callAudioState= */ null);
|
||||
InstrumentationRegistry.getTargetContext().getPackageManager(),
|
||||
mUninitializedCallDetails, /* callAudioState= */ null);
|
||||
crossDeviceCall.mIsEnterprise = true;
|
||||
crossDeviceCall.mIsOtt = false;
|
||||
crossDeviceCall.updateCallDetails(
|
||||
@@ -225,8 +229,8 @@ public class CrossDeviceCallTest {
|
||||
@Test
|
||||
public void getReadableCallerId_nonEnterpriseCall_adminBlocked_ott() {
|
||||
final CrossDeviceCall crossDeviceCall = new CrossDeviceCall(
|
||||
InstrumentationRegistry.getTargetContext().getPackageManager(), /* call= */
|
||||
null, /* callAudioState= */ null);
|
||||
InstrumentationRegistry.getTargetContext().getPackageManager(),
|
||||
mUninitializedCallDetails, /* callAudioState= */ null);
|
||||
crossDeviceCall.mIsEnterprise = false;
|
||||
crossDeviceCall.mIsOtt = true;
|
||||
crossDeviceCall.updateCallDetails(
|
||||
@@ -241,8 +245,8 @@ public class CrossDeviceCallTest {
|
||||
@Test
|
||||
public void getReadableCallerId_nonEnterpriseCall_adminUnblocked_ott() {
|
||||
final CrossDeviceCall crossDeviceCall = new CrossDeviceCall(
|
||||
InstrumentationRegistry.getTargetContext().getPackageManager(), /* call= */
|
||||
null, /* callAudioState= */ null);
|
||||
InstrumentationRegistry.getTargetContext().getPackageManager(),
|
||||
mUninitializedCallDetails, /* callAudioState= */ null);
|
||||
crossDeviceCall.mIsEnterprise = false;
|
||||
crossDeviceCall.mIsOtt = true;
|
||||
crossDeviceCall.updateCallDetails(
|
||||
@@ -257,8 +261,8 @@ public class CrossDeviceCallTest {
|
||||
@Test
|
||||
public void getReadableCallerId_nonEnterpriseCall_adminBlocked_pstn() {
|
||||
final CrossDeviceCall crossDeviceCall = new CrossDeviceCall(
|
||||
InstrumentationRegistry.getTargetContext().getPackageManager(), /* call= */
|
||||
null, /* callAudioState= */ null);
|
||||
InstrumentationRegistry.getTargetContext().getPackageManager(),
|
||||
mUninitializedCallDetails, /* callAudioState= */ null);
|
||||
crossDeviceCall.mIsEnterprise = false;
|
||||
crossDeviceCall.mIsOtt = false;
|
||||
crossDeviceCall.updateCallDetails(
|
||||
@@ -273,8 +277,8 @@ public class CrossDeviceCallTest {
|
||||
@Test
|
||||
public void getReadableCallerId_nonEnterpriseCall_adminUnblocked_pstn() {
|
||||
final CrossDeviceCall crossDeviceCall = new CrossDeviceCall(
|
||||
InstrumentationRegistry.getTargetContext().getPackageManager(), /* call= */
|
||||
null, /* callAudioState= */ null);
|
||||
InstrumentationRegistry.getTargetContext().getPackageManager(),
|
||||
mUninitializedCallDetails, /* callAudioState= */ null);
|
||||
crossDeviceCall.mIsEnterprise = false;
|
||||
crossDeviceCall.mIsOtt = false;
|
||||
crossDeviceCall.updateCallDetails(
|
||||
@@ -294,6 +298,8 @@ public class CrossDeviceCallTest {
|
||||
parcelableCallBuilder.setCapabilities(capabilities);
|
||||
parcelableCallBuilder.setState(state);
|
||||
parcelableCallBuilder.setConferenceableCallIds(Collections.emptyList());
|
||||
parcelableCallBuilder.setAccountHandle(new PhoneAccountHandle(
|
||||
new ComponentName("com.google.test", "com.google.test.Activity"), "label"));
|
||||
return Call.Details.createFromParcelableCall(parcelableCallBuilder.createParcelableCall());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user