aboutsummaryrefslogtreecommitdiff
path: root/src/com/android/tv/util/LocationUtils.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/tv/util/LocationUtils.java')
-rw-r--r--src/com/android/tv/util/LocationUtils.java24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/com/android/tv/util/LocationUtils.java b/src/com/android/tv/util/LocationUtils.java
index 8e3b59e9..2ae6db18 100644
--- a/src/com/android/tv/util/LocationUtils.java
+++ b/src/com/android/tv/util/LocationUtils.java
@@ -16,7 +16,9 @@
package com.android.tv.util;
+import android.Manifest;
import android.content.Context;
+import android.content.pm.PackageManager;
import android.location.Address;
import android.location.Geocoder;
import android.location.Location;
@@ -25,6 +27,7 @@ import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;
+import com.android.tv.tuner.util.PostalCodeUtils;
import java.io.IOException;
import java.util.List;
@@ -39,6 +42,7 @@ public class LocationUtils {
private static Context sApplicationContext;
private static Address sAddress;
+ private static String sCountry;
private static IOException sError;
/**
@@ -59,6 +63,19 @@ public class LocationUtils {
return null;
}
+ /**
+ * Returns the current country.
+ */
+ public static synchronized String getCurrentCountry(Context context) {
+ if (sCountry != null) {
+ return sCountry;
+ }
+ if (sCountry == null) {
+ sCountry = context.getResources().getConfiguration().locale.getCountry();
+ }
+ return sCountry;
+ }
+
private static void updateAddress(Location location) {
if (DEBUG) Log.d(TAG, "Updating address with " + location);
if (location == null) {
@@ -68,9 +85,14 @@ public class LocationUtils {
try {
List<Address> addresses = geocoder.getFromLocation(
location.getLatitude(), location.getLongitude(), 1);
- if (addresses != null) {
+ if (addresses != null && !addresses.isEmpty()) {
sAddress = addresses.get(0);
if (DEBUG) Log.d(TAG, "Got " + sAddress);
+ try {
+ PostalCodeUtils.updatePostalCode(sApplicationContext);
+ } catch (Exception e) {
+ // Do nothing
+ }
} else {
if (DEBUG) Log.d(TAG, "No address returned");
}