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

Commit ccd4fa8e authored by Bartosz Fabianowski's avatar Bartosz Fabianowski
Browse files

Add Device Owner disclosure to Add Accounts dialog

This CL adds a footer to the Add Accounts dialog that tells the user
when the device is managed by a Device Owner app.

Bug: 32692748
Test: make RunSettingsRoboTests

Change-Id: I0dd161eb0bbbc87c04692d4fa6547bd41dab05e0
parent 5782b390
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -8034,6 +8034,14 @@
    <string name="enterprise_privacy_always_on_vpn_work">Always-on VPN turned on in your work profile</string>
    <!-- Label explaining that a global HTTP proxy was set by the admin. [CHAR LIMIT=NONE] -->
    <string name="enterprise_privacy_global_http_proxy">Global HTTP proxy set</string>
    <!-- Message indicating that the device is enterprise-managed by a Device Owner [CHAR LIMIT=NONE] -->
    <string name="do_disclosure_generic">This device is managed.</string>
    <!-- Message indicating that the device is enterprise-managed by a Device Owner [CHAR LIMIT=NONE] -->
    <string name="do_disclosure_with_name">This device is managed by <xliff:g id="organization_name" example="Foo, Inc.">%s</xliff:g>.</string>
    <!-- Message indicating that the device is enterprise-managed: Space that separates the main text and the "learn more" link that follows it. [CHAR LIMIT=NONE] -->
    <string name="do_disclosure_learn_more_separator">" "</string>
    <!-- Message indicating that the device is enterprise-managed: Link to learn more about what a Device Owner app can do [CHAR LIMIT=NONE] -->
    <string name="do_disclosure_learn_more">Learn more</string>
    <!-- Preference label for the Photos & Videos storage section. [CHAR LIMIT=50] -->
    <string name="storage_photos_videos">Photos &amp; Videos</string>
+27 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import static android.content.Intent.EXTRA_USER;

import android.accounts.AccountManager;
import android.accounts.AuthenticatorDescription;
import android.app.Activity;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
@@ -41,6 +42,10 @@ import com.android.internal.util.CharSequences;
import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.Utils;
import com.android.settings.enterprise.EnterprisePrivacyFeatureProvider;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.widget.FooterPreference;
import com.android.settings.widget.FooterPreferenceMixin;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;

@@ -61,6 +66,10 @@ import java.util.Map;
public class ChooseAccountActivity extends SettingsPreferenceFragment {

    private static final String TAG = "ChooseAccountActivity";

    private EnterprisePrivacyFeatureProvider mFeatureProvider;
    private FooterPreference mEnterpriseDisclosurePreference = null;

    private String[] mAuthorities;
    private PreferenceGroup mAddAccountGroup;
    private final ArrayList<ProviderEntry> mProviderList = new ArrayList<ProviderEntry>();
@@ -101,6 +110,10 @@ public class ChooseAccountActivity extends SettingsPreferenceFragment {
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);

        final Activity activity = getActivity();
        mFeatureProvider = FeatureFactory.getFactory(activity)
                .getEnterprisePrivacyFeatureProvider(activity);

        addPreferencesFromResource(R.xml.add_account_settings);
        mAuthorities = getIntent().getStringArrayExtra(
                AccountPreferenceBase.AUTHORITIES_FILTER_KEY);
@@ -187,6 +200,7 @@ public class ChooseAccountActivity extends SettingsPreferenceFragment {
                p.checkAccountManagementAndSetDisabled(mUserHandle.getIdentifier());
                mAddAccountGroup.addPreference(p);
            }
            addEnterpriseDisclosure();
        } else {
            if (Log.isLoggable(TAG, Log.VERBOSE)) {
                final StringBuilder auths = new StringBuilder();
@@ -201,6 +215,19 @@ public class ChooseAccountActivity extends SettingsPreferenceFragment {
        }
    }

    private void addEnterpriseDisclosure() {
        final CharSequence disclosure = mFeatureProvider.getDeviceOwnerDisclosure(getActivity());
        if (disclosure == null) {
            return;
        }
        if (mEnterpriseDisclosurePreference == null) {
            mEnterpriseDisclosurePreference = mFooterPreferenceMixin.createFooterPreference();
            mEnterpriseDisclosurePreference.setSelectable(false);
        }
        mEnterpriseDisclosurePreference.setTitle(disclosure);
        mAddAccountGroup.addPreference(mEnterpriseDisclosurePreference);
    }

    public ArrayList<String> getAuthoritiesForAccountType(String type) {
        if (mAccountTypeToAuthorities == null) {
            mAccountTypeToAuthorities = Maps.newHashMap();
+7 −0
Original line number Diff line number Diff line
@@ -33,6 +33,13 @@ public interface DevicePolicyManagerWrapper {
     */
    ComponentName getDeviceOwnerComponentOnAnyUser();

    /**
     * Calls {@code DevicePolicyManager.getDeviceOwnerNameOnAnyUser()}.
     *
     * @see android.app.admin.DevicePolicyManager#getDeviceOwnerNameOnAnyUser
     */
    public CharSequence getDeviceOwnerOrganizationName();

    /**
     * Calls {@code DevicePolicyManager.getPermissionGrantState()}.
     *
+5 −0
Original line number Diff line number Diff line
@@ -32,6 +32,11 @@ public class DevicePolicyManagerWrapperImpl implements DevicePolicyManagerWrappe
        return mDpm.getDeviceOwnerComponentOnAnyUser();
    }

    @Override
    public CharSequence getDeviceOwnerOrganizationName() {
        return mDpm.getDeviceOwnerOrganizationName();
    }

    @Override
    public int getPermissionGrantState(@Nullable ComponentName admin, String packageName,
            String permission) {
+11 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.settings.enterprise;

import android.content.Context;

import java.util.Date;

public interface EnterprisePrivacyFeatureProvider {
@@ -31,6 +33,15 @@ public interface EnterprisePrivacyFeatureProvider {
     */
    boolean isInCompMode();

    /**
     * Returns a message informing the user that the device is managed by a Device Owner app. The
     * message includes a Learn More link that takes the user to the enterprise privacy section of
     * Settings. If the device is not managed by a Device Owner app, returns {@code null}.
     *
     * @param context The context in which to show the enterprise privacy section of Settings
     */
    CharSequence getDeviceOwnerDisclosure(Context context);

    /**
     * Returns the time at which the Device Owner last retrieved security logs, or {@code null} if
     * logs were never retrieved by the Device Owner on this device.
Loading