diff options
author | Neil Fuller <nfuller@google.com> | 2017-10-27 10:13:20 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2017-10-27 10:13:20 +0000 |
commit | ae26ce05fb601ac62ba035974d23cae50552ea67 (patch) | |
tree | 4d727110f7c3332c8b01cfed20b0d44bdff6cc54 | |
parent | fde6b9823389a57a0cac6d2e6293145316041fee (diff) | |
parent | 10291b3a6b2dd09ddd34edb806ec3301f0c07133 (diff) | |
download | TimeZoneData-ae26ce05fb601ac62ba035974d23cae50552ea67.tar.gz |
Explicitly disallow multiple user execute
am: 10291b3a6b
Change-Id: I73dadb96a26e2d929afcd1baf12c06b3ceeee84b
-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 ac5fc5f..23d9481 100644 --- a/src/main/com/android/timezone/data/TimeZoneRulesDataProvider.java +++ b/src/main/com/android/timezone/data/TimeZoneRulesDataProvider.java @@ -33,6 +33,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; @@ -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 */); |