Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ac26256f authored by Neil Fuller's avatar Neil Fuller
Browse files

Async initialization LocationTimeZoneProviders

Async initialization / resolution of LocationTimeZoneProviders.
Removes the expensive part of LocationTimeZoneProviders from the
critical path of system server start.

Bug: 174279651
Test: boot, look at delays in logcat (2ms -> 1ms on coral)
Change-Id: I7dd9c3b9c7c1e76a6a130468782aec1f93da4eaa
parent 649ed103
Loading
Loading
Loading
Loading
+15 −8
Original line number Diff line number Diff line
@@ -1605,21 +1605,28 @@
    <!-- Whether the geolocation time zone detection feature is enabled. -->
    <bool name="config_enableGeolocationTimeZoneDetection" translatable="false">true</bool>

    <!-- Whether to enable primary location time zone provider overlay which allows the primary
         location time zone provider to be replaced by an app at run-time. When disabled, only the
    <!-- Whether the primary LocationTimeZoneProvider is enabled device.
         Ignored if config_enableGeolocationTimeZoneDetection is false -->
    <bool name="config_enablePrimaryLocationTimeZoneProvider" translatable="false">false</bool>
    <!-- Used when enablePrimaryLocationTimeZoneProvider is true. Controls whether to enable primary
         location time zone provider overlay which allows the primary location time zone provider to
         be replaced by an app at run-time. When disabled, only the
         config_primaryLocationTimeZoneProviderPackageName package will be searched for the primary
         location time zone provider, otherwise any system package is eligible. Anyone who wants to
         disable the overlay mechanism can set it to false. -->
         disable the runtime overlay mechanism can set it to false. -->
    <bool name="config_enablePrimaryLocationTimeZoneOverlay" translatable="false">false</bool>
    <!-- Package name providing the primary location time zone provider. Used only when
         config_enablePrimaryLocationTimeZoneOverlay is false. -->
    <string name="config_primaryLocationTimeZoneProviderPackageName" translatable="false">@null</string>

    <!-- Whether to enable secondary location time zone provider overlay which allows the secondary
         location time zone provider to be replaced by an app at run-time. When disabled, only the
         config_secondaryLocationTimeZoneProviderPackageName package will be searched for the
         secondary location time zone provider, otherwise any system package is eligible. Anyone who
         wants to disable the overlay mechanism can set it to false. -->
    <!-- Whether the secondary LocationTimeZoneProvider is enabled device.
         Ignored if config_enableGeolocationTimeZoneDetection is false -->
    <bool name="config_enableSecondaryLocationTimeZoneProvider" translatable="false">true</bool>
    <!-- Used when enableSecondaryLocationTimeZoneProvider is true. Controls whether to enable
         secondary location time zone provider overlay which allows the primary location time zone
         provider to config_secondaryLocationTimeZoneProviderPackageName package will be searched
         for the secondary location time zone provider, otherwise any system package is eligible.
         Anyone who wants to disable the runtime overlay mechanism can set it to false. -->
    <bool name="config_enableSecondaryLocationTimeZoneOverlay" translatable="false">false</bool>
    <!-- Package name providing the secondary location time zone provider. Used only when
         config_enableSecondaryLocationTimeZoneOverlay is false.
+2 −0
Original line number Diff line number Diff line
@@ -2167,8 +2167,10 @@
  <java-symbol type="string" name="config_persistentDataPackageName" />
  <java-symbol type="string" name="config_deviceConfiguratorPackageName" />
  <java-symbol type="bool" name="config_enableGeolocationTimeZoneDetection" />
  <java-symbol type="bool" name="config_enablePrimaryLocationTimeZoneProvider" />
  <java-symbol type="bool" name="config_enablePrimaryLocationTimeZoneOverlay" />
  <java-symbol type="string" name="config_primaryLocationTimeZoneProviderPackageName" />
  <java-symbol type="bool" name="config_enableSecondaryLocationTimeZoneProvider" />
  <java-symbol type="bool" name="config_enableSecondaryLocationTimeZoneOverlay" />
  <java-symbol type="string" name="config_secondaryLocationTimeZoneProviderPackageName" />

+1 −1
Original line number Diff line number Diff line
@@ -55,7 +55,7 @@ class BinderLocationTimeZoneProvider extends LocationTimeZoneProvider {

    @Override
    void onInitialize() {
        mProxy.setListener(new LocationTimeZoneProviderProxy.Listener() {
        mProxy.initialize(new LocationTimeZoneProviderProxy.Listener() {
            @Override
            public void onReportLocationTimeZoneEvent(
                    @NonNull LocationTimeZoneEvent locationTimeZoneEvent) {
+20 −24
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.server.location.timezone;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.Context;
import android.content.res.Resources;
import android.os.Binder;
import android.os.ResultReceiver;
import android.os.ShellCallback;
@@ -27,6 +28,7 @@ import android.util.IndentingPrintWriter;
import android.util.Log;
import android.util.Slog;

import com.android.internal.R;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.util.DumpUtils;
import com.android.server.FgThread;
@@ -179,36 +181,45 @@ public class LocationTimeZoneManagerService extends Binder {
    }

    private LocationTimeZoneProvider createPrimaryProvider() {
        Resources resources = mContext.getResources();
        if (!resources.getBoolean(R.bool.config_enablePrimaryLocationTimeZoneProvider)) {
            return new NullLocationTimeZoneProvider(mThreadingDomain, PRIMARY_PROVIDER_NAME);
        }

        LocationTimeZoneProviderProxy proxy;
        if (isInSimulationMode(PRIMARY_PROVIDER_NAME)) {
            proxy = new SimulatedLocationTimeZoneProviderProxy(mContext, mThreadingDomain);
        } else {
            proxy = RealLocationTimeZoneProviderProxy.createAndRegister(
            proxy = new RealLocationTimeZoneProviderProxy(
                    mContext,
                    mThreadingDomain,
                    PRIMARY_LOCATION_TIME_ZONE_SERVICE_ACTION,
                    com.android.internal.R.bool.config_enablePrimaryLocationTimeZoneOverlay,
                    com.android.internal.R.string.config_primaryLocationTimeZoneProviderPackageName
                    R.bool.config_enablePrimaryLocationTimeZoneOverlay,
                    R.string.config_primaryLocationTimeZoneProviderPackageName
            );
        }
        return createLocationTimeZoneProvider(PRIMARY_PROVIDER_NAME, proxy);
        return new BinderLocationTimeZoneProvider(mThreadingDomain, PRIMARY_PROVIDER_NAME, proxy);
    }

    private LocationTimeZoneProvider createSecondaryProvider() {
        Resources resources = mContext.getResources();
        if (!resources.getBoolean(R.bool.config_enableSecondaryLocationTimeZoneProvider)) {
            return new NullLocationTimeZoneProvider(mThreadingDomain, SECONDARY_PROVIDER_NAME);
        }

        LocationTimeZoneProviderProxy proxy;
        if (isInSimulationMode(SECONDARY_PROVIDER_NAME)) {
            proxy = new SimulatedLocationTimeZoneProviderProxy(mContext, mThreadingDomain);
        } else {
            proxy = RealLocationTimeZoneProviderProxy.createAndRegister(
            proxy = new RealLocationTimeZoneProviderProxy(
                    mContext,
                    mThreadingDomain,
                    SECONDARY_LOCATION_TIME_ZONE_SERVICE_ACTION,
                    com.android.internal.R.bool.config_enableSecondaryLocationTimeZoneOverlay,
                    com.android.internal.R.string
                            .config_secondaryLocationTimeZoneProviderPackageName
                    R.bool.config_enableSecondaryLocationTimeZoneOverlay,
                    R.string.config_secondaryLocationTimeZoneProviderPackageName
            );
        }
        return createLocationTimeZoneProvider(SECONDARY_PROVIDER_NAME, proxy);
        return new BinderLocationTimeZoneProvider(mThreadingDomain, SECONDARY_PROVIDER_NAME, proxy);
    }

    private boolean isInSimulationMode(String providerName) {
@@ -216,21 +227,6 @@ public class LocationTimeZoneManagerService extends Binder {
                SIMULATION_MODE_SYSTEM_PROPERTY_PREFIX + providerName, false);
    }

    private LocationTimeZoneProvider createLocationTimeZoneProvider(
            @NonNull String providerName, @NonNull LocationTimeZoneProviderProxy proxy) {
        LocationTimeZoneProvider provider;
        if (proxy != null) {
            debugLog("LocationTimeZoneProvider found for providerName=" + providerName);
            provider = new BinderLocationTimeZoneProvider(mThreadingDomain,
                    providerName, proxy);
        } else {
            debugLog("No LocationTimeZoneProvider found for providerName=" + providerName
                    + ": stubbing");
            provider = new NullLocationTimeZoneProvider(mThreadingDomain, providerName);
        }
        return provider;
    }

    @Override
    public void onShellCommand(FileDescriptor in, FileDescriptor out,
            FileDescriptor err, String[] args, ShellCallback callback,
+10 −2
Original line number Diff line number Diff line
@@ -70,9 +70,11 @@ abstract class LocationTimeZoneProviderProxy implements Dumpable {
    }

    /**
     * Sets the listener. The listener can expect to receive all events after this point.
     * Initializes the proxy. The supplied listener can expect to receive all events after this
     * point. This method also calls {@link #onInitialize()} for subclasses to handle their own
     * initialization.
     */
    void setListener(@NonNull Listener listener) {
    void initialize(@NonNull Listener listener) {
        Objects.requireNonNull(listener);
        synchronized (mSharedLock) {
            if (mListener != null) {
@@ -80,8 +82,14 @@ abstract class LocationTimeZoneProviderProxy implements Dumpable {
            }
            this.mListener = listener;
        }
        onInitialize();
    }

    /**
     * Initializes the proxy. This is called after {@link #mListener} is set.
     */
    abstract void onInitialize();

    /**
     * Sets a new request for the provider.
     */
Loading