use of android.os.Message in project android_frameworks_base by ParanoidAndroid.
the class PowerManagerService method shutdownOrRebootInternal.
private void shutdownOrRebootInternal(final boolean shutdown, final boolean confirm, final String reason, boolean wait) {
if (mHandler == null || !mSystemReady) {
throw new IllegalStateException("Too early to call shutdown() or reboot()");
}
Runnable runnable = new Runnable() {
@Override
public void run() {
synchronized (this) {
if (shutdown) {
ShutdownThread.shutdown(mContext, confirm);
} else {
ShutdownThread.reboot(mContext, reason, confirm);
}
}
}
};
// ShutdownThread must run on a looper capable of displaying the UI.
Message msg = Message.obtain(mHandler, runnable);
msg.setAsynchronous(true);
mHandler.sendMessage(msg);
// PowerManager.reboot() is documented not to return so just wait for the inevitable.
if (wait) {
synchronized (runnable) {
while (true) {
try {
runnable.wait();
} catch (InterruptedException e) {
}
}
}
}
}
use of android.os.Message in project android_frameworks_base by ParanoidAndroid.
the class UsbDebuggingManager method listenToSocket.
private void listenToSocket() throws IOException {
try {
byte[] buffer = new byte[BUFFER_SIZE];
LocalSocketAddress address = new LocalSocketAddress(ADBD_SOCKET, LocalSocketAddress.Namespace.RESERVED);
InputStream inputStream = null;
mSocket = new LocalSocket();
mSocket.connect(address);
mOutputStream = mSocket.getOutputStream();
inputStream = mSocket.getInputStream();
while (true) {
int count = inputStream.read(buffer);
if (count < 0) {
Slog.e(TAG, "got " + count + " reading");
break;
}
if (buffer[0] == 'P' && buffer[1] == 'K') {
String key = new String(Arrays.copyOfRange(buffer, 2, count));
Slog.d(TAG, "Received public key: " + key);
Message msg = mHandler.obtainMessage(UsbDebuggingHandler.MESSAGE_ADB_CONFIRM);
msg.obj = key;
mHandler.sendMessage(msg);
} else {
Slog.e(TAG, "Wrong message: " + (new String(Arrays.copyOfRange(buffer, 0, 2))));
break;
}
}
} catch (IOException ex) {
Slog.e(TAG, "Communication error: ", ex);
throw ex;
} finally {
closeSocket();
}
}
use of android.os.Message in project android_frameworks_base by ParanoidAndroid.
the class WindowManagerService method removeWindowInnerLocked.
private void removeWindowInnerLocked(Session session, WindowState win) {
if (win.mRemoved) {
// Nothing to do.
return;
}
for (int i = win.mChildWindows.size() - 1; i >= 0; i--) {
WindowState cwin = win.mChildWindows.get(i);
Slog.w(TAG, "Force-removing child win " + cwin + " from container " + win);
removeWindowInnerLocked(cwin.mSession, cwin);
}
win.mRemoved = true;
if (mInputMethodTarget == win) {
moveInputMethodWindowsIfNeededLocked(false);
}
if (false) {
RuntimeException e = new RuntimeException("here");
e.fillInStackTrace();
Slog.w(TAG, "Removing window " + win, e);
}
mPolicy.removeWindowLw(win);
win.removeLocked();
if (DEBUG_ADD_REMOVE)
Slog.v(TAG, "removeWindowInnerLocked: " + win);
mWindowMap.remove(win.mClient.asBinder());
if (win.mAppOp != AppOpsManager.OP_NONE) {
mAppOps.finishOp(win.mAppOp, win.getOwningUid(), win.getOwningPackage());
}
final WindowList windows = win.getWindowList();
windows.remove(win);
mPendingRemove.remove(win);
mResizingWindows.remove(win);
mWindowsChanged = true;
if (DEBUG_WINDOW_MOVEMENT)
Slog.v(TAG, "Final remove of window: " + win);
if (mInputMethodWindow == win) {
mInputMethodWindow = null;
} else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) {
mInputMethodDialogs.remove(win);
}
final WindowToken token = win.mToken;
final AppWindowToken atoken = win.mAppToken;
if (DEBUG_ADD_REMOVE)
Slog.v(TAG, "Removing " + win + " from " + token);
token.windows.remove(win);
if (atoken != null) {
atoken.allAppWindows.remove(win);
}
if (localLOGV)
Slog.v(TAG, "**** Removing window " + win + ": count=" + token.windows.size());
if (token.windows.size() == 0) {
if (!token.explicit) {
mTokenMap.remove(token.token);
} else if (atoken != null) {
atoken.firstWindowDrawn = false;
}
}
if (atoken != null) {
if (atoken.startingWindow == win) {
if (DEBUG_STARTING_WINDOW)
Slog.v(TAG, "Nulling startingWindow " + win);
atoken.startingWindow = null;
} else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) {
// transition window, well there is no point now.
if (DEBUG_STARTING_WINDOW)
Slog.v(TAG, "Nulling last startingWindow");
atoken.startingData = null;
} else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) {
// window, we need to get rid of the starting transition.
if (DEBUG_STARTING_WINDOW) {
Slog.v(TAG, "Schedule remove starting " + token + ": no more real windows");
}
Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken);
mH.sendMessage(m);
}
}
if (win.mAttrs.type == TYPE_WALLPAPER) {
mLastWallpaperTimeoutTime = 0;
getDefaultDisplayContentLocked().pendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
} else if ((win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) {
getDefaultDisplayContentLocked().pendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
}
if (!mInLayout) {
assignLayersLocked(windows);
win.mDisplayContent.layoutNeeded = true;
performLayoutAndPlaceSurfacesLocked();
if (win.mAppToken != null) {
win.mAppToken.updateReportedVisibilityLocked();
}
}
mInputMonitor.updateInputWindowsLw(true);
}
use of android.os.Message in project android_frameworks_base by ParanoidAndroid.
the class WindowManagerService method prepareDragSurface.
// -------------------------------------------------------------
// Drag and drop
// -------------------------------------------------------------
IBinder prepareDragSurface(IWindow window, SurfaceSession session, int flags, int width, int height, Surface outSurface) {
if (DEBUG_DRAG) {
Slog.d(TAG, "prepare drag surface: w=" + width + " h=" + height + " flags=" + Integer.toHexString(flags) + " win=" + window + " asbinder=" + window.asBinder());
}
final int callerPid = Binder.getCallingPid();
final long origId = Binder.clearCallingIdentity();
IBinder token = null;
try {
synchronized (mWindowMap) {
try {
if (mDragState == null) {
// TODO(multi-display): support other displays
final DisplayContent displayContent = getDefaultDisplayContentLocked();
final Display display = displayContent.getDisplay();
SurfaceControl surface = new SurfaceControl(session, "drag surface", width, height, PixelFormat.TRANSLUCENT, SurfaceControl.HIDDEN);
surface.setLayerStack(display.getLayerStack());
if (SHOW_TRANSACTIONS)
Slog.i(TAG, " DRAG " + surface + ": CREATE");
outSurface.copyFrom(surface);
final IBinder winBinder = window.asBinder();
token = new Binder();
mDragState = new DragState(this, token, surface, /*flags*/
0, winBinder);
token = mDragState.mToken = new Binder();
// 5 second timeout for this window to actually begin the drag
mH.removeMessages(H.DRAG_START_TIMEOUT, winBinder);
Message msg = mH.obtainMessage(H.DRAG_START_TIMEOUT, winBinder);
mH.sendMessageDelayed(msg, 5000);
} else {
Slog.w(TAG, "Drag already in progress");
}
} catch (SurfaceControl.OutOfResourcesException e) {
Slog.e(TAG, "Can't allocate drag surface w=" + width + " h=" + height, e);
if (mDragState != null) {
mDragState.reset();
mDragState = null;
}
}
}
} finally {
Binder.restoreCallingIdentity(origId);
}
return token;
}
use of android.os.Message in project android_frameworks_base by ParanoidAndroid.
the class WindowManagerService method waitForWindowDrawn.
@Override
public boolean waitForWindowDrawn(IBinder token, IRemoteCallback callback) {
if (token != null && callback != null) {
synchronized (mWindowMap) {
WindowState win = windowForClientLocked(null, token, true);
if (win != null) {
Pair<WindowState, IRemoteCallback> pair = new Pair<WindowState, IRemoteCallback>(win, callback);
Message m = mH.obtainMessage(H.WAITING_FOR_DRAWN_TIMEOUT, pair);
mH.sendMessageDelayed(m, 2000);
mWaitingForDrawn.add(pair);
checkDrawnWindowsLocked();
return true;
}
}
}
return false;
}
Aggregations