Fix issue #4502672: Wrong xml resources used for homescreen widgets.

There was a race in the system process between applying the initial
configuration and executing code in higher-level system services
like the app widget service that relies on the config.  For some
reason it starting showing up more after my code changes; it should
now be completely fixed.

Also fix the activity starting window to run in compatibility mode
if its application is going to be in compatibility mode.

And some various cleanup and small fixes.

Change-Id: I0566933bf1bbb4259c1d99a60c0a3c19af1542e5
This commit is contained in:
Dianne Hackborn
2011-05-31 17:59:49 -07:00
parent 8ede62745f
commit 2f0b17573d
15 changed files with 86 additions and 40 deletions

View File

@ -29,6 +29,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import org.apache.commons.logging.impl.SimpleLog;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlSerializer;

View File

@ -12217,6 +12217,15 @@ public final class ActivityManagerService extends ActivityManagerNative
ac.updateConfiguration(mConfiguration);
}
// Make sure all resources in our process are updated
// right now, so that anyone who is going to retrieve
// resource values after we return will be sure to get
// the new ones. This is especially important during
// boot, where the first config change needs to guarantee
// all resources have that config before following boot
// code is executed.
mSystemThread.applyConfigurationToResources(newConfig);
if (Settings.System.hasInterestingConfigurationChanges(changes)) {
Message msg = mHandler.obtainMessage(UPDATE_CONFIGURATION_MSG);
msg.obj = new Configuration(mConfiguration);

View File

@ -1455,6 +1455,8 @@ public class ActivityStack {
if (SHOW_APP_STARTING_PREVIEW && mMainStack) {
mService.mWindowManager.setAppStartingWindow(
next, next.packageName, next.theme,
mService.compatibilityInfoForPackageLocked(
next.info.applicationInfo),
next.nonLocalizedLabel,
next.labelRes, next.icon, next.windowFlags,
null, true);
@ -1491,6 +1493,8 @@ public class ActivityStack {
if (SHOW_APP_STARTING_PREVIEW) {
mService.mWindowManager.setAppStartingWindow(
next, next.packageName, next.theme,
mService.compatibilityInfoForPackageLocked(
next.info.applicationInfo),
next.nonLocalizedLabel,
next.labelRes, next.icon, next.windowFlags,
null, true);
@ -1617,7 +1621,9 @@ public class ActivityStack {
else if (prev.nowVisible) prev = null;
}
mService.mWindowManager.setAppStartingWindow(
r, r.packageName, r.theme, r.nonLocalizedLabel,
r, r.packageName, r.theme,
mService.compatibilityInfoForPackageLocked(
r.info.applicationInfo), r.nonLocalizedLabel,
r.labelRes, r.icon, r.windowFlags, prev, showStartingIcon);
}
} else {

View File

@ -150,9 +150,11 @@ public class CompatModePackages {
}
public CompatibilityInfo compatibilityInfoForPackageLocked(ApplicationInfo ai) {
return new CompatibilityInfo(ai, mService.mConfiguration.screenLayout,
CompatibilityInfo ci = new CompatibilityInfo(ai, mService.mConfiguration.screenLayout,
mService.mConfiguration.smallestScreenWidthDp,
(getPackageFlags(ai.packageName)&COMPAT_FLAG_ENABLED) != 0);
//Slog.i(TAG, "*********** COMPAT FOR PKG " + ai.packageName + ": " + ci);
return ci;
}
public int computeCompatModeLocked(ApplicationInfo ai) {

View File

@ -16,18 +16,23 @@
package com.android.server.wm;
import android.content.res.CompatibilityInfo;
final class StartingData {
final String pkg;
final int theme;
final CompatibilityInfo compatInfo;
final CharSequence nonLocalizedLabel;
final int labelRes;
final int icon;
final int windowFlags;
StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel,
StartingData(String _pkg, int _theme, CompatibilityInfo _compatInfo,
CharSequence _nonLocalizedLabel,
int _labelRes, int _icon, int _windowFlags) {
pkg = _pkg;
theme = _theme;
compatInfo = _compatInfo;
nonLocalizedLabel = _nonLocalizedLabel;
labelRes = _labelRes;
icon = _icon;

View File

@ -602,8 +602,7 @@ public class WindowManagerService extends IWindowManager.Stub
final Configuration mTempConfiguration = new Configuration();
// The frame use to limit the size of the app running in compatibility mode.
Rect mCompatibleScreenFrame = new Rect();
// The desired scaling factor for compatible apps.
float mCompatibleScreenScale;
public static WindowManagerService main(Context context,
@ -3526,7 +3525,8 @@ public class WindowManagerService extends IWindowManager.Stub
}
public void setAppStartingWindow(IBinder token, String pkg,
int theme, CharSequence nonLocalizedLabel, int labelRes, int icon,
int theme, CompatibilityInfo compatInfo,
CharSequence nonLocalizedLabel, int labelRes, int icon,
int windowFlags, IBinder transferFrom, boolean createIfNeeded) {
if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
"setAppStartingIcon()")) {
@ -3676,8 +3676,7 @@ public class WindowManagerService extends IWindowManager.Stub
}
mStartingIconInTransition = true;
wtoken.startingData = new StartingData(
pkg, theme, nonLocalizedLabel,
wtoken.startingData = new StartingData(pkg, theme, compatInfo, nonLocalizedLabel,
labelRes, icon, windowFlags);
Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
// Note: we really want to do sendMessageAtFrontOfQueue() because we
@ -5562,8 +5561,7 @@ public class WindowManagerService extends IWindowManager.Stub
dm.heightPixels = dm.unscaledHeightPixels = mAppDisplayHeight
= mPolicy.getNonDecorDisplayHeight(mRotation, dh);
mCompatibleScreenScale = CompatibilityInfo.updateCompatibleScreenFrame(
dm, mCompatibleScreenFrame, null);
mCompatibleScreenScale = CompatibilityInfo.computeCompatibleScaling(dm, null);
config.screenWidthDp = (int)(mPolicy.getConfigDisplayWidth(mRotation, dw) / dm.density);
config.screenHeightDp = (int)(mPolicy.getConfigDisplayHeight(mRotation, dh) / dm.density);
@ -6138,9 +6136,8 @@ public class WindowManagerService extends IWindowManager.Stub
View view = null;
try {
view = mPolicy.addStartingWindow(
wtoken.token, sd.pkg,
sd.theme, sd.nonLocalizedLabel, sd.labelRes,
sd.icon, sd.windowFlags);
wtoken.token, sd.pkg, sd.theme, sd.compatInfo,
sd.nonLocalizedLabel, sd.labelRes, sd.icon, sd.windowFlags);
} catch (Exception e) {
Slog.w(TAG, "Exception when adding starting window", e);
}