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

Commit 0587313b authored by Felix Bechstein's avatar Felix Bechstein
Browse files

Add multiple UUID tags to profile (1/2 Frameworks)

Adding multiple UUID tags to a profile allows us to share a single NFC tag across multiple devices.

NFC tag writing works as before.
NFC tag reading is expanded to check the UUID and the UUID tags of a profile.

When reading unknown profiles, the user is asked to attach the tag to an exising profile.
The NFC tag itself stays untouched.

Patch Set 1:
* initial commit

Patch Set 2:
* rebase
* remove getProfileByTag() and use getProfile()
* rename tag to secondary uuid

Patch Set 3:
* rename "tag" leftovers

Change-Id: I284f8a823ced48d3b88ce3b3a1e83152cb145d2d
parent d470daff
Loading
Loading
Loading
Loading
+66 −0
Original line number Diff line number Diff line
@@ -30,8 +30,10 @@ import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

@@ -46,6 +48,8 @@ public final class Profile implements Parcelable, Comparable {

    private UUID mUuid;

    private ArrayList<UUID> mSecondaryUuids = new ArrayList<UUID>();

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

    private ProfileGroup mDefaultGroup;
@@ -172,6 +176,11 @@ public final class Profile implements Parcelable, Comparable {
        dest.writeString(mName);
        dest.writeInt(mNameResId);
        new ParcelUuid(mUuid).writeToParcel(dest, 0);
        ArrayList<ParcelUuid> uuids = new ArrayList<ParcelUuid>(mSecondaryUuids.size());
        for (UUID u : mSecondaryUuids) {
            uuids.add(new ParcelUuid(u));
        }
        dest.writeParcelableArray(uuids.toArray(new Parcelable[uuids.size()]), flags);
        dest.writeInt(mStatusBarIndicator ? 1 : 0);
        dest.writeInt(mProfileType);
        dest.writeInt(mDirty ? 1 : 0);
@@ -191,6 +200,10 @@ public final class Profile implements Parcelable, Comparable {
        mName = in.readString();
        mNameResId = in.readInt();
        mUuid = ParcelUuid.CREATOR.createFromParcel(in).getUuid();
        for (Parcelable parcel : in.readParcelableArray(null)) {
            ParcelUuid u = (ParcelUuid) parcel;
            mSecondaryUuids.add(u.getUuid());
        }
        mStatusBarIndicator = (in.readInt() == 1);
        mProfileType = in.readInt();
        mDirty = (in.readInt() == 1);
@@ -243,6 +256,25 @@ public final class Profile implements Parcelable, Comparable {
        return this.mUuid;
    }

    public UUID[] getSecondaryUuids() {
        return mSecondaryUuids.toArray(new UUID[mSecondaryUuids.size()]);
    }

    public void setSecondaryUuids(List<UUID> uuids) {
        mSecondaryUuids.clear();
        if (uuids != null) {
            mSecondaryUuids.addAll(uuids);
            mDirty = true;
        }
    }

    public void addSecondaryUuid(UUID uuid) {
        if (uuid != null) {
            mSecondaryUuids.add(uuid);
            mDirty = true;
        }
    }

    public boolean getStatusBarIndicator() {
        return mStatusBarIndicator;
    }
@@ -329,6 +361,14 @@ public final class Profile implements Parcelable, Comparable {
        builder.append(TextUtils.htmlEncode(getUuid().toString()));
        builder.append("\">\n");

        builder.append("<uuids>");
        for (UUID u : mSecondaryUuids) {
            builder.append("<uuid>");
            builder.append(TextUtils.htmlEncode(u.toString()));
            builder.append("</uuid>");
        }
        builder.append("</uuids>\n");

        builder.append("<profiletype>");
        builder.append(getProfileType() == TOGGLE_TYPE ? "toggle" : "conditional");
        builder.append("</profiletype>\n");
@@ -361,6 +401,29 @@ public final class Profile implements Parcelable, Comparable {
        mDirty = false;
    }

    private static List<UUID> readSecondaryUuidsFromXml(XmlPullParser xpp, Context context)
            throws XmlPullParserException,
            IOException {
        ArrayList<UUID> uuids = new ArrayList<UUID>();
        int event = xpp.next();
        while (event != XmlPullParser.END_TAG || !xpp.getName().equals("uuids")) {
            if (event == XmlPullParser.START_TAG) {
                String name = xpp.getName();
                if (name.equals("uuid")) {
                    try {
                        uuids.add(UUID.fromString(xpp.nextText()));
                    } catch (NullPointerException e) {
                        Log.w(TAG, "Null Pointer - invalid UUID");
                    } catch (IllegalArgumentException e) {
                        Log.w(TAG, "UUID not recognized");
                    }
                }
            }
            event = xpp.next();
        }
        return uuids;
    }

    /** @hide */
    public static Profile fromXml(XmlPullParser xpp, Context context)
            throws XmlPullParserException, IOException {
@@ -403,6 +466,9 @@ public final class Profile implements Parcelable, Comparable {
        while (event != XmlPullParser.END_TAG) {
            if (event == XmlPullParser.START_TAG) {
                String name = xpp.getName();
                if (name.equals("uuids")) {
                    profile.setSecondaryUuids(readSecondaryUuidsFromXml(xpp, context));
                }
                if (name.equals("statusbar")) {
                    profile.setStatusBarIndicator(xpp.nextText().equals("yes"));
                }
+15 −2
Original line number Diff line number Diff line
@@ -276,12 +276,25 @@ public class ProfileManagerService extends IProfileManager.Stub {
    @Override
    public Profile getProfile(ParcelUuid profileParcelUuid) {
        UUID profileUuid = profileParcelUuid.getUuid();
        return mProfiles.get(profileUuid);
        return getProfile(profileUuid);
    }

    public Profile getProfile(UUID profileUuid) {
        // use primary UUID first
        if (mProfiles.containsKey(profileUuid)) {
            return mProfiles.get(profileUuid);
        }
        // if no match was found: try secondary UUID
        for (Profile p : mProfiles.values()) {
            for (UUID uuid : p.getSecondaryUuids()) {
                if (profileUuid.equals(uuid)) {
                    return p;
                }
            }
        }
        // nothing found
        return null;
    }

    @Override
    public Profile[] getProfiles() throws RemoteException {