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

Commit 8c9047c8 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "RESTRICT AUTOMERGE Fixed and reenabled failing DevicePolicyManagerTest" into tm-dev

parents b7f5e21e 14913d1d
Loading
Loading
Loading
Loading
+16 −16
Original line number Diff line number Diff line
@@ -16,15 +16,12 @@

package com.android.server.devicepolicy;

import static android.app.admin.DevicePolicyResources.Drawables.Style;

import static java.util.Objects.requireNonNull;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.admin.DevicePolicyDrawableResource;
import android.app.admin.DevicePolicyResources;
import android.app.admin.DevicePolicyResources.Drawables;
import android.app.admin.DevicePolicyStringResource;
import android.app.admin.ParcelableResource;
import android.os.Environment;
@@ -180,6 +177,7 @@ class DeviceManagementResourcesProvider {
    @Nullable
    ParcelableResource getDrawable(
            String drawableId, String drawableStyle, String drawableSource) {
        synchronized (mLock) {
            if (mUpdatedDrawablesForSource.containsKey(drawableId)
                    && mUpdatedDrawablesForSource.get(drawableId).containsKey(drawableSource)) {
                return mUpdatedDrawablesForSource.get(drawableId).get(drawableSource);
@@ -191,6 +189,7 @@ class DeviceManagementResourcesProvider {
            if (mUpdatedDrawablesForStyle.get(drawableId).containsKey(drawableStyle)) {
                return mUpdatedDrawablesForStyle.get(drawableId).get(drawableStyle);
            }
        }
        Log.d(TAG, "No updated drawable found for drawable id " + drawableId);
        return null;
    }
@@ -249,10 +248,11 @@ class DeviceManagementResourcesProvider {

    @Nullable
    ParcelableResource getString(String stringId) {
        synchronized (mLock) {
            if (mUpdatedStrings.containsKey(stringId)) {
                return mUpdatedStrings.get(stringId);
            }

        }
        Log.d(TAG, "No updated string found for string id " + stringId);
        return null;
    }
+46 −51
Original line number Diff line number Diff line
@@ -114,6 +114,8 @@ import static android.app.admin.DevicePolicyResources.Strings.Core.LOCATION_CHAN
import static android.app.admin.DevicePolicyResources.Strings.Core.NETWORK_LOGGING_MESSAGE;
import static android.app.admin.DevicePolicyResources.Strings.Core.NETWORK_LOGGING_TITLE;
import static android.app.admin.DevicePolicyResources.Strings.Core.NOTIFICATION_WORK_PROFILE_CONTENT_DESCRIPTION;
import static android.app.admin.DevicePolicyResources.Strings.Core.PERSONAL_APP_SUSPENSION_MESSAGE;
import static android.app.admin.DevicePolicyResources.Strings.Core.PERSONAL_APP_SUSPENSION_SOON_MESSAGE;
import static android.app.admin.DevicePolicyResources.Strings.Core.PERSONAL_APP_SUSPENSION_TITLE;
import static android.app.admin.DevicePolicyResources.Strings.Core.PERSONAL_APP_SUSPENSION_TURN_ON_PROFILE;
import static android.app.admin.DevicePolicyResources.Strings.Core.PRINTING_DISABLED_NAMED_ADMIN;
@@ -172,7 +174,6 @@ import android.app.Activity;
import android.app.ActivityManager;
import android.app.ActivityManagerInternal;
import android.app.ActivityTaskManager;
import android.app.ActivityThread;
import android.app.AlarmManager;
import android.app.AppGlobals;
import android.app.AppOpsManager;
@@ -7030,14 +7031,13 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
    private String getGenericWipeReason(
            boolean calledByProfileOwnerOnOrgOwnedDevice, boolean calledOnParentInstance) {
        DevicePolicyManager dpm = mContext.getSystemService(DevicePolicyManager.class);
        return calledByProfileOwnerOnOrgOwnedDevice && !calledOnParentInstance
                ? dpm.getResources().getString(WORK_PROFILE_DELETED_ORG_OWNED_MESSAGE,
                        () -> mContext.getString(
                                R.string.device_ownership_relinquished))
                : dpm.getResources().getString(WORK_PROFILE_DELETED_GENERIC_MESSAGE,
                        () -> mContext.getString(
                                R.string.work_profile_deleted_description_dpm_wipe));
                ? getUpdatableString(
                        WORK_PROFILE_DELETED_ORG_OWNED_MESSAGE,
                        R.string.device_ownership_relinquished)
                : getUpdatableString(
                        WORK_PROFILE_DELETED_GENERIC_MESSAGE,
                        R.string.work_profile_deleted_description_dpm_wipe);
    }
    /**
@@ -7133,9 +7133,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
    }
    private String getWorkProfileDeletedTitle() {
        DevicePolicyManager dpm = mContext.getSystemService(DevicePolicyManager.class);
        return dpm.getResources().getString(WORK_PROFILE_DELETED_TITLE,
                () -> mContext.getString(R.string.work_profile_deleted));
        return getUpdatableString(WORK_PROFILE_DELETED_TITLE, R.string.work_profile_deleted);
    }
    private void clearWipeProfileNotification() {
@@ -7449,10 +7447,9 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
    }
    private String getFailedPasswordAttemptWipeMessage() {
        DevicePolicyManager dpm = mContext.getSystemService(DevicePolicyManager.class);
        return dpm.getResources().getString(WORK_PROFILE_DELETED_FAILED_PASSWORD_ATTEMPTS_MESSAGE,
                () -> mContext.getString(
                        R.string.work_profile_deleted_reason_maximum_password_failure));
        return getUpdatableString(
                WORK_PROFILE_DELETED_FAILED_PASSWORD_ATTEMPTS_MESSAGE,
               R.string.work_profile_deleted_reason_maximum_password_failure);
    }
    /**
@@ -12649,15 +12646,13 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
    }
    private String getLocationChangedTitle() {
        DevicePolicyManager dpm = mContext.getSystemService(DevicePolicyManager.class);
        return dpm.getResources().getString(LOCATION_CHANGED_TITLE,
                () -> mContext.getString(R.string.location_changed_notification_title));
        return getUpdatableString(
                LOCATION_CHANGED_TITLE, R.string.location_changed_notification_title);
    }
    private String getLocationChangedText() {
        DevicePolicyManager dpm = mContext.getSystemService(DevicePolicyManager.class);
        return dpm.getResources().getString(LOCATION_CHANGED_MESSAGE,
                () -> mContext.getString(R.string.location_changed_notification_text));
        return getUpdatableString(
                LOCATION_CHANGED_MESSAGE, R.string.location_changed_notification_text);
    }
    @Override
@@ -13256,19 +13251,13 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
                    Slogf.e(LOG_TAG, "appLabel is inexplicably null");
                    return null;
                }
                DevicePolicyManager dpm = mContext.getSystemService(DevicePolicyManager.class);
                return dpm.getResources().getString(
                return getUpdatableString(
                        PRINTING_DISABLED_NAMED_ADMIN,
                        () -> getDefaultPrintingDisabledMsg(appLabel),
                        R.string.printing_disabled_by,
                        appLabel);
            }
        }
        private String getDefaultPrintingDisabledMsg(CharSequence appLabel) {
            return ((Context) ActivityThread.currentActivityThread().getSystemUiContext())
                        .getResources().getString(R.string.printing_disabled_by, appLabel);
        }
        @Override
        protected DevicePolicyCache getDevicePolicyCache() {
            return mPolicyCache;
@@ -15875,15 +15864,13 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
    }
    private String getNetworkLoggingTitle() {
        DevicePolicyManager dpm = mContext.getSystemService(DevicePolicyManager.class);
        return dpm.getResources().getString(NETWORK_LOGGING_TITLE,
                () -> mContext.getString(R.string.network_logging_notification_title));
        return getUpdatableString(
                NETWORK_LOGGING_TITLE, R.string.network_logging_notification_title);
    }
    private String getNetworkLoggingText() {
        DevicePolicyManager dpm = mContext.getSystemService(DevicePolicyManager.class);
        return dpm.getResources().getString(NETWORK_LOGGING_MESSAGE,
                () -> mContext.getString(R.string.network_logging_notification_text));
        return getUpdatableString(
                NETWORK_LOGGING_MESSAGE, R.string.network_logging_notification_text);
    }
    private void handleCancelNetworkLoggingNotification() {
@@ -17470,35 +17457,31 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
    }
    private String getPersonalAppSuspensionButtonText() {
        DevicePolicyManager dpm = mContext.getSystemService(DevicePolicyManager.class);
        return dpm.getResources().getString(PERSONAL_APP_SUSPENSION_TURN_ON_PROFILE,
                () -> mContext.getString(R.string.personal_apps_suspended_turn_profile_on));
        return getUpdatableString(
                PERSONAL_APP_SUSPENSION_TURN_ON_PROFILE,
                R.string.personal_apps_suspended_turn_profile_on);
    }
    private String getPersonalAppSuspensionTitle() {
        DevicePolicyManager dpm = mContext.getSystemService(DevicePolicyManager.class);
        return dpm.getResources().getString(PERSONAL_APP_SUSPENSION_TITLE,
                () -> mContext.getString(R.string.personal_apps_suspension_title));
        return getUpdatableString(
                PERSONAL_APP_SUSPENSION_TITLE, R.string.personal_apps_suspension_title);
    }
    private String getPersonalAppSuspensionText() {
        DevicePolicyManager dpm = mContext.getSystemService(DevicePolicyManager.class);
        return dpm.getResources().getString(PERSONAL_APP_SUSPENSION_TITLE,
                () -> mContext.getString(R.string.personal_apps_suspension_text));
        return getUpdatableString(
                PERSONAL_APP_SUSPENSION_MESSAGE, R.string.personal_apps_suspension_text);
    }
    private String getPersonalAppSuspensionSoonText(String date, String time, int maxDays) {
        DevicePolicyManager dpm = mContext.getSystemService(DevicePolicyManager.class);
        return dpm.getResources().getString(PERSONAL_APP_SUSPENSION_TITLE,
                () -> mContext.getString(
                        R.string.personal_apps_suspension_soon_text, date, time, maxDays),
        return getUpdatableString(
                PERSONAL_APP_SUSPENSION_SOON_MESSAGE, R.string.personal_apps_suspension_soon_text,
                date, time, maxDays);
    }
    private String getWorkProfileContentDescription() {
        DevicePolicyManager dpm = mContext.getSystemService(DevicePolicyManager.class);
        return dpm.getResources().getString(NOTIFICATION_WORK_PROFILE_CONTENT_DESCRIPTION,
                () -> mContext.getString(R.string.notification_work_profile_content_description));
        return getUpdatableString(
                NOTIFICATION_WORK_PROFILE_CONTENT_DESCRIPTION,
                R.string.notification_work_profile_content_description);
    }
    @Override
@@ -18802,6 +18785,18 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
        }
    }
    private String getUpdatableString(
            String updatableStringId, int defaultStringId, Object... formatArgs) {
        ParcelableResource resource = mDeviceManagementResourcesProvider.getString(
                updatableStringId);
        if (resource == null) {
            return ParcelableResource.loadDefaultString(() ->
                    mContext.getString(defaultStringId, formatArgs));
        }
        return resource.getString(
                mContext, () -> mContext.getString(defaultStringId, formatArgs), formatArgs);
    }
    public boolean isDpcDownloaded() {
        Preconditions.checkCallAuthorization(hasCallingOrSelfPermission(
                android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS));
+5 −0
Original line number Diff line number Diff line
@@ -530,5 +530,10 @@ public class DevicePolicyManagerServiceTestable extends DevicePolicyManagerServi

            return true;
        }

        @Override
        public Context createContextAsUser(UserHandle user) {
            return context;
        }
    }
}
+6 −6
Original line number Diff line number Diff line
@@ -158,7 +158,6 @@ import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.mockito.Mockito;
import org.mockito.internal.util.collections.Sets;
@@ -187,7 +186,6 @@ import java.util.concurrent.TimeUnit;
 */
@SmallTest
@Presubmit
@Ignore("b/225415867")
public class DevicePolicyManagerTest extends DpmTestBase {

    private static final String TAG = DevicePolicyManagerTest.class.getSimpleName();
@@ -1786,10 +1784,9 @@ public class DevicePolicyManagerTest extends DpmTestBase {
        final int userId = CALLER_USER_HANDLE;
        final UserHandle user = UserHandle.of(userId);

        mContext.applicationInfo = new ApplicationInfo();
        mContext.callerPermissions.add(permission.MANAGE_USERS);
        mContext.packageName = "com.android.frameworks.servicestests";
        getServices().addPackageContext(user, mContext);
        mServiceContext.packageName = mRealTestContext.getPackageName();
        mServiceContext.applicationInfo = new ApplicationInfo();
        mServiceContext.binder.callingUid = DpmMockContext.SYSTEM_UID;
        when(mContext.resources.getColor(anyInt(), anyObject())).thenReturn(Color.WHITE);

        StringParceledListSlice oneCert = asSlice(new String[] {"1"});
@@ -6281,6 +6278,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
    @Test
    public void testGetOwnerInstalledCaCertsForDeviceOwner() throws Exception {
        mServiceContext.packageName = mRealTestContext.getPackageName();
        mServiceContext.applicationInfo = new ApplicationInfo();
        mServiceContext.binder.callingUid = DpmMockContext.SYSTEM_UID;
        mAdmin1Context.binder.callingUid = DpmMockContext.CALLER_SYSTEM_USER_UID;
        setDeviceOwner();
@@ -6291,6 +6289,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
    @Test
    public void testGetOwnerInstalledCaCertsForProfileOwner() throws Exception {
        mServiceContext.packageName = mRealTestContext.getPackageName();
        mServiceContext.applicationInfo = new ApplicationInfo();
        mServiceContext.binder.callingUid = DpmMockContext.SYSTEM_UID;
        mAdmin1Context.binder.callingUid = DpmMockContext.CALLER_UID;
        setAsProfileOwner(admin1);
@@ -6302,6 +6301,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
    @Test
    public void testGetOwnerInstalledCaCertsForDelegate() throws Exception {
        mServiceContext.packageName = mRealTestContext.getPackageName();
        mServiceContext.applicationInfo = new ApplicationInfo();
        mServiceContext.binder.callingUid = DpmMockContext.SYSTEM_UID;
        mAdmin1Context.binder.callingUid = DpmMockContext.CALLER_UID;
        setAsProfileOwner(admin1);