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

Commit 35216e02 authored by Kholoud Mohamed's avatar Kholoud Mohamed Committed by Android (Google) Code Review
Browse files

Merge "Allow updating enterprise strings in the framework"

parents c1149937 9b24fdfb
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -16,9 +16,13 @@
package android.accounts;


import static android.app.admin.DevicePolicyResources.Strings.Core.CANT_ADD_ACCOUNT_MESSAGE;

import android.app.Activity;
import android.app.admin.DevicePolicyManager;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.android.internal.R;

@@ -33,6 +37,12 @@ public class CantAddAccountActivity extends Activity {
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.app_not_authorized);

        TextView view = findViewById(R.id.description);
        String text = getSystemService(DevicePolicyManager.class).getString(
                CANT_ADD_ACCOUNT_MESSAGE,
                () -> getString(R.string.error_message_change_not_allowed));
        view.setText(text);
    }

    public void onCancelButtonClicked(View view) {
+10 −0
Original line number Diff line number Diff line
@@ -15,7 +15,10 @@
 */
package android.accounts;

import static android.app.admin.DevicePolicyResources.Strings.Core.CANT_ADD_ACCOUNT_MESSAGE;

import android.app.Activity;
import android.app.admin.DevicePolicyManager;
import android.content.Intent;
import android.os.Bundle;
import android.os.Parcelable;
@@ -199,7 +202,14 @@ public class ChooseTypeAndAccountActivity extends Activity

        if (mPossiblyVisibleAccounts.isEmpty() && mDisallowAddAccounts) {
            requestWindowFeature(Window.FEATURE_NO_TITLE);

            setContentView(R.layout.app_not_authorized);
            TextView view = findViewById(R.id.description);
            String text = getSystemService(DevicePolicyManager.class).getString(
                    CANT_ADD_ACCOUNT_MESSAGE,
                    () -> getString(R.string.error_message_change_not_allowed));
            view.setText(text);

            mDontShowPicker = true;
        }

+19 −3
Original line number Diff line number Diff line
@@ -15,6 +15,9 @@
 */
package android.content.pm;

import static android.app.admin.DevicePolicyResources.Strings.Core.SWITCH_TO_PERSONAL_LABEL;
import static android.app.admin.DevicePolicyResources.Strings.Core.SWITCH_TO_WORK_LABEL;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.RequiresPermission;
@@ -22,6 +25,7 @@ import android.annotation.SystemApi;
import android.annotation.TestApi;
import android.app.Activity;
import android.app.AppOpsManager.Mode;
import android.app.admin.DevicePolicyManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
@@ -241,12 +245,24 @@ public class CrossProfileApps {
    public @NonNull CharSequence getProfileSwitchingLabel(@NonNull UserHandle userHandle) {
        verifyCanAccessUser(userHandle);

        final int stringRes = mUserManager.isManagedProfile(userHandle.getIdentifier())
                ? R.string.managed_profile_label
                : R.string.user_owner_label;
        final boolean isManagedProfile = mUserManager.isManagedProfile(userHandle.getIdentifier());
        final DevicePolicyManager dpm = mContext.getSystemService(DevicePolicyManager.class);
        return dpm.getString(
                getUpdatableProfileSwitchingLabelId(isManagedProfile),
                () -> getDefaultProfileSwitchingLabel(isManagedProfile));
    }

    private String getUpdatableProfileSwitchingLabelId(boolean isManagedProfile) {
        return isManagedProfile ? SWITCH_TO_WORK_LABEL : SWITCH_TO_PERSONAL_LABEL;
    }

    private String getDefaultProfileSwitchingLabel(boolean isManagedProfile) {
        final int stringRes = isManagedProfile
                ? R.string.managed_profile_label : R.string.user_owner_label;
        return mResources.getString(stringRes);
    }


    /**
     * Return a drawable that calling app can show to user for the semantic of profile switching --
     * launching its own activity in specified user profile. For example, it may return a briefcase
+15 −0
Original line number Diff line number Diff line
@@ -16,6 +16,9 @@

package android.os;

import static android.app.admin.DevicePolicyResources.Strings.Core.WORK_PROFILE_BADGED_LABEL;
import static android.app.admin.DevicePolicyResources.Strings.UNDEFINED;

import android.Manifest;
import android.accounts.AccountManager;
import android.annotation.ColorInt;
@@ -4660,6 +4663,18 @@ public class UserManager {
        if (!hasBadge(userId)) {
            return label;
        }
        DevicePolicyManager dpm = mContext.getSystemService(DevicePolicyManager.class);
        return dpm.getString(
                getUpdatableUserBadgedLabelId(userId),
                () -> getDefaultUserBadgedLabel(label, userId),
                /* formatArgs= */ label);
    }

    private String getUpdatableUserBadgedLabelId(int userId) {
        return isManagedProfile(userId) ? WORK_PROFILE_BADGED_LABEL : UNDEFINED;
    }

    private String getDefaultUserBadgedLabel(CharSequence label, int userId) {
        try {
            final int resourceId = mService.getUserBadgeLabelResId(userId);
            return Resources.getSystem().getString(resourceId, label);
+20 −7
Original line number Diff line number Diff line
@@ -466,9 +466,22 @@ public abstract class AbstractMultiProfilePagerAdapter extends PagerAdapter {
        showEmptyState(activeListAdapter, iconRes, titleRes, subtitleRes, /* buttonOnClick */ null);
    }

    protected void showEmptyState(ResolverListAdapter activeListAdapter,
            @DrawableRes int iconRes, String title, String subtitle) {
        showEmptyState(activeListAdapter, iconRes, title, subtitle, /* buttonOnClick */ null);
    }

    protected void showEmptyState(ResolverListAdapter activeListAdapter,
            @DrawableRes int iconRes, @StringRes int titleRes, @StringRes int subtitleRes,
            View.OnClickListener buttonOnClick) {
        String title = titleRes == 0 ? null : mContext.getString(titleRes);
        String subtitle = subtitleRes == 0 ? null : mContext.getString(subtitleRes);
        showEmptyState(activeListAdapter, iconRes, title, subtitle, buttonOnClick);
    }

    protected void showEmptyState(ResolverListAdapter activeListAdapter,
            @DrawableRes int iconRes, String title, String subtitle,
            View.OnClickListener buttonOnClick) {
        ProfileDescriptor descriptor = getItem(
                userHandleToPageIndex(activeListAdapter.getUserHandle()));
        descriptor.rootView.findViewById(R.id.resolver_list).setVisibility(View.GONE);
@@ -479,15 +492,15 @@ public abstract class AbstractMultiProfilePagerAdapter extends PagerAdapter {
        View container = emptyStateView.findViewById(R.id.resolver_empty_state_container);
        setupContainerPadding(container);

        TextView title = emptyStateView.findViewById(R.id.resolver_empty_state_title);
        title.setText(titleRes);
        TextView titleView = emptyStateView.findViewById(R.id.resolver_empty_state_title);
        titleView.setText(title);

        TextView subtitle = emptyStateView.findViewById(R.id.resolver_empty_state_subtitle);
        if (subtitleRes != 0) {
            subtitle.setVisibility(View.VISIBLE);
            subtitle.setText(subtitleRes);
        TextView subtitleView = emptyStateView.findViewById(R.id.resolver_empty_state_subtitle);
        if (subtitle != null) {
            subtitleView.setVisibility(View.VISIBLE);
            subtitleView.setText(subtitle);
        } else {
            subtitle.setVisibility(View.GONE);
            subtitleView.setVisibility(View.GONE);
        }

        Button button = emptyStateView.findViewById(R.id.resolver_empty_state_button);
Loading