public static void systemReady(Context context) { new VActivityManagerService().onCreate(context); }
private ComponentName startServiceCommon(Intent service, boolean scheduleServiceArgs, int userId) { ServiceInfo serviceInfo = resolveServiceInfo(service, userId); if (serviceInfo == null) { return null; ProcessRecord targetApp = startProcessIfNeedLocked(ComponentUtils.getProcessName(serviceInfo), userId, serviceInfo.packageName); ServiceRecord r = findRecordLocked(userId, serviceInfo); if (r == null) { r = new ServiceRecord(); e.printStackTrace(); addRecord(r);
private ProcessRecord performStartProcessLocked(int vuid, int vpid, ApplicationInfo info, String processName) { ProcessRecord app = new ProcessRecord(info, processName, vuid, vpid); Bundle extras = new Bundle(); BundleCompat.putBinder(extras, "_VA_|_binder_", app); extras.putInt("_VA_|_vuid_", vuid); extras.putString("_VA_|_process_", processName); extras.putString("_VA_|_pkg_", info.packageName); Bundle res = ProviderCall.call(VASettings.getStubAuthority(vpid), "_VA_|_init_process_", null, extras); if (res == null) { return null; } int pid = res.getInt("_VA_|_pid_"); IBinder clientBinder = BundleCompat.getBinder(res, "_VA_|_client_"); attachClient(pid, clientBinder); return app; }
private void handleStaticBroadcastAsUser(int vuid, ActivityInfo info, Intent intent, PendingResultData result) { synchronized (this) { ProcessRecord r = findProcessLocked(info.processName, vuid); if ((BROADCAST_NOT_STARTED_PKG || isStartProcessForBroadcast(info.processName, info.packageName)) && r == null) { r = startProcessIfNeedLocked(info.processName, getUserId(vuid), info.packageName); } if (r != null && r.appThread != null) { performScheduleReceiver(r.client, vuid, info, intent, result); } } }
private void sendInstalledBroadcast(String packageName) { Intent intent = new Intent(Intent.ACTION_PACKAGE_ADDED); intent.setData(Uri.parse("package:" + packageName)); VActivityManagerService.get().sendBroadcastAsUser(intent, VUserHandle.ALL); }
ProcessRecord startProcessIfNeedLocked(String processName, int userId, String packageName) { if (VActivityManagerService.get().getFreeStubCount() < 3) { // run GC killAllApps(); } PackageSetting ps = PackageCacheManager.getSetting(packageName); ApplicationInfo info = VPackageManagerService.get().getApplicationInfo(packageName, 0, userId); if (ps == null || info == null) { return null; } if (!ps.isLaunched(userId)) { sendFirstLaunchBroadcast(ps, userId); ps.setLaunched(userId, true); VAppManagerService.get().savePersistenceData(); } int uid = VUserHandle.getUid(userId, ps.appId); ProcessRecord app = mProcessNames.get(processName, uid); if (app != null && app.client.asBinder().pingBinder()) { return app; } int vpid = queryFreeStubProcessLocked(); if (vpid == -1) { return null; } app = performStartProcessLocked(uid, vpid, info, processName); if (app != null) { app.pkgList.add(info.packageName); } return app; }
@Override public void processRestarted(String packageName, String processName, int userId) { int callingPid = getCallingPid(); int appId = VAppManagerService.get().getAppId(packageName); int uid = VUserHandle.getUid(userId, appId); synchronized (this) { ProcessRecord app = findProcessLocked(callingPid); if (app == null) { ApplicationInfo appInfo = VPackageManagerService.get().getApplicationInfo(packageName, 0, userId); appInfo.flags |= ApplicationInfo.FLAG_HAS_CODE; String stubProcessName = getProcessName(callingPid); int vpid = parseVPid(stubProcessName); if (vpid != -1) { performStartProcessLocked(uid, vpid, appInfo, processName); } } } }
@Override public boolean clearPackage(String packageName) throws RemoteException { try { BroadcastSystem.get().stopApp(packageName); VActivityManagerService.get().killAppByPkg(packageName, VUserHandle.USER_ALL); for (int id : VUserManagerService.get().getUserIds()) { FileUtils.deleteDir(VEnvironment.getDataUserPackageDirectory(id, packageName)); FileUtils.deleteDir(VEnvironment.getVirtualPrivateStorageDir(id, packageName)); } return true; } catch (Exception e) { return false; } }
IServiceConnection connection, int flags, int userId) { synchronized (this) { ServiceInfo serviceInfo = resolveServiceInfo(service, userId); if (serviceInfo == null) { return 0; ServiceRecord r = findRecordLocked(userId, serviceInfo); boolean firstLaunch = r == null; if (firstLaunch) { if ((flags & Context.BIND_AUTO_CREATE) != 0) { startServiceCommon(service, false, userId); r = findRecordLocked(userId, serviceInfo); connectService(connection, componentName, boundRecord, false); } else { try {
@Override public int stopService(IBinder caller, Intent service, String resolvedType, int userId) { synchronized (this) { ServiceInfo serviceInfo = resolveServiceInfo(service, userId); if (serviceInfo == null) { return 0; } ServiceRecord r = findRecordLocked(userId, serviceInfo); if (r == null) { return 0; } stopServiceCommon(r, ComponentUtils.toComponentName(serviceInfo)); return 1; } }
@Override public boolean isAppPid(int pid) { synchronized (mPidsSelfLocked) { return findProcessLocked(pid) != null; } }
@Override public IBinder peekService(Intent service, String resolvedType, int userId) { synchronized (this) { ServiceInfo serviceInfo = resolveServiceInfo(service, userId); if (serviceInfo == null) { return null; } ServiceRecord r = findRecordLocked(userId, serviceInfo); if (r != null) { ServiceRecord.IntentBindRecord boundRecord = r.peekBinding(service); if (boundRecord != null) { return boundRecord.binder; } } return null; } }
@Override public IBinder acquireProviderClient(int userId, ProviderInfo info) { ProcessRecord callerApp; synchronized (mPidsSelfLocked) { callerApp = findProcessLocked(VBinder.getCallingPid()); } if (callerApp == null) { throw new SecurityException("Who are you?"); } String processName = info.processName; ProcessRecord r; synchronized (this) { r = startProcessIfNeedLocked(processName, userId, info.packageName); } if (r != null && r.client.asBinder().pingBinder()) { try { return r.client.acquireProviderClient(info); } catch (RemoteException e) { e.printStackTrace(); } } return null; }
@Override public void setServiceForeground(ComponentName className, IBinder token, int id, Notification notification, boolean removeNotification, int userId) { ServiceRecord r = (ServiceRecord) token; if (r != null) { if (id != 0) { if (notification == null) { throw new IllegalArgumentException("null notification"); } if (r.foregroundId != id) { if (r.foregroundId != 0) { cancelNotification(userId, r.foregroundId, r.serviceInfo.packageName); } r.foregroundId = id; } r.foregroundNoti = notification; postNotification(userId, id, r.serviceInfo.packageName, notification); } else { if (removeNotification) { cancelNotification(userId, r.foregroundId, r.serviceInfo.packageName); r.foregroundId = 0; r.foregroundNoti = null; } } } }
@Override public boolean onCreate() { Context context = getContext(); DaemonService.startup(context); if (!VirtualCore.get().isStartup()) { return true; } VPackageManagerService.systemReady(); addService(ServiceManagerNative.PACKAGE, VPackageManagerService.get()); VActivityManagerService.systemReady(context); addService(ServiceManagerNative.ACTIVITY, VActivityManagerService.get()); addService(ServiceManagerNative.USER, VUserManagerService.get()); VAppManagerService.systemReady(); addService(ServiceManagerNative.APP, VAppManagerService.get()); BroadcastSystem.attach(VActivityManagerService.get(), VAppManagerService.get()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { addService(ServiceManagerNative.JOB, VJobSchedulerService.get()); } VNotificationManagerService.systemReady(context); addService(ServiceManagerNative.NOTIFICATION, VNotificationManagerService.get()); VAppManagerService.get().scanApps(); VAccountManagerService.systemReady(); addService(ServiceManagerNative.ACCOUNT, VAccountManagerService.get()); addService(ServiceManagerNative.VS, VirtualStorageService.get()); addService(ServiceManagerNative.DEVICE, VDeviceManagerService.get()); addService(ServiceManagerNative.VIRTUAL_LOC, VirtualLocationService.get()); return true; }
Intent addedIntent = new Intent(Constants.ACTION_USER_REMOVED); addedIntent.putExtra(Constants.EXTRA_USER_HANDLE, userHandle); VActivityManagerService.get().sendOrderedBroadcastAsUser(addedIntent, VUserHandle.ALL, null, new BroadcastReceiver() {
private void handleStaticBroadcastAsUser(int vuid, ActivityInfo info, Intent intent, PendingResultData result) { synchronized (this) { ProcessRecord r = findProcessLocked(info.processName, vuid); if (BROADCAST_NOT_STARTED_PKG && r == null) { r = startProcessIfNeedLocked(info.processName, getUserId(vuid), info.packageName); } if (r != null && r.appThread != null) { performScheduleReceiver(r.client, vuid, info, intent, result); } } }
@Override public void publishService(IBinder token, Intent intent, IBinder service, int userId) { synchronized (this) { ServiceRecord r = (ServiceRecord) token; if (r != null) { ServiceRecord.IntentBindRecord boundRecord = r.peekBinding(intent); if (boundRecord != null) { boundRecord.binder = service; for (IServiceConnection conn : boundRecord.connections) { ComponentName component = ComponentUtils.toComponentName(r.serviceInfo); connectService(conn, component, boundRecord, false); } } } } }
@Override public boolean unbindService(IServiceConnection connection, int userId) { synchronized (this) { ServiceRecord r = findRecordLocked(connection); if (r == null) { return false;