summaryrefslogtreecommitdiff
path: root/main/java/com/google/android/setupcompat/util
diff options
context:
space:
mode:
Diffstat (limited to 'main/java/com/google/android/setupcompat/util')
-rw-r--r--main/java/com/google/android/setupcompat/util/BuildCompatUtils.java66
-rw-r--r--main/java/com/google/android/setupcompat/util/Logger.java83
-rw-r--r--main/java/com/google/android/setupcompat/util/SystemBarHelper.java7
-rw-r--r--main/java/com/google/android/setupcompat/util/WizardManagerHelper.java28
4 files changed, 175 insertions, 9 deletions
diff --git a/main/java/com/google/android/setupcompat/util/BuildCompatUtils.java b/main/java/com/google/android/setupcompat/util/BuildCompatUtils.java
new file mode 100644
index 0000000..ea54745
--- /dev/null
+++ b/main/java/com/google/android/setupcompat/util/BuildCompatUtils.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2021 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.google.android.setupcompat.util;
+
+import android.os.Build;
+
+/**
+ * An util class to check whether the current OS version is higher or equal to sdk version of
+ * device.
+ */
+public final class BuildCompatUtils {
+
+ /**
+ * Implementation of BuildCompat.isAtLeast*() suitable for use in Setup
+ *
+ * <p>BuildCompat.isAtLeast*() can be changed by Android Release team, and once that is changed it
+ * may take weeks for that to propagate to stable/prerelease/experimental SDKs in Google3. Also it
+ * can be different in all these channels. This can cause random issues, especially with sidecars
+ * (i.e., the code running on R may not know that it runs on R).
+ *
+ * <p>This still should try using BuildCompat.isAtLeastR() as source of truth, but also checking
+ * for VERSION_SDK_INT and VERSION.CODENAME in case when BuildCompat implementation returned
+ * false. Note that both checks should be >= and not = to make sure that when Android version
+ * increases (i.e., from R to S), this does not stop working.
+ *
+ * <p>Supported configurations:
+ *
+ * <ul>
+ * <li>For current Android release: while new API is not finalized yet (CODENAME = "S", SDK_INT
+ * = 30|31)
+ * <li>For current Android release: when new API is finalized (CODENAME = "REL", SDK_INT = 31)
+ * <li>For next Android release (CODENAME = "T", SDK_INT = 30+)
+ * </ul>
+ *
+ * <p>Note that Build.VERSION_CODES.S cannot be used here until final SDK is available in all
+ * Google3 channels, because it is equal to Build.VERSION_CODES.CUR_DEVELOPMENT before API
+ * finalization.
+ *
+ * @return Whether the current OS version is higher or equal to S.
+ */
+ public static boolean isAtLeastS() {
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
+ return false;
+ }
+ return (Build.VERSION.CODENAME.equals("REL") && Build.VERSION.SDK_INT >= 31)
+ || (Build.VERSION.CODENAME.length() == 1
+ && Build.VERSION.CODENAME.charAt(0) >= 'S'
+ && Build.VERSION.CODENAME.charAt(0) <= 'Z');
+ }
+
+ private BuildCompatUtils() {}
+}
diff --git a/main/java/com/google/android/setupcompat/util/Logger.java b/main/java/com/google/android/setupcompat/util/Logger.java
new file mode 100644
index 0000000..3f8dfd1
--- /dev/null
+++ b/main/java/com/google/android/setupcompat/util/Logger.java
@@ -0,0 +1,83 @@
+/*
+ * Copyright (C) 2021 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.google.android.setupcompat.util;
+
+import android.util.Log;
+
+/**
+ * Helper class that wraps {@link Log} to log messages to logcat. This class consolidate the log
+ * {@link #TAG} in both SetupCompat and SetupDesign library.
+ *
+ * <p>When logging verbose and debug logs, the logs should either be guarded by {@code if
+ * (logger.isV())}, or a constant if (DEBUG). That DEBUG constant should be false on any submitted
+ * code.
+ */
+public final class Logger {
+
+ public static final String TAG = "SetupLibrary";
+
+ private final String prefix;
+
+ public Logger(Class<?> cls) {
+ this(cls.getSimpleName());
+ }
+
+ public Logger(String prefix) {
+ this.prefix = "[" + prefix + "] ";
+ }
+
+ public boolean isV() {
+ return Log.isLoggable(TAG, Log.VERBOSE);
+ }
+
+ public boolean isD() {
+ return Log.isLoggable(TAG, Log.DEBUG);
+ }
+
+ public boolean isI() {
+ return Log.isLoggable(TAG, Log.INFO);
+ }
+
+ public void atVerbose(String message) {
+ if (isV()) {
+ Log.v(TAG, prefix.concat(message));
+ }
+ }
+
+ public void atDebug(String message) {
+ if (isD()) {
+ Log.d(TAG, prefix.concat(message));
+ }
+ }
+
+ public void atInfo(String message) {
+ if (isI()) {
+ Log.i(TAG, prefix.concat(message));
+ }
+ }
+
+ public void w(String message) {
+ Log.w(TAG, prefix.concat(message));
+ }
+
+ public void e(String message) {
+ Log.e(TAG, prefix.concat(message));
+ }
+
+ public void e(String message, Throwable throwable) {
+ Log.e(TAG, prefix.concat(message), throwable);
+ }
+}
diff --git a/main/java/com/google/android/setupcompat/util/SystemBarHelper.java b/main/java/com/google/android/setupcompat/util/SystemBarHelper.java
index 75e5dd3..dd92501 100644
--- a/main/java/com/google/android/setupcompat/util/SystemBarHelper.java
+++ b/main/java/com/google/android/setupcompat/util/SystemBarHelper.java
@@ -24,13 +24,12 @@ import android.content.res.TypedArray;
import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;
import android.os.Handler;
-import androidx.annotation.RequiresPermission;
-import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowInsets;
import android.view.WindowManager;
+import androidx.annotation.RequiresPermission;
/**
* A helper class to manage the system navigation bar and status bar. This will add various
@@ -44,7 +43,7 @@ import android.view.WindowManager;
*/
public final class SystemBarHelper {
- private static final String TAG = "SystemBarHelper";
+ private static final Logger LOG = new Logger("SystemBarHelper");
/** Needs to be equal to View.STATUS_BAR_DISABLE_BACK */
private static final int STATUS_BAR_DISABLE_BACK = 0x00400000;
@@ -329,7 +328,7 @@ public final class SystemBarHelper {
// If the decor view is not installed yet, try again in the next loop.
handler.post(checkDecorViewRunnable);
} else {
- Log.w(TAG, "Cannot get decor view of window: " + window);
+ LOG.e("Cannot get decor view of window: " + window);
}
}
}
diff --git a/main/java/com/google/android/setupcompat/util/WizardManagerHelper.java b/main/java/com/google/android/setupcompat/util/WizardManagerHelper.java
index bfe1dbb..79976bc 100644
--- a/main/java/com/google/android/setupcompat/util/WizardManagerHelper.java
+++ b/main/java/com/google/android/setupcompat/util/WizardManagerHelper.java
@@ -34,7 +34,7 @@ import java.util.Arrays;
*/
public final class WizardManagerHelper {
- private static final String ACTION_NEXT = "com.android.wizard.NEXT";
+ @VisibleForTesting public static final String ACTION_NEXT = "com.android.wizard.NEXT";
// EXTRA_SCRIPT_URI and EXTRA_ACTION_ID are used in setup wizard in versions before M and are
// kept for backwards compatibility.
@@ -43,10 +43,27 @@ public final class WizardManagerHelper {
@VisibleForTesting static final String EXTRA_WIZARD_BUNDLE = "wizardBundle";
private static final String EXTRA_RESULT_CODE = "com.android.setupwizard.ResultCode";
- @VisibleForTesting public static final String EXTRA_IS_FIRST_RUN = "firstRun";
- @VisibleForTesting static final String EXTRA_IS_DEFERRED_SETUP = "deferredSetup";
- @VisibleForTesting static final String EXTRA_IS_PRE_DEFERRED_SETUP = "preDeferredSetup";
- @VisibleForTesting public static final String EXTRA_IS_SETUP_FLOW = "isSetupFlow";
+
+ /** Extra for notifying an Activity that it is inside the first SetupWizard flow or not. */
+ public static final String EXTRA_IS_FIRST_RUN = "firstRun";
+
+ /** Extra for notifying an Activity that it is inside the Deferred SetupWizard flow or not. */
+ public static final String EXTRA_IS_DEFERRED_SETUP = "deferredSetup";
+
+ /** Extra for notifying an Activity that it is inside the "Pre-Deferred Setup" flow. */
+ public static final String EXTRA_IS_PRE_DEFERRED_SETUP = "preDeferredSetup";
+
+ /** Extra for notifying an Activity that it is inside the "Portal Setup" flow. */
+ public static final String EXTRA_IS_PORTAL_SETUP = "portalSetup";
+
+ /**
+ * Extra for notifying an Activity that it is inside the any setup flow.
+ *
+ * <p>Apps that target API levels below {@link android.os.Build.VERSION_CODES#Q} is able to
+ * determine whether Activity is inside the any setup flow by one of {@link #EXTRA_IS_FIRST_RUN},
+ * {@link #EXTRA_IS_DEFERRED_SETUP}, and {@link #EXTRA_IS_PRE_DEFERRED_SETUP} is true.
+ */
+ public static final String EXTRA_IS_SETUP_FLOW = "isSetupFlow";
public static final String EXTRA_THEME = "theme";
public static final String EXTRA_USE_IMMERSIVE_MODE = "useImmersiveMode";
@@ -104,6 +121,7 @@ public final class WizardManagerHelper {
EXTRA_IS_FIRST_RUN,
EXTRA_IS_DEFERRED_SETUP,
EXTRA_IS_PRE_DEFERRED_SETUP,
+ EXTRA_IS_PORTAL_SETUP,
EXTRA_IS_SETUP_FLOW)) {
dstIntent.putExtra(key, srcIntent.getBooleanExtra(key, false));
}