Search in sources :

Example 81 with UserHandle

use of android.os.UserHandle in project android_frameworks_base by ResurrectionRemix.

the class VolumeInfo method buildStorageVolume.

public StorageVolume buildStorageVolume(Context context, int userId, boolean reportUnmounted) {
    final StorageManager storage = context.getSystemService(StorageManager.class);
    final boolean removable;
    final boolean emulated;
    final boolean allowMassStorage = false;
    final String envState = reportUnmounted ? Environment.MEDIA_UNMOUNTED : getEnvironmentForState(state);
    File userPath = getPathForUser(userId);
    if (userPath == null) {
        userPath = new File("/dev/null");
    }
    String description = null;
    String derivedFsUuid = fsUuid;
    long mtpReserveSize = 0;
    long maxFileSize = 0;
    int mtpStorageId = StorageVolume.STORAGE_ID_INVALID;
    if (type == TYPE_EMULATED) {
        emulated = true;
        final VolumeInfo privateVol = storage.findPrivateForEmulated(this);
        if (privateVol != null) {
            description = storage.getBestVolumeDescription(privateVol);
            derivedFsUuid = privateVol.fsUuid;
        }
        if (isPrimary()) {
            mtpStorageId = StorageVolume.STORAGE_ID_PRIMARY;
        }
        mtpReserveSize = storage.getStorageLowBytes(userPath);
        if (ID_EMULATED_INTERNAL.equals(id)) {
            removable = false;
        } else {
            removable = true;
        }
    } else if (type == TYPE_PUBLIC) {
        emulated = false;
        removable = true;
        description = storage.getBestVolumeDescription(this);
        if (isPrimary()) {
            mtpStorageId = StorageVolume.STORAGE_ID_PRIMARY;
        } else {
            // Since MediaProvider currently persists this value, we need a
            // value that is stable over time.
            mtpStorageId = buildStableMtpStorageId(fsUuid);
        }
        if ("vfat".equals(fsType)) {
            maxFileSize = 4294967295L;
        }
    } else {
        throw new IllegalStateException("Unexpected volume type " + type);
    }
    if (description == null) {
        description = context.getString(android.R.string.unknownName);
    }
    return new StorageVolume(id, mtpStorageId, userPath, description, isPrimary(), removable, emulated, mtpReserveSize, allowMassStorage, maxFileSize, new UserHandle(userId), derivedFsUuid, envState);
}
Also used : UserHandle(android.os.UserHandle) File(java.io.File)

Example 82 with UserHandle

use of android.os.UserHandle in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class SettingsInjector method getInjectedSettings.

/**
     * Gets a list of preferences that other apps have injected.
     *
     * @param profileId Identifier of the user/profile to obtain the injected settings for or
     *                  UserHandle.USER_CURRENT for all profiles associated with current user.
     */
public List<Preference> getInjectedSettings(final int profileId) {
    final UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
    final List<UserHandle> profiles = um.getUserProfiles();
    ArrayList<Preference> prefs = new ArrayList<Preference>();
    final int profileCount = profiles.size();
    for (int i = 0; i < profileCount; ++i) {
        final UserHandle userHandle = profiles.get(i);
        if (profileId == UserHandle.USER_CURRENT || profileId == userHandle.getIdentifier()) {
            Iterable<InjectedSetting> settings = getSettings(userHandle);
            for (InjectedSetting setting : settings) {
                Preference pref = addServiceSetting(prefs, setting);
                mSettings.add(new Setting(setting, pref));
            }
        }
    }
    reloadStatusMessages();
    return prefs;
}
Also used : DimmableIconPreference(com.android.settings.DimmableIconPreference) Preference(android.support.v7.preference.Preference) UserManager(android.os.UserManager) UserHandle(android.os.UserHandle) ArrayList(java.util.ArrayList)

Example 83 with UserHandle

use of android.os.UserHandle in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class CredentialStorage method installIfAvailable.

/**
     * Install credentials if available, otherwise do nothing.
     */
private void installIfAvailable() {
    if (mInstallBundle == null || mInstallBundle.isEmpty()) {
        return;
    }
    Bundle bundle = mInstallBundle;
    mInstallBundle = null;
    final int uid = bundle.getInt(Credentials.EXTRA_INSTALL_AS_UID, KeyStore.UID_SELF);
    if (uid != KeyStore.UID_SELF && !UserHandle.isSameUser(uid, Process.myUid())) {
        int dstUserId = UserHandle.getUserId(uid);
        int myUserId = UserHandle.myUserId();
        // Restrict install target to the wifi uid.
        if (uid != Process.WIFI_UID) {
            Log.e(TAG, "Failed to install credentials as uid " + uid + ": cross-user installs" + " may only target wifi uids");
            return;
        }
        Intent installIntent = new Intent(ACTION_INSTALL).setFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT).putExtras(bundle);
        startActivityAsUser(installIntent, new UserHandle(dstUserId));
        return;
    }
    if (bundle.containsKey(Credentials.EXTRA_USER_PRIVATE_KEY_NAME)) {
        String key = bundle.getString(Credentials.EXTRA_USER_PRIVATE_KEY_NAME);
        byte[] value = bundle.getByteArray(Credentials.EXTRA_USER_PRIVATE_KEY_DATA);
        int flags = KeyStore.FLAG_ENCRYPTED;
        if (uid == Process.WIFI_UID && isHardwareBackedKey(value)) {
            // Hardware backed keystore is secure enough to allow for WIFI stack
            // to enable access to secure networks without user intervention
            Log.d(TAG, "Saving private key with FLAG_NONE for WIFI_UID");
            flags = KeyStore.FLAG_NONE;
        }
        if (!mKeyStore.importKey(key, value, uid, flags)) {
            Log.e(TAG, "Failed to install " + key + " as uid " + uid);
            return;
        }
    }
    int flags = (uid == Process.WIFI_UID) ? KeyStore.FLAG_NONE : KeyStore.FLAG_ENCRYPTED;
    if (bundle.containsKey(Credentials.EXTRA_USER_CERTIFICATE_NAME)) {
        String certName = bundle.getString(Credentials.EXTRA_USER_CERTIFICATE_NAME);
        byte[] certData = bundle.getByteArray(Credentials.EXTRA_USER_CERTIFICATE_DATA);
        if (!mKeyStore.put(certName, certData, uid, flags)) {
            Log.e(TAG, "Failed to install " + certName + " as uid " + uid);
            return;
        }
    }
    if (bundle.containsKey(Credentials.EXTRA_CA_CERTIFICATES_NAME)) {
        String caListName = bundle.getString(Credentials.EXTRA_CA_CERTIFICATES_NAME);
        byte[] caListData = bundle.getByteArray(Credentials.EXTRA_CA_CERTIFICATES_DATA);
        if (!mKeyStore.put(caListName, caListData, uid, flags)) {
            Log.e(TAG, "Failed to install " + caListName + " as uid " + uid);
            return;
        }
    }
    setResult(RESULT_OK);
}
Also used : Bundle(android.os.Bundle) UserHandle(android.os.UserHandle) Intent(android.content.Intent)

Example 84 with UserHandle

use of android.os.UserHandle in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class AppManagementFragment method show.

public static void show(Context context, AppPreference pref) {
    Bundle args = new Bundle();
    args.putString(ARG_PACKAGE_NAME, pref.getPackageName());
    Utils.startWithFragmentAsUser(context, AppManagementFragment.class.getName(), args, -1, pref.getLabel(), false, new UserHandle(pref.getUserId()));
}
Also used : Bundle(android.os.Bundle) UserHandle(android.os.UserHandle)

Example 85 with UserHandle

use of android.os.UserHandle in project android_frameworks_base by DirtyUnicorns.

the class ResolveInfo method loadIcon.

/**
     * Retrieve the current graphical icon associated with this resolution.  This
     * will call back on the given PackageManager to load the icon from
     * the application.
     *
     * @param pm A PackageManager from which the icon can be loaded; usually
     * the PackageManager from which you originally retrieved this item.
     *
     * @return Returns a Drawable containing the resolution's icon.  If the
     * item does not have an icon, the default activity icon is returned.
     */
public Drawable loadIcon(PackageManager pm) {
    Drawable dr = null;
    if (resolvePackageName != null && iconResourceId != 0) {
        dr = pm.getDrawable(resolvePackageName, iconResourceId, null);
    }
    ComponentInfo ci = getComponentInfo();
    if (dr == null && iconResourceId != 0) {
        ApplicationInfo ai = ci.applicationInfo;
        dr = pm.getDrawable(ci.packageName, iconResourceId, ai);
    }
    if (dr != null) {
        return pm.getUserBadgedIcon(dr, new UserHandle(UserHandle.myUserId()));
    }
    return ci.loadIcon(pm);
}
Also used : UserHandle(android.os.UserHandle) Drawable(android.graphics.drawable.Drawable)

Aggregations

UserHandle (android.os.UserHandle)1087 Intent (android.content.Intent)306 RemoteException (android.os.RemoteException)205 Test (org.junit.Test)165 UserInfo (android.content.pm.UserInfo)152 PendingIntent (android.app.PendingIntent)134 Bundle (android.os.Bundle)127 Context (android.content.Context)126 ApplicationInfo (android.content.pm.ApplicationInfo)93 ArrayList (java.util.ArrayList)91 PackageManager (android.content.pm.PackageManager)86 UserManager (android.os.UserManager)85 ComponentName (android.content.ComponentName)82 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)82 Drawable (android.graphics.drawable.Drawable)61 IBinder (android.os.IBinder)49 IOException (java.io.IOException)45 Config (org.robolectric.annotation.Config)41 Account (android.accounts.Account)39 ResolveInfo (android.content.pm.ResolveInfo)37