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

Commit ceab8d8d authored by Vitor Carvalho's avatar Vitor Carvalho
Browse files

Replace usage of DPM supervision methods in SecurityControllerImpl with calls...

Replace usage of DPM supervision methods in SecurityControllerImpl with calls to SupervisionManager.

Bug: 382038943
Flag: android.app.supervision.flags.deprecate_dpm_supervision_apis
Test: atest SecurityControllerTest QSSecurityFooterTest
Change-Id: I4f068ae2b7cbc7d0f8d4546654dd43bb82f55f5b
parent b8e37841
Loading
Loading
Loading
Loading
+46 −2
Original line number Diff line number Diff line
@@ -40,6 +40,8 @@ import android.graphics.drawable.Drawable;
import android.graphics.drawable.VectorDrawable;
import android.os.Handler;
import android.os.Looper;
import android.platform.test.annotations.DisableFlags;
import android.platform.test.annotations.EnableFlags;
import android.provider.DeviceConfig;
import android.provider.Settings;
import android.testing.TestableLooper;
@@ -659,6 +661,7 @@ public class QSSecurityFooterTest extends SysuiTestCase {
    }

    @Test
    @DisableFlags(android.app.supervision.flags.Flags.FLAG_DEPRECATE_DPM_SUPERVISION_APIS)
    public void testParentalControls() {
        // Make sure the security footer is visible, so that the images are updated.
        when(mSecurityController.isProfileOwnerOfOrganizationOwnedDevice()).thenReturn(true);
@@ -673,7 +676,6 @@ public class QSSecurityFooterTest extends SysuiTestCase {

        Drawable testDrawable = new VectorDrawable();
        when(mSecurityController.getIcon(any())).thenReturn(testDrawable);
        assertNotNull(mSecurityController.getIcon(null));

        buttonConfig = getButtonConfig();
        assertNotNull(buttonConfig);
@@ -689,13 +691,55 @@ public class QSSecurityFooterTest extends SysuiTestCase {
    }

    @Test
    @EnableFlags(android.app.supervision.flags.Flags.FLAG_DEPRECATE_DPM_SUPERVISION_APIS)
    public void testParentalControls_newSupervisionApis() {
        // Make sure the security footer is visible, so that the images are updated.
        when(mSecurityController.isProfileOwnerOfOrganizationOwnedDevice()).thenReturn(true);
        when(mSecurityController.isParentalControlsEnabled()).thenReturn(true);

        // We use the default icon when there is no admin icon.
        when(mSecurityController.getIcon()).thenReturn(null);
        SecurityButtonConfig buttonConfig = getButtonConfig();
        assertEquals(mContext.getString(R.string.quick_settings_disclosure_parental_controls),
                buttonConfig.getText());
        assertIsDefaultIcon(buttonConfig.getIcon());

        Drawable testDrawable = new VectorDrawable();
        when(mSecurityController.getIcon()).thenReturn(testDrawable);

        buttonConfig = getButtonConfig();
        assertNotNull(buttonConfig);
        assertEquals(mContext.getString(R.string.quick_settings_disclosure_parental_controls),
                buttonConfig.getText());
        assertIsIconDrawable(buttonConfig.getIcon(), testDrawable);

        // Ensure the primary icon is back to default after parental controls are gone
        when(mSecurityController.isParentalControlsEnabled()).thenReturn(false);
        buttonConfig = getButtonConfig();
        assertNotNull(buttonConfig);
        assertIsDefaultIcon(buttonConfig.getIcon());
    }

    @Test
    @DisableFlags(android.app.supervision.flags.Flags.FLAG_DEPRECATE_DPM_SUPERVISION_APIS)
    public void testParentalControlsDialog() {
        when(mSecurityController.isParentalControlsEnabled()).thenReturn(true);
        when(mSecurityController.getLabel(any())).thenReturn(PARENTAL_CONTROLS_LABEL);

        View view = mFooterUtils.createDialogView(getContext());
        TextView textView = (TextView) view.findViewById(R.id.parental_controls_title);
        assertEquals(PARENTAL_CONTROLS_LABEL, textView.getText());
        assertEquals(PARENTAL_CONTROLS_LABEL, textView.getText().toString());
    }

    @Test
    @EnableFlags(android.app.supervision.flags.Flags.FLAG_DEPRECATE_DPM_SUPERVISION_APIS)
    public void testParentalControlsDialog_newSupervisionApis() {
        when(mSecurityController.isParentalControlsEnabled()).thenReturn(true);
        when(mSecurityController.getLabel()).thenReturn(PARENTAL_CONTROLS_LABEL);

        View view = mFooterUtils.createDialogView(getContext());
        TextView textView = (TextView) view.findViewById(R.id.parental_controls_title);
        assertEquals(PARENTAL_CONTROLS_LABEL, textView.getText().toString());
    }

    @Test
+11 −0
Original line number Diff line number Diff line

<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="24dp"
    android:height="24dp"
    android:viewportWidth="960"
    android:viewportHeight="960"
    android:tint="?attr/colorControlNormal">
  <path
      android:fillColor="@android:color/white"
      android:pathData="M390,920Q339,920 299.5,889.5Q260,859 246,811Q240,788 221,774Q202,760 178,760Q162,760 148,766.5Q134,773 124,785L63,734Q84,708 114.5,694Q145,680 178,680Q229,680 269,710Q309,740 323,789Q329,812 348,826Q367,840 390,840Q409,840 424,830Q439,820 450,805L451,803L175,422Q167,411 163.5,399Q160,387 160,375Q160,359 166,344.5Q172,330 184,318L444,63Q455,52 470,46Q485,40 500,40Q515,40 530,46Q545,52 556,63L816,318Q828,330 834,344.5Q840,359 840,375Q840,387 836.5,399Q833,411 825,422L500,872Q482,897 452,908.5Q422,920 390,920ZM500,735L760,375Q760,375 760,375Q760,375 760,375L500,120Q500,120 500,120Q500,120 500,120L241,376Q241,376 241,376Q241,376 241,376L500,735ZM501,427L501,427Q501,427 501,427Q501,427 501,427L501,427Q501,427 501,427Q501,427 501,427L501,427Q501,427 501,427Q501,427 501,427Z"/>
</vector>
+3 −0
Original line number Diff line number Diff line
@@ -1930,6 +1930,9 @@
    <!-- Name of the airplane status bar icon. -->
    <string name="status_bar_airplane">Airplane mode</string>

    <!-- Name of the supervision status bar icon. -->
    <string name="status_bar_supervision">Parental controls</string>

    <!-- Description for adding  a quick settings tile -->

    <!-- Name of a quick settings tile controlled by broadcast -->
+8 −0
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ import android.app.ambientcontext.AmbientContextManager;
import android.app.job.JobScheduler;
import android.app.role.RoleManager;
import android.app.smartspace.SmartspaceManager;
import android.app.supervision.SupervisionManager;
import android.app.trust.TrustManager;
import android.app.usage.UsageStatsManager;
import android.appwidget.AppWidgetManager;
@@ -836,4 +837,11 @@ public class FrameworkServicesModule {
    static ViewCapture provideViewCapture(Context context) {
        return ViewCaptureFactory.getInstance(context);
    }

    @Provides
    @Singleton
    @Nullable
    static SupervisionManager provideSupervisionManager(Context context) {
        return (SupervisionManager) context.getSystemService(Context.SUPERVISION_SERVICE);
    }
}
+13 −3
Original line number Diff line number Diff line
@@ -90,6 +90,7 @@ import com.android.systemui.settings.UserTracker;
import com.android.systemui.shade.ShadeDisplayAware;
import com.android.systemui.statusbar.phone.SystemUIDialog;
import com.android.systemui.statusbar.policy.SecurityController;
import com.android.systemui.supervision.shared.DeprecateDpmSupervisionApis;

import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Supplier;
@@ -585,8 +586,17 @@ public class QSSecurityFooterUtils implements DialogInterface.OnClickListener {
        View dialogView = LayoutInflater.from(quickSettingsContext)
                .inflate(R.layout.quick_settings_footer_dialog_parental_controls, null, false);

        Drawable icon;
        CharSequence label;
        if (DeprecateDpmSupervisionApis.isEnabled()) {
            icon = mSecurityController.getIcon();
            label = mSecurityController.getLabel();
        } else {
            DeviceAdminInfo info = mSecurityController.getDeviceAdminInfo();
        Drawable icon = mSecurityController.getIcon(info);
            icon = mSecurityController.getIcon(info);
            label = mSecurityController.getLabel(info);
        }

        if (icon != null) {
            ImageView imageView = (ImageView) dialogView.findViewById(R.id.parental_controls_icon);
            imageView.setImageDrawable(icon);
@@ -594,7 +604,7 @@ public class QSSecurityFooterUtils implements DialogInterface.OnClickListener {

        TextView parentalControlsTitle =
                (TextView) dialogView.findViewById(R.id.parental_controls_title);
        parentalControlsTitle.setText(mSecurityController.getLabel(info));
        parentalControlsTitle.setText(label);

        return dialogView;
    }
Loading