/** @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 addProfileGroup(ProfileGroup value) {
   if (value.isDefaultGroup()) {
     /* we must not have more than one default group */
     if (mDefaultGroup != null) {
       return;
     }
     mDefaultGroup = value;
   }
   profileGroups.put(value.getUuid(), value);
   mDirty = true;
 }
 public static ProfileGroup fromXml(XmlPullParser xpp) throws XmlPullParserException, IOException {
   String defaultGroup = xpp.getAttributeValue(null, "default");
   defaultGroup = defaultGroup == null ? "false" : defaultGroup;
   ProfileGroup profileGroup =
       new ProfileGroup(xpp.getAttributeValue(null, "name"), defaultGroup.equals("true"));
   int event = xpp.next();
   while (event != XmlPullParser.END_TAG || !xpp.getName().equals("profileGroup")) {
     if (event == XmlPullParser.START_TAG) {
       String name = xpp.getName();
       if (name.equals("sound")) {
         profileGroup.setSoundOverride(Uri.parse(xpp.nextText()));
       } else if (name.equals("ringer")) {
         profileGroup.setRingerOverride(Uri.parse(xpp.nextText()));
       } else if (name.equals("soundMode")) {
         profileGroup.setSoundMode(Mode.valueOf(xpp.nextText()));
       } else if (name.equals("ringerMode")) {
         profileGroup.setRingerMode(Mode.valueOf(xpp.nextText()));
       } else if (name.equals("vibrateMode")) {
         profileGroup.setVibrateMode(Mode.valueOf(xpp.nextText()));
       } else if (name.equals("lightsMode")) {
         profileGroup.setLightsMode(Mode.valueOf(xpp.nextText()));
       }
     }
     event = xpp.next();
   }
   return profileGroup;
 }
  /** @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 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;
  }