Java Code Examples for android.content.pm.IPackageDataObserver

The following are top voted examples for showing how to use android.content.pm.IPackageDataObserver. 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: BlockCanaryEx   File: TestUtil.java   View source code 6 votes vote down vote up
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();
}
 
Example 2
Project: MemoryCleaner   File: CleanerService.java   View source code 6 votes vote down vote up
@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;
}
 
Example 3
Project: MemoryCleaner   File: CleanerService.java   View source code 6 votes vote down vote up
@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();
    }
}
 
Example 4
Project: MobileGuard   File: AppManagerEngine.java   View source code 6 votes vote down vote up
/**
 * 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();
    }
}
 
Example 5
Project: PhoneMate   File: CleanerService.java   View source code 6 votes vote down vote up
@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;
}
 
Example 6
Project: safety   File: CleanCacheActivity.java   View source code 6 votes vote down vote up
/**
 * ����¼���һ��������
 */
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();
}
 
Example 7
Project: VirtualHook   File: MethodProxies.java   View source code 5 votes vote down vote up
@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;
}
 
Example 8
Project: TPlayer   File: MethodProxies.java   View source code 5 votes vote down vote up
@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;
}
 
Example 9
Project: mobilesafe   File: CacheClearActivity.java   View source code 5 votes vote down vote up
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();
			}
		}
	});
}
 
Example 10
Project: PhoneMate   File: CleanerService.java   View source code 5 votes vote down vote up
@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();
	}
}
 
Example 11
Project: android-cache-cleaner   File: CleanerService.java   View source code 5 votes vote down vote up
@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();
    }
}
 
Example 12
Project: MiPushFramework   File: PackageManagerWrapper.java   View source code 4 votes vote down vote up
/** @hide */
@Override public void clearApplicationUserData(String packageName, IPackageDataObserver observer) {
	mBase.clearApplicationUserData(packageName, observer);
}
 
Example 13
Project: MiPushFramework   File: PackageManagerWrapper.java   View source code 4 votes vote down vote up
/** @hide */
@Override public void deleteApplicationCacheFiles(String packageName, IPackageDataObserver observer) {
	mBase.deleteApplicationCacheFiles(packageName, observer);
}
 
Example 14
Project: MiPushFramework   File: PackageManagerWrapper.java   View source code 4 votes vote down vote up
/** @hide */
@Override public void deleteApplicationCacheFilesAsUser(String packageName, int userId, IPackageDataObserver observer) {
	mBase.deleteApplicationCacheFilesAsUser(packageName, userId, observer);
}
 
Example 15
Project: MiPushFramework   File: PackageManagerWrapper.java   View source code 4 votes vote down vote up
/** @hide */
@Override public void freeStorageAndNotify(long freeStorageSize, IPackageDataObserver observer) {
	mBase.freeStorageAndNotify(freeStorageSize, observer);
}
 
Example 16
Project: MiPushFramework   File: PackageManagerWrapper.java   View source code 4 votes vote down vote up
/** @hide */
@Override public void freeStorageAndNotify(String volumeUuid, long freeStorageSize, IPackageDataObserver observer) {
	mBase.freeStorageAndNotify(volumeUuid, freeStorageSize, observer);
}
 
Example 17
Project: condom   File: PackageManagerWrapper.java   View source code 4 votes vote down vote up
/** @hide */
@Override public void clearApplicationUserData(String packageName, IPackageDataObserver observer) {
	mBase.clearApplicationUserData(packageName, observer);
}
 
Example 18
Project: condom   File: PackageManagerWrapper.java   View source code 4 votes vote down vote up
/** @hide */
@Override public void deleteApplicationCacheFiles(String packageName, IPackageDataObserver observer) {
	mBase.deleteApplicationCacheFiles(packageName, observer);
}
 
Example 19
Project: condom   File: PackageManagerWrapper.java   View source code 4 votes vote down vote up
/** @hide */
@Override public void deleteApplicationCacheFilesAsUser(String packageName, int userId, IPackageDataObserver observer) {
	mBase.deleteApplicationCacheFilesAsUser(packageName, userId, observer);
}
 
Example 20
Project: condom   File: PackageManagerWrapper.java   View source code 4 votes vote down vote up
/** @hide */
@Override public void freeStorageAndNotify(long freeStorageSize, IPackageDataObserver observer) {
	mBase.freeStorageAndNotify(freeStorageSize, observer);
}
 
Example 21
Project: condom   File: PackageManagerWrapper.java   View source code 4 votes vote down vote up
/** @hide */
@Override public void freeStorageAndNotify(String volumeUuid, long freeStorageSize, IPackageDataObserver observer) {
	mBase.freeStorageAndNotify(volumeUuid, freeStorageSize, observer);
}
 
Example 22
Project: FullRobolectricTestSample   File: StubPackageManager.java   View source code 2 votes vote down vote up
@Override
public void clearApplicationUserData(String packageName, IPackageDataObserver observer) {

}
 
Example 23
Project: FullRobolectricTestSample   File: StubPackageManager.java   View source code 2 votes vote down vote up
@Override
public void deleteApplicationCacheFiles(String packageName, IPackageDataObserver observer) {

}
 
Example 24
Project: FullRobolectricTestSample   File: StubPackageManager.java   View source code 2 votes vote down vote up
@Override
public void freeStorageAndNotify(long freeStorageSize, IPackageDataObserver observer) {

}