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

Commit e526cf20 authored by Kenny Guy's avatar Kenny Guy Committed by Android (Google) Code Review
Browse files

Merge "Add support messages to device admin pages."

parents 3f48575e 7a355596
Loading
Loading
Loading
Loading
+6 −8
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@
            android:orientation="horizontal"
            android:gravity="center_vertical"
            android:paddingBottom="@dimen/admin_details_dialog_padding">
        <ImageView
        <ImageView android:id="@+id/admin_support_icon"
                android:layout_width="@dimen/admin_details_dialog_icon_size"
                android:layout_height="@dimen/admin_details_dialog_icon_size"
                android:src="@drawable/ic_settings_lock_outline"
@@ -46,21 +46,19 @@
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">
            <TextView android:id="@+id/disabled_by_admin_msg"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:textAppearance="@android:style/TextAppearance.Material.Subhead"
                    android:textColor="?android:attr/textColorSecondary" />
            <TextView android:id="@+id/admin_support_msg"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:textAppearance="@android:style/TextAppearance.Material.Subhead"
                    android:text="@string/default_admin_support_msg"
                    android:maxLength="200"
                    android:autoLink="email|phone"
                    android:textColor="?android:attr/textColorSecondary" />
            <TextView android:id="@+id/admins_policies_list"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:paddingTop="@dimen/admin_details_dialog_link_padding_top"
                    android:text="@string/list_of_administrators"
                    android:text="@string/admin_support_more_info"
                    android:textAppearance="@android:style/TextAppearance.Material.Subhead"
                    android:textColor="?android:attr/colorAccent"
                    android:clickable="true"
+9 −0
Original line number Diff line number Diff line
@@ -100,8 +100,10 @@
                <TextView android:id="@+id/admin_warning"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:textAppearance="?android:attr/textAppearanceMedium"
                    android:layout_weight="1"
                    android:padding="10dip" />

                <LinearLayout android:id="@+id/admin_policies"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
@@ -109,6 +111,13 @@
                    android:orientation="vertical"
                    android:paddingStart="16dip"
                    android:paddingEnd="12dip" />

                <TextView android:id="@+id/admin_support_message"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:textAppearance="?android:attr/textAppearanceMedium"
                    android:autoLink="email|phone"
                    android:padding="10dip" />
            </LinearLayout>

        </LinearLayout>
+11 −5
Original line number Diff line number Diff line
@@ -4435,7 +4435,6 @@
    <!-- Message when there are no available device admins to display -->
    <string name="no_device_admins">No available device administrators</string>
    <!-- Message displayed when the device admin can only be disabled by deleting the work profile [CHAR_LIMIT=120] -->
    <string name="managed_profile_device_admin_info">To stop <xliff:g id="app_name">%1$s</xliff:g> from accessing your work profile, remove the profile under Settings &gt; Accounts</string>
    <!-- Title for personal device admins on the list [CHAR_LIMIT=25] -->
    <string name="personal_device_admin_title">Personal</string>
    <!-- Title for managed device admins on the list [CHAR_LIMIT=25] -->
@@ -6716,11 +6715,18 @@
    <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">Disabled by policy</string>
    <string name="disabled_by_admin_msg">Disabled by your <xliff:g id="organisation_name" example="organisation">%s</xliff:g>\'s administrator.</string>
    <string name="default_organisation_name">organisation</string>
    <string name="default_admin_support_msg">Contact them to learn more.</string>
    <string name="list_of_administrators">List of administrators</string>
    <!-- Shown when the user tries to change a settings locked by an admin [CHAR LIMIT=200] -->
    <string name="default_admin_support_msg">Disabled by your organisation\'s administrator.\nContact them to learn more.</string>
    <!-- Shown in dialog to allow user to see more information about the device admin [CHAR LIMIT=30] -->
    <string name="admin_support_more_info">More details</string>
    <!-- Shown in admin details page to warn user about policies the admin can set in a work profile. [CHAR LIMIT=NONE] -->
    <string name="admin_profile_owner_message">Your administrator has the ability to monitor and manage settings, corporate access, apps, permissions, and data associated with the profile, including network activity and your device\'s location information.</string>
    <!-- Shown in admin details page to warn user about policies the admin can set on a user. [CHAR LIMIT=NONE] -->
    <string name="admin_profile_owner_user_message">Your administrator has the ability to monitor and manage settings, corporate access, apps, permissions, and data associated with this user, including network activity and your device\'s location information.</string>
    <!-- Shown in admin details page to warn user about policies the admin can set on a device. [CHAR LIMIT=NONE] -->
    <string name="admin_device_owner_message">Your administrator has the ability to monitor and manage settings, corporate access, apps, permissions, and data associated with this device, including network activity and your device\'s location information.</string>

    <!-- Turn off a conditional state of the device (e.g. airplane mode, or hotspot) [CHAR LIMIT=30] -->
    <string name="condition_turn_off">Turn off</string>
+64 −5
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ResolveInfo;
import android.content.pm.UserInfo;
import android.content.res.Resources;
import android.os.Binder;
import android.os.Bundle;
@@ -42,6 +43,7 @@ import android.os.RemoteCallback;
import android.os.RemoteException;
import android.os.UserHandle;
import android.os.UserManager;
import android.text.TextUtils;
import android.text.TextUtils.TruncateAt;
import android.util.EventLog;
import android.util.Log;
@@ -55,6 +57,8 @@ import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.settings.users.UserDialogs;

import org.xmlpull.v1.XmlPullParserException;

import java.io.IOException;
@@ -86,6 +90,7 @@ public class DeviceAdminAdd extends Activity {
    ImageView mAddMsgExpander;
    boolean mAddMsgEllipsized = true;
    TextView mAdminWarning;
    TextView mSupportMessage;
    ViewGroup mAdminPolicies;
    Button mActionButton;
    Button mCancelButton;
@@ -279,6 +284,7 @@ public class DeviceAdminAdd extends Activity {

        mAdminWarning = (TextView) findViewById(R.id.admin_warning);
        mAdminPolicies = (ViewGroup) findViewById(R.id.admin_policies);
        mSupportMessage = (TextView) findViewById(R.id.admin_support_message);
        mCancelButton = (Button) findViewById(R.id.cancel_button);
        mCancelButton.setFilterTouchesWhenObscured(true);
        mCancelButton.setOnClickListener(new View.OnClickListener() {
@@ -294,6 +300,19 @@ public class DeviceAdminAdd extends Activity {
            public void onClick(View v) {
                if (mAdding) {
                    addAndFinish();
                } else if (isManagedProfile(mDeviceAdmin)
                        && mDeviceAdmin.getComponent().equals(mDPM.getProfileOwner())) {
                    final int userId = UserHandle.myUserId();
                    UserDialogs.createRemoveDialog(DeviceAdminAdd.this, userId,
                            new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    UserManager um = UserManager.get(DeviceAdminAdd.this);
                                    um.removeUser(userId);
                                    finish();
                                }
                            }
                            ).show();
                } else if (!mWaitingForRemoveMsg) {
                    try {
                        // Don't allow the admin to put a dialog up in front
@@ -451,12 +470,42 @@ public class DeviceAdminAdd extends Activity {
        }
        if (!mRefreshing && !mAddingProfileOwner
                && mDPM.isAdminActive(mDeviceAdmin.getComponent())) {
            mAdding = false;
            final boolean isProfileOwner =
                    mDeviceAdmin.getComponent().equals(mDPM.getProfileOwner());
            final boolean isManagedProfile = isManagedProfile(mDeviceAdmin);
            if (isProfileOwner && isManagedProfile) {
                // Profile owner in a managed profile, user can remove profile to disable admin.
                mAdminWarning.setText(R.string.admin_profile_owner_message);
                mActionButton.setText(R.string.remove_managed_profile_label);
            } else if (isProfileOwner || mDeviceAdmin.getComponent().equals(
                            mDPM.getDeviceOwnerComponentOnCallingUser())) {
                // Profile owner in a user or device owner, user can't disable admin.
                if (isProfileOwner) {
                    // Show profile owner in a user description.
                    mAdminWarning.setText(R.string.admin_profile_owner_user_message);
                } else {
                    // Show device owner description.
                    mAdminWarning.setText(R.string.admin_device_owner_message);
                }
                mActionButton.setText(R.string.remove_device_admin);
                mActionButton.setEnabled(false);
            } else {
                addDeviceAdminPolicies(false /* showDescription */);
                mAdminWarning.setText(getString(R.string.device_admin_status,
                    mDeviceAdmin.getActivityInfo().applicationInfo.loadLabel(getPackageManager())));
            setTitle(getText(R.string.active_device_admin_msg));
            mActionButton.setText(getText(R.string.remove_device_admin));
            mAdding = false;
                        mDeviceAdmin.getActivityInfo().applicationInfo.loadLabel(
                        getPackageManager())));
                setTitle(R.string.active_device_admin_msg);
                mActionButton.setText(R.string.remove_device_admin);
            }
            String supportMessage = mDPM.getLongSupportMessageForUser(
                    mDeviceAdmin.getComponent(), UserHandle.myUserId());
            if (!TextUtils.isEmpty(supportMessage)) {
                mSupportMessage.setText(supportMessage);
                mSupportMessage.setVisibility(View.VISIBLE);
            } else {
                mSupportMessage.setVisibility(View.GONE);
            }
        } else {
            addDeviceAdminPolicies(true /* showDescription */);
            mAdminWarning.setText(getString(R.string.device_admin_warning,
@@ -467,6 +516,7 @@ public class DeviceAdminAdd extends Activity {
                setTitle(getText(R.string.add_device_admin_msg));
            }
            mActionButton.setText(getText(R.string.add_device_admin));
            mSupportMessage.setVisibility(View.GONE);
            mAdding = true;
        }
    }
@@ -505,4 +555,13 @@ public class DeviceAdminAdd extends Activity {
            MAX_ADD_MSG_LINES_PORTRAIT : MAX_ADD_MSG_LINES_LANDSCAPE;
    }

    /**
     * @return true if adminInfo is running in a managed profile.
     */
    private boolean isManagedProfile(DeviceAdminInfo adminInfo) {
        UserManager um = UserManager.get(this);
        UserInfo info = um.getUserInfo(
                UserHandle.getUserId(adminInfo.getActivityInfo().applicationInfo.uid));
        return info != null ? info.isManagedProfile() : false;
    }
}
+50 −102
Original line number Diff line number Diff line
@@ -59,12 +59,29 @@ public class DeviceAdminSettings extends ListFragment {
    private DevicePolicyManager mDPM;
    private UserManager mUm;


    private static class DeviceAdminListItem implements Comparable<DeviceAdminListItem> {
        public DeviceAdminInfo info;

        // These aren't updated so they keep a stable sort order if user activates / de-activates
        // an admin.
        public String name;
        public boolean active;

        public int compareTo(DeviceAdminListItem other)  {
            // Sort active admins first, then by name.
            if (this.active != other.active) {
                return this.active ? -1 : 1;
            }
            return this.name.compareTo(other.name);
        }
    }
    /**
     * Internal collection of device admin info objects for all profiles associated with the current
     * user.
     */
    private final SparseArray<ArrayList<DeviceAdminInfo>>
            mAdminsByProfile = new SparseArray<ArrayList<DeviceAdminInfo>>();
    private final ArrayList<DeviceAdminListItem>
            mAdmins = new ArrayList<DeviceAdminListItem>();

    private String mDeviceOwnerPkg;
    private SparseArray<ComponentName> mProfileOwnerComponents = new SparseArray<ComponentName>();
@@ -133,7 +150,7 @@ public class DeviceAdminSettings extends ListFragment {
     * current user.
     */
    void updateList() {
        mAdminsByProfile.clear();
        mAdmins.clear();

        final List<UserHandle> profiles = mUm.getUserProfiles();
        final int profilesSize = profiles.size();
@@ -141,6 +158,7 @@ public class DeviceAdminSettings extends ListFragment {
            final int profileId = profiles.get(i).getIdentifier();
            updateAvailableAdminsForProfile(profileId);
        }
        Collections.sort(mAdmins);

        getListView().setAdapter(new PolicyListAdapter());
    }
@@ -148,25 +166,12 @@ public class DeviceAdminSettings extends ListFragment {
    @Override
    public void onListItemClick(ListView l, View v, int position, long id) {
        Object o = l.getAdapter().getItem(position);
        if (!(o instanceof DeviceAdminInfo)) {
            // race conditions may cause this
            return;
        }
        DeviceAdminInfo dpi = (DeviceAdminInfo) o;
        final UserHandle user = new UserHandle(getUserId(dpi));
        final Activity activity = getActivity();
        final int userId = getUserId(dpi);
        if (userId == UserHandle.myUserId() || !isProfileOwner(dpi)) {
            Intent intent = new Intent();
            intent.setClass(activity, DeviceAdminAdd.class);
        Intent intent = new Intent(activity, DeviceAdminAdd.class);
        intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, dpi.getComponent());
            activity.startActivityAsUser(intent, new UserHandle(userId));
        } else {
            AlertDialog.Builder builder = new AlertDialog.Builder(activity);
            builder.setMessage(getString(R.string.managed_profile_device_admin_info,
                    dpi.loadLabel(activity.getPackageManager())));
            builder.setPositiveButton(android.R.string.ok, null);
            builder.create().show();
        }
        activity.startActivityAsUser(intent, user);
    }

    static class ViewHolder {
@@ -191,55 +196,17 @@ public class DeviceAdminSettings extends ListFragment {

        @Override
        public int getCount() {
            int adminCount = 0;
            final int profileCount = mAdminsByProfile.size();
            for (int i = 0; i < profileCount; ++i) {
                adminCount += mAdminsByProfile.valueAt(i).size();
            }
            // Add 'profileCount' for title items.
            return adminCount + profileCount;
            return mAdmins.size();
        }

        /**
         * The item for the given position in the list.
         *
         * @return a String object for title items and a DeviceAdminInfo object for actual device
         *         admins.
         * @return DeviceAdminInfo object for actual device admins.
         */
        @Override
        public Object getItem(int position) {
            if (position < 0) {
                throw new ArrayIndexOutOfBoundsException();
            }
            // The position of the item in the list of admins.
            // We start from the given position and discount the length of the upper lists until we
            // get the one for the right profile
            int adminPosition = position;
            final int n = mAdminsByProfile.size();
            int i = 0;
            for (; i < n; ++i) {
                // The elements in that section including the title item (that's why adding one).
                final int listSize = mAdminsByProfile.valueAt(i).size() + 1;
                if (adminPosition < listSize) {
                    break;
                }
                adminPosition -= listSize;
            }
            if (i == n) {
                throw new ArrayIndexOutOfBoundsException();
            }
            // If countdown == 0 that means the title item
            if (adminPosition == 0) {
                Resources res = getActivity().getResources();
                if (mAdminsByProfile.keyAt(i) == UserHandle.myUserId()) {
                    return res.getString(R.string.personal_device_admin_title);
                } else {
                    return res.getString(R.string.managed_device_admin_title);
                }
            } else {
                // Subtracting one for the title.
                return mAdminsByProfile.valueAt(i).get(adminPosition - 1);
            }
            return ((DeviceAdminListItem) (mAdmins.get(position))).info;
        }

        @Override
@@ -257,16 +224,15 @@ public class DeviceAdminSettings extends ListFragment {
         */
        @Override
        public int getViewTypeCount() {
            return 2;
            return 1;
        }

        /**
         * Returns 1 for title items and 0 for anything else.
         * Returns 0 for all types.
         */
        @Override
        public int getItemViewType(int position) {
            Object o = getItem(position);
            return (o instanceof String) ? 1 : 0;
            return 0;
        }

        @Override
@@ -276,15 +242,7 @@ public class DeviceAdminSettings extends ListFragment {
        }

        private boolean isEnabled(Object o) {
            if (!(o instanceof DeviceAdminInfo)) {
                // Title item
                return false;
            }
            DeviceAdminInfo info = (DeviceAdminInfo) o;
            if (isActiveAdmin(info) && getUserId(info) == UserHandle.myUserId()
                    && (isDeviceOwner(info) || isProfileOwner(info))) {
                return false;
            }
            // Disable item if admin is being removed
            if (isRemovingAdmin(info)) {
                return false;
@@ -295,18 +253,10 @@ public class DeviceAdminSettings extends ListFragment {
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            Object o = getItem(position);
            if (o instanceof DeviceAdminInfo) {
            if (convertView == null) {
                convertView = newDeviceAdminView(parent);
            }
            bindView(convertView, (DeviceAdminInfo) o);
            } else {
                if (convertView == null) {
                    convertView = Utils.inflateCategoryHeader(mInflater, parent);
                }
                final TextView title = (TextView) convertView.findViewById(android.R.id.title);
                title.setText((String)o);
            }
            return convertView;
        }

@@ -399,10 +349,6 @@ public class DeviceAdminSettings extends ListFragment {
            enabledForProfile = Collections.emptyList();
        }
        final int n = enabledForProfile.size();
        ArrayList<DeviceAdminInfo> deviceAdmins = mAdminsByProfile.get(profileId);
        if (deviceAdmins == null) {
            deviceAdmins = new ArrayList<DeviceAdminInfo>(n);
        }
        for (int i = 0; i < n; ++i) {
            ResolveInfo resolveInfo = enabledForProfile.get(i);
            ComponentName riComponentName =
@@ -413,12 +359,14 @@ public class DeviceAdminSettings extends ListFragment {
                DeviceAdminInfo deviceAdminInfo =  createDeviceAdminInfo(resolveInfo);
                // add only visible ones (note: active admins are added regardless of visibility)
                if (deviceAdminInfo != null && deviceAdminInfo.isVisible()) {
                    deviceAdmins.add(deviceAdminInfo);
                }
                    DeviceAdminListItem item = new DeviceAdminListItem();
                    item.info = deviceAdminInfo;
                    item.name = deviceAdminInfo.loadLabel(pm).toString();
                    // Active ones already added.
                    item.active = false;
                    mAdmins.add(item);
                }
            }
        if (!deviceAdmins.isEmpty()) {
            mAdminsByProfile.put(profileId, deviceAdmins);
        }
    }

@@ -433,7 +381,6 @@ public class DeviceAdminSettings extends ListFragment {
        if (activeAdmins != null) {
            final PackageManager packageManager = getActivity().getPackageManager();
            final int n = activeAdmins.size();
            ArrayList<DeviceAdminInfo> deviceAdmins = new ArrayList<DeviceAdminInfo>(n);
            for (int i = 0; i < n; ++i) {
                ComponentName activeAdmin = activeAdmins.get(i);
                List<ResolveInfo> resolved = packageManager.queryBroadcastReceivers(
@@ -444,13 +391,14 @@ public class DeviceAdminSettings extends ListFragment {
                    for (int j = 0; j < resolvedMax; ++j) {
                        DeviceAdminInfo deviceAdminInfo = createDeviceAdminInfo(resolved.get(j));
                        if (deviceAdminInfo != null) {
                            deviceAdmins.add(deviceAdminInfo);
                        }
                            DeviceAdminListItem item = new DeviceAdminListItem();
                            item.info = deviceAdminInfo;
                            item.name = deviceAdminInfo.loadLabel(packageManager).toString();
                            item.active = true;
                            mAdmins.add(item);
                        }
                    }
                }
            if (!deviceAdmins.isEmpty()) {
                mAdminsByProfile.put(profileId, deviceAdmins);
            }
        }
    }
Loading