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

Commit 3869971d authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes from topic "usbDisabled" into main

* changes:
  Drop null policy value during reading from file
  Flag usb data signaling api migration
parents 96fe7f89 fa76627b
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -24,4 +24,7 @@ java_library_static {
        "app-compat-annotations",
        "service-permission.stubs.system_server",
    ],
    static_libs: [
        "device_policy_aconfig_flags_lib",
    ],
}
+49 −13
Original line number Diff line number Diff line
@@ -491,6 +491,7 @@ import com.android.server.SystemServerInitThreadPool;
import com.android.server.SystemService;
import com.android.server.SystemServiceManager;
import com.android.server.devicepolicy.ActiveAdmin.TrustAgentInfo;
import com.android.server.devicepolicy.flags.FlagUtils;
import com.android.server.inputmethod.InputMethodManagerInternal;
import com.android.server.net.NetworkPolicyManagerInternal;
import com.android.server.pm.DefaultCrossProfileIntentFilter;
@@ -3432,6 +3433,9 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
            }
            revertTransferOwnershipIfNecessaryLocked();
            if (!FlagUtils.isPolicyEngineMigrationV2Enabled()) {
                updateUsbDataSignal(mContext, isUsbDataSignalingEnabledInternalLocked());
            }
        }
        // In case flag value has changed, we apply it during boot to avoid doing it concurrently
@@ -21575,7 +21579,17 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
        Objects.requireNonNull(packageName, "Admin package name must be provided");
        final CallerIdentity caller = getCallerIdentity(packageName);
        if (!FlagUtils.isPolicyEngineMigrationV2Enabled()) {
            Preconditions.checkCallAuthorization(
                    isDefaultDeviceOwner(caller) || isProfileOwnerOfOrganizationOwnedDevice(caller),
                    "USB data signaling can only be controlled by a device owner or "
                            + "a profile owner on an organization-owned device.");
            Preconditions.checkState(canUsbDataSignalingBeDisabled(),
                    "USB data signaling cannot be disabled.");
        }
        synchronized (getLockObject()) {
            if (FlagUtils.isPolicyEngineMigrationV2Enabled()) {
                EnforcingAdmin enforcingAdmin = enforcePermissionAndGetEnforcingAdmin(
                        /* admin= */ null, MANAGE_DEVICE_POLICY_USB_DATA_SIGNALLING,
                        caller.getPackageName(),
@@ -21586,6 +21600,14 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
                        PolicyDefinition.USB_DATA_SIGNALING,
                        enforcingAdmin,
                        new BooleanPolicyValue(enabled));
            } else {
                ActiveAdmin admin = getProfileOwnerOrDeviceOwnerLocked(caller.getUserId());
                if (admin.mUsbDataSignalingEnabled != enabled) {
                    admin.mUsbDataSignalingEnabled = enabled;
                    saveSettingsLocked(caller.getUserId());
                    updateUsbDataSignal(mContext, isUsbDataSignalingEnabledInternalLocked());
                }
            }
        }
        DevicePolicyEventLogger
                .createEvent(DevicePolicyEnums.SET_USB_DATA_SIGNALING)
@@ -21607,10 +21629,24 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
    @Override
    public boolean isUsbDataSignalingEnabled(String packageName) {
        final CallerIdentity caller = getCallerIdentity(packageName);
        if (FlagUtils.isPolicyEngineMigrationV2Enabled()) {
            Boolean enabled = mDevicePolicyEngine.getResolvedPolicy(
                    PolicyDefinition.USB_DATA_SIGNALING,
                    caller.getUserId());
            return enabled == null || enabled;
        } else {
            synchronized (getLockObject()) {
                // If the caller is an admin, return the policy set by itself. Otherwise
                // return the device-wide policy.
                if (isDefaultDeviceOwner(caller) || isProfileOwnerOfOrganizationOwnedDevice(
                        caller)) {
                    return getProfileOwnerOrDeviceOwnerLocked(
                            caller.getUserId()).mUsbDataSignalingEnabled;
                } else {
                    return isUsbDataSignalingEnabledInternalLocked();
                }
            }
        }
    }
    private boolean isUsbDataSignalingEnabledInternalLocked() {
+9 −4
Original line number Diff line number Diff line
@@ -260,11 +260,14 @@ final class PolicyState<V> {
                                break;
                        }
                    }
                    if (admin != null) {
                    if (admin != null && value != null) {
                        policiesSetByAdmins.put(admin, value);
                    } else {
                        Slogf.wtf(TAG, "Error Parsing TAG_ADMIN_POLICY_ENTRY, EnforcingAdmin "
                                + "is null");
                        Slogf.wtf(TAG, "Error Parsing TAG_ADMIN_POLICY_ENTRY for "
                                + (policyDefinition == null ? "unknown policy" : "policy with "
                                + "definition " + policyDefinition) + ", EnforcingAdmin is: "
                                + (admin == null ? "null" : admin) + ", value is : "
                                + (value == null ? "null" : value));
                    }
                    break;
                case TAG_POLICY_DEFINITION_ENTRY:
@@ -283,7 +286,9 @@ final class PolicyState<V> {
                    }
                    currentResolvedPolicy = policyDefinition.readPolicyValueFromXml(parser);
                    if (currentResolvedPolicy == null) {
                        Slogf.wtf(TAG, "Error Parsing TAG_RESOLVED_VALUE_ENTRY, "
                        Slogf.wtf(TAG, "Error Parsing TAG_RESOLVED_VALUE_ENTRY for "
                                + (policyDefinition == null ? "unknown policy" : "policy with "
                                + "definition " + policyDefinition) + ", "
                                + "currentResolvedPolicy is null");
                    }
                    break;
+16 −0
Original line number Diff line number Diff line
package {
    default_applicable_licenses: ["Android-Apache-2.0"],
}

aconfig_declarations {
    name: "device_policy_aconfig_flags",
    package: "com.android.server.devicepolicy.flags",
    srcs: [
        "flags.aconfig",
    ],
}

java_aconfig_library {
    name: "device_policy_aconfig_flags_lib",
    aconfig_declarations: "device_policy_aconfig_flags",
}
+31 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 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 com.android.server.devicepolicy.flags;

import static com.android.server.devicepolicy.flags.Flags.policyEngineMigrationV2Enabled;

import android.os.Binder;

public final class FlagUtils {
    private FlagUtils(){}

    public static boolean isPolicyEngineMigrationV2Enabled() {
        return Binder.withCleanCallingIdentity(() -> {
            return policyEngineMigrationV2Enabled();
        });
    }
}
Loading