Skip to content
Snippets Groups Projects
Commit 763a6e68 authored by Makoto Onuki's avatar Makoto Onuki Committed by Android (Google) Code Review
Browse files

Merge "Add a hidden API to detect ravenwood environment" into main

parents c2644b78 110c3175
No related branches found
No related tags found
No related merge requests found
/*
* Copyright (C) 2024 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.internal.ravenwood;
/**
* Class to interact with the Ravenwood environment.
*/
@android.ravenwood.annotation.RavenwoodKeepWholeClass
public class RavenwoodEnvironment {
private static RavenwoodEnvironment sInstance = new RavenwoodEnvironment();
private RavenwoodEnvironment() {
}
/**
* @return the singleton instance.
*/
public static RavenwoodEnvironment getInstance() {
return sInstance;
}
/**
* USE IT SPARINGLY! Returns true if it's running on Ravenwood, hostside test environment.
*
* <p>Using this allows code to behave differently on a real device and on Ravenwood, but
* generally speaking, that's a bad idea because we want the test target code to behave
* differently.
*
* <p>This should be only used when different behavior is absolutely needed.
*
* <p>If someone needs it without having access to the SDK, the following hack would work too.
* <code>System.getProperty("java.class.path").contains("ravenwood")</code>
*/
@android.ravenwood.annotation.RavenwoodReplace
public boolean isRunningOnRavenwood() {
return false;
}
public boolean isRunningOnRavenwood$ravenwood() {
return true;
}
}
......@@ -260,6 +260,7 @@ android_ravenwood_test {
"src/com/android/internal/os/**/*.java",
"src/com/android/internal/util/**/*.java",
"src/com/android/internal/power/EnergyConsumerStatsTest.java",
"src/com/android/internal/ravenwood/**/*.java",
// Pull in R.java from FrameworksCoreTests-resonly, not from FrameworksCoreTests,
// to avoid having a dependency to FrameworksCoreTests.
......
/*
* Copyright (C) 2024 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.internal.ravenwood;
import static junit.framework.TestCase.assertEquals;
import android.platform.test.ravenwood.RavenwoodRule;
import androidx.test.runner.AndroidJUnit4;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
public class RavenwoodEnvironmentTest {
@Rule
public final RavenwoodRule mRavenwood = new RavenwoodRule();
@Test
public void testIsRunningOnRavenwood() {
assertEquals(RavenwoodRule.isUnderRavenwood(),
RavenwoodEnvironment.getInstance().isRunningOnRavenwood());
}
}
# Only classes listed here can use the Ravenwood annotations.
com.android.internal.ravenwood.*
com.android.internal.display.BrightnessSynchronizer
com.android.internal.util.ArrayUtils
com.android.internal.logging.MetricsLogger
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment