Merge "Tightening migration conditions. (Bug 11973614)" into jb-ub-now-kermit

This commit is contained in:
Winson Chung
2014-01-15 19:42:39 +00:00
committed by Android (Google) Code Review
3 changed files with 57 additions and 22 deletions
+26 -3
View File
@@ -41,6 +41,7 @@ import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.pm.ActivityInfo; import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ResolveInfo; import android.content.pm.ResolveInfo;
@@ -478,11 +479,18 @@ public class Launcher extends Activity
// On large interfaces, we want the screen to auto-rotate based on the current orientation // On large interfaces, we want the screen to auto-rotate based on the current orientation
unlockScreenOrientation(true); unlockScreenOrientation(true);
// The two first run cling paths are mutually exclusive, if the launcher is preinstalled
// on the device, then we always show the first run cling experience (or if there is no
// launcher2). Otherwise, we prompt the user upon started for migration
showFirstRunActivity(); showFirstRunActivity();
if (mModel.canMigrateFromOldLauncherDb()) { if (mLauncherClings.shouldShowFirstRunOrMigrationClings()) {
mLauncherClings.showMigrationCling(); if (mModel.canMigrateFromOldLauncherDb(this)) {
mLauncherClings.showMigrationCling();
} else {
mLauncherClings.showFirstRunCling();
}
} else { } else {
mLauncherClings.showFirstRunCling(); mLauncherClings.removeFirstRunAndMigrationClings();
} }
} }
@@ -4280,6 +4288,21 @@ public class Launcher extends Activity
mLauncherClings.updateSearchBarHint(hint); mLauncherClings.updateSearchBarHint(hint);
} }
protected boolean isLauncherPreinstalled() {
PackageManager pm = getPackageManager();
try {
ApplicationInfo ai = pm.getApplicationInfo(getComponentName().getPackageName(), 0);
if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
return true;
} else {
return false;
}
} catch (NameNotFoundException e) {
e.printStackTrace();
return false;
}
}
protected String getFirstRunClingSearchBarHint() { protected String getFirstRunClingSearchBarHint() {
return ""; return "";
} }
+29 -17
View File
@@ -200,14 +200,27 @@ class LauncherClings {
} }
} }
/** Shows the first run cling */ public boolean shouldShowFirstRunOrMigrationClings() {
public void showFirstRunCling() {
SharedPreferences sharedPrefs = mLauncher.getSharedPrefs(); SharedPreferences sharedPrefs = mLauncher.getSharedPrefs();
if (isClingsEnabled() && return isClingsEnabled() &&
!sharedPrefs.getBoolean(FIRST_RUN_CLING_DISMISSED_KEY, false) && !sharedPrefs.getBoolean(FIRST_RUN_CLING_DISMISSED_KEY, false) &&
!skipCustomClingIfNoAccounts() ) { !sharedPrefs.getBoolean(MIGRATION_CLING_DISMISSED_KEY, false);
}
public void removeFirstRunAndMigrationClings() {
removeCling(R.id.first_run_cling);
removeCling(R.id.migration_cling);
}
/**
* Shows the first run cling.
*
* This flow is mutually exclusive with showMigrationCling, and only runs if this Launcher
* package was preinstalled or there is no db to migrate from.
*/
public void showFirstRunCling() {
if (!skipCustomClingIfNoAccounts()) {
SharedPreferences sharedPrefs = mLauncher.getSharedPrefs();
// If we're not using the default workspace layout, replace workspace cling // If we're not using the default workspace layout, replace workspace cling
// with a custom workspace cling (usually specified in an overlay) // with a custom workspace cling (usually specified in an overlay)
// For now, only do this on tablets // For now, only do this on tablets
@@ -238,22 +251,22 @@ class LauncherClings {
} }
initCling(R.id.first_run_cling, 0, false, true); initCling(R.id.first_run_cling, 0, false, true);
} else { } else {
removeCling(R.id.first_run_cling); removeFirstRunAndMigrationClings();
} }
} }
/**
* Shows the migration cling.
*
* This flow is mutually exclusive with showFirstRunCling, and only runs if this Launcher
* package was not preinstalled and there exists a db to migrate from.
*/
public void showMigrationCling() { public void showMigrationCling() {
// Enable the clings only if they have not been dismissed before mLauncher.hideWorkspaceSearchAndHotseat();
if (isClingsEnabled() && !mLauncher.getSharedPrefs().getBoolean(
MIGRATION_CLING_DISMISSED_KEY, false)) {
mLauncher.hideWorkspaceSearchAndHotseat();
Cling c = initCling(R.id.migration_cling, 0, false, true); Cling c = initCling(R.id.migration_cling, 0, false, true);
c.bringScrimToFront(); c.bringScrimToFront();
c.bringToFront(); c.bringToFront();
} else {
removeCling(R.id.migration_cling);
}
} }
public void showMigrationWorkspaceCling() { public void showMigrationWorkspaceCling() {
@@ -300,7 +313,6 @@ class LauncherClings {
} }
} }
/** Removes the cling outright from the DragLayer */ /** Removes the cling outright from the DragLayer */
private void removeCling(int id) { private void removeCling(int id) {
final View cling = mLauncher.findViewById(id); final View cling = mLauncher.findViewById(id);
+2 -2
View File
@@ -227,8 +227,8 @@ public class LauncherModel extends BroadcastReceiver {
} }
} }
boolean canMigrateFromOldLauncherDb() { boolean canMigrateFromOldLauncherDb(Launcher launcher) {
return mOldContentProviderExists; return mOldContentProviderExists && !launcher.isLauncherPreinstalled() ;
} }
static boolean findNextAvailableIconSpaceInScreen(ArrayList<ItemInfo> items, int[] xy, static boolean findNextAvailableIconSpaceInScreen(ArrayList<ItemInfo> items, int[] xy,