2017-07-24 01:02:38 -07:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2017 The Android Open Source Project
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package com.android.launcher3.config;
|
|
|
|
|
|
2018-10-12 14:14:16 -04:00
|
|
|
import static androidx.core.util.Preconditions.checkNotNull;
|
2019-01-29 11:01:22 -08:00
|
|
|
|
2018-11-04 11:39:08 -05:00
|
|
|
import android.content.ContentResolver;
|
2018-10-12 14:14:16 -04:00
|
|
|
import android.content.Context;
|
|
|
|
|
import android.content.SharedPreferences;
|
2019-03-08 16:32:59 -08:00
|
|
|
import android.database.ContentObserver;
|
|
|
|
|
import android.os.Handler;
|
|
|
|
|
import android.os.Looper;
|
2018-10-22 16:31:28 -04:00
|
|
|
import android.provider.Settings;
|
2019-01-29 11:01:22 -08:00
|
|
|
|
2018-11-04 11:39:08 -05:00
|
|
|
import androidx.annotation.GuardedBy;
|
|
|
|
|
import androidx.annotation.Keep;
|
|
|
|
|
import androidx.annotation.VisibleForTesting;
|
2019-01-29 11:01:22 -08:00
|
|
|
|
2018-10-12 14:14:16 -04:00
|
|
|
import com.android.launcher3.Utilities;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.SortedMap;
|
|
|
|
|
import java.util.TreeMap;
|
|
|
|
|
|
2017-07-24 01:02:38 -07:00
|
|
|
/**
|
|
|
|
|
* Defines a set of flags used to control various launcher behaviors.
|
|
|
|
|
*
|
2018-10-03 13:32:01 -04:00
|
|
|
* <p>All the flags should be defined here with appropriate default values.
|
2017-07-24 01:02:38 -07:00
|
|
|
*
|
2018-10-03 13:32:01 -04:00
|
|
|
* <p>This class is kept package-private to prevent direct access.
|
2017-07-24 01:02:38 -07:00
|
|
|
*/
|
2018-10-12 14:14:16 -04:00
|
|
|
@Keep
|
2017-07-24 01:02:38 -07:00
|
|
|
abstract class BaseFlags {
|
|
|
|
|
|
2018-10-12 14:14:16 -04:00
|
|
|
private static final Object sLock = new Object();
|
|
|
|
|
@GuardedBy("sLock")
|
|
|
|
|
private static final List<TogglableFlag> sFlags = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
static final String FLAGS_PREF_NAME = "featureFlags";
|
2018-10-03 13:32:01 -04:00
|
|
|
|
|
|
|
|
BaseFlags() {
|
2018-10-12 14:14:16 -04:00
|
|
|
throw new UnsupportedOperationException("Don't instantiate BaseFlags");
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-22 16:31:28 -04:00
|
|
|
public static boolean showFlagTogglerUi(Context context) {
|
|
|
|
|
return Utilities.IS_DEBUG_DEVICE &&
|
|
|
|
|
Settings.Global.getInt(context.getApplicationContext().getContentResolver(),
|
|
|
|
|
Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0) != 0;
|
2018-10-03 13:32:01 -04:00
|
|
|
}
|
2017-07-24 01:02:38 -07:00
|
|
|
|
|
|
|
|
public static final boolean IS_DOGFOOD_BUILD = false;
|
|
|
|
|
|
|
|
|
|
// When enabled the promise icon is visible in all apps while installation an app.
|
|
|
|
|
public static final boolean LAUNCHER3_PROMISE_APPS_IN_ALL_APPS = false;
|
|
|
|
|
|
2019-03-15 09:00:05 -07:00
|
|
|
// Enable moving the QSB on the 0th screen of the workspace
|
|
|
|
|
public static final boolean QSB_ON_FIRST_SCREEN = true;
|
2018-10-12 14:14:16 -04:00
|
|
|
|
|
|
|
|
public static final TogglableFlag EXAMPLE_FLAG = new TogglableFlag("EXAMPLE_FLAG", true,
|
|
|
|
|
"An example flag that doesn't do anything. Useful for testing");
|
2018-09-10 16:48:47 -07:00
|
|
|
|
|
|
|
|
//Feature flag to enable pulling down navigation shade from workspace.
|
|
|
|
|
public static final boolean PULL_DOWN_STATUS_BAR = true;
|
|
|
|
|
|
2017-08-16 04:59:08 -07:00
|
|
|
// When true, custom widgets are loaded using CustomWidgetParser.
|
|
|
|
|
public static final boolean ENABLE_CUSTOM_WIDGETS = false;
|
|
|
|
|
|
2017-07-24 01:02:38 -07:00
|
|
|
// Features to control Launcher3Go behavior
|
|
|
|
|
public static final boolean GO_DISABLE_WIDGETS = false;
|
2017-10-30 10:03:34 -07:00
|
|
|
|
2017-10-18 10:31:36 -07:00
|
|
|
// When enabled shows a work profile tab in all apps
|
2017-12-01 13:24:49 -08:00
|
|
|
public static final boolean ALL_APPS_TABS_ENABLED = true;
|
2018-03-26 17:18:36 -07:00
|
|
|
|
|
|
|
|
// When true, overview shows screenshots in the orientation they were taken rather than
|
|
|
|
|
// trying to make them fit the orientation the device is in.
|
|
|
|
|
public static final boolean OVERVIEW_USE_SCREENSHOT_ORIENTATION = true;
|
2018-10-12 14:14:16 -04:00
|
|
|
|
2018-10-12 11:42:33 -07:00
|
|
|
/**
|
|
|
|
|
* Feature flag to handle define config changes dynamically instead of killing the process.
|
|
|
|
|
*/
|
|
|
|
|
public static final TogglableFlag APPLY_CONFIG_AT_RUNTIME = new TogglableFlag(
|
2018-12-04 15:43:16 -08:00
|
|
|
"APPLY_CONFIG_AT_RUNTIME", true, "Apply display changes dynamically");
|
2018-10-12 11:42:33 -07:00
|
|
|
|
2019-01-08 16:01:57 -08:00
|
|
|
public static final TogglableFlag QUICKSTEP_SPRINGS = new TogglableFlag("QUICKSTEP_SPRINGS",
|
|
|
|
|
false, "Enable springs for quickstep animations");
|
|
|
|
|
|
2019-02-19 15:34:41 -08:00
|
|
|
public static final TogglableFlag ADAPTIVE_ICON_WINDOW_ANIM = new TogglableFlag(
|
2019-03-06 10:40:13 -08:00
|
|
|
"ADAPTIVE_ICON_WINDOW_ANIM", true,
|
2019-02-19 15:34:41 -08:00
|
|
|
"Use adaptive icons for window animations.");
|
|
|
|
|
|
2018-10-29 16:08:29 -04:00
|
|
|
public static final TogglableFlag ENABLE_QUICKSTEP_LIVE_TILE = new TogglableFlag(
|
|
|
|
|
"ENABLE_QUICKSTEP_LIVE_TILE", false, "Enable live tile in Quickstep overview");
|
|
|
|
|
|
2019-02-11 13:07:04 -05:00
|
|
|
public static final TogglableFlag ENABLE_HINTS_IN_OVERVIEW = new TogglableFlag(
|
|
|
|
|
"ENABLE_HINTS_IN_OVERVIEW", false,
|
|
|
|
|
"Show chip hints and gleams on the overview screen");
|
|
|
|
|
|
2019-04-30 12:04:37 -07:00
|
|
|
public static final TogglableFlag FAKE_LANDSCAPE_UI = new TogglableFlag(
|
2019-05-14 09:44:34 -07:00
|
|
|
"FAKE_LANDSCAPE_UI", true,
|
2019-04-30 12:04:37 -07:00
|
|
|
"Rotate launcher UI instead of using transposed layout");
|
|
|
|
|
|
2018-10-12 14:14:16 -04:00
|
|
|
public static void initialize(Context context) {
|
2018-10-22 16:31:28 -04:00
|
|
|
// Avoid the disk read for user builds
|
|
|
|
|
if (Utilities.IS_DEBUG_DEVICE) {
|
2018-10-12 14:14:16 -04:00
|
|
|
synchronized (sLock) {
|
|
|
|
|
for (TogglableFlag flag : sFlags) {
|
2018-11-04 11:39:08 -05:00
|
|
|
flag.initialize(context);
|
2018-10-12 14:14:16 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static List<TogglableFlag> getTogglableFlags() {
|
|
|
|
|
// By Java Language Spec 12.4.2
|
|
|
|
|
// https://docs.oracle.com/javase/specs/jls/se7/html/jls-12.html#jls-12.4.2, the
|
|
|
|
|
// TogglableFlag instances on BaseFlags will be created before those on the FeatureFlags
|
|
|
|
|
// subclass. This code handles flags that are redeclared in FeatureFlags, ensuring the
|
|
|
|
|
// FeatureFlags one takes priority.
|
|
|
|
|
SortedMap<String, TogglableFlag> flagsByKey = new TreeMap<>();
|
|
|
|
|
synchronized (sLock) {
|
|
|
|
|
for (TogglableFlag flag : sFlags) {
|
|
|
|
|
flagsByKey.put(flag.key, flag);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return new ArrayList<>(flagsByKey.values());
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-04 11:39:08 -05:00
|
|
|
public static class TogglableFlag {
|
2018-10-12 14:14:16 -04:00
|
|
|
private final String key;
|
|
|
|
|
private final boolean defaultValue;
|
|
|
|
|
private final String description;
|
|
|
|
|
private boolean currentValue;
|
|
|
|
|
|
|
|
|
|
TogglableFlag(
|
|
|
|
|
String key,
|
|
|
|
|
boolean defaultValue,
|
|
|
|
|
String description) {
|
|
|
|
|
this.key = checkNotNull(key);
|
2018-11-26 23:44:41 -08:00
|
|
|
this.currentValue = this.defaultValue = defaultValue;
|
2018-10-12 14:14:16 -04:00
|
|
|
this.description = checkNotNull(description);
|
|
|
|
|
synchronized (sLock) {
|
|
|
|
|
sFlags.add(this);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-08 11:30:14 -05:00
|
|
|
/** Set the value of this flag. This should only be used in tests. */
|
|
|
|
|
@VisibleForTesting
|
|
|
|
|
void setForTests(boolean value) {
|
|
|
|
|
currentValue = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE)
|
|
|
|
|
public String getKey() {
|
2018-10-12 14:14:16 -04:00
|
|
|
return key;
|
|
|
|
|
}
|
2018-11-04 11:39:08 -05:00
|
|
|
void initialize(Context context) {
|
|
|
|
|
currentValue = getFromStorage(context, defaultValue);
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-11 16:23:45 -07:00
|
|
|
public void updateStorage(Context context, boolean value) {
|
2018-11-04 11:39:08 -05:00
|
|
|
SharedPreferences.Editor editor = context.getSharedPreferences(FLAGS_PREF_NAME,
|
|
|
|
|
Context.MODE_PRIVATE).edit();
|
|
|
|
|
if (value == defaultValue) {
|
|
|
|
|
editor.remove(key).apply();
|
|
|
|
|
} else {
|
|
|
|
|
editor.putBoolean(key, value).apply();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
boolean getFromStorage(Context context, boolean defaultValue) {
|
|
|
|
|
return context.getSharedPreferences(FLAGS_PREF_NAME, Context.MODE_PRIVATE)
|
|
|
|
|
.getBoolean(key, defaultValue);
|
|
|
|
|
}
|
2018-10-12 14:14:16 -04:00
|
|
|
|
|
|
|
|
boolean getDefaultValue() {
|
|
|
|
|
return defaultValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Returns the value of the flag at process start, including any overrides present. */
|
|
|
|
|
public boolean get() {
|
|
|
|
|
return currentValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String getDescription() {
|
|
|
|
|
return description;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String toString() {
|
|
|
|
|
return "TogglableFlag{"
|
|
|
|
|
+ "key=" + key + ", "
|
|
|
|
|
+ "defaultValue=" + defaultValue + ", "
|
|
|
|
|
+ "description=" + description
|
|
|
|
|
+ "}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean equals(Object o) {
|
|
|
|
|
if (o == this) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (o instanceof TogglableFlag) {
|
|
|
|
|
TogglableFlag that = (TogglableFlag) o;
|
|
|
|
|
return (this.key.equals(that.getKey()))
|
|
|
|
|
&& (this.defaultValue == that.getDefaultValue())
|
|
|
|
|
&& (this.description.equals(that.getDescription()));
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int hashCode() {
|
|
|
|
|
int h$ = 1;
|
|
|
|
|
h$ *= 1000003;
|
|
|
|
|
h$ ^= key.hashCode();
|
|
|
|
|
h$ *= 1000003;
|
|
|
|
|
h$ ^= defaultValue ? 1231 : 1237;
|
|
|
|
|
h$ *= 1000003;
|
|
|
|
|
h$ ^= description.hashCode();
|
|
|
|
|
return h$;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-11-04 11:39:08 -05:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Stores the FeatureFlag's value in Settings.Global instead of our SharedPrefs.
|
|
|
|
|
* This is useful if we want to be able to control this flag from another process.
|
|
|
|
|
*/
|
|
|
|
|
public static final class ToggleableGlobalSettingsFlag extends TogglableFlag {
|
|
|
|
|
private ContentResolver contentResolver;
|
|
|
|
|
|
|
|
|
|
ToggleableGlobalSettingsFlag(String key, boolean defaultValue, String description) {
|
|
|
|
|
super(key, defaultValue, description);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void initialize(Context context) {
|
|
|
|
|
contentResolver = context.getContentResolver();
|
2019-03-08 16:32:59 -08:00
|
|
|
contentResolver.registerContentObserver(Settings.Global.getUriFor(getKey()), true,
|
|
|
|
|
new ContentObserver(new Handler(Looper.getMainLooper())) {
|
|
|
|
|
@Override
|
|
|
|
|
public void onChange(boolean selfChange) {
|
|
|
|
|
superInitialize(context);
|
|
|
|
|
}});
|
|
|
|
|
superInitialize(context);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void superInitialize(Context context) {
|
2018-11-04 11:39:08 -05:00
|
|
|
super.initialize(context);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2019-03-11 16:23:45 -07:00
|
|
|
public void updateStorage(Context context, boolean value) {
|
2019-01-29 11:01:22 -08:00
|
|
|
if (contentResolver == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2018-11-04 11:39:08 -05:00
|
|
|
Settings.Global.putInt(contentResolver, getKey(), value ? 1 : 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
boolean getFromStorage(Context context, boolean defaultValue) {
|
2019-01-29 11:01:22 -08:00
|
|
|
if (contentResolver == null) {
|
|
|
|
|
return defaultValue;
|
|
|
|
|
}
|
2018-11-04 11:39:08 -05:00
|
|
|
return Settings.Global.getInt(contentResolver, getKey(), defaultValue ? 1 : 0) == 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-07-24 01:02:38 -07:00
|
|
|
}
|