Loading services/companion/java/com/android/server/companion/datatransfer/contextsync/CrossDeviceCall.java +20 −2 Original line number Diff line number Diff line Loading @@ -45,10 +45,13 @@ public class CrossDeviceCall { private final long mId; private final Call mCall; @VisibleForTesting boolean mIsEnterprise; @VisibleForTesting boolean mIsOtt; private String mCallingAppName; private byte[] mCallingAppIcon; private String mCallerDisplayName; private int mStatus = android.companion.Telecom.Call.UNKNOWN_STATUS; private String mContactDisplayName; private boolean mIsMuted; private final Set<Integer> mControls = new HashSet<>(); Loading @@ -58,6 +61,12 @@ public class CrossDeviceCall { mCall = call; final String callingAppPackageName = call != null ? call.getDetails().getAccountHandle().getComponentName().getPackageName() : null; mIsOtt = call != null && (call.getDetails().getCallCapabilities() & Call.Details.PROPERTY_SELF_MANAGED) == Call.Details.PROPERTY_SELF_MANAGED; mIsEnterprise = call != null && (call.getDetails().getCallProperties() & Call.Details.PROPERTY_ENTERPRISE_CALL) == Call.Details.PROPERTY_ENTERPRISE_CALL; try { final ApplicationInfo applicationInfo = packageManager .getApplicationInfo(callingAppPackageName, Loading Loading @@ -133,6 +142,7 @@ public class CrossDeviceCall { @VisibleForTesting void updateCallDetails(Call.Details callDetails) { mCallerDisplayName = callDetails.getCallerDisplayName(); mContactDisplayName = callDetails.getContactDisplayName(); mStatus = convertStateToStatus(callDetails.getState()); mControls.clear(); if (mStatus == android.companion.Telecom.Call.RINGING Loading Loading @@ -198,9 +208,17 @@ public class CrossDeviceCall { return mCallingAppIcon; } public String getReadableCallerId() { /** * Get a human-readable "caller id" to display as the origin of the call. * * @param isAdminBlocked whether there is an admin that has blocked contacts over Bluetooth */ public String getReadableCallerId(boolean isAdminBlocked) { if (mIsOtt) { return mCallerDisplayName; } return mIsEnterprise && isAdminBlocked ? mCallerDisplayName : mContactDisplayName; } public int getStatus() { return mStatus; Loading services/tests/servicestests/src/com/android/server/companion/datatransfer/contextsync/CrossDeviceCallTest.java +117 −1 Original line number Diff line number Diff line Loading @@ -35,6 +35,9 @@ import java.util.Set; @RunWith(AndroidTestingRunner.class) public class CrossDeviceCallTest { private static final String CALLER_DISPLAY_NAME = "name"; private static final String CONTACT_DISPLAY_NAME = "contact"; @Test public void updateCallDetails_uninitialized() { final CrossDeviceCall crossDeviceCall = new CrossDeviceCall( Loading Loading @@ -171,10 +174,123 @@ public class CrossDeviceCallTest { android.companion.Telecom.Call.PUT_ON_HOLD)); } @Test public void getReadableCallerId_enterpriseCall_adminBlocked_ott() { final CrossDeviceCall crossDeviceCall = new CrossDeviceCall( InstrumentationRegistry.getTargetContext().getPackageManager(), /* call= */ null, /* callAudioState= */ null); crossDeviceCall.mIsEnterprise = true; crossDeviceCall.mIsOtt = true; crossDeviceCall.updateCallDetails( createCallDetails(Call.STATE_ACTIVE, /* capabilities= */ 0)); final String result = crossDeviceCall.getReadableCallerId(true); assertWithMessage("Wrong caller id").that(result) .isEqualTo(CALLER_DISPLAY_NAME); } @Test public void getReadableCallerId_enterpriseCall_adminUnblocked_ott() { final CrossDeviceCall crossDeviceCall = new CrossDeviceCall( InstrumentationRegistry.getTargetContext().getPackageManager(), /* call= */ null, /* callAudioState= */ null); crossDeviceCall.mIsEnterprise = true; crossDeviceCall.mIsOtt = true; crossDeviceCall.updateCallDetails( createCallDetails(Call.STATE_ACTIVE, /* capabilities= */ 0)); final String result = crossDeviceCall.getReadableCallerId(false); assertWithMessage("Wrong caller id").that(result) .isEqualTo(CALLER_DISPLAY_NAME); } @Test public void getReadableCallerId_enterpriseCall_adminBlocked_pstn() { final CrossDeviceCall crossDeviceCall = new CrossDeviceCall( InstrumentationRegistry.getTargetContext().getPackageManager(), /* call= */ null, /* callAudioState= */ null); crossDeviceCall.mIsEnterprise = true; crossDeviceCall.mIsOtt = false; crossDeviceCall.updateCallDetails( createCallDetails(Call.STATE_ACTIVE, /* capabilities= */ 0)); final String result = crossDeviceCall.getReadableCallerId(true); assertWithMessage("Wrong caller id").that(result) .isEqualTo(CALLER_DISPLAY_NAME); } @Test public void getReadableCallerId_nonEnterpriseCall_adminBlocked_ott() { final CrossDeviceCall crossDeviceCall = new CrossDeviceCall( InstrumentationRegistry.getTargetContext().getPackageManager(), /* call= */ null, /* callAudioState= */ null); crossDeviceCall.mIsEnterprise = false; crossDeviceCall.mIsOtt = true; crossDeviceCall.updateCallDetails( createCallDetails(Call.STATE_ACTIVE, /* capabilities= */ 0)); final String result = crossDeviceCall.getReadableCallerId(true); assertWithMessage("Wrong caller id").that(result) .isEqualTo(CALLER_DISPLAY_NAME); } @Test public void getReadableCallerId_nonEnterpriseCall_adminUnblocked_ott() { final CrossDeviceCall crossDeviceCall = new CrossDeviceCall( InstrumentationRegistry.getTargetContext().getPackageManager(), /* call= */ null, /* callAudioState= */ null); crossDeviceCall.mIsEnterprise = false; crossDeviceCall.mIsOtt = true; crossDeviceCall.updateCallDetails( createCallDetails(Call.STATE_ACTIVE, /* capabilities= */ 0)); final String result = crossDeviceCall.getReadableCallerId(false); assertWithMessage("Wrong caller id").that(result) .isEqualTo(CALLER_DISPLAY_NAME); } @Test public void getReadableCallerId_nonEnterpriseCall_adminBlocked_pstn() { final CrossDeviceCall crossDeviceCall = new CrossDeviceCall( InstrumentationRegistry.getTargetContext().getPackageManager(), /* call= */ null, /* callAudioState= */ null); crossDeviceCall.mIsEnterprise = false; crossDeviceCall.mIsOtt = false; crossDeviceCall.updateCallDetails( createCallDetails(Call.STATE_ACTIVE, /* capabilities= */ 0)); final String result = crossDeviceCall.getReadableCallerId(true); assertWithMessage("Wrong caller id").that(result) .isEqualTo(CONTACT_DISPLAY_NAME); } @Test public void getReadableCallerId_nonEnterpriseCall_adminUnblocked_pstn() { final CrossDeviceCall crossDeviceCall = new CrossDeviceCall( InstrumentationRegistry.getTargetContext().getPackageManager(), /* call= */ null, /* callAudioState= */ null); crossDeviceCall.mIsEnterprise = false; crossDeviceCall.mIsOtt = false; crossDeviceCall.updateCallDetails( createCallDetails(Call.STATE_ACTIVE, /* capabilities= */ 0)); final String result = crossDeviceCall.getReadableCallerId(false); assertWithMessage("Wrong caller id").that(result) .isEqualTo(CONTACT_DISPLAY_NAME); } private Call.Details createCallDetails(int state, int capabilities) { final ParcelableCall.ParcelableCallBuilder parcelableCallBuilder = new ParcelableCall.ParcelableCallBuilder(); parcelableCallBuilder.setCallerDisplayName("name"); parcelableCallBuilder.setCallerDisplayName(CALLER_DISPLAY_NAME); parcelableCallBuilder.setContactDisplayName(CONTACT_DISPLAY_NAME); parcelableCallBuilder.setCapabilities(capabilities); parcelableCallBuilder.setState(state); parcelableCallBuilder.setConferenceableCallIds(Collections.emptyList()); Loading Loading
services/companion/java/com/android/server/companion/datatransfer/contextsync/CrossDeviceCall.java +20 −2 Original line number Diff line number Diff line Loading @@ -45,10 +45,13 @@ public class CrossDeviceCall { private final long mId; private final Call mCall; @VisibleForTesting boolean mIsEnterprise; @VisibleForTesting boolean mIsOtt; private String mCallingAppName; private byte[] mCallingAppIcon; private String mCallerDisplayName; private int mStatus = android.companion.Telecom.Call.UNKNOWN_STATUS; private String mContactDisplayName; private boolean mIsMuted; private final Set<Integer> mControls = new HashSet<>(); Loading @@ -58,6 +61,12 @@ public class CrossDeviceCall { mCall = call; final String callingAppPackageName = call != null ? call.getDetails().getAccountHandle().getComponentName().getPackageName() : null; mIsOtt = call != null && (call.getDetails().getCallCapabilities() & Call.Details.PROPERTY_SELF_MANAGED) == Call.Details.PROPERTY_SELF_MANAGED; mIsEnterprise = call != null && (call.getDetails().getCallProperties() & Call.Details.PROPERTY_ENTERPRISE_CALL) == Call.Details.PROPERTY_ENTERPRISE_CALL; try { final ApplicationInfo applicationInfo = packageManager .getApplicationInfo(callingAppPackageName, Loading Loading @@ -133,6 +142,7 @@ public class CrossDeviceCall { @VisibleForTesting void updateCallDetails(Call.Details callDetails) { mCallerDisplayName = callDetails.getCallerDisplayName(); mContactDisplayName = callDetails.getContactDisplayName(); mStatus = convertStateToStatus(callDetails.getState()); mControls.clear(); if (mStatus == android.companion.Telecom.Call.RINGING Loading Loading @@ -198,9 +208,17 @@ public class CrossDeviceCall { return mCallingAppIcon; } public String getReadableCallerId() { /** * Get a human-readable "caller id" to display as the origin of the call. * * @param isAdminBlocked whether there is an admin that has blocked contacts over Bluetooth */ public String getReadableCallerId(boolean isAdminBlocked) { if (mIsOtt) { return mCallerDisplayName; } return mIsEnterprise && isAdminBlocked ? mCallerDisplayName : mContactDisplayName; } public int getStatus() { return mStatus; Loading
services/tests/servicestests/src/com/android/server/companion/datatransfer/contextsync/CrossDeviceCallTest.java +117 −1 Original line number Diff line number Diff line Loading @@ -35,6 +35,9 @@ import java.util.Set; @RunWith(AndroidTestingRunner.class) public class CrossDeviceCallTest { private static final String CALLER_DISPLAY_NAME = "name"; private static final String CONTACT_DISPLAY_NAME = "contact"; @Test public void updateCallDetails_uninitialized() { final CrossDeviceCall crossDeviceCall = new CrossDeviceCall( Loading Loading @@ -171,10 +174,123 @@ public class CrossDeviceCallTest { android.companion.Telecom.Call.PUT_ON_HOLD)); } @Test public void getReadableCallerId_enterpriseCall_adminBlocked_ott() { final CrossDeviceCall crossDeviceCall = new CrossDeviceCall( InstrumentationRegistry.getTargetContext().getPackageManager(), /* call= */ null, /* callAudioState= */ null); crossDeviceCall.mIsEnterprise = true; crossDeviceCall.mIsOtt = true; crossDeviceCall.updateCallDetails( createCallDetails(Call.STATE_ACTIVE, /* capabilities= */ 0)); final String result = crossDeviceCall.getReadableCallerId(true); assertWithMessage("Wrong caller id").that(result) .isEqualTo(CALLER_DISPLAY_NAME); } @Test public void getReadableCallerId_enterpriseCall_adminUnblocked_ott() { final CrossDeviceCall crossDeviceCall = new CrossDeviceCall( InstrumentationRegistry.getTargetContext().getPackageManager(), /* call= */ null, /* callAudioState= */ null); crossDeviceCall.mIsEnterprise = true; crossDeviceCall.mIsOtt = true; crossDeviceCall.updateCallDetails( createCallDetails(Call.STATE_ACTIVE, /* capabilities= */ 0)); final String result = crossDeviceCall.getReadableCallerId(false); assertWithMessage("Wrong caller id").that(result) .isEqualTo(CALLER_DISPLAY_NAME); } @Test public void getReadableCallerId_enterpriseCall_adminBlocked_pstn() { final CrossDeviceCall crossDeviceCall = new CrossDeviceCall( InstrumentationRegistry.getTargetContext().getPackageManager(), /* call= */ null, /* callAudioState= */ null); crossDeviceCall.mIsEnterprise = true; crossDeviceCall.mIsOtt = false; crossDeviceCall.updateCallDetails( createCallDetails(Call.STATE_ACTIVE, /* capabilities= */ 0)); final String result = crossDeviceCall.getReadableCallerId(true); assertWithMessage("Wrong caller id").that(result) .isEqualTo(CALLER_DISPLAY_NAME); } @Test public void getReadableCallerId_nonEnterpriseCall_adminBlocked_ott() { final CrossDeviceCall crossDeviceCall = new CrossDeviceCall( InstrumentationRegistry.getTargetContext().getPackageManager(), /* call= */ null, /* callAudioState= */ null); crossDeviceCall.mIsEnterprise = false; crossDeviceCall.mIsOtt = true; crossDeviceCall.updateCallDetails( createCallDetails(Call.STATE_ACTIVE, /* capabilities= */ 0)); final String result = crossDeviceCall.getReadableCallerId(true); assertWithMessage("Wrong caller id").that(result) .isEqualTo(CALLER_DISPLAY_NAME); } @Test public void getReadableCallerId_nonEnterpriseCall_adminUnblocked_ott() { final CrossDeviceCall crossDeviceCall = new CrossDeviceCall( InstrumentationRegistry.getTargetContext().getPackageManager(), /* call= */ null, /* callAudioState= */ null); crossDeviceCall.mIsEnterprise = false; crossDeviceCall.mIsOtt = true; crossDeviceCall.updateCallDetails( createCallDetails(Call.STATE_ACTIVE, /* capabilities= */ 0)); final String result = crossDeviceCall.getReadableCallerId(false); assertWithMessage("Wrong caller id").that(result) .isEqualTo(CALLER_DISPLAY_NAME); } @Test public void getReadableCallerId_nonEnterpriseCall_adminBlocked_pstn() { final CrossDeviceCall crossDeviceCall = new CrossDeviceCall( InstrumentationRegistry.getTargetContext().getPackageManager(), /* call= */ null, /* callAudioState= */ null); crossDeviceCall.mIsEnterprise = false; crossDeviceCall.mIsOtt = false; crossDeviceCall.updateCallDetails( createCallDetails(Call.STATE_ACTIVE, /* capabilities= */ 0)); final String result = crossDeviceCall.getReadableCallerId(true); assertWithMessage("Wrong caller id").that(result) .isEqualTo(CONTACT_DISPLAY_NAME); } @Test public void getReadableCallerId_nonEnterpriseCall_adminUnblocked_pstn() { final CrossDeviceCall crossDeviceCall = new CrossDeviceCall( InstrumentationRegistry.getTargetContext().getPackageManager(), /* call= */ null, /* callAudioState= */ null); crossDeviceCall.mIsEnterprise = false; crossDeviceCall.mIsOtt = false; crossDeviceCall.updateCallDetails( createCallDetails(Call.STATE_ACTIVE, /* capabilities= */ 0)); final String result = crossDeviceCall.getReadableCallerId(false); assertWithMessage("Wrong caller id").that(result) .isEqualTo(CONTACT_DISPLAY_NAME); } private Call.Details createCallDetails(int state, int capabilities) { final ParcelableCall.ParcelableCallBuilder parcelableCallBuilder = new ParcelableCall.ParcelableCallBuilder(); parcelableCallBuilder.setCallerDisplayName("name"); parcelableCallBuilder.setCallerDisplayName(CALLER_DISPLAY_NAME); parcelableCallBuilder.setContactDisplayName(CONTACT_DISPLAY_NAME); parcelableCallBuilder.setCapabilities(capabilities); parcelableCallBuilder.setState(state); parcelableCallBuilder.setConferenceableCallIds(Collections.emptyList()); Loading