Loading services/tests/servicestests/AndroidManifest.xml +1 −0 Original line number Diff line number Diff line Loading @@ -65,6 +65,7 @@ <uses-permission android:name="android.permission.FOREGROUND_SERVICE"/> <uses-permission android:name="android.permission.SUSPEND_APPS"/> <uses-permission android:name="android.permission.CONTROL_KEYGUARD"/> <uses-permission android:name="android.permission.MANAGE_BIND_INSTANT_SERVICE"/> <!-- Uses API introduced in O (26) --> <uses-sdk android:minSdkVersion="1" Loading services/tests/servicestests/src/com/android/server/accounts/AccountManagerServiceTest.java +33 −7 Original line number Diff line number Diff line Loading @@ -48,6 +48,7 @@ import android.content.pm.ActivityInfo; import android.content.pm.ApplicationInfo; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManagerInternal; import android.content.pm.ResolveInfo; import android.content.pm.Signature; import android.content.pm.UserInfo; Loading Loading @@ -114,6 +115,7 @@ public class AccountManagerServiceTest extends AndroidTestCase { @Mock private IAccountManagerResponse mMockAccountManagerResponse; @Mock private IBinder mMockBinder; @Mock private INotificationManager mMockNotificationManager; @Mock private PackageManagerInternal mMockPackageManagerInternal; @Captor private ArgumentCaptor<Intent> mIntentCaptor; @Captor private ArgumentCaptor<Bundle> mBundleCaptor; Loading Loading @@ -158,6 +160,9 @@ public class AccountManagerServiceTest extends AndroidTestCase { when(mMockContext.getSystemService(Context.DEVICE_POLICY_SERVICE)).thenReturn( mMockDevicePolicyManager); when(mMockAccountManagerResponse.asBinder()).thenReturn(mMockBinder); when(mMockPackageManagerInternal.hasSignatureCapability(anyInt(), anyInt(), anyInt())) .thenReturn(true); LocalServices.addService(PackageManagerInternal.class, mMockPackageManagerInternal); Context realTestContext = getContext(); MyMockContext mockContext = new MyMockContext(realTestContext, mMockContext); Loading @@ -177,6 +182,7 @@ public class AccountManagerServiceTest extends AndroidTestCase { cdl.countDown(); }); cdl.await(1, TimeUnit.SECONDS); LocalServices.removeServiceForTest(PackageManagerInternal.class); super.tearDown(); } Loading Loading @@ -610,6 +616,8 @@ public class AccountManagerServiceTest extends AndroidTestCase { any(Intent.class), anyInt(), anyInt())).thenReturn(resolveInfo); when(mMockPackageManager.checkSignatures( anyInt(), anyInt())).thenReturn(PackageManager.SIGNATURE_NO_MATCH); when(mMockPackageManagerInternal.hasSignatureCapability(anyInt(), anyInt(), anyInt())) .thenReturn(false); final CountDownLatch latch = new CountDownLatch(1); Response response = new Response(latch, mMockAccountManagerResponse); Loading @@ -626,7 +634,7 @@ public class AccountManagerServiceTest extends AndroidTestCase { waitForLatch(latch); verify(mMockAccountManagerResponse, never()).onResult(any(Bundle.class)); verify(mMockAccountManagerResponse).onError( eq(AccountManager.ERROR_CODE_REMOTE_EXCEPTION), anyString()); eq(AccountManager.ERROR_CODE_INVALID_RESPONSE), anyString()); } @SmallTest Loading Loading @@ -792,6 +800,8 @@ public class AccountManagerServiceTest extends AndroidTestCase { any(Intent.class), anyInt(), anyInt())).thenReturn(resolveInfo); when(mMockPackageManager.checkSignatures( anyInt(), anyInt())).thenReturn(PackageManager.SIGNATURE_NO_MATCH); when(mMockPackageManagerInternal.hasSignatureCapability(anyInt(), anyInt(), anyInt())) .thenReturn(false); final CountDownLatch latch = new CountDownLatch(1); Response response = new Response(latch, mMockAccountManagerResponse); Loading @@ -808,7 +818,7 @@ public class AccountManagerServiceTest extends AndroidTestCase { waitForLatch(latch); verify(mMockAccountManagerResponse, never()).onResult(any(Bundle.class)); verify(mMockAccountManagerResponse).onError( eq(AccountManager.ERROR_CODE_REMOTE_EXCEPTION), anyString()); eq(AccountManager.ERROR_CODE_INVALID_RESPONSE), anyString()); } @SmallTest Loading Loading @@ -1092,6 +1102,8 @@ public class AccountManagerServiceTest extends AndroidTestCase { any(Intent.class), anyInt(), anyInt())).thenReturn(resolveInfo); when(mMockPackageManager.checkSignatures( anyInt(), anyInt())).thenReturn(PackageManager.SIGNATURE_NO_MATCH); when(mMockPackageManagerInternal.hasSignatureCapability(anyInt(), anyInt(), anyInt())) .thenReturn(false); final CountDownLatch latch = new CountDownLatch(1); Response response = new Response(latch, mMockAccountManagerResponse); Loading @@ -1106,7 +1118,7 @@ public class AccountManagerServiceTest extends AndroidTestCase { waitForLatch(latch); verify(mMockAccountManagerResponse, never()).onResult(any(Bundle.class)); verify(mMockAccountManagerResponse).onError( eq(AccountManager.ERROR_CODE_REMOTE_EXCEPTION), anyString()); eq(AccountManager.ERROR_CODE_INVALID_RESPONSE), anyString()); } @SmallTest Loading Loading @@ -1352,6 +1364,8 @@ public class AccountManagerServiceTest extends AndroidTestCase { unlockSystemUser(); when(mMockPackageManager.checkSignatures(anyInt(), anyInt())) .thenReturn(PackageManager.SIGNATURE_NO_MATCH); when(mMockPackageManagerInternal.hasSignatureCapability(anyInt(), anyInt(), anyInt())) .thenReturn(false); try { mAms.removeAccountAsUser( mMockAccountManagerResponse, // response Loading Loading @@ -1688,6 +1702,8 @@ public class AccountManagerServiceTest extends AndroidTestCase { any(Intent.class), anyInt(), anyInt())).thenReturn(resolveInfo); when(mMockPackageManager.checkSignatures( anyInt(), anyInt())).thenReturn(PackageManager.SIGNATURE_NO_MATCH); when(mMockPackageManagerInternal.hasSignatureCapability(anyInt(), anyInt(), anyInt())) .thenReturn(false); final CountDownLatch latch = new CountDownLatch(1); Response response = new Response(latch, mMockAccountManagerResponse); Loading @@ -1701,7 +1717,7 @@ public class AccountManagerServiceTest extends AndroidTestCase { waitForLatch(latch); verify(mMockAccountManagerResponse, never()).onResult(any(Bundle.class)); verify(mMockAccountManagerResponse).onError( eq(AccountManager.ERROR_CODE_REMOTE_EXCEPTION), anyString()); eq(AccountManager.ERROR_CODE_INVALID_RESPONSE), anyString()); } @SmallTest Loading Loading @@ -1959,6 +1975,8 @@ public class AccountManagerServiceTest extends AndroidTestCase { any(Intent.class), anyInt(), anyInt())).thenReturn(resolveInfo); when(mMockPackageManager.checkSignatures( anyInt(), anyInt())).thenReturn(PackageManager.SIGNATURE_NO_MATCH); when(mMockPackageManagerInternal.hasSignatureCapability(anyInt(), anyInt(), anyInt())) .thenReturn(false); final CountDownLatch latch = new CountDownLatch(1); Response response = new Response(latch, mMockAccountManagerResponse); Loading @@ -1974,7 +1992,7 @@ public class AccountManagerServiceTest extends AndroidTestCase { waitForLatch(latch); verify(mMockAccountManagerResponse, never()).onResult(any(Bundle.class)); verify(mMockAccountManagerResponse).onError( eq(AccountManager.ERROR_CODE_REMOTE_EXCEPTION), anyString()); eq(AccountManager.ERROR_CODE_INVALID_RESPONSE), anyString()); } @SmallTest Loading Loading @@ -2097,6 +2115,8 @@ public class AccountManagerServiceTest extends AndroidTestCase { any(Intent.class), anyInt(), anyInt())).thenReturn(resolveInfo); when(mMockPackageManager.checkSignatures( anyInt(), anyInt())).thenReturn(PackageManager.SIGNATURE_NO_MATCH); when(mMockPackageManagerInternal.hasSignatureCapability(anyInt(), anyInt(), anyInt())) .thenReturn(false); final CountDownLatch latch = new CountDownLatch(1); Response response = new Response(latch, mMockAccountManagerResponse); Loading @@ -2110,7 +2130,7 @@ public class AccountManagerServiceTest extends AndroidTestCase { verify(mMockAccountManagerResponse, never()).onResult(any(Bundle.class)); verify(mMockAccountManagerResponse).onError( eq(AccountManager.ERROR_CODE_REMOTE_EXCEPTION), anyString()); eq(AccountManager.ERROR_CODE_INVALID_RESPONSE), anyString()); } @SmallTest Loading Loading @@ -2230,6 +2250,8 @@ public class AccountManagerServiceTest extends AndroidTestCase { any(Intent.class), anyInt(), anyInt())).thenReturn(resolveInfo); when(mMockPackageManager.checkSignatures( anyInt(), anyInt())).thenReturn(PackageManager.SIGNATURE_NO_MATCH); when(mMockPackageManagerInternal.hasSignatureCapability(anyInt(), anyInt(), anyInt())) .thenReturn(false); final CountDownLatch latch = new CountDownLatch(1); Response response = new Response(latch, mMockAccountManagerResponse); Loading @@ -2245,7 +2267,7 @@ public class AccountManagerServiceTest extends AndroidTestCase { verify(mMockAccountManagerResponse, never()).onResult(any(Bundle.class)); verify(mMockAccountManagerResponse).onError( eq(AccountManager.ERROR_CODE_REMOTE_EXCEPTION), anyString()); eq(AccountManager.ERROR_CODE_INVALID_RESPONSE), anyString()); } @SmallTest Loading Loading @@ -2332,6 +2354,8 @@ public class AccountManagerServiceTest extends AndroidTestCase { unlockSystemUser(); when(mMockPackageManager.checkSignatures(anyInt(), anyInt())) .thenReturn(PackageManager.SIGNATURE_NO_MATCH); when(mMockPackageManagerInternal.hasSignatureCapability(anyInt(), anyInt(), anyInt())) .thenReturn(false); try { mAms.editProperties( mMockAccountManagerResponse, // response Loading Loading @@ -2621,6 +2645,8 @@ public class AccountManagerServiceTest extends AndroidTestCase { PackageManager.PERMISSION_DENIED); when(mMockPackageManager.checkSignatures(anyInt(), anyInt())) .thenReturn(PackageManager.SIGNATURE_NO_MATCH); when(mMockPackageManagerInternal.hasSignatureCapability(anyInt(), anyInt(), anyInt())) .thenReturn(false); final CountDownLatch latch = new CountDownLatch(1); Response response = new Response(latch, mMockAccountManagerResponse); Loading services/tests/servicestests/src/com/android/server/accounts/AccountsDbTest.java +7 −0 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ import android.content.Context; import android.database.Cursor; import android.support.test.InstrumentationRegistry; import android.support.test.runner.AndroidJUnit4; import android.os.Build; import android.test.suitebuilder.annotation.SmallTest; import android.util.Pair; Loading Loading @@ -85,6 +86,12 @@ public class AccountsDbTest { @Test public void testCeNotAvailableInitially() { // If the CE database is not attached to the DE database then any calls that modify the CE // database will result in a Log.wtf call that will crash this process on eng builds. To // allow the test to run through to completion skip this test on eng builds. if (Build.IS_ENG) { return; } Account account = new Account("name", "example.com"); long id = mAccountsDb.insertCeAccount(account, ""); assertEquals("Insert into CE should fail until CE database is attached", -1, id); Loading Loading
services/tests/servicestests/AndroidManifest.xml +1 −0 Original line number Diff line number Diff line Loading @@ -65,6 +65,7 @@ <uses-permission android:name="android.permission.FOREGROUND_SERVICE"/> <uses-permission android:name="android.permission.SUSPEND_APPS"/> <uses-permission android:name="android.permission.CONTROL_KEYGUARD"/> <uses-permission android:name="android.permission.MANAGE_BIND_INSTANT_SERVICE"/> <!-- Uses API introduced in O (26) --> <uses-sdk android:minSdkVersion="1" Loading
services/tests/servicestests/src/com/android/server/accounts/AccountManagerServiceTest.java +33 −7 Original line number Diff line number Diff line Loading @@ -48,6 +48,7 @@ import android.content.pm.ActivityInfo; import android.content.pm.ApplicationInfo; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManagerInternal; import android.content.pm.ResolveInfo; import android.content.pm.Signature; import android.content.pm.UserInfo; Loading Loading @@ -114,6 +115,7 @@ public class AccountManagerServiceTest extends AndroidTestCase { @Mock private IAccountManagerResponse mMockAccountManagerResponse; @Mock private IBinder mMockBinder; @Mock private INotificationManager mMockNotificationManager; @Mock private PackageManagerInternal mMockPackageManagerInternal; @Captor private ArgumentCaptor<Intent> mIntentCaptor; @Captor private ArgumentCaptor<Bundle> mBundleCaptor; Loading Loading @@ -158,6 +160,9 @@ public class AccountManagerServiceTest extends AndroidTestCase { when(mMockContext.getSystemService(Context.DEVICE_POLICY_SERVICE)).thenReturn( mMockDevicePolicyManager); when(mMockAccountManagerResponse.asBinder()).thenReturn(mMockBinder); when(mMockPackageManagerInternal.hasSignatureCapability(anyInt(), anyInt(), anyInt())) .thenReturn(true); LocalServices.addService(PackageManagerInternal.class, mMockPackageManagerInternal); Context realTestContext = getContext(); MyMockContext mockContext = new MyMockContext(realTestContext, mMockContext); Loading @@ -177,6 +182,7 @@ public class AccountManagerServiceTest extends AndroidTestCase { cdl.countDown(); }); cdl.await(1, TimeUnit.SECONDS); LocalServices.removeServiceForTest(PackageManagerInternal.class); super.tearDown(); } Loading Loading @@ -610,6 +616,8 @@ public class AccountManagerServiceTest extends AndroidTestCase { any(Intent.class), anyInt(), anyInt())).thenReturn(resolveInfo); when(mMockPackageManager.checkSignatures( anyInt(), anyInt())).thenReturn(PackageManager.SIGNATURE_NO_MATCH); when(mMockPackageManagerInternal.hasSignatureCapability(anyInt(), anyInt(), anyInt())) .thenReturn(false); final CountDownLatch latch = new CountDownLatch(1); Response response = new Response(latch, mMockAccountManagerResponse); Loading @@ -626,7 +634,7 @@ public class AccountManagerServiceTest extends AndroidTestCase { waitForLatch(latch); verify(mMockAccountManagerResponse, never()).onResult(any(Bundle.class)); verify(mMockAccountManagerResponse).onError( eq(AccountManager.ERROR_CODE_REMOTE_EXCEPTION), anyString()); eq(AccountManager.ERROR_CODE_INVALID_RESPONSE), anyString()); } @SmallTest Loading Loading @@ -792,6 +800,8 @@ public class AccountManagerServiceTest extends AndroidTestCase { any(Intent.class), anyInt(), anyInt())).thenReturn(resolveInfo); when(mMockPackageManager.checkSignatures( anyInt(), anyInt())).thenReturn(PackageManager.SIGNATURE_NO_MATCH); when(mMockPackageManagerInternal.hasSignatureCapability(anyInt(), anyInt(), anyInt())) .thenReturn(false); final CountDownLatch latch = new CountDownLatch(1); Response response = new Response(latch, mMockAccountManagerResponse); Loading @@ -808,7 +818,7 @@ public class AccountManagerServiceTest extends AndroidTestCase { waitForLatch(latch); verify(mMockAccountManagerResponse, never()).onResult(any(Bundle.class)); verify(mMockAccountManagerResponse).onError( eq(AccountManager.ERROR_CODE_REMOTE_EXCEPTION), anyString()); eq(AccountManager.ERROR_CODE_INVALID_RESPONSE), anyString()); } @SmallTest Loading Loading @@ -1092,6 +1102,8 @@ public class AccountManagerServiceTest extends AndroidTestCase { any(Intent.class), anyInt(), anyInt())).thenReturn(resolveInfo); when(mMockPackageManager.checkSignatures( anyInt(), anyInt())).thenReturn(PackageManager.SIGNATURE_NO_MATCH); when(mMockPackageManagerInternal.hasSignatureCapability(anyInt(), anyInt(), anyInt())) .thenReturn(false); final CountDownLatch latch = new CountDownLatch(1); Response response = new Response(latch, mMockAccountManagerResponse); Loading @@ -1106,7 +1118,7 @@ public class AccountManagerServiceTest extends AndroidTestCase { waitForLatch(latch); verify(mMockAccountManagerResponse, never()).onResult(any(Bundle.class)); verify(mMockAccountManagerResponse).onError( eq(AccountManager.ERROR_CODE_REMOTE_EXCEPTION), anyString()); eq(AccountManager.ERROR_CODE_INVALID_RESPONSE), anyString()); } @SmallTest Loading Loading @@ -1352,6 +1364,8 @@ public class AccountManagerServiceTest extends AndroidTestCase { unlockSystemUser(); when(mMockPackageManager.checkSignatures(anyInt(), anyInt())) .thenReturn(PackageManager.SIGNATURE_NO_MATCH); when(mMockPackageManagerInternal.hasSignatureCapability(anyInt(), anyInt(), anyInt())) .thenReturn(false); try { mAms.removeAccountAsUser( mMockAccountManagerResponse, // response Loading Loading @@ -1688,6 +1702,8 @@ public class AccountManagerServiceTest extends AndroidTestCase { any(Intent.class), anyInt(), anyInt())).thenReturn(resolveInfo); when(mMockPackageManager.checkSignatures( anyInt(), anyInt())).thenReturn(PackageManager.SIGNATURE_NO_MATCH); when(mMockPackageManagerInternal.hasSignatureCapability(anyInt(), anyInt(), anyInt())) .thenReturn(false); final CountDownLatch latch = new CountDownLatch(1); Response response = new Response(latch, mMockAccountManagerResponse); Loading @@ -1701,7 +1717,7 @@ public class AccountManagerServiceTest extends AndroidTestCase { waitForLatch(latch); verify(mMockAccountManagerResponse, never()).onResult(any(Bundle.class)); verify(mMockAccountManagerResponse).onError( eq(AccountManager.ERROR_CODE_REMOTE_EXCEPTION), anyString()); eq(AccountManager.ERROR_CODE_INVALID_RESPONSE), anyString()); } @SmallTest Loading Loading @@ -1959,6 +1975,8 @@ public class AccountManagerServiceTest extends AndroidTestCase { any(Intent.class), anyInt(), anyInt())).thenReturn(resolveInfo); when(mMockPackageManager.checkSignatures( anyInt(), anyInt())).thenReturn(PackageManager.SIGNATURE_NO_MATCH); when(mMockPackageManagerInternal.hasSignatureCapability(anyInt(), anyInt(), anyInt())) .thenReturn(false); final CountDownLatch latch = new CountDownLatch(1); Response response = new Response(latch, mMockAccountManagerResponse); Loading @@ -1974,7 +1992,7 @@ public class AccountManagerServiceTest extends AndroidTestCase { waitForLatch(latch); verify(mMockAccountManagerResponse, never()).onResult(any(Bundle.class)); verify(mMockAccountManagerResponse).onError( eq(AccountManager.ERROR_CODE_REMOTE_EXCEPTION), anyString()); eq(AccountManager.ERROR_CODE_INVALID_RESPONSE), anyString()); } @SmallTest Loading Loading @@ -2097,6 +2115,8 @@ public class AccountManagerServiceTest extends AndroidTestCase { any(Intent.class), anyInt(), anyInt())).thenReturn(resolveInfo); when(mMockPackageManager.checkSignatures( anyInt(), anyInt())).thenReturn(PackageManager.SIGNATURE_NO_MATCH); when(mMockPackageManagerInternal.hasSignatureCapability(anyInt(), anyInt(), anyInt())) .thenReturn(false); final CountDownLatch latch = new CountDownLatch(1); Response response = new Response(latch, mMockAccountManagerResponse); Loading @@ -2110,7 +2130,7 @@ public class AccountManagerServiceTest extends AndroidTestCase { verify(mMockAccountManagerResponse, never()).onResult(any(Bundle.class)); verify(mMockAccountManagerResponse).onError( eq(AccountManager.ERROR_CODE_REMOTE_EXCEPTION), anyString()); eq(AccountManager.ERROR_CODE_INVALID_RESPONSE), anyString()); } @SmallTest Loading Loading @@ -2230,6 +2250,8 @@ public class AccountManagerServiceTest extends AndroidTestCase { any(Intent.class), anyInt(), anyInt())).thenReturn(resolveInfo); when(mMockPackageManager.checkSignatures( anyInt(), anyInt())).thenReturn(PackageManager.SIGNATURE_NO_MATCH); when(mMockPackageManagerInternal.hasSignatureCapability(anyInt(), anyInt(), anyInt())) .thenReturn(false); final CountDownLatch latch = new CountDownLatch(1); Response response = new Response(latch, mMockAccountManagerResponse); Loading @@ -2245,7 +2267,7 @@ public class AccountManagerServiceTest extends AndroidTestCase { verify(mMockAccountManagerResponse, never()).onResult(any(Bundle.class)); verify(mMockAccountManagerResponse).onError( eq(AccountManager.ERROR_CODE_REMOTE_EXCEPTION), anyString()); eq(AccountManager.ERROR_CODE_INVALID_RESPONSE), anyString()); } @SmallTest Loading Loading @@ -2332,6 +2354,8 @@ public class AccountManagerServiceTest extends AndroidTestCase { unlockSystemUser(); when(mMockPackageManager.checkSignatures(anyInt(), anyInt())) .thenReturn(PackageManager.SIGNATURE_NO_MATCH); when(mMockPackageManagerInternal.hasSignatureCapability(anyInt(), anyInt(), anyInt())) .thenReturn(false); try { mAms.editProperties( mMockAccountManagerResponse, // response Loading Loading @@ -2621,6 +2645,8 @@ public class AccountManagerServiceTest extends AndroidTestCase { PackageManager.PERMISSION_DENIED); when(mMockPackageManager.checkSignatures(anyInt(), anyInt())) .thenReturn(PackageManager.SIGNATURE_NO_MATCH); when(mMockPackageManagerInternal.hasSignatureCapability(anyInt(), anyInt(), anyInt())) .thenReturn(false); final CountDownLatch latch = new CountDownLatch(1); Response response = new Response(latch, mMockAccountManagerResponse); Loading
services/tests/servicestests/src/com/android/server/accounts/AccountsDbTest.java +7 −0 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ import android.content.Context; import android.database.Cursor; import android.support.test.InstrumentationRegistry; import android.support.test.runner.AndroidJUnit4; import android.os.Build; import android.test.suitebuilder.annotation.SmallTest; import android.util.Pair; Loading Loading @@ -85,6 +86,12 @@ public class AccountsDbTest { @Test public void testCeNotAvailableInitially() { // If the CE database is not attached to the DE database then any calls that modify the CE // database will result in a Log.wtf call that will crash this process on eng builds. To // allow the test to run through to completion skip this test on eng builds. if (Build.IS_ENG) { return; } Account account = new Account("name", "example.com"); long id = mAccountsDb.insertCeAccount(account, ""); assertEquals("Insert into CE should fail until CE database is attached", -1, id); Loading