下面列出了android.view.accessibility.AccessibilityManager.TouchExplorationStateChangeListener#org.chromium.base.CommandLine 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private static boolean detectEnabled() {
if (SysUtils.isLowEndDevice()) {
return false;
}
// Allow this user-flippable flag to disable the feature.
if (CommandLine.getInstance().hasSwitch(ChromeSwitches.DISABLE_CONTEXTUAL_SEARCH)) {
return false;
}
// Allow this user-flippable flag to enable the feature.
if (CommandLine.getInstance().hasSwitch(ChromeSwitches.ENABLE_CONTEXTUAL_SEARCH)) {
return true;
}
// Allow disabling the feature remotely.
if (getBooleanParam(DISABLED_PARAM)) {
return false;
}
return true;
}
private void preInflationStartup() {
ThreadUtils.assertOnUiThread();
if (mPreInflationStartupComplete) return;
PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX, mApplication);
// Ensure critical files are available, so they aren't blocked on the file-system
// behind long-running accesses in next phase.
// Don't do any large file access here!
ContentApplication.initCommandLine(mApplication);
waitForDebuggerIfNeeded();
ChromeStrictMode.configureStrictMode();
if (CommandLine.getInstance().hasSwitch(ChromeSwitches.ENABLE_WEBAPK)) {
ChromeWebApkHost.init();
}
warmUpSharedPrefs();
DeviceUtils.addDeviceSpecificUserAgentSwitch(mApplication);
ApplicationStatus.registerStateListenerForAllActivities(
createActivityStateListener());
mPreInflationStartupComplete = true;
}
/**
* Enable fullscreen related startup flags.
* @param resources Resources to use while calculating initialization constants.
* @param resControlContainerHeight The resource id for the height of the browser controls.
*/
public static void enableFullscreenFlags(
Resources resources, Context context, int resControlContainerHeight) {
ContentApplication.initCommandLine(context);
CommandLine commandLine = CommandLine.getInstance();
if (commandLine.hasSwitch(ChromeSwitches.DISABLE_FULLSCREEN)) return;
TypedValue threshold = new TypedValue();
resources.getValue(R.dimen.top_controls_show_threshold, threshold, true);
commandLine.appendSwitchWithValue(
ContentSwitches.TOP_CONTROLS_SHOW_THRESHOLD, threshold.coerceToString().toString());
resources.getValue(R.dimen.top_controls_hide_threshold, threshold, true);
commandLine.appendSwitchWithValue(
ContentSwitches.TOP_CONTROLS_HIDE_THRESHOLD, threshold.coerceToString().toString());
}
/**
* Enable fullscreen related startup flags.
* @param resources Resources to use while calculating initialization constants.
* @param resControlContainerHeight The resource id for the height of the top controls.
*/
public static void enableFullscreenFlags(
Resources resources, Context context, int resControlContainerHeight) {
ContentApplication.initCommandLine(context);
CommandLine commandLine = CommandLine.getInstance();
if (commandLine.hasSwitch(ChromeSwitches.DISABLE_FULLSCREEN)) return;
TypedValue threshold = new TypedValue();
resources.getValue(R.dimen.top_controls_show_threshold, threshold, true);
commandLine.appendSwitchWithValue(
ContentSwitches.TOP_CONTROLS_SHOW_THRESHOLD, threshold.coerceToString().toString());
resources.getValue(R.dimen.top_controls_hide_threshold, threshold, true);
commandLine.appendSwitchWithValue(
ContentSwitches.TOP_CONTROLS_HIDE_THRESHOLD, threshold.coerceToString().toString());
}
/**
* Returns an integer value for a Finch parameter, or the default value if no parameter exists
* in the current configuration. Also checks for a command-line switch with the same name.
* @param paramName The name of the Finch parameter (or command-line switch) to get a value for.
* @param defaultValue The default value to return when there's no param or switch.
* @return An integer value -- either the param or the default.
*/
private static int getIntParamValueOrDefault(String paramName, int defaultValue) {
String value = CommandLine.getInstance().getSwitchValue(paramName);
if (TextUtils.isEmpty(value)) {
value = VariationsAssociatedData.getVariationParamValue(FIELD_TRIAL_NAME, paramName);
}
if (!TextUtils.isEmpty(value)) {
try {
return Integer.parseInt(value);
} catch (NumberFormatException e) {
return defaultValue;
}
}
return defaultValue;
}
private static boolean hasForcedDIPScale() {
if (sForcedDIPScale == null) {
String forcedScaleAsString = CommandLine.getInstance().getSwitchValue(
DisplaySwitches.FORCE_DEVICE_SCALE_FACTOR);
if (forcedScaleAsString == null) {
sForcedDIPScale = Float.valueOf(0.0f);
} else {
boolean isInvalid = false;
try {
sForcedDIPScale = Float.valueOf(forcedScaleAsString);
// Negative values are discarded.
if (sForcedDIPScale.floatValue() <= 0.0f) isInvalid = true;
} catch (NumberFormatException e) {
// Strings that do not represent numbers are discarded.
isInvalid = true;
}
if (isInvalid) {
Log.w(TAG, "Ignoring invalid forced DIP scale '" + forcedScaleAsString + "'");
sForcedDIPScale = Float.valueOf(0.0f);
}
}
}
return sForcedDIPScale.floatValue() > 0;
}
/**
* Cache whether the Instant Apps feature is enabled.
* This should only be called with the native library loaded.
*/
public void cacheInstantAppsEnabled() {
Context context = ContextUtils.getApplicationContext();
boolean isEnabled = false;
boolean wasEnabled = isEnabled(context);
CommandLine instance = CommandLine.getInstance();
if (instance.hasSwitch(ChromeSwitches.DISABLE_APP_LINK)) {
isEnabled = false;
} else if (instance.hasSwitch(ChromeSwitches.ENABLE_APP_LINK)) {
isEnabled = true;
} else {
String experiment = FieldTrialList.findFullName(INSTANT_APPS_EXPERIMENT_NAME);
if (INSTANT_APPS_DISABLED_ARM.equals(experiment)) {
isEnabled = false;
} else if (INSTANT_APPS_ENABLED_ARM.equals(experiment)) {
isEnabled = true;
}
}
if (isEnabled != wasEnabled) {
ChromePreferenceManager.getInstance(context).setCachedInstantAppsEnabled(isEnabled);
}
}
private static boolean detectEnabled() {
if (SysUtils.isLowEndDevice()) {
return false;
}
// Allow this user-flippable flag to disable the feature.
if (CommandLine.getInstance().hasSwitch(ChromeSwitches.DISABLE_CONTEXTUAL_SEARCH)) {
return false;
}
// Allow this user-flippable flag to enable the feature.
if (CommandLine.getInstance().hasSwitch(ChromeSwitches.ENABLE_CONTEXTUAL_SEARCH)) {
return true;
}
// Allow disabling the feature remotely.
if (getBooleanParam(DISABLED_PARAM)) {
return false;
}
return true;
}
/**
* Returns an integer value for a Finch parameter, or the default value if no parameter exists
* in the current configuration. Also checks for a command-line switch with the same name.
* @param paramName The name of the Finch parameter (or command-line switch) to get a value for.
* @param defaultValue The default value to return when there's no param or switch.
* @return An integer value -- either the param or the default.
*/
private static int getIntParamValueOrDefault(String paramName, int defaultValue) {
String value = CommandLine.getInstance().getSwitchValue(paramName);
if (TextUtils.isEmpty(value)) {
value = VariationsAssociatedData.getVariationParamValue(FIELD_TRIAL_NAME, paramName);
}
if (!TextUtils.isEmpty(value)) {
try {
return Integer.parseInt(value);
} catch (NumberFormatException e) {
return defaultValue;
}
}
return defaultValue;
}
/**
* Enable fullscreen related startup flags.
* @param resources Resources to use while calculating initialization constants.
* @param resControlContainerHeight The resource id for the height of the browser controls.
*/
public static void enableFullscreenFlags(
Resources resources, Context context, int resControlContainerHeight) {
ContentApplication.initCommandLine(context);
CommandLine commandLine = CommandLine.getInstance();
if (commandLine.hasSwitch(ChromeSwitches.DISABLE_FULLSCREEN)) return;
TypedValue threshold = new TypedValue();
resources.getValue(R.dimen.top_controls_show_threshold, threshold, true);
commandLine.appendSwitchWithValue(
ContentSwitches.TOP_CONTROLS_SHOW_THRESHOLD, threshold.coerceToString().toString());
resources.getValue(R.dimen.top_controls_hide_threshold, threshold, true);
Log.w("renshuai: ", "hello" + threshold.coerceToString().toString());
commandLine.appendSwitchWithValue(
ContentSwitches.TOP_CONTROLS_HIDE_THRESHOLD, threshold.coerceToString().toString());
}
/**
* Starts determining parameters for the First Run.
* Once finished, calls onFlowIsKnown().
*/
public void start() {
if (CommandLine.getInstance().hasSwitch(ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE)
|| ApiCompatibilityUtils.isDemoUser(mActivity)) {
onFlowIsKnown(null);
return;
}
new AndroidEduAndChildAccountHelper() {
@Override
public void onParametersReady() {
initializeSharedState(isAndroidEduDevice(), hasChildAccount());
processFreEnvironmentPreNative();
}
}.start(mActivity.getApplicationContext());
}
/**
* Starts determining parameters for the First Run.
* Once finished, calls onFlowIsKnown().
*/
public void start() {
if (CommandLine.getInstance().hasSwitch(ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE)
|| ApiCompatibilityUtils.isDemoUser(mActivity)) {
onFlowIsKnown(null);
return;
}
if (!mLaunchProperties.getBoolean(FirstRunActivity.EXTRA_USE_FRE_FLOW_SEQUENCER)) {
onFlowIsKnown(mLaunchProperties);
return;
}
new AndroidEduAndChildAccountHelper() {
@Override
public void onParametersReady() {
processFreEnvironment(isAndroidEduDevice(), hasChildAccount());
}
}.start(mActivity.getApplicationContext());
}
@Override
public void onNewIntentWithNative(Intent intent) {
try {
TraceEvent.begin("ChromeTabbedActivity.onNewIntentWithNative");
super.onNewIntentWithNative(intent);
if (isMainIntentFromLauncher(intent)) {
if (IntentHandler.getUrlFromIntent(intent) == null) {
maybeLaunchNtpFromMainIntent(intent);
}
logMainIntentBehavior(intent);
}
if (CommandLine.getInstance().hasSwitch(ContentSwitches.ENABLE_TEST_INTENTS)) {
handleDebugIntent(intent);
}
} finally {
TraceEvent.end("ChromeTabbedActivity.onNewIntentWithNative");
}
}
/**
* Determines whether to use standard notification layouts, using NotificationCompat.Builder,
* or custom layouts using Chrome's own templates.
*
* The --{enable,disable}-web-notification-custom-layouts command line flags take precedence.
*
* @return Whether custom layouts should be used.
*/
@VisibleForTesting
static boolean useCustomLayouts() {
CommandLine commandLine = CommandLine.getInstance();
if (commandLine.hasSwitch(ChromeSwitches.ENABLE_WEB_NOTIFICATION_CUSTOM_LAYOUTS)) {
return true;
}
if (commandLine.hasSwitch(ChromeSwitches.DISABLE_WEB_NOTIFICATION_CUSTOM_LAYOUTS)) {
return false;
}
if (Build.VERSION.CODENAME.equals("N") || Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
return false;
}
return true;
}
/**
* @return Home page URL from Android provider. If null, that means either there is no homepage
* provider or provider set it to null to disable homepage.
*/
public static String getHomePageUrl() {
CommandLine commandLine = CommandLine.getInstance();
if (commandLine.hasSwitch(ChromeSwitches.PARTNER_HOMEPAGE_FOR_TESTING)) {
return commandLine.getSwitchValue(ChromeSwitches.PARTNER_HOMEPAGE_FOR_TESTING);
}
return sHomepage;
}
/**
* @param context The context that this cache is created in.
* @param resourceId The resource that this value might be defined in.
* @param commandLineSwitch The switch for which we would like to extract value from.
* @return the value of an integer resource. If the value is overridden on the command line
* with the given switch, return the override instead.
*/
private static int getIntegerResourceWithOverride(Context context, int resourceId,
String commandLineSwitch) {
int val = context.getResources().getInteger(resourceId);
String switchCount = CommandLine.getInstance().getSwitchValue(commandLineSwitch);
if (switchCount != null) {
int count = Integer.parseInt(switchCount);
val = count;
}
return val;
}
/**
* @return Whether Reader mode and its new UI are enabled.
* @param context A context
*/
public static boolean isEnabled(Context context) {
if (context == null) return false;
boolean enabled = CommandLine.getInstance().hasSwitch(ChromeSwitches.ENABLE_DOM_DISTILLER)
&& !CommandLine.getInstance().hasSwitch(
ChromeSwitches.DISABLE_READER_MODE_BOTTOM_BAR)
&& !DeviceFormFactor.isTablet(context)
&& DomDistillerTabUtils.isDistillerHeuristicsEnabled()
&& !SysUtils.isLowEndDevice();
return enabled;
}
/**
* The {@link DeviceClassManager} constructor should be self contained and
* rely on system information and command line flags.
*/
private DeviceClassManager() {
// Device based configurations.
if (SysUtils.isLowEndDevice()) {
mEnableSnapshots = false;
mEnableLayerDecorationCache = true;
mEnableAccessibilityLayout = true;
mEnableAnimations = false;
mEnablePrerendering = false;
mEnableToolbarSwipe = false;
mDisableDomainReliability = true;
} else {
mEnableSnapshots = true;
mEnableLayerDecorationCache = true;
mEnableAccessibilityLayout = false;
mEnableAnimations = true;
mEnablePrerendering = true;
mEnableToolbarSwipe = true;
mDisableDomainReliability = false;
}
if (DeviceFormFactor.isTablet(ContextUtils.getApplicationContext())) {
mEnableAccessibilityLayout = false;
}
// Flag based configurations.
CommandLine commandLine = CommandLine.getInstance();
mEnableAccessibilityLayout |= commandLine
.hasSwitch(ChromeSwitches.ENABLE_ACCESSIBILITY_TAB_SWITCHER);
mEnableFullscreen =
!commandLine.hasSwitch(ChromeSwitches.DISABLE_FULLSCREEN);
mEnableToolbarSwipeInDocumentMode =
commandLine.hasSwitch(ChromeSwitches.ENABLE_TOOLBAR_SWIPE_IN_DOCUMENT_MODE);
// Related features.
if (mEnableAccessibilityLayout) {
mEnableAnimations = false;
}
}
/**
* <strong>DO NOT CALL</strong>
* Public to be instanciable from {@link ChromeApplication}. This is however
* intended to be private.
*/
public CustomTabsConnection(Application application) {
super();
mApplication = application;
mClientManager = new ClientManager(mApplication);
mLogRequests = CommandLine.getInstance().hasSwitch(LOG_SERVICE_REQUESTS);
}
private void waitForDebuggerIfNeeded() {
if (CommandLine.getInstance().hasSwitch(BaseSwitches.WAIT_FOR_JAVA_DEBUGGER)) {
Log.e(TAG, "Waiting for Java debugger to connect...");
android.os.Debug.waitForDebugger();
Log.e(TAG, "Java debugger connected. Resuming execution.");
}
}
/**
* Gets a boolean Finch parameter, assuming the <paramName>="true" format. Also checks for a
* command-line switch with the same name, for easy local testing.
* @param paramName The name of the Finch parameter (or command-line switch) to get a value for.
* @return Whether the Finch param is defined with a value "true", if there's a command-line
* flag present with any value.
*/
private static boolean getBooleanParam(String paramName) {
if (CommandLine.getInstance().hasSwitch(paramName)) {
return true;
}
return TextUtils.equals(ENABLED_VALUE,
VariationsAssociatedData.getVariationParamValue(FIELD_TRIAL_NAME, paramName));
}
/**
* @return True if tab model merging for Android N+ is enabled.
*/
public static boolean isTabModelMergingEnabled() {
if (CommandLine.getInstance().hasSwitch(ChromeSwitches.DISABLE_TAB_MERGING_FOR_TESTING)) {
return false;
}
return Build.VERSION.SDK_INT > Build.VERSION_CODES.M;
}
/**
* Gets a boolean Finch parameter, assuming the <paramName>="true" format. Also checks for a
* command-line switch with the same name, for easy local testing.
* @param paramName The name of the Finch parameter (or command-line switch) to get a value for.
* @return Whether the Finch param is defined with a value "true", if there's a command-line
* flag present with any value.
*/
private static boolean getBooleanParam(String paramName) {
if (CommandLine.getInstance().hasSwitch(paramName)) {
return true;
}
return TextUtils.equals(ENABLED_VALUE,
VariationsAssociatedData.getVariationParamValue(FIELD_TRIAL_NAME, paramName));
}
/**
* Gets a boolean VariationsAssociatedData parameter, assuming the <paramName>="true" format.
* Also checks for a command-line switch with the same name, for easy local testing.
* @param paramName The name of the parameter (or command-line switch) to get a value for.
* @return Whether the param is defined with a value "true", if there's a command-line
* flag present with any value.
*/
private static boolean getBooleanParam(String paramName) {
if (CommandLine.getInstance().hasSwitch(paramName)) {
return true;
}
return TextUtils.equals(ENABLED_VALUE,
VariationsAssociatedData.getVariationParamValue(FIELD_TRIAL_NAME, paramName));
}
/**
* Gets a String VariationsAssociatedData parameter. Also checks for a command-line switch with
* the same name, for easy local testing.
* @param paramName The name of the parameter (or command-line switch) to get a value for.
* @return The command-line flag value if present, or the param is value if present.
*/
private static String getStringParamValue(String paramName) {
String value = CommandLine.getInstance().getSwitchValue(paramName);
if (TextUtils.isEmpty(value)) {
value = VariationsAssociatedData.getVariationParamValue(FIELD_TRIAL_NAME, paramName);
}
return value;
}
/**
* Gets a boolean VariationsAssociatedData parameter, assuming the <paramName>="true" format.
* Also checks for a command-line switch with the same name, for easy local testing.
* @param paramName The name of the parameter (or command-line switch) to get a value for.
* @return Whether the param is defined with a value "true", if there's a command-line
* flag present with any value.
*/
private static boolean getBooleanParam(String paramName) {
if (CommandLine.getInstance().hasSwitch(paramName)) {
return true;
}
return TextUtils.equals(ENABLED_VALUE,
VariationsAssociatedData.getVariationParamValue(FIELD_TRIAL_NAME, paramName));
}
/**
* Gets a String VariationsAssociatedData parameter. Also checks for a command-line switch with
* the same name, for easy local testing.
* @param paramName The name of the parameter (or command-line switch) to get a value for.
* @return The command-line flag value if present, or the param is value if present.
*/
private static String getStringParamValue(String paramName) {
String value = CommandLine.getInstance().getSwitchValue(paramName);
if (TextUtils.isEmpty(value)) {
value = VariationsAssociatedData.getVariationParamValue(FIELD_TRIAL_NAME, paramName);
}
return value;
}
/**
* Checks if the First Run needs to be launched.
* @return The intent to launch the First Run Experience if necessary, or null.
* @param context The context.
* @param fromIntent The intent that was used to launch Chrome. It contains the information of
* the client to launch different types of the First Run Experience.
*/
public static Intent checkIfFirstRunIsNecessary(Context context, Intent fromIntent) {
// If FRE is disabled (e.g. in tests), proceed directly to the intent handling.
if (CommandLine.getInstance().hasSwitch(ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE)) {
return null;
}
// If Chrome isn't opened via the Chrome icon, and the user accepted the ToS
// in the Setup Wizard, skip any First Run Experience screens and proceed directly
// to the intent handling.
final boolean fromChromeIcon =
fromIntent != null && TextUtils.equals(fromIntent.getAction(), Intent.ACTION_MAIN);
if (!fromChromeIcon && ToSAckedReceiver.checkAnyUserHasSeenToS(context)) return null;
final boolean baseFreComplete = FirstRunStatus.getFirstRunFlowComplete(context);
if (!baseFreComplete) {
// Show full First Run Experience if Chrome is opened via Chrome icon or GSA (Google
// Search App).
if (fromChromeIcon
|| (fromIntent != null
&& IntentHandler.determineExternalIntentSource(
context.getPackageName(), fromIntent) == ExternalAppId.GSA)) {
return createGenericFirstRunIntent(context, fromChromeIcon);
}
// Show lightweight First Run Experience if the user has not accepted the ToS.
if (!FirstRunStatus.shouldSkipWelcomePage(context)
&& !FirstRunStatus.getLightweightFirstRunFlowComplete(context)) {
return createLightweightFirstRunIntent(context, fromChromeIcon);
}
}
// Promo pages are removed, so there is nothing else to show in FRE.
return null;
}
/**
* Checks if the First Run needs to be launched.
* @param context The context.
* @param fromIntent The intent that was used to launch Chrome.
* @param forLightweightFre Whether this is a check for the Lightweight First Run Experience.
* @return The intent to launch the First Run Experience if necessary, or null.
*/
@Nullable
public static Intent checkIfFirstRunIsNecessary(
Context context, Intent fromIntent, boolean forLightweightFre) {
// If FRE is disabled (e.g. in tests), proceed directly to the intent handling.
if (CommandLine.getInstance().hasSwitch(ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE)
|| ApiCompatibilityUtils.isDemoUser(context)) {
return null;
}
if (fromIntent != null && fromIntent.getBooleanExtra(SKIP_FIRST_RUN_EXPERIENCE, false)) {
return null;
}
// If Chrome isn't opened via the Chrome icon, and the user accepted the ToS
// in the Setup Wizard, skip any First Run Experience screens and proceed directly
// to the intent handling.
final boolean fromChromeIcon =
fromIntent != null && TextUtils.equals(fromIntent.getAction(), Intent.ACTION_MAIN);
if (!fromChromeIcon && ToSAckedReceiver.checkAnyUserHasSeenToS(context)) return null;
final boolean baseFreComplete = FirstRunStatus.getFirstRunFlowComplete();
if (!baseFreComplete) {
if (forLightweightFre
&& CommandLine.getInstance().hasSwitch(
ChromeSwitches.ENABLE_LIGHTWEIGHT_FIRST_RUN_EXPERIENCE)) {
if (!FirstRunStatus.shouldSkipWelcomePage()
&& !FirstRunStatus.getLightweightFirstRunFlowComplete()) {
return createLightweightFirstRunIntent(context, fromChromeIcon);
}
} else {
return createGenericFirstRunIntent(context, fromChromeIcon);
}
}
// Promo pages are removed, so there is nothing else to show in FRE.
return null;
}
@Override
public void initializeState() {
super.initializeState();
IntentHandler.setTestIntentsEnabled(
CommandLine.getInstance().hasSwitch(ContentSwitches.ENABLE_TEST_INTENTS));
mIntentHandler = new IntentHandler(createIntentHandlerDelegate(), getPackageName());
}