summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSunny Goyal <sunnygoyal@google.com>2017-01-11 10:48:34 -0800
committerSunny Goyal <sunnygoyal@google.com>2017-01-11 12:52:03 -0800
commit87f784c285fdeed9091a4de8b9b44db3eca677d8 (patch)
tree94870e68378e8d0e1fb09555fc1be4ca149ba99b
parent41307051416b3e027d89e72301704432bd1c5eb3 (diff)
downloadandroid_packages_apps_Trebuchet-87f784c285fdeed9091a4de8b9b44db3eca677d8.tar.gz
android_packages_apps_Trebuchet-87f784c285fdeed9091a4de8b9b44db3eca677d8.tar.bz2
android_packages_apps_Trebuchet-87f784c285fdeed9091a4de8b9b44db3eca677d8.zip
Removing static Context access using LauncherAppState
> This ensures that LauncherAppState is only accessed in the presence of a valid context Bug: 33032833 Change-Id: I955e5cb022f8bd6374681ae6c0720a2666d5b750
-rw-r--r--src/com/android/launcher3/AppWidgetResizeFrame.java2
-rw-r--r--src/com/android/launcher3/AutoInstallsLayout.java4
-rw-r--r--src/com/android/launcher3/BubbleTextView.java2
-rw-r--r--src/com/android/launcher3/IconCache.java2
-rw-r--r--src/com/android/launcher3/InstallShortcutReceiver.java11
-rw-r--r--src/com/android/launcher3/Launcher.java4
-rw-r--r--src/com/android/launcher3/LauncherAppState.java9
-rw-r--r--src/com/android/launcher3/LauncherAppWidgetProviderInfo.java5
-rw-r--r--src/com/android/launcher3/LauncherModel.java24
-rw-r--r--src/com/android/launcher3/LauncherProvider.java3
-rw-r--r--src/com/android/launcher3/ShortcutInfo.java4
-rw-r--r--src/com/android/launcher3/Workspace.java3
-rw-r--r--src/com/android/launcher3/compat/PackageInstallerCompatVL.java2
-rw-r--r--src/com/android/launcher3/folder/FolderPagedView.java4
-rw-r--r--src/com/android/launcher3/graphics/IconNormalizer.java9
-rw-r--r--src/com/android/launcher3/graphics/LauncherIcons.java21
-rw-r--r--src/com/android/launcher3/graphics/ShadowGenerator.java9
-rw-r--r--src/com/android/launcher3/model/BgDataModel.java12
-rw-r--r--src/com/android/launcher3/model/GridSizeMigrationTask.java14
-rw-r--r--src/com/android/launcher3/model/LoaderCursor.java2
-rw-r--r--src/com/android/launcher3/model/WidgetItem.java8
-rw-r--r--src/com/android/launcher3/model/WidgetsModel.java12
-rw-r--r--src/com/android/launcher3/provider/ImportDataTask.java8
-rw-r--r--src/com/android/launcher3/provider/LauncherDbUtils.java3
-rw-r--r--src/com/android/launcher3/qsb/QsbContainerView.java2
-rw-r--r--src/com/android/launcher3/testing/ToggleWeightWatcher.java2
-rw-r--r--src/com/android/launcher3/util/ContentWriter.java6
-rw-r--r--src/com/android/launcher3/util/ManagedProfileHeuristic.java4
-rw-r--r--src/com/android/launcher3/widget/WidgetsContainerView.java4
-rw-r--r--src/com/android/launcher3/widget/WidgetsListAdapter.java2
-rw-r--r--tests/src/com/android/launcher3/BindWidgetTest.java18
-rw-r--r--tests/src/com/android/launcher3/model/AddWorkspaceItemsTaskTest.java2
-rw-r--r--tests/src/com/android/launcher3/model/BaseModelUpdateTaskTestCase.java2
-rw-r--r--tests/src/com/android/launcher3/ui/LauncherInstrumentationTestCase.java26
34 files changed, 118 insertions, 127 deletions
diff --git a/src/com/android/launcher3/AppWidgetResizeFrame.java b/src/com/android/launcher3/AppWidgetResizeFrame.java
index 92da9b7ed..1a405f934 100644
--- a/src/com/android/launcher3/AppWidgetResizeFrame.java
+++ b/src/com/android/launcher3/AppWidgetResizeFrame.java
@@ -320,7 +320,7 @@ public class AppWidgetResizeFrame extends FrameLayout
public static Rect getWidgetSizeRanges(Context context, int spanX, int spanY, Rect rect) {
if (sCellSize == null) {
- InvariantDeviceProfile inv = LauncherAppState.getInstance().getInvariantDeviceProfile();
+ InvariantDeviceProfile inv = LauncherAppState.getIDP(context);
// Initiate cell sizes.
sCellSize = new Point[2];
diff --git a/src/com/android/launcher3/AutoInstallsLayout.java b/src/com/android/launcher3/AutoInstallsLayout.java
index 2a4212a2d..2e017df9c 100644
--- a/src/com/android/launcher3/AutoInstallsLayout.java
+++ b/src/com/android/launcher3/AutoInstallsLayout.java
@@ -79,7 +79,7 @@ public class AutoInstallsLayout {
static AutoInstallsLayout get(Context context, String pkg, Resources targetRes,
AppWidgetHost appWidgetHost, LayoutParserCallback callback) {
- InvariantDeviceProfile grid = LauncherAppState.getInstance().getInvariantDeviceProfile();
+ InvariantDeviceProfile grid = LauncherAppState.getIDP(context);
// Try with grid size and hotseat count
String layoutName = String.format(Locale.ENGLISH, FORMATTED_LAYOUT_RES_WITH_HOSTEAT,
@@ -182,7 +182,7 @@ public class AutoInstallsLayout {
mSourceRes = res;
mLayoutId = layoutId;
- mIdp = LauncherAppState.getInstance().getInvariantDeviceProfile();
+ mIdp = LauncherAppState.getIDP(context);
mRowCount = mIdp.numRows;
mColumnCount = mIdp.numColumns;
}
diff --git a/src/com/android/launcher3/BubbleTextView.java b/src/com/android/launcher3/BubbleTextView.java
index b8b43c9c3..32c3ac8be 100644
--- a/src/com/android/launcher3/BubbleTextView.java
+++ b/src/com/android/launcher3/BubbleTextView.java
@@ -587,7 +587,7 @@ public class BubbleTextView extends TextView
if (getTag() instanceof ItemInfoWithIcon) {
ItemInfoWithIcon info = (ItemInfoWithIcon) getTag();
if (info.usingLowResIcon) {
- mIconLoadRequest = LauncherAppState.getInstance().getIconCache()
+ mIconLoadRequest = LauncherAppState.getInstance(getContext()).getIconCache()
.updateIconInBackground(BubbleTextView.this, info);
}
}
diff --git a/src/com/android/launcher3/IconCache.java b/src/com/android/launcher3/IconCache.java
index 603d25a74..0c0c53dad 100644
--- a/src/com/android/launcher3/IconCache.java
+++ b/src/com/android/launcher3/IconCache.java
@@ -734,7 +734,7 @@ public class IconCache {
if (mAppsToUpdate.isEmpty() && !mUpdatedPackages.isEmpty()) {
// No more app to update. Notify model.
- LauncherAppState.getInstance().getModel().onPackageIconsUpdated(
+ LauncherAppState.getInstance(mContext).getModel().onPackageIconsUpdated(
mUpdatedPackages, mUserManager.getUserForSerialNumber(mUserSerial));
}
diff --git a/src/com/android/launcher3/InstallShortcutReceiver.java b/src/com/android/launcher3/InstallShortcutReceiver.java
index cba7cfe4f..09b33297e 100644
--- a/src/com/android/launcher3/InstallShortcutReceiver.java
+++ b/src/com/android/launcher3/InstallShortcutReceiver.java
@@ -241,7 +241,7 @@ public class InstallShortcutReceiver extends BroadcastReceiver {
private static void queuePendingShortcutInfo(PendingInstallShortcutInfo info, Context context) {
// Queue the item up for adding if launcher has not loaded properly yet
- LauncherAppState app = LauncherAppState.getInstance();
+ LauncherAppState app = LauncherAppState.getInstance(context);
boolean launcherNotLoaded = app.getModel().getCallback() == null;
addToInstallQueue(Utilities.getPrefs(context), info);
@@ -261,7 +261,7 @@ public class InstallShortcutReceiver extends BroadcastReceiver {
static void flushInstallQueue(Context context) {
ArrayList<PendingInstallShortcutInfo> items = getAndClearInstallQueue(context);
if (!items.isEmpty()) {
- LauncherAppState.getInstance().getModel().addAndBindAddedWorkspaceItems(
+ LauncherAppState.getInstance(context).getModel().addAndBindAddedWorkspaceItems(
new LazyShortcutsProvider(context.getApplicationContext(), items));
}
}
@@ -438,7 +438,7 @@ public class InstallShortcutReceiver extends BroadcastReceiver {
public ItemInfo getItemInfo() {
if (activityInfo != null) {
AppInfo appInfo = new AppInfo(mContext, activityInfo, user);
- final LauncherAppState app = LauncherAppState.getInstance();
+ final LauncherAppState app = LauncherAppState.getInstance(mContext);
// Set default values until proper values is loaded.
appInfo.title = "";
appInfo.iconBitmap = app.getIconCache().getDefaultIcon(user);
@@ -464,15 +464,14 @@ public class InstallShortcutReceiver extends BroadcastReceiver {
LauncherAppWidgetInfo widgetInfo = new LauncherAppWidgetInfo(
launchIntent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, 0),
info.provider);
- InvariantDeviceProfile idp = LauncherAppState.getInstance()
- .getInvariantDeviceProfile();
+ InvariantDeviceProfile idp = LauncherAppState.getIDP(mContext);
widgetInfo.minSpanX = info.minSpanX;
widgetInfo.minSpanY = info.minSpanY;
widgetInfo.spanX = Math.min(info.spanX, idp.numColumns);
widgetInfo.spanY = Math.min(info.spanY, idp.numRows);
return widgetInfo;
} else {
- return createShortcutInfo(data, LauncherAppState.getInstance());
+ return createShortcutInfo(data, LauncherAppState.getInstance(mContext));
}
}
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index d6c8cfb95..8322f66cd 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -356,7 +356,7 @@ public class Launcher extends Activity
super.onCreate(savedInstanceState);
- LauncherAppState app = LauncherAppState.getInstance();
+ LauncherAppState app = LauncherAppState.getInstance(this);
// Load configuration-specific DeviceProfile
mDeviceProfile =
@@ -1815,7 +1815,7 @@ public class Launcher extends Activity
// been created. In this case, don't interfere with the new Launcher.
if (mModel.isCurrentCallbacks(this)) {
mModel.stopLoader();
- LauncherAppState.getInstance().setLauncher(null);
+ LauncherAppState.getInstance(this).setLauncher(null);
}
if (mRotationPrefChangeHandler != null) {
diff --git a/src/com/android/launcher3/LauncherAppState.java b/src/com/android/launcher3/LauncherAppState.java
index 00e4bf4dc..4dc5a9727 100644
--- a/src/com/android/launcher3/LauncherAppState.java
+++ b/src/com/android/launcher3/LauncherAppState.java
@@ -48,7 +48,7 @@ public class LauncherAppState {
private InvariantDeviceProfile mInvariantDeviceProfile;
- public static LauncherAppState getInstance() {
+ public static LauncherAppState getInstance(Context context) {
if (INSTANCE == null) {
INSTANCE = new LauncherAppState();
}
@@ -159,4 +159,11 @@ public class LauncherAppState {
public InvariantDeviceProfile getInvariantDeviceProfile() {
return mInvariantDeviceProfile;
}
+
+ /**
+ * Shorthand for {@link #getInvariantDeviceProfile()}
+ */
+ public static InvariantDeviceProfile getIDP(Context context) {
+ return LauncherAppState.getInstance(context).getInvariantDeviceProfile();
+ }
}
diff --git a/src/com/android/launcher3/LauncherAppWidgetProviderInfo.java b/src/com/android/launcher3/LauncherAppWidgetProviderInfo.java
index ab8f395b3..6cb703b43 100644
--- a/src/com/android/launcher3/LauncherAppWidgetProviderInfo.java
+++ b/src/com/android/launcher3/LauncherAppWidgetProviderInfo.java
@@ -65,7 +65,7 @@ public class LauncherAppWidgetProviderInfo extends AppWidgetProviderInfo {
}
public void initSpans(Context context) {
- InvariantDeviceProfile idp = LauncherAppState.getInstance().getInvariantDeviceProfile();
+ InvariantDeviceProfile idp = LauncherAppState.getIDP(context);
Point paddingLand = idp.landscapeProfile.getTotalWorkspacePadding();
Point paddingPort = idp.portraitProfile.getTotalWorkspacePadding();
@@ -107,8 +107,7 @@ public class LauncherAppWidgetProviderInfo extends AppWidgetProviderInfo {
if (isCustomWidget) {
return cache.getFullResIcon(provider.getPackageName(), icon);
}
- return super.loadIcon(context,
- LauncherAppState.getInstance().getInvariantDeviceProfile().fillResIconDpi);
+ return super.loadIcon(context, LauncherAppState.getIDP(context).fillResIconDpi);
}
public String toString(PackageManager pm) {
diff --git a/src/com/android/launcher3/LauncherModel.java b/src/com/android/launcher3/LauncherModel.java
index 56892ff21..af22ab749 100644
--- a/src/com/android/launcher3/LauncherModel.java
+++ b/src/com/android/launcher3/LauncherModel.java
@@ -336,9 +336,10 @@ public class LauncherModel extends BroadcastReceiver
final ContentResolver cr = context.getContentResolver();
final StackTraceElement[] stackTrace = new Throwable().getStackTrace();
+ final Context appContext = context.getApplicationContext();
Runnable r = new Runnable() {
public void run() {
- cr.update(uri, writer.getValues(), null, null);
+ cr.update(uri, writer.getValues(appContext), null, null);
updateItemArrays(item, itemId, stackTrace);
}
};
@@ -553,13 +554,14 @@ public class LauncherModel extends BroadcastReceiver
writer.put(LauncherSettings.Favorites._ID, item.id);
final StackTraceElement[] stackTrace = new Throwable().getStackTrace();
+ final Context appContext = context.getApplicationContext();
Runnable r = new Runnable() {
public void run() {
- cr.insert(LauncherSettings.Favorites.CONTENT_URI, writer.getValues());
+ cr.insert(LauncherSettings.Favorites.CONTENT_URI, writer.getValues(appContext));
synchronized (sBgDataModel) {
checkItemInfoLocked(item.id, item, stackTrace);
- sBgDataModel.addItem(item, true);
+ sBgDataModel.addItem(appContext, item, true);
}
}
};
@@ -588,13 +590,14 @@ public class LauncherModel extends BroadcastReceiver
public static void deleteItemsFromDatabase(Context context,
final Iterable<? extends ItemInfo> items) {
final ContentResolver cr = context.getContentResolver();
+ final Context appContext = context.getApplicationContext();
Runnable r = new Runnable() {
public void run() {
for (ItemInfo item : items) {
final Uri uri = LauncherSettings.Favorites.getContentUri(item.id);
cr.delete(uri, null, null);
- sBgDataModel.removeItem(item);
+ sBgDataModel.removeItem(appContext, item);
}
}
};
@@ -654,16 +657,17 @@ public class LauncherModel extends BroadcastReceiver
*/
public static void deleteFolderAndContentsFromDatabase(Context context, final FolderInfo info) {
final ContentResolver cr = context.getContentResolver();
+ final Context appContext = context.getApplicationContext();
Runnable r = new Runnable() {
public void run() {
cr.delete(LauncherSettings.Favorites.CONTENT_URI,
LauncherSettings.Favorites.CONTAINER + "=" + info.id, null);
- sBgDataModel.removeItem(info.contents);
+ sBgDataModel.removeItem(appContext, info.contents);
info.contents.clear();
cr.delete(LauncherSettings.Favorites.getContentUri(info.id), null, null);
- sBgDataModel.removeItem(info);
+ sBgDataModel.removeItem(appContext, info);
}
};
runOnWorkerThread(r);
@@ -1101,8 +1105,7 @@ public class LauncherModel extends BroadcastReceiver
final boolean isSdCardReady = Utilities.isBootCompleted();
final MultiHashMap<UserHandle, String> pendingPackages = new MultiHashMap<>();
- LauncherAppState app = LauncherAppState.getInstance();
- InvariantDeviceProfile profile = app.getInvariantDeviceProfile();
+ InvariantDeviceProfile profile = mApp.getInvariantDeviceProfile();
int countX = profile.numColumns;
int countY = profile.numRows;
@@ -1693,8 +1696,7 @@ public class LauncherModel extends BroadcastReceiver
/** Sorts the set of items by hotseat, workspace (spatially from top to bottom, left to
* right) */
private void sortWorkspaceItemsSpatially(ArrayList<ItemInfo> workspaceItems) {
- final LauncherAppState app = LauncherAppState.getInstance();
- final InvariantDeviceProfile profile = app.getInvariantDeviceProfile();
+ final InvariantDeviceProfile profile = mApp.getInvariantDeviceProfile();
final int screenCols = profile.numColumns;
final int screenCellCount = profile.numColumns * profile.numRows;
Collections.sort(workspaceItems, new Comparator<ItemInfo>() {
@@ -2261,7 +2263,7 @@ public class LauncherModel extends BroadcastReceiver
bindWidgetsModel(callbacks);
// update the Widget entries inside DB on the worker thread.
- LauncherAppState.getInstance().getWidgetCache().removeObsoletePreviews(allWidgets);
+ mApp.getWidgetCache().removeObsoletePreviews(allWidgets);
}
});
}
diff --git a/src/com/android/launcher3/LauncherProvider.java b/src/com/android/launcher3/LauncherProvider.java
index 8f56eb69e..6266fae8f 100644
--- a/src/com/android/launcher3/LauncherProvider.java
+++ b/src/com/android/launcher3/LauncherProvider.java
@@ -556,8 +556,7 @@ public class LauncherProvider extends ContentProvider {
}
private DefaultLayoutParser getDefaultLayoutParser(AppWidgetHost widgetHost) {
- int defaultLayout = LauncherAppState.getInstance()
- .getInvariantDeviceProfile().defaultLayoutId;
+ int defaultLayout = LauncherAppState.getIDP(getContext()).defaultLayoutId;
return new DefaultLayoutParser(getContext(), widgetHost,
mOpenHelper, getContext().getResources(), defaultLayout);
}
diff --git a/src/com/android/launcher3/ShortcutInfo.java b/src/com/android/launcher3/ShortcutInfo.java
index 77c6837d0..8c83dff2b 100644
--- a/src/com/android/launcher3/ShortcutInfo.java
+++ b/src/com/android/launcher3/ShortcutInfo.java
@@ -235,7 +235,7 @@ public class ShortcutInfo extends ItemInfoWithIcon {
disabledMessage = shortcutInfo.getDisabledMessage();
// TODO: Use cache for this
- LauncherAppState launcherAppState = LauncherAppState.getInstance();
+ LauncherAppState launcherAppState = LauncherAppState.getInstance(context);
Drawable unbadgedDrawable = DeepShortcutManager.getInstance(context)
.getShortcutIconDrawable(shortcutInfo,
launcherAppState.getInvariantDeviceProfile().fillResIconDpi);
@@ -249,7 +249,7 @@ public class ShortcutInfo extends ItemInfoWithIcon {
protected Bitmap getBadgedIcon(Bitmap unbadgedBitmap, ShortcutInfoCompat shortcutInfo,
IconCache cache, Context context) {
- unbadgedBitmap = LauncherIcons.addShadowToIcon(unbadgedBitmap);
+ unbadgedBitmap = LauncherIcons.addShadowToIcon(unbadgedBitmap, context);
// Get the app info for the source activity.
AppInfo appInfo = new AppInfo();
appInfo.user = user;
diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java
index cf6b02505..103077953 100644
--- a/src/com/android/launcher3/Workspace.java
+++ b/src/com/android/launcher3/Workspace.java
@@ -1613,8 +1613,7 @@ public class Workspace extends PagedView
Utilities.THREAD_POOL_EXECUTOR.execute(new Runnable() {
@Override
public void run() {
- final Point size = LauncherAppState.getInstance()
- .getInvariantDeviceProfile().defaultWallpaperSize;
+ final Point size = LauncherAppState.getIDP(getContext()).defaultWallpaperSize;
if (size.x != mWallpaperManager.getDesiredMinimumWidth()
|| size.y != mWallpaperManager.getDesiredMinimumHeight()) {
mWallpaperManager.suggestDesiredDimensions(size.x, size.y);
diff --git a/src/com/android/launcher3/compat/PackageInstallerCompatVL.java b/src/com/android/launcher3/compat/PackageInstallerCompatVL.java
index 953d93df9..b87582f55 100644
--- a/src/com/android/launcher3/compat/PackageInstallerCompatVL.java
+++ b/src/com/android/launcher3/compat/PackageInstallerCompatVL.java
@@ -42,7 +42,7 @@ public class PackageInstallerCompatVL extends PackageInstallerCompat {
PackageInstallerCompatVL(Context context) {
mInstaller = context.getPackageManager().getPackageInstaller();
- mCache = LauncherAppState.getInstance().getIconCache();
+ mCache = LauncherAppState.getInstance(context).getIconCache();
mWorker = new Handler(LauncherModel.getWorkerLooper());
mInstaller.registerSessionCallback(mCallback, mWorker);
diff --git a/src/com/android/launcher3/folder/FolderPagedView.java b/src/com/android/launcher3/folder/FolderPagedView.java
index 4c1203281..4a2a7350b 100644
--- a/src/com/android/launcher3/folder/FolderPagedView.java
+++ b/src/com/android/launcher3/folder/FolderPagedView.java
@@ -96,9 +96,7 @@ public class FolderPagedView extends PagedView {
public FolderPagedView(Context context, AttributeSet attrs) {
super(context, attrs);
- LauncherAppState app = LauncherAppState.getInstance();
-
- InvariantDeviceProfile profile = app.getInvariantDeviceProfile();
+ InvariantDeviceProfile profile = LauncherAppState.getIDP(context);
mMaxCountX = profile.numFolderColumns;
mMaxCountY = profile.numFolderRows;
diff --git a/src/com/android/launcher3/graphics/IconNormalizer.java b/src/com/android/launcher3/graphics/IconNormalizer.java
index 14109172b..70b3dd6c9 100644
--- a/src/com/android/launcher3/graphics/IconNormalizer.java
+++ b/src/com/android/launcher3/graphics/IconNormalizer.java
@@ -16,6 +16,7 @@
package com.android.launcher3.graphics;
+import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
@@ -53,9 +54,9 @@ public class IconNormalizer {
private final float[] mLeftBorder;
private final float[] mRightBorder;
- private IconNormalizer() {
+ private IconNormalizer(Context context) {
// Use twice the icon size as maximum size to avoid scaling down twice.
- mMaxSize = LauncherAppState.getInstance().getInvariantDeviceProfile().iconBitmapSize * 2;
+ mMaxSize = LauncherAppState.getIDP(context).iconBitmapSize * 2;
mBitmap = Bitmap.createBitmap(mMaxSize, mMaxSize, Bitmap.Config.ALPHA_8);
mCanvas = new Canvas(mBitmap);
mPixels = new byte[mMaxSize * mMaxSize];
@@ -239,10 +240,10 @@ public class IconNormalizer {
}
}
- public static IconNormalizer getInstance() {
+ public static IconNormalizer getInstance(Context context) {
synchronized (LOCK) {
if (sIconNormalizer == null) {
- sIconNormalizer = new IconNormalizer();
+ sIconNormalizer = new IconNormalizer(context);
}
}
return sIconNormalizer;
diff --git a/src/com/android/launcher3/graphics/LauncherIcons.java b/src/com/android/launcher3/graphics/LauncherIcons.java
index 0619187bd..01bae0e66 100644
--- a/src/com/android/launcher3/graphics/LauncherIcons.java
+++ b/src/com/android/launcher3/graphics/LauncherIcons.java
@@ -60,9 +60,8 @@ public class LauncherIcons {
Resources resources = packageManager.getResourcesForApplication(iconRes.packageName);
if (resources != null) {
final int id = resources.getIdentifier(iconRes.resourceName, null, null);
- return createIconBitmap(
- resources.getDrawableForDensity(id, LauncherAppState.getInstance()
- .getInvariantDeviceProfile().fillResIconDpi), context);
+ return createIconBitmap(resources.getDrawableForDensity(
+ id, LauncherAppState.getIDP(context).fillResIconDpi), context);
}
} catch (Exception e) {
// Icon not found.
@@ -70,15 +69,11 @@ public class LauncherIcons {
return null;
}
- private static int getIconBitmapSize() {
- return LauncherAppState.getInstance().getInvariantDeviceProfile().iconBitmapSize;
- }
-
/**
* Returns a bitmap which is of the appropriate size to be displayed as an icon
*/
public static Bitmap createIconBitmap(Bitmap icon, Context context) {
- final int iconBitmapSize = getIconBitmapSize();
+ final int iconBitmapSize = LauncherAppState.getIDP(context).iconBitmapSize;
if (iconBitmapSize == icon.getWidth() && iconBitmapSize == icon.getHeight()) {
return icon;
}
@@ -92,7 +87,7 @@ public class LauncherIcons {
public static Bitmap createBadgedIconBitmap(
Drawable icon, UserHandle user, Context context) {
float scale = FeatureFlags.LAUNCHER3_DISABLE_ICON_NORMALIZATION ?
- 1 : IconNormalizer.getInstance().getScale(icon, null);
+ 1 : IconNormalizer.getInstance(context).getScale(icon, null);
Bitmap bitmap = createIconBitmap(icon, context, scale);
return badgeIconForUser(bitmap, user, context);
}
@@ -122,7 +117,7 @@ public class LauncherIcons {
public static Bitmap createScaledBitmapWithoutShadow(Drawable icon, Context context) {
RectF iconBounds = new RectF();
float scale = FeatureFlags.LAUNCHER3_DISABLE_ICON_NORMALIZATION ?
- 1 : IconNormalizer.getInstance().getScale(icon, iconBounds);
+ 1 : IconNormalizer.getInstance(context).getScale(icon, iconBounds);
scale = Math.min(scale, ShadowGenerator.getScaleForBounds(iconBounds));
return createIconBitmap(icon, context, scale);
}
@@ -131,8 +126,8 @@ public class LauncherIcons {
* Adds a shadow to the provided icon. It assumes that the icon has already been scaled using
* {@link #createScaledBitmapWithoutShadow(Drawable, Context)}
*/
- public static Bitmap addShadowToIcon(Bitmap icon) {
- return ShadowGenerator.getInstance().recreateIcon(icon);
+ public static Bitmap addShadowToIcon(Bitmap icon, Context context) {
+ return ShadowGenerator.getInstance(context).recreateIcon(icon);
}
/**
@@ -163,7 +158,7 @@ public class LauncherIcons {
*/
public static Bitmap createIconBitmap(Drawable icon, Context context, float scale) {
synchronized (sCanvas) {
- final int iconBitmapSize = getIconBitmapSize();
+ final int iconBitmapSize = LauncherAppState.getIDP(context).iconBitmapSize;
int width = iconBitmapSize;
int height = iconBitmapSize;
diff --git a/src/com/android/launcher3/graphics/ShadowGenerator.java b/src/com/android/launcher3/graphics/ShadowGenerator.java
index 2b24ec932..8aea5a039 100644
--- a/src/com/android/launcher3/graphics/ShadowGenerator.java
+++ b/src/com/android/launcher3/graphics/ShadowGenerator.java
@@ -16,6 +16,7 @@
package com.android.launcher3.graphics;
+import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.BlurMaskFilter;
@@ -52,8 +53,8 @@ public class ShadowGenerator {
private final Paint mBlurPaint;
private final Paint mDrawPaint;
- private ShadowGenerator() {
- mIconSize = LauncherAppState.getInstance().getInvariantDeviceProfile().iconBitmapSize;
+ private ShadowGenerator(Context context) {
+ mIconSize = LauncherAppState.getIDP(context).iconBitmapSize;
mCanvas = new Canvas();
mBlurPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG);
mBlurPaint.setMaskFilter(new BlurMaskFilter(mIconSize * BLUR_FACTOR, Blur.NORMAL));
@@ -82,11 +83,11 @@ public class ShadowGenerator {
return result;
}
- public static ShadowGenerator getInstance() {
+ public static ShadowGenerator getInstance(Context context) {
Preconditions.assertNonUiThread();
synchronized (LOCK) {
if (sShadowGenerator == null) {
- sShadowGenerator = new ShadowGenerator();
+ sShadowGenerator = new ShadowGenerator(context);
}
}
return sShadowGenerator;
diff --git a/src/com/android/launcher3/model/BgDataModel.java b/src/com/android/launcher3/model/BgDataModel.java
index 6dc5a365d..2ac33eaef 100644
--- a/src/com/android/launcher3/model/BgDataModel.java
+++ b/src/com/android/launcher3/model/BgDataModel.java
@@ -99,11 +99,11 @@ public class BgDataModel {
deepShortcutMap.clear();
}
- public synchronized void removeItem(ItemInfo... items) {
- removeItem(Arrays.asList(items));
+ public synchronized void removeItem(Context context, ItemInfo... items) {
+ removeItem(context, Arrays.asList(items));
}
- public synchronized void removeItem(Iterable<? extends ItemInfo> items) {
+ public synchronized void removeItem(Context context, Iterable<? extends ItemInfo> items) {
for (ItemInfo item : items) {
switch (item.itemType) {
case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
@@ -125,7 +125,6 @@ public class BgDataModel {
// Decrement pinned shortcut count
ShortcutKey pinnedShortcut = ShortcutKey.fromItemInfo(item);
MutableInt count = pinnedShortcutCounts.get(pinnedShortcut);
- Context context = LauncherAppState.getInstance().getContext();
if ((count == null || --count.value == 0)
&& !InstallShortcutReceiver.getPendingShortcuts(context)
.contains(pinnedShortcut)) {
@@ -146,7 +145,7 @@ public class BgDataModel {
}
}
- public synchronized void addItem(ItemInfo item, boolean newItem) {
+ public synchronized void addItem(Context context, ItemInfo item, boolean newItem) {
itemsIdMap.put(item.id, item);
switch (item.itemType) {
case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
@@ -166,8 +165,7 @@ public class BgDataModel {
// Since this is a new item, pin the shortcut in the system server.
if (newItem && count.value == 1) {
- DeepShortcutManager.getInstance(LauncherAppState.getInstance().getContext())
- .pinShortcut(pinnedShortcut);
+ DeepShortcutManager.getInstance(context).pinShortcut(pinnedShortcut);
}
// Fall through
}
diff --git a/src/com/android/launcher3/model/GridSizeMigrationTask.java b/src/com/android/launcher3/model/GridSizeMigrationTask.java
index 599dcd0d3..bbc7ae461 100644
--- a/src/com/android/launcher3/model/GridSizeMigrationTask.java
+++ b/src/com/android/launcher3/model/GridSizeMigrationTask.java
@@ -895,7 +895,7 @@ public class GridSizeMigrationTask {
*/
public static boolean migrateGridIfNeeded(Context context) {
SharedPreferences prefs = Utilities.getPrefs(context);
- InvariantDeviceProfile idp = LauncherAppState.getInstance().getInvariantDeviceProfile();
+ InvariantDeviceProfile idp = LauncherAppState.getIDP(context);
String gridSizeString = getPointString(idp.numColumns, idp.numRows);
@@ -915,8 +915,7 @@ public class GridSizeMigrationTask {
if (srcHotseatCount != idp.numHotseatIcons) {
// Migrate hotseat.
- dbChanged = new GridSizeMigrationTask(context,
- LauncherAppState.getInstance().getInvariantDeviceProfile(),
+ dbChanged = new GridSizeMigrationTask(context, LauncherAppState.getIDP(context),
validPackages, srcHotseatCount, idp.numHotseatIcons).migrateHotseat();
}
@@ -978,9 +977,9 @@ public class GridSizeMigrationTask {
* @return a map with occupied hotseat position set to non-null value.
*/
public static LongArrayMap<Object> removeBrokenHotseatItems(Context context) throws Exception {
- GridSizeMigrationTask task = new GridSizeMigrationTask(context,
- LauncherAppState.getInstance().getInvariantDeviceProfile(),
- getValidPackages(context), Integer.MAX_VALUE, Integer.MAX_VALUE);
+ GridSizeMigrationTask task = new GridSizeMigrationTask(
+ context, LauncherAppState.getIDP(context), getValidPackages(context),
+ Integer.MAX_VALUE, Integer.MAX_VALUE);
// Load all the valid entries
ArrayList<DbEntry> items = task.loadHotseatEntries();
@@ -1038,8 +1037,7 @@ public class GridSizeMigrationTask {
}
protected boolean runStepTask(Point sourceSize, Point nextSize) throws Exception {
- return new GridSizeMigrationTask(mContext,
- LauncherAppState.getInstance().getInvariantDeviceProfile(),
+ return new GridSizeMigrationTask(mContext, LauncherAppState.getIDP(mContext),
mValidPackages, sourceSize, nextSize).migrateWorkspace();
}
}
diff --git a/src/com/android/launcher3/model/LoaderCursor.java b/src/com/android/launcher3/model/LoaderCursor.java
index 99a6cdf5e..0dfb1c7ac 100644
--- a/src/com/android/launcher3/model/LoaderCursor.java
+++ b/src/com/android/launcher3/model/LoaderCursor.java
@@ -349,7 +349,7 @@ public class LoaderCursor extends CursorWrapper {
*/
public void checkAndAddItem(ItemInfo info, BgDataModel dataModel) {
if (checkItemPlacement(info, dataModel.workspaceScreens)) {
- dataModel.addItem(info, false);
+ dataModel.addItem(mContext, info, false);
} else {
markDeleted("Item position overlap");
}
diff --git a/src/com/android/launcher3/model/WidgetItem.java b/src/com/android/launcher3/model/WidgetItem.java
index 452dbe2ad..c256176d2 100644
--- a/src/com/android/launcher3/model/WidgetItem.java
+++ b/src/com/android/launcher3/model/WidgetItem.java
@@ -31,16 +31,16 @@ public class WidgetItem extends ComponentKey implements Comparable<WidgetItem> {
public final String label;
public final int spanX, spanY;
- public WidgetItem(LauncherAppWidgetProviderInfo info, PackageManager pm) {
+ public WidgetItem(LauncherAppWidgetProviderInfo info, PackageManager pm,
+ InvariantDeviceProfile idp) {
super(info.provider, info.getProfile());
label = Utilities.trim(info.getLabel(pm));
widgetInfo = info;
activityInfo = null;
- InvariantDeviceProfile idv = LauncherAppState.getInstance().getInvariantDeviceProfile();
- spanX = Math.min(info.spanX, idv.numColumns);
- spanY = Math.min(info.spanY, idv.numRows);
+ spanX = Math.min(info.spanX, idp.numColumns);
+ spanY = Math.min(info.spanY, idp.numRows);
}
public WidgetItem(ResolveInfo info, PackageManager pm) {
diff --git a/src/com/android/launcher3/model/WidgetsModel.java b/src/com/android/launcher3/model/WidgetsModel.java
index 256598554..2c62f896b 100644
--- a/src/com/android/launcher3/model/WidgetsModel.java
+++ b/src/com/android/launcher3/model/WidgetsModel.java
@@ -60,12 +60,13 @@ public class WidgetsModel {
final ArrayList<WidgetItem> widgetsAndShortcuts = new ArrayList<>();
try {
PackageManager pm = context.getPackageManager();
+ InvariantDeviceProfile idp = LauncherAppState.getIDP(context);
// Widgets
for (AppWidgetProviderInfo widgetInfo :
AppWidgetManagerCompat.getInstance(context).getAllProviders()) {
- widgetsAndShortcuts.add(new WidgetItem(
- LauncherAppWidgetProviderInfo.fromProviderInfo(context, widgetInfo), pm));
+ widgetsAndShortcuts.add(new WidgetItem(LauncherAppWidgetProviderInfo
+ .fromProviderInfo(context, widgetInfo), pm, idp));
}
// Shortcuts
@@ -73,7 +74,7 @@ public class WidgetsModel {
pm.queryIntentActivities(new Intent(Intent.ACTION_CREATE_SHORTCUT), 0)) {
widgetsAndShortcuts.add(new WidgetItem(info, pm));
}
- setWidgetsAndShortcuts(widgetsAndShortcuts);
+ setWidgetsAndShortcuts(widgetsAndShortcuts, context);
} catch (Exception e) {
if (!ProviderConfig.IS_DOGFOOD_BUILD && Utilities.isBinderSizeError(e)) {
// the returned value may be incomplete and will not be refreshed until the next
@@ -87,7 +88,8 @@ public class WidgetsModel {
return widgetsAndShortcuts;
}
- private void setWidgetsAndShortcuts(ArrayList<WidgetItem> rawWidgetsShortcuts) {
+ private void setWidgetsAndShortcuts(ArrayList<WidgetItem> rawWidgetsShortcuts,
+ Context context) {
if (DEBUG) {
Log.d(TAG, "addWidgetsAndShortcuts, widgetsShortcuts#=" + rawWidgetsShortcuts.size());
}
@@ -99,7 +101,7 @@ public class WidgetsModel {
// clear the lists.
mWidgetsList.clear();
- InvariantDeviceProfile idp = LauncherAppState.getInstance().getInvariantDeviceProfile();
+ InvariantDeviceProfile idp = LauncherAppState.getIDP(context);
UserHandle myUser = Process.myUserHandle();
// add and update.
diff --git a/src/com/android/launcher3/provider/ImportDataTask.java b/src/com/android/launcher3/provider/ImportDataTask.java
index 808e6e3ac..b0482f8b2 100644
--- a/src/com/android/launcher3/provider/ImportDataTask.java
+++ b/src/com/android/launcher3/provider/ImportDataTask.java
@@ -306,7 +306,7 @@ public class ImportDataTask {
}
LongArrayMap<Object> hotseatItems = GridSizeMigrationTask.removeBrokenHotseatItems(mContext);
- int myHotseatCount = LauncherAppState.getInstance().getInvariantDeviceProfile().numHotseatIcons;
+ int myHotseatCount = LauncherAppState.getIDP(mContext).numHotseatIcons;
if (!FeatureFlags.NO_ALL_APPS_ICON) {
myHotseatCount--;
}
@@ -381,8 +381,8 @@ public class ImportDataTask {
return c.getSharedPreferences(LauncherFiles.DEVICE_PREFERENCES_KEY, Context.MODE_PRIVATE);
}
- private static final int getMyHotseatLayoutId() {
- return LauncherAppState.getInstance().getInvariantDeviceProfile().numHotseatIcons <= 5
+ private static final int getMyHotseatLayoutId(Context context) {
+ return LauncherAppState.getIDP(context).numHotseatIcons <= 5
? R.xml.dw_phone_hotseat
: R.xml.dw_tablet_hotseat;
}
@@ -392,7 +392,7 @@ public class ImportDataTask {
*/
private static class HotseatLayoutParser extends DefaultLayoutParser {
public HotseatLayoutParser(Context context, LayoutParserCallback callback) {
- super(context, null, callback, context.getResources(), getMyHotseatLayoutId());
+ super(context, null, callback, context.getResources(), getMyHotseatLayoutId(context));
}
@Override
diff --git a/src/com/android/launcher3/provider/LauncherDbUtils.java b/src/com/android/launcher3/provider/LauncherDbUtils.java
index 89fd99b23..175835011 100644
--- a/src/com/android/launcher3/provider/LauncherDbUtils.java
+++ b/src/com/android/launcher3/provider/LauncherDbUtils.java
@@ -76,8 +76,7 @@ public class LauncherDbUtils {
}
}
- new LossyScreenMigrationTask(
- context, LauncherAppState.getInstance().getInvariantDeviceProfile(), db)
+ new LossyScreenMigrationTask(context, LauncherAppState.getIDP(context), db)
.migrateScreen0();
db.setTransactionSuccessful();
return true;
diff --git a/src/com/android/launcher3/qsb/QsbContainerView.java b/src/com/android/launcher3/qsb/QsbContainerView.java
index c83143be9..38a3e1f58 100644
--- a/src/com/android/launcher3/qsb/QsbContainerView.java
+++ b/src/com/android/launcher3/qsb/QsbContainerView.java
@@ -102,7 +102,7 @@ public class QsbContainerView extends FrameLayout {
}
AppWidgetManagerCompat widgetManager = AppWidgetManagerCompat.getInstance(activity);
- InvariantDeviceProfile idp = LauncherAppState.getInstance().getInvariantDeviceProfile();
+ InvariantDeviceProfile idp = LauncherAppState.getIDP(activity);
Bundle opts = new Bundle();
Rect size = AppWidgetResizeFrame.getWidgetSizeRanges(activity, idp.numColumns, 1, null);
diff --git a/src/com/android/launcher3/testing/ToggleWeightWatcher.java b/src/com/android/launcher3/testing/ToggleWeightWatcher.java
index e08ec3aca..f0c39202b 100644
--- a/src/com/android/launcher3/testing/ToggleWeightWatcher.java
+++ b/src/com/android/launcher3/testing/ToggleWeightWatcher.java
@@ -22,7 +22,7 @@ public class ToggleWeightWatcher extends Activity {
show = !show;
sp.edit().putBoolean(TestingUtils.SHOW_WEIGHT_WATCHER, show).apply();
- Launcher launcher = (Launcher) LauncherAppState.getInstance().getModel().getCallback();
+ Launcher launcher = (Launcher) LauncherAppState.getInstance(this).getModel().getCallback();
if (launcher != null && launcher.mWeightWatcher != null) {
launcher.mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
}
diff --git a/src/com/android/launcher3/util/ContentWriter.java b/src/com/android/launcher3/util/ContentWriter.java
index 76ba9d63a..438432891 100644
--- a/src/com/android/launcher3/util/ContentWriter.java
+++ b/src/com/android/launcher3/util/ContentWriter.java
@@ -93,9 +93,9 @@ public class ContentWriter {
* Commits any pending validation and returns the final values.
* Must not be called on UI thread.
*/
- public ContentValues getValues() {
+ public ContentValues getValues(Context context) {
Preconditions.assertNonUiThread();
- if (mIcon != null && !LauncherAppState.getInstance().getIconCache()
+ if (mIcon != null && !LauncherAppState.getInstance(context).getIconCache()
.isDefaultIcon(mIcon, mUser)) {
mValues.put(LauncherSettings.Favorites.ICON, Utilities.flattenBitmap(mIcon));
mIcon = null;
@@ -105,7 +105,7 @@ public class ContentWriter {
public int commit() {
if (mCommitParams != null) {
- return mContext.getContentResolver().update(mCommitParams.mUri, getValues(),
+ return mContext.getContentResolver().update(mCommitParams.mUri, getValues(mContext),
mCommitParams.mWhere, mCommitParams.mSelectionArgs);
}
return 0;
diff --git a/src/com/android/launcher3/util/ManagedProfileHeuristic.java b/src/com/android/launcher3/util/ManagedProfileHeuristic.java
index c27a3b546..76378d154 100644
--- a/src/com/android/launcher3/util/ManagedProfileHeuristic.java
+++ b/src/com/android/launcher3/util/ManagedProfileHeuristic.java
@@ -72,8 +72,8 @@ public class ManagedProfileHeuristic {
private ManagedProfileHeuristic(Context context, UserHandle user) {
mContext = context;
mUser = user;
- mModel = LauncherAppState.getInstance().getModel();
- mIconCache = LauncherAppState.getInstance().getIconCache();
+ mModel = LauncherAppState.getInstance(context).getModel();
+ mIconCache = LauncherAppState.getInstance(context).getIconCache();
}
public void processPackageRemoved(String[] packages) {
diff --git a/src/com/android/launcher3/widget/WidgetsContainerView.java b/src/com/android/launcher3/widget/WidgetsContainerView.java
index 310c1dfb9..be4f6351f 100644
--- a/src/com/android/launcher3/widget/WidgetsContainerView.java
+++ b/src/com/android/launcher3/widget/WidgetsContainerView.java
@@ -87,7 +87,7 @@ public class WidgetsContainerView extends BaseContainerView
mLauncher = Launcher.getLauncher(context);
mDragController = mLauncher.getDragController();
mAdapter = new WidgetsListAdapter(this, this, context);
- mIconCache = (LauncherAppState.getInstance()).getIconCache();
+ mIconCache = LauncherAppState.getInstance(context).getIconCache();
if (LOGD) {
Log.d(TAG, "WidgetsContainerView constructor");
}
@@ -303,7 +303,7 @@ public class WidgetsContainerView extends BaseContainerView
private WidgetPreviewLoader getWidgetPreviewLoader() {
if (mWidgetPreviewLoader == null) {
- mWidgetPreviewLoader = LauncherAppState.getInstance().getWidgetCache();
+ mWidgetPreviewLoader = LauncherAppState.getInstance(getContext()).getWidgetCache();
}
return mWidgetPreviewLoader;
}
diff --git a/src/com/android/launcher3/widget/WidgetsListAdapter.java b/src/com/android/launcher3/widget/WidgetsListAdapter.java
index f18313fdf..2d746d762 100644
--- a/src/com/android/launcher3/widget/WidgetsListAdapter.java
+++ b/src/com/android/launcher3/widget/WidgetsListAdapter.java
@@ -68,7 +68,7 @@ public class WidgetsListAdapter extends Adapter<WidgetsRowViewHolder> {
View.OnLongClickListener iconLongClickListener,
Context context) {
mLayoutInflater = LayoutInflater.from(context);
- mWidgetPreviewLoader = LauncherAppState.getInstance().getWidgetCache();
+ mWidgetPreviewLoader = LauncherAppState.getInstance(context).getWidgetCache();
mIndexer = new AlphabeticIndexCompat(context);
diff --git a/tests/src/com/android/launcher3/BindWidgetTest.java b/tests/src/com/android/launcher3/BindWidgetTest.java
index 72533e7e1..575b42b87 100644
--- a/tests/src/com/android/launcher3/BindWidgetTest.java
+++ b/tests/src/com/android/launcher3/BindWidgetTest.java
@@ -16,7 +16,6 @@ import com.android.launcher3.compat.AppWidgetManagerCompat;
import com.android.launcher3.compat.PackageInstallerCompat;
import com.android.launcher3.ui.LauncherInstrumentationTestCase;
import com.android.launcher3.util.ContentWriter;
-import com.android.launcher3.util.ManagedProfileHeuristic;
import com.android.launcher3.widget.PendingAddWidgetInfo;
import com.android.launcher3.widget.WidgetHostViewLoader;
@@ -223,20 +222,9 @@ public class BindWidgetTest extends LauncherInstrumentationTestCase {
item.screenId = screenId;
item.onAddToDatabase(writer);
writer.put(LauncherSettings.Favorites._ID, item.id);
- mResolver.insert(LauncherSettings.Favorites.CONTENT_URI, writer.getValues());
-
- // Reset loader
- try {
- runTestOnUiThread(new Runnable() {
- @Override
- public void run() {
- ManagedProfileHeuristic.markExistingUsersForNoFolderCreation(mTargetContext);
- LauncherAppState.getInstance().getModel().resetLoadedState(true, true);
- }
- });
- } catch (Throwable t) {
- throw new IllegalArgumentException(t);
- }
+ mResolver.insert(LauncherSettings.Favorites.CONTENT_URI, writer.getValues(mTargetContext));
+ resetLoaderState();
+
// Launch the home activity
startLauncher();
// Verify UI
diff --git a/tests/src/com/android/launcher3/model/AddWorkspaceItemsTaskTest.java b/tests/src/com/android/launcher3/model/AddWorkspaceItemsTaskTest.java
index b2f0cbbbc..207138940 100644
--- a/tests/src/com/android/launcher3/model/AddWorkspaceItemsTaskTest.java
+++ b/tests/src/com/android/launcher3/model/AddWorkspaceItemsTaskTest.java
@@ -164,7 +164,7 @@ public class AddWorkspaceItemsTaskTest extends BaseModelUpdateTaskTestCase {
info.cellX = x;
info.cellY = y;
info.container = LauncherSettings.Favorites.CONTAINER_DESKTOP;
- bgDataModel.addItem(info, false);
+ bgDataModel.addItem(targetContext, info, false);
}
}
return startId;
diff --git a/tests/src/com/android/launcher3/model/BaseModelUpdateTaskTestCase.java b/tests/src/com/android/launcher3/model/BaseModelUpdateTaskTestCase.java
index 3a27d0dbf..73c90dade 100644
--- a/tests/src/com/android/launcher3/model/BaseModelUpdateTaskTestCase.java
+++ b/tests/src/com/android/launcher3/model/BaseModelUpdateTaskTestCase.java
@@ -128,7 +128,7 @@ public class BaseModelUpdateTaskTestCase extends ProviderTestCase2<TestLauncherP
classMap.put(commands[1], Class.forName(commands[2]));
break;
case "bgItem":
- bgDataModel.addItem(
+ bgDataModel.addItem(targetContext,
(ItemInfo) initItem(classMap.get(commands[1]), commands, 2), false);
break;
case "allApps":
diff --git a/tests/src/com/android/launcher3/ui/LauncherInstrumentationTestCase.java b/tests/src/com/android/launcher3/ui/LauncherInstrumentationTestCase.java
index fcf712227..42c6cd729 100644
--- a/tests/src/com/android/launcher3/ui/LauncherInstrumentationTestCase.java
+++ b/tests/src/com/android/launcher3/ui/LauncherInstrumentationTestCase.java
@@ -211,15 +211,22 @@ public class LauncherInstrumentationTestCase extends InstrumentationTestCase {
LauncherSettings.Settings.METHOD_CREATE_EMPTY_DB);
LauncherSettings.Settings.call(mTargetContext.getContentResolver(),
LauncherSettings.Settings.METHOD_CLEAR_EMPTY_DB_FLAG);
- ManagedProfileHeuristic.markExistingUsersForNoFolderCreation(mTargetContext);
+ resetLoaderState();
+ }
- runTestOnUiThread(new Runnable() {
- @Override
- public void run() {
- // Reset the loader state
- LauncherAppState.getInstance().getModel().resetLoadedState(true, true);
- }
- });
+ protected void resetLoaderState() {
+ try {
+ runTestOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ ManagedProfileHeuristic.markExistingUsersForNoFolderCreation(mTargetContext);
+ LauncherAppState.getInstance(mTargetContext).getModel()
+ .resetLoadedState(true, true);
+ }
+ });
+ } catch (Throwable t) {
+ throw new IllegalArgumentException(t);
+ }
}
/**
@@ -248,8 +255,7 @@ public class LauncherInstrumentationTestCase extends InstrumentationTestCase {
LauncherAppWidgetProviderInfo info = getOnUiThread(new Callable<LauncherAppWidgetProviderInfo>() {
@Override
public LauncherAppWidgetProviderInfo call() throws Exception {
- InvariantDeviceProfile idv =
- LauncherAppState.getInstance().getInvariantDeviceProfile();
+ InvariantDeviceProfile idv = LauncherAppState.getIDP(mTargetContext);
ComponentName searchComponent = ((SearchManager) mTargetContext
.getSystemService(Context.SEARCH_SERVICE)).getGlobalSearchActivity();