Session.java revision b961cd2c80abf1d2834e5ad690904da4fe56d755
16e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn/*
26e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn * Copyright (C) 2011 The Android Open Source Project
36e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn *
46e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn * Licensed under the Apache License, Version 2.0 (the "License");
56e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn * you may not use this file except in compliance with the License.
66e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn * You may obtain a copy of the License at
76e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn *
86e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn *      http://www.apache.org/licenses/LICENSE-2.0
96e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn *
106e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn * Unless required by applicable law or agreed to in writing, software
116e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn * distributed under the License is distributed on an "AS IS" BASIS,
126e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
136e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn * See the License for the specific language governing permissions and
146e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn * limitations under the License.
156e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn */
166e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn
176e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackbornpackage com.android.server.wm;
186e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn
196e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackbornimport com.android.internal.view.IInputContext;
206e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackbornimport com.android.internal.view.IInputMethodClient;
216e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackbornimport com.android.internal.view.IInputMethodManager;
226e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackbornimport com.android.server.wm.WindowManagerService.H;
236e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn
246e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackbornimport android.content.ClipData;
256e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackbornimport android.content.Context;
266e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackbornimport android.content.res.Configuration;
276e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackbornimport android.graphics.Rect;
286e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackbornimport android.graphics.Region;
296e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackbornimport android.os.Binder;
306e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackbornimport android.os.Bundle;
316e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackbornimport android.os.IBinder;
326e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackbornimport android.os.Parcel;
336e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackbornimport android.os.RemoteException;
346e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackbornimport android.os.ServiceManager;
356e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackbornimport android.util.Slog;
366e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackbornimport android.view.IWindow;
376e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackbornimport android.view.IWindowSession;
386e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackbornimport android.view.InputChannel;
396e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackbornimport android.view.Surface;
406e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackbornimport android.view.SurfaceSession;
416e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackbornimport android.view.WindowManager;
426e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn
436e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackbornimport java.io.PrintWriter;
446e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn
456e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn/**
466e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn * This class represents an active client session.  There is generally one
476e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn * Session object per process that is interacting with the window manager.
486e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn */
496e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackbornfinal class Session extends IWindowSession.Stub
506e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        implements IBinder.DeathRecipient {
516e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn    final WindowManagerService mService;
526e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn    final IInputMethodClient mClient;
536e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn    final IInputContext mInputContext;
546e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn    final int mUid;
556e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn    final int mPid;
566e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn    final String mStringName;
576e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn    SurfaceSession mSurfaceSession;
586e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn    int mNumWindow = 0;
596e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn    boolean mClientDead = false;
606e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn
616e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn    public Session(WindowManagerService service, IInputMethodClient client,
626e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            IInputContext inputContext) {
636e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        mService = service;
646e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        mClient = client;
656e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        mInputContext = inputContext;
666e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        mUid = Binder.getCallingUid();
676e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        mPid = Binder.getCallingPid();
686e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        StringBuilder sb = new StringBuilder();
696e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        sb.append("Session{");
706e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        sb.append(Integer.toHexString(System.identityHashCode(this)));
716e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        sb.append(" uid ");
726e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        sb.append(mUid);
736e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        sb.append("}");
746e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        mStringName = sb.toString();
756e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn
766e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        synchronized (mService.mWindowMap) {
776e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            if (mService.mInputMethodManager == null && mService.mHaveInputMethods) {
786e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                IBinder b = ServiceManager.getService(
796e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                        Context.INPUT_METHOD_SERVICE);
806e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                mService.mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
816e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            }
826e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        }
836e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        long ident = Binder.clearCallingIdentity();
846e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        try {
856e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            // Note: it is safe to call in to the input method manager
866e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            // here because we are not holding our lock.
876e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            if (mService.mInputMethodManager != null) {
886e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                mService.mInputMethodManager.addClient(client, inputContext,
896e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                        mUid, mPid);
906e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            } else {
916e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                client.setUsingInputMethod(false);
926e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            }
936e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            client.asBinder().linkToDeath(this, 0);
946e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        } catch (RemoteException e) {
956e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            // The caller has died, so we can just forget about this.
966e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            try {
976e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                if (mService.mInputMethodManager != null) {
986e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                    mService.mInputMethodManager.removeClient(client);
996e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                }
1006e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            } catch (RemoteException ee) {
1016e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            }
1026e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        } finally {
1036e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            Binder.restoreCallingIdentity(ident);
1046e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        }
1056e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn    }
1066e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn
1076e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn    @Override
1086e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn    public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
1096e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            throws RemoteException {
1106e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        try {
1116e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            return super.onTransact(code, data, reply, flags);
1126e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        } catch (RuntimeException e) {
1136e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            // Log all 'real' exceptions thrown to the caller
1146e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            if (!(e instanceof SecurityException)) {
1156e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                Slog.e(WindowManagerService.TAG, "Window Session Crash", e);
1166e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            }
1176e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            throw e;
1186e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        }
1196e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn    }
1206e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn
1216e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn    public void binderDied() {
1226e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        // Note: it is safe to call in to the input method manager
1236e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        // here because we are not holding our lock.
1246e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        try {
1256e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            if (mService.mInputMethodManager != null) {
1266e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                mService.mInputMethodManager.removeClient(mClient);
1276e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            }
1286e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        } catch (RemoteException e) {
1296e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        }
1306e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        synchronized(mService.mWindowMap) {
1316e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            mClient.asBinder().unlinkToDeath(this, 0);
1326e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            mClientDead = true;
1336e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            killSessionLocked();
1346e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        }
1356e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn    }
1366e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn
1376e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn    public int add(IWindow window, WindowManager.LayoutParams attrs,
1386e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) {
1396e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        return mService.addWindow(this, window, attrs, viewVisibility, outContentInsets,
1406e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                outInputChannel);
1416e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn    }
1426e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn
1436e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn    public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs,
1446e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            int viewVisibility, Rect outContentInsets) {
1456e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        return mService.addWindow(this, window, attrs, viewVisibility, outContentInsets, null);
1466e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn    }
1476e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn
1486e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn    public void remove(IWindow window) {
1496e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        mService.removeWindow(this, window);
1506e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn    }
1516e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn
1526e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn    public int relayout(IWindow window, WindowManager.LayoutParams attrs,
1536e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            int requestedWidth, int requestedHeight, int viewFlags,
1546e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            boolean insetsPending, Rect outFrame, Rect outContentInsets,
1556e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            Rect outVisibleInsets, Configuration outConfig, Surface outSurface) {
156b961cd2c80abf1d2834e5ad690904da4fe56d755Dianne Hackborn        if (false) Slog.d(WindowManagerService.TAG, ">>>>>> ENTERED relayout from "
157b961cd2c80abf1d2834e5ad690904da4fe56d755Dianne Hackborn                + Binder.getCallingPid());
1586e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        int res = mService.relayoutWindow(this, window, attrs,
1596e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                requestedWidth, requestedHeight, viewFlags, insetsPending,
1606e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface);
161b961cd2c80abf1d2834e5ad690904da4fe56d755Dianne Hackborn        if (false) Slog.d(WindowManagerService.TAG, "<<<<<< EXITING relayout to "
162b961cd2c80abf1d2834e5ad690904da4fe56d755Dianne Hackborn                + Binder.getCallingPid());
1636e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        return res;
1646e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn    }
1656e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn
166648251710162cdaf7371012a1cbb79b9bc5bc0e4Dianne Hackborn    public boolean outOfMemory(IWindow window) {
167648251710162cdaf7371012a1cbb79b9bc5bc0e4Dianne Hackborn        return mService.outOfMemoryWindow(this, window);
168648251710162cdaf7371012a1cbb79b9bc5bc0e4Dianne Hackborn    }
169648251710162cdaf7371012a1cbb79b9bc5bc0e4Dianne Hackborn
1706e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn    public void setTransparentRegion(IWindow window, Region region) {
1716e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        mService.setTransparentRegionWindow(this, window, region);
1726e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn    }
1736e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn
1746e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn    public void setInsets(IWindow window, int touchableInsets,
1756e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            Rect contentInsets, Rect visibleInsets, Region touchableArea) {
1766e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        mService.setInsetsWindow(this, window, touchableInsets, contentInsets,
1776e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                visibleInsets, touchableArea);
1786e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn    }
1796e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn
1806e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn    public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
1816e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        mService.getWindowDisplayFrame(this, window, outDisplayFrame);
1826e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn    }
1836e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn
1846e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn    public void finishDrawing(IWindow window) {
1856e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        if (WindowManagerService.localLOGV) Slog.v(
1866e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            WindowManagerService.TAG, "IWindow finishDrawing called for " + window);
1876e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        mService.finishDrawingWindow(this, window);
1886e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn    }
1896e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn
1906e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn    public void setInTouchMode(boolean mode) {
1916e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        synchronized(mService.mWindowMap) {
1926e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            mService.mInTouchMode = mode;
1936e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        }
1946e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn    }
1956e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn
1966e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn    public boolean getInTouchMode() {
1976e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        synchronized(mService.mWindowMap) {
1986e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            return mService.mInTouchMode;
1996e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        }
2006e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn    }
2016e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn
2026e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn    public boolean performHapticFeedback(IWindow window, int effectId,
2036e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            boolean always) {
2046e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        synchronized(mService.mWindowMap) {
2056e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            long ident = Binder.clearCallingIdentity();
2066e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            try {
2076e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                return mService.mPolicy.performHapticFeedbackLw(
2086e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                        mService.windowForClientLocked(this, window, true),
2096e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                        effectId, always);
2106e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            } finally {
2116e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                Binder.restoreCallingIdentity(ident);
2126e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            }
2136e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        }
2146e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn    }
2156e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn
2166e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn    /* Drag/drop */
2176e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn    public IBinder prepareDrag(IWindow window, int flags,
2186e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            int width, int height, Surface outSurface) {
2196e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        return mService.prepareDragSurface(window, mSurfaceSession, flags,
2206e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                width, height, outSurface);
2216e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn    }
2226e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn
2236e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn    public boolean performDrag(IWindow window, IBinder dragToken,
2246e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            float touchX, float touchY, float thumbCenterX, float thumbCenterY,
2256e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            ClipData data) {
2266e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        if (WindowManagerService.DEBUG_DRAG) {
2276e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            Slog.d(WindowManagerService.TAG, "perform drag: win=" + window + " data=" + data);
2286e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        }
2296e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn
2306e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        synchronized (mService.mWindowMap) {
2316e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            if (mService.mDragState == null) {
2326e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                Slog.w(WindowManagerService.TAG, "No drag prepared");
2336e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                throw new IllegalStateException("performDrag() without prepareDrag()");
2346e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            }
2356e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn
2366e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            if (dragToken != mService.mDragState.mToken) {
2376e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                Slog.w(WindowManagerService.TAG, "Performing mismatched drag");
2386e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                throw new IllegalStateException("performDrag() does not match prepareDrag()");
2396e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            }
2406e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn
2416e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            WindowState callingWin = mService.windowForClientLocked(null, window, false);
2426e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            if (callingWin == null) {
2436e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                Slog.w(WindowManagerService.TAG, "Bad requesting window " + window);
2446e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                return false;  // !!! TODO: throw here?
2456e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            }
2466e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn
2476e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            // !!! TODO: if input is not still focused on the initiating window, fail
2486e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            // the drag initiation (e.g. an alarm window popped up just as the application
2496e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            // called performDrag()
2506e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn
2516e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            mService.mH.removeMessages(H.DRAG_START_TIMEOUT, window.asBinder());
2526e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn
2536e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            // !!! TODO: extract the current touch (x, y) in screen coordinates.  That
2546e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            // will let us eliminate the (touchX,touchY) parameters from the API.
2556e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn
2566e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            // !!! FIXME: put all this heavy stuff onto the mH looper, as well as
2576e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            // the actual drag event dispatch stuff in the dragstate
2586e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn
2596e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            mService.mDragState.register();
2606e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            mService.mInputMonitor.updateInputWindowsLw(true /*force*/);
2616e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            if (!mService.mInputManager.transferTouchFocus(callingWin.mInputChannel,
2626e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                    mService.mDragState.mServerChannel)) {
2636e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                Slog.e(WindowManagerService.TAG, "Unable to transfer touch focus");
2646e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                mService.mDragState.unregister();
2656e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                mService.mDragState = null;
2666e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                mService.mInputMonitor.updateInputWindowsLw(true /*force*/);
2676e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                return false;
2686e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            }
2696e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn
2706e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            mService.mDragState.mData = data;
2716e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            mService.mDragState.mCurrentX = touchX;
2726e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            mService.mDragState.mCurrentY = touchY;
2736e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            mService.mDragState.broadcastDragStartedLw(touchX, touchY);
2746e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn
2756e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            // remember the thumb offsets for later
2766e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            mService.mDragState.mThumbOffsetX = thumbCenterX;
2776e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            mService.mDragState.mThumbOffsetY = thumbCenterY;
2786e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn
2796e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            // Make the surface visible at the proper location
2806e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            final Surface surface = mService.mDragState.mSurface;
2816e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            if (WindowManagerService.SHOW_TRANSACTIONS) Slog.i(WindowManagerService.TAG, ">>> OPEN TRANSACTION performDrag");
2826e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            Surface.openTransaction();
2836e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            try {
2846e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                surface.setPosition((int)(touchX - thumbCenterX),
2856e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                        (int)(touchY - thumbCenterY));
2866e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                surface.setAlpha(.7071f);
2876e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                surface.setLayer(mService.mDragState.getDragLayerLw());
2886e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                surface.show();
2896e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            } finally {
2906e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                Surface.closeTransaction();
2916e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                if (WindowManagerService.SHOW_TRANSACTIONS) Slog.i(WindowManagerService.TAG, "<<< CLOSE TRANSACTION performDrag");
2926e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            }
2936e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        }
2946e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn
2956e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        return true;    // success!
2966e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn    }
2976e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn
2986e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn    public void reportDropResult(IWindow window, boolean consumed) {
2996e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        IBinder token = window.asBinder();
3006e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        if (WindowManagerService.DEBUG_DRAG) {
3016e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            Slog.d(WindowManagerService.TAG, "Drop result=" + consumed + " reported by " + token);
3026e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        }
3036e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn
3046e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        synchronized (mService.mWindowMap) {
3056e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            long ident = Binder.clearCallingIdentity();
3066e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            try {
3076e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                if (mService.mDragState == null || mService.mDragState.mToken != token) {
3086e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                    Slog.w(WindowManagerService.TAG, "Invalid drop-result claim by " + window);
3096e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                    throw new IllegalStateException("reportDropResult() by non-recipient");
3106e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                }
3116e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn
3126e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                // The right window has responded, even if it's no longer around,
3136e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                // so be sure to halt the timeout even if the later WindowState
3146e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                // lookup fails.
3156e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                mService.mH.removeMessages(H.DRAG_END_TIMEOUT, window.asBinder());
3166e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                WindowState callingWin = mService.windowForClientLocked(null, window, false);
3176e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                if (callingWin == null) {
3186e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                    Slog.w(WindowManagerService.TAG, "Bad result-reporting window " + window);
3196e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                    return;  // !!! TODO: throw here?
3206e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                }
3216e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn
3226e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                mService.mDragState.mDragResult = consumed;
3236e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                mService.mDragState.endDragLw();
3246e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            } finally {
3256e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                Binder.restoreCallingIdentity(ident);
3266e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            }
3276e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        }
3286e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn    }
3296e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn
3306e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn    public void dragRecipientEntered(IWindow window) {
3316e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        if (WindowManagerService.DEBUG_DRAG) {
3326e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            Slog.d(WindowManagerService.TAG, "Drag into new candidate view @ " + window.asBinder());
3336e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        }
3346e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn    }
3356e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn
3366e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn    public void dragRecipientExited(IWindow window) {
3376e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        if (WindowManagerService.DEBUG_DRAG) {
3386e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            Slog.d(WindowManagerService.TAG, "Drag from old candidate view @ " + window.asBinder());
3396e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        }
3406e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn    }
3416e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn
3426e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn    public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
3436e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        synchronized(mService.mWindowMap) {
3446e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            long ident = Binder.clearCallingIdentity();
3456e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            try {
3466e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                mService.setWindowWallpaperPositionLocked(
3476e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                        mService.windowForClientLocked(this, window, true),
3486e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                        x, y, xStep, yStep);
3496e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            } finally {
3506e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                Binder.restoreCallingIdentity(ident);
3516e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            }
3526e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        }
3536e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn    }
3546e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn
3556e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn    public void wallpaperOffsetsComplete(IBinder window) {
3566e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        mService.wallpaperOffsetsComplete(window);
3576e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn    }
3586e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn
3596e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn    public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
3606e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            int z, Bundle extras, boolean sync) {
3616e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        synchronized(mService.mWindowMap) {
3626e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            long ident = Binder.clearCallingIdentity();
3636e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            try {
3646e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                return mService.sendWindowWallpaperCommandLocked(
3656e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                        mService.windowForClientLocked(this, window, true),
3666e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                        action, x, y, z, extras, sync);
3676e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            } finally {
3686e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                Binder.restoreCallingIdentity(ident);
3696e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            }
3706e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        }
3716e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn    }
3726e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn
3736e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn    public void wallpaperCommandComplete(IBinder window, Bundle result) {
3746e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        mService.wallpaperCommandComplete(window, result);
3756e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn    }
3766e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn
3776e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn    void windowAddedLocked() {
3786e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        if (mSurfaceSession == null) {
3796e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            if (WindowManagerService.localLOGV) Slog.v(
3806e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                WindowManagerService.TAG, "First window added to " + this + ", creating SurfaceSession");
3816e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            mSurfaceSession = new SurfaceSession();
3826e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            if (WindowManagerService.SHOW_TRANSACTIONS) Slog.i(
3836e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                    WindowManagerService.TAG, "  NEW SURFACE SESSION " + mSurfaceSession);
3846e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            mService.mSessions.add(this);
3856e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        }
3866e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        mNumWindow++;
3876e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn    }
3886e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn
3896e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn    void windowRemovedLocked() {
3906e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        mNumWindow--;
3916e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        killSessionLocked();
3926e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn    }
3936e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn
3946e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn    void killSessionLocked() {
3956e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        if (mNumWindow <= 0 && mClientDead) {
3966e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            mService.mSessions.remove(this);
3976e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            if (mSurfaceSession != null) {
3986e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                if (WindowManagerService.localLOGV) Slog.v(
3996e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                    WindowManagerService.TAG, "Last window removed from " + this
4006e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                    + ", destroying " + mSurfaceSession);
4016e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                if (WindowManagerService.SHOW_TRANSACTIONS) Slog.i(
4026e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                        WindowManagerService.TAG, "  KILL SURFACE SESSION " + mSurfaceSession);
4036e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                try {
4046e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                    mSurfaceSession.kill();
4056e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                } catch (Exception e) {
4066e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                    Slog.w(WindowManagerService.TAG, "Exception thrown when killing surface session "
4076e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                        + mSurfaceSession + " in session " + this
4086e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                        + ": " + e.toString());
4096e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                }
4106e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                mSurfaceSession = null;
4116e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn            }
4126e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        }
4136e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn    }
4146e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn
4156e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn    void dump(PrintWriter pw, String prefix) {
4166e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
4176e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                pw.print(" mClientDead="); pw.print(mClientDead);
4186e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn                pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
4196e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn    }
4206e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn
4216e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn    @Override
4226e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn    public String toString() {
4236e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn        return mStringName;
4246e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn    }
4256e1eb76f02ccc9dbc309b938f62d39312da8cafeDianne Hackborn}