Removing static instances of UserManagerCompat and AppWidgetManager
> Changing the lifecycle to follow other static objects in Launcher > Removing compat interface and inlining everything to helpers Bug: 141376165 Change-Id: I82bd5db1969101de9a7eac77f32728d70195bb35
This commit is contained in:
parent
ebc50f3095
commit
337c81f664
|
@ -19,24 +19,15 @@ import static com.android.systemui.shared.system.QuickStepContract.KEY_EXTRA_SYS
|
|||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Service;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.graphics.Region;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.IBinder;
|
||||
import android.os.Process;
|
||||
import android.os.RemoteException;
|
||||
import android.util.Log;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
import com.android.launcher3.Utilities;
|
||||
import com.android.launcher3.compat.UserManagerCompat;
|
||||
import com.android.launcher3.util.DefaultDisplay;
|
||||
import com.android.quickstep.RecentsAnimationDeviceState;
|
||||
import com.android.quickstep.SystemUiProxy;
|
||||
import com.android.systemui.shared.recents.IOverviewProxy;
|
||||
import com.android.systemui.shared.recents.ISystemUiProxy;
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ import android.graphics.CornerPathEffect;
|
|||
import android.graphics.Paint;
|
||||
import android.graphics.drawable.ShapeDrawable;
|
||||
import android.os.Handler;
|
||||
import android.os.UserManager;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.TypedValue;
|
||||
import android.view.Gravity;
|
||||
|
@ -33,6 +34,8 @@ import android.view.ViewGroup;
|
|||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import com.android.launcher3.AbstractFloatingView;
|
||||
import com.android.launcher3.Launcher;
|
||||
import com.android.launcher3.LauncherState;
|
||||
|
@ -41,13 +44,10 @@ import com.android.launcher3.R;
|
|||
import com.android.launcher3.Utilities;
|
||||
import com.android.launcher3.allapps.FloatingHeaderView;
|
||||
import com.android.launcher3.anim.Interpolators;
|
||||
import com.android.launcher3.compat.UserManagerCompat;
|
||||
import com.android.launcher3.dragndrop.DragLayer;
|
||||
import com.android.launcher3.graphics.TriangleShape;
|
||||
import com.android.systemui.shared.system.LauncherEventUtil;
|
||||
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
/**
|
||||
* All apps tip view aligned just above prediction apps, shown to users that enter all apps for the
|
||||
* first time.
|
||||
|
@ -151,7 +151,7 @@ public class AllAppsTipView extends AbstractFloatingView {
|
|||
TYPE_ON_BOARD_POPUP | TYPE_DISCOVERY_BOUNCE) != null
|
||||
|| !launcher.isInState(ALL_APPS)
|
||||
|| hasSeenAllAppsTip(launcher)
|
||||
|| UserManagerCompat.getInstance(launcher).isDemoUser()
|
||||
|| launcher.getSystemService(UserManager.class).isDemoUser()
|
||||
|| Utilities.IS_RUNNING_IN_TEST_HARNESS) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -17,10 +17,8 @@ package com.android.quickstep;
|
|||
|
||||
import static android.content.Intent.ACTION_USER_UNLOCKED;
|
||||
|
||||
import static android.provider.Settings.System.HAPTIC_FEEDBACK_ENABLED;
|
||||
import static com.android.launcher3.ResourceUtils.NAVBAR_BOTTOM_GESTURE_SIZE;
|
||||
import static com.android.launcher3.ResourceUtils.NAVBAR_LANDSCAPE_LEFT_RIGHT_SIZE;
|
||||
import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
|
||||
import static com.android.quickstep.SysUINavigationMode.Mode.NO_BUTTON;
|
||||
import static com.android.quickstep.SysUINavigationMode.Mode.THREE_BUTTONS;
|
||||
import static com.android.quickstep.SysUINavigationMode.Mode.TWO_BUTTONS;
|
||||
|
@ -42,12 +40,11 @@ import android.content.Context;
|
|||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.res.Resources;
|
||||
import android.database.ContentObserver;
|
||||
import android.graphics.Point;
|
||||
import android.graphics.RectF;
|
||||
import android.graphics.Region;
|
||||
import android.os.Process;
|
||||
import android.provider.Settings;
|
||||
import android.os.UserManager;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.MotionEvent;
|
||||
|
@ -58,7 +55,6 @@ import androidx.annotation.BinderThread;
|
|||
import com.android.launcher3.R;
|
||||
import com.android.launcher3.ResourceUtils;
|
||||
import com.android.launcher3.Utilities;
|
||||
import com.android.launcher3.compat.UserManagerCompat;
|
||||
import com.android.launcher3.testing.TestProtocol;
|
||||
import com.android.launcher3.util.DefaultDisplay;
|
||||
import com.android.quickstep.SysUINavigationMode.NavigationModeChangeListener;
|
||||
|
@ -79,7 +75,6 @@ public class RecentsAnimationDeviceState implements
|
|||
DefaultDisplay.DisplayInfoChangeListener {
|
||||
|
||||
private final Context mContext;
|
||||
private final UserManagerCompat mUserManager;
|
||||
private final SysUINavigationMode mSysUiNavMode;
|
||||
private final DefaultDisplay mDefaultDisplay;
|
||||
private final int mDisplayId;
|
||||
|
@ -117,14 +112,14 @@ public class RecentsAnimationDeviceState implements
|
|||
public RecentsAnimationDeviceState(Context context) {
|
||||
final ContentResolver resolver = context.getContentResolver();
|
||||
mContext = context;
|
||||
mUserManager = UserManagerCompat.getInstance(context);
|
||||
mSysUiNavMode = SysUINavigationMode.INSTANCE.get(context);
|
||||
mDefaultDisplay = DefaultDisplay.INSTANCE.get(context);
|
||||
mDisplayId = mDefaultDisplay.getInfo().id;
|
||||
runOnDestroy(() -> mDefaultDisplay.removeChangeListener(this));
|
||||
|
||||
// Register for user unlocked if necessary
|
||||
mIsUserUnlocked = mUserManager.isUserUnlocked(Process.myUserHandle());
|
||||
mIsUserUnlocked = context.getSystemService(UserManager.class)
|
||||
.isUserUnlocked(Process.myUserHandle());
|
||||
if (!mIsUserUnlocked) {
|
||||
mContext.registerReceiver(mUserUnlockedReceiver,
|
||||
new IntentFilter(ACTION_USER_UNLOCKED));
|
||||
|
|
|
@ -23,7 +23,7 @@ import android.content.pm.PackageManager;
|
|||
import android.os.UserHandle;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.launcher3.compat.UserManagerCompat;
|
||||
import com.android.launcher3.pm.UserCache;
|
||||
import com.android.launcher3.util.ComponentKey;
|
||||
import com.android.launcher3.util.PackageManagerHelper;
|
||||
import com.android.systemui.shared.recents.model.Task;
|
||||
|
@ -78,7 +78,7 @@ public final class TaskUtils {
|
|||
if (currentUserId == UserHandle.myUserId()) {
|
||||
return true;
|
||||
}
|
||||
List<UserHandle> allUsers = UserManagerCompat.getInstance(context).getUserProfiles();
|
||||
List<UserHandle> allUsers = UserCache.INSTANCE.get(context).getUserProfiles();
|
||||
for (int i = allUsers.size() - 1; i >= 0; i--) {
|
||||
if (currentUserId == allUsers.get(i).getIdentifier()) {
|
||||
return true;
|
||||
|
|
|
@ -24,8 +24,8 @@ import android.content.pm.LauncherActivityInfo;
|
|||
import android.os.Build;
|
||||
import android.os.Process;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
|
||||
import com.android.launcher3.compat.UserManagerCompat;
|
||||
import com.android.launcher3.util.ComponentKey;
|
||||
import com.android.launcher3.util.PackageManagerHelper;
|
||||
|
||||
|
@ -65,7 +65,7 @@ public class AppInfo extends ItemInfoWithIcon {
|
|||
* Must not hold the Context.
|
||||
*/
|
||||
public AppInfo(Context context, LauncherActivityInfo info, UserHandle user) {
|
||||
this(info, user, UserManagerCompat.getInstance(context).isQuietModeEnabled(user));
|
||||
this(info, user, context.getSystemService(UserManager.class).isQuietModeEnabled(user));
|
||||
}
|
||||
|
||||
public AppInfo(LauncherActivityInfo info, UserHandle user, boolean quietModeEnabled) {
|
||||
|
|
|
@ -12,15 +12,15 @@ import android.content.Intent;
|
|||
import android.database.Cursor;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.WorkerThread;
|
||||
|
||||
import com.android.launcher3.LauncherSettings.Favorites;
|
||||
import com.android.launcher3.compat.UserManagerCompat;
|
||||
import com.android.launcher3.model.LoaderTask;
|
||||
import com.android.launcher3.model.WidgetsModel;
|
||||
import com.android.launcher3.pm.UserCache;
|
||||
import com.android.launcher3.provider.RestoreDbTask;
|
||||
import com.android.launcher3.util.ContentWriter;
|
||||
|
||||
import androidx.annotation.WorkerThread;
|
||||
|
||||
public class AppWidgetsRestoredReceiver extends BroadcastReceiver {
|
||||
|
||||
private static final String TAG = "AWRestoredReceiver";
|
||||
|
@ -82,7 +82,7 @@ public class AppWidgetsRestoredReceiver extends BroadcastReceiver {
|
|||
|
||||
// b/135926478: Work profile widget restore is broken in platform. This forces us to
|
||||
// recreate the widget during loading with the correct host provider.
|
||||
long mainProfileId = UserManagerCompat.getInstance(context)
|
||||
long mainProfileId = UserCache.INSTANCE.get(context)
|
||||
.getSerialNumberForUser(myUserHandle());
|
||||
String oldWidgetId = Integer.toString(oldWidgetIds[i]);
|
||||
int result = new ContentWriter(context, new ContentWriter.CommitParams(
|
||||
|
|
|
@ -44,11 +44,11 @@ import android.util.Pair;
|
|||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.WorkerThread;
|
||||
|
||||
import com.android.launcher3.compat.UserManagerCompat;
|
||||
import com.android.launcher3.config.FeatureFlags;
|
||||
import com.android.launcher3.icons.BitmapInfo;
|
||||
import com.android.launcher3.icons.GraphicsUtils;
|
||||
import com.android.launcher3.icons.LauncherIcons;
|
||||
import com.android.launcher3.pm.UserCache;
|
||||
import com.android.launcher3.shortcuts.DeepShortcutManager;
|
||||
import com.android.launcher3.shortcuts.ShortcutKey;
|
||||
import com.android.launcher3.util.PackageManagerHelper;
|
||||
|
@ -422,7 +422,7 @@ public class InstallShortcutReceiver extends BroadcastReceiver {
|
|||
.object()
|
||||
.key(LAUNCH_INTENT_KEY).value(launchIntent.toUri(0))
|
||||
.key(DEEPSHORTCUT_TYPE_KEY).value(true)
|
||||
.key(USER_HANDLE_KEY).value(UserManagerCompat.getInstance(mContext)
|
||||
.key(USER_HANDLE_KEY).value(UserCache.INSTANCE.get(mContext)
|
||||
.getSerialNumberForUser(user))
|
||||
.endObject().toString();
|
||||
} else if (providerInfo != null) {
|
||||
|
@ -432,7 +432,7 @@ public class InstallShortcutReceiver extends BroadcastReceiver {
|
|||
.object()
|
||||
.key(LAUNCH_INTENT_KEY).value(launchIntent.toUri(0))
|
||||
.key(APP_WIDGET_TYPE_KEY).value(true)
|
||||
.key(USER_HANDLE_KEY).value(UserManagerCompat.getInstance(mContext)
|
||||
.key(USER_HANDLE_KEY).value(UserCache.INSTANCE.get(mContext)
|
||||
.getSerialNumberForUser(user))
|
||||
.endObject().toString();
|
||||
}
|
||||
|
@ -460,7 +460,7 @@ public class InstallShortcutReceiver extends BroadcastReceiver {
|
|||
.key(LAUNCH_INTENT_KEY).value(launchIntent.toUri(0))
|
||||
.key(NAME_KEY).value(name)
|
||||
.key(USER_HANDLE_KEY).value(
|
||||
UserManagerCompat.getInstance(mContext).getSerialNumberForUser(user))
|
||||
UserCache.INSTANCE.get(mContext).getSerialNumberForUser(user))
|
||||
.key(APP_SHORTCUT_TYPE_KEY).value(isActivity);
|
||||
if (icon != null) {
|
||||
byte[] iconByteArray = GraphicsUtils.flattenBitmap(icon);
|
||||
|
@ -598,7 +598,7 @@ public class InstallShortcutReceiver extends BroadcastReceiver {
|
|||
private Decoder(String encoded, Context context) throws JSONException, URISyntaxException {
|
||||
super(encoded);
|
||||
launcherIntent = Intent.parseUri(getString(LAUNCH_INTENT_KEY), 0);
|
||||
user = has(USER_HANDLE_KEY) ? UserManagerCompat.getInstance(context)
|
||||
user = has(USER_HANDLE_KEY) ? UserCache.INSTANCE.get(context)
|
||||
.getUserForSerialNumber(getLong(USER_HANDLE_KEY))
|
||||
: Process.myUserHandle();
|
||||
if (user == null) {
|
||||
|
|
|
@ -95,7 +95,6 @@ import com.android.launcher3.allapps.AllAppsStore;
|
|||
import com.android.launcher3.allapps.AllAppsTransitionController;
|
||||
import com.android.launcher3.allapps.DiscoveryBounce;
|
||||
import com.android.launcher3.anim.PropertyListBuilder;
|
||||
import com.android.launcher3.compat.AppWidgetManagerCompat;
|
||||
import com.android.launcher3.config.FeatureFlags;
|
||||
import com.android.launcher3.dot.DotInfo;
|
||||
import com.android.launcher3.dragndrop.DragController;
|
||||
|
@ -157,6 +156,7 @@ import com.android.launcher3.widget.PendingAppWidgetHostView;
|
|||
import com.android.launcher3.widget.WidgetAddFlowHandler;
|
||||
import com.android.launcher3.widget.WidgetHostViewLoader;
|
||||
import com.android.launcher3.widget.WidgetListRowEntry;
|
||||
import com.android.launcher3.widget.WidgetManagerHelper;
|
||||
import com.android.launcher3.widget.WidgetsFullSheet;
|
||||
import com.android.launcher3.widget.custom.CustomWidgetManager;
|
||||
import com.android.systemui.plugins.OverlayPlugin;
|
||||
|
@ -250,7 +250,7 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns,
|
|||
DragLayer mDragLayer;
|
||||
private DragController mDragController;
|
||||
|
||||
private AppWidgetManagerCompat mAppWidgetManager;
|
||||
private WidgetManagerHelper mAppWidgetManager;
|
||||
private LauncherAppWidgetHost mAppWidgetHost;
|
||||
|
||||
private final int[] mTmpAddItemCellCoordinates = new int[2];
|
||||
|
@ -360,7 +360,7 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns,
|
|||
mAllAppsController = new AllAppsTransitionController(this);
|
||||
mStateManager = new LauncherStateManager(this);
|
||||
|
||||
mAppWidgetManager = AppWidgetManagerCompat.getInstance(this);
|
||||
mAppWidgetManager = new WidgetManagerHelper(this);
|
||||
mAppWidgetHost = new LauncherAppWidgetHost(this,
|
||||
appWidgetId -> getWorkspace().removeWidget(appWidgetId));
|
||||
mAppWidgetHost.startListening();
|
||||
|
|
|
@ -27,7 +27,6 @@ import android.content.pm.LauncherApps;
|
|||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.launcher3.compat.UserManagerCompat;
|
||||
import com.android.launcher3.config.FeatureFlags;
|
||||
import com.android.launcher3.icons.IconCache;
|
||||
import com.android.launcher3.icons.IconProvider;
|
||||
|
@ -35,6 +34,7 @@ import com.android.launcher3.icons.LauncherIcons;
|
|||
import com.android.launcher3.notification.NotificationListener;
|
||||
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;
|
||||
import com.android.launcher3.util.SafeCloseable;
|
||||
|
@ -60,6 +60,7 @@ public class LauncherAppState {
|
|||
private final InstallSessionTracker mInstallSessionTracker;
|
||||
private final SimpleBroadcastReceiver mModelChangeReceiver;
|
||||
private final SafeCloseable mCalendarChangeTracker;
|
||||
private final SafeCloseable mUserChangeListener;
|
||||
|
||||
public static LauncherAppState getInstance(final Context context) {
|
||||
return INSTANCE.get(context);
|
||||
|
@ -87,8 +88,6 @@ public class LauncherAppState {
|
|||
|
||||
mContext.getSystemService(LauncherApps.class).registerCallback(mModel);
|
||||
mModelChangeReceiver.register(mContext, Intent.ACTION_LOCALE_CHANGED,
|
||||
Intent.ACTION_MANAGED_PROFILE_ADDED,
|
||||
Intent.ACTION_MANAGED_PROFILE_REMOVED,
|
||||
Intent.ACTION_MANAGED_PROFILE_AVAILABLE,
|
||||
Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE,
|
||||
Intent.ACTION_MANAGED_PROFILE_UNLOCKED);
|
||||
|
@ -104,7 +103,9 @@ public class LauncherAppState {
|
|||
CustomWidgetManager.INSTANCE.get(mContext)
|
||||
.setWidgetRefreshCallback(mModel::refreshAndBindWidgetsAndShortcuts);
|
||||
|
||||
UserManagerCompat.getInstance(mContext).enableAndResetCache();
|
||||
mUserChangeListener = UserCache.INSTANCE.get(mContext)
|
||||
.addUserChangeListener(mModel::forceReload);
|
||||
|
||||
mInvariantDeviceProfile.addOnChangeListener(this::onIdpChanged);
|
||||
new Handler().post( () -> mInvariantDeviceProfile.verifyConfigChangedInBackground(context));
|
||||
|
||||
|
@ -151,6 +152,7 @@ public class LauncherAppState {
|
|||
mContext.getSystemService(LauncherApps.class).unregisterCallback(mModel);
|
||||
mInstallSessionTracker.unregister();
|
||||
mCalendarChangeTracker.close();
|
||||
mUserChangeListener.close();
|
||||
CustomWidgetManager.INSTANCE.get(mContext).setWidgetRefreshCallback(null);
|
||||
|
||||
if (mNotificationDotsObserver != null) {
|
||||
|
|
|
@ -34,7 +34,6 @@ import android.util.Pair;
|
|||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.WorkerThread;
|
||||
|
||||
import com.android.launcher3.compat.UserManagerCompat;
|
||||
import com.android.launcher3.config.FeatureFlags;
|
||||
import com.android.launcher3.icons.IconCache;
|
||||
import com.android.launcher3.icons.LauncherIcons;
|
||||
|
@ -54,6 +53,7 @@ import com.android.launcher3.model.ShortcutsChangedTask;
|
|||
import com.android.launcher3.model.UserLockStateChangedTask;
|
||||
import com.android.launcher3.pm.InstallSessionTracker;
|
||||
import com.android.launcher3.pm.PackageInstallInfo;
|
||||
import com.android.launcher3.pm.UserCache;
|
||||
import com.android.launcher3.shortcuts.DeepShortcutManager;
|
||||
import com.android.launcher3.util.IntSparseArrayMap;
|
||||
import com.android.launcher3.util.ItemInfoMatcher;
|
||||
|
@ -234,10 +234,6 @@ public class LauncherModel extends LauncherApps.Callback implements InstallSessi
|
|||
if (Intent.ACTION_LOCALE_CHANGED.equals(action)) {
|
||||
// If we have changed locale we need to clear out the labels in all apps/workspace.
|
||||
forceReload();
|
||||
} else if (Intent.ACTION_MANAGED_PROFILE_ADDED.equals(action)
|
||||
|| Intent.ACTION_MANAGED_PROFILE_REMOVED.equals(action)) {
|
||||
UserManagerCompat.getInstance(mApp.getContext()).enableAndResetCache();
|
||||
forceReload();
|
||||
} else if (Intent.ACTION_MANAGED_PROFILE_AVAILABLE.equals(action) ||
|
||||
Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE.equals(action) ||
|
||||
Intent.ACTION_MANAGED_PROFILE_UNLOCKED.equals(action)) {
|
||||
|
@ -462,7 +458,7 @@ public class LauncherModel extends LauncherApps.Callback implements InstallSessi
|
|||
/**
|
||||
* Refreshes the cached shortcuts if the shortcut permission has changed.
|
||||
* Current implementation simply reloads the workspace, but it can be optimized to
|
||||
* use partial updates similar to {@link UserManagerCompat}
|
||||
* use partial updates similar to {@link UserCache}
|
||||
*/
|
||||
public void refreshShortcutsIfRequired() {
|
||||
MODEL_EXECUTOR.getHandler().removeCallbacks(mShortcutPermissionCheckRunnable);
|
||||
|
|
|
@ -47,6 +47,7 @@ import android.os.Build;
|
|||
import android.os.Bundle;
|
||||
import android.os.Process;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.provider.BaseColumns;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
|
@ -55,10 +56,10 @@ import android.util.Xml;
|
|||
|
||||
import com.android.launcher3.AutoInstallsLayout.LayoutParserCallback;
|
||||
import com.android.launcher3.LauncherSettings.Favorites;
|
||||
import com.android.launcher3.compat.UserManagerCompat;
|
||||
import com.android.launcher3.config.FeatureFlags;
|
||||
import com.android.launcher3.logging.FileLog;
|
||||
import com.android.launcher3.model.DbDowngradeHelper;
|
||||
import com.android.launcher3.pm.UserCache;
|
||||
import com.android.launcher3.provider.LauncherDbUtils;
|
||||
import com.android.launcher3.provider.LauncherDbUtils.SQLiteTransaction;
|
||||
import com.android.launcher3.provider.RestoreDbTask;
|
||||
|
@ -526,8 +527,8 @@ public class LauncherProvider extends ContentProvider {
|
|||
InvariantDeviceProfile idp = LauncherAppState.getIDP(getContext());
|
||||
int defaultLayout = idp.defaultLayoutId;
|
||||
|
||||
UserManagerCompat um = UserManagerCompat.getInstance(getContext());
|
||||
if (um.isDemoUser() && idp.demoModeLayoutId != 0) {
|
||||
if (getContext().getSystemService(UserManager.class).isDemoUser()
|
||||
&& idp.demoModeLayoutId != 0) {
|
||||
defaultLayout = idp.demoModeLayoutId;
|
||||
}
|
||||
|
||||
|
@ -608,7 +609,7 @@ public class LauncherProvider extends ContentProvider {
|
|||
}
|
||||
|
||||
public long getSerialNumberForUser(UserHandle user) {
|
||||
return UserManagerCompat.getInstance(mContext).getSerialNumberForUser(user);
|
||||
return UserCache.INSTANCE.get(mContext).getSerialNumberForUser(user);
|
||||
}
|
||||
|
||||
public long getDefaultUserSerial() {
|
||||
|
@ -639,7 +640,7 @@ public class LauncherProvider extends ContentProvider {
|
|||
*/
|
||||
protected void handleOneTimeDataUpgrade(SQLiteDatabase db) {
|
||||
// Remove "profile extra"
|
||||
UserManagerCompat um = UserManagerCompat.getInstance(mContext);
|
||||
UserCache um = UserCache.INSTANCE.get(mContext);
|
||||
for (UserHandle user : um.getUserProfiles()) {
|
||||
long serial = um.getSerialNumberForUser(user);
|
||||
String sql = "update favorites set intent = replace(intent, "
|
||||
|
|
|
@ -37,14 +37,13 @@ import android.util.Pair;
|
|||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.UiThread;
|
||||
|
||||
import com.android.launcher3.compat.AppWidgetManagerCompat;
|
||||
import com.android.launcher3.compat.UserManagerCompat;
|
||||
import com.android.launcher3.icons.GraphicsUtils;
|
||||
import com.android.launcher3.icons.IconCache;
|
||||
import com.android.launcher3.icons.LauncherIcons;
|
||||
import com.android.launcher3.icons.ShadowGenerator;
|
||||
import com.android.launcher3.model.WidgetItem;
|
||||
import com.android.launcher3.pm.ShortcutConfigActivityInfo;
|
||||
import com.android.launcher3.pm.UserCache;
|
||||
import com.android.launcher3.util.ComponentKey;
|
||||
import com.android.launcher3.util.Executors;
|
||||
import com.android.launcher3.util.PackageUserKey;
|
||||
|
@ -52,6 +51,7 @@ import com.android.launcher3.util.Preconditions;
|
|||
import com.android.launcher3.util.SQLiteCacheHelper;
|
||||
import com.android.launcher3.util.Thunk;
|
||||
import com.android.launcher3.widget.WidgetCell;
|
||||
import com.android.launcher3.widget.WidgetManagerHelper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
@ -78,7 +78,7 @@ public class WidgetPreviewLoader {
|
|||
|
||||
private final Context mContext;
|
||||
private final IconCache mIconCache;
|
||||
private final UserManagerCompat mUserManager;
|
||||
private final UserCache mUserCache;
|
||||
private final CacheDb mDb;
|
||||
|
||||
private final UserHandle mMyUser = Process.myUserHandle();
|
||||
|
@ -87,7 +87,7 @@ public class WidgetPreviewLoader {
|
|||
public WidgetPreviewLoader(Context context, IconCache iconCache) {
|
||||
mContext = context;
|
||||
mIconCache = iconCache;
|
||||
mUserManager = UserManagerCompat.getInstance(context);
|
||||
mUserCache = UserCache.INSTANCE.get(context);
|
||||
mDb = new CacheDb(context);
|
||||
}
|
||||
|
||||
|
@ -197,7 +197,7 @@ public class WidgetPreviewLoader {
|
|||
@Thunk void writeToDb(WidgetCacheKey key, long[] versions, Bitmap preview) {
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(CacheDb.COLUMN_COMPONENT, key.componentName.flattenToShortString());
|
||||
values.put(CacheDb.COLUMN_USER, mUserManager.getSerialNumberForUser(key.user));
|
||||
values.put(CacheDb.COLUMN_USER, mUserCache.getSerialNumberForUser(key.user));
|
||||
values.put(CacheDb.COLUMN_SIZE, key.size);
|
||||
values.put(CacheDb.COLUMN_PACKAGE, key.componentName.getPackageName());
|
||||
values.put(CacheDb.COLUMN_VERSION, versions[0]);
|
||||
|
@ -207,7 +207,7 @@ public class WidgetPreviewLoader {
|
|||
}
|
||||
|
||||
public void removePackage(String packageName, UserHandle user) {
|
||||
removePackage(packageName, user, mUserManager.getSerialNumberForUser(user));
|
||||
removePackage(packageName, user, mUserCache.getSerialNumberForUser(user));
|
||||
}
|
||||
|
||||
private void removePackage(String packageName, UserHandle user, long userSerial) {
|
||||
|
@ -236,7 +236,7 @@ public class WidgetPreviewLoader {
|
|||
LongSparseArray<HashSet<String>> validPackages = new LongSparseArray<>();
|
||||
|
||||
for (ComponentKey key : list) {
|
||||
final long userId = mUserManager.getSerialNumberForUser(key.user);
|
||||
final long userId = mUserCache.getSerialNumberForUser(key.user);
|
||||
HashSet<String> packages = validPackages.get(userId);
|
||||
if (packages == null) {
|
||||
packages = new HashSet<>();
|
||||
|
@ -247,7 +247,7 @@ public class WidgetPreviewLoader {
|
|||
|
||||
LongSparseArray<HashSet<String>> packagesToDelete = new LongSparseArray<>();
|
||||
long passedUserId = packageUser == null ? 0
|
||||
: mUserManager.getSerialNumberForUser(packageUser.mUser);
|
||||
: mUserCache.getSerialNumberForUser(packageUser.mUser);
|
||||
Cursor c = null;
|
||||
try {
|
||||
c = mDb.query(
|
||||
|
@ -286,7 +286,7 @@ public class WidgetPreviewLoader {
|
|||
|
||||
for (int i = 0; i < packagesToDelete.size(); i++) {
|
||||
long userId = packagesToDelete.keyAt(i);
|
||||
UserHandle user = mUserManager.getUserForSerialNumber(userId);
|
||||
UserHandle user = mUserCache.getUserForSerialNumber(userId);
|
||||
for (String pkg : packagesToDelete.valueAt(i)) {
|
||||
removePackage(pkg, user, userId);
|
||||
}
|
||||
|
@ -312,7 +312,7 @@ public class WidgetPreviewLoader {
|
|||
+ CacheDb.COLUMN_SIZE + " = ?",
|
||||
new String[]{
|
||||
key.componentName.flattenToShortString(),
|
||||
Long.toString(mUserManager.getSerialNumberForUser(key.user)),
|
||||
Long.toString(mUserCache.getSerialNumberForUser(key.user)),
|
||||
key.size
|
||||
});
|
||||
// If cancelled, skip getting the blob and decoding it into a bitmap
|
||||
|
@ -364,7 +364,7 @@ public class WidgetPreviewLoader {
|
|||
}
|
||||
|
||||
/**
|
||||
* Generates the widget preview from either the {@link AppWidgetManagerCompat} or cache
|
||||
* Generates the widget preview from either the {@link WidgetManagerHelper} or cache
|
||||
* and add badge at the bottom right corner.
|
||||
*
|
||||
* @param launcher
|
||||
|
|
|
@ -66,7 +66,6 @@ import com.android.launcher3.accessibility.AccessibleDragListenerAdapter;
|
|||
import com.android.launcher3.accessibility.WorkspaceAccessibilityHelper;
|
||||
import com.android.launcher3.anim.AnimatorSetBuilder;
|
||||
import com.android.launcher3.anim.Interpolators;
|
||||
import com.android.launcher3.compat.AppWidgetManagerCompat;
|
||||
import com.android.launcher3.config.FeatureFlags;
|
||||
import com.android.launcher3.dot.FolderDotInfo;
|
||||
import com.android.launcher3.dragndrop.DragController;
|
||||
|
@ -100,6 +99,7 @@ import com.android.launcher3.widget.LauncherAppWidgetHostView;
|
|||
import com.android.launcher3.widget.PendingAddShortcutInfo;
|
||||
import com.android.launcher3.widget.PendingAddWidgetInfo;
|
||||
import com.android.launcher3.widget.PendingAppWidgetHostView;
|
||||
import com.android.launcher3.widget.WidgetManagerHelper;
|
||||
import com.android.systemui.plugins.shared.LauncherOverlayManager.LauncherOverlay;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -3233,12 +3233,11 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
|
|||
|
||||
LauncherAppWidgetInfo item = changedInfo.get(0);
|
||||
final AppWidgetProviderInfo widgetInfo;
|
||||
WidgetManagerHelper widgetHelper = new WidgetManagerHelper(getContext());
|
||||
if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_NOT_VALID)) {
|
||||
widgetInfo = AppWidgetManagerCompat
|
||||
.getInstance(mLauncher).findProvider(item.providerName, item.user);
|
||||
widgetInfo = widgetHelper.findProvider(item.providerName, item.user);
|
||||
} else {
|
||||
widgetInfo = AppWidgetManagerCompat.getInstance(mLauncher)
|
||||
.getLauncherAppWidgetInfo(item.appWidgetId);
|
||||
widgetInfo = widgetHelper.getLauncherAppWidgetInfo(item.appWidgetId);
|
||||
}
|
||||
|
||||
if (widgetInfo != null) {
|
||||
|
|
|
@ -26,25 +26,25 @@ import android.view.ViewGroup;
|
|||
import android.view.accessibility.AccessibilityEvent;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.launcher3.AppInfo;
|
||||
import com.android.launcher3.BubbleTextView;
|
||||
import com.android.launcher3.Launcher;
|
||||
import com.android.launcher3.R;
|
||||
import com.android.launcher3.allapps.AlphabeticalAppsList.AdapterItem;
|
||||
import com.android.launcher3.compat.UserManagerCompat;
|
||||
import com.android.launcher3.model.AppLaunchTracker;
|
||||
import com.android.launcher3.touch.ItemClickHandler;
|
||||
import com.android.launcher3.touch.ItemLongClickListener;
|
||||
import com.android.launcher3.util.PackageManagerHelper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import androidx.core.view.accessibility.AccessibilityEventCompat;
|
||||
import androidx.core.view.accessibility.AccessibilityNodeInfoCompat;
|
||||
import androidx.core.view.accessibility.AccessibilityRecordCompat;
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.android.launcher3.AppInfo;
|
||||
import com.android.launcher3.BubbleTextView;
|
||||
import com.android.launcher3.Launcher;
|
||||
import com.android.launcher3.R;
|
||||
import com.android.launcher3.allapps.AlphabeticalAppsList.AdapterItem;
|
||||
import com.android.launcher3.model.AppLaunchTracker;
|
||||
import com.android.launcher3.pm.UserCache;
|
||||
import com.android.launcher3.touch.ItemClickHandler;
|
||||
import com.android.launcher3.touch.ItemLongClickListener;
|
||||
import com.android.launcher3.util.PackageManagerHelper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The grid view adapter of all the apps.
|
||||
*/
|
||||
|
@ -312,7 +312,7 @@ public class AllAppsGridAdapter extends RecyclerView.Adapter<AllAppsGridAdapter.
|
|||
WorkModeSwitch workModeToggle = holder.itemView.findViewById(R.id.work_mode_toggle);
|
||||
workModeToggle.refresh();
|
||||
TextView managedByLabel = holder.itemView.findViewById(R.id.managed_by_label);
|
||||
boolean anyProfileQuietModeEnabled = UserManagerCompat.getInstance(
|
||||
boolean anyProfileQuietModeEnabled = UserCache.INSTANCE.get(
|
||||
managedByLabel.getContext()).isAnyProfileQuietModeEnabled();
|
||||
managedByLabel.setText(anyProfileQuietModeEnabled
|
||||
? R.string.work_mode_off_label : R.string.work_mode_on_label);
|
||||
|
|
|
@ -20,7 +20,7 @@ import android.os.Process;
|
|||
import android.os.UserHandle;
|
||||
|
||||
import com.android.launcher3.AppInfo;
|
||||
import com.android.launcher3.compat.UserManagerCompat;
|
||||
import com.android.launcher3.pm.UserCache;
|
||||
import com.android.launcher3.util.LabelComparator;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
@ -30,12 +30,12 @@ import java.util.Comparator;
|
|||
*/
|
||||
public class AppInfoComparator implements Comparator<AppInfo> {
|
||||
|
||||
private final UserManagerCompat mUserManager;
|
||||
private final UserCache mUserManager;
|
||||
private final UserHandle mMyUser;
|
||||
private final LabelComparator mLabelComparator;
|
||||
|
||||
public AppInfoComparator(Context context) {
|
||||
mUserManager = UserManagerCompat.getInstance(context);
|
||||
mUserManager = UserCache.INSTANCE.get(context);
|
||||
mMyUser = Process.myUserHandle();
|
||||
mLabelComparator = new LabelComparator();
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ import android.animation.AnimatorInflater;
|
|||
import android.animation.AnimatorListenerAdapter;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Handler;
|
||||
import android.os.UserManager;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
import com.android.launcher3.AbstractFloatingView;
|
||||
|
@ -34,7 +35,7 @@ import com.android.launcher3.LauncherState;
|
|||
import com.android.launcher3.LauncherStateManager.StateListener;
|
||||
import com.android.launcher3.R;
|
||||
import com.android.launcher3.Utilities;
|
||||
import com.android.launcher3.compat.UserManagerCompat;
|
||||
import com.android.launcher3.pm.UserCache;
|
||||
|
||||
/**
|
||||
* Abstract base class of floating view responsible for showing discovery bounce animation
|
||||
|
@ -146,7 +147,7 @@ public class DiscoveryBounce extends AbstractFloatingView {
|
|||
|| (launcher.getSharedPrefs().getBoolean(HOME_BOUNCE_SEEN, false)
|
||||
&& !shouldShowForWorkProfile(launcher))
|
||||
|| AbstractFloatingView.getTopOpenView(launcher) != null
|
||||
|| UserManagerCompat.getInstance(launcher).isDemoUser()
|
||||
|| launcher.getSystemService(UserManager.class).isDemoUser()
|
||||
|| Utilities.IS_RUNNING_IN_TEST_HARNESS) {
|
||||
return;
|
||||
}
|
||||
|
@ -171,7 +172,7 @@ public class DiscoveryBounce extends AbstractFloatingView {
|
|||
|| launcher.getDeviceProfile().isVerticalBarLayout()
|
||||
|| (launcher.getSharedPrefs().getBoolean(SHELF_BOUNCE_SEEN, false)
|
||||
&& !shouldShowForWorkProfile(launcher))
|
||||
|| UserManagerCompat.getInstance(launcher).isDemoUser()
|
||||
|| launcher.getSystemService(UserManager.class).isDemoUser()
|
||||
|| Utilities.IS_RUNNING_IN_TEST_HARNESS) {
|
||||
return;
|
||||
}
|
||||
|
@ -215,7 +216,7 @@ public class DiscoveryBounce extends AbstractFloatingView {
|
|||
private static boolean shouldShowForWorkProfile(Launcher launcher) {
|
||||
return !launcher.getSharedPrefs().getBoolean(
|
||||
PersonalWorkSlidingTabStrip.KEY_SHOWED_PEEK_WORK_TAB, false)
|
||||
&& UserManagerCompat.getInstance(launcher).hasWorkProfile();
|
||||
&& UserCache.INSTANCE.get(launcher).hasWorkProfile();
|
||||
}
|
||||
|
||||
private static void incrementShelfBounceCount(Launcher launcher) {
|
||||
|
|
|
@ -19,14 +19,15 @@ import android.content.Context;
|
|||
import android.os.AsyncTask;
|
||||
import android.os.Process;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.MotionEvent;
|
||||
import android.widget.Switch;
|
||||
|
||||
import com.android.launcher3.compat.UserManagerCompat;
|
||||
import com.android.launcher3.Utilities;
|
||||
import com.android.launcher3.pm.UserCache;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.List;
|
||||
|
||||
public class WorkModeSwitch extends Switch {
|
||||
|
||||
|
@ -57,7 +58,7 @@ public class WorkModeSwitch extends Switch {
|
|||
}
|
||||
|
||||
public void refresh() {
|
||||
UserManagerCompat userManager = UserManagerCompat.getInstance(getContext());
|
||||
UserCache userManager = UserCache.INSTANCE.get(getContext());
|
||||
setCheckedInternal(!userManager.isAnyProfileQuietModeEnabled());
|
||||
setEnabled(true);
|
||||
}
|
||||
|
@ -95,14 +96,14 @@ public class WorkModeSwitch extends Switch {
|
|||
@Override
|
||||
protected Boolean doInBackground(Void... voids) {
|
||||
WorkModeSwitch workModeSwitch = switchWeakReference.get();
|
||||
if (workModeSwitch == null) {
|
||||
if (workModeSwitch == null || !Utilities.ATLEAST_P) {
|
||||
return false;
|
||||
}
|
||||
UserManagerCompat userManager =
|
||||
UserManagerCompat.getInstance(workModeSwitch.getContext());
|
||||
List<UserHandle> userProfiles = userManager.getUserProfiles();
|
||||
|
||||
Context context = workModeSwitch.getContext();
|
||||
UserManager userManager = context.getSystemService(UserManager.class);
|
||||
boolean showConfirm = false;
|
||||
for (UserHandle userProfile : userProfiles) {
|
||||
for (UserHandle userProfile : UserCache.INSTANCE.get(context).getUserProfiles()) {
|
||||
if (Process.myUserHandle().equals(userProfile)) {
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -1,82 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2014 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.launcher3.compat;
|
||||
|
||||
import android.appwidget.AppWidgetManager;
|
||||
import android.appwidget.AppWidgetProviderInfo;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserHandle;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.android.launcher3.LauncherAppWidgetInfo;
|
||||
import com.android.launcher3.LauncherAppWidgetProviderInfo;
|
||||
import com.android.launcher3.Utilities;
|
||||
import com.android.launcher3.util.ComponentKey;
|
||||
import com.android.launcher3.util.PackageUserKey;
|
||||
import com.android.launcher3.widget.custom.CustomWidgetManager;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class AppWidgetManagerCompat {
|
||||
|
||||
private static final Object sInstanceLock = new Object();
|
||||
private static AppWidgetManagerCompat sInstance;
|
||||
|
||||
public static AppWidgetManagerCompat getInstance(Context context) {
|
||||
synchronized (sInstanceLock) {
|
||||
if (sInstance == null) {
|
||||
if (Utilities.ATLEAST_OREO) {
|
||||
sInstance = new AppWidgetManagerCompatVO(context.getApplicationContext());
|
||||
} else {
|
||||
sInstance = new AppWidgetManagerCompatVL(context.getApplicationContext());
|
||||
}
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
}
|
||||
|
||||
final AppWidgetManager mAppWidgetManager;
|
||||
final Context mContext;
|
||||
|
||||
AppWidgetManagerCompat(Context context) {
|
||||
mContext = context;
|
||||
mAppWidgetManager = AppWidgetManager.getInstance(context);
|
||||
}
|
||||
|
||||
public LauncherAppWidgetProviderInfo getLauncherAppWidgetInfo(int appWidgetId) {
|
||||
if (appWidgetId <= LauncherAppWidgetInfo.CUSTOM_WIDGET_ID) {
|
||||
return CustomWidgetManager.INSTANCE.get(mContext).getWidgetProvider(appWidgetId);
|
||||
}
|
||||
AppWidgetProviderInfo info = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
|
||||
return info == null ? null : LauncherAppWidgetProviderInfo.fromProviderInfo(mContext, info);
|
||||
}
|
||||
|
||||
public abstract List<AppWidgetProviderInfo> getAllProviders(
|
||||
@Nullable PackageUserKey packageUser);
|
||||
|
||||
public abstract boolean bindAppWidgetIdIfAllowed(
|
||||
int appWidgetId, AppWidgetProviderInfo info, Bundle options);
|
||||
|
||||
public abstract LauncherAppWidgetProviderInfo findProvider(
|
||||
ComponentName provider, UserHandle user);
|
||||
|
||||
public abstract HashMap<ComponentKey, AppWidgetProviderInfo> getAllProvidersMap();
|
||||
}
|
|
@ -1,138 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2014 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.launcher3.compat;
|
||||
|
||||
import android.appwidget.AppWidgetProviderInfo;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.os.Process;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.android.launcher3.LauncherAppWidgetInfo;
|
||||
import com.android.launcher3.LauncherAppWidgetProviderInfo;
|
||||
import com.android.launcher3.model.WidgetsModel;
|
||||
import com.android.launcher3.util.ComponentKey;
|
||||
import com.android.launcher3.util.PackageUserKey;
|
||||
import com.android.launcher3.widget.custom.CustomAppWidgetProviderInfo;
|
||||
import com.android.launcher3.widget.custom.CustomWidgetManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
class AppWidgetManagerCompatVL extends AppWidgetManagerCompat {
|
||||
|
||||
private final UserManager mUserManager;
|
||||
|
||||
AppWidgetManagerCompatVL(Context context) {
|
||||
super(context);
|
||||
mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AppWidgetProviderInfo> getAllProviders(@Nullable PackageUserKey packageUser) {
|
||||
if (WidgetsModel.GO_DISABLE_WIDGETS) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
if (packageUser == null) {
|
||||
ArrayList<AppWidgetProviderInfo> providers = new ArrayList<>();
|
||||
for (UserHandle user : mUserManager.getUserProfiles()) {
|
||||
providers.addAll(mAppWidgetManager.getInstalledProvidersForProfile(user));
|
||||
}
|
||||
providers.addAll(getCustomWidgets());
|
||||
return providers;
|
||||
}
|
||||
// Only get providers for the given package/user.
|
||||
List<AppWidgetProviderInfo> providers = new ArrayList<>(mAppWidgetManager
|
||||
.getInstalledProvidersForProfile(packageUser.mUser));
|
||||
Iterator<AppWidgetProviderInfo> iterator = providers.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
if (!iterator.next().provider.getPackageName().equals(packageUser.mPackageName)) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
|
||||
if (Process.myUserHandle().equals(packageUser.mUser)
|
||||
&& mContext.getPackageName().equals(packageUser.mPackageName)) {
|
||||
providers.addAll(getCustomWidgets());
|
||||
}
|
||||
return providers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean bindAppWidgetIdIfAllowed(int appWidgetId, AppWidgetProviderInfo info,
|
||||
Bundle options) {
|
||||
if (WidgetsModel.GO_DISABLE_WIDGETS) {
|
||||
return false;
|
||||
}
|
||||
if (appWidgetId <= LauncherAppWidgetInfo.CUSTOM_WIDGET_ID) {
|
||||
return true;
|
||||
}
|
||||
return mAppWidgetManager.bindAppWidgetIdIfAllowed(
|
||||
appWidgetId, info.getProfile(), info.provider, options);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LauncherAppWidgetProviderInfo findProvider(ComponentName provider, UserHandle user) {
|
||||
if (WidgetsModel.GO_DISABLE_WIDGETS) {
|
||||
return null;
|
||||
}
|
||||
for (AppWidgetProviderInfo info :
|
||||
getAllProviders(new PackageUserKey(provider.getPackageName(), user))) {
|
||||
if (info.provider.equals(provider)) {
|
||||
return LauncherAppWidgetProviderInfo.fromProviderInfo(mContext, info);
|
||||
}
|
||||
}
|
||||
|
||||
if (Process.myUserHandle().equals(user)) {
|
||||
for (LauncherAppWidgetProviderInfo info : getCustomWidgets()) {
|
||||
if (info.provider.equals(provider)) {
|
||||
return info;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<ComponentKey, AppWidgetProviderInfo> getAllProvidersMap() {
|
||||
HashMap<ComponentKey, AppWidgetProviderInfo> result = new HashMap<>();
|
||||
if (WidgetsModel.GO_DISABLE_WIDGETS) {
|
||||
return result;
|
||||
}
|
||||
for (UserHandle user : mUserManager.getUserProfiles()) {
|
||||
for (AppWidgetProviderInfo info :
|
||||
mAppWidgetManager.getInstalledProvidersForProfile(user)) {
|
||||
result.put(new ComponentKey(info.provider, user), info);
|
||||
}
|
||||
}
|
||||
for (LauncherAppWidgetProviderInfo info : getCustomWidgets()) {
|
||||
result.put(new ComponentKey(info.provider, info.getProfile()), info);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
List<CustomAppWidgetProviderInfo> getCustomWidgets() {
|
||||
return CustomWidgetManager.INSTANCE.get(mContext).getCustomWidgets();
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.launcher3.compat;
|
||||
|
||||
import android.appwidget.AppWidgetProviderInfo;
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.android.launcher3.model.WidgetsModel;
|
||||
import com.android.launcher3.util.PackageUserKey;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
class AppWidgetManagerCompatVO extends AppWidgetManagerCompatVL {
|
||||
|
||||
AppWidgetManagerCompatVO(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AppWidgetProviderInfo> getAllProviders(@Nullable PackageUserKey packageUser) {
|
||||
if (WidgetsModel.GO_DISABLE_WIDGETS) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
if (packageUser == null) {
|
||||
return super.getAllProviders(null);
|
||||
}
|
||||
return mAppWidgetManager.getInstalledProvidersForPackage(packageUser.mPackageName,
|
||||
packageUser.mUser);
|
||||
}
|
||||
}
|
|
@ -1,62 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2014 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.launcher3.compat;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.UserHandle;
|
||||
|
||||
import com.android.launcher3.Utilities;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class UserManagerCompat {
|
||||
protected UserManagerCompat() {
|
||||
}
|
||||
|
||||
private static final Object sInstanceLock = new Object();
|
||||
private static UserManagerCompat sInstance;
|
||||
|
||||
public static UserManagerCompat getInstance(Context context) {
|
||||
synchronized (sInstanceLock) {
|
||||
if (sInstance == null) {
|
||||
if (Utilities.ATLEAST_P) {
|
||||
sInstance = new UserManagerCompatVP(context.getApplicationContext());
|
||||
} else {
|
||||
sInstance = new UserManagerCompatVNMr1(context.getApplicationContext());
|
||||
}
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a cache for users.
|
||||
*/
|
||||
public abstract void enableAndResetCache();
|
||||
|
||||
public abstract List<UserHandle> getUserProfiles();
|
||||
public abstract long getSerialNumberForUser(UserHandle user);
|
||||
public abstract UserHandle getUserForSerialNumber(long serialNumber);
|
||||
public abstract boolean isQuietModeEnabled(UserHandle user);
|
||||
public abstract boolean isUserUnlocked(UserHandle user);
|
||||
|
||||
public abstract boolean isDemoUser();
|
||||
public abstract boolean requestQuietModeEnabled(boolean enableQuietMode, UserHandle user);
|
||||
public abstract boolean isAnyProfileQuietModeEnabled();
|
||||
|
||||
public abstract boolean hasWorkProfile();
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2018 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.android.launcher3.compat;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.os.UserHandle;
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.P)
|
||||
public class UserManagerCompatVP extends UserManagerCompatVNMr1 {
|
||||
|
||||
UserManagerCompatVP(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean requestQuietModeEnabled(boolean enableQuietMode, UserHandle user) {
|
||||
return mUserManager.requestQuietModeEnabled(enableQuietMode, user);
|
||||
}
|
||||
}
|
|
@ -50,7 +50,6 @@ import com.android.launcher3.LauncherAppState;
|
|||
import com.android.launcher3.LauncherAppWidgetHost;
|
||||
import com.android.launcher3.LauncherAppWidgetProviderInfo;
|
||||
import com.android.launcher3.R;
|
||||
import com.android.launcher3.compat.AppWidgetManagerCompat;
|
||||
import com.android.launcher3.model.WidgetItem;
|
||||
import com.android.launcher3.pm.PinRequestHelper;
|
||||
import com.android.launcher3.userevent.nano.LauncherLogProto.Action;
|
||||
|
@ -61,6 +60,7 @@ import com.android.launcher3.widget.PendingAddShortcutInfo;
|
|||
import com.android.launcher3.widget.PendingAddWidgetInfo;
|
||||
import com.android.launcher3.widget.WidgetHostViewLoader;
|
||||
import com.android.launcher3.widget.WidgetImageView;
|
||||
import com.android.launcher3.widget.WidgetManagerHelper;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
|
@ -82,7 +82,7 @@ public class AddItemActivity extends BaseActivity implements OnLongClickListener
|
|||
|
||||
// Widget request specific options.
|
||||
private LauncherAppWidgetHost mAppWidgetHost;
|
||||
private AppWidgetManagerCompat mAppWidgetManager;
|
||||
private WidgetManagerHelper mAppWidgetManager;
|
||||
private int mPendingBindWidgetId;
|
||||
private Bundle mWidgetOptions;
|
||||
|
||||
|
@ -209,7 +209,7 @@ public class AddItemActivity extends BaseActivity implements OnLongClickListener
|
|||
}
|
||||
mWidgetCell.setPreview(PinItemDragListener.getPreview(mRequest));
|
||||
|
||||
mAppWidgetManager = AppWidgetManagerCompat.getInstance(this);
|
||||
mAppWidgetManager = new WidgetManagerHelper(this);
|
||||
mAppWidgetHost = new LauncherAppWidgetHost(this);
|
||||
|
||||
PendingAddWidgetInfo pendingInfo = new PendingAddWidgetInfo(widgetInfo);
|
||||
|
|
|
@ -43,13 +43,13 @@ import com.android.launcher3.ItemInfoWithIcon;
|
|||
import com.android.launcher3.LauncherFiles;
|
||||
import com.android.launcher3.Utilities;
|
||||
import com.android.launcher3.WorkspaceItemInfo;
|
||||
import com.android.launcher3.compat.UserManagerCompat;
|
||||
import com.android.launcher3.config.FeatureFlags;
|
||||
import com.android.launcher3.icons.ComponentWithLabel.ComponentCachingLogic;
|
||||
import com.android.launcher3.icons.cache.BaseIconCache;
|
||||
import com.android.launcher3.icons.cache.CachingLogic;
|
||||
import com.android.launcher3.icons.cache.HandlerRunnable;
|
||||
import com.android.launcher3.model.PackageItemInfo;
|
||||
import com.android.launcher3.pm.UserCache;
|
||||
import com.android.launcher3.shortcuts.ShortcutKey;
|
||||
import com.android.launcher3.util.ComponentKey;
|
||||
import com.android.launcher3.util.InstantAppResolver;
|
||||
|
@ -70,7 +70,7 @@ public class IconCache extends BaseIconCache {
|
|||
private final CachingLogic<ShortcutInfo> mShortcutCachingLogic;
|
||||
|
||||
private final LauncherApps mLauncherApps;
|
||||
private final UserManagerCompat mUserManager;
|
||||
private final UserCache mUserManager;
|
||||
private final InstantAppResolver mInstantAppResolver;
|
||||
private final IconProvider mIconProvider;
|
||||
|
||||
|
@ -83,7 +83,7 @@ public class IconCache extends BaseIconCache {
|
|||
mLauncherActivityInfoCachingLogic = LauncherActivityCachingLogic.newInstance(context);
|
||||
mShortcutCachingLogic = new ShortcutCachingLogic();
|
||||
mLauncherApps = mContext.getSystemService(LauncherApps.class);
|
||||
mUserManager = UserManagerCompat.getInstance(mContext);
|
||||
mUserManager = UserCache.INSTANCE.get(mContext);
|
||||
mInstantAppResolver = InstantAppResolver.newInstance(mContext);
|
||||
mIconProvider = new IconProvider(context);
|
||||
}
|
||||
|
|
|
@ -34,8 +34,8 @@ import android.text.TextUtils;
|
|||
import android.util.Log;
|
||||
|
||||
import com.android.launcher3.R;
|
||||
import com.android.launcher3.compat.UserManagerCompat;
|
||||
import com.android.launcher3.icons.BitmapInfo.Extender;
|
||||
import com.android.launcher3.pm.UserCache;
|
||||
import com.android.launcher3.util.ComponentKey;
|
||||
import com.android.launcher3.util.SafeCloseable;
|
||||
|
||||
|
@ -235,7 +235,7 @@ public class IconProvider {
|
|||
ComponentName calendar =
|
||||
parseComponentOrNull(context, R.string.calendar_component_name);
|
||||
if (calendar != null) {
|
||||
for (UserHandle user : UserManagerCompat.getInstance(context).getUserProfiles()) {
|
||||
for (UserHandle user : UserCache.INSTANCE.get(context).getUserProfiles()) {
|
||||
mCallback.accept(calendar.getPackageName(), user);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ import android.util.Log;
|
|||
|
||||
import com.android.launcher3.LauncherSettings.Favorites;
|
||||
import com.android.launcher3.LauncherSettings.Settings;
|
||||
import com.android.launcher3.compat.UserManagerCompat;
|
||||
import com.android.launcher3.pm.UserCache;
|
||||
|
||||
/**
|
||||
* Helper class to backup and restore Favorites table into a separate table
|
||||
|
@ -94,7 +94,7 @@ public class GridBackupTable {
|
|||
}
|
||||
|
||||
private void copyTable(String from, String to) {
|
||||
long userSerial = UserManagerCompat.getInstance(mContext).getSerialNumberForUser(
|
||||
long userSerial = UserCache.INSTANCE.get(mContext).getSerialNumberForUser(
|
||||
Process.myUserHandle());
|
||||
dropTable(mDb, to);
|
||||
Favorites.addTableToDb(mDb, userSerial, false, to);
|
||||
|
|
|
@ -28,7 +28,6 @@ import com.android.launcher3.LauncherSettings.Favorites;
|
|||
import com.android.launcher3.LauncherSettings.Settings;
|
||||
import com.android.launcher3.Utilities;
|
||||
import com.android.launcher3.Workspace;
|
||||
import com.android.launcher3.compat.AppWidgetManagerCompat;
|
||||
import com.android.launcher3.config.FeatureFlags;
|
||||
import com.android.launcher3.pm.PackageInstallerCompat;
|
||||
import com.android.launcher3.provider.LauncherDbUtils;
|
||||
|
@ -36,6 +35,7 @@ import com.android.launcher3.provider.LauncherDbUtils.SQLiteTransaction;
|
|||
import com.android.launcher3.util.GridOccupancy;
|
||||
import com.android.launcher3.util.IntArray;
|
||||
import com.android.launcher3.util.IntSparseArrayMap;
|
||||
import com.android.launcher3.widget.WidgetManagerHelper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
@ -692,6 +692,7 @@ public class GridSizeMigrationTask {
|
|||
final int indexAppWidgetId = c.getColumnIndexOrThrow(Favorites.APPWIDGET_ID);
|
||||
|
||||
ArrayList<DbEntry> entries = new ArrayList<>();
|
||||
WidgetManagerHelper widgetManagerHelper = new WidgetManagerHelper(mContext);
|
||||
while (c.moveToNext()) {
|
||||
DbEntry entry = new DbEntry();
|
||||
entry.id = c.getInt(indexId);
|
||||
|
@ -721,8 +722,8 @@ public class GridSizeMigrationTask {
|
|||
* entry.spanX * entry.spanY);
|
||||
|
||||
int widgetId = c.getInt(indexAppWidgetId);
|
||||
LauncherAppWidgetProviderInfo pInfo = AppWidgetManagerCompat.getInstance(
|
||||
mContext).getLauncherAppWidgetInfo(widgetId);
|
||||
LauncherAppWidgetProviderInfo pInfo =
|
||||
widgetManagerHelper.getLauncherAppWidgetInfo(widgetId);
|
||||
Point spans = null;
|
||||
if (pInfo != null) {
|
||||
spans = pInfo.getMinSpans();
|
||||
|
|
|
@ -36,6 +36,7 @@ import android.content.pm.PackageInstaller.SessionInfo;
|
|||
import android.content.pm.ShortcutInfo;
|
||||
import android.os.Process;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.util.LongSparseArray;
|
||||
|
@ -55,8 +56,6 @@ import com.android.launcher3.LauncherModel;
|
|||
import com.android.launcher3.LauncherSettings;
|
||||
import com.android.launcher3.Utilities;
|
||||
import com.android.launcher3.WorkspaceItemInfo;
|
||||
import com.android.launcher3.compat.AppWidgetManagerCompat;
|
||||
import com.android.launcher3.compat.UserManagerCompat;
|
||||
import com.android.launcher3.config.FeatureFlags;
|
||||
import com.android.launcher3.folder.Folder;
|
||||
import com.android.launcher3.folder.FolderGridOrganizer;
|
||||
|
@ -70,6 +69,7 @@ import com.android.launcher3.icons.cache.IconCacheUpdateHandler;
|
|||
import com.android.launcher3.logging.FileLog;
|
||||
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;
|
||||
import com.android.launcher3.shortcuts.DeepShortcutManager;
|
||||
|
@ -81,6 +81,7 @@ import com.android.launcher3.util.MultiHashMap;
|
|||
import com.android.launcher3.util.PackageManagerHelper;
|
||||
import com.android.launcher3.util.PackageUserKey;
|
||||
import com.android.launcher3.util.TraceHelper;
|
||||
import com.android.launcher3.widget.WidgetManagerHelper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
@ -110,10 +111,11 @@ public class LoaderTask implements Runnable {
|
|||
private final LoaderResults mResults;
|
||||
|
||||
private final LauncherApps mLauncherApps;
|
||||
private final UserManagerCompat mUserManager;
|
||||
private final UserManager mUserManager;
|
||||
private final UserCache mUserCache;
|
||||
|
||||
private final DeepShortcutManager mShortcutManager;
|
||||
private final PackageInstallerCompat mPackageInstaller;
|
||||
private final AppWidgetManagerCompat mAppWidgetManager;
|
||||
private final IconCache mIconCache;
|
||||
|
||||
private boolean mStopped;
|
||||
|
@ -126,10 +128,10 @@ public class LoaderTask implements Runnable {
|
|||
mResults = results;
|
||||
|
||||
mLauncherApps = mApp.getContext().getSystemService(LauncherApps.class);
|
||||
mUserManager = UserManagerCompat.getInstance(mApp.getContext());
|
||||
mUserManager = mApp.getContext().getSystemService(UserManager.class);
|
||||
mUserCache = UserCache.INSTANCE.get(mApp.getContext());
|
||||
mShortcutManager = DeepShortcutManager.getInstance(mApp.getContext());
|
||||
mPackageInstaller = PackageInstallerCompat.getInstance(mApp.getContext());
|
||||
mAppWidgetManager = AppWidgetManagerCompat.getInstance(mApp.getContext());
|
||||
mIconCache = mApp.getIconCache();
|
||||
}
|
||||
|
||||
|
@ -319,7 +321,7 @@ public class LoaderTask implements Runnable {
|
|||
final LoaderCursor c = new LoaderCursor(contentResolver.query(
|
||||
LauncherSettings.Favorites.CONTENT_URI, null, null, null, null), mApp);
|
||||
|
||||
HashMap<ComponentKey, AppWidgetProviderInfo> widgetProvidersMap = null;
|
||||
Map<ComponentKey, AppWidgetProviderInfo> widgetProvidersMap = null;
|
||||
|
||||
try {
|
||||
final int appWidgetIdIndex = c.getColumnIndexOrThrow(
|
||||
|
@ -338,8 +340,8 @@ public class LoaderTask implements Runnable {
|
|||
final LongSparseArray<UserHandle> allUsers = c.allUsers;
|
||||
final LongSparseArray<Boolean> quietMode = new LongSparseArray<>();
|
||||
final LongSparseArray<Boolean> unlockedUsers = new LongSparseArray<>();
|
||||
for (UserHandle user : mUserManager.getUserProfiles()) {
|
||||
long serialNo = mUserManager.getSerialNumberForUser(user);
|
||||
for (UserHandle user : mUserCache.getUserProfiles()) {
|
||||
long serialNo = mUserCache.getSerialNumberForUser(user);
|
||||
allUsers.put(serialNo, user);
|
||||
quietMode.put(serialNo, mUserManager.isQuietModeEnabled(user));
|
||||
|
||||
|
@ -634,7 +636,7 @@ public class LoaderTask implements Runnable {
|
|||
LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY);
|
||||
|
||||
if (widgetProvidersMap == null) {
|
||||
widgetProvidersMap = mAppWidgetManager.getAllProvidersMap();
|
||||
widgetProvidersMap = WidgetManagerHelper.getAllProvidersMap(context);
|
||||
}
|
||||
final AppWidgetProviderInfo provider = widgetProvidersMap.get(
|
||||
new ComponentKey(component, c.user));
|
||||
|
@ -844,7 +846,7 @@ public class LoaderTask implements Runnable {
|
|||
}
|
||||
|
||||
private List<LauncherActivityInfo> loadAllApps() {
|
||||
final List<UserHandle> profiles = mUserManager.getUserProfiles();
|
||||
final List<UserHandle> profiles = mUserCache.getUserProfiles();
|
||||
List<LauncherActivityInfo> allActivityList = new ArrayList<>();
|
||||
// Clear the list of apps
|
||||
mBgAllAppsList.clear();
|
||||
|
@ -884,7 +886,7 @@ public class LoaderTask implements Runnable {
|
|||
mBgDataModel.deepShortcutMap.clear();
|
||||
mBgDataModel.hasShortcutHostPermission = mShortcutManager.hasHostPermission();
|
||||
if (mBgDataModel.hasShortcutHostPermission) {
|
||||
for (UserHandle user : mUserManager.getUserProfiles()) {
|
||||
for (UserHandle user : mUserCache.getUserProfiles()) {
|
||||
if (mUserManager.isUserUnlocked(user)) {
|
||||
List<ShortcutInfo> shortcuts =
|
||||
mShortcutManager.queryForAllShortcuts(user);
|
||||
|
|
|
@ -25,6 +25,7 @@ import android.content.pm.LauncherApps;
|
|||
import android.content.pm.ShortcutInfo;
|
||||
import android.os.Process;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.launcher3.InstallShortcutReceiver;
|
||||
|
@ -35,7 +36,6 @@ import com.android.launcher3.LauncherSettings.Favorites;
|
|||
import com.android.launcher3.SessionCommitReceiver;
|
||||
import com.android.launcher3.Utilities;
|
||||
import com.android.launcher3.WorkspaceItemInfo;
|
||||
import com.android.launcher3.compat.UserManagerCompat;
|
||||
import com.android.launcher3.config.FeatureFlags;
|
||||
import com.android.launcher3.icons.BitmapInfo;
|
||||
import com.android.launcher3.icons.IconCache;
|
||||
|
@ -155,7 +155,7 @@ public class PackageUpdatedTask extends BaseModelUpdateTask {
|
|||
appsList.updateDisabledFlags(matcher, flagOp);
|
||||
break;
|
||||
case OP_USER_AVAILABILITY_CHANGE:
|
||||
flagOp = UserManagerCompat.getInstance(context).isQuietModeEnabled(mUser)
|
||||
flagOp = context.getSystemService(UserManager.class).isQuietModeEnabled(mUser)
|
||||
? FlagOp.addFlag(WorkspaceItemInfo.FLAG_DISABLED_QUIET_USER)
|
||||
: FlagOp.removeFlag(WorkspaceItemInfo.FLAG_DISABLED_QUIET_USER);
|
||||
// We want to update all packages for this user.
|
||||
|
|
|
@ -20,12 +20,12 @@ import static com.android.launcher3.ItemInfoWithIcon.FLAG_DISABLED_LOCKED_USER;
|
|||
import android.content.Context;
|
||||
import android.content.pm.ShortcutInfo;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
|
||||
import com.android.launcher3.ItemInfo;
|
||||
import com.android.launcher3.LauncherAppState;
|
||||
import com.android.launcher3.LauncherSettings;
|
||||
import com.android.launcher3.WorkspaceItemInfo;
|
||||
import com.android.launcher3.compat.UserManagerCompat;
|
||||
import com.android.launcher3.icons.LauncherIcons;
|
||||
import com.android.launcher3.shortcuts.DeepShortcutManager;
|
||||
import com.android.launcher3.shortcuts.ShortcutKey;
|
||||
|
@ -51,7 +51,7 @@ public class UserLockStateChangedTask extends BaseModelUpdateTask {
|
|||
@Override
|
||||
public void execute(LauncherAppState app, BgDataModel dataModel, AllAppsList apps) {
|
||||
Context context = app.getContext();
|
||||
boolean isUserUnlocked = UserManagerCompat.getInstance(context).isUserUnlocked(mUser);
|
||||
boolean isUserUnlocked = context.getSystemService(UserManager.class).isUserUnlocked(mUser);
|
||||
DeepShortcutManager deepShortcutManager = DeepShortcutManager.getInstance(context);
|
||||
|
||||
HashMap<ShortcutKey, ShortcutInfo> pinnedShortcuts = new HashMap<>();
|
||||
|
|
|
@ -41,7 +41,6 @@ import com.android.launcher3.LauncherSettings;
|
|||
import com.android.launcher3.R;
|
||||
import com.android.launcher3.Utilities;
|
||||
import com.android.launcher3.WorkspaceItemInfo;
|
||||
import com.android.launcher3.compat.UserManagerCompat;
|
||||
import com.android.launcher3.icons.ComponentWithLabel;
|
||||
import com.android.launcher3.icons.IconCache;
|
||||
import com.android.launcher3.util.PackageUserKey;
|
||||
|
@ -179,7 +178,7 @@ public abstract class ShortcutConfigActivityInfo implements ComponentWithLabel {
|
|||
final List<UserHandle> users;
|
||||
final String packageName;
|
||||
if (packageUser == null) {
|
||||
users = UserManagerCompat.getInstance(context).getUserProfiles();
|
||||
users = UserCache.INSTANCE.get(context).getUserProfiles();
|
||||
packageName = null;
|
||||
} else {
|
||||
users = new ArrayList<>(1);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (C) 2016 The Android Open Source Project
|
||||
* Copyright (C) 2014 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -14,92 +14,71 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.launcher3.compat;
|
||||
package com.android.launcher3.pm;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.content.Intent;
|
||||
import android.os.Process;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.util.ArrayMap;
|
||||
import android.util.LongSparseArray;
|
||||
|
||||
import com.android.launcher3.util.MainThreadInitializedObject;
|
||||
import com.android.launcher3.util.SafeCloseable;
|
||||
import com.android.launcher3.util.SimpleBroadcastReceiver;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.N_MR1)
|
||||
public class UserManagerCompatVNMr1 extends UserManagerCompat {
|
||||
/**
|
||||
* Class which manages a local cache of user handles to avoid system rpc
|
||||
*/
|
||||
public class UserCache {
|
||||
|
||||
protected final UserManager mUserManager;
|
||||
public static final MainThreadInitializedObject<UserCache> INSTANCE =
|
||||
new MainThreadInitializedObject<>(UserCache::new);
|
||||
|
||||
protected LongSparseArray<UserHandle> mUsers;
|
||||
private final Context mContext;
|
||||
private final UserManager mUserManager;
|
||||
private final ArrayList<Runnable> mUserChangeListeners = new ArrayList<>();
|
||||
private final SimpleBroadcastReceiver mUserChangeReceiver =
|
||||
new SimpleBroadcastReceiver(this::onUsersChanged);
|
||||
|
||||
private LongSparseArray<UserHandle> mUsers;
|
||||
// Create a separate reverse map as LongSparseArray.indexOfValue checks if objects are same
|
||||
// and not {@link Object#equals}
|
||||
protected ArrayMap<UserHandle, Long> mUserToSerialMap;
|
||||
private ArrayMap<UserHandle, Long> mUserToSerialMap;
|
||||
|
||||
UserManagerCompatVNMr1(Context context) {
|
||||
mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
|
||||
private UserCache(Context context) {
|
||||
mContext = context;
|
||||
mUserManager = context.getSystemService(UserManager.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isQuietModeEnabled(UserHandle user) {
|
||||
return mUserManager.isQuietModeEnabled(user);
|
||||
private void onUsersChanged(Intent intent) {
|
||||
enableAndResetCache();
|
||||
mUserChangeListeners.forEach(Runnable::run);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUserUnlocked(UserHandle user) {
|
||||
return mUserManager.isUserUnlocked(user);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAnyProfileQuietModeEnabled() {
|
||||
List<UserHandle> userProfiles = getUserProfiles();
|
||||
for (UserHandle userProfile : userProfiles) {
|
||||
if (Process.myUserHandle().equals(userProfile)) {
|
||||
continue;
|
||||
}
|
||||
if (isQuietModeEnabled(userProfile)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getSerialNumberForUser(UserHandle user) {
|
||||
/**
|
||||
* Adds a listener for user additions and removals
|
||||
*/
|
||||
public SafeCloseable addUserChangeListener(Runnable command) {
|
||||
synchronized (this) {
|
||||
if (mUserToSerialMap != null) {
|
||||
Long serial = mUserToSerialMap.get(user);
|
||||
return serial == null ? 0 : serial;
|
||||
if (mUserChangeListeners.isEmpty()) {
|
||||
// Enable caching and start listening for user broadcast
|
||||
mUserChangeReceiver.register(mContext,
|
||||
Intent.ACTION_MANAGED_PROFILE_ADDED,
|
||||
Intent.ACTION_MANAGED_PROFILE_REMOVED);
|
||||
enableAndResetCache();
|
||||
}
|
||||
mUserChangeListeners.add(command);
|
||||
return () -> removeUserChangeListener(command);
|
||||
}
|
||||
return mUserManager.getSerialNumberForUser(user);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserHandle getUserForSerialNumber(long serialNumber) {
|
||||
synchronized (this) {
|
||||
if (mUsers != null) {
|
||||
return mUsers.get(serialNumber);
|
||||
}
|
||||
}
|
||||
return mUserManager.getUserForSerialNumber(serialNumber);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDemoUser() {
|
||||
return mUserManager.isDemoUser();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean requestQuietModeEnabled(boolean enableQuietMode, UserHandle user) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enableAndResetCache() {
|
||||
private void enableAndResetCache() {
|
||||
synchronized (this) {
|
||||
mUsers = new LongSparseArray<>();
|
||||
mUserToSerialMap = new ArrayMap<>();
|
||||
|
@ -114,7 +93,63 @@ public class UserManagerCompatVNMr1 extends UserManagerCompat {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
private void removeUserChangeListener(Runnable command) {
|
||||
synchronized (this) {
|
||||
mUserChangeListeners.add(command);
|
||||
if (mUserChangeListeners.isEmpty()) {
|
||||
// Disable cache and stop listening
|
||||
mContext.unregisterReceiver(mUserChangeReceiver);
|
||||
|
||||
mUsers = null;
|
||||
mUserToSerialMap = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if any user profile has quiet mode enabled.
|
||||
*/
|
||||
public boolean isAnyProfileQuietModeEnabled() {
|
||||
List<UserHandle> userProfiles = getUserProfiles();
|
||||
for (UserHandle userProfile : userProfiles) {
|
||||
if (Process.myUserHandle().equals(userProfile)) {
|
||||
continue;
|
||||
}
|
||||
if (mUserManager.isQuietModeEnabled(userProfile)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see UserManager#getSerialNumberForUser(UserHandle)
|
||||
*/
|
||||
public long getSerialNumberForUser(UserHandle user) {
|
||||
synchronized (this) {
|
||||
if (mUserToSerialMap != null) {
|
||||
Long serial = mUserToSerialMap.get(user);
|
||||
return serial == null ? 0 : serial;
|
||||
}
|
||||
}
|
||||
return mUserManager.getSerialNumberForUser(user);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see UserManager#getUserForSerialNumber(long)
|
||||
*/
|
||||
public UserHandle getUserForSerialNumber(long serialNumber) {
|
||||
synchronized (this) {
|
||||
if (mUsers != null) {
|
||||
return mUsers.get(serialNumber);
|
||||
}
|
||||
}
|
||||
return mUserManager.getUserForSerialNumber(serialNumber);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see UserManager#getUserProfiles()
|
||||
*/
|
||||
public List<UserHandle> getUserProfiles() {
|
||||
synchronized (this) {
|
||||
if (mUsers != null) {
|
||||
|
@ -123,10 +158,12 @@ public class UserManagerCompatVNMr1 extends UserManagerCompat {
|
|||
}
|
||||
|
||||
List<UserHandle> users = mUserManager.getUserProfiles();
|
||||
return users == null ? Collections.<UserHandle>emptyList() : users;
|
||||
return users == null ? Collections.emptyList() : users;
|
||||
}
|
||||
|
||||
@Override
|
||||
/**
|
||||
* Returns true is there is at least one user profile enabled
|
||||
*/
|
||||
public boolean hasWorkProfile() {
|
||||
synchronized (this) {
|
||||
if (mUsers != null) {
|
|
@ -43,10 +43,10 @@ import com.android.launcher3.LauncherSettings;
|
|||
import com.android.launcher3.LauncherSettings.Favorites;
|
||||
import com.android.launcher3.LauncherSettings.Settings;
|
||||
import com.android.launcher3.Workspace;
|
||||
import com.android.launcher3.compat.UserManagerCompat;
|
||||
import com.android.launcher3.config.FeatureFlags;
|
||||
import com.android.launcher3.logging.FileLog;
|
||||
import com.android.launcher3.model.GridSizeMigrationTask;
|
||||
import com.android.launcher3.pm.UserCache;
|
||||
import com.android.launcher3.util.IntArray;
|
||||
import com.android.launcher3.util.IntSparseArrayMap;
|
||||
import com.android.launcher3.util.PackageManagerHelper;
|
||||
|
@ -100,7 +100,7 @@ public class ImportDataTask {
|
|||
* 3) In the end fills any holes in hotseat with items from default hotseat layout.
|
||||
*/
|
||||
private void importWorkspaceItems() throws Exception {
|
||||
String profileId = Long.toString(UserManagerCompat.getInstance(mContext)
|
||||
String profileId = Long.toString(UserCache.INSTANCE.get(mContext)
|
||||
.getSerialNumberForUser(Process.myUserHandle()));
|
||||
|
||||
boolean createEmptyRowOnFirstScreen;
|
||||
|
|
|
@ -54,7 +54,7 @@ import com.android.launcher3.graphics.FragmentWithPreview;
|
|||
* A frame layout which contains a QSB. This internally uses fragment to bind the view, which
|
||||
* allows it to contain the logic for {@link Fragment#startActivityForResult(Intent, int)}.
|
||||
*
|
||||
* Note: AppWidgetManagerCompat can be disabled using FeatureFlags. In QSB, we should use
|
||||
* Note: WidgetManagerHelper can be disabled using FeatureFlags. In QSB, we should use
|
||||
* AppWidgetManager directly, so that it keeps working in that case.
|
||||
*/
|
||||
public class QsbContainerView extends FrameLayout {
|
||||
|
|
|
@ -49,7 +49,6 @@ import com.android.launcher3.PromiseAppInfo;
|
|||
import com.android.launcher3.R;
|
||||
import com.android.launcher3.Utilities;
|
||||
import com.android.launcher3.WorkspaceItemInfo;
|
||||
import com.android.launcher3.compat.AppWidgetManagerCompat;
|
||||
import com.android.launcher3.folder.Folder;
|
||||
import com.android.launcher3.folder.FolderIcon;
|
||||
import com.android.launcher3.pm.PackageInstallerCompat;
|
||||
|
@ -57,6 +56,7 @@ import com.android.launcher3.util.PackageManagerHelper;
|
|||
import com.android.launcher3.views.FloatingIconView;
|
||||
import com.android.launcher3.widget.PendingAppWidgetHostView;
|
||||
import com.android.launcher3.widget.WidgetAddFlowHandler;
|
||||
import com.android.launcher3.widget.WidgetManagerHelper;
|
||||
|
||||
/**
|
||||
* Class for handling clicks on workspace and all-apps items
|
||||
|
@ -123,8 +123,8 @@ public class ItemClickHandler {
|
|||
|
||||
final LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) v.getTag();
|
||||
if (v.isReadyForClickSetup()) {
|
||||
LauncherAppWidgetProviderInfo appWidgetInfo = AppWidgetManagerCompat
|
||||
.getInstance(launcher).findProvider(info.providerName, info.user);
|
||||
LauncherAppWidgetProviderInfo appWidgetInfo = new WidgetManagerHelper(launcher)
|
||||
.findProvider(info.providerName, info.user);
|
||||
if (appWidgetInfo == null) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -19,15 +19,14 @@ package com.android.launcher3.util;
|
|||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.net.Uri;
|
||||
import android.os.UserHandle;
|
||||
|
||||
import com.android.launcher3.LauncherAppState;
|
||||
import com.android.launcher3.LauncherSettings;
|
||||
import com.android.launcher3.compat.UserManagerCompat;
|
||||
import com.android.launcher3.icons.BitmapInfo;
|
||||
import com.android.launcher3.icons.GraphicsUtils;
|
||||
import com.android.launcher3.pm.UserCache;
|
||||
|
||||
/**
|
||||
* A wrapper around {@link ContentValues} with some utility methods.
|
||||
|
@ -87,7 +86,7 @@ public class ContentWriter {
|
|||
}
|
||||
|
||||
public ContentWriter put(String key, UserHandle user) {
|
||||
return put(key, UserManagerCompat.getInstance(mContext).getSerialNumberForUser(user));
|
||||
return put(key, UserCache.INSTANCE.get(mContext).getSerialNumberForUser(user));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -13,7 +13,6 @@ import com.android.launcher3.AppWidgetResizeFrame;
|
|||
import com.android.launcher3.DropTarget;
|
||||
import com.android.launcher3.Launcher;
|
||||
import com.android.launcher3.LauncherAppWidgetProviderInfo;
|
||||
import com.android.launcher3.compat.AppWidgetManagerCompat;
|
||||
import com.android.launcher3.dragndrop.DragController;
|
||||
import com.android.launcher3.dragndrop.DragLayer;
|
||||
import com.android.launcher3.dragndrop.DragOptions;
|
||||
|
@ -103,7 +102,7 @@ public class WidgetHostViewLoader implements DragController.DragListener {
|
|||
if (LOGD) {
|
||||
Log.d(TAG, "Binding widget, id: " + mWidgetLoadingId);
|
||||
}
|
||||
if(AppWidgetManagerCompat.getInstance(mLauncher).bindAppWidgetIdIfAllowed(
|
||||
if (new WidgetManagerHelper(mLauncher).bindAppWidgetIdIfAllowed(
|
||||
mWidgetLoadingId, pInfo, options)) {
|
||||
|
||||
// Widget id bound. Inflate the widget.
|
||||
|
|
|
@ -0,0 +1,148 @@
|
|||
/*
|
||||
* Copyright (C) 2014 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.launcher3.widget;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.appwidget.AppWidgetManager;
|
||||
import android.appwidget.AppWidgetProviderInfo;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Process;
|
||||
import android.os.UserHandle;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.android.launcher3.LauncherAppWidgetInfo;
|
||||
import com.android.launcher3.LauncherAppWidgetProviderInfo;
|
||||
import com.android.launcher3.Utilities;
|
||||
import com.android.launcher3.model.WidgetsModel;
|
||||
import com.android.launcher3.pm.UserCache;
|
||||
import com.android.launcher3.util.ComponentKey;
|
||||
import com.android.launcher3.util.PackageUserKey;
|
||||
import com.android.launcher3.widget.custom.CustomWidgetManager;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* Utility class to working with {@link AppWidgetManager}
|
||||
*/
|
||||
public class WidgetManagerHelper {
|
||||
|
||||
final AppWidgetManager mAppWidgetManager;
|
||||
final Context mContext;
|
||||
|
||||
public WidgetManagerHelper(Context context) {
|
||||
mContext = context;
|
||||
mAppWidgetManager = AppWidgetManager.getInstance(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see AppWidgetManager#getAppWidgetInfo(int)
|
||||
*/
|
||||
public LauncherAppWidgetProviderInfo getLauncherAppWidgetInfo(int appWidgetId) {
|
||||
if (appWidgetId <= LauncherAppWidgetInfo.CUSTOM_WIDGET_ID) {
|
||||
return CustomWidgetManager.INSTANCE.get(mContext).getWidgetProvider(appWidgetId);
|
||||
}
|
||||
AppWidgetProviderInfo info = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
|
||||
return info == null ? null : LauncherAppWidgetProviderInfo.fromProviderInfo(mContext, info);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see AppWidgetManager#getInstalledProvidersForPackage(String, UserHandle)
|
||||
*/
|
||||
@TargetApi(Build.VERSION_CODES.O)
|
||||
public List<AppWidgetProviderInfo> getAllProviders(@Nullable PackageUserKey packageUser) {
|
||||
if (WidgetsModel.GO_DISABLE_WIDGETS) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
if (packageUser == null) {
|
||||
return allWidgetsSteam(mContext).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
if (Utilities.ATLEAST_OREO) {
|
||||
return mAppWidgetManager.getInstalledProvidersForPackage(
|
||||
packageUser.mPackageName, packageUser.mUser);
|
||||
}
|
||||
|
||||
String pkg = packageUser.mPackageName;
|
||||
return Stream.concat(
|
||||
// Only get providers for the given package/user.
|
||||
mAppWidgetManager.getInstalledProvidersForProfile(packageUser.mUser)
|
||||
.stream()
|
||||
.filter(w -> w.provider.equals(pkg)),
|
||||
Process.myUserHandle().equals(packageUser.mUser)
|
||||
&& mContext.getPackageName().equals(pkg)
|
||||
? CustomWidgetManager.INSTANCE.get(mContext).stream()
|
||||
: Stream.empty())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @see AppWidgetManager#bindAppWidgetIdIfAllowed(int, UserHandle, ComponentName, Bundle)
|
||||
*/
|
||||
public boolean bindAppWidgetIdIfAllowed(int appWidgetId, AppWidgetProviderInfo info,
|
||||
Bundle options) {
|
||||
if (WidgetsModel.GO_DISABLE_WIDGETS) {
|
||||
return false;
|
||||
}
|
||||
if (appWidgetId <= LauncherAppWidgetInfo.CUSTOM_WIDGET_ID) {
|
||||
return true;
|
||||
}
|
||||
return mAppWidgetManager.bindAppWidgetIdIfAllowed(
|
||||
appWidgetId, info.getProfile(), info.provider, options);
|
||||
}
|
||||
|
||||
public LauncherAppWidgetProviderInfo findProvider(ComponentName provider, UserHandle user) {
|
||||
if (WidgetsModel.GO_DISABLE_WIDGETS) {
|
||||
return null;
|
||||
}
|
||||
for (AppWidgetProviderInfo info :
|
||||
getAllProviders(new PackageUserKey(provider.getPackageName(), user))) {
|
||||
if (info.provider.equals(provider)) {
|
||||
return LauncherAppWidgetProviderInfo.fromProviderInfo(mContext, info);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Map<ComponentKey, AppWidgetProviderInfo> getAllProvidersMap(Context context) {
|
||||
if (WidgetsModel.GO_DISABLE_WIDGETS) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
return allWidgetsSteam(context).collect(
|
||||
Collectors.toMap(info -> new ComponentKey(info.provider, info.getProfile()),
|
||||
Function.identity()));
|
||||
}
|
||||
|
||||
private static Stream<AppWidgetProviderInfo> allWidgetsSteam(Context context) {
|
||||
AppWidgetManager awm = context.getSystemService(AppWidgetManager.class);
|
||||
return Stream.concat(
|
||||
UserCache.INSTANCE.get(context)
|
||||
.getUserProfiles()
|
||||
.stream()
|
||||
.flatMap(u -> awm.getInstalledProvidersForProfile(u).stream()),
|
||||
CustomWidgetManager.INSTANCE.get(context).stream());
|
||||
}
|
||||
}
|
|
@ -41,6 +41,7 @@ import com.android.systemui.plugins.PluginListener;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* CustomWidgetManager handles custom widgets implemented as a plugin.
|
||||
|
@ -112,11 +113,11 @@ public class CustomWidgetManager implements PluginListener<CustomWidgetPlugin> {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the list of custom widgets.
|
||||
* Returns the stream of custom widgets.
|
||||
*/
|
||||
@NonNull
|
||||
public List<CustomAppWidgetProviderInfo> getCustomWidgets() {
|
||||
return mCustomWidgets;
|
||||
public Stream<CustomAppWidgetProviderInfo> stream() {
|
||||
return mCustomWidgets.stream();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -20,7 +20,6 @@ import com.android.launcher3.LauncherAppState;
|
|||
import com.android.launcher3.LauncherAppWidgetProviderInfo;
|
||||
import com.android.launcher3.Utilities;
|
||||
import com.android.launcher3.compat.AlphabeticIndexCompat;
|
||||
import com.android.launcher3.compat.AppWidgetManagerCompat;
|
||||
import com.android.launcher3.config.FeatureFlags;
|
||||
import com.android.launcher3.icons.ComponentWithLabel;
|
||||
import com.android.launcher3.icons.IconCache;
|
||||
|
@ -30,6 +29,7 @@ import com.android.launcher3.util.PackageUserKey;
|
|||
import com.android.launcher3.util.Preconditions;
|
||||
import com.android.launcher3.widget.WidgetItemComparator;
|
||||
import com.android.launcher3.widget.WidgetListRowEntry;
|
||||
import com.android.launcher3.widget.WidgetManagerHelper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
@ -96,7 +96,7 @@ public class WidgetsModel {
|
|||
PackageManager pm = app.getContext().getPackageManager();
|
||||
|
||||
// Widgets
|
||||
AppWidgetManagerCompat widgetManager = AppWidgetManagerCompat.getInstance(context);
|
||||
WidgetManagerHelper widgetManager = new WidgetManagerHelper(context);
|
||||
for (AppWidgetProviderInfo widgetInfo : widgetManager.getAllProviders(packageUser)) {
|
||||
LauncherAppWidgetProviderInfo launcherWidgetInfo =
|
||||
LauncherAppWidgetProviderInfo.fromProviderInfo(context, widgetInfo);
|
||||
|
|
|
@ -24,12 +24,10 @@ import android.util.Log;
|
|||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.test.uiautomator.UiDevice;
|
||||
|
||||
import com.android.launcher3.LauncherAppWidgetProviderInfo;
|
||||
import com.android.launcher3.compat.AppWidgetManagerCompat;
|
||||
import com.android.launcher3.testcomponent.AppWidgetNoConfig;
|
||||
import com.android.launcher3.testcomponent.AppWidgetWithConfig;
|
||||
import com.android.launcher3.widget.WidgetManagerHelper;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.function.Function;
|
||||
|
@ -53,7 +51,7 @@ public class TestViewHelpers {
|
|||
hasConfigureScreen ? AppWidgetWithConfig.class
|
||||
: AppWidgetNoConfig.class);
|
||||
Log.d(TAG, "findWidgetProvider componentName=" + cn.flattenToString());
|
||||
return AppWidgetManagerCompat.getInstance(getTargetContext())
|
||||
return new WidgetManagerHelper(getTargetContext())
|
||||
.findProvider(cn, Process.myUserHandle());
|
||||
}
|
||||
});
|
||||
|
|
|
@ -41,13 +41,13 @@ import com.android.launcher3.LauncherAppWidgetHost;
|
|||
import com.android.launcher3.LauncherAppWidgetInfo;
|
||||
import com.android.launcher3.LauncherAppWidgetProviderInfo;
|
||||
import com.android.launcher3.LauncherSettings;
|
||||
import com.android.launcher3.compat.AppWidgetManagerCompat;
|
||||
import com.android.launcher3.pm.PackageInstallerCompat;
|
||||
import com.android.launcher3.tapl.Workspace;
|
||||
import com.android.launcher3.ui.AbstractLauncherUiTest;
|
||||
import com.android.launcher3.ui.TestViewHelpers;
|
||||
import com.android.launcher3.util.rule.ShellCommandRule;
|
||||
import com.android.launcher3.widget.PendingAddWidgetInfo;
|
||||
import com.android.launcher3.widget.WidgetManagerHelper;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
|
@ -282,7 +282,7 @@ public class BindWidgetTest extends AbstractLauncherUiTest {
|
|||
|
||||
AppWidgetHost host = new LauncherAppWidgetHost(targetContext);
|
||||
int widgetId = host.allocateAppWidgetId();
|
||||
if (!AppWidgetManagerCompat.getInstance(targetContext)
|
||||
if (!new WidgetManagerHelper(targetContext)
|
||||
.bindAppWidgetIdIfAllowed(widgetId, info, options)) {
|
||||
host.deleteAppWidgetId(widgetId);
|
||||
throw new IllegalArgumentException("Unable to bind widget id");
|
||||
|
|
|
@ -33,7 +33,6 @@ import androidx.test.runner.AndroidJUnit4;
|
|||
import com.android.launcher3.InvariantDeviceProfile;
|
||||
import com.android.launcher3.LauncherAppWidgetProviderInfo;
|
||||
import com.android.launcher3.WidgetPreviewLoader;
|
||||
import com.android.launcher3.compat.AppWidgetManagerCompat;
|
||||
import com.android.launcher3.icons.BitmapInfo;
|
||||
import com.android.launcher3.icons.IconCache;
|
||||
import com.android.launcher3.model.PackageItemInfo;
|
||||
|
@ -129,7 +128,7 @@ public class WidgetsListAdapterTest {
|
|||
if (num <= 0) return result;
|
||||
|
||||
MultiHashMap<PackageItemInfo, WidgetItem> newMap = new MultiHashMap();
|
||||
AppWidgetManagerCompat widgetManager = AppWidgetManagerCompat.getInstance(mContext);
|
||||
WidgetManagerHelper widgetManager = new WidgetManagerHelper(mContext);
|
||||
for (AppWidgetProviderInfo widgetInfo : widgetManager.getAllProviders(null)) {
|
||||
WidgetItem wi = new WidgetItem(LauncherAppWidgetProviderInfo
|
||||
.fromProviderInfo(mContext, widgetInfo), mTestProfile, mIconCache);
|
||||
|
|
Loading…
Reference in New Issue