Replaced use of WT.appWindowToken with WT.asAppWindowToken

Not a perfect implementation, but slightly less confusing as
the child class is no longer a member variable of the parent
class.

Also renamed WindowToken.service to WindowToken.mService to be
consistent with how we name in other places.

Bug: 30060889
Change-Id: Ib21472a784a4f24e7789d443876cf0912d9e89de
diff --git a/services/core/java/com/android/server/wm/AppWindowAnimator.java b/services/core/java/com/android/server/wm/AppWindowAnimator.java
index 950fb20..5ddf283 100644
--- a/services/core/java/com/android/server/wm/AppWindowAnimator.java
+++ b/services/core/java/com/android/server/wm/AppWindowAnimator.java
@@ -109,9 +109,9 @@
 
     static final Animation sDummyAnimation = new DummyAnimation();
 
-    public AppWindowAnimator(final AppWindowToken atoken) {
+    public AppWindowAnimator(final AppWindowToken atoken, WindowManagerService service) {
         mAppToken = atoken;
-        mService = atoken.service;
+        mService = service;
         mAnimator = mService.mAnimator;
     }
 
diff --git a/services/core/java/com/android/server/wm/AppWindowToken.java b/services/core/java/com/android/server/wm/AppWindowToken.java
index bbd6fd7..47f435f 100644
--- a/services/core/java/com/android/server/wm/AppWindowToken.java
+++ b/services/core/java/com/android/server/wm/AppWindowToken.java
@@ -149,20 +149,17 @@
     int mPendingRelaunchCount;
 
     private ArrayList<WindowSurfaceController.SurfaceControlWithBackground> mSurfaceViewBackgrounds =
-        new ArrayList<WindowSurfaceController.SurfaceControlWithBackground>();
+        new ArrayList<>();
 
     ArrayDeque<Rect> mFrozenBounds = new ArrayDeque<>();
     ArrayDeque<Configuration> mFrozenMergedConfig = new ArrayDeque<>();
 
-    AppWindowToken(WindowManagerService _service, IApplicationToken _token,
-            boolean _voiceInteraction) {
-        super(_service, _token.asBinder(),
-                WindowManager.LayoutParams.TYPE_APPLICATION, true);
-        appWindowToken = this;
+    AppWindowToken(WindowManagerService service, IApplicationToken _token, boolean _voiceInteraction) {
+        super(service, _token.asBinder(), WindowManager.LayoutParams.TYPE_APPLICATION, true);
         appToken = _token;
         voiceInteraction = _voiceInteraction;
         mInputApplicationHandle = new InputApplicationHandle(this);
-        mAppAnimator = new AppWindowAnimator(this);
+        mAppAnimator = new AppWindowAnimator(this, service);
     }
 
     void sendAppVisibilityToClients() {
@@ -272,9 +269,9 @@
                 + numInteresting + " visible=" + numVisible);
         if (nowDrawn != reportedDrawn) {
             if (nowDrawn) {
-                Message m = service.mH.obtainMessage(
+                Message m = mService.mH.obtainMessage(
                         H.REPORT_APPLICATION_TOKEN_DRAWN, this);
-                service.mH.sendMessage(m);
+                mService.mH.sendMessage(m);
             }
             reportedDrawn = nowDrawn;
         }
@@ -283,12 +280,12 @@
                     TAG, "Visibility changed in " + this
                     + ": vis=" + nowVisible);
             reportedVisible = nowVisible;
-            Message m = service.mH.obtainMessage(
+            Message m = mService.mH.obtainMessage(
                     H.REPORT_APPLICATION_TOKEN_WINDOWS,
                     nowVisible ? 1 : 0,
                     nowGone ? 1 : 0,
                     this);
-            service.mH.sendMessage(m);
+            mService.mH.sendMessage(m);
         }
     }
 
@@ -310,7 +307,7 @@
         // * or this is an opening app and windows are being replaced.
         boolean visibilityChanged = false;
         if (hidden == visible || (hidden && mIsExiting) || (visible && waitingForReplacement())) {
-            final AccessibilityController accessibilityController = service.mAccessibilityController;
+            final AccessibilityController accessibilityController = mService.mAccessibilityController;
             boolean changed = false;
             if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
                     "Changing app " + this + " hidden=" + hidden + " performLayout=" + performLayout);
@@ -321,7 +318,7 @@
                 if (mAppAnimator.animation == AppWindowAnimator.sDummyAnimation) {
                     mAppAnimator.setNullAnimation();
                 }
-                if (service.applyAnimationLocked(this, lp, transit, visible, isVoiceInteraction)) {
+                if (mService.applyAnimationLocked(this, lp, transit, visible, isVoiceInteraction)) {
                     delayed = runningAppAnimation = true;
                 }
                 final WindowState window = findMainWindow();
@@ -395,13 +392,13 @@
                     + ": hidden=" + hidden + " hiddenRequested=" + hiddenRequested);
 
             if (changed) {
-                service.mInputMonitor.setUpdateInputWindowsNeededLw();
+                mService.mInputMonitor.setUpdateInputWindowsNeededLw();
                 if (performLayout) {
-                    service.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
+                    mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
                             false /*updateInputWindows*/);
-                    service.mWindowPlacerLocked.performSurfacePlacement();
+                    mService.mWindowPlacerLocked.performSurfacePlacement();
                 }
-                service.mInputMonitor.updateInputWindowsLw(false /*force*/);
+                mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
             }
         }
 
@@ -420,14 +417,14 @@
                 // The token was made immediately visible, there will be no entrance animation.
                 // We need to inform the client the enter animation was finished.
                 mEnteringAnimation = true;
-                service.mActivityManagerAppTransitionNotifier.onAppTransitionFinishedLocked(token);
+                mService.mActivityManagerAppTransitionNotifier.onAppTransitionFinishedLocked(token);
             }
 
-            if (!service.mClosingApps.contains(this) && !service.mOpeningApps.contains(this)) {
+            if (!mService.mClosingApps.contains(this) && !mService.mOpeningApps.contains(this)) {
                 // The token is not closing nor opening, so even if there is an animation set, that
                 // doesn't mean that it goes through the normal app transition cycle so we have
                 // to inform the docked controller about visibility change.
-                service.getDefaultDisplayContentLocked().getDockedDividerController()
+                mService.getDefaultDisplayContentLocked().getDockedDividerController()
                         .notifyAppVisibilityChanged();
             }
         }
@@ -469,7 +466,7 @@
             if (!win.mAppFreezing
                     && (win.mViewVisibility == View.VISIBLE || win.isAnimatingWithSavedSurface()
                             || (win.mWinAnimator.isAnimationSet()
-                                    && !service.mAppTransition.isTransitionSet()))
+                                    && !mService.mAppTransition.isTransitionSet()))
                     && !win.mDestroying
                     && win.isDrawnLw()) {
                 return true;
@@ -580,7 +577,7 @@
         }
         for (int i = 0; i < displayList.size(); i++) {
             final DisplayContent displayContent = displayList.get(i);
-            service.mLayersController.assignLayersLocked(displayContent.getWindowList());
+            mService.mLayersController.assignLayersLocked(displayContent.getWindowList());
             displayContent.layoutNeeded = true;
         }
     }
@@ -666,7 +663,7 @@
                 w.clearAnimatingWithSavedSurface();
                 w.mDestroying = true;
                 w.mWinAnimator.hide("stopUsingSavedSurfaceLocked");
-                service.mWallpaperControllerLocked.hideWallpapers(w);
+                mService.mWallpaperControllerLocked.hideWallpapers(w);
             }
         }
         destroySurfaces();
@@ -707,7 +704,7 @@
         if (!allDrawn) {
             allDrawn = (numInteresting > 0) && (numInteresting == numDrawn);
             if (allDrawn) {
-                service.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
+                mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
             }
         }
         clearVisibleBeforeClientHidden();
@@ -744,7 +741,7 @@
                 Slog.w(TAG, "removeAllWindows: removing win=" + win);
             }
 
-            service.removeWindowLocked(win);
+            mService.removeWindowLocked(win);
         }
         allAppWindows.clear();
         windows.clear();
@@ -758,7 +755,7 @@
 
         if (startingWindow == win) {
             if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Notify removed startingWindow " + win);
-            service.scheduleRemoveStartingWindowLocked(this);
+            mService.scheduleRemoveStartingWindowLocked(this);
         } else if (allAppWindows.size() == 0 && startingData != null) {
             // If this is the last window and we had requested a starting transition window,
             // well there is no point now.
@@ -767,7 +764,7 @@
         } else if (allAppWindows.size() == 1 && startingView != null) {
             // If this is the last window except for a starting transition window,
             // we need to get rid of the starting transition.
-            service.scheduleRemoveStartingWindowLocked(this);
+            mService.scheduleRemoveStartingWindowLocked(this);
         }
     }
 
@@ -786,7 +783,7 @@
                 }
                 // Set mDestroying, we don't want any animation or delayed removal here.
                 win.mDestroying = true;
-                service.removeWindowLocked(win);
+                mService.removeWindowLocked(win);
             }
         }
     }
@@ -889,7 +886,7 @@
                 w.mSkipEnterAnimationForSeamlessReplacement = !candidate.mAnimateReplacingWindow;
 
                 // if we got a replacement window, reset the timeout to give drawing more time
-                service.scheduleReplacingWindowTimeouts(this);
+                mService.scheduleReplacingWindowTimeouts(this);
             }
         }
         allAppWindows.add(w);
@@ -946,7 +943,7 @@
 
         if (mTask.mPreparedFrozenMergedConfig.equals(Configuration.EMPTY)) {
             // We didn't call prepareFreezingBounds on the task, so use the current value.
-            final Configuration config = new Configuration(service.mCurConfiguration);
+            final Configuration config = new Configuration(mService.mCurConfiguration);
             config.updateFrom(mTask.mOverrideConfig);
             mFrozenMergedConfig.offer(config);
         } else {
@@ -972,11 +969,11 @@
             }
             win.mLayoutNeeded = true;
             win.setDisplayLayoutNeeded();
-            if (!service.mResizingWindows.contains(win)) {
-                service.mResizingWindows.add(win);
+            if (!mService.mResizingWindows.contains(win)) {
+                mService.mResizingWindows.add(win);
             }
         }
-        service.mWindowPlacerLocked.performSurfacePlacement();
+        mService.mWindowPlacerLocked.performSurfacePlacement();
     }
 
     void addSurfaceViewBackground(WindowSurfaceController.SurfaceControlWithBackground background) {
@@ -1030,8 +1027,8 @@
             if (animLayer > highestAnimLayer) {
                 highestAnimLayer = animLayer;
             }
-            if (w == service.mInputMethodTarget && !service.mInputMethodTargetWaitingAnim) {
-                service.mLayersController.setInputMethodAnimLayerAdjustment(adj);
+            if (w == mService.mInputMethodTarget && !mService.mInputMethodTargetWaitingAnim) {
+                mService.mLayersController.setInputMethodAnimLayerAdjustment(adj);
             }
         }
 
@@ -1054,13 +1051,13 @@
         for (int i = allAppWindows.size() - 1; i >= 0; --i) {
             final WindowState win = allAppWindows.get(i);
             if (win.isDragResizeChanged()) {
-                service.mWaitingForDrawn.add(win);
+                mService.mWaitingForDrawn.add(win);
             }
         }
     }
 
     void resizeWindows() {
-        final ArrayList<WindowState> resizingWindows = service.mResizingWindows;
+        final ArrayList<WindowState> resizingWindows = mService.mResizingWindows;
         // Some windows won't go through the resizing process, if they don't have a surface, so
         // destroy all saved surfaces here.
         destroySavedSurfaces();
@@ -1121,11 +1118,11 @@
         for (int winNdx = allAppWindows.size() - 1; winNdx >= 0; --winNdx) {
             // We are in the middle of changing the state of displays/stacks/tasks. We need
             // to finish that, before we let layout interfere with it.
-            service.removeWindowLocked(allAppWindows.get(winNdx));
+            mService.removeWindowLocked(allAppWindows.get(winNdx));
             doAnotherLayoutPass = true;
         }
         if (doAnotherLayoutPass) {
-            service.mWindowPlacerLocked.requestTraversal();
+            mService.mWindowPlacerLocked.requestTraversal();
         }
     }
 
@@ -1155,7 +1152,7 @@
             if (displayId == allAppWindows.get(i).getDisplayId()) {
                 windowAnimator.setPendingLayoutChanges(displayId, changes);
                 if (DEBUG_LAYOUT_REPEATS) {
-                    service.mWindowPlacerLocked.debugLayoutRepeats(
+                    mService.mWindowPlacerLocked.debugLayoutRepeats(
                             reason, windowAnimator.getPendingLayoutChanges(displayId));
                 }
                 break;
@@ -1181,11 +1178,11 @@
             if (!mAppAnimator.freezingScreen) {
                 mAppAnimator.freezingScreen = true;
                 mAppAnimator.lastFreezeDuration = 0;
-                service.mAppsFreezingScreen++;
-                if (service.mAppsFreezingScreen == 1) {
-                    service.startFreezingDisplayLocked(false, 0, 0);
-                    service.mH.removeMessages(H.APP_FREEZE_TIMEOUT);
-                    service.mH.sendEmptyMessageDelayed(H.APP_FREEZE_TIMEOUT, 2000);
+                mService.mAppsFreezingScreen++;
+                if (mService.mAppsFreezingScreen == 1) {
+                    mService.startFreezingDisplayLocked(false, 0, 0);
+                    mService.mH.removeMessages(H.APP_FREEZE_TIMEOUT);
+                    mService.mH.sendEmptyMessageDelayed(H.APP_FREEZE_TIMEOUT, 2000);
                 }
             }
             final int count = allAppWindows.size();
@@ -1208,10 +1205,10 @@
             if (w.mAppFreezing) {
                 w.mAppFreezing = false;
                 if (w.mHasSurface && !w.mOrientationChanging
-                        && service.mWindowsFreezingScreen != WINDOWS_FREEZING_SCREENS_TIMEOUT) {
+                        && mService.mWindowsFreezingScreen != WINDOWS_FREEZING_SCREENS_TIMEOUT) {
                     if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "set mOrientationChanging of " + w);
                     w.mOrientationChanging = true;
-                    service.mWindowPlacerLocked.mOrientationChangeComplete = false;
+                    mService.mWindowPlacerLocked.mOrientationChangeComplete = false;
                 }
                 w.mLastFreezeDuration = 0;
                 unfrozeWindows = true;
@@ -1222,20 +1219,20 @@
             if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "No longer freezing: " + this);
             mAppAnimator.freezingScreen = false;
             mAppAnimator.lastFreezeDuration =
-                    (int)(SystemClock.elapsedRealtime() - service.mDisplayFreezeTime);
-            service.mAppsFreezingScreen--;
-            service.mLastFinishedFreezeSource = this;
+                    (int)(SystemClock.elapsedRealtime() - mService.mDisplayFreezeTime);
+            mService.mAppsFreezingScreen--;
+            mService.mLastFinishedFreezeSource = this;
         }
         if (unfreezeSurfaceNow) {
             if (unfrozeWindows) {
-                service.mWindowPlacerLocked.performSurfacePlacement();
+                mService.mWindowPlacerLocked.performSurfacePlacement();
             }
-            service.stopFreezingDisplayLocked();
+            mService.stopFreezingDisplayLocked();
         }
     }
 
     boolean transferStartingWindow(IBinder transferFrom) {
-        final AppWindowToken fromToken = service.findAppWindowToken(transferFrom);
+        final AppWindowToken fromToken = mService.findAppWindowToken(transferFrom);
         if (fromToken == null) {
             return false;
         }
@@ -1244,7 +1241,7 @@
         if (tStartingWindow != null && fromToken.startingView != null) {
             // In this case, the starting icon has already been displayed, so start
             // letting windows get shown immediately without any more transitions.
-            service.mSkipAppTransitionAnimation = true;
+            mService.mSkipAppTransitionAnimation = true;
 
             if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Moving existing starting " + tStartingWindow
                     + " from " + fromToken + " to " + this);
@@ -1269,7 +1266,7 @@
             if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE || DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
                     "Removing starting window: " + tStartingWindow);
             tStartingWindow.getWindowList().remove(tStartingWindow);
-            service.mWindowsChanged = true;
+            mService.mWindowsChanged = true;
             if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
                     "Removing starting " + tStartingWindow + " from " + fromToken);
             fromToken.removeWindow(tStartingWindow);
@@ -1297,10 +1294,10 @@
             fromToken.mAppAnimator.transferCurrentAnimation(
                     mAppAnimator, tStartingWindow.mWinAnimator);
 
-            service.updateFocusedWindowLocked(
+            mService.updateFocusedWindowLocked(
                     UPDATE_FOCUS_WILL_PLACE_SURFACES, true /*updateInputWindows*/);
-            service.getDefaultDisplayContentLocked().layoutNeeded = true;
-            service.mWindowPlacerLocked.performSurfacePlacement();
+            mService.getDefaultDisplayContentLocked().layoutNeeded = true;
+            mService.mWindowPlacerLocked.performSurfacePlacement();
             Binder.restoreCallingIdentity(origId);
             return true;
         } else if (fromToken.startingData != null) {
@@ -1311,10 +1308,10 @@
             startingData = fromToken.startingData;
             fromToken.startingData = null;
             fromToken.startingMoved = true;
-            final Message m = service.mH.obtainMessage(H.ADD_STARTING, this);
+            final Message m = mService.mH.obtainMessage(H.ADD_STARTING, this);
             // Note: we really want to do sendMessageAtFrontOfQueue() because we want to process the
             // message ASAP, before any other queued messages.
-            service.mH.sendMessageAtFrontOfQueue(m);
+            mService.mH.sendMessageAtFrontOfQueue(m);
             return true;
         }
 
@@ -1354,6 +1351,12 @@
     }
 
     @Override
+    AppWindowToken asAppWindowToken() {
+        // I am an app window token!
+        return this;
+    }
+
+    @Override
     void dump(PrintWriter pw, String prefix) {
         super.dump(pw, prefix);
         if (appToken != null) {
diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java
index 6b46ddd..ac5e964 100644
--- a/services/core/java/com/android/server/wm/WindowManagerService.java
+++ b/services/core/java/com/android/server/wm/WindowManagerService.java
@@ -1549,7 +1549,7 @@
                 token = new WindowToken(this, attrs.token, -1, false);
                 addToken = true;
             } else if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
-                atoken = token.appWindowToken;
+                atoken = token.asAppWindowToken();
                 if (atoken == null) {
                     Slog.w(TAG_WM, "Attempted to add window with non-application token "
                           + token + ".  Aborting.");
@@ -1601,7 +1601,7 @@
                             + attrs.token + ".  Aborting.");
                     return WindowManagerGlobal.ADD_BAD_APP_TOKEN;
                 }
-            } else if (token.appWindowToken != null) {
+            } else if (token.asAppWindowToken() != null) {
                 Slog.w(TAG_WM, "Non-null appWindowToken for system window of type=" + type);
                 // It is not valid to use an app token with other system types; we will
                 // instead make a new token for it (as if null had been passed in for the token).
@@ -1663,9 +1663,10 @@
                 }
             }
 
-            if (type == TYPE_APPLICATION_STARTING && token.appWindowToken != null) {
-                token.appWindowToken.startingWindow = win;
-                if (DEBUG_STARTING_WINDOW) Slog.v (TAG_WM, "addWindow: " + token.appWindowToken
+            final AppWindowToken aToken = token.asAppWindowToken();
+            if (type == TYPE_APPLICATION_STARTING && aToken != null) {
+                aToken.startingWindow = win;
+                if (DEBUG_STARTING_WINDOW) Slog.v (TAG_WM, "addWindow: " + aToken
                         + " startingWindow=" + win);
             }
 
@@ -2725,7 +2726,7 @@
         if (wtoken == null) {
             return null;
         }
-        return wtoken.appWindowToken;
+        return wtoken.asAppWindowToken();
     }
 
     @Override
@@ -3534,7 +3535,7 @@
 
     public void removeAppStartingWindow(IBinder token) {
         synchronized (mWindowMap) {
-            final AppWindowToken wtoken = mTokenMap.get(token).appWindowToken;
+            final AppWindowToken wtoken = mTokenMap.get(token).asAppWindowToken();
             scheduleRemoveStartingWindowLocked(wtoken);
         }
     }
@@ -3788,7 +3789,7 @@
         final long origId = Binder.clearCallingIdentity();
         synchronized(mWindowMap) {
             WindowToken basewtoken = mTokenMap.remove(token);
-            if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) {
+            if (basewtoken != null && (wtoken = basewtoken.asAppWindowToken()) != null) {
                 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app token: " + wtoken);
                 delayed = wtoken.setVisibility(null, false,
                         TRANSIT_UNSET, true, wtoken.voiceInteraction);
diff --git a/services/core/java/com/android/server/wm/WindowState.java b/services/core/java/com/android/server/wm/WindowState.java
index 845f112..0ea353b 100644
--- a/services/core/java/com/android/server/wm/WindowState.java
+++ b/services/core/java/com/android/server/wm/WindowState.java
@@ -629,7 +629,7 @@
 
         final WindowState topParentWindow = getTopParentWindow();
         WindowToken rootToken = topParentWindow.mToken;
-        while (rootToken.appWindowToken == null) {
+        while (rootToken.asAppWindowToken() == null) {
             WindowToken parent = mService.mTokenMap.get(rootToken.token);
             if (parent == null || rootToken == parent) {
                 break;
@@ -637,7 +637,7 @@
             rootToken = parent;
         }
         mRootToken = rootToken;
-        mAppToken = rootToken.appWindowToken;
+        mAppToken = rootToken.asAppWindowToken();
         if (mAppToken != null) {
             final DisplayContent appDisplay = getDisplayContent();
             mNotOnAppsDisplay = displayContent != appDisplay;
diff --git a/services/core/java/com/android/server/wm/WindowToken.java b/services/core/java/com/android/server/wm/WindowToken.java
index c421cea..fdcce27 100644
--- a/services/core/java/com/android/server/wm/WindowToken.java
+++ b/services/core/java/com/android/server/wm/WindowToken.java
@@ -51,7 +51,7 @@
     private static final String TAG = TAG_WITH_CLASS_NAME ? "WindowToken" : TAG_WM;
 
     // The window manager!
-    final WindowManagerService service;
+    protected final WindowManagerService mService;
 
     // The actual token.
     final IBinder token;
@@ -66,9 +66,6 @@
     // For printing.
     String stringName;
 
-    // If this is an AppWindowToken, this is non-null.
-    AppWindowToken appWindowToken;
-
     // All of the windows associated with this token.
     protected final WindowList windows = new WindowList();
 
@@ -89,8 +86,8 @@
     // windows will be put to the bottom of the list.
     boolean sendingToBottom;
 
-    WindowToken(WindowManagerService _service, IBinder _token, int type, boolean _explicit) {
-        service = _service;
+    WindowToken(WindowManagerService service, IBinder _token, int type, boolean _explicit) {
+        mService = service;
         token = _token;
         windowType = type;
         explicit = _explicit;
@@ -126,8 +123,8 @@
             if (win.isVisibleNow()) {
                 win.mWinAnimator.applyAnimationLocked(TRANSIT_EXIT, false);
                 //TODO (multidisplay): Magnification is supported only for the default
-                if (service.mAccessibilityController != null && win.isDefaultDisplay()) {
-                    service.mAccessibilityController.onWindowTransitionLocked(win, TRANSIT_EXIT);
+                if (mService.mAccessibilityController != null && win.isDefaultDisplay()) {
+                    mService.mAccessibilityController.onWindowTransitionLocked(win, TRANSIT_EXIT);
                 }
                 changed = true;
                 if (displayContent != null) {
@@ -139,8 +136,8 @@
         hidden = true;
 
         if (changed) {
-            service.mWindowPlacerLocked.performSurfacePlacement();
-            service.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, false /*updateInputWindows*/);
+            mService.mWindowPlacerLocked.performSurfacePlacement();
+            mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, false /*updateInputWindows*/);
         }
 
         if (delayed && displayContent != null) {
@@ -266,7 +263,7 @@
 
         if (!win.isChildWindow()) {
             int tokenWindowsPos = 0;
-            if (appWindowToken != null) {
+            if (asAppWindowToken() != null) {
                 tokenWindowsPos = addAppWindow(win);
             } else {
                 win.addNonAppWindowToList();
@@ -301,7 +298,7 @@
         }
 
         // No windows from this token on this display
-        if (service.localLOGV) Slog.v(TAG_WM, "Figuring out where to add app window "
+        if (mService.localLOGV) Slog.v(TAG_WM, "Figuring out where to add app window "
                 + client.asBinder() + " (token=" + this + ")");
 
         // Figure out where the window should go, based on the order of applications.
@@ -343,7 +340,7 @@
         // position; else we need to look some more.
         if (pos != null) {
             // Move behind any windows attached to this one.
-            final WindowToken atoken = service.mTokenMap.get(pos.mClient.asBinder());
+            final WindowToken atoken = mService.mTokenMap.get(pos.mClient.asBinder());
             if (atoken != null) {
                 tokenWindowList = atoken.getTokenWindowsOnDisplay(displayContent);
                 final int NC = tokenWindowList.size();
@@ -378,7 +375,7 @@
 
         if (pos != null) {
             // Move in front of any windows attached to this one.
-            final WindowToken atoken = service.mTokenMap.get(pos.mClient.asBinder());
+            final WindowToken atoken = mService.mTokenMap.get(pos.mClient.asBinder());
             if (atoken != null) {
                 final WindowState top = atoken.getTopWindow();
                 if (top != null && top.mSubLayer >= 0) {
@@ -406,7 +403,7 @@
                 "Based on layer: Adding window " + win + " at " + (i + 1) + " of "
                         + windows.size());
         windows.add(i + 1, win);
-        service.mWindowsChanged = true;
+        mService.mWindowsChanged = true;
         return tokenWindowsPos;
     }
 
@@ -443,7 +440,7 @@
                 } else {
                     tokenWindowsPos = getWindowIndex(windowList.get(newIdx)) + 1;
                 }
-                service.mWindowsChanged = true;
+                mService.mWindowsChanged = true;
             }
         }
         return tokenWindowsPos;
@@ -529,7 +526,7 @@
     }
 
     void updateWallpaperOffset(int dw, int dh, boolean sync) {
-        final WallpaperController wallpaperController = service.mWallpaperControllerLocked;
+        final WallpaperController wallpaperController = mService.mWallpaperControllerLocked;
         for (int wallpaperNdx = windows.size() - 1; wallpaperNdx >= 0; wallpaperNdx--) {
             WindowState wallpaper = windows.get(wallpaperNdx);
             if (wallpaperController.updateWallpaperOffset(wallpaper, dw, dh, sync)) {
@@ -550,7 +547,7 @@
             displayContent.layoutNeeded = true;
         }
 
-        final WallpaperController wallpaperController = service.mWallpaperControllerLocked;
+        final WallpaperController wallpaperController = mService.mWallpaperControllerLocked;
         for (int wallpaperNdx = windows.size() - 1; wallpaperNdx >= 0; wallpaperNdx--) {
             WindowState wallpaper = windows.get(wallpaperNdx);
             if (visible) {
@@ -570,10 +567,10 @@
                     "Wallpaper token " + token + " hidden=" + !visible);
             hidden = !visible;
             // Need to do a layout to ensure the wallpaper now has the correct size.
-            service.getDefaultDisplayContentLocked().layoutNeeded = true;
+            mService.getDefaultDisplayContentLocked().layoutNeeded = true;
         }
 
-        final WallpaperController wallpaperController = service.mWallpaperControllerLocked;
+        final WallpaperController wallpaperController = mService.mWallpaperControllerLocked;
         for (int wallpaperNdx = windows.size() - 1; wallpaperNdx >= 0; wallpaperNdx--) {
             final WindowState wallpaper = windows.get(wallpaperNdx);
 
@@ -603,7 +600,7 @@
                 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
                         "Wallpaper removing at " + oldIndex + ": " + wallpaper);
                 windowList.remove(oldIndex);
-                service.mWindowsChanged = true;
+                mService.mWindowsChanged = true;
                 if (oldIndex < wallpaperTargetIndex) {
                     wallpaperTargetIndex--;
                 }
@@ -624,7 +621,7 @@
                     "Moving wallpaper " + wallpaper + " from " + oldIndex + " to " + insertionIndex);
 
             windowList.add(insertionIndex, wallpaper);
-            service.mWindowsChanged = true;
+            mService.mWindowsChanged = true;
             changed = true;
         }
 
@@ -652,6 +649,12 @@
         return layer;
     }
 
+    AppWindowToken asAppWindowToken() {
+        // TODO: Not sure if this is the best way to handle this vs. using instanceof and casting.
+        // I am not an app window token!
+        return null;
+    }
+
     void dump(PrintWriter pw, String prefix) {
         pw.print(prefix); pw.print("windows="); pw.println(windows);
         pw.print(prefix); pw.print("windowType="); pw.print(windowType);