Java 类android.content.pm.IPackageInstallObserver 实例源码

项目:fdroid    文件:PrivilegedService.java   
@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();
    }
}
项目:AppHub    文件:PrivilegedService.java   
@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();
    }
}
项目:f-droid    文件:SystemInstaller.java   
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);
    }
}
项目:SlienceInstall    文件:PM.java   
/**
 * 适配 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 });
}
项目:SlienceInstall    文件:PM.java   
/**
 * 适配 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 });
}
项目:Demo_Public    文件:ApplicationManager.java   
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);
}
项目:aptoide-client-v8    文件:SystemInstallOnSubscribe.java   
@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!"));
    }
  }
}
项目:GLAppManager    文件:ApplicationManager.java   
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);
}
项目:FMTech    文件:PackageManagerHelper.java   
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]);
  }
}
项目:FullRobolectricTestSample    文件:StubPackageManager.java   
@Override
public void installPackage(Uri packageURI, IPackageInstallObserver observer, int flags, String installerPackageName) {

}
项目:FullRobolectricTestSample    文件:StubPackageManager.java   
@Override
public void installPackageWithVerification(Uri packageURI, IPackageInstallObserver observer, int flags, String installerPackageName, Uri verificationURI, ManifestDigest manifestDigest, ContainerEncryptionParams encryptionParams) {

}
项目:FullRobolectricTestSample    文件:StubPackageManager.java   
@Override
public void installPackageWithVerificationAndEncryption(Uri packageURI, IPackageInstallObserver observer, int flags, String installerPackageName, VerificationParams verificationParams, ContainerEncryptionParams encryptionParams) {

}