-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
ShadowAppIntegrityManager.java
53 lines (45 loc) · 1.71 KB
/
ShadowAppIntegrityManager.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package org.robolectric.shadows;
import static android.os.Build.VERSION_CODES.R;
import android.content.IntentSender;
import android.content.integrity.AppIntegrityManager;
import android.content.integrity.RuleSet;
import java.util.Optional;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
/** Shadow of {@link AppIntegrityManager} */
@Implements(
value = AppIntegrityManager.class,
minSdk = R,
isInAndroidSdk = false)
public class ShadowAppIntegrityManager {
private Optional<RuleSet> recordedRuleSet;
/** Default shadow constructor that resets the {@code recordedRuleSet}. */
public ShadowAppIntegrityManager() {
recordedRuleSet = Optional.empty();
}
/**
* Overrides the implementation of the {@code updateRuleSet} method so that a copy of the pushed
* rule set is kept within the shadow class.
*/
@Implementation
protected void updateRuleSet(RuleSet updateRequest, IntentSender statusReceiver) {
recordedRuleSet = Optional.of(updateRequest);
}
/**
* Overrides the implementation of the {@code getCurrentRuleSetVersion} method to return the
* version stored in the recorded rule set. The method returns "None" if there is no such rule set
* available.
*/
@Implementation
protected String getCurrentRuleSetVersion() {
return recordedRuleSet.isPresent() ? recordedRuleSet.get().getVersion() : "None";
}
/**
* Overrides the implementation of the {@code getCurrentRuleSetProvider} method to return the
* gmscore package name for all the requests when a rule set exists.
*/
@Implementation
protected String getCurrentRuleSetProvider() {
return recordedRuleSet.isPresent() ? "com.google.android.gms" : "None";
}
}