Factor out global kill switch lookup code.
Test: TH
Change-Id: I9af744a779e20805cc71d228e3b8c46a0412853c
diff --git a/src/com/android/ondevicepersonalization/services/OnDevicePersonalizationManagingServiceDelegate.java b/src/com/android/ondevicepersonalization/services/OnDevicePersonalizationManagingServiceDelegate.java
index 56cb0d7..1cb86d3 100644
--- a/src/com/android/ondevicepersonalization/services/OnDevicePersonalizationManagingServiceDelegate.java
+++ b/src/com/android/ondevicepersonalization/services/OnDevicePersonalizationManagingServiceDelegate.java
@@ -88,11 +88,9 @@
@NonNull ComponentName handler,
@NonNull PersistableBundle params,
@NonNull IExecuteCallback callback) {
- long origId = Binder.clearCallingIdentity();
- if (FlagsFactory.getFlags().getGlobalKillSwitch()) {
+ if (getGlobalKillSwitch()) {
throw new IllegalStateException("Service skipped as the global kill switch is on.");
}
- Binder.restoreCallingIdentity(origId);
Objects.requireNonNull(callingPackageName);
Objects.requireNonNull(handler);
@@ -130,11 +128,9 @@
int width,
int height,
@NonNull IRequestSurfacePackageCallback callback) {
- long origId = Binder.clearCallingIdentity();
- if (FlagsFactory.getFlags().getGlobalKillSwitch()) {
+ if (getGlobalKillSwitch()) {
throw new IllegalStateException("Service skipped as the global kill switch is on.");
}
- Binder.restoreCallingIdentity(origId);
Objects.requireNonNull(slotResultToken);
Objects.requireNonNull(hostToken);
@@ -162,6 +158,12 @@
flow.run();
}
+ private boolean getGlobalKillSwitch() {
+ long origId = Binder.clearCallingIdentity();
+ boolean globalKillSwitch = FlagsFactory.getFlags().getGlobalKillSwitch();
+ Binder.restoreCallingIdentity(origId);
+ return globalKillSwitch;
+ }
private void enforceCallingPackageBelongsToUid(@NonNull String packageName, int uid) {
int packageUid;
PackageManager pm = mContext.getPackageManager();