Removing some obsolete features:ENABLE_MINIMAL_DEVICE, ENABLE_DATABASE_RESTORE

Bug: 270392984
Bug: 270392706
Test: Presubmit
Flag: N/A
Change-Id: I58c3e76de521e702fb44ccfc14c9b5a731b1d511
This commit is contained in:
Sunny Goyal
2023-04-07 11:25:54 -07:00
parent 8744d8b6f1
commit 895392e923
6 changed files with 1 additions and 156 deletions
@@ -47,11 +47,7 @@ import androidx.annotation.Nullable;
import androidx.annotation.WorkerThread;
import com.android.launcher3.BaseDraggingActivity;
import com.android.launcher3.InvariantDeviceProfile;
import com.android.launcher3.LauncherProvider;
import com.android.launcher3.LauncherSettings;
import com.android.launcher3.R;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.model.data.ItemInfo;
import com.android.launcher3.popup.RemoteActionShortcut;
import com.android.launcher3.popup.SystemShortcut;
@@ -73,21 +69,14 @@ public final class WellbeingModel extends BgObjectWithLooper {
private static final int[] RETRY_TIMES_MS = {5000, 15000, 30000};
private static final boolean DEBUG = false;
private static final int UNKNOWN_MINIMAL_DEVICE_STATE = 0;
private static final int IN_MINIMAL_DEVICE = 2;
// Welbeing contract
private static final String PATH_ACTIONS = "actions";
private static final String PATH_MINIMAL_DEVICE = "minimal_device";
private static final String METHOD_GET_MINIMAL_DEVICE_CONFIG = "get_minimal_device_config";
private static final String METHOD_GET_ACTIONS = "get_actions";
private static final String EXTRA_ACTIONS = "actions";
private static final String EXTRA_ACTION = "action";
private static final String EXTRA_MAX_NUM_ACTIONS_SHOWN = "max_num_actions_shown";
private static final String EXTRA_PACKAGES = "packages";
private static final String EXTRA_SUCCESS = "success";
private static final String EXTRA_MINIMAL_DEVICE_STATE = "minimal_device_state";
private static final String DB_NAME_MINIMAL_DEVICE = "minimal.db";
public static final MainThreadInitializedObject<WellbeingModel> INSTANCE =
new MainThreadInitializedObject<>(WellbeingModel::new);
@@ -137,36 +126,7 @@ public final class WellbeingModel extends BgObjectWithLooper {
@WorkerThread
private void onWellbeingUriChanged(Uri uri) {
Preconditions.assertNonUiThread();
if (DEBUG || mIsInTest) {
Log.d(TAG, "ContentObserver.onChange() called with: uri = [" + uri + "]");
}
if (uri.getPath().contains(PATH_ACTIONS)) {
// Wellbeing reports that app actions have changed.
updateAllPackages();
} else if (uri.getPath().contains(PATH_MINIMAL_DEVICE)) {
// Wellbeing reports that minimal device state or config is changed.
if (!FeatureFlags.ENABLE_MINIMAL_DEVICE.get()) {
return;
}
// Temporary bug fix for b/169771796. Wellbeing provides the layout configuration when
// minimal device is enabled. We always want to reload the configuration from Wellbeing
// since the layout configuration might have changed.
mContext.deleteDatabase(DB_NAME_MINIMAL_DEVICE);
final Bundle extras = new Bundle();
String dbFile;
if (isInMinimalDeviceMode()) {
dbFile = DB_NAME_MINIMAL_DEVICE;
extras.putString(LauncherProvider.KEY_LAYOUT_PROVIDER_AUTHORITY,
mWellbeingProviderPkg + ".api");
} else {
dbFile = InvariantDeviceProfile.INSTANCE.get(mContext).dbFile;
}
LauncherSettings.Settings.call(mContext.getContentResolver(),
LauncherSettings.Settings.METHOD_SWITCH_DATABASE,
dbFile, extras);
}
updateAllPackages();
}
public void setInTest(boolean inTest) {
@@ -178,12 +138,9 @@ public final class WellbeingModel extends BgObjectWithLooper {
final ContentResolver resolver = mContext.getContentResolver();
resolver.unregisterContentObserver(mContentObserver);
Uri actionsUri = apiBuilder().path(PATH_ACTIONS).build();
Uri minimalDeviceUri = apiBuilder().path(PATH_MINIMAL_DEVICE).build();
try {
resolver.registerContentObserver(
actionsUri, true /* notifyForDescendants */, mContentObserver);
resolver.registerContentObserver(
minimalDeviceUri, true /* notifyForDescendants */, mContentObserver);
} catch (Exception e) {
Log.e(TAG, "Failed to register content observer for " + actionsUri + ": " + e);
if (mIsInTest) throw new RuntimeException(e);
@@ -227,32 +184,6 @@ public final class WellbeingModel extends BgObjectWithLooper {
.authority(mWellbeingProviderPkg + ".api");
}
@WorkerThread
private boolean isInMinimalDeviceMode() {
if (!FeatureFlags.ENABLE_MINIMAL_DEVICE.get()) {
return false;
}
if (DEBUG || mIsInTest) {
Log.d(TAG, "isInMinimalDeviceMode() called");
}
Preconditions.assertNonUiThread();
final Uri contentUri = apiBuilder().build();
try (ContentProviderClient client = mContext.getContentResolver()
.acquireUnstableContentProviderClient(contentUri)) {
final Bundle remoteBundle = client == null ? null : client.call(
METHOD_GET_MINIMAL_DEVICE_CONFIG, null /* args */, null /* extras */);
return remoteBundle != null
&& remoteBundle.getInt(EXTRA_MINIMAL_DEVICE_STATE,
UNKNOWN_MINIMAL_DEVICE_STATE) == IN_MINIMAL_DEVICE;
} catch (Exception e) {
Log.e(TAG, "Failed to retrieve data from " + contentUri + ": " + e);
if (mIsInTest) throw new RuntimeException(e);
}
if (DEBUG || mIsInTest) Log.i(TAG, "isInMinimalDeviceMode(): finished");
return false;
}
@WorkerThread
private boolean updateActions(String[] packageNames) {
if (packageNames.length == 0) {
@@ -22,7 +22,6 @@ import static com.android.launcher3.provider.LauncherDbUtils.dropTable;
import static com.android.launcher3.provider.LauncherDbUtils.tableExists;
import android.annotation.TargetApi;
import android.app.backup.BackupManager;
import android.appwidget.AppWidgetManager;
import android.content.ComponentName;
import android.content.ContentProvider;
@@ -85,7 +84,6 @@ import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Locale;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;
import java.util.stream.Collectors;
@@ -94,7 +92,6 @@ public class LauncherProvider extends ContentProvider {
private static final boolean LOGD = false;
private static final String DOWNGRADE_SCHEMA_FILE = "downgrade_schema.json";
private static final long RESTORE_BACKUP_TABLE_DELAY = TimeUnit.SECONDS.toMillis(30);
/**
* Represents the schema of the database. Changes in scheme need not be backwards compatible.
@@ -114,8 +111,6 @@ public class LauncherProvider extends ContentProvider {
protected DatabaseHelper mOpenHelper;
protected String mProviderAuthority;
private long mLastRestoreTimestamp = 0L;
private int mDefaultWorkspaceLayoutOverride = 0;
/**
@@ -374,13 +369,6 @@ public class LauncherProvider extends ContentProvider {
clearFlagEmptyDbCreated();
return null;
}
case LauncherSettings.Settings.METHOD_WAS_EMPTY_DB_CREATED : {
Bundle result = new Bundle();
result.putBoolean(LauncherSettings.Settings.EXTRA_VALUE,
LauncherPrefs.getPrefs(getContext()).getBoolean(
mOpenHelper.getKey(EMPTY_DATABASE_CREATED), false));
return result;
}
case LauncherSettings.Settings.METHOD_DELETE_EMPTY_FOLDERS: {
Bundle result = new Bundle();
result.putIntArray(LauncherSettings.Settings.EXTRA_VALUE, deleteEmptyFolders()
@@ -438,25 +426,11 @@ public class LauncherProvider extends ContentProvider {
new SQLiteTransaction(mOpenHelper.getWritableDatabase()));
return result;
}
case LauncherSettings.Settings.METHOD_REFRESH_BACKUP_TABLE: {
mOpenHelper.mBackupTableExists = tableExists(mOpenHelper.getReadableDatabase(),
Favorites.BACKUP_TABLE_NAME);
return null;
}
case LauncherSettings.Settings.METHOD_REFRESH_HOTSEAT_RESTORE_TABLE: {
mOpenHelper.mHotseatRestoreTableExists = tableExists(
mOpenHelper.getReadableDatabase(), Favorites.HYBRID_HOTSEAT_BACKUP_TABLE);
return null;
}
case LauncherSettings.Settings.METHOD_RESTORE_BACKUP_TABLE: {
final long ts = System.currentTimeMillis();
if (ts - mLastRestoreTimestamp > RESTORE_BACKUP_TABLE_DELAY) {
mLastRestoreTimestamp = ts;
RestoreDbTask.restoreIfPossible(
getContext(), mOpenHelper, new BackupManager(getContext()));
}
return null;
}
case LauncherSettings.Settings.METHOD_UPDATE_CURRENT_OPEN_HELPER: {
Bundle result = new Bundle();
result.putBoolean(LauncherSettings.Settings.EXTRA_VALUE,
@@ -479,22 +453,6 @@ public class LauncherProvider extends ContentProvider {
() -> mOpenHelper));
return result;
}
case LauncherSettings.Settings.METHOD_SWITCH_DATABASE: {
if (TextUtils.equals(arg, mOpenHelper.getDatabaseName())) return null;
final DatabaseHelper helper = mOpenHelper;
if (extras == null || !extras.containsKey(KEY_LAYOUT_PROVIDER_AUTHORITY)) {
mProviderAuthority = null;
} else {
mProviderAuthority = extras.getString(KEY_LAYOUT_PROVIDER_AUTHORITY);
}
mOpenHelper = DatabaseHelper.createDatabaseHelper(
getContext(), arg, false /* forMigration */);
helper.close();
LauncherAppState app = LauncherAppState.getInstanceNoCreate();
if (app == null) return null;
app.getModel().forceReload();
return null;
}
}
return null;
}
@@ -666,7 +624,6 @@ public class LauncherProvider extends ContentProvider {
private final Context mContext;
private final boolean mForMigration;
private int mMaxItemId = -1;
private boolean mBackupTableExists;
private boolean mHotseatRestoreTableExists;
static DatabaseHelper createDatabaseHelper(Context context, boolean forMigration) {
@@ -727,10 +684,6 @@ public class LauncherProvider extends ContentProvider {
}
protected void onAddOrDeleteOp(SQLiteDatabase db) {
if (mBackupTableExists) {
dropTable(db, Favorites.BACKUP_TABLE_NAME);
mBackupTableExists = false;
}
if (mHotseatRestoreTableExists) {
dropTable(db, Favorites.HYBRID_HOTSEAT_BACKUP_TABLE);
mHotseatRestoreTableExists = false;
@@ -380,7 +380,6 @@ public class LauncherSettings {
LauncherProvider.AUTHORITY + "/settings");
public static final String METHOD_CLEAR_EMPTY_DB_FLAG = "clear_empty_db_flag";
public static final String METHOD_WAS_EMPTY_DB_CREATED = "get_empty_db_flag";
public static final String METHOD_DELETE_EMPTY_FOLDERS = "delete_empty_folders";
@@ -404,18 +403,12 @@ public class LauncherSettings {
public static final String METHOD_NEW_TRANSACTION = "new_db_transaction";
public static final String METHOD_REFRESH_BACKUP_TABLE = "refresh_backup_table";
public static final String METHOD_REFRESH_HOTSEAT_RESTORE_TABLE = "restore_hotseat_table";
public static final String METHOD_RESTORE_BACKUP_TABLE = "restore_backup_table";
public static final String METHOD_UPDATE_CURRENT_OPEN_HELPER = "update_current_open_helper";
public static final String METHOD_PREP_FOR_PREVIEW = "prep_for_preview";
public static final String METHOD_SWITCH_DATABASE = "switch_database";
public static final String EXTRA_VALUE = "value";
public static final String EXTRA_DB_NAME = "db_name";
@@ -71,7 +71,6 @@ public class SessionCommitReceiver extends BroadcastReceiver {
}
InstallSessionHelper packageInstallerCompat = InstallSessionHelper.INSTANCE.get(context);
packageInstallerCompat.restoreDbIfApplicable(info);
if (TextUtils.isEmpty(info.getAppPackageName())
|| info.getInstallReason() != PackageManager.INSTALL_REASON_USER
|| packageInstallerCompat.promiseIconAddedForId(info.getSessionId())) {
@@ -131,10 +131,6 @@ public final class FeatureFlags {
"ASSISTANT_GIVES_LAUNCHER_FOCUS", DISABLED,
"Allow Launcher to handle nav bar gestures while Assistant is running over it");
public static final BooleanFlag ENABLE_DATABASE_RESTORE = getDebugFlag(270392706,
"ENABLE_DATABASE_RESTORE", DISABLED,
"Enable database restore when new restore session is created");
public static final BooleanFlag ENABLE_OVERLAY_CONNECTION_OPTIM = getDebugFlag(270392629,
"ENABLE_OVERLAY_CONNECTION_OPTIM", DISABLED,
"Enable optimizing overlay service connection");
@@ -154,10 +150,6 @@ public final class FeatureFlags {
"SEPARATE_RECENTS_ACTIVITY", DISABLED,
"Uses a separate recents activity instead of using the integrated recents+Launcher UI");
public static final BooleanFlag ENABLE_MINIMAL_DEVICE = getDebugFlag(270392984,
"ENABLE_MINIMAL_DEVICE", DISABLED,
"Allow user to toggle minimal device mode in launcher.");
public static final BooleanFlag ENABLE_TWO_PANEL_HOME = getDebugFlag(270392643,
"ENABLE_TWO_PANEL_HOME", ENABLED,
"Uses two panel on home screen. Only applicable on large screen devices.");
@@ -29,14 +29,11 @@ import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.annotation.WorkerThread;
import com.android.launcher3.LauncherPrefs;
import com.android.launcher3.LauncherSettings;
import com.android.launcher3.SessionCommitReceiver;
import com.android.launcher3.Utilities;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.logging.FileLog;
import com.android.launcher3.model.ItemInstallQueue;
import com.android.launcher3.testing.shared.TestProtocol;
@@ -204,26 +201,6 @@ public class InstallSessionHelper {
return list;
}
/**
* Attempt to restore workspace layout if the session is triggered due to device restore.
*/
public boolean restoreDbIfApplicable(@NonNull final SessionInfo info) {
if (!FeatureFlags.ENABLE_DATABASE_RESTORE.get()) {
return false;
}
if (isRestore(info)) {
LauncherSettings.Settings.call(mAppContext.getContentResolver(),
LauncherSettings.Settings.METHOD_RESTORE_BACKUP_TABLE);
return true;
}
return false;
}
@RequiresApi(26)
private static boolean isRestore(@NonNull final SessionInfo info) {
return info.getInstallReason() == PackageManager.INSTALL_REASON_DEVICE_RESTORE;
}
@WorkerThread
public boolean promiseIconAddedForId(final int sessionId) {
return getPromiseIconIds().contains(sessionId);