4

I am trying to uninstall the piracy application. I don't have the following imports in my sdk .

 import android.app.PackageDeleteObserver;
import android.content.pm.IPackageDeleteObserver;

So i got the interface IPackageDeleteObserver from here https://github.com/android/platform_frameworks_base/blob/master/core/java/android/content/pm/IPackageInstallObserver2.aidl which i placed in the android/content/pm but my android studio does not detect it. Dropdown does not show android.content.pm.IPackageDeleteObserver . Does anybody knows how to solve these imports?

Here it's the whole code:

  package com.vivek.light.utils;

/**
 * Created by Shiva on 24-07-2015.
 */
import android.app.PackageDeleteObserver;
import android.content.pm.IPackageDeleteObserver;

import android.content.pm.PackageManager;
import android.os.RemoteException;
import android.util.Log;

import java.lang.reflect.Method;

import static com.vivek.light.utils.AntiPiracyConstants.*;

public class AntiPiracyUtils {

    static final String TAG = "ANTI-PIRACY: Utilities";

    private static PackageDeleteObserver sPDO;

    private AntiPiracyUtils() {
        sPDO = getPackageDeleteObserver();
    }

    private static Class<?>[] UNINSTALLTYPES = new Class[] {
            String.class, IPackageDeleteObserver.class, int.class
    };

    public static class PackageDeleteObserver extends IPackageDeleteObserver.stub  {
        public void packageDeleted(String packageName, int returnCode) throws RemoteException {
            if (DEBUG) Log.i(TAG, "PackageDeleteObserver: " + packageName + " removed");
        }
    }

    public static PackageDeleteObserver getPackageDeleteObserver() {
        if (sPDO == null) sPDO = new PackageDeleteObserver();
        return sPDO;
    }

    public static Method getUninstallTypes(PackageManager pm) throws NoSuchMethodException {
        try {
            return pm.getClass().getMethod("deletePackage", UNINSTALLTYPES);
        } catch (NoSuchMethodException WTF) {
            Log.e(TAG, "NoSuchMethodException" + l);
        }
        return null;
    }
}
Vivek_Neel
  • 1,343
  • 1
  • 14
  • 25

0 Answers0