aboutsummaryrefslogtreecommitdiff
path: root/locationtzprovider/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'locationtzprovider/src/main')
-rw-r--r--locationtzprovider/src/main/java/com/android/timezone/location/provider/EnvironmentImpl.java51
-rw-r--r--locationtzprovider/src/main/java/com/android/timezone/location/provider/GeoDataFileManager.java41
2 files changed, 75 insertions, 17 deletions
diff --git a/locationtzprovider/src/main/java/com/android/timezone/location/provider/EnvironmentImpl.java b/locationtzprovider/src/main/java/com/android/timezone/location/provider/EnvironmentImpl.java
index e1b1fd4..bd2056f 100644
--- a/locationtzprovider/src/main/java/com/android/timezone/location/provider/EnvironmentImpl.java
+++ b/locationtzprovider/src/main/java/com/android/timezone/location/provider/EnvironmentImpl.java
@@ -64,10 +64,11 @@ class EnvironmentImpl implements Environment {
private static final String RESOURCE_CONFIG_PROPERTIES_NAME = "offlineltzprovider.properties";
/**
- * The config properties key to get the location of the tzs2.dat file to use for time zone
- * boundaries.
+ *
+ * The config properties key to determine how the tzs2.dat file is loaded.
*/
- private static final String RESOURCE_CONFIG_KEY_GEODATA_PATH = "geodata.path";
+ private static final String RESOURCE_CONFIG_KEY_GEODATA_FILE_MANAGER_IMPL =
+ "geodata.file_manager_impl";
/**
* The config properties key for the namespace to pass to {@link android.provider.DeviceConfig}
@@ -88,12 +89,6 @@ class EnvironmentImpl implements Environment {
*/
private static final String RESOURCE_CONFIG_METRICS_REPORTER_IMPL = "metrics_reporter.impl";
- /**
- * An identifier that can be used to distinguish between different deployments of the same code.
- */
- private static final String RESOURCE_CONFIG_METRICS_REPORTER_DEPLOYMENT_IDENTIFIER =
- "metrics_reporter.identifier";
-
/** An arbitrary value larger than the largest time we might want to hold a wake lock. */
private static final long WAKELOCK_ACQUIRE_MILLIS = Duration.ofMinutes(1).toMillis();
@@ -159,16 +154,18 @@ class EnvironmentImpl implements Environment {
mHandler = new Handler(Looper.getMainLooper());
mExecutor = new HandlerExecutor(mHandler);
- Properties configProperties = loadConfigProperties(getClass().getClassLoader());
- mGeoDataFile = new File(configProperties.getProperty(RESOURCE_CONFIG_KEY_GEODATA_PATH));
+ ClassLoader classLoader = getClass().getClassLoader();
+ Properties configProperties = loadConfigProperties(classLoader);
+ GeoDataFileManager geoDataFileManager =
+ createGeoDataFileManager(context, classLoader, configProperties);
+ mGeoDataFile = geoDataFileManager.getGeoDataFile();
+
mDeviceConfigNamespace = Objects.requireNonNull(
configProperties.getProperty(RESOURCE_CONFIG_KEY_DEVICE_CONFIG_NAMESPACE));
mDeviceConfigKeyPrefix = Objects.requireNonNull(
configProperties.getProperty(RESOURCE_CONFIG_KEY_DEVICE_CONFIG_KEY_PREFIX));
- String metricsReporterClassName =
- configProperties.getProperty(RESOURCE_CONFIG_METRICS_REPORTER_IMPL);
- mMetricsReporter = createMetricsReporter(metricsReporterClassName);
+ mMetricsReporter = createMetricsReporter(classLoader, configProperties);
LocationListeningAccountant realLocationListeningAccountant =
createRealLocationListeningAccountant();
@@ -185,10 +182,30 @@ class EnvironmentImpl implements Environment {
mDeviceConfigNamespace, mExecutor, this::handleDeviceConfigChanged);
}
- private MetricsReporter createMetricsReporter(@NonNull String className) {
+ private static GeoDataFileManager createGeoDataFileManager(
+ @NonNull Context context, @NonNull ClassLoader classLoader,
+ @NonNull Properties configProperties) {
+ String className =
+ configProperties.getProperty(RESOURCE_CONFIG_KEY_GEODATA_FILE_MANAGER_IMPL);
+ try {
+ Class<?> clazz = classLoader.loadClass(className);
+ GeoDataFileManager geoDataFileManager =
+ (GeoDataFileManager) clazz.getConstructor().newInstance();
+ geoDataFileManager.init(context, configProperties);
+ return geoDataFileManager;
+ } catch (ReflectiveOperationException e) {
+ throw new IllegalStateException("Unable to instantiate GeoDataFileManager", e);
+ } catch (IOException e) {
+ throw new IllegalStateException("Unable to initialize GeoDataFileManager", e);
+ }
+ }
+
+ private static MetricsReporter createMetricsReporter(
+ @NonNull ClassLoader classLoader, @NonNull Properties configProperties) {
+ String className = configProperties.getProperty(RESOURCE_CONFIG_METRICS_REPORTER_IMPL);
try {
- Class<?> clazz = Class.forName(className);
- return (MetricsReporter) clazz.newInstance();
+ Class<?> clazz = classLoader.loadClass(className);
+ return (MetricsReporter) clazz.getConstructor().newInstance();
} catch (ReflectiveOperationException e) {
throw new IllegalStateException("Unable to instantiate MetricsReporter", e);
}
diff --git a/locationtzprovider/src/main/java/com/android/timezone/location/provider/GeoDataFileManager.java b/locationtzprovider/src/main/java/com/android/timezone/location/provider/GeoDataFileManager.java
new file mode 100644
index 0000000..5c0f664
--- /dev/null
+++ b/locationtzprovider/src/main/java/com/android/timezone/location/provider/GeoDataFileManager.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2022 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.timezone.location.provider;
+
+import android.content.Context;
+
+import androidx.annotation.NonNull;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Properties;
+
+/** An interface for classes that know how to obtain time zone geo data. */
+public interface GeoDataFileManager {
+
+ /**
+ * Performs any actions needed to make the geo data file available via {@link
+ * #getGeoDataFile()}.
+ */
+ void init(@NonNull Context context, @NonNull Properties configProperties) throws IOException;
+
+ /**
+ * Returns the location of the geo data file. Throws an exception if {@link
+ * #init(Context, Properties)} failed.
+ */
+ @NonNull
+ File getGeoDataFile();
+}