/** @hide */
  public void getXmlString(StringBuilder builder, Context context) {
    builder.append("<profile ");
    if (mNameResId > 0) {
      builder.append("nameres=\"");
      builder.append(context.getResources().getResourceEntryName(mNameResId));
    } else {
      builder.append("name=\"");
      builder.append(TextUtils.htmlEncode(getName()));
    }
    builder.append("\" uuid=\"");
    builder.append(TextUtils.htmlEncode(getUuid().toString()));
    builder.append("\">\n");

    builder.append("<statusbar>");
    builder.append(getStatusBarIndicator() ? "yes" : "no");
    builder.append("</statusbar>\n");

    for (ProfileGroup pGroup : profileGroups.values()) {
      pGroup.getXmlString(builder, context);
    }
    for (StreamSettings sd : streams.values()) {
      sd.getXmlString(builder, context);
    }
    for (ConnectionSettings cs : connections.values()) {
      cs.getXmlString(builder, context);
    }
    builder.append("</profile>\n");
    mDirty = false;
  }
 /** @hide */
 public void doSelect(Context context) {
   // Set stream volumes
   AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
   for (StreamSettings sd : streams.values()) {
     if (sd.isOverride()) {
       am.setStreamVolume(sd.getStreamId(), sd.getValue(), 0);
     }
   }
   // Set connections
   for (ConnectionSettings cs : connections.values()) {
     if (cs.isOverride()) {
       cs.processOverride(context);
     }
   }
 }
  /** @hide */
  public boolean isDirty() {
    if (mDirty) {
      return true;
    }
    for (ProfileGroup group : profileGroups.values()) {
      if (group.isDirty()) {
        return true;
      }
    }
    for (StreamSettings stream : streams.values()) {
      if (stream.isDirty()) {
        return true;
      }
    }
    for (ConnectionSettings conn : connections.values()) {
      if (conn.isDirty()) {
        return true;
      }
    }

    return false;
  }
 /** @hide */
 public void readFromParcel(Parcel in) {
   mName = in.readString();
   mNameResId = in.readInt();
   mUuid = ParcelUuid.CREATOR.createFromParcel(in).getUuid();
   mStatusBarIndicator = (in.readInt() == 1);
   mDirty = (in.readInt() == 1);
   for (Parcelable group : in.readParcelableArray(null)) {
     ProfileGroup grp = (ProfileGroup) group;
     profileGroups.put(grp.getUuid(), grp);
     if (grp.isDefaultGroup()) {
       mDefaultGroup = grp;
     }
   }
   for (Parcelable parcel : in.readParcelableArray(null)) {
     StreamSettings stream = (StreamSettings) parcel;
     streams.put(stream.getStreamId(), stream);
   }
   for (Parcelable parcel : in.readParcelableArray(null)) {
     ConnectionSettings connection = (ConnectionSettings) parcel;
     connections.put(connection.getConnectionId(), connection);
   }
 }
 /** @hide */
 public void setStreamSettings(StreamSettings descriptor) {
   streams.put(descriptor.getStreamId(), descriptor);
   mDirty = true;
 }
  /** @hide */
  public static Profile fromXml(XmlPullParser xpp, Context context)
      throws XmlPullParserException, IOException {
    String value = xpp.getAttributeValue(null, "nameres");
    int profileNameResId = -1;
    String profileName = null;

    if (value != null) {
      profileNameResId = context.getResources().getIdentifier(value, "string", "android");
      if (profileNameResId > 0) {
        profileName = context.getResources().getString(profileNameResId);
      }
    }

    if (profileName == null) {
      profileName = xpp.getAttributeValue(null, "name");
    }

    UUID profileUuid = UUID.randomUUID();
    try {
      profileUuid = UUID.fromString(xpp.getAttributeValue(null, "uuid"));
    } catch (NullPointerException e) {
      Log.w(
          TAG,
          "Null Pointer - UUID not found for "
              + profileName
              + ".  New UUID generated: "
              + profileUuid.toString());
    } catch (IllegalArgumentException e) {
      Log.w(
          TAG,
          "UUID not recognized for "
              + profileName
              + ".  New UUID generated: "
              + profileUuid.toString());
    }

    Profile profile = new Profile(profileName, profileNameResId, profileUuid);
    int event = xpp.next();
    while (event != XmlPullParser.END_TAG) {
      if (event == XmlPullParser.START_TAG) {
        String name = xpp.getName();
        if (name.equals("statusbar")) {
          profile.setStatusBarIndicator(xpp.nextText() == "yes");
        }
        if (name.equals("profileGroup")) {
          ProfileGroup pg = ProfileGroup.fromXml(xpp, context);
          profile.addProfileGroup(pg);
        }
        if (name.equals("streamDescriptor")) {
          StreamSettings sd = StreamSettings.fromXml(xpp, context);
          profile.setStreamSettings(sd);
        }
        if (name.equals("connectionDescriptor")) {
          ConnectionSettings cs = ConnectionSettings.fromXml(xpp, context);
          profile.connections.put(cs.getConnectionId(), cs);
        }
      }
      event = xpp.next();
    }

    /* we just loaded from XML, so nothing needs saving */
    profile.mDirty = false;

    return profile;
  }