Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e5519060 authored by Danny Baumann's avatar Danny Baumann
Browse files

Enhance profile framework to support runtime locale changes (1/2)

Before, the localized names of the default profiles were persisted into
the XML file. That way, the locale selected on first boot was used for
determining the profile names.

Now, instead of the name, the resource name is persisted for the default
profiles. That makes the default profile names follow the user's locale,
while custom profiles still use the user selected name.

Change-Id: I11768c3ffea2694aad83bf46709e3d4f5ade521c
parent 2770abd7
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ interface IProfileManager

    boolean addProfile(in Profile profile);
    boolean removeProfile(in Profile profile);
    void updateProfile(in Profile profile);

    Profile getProfile(in ParcelUuid profileParcelUuid);
    Profile getProfileByName(String profileName);
@@ -37,11 +38,10 @@ interface IProfileManager
    boolean profileExists(in ParcelUuid profileUuid);
    boolean profileExistsByName(String profileName);

    void persist();

    NotificationGroup[] getNotificationGroups();
    void addNotificationGroup(in NotificationGroup group);
    void removeNotificationGroup(in NotificationGroup group);
    void updateNotificationGroup(in NotificationGroup group);
    NotificationGroup getNotificationGroupForPackage(in String pkg);
    NotificationGroup getNotificationGroup(in String name);
    NotificationGroup getNotificationGroup(in ParcelUuid groupParcelUuid);
}
+79 −20
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import org.xmlpull.v1.XmlPullParserException;
import android.content.Context;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.ParcelUuid;
import android.text.TextUtils;
import android.util.Log;

@@ -29,14 +30,21 @@ import java.io.IOException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;

/** @hide */
public class NotificationGroup implements Parcelable {
    private static final String TAG = "NotificationGroup";

    private String mName;
    private int mNameResId;

    private UUID mUuid;

    private Set<String> mPackages = new HashSet<String>();

    private boolean mDirty;

    public static final Parcelable.Creator<NotificationGroup> CREATOR = new Parcelable.Creator<NotificationGroup>() {
        public NotificationGroup createFromParcel(Parcel in) {
            return new NotificationGroup(in);
@@ -49,7 +57,14 @@ public class NotificationGroup implements Parcelable {
    };

    public NotificationGroup(String name) {
        this.mName = name;
        this(name, -1, null);
    }

    public NotificationGroup(String name, int nameResId, UUID uuid) {
        mName = name;
        mNameResId = nameResId;
        mUuid = (uuid != null) ? uuid : UUID.randomUUID();
        mDirty = uuid == null;
    }

    private NotificationGroup(Parcel in) {
@@ -65,8 +80,13 @@ public class NotificationGroup implements Parcelable {
        return mName;
    }

    public UUID getUuid() {
        return mUuid;
    }

    public void addPackage(String pkg) {
        mPackages.add(pkg);
        mDirty = true;
    }

    public String[] getPackages() {
@@ -75,14 +95,19 @@ public class NotificationGroup implements Parcelable {

    public void removePackage(String pkg) {
        mPackages.remove(pkg);
        mDirty = true;
    }

    public boolean hasPackage(String pkg) {
        boolean result = mPackages.contains(pkg);
        Log.i("PROFILE", "Group: " + mName + " containing : " + pkg + " : " + result);
        Log.i(TAG, "Group: " + mName + " containing : " + pkg + " : " + result);
        return result;
    }

    public boolean isDirty() {
        return mDirty;
    }

    @Override
    public int describeContents() {
        return 0;
@@ -91,47 +116,81 @@ public class NotificationGroup implements Parcelable {
    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(mName);
        dest.writeInt(mNameResId);
        dest.writeInt(mDirty ? 1 : 0);
        new ParcelUuid(mUuid).writeToParcel(dest, 0);
        dest.writeStringArray(getPackages());
    }

    public void readFromParcel(Parcel in) {
        mName = in.readString();
        mNameResId = in.readInt();
        mDirty = in.readInt() != 0;
        mUuid = ParcelUuid.CREATOR.createFromParcel(in).getUuid();
        mPackages.addAll(Arrays.asList(in.readStringArray()));
    }

    public String getXmlString() {
        StringBuilder builder = new StringBuilder();
        getXmlString(builder);
        return builder.toString();
    public void getXmlString(StringBuilder builder, Context context) {
        builder.append("<notificationGroup ");
        if (mNameResId > 0) {
            builder.append("nameres=\"");
            builder.append(context.getResources().getResourceEntryName(mNameResId));
        } else {
            builder.append("name=\"");
            builder.append(TextUtils.htmlEncode(getName()));
        }

    public void getXmlString(StringBuilder builder) {
        builder.append("<notificationGroup name=\"" + TextUtils.htmlEncode(getName()) + "\">\n");
        builder.append("\" uuid=\"");
        builder.append(TextUtils.htmlEncode(getUuid().toString()));
        builder.append("\">\n");
        for (String pkg : mPackages) {
            builder.append("<package>" + TextUtils.htmlEncode(pkg) + "</package>\n");
        }
        builder.append("</notificationGroup>\n");
        mDirty = false;
    }

    public static NotificationGroup fromXml(XmlPullParser xpp) throws XmlPullParserException,
            IOException {
        return fromXml(xpp, null);
    public static NotificationGroup fromXml(XmlPullParser xpp, Context context)
            throws XmlPullParserException, IOException {
        String value = xpp.getAttributeValue(null, "nameres");
        int nameResId = -1;
        String name = null;
        UUID uuid = null;

        if (value != null) {
            nameResId = context.getResources().getIdentifier(value, "string", "android");
            if (nameResId > 0) {
                name = context.getResources().getString(nameResId);
            }
    public static NotificationGroup fromXml(XmlPullParser xpp, Context context) throws XmlPullParserException,
            IOException {
        String attr = Profile.getAttrResString(xpp, context);
        NotificationGroup notificationGroup = new NotificationGroup(attr);
        }

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

        value = xpp.getAttributeValue(null, "uuid");
        if (value != null) {
            try {
                uuid = UUID.fromString(value);
            } catch (IllegalArgumentException e) {
                Log.w(TAG, "UUID not recognized for " + name + ", using new one.");
            }
        }

        NotificationGroup notificationGroup = new NotificationGroup(name, nameResId, uuid);
        int event = xpp.next();
        while (event != XmlPullParser.END_TAG || !xpp.getName().equals("notificationGroup")) {
            if (event == XmlPullParser.START_TAG) {
                String name = xpp.getName();
                if (name.equals("package")) {
                if (xpp.getName().equals("package")) {
                    String pkg = xpp.nextText();
                    notificationGroup.addPackage(pkg);
                }
            }
            event = xpp.next();
        }

        /* we just loaded from XML, no need to save */
        notificationGroup.mDirty = false;

        return notificationGroup;
    }
}
+80 −76
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@ import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

import android.content.Context;
import android.content.res.XmlResourceParser;
import android.media.AudioManager;
import android.os.Parcel;
import android.os.Parcelable;
@@ -37,14 +36,16 @@ import java.util.UUID;
public class Profile implements Parcelable {

    private String mName;
    private int mNameResId;

    private UUID mUuid;

    private Map<String, ProfileGroup> profileGroups = new HashMap<String, ProfileGroup>();
    private Map<UUID, ProfileGroup> profileGroups = new HashMap<UUID, ProfileGroup>();

    private ProfileGroup mDefaultGroup;

    private boolean mStatusBarIndicator = false;
    private boolean mDirty;

    private static final String TAG = "Profile";

@@ -64,14 +65,14 @@ public class Profile implements Parcelable {

    /** @hide */
    public Profile(String name) {
        this.mName = name;
        // Generate a new UUID, since one was not specified.
        this.mUuid = UUID.randomUUID();
        this(name, -1, UUID.randomUUID());
    }

    public Profile(String name, UUID uuid) {
        this.mName = name;
        this.mUuid = uuid;
    private Profile(String name, int nameResId, UUID uuid) {
        mName = name;
        mNameResId = nameResId;
        mUuid = uuid;
        mDirty = false;
    }

    private Profile(Parcel in) {
@@ -79,32 +80,20 @@ public class Profile implements Parcelable {
    }

    /** @hide */
    public void ensureProfileGroup(String groupName) {
        ensureProfileGroup(groupName, false);
    }

    /** @hide */
    public void ensureProfileGroup(String groupName, boolean defaultGroup) {
        if (!profileGroups.containsKey(groupName)) {
            ProfileGroup value = new ProfileGroup(groupName, defaultGroup);
            addProfileGroup(value);
        }
    }

    /** @hide */
    private void addProfileGroup(ProfileGroup value) {
        profileGroups.put(value.getName(), value);
    public void addProfileGroup(ProfileGroup value) {
        profileGroups.put(value.getUuid(), value);
        if (value.isDefaultGroup()) {
            mDefaultGroup = value;
        }
        mDirty = true;
    }

    /** @hide */
    public void removeProfileGroup(String name) {
        if (!profileGroups.get(name).isDefaultGroup()) {
            profileGroups.remove(name);
    public void removeProfileGroup(UUID uuid) {
        if (!profileGroups.get(uuid).isDefaultGroup()) {
            profileGroups.remove(uuid);
        } else {
            Log.e(TAG, "Cannot remove default group: " + name);
            Log.e(TAG, "Cannot remove default group: " + uuid);
        }
    }

@@ -112,8 +101,8 @@ public class Profile implements Parcelable {
        return profileGroups.values().toArray(new ProfileGroup[profileGroups.size()]);
    }

    public ProfileGroup getProfileGroup(String name) {
        return profileGroups.get(name);
    public ProfileGroup getProfileGroup(UUID uuid) {
        return profileGroups.get(uuid);
    }

    public ProfileGroup getDefaultGroup() {
@@ -130,8 +119,10 @@ public class Profile implements Parcelable {
    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(mName);
        dest.writeInt(mNameResId);
        new ParcelUuid(mUuid).writeToParcel(dest, 0);
        dest.writeInt(mStatusBarIndicator ? 1 : 0);
        dest.writeInt(mDirty ? 1 : 0);
        dest.writeParcelableArray(
                profileGroups.values().toArray(new Parcelable[profileGroups.size()]), flags);
        dest.writeParcelableArray(
@@ -141,18 +132,20 @@ public class Profile implements Parcelable {
    /** @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.getName(), grp);
            profileGroups.put(grp.getUuid(), grp);
            if (grp.isDefaultGroup()) {
                mDefaultGroup = grp;
            }
        }
        for (Parcelable parcel : in.readParcelableArray(null)) {
            StreamSettings stream = (StreamSettings) parcel;
            streams.put(stream.streamId, stream);
            streams.put(stream.getStreamId(), stream);
        }
    }

@@ -162,7 +155,9 @@ public class Profile implements Parcelable {

    /** @hide */
    public void setName(String name) {
        this.mName = name;
        mName = name;
        mNameResId = -1;
        mDirty = true;
    }

    public UUID getUuid() {
@@ -176,27 +171,38 @@ public class Profile implements Parcelable {

    public void setStatusBarIndicator(boolean newStatusBarIndicator) {
        mStatusBarIndicator = newStatusBarIndicator;
        mDirty = true;
    }

    /** @hide */
    public Notification processNotification(String groupName, Notification notification) {
        ProfileGroup profileGroupSettings = groupName == null ? mDefaultGroup : profileGroups
                .get(groupName);
        notification = profileGroupSettings.processNotification(notification);
        return notification;
    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;
            }
        }

    /** @hide */
    public String getXmlString() {
        StringBuilder builder = new StringBuilder();
        getXmlString(builder);
        return builder.toString();
        return false;
    }

    /** @hide */
    public void getXmlString(StringBuilder builder) {
        builder.append("<profile name=\"");
    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");
@@ -206,41 +212,33 @@ public class Profile implements Parcelable {
        builder.append("</statusbar>\n");

        for (ProfileGroup pGroup : profileGroups.values()) {
            pGroup.getXmlString(builder);
            pGroup.getXmlString(builder, context);
        }
        for (StreamSettings sd : streams.values()) {
            sd.getXmlString(builder);
            sd.getXmlString(builder, context);
        }
        builder.append("</profile>\n");
        mDirty = false;
    }

    /** @hide */
    public static String getAttrResString(XmlPullParser xpp, Context context) {
        return Profile.getAttrResString(xpp, context, "name");
    }
    public static Profile fromXml(XmlPullParser xpp, Context context)
            throws XmlPullParserException, IOException {
        String value = xpp.getAttributeValue(null, "nameres");
        int profileNameResId = -1;
        String profileName = null;

    /** @hide */
    public static String getAttrResString(XmlPullParser xpp, Context context, String attrib) {
        String response = null;
        if (attrib == null) attrib = "name";
        if (xpp instanceof XmlResourceParser && context != null) {
            XmlResourceParser xrp = (XmlResourceParser) xpp;
            int resId = xrp.getAttributeResourceValue(null, attrib, 0);
            if (resId != 0) {
                response = context.getResources().getString(resId);
            } else {
                response = xrp.getAttributeValue(null, attrib);
        if (value != null) {
            profileNameResId = context.getResources().getIdentifier(value, "string", "android");
            if (profileNameResId > 0) {
                profileName = context.getResources().getString(profileNameResId);
            }
        } else {
            response = xpp.getAttributeValue(null, attrib);
        }
        return response;

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

    /** @hide */
    public static Profile fromXml(XmlPullParser xpp, Context context)
            throws XmlPullParserException, IOException {
        String profileName = getAttrResString(xpp, context, "name");
        UUID profileUuid = UUID.randomUUID();
        try {
            profileUuid = UUID.fromString(xpp.getAttributeValue(null, "uuid"));
@@ -259,7 +257,8 @@ public class Profile implements Parcelable {
                    + profileUuid.toString()
                    );
        }
        Profile profile = new Profile(profileName, profileUuid);

        Profile profile = new Profile(profileName, profileNameResId, profileUuid);
        int event = xpp.next();
        while (event != XmlPullParser.END_TAG) {
            if (event == XmlPullParser.START_TAG) {
@@ -273,11 +272,15 @@ public class Profile implements Parcelable {
                }
                if (name.equals("streamDescriptor")) {
                    StreamSettings sd = StreamSettings.fromXml(xpp, context);
                    profile.streams.put(sd.streamId, sd);
                    profile.setStreamSettings(sd);
                }
            }
            event = xpp.next();
        }

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

        return profile;
    }

@@ -286,8 +289,8 @@ public class Profile implements Parcelable {
        // Set stream volumes
        AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
        for (StreamSettings sd : streams.values()) {
            if (sd.override) {
                am.setStreamVolume(sd.streamId, sd.value, 0);
            if (sd.isOverride()) {
                am.setStreamVolume(sd.getStreamId(), sd.getValue(), 0);
            }
        }
    }
@@ -299,7 +302,8 @@ public class Profile implements Parcelable {

    /** @hide */
    public void setStreamSettings(StreamSettings descriptor){
        streams.put(descriptor.streamId, descriptor);
        streams.put(descriptor.getStreamId(), descriptor);
        mDirty = true;
    }

    /** @hide */
+100 −49
Original line number Diff line number Diff line
@@ -24,27 +24,31 @@ import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.ParcelUuid;
import android.text.TextUtils;
import android.util.Log;

import java.io.IOException;
import java.util.UUID;

public class ProfileGroup implements Parcelable {
    private static final String TAG = "ProfileGroup";

    private String mName;
    private int mNameResId;

    private Uri mSoundOverride = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    private UUID mUuid;

    private Uri mSoundOverride = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    private Uri mRingerOverride = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);

    private Mode mSoundMode = Mode.DEFAULT;

    private Mode mRingerMode = Mode.DEFAULT;

    private Mode mVibrateMode = Mode.DEFAULT;

    private Mode mLightsMode = Mode.DEFAULT;

    private boolean mDefaultGroup = false;
    private boolean mDirty;

    /** @hide */
    public static final Parcelable.Creator<ProfileGroup> CREATOR = new Parcelable.Creator<ProfileGroup>() {
@@ -59,14 +63,15 @@ public class ProfileGroup implements Parcelable {
    };

    /** @hide */
    public ProfileGroup(String name) {
        this(name, false);
    public ProfileGroup(UUID uuid, boolean defaultGroup) {
        this(null, uuid, defaultGroup);
    }

    /** @hide */
    ProfileGroup(String name, boolean defaultGroup) {
    private ProfileGroup(String name, UUID uuid, boolean defaultGroup) {
        mName = name;
        mUuid = (uuid != null) ? uuid : UUID.randomUUID();
        mDefaultGroup = defaultGroup;
        mDirty = uuid == null;
    }

    /** @hide */
@@ -74,17 +79,40 @@ public class ProfileGroup implements Parcelable {
        readFromParcel(in);
    }

    public String getName() {
        return mName;
    /** @hide */
    public boolean matches(NotificationGroup group) {
        if (mUuid.equals(group.getUuid())) {
            return true;
        }

        /* second try: match name for backwards compat */
        if (mName != null && mName.equals(group.getName())) {
            mName = null;
            mUuid = group.getUuid();
            mDirty = true;
            return true;
        }

        return false;
    }

    public UUID getUuid() {
        return mUuid;
    }

    public boolean isDefaultGroup() {
        return mDefaultGroup;
    }

    /** @hide */
    public boolean isDirty() {
        return mDirty;
    }

    /** @hide */
    public void setSoundOverride(Uri sound) {
        this.mSoundOverride = sound;
        mSoundOverride = sound;
        mDirty = true;
    }

    public Uri getSoundOverride() {
@@ -93,7 +121,8 @@ public class ProfileGroup implements Parcelable {

    /** @hide */
    public void setRingerOverride(Uri ringer) {
        this.mRingerOverride = ringer;
        mRingerOverride = ringer;
        mDirty = true;
    }

    public Uri getRingerOverride() {
@@ -102,7 +131,8 @@ public class ProfileGroup implements Parcelable {

    /** @hide */
    public void setSoundMode(Mode soundMode) {
        this.mSoundMode = soundMode;
        mSoundMode = soundMode;
        mDirty = true;
    }

    public Mode getSoundMode() {
@@ -111,7 +141,8 @@ public class ProfileGroup implements Parcelable {

    /** @hide */
    public void setRingerMode(Mode ringerMode) {
        this.mRingerMode = ringerMode;
        mRingerMode = ringerMode;
        mDirty = true;
    }

    public Mode getRingerMode() {
@@ -120,7 +151,8 @@ public class ProfileGroup implements Parcelable {

    /** @hide */
    public void setVibrateMode(Mode vibrateMode) {
        this.mVibrateMode = vibrateMode;
        mVibrateMode = vibrateMode;
        mDirty = true;
    }

    public Mode getVibrateMode() {
@@ -129,7 +161,8 @@ public class ProfileGroup implements Parcelable {

    /** @hide */
    public void setLightsMode(Mode lightsMode) {
        this.mLightsMode = lightsMode;
        mLightsMode = lightsMode;
        mDirty = true;
    }

    public Mode getLightsMode() {
@@ -139,7 +172,7 @@ public class ProfileGroup implements Parcelable {
    // TODO : add support for LEDs / screen etc.

    /** @hide */
    Notification processNotification(Notification notification) {
    public Notification processNotification(Notification notification) {

        switch (mSoundMode) {
            case OVERRIDE:
@@ -196,7 +229,9 @@ public class ProfileGroup implements Parcelable {
    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(mName);
        dest.writeValue(mDefaultGroup);
        new ParcelUuid(mUuid).writeToParcel(dest, 0);
        dest.writeInt(mDefaultGroup ? 1 : 0);
        dest.writeInt(mDirty ? 1 : 0);
        dest.writeParcelable(mSoundOverride, flags);
        dest.writeParcelable(mRingerOverride, flags);

@@ -209,7 +244,9 @@ public class ProfileGroup implements Parcelable {
    /** @hide */
    public void readFromParcel(Parcel in) {
        mName = in.readString();
        mDefaultGroup = (Boolean)in.readValue(null);
        mUuid = ParcelUuid.CREATOR.createFromParcel(in).getUuid();
        mDefaultGroup = in.readInt() != 0;
        mDirty = in.readInt() != 0;
        mSoundOverride = in.readParcelable(null);
        mRingerOverride = in.readParcelable(null);

@@ -224,43 +261,54 @@ public class ProfileGroup implements Parcelable {
    }

    /** @hide */
    public String getXmlString() {
        StringBuilder builder = new StringBuilder();
        getXmlString(builder);
        return builder.toString();
    public void getXmlString(StringBuilder builder, Context context) {
        builder.append("<profileGroup uuid=\"");
        builder.append(TextUtils.htmlEncode(mUuid.toString()));
        if (mName != null) {
            builder.append("\" name=\"");
            builder.append(mName);
        }
        builder.append("\" default=\"");
        builder.append(isDefaultGroup());
        builder.append("\">\n<sound>");
        builder.append(TextUtils.htmlEncode(mSoundOverride.toString()));
        builder.append("</sound>\n<ringer>");
        builder.append(TextUtils.htmlEncode(mRingerOverride.toString()));
        builder.append("</ringer>\n<soundMode>");
        builder.append(mSoundMode);
        builder.append("</soundMode>\n<ringerMode>");
        builder.append(mRingerMode);
        builder.append("</ringerMode>\n<vibrateMode>");
        builder.append(mVibrateMode);
        builder.append("</vibrateMode>\n<lightsMode>");
        builder.append(mLightsMode);
        builder.append("</lightsMode>\n</profileGroup>\n");
        mDirty = false;
    }

    /** @hide */
    public void getXmlString(StringBuilder builder) {
        builder.append("<profileGroup name=\"" + TextUtils.htmlEncode(getName()) + "\" default=\""
                + isDefaultGroup() + "\">\n");
        builder.append("<sound>" + TextUtils.htmlEncode(mSoundOverride.toString()) + "</sound>\n");
        builder.append("<ringer>" + TextUtils.htmlEncode(mRingerOverride.toString())
                + "</ringer>\n");
        builder.append("<soundMode>" + mSoundMode + "</soundMode>\n");
        builder.append("<ringerMode>" + mRingerMode + "</ringerMode>\n");
        builder.append("<vibrateMode>" + mVibrateMode + "</vibrateMode>\n");
        builder.append("<lightsMode>" + mLightsMode + "</lightsMode>\n");
        builder.append("</profileGroup>\n");
    }
    public static ProfileGroup fromXml(XmlPullParser xpp, Context context)
            throws XmlPullParserException, IOException {
        String name = xpp.getAttributeValue(null, "name");
        UUID uuid = null;
        String value = xpp.getAttributeValue(null, "uuid");

    /** @hide */
    public static ProfileGroup fromXml(XmlPullParser xpp) throws XmlPullParserException,
            IOException {
        return fromXml(xpp, null);
        if (value != null) {
            try {
                uuid = UUID.fromString(value);
            } catch (IllegalArgumentException e) {
                Log.w(TAG, "UUID not recognized for " + name + ", using new one.");
            }
        }

    /** @hide */
    public static ProfileGroup fromXml(XmlPullParser xpp, Context context) throws XmlPullParserException,
            IOException {
        String defaultGroup = xpp.getAttributeValue(null, "default");
        defaultGroup = defaultGroup == null ? "false" : defaultGroup;
        String attr = Profile.getAttrResString(xpp, context);
        ProfileGroup profileGroup = new ProfileGroup(attr, defaultGroup.equals("true"));
        value = xpp.getAttributeValue(null, "default");
        boolean defaultGroup = TextUtils.equals(value, "true");

        ProfileGroup profileGroup = new ProfileGroup(name, uuid, defaultGroup);
        int event = xpp.next();
        while (event != XmlPullParser.END_TAG || !xpp.getName().equals("profileGroup")) {
            if (event == XmlPullParser.START_TAG) {
                String name = xpp.getName();
                name = xpp.getName();
                if (name.equals("sound")) {
                    profileGroup.setSoundOverride(Uri.parse(xpp.nextText()));
                } else if (name.equals("ringer")) {
@@ -277,7 +325,10 @@ public class ProfileGroup implements Parcelable {
            }
            event = xpp.next();
        }

        /* we just loaded from XML, no need to save */
        profileGroup.mDirty = false;

        return profileGroup;
    }

}
+38 −29

File changed.

Preview size limit exceeded, changes collapsed.

Loading