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

Commit 417e158c authored by Julia Reynolds's avatar Julia Reynolds Committed by Automerger Merge Worker
Browse files

Merge "Fix uiservicestests" into udc-dev am: 9dfeef8c

parents 7a4d7251 9dfeef8c
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -32,6 +32,7 @@
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.OBSERVE_ROLE_HOLDERS" />
    <uses-permission android:name="android.permission.OBSERVE_ROLE_HOLDERS" />
    <uses-permission android:name="android.permission.GET_INTENT_SENDER_INTENT"/>
    <uses-permission android:name="android.permission.GET_INTENT_SENDER_INTENT"/>
    <uses-permission android:name="android.permission.READ_DEVICE_CONFIG" />
    <uses-permission android:name="android.permission.WRITE_DEVICE_CONFIG" />
    <uses-permission android:name="android.permission.WRITE_DEVICE_CONFIG" />
    <uses-permission android:name="android.permission.ACCESS_KEYGUARD_SECURE_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_KEYGUARD_SECURE_STORAGE" />


+9 −2
Original line number Original line Diff line number Diff line
@@ -16,8 +16,10 @@ package com.android.server;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.when;


import android.content.Intent;
import android.content.pm.PackageManagerInternal;
import android.content.pm.PackageManagerInternal;
import android.net.Uri;
import android.net.Uri;
import android.os.Build;
import android.os.Build;
@@ -44,8 +46,8 @@ public class UiServiceTestCase {
    protected static final String PKG_R = "com.example.r";
    protected static final String PKG_R = "com.example.r";


    @Rule
    @Rule
    public final TestableContext mContext =
    public TestableContext mContext =
            new TestableContext(InstrumentationRegistry.getContext(), null);
            spy(new TestableContext(InstrumentationRegistry.getContext(), null));


    protected TestableContext getContext() {
    protected TestableContext getContext() {
        return mContext;
        return mContext;
@@ -81,6 +83,11 @@ public class UiServiceTestCase {
        LocalServices.addService(UriGrantsManagerInternal.class, mUgmInternal);
        LocalServices.addService(UriGrantsManagerInternal.class, mUgmInternal);
        when(mUgmInternal.checkGrantUriPermission(
        when(mUgmInternal.checkGrantUriPermission(
                anyInt(), anyString(), any(Uri.class), anyInt(), anyInt())).thenReturn(-1);
                anyInt(), anyString(), any(Uri.class), anyInt(), anyInt())).thenReturn(-1);

        Mockito.doReturn(new Intent()).when(mContext).registerReceiverAsUser(
                any(), any(), any(), any(), any());
        Mockito.doReturn(new Intent()).when(mContext).registerReceiver(any(), any());
        Mockito.doNothing().when(mContext).unregisterReceiver(any());
    }
    }


    @After
    @After
+36 −31
Original line number Original line Diff line number Diff line
@@ -130,13 +130,18 @@ public class ManagedServicesTest extends UiServiceTestCase {
    private ArrayMap<Integer, ArrayMap<Integer, String>> mExpectedPrimary;
    private ArrayMap<Integer, ArrayMap<Integer, String>> mExpectedPrimary;
    private ArrayMap<Integer, ArrayMap<Integer, String>> mExpectedSecondary;
    private ArrayMap<Integer, ArrayMap<Integer, String>> mExpectedSecondary;


    private UserHandle mUser;
    private String mPkg;

    @Before
    @Before
    public void setUp() throws Exception {
    public void setUp() throws Exception {
        MockitoAnnotations.initMocks(this);
        MockitoAnnotations.initMocks(this);


        getContext().setMockPackageManager(mPm);
        mContext.setMockPackageManager(mPm);
        getContext().addMockSystemService(Context.USER_SERVICE, mUm);
        mContext.addMockSystemService(Context.USER_SERVICE, mUm);
        getContext().addMockSystemService(DEVICE_POLICY_SERVICE, mDpm);
        mContext.addMockSystemService(DEVICE_POLICY_SERVICE, mDpm);
        mUser = mContext.getUser();
        mPkg = mContext.getPackageName();


        List<UserInfo> users = new ArrayList<>();
        List<UserInfo> users = new ArrayList<>();
        users.add(mZero);
        users.add(mZero);
@@ -861,8 +866,8 @@ public class ManagedServicesTest extends UiServiceTestCase {
        ApplicationInfo ai = new ApplicationInfo();
        ApplicationInfo ai = new ApplicationInfo();
        ai.targetSdkVersion = Build.VERSION_CODES.CUR_DEVELOPMENT;
        ai.targetSdkVersion = Build.VERSION_CODES.CUR_DEVELOPMENT;


        when(context.getPackageName()).thenReturn(mContext.getPackageName());
        when(context.getPackageName()).thenReturn(mPkg);
        when(context.getUserId()).thenReturn(mContext.getUserId());
        when(context.getUserId()).thenReturn(mUser.getIdentifier());
        when(context.getPackageManager()).thenReturn(pm);
        when(context.getPackageManager()).thenReturn(pm);
        when(pm.getApplicationInfo(anyString(), anyInt())).thenReturn(ai);
        when(pm.getApplicationInfo(anyString(), anyInt())).thenReturn(ai);


@@ -891,8 +896,8 @@ public class ManagedServicesTest extends UiServiceTestCase {
        ApplicationInfo ai = new ApplicationInfo();
        ApplicationInfo ai = new ApplicationInfo();
        ai.targetSdkVersion = Build.VERSION_CODES.CUR_DEVELOPMENT;
        ai.targetSdkVersion = Build.VERSION_CODES.CUR_DEVELOPMENT;


        when(context.getPackageName()).thenReturn(mContext.getPackageName());
        when(context.getPackageName()).thenReturn(mPkg);
        when(context.getUserId()).thenReturn(mContext.getUserId());
        when(context.getUserId()).thenReturn(mUser.getIdentifier());
        when(context.getPackageManager()).thenReturn(pm);
        when(context.getPackageManager()).thenReturn(pm);
        when(pm.getApplicationInfo(anyString(), anyInt())).thenReturn(ai);
        when(pm.getApplicationInfo(anyString(), anyInt())).thenReturn(ai);


@@ -921,8 +926,8 @@ public class ManagedServicesTest extends UiServiceTestCase {
        ApplicationInfo ai = new ApplicationInfo();
        ApplicationInfo ai = new ApplicationInfo();
        ai.targetSdkVersion = Build.VERSION_CODES.CUR_DEVELOPMENT;
        ai.targetSdkVersion = Build.VERSION_CODES.CUR_DEVELOPMENT;


        when(context.getPackageName()).thenReturn(mContext.getPackageName());
        when(context.getPackageName()).thenReturn(mPkg);
        when(context.getUserId()).thenReturn(mContext.getUserId());
        when(context.getUserId()).thenReturn(mUser.getIdentifier());
        when(context.getPackageManager()).thenReturn(pm);
        when(context.getPackageManager()).thenReturn(pm);
        when(pm.getApplicationInfo(anyString(), anyInt())).thenReturn(ai);
        when(pm.getApplicationInfo(anyString(), anyInt())).thenReturn(ai);


@@ -951,8 +956,8 @@ public class ManagedServicesTest extends UiServiceTestCase {
        ApplicationInfo ai = new ApplicationInfo();
        ApplicationInfo ai = new ApplicationInfo();
        ai.targetSdkVersion = Build.VERSION_CODES.CUR_DEVELOPMENT;
        ai.targetSdkVersion = Build.VERSION_CODES.CUR_DEVELOPMENT;


        when(context.getPackageName()).thenReturn(mContext.getPackageName());
        when(context.getPackageName()).thenReturn(mPkg);
        when(context.getUserId()).thenReturn(mContext.getUserId());
        when(context.getUserId()).thenReturn(mUser.getIdentifier());
        when(context.getPackageManager()).thenReturn(pm);
        when(context.getPackageManager()).thenReturn(pm);
        when(pm.getApplicationInfo(anyString(), anyInt())).thenReturn(ai);
        when(pm.getApplicationInfo(anyString(), anyInt())).thenReturn(ai);


@@ -981,8 +986,8 @@ public class ManagedServicesTest extends UiServiceTestCase {
        ApplicationInfo ai = new ApplicationInfo();
        ApplicationInfo ai = new ApplicationInfo();
        ai.targetSdkVersion = Build.VERSION_CODES.CUR_DEVELOPMENT;
        ai.targetSdkVersion = Build.VERSION_CODES.CUR_DEVELOPMENT;


        when(context.getPackageName()).thenReturn(mContext.getPackageName());
        when(context.getPackageName()).thenReturn(mPkg);
        when(context.getUserId()).thenReturn(mContext.getUserId());
        when(context.getUserId()).thenReturn(mUser.getIdentifier());
        when(context.getPackageManager()).thenReturn(pm);
        when(context.getPackageManager()).thenReturn(pm);
        when(pm.getApplicationInfo(anyString(), anyInt())).thenReturn(ai);
        when(pm.getApplicationInfo(anyString(), anyInt())).thenReturn(ai);


@@ -1011,8 +1016,8 @@ public class ManagedServicesTest extends UiServiceTestCase {
        ApplicationInfo ai = new ApplicationInfo();
        ApplicationInfo ai = new ApplicationInfo();
        ai.targetSdkVersion = Build.VERSION_CODES.CUR_DEVELOPMENT;
        ai.targetSdkVersion = Build.VERSION_CODES.CUR_DEVELOPMENT;


        when(context.getPackageName()).thenReturn(mContext.getPackageName());
        when(context.getPackageName()).thenReturn(mPkg);
        when(context.getUserId()).thenReturn(mContext.getUserId());
        when(context.getUserId()).thenReturn(mUser.getIdentifier());
        when(context.getPackageManager()).thenReturn(pm);
        when(context.getPackageManager()).thenReturn(pm);
        when(pm.getApplicationInfo(anyString(), anyInt())).thenReturn(ai);
        when(pm.getApplicationInfo(anyString(), anyInt())).thenReturn(ai);


@@ -1437,8 +1442,8 @@ public class ManagedServicesTest extends UiServiceTestCase {
        ApplicationInfo ai = new ApplicationInfo();
        ApplicationInfo ai = new ApplicationInfo();
        ai.targetSdkVersion = Build.VERSION_CODES.CUR_DEVELOPMENT;
        ai.targetSdkVersion = Build.VERSION_CODES.CUR_DEVELOPMENT;


        when(context.getPackageName()).thenReturn(mContext.getPackageName());
        when(context.getPackageName()).thenReturn(mPkg);
        when(context.getUserId()).thenReturn(mContext.getUserId());
        when(context.getUserId()).thenReturn(mUser.getIdentifier());
        when(context.getPackageManager()).thenReturn(pm);
        when(context.getPackageManager()).thenReturn(pm);
        when(pm.getApplicationInfo(anyString(), anyInt())).thenReturn(ai);
        when(pm.getApplicationInfo(anyString(), anyInt())).thenReturn(ai);


@@ -1464,8 +1469,8 @@ public class ManagedServicesTest extends UiServiceTestCase {
        ApplicationInfo ai = new ApplicationInfo();
        ApplicationInfo ai = new ApplicationInfo();
        ai.targetSdkVersion = Build.VERSION_CODES.CUR_DEVELOPMENT;
        ai.targetSdkVersion = Build.VERSION_CODES.CUR_DEVELOPMENT;


        when(context.getPackageName()).thenReturn(mContext.getPackageName());
        when(context.getPackageName()).thenReturn(mPkg);
        when(context.getUserId()).thenReturn(mContext.getUserId());
        when(context.getUserId()).thenReturn(mUser.getIdentifier());
        when(context.getPackageManager()).thenReturn(pm);
        when(context.getPackageManager()).thenReturn(pm);
        when(pm.getApplicationInfo(anyString(), anyInt())).thenReturn(ai);
        when(pm.getApplicationInfo(anyString(), anyInt())).thenReturn(ai);


@@ -1492,8 +1497,8 @@ public class ManagedServicesTest extends UiServiceTestCase {
        ApplicationInfo ai = new ApplicationInfo();
        ApplicationInfo ai = new ApplicationInfo();
        ai.targetSdkVersion = Build.VERSION_CODES.CUR_DEVELOPMENT;
        ai.targetSdkVersion = Build.VERSION_CODES.CUR_DEVELOPMENT;


        when(context.getPackageName()).thenReturn(mContext.getPackageName());
        when(context.getPackageName()).thenReturn(mPkg);
        when(context.getUserId()).thenReturn(mContext.getUserId());
        when(context.getUserId()).thenReturn(mUser.getIdentifier());
        when(context.getPackageManager()).thenReturn(pm);
        when(context.getPackageManager()).thenReturn(pm);
        when(pm.getApplicationInfo(anyString(), anyInt())).thenReturn(ai);
        when(pm.getApplicationInfo(anyString(), anyInt())).thenReturn(ai);


@@ -1522,8 +1527,8 @@ public class ManagedServicesTest extends UiServiceTestCase {
        ApplicationInfo ai = new ApplicationInfo();
        ApplicationInfo ai = new ApplicationInfo();
        ai.targetSdkVersion = Build.VERSION_CODES.CUR_DEVELOPMENT;
        ai.targetSdkVersion = Build.VERSION_CODES.CUR_DEVELOPMENT;


        when(context.getPackageName()).thenReturn(mContext.getPackageName());
        when(context.getPackageName()).thenReturn(mPkg);
        when(context.getUserId()).thenReturn(mContext.getUserId());
        when(context.getUserId()).thenReturn(mUser.getIdentifier());
        when(context.getPackageManager()).thenReturn(pm);
        when(context.getPackageManager()).thenReturn(pm);
        when(pm.getApplicationInfo(anyString(), anyInt())).thenReturn(ai);
        when(pm.getApplicationInfo(anyString(), anyInt())).thenReturn(ai);


@@ -1552,8 +1557,8 @@ public class ManagedServicesTest extends UiServiceTestCase {
        ApplicationInfo ai = new ApplicationInfo();
        ApplicationInfo ai = new ApplicationInfo();
        ai.targetSdkVersion = Build.VERSION_CODES.CUR_DEVELOPMENT;
        ai.targetSdkVersion = Build.VERSION_CODES.CUR_DEVELOPMENT;


        when(context.getPackageName()).thenReturn(mContext.getPackageName());
        when(context.getPackageName()).thenReturn(mPkg);
        when(context.getUserId()).thenReturn(mContext.getUserId());
        when(context.getUserId()).thenReturn(mUser.getIdentifier());
        when(context.getPackageManager()).thenReturn(pm);
        when(context.getPackageManager()).thenReturn(pm);
        when(pm.getApplicationInfo(anyString(), anyInt())).thenReturn(ai);
        when(pm.getApplicationInfo(anyString(), anyInt())).thenReturn(ai);


@@ -1791,8 +1796,8 @@ public class ManagedServicesTest extends UiServiceTestCase {
        ApplicationInfo ai = new ApplicationInfo();
        ApplicationInfo ai = new ApplicationInfo();
        ai.targetSdkVersion = Build.VERSION_CODES.CUR_DEVELOPMENT;
        ai.targetSdkVersion = Build.VERSION_CODES.CUR_DEVELOPMENT;


        when(context.getPackageName()).thenReturn(mContext.getPackageName());
        when(context.getPackageName()).thenReturn(mPkg);
        when(context.getUserId()).thenReturn(mContext.getUserId());
        when(context.getUserId()).thenReturn(mUser.getIdentifier());
        when(context.getPackageManager()).thenReturn(pm);
        when(context.getPackageManager()).thenReturn(pm);
        when(pm.getApplicationInfo(anyString(), anyInt())).thenReturn(ai);
        when(pm.getApplicationInfo(anyString(), anyInt())).thenReturn(ai);


@@ -1837,8 +1842,8 @@ public class ManagedServicesTest extends UiServiceTestCase {
        ApplicationInfo ai = new ApplicationInfo();
        ApplicationInfo ai = new ApplicationInfo();
        ai.targetSdkVersion = Build.VERSION_CODES.CUR_DEVELOPMENT;
        ai.targetSdkVersion = Build.VERSION_CODES.CUR_DEVELOPMENT;


        when(context.getPackageName()).thenReturn(mContext.getPackageName());
        when(context.getPackageName()).thenReturn(mPkg);
        when(context.getUserId()).thenReturn(mContext.getUserId());
        when(context.getUserId()).thenReturn(mUser.getIdentifier());
        when(context.getPackageManager()).thenReturn(pm);
        when(context.getPackageManager()).thenReturn(pm);
        when(pm.getApplicationInfo(anyString(), anyInt())).thenReturn(ai);
        when(pm.getApplicationInfo(anyString(), anyInt())).thenReturn(ai);


@@ -1880,8 +1885,8 @@ public class ManagedServicesTest extends UiServiceTestCase {
        ApplicationInfo ai = new ApplicationInfo();
        ApplicationInfo ai = new ApplicationInfo();
        ai.targetSdkVersion = Build.VERSION_CODES.CUR_DEVELOPMENT;
        ai.targetSdkVersion = Build.VERSION_CODES.CUR_DEVELOPMENT;


        when(context.getPackageName()).thenReturn(mContext.getPackageName());
        when(context.getPackageName()).thenReturn(mPkg);
        when(context.getUserId()).thenReturn(mContext.getUserId());
        when(context.getUserId()).thenReturn(mUser.getIdentifier());
        when(context.getPackageManager()).thenReturn(pm);
        when(context.getPackageManager()).thenReturn(pm);
        when(pm.getApplicationInfo(anyString(), anyInt())).thenReturn(ai);
        when(pm.getApplicationInfo(anyString(), anyInt())).thenReturn(ai);


+56 −51

File changed.

Preview size limit exceeded, changes collapsed.

+3 −6
Original line number Original line Diff line number Diff line
@@ -30,6 +30,7 @@ import android.app.NotificationHistory.HistoricalNotification;
import android.content.Context;
import android.content.Context;
import android.graphics.drawable.Icon;
import android.graphics.drawable.Icon;
import android.os.Handler;
import android.os.Handler;
import android.os.UserHandle;
import android.util.AtomicFile;
import android.util.AtomicFile;


import androidx.test.InstrumentationRegistry;
import androidx.test.InstrumentationRegistry;
@@ -56,8 +57,6 @@ public class NotificationHistoryDatabaseTest extends UiServiceTestCase {
    File mRootDir;
    File mRootDir;
    @Mock
    @Mock
    Handler mFileWriteHandler;
    Handler mFileWriteHandler;
    @Mock
    Context mContext;


    NotificationHistoryDatabase mDataBase;
    NotificationHistoryDatabase mDataBase;


@@ -92,10 +91,8 @@ public class NotificationHistoryDatabaseTest extends UiServiceTestCase {
    @Before
    @Before
    public void setUp() {
    public void setUp() {
        MockitoAnnotations.initMocks(this);
        MockitoAnnotations.initMocks(this);
        when(mContext.getUser()).thenReturn(getContext().getUser());
        final File fileDir = mContext.getFilesDir();
        when(mContext.getPackageName()).thenReturn(getContext().getPackageName());
        mRootDir = new File(fileDir, "NotificationHistoryDatabaseTest");

        mRootDir = new File(mContext.getFilesDir(), "NotificationHistoryDatabaseTest");


        mDataBase = new NotificationHistoryDatabase(mFileWriteHandler, mRootDir);
        mDataBase = new NotificationHistoryDatabase(mFileWriteHandler, mRootDir);
        mDataBase.init();
        mDataBase.init();
Loading