Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ffeeceaa authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Respect UserManager.DISALLOW_DEBUGGING_FEATURES." into arc-apps

parents d4a996b7 5bd5cb44
Loading
Loading
Loading
Loading
+24 −5
Original line number Diff line number Diff line
@@ -16,7 +16,9 @@
package com.android.documentsui.base;

import android.annotation.BoolRes;
import android.content.Context;
import android.content.res.Resources;
import android.os.UserManager;
import android.util.SparseBooleanArray;

import com.android.documentsui.R;
@@ -42,8 +44,8 @@ public interface Features {
    boolean isSystemKeyboardNavigationEnabled();
    boolean isVirtualFilesSharingEnabled();

    public static Features create(Resources resources) {
        return new RuntimeFeatures(resources);
    public static Features create(Context context) {
        return new RuntimeFeatures(context.getResources(), UserManager.get(context));
    }

    /**
@@ -62,15 +64,31 @@ public interface Features {
    final class RuntimeFeatures implements Features {

        private static final SparseBooleanArray sDebugEnabled = new SparseBooleanArray();
        private final SparseBooleanArray mDebugEnabled = new SparseBooleanArray();

        private final Resources mRes;
        private final UserManager mUserMgr;

        public RuntimeFeatures(Resources resources) {
        public RuntimeFeatures(Resources resources, UserManager userMgr) {
            mRes = resources;
            mUserMgr = userMgr;
        }

        /**
         * Call this to force-enable any particular feature known by this instance.
         * Note that all feature may not support being enabled at runtime as
         * they may depend on runtime initialization guarded by feature check.
         *
         * <p>Feature changes will be persisted across activities, but not app restarts.
         *
         * @param feature int reference to a boolean feature resource.
         */
        public void forceFeature(@BoolRes int feature, boolean enabled) {
            mDebugEnabled.put(feature, enabled);
        }

        private boolean isEnabled(@BoolRes int feature) {
            return sDebugEnabled.get(feature, mRes.getBoolean(feature));
            return mDebugEnabled.get(feature, sDebugEnabled.get(feature, mRes.getBoolean(feature)));
        }

        @Override
@@ -80,7 +98,8 @@ public interface Features {

        @Override
        public boolean isCommandInterceptorEnabled() {
            return isEnabled(R.bool.feature_command_interceptor);
            return !mUserMgr.hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES)
                    && isEnabled(R.bool.feature_command_interceptor);
        }

        @Override
+1 −1
Original line number Diff line number Diff line
@@ -80,7 +80,7 @@ public class FilesActivity extends BaseActivity implements ActionHandler.Addons
    public void onCreate(Bundle icicle) {

        MessageBuilder messages = new MessageBuilder(this);
        Features features = Features.create(getResources());
        Features features = Features.create(this);
        mInjector = new Injector<>(
                features,
                new Config(),
+1 −1
Original line number Diff line number Diff line
@@ -79,7 +79,7 @@ public class PickActivity extends BaseActivity implements ActionHandler.Addons {
    @Override
    public void onCreate(Bundle icicle) {

        Features features = Features.create(getResources());
        Features features = Features.create(this);
        mInjector = new Injector<>(
                features,
                new Config(),
+11 −11
Original line number Diff line number Diff line
@@ -43,7 +43,6 @@ public final class CommandInterceptor implements EventHandler<String> {
    public CommandInterceptor(Features features) {
        mFeatures = features;

        if (mFeatures.isCommandInterceptorEnabled()) {
        mCommands.add(CommandInterceptor::quickViewer);
        mCommands.add(CommandInterceptor::gestureScale);
        mCommands.add(CommandInterceptor::jobProgressDialog);
@@ -51,16 +50,17 @@ public final class CommandInterceptor implements EventHandler<String> {
        mCommands.add(CommandInterceptor::docDetails);
        mCommands.add(CommandInterceptor::forcePaging);
    }
    }

    public void add(EventHandler<String[]> handler) {
        if (mFeatures.isCommandInterceptorEnabled()) {
        mCommands.add(handler);
    }
    }

    @Override
    public boolean accept(String query) {
        if (!mFeatures.isCommandInterceptorEnabled()) {
            return false;
        }

        if (query.length() > COMMAND_PREFIX.length() && query.startsWith(COMMAND_PREFIX)) {
            String[] tokens = query.substring(COMMAND_PREFIX.length()).split("\\s+");
            for (EventHandler<String[]> command : mCommands) {
+4 −4
Original line number Diff line number Diff line
@@ -35,22 +35,22 @@ public class RootsList extends ListView {
    // constructed by the framework. Don't remove them!
    public RootsList(Context context) {
        super(context);
        mFeatures = Features.create(getResources());
        mFeatures = Features.create(getContext());
    }

    public RootsList(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        mFeatures = Features.create(getResources());
        mFeatures = Features.create(getContext());
    }

    public RootsList(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        mFeatures = Features.create(getResources());
        mFeatures = Features.create(getContext());
    }

    public RootsList(Context context, AttributeSet attrs) {
        super(context, attrs);
        mFeatures = Features.create(getResources());
        mFeatures = Features.create(getContext());
    }

    @Override