Fixing widget id restore broadcast. am: f5b4b80972
Change-Id: Ib5ae4d080a48f2a2d0839ffd233c70f8972ecdc0
diff --git a/src/com/android/launcher3/AppWidgetsRestoredReceiver.java b/src/com/android/launcher3/AppWidgetsRestoredReceiver.java
index 70be7da..6e33d2a 100644
--- a/src/com/android/launcher3/AppWidgetsRestoredReceiver.java
+++ b/src/com/android/launcher3/AppWidgetsRestoredReceiver.java
@@ -9,10 +9,12 @@
import android.content.Intent;
import android.database.Cursor;
import android.os.Handler;
+import android.support.annotation.WorkerThread;
import android.util.Log;
import com.android.launcher3.LauncherSettings.Favorites;
import com.android.launcher3.model.LoaderTask;
+import com.android.launcher3.provider.RestoreDbTask;
import com.android.launcher3.util.ContentWriter;
public class AppWidgetsRestoredReceiver extends BroadcastReceiver {
@@ -22,6 +24,12 @@
@Override
public void onReceive(final Context context, Intent intent) {
if (AppWidgetManager.ACTION_APPWIDGET_HOST_RESTORED.equals(intent.getAction())) {
+ int hostId = intent.getIntExtra(AppWidgetManager.EXTRA_HOST_ID, 0);
+ Log.d(TAG, "Widget ID map received for host:" + hostId);
+ if (hostId != Launcher.APPWIDGET_HOST_ID) {
+ return;
+ }
+
final int[] oldIds = intent.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_OLD_IDS);
final int[] newIds = intent.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS);
if (oldIds.length == newIds.length) {
@@ -42,11 +50,23 @@
/**
* Updates the app widgets whose id has changed during the restore process.
*/
+ @WorkerThread
static void restoreAppWidgetIds(Context context, PendingResult asyncResult,
int[] oldWidgetIds, int[] newWidgetIds) {
+ AppWidgetHost appWidgetHost = new AppWidgetHost(context, Launcher.APPWIDGET_HOST_ID);
+ if (!RestoreDbTask.isPending(context)) {
+ // Someone has already gone through our DB once, probably LoaderTask. Skip any further
+ // modifications of the DB.
+ Log.e(TAG, "Skipping widget ID remap as DB already in use");
+ for (int widgetId : newWidgetIds) {
+ Log.d(TAG, "Deleting widgetId: " + widgetId);
+ appWidgetHost.deleteAppWidgetId(widgetId);
+ }
+ asyncResult.finish();
+ return;
+ }
final ContentResolver cr = context.getContentResolver();
final AppWidgetManager widgets = AppWidgetManager.getInstance(context);
- AppWidgetHost appWidgetHost = new AppWidgetHost(context, Launcher.APPWIDGET_HOST_ID);
for (int i = 0; i < oldWidgetIds.length; i++) {
Log.i(TAG, "Widget state restore id " + oldWidgetIds[i] + " => " + newWidgetIds[i]);
diff --git a/src/com/android/launcher3/allapps/search/DefaultAppSearchAlgorithm.java b/src/com/android/launcher3/allapps/search/DefaultAppSearchAlgorithm.java
index 8a0fd46..4303302 100644
--- a/src/com/android/launcher3/allapps/search/DefaultAppSearchAlgorithm.java
+++ b/src/com/android/launcher3/allapps/search/DefaultAppSearchAlgorithm.java
@@ -132,7 +132,8 @@
// Always a break point for a symbol
return true;
default:
- return false;
+ // Always a break point at first character
+ return prevType == Character.UNASSIGNED;
}
}
}
diff --git a/src/com/android/launcher3/provider/RestoreDbTask.java b/src/com/android/launcher3/provider/RestoreDbTask.java
index 00e2644..5230160 100644
--- a/src/com/android/launcher3/provider/RestoreDbTask.java
+++ b/src/com/android/launcher3/provider/RestoreDbTask.java
@@ -134,7 +134,7 @@
}
public static void setPending(Context context, boolean isPending) {
- FileLog.d(TAG, "Restore data received through full backup");
+ FileLog.d(TAG, "Restore data received through full backup " + isPending);
Utilities.getPrefs(context).edit().putBoolean(RESTORE_TASK_PENDING, isPending).commit();
}
}
diff --git a/tests/src/com/android/launcher3/allapps/search/DefaultAppSearchAlgorithmTest.java b/tests/src/com/android/launcher3/allapps/search/DefaultAppSearchAlgorithmTest.java
index 20b23b0..58dc0c4 100644
--- a/tests/src/com/android/launcher3/allapps/search/DefaultAppSearchAlgorithmTest.java
+++ b/tests/src/com/android/launcher3/allapps/search/DefaultAppSearchAlgorithmTest.java
@@ -71,6 +71,10 @@
// match lower case words
assertTrue(mAlgorithm.matches(getInfo("elephant"), "e"));
+ assertTrue(mAlgorithm.matches(getInfo("电子邮件"), "电"));
+ assertTrue(mAlgorithm.matches(getInfo("电子邮件"), "电子"));
+ assertFalse(mAlgorithm.matches(getInfo("电子邮件"), "子"));
+ assertFalse(mAlgorithm.matches(getInfo("电子邮件"), "邮件"));
}
private AppInfo getInfo(String title) {