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

Commit 15931742 authored by phweiss's avatar phweiss
Browse files

Specify disallowed action in AdminSupportDetailsDialog

The title of an AdminSupportDetailsDialog "Action not allowed" is
replaced by specialized strings such as "Screenshot not allowed" if
the action is specified by the extra DevicePolicyManager.EXTRA_RESTRICTION
in the calling intent.

This is done because these intents can be created by
third-party apps via the new public API
DevicePolicyManager.createAdminSupportIntent, and the disallowed action
might not be obvious in context of the third party app.

Bug: 31215663
Test: CtsVerifier in separate CL
Change-Id: I0c9e360cea34bec8eda29d86c5bf55d8c38c47ec
parent e11cb90e
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -30,7 +30,7 @@
                android:src="@drawable/ic_info"
                android:scaleType="fitCenter"
                android:contentDescription="@null" />
        <TextView
        <TextView android:id="@+id/admin_support_dialog_title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingStart="@dimen/admin_details_dialog_padding"
+10 −1
Original line number Diff line number Diff line
@@ -7489,9 +7489,18 @@
    <!-- Summary of device info page [CHAR LIMIT=NONE] -->
    <string name="about_summary">Android <xliff:g id="version" example="6.0">%1$s</xliff:g></string>
    <!-- TODO: Update these strings with the finalized ones. -->
    <!-- Title for dialog displayed when user clicks on a setting locked by an admin [CHAR LIMIT=30] -->
    <string name="disabled_by_policy_title">Action not allowed</string>
    <!-- Title for dialog displayed to tell user that changing volume was disallowed by an admin [CHAR LIMIT=50] -->
    <string name="disabled_by_policy_title_adjust_volume">Can\'t change volume</string>
    <!-- Title for dialog displayed to tell user that outgoing calls were disabled by an admin [CHAR LIMIT=50] -->
    <string name="disabled_by_policy_title_outgoing_calls">Calling not allowed</string>
    <!-- Title for dialog displayed to tell user that sending SMS were disabled by an admin [CHAR LIMIT=50] -->
    <string name="disabled_by_policy_title_sms">SMS not allowed</string>
    <!-- Title for dialog displayed to tell user that the camera was disabled by an admin [CHAR LIMIT=50] -->
    <string name="disabled_by_policy_title_camera">Camera not allowed</string>
    <!-- Title for dialog displayed to tell user that screenshots are disabled by an admin [CHAR LIMIT=50] -->
    <string name="disabled_by_policy_title_screen_capture">Screenshot not allowed</string>
    <!-- Shown when the user tries to change a settings locked by an admin [CHAR LIMIT=200] -->
    <string name="default_admin_support_msg">This action is disabled. Contact your organization\'s administrator to learn more.</string>
    <!-- Shown in dialog to allow user to see more information about the device admin [CHAR LIMIT=30] -->
+51 −4
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import android.os.Bundle;
import android.os.Process;
import android.os.RemoteException;
import android.os.UserHandle;
import android.os.UserManager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
@@ -39,6 +40,8 @@ import android.widget.TextView;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;

import java.util.Objects;

public class ShowAdminSupportDetailsDialog extends Activity
        implements DialogInterface.OnDismissListener {

@@ -46,17 +49,20 @@ public class ShowAdminSupportDetailsDialog extends Activity

    private EnforcedAdmin mEnforcedAdmin;
    private View mDialogView;
    private String mRestriction = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mEnforcedAdmin = getAdminDetailsFromIntent(getIntent());
        mRestriction = getRestrictionFromIntent(getIntent());

        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        mDialogView = LayoutInflater.from(builder.getContext()).inflate(
                R.layout.admin_support_details_dialog, null);
        initializeDialogViews(mDialogView, mEnforcedAdmin.component, mEnforcedAdmin.userId);
        initializeDialogViews(mDialogView, mEnforcedAdmin.component, mEnforcedAdmin.userId,
                mRestriction);
        builder.setOnDismissListener(this)
                .setPositiveButton(R.string.okay, null)
                .setView(mDialogView)
@@ -67,9 +73,12 @@ public class ShowAdminSupportDetailsDialog extends Activity
    public void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        EnforcedAdmin admin = getAdminDetailsFromIntent(intent);
        if (!mEnforcedAdmin.equals(admin)) {
        String restriction = getRestrictionFromIntent(intent);
        if (!mEnforcedAdmin.equals(admin) || !Objects.equals(mRestriction, restriction)) {
            mEnforcedAdmin = admin;
            initializeDialogViews(mDialogView, mEnforcedAdmin.component, mEnforcedAdmin.userId);
            mRestriction = restriction;
            initializeDialogViews(mDialogView, mEnforcedAdmin.component, mEnforcedAdmin.userId,
                    mRestriction);
        }
    }

@@ -83,7 +92,13 @@ public class ShowAdminSupportDetailsDialog extends Activity
        return admin;
    }

    private void initializeDialogViews(View root, ComponentName admin, int userId) {
    private String getRestrictionFromIntent(Intent intent) {
        if (intent == null) return null;
        return intent.getStringExtra(DevicePolicyManager.EXTRA_RESTRICTION);
    }

    private void initializeDialogViews(View root, ComponentName admin, int userId,
                                               String restriction) {
        if (admin != null) {
            if (!RestrictedLockUtils.isAdminInCurrentUserOrProfile(this, admin)
                    || !RestrictedLockUtils.isCurrentUserOrProfile(this, userId)) {
@@ -106,9 +121,41 @@ public class ShowAdminSupportDetailsDialog extends Activity
            }
        }

        setAdminSupportTitle(root, restriction);
        setAdminSupportDetails(this, root, new EnforcedAdmin(admin, userId), true);
    }

    private void setAdminSupportTitle(View root, String restriction) {
        final TextView titleView = (TextView) root.findViewById(R.id.admin_support_dialog_title);
        if (titleView == null) {
            return;
        }
        if (restriction == null) {
            titleView.setText(R.string.disabled_by_policy_title);
            return;
        }
        switch(restriction) {
            case UserManager.DISALLOW_ADJUST_VOLUME:
                titleView.setText(R.string.disabled_by_policy_title_adjust_volume);
                break;
            case UserManager.DISALLOW_OUTGOING_CALLS:
                titleView.setText(R.string.disabled_by_policy_title_outgoing_calls);
                break;
            case UserManager.DISALLOW_SMS:
                titleView.setText(R.string.disabled_by_policy_title_sms);
                break;
            case DevicePolicyManager.POLICY_DISABLE_CAMERA:
                titleView.setText(R.string.disabled_by_policy_title_camera);
                break;
            case DevicePolicyManager.POLICY_DISABLE_SCREEN_CAPTURE:
                titleView.setText(R.string.disabled_by_policy_title_screen_capture);
                break;
            default:
                // Use general text if no specialized title applies
                titleView.setText(R.string.disabled_by_policy_title);
        }
    }

    public static void setAdminSupportDetails(final Activity activity, View root,
            final EnforcedAdmin enforcedAdmin, final boolean finishActivity) {
        if (enforcedAdmin == null) {