FileDocCategorySizeDatePackage
PolicyControl.javaAPI DocAndroid 5.1 API10822Thu Mar 12 22:22:42 GMT 2015com.android.internal.policy.impl

PolicyControl

public class PolicyControl extends Object
Runtime adjustments applied to the global window policy. This includes forcing immersive mode behavior for one or both system bars (based on a package list) and permanently disabling immersive mode confirmations for specific packages. Control by setting {@link Settings.Global.POLICY_CONTROL} to one or more name-value pairs. e.g. to force immersive mode everywhere: "immersive.full=*" to force transient status for all apps except a specific package: "immersive.status=apps,-com.package" to disable the immersive mode confirmations for specific packages: "immersive.preconfirms=com.package.one,com.package.two" Separate multiple name-value pairs with ':' e.g. "immersive.status=apps:immersive.preconfirms=*"

Fields Summary
private static String
TAG
private static boolean
DEBUG
private static final String
NAME_IMMERSIVE_FULL
private static final String
NAME_IMMERSIVE_STATUS
private static final String
NAME_IMMERSIVE_NAVIGATION
private static final String
NAME_IMMERSIVE_PRECONFIRMATIONS
private static String
sSettingValue
private static Filter
sImmersivePreconfirmationsFilter
private static Filter
sImmersiveStatusFilter
private static Filter
sImmersiveNavigationFilter
Constructors Summary
Methods Summary
public static intadjustClearableFlags(android.view.WindowManagerPolicy.WindowState win, int clearableFlags)

        final LayoutParams attrs = win != null ? win.getAttrs() : null;
        if (sImmersiveStatusFilter != null && sImmersiveStatusFilter.matches(attrs)) {
            clearableFlags &= ~View.SYSTEM_UI_FLAG_FULLSCREEN;
        }
        return clearableFlags;
    
public static booleandisableImmersiveConfirmation(java.lang.String pkg)

        return (sImmersivePreconfirmationsFilter != null
                && sImmersivePreconfirmationsFilter.matches(pkg))
                || ActivityManager.isRunningInTestHarness();
    
public static voiddump(java.lang.String prefix, java.io.PrintWriter pw)

        dump("sImmersiveStatusFilter", sImmersiveStatusFilter, prefix, pw);
        dump("sImmersiveNavigationFilter", sImmersiveNavigationFilter, prefix, pw);
        dump("sImmersivePreconfirmationsFilter", sImmersivePreconfirmationsFilter, prefix, pw);
    
private static voiddump(java.lang.String name, com.android.internal.policy.impl.PolicyControl$Filter filter, java.lang.String prefix, java.io.PrintWriter pw)

        pw.print(prefix); pw.print("PolicyControl."); pw.print(name); pw.print('=");
        if (filter == null) {
            pw.println("null");
        } else {
            filter.dump(pw); pw.println();
        }
    
public static intgetSystemUiVisibility(android.view.WindowManagerPolicy.WindowState win, android.view.WindowManager.LayoutParams attrs)


           
        attrs = attrs != null ? attrs : win.getAttrs();
        int vis = win != null ? win.getSystemUiVisibility() : attrs.systemUiVisibility;
        if (sImmersiveStatusFilter != null && sImmersiveStatusFilter.matches(attrs)) {
            vis |= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
                    | View.SYSTEM_UI_FLAG_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
            vis &= ~(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                    | View.STATUS_BAR_TRANSLUCENT);
        }
        if (sImmersiveNavigationFilter != null && sImmersiveNavigationFilter.matches(attrs)) {
            vis |= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
                    | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
            vis &= ~(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                    | View.NAVIGATION_BAR_TRANSLUCENT);
        }
        return vis;
    
public static intgetWindowFlags(android.view.WindowManagerPolicy.WindowState win, android.view.WindowManager.LayoutParams attrs)

        attrs = attrs != null ? attrs : win.getAttrs();
        int flags = attrs.flags;
        if (sImmersiveStatusFilter != null && sImmersiveStatusFilter.matches(attrs)) {
            flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
            flags &= ~(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
                    | WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
        }
        if (sImmersiveNavigationFilter != null && sImmersiveNavigationFilter.matches(attrs)) {
            flags &= ~WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION;
        }
        return flags;
    
public static voidreloadFromSetting(android.content.Context context)

        if (DEBUG) Slog.d(TAG, "reloadFromSetting()");
        String value = null;
        try {
            value = Settings.Global.getStringForUser(context.getContentResolver(),
                    Settings.Global.POLICY_CONTROL,
                    UserHandle.USER_CURRENT);
            if (sSettingValue != null && sSettingValue.equals(value)) return;
            setFilters(value);
            sSettingValue = value;
        } catch (Throwable t) {
            Slog.w(TAG, "Error loading policy control, value=" + value, t);
        }
    
private static voidsetFilters(java.lang.String value)

        if (DEBUG) Slog.d(TAG, "setFilters: " + value);
        sImmersiveStatusFilter = null;
        sImmersiveNavigationFilter = null;
        sImmersivePreconfirmationsFilter = null;
        if (value != null) {
            String[] nvps = value.split(":");
            for (String nvp : nvps) {
                int i = nvp.indexOf('=");
                if (i == -1) continue;
                String n = nvp.substring(0, i);
                String v = nvp.substring(i + 1);
                if (n.equals(NAME_IMMERSIVE_FULL)) {
                    Filter f = Filter.parse(v);
                    sImmersiveStatusFilter = sImmersiveNavigationFilter = f;
                    if (sImmersivePreconfirmationsFilter == null) {
                        sImmersivePreconfirmationsFilter = f;
                    }
                } else if (n.equals(NAME_IMMERSIVE_STATUS)) {
                    Filter f = Filter.parse(v);
                    sImmersiveStatusFilter = f;
                } else if (n.equals(NAME_IMMERSIVE_NAVIGATION)) {
                    Filter f = Filter.parse(v);
                    sImmersiveNavigationFilter = f;
                    if (sImmersivePreconfirmationsFilter == null) {
                        sImmersivePreconfirmationsFilter = f;
                    }
                } else if (n.equals(NAME_IMMERSIVE_PRECONFIRMATIONS)) {
                    Filter f = Filter.parse(v);
                    sImmersivePreconfirmationsFilter = f;
                }
            }
        }
        if (DEBUG) {
            Slog.d(TAG, "immersiveStatusFilter: " + sImmersiveStatusFilter);
            Slog.d(TAG, "immersiveNavigationFilter: " + sImmersiveNavigationFilter);
            Slog.d(TAG, "immersivePreconfirmationsFilter: " + sImmersivePreconfirmationsFilter);
        }