Merge "Refactor usage of getting GRID_OPTIONS_PREFERENCE_KEY value into whether GridOptionsProvider is enabled" into ub-launcher3-rvc-dev
This commit is contained in:
@@ -19,7 +19,6 @@ package com.android.launcher3;
|
||||
import static com.android.launcher3.Utilities.getDevicePrefs;
|
||||
import static com.android.launcher3.Utilities.getPointString;
|
||||
import static com.android.launcher3.config.FeatureFlags.APPLY_CONFIG_AT_RUNTIME;
|
||||
import static com.android.launcher3.settings.SettingsActivity.GRID_OPTIONS_PREFERENCE_KEY;
|
||||
import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
|
||||
import static com.android.launcher3.util.PackageManagerHelper.getPackageFilter;
|
||||
|
||||
@@ -29,7 +28,6 @@ import android.content.BroadcastReceiver;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.content.res.TypedArray;
|
||||
@@ -216,9 +214,8 @@ public class InvariantDeviceProfile {
|
||||
}
|
||||
|
||||
public static String getCurrentGridName(Context context) {
|
||||
SharedPreferences prefs = Utilities.getPrefs(context);
|
||||
return prefs.getBoolean(GRID_OPTIONS_PREFERENCE_KEY, false)
|
||||
? prefs.getString(KEY_IDP_GRID_NAME, null) : null;
|
||||
return Utilities.isGridOptionsEnabled(context)
|
||||
? Utilities.getPrefs(context).getString(KEY_IDP_GRID_NAME, null) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -263,7 +260,7 @@ public class InvariantDeviceProfile {
|
||||
iconTextSize = displayOption.iconTextSize;
|
||||
fillResIconDpi = getLauncherIconDensity(iconBitmapSize);
|
||||
|
||||
if (Utilities.getPrefs(context).getBoolean(GRID_OPTIONS_PREFERENCE_KEY, false)) {
|
||||
if (Utilities.isGridOptionsEnabled(context)) {
|
||||
allAppsIconSize = displayOption.allAppsIconSize;
|
||||
allAppsIconTextSize = displayOption.allAppsIconTextSize;
|
||||
} else {
|
||||
@@ -344,9 +341,7 @@ public class InvariantDeviceProfile {
|
||||
InvariantDeviceProfile oldProfile = new InvariantDeviceProfile(this);
|
||||
|
||||
// Re-init grid
|
||||
String gridName = Utilities.getPrefs(context).getBoolean(GRID_OPTIONS_PREFERENCE_KEY, false)
|
||||
? Utilities.getPrefs(context).getString(KEY_IDP_GRID_NAME, null)
|
||||
: null;
|
||||
String gridName = getCurrentGridName(context);
|
||||
initGrid(context, gridName);
|
||||
|
||||
int changeFlags = 0;
|
||||
|
||||
@@ -24,10 +24,13 @@ import android.app.ActivityManager;
|
||||
import android.app.Person;
|
||||
import android.app.WallpaperManager;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.LauncherActivityInfo;
|
||||
import android.content.pm.LauncherApps;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.content.pm.ShortcutInfo;
|
||||
import android.content.res.Resources;
|
||||
@@ -62,6 +65,7 @@ import android.view.animation.Interpolator;
|
||||
|
||||
import com.android.launcher3.config.FeatureFlags;
|
||||
import com.android.launcher3.dragndrop.FolderAdaptiveIcon;
|
||||
import com.android.launcher3.graphics.GridOptionsProvider;
|
||||
import com.android.launcher3.graphics.TintedDrawableSpan;
|
||||
import com.android.launcher3.icons.IconProvider;
|
||||
import com.android.launcher3.icons.LauncherIcons;
|
||||
@@ -76,6 +80,7 @@ import com.android.launcher3.util.PackageManagerHelper;
|
||||
import com.android.launcher3.widget.PendingAddShortcutInfo;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.regex.Matcher;
|
||||
@@ -509,6 +514,42 @@ public final class Utilities {
|
||||
|| e.getCause() instanceof DeadObjectException;
|
||||
}
|
||||
|
||||
public static boolean isGridOptionsEnabled(Context context) {
|
||||
return isComponentEnabled(context.getPackageManager(),
|
||||
context.getPackageName(),
|
||||
GridOptionsProvider.class.getName());
|
||||
}
|
||||
|
||||
private static boolean isComponentEnabled(PackageManager pm, String pkgName, String clsName) {
|
||||
ComponentName componentName = new ComponentName(pkgName, clsName);
|
||||
int componentEnabledSetting = pm.getComponentEnabledSetting(componentName);
|
||||
|
||||
switch (componentEnabledSetting) {
|
||||
case PackageManager.COMPONENT_ENABLED_STATE_DISABLED:
|
||||
return false;
|
||||
case PackageManager.COMPONENT_ENABLED_STATE_ENABLED:
|
||||
return true;
|
||||
case PackageManager.COMPONENT_ENABLED_STATE_DEFAULT:
|
||||
default:
|
||||
// We need to get the application info to get the component's default state
|
||||
try {
|
||||
PackageInfo packageInfo = pm.getPackageInfo(pkgName,
|
||||
PackageManager.GET_PROVIDERS | PackageManager.GET_DISABLED_COMPONENTS);
|
||||
|
||||
if (packageInfo.providers != null) {
|
||||
return Arrays.stream(packageInfo.providers).anyMatch(
|
||||
pi -> pi.name.equals(clsName) && pi.isEnabled());
|
||||
}
|
||||
|
||||
// the component is not declared in the AndroidManifest
|
||||
return false;
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
// the package isn't installed on the device
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility method to post a runnable on the handler, skipping the synchronization barriers.
|
||||
*/
|
||||
|
||||
@@ -71,7 +71,7 @@ public class SettingsActivity extends FragmentActivity
|
||||
private static final int DELAY_HIGHLIGHT_DURATION_MILLIS = 600;
|
||||
public static final String SAVE_HIGHLIGHTED_KEY = "android:preference_highlighted";
|
||||
|
||||
public static final String GRID_OPTIONS_PREFERENCE_KEY = "pref_grid_options";
|
||||
private static final String GRID_OPTIONS_PREFERENCE_KEY = "pref_grid_options";
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
Reference in New Issue
Block a user