diff options
author | Neil Fuller <nfuller@google.com> | 2017-10-27 10:26:05 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2017-10-27 10:26:05 +0000 |
commit | 1f5c91fe8d6a6b47378900c4c457604ae6b86d81 (patch) | |
tree | 86857950ed8441b4ce1bc5e728aa07072e9cb686 | |
parent | 587cdcfbad39f38bdd25c267eeae01202a52f29d (diff) | |
parent | ae26ce05fb601ac62ba035974d23cae50552ea67 (diff) | |
download | TimeZoneData-1f5c91fe8d6a6b47378900c4c457604ae6b86d81.tar.gz |
Explicitly disallow multiple user execute am: 10291b3a6b
am: ae26ce05fb
Change-Id: I6f86160027dc3aaaa17def083fde02ccd34c1b8c
-rw-r--r-- | src/main/com/android/timezone/data/TimeZoneRulesDataProvider.java | 9 | ||||
-rw-r--r-- | testing/xts/src/com/android/timezone/xts/TimeZoneUpdateHostTest.java | 43 |
2 files changed, 52 insertions, 0 deletions
diff --git a/src/main/com/android/timezone/data/TimeZoneRulesDataProvider.java b/src/main/com/android/timezone/data/TimeZoneRulesDataProvider.java index 194620f..d92665a 100644 --- a/src/main/com/android/timezone/data/TimeZoneRulesDataProvider.java +++ b/src/main/com/android/timezone/data/TimeZoneRulesDataProvider.java @@ -31,6 +31,7 @@ import android.database.Cursor; import android.net.Uri; import android.os.Bundle; import android.os.ParcelFileDescriptor; +import android.os.UserHandle; import android.provider.TimeZoneRulesDataContract; import android.provider.TimeZoneRulesDataContract.Operation; import android.support.annotation.NonNull; @@ -94,6 +95,14 @@ public final class TimeZoneRulesDataProvider extends ContentProvider { public void attachInfo(Context context, ProviderInfo info) { super.attachInfo(context, info); + // The time zone update process should run as the system user exclusively as it's a + // system feature, not user dependent. + UserHandle currentUserHandle = android.os.Process.myUserHandle(); + if (!currentUserHandle.isSystem()) { + throw new SecurityException("ContentProvider is supposed to run as the system user," + + " instead user=" + currentUserHandle); + } + // Sanity check our security if (!TimeZoneRulesDataContract.AUTHORITY.equals(info.authority)) { // The authority looked for by the time zone updater is fixed. diff --git a/testing/xts/src/com/android/timezone/xts/TimeZoneUpdateHostTest.java b/testing/xts/src/com/android/timezone/xts/TimeZoneUpdateHostTest.java index a875634..71ae1d0 100644 --- a/testing/xts/src/com/android/timezone/xts/TimeZoneUpdateHostTest.java +++ b/testing/xts/src/com/android/timezone/xts/TimeZoneUpdateHostTest.java @@ -18,6 +18,7 @@ package com.android.timezone.xts; import com.android.compatibility.common.tradefed.build.CompatibilityBuildHelper; import com.android.tradefed.build.IBuildInfo; import com.android.tradefed.config.Option; +import com.android.tradefed.device.ITestDevice; import com.android.tradefed.log.LogUtil; import com.android.tradefed.testtype.DeviceTestCase; import com.android.tradefed.testtype.IBuildReceiver; @@ -186,6 +187,48 @@ public class TimeZoneUpdateHostTest extends DeviceTestCase implements IBuildRece } // @Test + public void testInstallNewerRulesVersion_secondaryUser() throws Exception { + ITestDevice device = getDevice(); + if (!device.isMultiUserSupported()) { + // Just pass on non-multi-user devices. + return; + } + + int userId = device.createUser("TimeZoneTest", false /* guest */, false /* ephemeral */); + try { + + // This information must match the rules version in test1: IANA version=2030a, revision=1 + String test1VersionInfo = "2030a,1"; + + // Confirm the staged / install state before we start. + assertFalse(test1VersionInfo.equals(getCurrentInstalledVersion())); + assertEquals(STAGED_OPERATION_NONE, getStagedOperationType()); + + File appFile = getTimeZoneDataApkFile("test1"); + + // Install the app for the test user. It should still all work. + device.installPackageForUser(appFile, true /* reinstall */, userId); + + waitForStagedInstall(test1VersionInfo); + + // Confirm the install state hasn't changed. + assertFalse(test1VersionInfo.equals(getCurrentInstalledVersion())); + + // Now reboot, and the staged version should become the installed version. + rebootDeviceAndWaitForRestart(); + + // After reboot, check the state. + assertEquals(STAGED_OPERATION_NONE, getStagedOperationType()); + assertEquals(INSTALL_STATE_INSTALLED, getCurrentInstallState()); + assertEquals(test1VersionInfo, getCurrentInstalledVersion()); + } + finally { + // If this fails, the device may be left in a bad state. + device.removeUser(userId); + } + } + + // @Test public void testInstallOlderRulesVersion() throws Exception { File appFile = getTimeZoneDataApkFile("test2"); getDevice().installPackage(appFile, true /* reinstall */); |