Skip to content

Commit

Permalink
Use looseSignatures for ShadowAppOpsManager's noteProxyOpNoThrow(int,…
Browse files Browse the repository at this point in the history
… AttributionSource, String, bool)

We have tried to use Object to replace AttributionSource as type of
second input parameter for noteProxyOpNoThrow(int, AttributeSource,
String, bool) to make sure ShadowAppOpsManager can be loaded and used
when compile SDK is less than 31. But changed method's siganture doesn't
match origin method signature, and it will be used as shadow method. To
fix this problem, this CL uses looseSignatures for ShadowAppOpsManager,
and chagnes all input parameters' type to Object to meet
looseSignatures' requirement.

Signed-off-by: utzcoz <utzcoz@outlook.com>
  • Loading branch information
utzcoz committed Nov 25, 2021
1 parent 9d0fcf7 commit 35d4bab
Showing 1 changed file with 7 additions and 4 deletions.
Expand Up @@ -59,7 +59,7 @@
import org.robolectric.util.ReflectionHelpers;
import org.robolectric.util.ReflectionHelpers.ClassParameter;

@Implements(value = AppOpsManager.class)
@Implements(value = AppOpsManager.class, looseSignatures = true)
public class ShadowAppOpsManager {

// OpEntry fields that the shadow doesn't currently allow the test to configure.
Expand Down Expand Up @@ -399,15 +399,18 @@ protected int noteProxyOpNoThrow(
@RequiresApi(api = Build.VERSION_CODES.S)
@Implementation(minSdk = Build.VERSION_CODES.S)
protected int noteProxyOpNoThrow(
int op, Object attributionSource, String message, boolean ignoredSkipProxyOperation) {
Object op, Object attributionSource, Object message, Object ignoredSkipProxyOperation) {
Preconditions.checkArgument(op instanceof Integer);
Preconditions.checkArgument(attributionSource instanceof AttributionSource);
Preconditions.checkArgument(message == null || message instanceof String);
Preconditions.checkArgument(ignoredSkipProxyOperation instanceof Boolean);
AttributionSource castedAttributionSource = (AttributionSource) attributionSource;
return noteProxyOpNoThrow(
op,
(int) op,
castedAttributionSource.getNextPackageName(),
castedAttributionSource.getNextUid(),
castedAttributionSource.getNextAttributionTag(),
message);
(String) message);
}

@Implementation(minSdk = KITKAT)
Expand Down

0 comments on commit 35d4bab

Please sign in to comment.