SetupWizard: Fix race condition on finish
Change-Id: Ie4a5893c49db7ce9622091e05776cb5523ed5c45
This commit is contained in:
parent
226687c0b2
commit
7c8e091320
@ -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,41 +291,34 @@ 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);
|
||||||
@Override
|
|
||||||
public void onProgress(int progress) {
|
|
||||||
if (progress > 0) {
|
|
||||||
mFinishingProgressBar.setIndeterminate(false);
|
|
||||||
mFinishingProgressBar.setProgress(progress);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onFinish(boolean isSuccess) {
|
|
||||||
finishSetup();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
tm.addClient(mThemeChangeListener);
|
|
||||||
mSetupData.finishPages();
|
mSetupData.finishPages();
|
||||||
SetupStats.addEvent(SetupStats.Categories.APP_FINISHED, TAG,
|
SetupStats.addEvent(SetupStats.Categories.APP_FINISHED, TAG,
|
||||||
SetupStats.Label.TOTAL_TIME, String.valueOf(
|
SetupStats.Label.TOTAL_TIME, String.valueOf(
|
||||||
System.nanoTime() - sLaunchTime));
|
System.nanoTime() - sLaunchTime));
|
||||||
|
setupWizardApp.sendStickyBroadcastAsUser(
|
||||||
|
new Intent(SetupWizardApp.ACTION_FINISHED),
|
||||||
|
UserHandle.getCallingUserHandle());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFinish(boolean isSuccess) {
|
||||||
|
finishSetup();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onProgress(int progress) {
|
||||||
|
if (progress > 0) {
|
||||||
|
mFinishingProgressBar.setIndeterminate(false);
|
||||||
|
mFinishingProgressBar.setProgress(progress);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void finishSetup() {
|
public void finishSetup() {
|
||||||
if (!mIsFinishing) {
|
if (!mIsFinishing) {
|
||||||
mIsFinishing = true;
|
mIsFinishing = true;
|
||||||
mHandler.post(new Runnable() {
|
setupRevealImage();
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
final SetupWizardApp setupWizardApp = (SetupWizardApp)getApplication();
|
|
||||||
setupWizardApp.sendStickyBroadcastAsUser(
|
|
||||||
new Intent(SetupWizardApp.ACTION_FINISHED),
|
|
||||||
UserHandle.getCallingUserHandle());
|
|
||||||
setupRevealImage();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -342,39 +334,26 @@ 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() {
|
final Point p = new Point();
|
||||||
@Override
|
getWindowManager().getDefaultDisplay().getRealSize(p);
|
||||||
public void run() {
|
final WallpaperManager wallpaperManager =
|
||||||
final Point p = new Point();
|
WallpaperManager.getInstance(SetupWizardActivity.this);
|
||||||
getWindowManager().getDefaultDisplay().getRealSize(p);
|
wallpaperManager.forgetLoadedWallpaper();
|
||||||
final WallpaperManager wallpaperManager =
|
final Bitmap wallpaper = wallpaperManager.getBitmap();
|
||||||
WallpaperManager.getInstance(SetupWizardActivity.this);
|
Bitmap cropped = null;
|
||||||
wallpaperManager.forgetLoadedWallpaper();
|
if (wallpaper != null) {
|
||||||
final Bitmap wallpaper = wallpaperManager.getBitmap();
|
cropped = Bitmap.createBitmap(wallpaper, 0,
|
||||||
Bitmap cropped = null;
|
0, Math.min(p.x, wallpaper.getWidth()),
|
||||||
if (wallpaper != null) {
|
Math.min(p.y, wallpaper.getHeight()));
|
||||||
cropped = Bitmap.createBitmap(wallpaper, 0,
|
}
|
||||||
0, Math.min(p.x, wallpaper.getWidth()),
|
if (cropped != null) {
|
||||||
Math.min(p.y, wallpaper.getHeight()));
|
mReveal.setScaleType(ImageView.ScaleType.CENTER_CROP);
|
||||||
}
|
mReveal.setImageBitmap(cropped);
|
||||||
final Bitmap croppedWallpaper = cropped;
|
} else {
|
||||||
mHandler.post(new Runnable() {
|
mReveal.setBackground(wallpaperManager
|
||||||
@Override
|
.getBuiltInDrawable(p.x, p.y, false, 0, 0));
|
||||||
public void run() {
|
}
|
||||||
if (croppedWallpaper != null) {
|
animateOut();
|
||||||
mReveal.setScaleType(ImageView.ScaleType.CENTER_CROP);
|
|
||||||
mReveal.setImageBitmap(croppedWallpaper);
|
|
||||||
} else {
|
|
||||||
mReveal.setBackground(wallpaperManager
|
|
||||||
.getBuiltInDrawable(p.x, p.y, false, 0, 0));
|
|
||||||
}
|
|
||||||
animateOut();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
};
|
|
||||||
t.start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void animateOut() {
|
private void animateOut() {
|
||||||
@ -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);
|
||||||
|
Loading…
Reference in New Issue
Block a user