Commit f7b97b87 authored by Amit Kumar's avatar Amit Kumar

Fix icon reset issue and add support for work profile

parent 9b74e296
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="foundation.e.blisslauncher">
xmlns:tools="http://schemas.android.com/tools"
package="foundation.e.blisslauncher">
<permission
android:name="com.android.launcher.permission.INSTALL_SHORTCUT"
android:description="@string/permdesc_install_shortcut"
android:label="@string/permlab_install_shortcut"
android:permissionGroup="android.permission-group.SYSTEM_TOOLS"
android:protectionLevel="dangerous"/>
android:protectionLevel="dangerous" />
<permission
android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT"
android:permissionGroup="android.permission-group.SYSTEM_TOOLS"
android:protectionLevel="dangerous"
android:description="@string/permdesc_uninstall_shortcut"
android:label="@string/permlab_uninstall_shortcut"
android:description="@string/permdesc_uninstall_shortcut"/>
<!-- General -->
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
android:permissionGroup="android.permission-group.SYSTEM_TOOLS"
android:protectionLevel="dangerous" /> <!-- General -->
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.BIND_APPWIDGET" />
<uses-permission
android:name="android.permission.PACKAGE_USAGE_STATS"
tools:ignore="ProtectedPermissions"/>
tools:ignore="ProtectedPermissions" />
<uses-permission
android:name="android.permission.WRITE_SECURE_SETTINGS"
tools:ignore="ProtectedPermissions"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="lineageos.permission.ACCESS_WEATHER_MANAGER"/>
<uses-permission android:name="lineageos.permission.READ_WEATHER"/>
tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="lineageos.permission.ACCESS_WEATHER_MANAGER" />
<uses-permission android:name="lineageos.permission.READ_WEATHER" />
<application
android:name="BlissLauncher"
android:name=".BlissLauncher"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
......@@ -50,9 +48,10 @@
android:theme="@style/HomeScreenTheme"
android:windowSoftInputMode="adjustPan">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.HOME"/>
<category android:name="android.intent.category.DEFAULT"/>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
......@@ -60,38 +59,33 @@
android:name=".features.notification.NotificationService"
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">
<intent-filter>
<action android:name="android.service.notification.NotificationListenerService"/>
<action android:name="android.service.notification.NotificationListenerService" />
</intent-filter>
</service>
<activity
android:name=".features.weather.WeatherPreferences"
android:theme="@style/AppTheme">
</activity>
android:theme="@style/AppTheme"></activity>
<activity
android:name=".features.weather.PermissionRequestActivity"
android:excludeFromRecents="true"
android:exported="true"
android:noHistory="true"
android:theme="@android:style/Theme.Translucent.NoTitleBar"/>
<service android:name=".features.weather.WeatherUpdateService"/>
<service android:name=".features.weather.DeviceStatusService"/>
<service android:name=".features.weather.WeatherSourceListenerService"/>
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
<receiver android:name="core.broadcast.PackageAddedRemovedHandler"/>
<service android:name=".features.weather.WeatherUpdateService" />
<service android:name=".features.weather.DeviceStatusService" />
<service android:name=".features.weather.WeatherSourceListenerService" />
<!-- Intent received used to install shortcuts from other applications -->
<receiver android:name="core.broadcast.PackageAddedRemovedHandler" /> <!-- Intent received used to install shortcuts from other applications -->
<receiver
android:name=".features.shortcuts.InstallShortcutReceiver"
android:enabled="true"
android:permission="com.android.launcher.permission.INSTALL_SHORTCUT">
<intent-filter>
<action android:name="com.android.launcher.action.INSTALL_SHORTCUT"/>
<action android:name="com.android.launcher.action.INSTALL_SHORTCUT" />
</intent-filter>
</receiver>
<!-- Intent received used to uninstall shortcuts from other applications -->
</receiver> <!-- Intent received used to uninstall shortcuts from other applications -->
<receiver
android:name=".features.shortcuts.UninstallShortcutReceiver"
android:enabled="true"
......@@ -108,22 +102,23 @@
android:label="@string/action_add_to_workspace"
android:theme="@android:style/Theme.DeviceDefault.Light.Dialog.Alert">
<intent-filter>
<action android:name="android.content.pm.action.CONFIRM_PIN_SHORTCUT"/>
<action android:name="android.content.pm.action.CONFIRM_PIN_SHORTCUT" />
</intent-filter>
</activity>
<activity android:name=".features.widgets.WidgetsActivity"
android:autoRemoveFromRecents="true"
android:excludeFromRecents="true"
android:theme="@style/AppTheme"
android:label="Widgets"/>
<activity android:name=".features.widgets.WidgetPicker"
android:autoRemoveFromRecents="true"
android:excludeFromRecents="true"
android:theme="@style/WidgetPickerDialog"
android:finishOnCloseSystemDialogs="true"
android:label="Choose widget"
android:exported="true"/>
<activity
android:name=".features.widgets.WidgetsActivity"
android:autoRemoveFromRecents="true"
android:excludeFromRecents="true"
android:label="Widgets"
android:theme="@style/AppTheme" />
<activity
android:name=".features.widgets.WidgetPicker"
android:autoRemoveFromRecents="true"
android:excludeFromRecents="true"
android:exported="true"
android:finishOnCloseSystemDialogs="true"
android:label="Choose widget"
android:theme="@style/WidgetPickerDialog" />
</application>
</manifest>
\ No newline at end of file
......@@ -3,6 +3,7 @@ package foundation.e.blisslauncher.core;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.LauncherActivityInfo;
import android.content.pm.LauncherApps;
import android.content.pm.PackageManager;
......@@ -15,6 +16,7 @@ import android.graphics.Canvas;
import android.graphics.drawable.AdaptiveIconDrawable;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.UserManager;
import android.util.Log;
import org.w3c.dom.Document;
......@@ -34,6 +36,7 @@ import foundation.e.blisslauncher.BlissLauncher;
import foundation.e.blisslauncher.core.customviews.AdaptiveIconDrawableCompat;
import foundation.e.blisslauncher.core.utils.GraphicsUtil;
import foundation.e.blisslauncher.core.utils.UserHandle;
import foundation.e.blisslauncher.features.launcher.LauncherActivity;
/**
* Inspired from http://stackoverflow.com/questions/31490630/how-to-load-icon-from-icon-pack
......@@ -97,7 +100,6 @@ public class IconsHandler {
}
packagesDrawables.clear();
cacheClear();
// system icons, nothing to do
if (iconsPackPackageName.equalsIgnoreCase("default")) {
......@@ -133,17 +135,8 @@ public class IconsHandler {
}
private Drawable getDefaultAppDrawable(ComponentName componentName, UserHandle userHandle) {
try {
LauncherApps launcher = (LauncherApps) ctx.getSystemService(
Context.LAUNCHER_APPS_SERVICE);
LauncherActivityInfo info = launcher.getActivityList(componentName.getPackageName(),
userHandle.getRealHandle()).get(0);
return info.getBadgedIcon(0);
} catch (IndexOutOfBoundsException e) {
Log.e(TAG, "Unable to found component " + componentName.toString() + e);
return null;
}
private Drawable getDefaultAppDrawable(LauncherActivityInfo activityInfo, UserHandle userHandle) {
return activityInfo.getIcon(0);
}
public boolean isClock(String componentName) {
......@@ -160,18 +153,20 @@ public class IconsHandler {
/**
* Get or generate icon for an app
*/
public Drawable getDrawableIconForPackage(ComponentName componentName, UserHandle userHandle) {
public Drawable getDrawableIconForPackage(LauncherActivityInfo activityInfo, UserHandle userHandle) {
/* // system icons, nothing to do
if (iconsPackPackageName.equalsIgnoreCase("default")) {
return this.getDefaultAppDrawable(componentName, userHandle);
}*/
String drawable = packagesDrawables.get(componentName.toString());
ComponentName componentName = activityInfo.getComponentName();
String drawable = packagesDrawables.get(activityInfo.getComponentName().toString());
if (drawable != null) { //there is a custom icon
int id = iconPackres.getIdentifier(drawable, "drawable", iconsPackPackageName);
if (id > 0) {
//noinspection deprecation: Resources.getDrawable(int, Theme) requires SDK 21+
try {
return iconPackres.getDrawable(id);
return getBadgedIcon(iconPackres.getDrawable(id), activityInfo.getUser());
} catch (Resources.NotFoundException e) {
// Unable to load icon, keep going.
e.printStackTrace();
......@@ -179,13 +174,15 @@ public class IconsHandler {
}
}
String key = userHandle.addUserSuffixToString(componentName.flattenToString(), '/');
// Search first in cache
Drawable systemIcon = cacheGetDrawable(componentName.toString());
Drawable systemIcon = cacheGetDrawable(key);
if (systemIcon != null) {
return systemIcon;
}
systemIcon = this.getDefaultAppDrawable(componentName, userHandle);
systemIcon = this.getDefaultAppDrawable(activityInfo, userHandle);
if (Utilities.ATLEAST_OREO && systemIcon instanceof AdaptiveIconDrawable) {
systemIcon = new AdaptiveIconDrawableCompat(
((AdaptiveIconDrawable) systemIcon).getBackground(),
......@@ -201,8 +198,43 @@ public class IconsHandler {
}
}
cacheStoreDrawable(componentName.toString(), systemIcon);
return systemIcon;
Drawable badgedIcon = getBadgedIcon(systemIcon, activityInfo.getUser());
cacheStoreDrawable(key, badgedIcon);
return badgedIcon;
}
public void resetIconDrawableForPackage(ComponentName componentName, UserHandle userHandle) {
if (!packagesDrawables.containsKey(componentName.toString())) {
LauncherApps launcherApps = (LauncherApps) ctx.getSystemService(Context.LAUNCHER_APPS_SERVICE);
for (LauncherActivityInfo launcherActivityInfo : launcherApps.getActivityList(componentName.getPackageName(), userHandle.getRealHandle())) {
if (launcherActivityInfo.getComponentName().flattenToString().equals(componentName.flattenToString())) {
Drawable icon = this.getDefaultAppDrawable(launcherActivityInfo, userHandle);
if (Utilities.ATLEAST_OREO && icon instanceof AdaptiveIconDrawable) {
icon = new AdaptiveIconDrawableCompat(
((AdaptiveIconDrawable) icon).getBackground(),
((AdaptiveIconDrawable) icon).getForeground());
} else {
Drawable adaptiveIcon = new AdaptiveIconProvider().load(ctx,
componentName.getPackageName());
if (adaptiveIcon != null) {
icon = adaptiveIcon;
} else {
icon = graphicsUtil.convertToRoundedCorner(ctx,
graphicsUtil.addBackground(icon, false));
}
}
Drawable badgedIcon = getBadgedIcon(icon, launcherActivityInfo.getUser());
cacheStoreDrawable(userHandle.addUserSuffixToString(componentName.flattenToString(), '/'), badgedIcon);
}
}
}
}
private Drawable getBadgedIcon(Drawable icon, android.os.UserHandle userHandle) {
return ctx.getApplicationContext().getPackageManager().getUserBadgedIcon(icon, userHandle);
}
private boolean isDrawableInCache(String key) {
......@@ -211,7 +243,6 @@ public class IconsHandler {
}
private void cacheStoreDrawable(String key, Drawable drawable) {
Log.i(TAG, "cacheStoreDrawable: " + key);
Bitmap bitmap = getBitmapFromDrawable(drawable);
File drawableFile = cacheGetFileName(key);
FileOutputStream fos;
......@@ -259,7 +290,7 @@ public class IconsHandler {
* {cacheDir}/icons/{icons_pack_package_name}_{key_hash}.png
*/
private File cacheGetFileName(String key) {
return new File(getIconsCacheDir() + iconsPackPackageName + "_" + key.hashCode() + ".png");
return new File(getIconsCacheDir() + File.separator + iconsPackPackageName + "_" + key.hashCode() + ".png");
}
......@@ -267,7 +298,9 @@ public class IconsHandler {
* returns icons cache directory.
*/
private File getIconsCacheDir() {
return new File(this.ctx.getCacheDir().getPath() + "/icons/");
File file = new File(this.ctx.getCacheDir().getPath() + "/icons/");
file.mkdir();
return file;
}
/**
......@@ -287,28 +320,6 @@ public class IconsHandler {
}
}
public void resetIconDrawableForPackage(ComponentName componentName, UserHandle user) {
if (!packagesDrawables.containsKey(componentName.toString())) {
Drawable icon = this.getDefaultAppDrawable(componentName, user);
if (Utilities.ATLEAST_OREO && icon instanceof AdaptiveIconDrawable) {
icon = new AdaptiveIconDrawableCompat(
((AdaptiveIconDrawable) icon).getBackground(),
((AdaptiveIconDrawable) icon).getForeground());
} else {
Drawable adaptiveIcon = new AdaptiveIconProvider().load(ctx,
componentName.getPackageName());
if (adaptiveIcon != null) {
icon = adaptiveIcon;
} else {
icon = graphicsUtil.convertToRoundedCorner(ctx,
graphicsUtil.addBackground(icon, false));
}
}
cacheStoreDrawable(componentName.toString(), icon);
}
}
public Drawable convertIcon(Drawable icon) {
return graphicsUtil.convertToRoundedCorner(ctx,
graphicsUtil.addBackground(icon, false));
......@@ -319,7 +330,7 @@ public class IconsHandler {
* exist, it returns null.
*/
public static Drawable createIconDrawable(Intent.ShortcutIconResource iconRes,
Context context) {
Context context) {
PackageManager packageManager = context.getPackageManager();
// the resource
try {
......@@ -358,4 +369,9 @@ public class IconsHandler {
return (d != null) ? d : getFullResDefaultActivityIcon();
}
public void clearAll() {
packagesDrawables.clear();
cacheClear();
}
}
package foundation.e.blisslauncher.core.broadcast;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.UserHandle;
import android.util.Log;
import foundation.e.blisslauncher.core.events.Event;
import foundation.e.blisslauncher.core.events.EventRelay;
import foundation.e.blisslauncher.core.events.ForceReloadEvent;
public class ManagedProfileBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.i("PROFILE", "onReceive: "+intent.getAction());
final String action = intent.getAction();
if (Intent.ACTION_MANAGED_PROFILE_ADDED.equals(action)
|| Intent.ACTION_MANAGED_PROFILE_REMOVED.equals(action)) {
EventRelay.getInstance().push(new ForceReloadEvent());
} else if (Intent.ACTION_MANAGED_PROFILE_AVAILABLE.equals(action) ||
Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE.equals(action) ||
Intent.ACTION_MANAGED_PROFILE_UNLOCKED.equals(action)) {
UserHandle user = intent.getParcelableExtra(Intent.EXTRA_USER);
if (user != null) {
/*if (Intent.ACTION_MANAGED_PROFILE_AVAILABLE.equals(action) ||
Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE.equals(action)) {
//enqueueModelUpdateTask(new PackageUpdatedTask(PackageUpdatedTask.OP_USER_AVAILABILITY_CHANGE, user));
}
// ACTION_MANAGED_PROFILE_UNAVAILABLE sends the profile back to locked mode, so
// we need to run the state change task again.
if (Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE.equals(action) ||
Intent.ACTION_MANAGED_PROFILE_UNLOCKED.equals(action)) {
//enqueueModelUpdateTask(new UserLockStateChangedTask(user));
}*/
// TODO: Need to handle it more gracefully. Currently it just recreate the launcher.
EventRelay.getInstance().push(new ForceReloadEvent());
}
}
}
public static ManagedProfileBroadcastReceiver register(Context context) {
IntentFilter timeIntentFilter = new IntentFilter(Intent.ACTION_MANAGED_PROFILE_ADDED);
timeIntentFilter.addAction(Intent.ACTION_MANAGED_PROFILE_REMOVED);
timeIntentFilter.addAction(Intent.ACTION_MANAGED_PROFILE_AVAILABLE);
timeIntentFilter.addAction(Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE);
timeIntentFilter.addAction(Intent.ACTION_MANAGED_PROFILE_UNLOCKED);
ManagedProfileBroadcastReceiver receiver = new ManagedProfileBroadcastReceiver();
context.registerReceiver(receiver, timeIntentFilter);
return receiver;
}
public static void unregister(Context context, ManagedProfileBroadcastReceiver receiver) {
context.unregisterReceiver(receiver);
}
}
......@@ -3,6 +3,8 @@ package foundation.e.blisslauncher.core.broadcast;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Process;
import android.util.Log;
import org.greenrobot.eventbus.EventBus;
......@@ -10,6 +12,7 @@ import foundation.e.blisslauncher.BlissLauncher;
import foundation.e.blisslauncher.core.events.AppAddEvent;
import foundation.e.blisslauncher.core.events.AppChangeEvent;
import foundation.e.blisslauncher.core.events.AppRemoveEvent;
import foundation.e.blisslauncher.core.events.EventRelay;
import foundation.e.blisslauncher.core.utils.UserHandle;
import foundation.e.blisslauncher.features.launcher.AppProvider;
......@@ -18,7 +21,12 @@ public class PackageAddedRemovedHandler extends BroadcastReceiver {
private static final String TAG = "PackageAddedRemovedHand";
public static void handleEvent(Context ctx, String action, String packageName, UserHandle user,
boolean replacing) {
boolean replacing) {
if (!Process.myUserHandle().equals(user.getRealHandle())) {
return;
}
Log.d(TAG, "handleEvent() called with: ctx = [" + ctx + "], action = [" + action + "], packageName = [" + packageName + "], user = [" + user + "], replacing = [" + replacing + "]");
// Insert into history new packages (not updated ones)
if ("android.intent.action.PACKAGE_ADDED".equals(action) && !replacing) {
Intent launchIntent = ctx.getPackageManager().getLaunchIntentForPackage(packageName);
......@@ -26,11 +34,10 @@ public class PackageAddedRemovedHandler extends BroadcastReceiver {
return;
}
BlissLauncher.getApplication(ctx).resetIconsHandler();
BlissLauncher.getApplication(ctx).getIconsHandler().clearAll();
AppAddEvent appAddEvent = new AppAddEvent();
appAddEvent.packageName = packageName;
EventBus.getDefault().post(appAddEvent);
AppAddEvent event = new AppAddEvent(packageName, user);
EventRelay.getInstance().push(event);
}
if ("android.intent.action.PACKAGE_CHANGED".equalsIgnoreCase(action)) {
......@@ -40,23 +47,14 @@ public class PackageAddedRemovedHandler extends BroadcastReceiver {
launchIntent.getComponent(), user);
}
BlissLauncher.getApplication(ctx).resetIconsHandler();
AppChangeEvent appChangeEvent = new AppChangeEvent();
appChangeEvent.packageName = packageName;
EventBus.getDefault().post(appChangeEvent);
BlissLauncher.getApplication(ctx).getIconsHandler().clearAll();
AppChangeEvent event = new AppChangeEvent(packageName, user);
EventRelay.getInstance().push(event);
}
if ("android.intent.action.PACKAGE_REMOVED".equals(action) && !replacing) {
AppRemoveEvent appRemoveEvent = new AppRemoveEvent();
appRemoveEvent.packageName = packageName;
EventBus.getDefault().post(appRemoveEvent);
}
// Reload application list
final AppProvider provider = BlissLauncher.getApplication(ctx).getAppProvider();
if (provider != null) {
provider.reload();
AppRemoveEvent event = new AppRemoveEvent(packageName, user);
EventRelay.getInstance().push(event);
}
}
......
package foundation.e.blisslauncher.core.broadcast;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import foundation.e.blisslauncher.core.events.EventRelay;
import foundation.e.blisslauncher.core.events.TimeChangedEvent;
public class TimeChangeBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction() != null && (intent.getAction().equalsIgnoreCase(Intent.ACTION_TIME_CHANGED)
|| intent.getAction().equalsIgnoreCase(Intent.ACTION_DATE_CHANGED)
|| intent.getAction().equalsIgnoreCase(Intent.ACTION_TIMEZONE_CHANGED)))
EventRelay.getInstance().push(new TimeChangedEvent());
}
public static TimeChangeBroadcastReceiver register(Context context) {
IntentFilter timeIntentFilter = new IntentFilter(Intent.ACTION_TIME_CHANGED);
timeIntentFilter.addAction(Intent.ACTION_DATE_CHANGED);
timeIntentFilter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
TimeChangeBroadcastReceiver receiver = new TimeChangeBroadcastReceiver();
context.registerReceiver(receiver, timeIntentFilter);
return receiver;
}
public static void unregister(Context context, TimeChangeBroadcastReceiver receiver) {
context.unregisterReceiver(receiver);
}
}
package foundation.e.blisslauncher.core.database;
import android.content.Context;
import android.util.Log;
import android.widget.GridLayout;
import java.util.ArrayList;
import java.util.List;
import foundation.e.blisslauncher.core.customviews.BlissFrameLayout;
......@@ -46,6 +48,7 @@ public class DatabaseManager {
}
private void saveLauncherItems(final List<GridLayout> pages, final GridLayout dock) {
List<LauncherItem> items = new ArrayList<>();
for (int i = 0; i < dock.getChildCount(); i++) {
LauncherItem launcherItem = ((BlissFrameLayout) dock.getChildAt(i)).getLauncherItem();
if (launcherItem.itemType == Constants.ITEM_TYPE_FOLDER) {
......@@ -53,20 +56,20 @@ public class DatabaseManager {
folderItem.screenId = -1;
folderItem.cell = i;
folderItem.container = Constants.CONTAINER_HOTSEAT;
LauncherDB.getDatabase(mContext).launcherDao().insert(folderItem);
items.add(launcherItem);
for (int j = 0; j < folderItem.items.size(); j++) {
LauncherItem item = folderItem.items.get(j);
item.screenId = -1;
item.container = Long.parseLong(folderItem.id);
item.cell = j;
LauncherDB.getDatabase(mContext).launcherDao().insert(item);
items.add(item);
}
} else {
launcherItem.screenId = -1;
launcherItem.container = Constants.CONTAINER_HOTSEAT;
launcherItem.cell = i;
LauncherDB.getDatabase(mContext).launcherDao().insert(launcherItem);
items.add(launcherItem);
}
}
......@@ -80,22 +83,24 @@ public class DatabaseManager {
folderItem.screenId = i;
folderItem.cell = j;
folderItem.container = Constants.CONTAINER_DESKTOP;
LauncherDB.getDatabase(mContext).launcherDao().insert(folderItem);
items.add(folderItem);
for (int k = 0; k < folderItem.items.size(); k++) {
LauncherItem item = folderItem.items.get(k);
item.screenId = -1;
item.container = Long.parseLong(folderItem.id);
item.cell = k;
LauncherDB.getDatabase(mContext).launcherDao().insert(item);
items.add(item);
}
} else {
launcherItem.screenId = i;
launcherItem.container = Constants.CONTAINER_DESKTOP;
launcherItem.cell = j;
LauncherDB.getDatabase(mContext).launcherDao().insert(launcherItem);
items.add(launcherItem);
}
}
}
Log.i("Database", "saveLauncherItems: "+items.size());
LauncherDB.getDatabase(mContext).launcherDao().insertAll(items);
}
public void removeShortcut(String name) {
......@@ -110,17 +115,17 @@ public class DatabaseManager {
new_component_name);
}
public Single<Integer> getHeightOfWidget(int id){
public Single<Integer> getHeightOfWidget(int id) {
return Single.defer(() -> Single.just(LauncherDB.getDatabase(mContext).widgetDao().getHeight(id)));
}
public void saveWidget(int id, int height){
public void saveWidget(int id, int height) {
WidgetItem widgetItem = new WidgetItem(id, height);
mAppExecutors.diskIO().execute(
() -> LauncherDB.getDatabase(mContext).widgetDao().insert(widgetItem));
}
public void removeWidget(int id){
public void removeWidget(int id) {
mAppExecutors.diskIO().execute(() -> LauncherDB.getDatabase(mContext).widgetDao().delete(id));
}
}
......@@ -7,6 +7,9 @@ import android.arch.persistence.room.RoomDatabase;
import android.arch.persistence.room.TypeConverters;
import android.arch.persistence.room.migration.Migration;
import android.content.Context;
import android.os.Process;
import android.os.UserManager;
import android.support.annotation.NonNull;
import foundation.e.blisslauncher.core.database.converters.CharSequenceConverter;
import foundation.e.blisslauncher.core.database.daos.LauncherDao;
......@@ -31,7 +34,13 @@ public abstract class LauncherDB extends RoomDatabase {
}
};
public static LauncherDB getDatabase(Context context){
private static final Migration MIGRATION_4_5 = new Migration(4, 5) {
@Override
public void migrate(@NonNull SupportSQLiteDatabase database) {
}
};
public static LauncherDB getDatabase(Context context) {
if (INSTANCE == null) {
synchronized (LauncherDB.class) {
if (INSTANCE == null) {
......@@ -44,4 +53,20 @@ public abstract class LauncherDB extends RoomDatabase {
}
return INSTANCE;
}
private static final class UserHandleMigration extends Migration {
private long userSerialNumber;
public UserHandleMigration(int startVersion, int endVersion, long userSerialNumber) {
super(startVersion, endVersion);
this.userSerialNumber = userSerialNumber;
}
@Override
public void migrate(@NonNull SupportSQLiteDatabase database) {
String suffix = "\"/" + userSerialNumber +"\"";
String query = "UPDATE launcher_items set item_id=item_id || " + suffix + "WHERE item_type <> 2";
database.execSQL(query);
}
}
}
......@@ -5,10 +5,10 @@ import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.LauncherActivityInfo;
import android.os.UserHandle;
import foundation.e.blisslauncher.core.UserManagerCompat;
import foundation.e.blisslauncher.core.utils.Constants;