Java Code Examples for android.content.pm.PackageManager#COMPONENT_ENABLED_STATE_DISABLED_USER

The following examples show how to use android.content.pm.PackageManager#COMPONENT_ENABLED_STATE_DISABLED_USER . 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: AppDumperPlugin.java    From droidconat-2016 with Apache License 2.0 6 votes vote down vote up
private void displayBootReceiverState(PrintStream writer) {
    ComponentName componentName = new ComponentName(context, BootReceiver.class);
    PackageManager pm = context.getPackageManager();

    writer.print("Boot receiver state: ");
    int state = pm.getComponentEnabledSetting(componentName);
    switch (state) {
        case PackageManager.COMPONENT_ENABLED_STATE_DEFAULT:
            writer.println("default");
            break;
        case PackageManager.COMPONENT_ENABLED_STATE_ENABLED:
            writer.println("enabled");
            break;
        case PackageManager.COMPONENT_ENABLED_STATE_DISABLED:
            writer.println("disabled");
            break;
        case PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER:
            writer.println("disabled by user");
            break;
        default:
            writer.println(state);
            break;
    }
}
 
Example 2
Source File: IDownloadManagerImpl.java    From edx-app-android with Apache License 2.0 6 votes vote down vote up
@Override
public synchronized boolean isDownloadManagerEnabled(){
    if(context==null){
        return false;
    }

    int state = context.getPackageManager()
            .getApplicationEnabledSetting("com.android.providers.downloads");

    if (state == PackageManager.COMPONENT_ENABLED_STATE_DISABLED ||
            state == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER
            || state == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED) {
        //download manager is disabled
        return false;
    }
    return true;
}
 
Example 3
Source File: PackageManagerShellCommand.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private static String enabledSettingToString(int state) {
    switch (state) {
        case PackageManager.COMPONENT_ENABLED_STATE_DEFAULT:
            return "default";
        case PackageManager.COMPONENT_ENABLED_STATE_ENABLED:
            return "enabled";
        case PackageManager.COMPONENT_ENABLED_STATE_DISABLED:
            return "disabled";
        case PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER:
            return "disabled-user";
        case PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED:
            return "disabled-until-used";
    }
    return "unknown";
}
 
Example 4
Source File: DownloadUtil.java    From Yuan-WanAndroid with Apache License 2.0 5 votes vote down vote up
/**
 * 是否可以使用DownloadManager,如果不能则使用系统浏览器
 */
public static boolean canDownloadState(Context context) {
    try {
        int state = context.getPackageManager().getApplicationEnabledSetting("com.android.providers.downloads");
        if (state == PackageManager.COMPONENT_ENABLED_STATE_DISABLED
                || state == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER
                || state == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED) {
            return false;
        }
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
    return true;
}
 
Example 5
Source File: DownloadUtil.java    From WanAndroid with Apache License 2.0 5 votes vote down vote up
/**
 * 是否可以使用DownloadManager,如果不能则使用系统浏览器
 */
public static boolean canDownloadState(Context ctx) {
    try {
        int state = ctx.getPackageManager().getApplicationEnabledSetting("com.android.providers.downloads");
        if (state == PackageManager.COMPONENT_ENABLED_STATE_DISABLED
                || state == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER
                || state == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED) {
            return false;
        }
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
    return true;
}
 
Example 6
Source File: FUFUtils.java    From FreezeYou with Apache License 2.0 5 votes vote down vote up
public static boolean checkRootFrozen(Context context, String pkgName, PackageManager packageManager) {
    int tmp;
    try {
        tmp = packageManager == null ? context.getPackageManager().getApplicationEnabledSetting(pkgName) : packageManager.getApplicationEnabledSetting(pkgName);
    } catch (Exception e) {
        tmp = -1;
    }
    return ((tmp == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER) || (tmp == PackageManager.COMPONENT_ENABLED_STATE_DISABLED));
}
 
Example 7
Source File: UpdaterUtils.java    From AndroidUpdater with Apache License 2.0 5 votes vote down vote up
/**
 * 系统的下载组件是否可用
 *
 * @return boolean
 */
public static boolean checkDownloadState(Context context) {
    try {
        int state = context.getPackageManager().getApplicationEnabledSetting("com.android.providers.downloads");
        if (state == PackageManager.COMPONENT_ENABLED_STATE_DISABLED
                || state == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER
                || state == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED) {
            return false;
        }
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
    return true;
}
 
Example 8
Source File: DownloadManagerResolver.java    From FaceSlim with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Resolve whether the DownloadManager is enable in current devices.
 *
 * @param context Context of application
 * @return true if DownloadManager is enable, false otherwise.
 */
private static boolean resolveEnable(Context context) {
    int state = context.getPackageManager()
            .getApplicationEnabledSetting(DOWNLOAD_MANAGER_PACKAGE_NAME);

    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR2) {
        return !(state == PackageManager.COMPONENT_ENABLED_STATE_DISABLED ||
                state == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER
                || state == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED);
    } else {
        return !(state == PackageManager.COMPONENT_ENABLED_STATE_DISABLED ||
                state == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER);
    }
}
 
Example 9
Source File: GcmAvailableHelper.java    From android-job with Apache License 2.0 5 votes vote down vote up
private static void setServiceEnabled(Context context, boolean enabled) {
    try {
        PackageManager packageManager = context.getPackageManager();

        // use a string, the class object probably cannot be instantiated
        ComponentName component = new ComponentName(context, getPlatformGcmServiceClassName());

        int componentEnabled = packageManager.getComponentEnabledSetting(component);
        switch (componentEnabled) {
            case PackageManager.COMPONENT_ENABLED_STATE_ENABLED:
                if (!enabled) {
                    packageManager.setComponentEnabledSetting(component, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
                    CAT.i("GCM service disabled");
                }
                break;

            case PackageManager.COMPONENT_ENABLED_STATE_DEFAULT: // default is disable
            case PackageManager.COMPONENT_ENABLED_STATE_DISABLED:
                if (enabled) {
                    packageManager.setComponentEnabledSetting(component, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
                    CAT.i("GCM service enabled");
                }
                break;
            case PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED:
            case PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER:
                // do nothing
                break;
        }

    } catch (Throwable t) {
        // just in case, don't let the app crash with each restart
        if (BuildConfig.DEBUG) {
            CAT.e(t.getMessage());
        }
    }
}
 
Example 10
Source File: DownloadManagerResolver.java    From hipda with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Resolve whether the DownloadManager is enable in current devices.
 *
 * @param context
 * @return true if DownloadManager is enable,false otherwise.
 */
private static boolean resolveEnable(Context context) {
    int state = context.getPackageManager()
            .getApplicationEnabledSetting(DOWNLOAD_MANAGER_PACKAGE_NAME);

    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR2) {
        return !(state == PackageManager.COMPONENT_ENABLED_STATE_DISABLED ||
                state == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER
                || state == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED);
    } else {
        return !(state == PackageManager.COMPONENT_ENABLED_STATE_DISABLED ||
                state == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER);
    }
}
 
Example 11
Source File: InstalledApp.java    From ApkTrack with GNU General Public License v3.0 4 votes vote down vote up
/**
 * This function queries the system to obtain all the information needed to insert a new
 * app in the database.
 * The app will be persisted by this function.
 *
 * @param pacman The package manager
 * @param pi The PackageInfo object related to the target application
 * @return The resulting InstalledApp object, or <code>null</code> if the app couldn't be
 *         created (happens if the app is deleted while this function runs).
 */
private static InstalledApp _create_application(PackageManager pacman,
                                                PackageInfo pi)
{
    if (pi == null || pacman == null) {
        return null;
    }

    ApplicationInfo info;
    try {
        info = pacman.getApplicationInfo(pi.packageName, PackageManager.GET_META_DATA);
    }
    catch (final PackageManager.NameNotFoundException e) {
        info = null;
    }

    String applicationName = (String) (info != null ? pacman.getApplicationLabel(info) : null);
    InstalledApp app = new InstalledApp(pi.packageName,
            applicationName,
            pi.versionName,
            null,
            is_system_package(pi));

    // Try to guess the update source
    UpdateSource us = UpdateSource.guess_update_source(pi, info != null ? info.metaData : null);
    if (us != null) {
        app.set_update_source(us.get_name());
    }

    // If the app is disabled, assume the user wants to ignore its updates.
    int status;
    try {
        status = pacman.getApplicationEnabledSetting(pi.packageName);
    }
    // It happened once that the app was deleted in the meantime
    catch (IllegalArgumentException ignored) {
        return null;
    }

    if (status == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER ||
        status == PackageManager.COMPONENT_ENABLED_STATE_DISABLED)
    {
        app.set_ignored(true);
    }

    // Handle the icon if there is one present.
    _handle_icon(pacman, info, app);

    app.save();
    return app;
}