Loading src/com/android/documentsui/base/Features.java +24 −5 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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)); } /** Loading @@ -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 Loading @@ -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 Loading src/com/android/documentsui/files/FilesActivity.java +1 −1 Original line number Diff line number Diff line Loading @@ -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(), Loading src/com/android/documentsui/picker/PickActivity.java +1 −1 Original line number Diff line number Diff line Loading @@ -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(), Loading src/com/android/documentsui/queries/CommandInterceptor.java +11 −11 Original line number Diff line number Diff line Loading @@ -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); Loading @@ -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) { Loading src/com/android/documentsui/sidebar/RootsList.java +4 −4 Original line number Diff line number Diff line Loading @@ -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 Loading Loading
src/com/android/documentsui/base/Features.java +24 −5 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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)); } /** Loading @@ -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 Loading @@ -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 Loading
src/com/android/documentsui/files/FilesActivity.java +1 −1 Original line number Diff line number Diff line Loading @@ -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(), Loading
src/com/android/documentsui/picker/PickActivity.java +1 −1 Original line number Diff line number Diff line Loading @@ -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(), Loading
src/com/android/documentsui/queries/CommandInterceptor.java +11 −11 Original line number Diff line number Diff line Loading @@ -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); Loading @@ -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) { Loading
src/com/android/documentsui/sidebar/RootsList.java +4 −4 Original line number Diff line number Diff line Loading @@ -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 Loading