diff options
author | 2023-09-18 17:04:02 -0400 | |
---|---|---|
committer | 2023-11-13 15:51:03 -0500 | |
commit | 7b3cb6c1cee654303e0644139c636e8c36755ded (patch) | |
tree | 89b7260c5e1c3344b46822b53f152578910e5827 | |
parent | 75e928b3330c383363096d9113a804215863fba5 (diff) |
Unify annotations packages, fix missing nullability info
Automated cleanups:
use androidx.annotation.* consistently across the codebase.
corrects missing nullability annotations method parameters,
constructors and and overridden methods return values.
Test: atest IntentResolverUnitTests
Bug: 300157408
Change-Id: Id48b7ce3e70400bd8ff5d51dabc77e8e04bbfc5c
50 files changed, 255 insertions, 167 deletions
diff --git a/java/src/com/android/intentresolver/AnnotatedUserHandles.java b/java/src/com/android/intentresolver/AnnotatedUserHandles.java index 5d559f5b..3565e757 100644 --- a/java/src/com/android/intentresolver/AnnotatedUserHandles.java +++ b/java/src/com/android/intentresolver/AnnotatedUserHandles.java @@ -16,12 +16,12 @@ package com.android.intentresolver; -import android.annotation.Nullable; import android.app.Activity; import android.app.ActivityManager; import android.os.UserHandle; import android.os.UserManager; +import androidx.annotation.Nullable; import androidx.annotation.VisibleForTesting; /** @@ -35,7 +35,7 @@ public final class AnnotatedUserHandles { /** * The {@link UserHandle} that launched Sharesheet. * TODO: I believe this would always be the handle corresponding to {@code userIdOfCallingApp} - * except possibly if the caller used {@link Activity#startActivityAsUser()} to launch + * except possibly if the caller used {@link Activity#startActivityAsUser} to launch * Sharesheet as a different user than they themselves were running as. Verify and document. */ public final UserHandle userHandleSharesheetLaunchedAs; @@ -57,21 +57,21 @@ public final class AnnotatedUserHandles { /** * The {@link UserHandle} that owns the "work tab" in a tabbed share UI. This is (an arbitrary) - * one of the "managed" profiles associated with {@link personalProfileUserHandle}. + * one of the "managed" profiles associated with {@link #personalProfileUserHandle}. */ @Nullable public final UserHandle workProfileUserHandle; /** - * The {@link UserHandle} of the clone profile belonging to {@link personalProfileUserHandle}. + * The {@link UserHandle} of the clone profile belonging to {@link #personalProfileUserHandle}. */ @Nullable public final UserHandle cloneProfileUserHandle; /** - * The "tab owner" user handle (i.e., either {@link personalProfileUserHandle} or - * {@link workProfileUserHandle}) that either matches or owns the profile of the - * {@link userHandleSharesheetLaunchedAs}. + * The "tab owner" user handle (i.e., either {@link #personalProfileUserHandle} or + * {@link #workProfileUserHandle}) that either matches or owns the profile of the + * {@link #userHandleSharesheetLaunchedAs}. * * In the current implementation, we can assert that this is the same as * `userHandleSharesheetLaunchedAs` except when the latter is the clone profile; then this is diff --git a/java/src/com/android/intentresolver/ChooserActionFactory.java b/java/src/com/android/intentresolver/ChooserActionFactory.java index c7c0beeb..310fcc27 100644 --- a/java/src/com/android/intentresolver/ChooserActionFactory.java +++ b/java/src/com/android/intentresolver/ChooserActionFactory.java @@ -16,7 +16,6 @@ package com.android.intentresolver; -import android.annotation.Nullable; import android.app.Activity; import android.app.ActivityOptions; import android.app.PendingIntent; @@ -34,6 +33,8 @@ import android.text.TextUtils; import android.util.Log; import android.view.View; +import androidx.annotation.Nullable; + import com.android.intentresolver.chooser.DisplayResolveInfo; import com.android.intentresolver.chooser.TargetInfo; import com.android.intentresolver.contentpreview.ChooserContentPreviewUi; diff --git a/java/src/com/android/intentresolver/ChooserActivity.java b/java/src/com/android/intentresolver/ChooserActivity.java index 707c64b7..2f950baa 100644 --- a/java/src/com/android/intentresolver/ChooserActivity.java +++ b/java/src/com/android/intentresolver/ChooserActivity.java @@ -28,8 +28,6 @@ import static androidx.lifecycle.LifecycleKt.getCoroutineScope; import static com.android.internal.util.LatencyTracker.ACTION_LOAD_SHARE_SHEET; -import android.annotation.IntDef; -import android.annotation.Nullable; import android.app.Activity; import android.app.ActivityManager; import android.app.ActivityOptions; @@ -67,8 +65,10 @@ import android.view.ViewTreeObserver; import android.view.WindowInsets; import android.widget.TextView; +import androidx.annotation.IntDef; import androidx.annotation.MainThread; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import androidx.lifecycle.ViewModelProvider; import androidx.recyclerview.widget.GridLayoutManager; import androidx.recyclerview.widget.RecyclerView; @@ -165,7 +165,7 @@ public class ChooserActivity extends Hilt_ChooserActivity implements private static final int SCROLL_STATUS_SCROLLING_VERTICAL = 1; private static final int SCROLL_STATUS_SCROLLING_HORIZONTAL = 2; - @IntDef(flag = false, prefix = { "TARGET_TYPE_" }, value = { + @IntDef({ TARGET_TYPE_DEFAULT, TARGET_TYPE_CHOOSER_TARGET, TARGET_TYPE_SHORTCUTS_FROM_SHORTCUT_MANAGER, @@ -605,7 +605,7 @@ public class ChooserActivity extends Hilt_ChooserActivity implements } @Override - public void onConfigurationChanged(Configuration newConfig) { + public void onConfigurationChanged(@NonNull Configuration newConfig) { super.onConfigurationChanged(newConfig); ViewPager viewPager = findViewById(com.android.internal.R.id.profile_pager); if (viewPager.isLayoutRtl()) { @@ -1592,7 +1592,7 @@ public class ChooserActivity extends Hilt_ChooserActivity implements mChooserMultiProfilePagerAdapter.getActiveAdapterView().addOnScrollListener( new RecyclerView.OnScrollListener() { @Override - public void onScrollStateChanged(RecyclerView view, int scrollState) { + public void onScrollStateChanged(@NonNull RecyclerView view, int scrollState) { if (scrollState == RecyclerView.SCROLL_STATE_IDLE) { if (mScrollStatus == SCROLL_STATUS_SCROLLING_VERTICAL) { mScrollStatus = SCROLL_STATUS_IDLE; @@ -1607,7 +1607,7 @@ public class ChooserActivity extends Hilt_ChooserActivity implements } @Override - public void onScrolled(RecyclerView view, int dx, int dy) { + public void onScrolled(@NonNull RecyclerView view, int dx, int dy) { if (view.getChildCount() > 0) { View child = view.getLayoutManager().findViewByPosition(0); if (child == null || child.getTop() < 0) { diff --git a/java/src/com/android/intentresolver/ChooserIntegratedDeviceComponents.java b/java/src/com/android/intentresolver/ChooserIntegratedDeviceComponents.java index df5a8dc8..7cd86bf4 100644 --- a/java/src/com/android/intentresolver/ChooserIntegratedDeviceComponents.java +++ b/java/src/com/android/intentresolver/ChooserIntegratedDeviceComponents.java @@ -16,12 +16,13 @@ package com.android.intentresolver; -import android.annotation.Nullable; import android.content.ComponentName; import android.content.Context; import android.provider.Settings; import android.text.TextUtils; +import androidx.annotation.Nullable; + import com.android.internal.annotations.VisibleForTesting; /** @@ -49,8 +50,9 @@ public class ChooserIntegratedDeviceComponents { } @VisibleForTesting - public ChooserIntegratedDeviceComponents( - ComponentName editSharingComponent, ComponentName nearbySharingComponent) { + ChooserIntegratedDeviceComponents( + @Nullable ComponentName editSharingComponent, + @Nullable ComponentName nearbySharingComponent) { mEditSharingComponent = editSharingComponent; mNearbySharingComponent = nearbySharingComponent; } diff --git a/java/src/com/android/intentresolver/ChooserListAdapter.java b/java/src/com/android/intentresolver/ChooserListAdapter.java index 9a15c919..823b5e13 100644 --- a/java/src/com/android/intentresolver/ChooserListAdapter.java +++ b/java/src/com/android/intentresolver/ChooserListAdapter.java @@ -19,7 +19,6 @@ package com.android.intentresolver; import static com.android.intentresolver.ChooserActivity.TARGET_TYPE_SHORTCUTS_FROM_PREDICTION_SERVICE; import static com.android.intentresolver.ChooserActivity.TARGET_TYPE_SHORTCUTS_FROM_SHORTCUT_MANAGER; -import android.annotation.Nullable; import android.app.ActivityManager; import android.app.prediction.AppTarget; import android.content.ComponentName; @@ -45,6 +44,7 @@ import android.view.ViewGroup; import android.widget.TextView; import androidx.annotation.MainThread; +import androidx.annotation.Nullable; import androidx.annotation.WorkerThread; import com.android.intentresolver.chooser.DisplayResolveInfo; diff --git a/java/src/com/android/intentresolver/ChooserRecyclerViewAccessibilityDelegate.java b/java/src/com/android/intentresolver/ChooserRecyclerViewAccessibilityDelegate.java index 3f6a3437..d6688d90 100644 --- a/java/src/com/android/intentresolver/ChooserRecyclerViewAccessibilityDelegate.java +++ b/java/src/com/android/intentresolver/ChooserRecyclerViewAccessibilityDelegate.java @@ -16,12 +16,12 @@ package com.android.intentresolver; -import android.annotation.NonNull; import android.graphics.Rect; import android.view.View; import android.view.ViewGroup; import android.view.accessibility.AccessibilityEvent; +import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerViewAccessibilityDelegate; diff --git a/java/src/com/android/intentresolver/ChooserRefinementManager.java b/java/src/com/android/intentresolver/ChooserRefinementManager.java index b3b08de7..474b240f 100644 --- a/java/src/com/android/intentresolver/ChooserRefinementManager.java +++ b/java/src/com/android/intentresolver/ChooserRefinementManager.java @@ -16,8 +16,6 @@ package com.android.intentresolver; -import android.annotation.Nullable; -import android.annotation.UiThread; import android.app.Activity; import android.app.Application; import android.content.Intent; @@ -28,6 +26,8 @@ import android.os.Parcel; import android.os.ResultReceiver; import android.util.Log; +import androidx.annotation.Nullable; +import androidx.annotation.UiThread; import androidx.lifecycle.LiveData; import androidx.lifecycle.MutableLiveData; import androidx.lifecycle.ViewModel; @@ -41,6 +41,7 @@ import java.util.function.Consumer; import javax.inject.Inject; + /** * Helper class to manage Sharesheet's "refinement" flow, where callers supply a "refinement * activity" that will be invoked when a target is selected, allowing the calling app to add diff --git a/java/src/com/android/intentresolver/ChooserRequestParameters.java b/java/src/com/android/intentresolver/ChooserRequestParameters.java index b05d51b2..7ad809e9 100644 --- a/java/src/com/android/intentresolver/ChooserRequestParameters.java +++ b/java/src/com/android/intentresolver/ChooserRequestParameters.java @@ -16,8 +16,6 @@ package com.android.intentresolver; -import android.annotation.NonNull; -import android.annotation.Nullable; import android.content.ComponentName; import android.content.Intent; import android.content.IntentFilter; @@ -32,6 +30,9 @@ import android.text.TextUtils; import android.util.Log; import android.util.Pair; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + import com.android.intentresolver.util.UriFilters; import com.google.common.collect.ImmutableList; @@ -210,7 +211,7 @@ public class ChooserRequestParameters { /** * TODO: this returns a nullable array for convenience, but if the legacy APIs can be - * refactored, returning {@link mAdditionalTargets} directly is simpler and safer. + * refactored, returning {@link #mAdditionalTargets} directly is simpler and safer. */ @Nullable public Intent[] getAdditionalTargets() { @@ -224,7 +225,7 @@ public class ChooserRequestParameters { /** * TODO: this returns a nullable array for convenience, but if the legacy APIs can be - * refactored, returning {@link mInitialIntents} directly is simpler and safer. + * refactored, returning {@link #mInitialIntents} directly is simpler and safer. */ @Nullable public Intent[] getInitialIntents() { @@ -286,7 +287,7 @@ public class ChooserRequestParameters { * requested target <em>wasn't</em> a send action; otherwise it is null. The second value is * the resource ID of a default title string; this is nonzero only if the first value is null. * - * TODO: change the API for how these are passed up to {@link ResolverActivity#onCreate()}, or + * TODO: change the API for how these are passed up to {@link ResolverActivity#onCreate}, or * create a real type (not {@link Pair}) to express the semantics described in this comment. */ private static Pair<CharSequence, Integer> makeTitleSpec( @@ -369,7 +370,7 @@ public class ChooserRequestParameters { * the required type. If false, throw an {@link IllegalArgumentException} if the extra is * non-null but can't be assigned to variables of type {@code T}. * @param streamEmptyIfNull Whether to return an empty stream if the optional extra isn't - * present in the intent (or if it had the wrong type, but {@link warnOnTypeError} is true). + * present in the intent (or if it had the wrong type, but <em>warnOnTypeError</em> is true). * If false, return null in these cases, and only return an empty stream if the intent * explicitly provided an empty array for the specified extra. */ diff --git a/java/src/com/android/intentresolver/ChooserStackedAppDialogFragment.java b/java/src/com/android/intentresolver/ChooserStackedAppDialogFragment.java index 2cfceeae..f0fcd149 100644 --- a/java/src/com/android/intentresolver/ChooserStackedAppDialogFragment.java +++ b/java/src/com/android/intentresolver/ChooserStackedAppDialogFragment.java @@ -22,6 +22,7 @@ import android.content.pm.PackageManager; import android.graphics.drawable.Drawable; import android.os.UserHandle; +import androidx.annotation.NonNull; import androidx.fragment.app.FragmentManager; import com.android.intentresolver.chooser.DisplayResolveInfo; @@ -66,6 +67,7 @@ public class ChooserStackedAppDialogFragment extends ChooserTargetActionsDialogF dismiss(); } + @NonNull @Override protected CharSequence getItemLabel(DisplayResolveInfo dri) { final PackageManager pm = getContext().getPackageManager(); diff --git a/java/src/com/android/intentresolver/ChooserTargetActionsDialogFragment.java b/java/src/com/android/intentresolver/ChooserTargetActionsDialogFragment.java index 4bfb21aa..b6b7de96 100644 --- a/java/src/com/android/intentresolver/ChooserTargetActionsDialogFragment.java +++ b/java/src/com/android/intentresolver/ChooserTargetActionsDialogFragment.java @@ -21,8 +21,6 @@ import static android.content.Context.ACTIVITY_SERVICE; import static java.util.stream.Collectors.toList; -import android.annotation.NonNull; -import android.annotation.Nullable; import android.app.ActivityManager; import android.app.Dialog; import android.content.ComponentName; @@ -46,6 +44,8 @@ import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import androidx.fragment.app.DialogFragment; import androidx.fragment.app.FragmentManager; import androidx.recyclerview.widget.RecyclerView; diff --git a/java/src/com/android/intentresolver/IntentForwarderActivity.java b/java/src/com/android/intentresolver/IntentForwarderActivity.java index acee1316..15996d00 100644 --- a/java/src/com/android/intentresolver/IntentForwarderActivity.java +++ b/java/src/com/android/intentresolver/IntentForwarderActivity.java @@ -23,7 +23,6 @@ import static android.content.pm.PackageManager.MATCH_DEFAULT_ONLY; import static com.android.intentresolver.ResolverActivity.EXTRA_CALLING_USER; import static com.android.intentresolver.ResolverActivity.EXTRA_SELECTED_PROFILE; -import android.annotation.Nullable; import android.app.Activity; import android.app.ActivityThread; import android.app.AppGlobals; @@ -45,6 +44,8 @@ import android.provider.Settings; import android.util.Slog; import android.widget.Toast; +import androidx.annotation.Nullable; + import com.android.internal.annotations.VisibleForTesting; import com.android.internal.logging.MetricsLogger; import com.android.internal.logging.nano.MetricsProto.MetricsEvent; diff --git a/java/src/com/android/intentresolver/MultiProfilePagerAdapter.java b/java/src/com/android/intentresolver/MultiProfilePagerAdapter.java index 8ce42b28..42a29e55 100644 --- a/java/src/com/android/intentresolver/MultiProfilePagerAdapter.java +++ b/java/src/com/android/intentresolver/MultiProfilePagerAdapter.java @@ -15,8 +15,6 @@ */ package com.android.intentresolver; -import android.annotation.IntDef; -import android.annotation.Nullable; import android.os.Trace; import android.os.UserHandle; import android.view.View; @@ -24,6 +22,9 @@ import android.view.ViewGroup; import android.widget.Button; import android.widget.TextView; +import androidx.annotation.IntDef; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import androidx.viewpager.widget.PagerAdapter; import androidx.viewpager.widget.ViewPager; @@ -179,6 +180,7 @@ public class MultiProfilePagerAdapter< mLoadedPages.remove(1 - mCurrentPage); } + @NonNull @Override public final ViewGroup instantiateItem(ViewGroup container, int position) { setupListAdapter(position); @@ -188,7 +190,7 @@ public class MultiProfilePagerAdapter< } @Override - public void destroyItem(ViewGroup container, int position, Object view) { + public void destroyItem(ViewGroup container, int position, @NonNull Object view) { container.removeView((View) view); } @@ -207,7 +209,7 @@ public class MultiProfilePagerAdapter< } @Override - public boolean isViewFromObject(View view, Object object) { + public boolean isViewFromObject(@NonNull View view, @NonNull Object object) { return view == object; } diff --git a/java/src/com/android/intentresolver/ResolvedComponentInfo.java b/java/src/com/android/intentresolver/ResolvedComponentInfo.java index ecb72cbf..aaa97c42 100644 --- a/java/src/com/android/intentresolver/ResolvedComponentInfo.java +++ b/java/src/com/android/intentresolver/ResolvedComponentInfo.java @@ -20,6 +20,8 @@ import android.content.ComponentName; import android.content.Intent; import android.content.pm.ResolveInfo; +import com.android.intentresolver.chooser.TargetInfo; + import java.util.ArrayList; import java.util.List; @@ -86,7 +88,7 @@ public final class ResolvedComponentInfo { } /** - * @return whether this component was pinned by a call to {@link #setPinned()}. + * @return whether this component was pinned by a call to {@link #setPinned}. * TODO: consolidate sources of pinning data and/or document how this differs from other places * we make a "pinning" determination. */ diff --git a/java/src/com/android/intentresolver/ResolverActivity.java b/java/src/com/android/intentresolver/ResolverActivity.java index aa9d051c..0331c33e 100644 --- a/java/src/com/android/intentresolver/ResolverActivity.java +++ b/java/src/com/android/intentresolver/ResolverActivity.java @@ -36,9 +36,6 @@ import static android.view.WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTE import static com.android.internal.annotations.VisibleForTesting.Visibility.PROTECTED; -import android.annotation.Nullable; -import android.annotation.StringRes; -import android.annotation.UiThread; import android.app.Activity; import android.app.ActivityManager; import android.app.ActivityThread; @@ -96,6 +93,10 @@ import android.widget.TabWidget; import android.widget.TextView; import android.widget.Toast; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.annotation.StringRes; +import androidx.annotation.UiThread; import androidx.fragment.app.FragmentActivity; import androidx.viewpager.widget.ViewPager; @@ -612,7 +613,7 @@ public class ResolverActivity extends FragmentActivity implements } @Override - public void onConfigurationChanged(Configuration newConfig) { + public void onConfigurationChanged(@NonNull Configuration newConfig) { super.onConfigurationChanged(newConfig); mMultiProfilePagerAdapter.getActiveListAdapter().handlePackagesChanged(); if (mIsIntentPicker && shouldShowTabs() && !useLayoutWithDefault() @@ -1528,7 +1529,7 @@ public class ResolverActivity extends FragmentActivity implements } @Override - protected final void onSaveInstanceState(Bundle outState) { + protected final void onSaveInstanceState(@NonNull Bundle outState) { super.onSaveInstanceState(outState); ViewPager viewPager = findViewById(com.android.internal.R.id.profile_pager); if (viewPager != null) { @@ -1537,7 +1538,7 @@ public class ResolverActivity extends FragmentActivity implements } @Override - protected final void onRestoreInstanceState(Bundle savedInstanceState) { + protected final void onRestoreInstanceState(@NonNull Bundle savedInstanceState) { super.onRestoreInstanceState(savedInstanceState); resetButtonBar(); ViewPager viewPager = findViewById(com.android.internal.R.id.profile_pager); diff --git a/java/src/com/android/intentresolver/ResolverListAdapter.java b/java/src/com/android/intentresolver/ResolverListAdapter.java index 6c17df1d..8f1f9275 100644 --- a/java/src/com/android/intentresolver/ResolverListAdapter.java +++ b/java/src/com/android/intentresolver/ResolverListAdapter.java @@ -16,8 +16,6 @@ package com.android.intentresolver; -import android.annotation.NonNull; -import android.annotation.Nullable; import android.content.Context; import android.content.Intent; import android.content.pm.ActivityInfo; @@ -43,6 +41,8 @@ import android.widget.ImageView; import android.widget.TextView; import androidx.annotation.MainThread; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import androidx.annotation.WorkerThread; import com.android.intentresolver.chooser.DisplayResolveInfo; diff --git a/java/src/com/android/intentresolver/ResolverListController.java b/java/src/com/android/intentresolver/ResolverListController.java index 05121576..e88d766d 100644 --- a/java/src/com/android/intentresolver/ResolverListController.java +++ b/java/src/com/android/intentresolver/ResolverListController.java @@ -17,7 +17,6 @@ package com.android.intentresolver; -import android.annotation.WorkerThread; import android.app.ActivityManager; import android.app.AppGlobals; import android.content.ComponentName; @@ -31,6 +30,8 @@ import android.os.RemoteException; import android.os.UserHandle; import android.util.Log; +import androidx.annotation.WorkerThread; + import com.android.intentresolver.chooser.DisplayResolveInfo; import com.android.intentresolver.chooser.TargetInfo; import com.android.intentresolver.model.AbstractResolverComparator; diff --git a/java/src/com/android/intentresolver/ShortcutSelectionLogic.java b/java/src/com/android/intentresolver/ShortcutSelectionLogic.java index 645b9391..efaaf894 100644 --- a/java/src/com/android/intentresolver/ShortcutSelectionLogic.java +++ b/java/src/com/android/intentresolver/ShortcutSelectionLogic.java @@ -16,7 +16,6 @@ package com.android.intentresolver; -import android.annotation.Nullable; import android.app.prediction.AppTarget; import android.content.Context; import android.content.Intent; @@ -26,6 +25,8 @@ import android.content.pm.ShortcutInfo; import android.service.chooser.ChooserTarget; import android.util.Log; +import androidx.annotation.Nullable; + import com.android.intentresolver.chooser.DisplayResolveInfo; import com.android.intentresolver.chooser.SelectableTargetInfo; import com.android.intentresolver.chooser.TargetInfo; diff --git a/java/src/com/android/intentresolver/SimpleIconFactory.java b/java/src/com/android/intentresolver/SimpleIconFactory.java index ec5179ac..750b24ac 100644 --- a/java/src/com/android/intentresolver/SimpleIconFactory.java +++ b/java/src/com/android/intentresolver/SimpleIconFactory.java @@ -21,9 +21,6 @@ import static android.graphics.Paint.DITHER_FLAG; import static android.graphics.Paint.FILTER_BITMAP_FLAG; import static android.graphics.drawable.AdaptiveIconDrawable.getExtraInsetFraction; -import android.annotation.AttrRes; -import android.annotation.NonNull; -import android.annotation.Nullable; import android.app.ActivityManager; import android.content.Context; import android.content.pm.PackageManager; @@ -50,6 +47,10 @@ import android.util.AttributeSet; import android.util.Pools.SynchronizedPool; import android.util.TypedValue; +import androidx.annotation.AttrRes; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + import com.android.internal.annotations.VisibleForTesting; import org.xmlpull.v1.XmlPullParser; @@ -719,10 +720,18 @@ public class SimpleIconFactory { } @Override - public void inflate(Resources r, XmlPullParser parser, AttributeSet attrs) { } + public void inflate( + @NonNull Resources r, + @NonNull XmlPullParser parser, + @NonNull AttributeSet attrs) { + } @Override - public void inflate(Resources r, XmlPullParser parser, AttributeSet attrs, Theme theme) { } + public void inflate( + @NonNull Resources r, + @NonNull XmlPullParser parser, + @NonNull AttributeSet attrs, Theme theme) { + } /** * Sets the scale associated with this drawable diff --git a/java/src/com/android/intentresolver/TargetPresentationGetter.java b/java/src/com/android/intentresolver/TargetPresentationGetter.java index f8b36566..910c65c9 100644 --- a/java/src/com/android/intentresolver/TargetPresentationGetter.java +++ b/java/src/com/android/intentresolver/TargetPresentationGetter.java @@ -16,7 +16,6 @@ package com.android.intentresolver; -import android.annotation.Nullable; import android.content.Context; import android.content.pm.ActivityInfo; import android.content.pm.ApplicationInfo; @@ -30,6 +29,8 @@ import android.os.UserHandle; import android.text.TextUtils; import android.util.Log; +import androidx.annotation.Nullable; + /** * Loads the icon and label for the provided ApplicationInfo. Defaults to using the application icon * and label over any IntentFilter or Activity icon to increase user understanding, with an @@ -37,7 +38,7 @@ import android.util.Log; * resources over PackageManager loading mechanisms so badging can be done by iconloader. Uses * Strings to strip creative formatting. * - * Use one of the {@link TargetPresentationGetter#Factory} methods to create an instance of the + * Use one of the {@link TargetPresentationGetter.Factory} methods to create an instance of the * appropriate concrete type. * * TODO: once this component (and its tests) are merged, it should be possible to refactor and diff --git a/java/src/com/android/intentresolver/chooser/ChooserTargetInfo.java b/java/src/com/android/intentresolver/chooser/ChooserTargetInfo.java index 8b9bfb32..074537ef 100644 --- a/java/src/com/android/intentresolver/chooser/ChooserTargetInfo.java +++ b/java/src/com/android/intentresolver/chooser/ChooserTargetInfo.java @@ -16,6 +16,8 @@ package com.android.intentresolver.chooser; +import android.service.chooser.ChooserTarget; + import java.util.ArrayList; import java.util.Arrays; diff --git a/java/src/com/android/intentresolver/chooser/DisplayResolveInfo.java b/java/src/com/android/intentresolver/chooser/DisplayResolveInfo.java index 866da5f6..536f11ce 100644 --- a/java/src/com/android/intentresolver/chooser/DisplayResolveInfo.java +++ b/java/src/com/android/intentresolver/chooser/DisplayResolveInfo.java @@ -16,8 +16,6 @@ package com.android.intentresolver.chooser; -import android.annotation.NonNull; -import android.annotation.Nullable; import android.app.Activity; import android.content.ComponentName; import android.content.Intent; @@ -27,6 +25,9 @@ import android.content.pm.ResolveInfo; import android.os.Bundle; import android.os.UserHandle; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + import java.util.ArrayList; import java.util.List; diff --git a/java/src/com/android/intentresolver/chooser/ImmutableTargetInfo.java b/java/src/com/android/intentresolver/chooser/ImmutableTargetInfo.java index 10d4415a..50aaec0b 100644 --- a/java/src/com/android/intentresolver/chooser/ImmutableTargetInfo.java +++ b/java/src/com/android/intentresolver/chooser/ImmutableTargetInfo.java @@ -16,8 +16,6 @@ package com.android.intentresolver.chooser; -import android.annotation.NonNull; -import android.annotation.Nullable; import android.app.Activity; import android.app.prediction.AppTarget; import android.content.ComponentName; @@ -27,8 +25,11 @@ import android.content.pm.ResolveInfo; import android.content.pm.ShortcutInfo; import android.os.Bundle; import android.os.UserHandle; +import android.service.chooser.ChooserTarget; import android.util.HashedStringCache; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import androidx.annotation.VisibleForTesting; import com.google.common.collect.ImmutableList; @@ -43,7 +44,7 @@ import java.util.List; public final class ImmutableTargetInfo implements TargetInfo { private static final String TAG = "TargetInfo"; - /** Delegate interface to implement {@link TargetInfo#getHashedTargetIdForMetrics()}. */ + /** Delegate interface to implement {@link TargetInfo#getHashedTargetIdForMetrics}. */ public interface TargetHashProvider { /** Request a hash for the specified {@code target}. */ HashedStringCache.HashResult getHashedTargetIdForMetrics( @@ -53,15 +54,15 @@ public final class ImmutableTargetInfo implements TargetInfo { /** Delegate interface to request that the target be launched by a particular API. */ public interface TargetActivityStarter { /** - * Request that the delegate use the {@link Activity#startAsCaller()} API to launch the - * specified {@code target}. + * Request that the delegate use the {@link Activity#startActivityAsCaller} API to launch + * the specified {@code target}. * * @return true if the target was launched successfully. */ boolean startAsCaller(TargetInfo target, Activity activity, Bundle options, int userId); /** - * Request that the delegate use the {@link Activity#startAsUser()} API to launch the + * Request that the delegate use the {@link Activity#startActivityAsUser} API to launch the * specified {@code target}. * * @return true if the target was launched successfully. @@ -145,7 +146,7 @@ public final class ImmutableTargetInfo implements TargetInfo { /** * Configure an {@link Intent} to be built in to the output target as the "base intent to * send," which may be a refinement of any of our source targets. This is private because - * it's only used internally by {@link #tryToCloneWithAppliedRefinement()}; if it's ever + * it's only used internally by {@link #tryToCloneWithAppliedRefinement}; if it's ever * expanded, the builder should probably be responsible for enforcing the refinement check. */ private Builder setBaseIntentToSend(Intent baseIntent) { @@ -229,8 +230,8 @@ public final class ImmutableTargetInfo implements TargetInfo { /** * Configure the full list of source intents we could resolve for this target. This is - * effectively the same as calling {@link #setResolvedIntent()} with the first element of - * the list, and {@link #setAlternateSourceIntents()} with the remainder (or clearing those + * effectively the same as calling {@link #setResolvedIntent} with the first element of + * the list, and {@link #setAlternateSourceIntents} with the remainder (or clearing those * fields on the builder if there are no corresponding elements in the list). */ public Builder setAllSourceIntents(List<Intent> sourceIntents) { diff --git a/java/src/com/android/intentresolver/chooser/NotSelectableTargetInfo.java b/java/src/com/android/intentresolver/chooser/NotSelectableTargetInfo.java index 6444e13b..46803a04 100644 --- a/java/src/com/android/intentresolver/chooser/NotSelectableTargetInfo.java +++ b/java/src/com/android/intentresolver/chooser/NotSelectableTargetInfo.java @@ -16,7 +16,6 @@ package com.android.intentresolver.chooser; -import android.annotation.Nullable; import android.app.Activity; import android.content.Context; import android.graphics.drawable.AnimatedVectorDrawable; @@ -24,6 +23,8 @@ import android.graphics.drawable.Drawable; import android.os.Bundle; import android.os.UserHandle; +import androidx.annotation.Nullable; + import com.android.intentresolver.R; import java.util.function.Supplier; diff --git a/java/src/com/android/intentresolver/chooser/SelectableTargetInfo.java b/java/src/com/android/intentresolver/chooser/SelectableTargetInfo.java index 5766db0e..c4aa9021 100644 --- a/java/src/com/android/intentresolver/chooser/SelectableTargetInfo.java +++ b/java/src/com/android/intentresolver/chooser/SelectableTargetInfo.java @@ -16,7 +16,6 @@ package com.android.intentresolver.chooser; -import android.annotation.Nullable; import android.app.Activity; import android.app.prediction.AppTarget; import android.content.ComponentName; @@ -33,6 +32,8 @@ import android.text.SpannableStringBuilder; import android.util.HashedStringCache; import android.util.Log; +import androidx.annotation.Nullable; + import com.android.internal.config.sysui.SystemUiDeviceConfigFlags; import java.util.ArrayList; diff --git a/java/src/com/android/intentresolver/chooser/TargetInfo.java b/java/src/com/android/intentresolver/chooser/TargetInfo.java index 9d793994..ba6c3c05 100644 --- a/java/src/com/android/intentresolver/chooser/TargetInfo.java +++ b/java/src/com/android/intentresolver/chooser/TargetInfo.java @@ -17,14 +17,15 @@ package com.android.intentresolver.chooser; -import android.annotation.Nullable; import android.app.Activity; import android.app.prediction.AppTarget; import android.content.ComponentName; import android.content.Context; import android.content.Intent; +import android.content.SharedPreferences; import android.content.pm.ResolveInfo; import android.content.pm.ShortcutInfo; +import android.content.pm.ShortcutManager; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.os.UserHandle; @@ -32,6 +33,12 @@ import android.service.chooser.ChooserTarget; import android.text.TextUtils; import android.util.HashedStringCache; +import androidx.annotation.Nullable; + +import com.android.intentresolver.ChooserListAdapter; +import com.android.intentresolver.ChooserRefinementManager; +import com.android.intentresolver.ResolverActivity; + import java.util.ArrayList; import java.util.List; import java.util.Objects; @@ -187,9 +194,9 @@ public interface TargetInfo { * Attempt to apply a {@code proposedRefinement} that the {@link ChooserRefinementManager} * received from the caller's refinement flow. This may succeed only if the target has a source * intent that matches the filtering parameters of the proposed refinement (according to - * {@link Intent#filterEquals()}). Then the first such match is the "base intent," and the - * proposed refinement is merged into that base (via {@link Intent#fillIn()}; this can never - * result in a change to the {@link Intent#filterEquals()} status of the base, but may e.g. add + * {@link Intent#filterEquals}). Then the first such match is the "base intent," and the + * proposed refinement is merged into that base (via {@link Intent#fillIn}; this can never + * result in a change to the {@link Intent#filterEquals} status of the base, but may e.g. add * new "extras" that weren't previously given in the base intent). * * @return a copy of this {@link TargetInfo} where the "base intent to send" is the result of @@ -280,7 +287,7 @@ public interface TargetInfo { } /** - * @return the {@link ShortcutManager} data for any shortcut associated with this target. + * @return the {@link ShortcutInfo} for any shortcut associated with this target. */ @Nullable default ShortcutInfo getDirectShareShortcutInfo() { @@ -422,7 +429,7 @@ public interface TargetInfo { /** * @return true if this target should be logged with the "direct_share" metrics category in - * {@link ResolverActivity#maybeLogCrossProfileTargetLaunch()}. This is defined for legacy + * {@link ResolverActivity#maybeLogCrossProfileTargetLaunch}. This is defined for legacy * compatibility and is <em>not</em> likely to be a good indicator of whether this is actually a * "direct share" target (e.g. because it historically also applies to "empty" and "placeholder" * targets). diff --git a/java/src/com/android/intentresolver/contentpreview/ContentPreviewType.java b/java/src/com/android/intentresolver/contentpreview/ContentPreviewType.java index ebab147d..ad1c6c01 100644 --- a/java/src/com/android/intentresolver/contentpreview/ContentPreviewType.java +++ b/java/src/com/android/intentresolver/contentpreview/ContentPreviewType.java @@ -18,7 +18,7 @@ package com.android.intentresolver.contentpreview; import static java.lang.annotation.RetentionPolicy.SOURCE; -import android.annotation.IntDef; +import androidx.annotation.IntDef; import java.lang.annotation.Retention; diff --git a/java/src/com/android/intentresolver/contentpreview/HeadlineGeneratorImpl.kt b/java/src/com/android/intentresolver/contentpreview/HeadlineGeneratorImpl.kt index 1aace8c3..ef1e55d8 100644 --- a/java/src/com/android/intentresolver/contentpreview/HeadlineGeneratorImpl.kt +++ b/java/src/com/android/intentresolver/contentpreview/HeadlineGeneratorImpl.kt @@ -16,36 +16,55 @@ package com.android.intentresolver.contentpreview -import android.annotation.StringRes import android.content.Context -import com.android.intentresolver.R import android.util.PluralsMessageFormatter +import androidx.annotation.StringRes +import com.android.intentresolver.R private const val PLURALS_COUNT = "count" /** - * HeadlineGenerator generates the text to show at the top of the sharesheet as a brief - * description of the content being shared. + * HeadlineGenerator generates the text to show at the top of the sharesheet as a brief description + * of the content being shared. */ class HeadlineGeneratorImpl(private val context: Context) : HeadlineGenerator { override fun getTextHeadline(text: CharSequence): String { return context.getString( - getTemplateResource(text, R.string.sharing_link, R.string.sharing_text)) + getTemplateResource(text, R.string.sharing_link, R.string.sharing_text) + ) } override fun getImagesWithTextHeadline(text: CharSequence, count: Int): String { - return getPluralString(getTemplateResource( - text, R.string.sharing_images_with_link, R.string.sharing_images_with_text), count) + return getPluralString( + getTemplateResource( + text, + R.string.sharing_images_with_link, + R.string.sharing_images_with_text + ), + count + ) } override fun getVideosWithTextHeadline(text: CharSequence, count: Int): String { - return getPluralString(getTemplateResource( - text, R.string.sharing_videos_with_link, R.string.sharing_videos_with_text), count) + return getPluralString( + getTemplateResource( + text, + R.string.sharing_videos_with_link, + R.string.sharing_videos_with_text + ), + count + ) } override fun getFilesWithTextHeadline(text: CharSequence, count: Int): String { - return getPluralString(getTemplateResource( - text, R.string.sharing_files_with_link, R.string.sharing_files_with_text), count) + return getPluralString( + getTemplateResource( + text, + R.string.sharing_files_with_link, + R.string.sharing_files_with_text + ), + count + ) } override fun getImagesHeadline(count: Int): String { @@ -70,7 +89,9 @@ class HeadlineGeneratorImpl(private val context: Context) : HeadlineGenerator { @StringRes private fun getTemplateResource( - text: CharSequence, @StringRes linkResource: Int, @StringRes nonLinkResource: Int + text: CharSequence, + @StringRes linkResource: Int, + @StringRes nonLinkResource: Int ): Int { return if (text.toString().isHttpUri()) linkResource else nonLinkResource } diff --git a/java/src/com/android/intentresolver/emptystate/NoAppsAvailableEmptyStateProvider.java b/java/src/com/android/intentresolver/emptystate/NoAppsAvailableEmptyStateProvider.java index b7084466..2653c560 100644 --- a/java/src/com/android/intentresolver/emptystate/NoAppsAvailableEmptyStateProvider.java +++ b/java/src/com/android/intentresolver/emptystate/NoAppsAvailableEmptyStateProvider.java @@ -19,8 +19,6 @@ package com.android.intentresolver.emptystate; import static android.app.admin.DevicePolicyResources.Strings.Core.RESOLVER_NO_PERSONAL_APPS; import static android.app.admin.DevicePolicyResources.Strings.Core.RESOLVER_NO_WORK_APPS; -import android.annotation.NonNull; -import android.annotation.Nullable; import android.app.admin.DevicePolicyEventLogger; import android.app.admin.DevicePolicyManager; import android.content.Context; @@ -28,6 +26,9 @@ import android.content.pm.ResolveInfo; import android.os.UserHandle; import android.stats.devicepolicy.nano.DevicePolicyEnums; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + import com.android.intentresolver.ResolvedComponentInfo; import com.android.intentresolver.ResolverListAdapter; import com.android.internal.R; @@ -51,9 +52,12 @@ public class NoAppsAvailableEmptyStateProvider implements EmptyStateProvider { @NonNull private final UserHandle mTabOwnerUserHandleForLaunch; - public NoAppsAvailableEmptyStateProvider(Context context, UserHandle workProfileUserHandle, - UserHandle personalProfileUserHandle, String metricsCategory, - UserHandle tabOwnerUserHandleForLaunch) { + public NoAppsAvailableEmptyStateProvider( + @NonNull Context context, + @Nullable UserHandle workProfileUserHandle, + @Nullable UserHandle personalProfileUserHandle, + @NonNull String metricsCategory, + @NonNull UserHandle tabOwnerUserHandleForLaunch) { mContext = context; mWorkProfileUserHandle = workProfileUserHandle; mPersonalProfileUserHandle = personalProfileUserHandle; @@ -128,8 +132,9 @@ public class NoAppsAvailableEmptyStateProvider implements EmptyStateProvider { private boolean mIsPersonalProfile; - public NoAppsAvailableEmptyState(String title, String metricsCategory, - boolean isPersonalProfile) { + public NoAppsAvailableEmptyState(@NonNull String title, + @NonNull String metricsCategory, + boolean isPersonalProfile) { mTitle = title; mMetricsCategory = metricsCategory; mIsPersonalProfile = isPersonalProfile; diff --git a/java/src/com/android/intentresolver/emptystate/NoCrossProfileEmptyStateProvider.java b/java/src/com/android/intentresolver/emptystate/NoCrossProfileEmptyStateProvider.java index 686027c3..ce7bd8d9 100644 --- a/java/src/com/android/intentresolver/emptystate/NoCrossProfileEmptyStateProvider.java +++ b/java/src/com/android/intentresolver/emptystate/NoCrossProfileEmptyStateProvider.java @@ -16,14 +16,15 @@ package com.android.intentresolver.emptystate; -import android.annotation.NonNull; -import android.annotation.Nullable; -import android.annotation.StringRes; import android.app.admin.DevicePolicyEventLogger; import android.app.admin.DevicePolicyManager; import android.content.Context; import android.os.UserHandle; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.annotation.StringRes; + import com.android.intentresolver.ResolverListAdapter; /** @@ -90,10 +91,14 @@ public class NoCrossProfileEmptyStateProvider implements EmptyStateProvider { @NonNull private final String mEventCategory; - public DevicePolicyBlockerEmptyState(Context context, String devicePolicyStringTitleId, - @StringRes int defaultTitleResource, String devicePolicyStringSubtitleId, + public DevicePolicyBlockerEmptyState( + @NonNull Context context, + String devicePolicyStringTitleId, + @StringRes int defaultTitleResource, + String devicePolicyStringSubtitleId, @StringRes int defaultSubtitleResource, - int devicePolicyEventId, String devicePolicyEventCategory) { + int devicePolicyEventId, + @NonNull String devicePolicyEventCategory) { mContext = context; mDevicePolicyStringTitleId = devicePolicyStringTitleId; mDefaultTitleResource = defaultTitleResource; diff --git a/java/src/com/android/intentresolver/emptystate/WorkProfilePausedEmptyStateProvider.java b/java/src/com/android/intentresolver/emptystate/WorkProfilePausedEmptyStateProvider.java index ca04f1b7..612828e0 100644 --- a/java/src/com/android/intentresolver/emptystate/WorkProfilePausedEmptyStateProvider.java +++ b/java/src/com/android/intentresolver/emptystate/WorkProfilePausedEmptyStateProvider.java @@ -18,14 +18,15 @@ package com.android.intentresolver.emptystate; import static android.app.admin.DevicePolicyResources.Strings.Core.RESOLVER_WORK_PAUSED_TITLE; -import android.annotation.NonNull; -import android.annotation.Nullable; import android.app.admin.DevicePolicyEventLogger; import android.app.admin.DevicePolicyManager; import android.content.Context; import android.os.UserHandle; import android.stats.devicepolicy.nano.DevicePolicyEnums; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + import com.android.intentresolver.MultiProfilePagerAdapter.OnSwitchOnWorkSelectedListener; import com.android.intentresolver.R; import com.android.intentresolver.ResolverListAdapter; diff --git a/java/src/com/android/intentresolver/grid/ChooserGridAdapter.java b/java/src/com/android/intentresolver/grid/ChooserGridAdapter.java index 2ab38f30..51d4e677 100644 --- a/java/src/com/android/intentresolver/grid/ChooserGridAdapter.java +++ b/java/src/com/android/intentresolver/grid/ChooserGridAdapter.java @@ -288,8 +288,9 @@ public final class ChooserGridAdapter extends RecyclerView.Adapter<RecyclerView. + getFooterRowCount(); } + @NonNull @Override - public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { switch (viewType) { case VIEW_TYPE_CONTENT_PREVIEW: return new ItemViewHolder( @@ -325,7 +326,7 @@ public final class ChooserGridAdapter extends RecyclerView.Adapter<RecyclerView. return new FooterViewHolder(sp, viewType); default: // Since we catch all possible viewTypes above, no chance this is being called. - return null; + throw new IllegalStateException("unmatched view type"); } } diff --git a/java/src/com/android/intentresolver/icons/LoadDirectShareIconTask.java b/java/src/com/android/intentresolver/icons/LoadDirectShareIconTask.java index 6aee69b5..0f135d63 100644 --- a/java/src/com/android/intentresolver/icons/LoadDirectShareIconTask.java +++ b/java/src/com/android/intentresolver/icons/LoadDirectShareIconTask.java @@ -16,7 +16,6 @@ package com.android.intentresolver.icons; -import android.annotation.Nullable; import android.content.ComponentName; import android.content.Context; import android.content.pm.ActivityInfo; @@ -30,6 +29,7 @@ import android.graphics.drawable.Icon; import android.os.Trace; import android.util.Log; +import androidx.annotation.Nullable; import androidx.annotation.WorkerThread; import com.android.intentresolver.SimpleIconFactory; diff --git a/java/src/com/android/intentresolver/logging/EventLogImpl.java b/java/src/com/android/intentresolver/logging/EventLogImpl.java index 26c79d00..84029e76 100644 --- a/java/src/com/android/intentresolver/logging/EventLogImpl.java +++ b/java/src/com/android/intentresolver/logging/EventLogImpl.java @@ -16,7 +16,6 @@ package com.android.intentresolver.logging; -import android.annotation.Nullable; import android.content.Intent; import android.metrics.LogMaker; import android.net.Uri; @@ -24,6 +23,8 @@ import android.provider.MediaStore; import android.util.HashedStringCache; import android.util.Log; +import androidx.annotation.Nullable; + import com.android.intentresolver.ChooserActivity; import com.android.intentresolver.contentpreview.ContentPreviewType; import com.android.internal.annotations.VisibleForTesting; @@ -37,8 +38,6 @@ import com.android.internal.util.FrameworkStatsLog; import javax.inject.Inject; -import dagger.hilt.android.scopes.ActivityScoped; - /** * Helper for writing Sharesheet atoms to statsd log. */ diff --git a/java/src/com/android/intentresolver/model/AbstractResolverComparator.java b/java/src/com/android/intentresolver/model/AbstractResolverComparator.java index 932d8590..131aa8d9 100644 --- a/java/src/com/android/intentresolver/model/AbstractResolverComparator.java +++ b/java/src/com/android/intentresolver/model/AbstractResolverComparator.java @@ -16,7 +16,6 @@ package com.android.intentresolver.model; -import android.annotation.Nullable; import android.app.usage.UsageStatsManager; import android.content.ComponentName; import android.content.Context; @@ -30,6 +29,8 @@ import android.os.Message; import android.os.UserHandle; import android.util.Log; +import androidx.annotation.Nullable; + import com.android.intentresolver.ResolvedComponentInfo; import com.android.intentresolver.ResolverActivity; import com.android.intentresolver.ResolverListController; diff --git a/java/src/com/android/intentresolver/model/AppPredictionServiceResolverComparator.java b/java/src/com/android/intentresolver/model/AppPredictionServiceResolverComparator.java index 15c0acc9..6f7b54dd 100644 --- a/java/src/com/android/intentresolver/model/AppPredictionServiceResolverComparator.java +++ b/java/src/com/android/intentresolver/model/AppPredictionServiceResolverComparator.java @@ -18,7 +18,6 @@ package com.android.intentresolver.model; import static android.app.prediction.AppTargetEvent.ACTION_LAUNCH; -import android.annotation.Nullable; import android.app.prediction.AppPredictor; import android.app.prediction.AppTarget; import android.app.prediction.AppTargetEvent; @@ -31,6 +30,8 @@ import android.os.Message; import android.os.UserHandle; import android.util.Log; +import androidx.annotation.Nullable; + import com.android.intentresolver.ResolvedComponentInfo; import com.android.intentresolver.chooser.TargetInfo; import com.android.intentresolver.logging.EventLog; diff --git a/java/src/com/android/intentresolver/model/ResolverRankerServiceResolverComparator.java b/java/src/com/android/intentresolver/model/ResolverRankerServiceResolverComparator.java index 42b8a932..f3804154 100644 --- a/java/src/com/android/intentresolver/model/ResolverRankerServiceResolverComparator.java +++ b/java/src/com/android/intentresolver/model/ResolverRankerServiceResolverComparator.java @@ -17,7 +17,6 @@ package com.android.intentresolver.model; -import android.annotation.Nullable; import android.app.usage.UsageStats; import android.content.ComponentName; import android.content.Context; @@ -39,6 +38,8 @@ import android.service.resolver.ResolverRankerService; import android.service.resolver.ResolverTarget; import android.util.Log; +import androidx.annotation.Nullable; + import com.android.intentresolver.ResolvedComponentInfo; import com.android.intentresolver.chooser.TargetInfo; import com.android.intentresolver.logging.EventLog; diff --git a/java/src/com/android/intentresolver/shortcuts/ShortcutToChooserTargetConverter.java b/java/src/com/android/intentresolver/shortcuts/ShortcutToChooserTargetConverter.java index a37d6558..31929948 100644 --- a/java/src/com/android/intentresolver/shortcuts/ShortcutToChooserTargetConverter.java +++ b/java/src/com/android/intentresolver/shortcuts/ShortcutToChooserTargetConverter.java @@ -16,8 +16,6 @@ package com.android.intentresolver.shortcuts; -import android.annotation.NonNull; -import android.annotation.Nullable; import android.app.prediction.AppTarget; import android.content.Intent; import android.content.pm.ShortcutInfo; @@ -25,6 +23,9 @@ import android.content.pm.ShortcutManager; import android.os.Bundle; import android.service.chooser.ChooserTarget; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; diff --git a/java/src/com/android/intentresolver/v2/ChooserActionFactory.java b/java/src/com/android/intentresolver/v2/ChooserActionFactory.java index 2da194ca..a4a6d670 100644 --- a/java/src/com/android/intentresolver/v2/ChooserActionFactory.java +++ b/java/src/com/android/intentresolver/v2/ChooserActionFactory.java @@ -16,7 +16,6 @@ package com.android.intentresolver.v2; -import android.annotation.Nullable; import android.app.Activity; import android.app.ActivityOptions; import android.app.PendingIntent; @@ -34,6 +33,8 @@ import android.text.TextUtils; import android.util.Log; import android.view.View; +import androidx.annotation.Nullable; + import com.android.intentresolver.ChooserRequestParameters; import com.android.intentresolver.R; import com.android.intentresolver.chooser.DisplayResolveInfo; @@ -55,6 +56,7 @@ import java.util.function.Consumer; * Implementation of {@link ChooserContentPreviewUi.ActionFactory} specialized to the application * requirements of Sharesheet / {@link ChooserActivity}. */ +@SuppressWarnings("OptionalUsedAsFieldOrParameterType") public final class ChooserActionFactory implements ChooserContentPreviewUi.ActionFactory { /** * Delegate interface to launch activities when the actions are selected. diff --git a/java/src/com/android/intentresolver/v2/ChooserActivity.java b/java/src/com/android/intentresolver/v2/ChooserActivity.java index 36e0cad1..446577ef 100644 --- a/java/src/com/android/intentresolver/v2/ChooserActivity.java +++ b/java/src/com/android/intentresolver/v2/ChooserActivity.java @@ -30,8 +30,6 @@ import static com.android.internal.util.LatencyTracker.ACTION_LOAD_SHARE_SHEET; import static java.util.Objects.requireNonNull; -import android.annotation.IntDef; -import android.annotation.Nullable; import android.app.Activity; import android.app.ActivityManager; import android.app.ActivityOptions; @@ -71,6 +69,7 @@ import android.widget.TextView; import androidx.annotation.MainThread; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import androidx.lifecycle.ViewModelProvider; import androidx.recyclerview.widget.GridLayoutManager; import androidx.recyclerview.widget.RecyclerView; @@ -121,8 +120,6 @@ import dagger.hilt.android.AndroidEntryPoint; import kotlin.Unit; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; import java.text.Collator; import java.util.ArrayList; import java.util.Collections; @@ -144,6 +141,7 @@ import javax.inject.Inject; * for example, as generated by {@see android.content.Intent#createChooser(Intent, CharSequence)}. * */ +@SuppressWarnings("OptionalUsedAsFieldOrParameterType") @AndroidEntryPoint(ResolverActivity.class) public class ChooserActivity extends Hilt_ChooserActivity implements ResolverListAdapter.ResolverListCommunicator { @@ -177,24 +175,15 @@ public class ChooserActivity extends Hilt_ChooserActivity implements private final Map<ChooserTarget, AppTarget> mDirectShareAppTargetCache = new HashMap<>(); private final Map<ChooserTarget, ShortcutInfo> mDirectShareShortcutInfoCache = new HashMap<>(); - public static final int TARGET_TYPE_DEFAULT = 0; - public static final int TARGET_TYPE_CHOOSER_TARGET = 1; - public static final int TARGET_TYPE_SHORTCUTS_FROM_SHORTCUT_MANAGER = 2; - public static final int TARGET_TYPE_SHORTCUTS_FROM_PREDICTION_SERVICE = 3; + private static final int TARGET_TYPE_DEFAULT = 0; + private static final int TARGET_TYPE_CHOOSER_TARGET = 1; + private static final int TARGET_TYPE_SHORTCUTS_FROM_SHORTCUT_MANAGER = 2; + private static final int TARGET_TYPE_SHORTCUTS_FROM_PREDICTION_SERVICE = 3; private static final int SCROLL_STATUS_IDLE = 0; private static final int SCROLL_STATUS_SCROLLING_VERTICAL = 1; private static final int SCROLL_STATUS_SCROLLING_HORIZONTAL = 2; - @IntDef(flag = false, prefix = { "TARGET_TYPE_" }, value = { - TARGET_TYPE_DEFAULT, - TARGET_TYPE_CHOOSER_TARGET, - TARGET_TYPE_SHORTCUTS_FROM_SHORTCUT_MANAGER, - TARGET_TYPE_SHORTCUTS_FROM_PREDICTION_SERVICE - }) - @Retention(RetentionPolicy.SOURCE) - public @interface ShareTargetType {} - @Inject public FeatureFlags mFeatureFlags; @Inject public EventLog mEventLog; @Inject @ImageEditor public Optional<ComponentName> mImageEditor; diff --git a/java/src/com/android/intentresolver/v2/ChooserMultiProfilePagerAdapter.java b/java/src/com/android/intentresolver/v2/ChooserMultiProfilePagerAdapter.java index 8ca976bc..81797e9a 100644 --- a/java/src/com/android/intentresolver/v2/ChooserMultiProfilePagerAdapter.java +++ b/java/src/com/android/intentresolver/v2/ChooserMultiProfilePagerAdapter.java @@ -181,6 +181,7 @@ public class ChooserMultiProfilePagerAdapter extends MultiProfilePagerAdapter< mBottomOffset = bottomOffset; } + @Override public Optional<Integer> get() { int initialBottomPadding = mContext.getResources().getDimensionPixelSize( R.dimen.resolver_empty_state_container_padding_bottom); diff --git a/java/src/com/android/intentresolver/v2/MultiProfilePagerAdapter.java b/java/src/com/android/intentresolver/v2/MultiProfilePagerAdapter.java index 391cce7a..0b64a0ee 100644 --- a/java/src/com/android/intentresolver/v2/MultiProfilePagerAdapter.java +++ b/java/src/com/android/intentresolver/v2/MultiProfilePagerAdapter.java @@ -41,24 +41,28 @@ import java.util.function.Supplier; /** * Skeletal {@link PagerAdapter} implementation for a UI with per-profile tabs (as in Sharesheet). - * + * <p> * TODO: attempt to further restrict visibility/improve encapsulation in the methods we expose. + * <p> * TODO: deprecate and audit/fix usages of any methods that refer to the "active" or "inactive" + * <p> * adapters; these were marked {@link VisibleForTesting} and their usage seems like an accident * waiting to happen since clients seem to make assumptions about which adapter will be "active" in * a particular context, and more explicit APIs would make sure those were valid. + * <p> * TODO: consider renaming legacy methods (e.g. why do we know it's a "list", not just a "page"?) + * <p> + * TODO: this is part of an in-progress refactor to merge with `GenericMultiProfilePagerAdapter`. + * As originally noted there, we've reduced explicit references to the `ResolverListAdapter` base + * type and may be able to drop the type constraint. * * @param <PageViewT> the type of the widget that represents the contents of a page in this adapter * @param <SinglePageAdapterT> the type of a "root" adapter class to be instantiated and included in * the per-profile records. * @param <ListAdapterT> the concrete type of a {@link ResolverListAdapter} implementation to * control the contents of a given per-profile list. This is provided for convenience, since it must - * be possible to get the list adapter from the page adapter via our {@link mListAdapterExtractor}. - * - * TODO: this is part of an in-progress refactor to merge with `GenericMultiProfilePagerAdapter`. - * As originally noted there, we've reduced explicit references to the `ResolverListAdapter` base - * type and may be able to drop the type constraint. + * be possible to get the list adapter from the page adapter via our + * <code>mListAdapterExtractor</code>. */ public class MultiProfilePagerAdapter< PageViewT extends ViewGroup, diff --git a/java/src/com/android/intentresolver/v2/ResolverActivity.java b/java/src/com/android/intentresolver/v2/ResolverActivity.java index b34ce16d..a97ef962 100644 --- a/java/src/com/android/intentresolver/v2/ResolverActivity.java +++ b/java/src/com/android/intentresolver/v2/ResolverActivity.java @@ -35,9 +35,6 @@ import static com.android.internal.annotations.VisibleForTesting.Visibility.PROT import static java.util.Objects.requireNonNull; -import android.annotation.Nullable; -import android.annotation.StringRes; -import android.annotation.UiThread; import android.app.ActivityManager; import android.app.ActivityThread; import android.app.VoiceInteractor.PickOptionRequest; @@ -94,6 +91,9 @@ import android.widget.TabWidget; import android.widget.TextView; import android.widget.Toast; +import androidx.annotation.Nullable; +import androidx.annotation.StringRes; +import androidx.annotation.UiThread; import androidx.fragment.app.FragmentActivity; import androidx.viewpager.widget.ViewPager; diff --git a/java/src/com/android/intentresolver/v2/emptystate/NoAppsAvailableEmptyStateProvider.java b/java/src/com/android/intentresolver/v2/emptystate/NoAppsAvailableEmptyStateProvider.java index c76f8a2d..e9d1bb34 100644 --- a/java/src/com/android/intentresolver/v2/emptystate/NoAppsAvailableEmptyStateProvider.java +++ b/java/src/com/android/intentresolver/v2/emptystate/NoAppsAvailableEmptyStateProvider.java @@ -19,8 +19,6 @@ package com.android.intentresolver.v2.emptystate; import static android.app.admin.DevicePolicyResources.Strings.Core.RESOLVER_NO_PERSONAL_APPS; import static android.app.admin.DevicePolicyResources.Strings.Core.RESOLVER_NO_WORK_APPS; -import android.annotation.NonNull; -import android.annotation.Nullable; import android.app.admin.DevicePolicyEventLogger; import android.app.admin.DevicePolicyManager; import android.content.Context; @@ -28,6 +26,9 @@ import android.content.pm.ResolveInfo; import android.os.UserHandle; import android.stats.devicepolicy.nano.DevicePolicyEnums; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + import com.android.intentresolver.ResolvedComponentInfo; import com.android.intentresolver.ResolverListAdapter; import com.android.intentresolver.emptystate.EmptyState; @@ -53,9 +54,10 @@ public class NoAppsAvailableEmptyStateProvider implements EmptyStateProvider { @NonNull private final UserHandle mTabOwnerUserHandleForLaunch; - public NoAppsAvailableEmptyStateProvider(Context context, UserHandle workProfileUserHandle, - UserHandle personalProfileUserHandle, String metricsCategory, - UserHandle tabOwnerUserHandleForLaunch) { + public NoAppsAvailableEmptyStateProvider(@NonNull Context context, + @Nullable UserHandle workProfileUserHandle, + @Nullable UserHandle personalProfileUserHandle, @NonNull String metricsCategory, + @NonNull UserHandle tabOwnerUserHandleForLaunch) { mContext = context; mWorkProfileUserHandle = workProfileUserHandle; mPersonalProfileUserHandle = personalProfileUserHandle; @@ -123,21 +125,21 @@ public class NoAppsAvailableEmptyStateProvider implements EmptyStateProvider { public static class NoAppsAvailableEmptyState implements EmptyState { @NonNull - private String mTitle; + private final String mTitle; @NonNull - private String mMetricsCategory; + private final String mMetricsCategory; - private boolean mIsPersonalProfile; + private final boolean mIsPersonalProfile; - public NoAppsAvailableEmptyState(String title, String metricsCategory, + public NoAppsAvailableEmptyState(@NonNull String title, @NonNull String metricsCategory, boolean isPersonalProfile) { mTitle = title; mMetricsCategory = metricsCategory; mIsPersonalProfile = isPersonalProfile; } - @Nullable + @NonNull @Override public String getTitle() { return mTitle; diff --git a/java/src/com/android/intentresolver/v2/emptystate/NoCrossProfileEmptyStateProvider.java b/java/src/com/android/intentresolver/v2/emptystate/NoCrossProfileEmptyStateProvider.java index aef39cf4..b744c589 100644 --- a/java/src/com/android/intentresolver/v2/emptystate/NoCrossProfileEmptyStateProvider.java +++ b/java/src/com/android/intentresolver/v2/emptystate/NoCrossProfileEmptyStateProvider.java @@ -16,14 +16,15 @@ package com.android.intentresolver.v2.emptystate; -import android.annotation.NonNull; -import android.annotation.Nullable; -import android.annotation.StringRes; import android.app.admin.DevicePolicyEventLogger; import android.app.admin.DevicePolicyManager; import android.content.Context; import android.os.UserHandle; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.annotation.StringRes; + import com.android.intentresolver.ResolverListAdapter; import com.android.intentresolver.emptystate.CrossProfileIntentsChecker; import com.android.intentresolver.emptystate.EmptyState; @@ -93,10 +94,10 @@ public class NoCrossProfileEmptyStateProvider implements EmptyStateProvider { @NonNull private final String mEventCategory; - public DevicePolicyBlockerEmptyState(Context context, String devicePolicyStringTitleId, - @StringRes int defaultTitleResource, String devicePolicyStringSubtitleId, - @StringRes int defaultSubtitleResource, - int devicePolicyEventId, String devicePolicyEventCategory) { + public DevicePolicyBlockerEmptyState(@NonNull Context context, + String devicePolicyStringTitleId, @StringRes int defaultTitleResource, + String devicePolicyStringSubtitleId, @StringRes int defaultSubtitleResource, + int devicePolicyEventId, @NonNull String devicePolicyEventCategory) { mContext = context; mDevicePolicyStringTitleId = devicePolicyStringTitleId; mDefaultTitleResource = defaultTitleResource; diff --git a/java/src/com/android/intentresolver/v2/emptystate/WorkProfilePausedEmptyStateProvider.java b/java/src/com/android/intentresolver/v2/emptystate/WorkProfilePausedEmptyStateProvider.java index bc28fc30..a6fee3ec 100644 --- a/java/src/com/android/intentresolver/v2/emptystate/WorkProfilePausedEmptyStateProvider.java +++ b/java/src/com/android/intentresolver/v2/emptystate/WorkProfilePausedEmptyStateProvider.java @@ -18,14 +18,15 @@ package com.android.intentresolver.v2.emptystate; import static android.app.admin.DevicePolicyResources.Strings.Core.RESOLVER_WORK_PAUSED_TITLE; -import android.annotation.NonNull; -import android.annotation.Nullable; import android.app.admin.DevicePolicyEventLogger; import android.app.admin.DevicePolicyManager; import android.content.Context; import android.os.UserHandle; import android.stats.devicepolicy.nano.DevicePolicyEnums; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + import com.android.intentresolver.MultiProfilePagerAdapter.OnSwitchOnWorkSelectedListener; import com.android.intentresolver.R; import com.android.intentresolver.ResolverListAdapter; diff --git a/java/src/com/android/intentresolver/widget/ResolverDrawerLayout.java b/java/src/com/android/intentresolver/widget/ResolverDrawerLayout.java index b8fbedbf..2c8140d9 100644 --- a/java/src/com/android/intentresolver/widget/ResolverDrawerLayout.java +++ b/java/src/com/android/intentresolver/widget/ResolverDrawerLayout.java @@ -19,7 +19,6 @@ package com.android.intentresolver.widget; import static android.content.res.Resources.ID_NULL; -import android.annotation.IdRes; import android.content.Context; import android.content.res.TypedArray; import android.graphics.Canvas; @@ -45,6 +44,8 @@ import android.view.animation.AnimationUtils; import android.widget.AbsListView; import android.widget.OverScroller; +import androidx.annotation.IdRes; +import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.core.view.ScrollingView; import androidx.recyclerview.widget.RecyclerView; @@ -998,7 +999,7 @@ public class ResolverDrawerLayout extends ViewGroup { } @Override - public void onDrawForeground(Canvas canvas) { + public void onDrawForeground(@NonNull Canvas canvas) { if (mScrollIndicatorDrawable != null) { mScrollIndicatorDrawable.draw(canvas); } diff --git a/java/tests/src/com/android/intentresolver/ChooserWrapperActivity.java b/java/tests/src/com/android/intentresolver/ChooserWrapperActivity.java index c9f47a33..72f1f452 100644 --- a/java/tests/src/com/android/intentresolver/ChooserWrapperActivity.java +++ b/java/tests/src/com/android/intentresolver/ChooserWrapperActivity.java @@ -16,7 +16,6 @@ package com.android.intentresolver; -import android.annotation.Nullable; import android.app.prediction.AppPredictor; import android.app.usage.UsageStatsManager; import android.content.ComponentName; @@ -32,6 +31,8 @@ import android.net.Uri; import android.os.Bundle; import android.os.UserHandle; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import androidx.lifecycle.ViewModelProvider; import com.android.intentresolver.chooser.DisplayResolveInfo; @@ -248,6 +249,7 @@ public class ChooserWrapperActivity extends ChooserActivity implements IChooserW return mMultiProfilePagerAdapter.getCurrentUserHandle(); } + @NonNull @Override public Context createContextAsUser(UserHandle user, int flags) { // return the current context as a work profile doesn't really exist in these tests diff --git a/java/tests/src/com/android/intentresolver/IChooserWrapper.java b/java/tests/src/com/android/intentresolver/IChooserWrapper.java index e34217a8..481cf3b2 100644 --- a/java/tests/src/com/android/intentresolver/IChooserWrapper.java +++ b/java/tests/src/com/android/intentresolver/IChooserWrapper.java @@ -21,6 +21,8 @@ import android.content.Intent; import android.content.pm.ResolveInfo; import android.os.UserHandle; +import androidx.annotation.Nullable; + import com.android.intentresolver.chooser.DisplayResolveInfo; import java.util.concurrent.Executor; @@ -41,7 +43,7 @@ public interface IChooserWrapper { ResolveInfo pri, CharSequence pLabel, CharSequence pInfo, - Intent replacementIntent); + @Nullable Intent replacementIntent); UserHandle getCurrentUserHandle(); Executor getMainExecutor(); } diff --git a/java/tests/src/com/android/intentresolver/ResolverDataProvider.java b/java/tests/src/com/android/intentresolver/ResolverDataProvider.java index 4eb350fc..db109941 100644 --- a/java/tests/src/com/android/intentresolver/ResolverDataProvider.java +++ b/java/tests/src/com/android/intentresolver/ResolverDataProvider.java @@ -29,6 +29,8 @@ import android.test.mock.MockContext; import android.test.mock.MockPackageManager; import android.test.mock.MockResources; +import androidx.annotation.NonNull; + /** * Utility class used by resolver tests to create mock data */ @@ -195,28 +197,31 @@ public class ResolverDataProvider { @Override public Resources getResources() { return new MockResources() { + @NonNull @Override public String getString(int id) throws NotFoundException { if (id == 1) return appLabel; if (id == 2) return activityLabel; if (id == 3) return resolveInfoLabel; - return null; + throw new NotFoundException(); } }; } }; ApplicationInfo appInfo = new ApplicationInfo() { + @NonNull @Override - public CharSequence loadLabel(PackageManager pm) { + public CharSequence loadLabel(@NonNull PackageManager pm) { return appLabel; } }; appInfo.labelRes = 1; ActivityInfo activityInfo = new ActivityInfo() { + @NonNull @Override - public CharSequence loadLabel(PackageManager pm) { + public CharSequence loadLabel(@NonNull PackageManager pm) { return activityLabel; } }; @@ -224,8 +229,9 @@ public class ResolverDataProvider { activityInfo.applicationInfo = appInfo; ResolveInfo resolveInfo = new ResolveInfo() { + @NonNull @Override - public CharSequence loadLabel(PackageManager pm) { + public CharSequence loadLabel(@NonNull PackageManager pm) { return resolveInfoLabel; } }; diff --git a/java/tests/src/com/android/intentresolver/ResolverWrapperActivity.java b/java/tests/src/com/android/intentresolver/ResolverWrapperActivity.java index 7ffb90ce..d1adfba9 100644 --- a/java/tests/src/com/android/intentresolver/ResolverWrapperActivity.java +++ b/java/tests/src/com/android/intentresolver/ResolverWrapperActivity.java @@ -21,7 +21,6 @@ import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import android.annotation.Nullable; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; @@ -32,6 +31,7 @@ import android.os.UserHandle; import android.util.Pair; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import androidx.test.espresso.idling.CountingIdlingResource; import com.android.intentresolver.chooser.DisplayResolveInfo; @@ -158,9 +158,12 @@ public class ResolverWrapperActivity extends ResolverActivity { protected AnnotatedUserHandles computeAnnotatedUserHandles() { return sOverrides.annotatedUserHandles; } - @Override - public void startActivityAsUser(Intent intent, Bundle options, UserHandle user) { + public void startActivityAsUser( + @NonNull Intent intent, + Bundle options, + @NonNull UserHandle user + ) { super.startActivityAsUser(intent, options, user); } |