SetupWizard: Fix race condition on finish

Change-Id: Ie4a5893c49db7ce9622091e05776cb5523ed5c45
This commit is contained in:
cretin45 2015-03-06 14:01:53 -08:00
parent 226687c0b2
commit 7c8e091320

View File

@ -51,7 +51,8 @@ import com.cyanogenmod.setupwizard.util.SetupWizardUtils;
import java.util.ArrayList; import java.util.ArrayList;
public class SetupWizardActivity extends Activity implements SetupDataCallbacks { public class SetupWizardActivity extends Activity implements SetupDataCallbacks,
ThemeManager.ThemeChangeListener {
private static final String TAG = SetupWizardActivity.class.getSimpleName(); private static final String TAG = SetupWizardActivity.class.getSimpleName();
@ -76,8 +77,6 @@ public class SetupWizardActivity extends Activity implements SetupDataCallbacks
private final ArrayList<Runnable> mFinishRunnables = new ArrayList<Runnable>(); private final ArrayList<Runnable> mFinishRunnables = new ArrayList<Runnable>();
private ThemeManager.ThemeChangeListener mThemeChangeListener;
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
if (sLaunchTime == 0) { if (sLaunchTime == 0) {
@ -292,7 +291,21 @@ public class SetupWizardActivity extends Activity implements SetupDataCallbacks
mFinishingProgressBar.setIndeterminate(true); mFinishingProgressBar.setIndeterminate(true);
mFinishingProgressBar.startAnimation(fadeIn); mFinishingProgressBar.startAnimation(fadeIn);
final ThemeManager tm = (ThemeManager) getSystemService(Context.THEME_SERVICE); final ThemeManager tm = (ThemeManager) getSystemService(Context.THEME_SERVICE);
mThemeChangeListener = new ThemeManager.ThemeChangeListener() { tm.addClient(this);
mSetupData.finishPages();
SetupStats.addEvent(SetupStats.Categories.APP_FINISHED, TAG,
SetupStats.Label.TOTAL_TIME, String.valueOf(
System.nanoTime() - sLaunchTime));
setupWizardApp.sendStickyBroadcastAsUser(
new Intent(SetupWizardApp.ACTION_FINISHED),
UserHandle.getCallingUserHandle());
}
@Override
public void onFinish(boolean isSuccess) {
finishSetup();
}
@Override @Override
public void onProgress(int progress) { public void onProgress(int progress) {
if (progress > 0) { if (progress > 0) {
@ -301,33 +314,12 @@ public class SetupWizardActivity extends Activity implements SetupDataCallbacks
} }
} }
@Override
public void onFinish(boolean isSuccess) {
finishSetup();
}
};
tm.addClient(mThemeChangeListener);
mSetupData.finishPages();
SetupStats.addEvent(SetupStats.Categories.APP_FINISHED, TAG,
SetupStats.Label.TOTAL_TIME, String.valueOf(
System.nanoTime() - sLaunchTime));
}
@Override @Override
public void finishSetup() { public void finishSetup() {
if (!mIsFinishing) { if (!mIsFinishing) {
mIsFinishing = true; mIsFinishing = true;
mHandler.post(new Runnable() {
@Override
public void run() {
final SetupWizardApp setupWizardApp = (SetupWizardApp)getApplication();
setupWizardApp.sendStickyBroadcastAsUser(
new Intent(SetupWizardApp.ACTION_FINISHED),
UserHandle.getCallingUserHandle());
setupRevealImage(); setupRevealImage();
} }
});
}
} }
@Override @Override
@ -342,9 +334,6 @@ public class SetupWizardActivity extends Activity implements SetupDataCallbacks
mFinishingProgressBar.startAnimation(fadeOut); mFinishingProgressBar.startAnimation(fadeOut);
mFinishingProgressBar.setVisibility(View.INVISIBLE); mFinishingProgressBar.setVisibility(View.INVISIBLE);
final Thread t = new Thread() {
@Override
public void run() {
final Point p = new Point(); final Point p = new Point();
getWindowManager().getDefaultDisplay().getRealSize(p); getWindowManager().getDefaultDisplay().getRealSize(p);
final WallpaperManager wallpaperManager = final WallpaperManager wallpaperManager =
@ -357,25 +346,15 @@ public class SetupWizardActivity extends Activity implements SetupDataCallbacks
0, Math.min(p.x, wallpaper.getWidth()), 0, Math.min(p.x, wallpaper.getWidth()),
Math.min(p.y, wallpaper.getHeight())); Math.min(p.y, wallpaper.getHeight()));
} }
final Bitmap croppedWallpaper = cropped; if (cropped != null) {
mHandler.post(new Runnable() {
@Override
public void run() {
if (croppedWallpaper != null) {
mReveal.setScaleType(ImageView.ScaleType.CENTER_CROP); mReveal.setScaleType(ImageView.ScaleType.CENTER_CROP);
mReveal.setImageBitmap(croppedWallpaper); mReveal.setImageBitmap(cropped);
} else { } else {
mReveal.setBackground(wallpaperManager mReveal.setBackground(wallpaperManager
.getBuiltInDrawable(p.x, p.y, false, 0, 0)); .getBuiltInDrawable(p.x, p.y, false, 0, 0));
} }
animateOut(); animateOut();
} }
});
}
};
t.start();
}
private void animateOut() { private void animateOut() {
int cx = (mReveal.getLeft() + mReveal.getRight()) / 2; int cx = (mReveal.getLeft() + mReveal.getRight()) / 2;
@ -421,7 +400,7 @@ public class SetupWizardActivity extends Activity implements SetupDataCallbacks
} }
final ThemeManager tm = final ThemeManager tm =
(ThemeManager) SetupWizardActivity.this.getSystemService(THEME_SERVICE); (ThemeManager) SetupWizardActivity.this.getSystemService(THEME_SERVICE);
tm.removeClient(mThemeChangeListener); tm.removeClient(SetupWizardActivity.this);
SetupStats.sendEvents(SetupWizardActivity.this); SetupStats.sendEvents(SetupWizardActivity.this);
SetupWizardUtils.disableGMSSetupWizard(SetupWizardActivity.this); SetupWizardUtils.disableGMSSetupWizard(SetupWizardActivity.this);
Intent intent = new Intent(Intent.ACTION_MAIN); Intent intent = new Intent(Intent.ACTION_MAIN);