Skip to content

Commit

Permalink
Merge branch 'google' into 'master'
Browse files Browse the repository at this point in the history
  • Loading branch information
hoisie committed Nov 23, 2024
2 parents e36f7ad + 079f358 commit cfdb752
Show file tree
Hide file tree
Showing 31 changed files with 1,636 additions and 828 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import android.view.accessibility.AccessibilityWindowInfo;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -36,15 +35,9 @@ public class ShadowAccessibilityNodeInfoTest {
@Before
public void setUp() {
ShadowAccessibilityNodeInfo.resetObtainedInstances();
assertThat(ShadowAccessibilityNodeInfo.areThereUnrecycledNodes(true)).isEqualTo(false);
node = AccessibilityNodeInfo.obtain();
}

@Test
public void shouldHaveObtainedNode() {
assertThat(ShadowAccessibilityNodeInfo.areThereUnrecycledNodes(false)).isEqualTo(true);
}

@Test
public void shouldHaveZeroBounds() {
Rect outBounds = new Rect();
Expand Down Expand Up @@ -322,10 +315,4 @@ public void obtainWithNode_afterSetSealed() {
AccessibilityNodeInfo node2 = AccessibilityNodeInfo.obtain(node);
assertThat(node2.isSealed()).isTrue();
}

@After
public void tearDown() {
ShadowAccessibilityNodeInfo.resetObtainedInstances();
assertThat(ShadowAccessibilityNodeInfo.areThereUnrecycledNodes(true)).isEqualTo(false);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void before() {

@Test
public void acquire_shouldAcquireAndReleaseReferenceCountedLock() {
PowerManager.WakeLock lock = powerManager.newWakeLock(0, "TAG");
PowerManager.WakeLock lock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, "TAG");
assertThat(lock.isHeld()).isFalse();
lock.acquire();
assertThat(lock.isHeld()).isTrue();
Expand Down Expand Up @@ -88,7 +88,7 @@ public void acquire_shouldLogLatestWakeLock() {
ShadowPowerManager.reset();
assertThat(ShadowPowerManager.getLatestWakeLock()).isNull();

PowerManager.WakeLock lock = powerManager.newWakeLock(0, "TAG");
PowerManager.WakeLock lock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, "TAG");
lock.acquire();

assertThat(ShadowPowerManager.getLatestWakeLock()).isNotNull();
Expand All @@ -107,18 +107,18 @@ public void acquire_shouldLogLatestWakeLock() {

@Test
public void newWakeLock_shouldCreateWakeLock() {
assertThat(powerManager.newWakeLock(0, "TAG")).isNotNull();
assertThat(powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, "TAG")).isNotNull();
}

@Test
public void newWakeLock_shouldSetWakeLockTag() {
PowerManager.WakeLock wakeLock = powerManager.newWakeLock(0, "FOO");
PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, "FOO");
assertThat(shadowOf(wakeLock).getTag()).isEqualTo("FOO");
}

@Test
public void newWakeLock_shouldAcquireAndReleaseNonReferenceCountedLock() {
PowerManager.WakeLock lock = powerManager.newWakeLock(0, "TAG");
PowerManager.WakeLock lock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, "TAG");
lock.setReferenceCounted(false);

assertThat(lock.isHeld()).isFalse();
Expand All @@ -134,7 +134,7 @@ public void newWakeLock_shouldAcquireAndReleaseNonReferenceCountedLock() {

@Test
public void newWakeLock_shouldThrowRuntimeExceptionIfLockIsUnderlocked() {
PowerManager.WakeLock lock = powerManager.newWakeLock(0, "TAG");
PowerManager.WakeLock lock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, "TAG");
try {
lock.release();
fail();
Expand All @@ -156,7 +156,7 @@ public void isScreenOn_shouldGetAndSet() {

@Test
public void isReferenceCounted_shouldGetAndSet() {
PowerManager.WakeLock lock = powerManager.newWakeLock(0, "TAG");
PowerManager.WakeLock lock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, "TAG");
assertThat(shadowOf(lock).isReferenceCounted()).isTrue();
lock.setReferenceCounted(false);
assertThat(shadowOf(lock).isReferenceCounted()).isFalse();
Expand Down Expand Up @@ -229,7 +229,7 @@ public void addThermalStatusListener() {

@Test
public void workSource_shouldGetAndSet() {
PowerManager.WakeLock lock = powerManager.newWakeLock(0, "TAG");
PowerManager.WakeLock lock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, "TAG");
WorkSource workSource = new WorkSource();
assertThat(shadowOf(lock).getWorkSource()).isNull();
lock.setWorkSource(workSource);
Expand Down Expand Up @@ -294,7 +294,7 @@ public void reboot_incrementsTimesRebootedAndAppendsRebootReason() {

@Test
public void acquire_shouldIncreaseTimesHeld() {
PowerManager.WakeLock lock = powerManager.newWakeLock(0, "TAG");
PowerManager.WakeLock lock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, "TAG");

assertThat(shadowOf(lock).getTimesHeld()).isEqualTo(0);

Expand All @@ -307,7 +307,7 @@ public void acquire_shouldIncreaseTimesHeld() {

@Test
public void release_shouldNotDecreaseTimesHeld() {
PowerManager.WakeLock lock = powerManager.newWakeLock(0, "TAG");
PowerManager.WakeLock lock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, "TAG");
lock.acquire();
lock.acquire();

Expand Down Expand Up @@ -474,7 +474,7 @@ public void preR_userspaceReboot_shouldReboot() {

@Test
public void releaseWithFlags() {
PowerManager.WakeLock lock = powerManager.newWakeLock(0, "TAG");
PowerManager.WakeLock lock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, "TAG");
lock.acquire();

lock.release(PowerManager.RELEASE_FLAG_WAIT_FOR_NO_PROXIMITY);
Expand All @@ -484,7 +484,7 @@ public void releaseWithFlags() {

@Test
public void release() {
PowerManager.WakeLock lock = powerManager.newWakeLock(0, "TAG");
PowerManager.WakeLock lock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, "TAG");
lock.acquire();

lock.release();
Expand Down Expand Up @@ -538,15 +538,15 @@ public void getBatteryDischargePrediction_default() {

@Test
public void isHeld_neverAcquired_returnsFalse() {
PowerManager.WakeLock lock = powerManager.newWakeLock(0, "TIMEOUT");
PowerManager.WakeLock lock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, "TIMEOUT");
lock.setReferenceCounted(false);

assertThat(lock.isHeld()).isFalse();
}

@Test
public void isHeld_wakeLockTimeout_returnsFalse() {
PowerManager.WakeLock lock = powerManager.newWakeLock(0, "TIMEOUT");
PowerManager.WakeLock lock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, "TIMEOUT");
lock.setReferenceCounted(false);

lock.acquire(100);
Expand All @@ -557,7 +557,7 @@ public void isHeld_wakeLockTimeout_returnsFalse() {

@Test
public void isHeld_wakeLockJustTimeout_returnsTrue() {
PowerManager.WakeLock lock = powerManager.newWakeLock(0, "TIMEOUT");
PowerManager.WakeLock lock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, "TIMEOUT");
lock.setReferenceCounted(false);

lock.acquire(100);
Expand All @@ -568,7 +568,7 @@ public void isHeld_wakeLockJustTimeout_returnsTrue() {

@Test
public void isHeld_wakeLockNotTimeout_returnsTrue() {
PowerManager.WakeLock lock = powerManager.newWakeLock(0, "TIMEOUT");
PowerManager.WakeLock lock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, "TIMEOUT");
lock.setReferenceCounted(false);

lock.acquire(100);
Expand All @@ -579,7 +579,7 @@ public void isHeld_wakeLockNotTimeout_returnsTrue() {

@Test
public void isHeld_unlimitedWakeLockAcquired_returnsTrue() {
PowerManager.WakeLock lock = powerManager.newWakeLock(0, "TIMEOUT");
PowerManager.WakeLock lock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, "TIMEOUT");
lock.setReferenceCounted(false);

lock.acquire();
Expand All @@ -590,7 +590,7 @@ public void isHeld_unlimitedWakeLockAcquired_returnsTrue() {

@Test
public void release_isRefCounted_dequeueTheSmallestTimeoutLock() {
PowerManager.WakeLock lock = powerManager.newWakeLock(0, "TIMEOUT");
PowerManager.WakeLock lock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, "TIMEOUT");

// There are 2 wake lock acquires when calling release(). The wake lock with the smallest
// timeout timestamp is release first.
Expand All @@ -604,7 +604,7 @@ public void release_isRefCounted_dequeueTheSmallestTimeoutLock() {

@Test
public void release_isRefCounted_dequeueTimeoutLockBeforeUnlimited() {
PowerManager.WakeLock lock = powerManager.newWakeLock(0, "TIMEOUT");
PowerManager.WakeLock lock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, "TIMEOUT");

// There are 2 wake lock acquires when calling release(). The lock with timeout 100ms will be
// released first.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import static android.os.Build.VERSION_CODES.Q;
import static android.os.Build.VERSION_CODES.R;
import static android.os.Build.VERSION_CODES.TIRAMISU;
import static android.os.Build.VERSION_CODES.UPSIDE_DOWN_CAKE;
import static androidx.test.core.app.ApplicationProvider.getApplicationContext;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertThrows;
Expand Down Expand Up @@ -404,6 +405,80 @@ public void getPhoneId_shouldReturnInvalidIfReset() {
.isEqualTo(ShadowSubscriptionManager.INVALID_PHONE_INDEX);
}

@Test
public void getSubId() {
// Explicitly callable without any permissions.
shadowOf(subscriptionManager).setReadPhoneStatePermission(false);

assertThat(SubscriptionManager.getSubId(/* slotIndex= */ 0)).isNull();

shadowOf(subscriptionManager)
.setActiveSubscriptionInfos(
SubscriptionInfoBuilder.newBuilder()
.setId(123)
.setSimSlotIndex(0)
.buildSubscriptionInfo(),
SubscriptionInfoBuilder.newBuilder()
.setId(456)
.setSimSlotIndex(1)
.buildSubscriptionInfo());
int[] subId = SubscriptionManager.getSubId(/* slotIndex= */ 0);
assertThat(subId).hasLength(1);
assertThat(subId[0]).isEqualTo(123);

assertThat(SubscriptionManager.getSubId(/* slotIndex= */ 2)).isNull();
}

@Test
@Config(minSdk = Q)
public void getSubscriptionIds() {
// Explicitly callable without any permissions.
shadowOf(subscriptionManager).setReadPhoneStatePermission(false);

assertThat(subscriptionManager.getSubscriptionIds(/* slotIndex= */ 0)).isNull();

shadowOf(subscriptionManager)
.setActiveSubscriptionInfos(
SubscriptionInfoBuilder.newBuilder()
.setId(123)
.setSimSlotIndex(0)
.buildSubscriptionInfo(),
SubscriptionInfoBuilder.newBuilder()
.setId(456)
.setSimSlotIndex(1)
.buildSubscriptionInfo());
int[] subId = subscriptionManager.getSubscriptionIds(/* slotIndex= */ 0);
assertThat(subId).hasLength(1);
assertThat(subId[0]).isEqualTo(123);

assertThat(subscriptionManager.getSubscriptionIds(/* slotIndex= */ 2)).isNull();
}

@Test
@Config(minSdk = UPSIDE_DOWN_CAKE)
public void getSubscriptionId() {
// Explicitly callable without any permissions.
shadowOf(subscriptionManager).setReadPhoneStatePermission(false);

assertThat(SubscriptionManager.getSubscriptionId(/* slotIndex= */ 0))
.isEqualTo(SubscriptionManager.INVALID_SUBSCRIPTION_ID);

shadowOf(subscriptionManager)
.setActiveSubscriptionInfos(
SubscriptionInfoBuilder.newBuilder()
.setId(123)
.setSimSlotIndex(0)
.buildSubscriptionInfo(),
SubscriptionInfoBuilder.newBuilder()
.setId(456)
.setSimSlotIndex(1)
.buildSubscriptionInfo());
assertThat(SubscriptionManager.getSubscriptionId(/* slotIndex= */ 0)).isEqualTo(123);

assertThat(SubscriptionManager.getSubscriptionId(/* slotIndex= */ 2))
.isEqualTo(SubscriptionManager.INVALID_SUBSCRIPTION_ID);
}

@Test
public void setMcc() {
assertThat(
Expand Down
Loading

0 comments on commit cfdb752

Please sign in to comment.