Java Code Examples for android.content.pm.IPackageInstallObserver

The following are top voted examples for showing how to use android.content.pm.IPackageInstallObserver. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: aptoide-client-v8   File: SystemInstallOnSubscribe.java   View source code 8 votes vote down vote up
@Override public void call(Subscriber<? super Void> subscriber) {
  final IPackageInstallObserver.Stub silentObserver = new IPackageInstallObserver.Stub() {
    @Override public void packageInstalled(String packageName, int returnCode)
        throws RemoteException {
      if (returnCode == INSTALL_SUCCEEDED) {
        if (!subscriber.isUnsubscribed()) {
          subscriber.onNext(null);
          subscriber.onCompleted();
        }
      } else {
        if (!subscriber.isUnsubscribed()) {
          subscriber.onError(
              new InstallationException("Package not installed with error code: " + returnCode));
        }
      }
    }
  };

  if (isSystem(context)) {
    try {
      Method installPackage = packageManager.getClass()
          .getMethod("installPackage", Uri.class, IPackageInstallObserver.class, int.class,
              String.class);
      Object[] params = new Object[] { packageUri, silentObserver, INSTALL_REPLACE_EXISTING, "" };
      installPackage.invoke(packageManager, params);
    } catch (Exception e) {
      if (!subscriber.isUnsubscribed()) {
        subscriber.onError(new InstallationException(e));
      }
    }
  } else {
    if (!subscriber.isUnsubscribed()) {
      subscriber.onError(new InstallationException("Aptoide does not hold system privilege!"));
    }
  }
}
 
Example 2
Project: fdroid   File: PrivilegedService.java   View source code 6 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();

    // get internal methods via reflection
    try {
        Class<?>[] installTypes = {
            Uri.class, IPackageInstallObserver.class, int.class,
            String.class,
        };
        Class<?>[] deleteTypes = {
            String.class, IPackageDeleteObserver.class,
            int.class,
        };

        PackageManager pm = getPackageManager();
        mInstallMethod = pm.getClass().getMethod("installPackage", installTypes);
        mDeleteMethod = pm.getClass().getMethod("deletePackage", deleteTypes);
    } catch (NoSuchMethodException e) {
        Log.e(TAG, "Android not compatible!", e);
        stopSelf();
    }
}
 
Example 3
Project: AppHub   File: PrivilegedService.java   View source code 6 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();

    // get internal methods via reflection
    try {
        Class<?>[] installTypes = {
            Uri.class, IPackageInstallObserver.class, int.class,
            String.class,
        };
        Class<?>[] deleteTypes = {
            String.class, IPackageDeleteObserver.class,
            int.class,
        };

        PackageManager pm = getPackageManager();
        mInstallMethod = pm.getClass().getMethod("installPackage", installTypes);
        mDeleteMethod = pm.getClass().getMethod("deletePackage", deleteTypes);
    } catch (NoSuchMethodException e) {
        Log.e(TAG, "Android not compatible!", e);
        stopSelf();
    }
}
 
Example 4
Project: f-droid   File: SystemInstaller.java   View source code 6 votes vote down vote up
public SystemInstaller(Context context, PackageManager pm,
        InstallerCallback callback) throws AndroidNotCompatibleException {
    super(context, pm, callback);

    // create internal callbacks
    mInstallObserver = new PackageInstallObserver();
    mDeleteObserver = new PackageDeleteObserver();

    try {
        Class<?>[] installTypes = new Class[] {
                Uri.class, IPackageInstallObserver.class, int.class,
                String.class
        };
        Class<?>[] deleteTypes = new Class[] {
                String.class, IPackageDeleteObserver.class,
                int.class
        };

        mInstallMethod = mPm.getClass().getMethod("installPackage", installTypes);
        mDeleteMethod = mPm.getClass().getMethod("deletePackage", deleteTypes);
    } catch (NoSuchMethodException e) {
        throw new AndroidNotCompatibleException(e);
    }
}
 
Example 5
Project: SlienceInstall   File: PM.java   View source code 5 votes vote down vote up
/**
 * 适配 5.0以下系统
 * 
 * @param path
 * @param iInstallerCallback
 * @throws Exception
 */
private void installPackageLowApi(String path, final IInstallerCallback iInstallerCallback) throws Exception {
	final Uri uri = Uri.parse(path);
	final int flags = PMFlags.INSTALL_REPLACE_EXISTING;
	final PackageInstallObserver observer = new PackageInstallObserver(iInstallerCallback);
	final IPackageManager ipm = getIPackageManager();
	RefInvoke.invokeMethodWithException(ipm.getClass(), "installPackage", ipm, new Class[] { Uri.class, IPackageInstallObserver.class, int.class, String.class }, new Object[] { uri, observer, flags, null });
}
 
Example 6
Project: SlienceInstall   File: PM.java   View source code 5 votes vote down vote up
/**
 * 适配 5.0以下系统
 * 
 * @param path
 * @param iInstallerCallback
 * @throws Exception
 */
private void installPackageLowApi(String path, final IInstallerCallback iInstallerCallback) throws Exception {
	final Uri uri = Uri.parse(path);
	final int flags = PMFlags.INSTALL_REPLACE_EXISTING;
	final PackageInstallObserver observer = new PackageInstallObserver(iInstallerCallback);
	final IPackageManager ipm = getIPackageManager();
	RefInvoke.invokeMethodWithException(ipm.getClass(), "installPackage", ipm, new Class[] { Uri.class, IPackageInstallObserver.class, int.class, String.class }, new Object[] { uri, observer, flags, null });
}
 
Example 7
Project: Demo_Public   File: ApplicationManager.java   View source code 5 votes vote down vote up
public ApplicationManager(Context context) throws SecurityException, NoSuchMethodException {
	
       observer = new PackageInstallObserver();
       observerdelete = new PackageDeleteObserver(); 
       pm = context.getPackageManager();
       
       Class<?>[] types = new Class[] {Uri.class, IPackageInstallObserver.class, int.class, String.class};
       Class<?>[] uninstalltypes = new Class[] {String.class, IPackageDeleteObserver.class, int.class};
       
	method = pm.getClass().getMethod("installPackage", types);
	uninstallmethod = pm.getClass().getMethod("deletePackage", uninstalltypes);
}
 
Example 8
Project: GLAppManager   File: ApplicationManager.java   View source code 5 votes vote down vote up
public ApplicationManager(Context context) throws SecurityException, NoSuchMethodException {
    observer = new PackageInstallObserver();
    pm = context.getPackageManager();

    // 파라미터 설정
    Class<?>[] types = new Class[]{Uri.class, IPackageInstallObserver.class, int.class, String.class};
    // installPackage 이름 붙은거와 위 types 라는 파라미터를 담은 메소드를 찾음
    method = pm.getClass().getMethod("installPackage", types);
}
 
Example 9
Project: FMTech   File: PackageManagerHelper.java   View source code 4 votes vote down vote up
public static void installPackage(Context paramContext, Uri paramUri, PackageInstallObserver paramPackageInstallObserver, int paramInt)
{
  IPackageInstallObserver.Stub local1 = new IPackageInstallObserver.Stub()
  {
    public final void packageInstalled(String paramAnonymousString, int paramAnonymousInt)
    {
      if (this.val$observer != null) {
        this.val$observer.packageInstalled(paramAnonymousString, paramAnonymousInt);
      }
    }
  };
  try
  {
    Class[] arrayOfClass = new Class[4];
    arrayOfClass[0] = Uri.class;
    arrayOfClass[1] = IPackageInstallObserver.class;
    arrayOfClass[2] = Integer.TYPE;
    arrayOfClass[3] = String.class;
    Method localMethod = PackageManager.class.getMethod("installPackage", arrayOfClass);
    PackageManager localPackageManager = paramContext.getPackageManager();
    Object[] arrayOfObject = new Object[4];
    arrayOfObject[0] = paramUri;
    arrayOfObject[1] = local1;
    arrayOfObject[2] = Integer.valueOf(paramInt);
    arrayOfObject[3] = "com.android.vending";
    localMethod.invoke(localPackageManager, arrayOfObject);
    return;
  }
  catch (NoSuchMethodException localNoSuchMethodException)
  {
    FinskyLog.d("Cannot install packages on this platform", new Object[0]);
    return;
  }
  catch (SecurityException localSecurityException)
  {
    FinskyLog.wtf(localSecurityException, "Cannot install packages due to security exception", new Object[0]);
    return;
  }
  catch (IllegalAccessException localIllegalAccessException)
  {
    FinskyLog.wtf(localIllegalAccessException, "Cannot install packages due to reflection access exception", new Object[0]);
    return;
  }
  catch (InvocationTargetException localInvocationTargetException)
  {
    FinskyLog.wtf(localInvocationTargetException, "Cannot install packages due to reflection invocation exception", new Object[0]);
  }
}
 
Example 10
Project: FullRobolectricTestSample   File: StubPackageManager.java   View source code 2 votes vote down vote up
@Override
public void installPackage(Uri packageURI, IPackageInstallObserver observer, int flags, String installerPackageName) {

}
 
Example 11
Project: FullRobolectricTestSample   File: StubPackageManager.java   View source code 2 votes vote down vote up
@Override
public void installPackageWithVerification(Uri packageURI, IPackageInstallObserver observer, int flags, String installerPackageName, Uri verificationURI, ManifestDigest manifestDigest, ContainerEncryptionParams encryptionParams) {

}
 
Example 12
Project: FullRobolectricTestSample   File: StubPackageManager.java   View source code 2 votes vote down vote up
@Override
public void installPackageWithVerificationAndEncryption(Uri packageURI, IPackageInstallObserver observer, int flags, String installerPackageName, VerificationParams verificationParams, ContainerEncryptionParams encryptionParams) {

}