private VUserInfo getUserInfoLocked(int userId) { VUserInfo ui = mUsers.get(userId); // If it is partial and not in the process of being removed, return as unknown user. if (ui != null && ui.partial && !mRemovingUserIds.contains(userId)) { VLog.w(LOG_TAG, "getUserInfo: unknown user #" + userId); return null; } return ui; }
private static File ensureCreated(File folder) { if (!folder.exists() && !folder.mkdirs()) { VLog.w(TAG, "Unable to create the directory: %s.", folder.getPath()); } return folder; }
@Override public Bitmap getUserIcon(int userId) { //checkManageUsersPermission("read users"); synchronized (mPackagesLock) { VUserInfo info = mUsers.get(userId); if (info == null || info.partial) { VLog.w(LOG_TAG, "getUserIcon: unknown user #" + userId); return null; } if (info.iconPath == null) { return null; } return BitmapFactory.decodeFile(info.iconPath); } }
@Override public void handleMessage(Message msg) { IBinder token = (IBinder) msg.obj; BroadcastRecord r = mBroadcastRecords.remove(token); if (r != null) { VLog.w(TAG, "Broadcast timeout, cancel to dispatch it."); r.pendingResult.finish(); } } }
View toView(final Context context, RemoteViews remoteViews, boolean isBig, boolean systemId) { View mCache = null; try { mCache = createView(context, remoteViews, isBig, systemId); } catch (Throwable throwable) { VLog.w(TAG, "toView 1", throwable); try { mCache = LayoutInflater.from(context).inflate(remoteViews.getLayoutId(), null); } catch (Throwable e) { VLog.w(TAG, "toView 2", e); } } return mCache; }
private void writeBitmapLocked(VUserInfo info, Bitmap bitmap) { try { File dir = new File(mUsersDir, Integer.toString(info.id)); File file = new File(dir, USER_PHOTO_FILENAME); if (!dir.exists()) { dir.mkdir(); // FileUtils.setPermissions( // dir.getPath(), // FileUtils.S_IRWXU|FileUtils.S_IRWXG|FileUtils.S_IXOTH, // -1, -1); } FileOutputStream os; if (bitmap.compress(Bitmap.CompressFormat.PNG, 100, os = new FileOutputStream(file))) { info.iconPath = file.getAbsolutePath(); } try { os.close(); } catch (IOException ioe) { // What the ... ! } } catch (FileNotFoundException e) { VLog.w(LOG_TAG, "Error setting photo for user ", e); } }
/** * Make a note of the last started time of a user. * @param userId the user that was just foregrounded */ public void userForeground(int userId) { synchronized (mPackagesLock) { VUserInfo user = mUsers.get(userId); long now = System.currentTimeMillis(); if (user == null || user.partial) { VLog.w(LOG_TAG, "userForeground: unknown user #" + userId); return; } if (now > EPOCH_PLUS_30_YEARS) { user.lastLoggedInTime = now; writeUserLocked(user); } } }
public MethodInvocationStub(T baseInterface, Class<?>... proxyInterfaces) { this.mBaseInterface = baseInterface; if (baseInterface != null) { if (proxyInterfaces == null) { proxyInterfaces = MethodParameterUtils.getAllInterface(baseInterface.getClass()); } mProxyInterface = (T) Proxy.newProxyInstance(baseInterface.getClass().getClassLoader(), proxyInterfaces, new HookInvocationHandler()); } else { VLog.w(TAG, "Unable to build HookDelegate: %s.", getIdentityName()); } }
boolean handleStaticBroadcast(int appId, ActivityInfo info, Intent intent, PendingResultData result) { Intent realIntent = intent.getParcelableExtra("_VA_|_intent_"); ComponentName component = intent.getParcelableExtra("_VA_|_component_"); int userId = intent.getIntExtra("_VA_|_user_id_", VUserHandle.USER_NULL); if (realIntent == null) { return false; } if (userId < 0) { VLog.w(TAG, "Sent a broadcast without userId " + realIntent); return false; } int vuid = VUserHandle.getUid(userId, appId); return handleUserBroadcast(vuid, info, component, realIntent, result); }
public void makeInitialized(int userId) { checkManageUsersPermission("makeInitialized"); synchronized (mPackagesLock) { VUserInfo info = mUsers.get(userId); if (info == null || info.partial) { VLog.w(LOG_TAG, "makeInitialized: unknown user #" + userId); } if ((info.flags& VUserInfo.FLAG_INITIALIZED) == 0) { info.flags |= VUserInfo.FLAG_INITIALIZED; writeUserLocked(info); } } }
void restoreFactoryState() { VLog.w(TAG, "Warning: Restore the factory state..."); VEnvironment.getDalvikCacheDirectory().delete(); VEnvironment.getUserSystemDirectory().delete(); VEnvironment.getDataAppDirectory().delete(); }
private void cleanUpResidualFiles(PackageSetting ps) { VLog.w(TAG, "cleanUpResidualFiles: " + ps.packageName); File dataAppDir = VEnvironment.getDataAppPackageDirectory(ps.packageName); FileUtils.deleteDir(dataAppDir); // We shouldn't remove user data here!!! Just remove the package. // for (int userId : VUserManagerService.get().getUserIds()) { // FileUtils.deleteDir(VEnvironment.getDataUserPackageDirectory(userId, ps.packageName)); // } }
private void save() { File uidFile = VEnvironment.getUidListFile(); File bakUidFile = VEnvironment.getBakUidListFile(); if (uidFile.exists()) { if (bakUidFile.exists() && !bakUidFile.delete()) { VLog.w(TAG, "Warning: Unable to delete the expired file --\n " + bakUidFile.getPath()); } try { FileUtils.copyFile(uidFile, bakUidFile); } catch (IOException e) { e.printStackTrace(); } } try { ObjectOutputStream os = new ObjectOutputStream(new FileOutputStream(uidFile)); os.writeInt(mFreeUid); os.writeObject(mSharedUserIdMap); os.close(); } catch (IOException e) { e.printStackTrace(); } }
public final void addProvider(VPackage.ProviderComponent p) { if (mProviders.containsKey(p.getComponentName())) { VLog.w(TAG, "Provider " + p.getComponentName() + " already defined; ignoring"); return; } mProviders.put(p.getComponentName(), p); final int NI = p.intents.size(); int j; for (j = 0; j < NI; j++) { VPackage.ProviderIntentInfo intent = p.intents.get(j); addFilter(intent); } }
/** * This fixes an incorrect initialization of user name for the owner. * TODO: Remove in the next release. */ private void upgradeIfNecessary() { int userVersion = mUserVersion; if (userVersion < 1) { // Assign a proper name for the owner, if not initialized correctly before VUserInfo user = mUsers.get(VUserHandle.USER_OWNER); if ("Primary".equals(user.name)) { user.name = "Admin"; writeUserLocked(user); } userVersion = 1; } if (userVersion < USER_VERSION) { VLog.w(LOG_TAG, "User version " + mUserVersion + " didn't upgrade as expected to " + USER_VERSION); } else { mUserVersion = userVersion; writeUserListLocked(); } }
/** * Add a method proxy. * * @param methodProxy proxy */ public MethodProxy addMethodProxy(MethodProxy methodProxy) { if (methodProxy != null && !TextUtils.isEmpty(methodProxy.getMethodName())) { if (mInternalMethodProxies.containsKey(methodProxy.getMethodName())) { VLog.w(TAG, "The Hook(%s, %s) you added has been in existence.", methodProxy.getMethodName(), methodProxy.getClass().getName()); return methodProxy; } mInternalMethodProxies.put(methodProxy.getMethodName(), methodProxy); } return methodProxy; }
@Override public void setUserName(int userId, String name) { checkManageUsersPermission("rename users"); boolean changed = false; synchronized (mPackagesLock) { VUserInfo info = mUsers.get(userId); if (info == null || info.partial) { VLog.w(LOG_TAG, "setUserName: unknown user #" + userId); return; } if (name != null && !name.equals(info.name)) { info.name = name; writeUserLocked(info); changed = true; } } if (changed) { sendUserInfoChangedBroadcast(userId); } }
private void buildTypeToAuthDescriptionMap() { for(AuthenticatorDescription desc : VAccountManager.get().getAuthenticatorTypes()) { String name = null; Drawable icon = null; try { Resources res = VirtualCore.get().getResources(desc.packageName); icon = res.getDrawable(desc.iconId); final CharSequence sequence = res.getText(desc.labelId); name = sequence.toString(); name = sequence.toString(); } catch (Resources.NotFoundException e) { // Nothing we can do much here, just log VLog.w(TAG, "No icon resource for account type " + desc.type); } AuthInfo authInfo = new AuthInfo(desc, name, icon); mTypeToAuthenticatorInfo.put(desc.type, authInfo); } }
@Override public void setUserIcon(int userId, Bitmap bitmap) { checkManageUsersPermission("update users"); synchronized (mPackagesLock) { VUserInfo info = mUsers.get(userId); if (info == null || info.partial) { VLog.w(LOG_TAG, "setUserIcon: unknown user #" + userId); return; } writeBitmapLocked(info, bitmap); writeUserLocked(info); } sendUserInfoChangedBroadcast(userId); }
public static int onGetCallingUid(int originUid) { int callingPid = Binder.getCallingPid(); if (callingPid == Process.myPid()) { return VClientImpl.get().getBaseVUid(); } if (callingPid == VirtualCore.get().getSystemPid()) { return Process.SYSTEM_UID; } int vuid = VActivityManager.get().getUidByPid(callingPid); if (vuid != -1) { return VUserHandle.getAppId(vuid); } VLog.w(TAG, String.format("Unknown uid: %s", callingPid)); return VClientImpl.get().getBaseVUid(); }