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

Commit 392fd855 authored by Antoan Angelov's avatar Antoan Angelov Committed by Android (Google) Code Review
Browse files

Merge "SettingsLib logic for updated ActionDisabledByAdminDialogHelper" into sc-dev

parents 48f51861 51fd49ac
Loading
Loading
Loading
Loading
+53 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2021 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.settingslib.enterprise;

import android.app.Activity;
import android.content.Context;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog.Builder;

import com.android.settingslib.RestrictedLockUtils;

/**
 * A controller used to customize the action disabled by admin dialog.
 */
public interface ActionDisabledByAdminController {

    /**
     * Handles the adding and setting up of the learn more button. If button is not needed, then
     * this method can be left empty.
     */
    void setupLearnMoreButton(Activity activity, Builder builder);

    /**
     * Returns the admin support dialog's title resource id.
     */
    String getAdminSupportTitle(@Nullable String restriction);

    /**
     * Returns the admin support dialog's content string.
     */
    CharSequence getAdminSupportContentString(
            Context context, @Nullable CharSequence supportMessage);

    /**
     * Updates the enforced admin
     */
    void updateEnforcedAdmin(RestrictedLockUtils.EnforcedAdmin admin, int adminUserId);
}
+47 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2021 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.settingslib.enterprise;

import static android.app.admin.DevicePolicyManager.DEVICE_OWNER_TYPE_FINANCED;

import android.app.admin.DevicePolicyManager;

/**
 * A factory that returns the relevant instance of {@link ActionDisabledByAdminController}.
 */
public class ActionDisabledByAdminControllerFactory {

    /**
     * Returns the relevant instance of {@link ActionDisabledByAdminController}.
     */
    public static ActionDisabledByAdminController createInstance(
            DevicePolicyManager dpm,
            ActionDisabledLearnMoreButtonLauncher helper,
            DeviceAdminStringProvider deviceAdminStringProvider) {
        if (isFinancedDevice(dpm)) {
            return new FinancedDeviceActionDisabledByAdminController(
                    helper, deviceAdminStringProvider);
        }
        return new ManagedDeviceActionDisabledByAdminController(
                helper, deviceAdminStringProvider);
    }

    private static boolean isFinancedDevice(DevicePolicyManager dpm) {
        return dpm.isDeviceManaged() && dpm.getDeviceOwnerType(
                dpm.getDeviceOwnerComponentOnAnyUser()) == DEVICE_OWNER_TYPE_FINANCED;
    }
}
+46 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2021 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.settingslib.enterprise;

import android.app.Activity;

import androidx.appcompat.app.AlertDialog;

import com.android.settingslib.RestrictedLockUtils;

/**
 * Helper interface meant to set up the "Learn more" button in the action disabled dialog.
 */
public interface ActionDisabledLearnMoreButtonLauncher {

    /**
     * Sets up a "learn more" button which shows a screen with device policy settings
     */
    void setupLearnMoreButtonToShowAdminPolicies(
            Activity activity,
            AlertDialog.Builder builder,
            int enforcementAdminUserId,
            RestrictedLockUtils.EnforcedAdmin enforcedAdmin);

    /**
     * Sets up a "learn more" button which launches a help page
     */
    void setupLearnMoreButtonToLaunchHelpPage(
            Activity activity,
            AlertDialog.Builder builder,
            String url);
}
+75 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2021 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.settingslib.enterprise;

/**
 * A {@code String} provider for the action disabled by admin dialog.
 */
public interface DeviceAdminStringProvider {

    /**
     * Returns the default dialog title for the case when an action is disabled by policy on a
     * managed device.
     */
    String getDefaultDisabledByPolicyTitle();

    /**
     * Returns the dialog title for the case when volume adjusting is disabled.
     */
    String getDisallowAdjustVolumeTitle();

    /**
     * Returns the dialog title for the case when outgoing calls are disabled.
     */
    String getDisallowOutgoingCallsTitle();

    /**
     * Returns the dialog title for the case when sending SMS is disabled.
     */
    String getDisallowSmsTitle();

    /**
     * Returns the dialog title for the case when the camera is disabled.
     */
    String getDisableCameraTitle();

    /**
     * Returns the dialog title for the case when screen capturing is disabled.
     */
    String getDisableScreenCaptureTitle();

    /**
     * Returns the dialog title for the case when suspending apps is disabled.
     */
    String getSuspendPackagesTitle();

    /**
     * Returns the default dialog content for the case when an action is disabled by policy.
     */
    String getDefaultDisabledByPolicyContent();

    /**
     * Returns the URL for the page to be shown when the learn more button is chosen.
     */
    String getLearnMoreHelpPageUrl();

    /**
     * Returns the default dialog title for the case when an action is disabled by policy on
     * a financed device.
     */
    String getDisabledByPolicyTitleForFinancedDevice();
}
+72 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2021 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.settingslib.enterprise;

import static java.util.Objects.requireNonNull;

import android.annotation.UserIdInt;
import android.app.Activity;
import android.content.Context;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog.Builder;

import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;

/**
 * An {@link ActionDisabledByAdminController} to be used with financed devices.
 */
public class FinancedDeviceActionDisabledByAdminController
        implements ActionDisabledByAdminController {

    private @UserIdInt int mEnforcementAdminUserId;
    private EnforcedAdmin mEnforcedAdmin;
    private final ActionDisabledLearnMoreButtonLauncher mHelper;
    private final DeviceAdminStringProvider mDeviceAdminStringProvider;

    FinancedDeviceActionDisabledByAdminController(
            ActionDisabledLearnMoreButtonLauncher helper,
            DeviceAdminStringProvider deviceAdminStringProvider) {
        mHelper = requireNonNull(helper);
        mDeviceAdminStringProvider = requireNonNull(deviceAdminStringProvider);
    }

    @Override
    public void updateEnforcedAdmin(EnforcedAdmin admin, int adminUserId) {
        mEnforcementAdminUserId = adminUserId;
        mEnforcedAdmin = requireNonNull(admin);
    }

    @Override
    public void setupLearnMoreButton(Activity activity, Builder builder) {
        mHelper.setupLearnMoreButtonToShowAdminPolicies(
                activity,
                builder,
                mEnforcementAdminUserId,
                mEnforcedAdmin);
    }

    @Override
    public String getAdminSupportTitle(@Nullable String restriction) {
        return mDeviceAdminStringProvider.getDisabledByPolicyTitleForFinancedDevice();
    }

    @Override
    public CharSequence getAdminSupportContentString(Context context, CharSequence supportMessage) {
        return supportMessage;
    }
}
Loading