blob: a11e667022ff69c0dd363e5b25e79f12c2ea2bb6 [file] [log] [blame]
/*
* Copyright (C) 2020 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.geotz.provider;
import android.content.Context;
import androidx.annotation.NonNull;
import com.android.location.timezone.provider.LocationTimeZoneProviderBase;
import com.android.location.timezone.provider.LocationTimeZoneProviderRequestUnbundled;
import com.android.timezone.geotz.provider.core.LogUtils;
import com.android.timezone.geotz.provider.core.OfflineLocationTimeZoneDelegate;
import com.android.timezone.geotz.provider.core.OfflineLocationTimeZoneDelegate.Environment;
import java.io.PrintWriter;
/**
* A Location Time Zone Provider implementation that uses only Android public SDK APIs and on-device
* data to determine the current time zone(s) for a location.
*
* <p>This implementation can be deployed to run as either the current user (e.g. it could run in a
* user-specific process like GMS core), or always as the system user (e.g. it can run in a single
* user process like system server). It relies on being disabled by the system server when the user
* changes. No location state is retained when the provider is disabled.
*
* <p>See {@link OfflineLocationTimeZoneDelegate} for implementation details.
*
* <p>The provider is configured via a "offlineltzprovider.properties" resource file. See
* {@link EnvironmentImpl} for details.
*/
final class OfflineLocationTimeZoneProvider extends LocationTimeZoneProviderBase {
private static final String ATTRIBUTION_TAG = "OfflineLocationTimeZoneProvider";
@NonNull
private final OfflineLocationTimeZoneDelegate mDelegate;
OfflineLocationTimeZoneProvider(@NonNull Context context) {
super(context, LogUtils.LOG_TAG);
Context attributionContext = context.createAttributionContext(ATTRIBUTION_TAG);
Environment environment = new EnvironmentImpl(
attributionContext, this::reportLocationTimeZoneEvent);
mDelegate = new OfflineLocationTimeZoneDelegate(environment);
}
public void onBind() {
mDelegate.onBind();
}
public void onDestroy() {
mDelegate.onDestroy();
}
@Override
protected void onSetRequest(@NonNull LocationTimeZoneProviderRequestUnbundled request) {
if (request.getReportLocationTimeZone()) {
mDelegate.onEnable(request.getInitializationTimeoutMillis());
} else {
mDelegate.onDisable();
}
}
public void dump(@NonNull PrintWriter pw) {
mDelegate.dump(pw);
}
}