Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4438f359 authored by Atneya Nair's avatar Atneya Nair
Browse files

java FlagImpl: Clear context into Provider

We should use the process local context, not the calling context when
we query the device provider for flag state, since we aren't exposing
any content to the caller.

Test: Compiles
Bug: 375288788
Change-Id: Idecda9c357f6a92b9b4a63b2ec9b0c04ff441a6d
parent a452c297
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -513,6 +513,7 @@ mod tests {
        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 @@ mod tests {
                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 @@ mod tests {
                    );
                } 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 @@ mod tests {
                    );
                } 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 @@ mod tests {

        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 @@ mod tests {
            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 @@ mod tests {
                    );
                } 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;
            }
+4 −0
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@ import android.compat.annotation.UnsupportedAppUsage;
{{ -endif }}

{{ -if runtime_lookup_required }}
import android.os.Binder;
import android.provider.DeviceConfig;
import android.provider.DeviceConfig.Properties;

@@ -57,6 +58,7 @@ public final class FeatureFlagsImpl implements FeatureFlags \{

{{ 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 @@ public final class FeatureFlagsImpl implements FeatureFlags \{
            );
        } 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;
    }
+26 −0
Original line number Diff line number Diff line
/*
 * 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!");
    }
}