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

项目:BlockCanaryEx    文件:TestUtil.java   
public static void testProvide() {
    IPackageDataObserver packageDataObserver = new IPackageDataObserver() {
        @Override
        public void onRemoveCompleted(String s, boolean b) throws RemoteException {
            doHeavyWork();
            doHeavyWork();
        }

        @Override
        public IBinder asBinder() {
            return null;
        }
    };
    try {
        packageDataObserver.onRemoveCompleted("haha", false);
    } catch (RemoteException e) {
        e.printStackTrace();
    }
    doHeavyWork();
}
项目:MemoryCleaner    文件:CleanerService.java   
@Override protected Long doInBackground(Void... params) {
    final CountDownLatch countDownLatch = new CountDownLatch(1);

    StatFs stat = new StatFs(
            Environment.getDataDirectory().getAbsolutePath());

    try {
        mFreeStorageAndNotifyMethod.invoke(getPackageManager(),
                (long) stat.getBlockCount() *
                        (long) stat.getBlockSize(),
                new IPackageDataObserver.Stub() {
                    @Override
                    public void onRemoveCompleted(String packageName, boolean succeeded)
                            throws RemoteException {
                        countDownLatch.countDown();
                    }
                });

        countDownLatch.await();
    } catch (InvocationTargetException | InterruptedException | IllegalAccessException e) {
        e.printStackTrace();
    }

    return mCacheSize;
}
项目:MemoryCleaner    文件:CleanerService.java   
@Override public void onCreate() {
    try {
        mGetPackageSizeInfoMethod = getPackageManager().getClass()
                                                       .getMethod(
                                                               "getPackageSizeInfo",
                                                               String.class,
                                                               IPackageStatsObserver.class);

        mFreeStorageAndNotifyMethod = getPackageManager().getClass()
                                                         .getMethod(
                                                                 "freeStorageAndNotify",
                                                                 long.class,
                                                                 IPackageDataObserver.class);
        mDeleteApplicationCacheFiles = getPackageManager().getClass()
                                                          .getMethod(
                                                                  "deleteApplicationCacheFiles",
                                                                  String.class,
                                                                  IPackageDataObserver.class);
    } catch (NoSuchMethodException e) {
        e.printStackTrace();
    }
}
项目:MobileGuard    文件:AppManagerEngine.java   
/**
 * clear all app cache
 * @param context
 * @param listener the completion listener, it can be null if you don't care the result.
 *                 onClearCompleted run on child thread.
 *                 onClearFailed run on UI thread.
 */
public static void clearAllCache(Context context, final ClearCacheListener listener) {
    /*
    public void freeStorageAndNotify(long freeStorageSize, IPackageDataObserver observer) {
        freeStorageAndNotify(null, freeStorageSize, observer);
    }
     */
    PackageManager pm = context.getPackageManager();
    try {
        Method freeStorageAndNotify = pm.getClass().getDeclaredMethod("freeStorageAndNotify", long.class, IPackageDataObserver.class);
        freeStorageAndNotify.invoke(pm, Long.MAX_VALUE, new IPackageDataObserver.Stub(){
            @Override
            public void onRemoveCompleted(String packageName, boolean succeeded) throws RemoteException {
                if(null != listener)
                    listener.onClearCompleted();
            }
        });

    } catch (Exception e) {
        e.printStackTrace();
        if(null != listener)
            listener.onClearFailed();
    }
}
项目:PhoneMate    文件:CleanerService.java   
@Override
protected Long doInBackground(Void... params) {
    final CountDownLatch countDownLatch = new CountDownLatch(1);

    StatFs stat = new StatFs(Environment.getDataDirectory().getAbsolutePath());

    try {
        mFreeStorageAndNotifyMethod.invoke(getPackageManager(),
                (long) stat.getBlockCount() * (long) stat.getBlockSize(),
                new IPackageDataObserver.Stub() {
                    @Override
                    public void onRemoveCompleted(String packageName, boolean succeeded)
                            throws RemoteException {
                        countDownLatch.countDown();
                    }
                }
        );

        countDownLatch.await();
    } catch (InvocationTargetException | InterruptedException | IllegalAccessException e) {
        e.printStackTrace();
    }

    return mCacheSize;
}
项目:safety    文件:CleanCacheActivity.java   
/**
 * ����¼���һ��������
 */
public void cleanAll(View view) {
    try {
        Method method = PackageManager.class.getDeclaredMethod(
                "freeStorageAndNotify", long.class,
                IPackageDataObserver.class);
        // ����Ҫ�ͷŵĿռ��С
        long localLong = Long.valueOf(getEnviromenSize() - 1L);
        // method.invoke(pm, localLong, new MyIPackageDataObserver());
        // ֱ�Ӹ�һ��Long.MAX_VALUEҲ��
        method.invoke(pm, Long.MAX_VALUE, new MyIPackageDataObserver());
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    Toast.makeText(context, "ȫ��������", Toast.LENGTH_LONG).show();
    fillData();
}
项目:VirtualHook    文件:MethodProxies.java   
@Override
public Object call(Object who, Method method, Object... args) throws Throwable {
    if (args[args.length - 1] instanceof IPackageDataObserver) {
        IPackageDataObserver observer = (IPackageDataObserver) args[args.length - 1];
        observer.onRemoveCompleted(null, true);
    }
    return 0;
}
项目:TPlayer    文件:MethodProxies.java   
@Override
public Object call(Object who, Method method, Object... args) throws Throwable {
    if (args[args.length - 1] instanceof IPackageDataObserver) {
        IPackageDataObserver observer = (IPackageDataObserver) args[args.length - 1];
        observer.onRemoveCompleted(null, true);
    }
    return 0;
}
项目:mobilesafe    文件:CacheClearActivity.java   
private void initUI() {
    bt_clear = (Button) findViewById(R.id.bt_clear);
    pb_bar = (ProgressBar) findViewById(R.id.pb_bar);
    tv_name = (TextView) findViewById(R.id.tv_name);
    ll_add_text = (LinearLayout) findViewById(R.id.ll_add_text);

    bt_clear.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            //1.��ȡָ������ֽ����ļ�
            try {
                Class<?> clazz = Class.forName("android.content.pm.PackageManager");
                //2.��ȡ���÷�������
                Method method = clazz.getMethod("freeStorageAndNotify", long.class,IPackageDataObserver.class);
                //3.��ȡ������÷���
                method.invoke(mPm, Long.MAX_VALUE,new IPackageDataObserver.Stub() {
                    @Override
                    public void onRemoveCompleted(String packageName, boolean succeeded)
                            throws RemoteException {
                        //���������ɺ���õķ���(����Ȩ��)
                        Message msg = Message.obtain();
                        msg.what = CLEAR_CACHE;
                        mHandler.sendMessage(msg);
                    }
                });
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}
项目:PhoneMate    文件:CleanerService.java   
@Override
public void onCreate() {
    try {
        mGetPackageSizeInfoMethod = getPackageManager().getClass()
                .getMethod("getPackageSizeInfo", String.class,
                        IPackageStatsObserver.class);

        mFreeStorageAndNotifyMethod = getPackageManager().getClass()
                .getMethod("freeStorageAndNotify", long.class,
                        IPackageDataObserver.class);
    } catch (NoSuchMethodException e) {
        e.printStackTrace();
    }
}
项目:android-cache-cleaner    文件:CleanerService.java   
@Override
public void onCreate() {
    try {
        mGetPackageSizeInfoMethod = getPackageManager().getClass().getMethod(
                "getPackageSizeInfo", String.class, IPackageStatsObserver.class);

        mFreeStorageAndNotifyMethod = getPackageManager().getClass().getMethod(
                "freeStorageAndNotify", long.class, IPackageDataObserver.class);
    } catch (NoSuchMethodException e) {
        e.printStackTrace();
    }
}
项目:MiPushFramework    文件:PackageManagerWrapper.java   
/** @hide */
@Override public void clearApplicationUserData(String packageName, IPackageDataObserver observer) {
    mBase.clearApplicationUserData(packageName, observer);
}
项目:MiPushFramework    文件:PackageManagerWrapper.java   
/** @hide */
@Override public void deleteApplicationCacheFiles(String packageName, IPackageDataObserver observer) {
    mBase.deleteApplicationCacheFiles(packageName, observer);
}
项目:MiPushFramework    文件:PackageManagerWrapper.java   
/** @hide */
@Override public void deleteApplicationCacheFilesAsUser(String packageName, int userId, IPackageDataObserver observer) {
    mBase.deleteApplicationCacheFilesAsUser(packageName, userId, observer);
}
项目:MiPushFramework    文件:PackageManagerWrapper.java   
/** @hide */
@Override public void freeStorageAndNotify(long freeStorageSize, IPackageDataObserver observer) {
    mBase.freeStorageAndNotify(freeStorageSize, observer);
}
项目:MiPushFramework    文件:PackageManagerWrapper.java   
/** @hide */
@Override public void freeStorageAndNotify(String volumeUuid, long freeStorageSize, IPackageDataObserver observer) {
    mBase.freeStorageAndNotify(volumeUuid, freeStorageSize, observer);
}
项目:condom    文件:PackageManagerWrapper.java   
/** @hide */
@Override public void clearApplicationUserData(String packageName, IPackageDataObserver observer) {
    mBase.clearApplicationUserData(packageName, observer);
}
项目:condom    文件:PackageManagerWrapper.java   
/** @hide */
@Override public void deleteApplicationCacheFiles(String packageName, IPackageDataObserver observer) {
    mBase.deleteApplicationCacheFiles(packageName, observer);
}
项目:condom    文件:PackageManagerWrapper.java   
/** @hide */
@Override public void deleteApplicationCacheFilesAsUser(String packageName, int userId, IPackageDataObserver observer) {
    mBase.deleteApplicationCacheFilesAsUser(packageName, userId, observer);
}
项目:condom    文件:PackageManagerWrapper.java   
/** @hide */
@Override public void freeStorageAndNotify(long freeStorageSize, IPackageDataObserver observer) {
    mBase.freeStorageAndNotify(freeStorageSize, observer);
}
项目:condom    文件:PackageManagerWrapper.java   
/** @hide */
@Override public void freeStorageAndNotify(String volumeUuid, long freeStorageSize, IPackageDataObserver observer) {
    mBase.freeStorageAndNotify(volumeUuid, freeStorageSize, observer);
}
项目:FullRobolectricTestSample    文件:StubPackageManager.java   
@Override
public void clearApplicationUserData(String packageName, IPackageDataObserver observer) {

}
项目:FullRobolectricTestSample    文件:StubPackageManager.java   
@Override
public void deleteApplicationCacheFiles(String packageName, IPackageDataObserver observer) {

}
项目:FullRobolectricTestSample    文件:StubPackageManager.java   
@Override
public void freeStorageAndNotify(long freeStorageSize, IPackageDataObserver observer) {

}