Java Code Examples for com.android.internal.os.SomeArgs#recycle()

The following examples show how to use com.android.internal.os.SomeArgs#recycle() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PrintManager.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new instance.
 *
 * @param context The current context in which to operate.
 * @param service The backing system service.
 * @param userId The user id in which to operate.
 * @param appId The application id in which to operate.
 * @hide
 */
public PrintManager(Context context, IPrintManager service, int userId, int appId) {
    mContext = context;
    mService = service;
    mUserId = userId;
    mAppId = appId;
    mHandler = new Handler(context.getMainLooper(), null, false) {
        @Override
        public void handleMessage(Message message) {
            switch (message.what) {
                case MSG_NOTIFY_PRINT_JOB_STATE_CHANGED: {
                    SomeArgs args = (SomeArgs) message.obj;
                    PrintJobStateChangeListenerWrapper wrapper =
                            (PrintJobStateChangeListenerWrapper) args.arg1;
                    PrintJobStateChangeListener listener = wrapper.getListener();
                    if (listener != null) {
                        PrintJobId printJobId = (PrintJobId) args.arg2;
                        listener.onPrintJobStateChanged(printJobId);
                    }
                    args.recycle();
                } break;
            }
        }
    };
}
 
Example 2
Source File: StorageManagerService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public void handleMessage(Message msg) {
    final SomeArgs args = (SomeArgs) msg.obj;
    final int n = mCallbacks.beginBroadcast();
    for (int i = 0; i < n; i++) {
        final IStorageEventListener callback = mCallbacks.getBroadcastItem(i);
        try {
            invokeCallback(callback, msg.what, args);
        } catch (RemoteException ignored) {
        }
    }
    mCallbacks.finishBroadcast();
    args.recycle();
}
 
Example 3
Source File: PackageInstallerSession.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public boolean handleMessage(Message msg) {
    switch (msg.what) {
        case MSG_EARLY_BIND:
            earlyBindToDefContainer();
            break;
        case MSG_COMMIT:
            synchronized (mLock) {
                try {
                    commitLocked();
                } catch (PackageManagerException e) {
                    final String completeMsg = ExceptionUtils.getCompleteMessage(e);
                    Slog.e(TAG,
                            "Commit of session " + sessionId + " failed: " + completeMsg);
                    destroyInternal();
                    dispatchSessionFinished(e.error, completeMsg, null);
                }
            }

            break;
        case MSG_ON_PACKAGE_INSTALLED:
            final SomeArgs args = (SomeArgs) msg.obj;
            final String packageName = (String) args.arg1;
            final String message = (String) args.arg2;
            final Bundle extras = (Bundle) args.arg3;
            final IPackageInstallObserver2 observer = (IPackageInstallObserver2) args.arg4;
            final int returnCode = args.argi1;
            args.recycle();

            try {
                observer.onPackageInstalled(packageName, returnCode, message, extras);
            } catch (RemoteException ignored) {
            }

            break;
    }

    return true;
}
 
Example 4
Source File: InstantAppRegistry.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
public void cancelPendingPersistLPw(@NonNull PackageParser.Package pkg,
        @UserIdInt int userId) {
    removeMessages(userId, pkg);
    SomeArgs state = removePendingPersistCookieLPr(pkg, userId);
    if (state != null) {
        state.recycle();
    }
}
 
Example 5
Source File: InstantAppRegistry.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public void handleMessage(Message message) {
    int userId = message.what;
    PackageParser.Package pkg = (PackageParser.Package) message.obj;
    SomeArgs state = removePendingPersistCookieLPr(pkg, userId);
    if (state == null) {
        return;
    }
    byte[] cookie = (byte[]) state.arg1;
    File cookieFile = (File) state.arg2;
    state.recycle();
    persistInstantApplicationCookie(cookie, pkg.packageName, cookieFile, userId);
}
 
Example 6
Source File: AccessibilityInteractionController.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private void findAccessibilityNodeInfoByAccessibilityIdUiThread(Message message) {
    final int flags = message.arg1;

    SomeArgs args = (SomeArgs) message.obj;
    final int accessibilityViewId = args.argi1;
    final int virtualDescendantId = args.argi2;
    final int interactionId = args.argi3;
    final IAccessibilityInteractionConnectionCallback callback =
        (IAccessibilityInteractionConnectionCallback) args.arg1;
    final MagnificationSpec spec = (MagnificationSpec) args.arg2;
    final Region interactiveRegion = (Region) args.arg3;
    final Bundle arguments = (Bundle) args.arg4;

    args.recycle();

    List<AccessibilityNodeInfo> infos = mTempAccessibilityNodeInfoList;
    infos.clear();
    try {
        if (mViewRootImpl.mView == null || mViewRootImpl.mAttachInfo == null) {
            return;
        }
        mViewRootImpl.mAttachInfo.mAccessibilityFetchFlags = flags;
        View root = null;
        if (accessibilityViewId == AccessibilityNodeInfo.ROOT_ITEM_ID) {
            root = mViewRootImpl.mView;
        } else {
            root = findViewByAccessibilityId(accessibilityViewId);
        }
        if (root != null && isShown(root)) {
            mPrefetcher.prefetchAccessibilityNodeInfos(
                    root, virtualDescendantId, flags, infos, arguments);
        }
    } finally {
        updateInfosForViewportAndReturnFindNodeResult(
                infos, callback, interactionId, spec, interactiveRegion);
    }
}
 
Example 7
Source File: AccessibilityInteractionController.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private void focusSearchUiThread(Message message) {
    final int flags = message.arg1;
    final int accessibilityViewId = message.arg2;

    SomeArgs args = (SomeArgs) message.obj;
    final int direction = args.argi2;
    final int interactionId = args.argi3;
    final IAccessibilityInteractionConnectionCallback callback =
        (IAccessibilityInteractionConnectionCallback) args.arg1;
    final MagnificationSpec spec = (MagnificationSpec) args.arg2;
    final Region interactiveRegion = (Region) args.arg3;

    args.recycle();

    AccessibilityNodeInfo next = null;
    try {
        if (mViewRootImpl.mView == null || mViewRootImpl.mAttachInfo == null) {
            return;
        }
        mViewRootImpl.mAttachInfo.mAccessibilityFetchFlags = flags;
        View root = null;
        if (accessibilityViewId != AccessibilityNodeInfo.ROOT_ITEM_ID) {
            root = findViewByAccessibilityId(accessibilityViewId);
        } else {
            root = mViewRootImpl.mView;
        }
        if (root != null && isShown(root)) {
            View nextView = root.focusSearch(direction);
            if (nextView != null) {
                next = nextView.createAccessibilityNodeInfo();
            }
        }
    } finally {
        updateInfoForViewportAndReturnFindNodeResult(
                next, callback, interactionId, spec, interactiveRegion);
    }
}
 
Example 8
Source File: StorageManager.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public boolean handleMessage(Message msg) {
    final SomeArgs args = (SomeArgs) msg.obj;
    switch (msg.what) {
        case MSG_STORAGE_STATE_CHANGED:
            mCallback.onStorageStateChanged((String) args.arg1, (String) args.arg2,
                    (String) args.arg3);
            args.recycle();
            return true;
        case MSG_VOLUME_STATE_CHANGED:
            mCallback.onVolumeStateChanged((VolumeInfo) args.arg1, args.argi2, args.argi3);
            args.recycle();
            return true;
        case MSG_VOLUME_RECORD_CHANGED:
            mCallback.onVolumeRecordChanged((VolumeRecord) args.arg1);
            args.recycle();
            return true;
        case MSG_VOLUME_FORGOTTEN:
            mCallback.onVolumeForgotten((String) args.arg1);
            args.recycle();
            return true;
        case MSG_DISK_SCANNED:
            mCallback.onDiskScanned((DiskInfo) args.arg1, args.argi2);
            args.recycle();
            return true;
        case MSG_DISK_DESTROYED:
            mCallback.onDiskDestroyed((DiskInfo) args.arg1);
            args.recycle();
            return true;
    }
    args.recycle();
    return false;
}
 
Example 9
Source File: VoiceInteractionSession.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public boolean[] supportsCommands(String callingPackage, String[] commands) {
    Message msg = mHandlerCaller.obtainMessageIOO(MSG_SUPPORTS_COMMANDS,
            0, commands, null);
    SomeArgs args = mHandlerCaller.sendMessageAndWait(msg);
    if (args != null) {
        boolean[] res = (boolean[])args.arg1;
        args.recycle();
        return res;
    }
    return new boolean[commands.length];
}
 
Example 10
Source File: AccessibilityInteractionController.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private void findAccessibilityNodeInfosByViewIdUiThread(Message message) {
    final int flags = message.arg1;
    final int accessibilityViewId = message.arg2;

    SomeArgs args = (SomeArgs) message.obj;
    final int interactionId = args.argi1;
    final IAccessibilityInteractionConnectionCallback callback =
        (IAccessibilityInteractionConnectionCallback) args.arg1;
    final MagnificationSpec spec = (MagnificationSpec) args.arg2;
    final String viewId = (String) args.arg3;
    final Region interactiveRegion = (Region) args.arg4;
    args.recycle();

    final List<AccessibilityNodeInfo> infos = mTempAccessibilityNodeInfoList;
    infos.clear();
    try {
        if (mViewRootImpl.mView == null || mViewRootImpl.mAttachInfo == null) {
            return;
        }
        mViewRootImpl.mAttachInfo.mAccessibilityFetchFlags = flags;
        View root = null;
        if (accessibilityViewId != AccessibilityNodeInfo.ROOT_ITEM_ID) {
            root = findViewByAccessibilityId(accessibilityViewId);
        } else {
            root = mViewRootImpl.mView;
        }
        if (root != null) {
            final int resolvedViewId = root.getContext().getResources()
                    .getIdentifier(viewId, null, null);
            if (resolvedViewId <= 0) {
                return;
            }
            if (mAddNodeInfosForViewId == null) {
                mAddNodeInfosForViewId = new AddNodeInfosForViewId();
            }
            mAddNodeInfosForViewId.init(resolvedViewId, infos);
            root.findViewByPredicate(mAddNodeInfosForViewId);
            mAddNodeInfosForViewId.reset();
        }
    } finally {
        updateInfosForViewportAndReturnFindNodeResult(
                infos, callback, interactionId, spec, interactiveRegion);
    }
}
 
Example 11
Source File: AccessibilityInteractionController.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private void findAccessibilityNodeInfosByTextUiThread(Message message) {
    final int flags = message.arg1;

    SomeArgs args = (SomeArgs) message.obj;
    final String text = (String) args.arg1;
    final IAccessibilityInteractionConnectionCallback callback =
        (IAccessibilityInteractionConnectionCallback) args.arg2;
    final MagnificationSpec spec = (MagnificationSpec) args.arg3;
    final int accessibilityViewId = args.argi1;
    final int virtualDescendantId = args.argi2;
    final int interactionId = args.argi3;
    final Region interactiveRegion = (Region) args.arg4;
    args.recycle();

    List<AccessibilityNodeInfo> infos = null;
    try {
        if (mViewRootImpl.mView == null || mViewRootImpl.mAttachInfo == null) {
            return;
        }
        mViewRootImpl.mAttachInfo.mAccessibilityFetchFlags = flags;
        View root = null;
        if (accessibilityViewId != AccessibilityNodeInfo.ROOT_ITEM_ID) {
            root = findViewByAccessibilityId(accessibilityViewId);
        } else {
            root = mViewRootImpl.mView;
        }
        if (root != null && isShown(root)) {
            AccessibilityNodeProvider provider = root.getAccessibilityNodeProvider();
            if (provider != null) {
                infos = provider.findAccessibilityNodeInfosByText(text,
                        virtualDescendantId);
            } else if (virtualDescendantId == AccessibilityNodeProvider.HOST_VIEW_ID) {
                ArrayList<View> foundViews = mTempArrayList;
                foundViews.clear();
                root.findViewsWithText(foundViews, text, View.FIND_VIEWS_WITH_TEXT
                        | View.FIND_VIEWS_WITH_CONTENT_DESCRIPTION
                        | View.FIND_VIEWS_WITH_ACCESSIBILITY_NODE_PROVIDERS);
                if (!foundViews.isEmpty()) {
                    infos = mTempAccessibilityNodeInfoList;
                    infos.clear();
                    final int viewCount = foundViews.size();
                    for (int i = 0; i < viewCount; i++) {
                        View foundView = foundViews.get(i);
                        if (isShown(foundView)) {
                            provider = foundView.getAccessibilityNodeProvider();
                            if (provider != null) {
                                List<AccessibilityNodeInfo> infosFromProvider =
                                    provider.findAccessibilityNodeInfosByText(text,
                                            AccessibilityNodeProvider.HOST_VIEW_ID);
                                if (infosFromProvider != null) {
                                    infos.addAll(infosFromProvider);
                                }
                            } else  {
                                infos.add(foundView.createAccessibilityNodeInfo());
                            }
                        }
                    }
                }
            }
        }
    } finally {
        updateInfosForViewportAndReturnFindNodeResult(
                infos, callback, interactionId, spec, interactiveRegion);
    }
}
 
Example 12
Source File: AccessibilityInteractionController.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private void performAccessibilityActionUiThread(Message message) {
    final int flags = message.arg1;
    final int accessibilityViewId = message.arg2;

    SomeArgs args = (SomeArgs) message.obj;
    final int virtualDescendantId = args.argi1;
    final int action = args.argi2;
    final int interactionId = args.argi3;
    final IAccessibilityInteractionConnectionCallback callback =
        (IAccessibilityInteractionConnectionCallback) args.arg1;
    Bundle arguments = (Bundle) args.arg2;

    args.recycle();

    boolean succeeded = false;
    try {
        if (mViewRootImpl.mView == null || mViewRootImpl.mAttachInfo == null ||
                mViewRootImpl.mStopped || mViewRootImpl.mPausedForTransition) {
            return;
        }
        mViewRootImpl.mAttachInfo.mAccessibilityFetchFlags = flags;
        View target = null;
        if (accessibilityViewId != AccessibilityNodeInfo.ROOT_ITEM_ID) {
            target = findViewByAccessibilityId(accessibilityViewId);
        } else {
            target = mViewRootImpl.mView;
        }
        if (target != null && isShown(target)) {
            if (action == R.id.accessibilityActionClickOnClickableSpan) {
                // Handle this hidden action separately
                succeeded = handleClickableSpanActionUiThread(
                        target, virtualDescendantId, arguments);
            } else {
                AccessibilityNodeProvider provider = target.getAccessibilityNodeProvider();
                if (provider != null) {
                    succeeded = provider.performAction(virtualDescendantId, action,
                            arguments);
                } else if (virtualDescendantId == AccessibilityNodeProvider.HOST_VIEW_ID) {
                    succeeded = target.performAccessibilityAction(action, arguments);
                }
            }
        }
    } finally {
        try {
            mViewRootImpl.mAttachInfo.mAccessibilityFetchFlags = 0;
            callback.setPerformAccessibilityActionResult(succeeded, interactionId);
        } catch (RemoteException re) {
            /* ignore - the other side will time out */
        }
    }
}