diff options
Diffstat (limited to 'java/com')
3 files changed, 113 insertions, 3 deletions
diff --git a/java/com/android/dialer/assisteddialing/AssistedDialingMediator.java b/java/com/android/dialer/assisteddialing/AssistedDialingMediator.java index 2613d07a9..3d027296c 100644 --- a/java/com/android/dialer/assisteddialing/AssistedDialingMediator.java +++ b/java/com/android/dialer/assisteddialing/AssistedDialingMediator.java @@ -66,7 +66,7 @@ public final class AssistedDialingMediator { */ @SuppressWarnings("AndroidApiChecker") // Use of optional @TargetApi(VERSION_CODES.N) - public Optional<String> attemptAssistedDial(@NonNull String numberToTransform) { + public Optional<TransformationInfo> attemptAssistedDial(@NonNull String numberToTransform) { Optional<String> userHomeCountryCode = locationDetector.getUpperCaseUserHomeCountry(); Optional<String> userRoamingCountryCode = locationDetector.getUpperCaseUserRoamingCountry(); diff --git a/java/com/android/dialer/assisteddialing/NumberTransformer.java b/java/com/android/dialer/assisteddialing/NumberTransformer.java index f01d1a08f..0156f2ec2 100644 --- a/java/com/android/dialer/assisteddialing/NumberTransformer.java +++ b/java/com/android/dialer/assisteddialing/NumberTransformer.java @@ -57,7 +57,7 @@ final class NumberTransformer { */ @SuppressWarnings("AndroidApiChecker") // Use of optional @TargetApi(VERSION_CODES.N) - public Optional<String> doAssistedDialingTransformation( + public Optional<TransformationInfo> doAssistedDialingTransformation( String numbertoTransform, String userHomeCountryCode, String userRoamingCountryCode) { if (!constraints.meetsPreconditions( @@ -88,6 +88,13 @@ final class NumberTransformer { } // TODO Verify the transformed number is still valid? - return Optional.of(transformedNumber); + return Optional.of( + TransformationInfo.builder() + .setOriginalNumber(numbertoTransform) + .setTransformedNumber(transformedNumber) + .setUserHomeCountryCode(userHomeCountryCode) + .setUserRoamingCountryCode(userRoamingCountryCode) + .setTransformedNumberCountryCallingCode(phoneNumber.getCountryCode()) + .build()); } } diff --git a/java/com/android/dialer/assisteddialing/TransformationInfo.java b/java/com/android/dialer/assisteddialing/TransformationInfo.java new file mode 100644 index 000000000..7149d71cc --- /dev/null +++ b/java/com/android/dialer/assisteddialing/TransformationInfo.java @@ -0,0 +1,103 @@ +/* + * Copyright (C) 2017 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.dialer.assisteddialing; + +import android.os.Bundle; +import android.support.annotation.NonNull; +import com.google.auto.value.AutoValue; + +/** + * A container class to hold information related to the Assisted Dialing operation. All member + * variables must be set when constructing a new instance of this class. + */ +@AutoValue +public abstract class TransformationInfo { + @NonNull private static final String ORIGINAL_NUBMER_KEY = "TRANSFORMATION_INFO_ORIGINAL_NUMBER"; + + @NonNull + private static final String TRANSFORMED_NUMBER_KEY = "TRANSFORMATION_INFO_TRANSFORMED_NUMBER"; + + @NonNull + private static final String USER_HOME_COUNTRY_CODE_KEY = + "TRANSFORMATION_INFO_USER_HOME_COUNTRY_CODE"; + + @NonNull + private static final String USER_ROAMING_COUNTRY_CODE_KEY = + "TRANSFORMATION_INFO_USER_ROAMING_COUNTRY_CODE"; + + @NonNull + private static final String TRANSFORMED_NUMBER_COUNTRY_CALLING_CODE_KEY = + "TRANSFORMED_NUMBER_COUNTRY_CALLING_CODE"; + + abstract String originalNumber(); + + abstract String transformedNumber(); + + abstract String userHomeCountryCode(); + + abstract String userRoamingCountryCode(); + + abstract int transformedNumberCountryCallingCode(); + + public static Builder builder() { + return new AutoValue_TransformationInfo.Builder(); + } + + @AutoValue.Builder + abstract static class Builder { + abstract Builder setOriginalNumber(String value); + + abstract Builder setTransformedNumber(String value); + + abstract Builder setUserHomeCountryCode(String value); + + abstract Builder setUserRoamingCountryCode(String value); + + abstract Builder setTransformedNumberCountryCallingCode(int value); + + abstract TransformationInfo build(); + } + + public static TransformationInfo newInstanceFromBundle(@NonNull Bundle transformationInfoBundle) { + + return TransformationInfo.builder() + .setOriginalNumber(transformationInfoBundle.getString(ORIGINAL_NUBMER_KEY)) + .setTransformedNumber(transformationInfoBundle.getString(TRANSFORMED_NUMBER_KEY)) + .setUserHomeCountryCode(transformationInfoBundle.getString(USER_HOME_COUNTRY_CODE_KEY)) + .setUserRoamingCountryCode( + transformationInfoBundle.getString(USER_ROAMING_COUNTRY_CODE_KEY)) + .setTransformedNumberCountryCallingCode( + transformationInfoBundle.getInt(TRANSFORMED_NUMBER_COUNTRY_CALLING_CODE_KEY)) + .build(); + } + + /** + * Callers are not expected to directly use this bundle. The bundle is provided for IPC purposes. + * Callers wishing to use the data should call newInstanceFromBundle with the bundle to get a + * usable POJO. + */ + public Bundle toBundle() { + Bundle assistedDialingExtras = new Bundle(); + assistedDialingExtras.putString(ORIGINAL_NUBMER_KEY, originalNumber()); + assistedDialingExtras.putString(TRANSFORMED_NUMBER_KEY, transformedNumber()); + assistedDialingExtras.putString(USER_HOME_COUNTRY_CODE_KEY, userHomeCountryCode()); + assistedDialingExtras.putString(USER_ROAMING_COUNTRY_CODE_KEY, userRoamingCountryCode()); + assistedDialingExtras.putInt( + TRANSFORMED_NUMBER_COUNTRY_CALLING_CODE_KEY, transformedNumberCountryCallingCode()); + return assistedDialingExtras; + } +} |