1 /* 2 * Copyright (C) 2010 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 android.location; 18 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.compat.annotation.UnsupportedAppUsage; 22 import android.content.Context; 23 import android.os.Parcel; 24 import android.os.Parcelable; 25 import android.os.Process; 26 27 import java.util.Locale; 28 import java.util.Objects; 29 30 /** 31 * This class contains extra parameters to pass to an IGeocodeProvider 32 * implementation from the Geocoder class. Currently this contains the 33 * language, country and variant information from the Geocoder's locale 34 * as well as the Geocoder client's package name for geocoder server 35 * logging. This information is kept in a separate class to allow for 36 * future expansion of the IGeocodeProvider interface. 37 * 38 * @hide 39 */ 40 public class GeocoderParams implements Parcelable { 41 42 private final int mUid; 43 private final String mPackageName; 44 private final @Nullable String mAttributionTag; 45 private final Locale mLocale; 46 GeocoderParams(Context context)47 public GeocoderParams(Context context) { 48 this(context, Locale.getDefault()); 49 } 50 GeocoderParams(Context context, Locale locale)51 public GeocoderParams(Context context, Locale locale) { 52 this(Process.myUid(), context.getPackageName(), context.getAttributionTag(), locale); 53 } 54 GeocoderParams(int uid, String packageName, String attributionTag, Locale locale)55 private GeocoderParams(int uid, String packageName, String attributionTag, Locale locale) { 56 mUid = uid; 57 mPackageName = Objects.requireNonNull(packageName); 58 mAttributionTag = attributionTag; 59 mLocale = Objects.requireNonNull(locale); 60 } 61 62 /** 63 * Returns the client UID. 64 */ 65 @UnsupportedAppUsage getClientUid()66 public int getClientUid() { 67 return mUid; 68 } 69 70 /** 71 * Returns the client package name. 72 */ 73 @UnsupportedAppUsage getClientPackage()74 public @NonNull String getClientPackage() { 75 return mPackageName; 76 } 77 78 /** 79 * Returns the client attribution tag. 80 */ 81 @UnsupportedAppUsage getClientAttributionTag()82 public @Nullable String getClientAttributionTag() { 83 return mAttributionTag; 84 } 85 86 /** 87 * Returns the locale. 88 */ 89 @UnsupportedAppUsage getLocale()90 public @NonNull Locale getLocale() { 91 return mLocale; 92 } 93 94 public static final @NonNull Parcelable.Creator<GeocoderParams> CREATOR = 95 new Parcelable.Creator<GeocoderParams>() { 96 public GeocoderParams createFromParcel(Parcel in) { 97 int uid = in.readInt(); 98 String packageName = in.readString(); 99 String attributionTag = in.readString(); 100 String language = in.readString(); 101 String country = in.readString(); 102 String variant = in.readString(); 103 104 return new GeocoderParams(uid, packageName, attributionTag, 105 new Locale(language, country, variant)); 106 } 107 108 public GeocoderParams[] newArray(int size) { 109 return new GeocoderParams[size]; 110 } 111 }; 112 describeContents()113 public int describeContents() { 114 return 0; 115 } 116 writeToParcel(Parcel parcel, int flags)117 public void writeToParcel(Parcel parcel, int flags) { 118 parcel.writeInt(mUid); 119 parcel.writeString(mPackageName); 120 parcel.writeString(mAttributionTag); 121 parcel.writeString(mLocale.getLanguage()); 122 parcel.writeString(mLocale.getCountry()); 123 parcel.writeString(mLocale.getVariant()); 124 } 125 } 126