Skip to content

Commit

Permalink
Merge pull request #6836 from robolectric/piper_408717180
Browse files Browse the repository at this point in the history
Shadow Build.VERSION#MEDIA_PERFORMANCE_CLASS
  • Loading branch information
hoisie committed Nov 17, 2021
2 parents 326991f + f279da2 commit 92174b5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Expand Up @@ -2,6 +2,8 @@

import static android.os.Build.VERSION_CODES.M;
import static android.os.Build.VERSION_CODES.O;
import static android.os.Build.VERSION_CODES.R;
import static android.os.Build.VERSION_CODES.S;
import static com.google.common.truth.Truth.assertThat;

import android.os.Build;
Expand Down Expand Up @@ -56,6 +58,13 @@ public void setVersionIncremental() {
assertThat(VERSION.INCREMENTAL).isEqualTo("robo_incremental");
}

@Test
@Config(minSdk = S)
public void setVersionMediaPerformanceClass() {
ShadowBuild.setVersionMediaPerformanceClass(R);
assertThat(VERSION.MEDIA_PERFORMANCE_CLASS).isEqualTo(R);
}

@Test
@Config(minSdk = M)
public void setVersionSecurityPatch() {
Expand Down
Expand Up @@ -3,6 +3,7 @@
import static android.os.Build.VERSION_CODES.LOLLIPOP;
import static android.os.Build.VERSION_CODES.M;
import static android.os.Build.VERSION_CODES.O;
import static android.os.Build.VERSION_CODES.S;
import static org.robolectric.util.reflector.Reflector.reflector;

import android.annotation.TargetApi;
Expand Down Expand Up @@ -110,6 +111,18 @@ public static void setVersionIncremental(String versionIncremental) {
ReflectionHelpers.setStaticField(Build.VERSION.class, "INCREMENTAL", versionIncremental);
}

/**
* Sets the value of the {@link Build.VERSION#MEDIA_PERFORMANCE_CLASS} field. Available in Android
* S+.
*
* <p>It will be reset for the next test.
*/
@TargetApi(S)
public static void setVersionMediaPerformanceClass(int performanceClass) {
ReflectionHelpers.setStaticField(
Build.VERSION.class, "MEDIA_PERFORMANCE_CLASS", performanceClass);
}

/**
* Sets the value of the {@link Build.VERSION#RELEASE} field.
*
Expand Down

0 comments on commit 92174b5

Please sign in to comment.