android.app.IActivityManager源码实例Demo

类android.app.IActivityManager源码实例Demo

下面列出了android.app.IActivityManager 类实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

/** @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) {
        }
    }
}
 
源代码2 项目: android_9.0.0_r45   文件: JobStatus.java
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();
}
 
源代码3 项目: android_9.0.0_r45   文件: JobStatus.java
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;
    }
}
 
源代码4 项目: android_9.0.0_r45   文件: GrantedUriPermissions.java
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;
}
 
源代码5 项目: android_9.0.0_r45   文件: GrantedUriPermissions.java
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;
}
 
源代码6 项目: android_9.0.0_r45   文件: SearchManagerService.java
@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;
}
 
源代码7 项目: android_9.0.0_r45   文件: BroadcastReceiver.java
/** @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) {
        }
    }
}
 
源代码8 项目: JsDroidCmd   文件: UiAutomationShellWrapper.java
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);
	}
}
 
源代码9 项目: JsDroidCmd   文件: UiDevice.java
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);
						}
					}
				}
			});
}
 
源代码10 项目: VirtualAPK   文件: PluginManager.java
/**
 * 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);
    }
}
 
源代码11 项目: android_9.0.0_r45   文件: StorageManagerService.java
/**
 * 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);
    }
}
 
TaskPositioningController(WindowManagerService service, InputManagerService inputManager,
        InputMonitor inputMonitor, IActivityManager activityManager, Looper looper) {
    mService = service;
    mInputMonitor = inputMonitor;
    mInputManager = inputManager;
    mActivityManager = activityManager;
    mHandler = new Handler(looper);
}
 
源代码13 项目: android_9.0.0_r45   文件: JobStatus.java
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();
}
 
源代码14 项目: android_9.0.0_r45   文件: JobStatus.java
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;
}
 
源代码15 项目: android_9.0.0_r45   文件: JobStatus.java
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));
        }
    }
}
 
源代码16 项目: android_9.0.0_r45   文件: JobStatus.java
public void prepareLocked(IActivityManager am) {
    if (prepared) {
        Slog.wtf(TAG, "Already prepared: " + this);
        return;
    }
    prepared = true;
    if (DEBUG_PREPARE) {
        unpreparedPoint = null;
    }
    final ClipData clip = job.getClipData();
    if (clip != null) {
        uriPerms = GrantedUriPermissions.createFromClip(am, clip, sourceUid, sourcePackageName,
                sourceUserId, job.getClipGrantFlags(), toShortString());
    }
}
 
源代码17 项目: android_9.0.0_r45   文件: GrantedUriPermissions.java
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);
}
 
源代码18 项目: android_9.0.0_r45   文件: GrantedUriPermissions.java
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();
}
 
源代码19 项目: android_9.0.0_r45   文件: GrantedUriPermissions.java
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;
}
 
源代码20 项目: android_9.0.0_r45   文件: GrantedUriPermissions.java
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;
}
 
源代码21 项目: android_9.0.0_r45   文件: GrantedUriPermissions.java
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;
}
 
源代码22 项目: android_9.0.0_r45   文件: UserManagerService.java
/**
 * 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);
    }
}
 
源代码23 项目: android_9.0.0_r45   文件: UserManagerService.java
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;
    }
}
 
源代码24 项目: android_9.0.0_r45   文件: OverlayManagerService.java
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.
    }
}
 
源代码25 项目: android_9.0.0_r45   文件: AssistDataRequester.java
/**
 * @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;
}
 
MyActivityController(IActivityManager iam, PrintWriter pw, InputStream input,
        String gdbPort, boolean monkey) {
    mInterface = iam;
    mPw = pw;
    mInput = input;
    mGdbPort = gdbPort;
    mMonkey = monkey;
}
 
源代码27 项目: android_9.0.0_r45   文件: StrictMode.java
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);
    }
}
 
源代码28 项目: JsDroidCmd   文件: ShellUiAutomatorBridge.java
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;
}
 
源代码29 项目: Study_Android_Demo   文件: SettingsHelper.java
/**
 * 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
    }
}
 
源代码30 项目: Study_Android_Demo   文件: SettingsHelper.java
/**
 * 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
    }
}
 
源代码评论
动弹
沙发等你来抢
 类所在包
 类方法
 同包方法