Deprecate work folder

FIX: 73876183

Change-Id: I9d15df247eed3500c679cba085c680b75581cffb
This commit is contained in:
Tony Mak 2018-02-27 15:06:12 +00:00
parent 7eadfc4f15
commit 1b6826c53c
9 changed files with 8 additions and 318 deletions

View File

@ -59,7 +59,6 @@ import com.android.launcher3.model.DbDowngradeHelper;
import com.android.launcher3.provider.LauncherDbUtils;
import com.android.launcher3.provider.LauncherDbUtils.SQLiteTransaction;
import com.android.launcher3.provider.RestoreDbTask;
import com.android.launcher3.util.ManagedProfileHeuristic;
import com.android.launcher3.util.NoLocaleSqliteContext;
import com.android.launcher3.util.Preconditions;
import com.android.launcher3.util.Thunk;
@ -623,10 +622,6 @@ public class LauncherProvider extends ContentProvider {
// Set the flag for empty DB
Utilities.getPrefs(mContext).edit().putBoolean(EMPTY_DATABASE_CREATED, true).commit();
// When a new DB is created, remove all previously stored managed profile information.
ManagedProfileHeuristic.processAllUsers(Collections.<UserHandle>emptyList(),
mContext);
}
public long getDefaultUserSerial() {
@ -790,7 +785,7 @@ public class LauncherProvider extends ContentProvider {
case 23:
// No-op
case 24:
ManagedProfileHeuristic.markExistingUsersForNoFolderCreation(mContext);
// No-op
case 25:
convertShortcutsToLauncherActivities(db);
case 26:

View File

@ -67,11 +67,9 @@ public class SessionCommitReceiver extends BroadcastReceiver {
SessionInfo info = intent.getParcelableExtra(PackageInstaller.EXTRA_SESSION);
UserHandle user = intent.getParcelableExtra(Intent.EXTRA_USER);
if (Process.myUserHandle().equals(user)) {
if (TextUtils.isEmpty(info.getAppPackageName()) ||
info.getInstallReason() != PackageManager.INSTALL_REASON_USER) {
return;
}
if (TextUtils.isEmpty(info.getAppPackageName()) ||
info.getInstallReason() != PackageManager.INSTALL_REASON_USER) {
return;
}
queueAppIconAddition(context, info.getAppPackageName(), user);

View File

@ -58,7 +58,6 @@ public abstract class UserManagerCompat {
public abstract long getSerialNumberForUser(UserHandle user);
public abstract UserHandle getUserForSerialNumber(long serialNumber);
public abstract CharSequence getBadgedLabelForUser(CharSequence label, UserHandle user);
public abstract long getUserCreationTime(UserHandle user);
public abstract boolean isQuietModeEnabled(UserHandle user);
public abstract boolean isUserUnlocked(UserHandle user);

View File

@ -23,7 +23,6 @@ import android.os.UserHandle;
import android.os.UserManager;
import android.util.ArrayMap;
import com.android.launcher3.util.LongArrayMap;
import com.android.launcher3.util.ManagedProfileHeuristic;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@ -127,15 +126,5 @@ public class UserManagerCompatVL extends UserManagerCompat {
}
return mPm.getUserBadgedLabel(label, user);
}
@Override
public long getUserCreationTime(UserHandle user) {
SharedPreferences prefs = ManagedProfileHeuristic.prefs(mContext);
String key = USER_CREATION_TIME_KEY + getSerialNumberForUser(user);
if (!prefs.contains(key)) {
prefs.edit().putLong(key, System.currentTimeMillis()).apply();
}
return prefs.getLong(key, 0);
}
}

View File

@ -27,9 +27,4 @@ public class UserManagerCompatVM extends UserManagerCompatVL {
UserManagerCompatVM(Context context) {
super(context);
}
@Override
public long getUserCreationTime(UserHandle user) {
return mUserManager.getUserCreationTime(user);
}
}

View File

@ -17,10 +17,7 @@ package com.android.launcher3.model;
import android.content.Context;
import android.content.Intent;
import android.content.pm.LauncherActivityInfo;
import android.os.Process;
import android.os.UserHandle;
import android.util.ArrayMap;
import android.util.LongSparseArray;
import android.util.Pair;
import com.android.launcher3.AllAppsList;
@ -37,7 +34,6 @@ import com.android.launcher3.LauncherSettings;
import com.android.launcher3.ShortcutInfo;
import com.android.launcher3.Utilities;
import com.android.launcher3.util.GridOccupancy;
import com.android.launcher3.util.ManagedProfileHeuristic.UserFolderInfo;
import java.util.ArrayList;
import java.util.List;
@ -64,7 +60,6 @@ public class AddWorkspaceItemsTask extends BaseModelUpdateTask {
final ArrayList<ItemInfo> addedItemsFinal = new ArrayList<>();
final ArrayList<Long> addedWorkspaceScreensFinal = new ArrayList<>();
ArrayMap<UserHandle, UserFolderInfo> userFolderMap = new ArrayMap<>();
// Get the list of workspace screens. We need to append to this list and
// can not use sBgWorkspaceScreens because loadWorkspace() may not have been
@ -87,21 +82,6 @@ public class AddWorkspaceItemsTask extends BaseModelUpdateTask {
if (item instanceof AppInfo) {
item = ((AppInfo) item).makeShortcut();
}
if (!Process.myUserHandle().equals(item.user)) {
// Check if this belongs to a work folder.
if (!(entry.second instanceof LauncherActivityInfo)) {
continue;
}
UserFolderInfo userFolderInfo = userFolderMap.get(item.user);
if (userFolderInfo == null) {
userFolderInfo = new UserFolderInfo(context, item.user, dataModel);
userFolderMap.put(item.user, userFolderInfo);
}
item = userFolderInfo.convertToWorkspaceItem(
(ShortcutInfo) item, (LauncherActivityInfo) entry.second);
}
}
if (item != null) {
filteredItems.add(item);
@ -160,10 +140,6 @@ public class AddWorkspaceItemsTask extends BaseModelUpdateTask {
}
});
}
for (UserFolderInfo userFolderInfo : userFolderMap.values()) {
userFolderInfo.applyPendingState(getModelWriter());
}
}
protected void updateScreens(Context context, ArrayList<Long> workspaceScreens) {

View File

@ -62,7 +62,6 @@ import com.android.launcher3.shortcuts.ShortcutInfoCompat;
import com.android.launcher3.shortcuts.ShortcutKey;
import com.android.launcher3.util.ComponentKey;
import com.android.launcher3.util.LooperIdleLock;
import com.android.launcher3.util.ManagedProfileHeuristic;
import com.android.launcher3.util.MultiHashMap;
import com.android.launcher3.util.PackageManagerHelper;
import com.android.launcher3.util.Provider;
@ -812,8 +811,6 @@ public class LoaderTask implements Runnable {
// This builds the icon bitmaps.
mBgAllAppsList.add(new AppInfo(app, user, quietMode), app);
}
ManagedProfileHeuristic.onAllAppsLoaded(mApp.getContext(), apps, user);
}
if (FeatureFlags.LAUNCHER3_PROMISE_APPS_IN_ALL_APPS) {

View File

@ -1,254 +0,0 @@
/*
* Copyright (C) 2015 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.util;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.LauncherActivityInfo;
import android.os.Handler;
import android.os.Process;
import android.os.UserHandle;
import com.android.launcher3.FolderInfo;
import com.android.launcher3.InstallShortcutReceiver;
import com.android.launcher3.ItemInfo;
import com.android.launcher3.LauncherFiles;
import com.android.launcher3.LauncherModel;
import com.android.launcher3.MainThreadExecutor;
import com.android.launcher3.R;
import com.android.launcher3.SessionCommitReceiver;
import com.android.launcher3.ShortcutInfo;
import com.android.launcher3.Utilities;
import com.android.launcher3.compat.UserManagerCompat;
import com.android.launcher3.model.BgDataModel;
import com.android.launcher3.model.ModelWriter;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
/**
* Handles addition of app shortcuts for managed profiles.
* Methods of class should only be called on {@link LauncherModel#sWorkerThread}.
*/
public class ManagedProfileHeuristic {
private static final String USER_FOLDER_ID_PREFIX = "user_folder_";
/**
* Duration (in milliseconds) for which app shortcuts will be added to work folder.
*/
private static final long AUTO_ADD_TO_FOLDER_DURATION = 8 * 60 * 60 * 1000;
public static void onAllAppsLoaded(final Context context,
List<LauncherActivityInfo> apps, UserHandle user) {
if (Process.myUserHandle().equals(user)) {
return;
}
UserFolderInfo ufi = new UserFolderInfo(context, user, null);
// We only handle folder creation once. Later icon additions are handled using package
// or session events.
if (ufi.folderAlreadyCreated) {
return;
}
if (Utilities.ATLEAST_OREO && !SessionCommitReceiver.isEnabled(context)) {
// Just mark the folder id preference to avoid new folder creation later.
ufi.prefs.edit().putLong(ufi.folderIdKey, ItemInfo.NO_ID).apply();
return;
}
InstallShortcutReceiver.enableInstallQueue(InstallShortcutReceiver.FLAG_BULK_ADD);
for (LauncherActivityInfo app : apps) {
// Queue all items which should go in the work folder.
if (app.getFirstInstallTime() < ufi.addIconToFolderTime) {
InstallShortcutReceiver.queueActivityInfo(app, context);
}
}
// Post the queue update on next frame, so that the loader gets finished.
new Handler(LauncherModel.getWorkerLooper()).post(new Runnable() {
@Override
public void run() {
InstallShortcutReceiver.disableAndFlushInstallQueue(
InstallShortcutReceiver.FLAG_BULK_ADD, context);
}
});
}
/**
* Utility class to help workspace icon addition.
*/
public static class UserFolderInfo {
final ArrayList<ShortcutInfo> pendingShortcuts = new ArrayList<>();
final UserHandle user;
final long userSerial;
// Time until which icons will be added to folder instead.
final long addIconToFolderTime;
final String folderIdKey;
final SharedPreferences prefs;
final boolean folderAlreadyCreated;
final FolderInfo folderInfo;
boolean folderPendingAddition;
public UserFolderInfo(Context context, UserHandle user, BgDataModel dataModel) {
this.user = user;
UserManagerCompat um = UserManagerCompat.getInstance(context);
userSerial = um.getSerialNumberForUser(user);
addIconToFolderTime = um.getUserCreationTime(user) + AUTO_ADD_TO_FOLDER_DURATION;
folderIdKey = USER_FOLDER_ID_PREFIX + userSerial;
prefs = prefs(context);
folderAlreadyCreated = prefs.contains(folderIdKey);
if (dataModel != null) {
if (folderAlreadyCreated) {
long folderId = prefs.getLong(folderIdKey, ItemInfo.NO_ID);
folderInfo = dataModel.folders.get(folderId);
} else {
folderInfo = new FolderInfo();
folderInfo.title = context.getText(R.string.work_folder_name);
folderInfo.setOption(FolderInfo.FLAG_WORK_FOLDER, true, null);
folderPendingAddition = true;
}
} else {
folderInfo = null;
}
}
/**
* Returns the ItemInfo which should be added to the workspace. In case the the provided
* {@link ShortcutInfo} or a wrapped {@link FolderInfo} or null.
*/
public ItemInfo convertToWorkspaceItem(
ShortcutInfo shortcut, LauncherActivityInfo activityInfo) {
if (activityInfo.getFirstInstallTime() >= addIconToFolderTime) {
return shortcut;
}
if (folderAlreadyCreated) {
if (folderInfo == null) {
// Work folder was deleted by user, add icon to home screen.
return shortcut;
} else {
// Add item to work folder instead. Nothing needs to be added
// on the homescreen.
pendingShortcuts.add(shortcut);
return null;
}
}
pendingShortcuts.add(shortcut);
folderInfo.add(shortcut, false);
if (folderPendingAddition) {
folderPendingAddition = false;
return folderInfo;
} else {
// WorkFolder already requested to be added. Nothing new needs to be added.
return null;
}
}
public void applyPendingState(ModelWriter writer) {
if (folderInfo == null) {
return;
}
int startingRank = 0;
if (folderAlreadyCreated) {
startingRank = folderInfo.contents.size();
}
for (ShortcutInfo info : pendingShortcuts) {
info.rank = startingRank++;
writer.addItemToDatabase(info, folderInfo.id, 0, 0, 0);
}
if (folderAlreadyCreated) {
// FolderInfo could already be bound. We need to add shortcuts on the UI thread.
new MainThreadExecutor().execute(new Runnable() {
@Override
public void run() {
folderInfo.prepareAutoUpdate();
for (ShortcutInfo info : pendingShortcuts) {
folderInfo.add(info, false);
}
}
});
} else {
prefs.edit().putLong(folderIdKey, folderInfo.id).apply();
}
}
}
/**
* Verifies that entries corresponding to {@param users} exist and removes all invalid entries.
*/
public static void processAllUsers(List<UserHandle> users, Context context) {
UserManagerCompat userManager = UserManagerCompat.getInstance(context);
HashSet<String> validKeys = new HashSet<>();
for (UserHandle user : users) {
validKeys.add(USER_FOLDER_ID_PREFIX + userManager.getSerialNumberForUser(user));
}
SharedPreferences prefs = prefs(context);
SharedPreferences.Editor editor = prefs.edit();
for (String key : prefs.getAll().keySet()) {
if (!validKeys.contains(key)) {
editor.remove(key);
}
}
editor.apply();
}
/**
* For each user, if a work folder has not been created, mark it such that the folder will
* never get created.
*/
public static void markExistingUsersForNoFolderCreation(Context context) {
UserManagerCompat userManager = UserManagerCompat.getInstance(context);
UserHandle myUser = Process.myUserHandle();
SharedPreferences prefs = null;
for (UserHandle user : userManager.getUserProfiles()) {
if (myUser.equals(user)) {
continue;
}
if (prefs == null) {
prefs = prefs(context);
}
String folderIdKey = USER_FOLDER_ID_PREFIX + userManager.getSerialNumberForUser(user);
if (!prefs.contains(folderIdKey)) {
prefs.edit().putLong(folderIdKey, ItemInfo.NO_ID).apply();
}
}
}
public static SharedPreferences prefs(Context context) {
return context.getSharedPreferences(
LauncherFiles.MANAGED_USER_PREFERENCES_KEY, Context.MODE_PRIVATE);
}
}

View File

@ -15,6 +15,9 @@
*/
package com.android.launcher3.ui;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import android.app.Instrumentation;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
@ -34,7 +37,6 @@ import android.support.test.uiautomator.UiDevice;
import android.support.test.uiautomator.UiObject2;
import android.support.test.uiautomator.Until;
import android.view.MotionEvent;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.LauncherAppWidgetProviderInfo;
import com.android.launcher3.LauncherSettings;
@ -46,17 +48,11 @@ import com.android.launcher3.compat.LauncherAppsCompat;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.testcomponent.AppWidgetNoConfig;
import com.android.launcher3.testcomponent.AppWidgetWithConfig;
import com.android.launcher3.util.ManagedProfileHeuristic;
import org.junit.Before;
import java.util.Locale;
import java.util.concurrent.Callable;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import org.junit.Before;
/**
* Base class for all instrumentation tests providing various utility methods.
@ -221,7 +217,6 @@ public abstract class AbstractLauncherUiTest {
mMainThreadExecutor.execute(new Runnable() {
@Override
public void run() {
ManagedProfileHeuristic.markExistingUsersForNoFolderCreation(mTargetContext);
LauncherAppState.getInstance(mTargetContext).getModel().forceReload();
}
});