android.app.IActivityManager Java Examples
The following examples show how to use
android.app.IActivityManager.
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: GrantedUriPermissions.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
private static GrantedUriPermissions grantUri(IActivityManager am, Uri uri, int sourceUid, String targetPackage, int targetUserId, int grantFlags, String tag, GrantedUriPermissions curPerms) { try { int sourceUserId = ContentProvider.getUserIdFromUri(uri, UserHandle.getUserId(sourceUid)); uri = ContentProvider.getUriWithoutUserId(uri); if (curPerms == null) { curPerms = new GrantedUriPermissions(am, grantFlags, sourceUid, tag); } am.grantUriPermissionFromOwner(curPerms.mPermissionOwner, sourceUid, targetPackage, uri, grantFlags, sourceUserId, targetUserId); curPerms.mUris.add(uri); } catch (RemoteException e) { Slog.e("JobScheduler", "AM dead"); } return curPerms; }
Example #2
Source File: PluginManager.java From VirtualAPK with Apache License 2.0 | 6 votes |
/** * hookSystemServices, but need to compatible with Android O in future. */ protected void hookSystemServices() { try { Singleton<IActivityManager> defaultSingleton; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { defaultSingleton = Reflector.on(ActivityManager.class).field("IActivityManagerSingleton").get(); } else { defaultSingleton = Reflector.on(ActivityManagerNative.class).field("gDefault").get(); } IActivityManager origin = defaultSingleton.get(); IActivityManager activityManagerProxy = (IActivityManager) Proxy.newProxyInstance(mContext.getClassLoader(), new Class[] { IActivityManager.class }, createActivityManagerProxy(origin)); // Hook IActivityManager from ActivityManagerNative Reflector.with(defaultSingleton).field("mInstance").set(activityManagerProxy); if (defaultSingleton.get() == activityManagerProxy) { this.mActivityManager = activityManagerProxy; Log.d(TAG, "hookSystemServices succeed : " + mActivityManager); } } catch (Exception e) { Log.w(TAG, e); } }
Example #3
Source File: UiDevice.java From JsDroidCmd with Mozilla Public License 2.0 | 6 votes |
public void initialize(ShellUiAutomatorBridge uiAutomatorBridge) { mUiAutomationBridge = uiAutomatorBridge; // 监听activity变化,用于getAct try { IActivityManager am = ActivityManagerNative.getDefault(); am.setActivityController(new DummyActivityController()); } catch (RemoteException e) { } UiAutomation uiAutomation = uiAutomatorBridge.getUiAutomation(); uiAutomation .setOnAccessibilityEventListener(new OnAccessibilityEventListener() { public void onAccessibilityEvent(AccessibilityEvent event) { synchronized (onAccessibilityEventListeners) { for (OnAccessibilityEventListener listener : onAccessibilityEventListeners) { listener.onAccessibilityEvent(event); } } } }); }
Example #4
Source File: UiAutomationShellWrapper.java From JsDroidCmd with Mozilla Public License 2.0 | 6 votes |
public void setRunAsMonkey(boolean isSet) { IActivityManager am = ActivityManagerNative.getDefault(); if (am == null) { throw new RuntimeException( "Can't manage monkey status; is the system running?"); } try { if (isSet) { am.setActivityController(new DummyActivityController()); } else { am.setActivityController(null); } } catch (RemoteException e) { throw new RuntimeException(e); } }
Example #5
Source File: BroadcastReceiver.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
/** @hide */ public void sendFinished(IActivityManager am) { synchronized (this) { if (mFinished) { throw new IllegalStateException("Broadcast already finished"); } mFinished = true; try { if (mResultExtras != null) { mResultExtras.setAllowFds(false); } if (mOrderedHint) { am.finishReceiver(mToken, mResultCode, mResultData, mResultExtras, mAbortBroadcast, mFlags); } else { // This broadcast was sent to a component; it is not ordered, // but we still need to tell the activity manager we are done. am.finishReceiver(mToken, 0, null, null, false, mFlags); } } catch (RemoteException ex) { } } }
Example #6
Source File: SearchManagerService.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
@Override public boolean launchLegacyAssist(String hint, int userHandle, Bundle args) { ComponentName comp = getLegacyAssistComponent(userHandle); if (comp == null) { return false; } long ident = Binder.clearCallingIdentity(); try { Intent intent = new Intent(VoiceInteractionService.SERVICE_INTERFACE); intent.setComponent(comp); IActivityManager am = ActivityManager.getService(); if (args != null) { args.putInt(Intent.EXTRA_KEY_EVENT, android.view.KeyEvent.KEYCODE_ASSIST); } intent.putExtras(args); return am.launchAssistIntent(intent, ActivityManager.ASSIST_CONTEXT_BASIC, hint, userHandle, args); } catch (RemoteException e) { } finally { Binder.restoreCallingIdentity(ident); } return true; }
Example #7
Source File: GrantedUriPermissions.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
public static GrantedUriPermissions createFromIntent(IActivityManager am, Intent intent, int sourceUid, String targetPackage, int targetUserId, String tag) { int grantFlags = intent.getFlags(); if (!checkGrantFlags(grantFlags)) { return null; } GrantedUriPermissions perms = null; Uri data = intent.getData(); if (data != null) { perms = grantUri(am, data, sourceUid, targetPackage, targetUserId, grantFlags, tag, perms); } ClipData clip = intent.getClipData(); if (clip != null) { perms = grantClip(am, clip, sourceUid, targetPackage, targetUserId, grantFlags, tag, perms); } return perms; }
Example #8
Source File: JobStatus.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
public void unprepareLocked(IActivityManager am) { if (!prepared) { Slog.wtf(TAG, "Hasn't been prepared: " + this); if (DEBUG_PREPARE && unpreparedPoint != null) { Slog.e(TAG, "Was already unprepared at ", unpreparedPoint); } return; } prepared = false; if (DEBUG_PREPARE) { unpreparedPoint = new Throwable().fillInStackTrace(); } if (uriPerms != null) { uriPerms.revoke(am); uriPerms = null; } }
Example #9
Source File: JobStatus.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
public void stopTrackingJobLocked(IActivityManager am, JobStatus incomingJob) { if (incomingJob != null) { // We are replacing with a new job -- transfer the work! We do any executing // work first, since that was originally at the front of the pending work. if (executingWork != null && executingWork.size() > 0) { incomingJob.pendingWork = executingWork; } if (incomingJob.pendingWork == null) { incomingJob.pendingWork = pendingWork; } else if (pendingWork != null && pendingWork.size() > 0) { incomingJob.pendingWork.addAll(pendingWork); } pendingWork = null; executingWork = null; incomingJob.nextPendingWorkId = nextPendingWorkId; incomingJob.updateEstimatedNetworkBytesLocked(); } else { // We are completely stopping the job... need to clean up work. ungrantWorkList(am, pendingWork); pendingWork = null; ungrantWorkList(am, executingWork); executingWork = null; } updateEstimatedNetworkBytesLocked(); }
Example #10
Source File: BroadcastReceiver.java From AndroidComponentPlugin with Apache License 2.0 | 6 votes |
/** @hide */ public void sendFinished(IActivityManager am) { synchronized (this) { if (mFinished) { throw new IllegalStateException("Broadcast already finished"); } mFinished = true; try { if (mResultExtras != null) { mResultExtras.setAllowFds(false); } if (mOrderedHint) { am.finishReceiver(mToken, mResultCode, mResultData, mResultExtras, mAbortBroadcast, mFlags); } else { // This broadcast was sent to a component; it is not ordered, // but we still need to tell the activity manager we are done. am.finishReceiver(mToken, 0, null, null, false, mFlags); } } catch (RemoteException ex) { } } }
Example #11
Source File: UserManagerService.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private int runList(PrintWriter pw) throws RemoteException { final IActivityManager am = ActivityManager.getService(); final List<UserInfo> users = getUsers(false); if (users == null) { pw.println("Error: couldn't get users"); return 1; } else { pw.println("Users:"); for (int i = 0; i < users.size(); i++) { String running = am.isUserRunning(users.get(i).id, 0) ? " running" : ""; pw.println("\t" + users.get(i).toString() + running); } return 0; } }
Example #12
Source File: SettingsHelper.java From Study_Android_Demo with Apache License 2.0 | 5 votes |
/** * Sets the locale specified. Input data is the byte representation of a * BCP-47 language tag. For backwards compatibility, strings of the form * {@code ll_CC} are also accepted, where {@code ll} is a two letter language * code and {@code CC} is a two letter country code. * * @param data the locale string in bytes. */ void setLocaleData(byte[] data, int size) { // Check if locale was set by the user: Configuration conf = mContext.getResources().getConfiguration(); // TODO: The following is not working as intended because the network is forcing a locale // change after registering. Need to find some other way to detect if the user manually // changed the locale if (conf.userSetLocale) return; // Don't change if user set it in the SetupWizard final String[] availableLocales = mContext.getAssets().getLocales(); // Replace "_" with "-" to deal with older backups. String localeCode = new String(data, 0, size).replace('_', '-'); Locale loc = null; for (int i = 0; i < availableLocales.length; i++) { if (availableLocales[i].equals(localeCode)) { loc = Locale.forLanguageTag(localeCode); break; } } if (loc == null) return; // Couldn't find the saved locale in this version of the software try { IActivityManager am = ActivityManagerNative.getDefault(); Configuration config = am.getConfiguration(); config.locale = loc; // indicate this isn't some passing default - the user wants this remembered config.userSetLocale = true; am.updateConfiguration(config); } catch (RemoteException e) { // Intentionally left blank } }
Example #13
Source File: StorageManagerService.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** * MediaProvider has a ton of code that makes assumptions about storage * paths never changing, so we outright kill them to pick up new state. */ @Deprecated private void killMediaProvider(List<UserInfo> users) { if (users == null) return; final long token = Binder.clearCallingIdentity(); try { for (UserInfo user : users) { // System user does not have media provider, so skip. if (user.isSystemOnly()) continue; final ProviderInfo provider = mPms.resolveContentProvider(MediaStore.AUTHORITY, PackageManager.MATCH_DIRECT_BOOT_AWARE | PackageManager.MATCH_DIRECT_BOOT_UNAWARE, user.id); if (provider != null) { final IActivityManager am = ActivityManager.getService(); try { am.killApplication(provider.applicationInfo.packageName, UserHandle.getAppId(provider.applicationInfo.uid), UserHandle.USER_ALL, "vold reset"); // We only need to run this once. It will kill all users' media processes. break; } catch (RemoteException e) { } } } } finally { Binder.restoreCallingIdentity(token); } }
Example #14
Source File: ShellUiAutomatorBridge.java From JsDroidCmd with Mozilla Public License 2.0 | 5 votes |
public long getSystemLongPressTime() { long longPressTimeout = 2000; try { IContentProvider provider = null; Cursor cursor = null; IActivityManager activityManager = ActivityManagerNative .getDefault(); String providerName = Settings.Secure.CONTENT_URI.getAuthority(); IBinder token = new Binder(); try { ContentProviderHolder holder = activityManager .getContentProviderExternal(providerName, UserHandle.USER_OWNER, token); if (holder == null) { throw new IllegalStateException("Could not find provider: " + providerName); } provider = holder.provider; cursor = provider.query(null, Settings.Secure.CONTENT_URI, new String[] { Settings.Secure.VALUE }, "name=?", new String[] { Settings.Secure.LONG_PRESS_TIMEOUT }, null, null); if (cursor.moveToFirst()) { longPressTimeout = cursor.getInt(0); } } finally { if (cursor != null) { cursor.close(); } if (provider != null) { activityManager.removeContentProviderExternal(providerName, token); } } } catch (Throwable e) { } return longPressTimeout; }
Example #15
Source File: TaskPositioningController.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
TaskPositioningController(WindowManagerService service, InputManagerService inputManager, InputMonitor inputMonitor, IActivityManager activityManager, Looper looper) { mService = service; mInputMonitor = inputMonitor; mInputManager = inputManager; mActivityManager = activityManager; mHandler = new Handler(looper); }
Example #16
Source File: SettingsHelper.java From Study_Android_Demo with Apache License 2.0 | 5 votes |
/** * Sets the locale specified. Input data is the byte representation of a * BCP-47 language tag. For backwards compatibility, strings of the form * {@code ll_CC} are also accepted, where {@code ll} is a two letter language * code and {@code CC} is a two letter country code. * * @param data the locale string in bytes. */ void setLocaleData(byte[] data, int size) { // Check if locale was set by the user: Configuration conf = mContext.getResources().getConfiguration(); // TODO: The following is not working as intended because the network is forcing a locale // change after registering. Need to find some other way to detect if the user manually // changed the locale if (conf.userSetLocale) return; // Don't change if user set it in the SetupWizard final String[] availableLocales = mContext.getAssets().getLocales(); // Replace "_" with "-" to deal with older backups. String localeCode = new String(data, 0, size).replace('_', '-'); Locale loc = null; for (int i = 0; i < availableLocales.length; i++) { if (availableLocales[i].equals(localeCode)) { loc = Locale.forLanguageTag(localeCode); break; } } if (loc == null) return; // Couldn't find the saved locale in this version of the software try { IActivityManager am = ActivityManager.getService(); Configuration config = am.getConfiguration(); config.locale = loc; // indicate this isn't some passing default - the user wants this remembered config.userSetLocale = true; am.updateConfiguration(config); } catch (RemoteException e) { // Intentionally left blank } }
Example #17
Source File: ActivityManagerPatch.java From DeepInVirtualApp with MIT License | 5 votes |
@Override public void inject() throws Throwable { Field f_gDefault = ActivityManagerNative.class.getDeclaredField("gDefault"); if (!f_gDefault.isAccessible()) { f_gDefault.setAccessible(true); } if (f_gDefault.getType() == IActivityManager.class) { f_gDefault.set(null, getHookObject().getProxyObject()); } else if (f_gDefault.getType() == Singleton.class) { Singleton gDefault = (Singleton) f_gDefault.get(null); Field f_mInstance = Singleton.class.getDeclaredField("mInstance"); if (!f_mInstance.isAccessible()) { f_mInstance.setAccessible(true); } f_mInstance.set(gDefault, getHookObject().getProxyObject()); } else { // 不会经过这里 throw new UnsupportedOperationException("Singleton is not visible in AMN."); } HookBinder<IActivityManager> hookAMBinder = new HookBinder<IActivityManager>() { @Override protected IBinder queryBaseBinder() { return ServiceManager.getService(Context.ACTIVITY_SERVICE); } @Override protected IActivityManager createInterface(IBinder baseBinder) { return getHookObject().getProxyObject(); } }; hookAMBinder.injectService(Context.ACTIVITY_SERVICE); }
Example #18
Source File: StrictMode.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private static void handleApplicationStrictModeViolation(int violationMaskSubset, ViolationInfo info) { final int oldMask = getThreadPolicyMask(); try { // First, remove any policy before we call into the Activity Manager, // otherwise we'll infinite recurse as we try to log policy violations // to disk, thus violating policy, thus requiring logging, etc... // We restore the current policy below, in the finally block. setThreadPolicyMask(0); IActivityManager am = ActivityManager.getService(); if (am == null) { Log.w(TAG, "No activity manager; failed to Dropbox violation."); } else { am.handleApplicationStrictModeViolation( RuntimeInit.getApplicationObject(), violationMaskSubset, info); } } catch (RemoteException e) { if (e instanceof DeadObjectException) { // System process is dead; ignore } else { Log.e(TAG, "RemoteException handling StrictMode violation", e); } } finally { setThreadPolicyMask(oldMask); } }
Example #19
Source File: ActivityManagerShellCommand.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
MyActivityController(IActivityManager iam, PrintWriter pw, InputStream input, String gdbPort, boolean monkey) { mInterface = iam; mPw = pw; mInput = input; mGdbPort = gdbPort; mMonkey = monkey; }
Example #20
Source File: AssistDataRequester.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** * @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; }
Example #21
Source File: OverlayManagerService.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private void updateAssets(final int userId, List<String> targetPackageNames) { updateOverlayPaths(userId, targetPackageNames); final IActivityManager am = ActivityManager.getService(); try { am.scheduleApplicationInfoChanged(targetPackageNames, userId); } catch (RemoteException e) { // Intentionally left empty. } }
Example #22
Source File: JobStatus.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private static void ungrantWorkList(IActivityManager am, ArrayList<JobWorkItem> list) { if (list != null) { final int N = list.size(); for (int i = 0; i < N; i++) { ungrantWorkItem(am, list.get(i)); } } }
Example #23
Source File: UserManagerService.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** * Evicts a user's CE key by stopping and restarting the user. * * The key is evicted automatically by the user controller when the user has stopped. */ @Override public void evictCredentialEncryptionKey(@UserIdInt int userId) { checkManageUsersPermission("evict CE key"); final IActivityManager am = ActivityManagerNative.getDefault(); final long identity = Binder.clearCallingIdentity(); try { am.restartUserInBackground(userId); } catch (RemoteException re) { throw re.rethrowAsRuntimeException(); } finally { Binder.restoreCallingIdentity(identity); } }
Example #24
Source File: JobStatus.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
public void enqueueWorkLocked(IActivityManager am, JobWorkItem work) { if (pendingWork == null) { pendingWork = new ArrayList<>(); } work.setWorkId(nextPendingWorkId); nextPendingWorkId++; if (work.getIntent() != null && GrantedUriPermissions.checkGrantFlags(work.getIntent().getFlags())) { work.setGrants(GrantedUriPermissions.createFromIntent(am, work.getIntent(), sourceUid, sourcePackageName, sourceUserId, toShortString())); } pendingWork.add(work); updateEstimatedNetworkBytesLocked(); }
Example #25
Source File: GrantedUriPermissions.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private static GrantedUriPermissions grantItem(IActivityManager am, ClipData.Item item, int sourceUid, String targetPackage, int targetUserId, int grantFlags, String tag, GrantedUriPermissions curPerms) { if (item.getUri() != null) { curPerms = grantUri(am, item.getUri(), sourceUid, targetPackage, targetUserId, grantFlags, tag, curPerms); } Intent intent = item.getIntent(); if (intent != null && intent.getData() != null) { curPerms = grantUri(am, intent.getData(), sourceUid, targetPackage, targetUserId, grantFlags, tag, curPerms); } return curPerms; }
Example #26
Source File: GrantedUriPermissions.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private static GrantedUriPermissions grantClip(IActivityManager am, ClipData clip, int sourceUid, String targetPackage, int targetUserId, int grantFlags, String tag, GrantedUriPermissions curPerms) { final int N = clip.getItemCount(); for (int i = 0; i < N; i++) { curPerms = grantItem(am, clip.getItemAt(i), sourceUid, targetPackage, targetUserId, grantFlags, tag, curPerms); } return curPerms; }
Example #27
Source File: GrantedUriPermissions.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
public static GrantedUriPermissions createFromClip(IActivityManager am, ClipData clip, int sourceUid, String targetPackage, int targetUserId, int grantFlags, String tag) { if (!checkGrantFlags(grantFlags)) { return null; } GrantedUriPermissions perms = null; if (clip != null) { perms = grantClip(am, clip, sourceUid, targetPackage, targetUserId, grantFlags, tag, perms); } return perms; }
Example #28
Source File: GrantedUriPermissions.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
public void revoke(IActivityManager am) { for (int i = mUris.size()-1; i >= 0; i--) { try { am.revokeUriPermissionFromOwner(mPermissionOwner, mUris.get(i), mGrantFlags, mSourceUserId); } catch (RemoteException e) { } } mUris.clear(); }
Example #29
Source File: GrantedUriPermissions.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private GrantedUriPermissions(IActivityManager am, int grantFlags, int uid, String tag) throws RemoteException { mGrantFlags = grantFlags; mSourceUserId = UserHandle.getUserId(uid); mTag = tag; mPermissionOwner = am.newUriPermissionOwner("job: " + tag); }
Example #30
Source File: JobStatus.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
public boolean completeWorkLocked(IActivityManager am, int workId) { if (executingWork != null) { final int N = executingWork.size(); for (int i = 0; i < N; i++) { JobWorkItem work = executingWork.get(i); if (work.getWorkId() == workId) { executingWork.remove(i); ungrantWorkItem(am, work); return true; } } } return false; }