package com.cooleshow.base.utils; import android.app.ActivityManager; import android.content.Context; import android.os.Build; import android.os.Environment; import java.io.File; import androidx.annotation.RequiresApi; /** *
 *     author: Blankj
 *     blog  : http://blankj.com
 *     time  : 2016/09/27
 *     desc  : utils about clean
 * 
*/ public final class CleanUtils { private CleanUtils() { throw new UnsupportedOperationException("u can't instantiate me..."); } /** * Clean the internal cache. *

directory: /data/data/package/cache

* * @return {@code true}: success
{@code false}: fail */ public static boolean cleanInternalCache() { return UtilsBridge.deleteAllInDir(Utils.getApp().getCacheDir()); } /** * Clean the internal files. *

directory: /data/data/package/files

* * @return {@code true}: success
{@code false}: fail */ public static boolean cleanInternalFiles() { return UtilsBridge.deleteAllInDir(Utils.getApp().getFilesDir()); } /** * Clean the internal databases. *

directory: /data/data/package/databases

* * @return {@code true}: success
{@code false}: fail */ public static boolean cleanInternalDbs() { return UtilsBridge.deleteAllInDir(new File(Utils.getApp().getFilesDir().getParent(), "databases")); } /** * Clean the internal database by name. *

directory: /data/data/package/databases/dbName

* * @param dbName The name of database. * @return {@code true}: success
{@code false}: fail */ public static boolean cleanInternalDbByName(final String dbName) { return Utils.getApp().deleteDatabase(dbName); } /** * Clean the internal shared preferences. *

directory: /data/data/package/shared_prefs

* * @return {@code true}: success
{@code false}: fail */ public static boolean cleanInternalSp() { return UtilsBridge.deleteAllInDir(new File(Utils.getApp().getFilesDir().getParent(), "shared_prefs")); } /** * Clean the external cache. *

directory: /storage/emulated/0/android/data/package/cache

* * @return {@code true}: success
{@code false}: fail */ public static boolean cleanExternalCache() { return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) && UtilsBridge.deleteAllInDir(Utils.getApp().getExternalCacheDir()); } /** * Clean the custom directory. * * @param dirPath The path of directory. * @return {@code true}: success
{@code false}: fail */ public static boolean cleanCustomDir(final String dirPath) { return UtilsBridge.deleteAllInDir(UtilsBridge.getFileByPath(dirPath)); } @RequiresApi(api = Build.VERSION_CODES.KITKAT) public static void cleanAppUserData() { ActivityManager am = (ActivityManager) Utils.getApp().getSystemService(Context.ACTIVITY_SERVICE); //noinspection ConstantConditions am.clearApplicationUserData(); } }