下面列出了android.view.IRotationWatcher#android.view.IWindowManager 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public LegacySensorManager(SensorManager sensorManager) {
mSensorManager = sensorManager;
synchronized (SensorManager.class) {
if (!sInitialized) {
sWindowManager = IWindowManager.Stub.asInterface(
ServiceManager.getService("window"));
if (sWindowManager != null) {
// if it's null we're running in the system process
// which won't get the rotated values
try {
sRotation = sWindowManager.watchRotation(
new IRotationWatcher.Stub() {
public void onRotationChanged(int rotation) {
LegacySensorManager.onRotationChanged(rotation);
}
}, DEFAULT_DISPLAY);
} catch (RemoteException e) {
}
}
}
}
}
@SuppressLint("PrivateApi")
public DisplayUtil() {
Class<?> serviceManagerClass = null;
try {
serviceManagerClass = Class.forName("android.os.ServiceManager");
Method getService = serviceManagerClass.getDeclaredMethod("getService", String.class);
// WindowManager
Object ws = getService.invoke(null, Context.WINDOW_SERVICE);
iWindowManager = IWindowManager.Stub.asInterface((IBinder) ws);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Force the global system in or out of touch mode. This can be used if
* your instrumentation relies on the UI being in one more or the other
* when it starts.
*
* @param inTouch Set to true to be in touch mode, false to be in
* focus mode.
*/
public void setInTouchMode(boolean inTouch) {
try {
IWindowManager.Stub.asInterface(
ServiceManager.getService("window")).setInTouchMode(inTouch);
} catch (RemoteException e) {
// Shouldn't happen!
}
}
/**
* Force the global system in or out of touch mode. This can be used if
* your instrumentation relies on the UI being in one more or the other
* when it starts.
*
* @param inTouch Set to true to be in touch mode, false to be in
* focus mode.
*/
public void setInTouchMode(boolean inTouch) {
try {
IWindowManager.Stub.asInterface(
ServiceManager.getService("window")).setInTouchMode(inTouch);
} catch (RemoteException e) {
// Shouldn't happen!
}
}
/**
* Force the global system in or out of touch mode. This can be used if
* your instrumentation relies on the UI being in one more or the other
* when it starts.
*
* @param inTouch Set to true to be in touch mode, false to be in
* focus mode.
*/
public void setInTouchMode(boolean inTouch) {
try {
IWindowManager.Stub.asInterface(
ServiceManager.getService("window")).setInTouchMode(inTouch);
} catch (RemoteException e) {
// Shouldn't happen!
}
}
/**
* Force the global system in or out of touch mode. This can be used if
* your instrumentation relies on the UI being in one more or the other
* when it starts.
*
* @param inTouch Set to true to be in touch mode, false to be in
* focus mode.
*/
public void setInTouchMode(boolean inTouch) {
try {
IWindowManager.Stub.asInterface(
ServiceManager.getService("window")).setInTouchMode(inTouch);
} catch (RemoteException e) {
// Shouldn't happen!
}
}
public WallpaperManagerService(Context context) {
if (DEBUG) Slog.v(TAG, "WallpaperService startup");
mContext = context;
mShuttingDown = false;
mImageWallpaper = ComponentName.unflattenFromString(
context.getResources().getString(R.string.image_wallpaper_component));
mDefaultWallpaperComponent = WallpaperManager.getDefaultWallpaperComponent(context);
mIWindowManager = IWindowManager.Stub.asInterface(
ServiceManager.getService(Context.WINDOW_SERVICE));
mIPackageManager = AppGlobals.getPackageManager();
mAppOpsManager = (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE);
mMonitor = new MyPackageMonitor();
mColorsChangedListeners = new SparseArray<>();
}
boolean injectIsSafeModeEnabled() {
final long token = injectClearCallingIdentity();
try {
return IWindowManager.Stub
.asInterface(ServiceManager.getService(Context.WINDOW_SERVICE))
.isSafeModeEnabled();
} catch (RemoteException e) {
return false; // Shouldn't happen though.
} finally {
injectRestoreCallingIdentity(token);
}
}
/**
* @param callbacks The callbacks to handle the asynchronous reply with the assist data.
* @param callbacksLock The lock for the requester to hold when calling any of the
* {@param callbacks}. The owner should also take care in locking
* appropriately when calling into this requester.
* @param requestStructureAppOps The app ops to check before requesting the assist structure
* @param requestScreenshotAppOps The app ops to check before requesting the assist screenshot.
* This can be {@link AppOpsManager#OP_NONE} to indicate that
* screenshots should never be fetched.
*/
public AssistDataRequester(Context context, IActivityManager service,
IWindowManager windowManager, AppOpsManager appOpsManager,
AssistDataRequesterCallbacks callbacks, Object callbacksLock,
int requestStructureAppOps, int requestScreenshotAppOps) {
mCallbacks = callbacks;
mCallbacksLock = callbacksLock;
mWindowManager = windowManager;
mService = service;
mContext = context;
mAppOpsManager = appOpsManager;
mRequestStructureAppOps = requestStructureAppOps;
mRequestScreenshotAppOps = requestScreenshotAppOps;
}
/**
* Force the global system in or out of touch mode. This can be used if
* your instrumentation relies on the UI being in one more or the other
* when it starts.
*
* @param inTouch Set to true to be in touch mode, false to be in
* focus mode.
*/
public void setInTouchMode(boolean inTouch) {
try {
IWindowManager.Stub.asInterface(
ServiceManager.getService("window")).setInTouchMode(inTouch);
} catch (RemoteException e) {
// Shouldn't happen!
}
}
private static void calculateCanvas() throws Exception {
Method getServiceMethod = Class.forName("android.os.ServiceManager").
getDeclaredMethod("getService", String.class);
Point displaySize = new Point();
IWindowManager wm = IWindowManager.Stub.asInterface((IBinder)
getServiceMethod.invoke(null, Context.WINDOW_SERVICE));
wm.getBaseDisplaySize(0, displaySize);
Rect canvasRect = new Rect(100, 400, displaySize.x - 100, displaySize.y);
Canvas canvas = new Canvas(canvasRect.width(), canvasRect.height(), canvasRect.centerX(),
canvasRect.centerY());
SampleManager.get().setCanvas(canvas);
}
/**
* Force the global system in or out of touch mode. This can be used if
* your instrumentation relies on the UI being in one more or the other
* when it starts.
*
* @param inTouch Set to true to be in touch mode, false to be in
* focus mode.
*/
public void setInTouchMode(boolean inTouch) {
try {
IWindowManager.Stub.asInterface(
ServiceManager.getService("window")).setInTouchMode(inTouch);
} catch (RemoteException e) {
// Shouldn't happen!
}
}
protected IWindowManager create() {
return IWindowManager.Stub.asInterface(ServiceManager.getService("window"));
}
public InjectionManager(Context c)
{
if(Integer.valueOf(android.os.Build.VERSION.SDK_INT) < android.os.Build.VERSION_CODES.JELLY_BEAN)
{
mWmbinder = ServiceManager.getService( INTERNAL_SERVICE_PRE_JELLY );
mWinMan = IWindowManager.Stub.asInterface( mWmbinder );
printDeclaredMethods(mWinMan.getClass());
//TODO: Implement full injection support for pre Jelly Bean solutions
}
else
{
mInputManager = c.getSystemService(Context.INPUT_SERVICE);
try
{
//printDeclaredMethods(mInputManager.getClass());
//Unveil hidden methods
mInjectEventMethod = mInputManager.getClass().getDeclaredMethod("injectInputEvent", new Class[] { InputEvent.class, Integer.TYPE });
mInjectEventMethod.setAccessible(true);
Field eventAsync = mInputManager.getClass().getDeclaredField("INJECT_INPUT_EVENT_MODE_ASYNC");
Field eventResult = mInputManager.getClass().getDeclaredField("INJECT_INPUT_EVENT_MODE_WAIT_FOR_RESULT");
Field eventFinish = mInputManager.getClass().getDeclaredField("INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH");
eventAsync.setAccessible(true);
eventResult.setAccessible(true);
eventFinish.setAccessible(true);
INJECT_INPUT_EVENT_MODE_ASYNC = eventAsync.getInt(mInputManager.getClass());
INJECT_INPUT_EVENT_MODE_WAIT_FOR_RESULT = eventResult.getInt(mInputManager.getClass());
INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH = eventFinish.getInt(mInputManager.getClass());
}
catch (NoSuchMethodException nsme)
{
Log.e(TAG, "Critical methods not available");
}
catch (NoSuchFieldException nsfe)
{
Log.e(TAG, "Critical fields not available");
}
catch (IllegalAccessException iae)
{
Log.e(TAG, "Critical fields not accessable");
}
}
}
/**
* Send a key event to the currently focused window/view and wait for it to
* be processed. Finished at some point after the recipient has returned
* from its event processing, though it may <em>not</em> have completely
* finished reacting from the event -- for example, if it needs to update
* its display as a result, it may still be in the process of doing that.
*
* @param event The event to send to the current focus.
*/
public void sendKeySync(KeyEvent event) {
validateNotAppThread();
try {
(IWindowManager.Stub.asInterface(ServiceManager.getService("window")))
.injectKeyEvent(event, true);
} catch (RemoteException e) {
}
}
/**
* Dispatch a pointer event. Finished at some point after the recipient has
* returned from its event processing, though it may <em>not</em> have
* completely finished reacting from the event -- for example, if it needs
* to update its display as a result, it may still be in the process of
* doing that.
*
* @param event A motion event describing the pointer action. (As noted in
* {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
* {@link SystemClock#uptimeMillis()} as the timebase.
*/
public void sendPointerSync(MotionEvent event) {
validateNotAppThread();
try {
(IWindowManager.Stub.asInterface(ServiceManager.getService("window")))
.injectPointerEvent(event, true);
} catch (RemoteException e) {
}
}
/**
* Dispatch a trackball event. Finished at some point after the recipient has
* returned from its event processing, though it may <em>not</em> have
* completely finished reacting from the event -- for example, if it needs
* to update its display as a result, it may still be in the process of
* doing that.
*
* @param event A motion event describing the trackball action. (As noted in
* {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
* {@link SystemClock#uptimeMillis()} as the timebase.
*/
public void sendTrackballEventSync(MotionEvent event) {
validateNotAppThread();
try {
(IWindowManager.Stub.asInterface(ServiceManager.getService("window")))
.injectTrackballEvent(event, true);
} catch (RemoteException e) {
}
}
/**
* Perform initialization of the policy.
*
* @param context The system context we are running in.
*/
public void init(Context context, IWindowManager windowManager,
WindowManagerFuncs windowManagerFuncs);