Skip to content

Commit 58f42a5

Browse files
author
Dianne Hackborn
committed
Fix issue #5405788: Device continuously opening and closing...
...the "Complete action using" dialog When an application goes idle, it sends back to the activity manager the configuration it last used, to make sure the two don't get out of sync. Fix a bunch of edge cases here in dealing with that, and be sure to also send the current configuration when launching an activity so the client is always up-to-date when launching. Also a small fix to not show the upgrading dialog during first boot. Change-Id: I14ed366a87cd689d1c78787369e052422290ac6f
1 parent 8c3e707 commit 58f42a5

File tree

9 files changed

+79
-37
lines changed

9 files changed

+79
-37
lines changed

core/java/android/app/ActivityThread.java

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,15 @@ private class ApplicationThread extends ApplicationThreadNative {
490490
// Formatting for checkin service - update version if row format changes
491491
private static final int ACTIVITY_THREAD_CHECKIN_VERSION = 1;
492492

493+
private void updatePendingConfiguration(Configuration config) {
494+
synchronized (mPackages) {
495+
if (mPendingConfiguration == null ||
496+
mPendingConfiguration.isOtherSeqNewer(config)) {
497+
mPendingConfiguration = config;
498+
}
499+
}
500+
}
501+
493502
public final void schedulePauseActivity(IBinder token, boolean finished,
494503
boolean userLeaving, int configChanges) {
495504
queueOrSendMessage(
@@ -530,8 +539,8 @@ public final void scheduleSendResult(IBinder token, List<ResultInfo> results) {
530539
// we use token to identify this activity without having to send the
531540
// activity itself back to the activity manager. (matters more with ipc)
532541
public final void scheduleLaunchActivity(Intent intent, IBinder token, int ident,
533-
ActivityInfo info, CompatibilityInfo compatInfo, Bundle state,
534-
List<ResultInfo> pendingResults,
542+
ActivityInfo info, Configuration curConfig, CompatibilityInfo compatInfo,
543+
Bundle state, List<ResultInfo> pendingResults,
535544
List<Intent> pendingNewIntents, boolean notResumed, boolean isForward,
536545
String profileName, ParcelFileDescriptor profileFd, boolean autoStopProfiler) {
537546
ActivityClientRecord r = new ActivityClientRecord();
@@ -553,6 +562,8 @@ public final void scheduleLaunchActivity(Intent intent, IBinder token, int ident
553562
r.profileFd = profileFd;
554563
r.autoStopProfiler = autoStopProfiler;
555564

565+
updatePendingConfiguration(curConfig);
566+
556567
queueOrSendMessage(H.LAUNCH_ACTIVITY, r);
557568
}
558569

@@ -697,12 +708,7 @@ public void requestThumbnail(IBinder token) {
697708
}
698709

699710
public void scheduleConfigurationChanged(Configuration config) {
700-
synchronized (mPackages) {
701-
if (mPendingConfiguration == null ||
702-
mPendingConfiguration.isOtherSeqNewer(config)) {
703-
mPendingConfiguration = config;
704-
}
705-
}
711+
updatePendingConfiguration(config);
706712
queueOrSendMessage(H.CONFIGURATION_CHANGED, config);
707713
}
708714

@@ -1966,6 +1972,9 @@ private void handleLaunchActivity(ActivityClientRecord r, Intent customIntent) {
19661972
mProfiler.autoStopProfiler = r.autoStopProfiler;
19671973
}
19681974

1975+
// Make sure we are running with the most recent config.
1976+
handleConfigurationChanged(null, null);
1977+
19691978
if (localLOGV) Slog.v(
19701979
TAG, "Handling launch of " + r);
19711980
Activity a = performLaunchActivity(r, customIntent);

core/java/android/app/ApplicationThreadNative.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
132132
IBinder b = data.readStrongBinder();
133133
int ident = data.readInt();
134134
ActivityInfo info = ActivityInfo.CREATOR.createFromParcel(data);
135+
Configuration curConfig = Configuration.CREATOR.createFromParcel(data);
135136
CompatibilityInfo compatInfo = CompatibilityInfo.CREATOR.createFromParcel(data);
136137
Bundle state = data.readBundle();
137138
List<ResultInfo> ri = data.createTypedArrayList(ResultInfo.CREATOR);
@@ -142,7 +143,7 @@ public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
142143
ParcelFileDescriptor profileFd = data.readInt() != 0
143144
? data.readFileDescriptor() : null;
144145
boolean autoStopProfiler = data.readInt() != 0;
145-
scheduleLaunchActivity(intent, b, ident, info, compatInfo, state, ri, pi,
146+
scheduleLaunchActivity(intent, b, ident, info, curConfig, compatInfo, state, ri, pi,
146147
notResumed, isForward, profileName, profileFd, autoStopProfiler);
147148
return true;
148149
}
@@ -630,17 +631,18 @@ public final void scheduleSendResult(IBinder token, List<ResultInfo> results)
630631
}
631632

632633
public final void scheduleLaunchActivity(Intent intent, IBinder token, int ident,
633-
ActivityInfo info, CompatibilityInfo compatInfo, Bundle state,
634-
List<ResultInfo> pendingResults,
635-
List<Intent> pendingNewIntents, boolean notResumed, boolean isForward,
636-
String profileName, ParcelFileDescriptor profileFd, boolean autoStopProfiler)
634+
ActivityInfo info, Configuration curConfig, CompatibilityInfo compatInfo,
635+
Bundle state, List<ResultInfo> pendingResults,
636+
List<Intent> pendingNewIntents, boolean notResumed, boolean isForward,
637+
String profileName, ParcelFileDescriptor profileFd, boolean autoStopProfiler)
637638
throws RemoteException {
638639
Parcel data = Parcel.obtain();
639640
data.writeInterfaceToken(IApplicationThread.descriptor);
640641
intent.writeToParcel(data, 0);
641642
data.writeStrongBinder(token);
642643
data.writeInt(ident);
643644
info.writeToParcel(data, 0);
645+
curConfig.writeToParcel(data, 0);
644646
compatInfo.writeToParcel(data, 0);
645647
data.writeBundle(state);
646648
data.writeTypedList(pendingResults);

core/java/android/app/IApplicationThread.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ void scheduleStopActivity(IBinder token, boolean showWindow,
5353
void scheduleResumeActivity(IBinder token, boolean isForward) throws RemoteException;
5454
void scheduleSendResult(IBinder token, List<ResultInfo> results) throws RemoteException;
5555
void scheduleLaunchActivity(Intent intent, IBinder token, int ident,
56-
ActivityInfo info, CompatibilityInfo compatInfo, Bundle state,
57-
List<ResultInfo> pendingResults,
58-
List<Intent> pendingNewIntents, boolean notResumed, boolean isForward,
59-
String profileName, ParcelFileDescriptor profileFd, boolean autoStopProfiler)
56+
ActivityInfo info, Configuration curConfig, CompatibilityInfo compatInfo,
57+
Bundle state, List<ResultInfo> pendingResults,
58+
List<Intent> pendingNewIntents, boolean notResumed, boolean isForward,
59+
String profileName, ParcelFileDescriptor profileFd, boolean autoStopProfiler)
6060
throws RemoteException;
6161
void scheduleRelaunchActivity(IBinder token, List<ResultInfo> pendingResults,
6262
List<Intent> pendingNewIntents, int configChanges,

core/java/android/content/pm/IPackageManager.aidl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,4 +362,6 @@ interface IPackageManager {
362362
void verifyPendingInstall(int id, int verificationCode);
363363

364364
VerifierDeviceIdentity getVerifierDeviceIdentity();
365+
366+
boolean isFirstBoot();
365367
}

services/java/com/android/server/SystemServer.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,11 @@ public void run() {
163163
pm = PackageManagerService.main(context,
164164
factoryTest != SystemServer.FACTORY_TEST_OFF,
165165
onlyCore);
166+
boolean firstBoot = false;
167+
try {
168+
firstBoot = pm.isFirstBoot();
169+
} catch (RemoteException e) {
170+
}
166171

167172
ActivityManagerService.setSystemProcess();
168173

@@ -208,7 +213,8 @@ public void run() {
208213

209214
Slog.i(TAG, "Window Manager");
210215
wm = WindowManagerService.main(context, power,
211-
factoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL);
216+
factoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL,
217+
!firstBoot);
212218
ServiceManager.addService(Context.WINDOW_SERVICE, wm);
213219

214220
ActivityManagerService.self().setWindowManager(wm);

services/java/com/android/server/am/ActivityStack.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -589,8 +589,8 @@ final boolean realStartActivityLocked(ActivityRecord r,
589589
}
590590
}
591591
app.thread.scheduleLaunchActivity(new Intent(r.intent), r,
592-
System.identityHashCode(r),
593-
r.info, r.compat, r.icicle, results, newIntents, !andResume,
592+
System.identityHashCode(r), r.info, mService.mConfiguration,
593+
r.compat, r.icicle, results, newIntents, !andResume,
594594
mService.isNextTransitionForward(), profileFile, profileFd,
595595
profileAutoStop);
596596

@@ -4035,7 +4035,18 @@ final boolean ensureActivityConfigurationLocked(ActivityRecord r,
40354035
// But then we need to figure out how it needs to deal with that.
40364036
Configuration oldConfig = r.configuration;
40374037
r.configuration = newConfig;
4038-
4038+
4039+
// Determine what has changed. May be nothing, if this is a config
4040+
// that has come back from the app after going idle. In that case
4041+
// we just want to leave the official config object now in the
4042+
// activity and do nothing else.
4043+
final int changes = oldConfig.diff(newConfig);
4044+
if (changes == 0 && !r.forceNewConfig) {
4045+
if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG,
4046+
"Configuration no differences in " + r);
4047+
return true;
4048+
}
4049+
40394050
// If the activity isn't currently running, just leave the new
40404051
// configuration and it will pick that up next time it starts.
40414052
if (r.app == null || r.app.thread == null) {
@@ -4046,8 +4057,7 @@ final boolean ensureActivityConfigurationLocked(ActivityRecord r,
40464057
return true;
40474058
}
40484059

4049-
// Figure out what has changed between the two configurations.
4050-
int changes = oldConfig.diff(newConfig);
4060+
// Figure out how to handle the changes between the configurations.
40514061
if (DEBUG_SWITCH || DEBUG_CONFIGURATION) {
40524062
Slog.v(TAG, "Checking to restart " + r.info.name + ": changed=0x"
40534063
+ Integer.toHexString(changes) + ", handles=0x"

services/java/com/android/server/pm/PackageManagerService.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,6 +1157,10 @@ public PackageManagerService(Context context, boolean factoryTest, boolean onlyC
11571157
} // synchronized (mInstallLock)
11581158
}
11591159

1160+
public boolean isFirstBoot() {
1161+
return !mRestoredSettings;
1162+
}
1163+
11601164
private String getRequiredVerifierLPr() {
11611165
final Intent verification = new Intent(Intent.ACTION_PACKAGE_NEEDS_VERIFICATION);
11621166
final List<ResolveInfo> receivers = queryIntentReceivers(verification, PACKAGE_MIME_TYPE,
@@ -2983,12 +2987,14 @@ public void performBootDexOpt() {
29832987
}
29842988
if (pkgs != null) {
29852989
for (int i=0; i<pkgs.size(); i++) {
2986-
try {
2987-
ActivityManagerNative.getDefault().showBootMessage(
2988-
mContext.getResources().getString(
2989-
com.android.internal.R.string.android_upgrading_apk,
2990-
i+1, pkgs.size()), true);
2991-
} catch (RemoteException e) {
2990+
if (!isFirstBoot()) {
2991+
try {
2992+
ActivityManagerNative.getDefault().showBootMessage(
2993+
mContext.getResources().getString(
2994+
com.android.internal.R.string.android_upgrading_apk,
2995+
i+1, pkgs.size()), true);
2996+
} catch (RemoteException e) {
2997+
}
29922998
}
29932999
PackageParser.Package p = pkgs.get(i);
29943000
synchronized (mInstallLock) {

services/java/com/android/server/pm/Settings.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,9 +1238,8 @@ boolean readLPw() {
12381238
mReadMessages.append("No start tag found in settings file\n");
12391239
PackageManagerService.reportSettingsProblem(Log.WARN,
12401240
"No start tag found in package manager settings");
1241-
Log
1242-
.wtf(PackageManagerService.TAG,
1243-
"No start tag found in package manager settings");
1241+
Log.wtf(PackageManagerService.TAG,
1242+
"No start tag found in package manager settings");
12441243
return false;
12451244
}
12461245

services/java/com/android/server/wm/WindowManagerService.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,8 @@ public void onReceive(Context context, Intent intent) {
297297

298298
final boolean mHaveInputMethods;
299299

300+
final boolean mAllowBootMessages;
301+
300302
final boolean mLimitedAlphaCompositing;
301303

302304
final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager();
@@ -633,8 +635,8 @@ public interface WindowChangeListener {
633635
float mCompatibleScreenScale;
634636

635637
public static WindowManagerService main(Context context,
636-
PowerManagerService pm, boolean haveInputMethods) {
637-
WMThread thr = new WMThread(context, pm, haveInputMethods);
638+
PowerManagerService pm, boolean haveInputMethods, boolean allowBootMsgs) {
639+
WMThread thr = new WMThread(context, pm, haveInputMethods, allowBootMsgs);
638640
thr.start();
639641

640642
synchronized (thr) {
@@ -654,19 +656,21 @@ static class WMThread extends Thread {
654656
private final Context mContext;
655657
private final PowerManagerService mPM;
656658
private final boolean mHaveInputMethods;
659+
private final boolean mAllowBootMessages;
657660

658661
public WMThread(Context context, PowerManagerService pm,
659-
boolean haveInputMethods) {
662+
boolean haveInputMethods, boolean allowBootMsgs) {
660663
super("WindowManager");
661664
mContext = context;
662665
mPM = pm;
663666
mHaveInputMethods = haveInputMethods;
667+
mAllowBootMessages = allowBootMsgs;
664668
}
665669

666670
public void run() {
667671
Looper.prepare();
668672
WindowManagerService s = new WindowManagerService(mContext, mPM,
669-
mHaveInputMethods);
673+
mHaveInputMethods, mAllowBootMessages);
670674
android.os.Process.setThreadPriority(
671675
android.os.Process.THREAD_PRIORITY_DISPLAY);
672676
android.os.Process.setCanSelfBackground(false);
@@ -728,9 +732,10 @@ public void run() {
728732
}
729733

730734
private WindowManagerService(Context context, PowerManagerService pm,
731-
boolean haveInputMethods) {
735+
boolean haveInputMethods, boolean showBootMsgs) {
732736
mContext = context;
733737
mHaveInputMethods = haveInputMethods;
738+
mAllowBootMessages = showBootMsgs;
734739
mLimitedAlphaCompositing = context.getResources().getBoolean(
735740
com.android.internal.R.bool.config_sf_limitedAlpha);
736741

@@ -4846,6 +4851,9 @@ public void performEnableScreen() {
48464851
public void showBootMessage(final CharSequence msg, final boolean always) {
48474852
boolean first = false;
48484853
synchronized(mWindowMap) {
4854+
if (!mAllowBootMessages) {
4855+
return;
4856+
}
48494857
if (!mShowingBootMessages) {
48504858
if (!always) {
48514859
return;

0 commit comments

Comments
 (0)