Updating some non-final static objects

Updating various static objects to use a standard pattern so that
it is easier to track and cleanup those objects

Bug: 141376165
Change-Id: Ia539cbfa338d544dddad771c5027b6748762768b
This commit is contained in:
Sunny Goyal 2019-12-09 14:55:56 -08:00
parent 4f37a5e268
commit 73b5a27b14
46 changed files with 136 additions and 225 deletions

View File

@ -63,7 +63,7 @@ public class QuickstepLauncher extends BaseQuickstepLauncher {
*/
public static final AsyncCommand SET_SHELF_HEIGHT = (context, arg1, arg2) ->
SystemUiProxy.INSTANCE.get(context).setShelfHeight(arg1 != 0, arg2);
public static RotationMode ROTATION_LANDSCAPE = new RotationMode(-90) {
public static final RotationMode ROTATION_LANDSCAPE = new RotationMode(-90) {
@Override
public void mapRect(int left, int top, int right, int bottom, Rect out) {
out.left = top;
@ -89,7 +89,7 @@ public class QuickstepLauncher extends BaseQuickstepLauncher {
}
}
};
public static RotationMode ROTATION_SEASCAPE = new RotationMode(90) {
public static final RotationMode ROTATION_SEASCAPE = new RotationMode(90) {
@Override
public void mapRect(int left, int top, int right, int bottom, Rect out) {
out.left = bottom;

View File

@ -89,7 +89,7 @@ public class FallbackSwipeHandler extends BaseSwipeUpHandler<RecentsActivity, Fa
mLauncherAlpha = launcherAlpha;
}
}
private static ArrayMap<GestureEndTarget, EndTargetAnimationParams>
private final ArrayMap<GestureEndTarget, EndTargetAnimationParams>
mEndTargetAnimationParams = new ArrayMap();
private final AnimatedFloat mLauncherAlpha = new AnimatedFloat(this::onLauncherAlphaChanged);

View File

@ -544,7 +544,7 @@ public class LauncherSwipeHandler<T extends BaseDraggingActivity>
if (ENABLE_QUICKSTEP_LIVE_TILE.get()) {
if (mRecentsAnimationTargets != null) {
LiveTileOverlay.getInstance().update(
LiveTileOverlay.INSTANCE.update(
mAppWindowAnimationHelper.getCurrentRectWithInsets(),
mAppWindowAnimationHelper.getCurrentCornerRadius());
}
@ -829,7 +829,7 @@ public class LauncherSwipeHandler<T extends BaseDraggingActivity>
setShelfState(ShelfAnimState.CANCEL, LINEAR, 0);
duration = Math.max(MIN_OVERSHOOT_DURATION, duration);
} else if (endTarget == RECENTS) {
LiveTileOverlay.getInstance().startIconAnimation();
LiveTileOverlay.INSTANCE.startIconAnimation();
if (mRecentsView != null) {
int nearestPage = mRecentsView.getPageNearestToCenterOfScreen();
if (mRecentsView.getNextPage() != nearestPage) {
@ -1231,13 +1231,13 @@ public class LauncherSwipeHandler<T extends BaseDraggingActivity>
}
private void addLiveTileOverlay() {
if (LiveTileOverlay.getInstance().attach(mActivity.getRootView().getOverlay())) {
if (LiveTileOverlay.INSTANCE.attach(mActivity.getRootView().getOverlay())) {
mRecentsView.setLiveTileOverlayAttached(true);
}
}
private void removeLiveTileOverlay() {
LiveTileOverlay.getInstance().detach(mActivity.getRootView().getOverlay());
LiveTileOverlay.INSTANCE.detach(mActivity.getRootView().getOverlay());
mRecentsView.setLiveTileOverlayAttached(false);
}

View File

@ -37,18 +37,11 @@ public class LiveTileOverlay extends Drawable {
}
};
private static LiveTileOverlay sInstance;
public static LiveTileOverlay getInstance() {
if (sInstance == null) {
sInstance = new LiveTileOverlay();
}
return sInstance;
}
public static final LiveTileOverlay INSTANCE = new LiveTileOverlay();
private final Paint mPaint = new Paint();
private final Rect mBoundsRect = new Rect();
private Rect mBoundsRect = new Rect();
private RectF mCurrentRect;
private float mCornerRadius;
private Drawable mIcon;

View File

@ -886,7 +886,7 @@ public abstract class RecentsView<T extends BaseActivity> extends PagedView impl
public void onSwipeUpAnimationSuccess() {
if (getRunningTaskView() != null) {
float startProgress = ENABLE_QUICKSTEP_LIVE_TILE.get() && mLiveTileOverlayAttached
? LiveTileOverlay.getInstance().cancelIconAnimation()
? LiveTileOverlay.INSTANCE.cancelIconAnimation()
: 0f;
animateUpRunningTaskIconScale(startProgress);
}
@ -1739,7 +1739,7 @@ public abstract class RecentsView<T extends BaseActivity> extends PagedView impl
public void updateLiveTileIcon(Drawable icon) {
if (mLiveTileOverlayAttached) {
LiveTileOverlay.getInstance().setIcon(icon);
LiveTileOverlay.INSTANCE.setIcon(icon);
}
}

View File

@ -61,9 +61,9 @@ import com.android.systemui.shared.recents.model.ThumbnailData;
*/
public class TaskThumbnailView extends View implements PluginListener<OverviewScreenshotActions> {
private final static ColorMatrix COLOR_MATRIX = new ColorMatrix();
private final static ColorMatrix SATURATION_COLOR_MATRIX = new ColorMatrix();
private final static RectF EMPTY_RECT_F = new RectF();
private static final ColorMatrix COLOR_MATRIX = new ColorMatrix();
private static final ColorMatrix SATURATION_COLOR_MATRIX = new ColorMatrix();
private static final RectF EMPTY_RECT_F = new RectF();
public static final Property<TaskThumbnailView, Float> DIM_ALPHA =
new FloatProperty<TaskThumbnailView>("dimAlpha") {

View File

@ -265,7 +265,7 @@ public abstract class BaseQuickstepLauncher extends Launcher
// Instantiate and initialize WellbeingModel now that its loading won't interfere with
// populating workspace.
// TODO: Find a better place for this
WellbeingModel.get(this);
WellbeingModel.INSTANCE.get(this);
}
@Override

View File

@ -43,13 +43,13 @@ import android.util.ArrayMap;
import android.util.Log;
import androidx.annotation.MainThread;
import androidx.annotation.NonNull;
import com.android.launcher3.BaseDraggingActivity;
import com.android.launcher3.ItemInfo;
import com.android.launcher3.R;
import com.android.launcher3.popup.RemoteActionShortcut;
import com.android.launcher3.popup.SystemShortcut;
import com.android.launcher3.util.MainThreadInitializedObject;
import com.android.launcher3.util.PackageManagerHelper;
import com.android.launcher3.util.Preconditions;
import com.android.launcher3.util.SimpleBroadcastReceiver;
@ -78,7 +78,8 @@ public final class WellbeingModel {
private static final String EXTRA_MAX_NUM_ACTIONS_SHOWN = "max_num_actions_shown";
private static final String EXTRA_PACKAGES = "packages";
private static WellbeingModel sInstance;
public static final MainThreadInitializedObject<WellbeingModel> INSTANCE =
new MainThreadInitializedObject<>(WellbeingModel::new);
private final Context mContext;
private final String mWellbeingProviderPkg;
@ -155,15 +156,6 @@ public final class WellbeingModel {
updateWellbeingData();
}
@MainThread
public static WellbeingModel get(@NonNull Context context) {
Preconditions.assertUIThread();
if (sInstance == null) {
sInstance = new WellbeingModel(context.getApplicationContext());
}
return sInstance;
}
@MainThread
private SystemShortcut getShortcutForApp(String packageName, int userId,
BaseDraggingActivity activity, ItemInfo info) {
@ -334,8 +326,8 @@ public final class WellbeingModel {
/**
* Shortcut factory for generating wellbeing action
*/
public static final SystemShortcut.Factory SHORTCUT_FACTORY = (activity, info) ->
(info.getTargetComponent() == null) ? null : WellbeingModel.get(activity)
public static final SystemShortcut.Factory SHORTCUT_FACTORY =
(activity, info) -> (info.getTargetComponent() == null) ? null : INSTANCE.get(activity)
.getShortcutForApp(
info.getTargetComponent().getPackageName(), info.user.getIdentifier(),
activity, info);

View File

@ -27,6 +27,7 @@ import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import com.android.launcher3.util.MainThreadInitializedObject;
import com.android.systemui.shared.system.TonalCompat;
import com.android.systemui.shared.system.TonalCompat.ExtractionInfo;
@ -39,17 +40,8 @@ public class WallpaperColorInfo implements OnColorsChangedListener {
private static final int MAIN_COLOR_DARK = 0xff202124;
private static final int MAIN_COLOR_REGULAR = 0xff000000;
private static final Object sInstanceLock = new Object();
private static WallpaperColorInfo sInstance;
public static WallpaperColorInfo getInstance(Context context) {
synchronized (sInstanceLock) {
if (sInstance == null) {
sInstance = new WallpaperColorInfo(context.getApplicationContext());
}
return sInstance;
}
}
public static final MainThreadInitializedObject<WallpaperColorInfo> INSTANCE =
new MainThreadInitializedObject<>(WallpaperColorInfo::new);
private final ArrayList<OnChangeListener> mListeners = new ArrayList<>();
private final WallpaperManager mWallpaperManager;

View File

@ -25,17 +25,18 @@ import android.util.FloatProperty;
*/
public class AnimatedFloat {
public static FloatProperty<AnimatedFloat> VALUE = new FloatProperty<AnimatedFloat>("value") {
@Override
public void setValue(AnimatedFloat obj, float v) {
obj.updateValue(v);
}
public static final FloatProperty<AnimatedFloat> VALUE =
new FloatProperty<AnimatedFloat>("value") {
@Override
public void setValue(AnimatedFloat obj, float v) {
obj.updateValue(v);
}
@Override
public Float get(AnimatedFloat obj) {
return obj.value;
}
};
@Override
public Float get(AnimatedFloat obj) {
return obj.value;
}
};
private final Runnable mUpdateCallback;
private ObjectAnimator mValueAnimator;

View File

@ -43,7 +43,8 @@ import java.io.PrintWriter;
*/
public abstract class BaseRecentsActivity extends BaseDraggingActivity {
public static ActivityTracker<BaseRecentsActivity> ACTIVITY_TRACKER = new ActivityTracker<>();
public static final ActivityTracker<BaseRecentsActivity> ACTIVITY_TRACKER =
new ActivityTracker<>();
private Configuration mOldConfig;
@Override
@ -56,7 +57,7 @@ public abstract class BaseRecentsActivity extends BaseDraggingActivity {
getSystemUiController().updateUiState(SystemUiController.UI_STATE_BASE_WINDOW,
Themes.getAttrBoolean(this, R.attr.isWorkspaceDarkText));
ACTIVITY_TRACKER.handleCreate((RecentsActivity) this);
ACTIVITY_TRACKER.handleCreate(this);
}
/**

View File

@ -52,7 +52,7 @@ public class SysUINavigationMode {
return INSTANCE.get(context).getMode();
}
public static MainThreadInitializedObject<SysUINavigationMode> INSTANCE =
public static final MainThreadInitializedObject<SysUINavigationMode> INSTANCE =
new MainThreadInitializedObject<>(SysUINavigationMode::new);
private static final String TAG = "SysUINavigationMode";

View File

@ -31,7 +31,7 @@ import com.android.quickstep.SysUINavigationMode;
*/
public class NavBarPosition {
public static RotationMode ROTATION_LANDSCAPE = new RotationMode(-90) {
public static final RotationMode ROTATION_LANDSCAPE = new RotationMode(-90) {
@Override
public void mapRect(int left, int top, int right, int bottom, Rect out) {
out.left = top;
@ -58,7 +58,7 @@ public class NavBarPosition {
}
};
public static RotationMode ROTATION_SEASCAPE = new RotationMode(90) {
public static final RotationMode ROTATION_SEASCAPE = new RotationMode(90) {
@Override
public void mapRect(int left, int top, int right, int bottom, Rect out) {
out.left = bottom;

View File

@ -7,7 +7,6 @@ import static org.mockito.Mockito.atLeast;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.robolectric.util.ReflectionHelpers.setField;
import android.content.ComponentName;
import android.content.Context;
@ -32,7 +31,7 @@ import com.android.launcher3.icons.BitmapInfo;
import com.android.launcher3.icons.IconCache;
import com.android.launcher3.icons.cache.CachingLogic;
import com.android.launcher3.model.BgDataModel.Callbacks;
import com.android.launcher3.pm.PackageInstallerCompat;
import com.android.launcher3.pm.InstallSessionHelper;
import com.android.launcher3.util.ComponentKey;
import com.android.launcher3.util.TestLauncherProvider;
@ -76,7 +75,7 @@ public class BaseModelUpdateTaskTestCase {
public void setUp() throws Exception {
ShadowLog.stream = System.out;
reinitializeStaticExecutors();
setField(PackageInstallerCompat.class, null, "sInstance", null);
InstallSessionHelper.INSTANCE.initializeForTesting(null);
provider = Robolectric.setupContentProvider(TestLauncherProvider.class);
ShadowContentResolver.registerProviderInternal(LauncherProvider.AUTHORITY, provider);

View File

@ -34,6 +34,7 @@ import com.android.launcher3.ItemInfo;
import com.android.launcher3.LauncherProvider;
import com.android.launcher3.LauncherSettings;
import com.android.launcher3.icons.BitmapInfo;
import com.android.launcher3.pm.InstallSessionHelper;
import com.android.launcher3.shadows.LShadowLauncherApps;
import com.android.launcher3.shadows.LShadowUserManager;
import com.android.launcher3.shadows.ShadowLooperExecutor;
@ -95,6 +96,7 @@ public class DefaultLayoutProviderTest extends BaseModelUpdateTaskTestCase {
public void cleanup() {
InvariantDeviceProfile.INSTANCE.initializeForTesting(null);
CustomWidgetManager.INSTANCE.initializeForTesting(null);
InstallSessionHelper.INSTANCE.initializeForTesting(null);
}
@Test

View File

@ -36,8 +36,8 @@ import java.util.Comparator;
*/
public class AppInfo extends ItemInfoWithIcon {
public static AppInfo[] EMPTY_ARRAY = new AppInfo[0];
public static Comparator<AppInfo> COMPONENT_KEY_COMPARATOR = (a, b) -> {
public static final AppInfo[] EMPTY_ARRAY = new AppInfo[0];
public static final Comparator<AppInfo> COMPONENT_KEY_COMPARATOR = (a, b) -> {
int uc = a.user.hashCode() - b.user.hashCode();
return uc != 0 ? uc : a.componentName.compareTo(b.componentName);
};

View File

@ -22,6 +22,7 @@ import android.view.ViewGroup;
import com.android.launcher3.accessibility.DragViewStateAnnouncer;
import com.android.launcher3.dragndrop.DragLayer;
import com.android.launcher3.util.FocusLogic;
import com.android.launcher3.util.MainThreadInitializedObject;
import com.android.launcher3.widget.LauncherAppWidgetHostView;
import java.util.ArrayList;
@ -35,7 +36,12 @@ public class AppWidgetResizeFrame extends AbstractFloatingView implements View.O
private static final Rect sTmpRect = new Rect();
// Represents the cell size on the grid in the two orientations.
private static Point[] sCellSize;
private static final MainThreadInitializedObject<Point[]> CELL_SIZE =
new MainThreadInitializedObject<>(c -> {
InvariantDeviceProfile inv = LauncherAppState.getIDP(c);
return new Point[] {inv.landscapeProfile.getCellSize(),
inv.portraitProfile.getCellSize()};
});
private static final int HANDLE_COUNT = 4;
private static final int INDEX_LEFT = 0;
@ -352,27 +358,19 @@ public class AppWidgetResizeFrame extends AbstractFloatingView implements View.O
}
public static Rect getWidgetSizeRanges(Context context, int spanX, int spanY, Rect rect) {
if (sCellSize == null) {
InvariantDeviceProfile inv = LauncherAppState.getIDP(context);
// Initiate cell sizes.
sCellSize = new Point[2];
sCellSize[0] = inv.landscapeProfile.getCellSize();
sCellSize[1] = inv.portraitProfile.getCellSize();
}
if (rect == null) {
rect = new Rect();
}
final float density = context.getResources().getDisplayMetrics().density;
final Point[] cellSize = CELL_SIZE.get(context);
// Compute landscape size
int landWidth = (int) ((spanX * sCellSize[0].x) / density);
int landHeight = (int) ((spanY * sCellSize[0].y) / density);
int landWidth = (int) ((spanX * cellSize[0].x) / density);
int landHeight = (int) ((spanY * cellSize[0].y) / density);
// Compute portrait size
int portWidth = (int) ((spanX * sCellSize[1].x) / density);
int portHeight = (int) ((spanY * sCellSize[1].y) / density);
int portWidth = (int) ((spanX * cellSize[1].x) / density);
int portHeight = (int) ((spanY * cellSize[1].y) / density);
rect.set(portWidth, landHeight, landWidth, portHeight);
return rect;
}

View File

@ -73,8 +73,7 @@ public abstract class BaseDraggingActivity extends BaseActivity
mRotationListener = new DisplayRotationListener(this, this::onDeviceRotationChanged);
// Update theme
WallpaperColorInfo wallpaperColorInfo = WallpaperColorInfo.getInstance(this);
wallpaperColorInfo.addOnChangeListener(this);
WallpaperColorInfo.INSTANCE.get(this).addOnChangeListener(this);
int themeRes = Themes.getActivityThemeRes(this);
if (themeRes != mThemeRes) {
mThemeRes = themeRes;
@ -234,7 +233,7 @@ public abstract class BaseDraggingActivity extends BaseActivity
@Override
protected void onDestroy() {
super.onDestroy();
WallpaperColorInfo.getInstance(this).removeOnChangeListener(this);
WallpaperColorInfo.INSTANCE.get(this).removeOnChangeListener(this);
mRotationListener.disable();
}

View File

@ -179,7 +179,7 @@ public class CellLayout extends ViewGroup implements Transposable {
private final Rect mTempRect = new Rect();
private final static Paint sPaint = new Paint();
private static final Paint sPaint = new Paint();
// Related to accessible drag and drop
private DragAndDropAccessibilityDelegate mTouchHelper;

View File

@ -32,8 +32,8 @@ import com.android.launcher3.icons.IconCache;
import com.android.launcher3.icons.IconProvider;
import com.android.launcher3.icons.LauncherIcons;
import com.android.launcher3.notification.NotificationListener;
import com.android.launcher3.pm.InstallSessionHelper;
import com.android.launcher3.pm.InstallSessionTracker;
import com.android.launcher3.pm.PackageInstallerCompat;
import com.android.launcher3.pm.UserCache;
import com.android.launcher3.util.MainThreadInitializedObject;
import com.android.launcher3.util.Preconditions;
@ -109,7 +109,7 @@ public class LauncherAppState {
mInvariantDeviceProfile.addOnChangeListener(this::onIdpChanged);
new Handler().post( () -> mInvariantDeviceProfile.verifyConfigChangedInBackground(context));
mInstallSessionTracker = PackageInstallerCompat.getInstance(context)
mInstallSessionTracker = InstallSessionHelper.INSTANCE.get(context)
.registerInstallTracker(mModel, MODEL_EXECUTOR);
if (!mContext.getResources().getBoolean(R.bool.notification_dots_enabled)) {

View File

@ -53,21 +53,12 @@ public class Partner {
public static final String RES_GRID_NUM_COLUMNS = "grid_num_columns";
public static final String RES_GRID_ICON_SIZE_DP = "grid_icon_size_dp";
private static boolean sSearched = false;
private static Partner sPartner;
/**
* Find and return partner details, or {@code null} if none exists.
*/
public static synchronized Partner get(PackageManager pm) {
if (!sSearched) {
Pair<String, Resources> apkInfo = findSystemApk(ACTION_PARTNER_CUSTOMIZATION, pm);
if (apkInfo != null) {
sPartner = new Partner(apkInfo.first, apkInfo.second);
}
sSearched = true;
}
return sPartner;
Pair<String, Resources> apkInfo = findSystemApk(ACTION_PARTNER_CUSTOMIZATION, pm);
return apkInfo != null ? new Partner(apkInfo.first, apkInfo.second) : null;
}
private final String mPackageName;

View File

@ -16,7 +16,7 @@
package com.android.launcher3;
import static com.android.launcher3.pm.PackageInstallerCompat.getUserHandle;
import static com.android.launcher3.pm.InstallSessionHelper.getUserHandle;
import android.annotation.TargetApi;
import android.content.BroadcastReceiver;
@ -40,7 +40,7 @@ import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
import com.android.launcher3.pm.PackageInstallerCompat;
import com.android.launcher3.pm.InstallSessionHelper;
import com.android.launcher3.util.Executors;
import java.util.List;
@ -77,7 +77,7 @@ public class SessionCommitReceiver extends BroadcastReceiver {
return;
}
PackageInstallerCompat packageInstallerCompat = PackageInstallerCompat.getInstance(context);
InstallSessionHelper packageInstallerCompat = InstallSessionHelper.INSTANCE.get(context);
if (TextUtils.isEmpty(info.getAppPackageName())
|| info.getInstallReason() != PackageManager.INSTALL_REASON_USER
|| packageInstallerCompat.promiseIconAddedForId(info.getSessionId())) {

View File

@ -44,7 +44,8 @@ class FolderPreviewItemAnim {
}
};
private static PreviewItemDrawingParams sTmpParams = new PreviewItemDrawingParams(0, 0, 0, 0);
private static final PreviewItemDrawingParams sTmpParams =
new PreviewItemDrawingParams(0, 0, 0, 0);
private static final float[] sTempParamsArray = new float[3];
private final ObjectAnimator mAnimator;

View File

@ -20,7 +20,7 @@ import android.graphics.Rect;
public abstract class RotationMode {
public static RotationMode NORMAL = new RotationMode(0) { };
public static final RotationMode NORMAL = new RotationMode(0) { };
public final float surfaceRotation;
public final boolean isTransposed;

View File

@ -31,7 +31,7 @@ import com.android.launcher3.uioverrides.WallpaperColorInfo;
public class Scrim implements View.OnAttachStateChangeListener,
WallpaperColorInfo.OnChangeListener {
public static Property<Scrim, Float> SCRIM_PROGRESS =
public static final Property<Scrim, Float> SCRIM_PROGRESS =
new Property<Scrim, Float>(Float.TYPE, "scrimProgress") {
@Override
public Float get(Scrim scrim) {
@ -55,7 +55,7 @@ public class Scrim implements View.OnAttachStateChangeListener,
public Scrim(View view) {
mRoot = view;
mLauncher = Launcher.getLauncher(view.getContext());
mWallpaperColorInfo = WallpaperColorInfo.getInstance(mLauncher);
mWallpaperColorInfo = WallpaperColorInfo.INSTANCE.get(mLauncher);
view.addOnAttachStateChangeListener(this);
}

View File

@ -54,7 +54,7 @@ import com.android.launcher3.util.Themes;
*/
public class WorkspaceAndHotseatScrim extends Scrim {
public static Property<WorkspaceAndHotseatScrim, Float> SYSUI_PROGRESS =
public static final Property<WorkspaceAndHotseatScrim, Float> SYSUI_PROGRESS =
new Property<WorkspaceAndHotseatScrim, Float>(Float.TYPE, "sysUiProgress") {
@Override
public Float get(WorkspaceAndHotseatScrim scrim) {
@ -67,7 +67,7 @@ public class WorkspaceAndHotseatScrim extends Scrim {
}
};
private static Property<WorkspaceAndHotseatScrim, Float> SYSUI_ANIM_MULTIPLIER =
private static final Property<WorkspaceAndHotseatScrim, Float> SYSUI_ANIM_MULTIPLIER =
new Property<WorkspaceAndHotseatScrim, Float>(Float.TYPE, "sysUiAnimMultiplier") {
@Override
public Float get(WorkspaceAndHotseatScrim scrim) {

View File

@ -33,7 +33,7 @@ import com.android.launcher3.LauncherModel.CallbackTask;
import com.android.launcher3.LauncherSettings;
import com.android.launcher3.WorkspaceItemInfo;
import com.android.launcher3.model.BgDataModel.Callbacks;
import com.android.launcher3.pm.PackageInstallerCompat;
import com.android.launcher3.pm.InstallSessionHelper;
import com.android.launcher3.util.GridOccupancy;
import com.android.launcher3.util.IntArray;
import com.android.launcher3.util.PackageManagerHelper;
@ -93,8 +93,8 @@ public class AddWorkspaceItemsTask extends BaseModelUpdateTask {
}
}
PackageInstallerCompat packageInstaller =
PackageInstallerCompat.getInstance(app.getContext());
InstallSessionHelper packageInstaller =
InstallSessionHelper.INSTANCE.get(app.getContext());
LauncherApps launcherApps = app.getContext().getSystemService(LauncherApps.class);
for (ItemInfo item : filteredItems) {

View File

@ -29,7 +29,7 @@ import com.android.launcher3.LauncherSettings.Settings;
import com.android.launcher3.Utilities;
import com.android.launcher3.Workspace;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.pm.PackageInstallerCompat;
import com.android.launcher3.pm.InstallSessionHelper;
import com.android.launcher3.provider.LauncherDbUtils;
import com.android.launcher3.provider.LauncherDbUtils.SQLiteTransaction;
import com.android.launcher3.util.GridOccupancy;
@ -971,7 +971,7 @@ public class GridSizeMigrationTask {
.getInstalledPackages(PackageManager.GET_UNINSTALLED_PACKAGES)) {
validPackages.add(info.packageName);
}
PackageInstallerCompat.getInstance(context)
InstallSessionHelper.INSTANCE.get(context)
.getActiveSessions().keySet()
.forEach(packageUserKey -> validPackages.add(packageUserKey.mPackageName));
return validPackages;

View File

@ -67,8 +67,8 @@ import com.android.launcher3.icons.LauncherIcons;
import com.android.launcher3.icons.ShortcutCachingLogic;
import com.android.launcher3.icons.cache.IconCacheUpdateHandler;
import com.android.launcher3.logging.FileLog;
import com.android.launcher3.pm.InstallSessionHelper;
import com.android.launcher3.pm.PackageInstallInfo;
import com.android.launcher3.pm.PackageInstallerCompat;
import com.android.launcher3.pm.UserCache;
import com.android.launcher3.provider.ImportDataTask;
import com.android.launcher3.qsb.QsbContainerView;
@ -115,7 +115,7 @@ public class LoaderTask implements Runnable {
private final UserCache mUserCache;
private final DeepShortcutManager mShortcutManager;
private final PackageInstallerCompat mPackageInstaller;
private final InstallSessionHelper mSessionHelper;
private final IconCache mIconCache;
private boolean mStopped;
@ -131,7 +131,7 @@ public class LoaderTask implements Runnable {
mUserManager = mApp.getContext().getSystemService(UserManager.class);
mUserCache = UserCache.INSTANCE.get(mApp.getContext());
mShortcutManager = DeepShortcutManager.getInstance(mApp.getContext());
mPackageInstaller = PackageInstallerCompat.getInstance(mApp.getContext());
mSessionHelper = InstallSessionHelper.INSTANCE.get(mApp.getContext());
mIconCache = mApp.getIconCache();
}
@ -311,7 +311,7 @@ public class LoaderTask implements Runnable {
mBgDataModel.clear();
final HashMap<PackageUserKey, SessionInfo> installingPkgs =
mPackageInstaller.getActiveSessions();
mSessionHelper.getActiveSessions();
installingPkgs.forEach(mApp.getIconCache()::updateSessionCache);
final PackageUserKey tempPackageKey = new PackageUserKey(null, null);
@ -871,7 +871,7 @@ public class LoaderTask implements Runnable {
if (FeatureFlags.PROMISE_APPS_IN_ALL_APPS.get()) {
// get all active sessions and add them to the all apps list
for (PackageInstaller.SessionInfo info :
mPackageInstaller.getAllVerifiedSessions()) {
mSessionHelper.getAllVerifiedSessions()) {
mBgAllAppsList.addPromiseApp(mApp.getContext(),
PackageInstallInfo.fromInstallingState(info));
}

View File

@ -2,8 +2,6 @@ package com.android.launcher3.model;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.os.Process;
import android.os.UserHandle;
import com.android.launcher3.InvariantDeviceProfile;
import com.android.launcher3.LauncherAppWidgetProviderInfo;
@ -12,17 +10,12 @@ import com.android.launcher3.icons.IconCache;
import com.android.launcher3.pm.ShortcutConfigActivityInfo;
import com.android.launcher3.util.ComponentKey;
import java.text.Collator;
/**
* An wrapper over various items displayed in a widget picker,
* {@link LauncherAppWidgetProviderInfo} & {@link ActivityInfo}. This provides easier access to
* common attributes like spanX and spanY.
*/
public class WidgetItem extends ComponentKey implements Comparable<WidgetItem> {
private static UserHandle sMyUserHandle;
private static Collator sCollator;
public class WidgetItem extends ComponentKey {
public final LauncherAppWidgetProviderInfo widgetInfo;
public final ShortcutConfigActivityInfo activityInfo;
@ -50,34 +43,4 @@ public class WidgetItem extends ComponentKey implements Comparable<WidgetItem> {
activityInfo = info;
spanX = spanY = 1;
}
@Override
public int compareTo(WidgetItem another) {
if (sMyUserHandle == null) {
// Delay these object creation until required.
sMyUserHandle = Process.myUserHandle();
sCollator = Collator.getInstance();
}
// Independent of how the labels compare, if only one of the two widget info belongs to
// work profile, put that one in the back.
boolean thisWorkProfile = !sMyUserHandle.equals(user);
boolean otherWorkProfile = !sMyUserHandle.equals(another.user);
if (thisWorkProfile ^ otherWorkProfile) {
return thisWorkProfile ? 1 : -1;
}
int labelCompare = sCollator.compare(label, another.label);
if (labelCompare != 0) {
return labelCompare;
}
// If the label is same, put the smaller widget before the larger widget. If the area is
// also same, put the widget with smaller height before.
int thisArea = spanX * spanY;
int otherArea = another.spanX * another.spanY;
return thisArea == otherArea
? Integer.compare(spanY, another.spanY)
: Integer.compare(thisArea, otherArea);
}
}

View File

@ -51,7 +51,7 @@ import com.android.launcher3.util.Themes;
@TargetApi(Build.VERSION_CODES.N)
public class NotificationMainView extends FrameLayout implements SingleAxisSwipeDetector.Listener {
private static FloatProperty<NotificationMainView> CONTENT_TRANSLATION =
private static final FloatProperty<NotificationMainView> CONTENT_TRANSLATION =
new FloatProperty<NotificationMainView>("contentTranslation") {
@Override
public void setValue(NotificationMainView view, float v) {

View File

@ -123,7 +123,7 @@ public class WorkspacePageIndicator extends View implements Insettable, PageIndi
mLauncher = Launcher.getLauncher(context);
mLineHeight = res.getDimensionPixelSize(R.dimen.dynamic_grid_page_indicator_line_height);
boolean darkText = WallpaperColorInfo.getInstance(context).supportsDarkText();
boolean darkText = WallpaperColorInfo.INSTANCE.get(context).supportsDarkText();
mActiveAlpha = darkText ? BLACK_ALPHA : WHITE_ALPHA;
mLinePaint.setColor(darkText ? Color.BLACK : Color.WHITE);
}

View File

@ -35,6 +35,7 @@ import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.util.IntArray;
import com.android.launcher3.util.IntSet;
import com.android.launcher3.util.LooperExecutor;
import com.android.launcher3.util.MainThreadInitializedObject;
import com.android.launcher3.util.PackageManagerHelper;
import com.android.launcher3.util.PackageUserKey;
@ -43,15 +44,20 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
public class PackageInstallerCompat {
/**
* Utility class to tracking install sessions
*/
public class InstallSessionHelper {
// Set<String> of session ids of promise icons that have been added to the home screen
// as FLAG_PROMISE_NEW_INSTALLS.
protected static final String PROMISE_ICON_IDS = "promise_icon_ids";
private static final Object sInstanceLock = new Object();
private static final boolean DEBUG = false;
private static PackageInstallerCompat sInstance;
public static final MainThreadInitializedObject<InstallSessionHelper> INSTANCE =
new MainThreadInitializedObject<>(InstallSessionHelper::new);
private final LauncherApps mLauncherApps;
private final Context mAppContext;
private final IntSet mPromiseIconIds;
@ -59,7 +65,7 @@ public class PackageInstallerCompat {
private final PackageInstaller mInstaller;
private final HashMap<String, Boolean> mSessionVerifiedMap = new HashMap<>();
public PackageInstallerCompat(Context context) {
public InstallSessionHelper(Context context) {
mInstaller = context.getPackageManager().getPackageInstaller();
mAppContext = context.getApplicationContext();
mLauncherApps = context.getSystemService(LauncherApps.class);
@ -70,15 +76,6 @@ public class PackageInstallerCompat {
cleanUpPromiseIconIds();
}
public static PackageInstallerCompat getInstance(Context context) {
synchronized (sInstanceLock) {
if (sInstance == null) {
sInstance = new PackageInstallerCompat(context);
}
return sInstance;
}
}
public static UserHandle getUserHandle(SessionInfo info) {
return Utilities.ATLEAST_Q ? info.getUser() : Process.myUserHandle();
}

View File

@ -15,9 +15,9 @@
*/
package com.android.launcher3.pm;
import static com.android.launcher3.pm.InstallSessionHelper.getUserHandle;
import static com.android.launcher3.pm.PackageInstallInfo.STATUS_FAILED;
import static com.android.launcher3.pm.PackageInstallInfo.STATUS_INSTALLED;
import static com.android.launcher3.pm.PackageInstallerCompat.getUserHandle;
import android.content.pm.PackageInstaller;
import android.content.pm.PackageInstaller.SessionInfo;
@ -31,10 +31,10 @@ public class InstallSessionTracker extends PackageInstaller.SessionCallback {
// Lazily initialized
private SparseArray<PackageUserKey> mActiveSessions = null;
private final PackageInstallerCompat mInstallerCompat;
private final InstallSessionHelper mInstallerCompat;
private final Callback mCallback;
InstallSessionTracker(PackageInstallerCompat installerCompat, Callback callback) {
InstallSessionTracker(InstallSessionHelper installerCompat, Callback callback) {
mInstallerCompat = installerCompat;
mCallback = callback;
}

View File

@ -38,7 +38,7 @@ public final class PackageInstallInfo {
this.packageName = info.getAppPackageName();
this.componentName = new ComponentName(packageName, "");
this.progress = (int) (info.getProgress() * 100f);
this.user = PackageInstallerCompat.getUserHandle(info);
this.user = InstallSessionHelper.getUserHandle(info);
}
public PackageInstallInfo(String packageName, int state, int progress, UserHandle user) {

View File

@ -144,7 +144,7 @@ public abstract class SystemShortcut<T extends BaseDraggingActivity> extends Ite
}
}
public static Factory<BaseDraggingActivity> INSTALL = (activity, itemInfo) -> {
public static final Factory<BaseDraggingActivity> INSTALL = (activity, itemInfo) -> {
boolean supportsWebUI = (itemInfo instanceof WorkspaceItemInfo)
&& ((WorkspaceItemInfo) itemInfo).hasStatusFlag(
WorkspaceItemInfo.FLAG_SUPPORTS_WEB_UI);
@ -176,7 +176,7 @@ public abstract class SystemShortcut<T extends BaseDraggingActivity> extends Ite
}
}
public static Factory<Launcher> DISMISS_PREDICTION = (launcher, itemInfo) -> {
public static final Factory<Launcher> DISMISS_PREDICTION = (launcher, itemInfo) -> {
if (!FeatureFlags.ENABLE_PREDICTION_DISMISS.get()) return null;
if (itemInfo.container != LauncherSettings.Favorites.CONTAINER_PREDICTION) return null;
return new DismissPrediction(launcher, itemInfo);

View File

@ -51,7 +51,7 @@ import com.android.launcher3.Utilities;
import com.android.launcher3.WorkspaceItemInfo;
import com.android.launcher3.folder.Folder;
import com.android.launcher3.folder.FolderIcon;
import com.android.launcher3.pm.PackageInstallerCompat;
import com.android.launcher3.pm.InstallSessionHelper;
import com.android.launcher3.util.PackageManagerHelper;
import com.android.launcher3.views.FloatingIconView;
import com.android.launcher3.widget.PendingAppWidgetHostView;
@ -169,8 +169,8 @@ public class ItemClickHandler {
private static void startMarketIntentForPackage(View v, Launcher launcher, String packageName) {
ItemInfo item = (ItemInfo) v.getTag();
if (Utilities.ATLEAST_Q) {
PackageInstallerCompat pkgInstaller = PackageInstallerCompat.getInstance(launcher);
SessionInfo sessionInfo = pkgInstaller.getActiveSessionInfo(item.user, packageName);
SessionInfo sessionInfo = InstallSessionHelper.INSTANCE.get(launcher)
.getActiveSessionInfo(item.user, packageName);
if (sessionInfo != null) {
LauncherApps launcherApps = launcher.getSystemService(LauncherApps.class);
try {

View File

@ -22,7 +22,6 @@ import static com.android.launcher3.LauncherState.ALL_APPS;
import static com.android.launcher3.LauncherState.NORMAL;
import static com.android.launcher3.LauncherState.OVERVIEW;
import android.util.Log;
import android.view.View;
import android.view.View.OnLongClickListener;
@ -34,19 +33,16 @@ import com.android.launcher3.Launcher;
import com.android.launcher3.dragndrop.DragController;
import com.android.launcher3.dragndrop.DragOptions;
import com.android.launcher3.folder.Folder;
import com.android.launcher3.testing.TestProtocol;
import java.util.Arrays;
/**
* Class to handle long-clicks on workspace items and start drag as a result.
*/
public class ItemLongClickListener {
public static OnLongClickListener INSTANCE_WORKSPACE =
public static final OnLongClickListener INSTANCE_WORKSPACE =
ItemLongClickListener::onWorkspaceItemLongClick;
public static OnLongClickListener INSTANCE_ALL_APPS =
public static final OnLongClickListener INSTANCE_ALL_APPS =
ItemLongClickListener::onAllAppsItemLongClick;
private static boolean onWorkspaceItemLongClick(View v) {

View File

@ -16,6 +16,8 @@
package com.android.launcher3.util;
import static android.content.pm.PackageManager.MATCH_SYSTEM_ONLY;
import android.app.AppOpsManager;
import android.content.ActivityNotFoundException;
import android.content.ComponentName;
@ -297,16 +299,13 @@ public class PackageManagerHelper {
*/
public static Pair<String, Resources> findSystemApk(String action, PackageManager pm) {
final Intent intent = new Intent(action);
for (ResolveInfo info : pm.queryBroadcastReceivers(intent, 0)) {
if (info.activityInfo != null &&
(info.activityInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
final String packageName = info.activityInfo.packageName;
try {
final Resources res = pm.getResourcesForApplication(packageName);
return Pair.create(packageName, res);
} catch (NameNotFoundException e) {
Log.w(TAG, "Failed to find resources for " + packageName);
}
for (ResolveInfo info : pm.queryBroadcastReceivers(intent, MATCH_SYSTEM_ONLY)) {
final String packageName = info.activityInfo.packageName;
try {
final Resources res = pm.getResourcesForApplication(packageName);
return Pair.create(packageName, res);
} catch (NameNotFoundException e) {
Log.w(TAG, "Failed to find resources for " + packageName);
}
}
return null;

View File

@ -36,7 +36,7 @@ import com.android.launcher3.uioverrides.WallpaperColorInfo;
public class Themes {
public static int getActivityThemeRes(Context context) {
WallpaperColorInfo wallpaperColorInfo = WallpaperColorInfo.getInstance(context);
WallpaperColorInfo wallpaperColorInfo = WallpaperColorInfo.INSTANCE.get(context);
boolean darkTheme;
if (Utilities.ATLEAST_Q) {
Configuration configuration = context.getResources().getConfiguration();

View File

@ -29,26 +29,20 @@ import android.view.inputmethod.InputMethodManager;
*/
public class UiThreadHelper {
private static Handler sHandler;
private static final MainThreadInitializedObject<Handler> HANDLER =
new MainThreadInitializedObject<>(
c -> new Handler(UI_HELPER_EXECUTOR.getLooper(), new UiCallbacks(c)));
private static final int MSG_HIDE_KEYBOARD = 1;
private static final int MSG_SET_ORIENTATION = 2;
private static final int MSG_RUN_COMMAND = 3;
private static Handler getHandler(Context context) {
if (sHandler == null) {
sHandler = new Handler(UI_HELPER_EXECUTOR.getLooper(),
new UiCallbacks(context.getApplicationContext()));
}
return sHandler;
}
public static void hideKeyboardAsync(Context context, IBinder token) {
Message.obtain(getHandler(context), MSG_HIDE_KEYBOARD, token).sendToTarget();
Message.obtain(HANDLER.get(context), MSG_HIDE_KEYBOARD, token).sendToTarget();
}
public static void setOrientationAsync(Activity activity, int orientation) {
Message.obtain(getHandler(activity), MSG_SET_ORIENTATION, orientation, 0, activity)
Message.obtain(HANDLER.get(activity), MSG_SET_ORIENTATION, orientation, 0, activity)
.sendToTarget();
}
@ -58,7 +52,7 @@ public class UiThreadHelper {
}
public static void runAsyncCommand(Context context, AsyncCommand command, int arg1, int arg2) {
Message.obtain(getHandler(context), MSG_RUN_COMMAND, arg1, arg2, command).sendToTarget();
Message.obtain(HANDLER.get(context), MSG_RUN_COMMAND, arg1, arg2, command).sendToTarget();
}
private static class UiCallbacks implements Handler.Callback {

View File

@ -41,7 +41,7 @@ import com.android.launcher3.touch.SingleAxisSwipeDetector;
public abstract class AbstractSlideInView extends AbstractFloatingView
implements SingleAxisSwipeDetector.Listener {
protected static Property<AbstractSlideInView, Float> TRANSLATION_SHIFT =
protected static final Property<AbstractSlideInView, Float> TRANSLATION_SHIFT =
new Property<AbstractSlideInView, Float>(Float.class, "translationShift") {
@Override

View File

@ -131,7 +131,7 @@ public class ScrimView<T extends Launcher> extends View implements Insettable, O
public ScrimView(Context context, AttributeSet attrs) {
super(context, attrs);
mLauncher = Launcher.cast(Launcher.getLauncher(context));
mWallpaperColorInfo = WallpaperColorInfo.getInstance(context);
mWallpaperColorInfo = WallpaperColorInfo.INSTANCE.get(context);
mEndScrim = Themes.getAttrColor(context, R.attr.allAppsScrimColor);
mMaxScrimAlpha = 0.7f;

View File

@ -182,7 +182,7 @@ abstract class BaseWidgetSheet extends AbstractSlideInView
View view = new View(context);
view.forceHasOverlappingRendering(false);
WallpaperColorInfo colors = WallpaperColorInfo.getInstance(context);
WallpaperColorInfo colors = WallpaperColorInfo.INSTANCE.get(context);
int alpha = context.getResources().getInteger(R.integer.extracted_color_gradient_alpha);
view.setBackgroundColor(setColorAlphaBound(colors.getSecondaryColor(), alpha));

View File

@ -16,18 +16,19 @@
package com.android.launcher3.uioverrides;
import static android.app.WallpaperManager.FLAG_SYSTEM;
import android.content.Context;
import android.graphics.Color;
import android.util.Pair;
import com.android.launcher3.uioverrides.dynamicui.ColorExtractionAlgorithm;
import com.android.launcher3.uioverrides.dynamicui.WallpaperColorsCompat;
import com.android.launcher3.uioverrides.dynamicui.WallpaperManagerCompat;
import com.android.launcher3.uioverrides.dynamicui.ColorExtractionAlgorithm;
import com.android.launcher3.util.MainThreadInitializedObject;
import java.util.ArrayList;
import static android.app.WallpaperManager.FLAG_SYSTEM;
public class WallpaperColorInfo implements WallpaperManagerCompat.OnColorsChangedListenerCompat {
private static final int MAIN_COLOR_LIGHT = 0xffdadce0;
@ -35,17 +36,9 @@ public class WallpaperColorInfo implements WallpaperManagerCompat.OnColorsChange
private static final int MAIN_COLOR_REGULAR = 0xff000000;
private static final int FALLBACK_COLOR = Color.WHITE;
private static final Object sInstanceLock = new Object();
private static WallpaperColorInfo sInstance;
public static WallpaperColorInfo getInstance(Context context) {
synchronized (sInstanceLock) {
if (sInstance == null) {
sInstance = new WallpaperColorInfo(context.getApplicationContext());
}
return sInstance;
}
}
public static final MainThreadInitializedObject<WallpaperColorInfo> INSTANCE =
new MainThreadInitializedObject<>(WallpaperColorInfo::new);
private final ArrayList<OnChangeListener> mListeners = new ArrayList<>();
private final WallpaperManagerCompat mWallpaperManager;

View File

@ -41,7 +41,7 @@ import com.android.launcher3.LauncherAppWidgetHost;
import com.android.launcher3.LauncherAppWidgetInfo;
import com.android.launcher3.LauncherAppWidgetProviderInfo;
import com.android.launcher3.LauncherSettings;
import com.android.launcher3.pm.PackageInstallerCompat;
import com.android.launcher3.pm.InstallSessionHelper;
import com.android.launcher3.tapl.Workspace;
import com.android.launcher3.ui.AbstractLauncherUiTest;
import com.android.launcher3.ui.TestViewHelpers;
@ -302,7 +302,7 @@ public class BindWidgetTest extends AbstractLauncherUiTest {
Set<String> activePackage = getOnUiThread(() -> {
Set<String> packages = new HashSet<>();
PackageInstallerCompat.getInstance(mTargetContext).getActiveSessions()
InstallSessionHelper.INSTANCE.get(mTargetContext).getActiveSessions()
.keySet().forEach(packageUserKey -> packages.add(packageUserKey.mPackageName));
return packages;
});