Search in sources :

Example 21 with UserManager

use of android.os.UserManager in project platform_frameworks_base by android.

the class MediaSessionService method updateUser.

private void updateUser() {
    synchronized (mLock) {
        UserManager manager = (UserManager) getContext().getSystemService(Context.USER_SERVICE);
        int currentUser = ActivityManager.getCurrentUser();
        // Include all profiles even though they aren't yet enabled to handle work profile case.
        int[] userIds = manager.getProfileIdsWithDisabled(currentUser);
        mCurrentUserIdList.clear();
        if (userIds != null && userIds.length > 0) {
            for (int userId : userIds) {
                mCurrentUserIdList.add(userId);
            }
        } else {
            // This shouldn't happen.
            Log.w(TAG, "Failed to get enabled profiles.");
            mCurrentUserIdList.add(currentUser);
        }
        for (int userId : mCurrentUserIdList) {
            if (mUserRecords.get(userId) == null) {
                mUserRecords.put(userId, new UserRecord(getContext(), userId));
            }
        }
    }
}
Also used : UserManager(android.os.UserManager)

Example 22 with UserManager

use of android.os.UserManager in project platform_frameworks_base by android.

the class Vpn method establish.

/**
     * Establish a VPN network and return the file descriptor of the VPN
     * interface. This methods returns {@code null} if the application is
     * revoked or not prepared.
     *
     * @param config The parameters to configure the network.
     * @return The file descriptor of the VPN interface.
     */
public synchronized ParcelFileDescriptor establish(VpnConfig config) {
    // Check if the caller is already prepared.
    UserManager mgr = UserManager.get(mContext);
    if (Binder.getCallingUid() != mOwnerUID) {
        return null;
    }
    // Check to ensure consent hasn't been revoked since we were prepared.
    if (!isVpnUserPreConsented(mPackage)) {
        return null;
    }
    // Check if the service is properly declared.
    Intent intent = new Intent(VpnConfig.SERVICE_INTERFACE);
    intent.setClassName(mPackage, config.user);
    long token = Binder.clearCallingIdentity();
    try {
        // Restricted users are not allowed to create VPNs, they are tied to Owner
        UserInfo user = mgr.getUserInfo(mUserHandle);
        if (user.isRestricted()) {
            throw new SecurityException("Restricted users cannot establish VPNs");
        }
        ResolveInfo info = AppGlobals.getPackageManager().resolveService(intent, null, 0, mUserHandle);
        if (info == null) {
            throw new SecurityException("Cannot find " + config.user);
        }
        if (!BIND_VPN_SERVICE.equals(info.serviceInfo.permission)) {
            throw new SecurityException(config.user + " does not require " + BIND_VPN_SERVICE);
        }
    } catch (RemoteException e) {
        throw new SecurityException("Cannot find " + config.user);
    } finally {
        Binder.restoreCallingIdentity(token);
    }
    // Save the old config in case we need to go back.
    VpnConfig oldConfig = mConfig;
    String oldInterface = mInterface;
    Connection oldConnection = mConnection;
    NetworkAgent oldNetworkAgent = mNetworkAgent;
    mNetworkAgent = null;
    Set<UidRange> oldUsers = mVpnUsers;
    // Configure the interface. Abort if any of these steps fails.
    ParcelFileDescriptor tun = ParcelFileDescriptor.adoptFd(jniCreate(config.mtu));
    try {
        updateState(DetailedState.CONNECTING, "establish");
        String interfaze = jniGetName(tun.getFd());
        // TEMP use the old jni calls until there is support for netd address setting
        StringBuilder builder = new StringBuilder();
        for (LinkAddress address : config.addresses) {
            builder.append(" " + address);
        }
        if (jniSetAddresses(interfaze, builder.toString()) < 1) {
            throw new IllegalArgumentException("At least one address must be specified");
        }
        Connection connection = new Connection();
        if (!mContext.bindServiceAsUser(intent, connection, Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE, new UserHandle(mUserHandle))) {
            throw new IllegalStateException("Cannot bind " + config.user);
        }
        mConnection = connection;
        mInterface = interfaze;
        // Fill more values.
        config.user = mPackage;
        config.interfaze = mInterface;
        config.startTime = SystemClock.elapsedRealtime();
        mConfig = config;
        // Set up forwarding and DNS rules.
        agentConnect();
        if (oldConnection != null) {
            mContext.unbindService(oldConnection);
        }
        // Remove the old tun's user forwarding rules
        // The new tun's user rules have already been added so they will take over
        // as rules are deleted. This prevents data leakage as the rules are moved over.
        agentDisconnect(oldNetworkAgent);
        if (oldInterface != null && !oldInterface.equals(interfaze)) {
            jniReset(oldInterface);
        }
        try {
            IoUtils.setBlocking(tun.getFileDescriptor(), config.blocking);
        } catch (IOException e) {
            throw new IllegalStateException("Cannot set tunnel's fd as blocking=" + config.blocking, e);
        }
    } catch (RuntimeException e) {
        IoUtils.closeQuietly(tun);
        agentDisconnect();
        // restore old state
        mConfig = oldConfig;
        mConnection = oldConnection;
        mVpnUsers = oldUsers;
        mNetworkAgent = oldNetworkAgent;
        mInterface = oldInterface;
        throw e;
    }
    Log.i(TAG, "Established by " + config.user + " on " + mInterface);
    return tun;
}
Also used : LinkAddress(android.net.LinkAddress) NetworkAgent(android.net.NetworkAgent) VpnConfig(com.android.internal.net.VpnConfig) UidRange(android.net.UidRange) ServiceConnection(android.content.ServiceConnection) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) UserInfo(android.content.pm.UserInfo) IOException(java.io.IOException) ResolveInfo(android.content.pm.ResolveInfo) UserManager(android.os.UserManager) UserHandle(android.os.UserHandle) ParcelFileDescriptor(android.os.ParcelFileDescriptor) RemoteException(android.os.RemoteException)

Example 23 with UserManager

use of android.os.UserManager in project platform_frameworks_base by android.

the class ShutdownThread method rebootSafeMode.

/**
     * Request a reboot into safe mode.  Must be called from a Looper thread in which its UI
     * is shown.
     *
     * @param context Context used to display the shutdown progress dialog.
     * @param confirm true if user confirmation is needed before shutting down.
     */
public static void rebootSafeMode(final Context context, boolean confirm) {
    UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
    if (um.hasUserRestriction(UserManager.DISALLOW_SAFE_BOOT)) {
        return;
    }
    mReboot = true;
    mRebootSafeMode = true;
    mRebootHasProgressBar = false;
    mReason = null;
    shutdownInner(context, confirm);
}
Also used : UserManager(android.os.UserManager)

Example 24 with UserManager

use of android.os.UserManager in project platform_frameworks_base by android.

the class EnableAccessibilityController method enableAccessibility.

public static boolean enableAccessibility(Context context) {
    final IAccessibilityManager accessibilityManager = IAccessibilityManager.Stub.asInterface(ServiceManager.getService("accessibility"));
    final WindowManagerInternal windowManager = LocalServices.getService(WindowManagerInternal.class);
    final UserManager userManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
    ComponentName componentName = getInstalledSpeakingAccessibilityServiceComponent(context);
    if (componentName == null) {
        return false;
    }
    boolean keyguardLocked = windowManager.isKeyguardLocked();
    final boolean hasMoreThanOneUser = userManager.getUsers().size() > 1;
    try {
        if (!keyguardLocked || !hasMoreThanOneUser) {
            final int userId = ActivityManager.getCurrentUser();
            accessibilityManager.enableAccessibilityService(componentName, userId);
        } else if (keyguardLocked) {
            accessibilityManager.temporaryEnableAccessibilityStateUntilKeyguardRemoved(componentName, true);
        }
    } catch (RemoteException e) {
        Log.e(TAG, "cannot enable accessibilty: " + e);
    }
    return true;
}
Also used : WindowManagerInternal(android.view.WindowManagerInternal) IAccessibilityManager(android.view.accessibility.IAccessibilityManager) UserManager(android.os.UserManager) ComponentName(android.content.ComponentName) RemoteException(android.os.RemoteException)

Example 25 with UserManager

use of android.os.UserManager in project platform_frameworks_base by android.

the class GlobalActions method addUsersToMenu.

private void addUsersToMenu(ArrayList<Action> items) {
    UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
    if (um.isUserSwitcherEnabled()) {
        List<UserInfo> users = um.getUsers();
        UserInfo currentUser = getCurrentUser();
        for (final UserInfo user : users) {
            if (user.supportsSwitchToByUser()) {
                boolean isCurrentUser = currentUser == null ? user.id == 0 : (currentUser.id == user.id);
                Drawable icon = user.iconPath != null ? Drawable.createFromPath(user.iconPath) : null;
                SinglePressAction switchToUser = new SinglePressAction(com.android.internal.R.drawable.ic_menu_cc, icon, (user.name != null ? user.name : "Primary") + (isCurrentUser ? " ✔" : "")) {

                    public void onPress() {
                        try {
                            ActivityManagerNative.getDefault().switchUser(user.id);
                        } catch (RemoteException re) {
                            Log.e(TAG, "Couldn't switch user " + re);
                        }
                    }

                    public boolean showDuringKeyguard() {
                        return true;
                    }

                    public boolean showBeforeProvisioning() {
                        return false;
                    }
                };
                items.add(switchToUser);
            }
        }
    }
}
Also used : UserManager(android.os.UserManager) Drawable(android.graphics.drawable.Drawable) UserInfo(android.content.pm.UserInfo) RemoteException(android.os.RemoteException)

Aggregations

UserManager (android.os.UserManager)271 UserInfo (android.content.pm.UserInfo)146 UserHandle (android.os.UserHandle)44 RemoteException (android.os.RemoteException)40 Intent (android.content.Intent)30 DevicePolicyManager (android.app.admin.DevicePolicyManager)29 ComponentName (android.content.ComponentName)29 Context (android.content.Context)25 PackageManager (android.content.pm.PackageManager)25 ArrayList (java.util.ArrayList)21 PendingIntent (android.app.PendingIntent)16 LockPatternUtils (com.android.internal.widget.LockPatternUtils)16 ApplicationInfo (android.content.pm.ApplicationInfo)15 File (java.io.File)15 ContentResolver (android.content.ContentResolver)14 ResolveInfo (android.content.pm.ResolveInfo)13 IPackageManager (android.content.pm.IPackageManager)12 Drawable (android.graphics.drawable.Drawable)12 MediumTest (android.test.suitebuilder.annotation.MediumTest)12 Resources (android.content.res.Resources)11