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

Commit 0a6aecca authored by Neil Fuller's avatar Neil Fuller Committed by android-build-merger
Browse files

Merge "Add (disabled) time zone update system server impl"

am: cba224e8

Change-Id: I603af513ae8170a1fac6e2e2fdc364ecbea0abfd
parents 2ea38744 cba224e8
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import android.accounts.IAccountManager;
import android.app.admin.DevicePolicyManager;
import android.app.job.IJobScheduler;
import android.app.job.JobScheduler;
import android.app.timezone.RulesManager;
import android.app.trust.TrustManager;
import android.app.usage.IUsageStatsManager;
import android.app.usage.NetworkStatsManager;
@@ -786,6 +787,13 @@ final class SystemServiceRegistry {
                return new ContextHubManager(ctx.getOuterContext(),
                  ctx.mMainThread.getHandler().getLooper());
            }});

        registerService(Context.TIME_ZONE_RULES_MANAGER_SERVICE, RulesManager.class,
                new CachedServiceFetcher<RulesManager>() {
            @Override
            public RulesManager createService(ContextImpl ctx) {
                return new RulesManager(ctx.getOuterContext());
            }});
    }

    /**
+43 −0
Original line number Diff line number Diff line
@@ -1282,6 +1282,49 @@
    <!-- True if WallpaperService is enabled -->
    <bool name="config_enableWallpaperService">true</bool>

    <!-- Enables the TimeZoneRuleManager service. This is the master switch for the updateable time
         zone update mechanism. -->
    <bool name="config_enableUpdateableTimeZoneRules">false</bool>

    <!-- Enables APK-based time zone update triggering. Set this to false when updates are triggered
         via external events and not by APK updates. For example, if an updater checks with a server
         on a regular schedule.
         [This is only used if config_enableUpdateableTimeZoneRules is true.] -->
    <bool name="config_timeZoneRulesUpdateTrackingEnabled">false</bool>

    <!-- The package of the time zone rules updater application. Expected to be the same
         for all Android devices that support APK-based time zone rule updates.
         A package-targeted android.intent.action.timezone.TRIGGER_RULES_UPDATE_CHECK intent
         will be sent to the updater app if the system server detects an update to the updater or
         data app packages.
         The package referenced here must have the android.permission.UPDATE_TIME_ZONE_RULES
         permission.
         [This is only used if config_enableUpdateableTimeZoneRules and
         config_timeZoneRulesUpdateTrackingEnabled are true.] -->
    <string name="config_timeZoneRulesUpdaterPackage" translateable="false"></string>

    <!-- The package of the time zone rules data application. Expected to be configured
         by OEMs to reference their own priv-app APK package.
         A package-targeted android.intent.action.timezone.TRIGGER_RULES_UPDATE_CHECK intent
         will be sent to the updater app if the system server detects an update to the updater or
         data app packages.
         [This is only used if config_enableUpdateableTimeZoneRules and
         config_timeZoneRulesUpdateTrackingEnabled are true.] -->
    <string name="config_timeZoneRulesDataPackage" translateable="false"></string>

    <!-- The allowed time in milliseconds between an update check intent being broadcast and the
         response being considered overdue. Reliability triggers will not fire in this time.
         [This is only used if config_enableUpdateableTimeZoneRules and
         config_timeZoneRulesUpdateTrackingEnabled are true.] -->
    <!-- 5 minutes -->
    <integer name="config_timeZoneRulesCheckTimeMillisAllowed">300000</integer>

    <!-- The number of times a time zone update check is allowed to fail before the system will stop
         reacting to reliability triggers.
         [This is only used if config_enableUpdateableTimeZoneRules and
         config_timeZoneRulesUpdateTrackingEnabled are true.] -->
    <integer name="config_timeZoneRulesCheckRetryCount">5</integer>

    <!-- Whether to enable network location overlay which allows network
         location provider to be replaced by an app at run-time. When disabled,
         only the config_networkLocationProviderPackageName package will be
+6 −0
Original line number Diff line number Diff line
@@ -275,6 +275,12 @@
  <java-symbol type="bool" name="split_action_bar_is_narrow" />
  <java-symbol type="bool" name="config_useVolumeKeySounds" />
  <java-symbol type="bool" name="config_enableWallpaperService" />
  <java-symbol type="bool" name="config_enableUpdateableTimeZoneRules" />
  <java-symbol type="bool" name="config_timeZoneRulesUpdateTrackingEnabled" />
  <java-symbol type="string" name="config_timeZoneRulesUpdaterPackage" />
  <java-symbol type="string" name="config_timeZoneRulesDataPackage" />
  <java-symbol type="integer" name="config_timeZoneRulesCheckTimeMillisAllowed" />
  <java-symbol type="integer" name="config_timeZoneRulesCheckRetryCount" />
  <java-symbol type="bool" name="config_sendAudioBecomingNoisy" />
  <java-symbol type="bool" name="config_enableScreenshotChord" />
  <java-symbol type="bool" name="config_bluetooth_default_profiles" />
+98 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 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.server.timezone;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.Arrays;

/**
 * A deserialized version of the byte[] sent to the time zone update application to identify a
 * triggered time zone update check. It encodes the optimistic lock ID used to detect
 * concurrent checks and the minimal package versions that will have been checked.
 */
final class CheckToken {

    final int mOptimisticLockId;
    final PackageVersions mPackageVersions;

    CheckToken(int optimisticLockId, PackageVersions packageVersions) {
        this.mOptimisticLockId = optimisticLockId;

        if (packageVersions == null) {
            throw new NullPointerException("packageVersions == null");
        }
        this.mPackageVersions = packageVersions;
    }

    byte[] toByteArray() {
        ByteArrayOutputStream baos = new ByteArrayOutputStream(12 /* (3 * sizeof(int)) */);
        try (DataOutputStream dos = new DataOutputStream(baos)) {
            dos.writeInt(mOptimisticLockId);
            dos.writeInt(mPackageVersions.mUpdateAppVersion);
            dos.writeInt(mPackageVersions.mDataAppVersion);
        } catch (IOException e) {
            throw new RuntimeException("Unable to write into a ByteArrayOutputStream", e);
        }
        return baos.toByteArray();
    }

    static CheckToken fromByteArray(byte[] tokenBytes) throws IOException {
        ByteArrayInputStream bais = new ByteArrayInputStream(tokenBytes);
        try (DataInputStream dis = new DataInputStream(bais)) {
            int versionId = dis.readInt();
            int updateAppVersion = dis.readInt();
            int dataAppVersion = dis.readInt();
            return new CheckToken(versionId, new PackageVersions(updateAppVersion, dataAppVersion));
        }
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }

        CheckToken checkToken = (CheckToken) o;

        if (mOptimisticLockId != checkToken.mOptimisticLockId) {
            return false;
        }
        return mPackageVersions.equals(checkToken.mPackageVersions);
    }

    @Override
    public int hashCode() {
        int result = mOptimisticLockId;
        result = 31 * result + mPackageVersions.hashCode();
        return result;
    }

    @Override
    public String toString() {
        return "Token{" +
                "mOptimisticLockId=" + mOptimisticLockId +
                ", mPackageVersions=" + mPackageVersions +
                '}';
    }
}
+25 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 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.server.timezone;

/**
 * An easy-to-mock interface for obtaining a monotonically increasing time value in milliseconds.
 */
interface ClockHelper {

    long currentTimestamp();
}
Loading