summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSunny Goyal <sunnygoyal@google.com>2015-03-30 11:11:46 -0700
committerSunny Goyal <sunnygoyal@google.com>2015-04-01 10:20:18 -0700
commit1d4a2df091e2b5928406ea503321563a0ec8a01e (patch)
tree335f495845942a76a80c972fa849cc198510ad82 /src
parente9909f58c2b235f8066295c4faa6a00415968ae7 (diff)
downloadandroid_packages_apps_Trebuchet-1d4a2df091e2b5928406ea503321563a0ec8a01e.tar.gz
android_packages_apps_Trebuchet-1d4a2df091e2b5928406ea503321563a0ec8a01e.tar.bz2
android_packages_apps_Trebuchet-1d4a2df091e2b5928406ea503321563a0ec8a01e.zip
Removing ContentObserver from LauncherModel, and calling reload
whereever necessary Change-Id: Ia4a8abdfe2be9703f3217a60527d3a1220b33bdc
Diffstat (limited to 'src')
-rw-r--r--src/com/android/launcher3/AppWidgetsRestoredReceiver.java5
-rw-r--r--src/com/android/launcher3/AutoInstallsLayout.java2
-rw-r--r--src/com/android/launcher3/Folder.java2
-rw-r--r--src/com/android/launcher3/Launcher.java8
-rw-r--r--src/com/android/launcher3/LauncherAppState.java27
-rw-r--r--src/com/android/launcher3/LauncherBackupAgentHelper.java2
-rw-r--r--src/com/android/launcher3/LauncherBackupHelper.java2
-rw-r--r--src/com/android/launcher3/LauncherModel.java28
-rw-r--r--src/com/android/launcher3/LauncherProvider.java26
-rw-r--r--src/com/android/launcher3/LauncherSettings.java27
-rw-r--r--src/com/android/launcher3/Workspace.java3
11 files changed, 51 insertions, 81 deletions
diff --git a/src/com/android/launcher3/AppWidgetsRestoredReceiver.java b/src/com/android/launcher3/AppWidgetsRestoredReceiver.java
index 880aaf1ec..5e7a012d2 100644
--- a/src/com/android/launcher3/AppWidgetsRestoredReceiver.java
+++ b/src/com/android/launcher3/AppWidgetsRestoredReceiver.java
@@ -90,5 +90,10 @@ public class AppWidgetsRestoredReceiver extends BroadcastReceiver {
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
}
+
+ LauncherAppState app = LauncherAppState.getInstanceNoCreate();
+ if (app != null) {
+ app.reloadWorkspace();
+ }
}
}
diff --git a/src/com/android/launcher3/AutoInstallsLayout.java b/src/com/android/launcher3/AutoInstallsLayout.java
index 9180dcf42..dac79a8ef 100644
--- a/src/com/android/launcher3/AutoInstallsLayout.java
+++ b/src/com/android/launcher3/AutoInstallsLayout.java
@@ -606,7 +606,7 @@ public class AutoInstallsLayout {
// failed to add, and less than 2 were actually added
if (folderItems.size() < 2) {
// Delete the folder
- Uri uri = Favorites.getContentUri(folderId, false);
+ Uri uri = Favorites.getContentUri(folderId);
SqlArguments args = new SqlArguments(uri, null, null);
mDb.delete(args.table, args.where, args.args);
addedId = -1;
diff --git a/src/com/android/launcher3/Folder.java b/src/com/android/launcher3/Folder.java
index 23582cec8..4529a9459 100644
--- a/src/com/android/launcher3/Folder.java
+++ b/src/com/android/launcher3/Folder.java
@@ -845,7 +845,7 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
View v = list.get(i);
ItemInfo info = (ItemInfo) v.getTag();
LauncherModel.addItemToDatabase(mLauncher, info, mInfo.id, 0,
- info.cellX, info.cellY, false);
+ info.cellX, info.cellY);
}
}
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index 8a9db71ac..8a21d624c 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -1554,7 +1554,7 @@ public class Launcher extends Activity
return;
}
- LauncherModel.addItemToDatabase(this, info, container, screenId, cellXY[0], cellXY[1], false);
+ LauncherModel.addItemToDatabase(this, info, container, screenId, cellXY[0], cellXY[1]);
if (!mRestoring) {
mWorkspace.addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1,
@@ -1616,7 +1616,7 @@ public class Launcher extends Activity
launcherInfo.user = mAppWidgetManager.getUser(appWidgetInfo);
LauncherModel.addItemToDatabase(this, launcherInfo,
- container, screenId, info.cellX, info.cellY, false);
+ container, screenId, info.cellX, info.cellY);
if (!mRestoring) {
if (hostView == null) {
@@ -2409,8 +2409,8 @@ public class Launcher extends Activity
folderInfo.title = getText(R.string.folder_name);
// Update the model
- LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId, cellX, cellY,
- false);
+ LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId,
+ cellX, cellY);
sFolders.put(folderInfo.id, folderInfo);
// Create the view
diff --git a/src/com/android/launcher3/LauncherAppState.java b/src/com/android/launcher3/LauncherAppState.java
index 555b1ccad..2a08b8176 100644
--- a/src/com/android/launcher3/LauncherAppState.java
+++ b/src/com/android/launcher3/LauncherAppState.java
@@ -19,16 +19,13 @@ package com.android.launcher3;
import android.annotation.TargetApi;
import android.app.SearchManager;
import android.content.ComponentName;
-import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Configuration;
import android.content.res.Resources;
-import android.database.ContentObserver;
import android.graphics.Point;
import android.os.Build;
-import android.os.Handler;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Display;
@@ -116,11 +113,6 @@ public class LauncherAppState implements DeviceProfile.DeviceProfileCallbacks {
filter.addAction(SearchManager.INTENT_GLOBAL_SEARCH_ACTIVITY_CHANGED);
filter.addAction(SearchManager.INTENT_ACTION_SEARCHABLES_CHANGED);
sContext.registerReceiver(mModel, filter);
-
- // Register for changes to the favorites
- ContentResolver resolver = sContext.getContentResolver();
- resolver.registerContentObserver(LauncherSettings.Favorites.CONTENT_URI, true,
- mFavoritesObserver);
}
/**
@@ -131,23 +123,16 @@ public class LauncherAppState implements DeviceProfile.DeviceProfileCallbacks {
final LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(sContext);
launcherApps.removeOnAppsChangedCallback(mModel);
PackageInstallerCompat.getInstance(sContext).onStop();
-
- ContentResolver resolver = sContext.getContentResolver();
- resolver.unregisterContentObserver(mFavoritesObserver);
}
/**
- * Receives notifications whenever the user favorites have changed.
+ * Reloads the workspace items from the DB and re-binds the workspace. This should generally
+ * not be called as DB updates are automatically followed by UI update
*/
- private final ContentObserver mFavoritesObserver = new ContentObserver(new Handler()) {
- @Override
- public void onChange(boolean selfChange) {
- // If the database has ever changed, then we really need to force a reload of the
- // workspace on the next load
- mModel.resetLoadedState(false, true);
- mModel.startLoaderFromBackground();
- }
- };
+ public void reloadWorkspace() {
+ mModel.resetLoadedState(false, true);
+ mModel.startLoaderFromBackground();
+ }
LauncherModel setLauncher(Launcher launcher) {
mModel.initialize(launcher);
diff --git a/src/com/android/launcher3/LauncherBackupAgentHelper.java b/src/com/android/launcher3/LauncherBackupAgentHelper.java
index ddfd70d6b..5f7173fac 100644
--- a/src/com/android/launcher3/LauncherBackupAgentHelper.java
+++ b/src/com/android/launcher3/LauncherBackupAgentHelper.java
@@ -78,7 +78,7 @@ public class LauncherBackupAgentHelper extends BackupAgentHelper {
super.onRestore(data, appVersionCode, newState);
// If no favorite was migrated, clear the data and start fresh.
final Cursor c = getContentResolver().query(
- LauncherSettings.Favorites.CONTENT_URI_NO_NOTIFICATION, null, null, null, null);
+ LauncherSettings.Favorites.CONTENT_URI, null, null, null, null);
hasData = c.moveToNext();
c.close();
} catch (Exception e) {
diff --git a/src/com/android/launcher3/LauncherBackupHelper.java b/src/com/android/launcher3/LauncherBackupHelper.java
index c03480065..064f4363a 100644
--- a/src/com/android/launcher3/LauncherBackupHelper.java
+++ b/src/com/android/launcher3/LauncherBackupHelper.java
@@ -462,7 +462,7 @@ public class LauncherBackupHelper implements BackupHelper {
ContentResolver cr = mContext.getContentResolver();
ContentValues values = unpackFavorite(buffer, dataSize);
- cr.insert(Favorites.CONTENT_URI_NO_NOTIFICATION, values);
+ cr.insert(Favorites.CONTENT_URI, values);
}
/**
diff --git a/src/com/android/launcher3/LauncherModel.java b/src/com/android/launcher3/LauncherModel.java
index dcb375928..c6ed0da82 100644
--- a/src/com/android/launcher3/LauncherModel.java
+++ b/src/com/android/launcher3/LauncherModel.java
@@ -566,7 +566,7 @@ public class LauncherModel extends BroadcastReceiver
// Add the shortcut to the db
addItemToDatabase(context, shortcutInfo,
LauncherSettings.Favorites.CONTAINER_DESKTOP,
- screenId, cordinates[0], cordinates[1], false);
+ screenId, cordinates[0], cordinates[1]);
// Save the ShortcutInfo for binding in the workspace
addedShortcutsFinal.add(shortcutInfo);
}
@@ -652,7 +652,7 @@ public class LauncherModel extends BroadcastReceiver
long screenId, int cellX, int cellY) {
if (item.container == ItemInfo.NO_ID) {
// From all apps
- addItemToDatabase(context, item, container, screenId, cellX, cellY, false);
+ addItemToDatabase(context, item, container, screenId, cellX, cellY);
} else {
// From somewhere else
moveItemInDatabase(context, item, container, screenId, cellX, cellY);
@@ -718,7 +718,7 @@ public class LauncherModel extends BroadcastReceiver
static void updateItemInDatabaseHelper(Context context, final ContentValues values,
final ItemInfo item, final String callingFunction) {
final long itemId = item.id;
- final Uri uri = LauncherSettings.Favorites.getContentUri(itemId, false);
+ final Uri uri = LauncherSettings.Favorites.getContentUri(itemId);
final ContentResolver cr = context.getContentResolver();
final StackTraceElement[] stackTrace = new Throwable().getStackTrace();
@@ -744,7 +744,7 @@ public class LauncherModel extends BroadcastReceiver
for (int i = 0; i < count; i++) {
ItemInfo item = items.get(i);
final long itemId = item.id;
- final Uri uri = LauncherSettings.Favorites.getContentUri(itemId, false);
+ final Uri uri = LauncherSettings.Favorites.getContentUri(itemId);
ContentValues values = valuesList.get(i);
ops.add(ContentProviderOperation.newUpdate(uri).withValues(values).build());
@@ -994,7 +994,7 @@ public class LauncherModel extends BroadcastReceiver
* cellY fields of the item. Also assigns an ID to the item.
*/
static void addItemToDatabase(Context context, final ItemInfo item, final long container,
- final long screenId, final int cellX, final int cellY, final boolean notify) {
+ final long screenId, final int cellX, final int cellY) {
item.container = container;
item.cellX = cellX;
item.cellY = cellY;
@@ -1017,8 +1017,7 @@ public class LauncherModel extends BroadcastReceiver
final StackTraceElement[] stackTrace = new Throwable().getStackTrace();
Runnable r = new Runnable() {
public void run() {
- cr.insert(notify ? LauncherSettings.Favorites.CONTENT_URI :
- LauncherSettings.Favorites.CONTENT_URI_NO_NOTIFICATION, values);
+ cr.insert(LauncherSettings.Favorites.CONTENT_URI, values);
// Lock on mBgLock *after* the db operation
synchronized (sBgLock) {
@@ -1102,7 +1101,7 @@ public class LauncherModel extends BroadcastReceiver
Runnable r = new Runnable() {
public void run() {
for (ItemInfo item : items) {
- final Uri uri = LauncherSettings.Favorites.getContentUri(item.id, false);
+ final Uri uri = LauncherSettings.Favorites.getContentUri(item.id);
cr.delete(uri, null, null);
// Lock on mBgLock *after* the db operation
@@ -1197,7 +1196,7 @@ public class LauncherModel extends BroadcastReceiver
Runnable r = new Runnable() {
public void run() {
- cr.delete(LauncherSettings.Favorites.getContentUri(info.id, false), null, null);
+ cr.delete(LauncherSettings.Favorites.getContentUri(info.id), null, null);
// Lock on mBgLock *after* the db operation
synchronized (sBgLock) {
sBgItemsIdMap.remove(info.id);
@@ -1205,7 +1204,7 @@ public class LauncherModel extends BroadcastReceiver
sBgWorkspaceItems.remove(info);
}
- cr.delete(LauncherSettings.Favorites.CONTENT_URI_NO_NOTIFICATION,
+ cr.delete(LauncherSettings.Favorites.CONTENT_URI,
LauncherSettings.Favorites.CONTAINER + "=" + info.id, null);
// Lock on mBgLock *after* the db operation
synchronized (sBgLock) {
@@ -1823,7 +1822,7 @@ public class LauncherModel extends BroadcastReceiver
final ArrayList<Long> itemsToRemove = new ArrayList<Long>();
final ArrayList<Long> restoredRows = new ArrayList<Long>();
- final Uri contentUri = LauncherSettings.Favorites.CONTENT_URI_NO_NOTIFICATION;
+ final Uri contentUri = LauncherSettings.Favorites.CONTENT_URI;
if (DEBUG_LOADERS) Log.d(TAG, "loading model from " + contentUri);
final Cursor c = contentResolver.query(contentUri, null, null, null, null);
@@ -2304,8 +2303,7 @@ public class LauncherModel extends BroadcastReceiver
}
// Don't notify content observers
try {
- client.delete(LauncherSettings.Favorites.getContentUri(id, false),
- null, null);
+ client.delete(LauncherSettings.Favorites.getContentUri(id), null, null);
} catch (RemoteException e) {
Log.w(TAG, "Could not remove id = " + id);
}
@@ -2324,7 +2322,7 @@ public class LauncherModel extends BroadcastReceiver
selectionBuilder.append(")");
ContentValues values = new ContentValues();
values.put(LauncherSettings.Favorites.RESTORED, 0);
- updater.update(LauncherSettings.Favorites.CONTENT_URI_NO_NOTIFICATION,
+ updater.update(LauncherSettings.Favorites.CONTENT_URI,
values, selectionBuilder.toString(), null);
} catch (RemoteException e) {
Log.w(TAG, "Could not update restored rows");
@@ -2395,7 +2393,7 @@ public class LauncherModel extends BroadcastReceiver
*/
private void updateItem(long itemId, ContentValues update) {
mContext.getContentResolver().update(
- LauncherSettings.Favorites.CONTENT_URI_NO_NOTIFICATION,
+ LauncherSettings.Favorites.CONTENT_URI,
update,
BaseColumns._ID + "= ?",
new String[]{Long.toString(itemId)});
diff --git a/src/com/android/launcher3/LauncherProvider.java b/src/com/android/launcher3/LauncherProvider.java
index dfacfa3e4..a23553a04 100644
--- a/src/com/android/launcher3/LauncherProvider.java
+++ b/src/com/android/launcher3/LauncherProvider.java
@@ -70,7 +70,6 @@ public class LauncherProvider extends ContentProvider {
static final String TABLE_FAVORITES = "favorites";
static final String TABLE_WORKSPACE_SCREENS = "workspaceScreens";
- static final String PARAMETER_NOTIFY = "notify";
static final String EMPTY_DATABASE_CREATED = "EMPTY_DATABASE_CREATED";
private static final String URI_PARAM_IS_EXTERNAL_ADD = "isExternalAdd";
@@ -150,7 +149,8 @@ public class LauncherProvider extends ContentProvider {
// In very limited cases, we support system|signature permission apps to add to the db
String externalAdd = uri.getQueryParameter(URI_PARAM_IS_EXTERNAL_ADD);
- if (externalAdd != null && "true".equals(externalAdd)) {
+ final boolean isExternalAll = externalAdd != null && "true".equals(externalAdd);
+ if (isExternalAll) {
if (!mOpenHelper.initializeExternalAdd(initialValues)) {
return null;
}
@@ -162,7 +162,14 @@ public class LauncherProvider extends ContentProvider {
if (rowId < 0) return null;
uri = ContentUris.withAppendedId(uri, rowId);
- sendNotify(uri);
+ notifyListeners();
+
+ if (isExternalAll) {
+ LauncherAppState app = LauncherAppState.getInstanceNoCreate();
+ if (app != null) {
+ app.reloadWorkspace();
+ }
+ }
return uri;
}
@@ -187,7 +194,7 @@ public class LauncherProvider extends ContentProvider {
db.endTransaction();
}
- sendNotify(uri);
+ notifyListeners();
return values.length;
}
@@ -211,7 +218,7 @@ public class LauncherProvider extends ContentProvider {
SQLiteDatabase db = mOpenHelper.getWritableDatabase();
int count = db.delete(args.table, args.where, args.args);
- if (count > 0) sendNotify(uri);
+ if (count > 0) notifyListeners();
return count;
}
@@ -223,17 +230,12 @@ public class LauncherProvider extends ContentProvider {
addModifiedTime(values);
SQLiteDatabase db = mOpenHelper.getWritableDatabase();
int count = db.update(args.table, values, args.where, args.args);
- if (count > 0) sendNotify(uri);
+ if (count > 0) notifyListeners();
return count;
}
- private void sendNotify(Uri uri) {
- String notify = uri.getQueryParameter(PARAMETER_NOTIFY);
- if (notify == null || "true".equals(notify)) {
- getContext().getContentResolver().notifyChange(uri, null);
- }
-
+ private void notifyListeners() {
// always notify the backup agent
LauncherBackupAgentHelper.dataChanged(getContext());
if (mListener != null) {
diff --git a/src/com/android/launcher3/LauncherSettings.java b/src/com/android/launcher3/LauncherSettings.java
index d161fbb3d..d657cb50f 100644
--- a/src/com/android/launcher3/LauncherSettings.java
+++ b/src/com/android/launcher3/LauncherSettings.java
@@ -109,8 +109,7 @@ class LauncherSettings {
* The content:// style URL for this table
*/
static final Uri CONTENT_URI = Uri.parse("content://" +
- LauncherProvider.AUTHORITY + "/" + LauncherProvider.TABLE_WORKSPACE_SCREENS +
- "?" + LauncherProvider.PARAMETER_NOTIFY + "=true");
+ LauncherProvider.AUTHORITY + "/" + LauncherProvider.TABLE_WORKSPACE_SCREENS);
/**
* The rank of this screen -- ie. how it is ordered relative to the other screens.
@@ -127,36 +126,18 @@ class LauncherSettings {
* The content:// style URL for this table
*/
static final Uri CONTENT_URI = Uri.parse("content://" +
- LauncherProvider.AUTHORITY + "/" + LauncherProvider.TABLE_FAVORITES +
- "?" + LauncherProvider.PARAMETER_NOTIFY + "=true");
-
- /**
- * The content:// style URL for this table
- */
- static final Uri OLD_CONTENT_URI = Uri.parse("content://" +
- LauncherProvider.OLD_AUTHORITY + "/" + LauncherProvider.TABLE_FAVORITES +
- "?" + LauncherProvider.PARAMETER_NOTIFY + "=true");
-
- /**
- * The content:// style URL for this table. When this Uri is used, no notification is
- * sent if the content changes.
- */
- static final Uri CONTENT_URI_NO_NOTIFICATION = Uri.parse("content://" +
- LauncherProvider.AUTHORITY + "/" + LauncherProvider.TABLE_FAVORITES +
- "?" + LauncherProvider.PARAMETER_NOTIFY + "=false");
+ LauncherProvider.AUTHORITY + "/" + LauncherProvider.TABLE_FAVORITES);
/**
* The content:// style URL for a given row, identified by its id.
*
* @param id The row id.
- * @param notify True to send a notification is the content changes.
*
* @return The unique content URL for the specified row.
*/
- static Uri getContentUri(long id, boolean notify) {
+ static Uri getContentUri(long id) {
return Uri.parse("content://" + LauncherProvider.AUTHORITY +
- "/" + LauncherProvider.TABLE_FAVORITES + "/" + id + "?" +
- LauncherProvider.PARAMETER_NOTIFY + "=" + notify);
+ "/" + LauncherProvider.TABLE_FAVORITES + "/" + id);
}
/**
diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java
index ad15a6c33..a79add05f 100644
--- a/src/com/android/launcher3/Workspace.java
+++ b/src/com/android/launcher3/Workspace.java
@@ -4323,8 +4323,7 @@ public class Workspace extends SmoothPagedView
cellX = hotseat.getCellXFromOrder((int) info.screenId);
cellY = hotseat.getCellYFromOrder((int) info.screenId);
}
- LauncherModel.addItemToDatabase(mLauncher, info, container, screenId, cellX,
- cellY, false);
+ LauncherModel.addItemToDatabase(mLauncher, info, container, screenId, cellX, cellY);
}
if (v instanceof FolderIcon) {
FolderIcon fi = (FolderIcon) v;