Merge "java FlagImpl: Clear context into Provider" into main am: b0c550dcb2
Original change: https://android-review.googlesource.com/c/platform/build/+/3324158
Change-Id: I2c8fd8d1517c88bcbaf1d5fd683c5a0f067bcfc0
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/tools/aconfig/aconfig/src/codegen/java.rs b/tools/aconfig/aconfig/src/codegen/java.rs
index 067a3b4..bfdf1a7 100644
--- a/tools/aconfig/aconfig/src/codegen/java.rs
+++ b/tools/aconfig/aconfig/src/codegen/java.rs
@@ -513,6 +513,7 @@
package com.android.aconfig.test;
// TODO(b/303773055): Remove the annotation after access issue is resolved.
import android.compat.annotation.UnsupportedAppUsage;
+ import android.os.Binder;
import android.provider.DeviceConfig;
import android.provider.DeviceConfig.Properties;
import android.aconfig.storage.StorageInternalReader;
@@ -544,6 +545,7 @@
isCached = true;
}
private void load_overrides_aconfig_test() {
+ final long ident = Binder.clearCallingIdentity();
try {
Properties properties = DeviceConfig.getProperties("aconfig_test");
disabledRw =
@@ -563,11 +565,14 @@
);
} catch (SecurityException e) {
// for isolated process case, skip loading flag value from the storage, use the default
+ } finally {
+ Binder.restoreCallingIdentity(ident);
}
aconfig_test_is_cached = true;
}
private void load_overrides_other_namespace() {
+ final long ident = Binder.clearCallingIdentity();
try {
Properties properties = DeviceConfig.getProperties("other_namespace");
disabledRwInOtherNamespace =
@@ -583,6 +588,8 @@
);
} catch (SecurityException e) {
// for isolated process case, skip loading flag value from the storage, use the default
+ } finally {
+ Binder.restoreCallingIdentity(ident);
}
other_namespace_is_cached = true;
}
@@ -764,6 +771,7 @@
let expect_feature_flags_impl_content = r#"
package com.android.aconfig.test;
+ import android.os.Binder;
import android.provider.DeviceConfig;
import android.provider.DeviceConfig.Properties;
/** @hide */
@@ -774,6 +782,7 @@
private static boolean enabledRoExported = false;
private void load_overrides_aconfig_test() {
+ final long ident = Binder.clearCallingIdentity();
try {
Properties properties = DeviceConfig.getProperties("aconfig_test");
disabledRwExported =
@@ -793,6 +802,8 @@
);
} catch (SecurityException e) {
// for isolated process case, skip loading flag value from the storage, use the default
+ } finally {
+ Binder.restoreCallingIdentity(ident);
}
aconfig_test_is_cached = true;
}
diff --git a/tools/aconfig/aconfig/templates/FeatureFlagsImpl.java.template b/tools/aconfig/aconfig/templates/FeatureFlagsImpl.java.template
index 15df902..ec86806 100644
--- a/tools/aconfig/aconfig/templates/FeatureFlagsImpl.java.template
+++ b/tools/aconfig/aconfig/templates/FeatureFlagsImpl.java.template
@@ -7,6 +7,7 @@
{{ -endif }}
{{ -if runtime_lookup_required }}
+import android.os.Binder;
import android.provider.DeviceConfig;
import android.provider.DeviceConfig.Properties;
@@ -57,6 +58,7 @@
{{ for namespace_with_flags in namespace_flags }}
private void load_overrides_{namespace_with_flags.namespace}() \{
+ final long ident = Binder.clearCallingIdentity();
try \{
Properties properties = DeviceConfig.getProperties("{namespace_with_flags.namespace}");
{{ -for flag in namespace_with_flags.flags }}
@@ -76,6 +78,8 @@
);
} catch (SecurityException e) \{
// for isolated process case, skip loading flag value from the storage, use the default
+ } finally \{
+ Binder.restoreCallingIdentity(ident);
}
{namespace_with_flags.namespace}_is_cached = true;
}
diff --git a/tools/aconfig/fake_device_config/src/android/os/Binder.java b/tools/aconfig/fake_device_config/src/android/os/Binder.java
new file mode 100644
index 0000000..8a2313d
--- /dev/null
+++ b/tools/aconfig/fake_device_config/src/android/os/Binder.java
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.os;
+
+public class Binder {
+ public static final long clearCallingIdentity() {
+ throw new UnsupportedOperationException("Stub!");
+ }
+ public static final void restoreCallingIdentity(long token) {
+ throw new UnsupportedOperationException("Stub!");
+ }
+}