1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.dialer.assisteddialing; 18 19 import android.os.Bundle; 20 import android.support.annotation.NonNull; 21 import com.google.auto.value.AutoValue; 22 23 /** 24 * A container class to hold information related to the Assisted Dialing operation. All member 25 * variables must be set when constructing a new instance of this class. 26 */ 27 @AutoValue 28 public abstract class TransformationInfo { 29 @NonNull private static final String ORIGINAL_NUBMER_KEY = "TRANSFORMATION_INFO_ORIGINAL_NUMBER"; 30 31 @NonNull 32 private static final String TRANSFORMED_NUMBER_KEY = "TRANSFORMATION_INFO_TRANSFORMED_NUMBER"; 33 34 @NonNull 35 private static final String USER_HOME_COUNTRY_CODE_KEY = 36 "TRANSFORMATION_INFO_USER_HOME_COUNTRY_CODE"; 37 38 @NonNull 39 private static final String USER_ROAMING_COUNTRY_CODE_KEY = 40 "TRANSFORMATION_INFO_USER_ROAMING_COUNTRY_CODE"; 41 42 @NonNull 43 private static final String TRANSFORMED_NUMBER_COUNTRY_CALLING_CODE_KEY = 44 "TRANSFORMED_NUMBER_COUNTRY_CALLING_CODE"; 45 originalNumber()46 public abstract String originalNumber(); 47 transformedNumber()48 public abstract String transformedNumber(); 49 userHomeCountryCode()50 public abstract String userHomeCountryCode(); 51 userRoamingCountryCode()52 public abstract String userRoamingCountryCode(); 53 transformedNumberCountryCallingCode()54 public abstract int transformedNumberCountryCallingCode(); 55 builder()56 public static Builder builder() { 57 return new AutoValue_TransformationInfo.Builder(); 58 } 59 60 /** A builder for TransformationInfo. */ 61 @AutoValue.Builder 62 public abstract static class Builder { setOriginalNumber(String value)63 public abstract Builder setOriginalNumber(String value); 64 setTransformedNumber(String value)65 public abstract Builder setTransformedNumber(String value); 66 setUserHomeCountryCode(String value)67 public abstract Builder setUserHomeCountryCode(String value); 68 setUserRoamingCountryCode(String value)69 public abstract Builder setUserRoamingCountryCode(String value); 70 setTransformedNumberCountryCallingCode(int value)71 public abstract Builder setTransformedNumberCountryCallingCode(int value); 72 build()73 public abstract TransformationInfo build(); 74 } 75 newInstanceFromBundle(@onNull Bundle transformationInfoBundle)76 public static TransformationInfo newInstanceFromBundle(@NonNull Bundle transformationInfoBundle) { 77 78 return TransformationInfo.builder() 79 .setOriginalNumber(transformationInfoBundle.getString(ORIGINAL_NUBMER_KEY)) 80 .setTransformedNumber(transformationInfoBundle.getString(TRANSFORMED_NUMBER_KEY)) 81 .setUserHomeCountryCode(transformationInfoBundle.getString(USER_HOME_COUNTRY_CODE_KEY)) 82 .setUserRoamingCountryCode( 83 transformationInfoBundle.getString(USER_ROAMING_COUNTRY_CODE_KEY)) 84 .setTransformedNumberCountryCallingCode( 85 transformationInfoBundle.getInt(TRANSFORMED_NUMBER_COUNTRY_CALLING_CODE_KEY)) 86 .build(); 87 } 88 89 /** 90 * Callers are not expected to directly use this bundle. The bundle is provided for IPC purposes. 91 * Callers wishing to use the data should call newInstanceFromBundle with the bundle to get a 92 * usable POJO. 93 */ toBundle()94 public Bundle toBundle() { 95 Bundle assistedDialingExtras = new Bundle(); 96 assistedDialingExtras.putString(ORIGINAL_NUBMER_KEY, originalNumber()); 97 assistedDialingExtras.putString(TRANSFORMED_NUMBER_KEY, transformedNumber()); 98 assistedDialingExtras.putString(USER_HOME_COUNTRY_CODE_KEY, userHomeCountryCode()); 99 assistedDialingExtras.putString(USER_ROAMING_COUNTRY_CODE_KEY, userRoamingCountryCode()); 100 assistedDialingExtras.putInt( 101 TRANSFORMED_NUMBER_COUNTRY_CALLING_CODE_KEY, transformedNumberCountryCallingCode()); 102 return assistedDialingExtras; 103 } 104 } 105