Loading services/core/java/com/android/server/pm/BackgroundInstallControlService.java +20 −37 Original line number Original line Diff line number Diff line Loading @@ -22,8 +22,6 @@ import android.app.usage.UsageStatsManagerInternal; import android.content.Context; import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.pm.ApplicationInfo; import android.content.pm.IBackgroundInstallControlService; import android.content.pm.IBackgroundInstallControlService; import android.content.pm.IPackageManager; import android.content.pm.InstallSourceInfo; import android.content.pm.PackageInfo; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager; import android.content.pm.PackageManagerInternal; import android.content.pm.PackageManagerInternal; Loading @@ -32,8 +30,6 @@ import android.os.Environment; import android.os.Handler; import android.os.Handler; import android.os.Looper; import android.os.Looper; import android.os.Message; import android.os.Message; import android.os.RemoteException; import android.os.ServiceManager; import android.os.SystemClock; import android.os.SystemClock; import android.os.UserHandle; import android.os.UserHandle; import android.util.ArraySet; import android.util.ArraySet; Loading @@ -54,6 +50,7 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.IOException; import java.util.List; import java.util.ListIterator; import java.util.ListIterator; import java.util.Set; import java.util.Set; import java.util.TreeSet; import java.util.TreeSet; Loading @@ -75,7 +72,7 @@ public class BackgroundInstallControlService extends SystemService { private final Context mContext; private final Context mContext; private final BinderService mBinderService; private final BinderService mBinderService; private final IPackageManager mIPackageManager; private final PackageManager mPackageManager; private final PackageManagerInternal mPackageManagerInternal; private final PackageManagerInternal mPackageManagerInternal; private final UsageStatsManagerInternal mUsageStatsManagerInternal; private final UsageStatsManagerInternal mUsageStatsManagerInternal; private final PermissionManagerServiceInternal mPermissionManager; private final PermissionManagerServiceInternal mPermissionManager; Loading @@ -98,7 +95,7 @@ public class BackgroundInstallControlService extends SystemService { BackgroundInstallControlService(@NonNull Injector injector) { BackgroundInstallControlService(@NonNull Injector injector) { super(injector.getContext()); super(injector.getContext()); mContext = injector.getContext(); mContext = injector.getContext(); mIPackageManager = injector.getIPackageManager(); mPackageManager = injector.getPackageManager(); mPackageManagerInternal = injector.getPackageManagerInternal(); mPackageManagerInternal = injector.getPackageManagerInternal(); mPermissionManager = injector.getPermissionManager(); mPermissionManager = injector.getPermissionManager(); mHandler = new EventHandler(injector.getLooper(), this); mHandler = new EventHandler(injector.getLooper(), this); Loading Loading @@ -131,16 +128,12 @@ public class BackgroundInstallControlService extends SystemService { @VisibleForTesting @VisibleForTesting ParceledListSlice<PackageInfo> getBackgroundInstalledPackages( ParceledListSlice<PackageInfo> getBackgroundInstalledPackages( @PackageManager.PackageInfoFlagsBits long flags, int userId) { @PackageManager.PackageInfoFlagsBits long flags, int userId) { ParceledListSlice<PackageInfo> packages; List<PackageInfo> packages = mPackageManager.getInstalledPackagesAsUser( try { PackageManager.PackageInfoFlags.of(flags), userId); packages = mIPackageManager.getInstalledPackages(flags, userId); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } initBackgroundInstalledPackages(); initBackgroundInstalledPackages(); ListIterator<PackageInfo> iter = packages.getList().listIterator(); ListIterator<PackageInfo> iter = packages.listIterator(); while (iter.hasNext()) { while (iter.hasNext()) { String packageName = iter.next().packageName; String packageName = iter.next().packageName; if (!mBackgroundInstalledPackages.contains(userId, packageName)) { if (!mBackgroundInstalledPackages.contains(userId, packageName)) { Loading @@ -148,7 +141,7 @@ public class BackgroundInstallControlService extends SystemService { } } } } return packages; return new ParceledListSlice<>(packages); } } private static class EventHandler extends Handler { private static class EventHandler extends Handler { Loading Loading @@ -181,31 +174,21 @@ public class BackgroundInstallControlService extends SystemService { } } void handlePackageAdd(String packageName, int userId) { void handlePackageAdd(String packageName, int userId) { InstallSourceInfo installSourceInfo = null; ApplicationInfo appInfo = null; try { try { installSourceInfo = mIPackageManager.getInstallSourceInfo(packageName); appInfo = mPackageManager.getApplicationInfoAsUser(packageName, } catch (RemoteException e) { PackageManager.ApplicationInfoFlags.of(0), userId); // Failed to talk to PackageManagerService Should never happen! } catch (PackageManager.NameNotFoundException e) { throw e.rethrowFromSystemServer(); Slog.w(TAG, "Package's appInfo not found " + packageName); } String installerPackageName = installSourceInfo == null ? null : installSourceInfo.getInstallingPackageName(); if (installerPackageName == null) { Slog.w(TAG, "fails to get installerPackageName for " + packageName); return; return; } } ApplicationInfo appInfo = null; String installerPackageName = null; try { try { appInfo = mIPackageManager.getApplicationInfo(packageName, installerPackageName = mPackageManager 0, userId); .getInstallSourceInfo(packageName).getInstallingPackageName(); } catch (RemoteException e) { } catch (PackageManager.NameNotFoundException e) { // Failed to talk to PackageManagerService Should never happen! Slog.w(TAG, "Package's installer not found " + packageName); throw e.rethrowFromSystemServer(); } if (appInfo == null) { Slog.w(TAG, "fails to get appInfo for " + packageName); return; return; } } Loading Loading @@ -486,7 +469,7 @@ public class BackgroundInstallControlService extends SystemService { interface Injector { interface Injector { Context getContext(); Context getContext(); IPackageManager getIPackageManager(); PackageManager getPackageManager(); PackageManagerInternal getPackageManagerInternal(); PackageManagerInternal getPackageManagerInternal(); Loading @@ -512,8 +495,8 @@ public class BackgroundInstallControlService extends SystemService { } } @Override @Override public IPackageManager getIPackageManager() { public PackageManager getPackageManager() { return IPackageManager.Stub.asInterface(ServiceManager.getService("package")); return mContext.getPackageManager(); } } @Override @Override Loading services/tests/servicestests/src/com/android/server/pm/BackgroundInstallControlServiceTest.java +22 −24 Original line number Original line Diff line number Diff line Loading @@ -22,8 +22,8 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doReturn; Loading @@ -37,12 +37,10 @@ import android.app.usage.UsageStatsManagerInternal; import android.app.usage.UsageStatsManagerInternal.UsageEventListener; import android.app.usage.UsageStatsManagerInternal.UsageEventListener; import android.content.Context; import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.pm.ApplicationInfo; import android.content.pm.IPackageManager; import android.content.pm.InstallSourceInfo; import android.content.pm.InstallSourceInfo; import android.content.pm.PackageInfo; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager; import android.content.pm.PackageManagerInternal; import android.content.pm.PackageManagerInternal; import android.content.pm.ParceledListSlice; import android.os.FileUtils; import android.os.FileUtils; import android.os.Looper; import android.os.Looper; import android.os.RemoteException; import android.os.RemoteException; Loading Loading @@ -103,7 +101,7 @@ public final class BackgroundInstallControlServiceTest { @Mock @Mock private Context mContext; private Context mContext; @Mock @Mock private IPackageManager mIPackageManager; private PackageManager mPackageManager; @Mock @Mock private PackageManagerInternal mPackageManagerInternal; private PackageManagerInternal mPackageManagerInternal; @Mock @Mock Loading Loading @@ -538,19 +536,19 @@ public final class BackgroundInstallControlServiceTest { @Test @Test public void testHandleUsageEvent_packageAddedNoUsageEvent() throws public void testHandleUsageEvent_packageAddedNoUsageEvent() throws RemoteException, NoSuchFieldException { NoSuchFieldException, PackageManager.NameNotFoundException { assertNull(mBackgroundInstallControlService.getBackgroundInstalledPackages()); assertNull(mBackgroundInstallControlService.getBackgroundInstalledPackages()); InstallSourceInfo installSourceInfo = new InstallSourceInfo( InstallSourceInfo installSourceInfo = new InstallSourceInfo( /* initiatingPackageName = */ null, /* initiatingPackageSigningInfo = */ null, /* initiatingPackageName = */ null, /* initiatingPackageSigningInfo = */ null, /* originatingPackageName = */ null, /* originatingPackageName = */ null, /* installingPackageName = */ INSTALLER_NAME_1); /* installingPackageName = */ INSTALLER_NAME_1); assertEquals(installSourceInfo.getInstallingPackageName(), INSTALLER_NAME_1); assertEquals(installSourceInfo.getInstallingPackageName(), INSTALLER_NAME_1); when(mIPackageManager.getInstallSourceInfo(anyString())).thenReturn(installSourceInfo); when(mPackageManager.getInstallSourceInfo(anyString())).thenReturn(installSourceInfo); ApplicationInfo appInfo = mock(ApplicationInfo.class); ApplicationInfo appInfo = mock(ApplicationInfo.class); when(mIPackageManager.getApplicationInfo( when(mPackageManager.getApplicationInfoAsUser( eq(PACKAGE_NAME_1), eq(PACKAGE_NAME_1), eq(0L), any(), anyInt()) anyInt()) ).thenReturn(appInfo); ).thenReturn(appInfo); Loading @@ -574,19 +572,19 @@ public final class BackgroundInstallControlServiceTest { @Test @Test public void testHandleUsageEvent_packageAddedInsideTimeFrame() throws public void testHandleUsageEvent_packageAddedInsideTimeFrame() throws RemoteException, NoSuchFieldException { NoSuchFieldException, PackageManager.NameNotFoundException { assertNull(mBackgroundInstallControlService.getBackgroundInstalledPackages()); assertNull(mBackgroundInstallControlService.getBackgroundInstalledPackages()); InstallSourceInfo installSourceInfo = new InstallSourceInfo( InstallSourceInfo installSourceInfo = new InstallSourceInfo( /* initiatingPackageName = */ null, /* initiatingPackageSigningInfo = */ null, /* initiatingPackageName = */ null, /* initiatingPackageSigningInfo = */ null, /* originatingPackageName = */ null, /* originatingPackageName = */ null, /* installingPackageName = */ INSTALLER_NAME_1); /* installingPackageName = */ INSTALLER_NAME_1); assertEquals(installSourceInfo.getInstallingPackageName(), INSTALLER_NAME_1); assertEquals(installSourceInfo.getInstallingPackageName(), INSTALLER_NAME_1); when(mIPackageManager.getInstallSourceInfo(anyString())).thenReturn(installSourceInfo); when(mPackageManager.getInstallSourceInfo(anyString())).thenReturn(installSourceInfo); ApplicationInfo appInfo = mock(ApplicationInfo.class); ApplicationInfo appInfo = mock(ApplicationInfo.class); when(mIPackageManager.getApplicationInfo( when(mPackageManager.getApplicationInfoAsUser( eq(PACKAGE_NAME_1), eq(PACKAGE_NAME_1), eq(0L), any(), anyInt()) anyInt()) ).thenReturn(appInfo); ).thenReturn(appInfo); Loading Loading @@ -618,19 +616,19 @@ public final class BackgroundInstallControlServiceTest { @Test @Test public void testHandleUsageEvent_packageAddedOutsideTimeFrame1() throws public void testHandleUsageEvent_packageAddedOutsideTimeFrame1() throws RemoteException, NoSuchFieldException { NoSuchFieldException, PackageManager.NameNotFoundException { assertNull(mBackgroundInstallControlService.getBackgroundInstalledPackages()); assertNull(mBackgroundInstallControlService.getBackgroundInstalledPackages()); InstallSourceInfo installSourceInfo = new InstallSourceInfo( InstallSourceInfo installSourceInfo = new InstallSourceInfo( /* initiatingPackageName = */ null, /* initiatingPackageSigningInfo = */ null, /* initiatingPackageName = */ null, /* initiatingPackageSigningInfo = */ null, /* originatingPackageName = */ null, /* originatingPackageName = */ null, /* installingPackageName = */ INSTALLER_NAME_1); /* installingPackageName = */ INSTALLER_NAME_1); assertEquals(installSourceInfo.getInstallingPackageName(), INSTALLER_NAME_1); assertEquals(installSourceInfo.getInstallingPackageName(), INSTALLER_NAME_1); when(mIPackageManager.getInstallSourceInfo(anyString())).thenReturn(installSourceInfo); when(mPackageManager.getInstallSourceInfo(anyString())).thenReturn(installSourceInfo); ApplicationInfo appInfo = mock(ApplicationInfo.class); ApplicationInfo appInfo = mock(ApplicationInfo.class); when(mIPackageManager.getApplicationInfo( when(mPackageManager.getApplicationInfoAsUser( eq(PACKAGE_NAME_1), eq(PACKAGE_NAME_1), eq(0L), any(), anyInt()) anyInt()) ).thenReturn(appInfo); ).thenReturn(appInfo); Loading Loading @@ -666,19 +664,19 @@ public final class BackgroundInstallControlServiceTest { } } @Test @Test public void testHandleUsageEvent_packageAddedOutsideTimeFrame2() throws public void testHandleUsageEvent_packageAddedOutsideTimeFrame2() throws RemoteException, NoSuchFieldException { NoSuchFieldException, PackageManager.NameNotFoundException { assertNull(mBackgroundInstallControlService.getBackgroundInstalledPackages()); assertNull(mBackgroundInstallControlService.getBackgroundInstalledPackages()); InstallSourceInfo installSourceInfo = new InstallSourceInfo( InstallSourceInfo installSourceInfo = new InstallSourceInfo( /* initiatingPackageName = */ null, /* initiatingPackageSigningInfo = */ null, /* initiatingPackageName = */ null, /* initiatingPackageSigningInfo = */ null, /* originatingPackageName = */ null, /* originatingPackageName = */ null, /* installingPackageName = */ INSTALLER_NAME_1); /* installingPackageName = */ INSTALLER_NAME_1); assertEquals(installSourceInfo.getInstallingPackageName(), INSTALLER_NAME_1); assertEquals(installSourceInfo.getInstallingPackageName(), INSTALLER_NAME_1); when(mIPackageManager.getInstallSourceInfo(anyString())).thenReturn(installSourceInfo); when(mPackageManager.getInstallSourceInfo(anyString())).thenReturn(installSourceInfo); ApplicationInfo appInfo = mock(ApplicationInfo.class); ApplicationInfo appInfo = mock(ApplicationInfo.class); when(mIPackageManager.getApplicationInfo( when(mPackageManager.getApplicationInfoAsUser( eq(PACKAGE_NAME_1), eq(PACKAGE_NAME_1), eq(0L), any(), anyInt()) anyInt()) ).thenReturn(appInfo); ).thenReturn(appInfo); Loading Loading @@ -760,8 +758,8 @@ public final class BackgroundInstallControlServiceTest { packages.add(packageInfo2); packages.add(packageInfo2); var packageInfo3 = makePackageInfo(PACKAGE_NAME_3); var packageInfo3 = makePackageInfo(PACKAGE_NAME_3); packages.add(packageInfo3); packages.add(packageInfo3); doReturn(new ParceledListSlice<>(packages)).when(mIPackageManager).getInstalledPackages( doReturn(packages).when(mPackageManager).getInstalledPackagesAsUser( anyLong(), anyInt()); any(), anyInt()); var resultPackages = var resultPackages = mBackgroundInstallControlService.getBackgroundInstalledPackages(0L, USER_ID_1); mBackgroundInstallControlService.getBackgroundInstalledPackages(0L, USER_ID_1); Loading Loading @@ -808,8 +806,8 @@ public final class BackgroundInstallControlServiceTest { } } @Override @Override public IPackageManager getIPackageManager() { public PackageManager getPackageManager() { return mIPackageManager; return mPackageManager; } } @Override @Override Loading Loading
services/core/java/com/android/server/pm/BackgroundInstallControlService.java +20 −37 Original line number Original line Diff line number Diff line Loading @@ -22,8 +22,6 @@ import android.app.usage.UsageStatsManagerInternal; import android.content.Context; import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.pm.ApplicationInfo; import android.content.pm.IBackgroundInstallControlService; import android.content.pm.IBackgroundInstallControlService; import android.content.pm.IPackageManager; import android.content.pm.InstallSourceInfo; import android.content.pm.PackageInfo; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager; import android.content.pm.PackageManagerInternal; import android.content.pm.PackageManagerInternal; Loading @@ -32,8 +30,6 @@ import android.os.Environment; import android.os.Handler; import android.os.Handler; import android.os.Looper; import android.os.Looper; import android.os.Message; import android.os.Message; import android.os.RemoteException; import android.os.ServiceManager; import android.os.SystemClock; import android.os.SystemClock; import android.os.UserHandle; import android.os.UserHandle; import android.util.ArraySet; import android.util.ArraySet; Loading @@ -54,6 +50,7 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.IOException; import java.util.List; import java.util.ListIterator; import java.util.ListIterator; import java.util.Set; import java.util.Set; import java.util.TreeSet; import java.util.TreeSet; Loading @@ -75,7 +72,7 @@ public class BackgroundInstallControlService extends SystemService { private final Context mContext; private final Context mContext; private final BinderService mBinderService; private final BinderService mBinderService; private final IPackageManager mIPackageManager; private final PackageManager mPackageManager; private final PackageManagerInternal mPackageManagerInternal; private final PackageManagerInternal mPackageManagerInternal; private final UsageStatsManagerInternal mUsageStatsManagerInternal; private final UsageStatsManagerInternal mUsageStatsManagerInternal; private final PermissionManagerServiceInternal mPermissionManager; private final PermissionManagerServiceInternal mPermissionManager; Loading @@ -98,7 +95,7 @@ public class BackgroundInstallControlService extends SystemService { BackgroundInstallControlService(@NonNull Injector injector) { BackgroundInstallControlService(@NonNull Injector injector) { super(injector.getContext()); super(injector.getContext()); mContext = injector.getContext(); mContext = injector.getContext(); mIPackageManager = injector.getIPackageManager(); mPackageManager = injector.getPackageManager(); mPackageManagerInternal = injector.getPackageManagerInternal(); mPackageManagerInternal = injector.getPackageManagerInternal(); mPermissionManager = injector.getPermissionManager(); mPermissionManager = injector.getPermissionManager(); mHandler = new EventHandler(injector.getLooper(), this); mHandler = new EventHandler(injector.getLooper(), this); Loading Loading @@ -131,16 +128,12 @@ public class BackgroundInstallControlService extends SystemService { @VisibleForTesting @VisibleForTesting ParceledListSlice<PackageInfo> getBackgroundInstalledPackages( ParceledListSlice<PackageInfo> getBackgroundInstalledPackages( @PackageManager.PackageInfoFlagsBits long flags, int userId) { @PackageManager.PackageInfoFlagsBits long flags, int userId) { ParceledListSlice<PackageInfo> packages; List<PackageInfo> packages = mPackageManager.getInstalledPackagesAsUser( try { PackageManager.PackageInfoFlags.of(flags), userId); packages = mIPackageManager.getInstalledPackages(flags, userId); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } initBackgroundInstalledPackages(); initBackgroundInstalledPackages(); ListIterator<PackageInfo> iter = packages.getList().listIterator(); ListIterator<PackageInfo> iter = packages.listIterator(); while (iter.hasNext()) { while (iter.hasNext()) { String packageName = iter.next().packageName; String packageName = iter.next().packageName; if (!mBackgroundInstalledPackages.contains(userId, packageName)) { if (!mBackgroundInstalledPackages.contains(userId, packageName)) { Loading @@ -148,7 +141,7 @@ public class BackgroundInstallControlService extends SystemService { } } } } return packages; return new ParceledListSlice<>(packages); } } private static class EventHandler extends Handler { private static class EventHandler extends Handler { Loading Loading @@ -181,31 +174,21 @@ public class BackgroundInstallControlService extends SystemService { } } void handlePackageAdd(String packageName, int userId) { void handlePackageAdd(String packageName, int userId) { InstallSourceInfo installSourceInfo = null; ApplicationInfo appInfo = null; try { try { installSourceInfo = mIPackageManager.getInstallSourceInfo(packageName); appInfo = mPackageManager.getApplicationInfoAsUser(packageName, } catch (RemoteException e) { PackageManager.ApplicationInfoFlags.of(0), userId); // Failed to talk to PackageManagerService Should never happen! } catch (PackageManager.NameNotFoundException e) { throw e.rethrowFromSystemServer(); Slog.w(TAG, "Package's appInfo not found " + packageName); } String installerPackageName = installSourceInfo == null ? null : installSourceInfo.getInstallingPackageName(); if (installerPackageName == null) { Slog.w(TAG, "fails to get installerPackageName for " + packageName); return; return; } } ApplicationInfo appInfo = null; String installerPackageName = null; try { try { appInfo = mIPackageManager.getApplicationInfo(packageName, installerPackageName = mPackageManager 0, userId); .getInstallSourceInfo(packageName).getInstallingPackageName(); } catch (RemoteException e) { } catch (PackageManager.NameNotFoundException e) { // Failed to talk to PackageManagerService Should never happen! Slog.w(TAG, "Package's installer not found " + packageName); throw e.rethrowFromSystemServer(); } if (appInfo == null) { Slog.w(TAG, "fails to get appInfo for " + packageName); return; return; } } Loading Loading @@ -486,7 +469,7 @@ public class BackgroundInstallControlService extends SystemService { interface Injector { interface Injector { Context getContext(); Context getContext(); IPackageManager getIPackageManager(); PackageManager getPackageManager(); PackageManagerInternal getPackageManagerInternal(); PackageManagerInternal getPackageManagerInternal(); Loading @@ -512,8 +495,8 @@ public class BackgroundInstallControlService extends SystemService { } } @Override @Override public IPackageManager getIPackageManager() { public PackageManager getPackageManager() { return IPackageManager.Stub.asInterface(ServiceManager.getService("package")); return mContext.getPackageManager(); } } @Override @Override Loading
services/tests/servicestests/src/com/android/server/pm/BackgroundInstallControlServiceTest.java +22 −24 Original line number Original line Diff line number Diff line Loading @@ -22,8 +22,8 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doReturn; Loading @@ -37,12 +37,10 @@ import android.app.usage.UsageStatsManagerInternal; import android.app.usage.UsageStatsManagerInternal.UsageEventListener; import android.app.usage.UsageStatsManagerInternal.UsageEventListener; import android.content.Context; import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.pm.ApplicationInfo; import android.content.pm.IPackageManager; import android.content.pm.InstallSourceInfo; import android.content.pm.InstallSourceInfo; import android.content.pm.PackageInfo; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager; import android.content.pm.PackageManagerInternal; import android.content.pm.PackageManagerInternal; import android.content.pm.ParceledListSlice; import android.os.FileUtils; import android.os.FileUtils; import android.os.Looper; import android.os.Looper; import android.os.RemoteException; import android.os.RemoteException; Loading Loading @@ -103,7 +101,7 @@ public final class BackgroundInstallControlServiceTest { @Mock @Mock private Context mContext; private Context mContext; @Mock @Mock private IPackageManager mIPackageManager; private PackageManager mPackageManager; @Mock @Mock private PackageManagerInternal mPackageManagerInternal; private PackageManagerInternal mPackageManagerInternal; @Mock @Mock Loading Loading @@ -538,19 +536,19 @@ public final class BackgroundInstallControlServiceTest { @Test @Test public void testHandleUsageEvent_packageAddedNoUsageEvent() throws public void testHandleUsageEvent_packageAddedNoUsageEvent() throws RemoteException, NoSuchFieldException { NoSuchFieldException, PackageManager.NameNotFoundException { assertNull(mBackgroundInstallControlService.getBackgroundInstalledPackages()); assertNull(mBackgroundInstallControlService.getBackgroundInstalledPackages()); InstallSourceInfo installSourceInfo = new InstallSourceInfo( InstallSourceInfo installSourceInfo = new InstallSourceInfo( /* initiatingPackageName = */ null, /* initiatingPackageSigningInfo = */ null, /* initiatingPackageName = */ null, /* initiatingPackageSigningInfo = */ null, /* originatingPackageName = */ null, /* originatingPackageName = */ null, /* installingPackageName = */ INSTALLER_NAME_1); /* installingPackageName = */ INSTALLER_NAME_1); assertEquals(installSourceInfo.getInstallingPackageName(), INSTALLER_NAME_1); assertEquals(installSourceInfo.getInstallingPackageName(), INSTALLER_NAME_1); when(mIPackageManager.getInstallSourceInfo(anyString())).thenReturn(installSourceInfo); when(mPackageManager.getInstallSourceInfo(anyString())).thenReturn(installSourceInfo); ApplicationInfo appInfo = mock(ApplicationInfo.class); ApplicationInfo appInfo = mock(ApplicationInfo.class); when(mIPackageManager.getApplicationInfo( when(mPackageManager.getApplicationInfoAsUser( eq(PACKAGE_NAME_1), eq(PACKAGE_NAME_1), eq(0L), any(), anyInt()) anyInt()) ).thenReturn(appInfo); ).thenReturn(appInfo); Loading @@ -574,19 +572,19 @@ public final class BackgroundInstallControlServiceTest { @Test @Test public void testHandleUsageEvent_packageAddedInsideTimeFrame() throws public void testHandleUsageEvent_packageAddedInsideTimeFrame() throws RemoteException, NoSuchFieldException { NoSuchFieldException, PackageManager.NameNotFoundException { assertNull(mBackgroundInstallControlService.getBackgroundInstalledPackages()); assertNull(mBackgroundInstallControlService.getBackgroundInstalledPackages()); InstallSourceInfo installSourceInfo = new InstallSourceInfo( InstallSourceInfo installSourceInfo = new InstallSourceInfo( /* initiatingPackageName = */ null, /* initiatingPackageSigningInfo = */ null, /* initiatingPackageName = */ null, /* initiatingPackageSigningInfo = */ null, /* originatingPackageName = */ null, /* originatingPackageName = */ null, /* installingPackageName = */ INSTALLER_NAME_1); /* installingPackageName = */ INSTALLER_NAME_1); assertEquals(installSourceInfo.getInstallingPackageName(), INSTALLER_NAME_1); assertEquals(installSourceInfo.getInstallingPackageName(), INSTALLER_NAME_1); when(mIPackageManager.getInstallSourceInfo(anyString())).thenReturn(installSourceInfo); when(mPackageManager.getInstallSourceInfo(anyString())).thenReturn(installSourceInfo); ApplicationInfo appInfo = mock(ApplicationInfo.class); ApplicationInfo appInfo = mock(ApplicationInfo.class); when(mIPackageManager.getApplicationInfo( when(mPackageManager.getApplicationInfoAsUser( eq(PACKAGE_NAME_1), eq(PACKAGE_NAME_1), eq(0L), any(), anyInt()) anyInt()) ).thenReturn(appInfo); ).thenReturn(appInfo); Loading Loading @@ -618,19 +616,19 @@ public final class BackgroundInstallControlServiceTest { @Test @Test public void testHandleUsageEvent_packageAddedOutsideTimeFrame1() throws public void testHandleUsageEvent_packageAddedOutsideTimeFrame1() throws RemoteException, NoSuchFieldException { NoSuchFieldException, PackageManager.NameNotFoundException { assertNull(mBackgroundInstallControlService.getBackgroundInstalledPackages()); assertNull(mBackgroundInstallControlService.getBackgroundInstalledPackages()); InstallSourceInfo installSourceInfo = new InstallSourceInfo( InstallSourceInfo installSourceInfo = new InstallSourceInfo( /* initiatingPackageName = */ null, /* initiatingPackageSigningInfo = */ null, /* initiatingPackageName = */ null, /* initiatingPackageSigningInfo = */ null, /* originatingPackageName = */ null, /* originatingPackageName = */ null, /* installingPackageName = */ INSTALLER_NAME_1); /* installingPackageName = */ INSTALLER_NAME_1); assertEquals(installSourceInfo.getInstallingPackageName(), INSTALLER_NAME_1); assertEquals(installSourceInfo.getInstallingPackageName(), INSTALLER_NAME_1); when(mIPackageManager.getInstallSourceInfo(anyString())).thenReturn(installSourceInfo); when(mPackageManager.getInstallSourceInfo(anyString())).thenReturn(installSourceInfo); ApplicationInfo appInfo = mock(ApplicationInfo.class); ApplicationInfo appInfo = mock(ApplicationInfo.class); when(mIPackageManager.getApplicationInfo( when(mPackageManager.getApplicationInfoAsUser( eq(PACKAGE_NAME_1), eq(PACKAGE_NAME_1), eq(0L), any(), anyInt()) anyInt()) ).thenReturn(appInfo); ).thenReturn(appInfo); Loading Loading @@ -666,19 +664,19 @@ public final class BackgroundInstallControlServiceTest { } } @Test @Test public void testHandleUsageEvent_packageAddedOutsideTimeFrame2() throws public void testHandleUsageEvent_packageAddedOutsideTimeFrame2() throws RemoteException, NoSuchFieldException { NoSuchFieldException, PackageManager.NameNotFoundException { assertNull(mBackgroundInstallControlService.getBackgroundInstalledPackages()); assertNull(mBackgroundInstallControlService.getBackgroundInstalledPackages()); InstallSourceInfo installSourceInfo = new InstallSourceInfo( InstallSourceInfo installSourceInfo = new InstallSourceInfo( /* initiatingPackageName = */ null, /* initiatingPackageSigningInfo = */ null, /* initiatingPackageName = */ null, /* initiatingPackageSigningInfo = */ null, /* originatingPackageName = */ null, /* originatingPackageName = */ null, /* installingPackageName = */ INSTALLER_NAME_1); /* installingPackageName = */ INSTALLER_NAME_1); assertEquals(installSourceInfo.getInstallingPackageName(), INSTALLER_NAME_1); assertEquals(installSourceInfo.getInstallingPackageName(), INSTALLER_NAME_1); when(mIPackageManager.getInstallSourceInfo(anyString())).thenReturn(installSourceInfo); when(mPackageManager.getInstallSourceInfo(anyString())).thenReturn(installSourceInfo); ApplicationInfo appInfo = mock(ApplicationInfo.class); ApplicationInfo appInfo = mock(ApplicationInfo.class); when(mIPackageManager.getApplicationInfo( when(mPackageManager.getApplicationInfoAsUser( eq(PACKAGE_NAME_1), eq(PACKAGE_NAME_1), eq(0L), any(), anyInt()) anyInt()) ).thenReturn(appInfo); ).thenReturn(appInfo); Loading Loading @@ -760,8 +758,8 @@ public final class BackgroundInstallControlServiceTest { packages.add(packageInfo2); packages.add(packageInfo2); var packageInfo3 = makePackageInfo(PACKAGE_NAME_3); var packageInfo3 = makePackageInfo(PACKAGE_NAME_3); packages.add(packageInfo3); packages.add(packageInfo3); doReturn(new ParceledListSlice<>(packages)).when(mIPackageManager).getInstalledPackages( doReturn(packages).when(mPackageManager).getInstalledPackagesAsUser( anyLong(), anyInt()); any(), anyInt()); var resultPackages = var resultPackages = mBackgroundInstallControlService.getBackgroundInstalledPackages(0L, USER_ID_1); mBackgroundInstallControlService.getBackgroundInstalledPackages(0L, USER_ID_1); Loading Loading @@ -808,8 +806,8 @@ public final class BackgroundInstallControlServiceTest { } } @Override @Override public IPackageManager getIPackageManager() { public PackageManager getPackageManager() { return mIPackageManager; return mPackageManager; } } @Override @Override Loading