Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make ShadowPendingIntent implement is___ methods of PendingIntent #7268

Open
wants to merge 1 commit into
base: google
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -517,6 +517,80 @@ public void cancel_shouldRemovePendingIntentForForegroundService() {
assertThat(PendingIntent.getForegroundService(context, 99, intent, FLAG_NO_CREATE)).isNull();
}

@Test
@Config(minSdk = Build.VERSION_CODES.S)
public void isActivity_activityPendingIntent_returnsTrue() {
Intent intent = new Intent();
assertThat(PendingIntent.getActivity(context, 99, intent, 100).isActivity()).isTrue();
}

@Test
@Config(minSdk = Build.VERSION_CODES.S)
public void isActivity_broadcastPendingIntent_returnsFalse() {
Intent intent = new Intent();
assertThat(PendingIntent.getBroadcast(context, 99, intent, 100).isActivity()).isFalse();
}

@Test
@Config(minSdk = Build.VERSION_CODES.S)
public void isBroadcast_broadcastPendingIntent_returnsTrue() {
Intent intent = new Intent();
assertThat(PendingIntent.getBroadcast(context, 99, intent, 100).isBroadcast()).isTrue();
}

@Test
@Config(minSdk = Build.VERSION_CODES.S)
public void isBroadcast_activityPendingIntent_returnsFalse() {
Intent intent = new Intent();
assertThat(PendingIntent.getActivity(context, 99, intent, 100).isBroadcast()).isFalse();
}

@Test
@Config(minSdk = Build.VERSION_CODES.S)
public void isForegroundService_foregroundServicePendingIntent_returnsTrue() {
Intent intent = new Intent();
assertThat(PendingIntent.getForegroundService(context, 99, intent, 100).isForegroundService())
.isTrue();
}

@Test
@Config(minSdk = Build.VERSION_CODES.S)
public void isForegroundService_normalServicePendingIntent_returnsFalse() {
Intent intent = new Intent();
assertThat(PendingIntent.getService(context, 99, intent, 100).isForegroundService()).isFalse();
}

@Test
@Config(minSdk = Build.VERSION_CODES.S)
public void isService_servicePendingIntent_returnsTrue() {
Intent intent = new Intent();
assertThat(PendingIntent.getService(context, 99, intent, 100).isService()).isTrue();
}

@Test
@Config(minSdk = Build.VERSION_CODES.S)
public void isService_foregroundServicePendingIntent_returnsFalse() {
Intent intent = new Intent();
assertThat(PendingIntent.getForegroundService(context, 99, intent, 100).isService()).isFalse();
}

@Test
@Config(minSdk = Build.VERSION_CODES.S)
public void isImmutable_pendingIntentWithImmutableFlag_returnsTrue() {
Intent intent = new Intent();
assertThat(
PendingIntent.getActivity(context, 99, intent, PendingIntent.FLAG_IMMUTABLE)
.isImmutable())
.isTrue();
}

@Test
@Config(minSdk = Build.VERSION_CODES.S)
public void isImmutable_pendingIntentWithoutImmutableFlag_returnsFalse() {
Intent intent = new Intent();
assertThat(PendingIntent.getActivity(context, 99, intent, 0).isActivity()).isTrue();
}

@Test
public void send_canceledPendingIntent_throwsCanceledException() throws CanceledException {
Intent intent = new Intent().setPackage("dummy.package");
Expand Down
Expand Up @@ -9,6 +9,7 @@
import static android.os.Build.VERSION_CODES.M;
import static android.os.Build.VERSION_CODES.N;
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.NonNull;
Expand Down Expand Up @@ -240,6 +241,31 @@ protected IntentSender getIntentSender() {
return new RoboIntentSender(realPendingIntent);
}

@Implementation(minSdk = S)
public boolean isActivity() {
return isActivityIntent();
}

@Implementation(minSdk = S)
public boolean isBroadcast() {
return isBroadcastIntent();
}

@Implementation(minSdk = S)
public boolean isForegroundService() {
return isForegroundServiceIntent();
}

@Implementation(minSdk = S)
public boolean isService() {
return isServiceIntent();
}

@Implementation(minSdk = S)
public boolean isImmutable() {
return (flags & FLAG_IMMUTABLE) > 0;
}

/**
* @return {@code true} iff sending this PendingIntent will start an activity
*/
Expand Down