Search in sources :

Example 6 with AutoStartInfo

use of com.yzy.supercleanmaster.model.AutoStartInfo in project superCleanMaster by joyoyao.

the class BootStartUtils method fetchAutoApps.

public static List<AutoStartInfo> fetchAutoApps(Context mContext) {
    PackageManager pm = mContext.getPackageManager();
    Intent intent = new Intent(Intent.ACTION_BOOT_COMPLETED);
    List<ResolveInfo> resolveInfoList = pm.queryBroadcastReceivers(intent, PackageManager.GET_DISABLED_COMPONENTS);
    List<AutoStartInfo> appList = new ArrayList<AutoStartInfo>();
    String appName = null;
    String packageReceiver = null;
    Drawable icon = null;
    boolean isSystem = false;
    boolean isenable = true;
    if (resolveInfoList.size() > 0) {
        appName = resolveInfoList.get(0).loadLabel(pm).toString();
        packageReceiver = resolveInfoList.get(0).activityInfo.packageName + "/" + resolveInfoList.get(0).activityInfo.name;
        icon = resolveInfoList.get(0).loadIcon(pm);
        ComponentName mComponentName1 = new ComponentName(resolveInfoList.get(0).activityInfo.packageName, resolveInfoList.get(0).activityInfo.name);
        if (pm.getComponentEnabledSetting(mComponentName1) == 2) {
            isenable = false;
        } else {
            isenable = true;
        }
        if ((resolveInfoList.get(0).activityInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
            isSystem = true;
        } else {
            isSystem = false;
        }
        for (int i = 1; i < resolveInfoList.size(); i++) {
            AutoStartInfo mAutoStartInfo = new AutoStartInfo();
            if (appName.equals(resolveInfoList.get(i).loadLabel(pm).toString())) {
                packageReceiver = packageReceiver + ";" + resolveInfoList.get(i).activityInfo.packageName + "/" + resolveInfoList.get(i).activityInfo.name;
            } else {
                mAutoStartInfo.setLabel(appName);
                mAutoStartInfo.setSystem(isSystem);
                mAutoStartInfo.setEnable(isenable);
                mAutoStartInfo.setIcon(icon);
                mAutoStartInfo.setPackageReceiver(packageReceiver);
                appList.add(mAutoStartInfo);
                appName = resolveInfoList.get(i).loadLabel(pm).toString();
                packageReceiver = resolveInfoList.get(i).activityInfo.packageName + "/" + resolveInfoList.get(i).activityInfo.name;
                icon = resolveInfoList.get(i).loadIcon(pm);
                ComponentName mComponentName2 = new ComponentName(resolveInfoList.get(i).activityInfo.packageName, resolveInfoList.get(i).activityInfo.name);
                if (pm.getComponentEnabledSetting(mComponentName2) == 2) {
                    isenable = false;
                } else {
                    isenable = true;
                }
                if ((resolveInfoList.get(i).activityInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
                    isSystem = true;
                } else {
                    isSystem = false;
                }
            }
        }
        AutoStartInfo mAutoStartInfo = new AutoStartInfo();
        mAutoStartInfo.setLabel(appName);
        mAutoStartInfo.setSystem(isSystem);
        mAutoStartInfo.setEnable(isenable);
        mAutoStartInfo.setIcon(icon);
        mAutoStartInfo.setPackageReceiver(packageReceiver);
        appList.add(mAutoStartInfo);
    }
    return appList;
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) AutoStartInfo(com.yzy.supercleanmaster.model.AutoStartInfo) PackageManager(android.content.pm.PackageManager) ArrayList(java.util.ArrayList) Drawable(android.graphics.drawable.Drawable) Intent(android.content.Intent) ComponentName(android.content.ComponentName)

Aggregations

AutoStartInfo (com.yzy.supercleanmaster.model.AutoStartInfo)6 ArrayList (java.util.ArrayList)3 PackageManager (android.content.pm.PackageManager)2 Drawable (android.graphics.drawable.Drawable)2 ComponentName (android.content.ComponentName)1 Intent (android.content.Intent)1 ApplicationInfo (android.content.pm.ApplicationInfo)1 ResolveInfo (android.content.pm.ResolveInfo)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 AutoStartAdapter (com.yzy.supercleanmaster.adapter.AutoStartAdapter)1 ShellUtils (com.yzy.supercleanmaster.utils.ShellUtils)1