0

Add @NullMarked to //chrome/browser/supervised_user

Bug: 389129271
Change-Id: I1d598acd50901cccb19ba5f522f0d4337408b133
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6382878
Commit-Queue: Andrew Grieve <agrieve@chromium.org>
Owners-Override: Andrew Grieve <agrieve@chromium.org>
Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1436204}
This commit is contained in:
Andrew Grieve
2025-03-21 11:58:47 -07:00
committed by Chromium LUCI CQ
parent 76a46310d7
commit 715c4dbba8
11 changed files with 60 additions and 28 deletions
chrome/browser
data_sharing
android
java
src
org
chromium
chrome
browser
data_sharing
ui
shared_image_tiles
password_manager
android
java
src
org
chromium
chrome
browser
password_manager
supervised_user
components/autofill/android/java/src/org/chromium/components/autofill

@ -10,6 +10,7 @@ import androidx.annotation.ColorInt;
import androidx.annotation.DimenRes;
import androidx.annotation.StyleRes;
import org.chromium.build.annotations.NullMarked;
import org.chromium.components.browser_ui.styles.ChromeColors;
import org.chromium.components.browser_ui.styles.SemanticColorUtils;
@ -17,6 +18,7 @@ import org.chromium.components.browser_ui.styles.SemanticColorUtils;
* Config class for the SharedImageTiles UI. By default this component is dynamically colored with a
* size of 28dp for each image tiles.
*/
@NullMarked
public class SharedImageTilesConfig {
// --- Sizes ---
public final @DimenRes int iconSizeDp;

@ -10,16 +10,18 @@ import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.DialogFragment;
import org.chromium.build.annotations.NullMarked;
import org.chromium.build.annotations.Nullable;
import org.chromium.chrome.browser.password_manager.R;
/**
* Shows the dialog that explains to the user the error which just happened during exporting and
* optionally helps them to take actions to fix that (learning more, retrying export).
*/
@NullMarked
public class ExportErrorDialogFragment extends DialogFragment {
/** Parameters to fill in the strings in the dialog. Pass them through {@link #initialize()}. */
public static class ErrorDialogParams {
@ -30,20 +32,20 @@ public class ExportErrorDialogFragment extends DialogFragment {
public int positiveButtonLabelId;
/** The main description of the error. Required. */
public String description;
public @Nullable String description;
/**
* An optional detailed description. Will be prefixed with "Details:" and displayed below
* the main one.
*/
@Nullable public String detailedDescription;
public @Nullable String detailedDescription;
}
// This handler is used to answer the user actions on the dialog.
private DialogInterface.OnClickListener mHandler;
private DialogInterface.@Nullable OnClickListener mHandler;
/** Defines the strings to be shown. Set in {@link #initialize()}. */
private ErrorDialogParams mParams;
private @Nullable ErrorDialogParams mParams;
/**
* Sets the click handler for the dialog buttons.
@ -58,7 +60,7 @@ public class ExportErrorDialogFragment extends DialogFragment {
* passed in arguments.
*/
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
assert mParams != null;
final View dialog =
getActivity().getLayoutInflater().inflate(R.layout.passwords_error_dialog, null);
@ -85,7 +87,7 @@ public class ExportErrorDialogFragment extends DialogFragment {
}
@Override
public void onCreate(Bundle savedInstanceState) {
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// If there is savedInstanceState, then the dialog is being recreated by Android and will
// lack the necessary callbacks. The user likely already saw it first and then replaced the

@ -10,11 +10,14 @@ import androidx.annotation.VisibleForTesting;
import org.chromium.base.ServiceLoaderUtil;
import org.chromium.base.ThreadUtils;
import org.chromium.build.annotations.NullMarked;
import org.chromium.build.annotations.Nullable;
/** Helper class that provides a test or production instance for {@link ParentAuthDelegate}. */
@NullMarked
public class ParentAuthDelegateProvider {
private static ParentAuthDelegate sInstance;
private static ParentAuthDelegate sTestingInstance;
private static @Nullable ParentAuthDelegate sInstance;
private static @Nullable ParentAuthDelegate sTestingInstance;
/**
* Sets the test instance. Can be called multiple times to change the instance
@ -32,7 +35,7 @@ public class ParentAuthDelegateProvider {
/** Returns singleton instance. */
@MainThread
public static ParentAuthDelegate getInstance() {
public static @Nullable ParentAuthDelegate getInstance() {
ThreadUtils.assertOnUiThread();
if (sTestingInstance != null) {
return sTestingInstance;

@ -4,6 +4,9 @@
package org.chromium.chrome.browser.supervised_user;
import static org.chromium.build.NullUtil.assumeNonNull;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Color;
@ -13,6 +16,8 @@ import org.jni_zero.JniType;
import org.jni_zero.NativeMethods;
import org.chromium.base.Callback;
import org.chromium.build.annotations.NullMarked;
import org.chromium.build.annotations.Nullable;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.supervised_user.android.AndroidLocalWebApprovalFlowOutcome;
import org.chromium.chrome.browser.supervised_user.website_approval.WebsiteApprovalCoordinator;
@ -21,34 +26,35 @@ import org.chromium.ui.base.WindowAndroid;
import org.chromium.url.GURL;
/** Requests approval from a parent of a supervised user to unblock navigation to a given URL. */
@NullMarked
class WebsiteParentApproval {
// Favicon default specifications
private static final int FAVICON_MIN_SOURCE_SIZE_PIXEL = 16;
/** Wrapper class used to store a fetched favicon and the fallback monogram icon. */
private static final class FaviconHelper {
Bitmap mFavicon;
Bitmap mFallbackIcon;
@Nullable Bitmap mFavicon;
@Nullable Bitmap mFallbackIcon;
public void setFavicon(Bitmap favicon) {
mFavicon = favicon;
}
public Bitmap getFavicon() {
public @Nullable Bitmap getFavicon() {
return mFavicon;
}
public void setFallbackIcon(Bitmap fallbackIcon) {
public void setFallbackIcon(@Nullable Bitmap fallbackIcon) {
mFallbackIcon = fallbackIcon;
}
public Bitmap getFallbackIcon() {
public @Nullable Bitmap getFallbackIcon() {
return mFallbackIcon;
}
}
/** Created a fallback monogram icon from the first letter of the formatted url. */
private static Bitmap createFaviconFallback(Resources res, GURL url) {
private static @Nullable Bitmap createFaviconFallback(Resources res, GURL url) {
int sizeWidthPx = res.getDimensionPixelSize(R.dimen.monogram_size);
int cornerRadiusPx = res.getDimensionPixelSize(R.dimen.monogram_corner_radius);
int textSizePx = res.getDimensionPixelSize(R.dimen.monogram_text_size);
@ -95,12 +101,10 @@ class WebsiteParentApproval {
onParentAuthComplete(success, windowAndroid, url, faviconHelper, profile);
});
Context context = windowAndroid.getContext().get();
assumeNonNull(context);
int desiredFaviconWidthPx =
windowAndroid
.getContext()
.get()
.getResources()
.getDimensionPixelSize(R.dimen.favicon_size_width);
context.getResources().getDimensionPixelSize(R.dimen.favicon_size_width);
// Trigger favicon fetching asynchronously and create fallback monoggram.
WebsiteParentApprovalJni.get()
.fetchFavicon(
@ -109,8 +113,7 @@ class WebsiteParentApproval {
desiredFaviconWidthPx,
profile,
(Bitmap favicon) -> faviconHelper.setFavicon(favicon));
faviconHelper.setFallbackIcon(
createFaviconFallback(windowAndroid.getContext().get().getResources(), url));
faviconHelper.setFallbackIcon(createFaviconFallback(context.getResources(), url));
}
/** Displays the screen giving the parent the option to approve or deny the website. */

@ -4,8 +4,12 @@
package org.chromium.chrome.browser.supervised_user.website_approval;
import static org.chromium.build.NullUtil.assertNonNull;
import android.graphics.Bitmap;
import org.chromium.build.annotations.NullMarked;
import org.chromium.build.annotations.Nullable;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.components.browser_ui.bottomsheet.BottomSheetController;
import org.chromium.components.browser_ui.bottomsheet.BottomSheetControllerProvider;
@ -18,6 +22,7 @@ import org.chromium.url.GURL;
* Coordinator for the bottom sheet content in the screen which allows a parent to approve or deny
* a website.
*/
@NullMarked
public class WebsiteApprovalCoordinator {
private final WebsiteApprovalMediator mMediator;
@ -40,7 +45,7 @@ public class WebsiteApprovalCoordinator {
WindowAndroid windowAndroid,
GURL url,
CompletionCallback completionCallback,
Bitmap favicon,
@Nullable Bitmap favicon,
Profile profile) {
PropertyModel model =
new PropertyModel.Builder(WebsiteApprovalProperties.ALL_KEYS)
@ -50,8 +55,9 @@ public class WebsiteApprovalCoordinator {
BottomSheetController bottomSheetController =
BottomSheetControllerProvider.from(windowAndroid);
assert bottomSheetController != null;
WebsiteApprovalSheetContent sheetContent =
new WebsiteApprovalSheetContent(windowAndroid.getContext().get());
new WebsiteApprovalSheetContent(assertNonNull(windowAndroid.getContext().get()));
PropertyModelChangeProcessor.create(model, sheetContent, WebsiteApprovalViewBinder::bind);

@ -4,6 +4,9 @@
package org.chromium.chrome.browser.supervised_user.website_approval;
import static org.chromium.build.NullUtil.assumeNonNull;
import org.chromium.build.annotations.NullMarked;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.signin.services.IdentityServicesProvider;
import org.chromium.components.browser_ui.bottomsheet.BottomSheetController;
@ -17,6 +20,7 @@ import org.chromium.ui.modelutil.PropertyModel;
* Contains the logic for the WebsiteApproval component. It sets the state of the model and reacts
* to events like clicks.
*/
@NullMarked
class WebsiteApprovalMediator {
private final WebsiteApprovalCoordinator.CompletionCallback mCompletionCallback;
private final BottomSheetController mBottomSheetController;
@ -61,6 +65,7 @@ class WebsiteApprovalMediator {
// use the full account email address.
IdentityManager identityManager =
IdentityServicesProvider.get().getIdentityManager(mProfile);
assumeNonNull(identityManager);
String childEmail =
CoreAccountInfo.getEmailFrom(
identityManager.getPrimaryAccountInfo(ConsentLevel.SIGNIN));

@ -7,11 +7,13 @@ package org.chromium.chrome.browser.supervised_user.website_approval;
import android.graphics.Bitmap;
import android.view.View.OnClickListener;
import org.chromium.build.annotations.NullMarked;
import org.chromium.ui.modelutil.PropertyKey;
import org.chromium.ui.modelutil.PropertyModel;
import org.chromium.url.GURL;
/** Properties defined here reflect the visible state of the WebsiteApproval components. */
@NullMarked
class WebsiteApprovalProperties {
static final PropertyModel.WritableObjectPropertyKey<String> CHILD_NAME =
new PropertyModel.WritableObjectPropertyKey<>("child_name");

@ -13,12 +13,12 @@ import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import androidx.annotation.VisibleForTesting;
import androidx.appcompat.widget.DialogTitle;
import org.chromium.build.annotations.NullMarked;
import org.chromium.build.annotations.Nullable;
import org.chromium.chrome.browser.supervised_user.R;
import org.chromium.components.browser_ui.bottomsheet.BottomSheetContent;
import org.chromium.components.url_formatter.UrlFormatter;
@ -27,6 +27,7 @@ import org.chromium.ui.widget.ButtonCompat;
import org.chromium.url.GURL;
/** Bottom sheet content for the screen which allows a parent to approve or deny a website. */
@NullMarked
class WebsiteApprovalSheetContent implements BottomSheetContent {
private static final String ELLIPSIS = "...";
static final int MAX_HOST_SIZE = 256;
@ -100,7 +101,7 @@ class WebsiteApprovalSheetContent implements BottomSheetContent {
}
@Override
public @NonNull String getSheetContentDescription(Context context) {
public String getSheetContentDescription(Context context) {
return context.getString(R.string.parent_website_approval_content_description);
}

@ -4,6 +4,7 @@
package org.chromium.chrome.browser.supervised_user.website_approval;
import org.chromium.build.annotations.NullMarked;
import org.chromium.ui.modelutil.PropertyKey;
import org.chromium.ui.modelutil.PropertyModel;
@ -11,6 +12,7 @@ import org.chromium.ui.modelutil.PropertyModel;
* Provides functions that map {@link WebsiteApprovalProperties} changes in a {@link PropertyModel}
* to the suitable method in {@link WebsiteApprovalSheetContent}.
*/
@NullMarked
class WebsiteApprovalViewBinder {
/**
* Called whenever a property in the given model changes. It updates the given view

@ -8,9 +8,12 @@ import org.jni_zero.CalledByNative;
import org.jni_zero.JNINamespace;
import org.jni_zero.JniType;
import org.chromium.build.annotations.NullMarked;
import java.util.List;
@JNINamespace("autofill")
@NullMarked
public class AutofillAddressEditorUiInfo {
private String mBestLanguageTag;

@ -10,8 +10,11 @@ import org.jni_zero.CalledByNative;
import org.jni_zero.JNINamespace;
import org.jni_zero.JniType;
import org.chromium.build.annotations.NullMarked;
/** A convenience class for displaying keyed values in a dropdown. */
@JNINamespace("autofill")
@NullMarked
public class DropdownKeyValue extends Pair<String, String> {
@CalledByNative
public DropdownKeyValue(