Loading core/java/android/app/SystemServiceRegistry.java +8 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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()); }}); } /** Loading core/res/res/values/config.xml +43 −0 Original line number Diff line number Diff line Loading @@ -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 Loading core/res/res/values/symbols.xml +6 −0 Original line number Diff line number Diff line Loading @@ -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" /> Loading services/core/java/com/android/server/timezone/CheckToken.java 0 → 100644 +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 + '}'; } } services/core/java/com/android/server/timezone/ClockHelper.java 0 → 100644 +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
core/java/android/app/SystemServiceRegistry.java +8 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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()); }}); } /** Loading
core/res/res/values/config.xml +43 −0 Original line number Diff line number Diff line Loading @@ -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 Loading
core/res/res/values/symbols.xml +6 −0 Original line number Diff line number Diff line Loading @@ -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" /> Loading
services/core/java/com/android/server/timezone/CheckToken.java 0 → 100644 +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 + '}'; } }
services/core/java/com/android/server/timezone/ClockHelper.java 0 → 100644 +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(); }