Skip to content

Commit c7e52d7

Browse files
Jeff BrownAndroid (Google) Code Review
authored andcommitted
Merge "Remove dead code in window manager."
2 parents d8031f0 + 23e7c35 commit c7e52d7

File tree

2 files changed

+17
-68
lines changed

2 files changed

+17
-68
lines changed

core/java/android/view/ViewRootImpl.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,6 @@ public final class ViewRootImpl implements ViewParent,
251251

252252
CompatibilityInfoHolder mCompatibilityInfo;
253253

254-
/*package*/ int mAddNesting;
255-
256254
// These are accessed by multiple threads.
257255
final Rect mWinFrame; // frame given by window manager.
258256

core/java/android/view/WindowManagerImpl.java

Lines changed: 17 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -217,15 +217,10 @@ public void addView(View view) {
217217
}
218218

219219
public void addView(View view, ViewGroup.LayoutParams params) {
220-
addView(view, params, null, false);
220+
addView(view, params, null);
221221
}
222222

223223
public void addView(View view, ViewGroup.LayoutParams params, CompatibilityInfoHolder cih) {
224-
addView(view, params, cih, false);
225-
}
226-
227-
private void addView(View view, ViewGroup.LayoutParams params,
228-
CompatibilityInfoHolder cih, boolean nest) {
229224
if (false) Log.v("WindowManager", "addView view=" + view);
230225

231226
if (!(params instanceof WindowManager.LayoutParams)) {
@@ -256,25 +251,10 @@ private void addView(View view, ViewGroup.LayoutParams params,
256251
SystemProperties.addChangeCallback(mSystemPropertyUpdater);
257252
}
258253

259-
// Here's an odd/questionable case: if someone tries to add a
260-
// view multiple times, then we simply bump up a nesting count
261-
// and they need to remove the view the corresponding number of
262-
// times to have it actually removed from the window manager.
263-
// This is useful specifically for the notification manager,
264-
// which can continually add/remove the same view as a
265-
// notification gets updated.
266254
int index = findViewLocked(view, false);
267255
if (index >= 0) {
268-
if (!nest) {
269-
throw new IllegalStateException("View " + view
270-
+ " has already been added to the window manager.");
271-
}
272-
root = mRoots[index];
273-
root.mAddNesting++;
274-
// Update layout parameters.
275-
view.setLayoutParams(wparams);
276-
root.setLayoutParams(wparams, true);
277-
return;
256+
throw new IllegalStateException("View " + view
257+
+ " has already been added to the window manager.");
278258
}
279259

280260
// If this is a panel window, then find the window it is being
@@ -290,7 +270,6 @@ private void addView(View view, ViewGroup.LayoutParams params,
290270
}
291271

292272
root = new ViewRootImpl(view.getContext());
293-
root.mAddNesting = 1;
294273
if (cih == null) {
295274
root.mCompatibilityInfo = new CompatibilityInfoHolder();
296275
} else {
@@ -345,66 +324,38 @@ public void updateViewLayout(View view, ViewGroup.LayoutParams params) {
345324
}
346325

347326
public void removeView(View view) {
348-
synchronized (this) {
349-
int index = findViewLocked(view, true);
350-
View curView = removeViewLocked(index);
351-
if (curView == view) {
352-
return;
353-
}
354-
355-
throw new IllegalStateException("Calling with view " + view
356-
+ " but the ViewAncestor is attached to " + curView);
357-
}
327+
removeView(view, false);
358328
}
359329

360330
public void removeViewImmediate(View view) {
331+
removeView(view, true);
332+
}
333+
334+
private void removeView(View view, boolean immediate) {
361335
synchronized (this) {
362336
int index = findViewLocked(view, true);
363-
ViewRootImpl root = mRoots[index];
364-
View curView = root.getView();
365-
366-
root.mAddNesting = 0;
367-
368-
if (view != null) {
369-
InputMethodManager imm = InputMethodManager.getInstance(view.getContext());
370-
if (imm != null) {
371-
imm.windowDismissed(mViews[index].getWindowToken());
372-
}
373-
}
374-
375-
root.die(true);
376-
finishRemoveViewLocked(curView, index);
337+
View curView = removeViewLocked(index, immediate);
377338
if (curView == view) {
378339
return;
379340
}
380-
341+
381342
throw new IllegalStateException("Calling with view " + view
382343
+ " but the ViewAncestor is attached to " + curView);
383344
}
384345
}
385-
386-
View removeViewLocked(int index) {
346+
347+
View removeViewLocked(int index, boolean immediate) {
387348
ViewRootImpl root = mRoots[index];
388349
View view = root.getView();
389350

390-
// Don't really remove until we have matched all calls to add().
391-
root.mAddNesting--;
392-
if (root.mAddNesting > 0) {
393-
return view;
394-
}
395-
396351
if (view != null) {
397352
InputMethodManager imm = InputMethodManager.getInstance(view.getContext());
398353
if (imm != null) {
399354
imm.windowDismissed(mViews[index].getWindowToken());
400355
}
401356
}
402-
root.die(false);
403-
finishRemoveViewLocked(view, index);
404-
return view;
405-
}
406-
407-
void finishRemoveViewLocked(View view, int index) {
357+
root.die(immediate);
358+
408359
final int count = mViews.length;
409360

410361
// remove it from the list
@@ -426,6 +377,7 @@ void finishRemoveViewLocked(View view, int index) {
426377
// func doesn't allow null... does it matter if we clear them?
427378
//view.setLayoutParams(null);
428379
}
380+
return view;
429381
}
430382

431383
public void closeAll(IBinder token, String who, String what) {
@@ -440,8 +392,7 @@ public void closeAll(IBinder token, String who, String what) {
440392
// + " view " + mRoots[i].getView());
441393
if (token == null || mParams[i].token == token) {
442394
ViewRootImpl root = mRoots[i];
443-
root.mAddNesting = 1;
444-
395+
445396
//Log.i("foo", "Force closing " + root);
446397
if (who != null) {
447398
WindowLeaked leak = new WindowLeaked(
@@ -451,7 +402,7 @@ public void closeAll(IBinder token, String who, String what) {
451402
Log.e("WindowManager", leak.getMessage(), leak);
452403
}
453404

454-
removeViewLocked(i);
405+
removeViewLocked(i, false);
455406
i--;
456407
count--;
457408
}

0 commit comments

Comments
 (0)