Example usage for android.os UserHandle USER_OWNER

List of usage examples for android.os UserHandle USER_OWNER

Introduction

In this page you can find the example usage for android.os UserHandle USER_OWNER.

Prototype

int USER_OWNER

To view the source code for android.os UserHandle USER_OWNER.

Click Source Link

Usage

From source file:com.android.managedprovisioning.ProfileOwnerPreProvisioningActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final LayoutInflater inflater = getLayoutInflater();
    View contentView = inflater.inflate(R.layout.user_consent, null);
    setContentView(contentView);/* w w w .  j  a  v a  2s . co  m*/

    // Check whether system has the required managed profile feature.
    if (!systemHasManagedProfileFeature()) {
        showErrorAndClose(R.string.managed_provisioning_not_supported,
                "Exiting managed profile provisioning, " + "managed profiles feature is not available");
        return;
    }
    if (Process.myUserHandle().getIdentifier() != UserHandle.USER_OWNER) {
        showErrorAndClose(R.string.user_is_not_owner,
                "Exiting managed profile provisioning, calling user is not owner.");
        return;
    }

    // Initialize member variables from the intent, stop if the intent wasn't valid.
    try {
        initialize(getIntent());
    } catch (ProvisioningFailedException e) {
        showErrorAndClose(R.string.managed_provisioning_error_text, e.getMessage());
        return;
    }

    setMdmIcon(mMdmPackageName);

    // If the caller started us via ALIAS_NO_CHECK_CALLER then they must have permission to
    // MANAGE_USERS since it is a restricted intent. Otherwise, check the calling package.
    boolean hasManageUsersPermission = (getComponentName().equals(ALIAS_NO_CHECK_CALLER));
    if (!hasManageUsersPermission) {
        // Calling package has to equal the requested device admin package or has to be system.
        String callingPackage = getCallingPackage();
        if (callingPackage == null) {
            showErrorAndClose(R.string.managed_provisioning_error_text,
                    "Calling package is null. " + "Was startActivityForResult used to start this activity?");
            return;
        }
        if (!callingPackage.equals(mMdmPackageName) && !packageHasManageUsersPermission(callingPackage)) {
            showErrorAndClose(R.string.managed_provisioning_error_text,
                    "Permission denied, "
                            + "calling package tried to set a different package as profile owner. "
                            + "The system MANAGE_USERS permission is required.");
            return;
        }
    }

    DevicePolicyManager dpm = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
    String deviceOwner = dpm.getDeviceOwner();
    if (deviceOwner != null && !deviceOwner.equals(mMdmPackageName)) {
        showErrorAndClose(R.string.managed_provisioning_error_text,
                "Permission denied, " + "profile owner must be in the same package as device owner.");
        return;
    }

    // If there is already a managed profile, allow the user to cancel or delete it.
    int existingManagedProfileUserId = alreadyHasManagedProfile();
    if (existingManagedProfileUserId != -1) {
        showManagedProfileExistsDialog(existingManagedProfileUserId);
    } else {
        showStartProvisioningScreen();
    }
}

From source file:com.android.settings.HWSettings.java

@Override
public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) {
    // Override the fragment title for Wallpaper settings
    int titleRes = pref.getTitleRes();
    if (pref.getFragment().equals(WallpaperTypeSettings.class.getName())) {
        titleRes = R.string.wallpaper_settings_fragment_title;
    } else if (pref.getFragment().equals(OwnerInfoSettings.class.getName())
            && UserHandle.myUserId() != UserHandle.USER_OWNER) {
        if (UserManager.get(this).isLinkedUser()) {
            titleRes = R.string.profile_info_settings_title;
        } else {/*from   w w w . j a  va2s .  c o m*/
            titleRes = R.string.user_info_settings_title;
        }
    }
    startPreferencePanel(pref.getFragment(), pref.getExtras(), titleRes, pref.getTitle(), null, 0);
    return true;
}

From source file:com.android.server.MountService.java

@VisibleForTesting
public static String buildObbPath(final String canonicalPath, int userId, boolean forVold) {
    // TODO: allow caller to provide Environment for full testing
    // TODO: extend to support OBB mounts on secondary external storage

    // Only adjust paths when storage is emulated
    if (!Environment.isExternalStorageEmulated()) {
        return canonicalPath;
    }//from   www  .  ja  v a2s.c  o  m

    String path = canonicalPath.toString();

    // First trim off any external storage prefix
    final UserEnvironment userEnv = new UserEnvironment(userId);

    // /storage/emulated/0
    final String externalPath = userEnv.getExternalStorageDirectory().getAbsolutePath();
    // /storage/emulated_legacy
    final String legacyExternalPath = Environment.getLegacyExternalStorageDirectory().getAbsolutePath();

    if (path.startsWith(externalPath)) {
        path = path.substring(externalPath.length() + 1);
    } else if (path.startsWith(legacyExternalPath)) {
        path = path.substring(legacyExternalPath.length() + 1);
    } else {
        return canonicalPath;
    }

    // Handle special OBB paths on emulated storage
    final String obbPath = "Android/obb";
    if (path.startsWith(obbPath)) {
        path = path.substring(obbPath.length() + 1);

        if (forVold) {
            return new File(Environment.getEmulatedStorageObbSource(), path).getAbsolutePath();
        } else {
            final UserEnvironment ownerEnv = new UserEnvironment(UserHandle.USER_OWNER);
            return new File(ownerEnv.buildExternalStorageAndroidObbDirs()[0], path).getAbsolutePath();
        }
    }

    // Handle normal external storage paths
    if (forVold) {
        return new File(Environment.getEmulatedStorageSource(userId), path).getAbsolutePath();
    } else {
        return new File(userEnv.getExternalDirsForApp()[0], path).getAbsolutePath();
    }
}

From source file:android.content.pm.PackageParser.java

private static boolean copyNeeded(int flags, Package p, PackageUserState state, Bundle metaData, int userId) {
    if (userId != UserHandle.USER_OWNER) {
        // We always need to copy for other users, since we need
        // to fix up the uid.
        return true;
    }//w  w  w .  j a  v a 2 s  . c  om
    if (state.enabled != PackageManager.COMPONENT_ENABLED_STATE_DEFAULT) {
        boolean enabled = state.enabled == PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
        if (p.applicationInfo.enabled != enabled) {
            return true;
        }
    }
    if (!state.installed || state.hidden) {
        return true;
    }
    if (state.stopped) {
        return true;
    }
    if ((flags & PackageManager.GET_META_DATA) != 0 && (metaData != null || p.mAppMetaData != null)) {
        return true;
    }
    if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0 && p.usesLibraryFiles != null) {
        return true;
    }
    return false;
}