android.content.pm.IPackageDataObserver Java Examples

The following examples show how to use android.content.pm.IPackageDataObserver. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AppManagerEngine.java    From MobileGuard with MIT License 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 #2
Source File: CleanerService.java    From MemoryCleaner with Apache License 2.0 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 #3
Source File: CleanerService.java    From MemoryCleaner with Apache License 2.0 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 #4
Source File: TestUtil.java    From BlockCanaryEx with Apache License 2.0 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 #5
Source File: ApplicationPackageManager.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
@Override
public void deleteApplicationCacheFilesAsUser(String packageName, int userId,
        IPackageDataObserver observer) {
    try {
        mPM.deleteApplicationCacheFilesAsUser(packageName, userId, observer);
    } catch (RemoteException e) {
        throw e.rethrowFromSystemServer();
    }
}
 
Example #6
Source File: ApplicationPackageManager.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
@Override
public void clearApplicationUserData(String packageName,
                                     IPackageDataObserver observer) {
    try {
        mPM.clearApplicationUserData(packageName, observer, mContext.getUserId());
    } catch (RemoteException e) {
        throw e.rethrowFromSystemServer();
    }
}
 
Example #7
Source File: ApplicationPackageManager.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
@Override
public void clearApplicationUserData(String packageName,
                                     IPackageDataObserver observer) {
    try {
        mPM.clearApplicationUserData(packageName, observer, mContext.getUserId());
    } catch (RemoteException e) {
        throw e.rethrowFromSystemServer();
    }
}
 
Example #8
Source File: ApplicationPackageManager.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
@Override
public void deleteApplicationCacheFilesAsUser(String packageName, int userId,
        IPackageDataObserver observer) {
    try {
        mPM.deleteApplicationCacheFilesAsUser(packageName, userId, observer);
    } catch (RemoteException e) {
        throw e.rethrowFromSystemServer();
    }
}
 
Example #9
Source File: ApplicationPackageManager.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
@Override
public void freeStorageAndNotify(String volumeUuid, long idealStorageSize,
        IPackageDataObserver observer) {
    try {
        mPM.freeStorageAndNotify(volumeUuid, idealStorageSize, 0, observer);
    } catch (RemoteException e) {
        throw e.rethrowFromSystemServer();
    }
}
 
Example #10
Source File: ActivityManager.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
/**
 * @hide
 */
@RequiresPermission(anyOf={Manifest.permission.CLEAR_APP_USER_DATA,
        Manifest.permission.ACCESS_INSTANT_APPS})
public boolean clearApplicationUserData(String packageName, IPackageDataObserver observer) {
    try {
        return getService().clearApplicationUserData(packageName,
                observer, UserHandle.myUserId());
    } catch (RemoteException e) {
        throw e.rethrowFromSystemServer();
    }
}
 
Example #11
Source File: ApplicationPackageManager.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
@Override
public void clearApplicationUserData(String packageName,
                                     IPackageDataObserver observer) {
    try {
        mPM.clearApplicationUserData(packageName, observer, getUserId());
    } catch (RemoteException e) {
        throw e.rethrowFromSystemServer();
    }
}
 
Example #12
Source File: ApplicationPackageManager.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
@Override
public void deleteApplicationCacheFiles(String packageName,
                                        IPackageDataObserver observer) {
    try {
        mPM.deleteApplicationCacheFiles(packageName, observer);
    } catch (RemoteException e) {
        throw e.rethrowFromSystemServer();
    }
}
 
Example #13
Source File: ApplicationPackageManager.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
@Override
public void deleteApplicationCacheFilesAsUser(String packageName, int userId,
        IPackageDataObserver observer) {
    try {
        mPM.deleteApplicationCacheFilesAsUser(packageName, userId, observer);
    } catch (RemoteException e) {
        throw e.rethrowFromSystemServer();
    }
}
 
Example #14
Source File: ApplicationPackageManager.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
@Override
public void freeStorageAndNotify(String volumeUuid, long idealStorageSize,
        IPackageDataObserver observer) {
    try {
        mPM.freeStorageAndNotify(volumeUuid, idealStorageSize, 0, observer);
    } catch (RemoteException e) {
        throw e.rethrowFromSystemServer();
    }
}
 
Example #15
Source File: ApplicationPackageManager.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
@Override
public void clearApplicationUserData(String packageName,
                                     IPackageDataObserver observer) {
    try {
        mPM.clearApplicationUserData(packageName, observer, mContext.getUserId());
    } catch (RemoteException e) {
        throw e.rethrowFromSystemServer();
    }
}
 
Example #16
Source File: ApplicationPackageManager.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
@Override
public void deleteApplicationCacheFiles(String packageName,
                                        IPackageDataObserver observer) {
    try {
        mPM.deleteApplicationCacheFiles(packageName, observer);
    } catch (RemoteException e) {
        throw e.rethrowFromSystemServer();
    }
}
 
Example #17
Source File: ApplicationPackageManager.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
@Override
public void deleteApplicationCacheFiles(String packageName,
                                        IPackageDataObserver observer) {
    try {
        mPM.deleteApplicationCacheFiles(packageName, observer);
    } catch (RemoteException e) {
        throw e.rethrowFromSystemServer();
    }
}
 
Example #18
Source File: ApplicationPackageManager.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
@Override
public void freeStorageAndNotify(String volumeUuid, long idealStorageSize,
        IPackageDataObserver observer) {
    try {
        mPM.freeStorageAndNotify(volumeUuid, idealStorageSize, observer);
    } catch (RemoteException e) {
        throw e.rethrowFromSystemServer();
    }
}
 
Example #19
Source File: ApplicationPackageManager.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public void clearApplicationUserData(String packageName,
                                     IPackageDataObserver observer) {
    try {
        mPM.clearApplicationUserData(packageName, observer, mContext.getUserId());
    } catch (RemoteException e) {
        throw e.rethrowFromSystemServer();
    }
}
 
Example #20
Source File: ApplicationPackageManager.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public void deleteApplicationCacheFiles(String packageName,
                                        IPackageDataObserver observer) {
    try {
        mPM.deleteApplicationCacheFiles(packageName, observer);
    } catch (RemoteException e) {
        throw e.rethrowFromSystemServer();
    }
}
 
Example #21
Source File: ApplicationPackageManager.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public void deleteApplicationCacheFilesAsUser(String packageName, int userId,
        IPackageDataObserver observer) {
    try {
        mPM.deleteApplicationCacheFilesAsUser(packageName, userId, observer);
    } catch (RemoteException e) {
        throw e.rethrowFromSystemServer();
    }
}
 
Example #22
Source File: ApplicationPackageManager.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public void freeStorageAndNotify(String volumeUuid, long idealStorageSize,
        IPackageDataObserver observer) {
    try {
        mPM.freeStorageAndNotify(volumeUuid, idealStorageSize, 0, observer);
    } catch (RemoteException e) {
        throw e.rethrowFromSystemServer();
    }
}
 
Example #23
Source File: ActivityManager.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * @hide
 */
@RequiresPermission(anyOf={Manifest.permission.CLEAR_APP_USER_DATA,
        Manifest.permission.ACCESS_INSTANT_APPS})
public boolean clearApplicationUserData(String packageName, IPackageDataObserver observer) {
    try {
        return getService().clearApplicationUserData(packageName, false,
                observer, mContext.getUserId());
    } catch (RemoteException e) {
        throw e.rethrowFromSystemServer();
    }
}
 
Example #24
Source File: CleanerService.java    From android-cache-cleaner with MIT License 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 #25
Source File: ApplicationPackageManager.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
@Override
public void freeStorageAndNotify(String volumeUuid, long idealStorageSize,
        IPackageDataObserver observer) {
    try {
        mPM.freeStorageAndNotify(volumeUuid, idealStorageSize, observer);
    } catch (RemoteException e) {
        // Should never happen!
    }
}
 
Example #26
Source File: ApplicationPackageManager.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
@Override
public void deleteApplicationCacheFiles(String packageName,
                                        IPackageDataObserver observer) {
    try {
        mPM.deleteApplicationCacheFiles(packageName, observer);
    } catch (RemoteException e) {
        throw e.rethrowFromSystemServer();
    }
}
 
Example #27
Source File: ApplicationPackageManager.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
@Override
public void deleteApplicationCacheFilesAsUser(String packageName, int userId,
        IPackageDataObserver observer) {
    try {
        mPM.deleteApplicationCacheFilesAsUser(packageName, userId, observer);
    } catch (RemoteException e) {
        throw e.rethrowFromSystemServer();
    }
}
 
Example #28
Source File: ApplicationPackageManager.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
@Override
public void freeStorageAndNotify(String volumeUuid, long idealStorageSize,
        IPackageDataObserver observer) {
    try {
        mPM.freeStorageAndNotify(volumeUuid, idealStorageSize, observer);
    } catch (RemoteException e) {
        throw e.rethrowFromSystemServer();
    }
}
 
Example #29
Source File: ApplicationPackageManager.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
@Override
public void clearApplicationUserData(String packageName,
                                     IPackageDataObserver observer) {
    try {
        mPM.clearApplicationUserData(packageName, observer, mContext.getUserId());
    } catch (RemoteException e) {
        throw e.rethrowFromSystemServer();
    }
}
 
Example #30
Source File: ApplicationPackageManager.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
@Override
public void deleteApplicationCacheFiles(String packageName,
                                        IPackageDataObserver observer) {
    try {
        mPM.deleteApplicationCacheFiles(packageName, observer);
    } catch (RemoteException e) {
        throw e.rethrowFromSystemServer();
    }
}