UpdateManager { protected static boolean installedFromMarket(WeakReference<? extends Context> weakContext) { boolean result = false; Context context = weakContext.get(); if (context != null) { try { String installer = context.getPackageManager().getInstallerPackageName(context.getPackageName()); if (!TextUtils.isEmpty(installer)) { result = true; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && (TextUtils.equals(installer, INSTALLER_PACKAGE_INSTALLER_NOUGAT) || TextUtils.equals(installer, INSTALLER_PACKAGE_INSTALLER_NOUGAT2))) { result = false; } if (TextUtils.equals(installer, INSTALLER_ADB)) { result = false; } } } catch (Throwable ignored) { } } return result; }  static void register(Activity activity); static void register(Activity activity, UpdateManagerListener listener); static void register(Activity activity, String appIdentifier); static void register(Activity activity, String appIdentifier, boolean isDialogRequired); static void register(Activity activity, String appIdentifier, UpdateManagerListener listener); static void register(Activity activity, String appIdentifier, UpdateManagerListener listener, boolean isDialogRequired); static void register(Activity activity, String urlString, String appIdentifier, UpdateManagerListener listener); static void register(Activity activity, String urlString, String appIdentifier, UpdateManagerListener listener, boolean isDialogRequired); static void registerForBackground(Context appContext, String appIdentifier, UpdateManagerListener listener); static void registerForBackground(Context appContext, String urlString, String appIdentifier, UpdateManagerListener listener); static void unregister(); static final String INSTALLER_ADB; static final String INSTALLER_PACKAGE_INSTALLER_NOUGAT; static final String INSTALLER_PACKAGE_INSTALLER_NOUGAT2; }
@Test public void testInstalledViaADBDefault() { when(mockPackageManager.getInstallerPackageName(any(String.class))).thenReturn(null); assertFalse(UpdateManager.installedFromMarket(contextWeakReference)); when(mockPackageManager.getInstallerPackageName(any(String.class))).thenReturn(""); assertFalse(UpdateManager.installedFromMarket(contextWeakReference)); Whitebox.setInternalState(Build.VERSION.class, "SDK_INT", Build.VERSION_CODES.N); assertFalse(UpdateManager.installedFromMarket(contextWeakReference)); }
@Test public void testInstalledViaGooglePlay() { when(mockPackageManager.getInstallerPackageName(any(String.class))).thenReturn("com.google.play"); assertTrue(UpdateManager.installedFromMarket(contextWeakReference)); Whitebox.setInternalState(Build.VERSION.class, "SDK_INT", Build.VERSION_CODES.N); assertTrue(UpdateManager.installedFromMarket(contextWeakReference)); }
@Test public void testInstalledViaADBXiaomi() { when(mockPackageManager.getInstallerPackageName(any(String.class))).thenReturn("adb"); assertFalse(UpdateManager.installedFromMarket(contextWeakReference)); Whitebox.setInternalState(Build.VERSION.class, "SDK_INT", Build.VERSION_CODES.N); assertFalse(UpdateManager.installedFromMarket(contextWeakReference)); }
@Test public void testInstalledViaPackageManagerNougat() { when(mockPackageManager.getInstallerPackageName(any(String.class))).thenReturn("com.google.android.packageinstaller"); assertTrue(UpdateManager.installedFromMarket(contextWeakReference)); Whitebox.setInternalState(Build.VERSION.class, "SDK_INT", Build.VERSION_CODES.N); assertFalse(UpdateManager.installedFromMarket(contextWeakReference)); }
@Test public void testInstalledViaPackageManagerNougat2() { when(mockPackageManager.getInstallerPackageName(any(String.class))).thenReturn("com.android.packageinstaller"); assertTrue(UpdateManager.installedFromMarket(contextWeakReference)); Whitebox.setInternalState(Build.VERSION.class, "SDK_INT", Build.VERSION_CODES.N); assertFalse(UpdateManager.installedFromMarket(contextWeakReference)); }