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

Commit b0f34704 authored by Steve Kondik's avatar Steve Kondik Committed by Gerrit Code Review
Browse files

Merge "Added volume control to Notification Profiles." into gingerbread

parents 80176b87 e9c86a7e
Loading
Loading
Loading
Loading
+52 −11
Original line number Diff line number Diff line
@@ -21,12 +21,14 @@ 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;
import android.text.TextUtils;
import android.util.Log;

import java.io.IOException;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

@@ -40,6 +42,8 @@ public class Profile implements Parcelable {

    private static final String TAG = "Profile";

    private Map<Integer, StreamSettings> streams = new HashMap<Integer, StreamSettings>();

    /** @hide */
    public static final Parcelable.Creator<Profile> CREATOR = new Parcelable.Creator<Profile>() {
        public Profile createFromParcel(Parcel in) {
@@ -115,6 +119,8 @@ public class Profile implements Parcelable {
        dest.writeString(mName);
        dest.writeParcelableArray(
                profileGroups.values().toArray(new Parcelable[profileGroups.size()]), flags);
        dest.writeParcelableArray(
                streams.values().toArray(new Parcelable[streams.size()]), flags);
    }

    /** @hide */
@@ -127,6 +133,10 @@ public class Profile implements Parcelable {
                mDefaultGroup = grp;
            }
        }
        for (Parcelable parcel : in.readParcelableArray(null)) {
            StreamSettings stream = (StreamSettings) parcel;
            streams.put(stream.streamId, stream);
        }
    }

    public String getName() {
@@ -140,7 +150,8 @@ public class Profile implements Parcelable {

    /** @hide */
    public Notification processNotification(String groupName, Notification notification) {
        ProfileGroup profileGroupSettings = groupName == null ? mDefaultGroup : profileGroups.get(groupName);
        ProfileGroup profileGroupSettings = groupName == null ? mDefaultGroup : profileGroups
                .get(groupName);
        notification = profileGroupSettings.processNotification(notification);
        return notification;
    }
@@ -158,6 +169,9 @@ public class Profile implements Parcelable {
        for (ProfileGroup pGroup : profileGroups.values()) {
            pGroup.getXmlString(builder);
        }
        for (StreamSettings sd : streams.values()) {
            sd.getXmlString(builder);
        }
        builder.append("</profile>\n");
    }

@@ -179,12 +193,8 @@ public class Profile implements Parcelable {
    }

    /** @hide */
    public static Profile fromXml(XmlPullParser xpp) throws XmlPullParserException, IOException {
        return fromXml(xpp, null);
    }

    /** @hide */
    public static Profile fromXml(XmlPullParser xpp, Context context) throws XmlPullParserException, IOException {
    public static Profile fromXml(XmlPullParser xpp, Context context)
            throws XmlPullParserException, IOException {
        String attr = getAttrResString(xpp, context);
        Profile profile = new Profile(attr);
        int event = xpp.next();
@@ -195,10 +205,41 @@ public class Profile implements Parcelable {
                    ProfileGroup pg = ProfileGroup.fromXml(xpp, context);
                    profile.addProfileGroup(pg);
                }
                if (name.equals("streamDescriptor")) {
                    StreamSettings sd = StreamSettings.fromXml(xpp, context);
                    profile.streams.put(sd.streamId, sd);
                }
            }
            event = xpp.next();
        }
        return profile;
    }

    /** @hide */
    public void doSelect(Context context) {
        // 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);
            }
        }
    }

    /** @hide */
    public StreamSettings getSettingsForStream(int streamId){
        return streams.get(streamId);
    }

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

    /** @hide */
    public Collection<StreamSettings> getStreamSettings(){
        return streams.values();
    }


}
+122 −0
Original line number Diff line number Diff line

package android.app;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

import android.content.Context;
import android.os.Parcel;
import android.os.Parcelable;

import java.io.IOException;

/** @hide */
public class StreamSettings implements Parcelable{

    int streamId;

    int value;

    boolean override;
    
    /** @hide */
    public static final Parcelable.Creator<StreamSettings> CREATOR = new Parcelable.Creator<StreamSettings>() {
        public StreamSettings createFromParcel(Parcel in) {
            return new StreamSettings(in);
        }

        @Override
        public StreamSettings[] newArray(int size) {
            return new StreamSettings[size];
        }
    };


    public StreamSettings(Parcel parcel){
        readFromParcel(parcel);
    }

    public StreamSettings(int streamId) {
        this.streamId = streamId;
        this.value = 0;
        this.override = false;
    }

    public StreamSettings(int streamId, int value, boolean override) {
        this.streamId = streamId;
        this.value = value;
        this.override = override;
    }

    public int getStreamId() {
        return streamId;
    }

    public int getValue() {
        return value;
    }

    public void setValue(int value) {
        this.value = value;
    }

    public void setOverride(boolean override) {
        this.override = override;
    }

    public boolean isOverride() {
        return override;
    }

    /** @hide */
    public static StreamSettings fromXml(XmlPullParser xpp, Context context)
            throws XmlPullParserException, IOException {
        int event = xpp.next();
        StreamSettings streamDescriptor = new StreamSettings(0);
        while (event != XmlPullParser.END_TAG || !xpp.getName().equals("streamDescriptor")) {
            if (event == XmlPullParser.START_TAG) {
                String name = xpp.getName();
                if (name.equals("streamId")) {
                    streamDescriptor.streamId = Integer.parseInt(xpp.nextText());
                } else if (name.equals("value")) {
                    streamDescriptor.value = Integer.parseInt(xpp.nextText());
                } else if (name.equals("override")) {
                    streamDescriptor.override = Boolean.parseBoolean(xpp.nextText());
                }
            }
            event = xpp.next();
        }
        return streamDescriptor;
    }

    /** @hide */
    public void getXmlString(StringBuilder builder) {
        builder.append("<streamDescriptor>\n");
        builder.append("<streamId>" + streamId + "</streamId>\n");
        builder.append("<value>" + value + "</value>\n");
        builder.append("<override>" + override + "</override>\n");
        builder.append("</streamDescriptor>\n");
    }

    @Override
    public int describeContents() {
        return 0;
    }

    /** @hide */
    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(streamId);
        dest.writeValue(override);
        dest.writeInt(value);
    }

    /** @hide */
    public void readFromParcel(Parcel in) {
        streamId = in.readInt();
        override = (Boolean)in.readValue(null);
        value = in.readInt();
    }


}
+4 −3
Original line number Diff line number Diff line
@@ -46,7 +46,7 @@ public class ProfileManagerService extends IProfileManager.Stub {

    private Map<String, NotificationGroup> mGroups = new HashMap<String, NotificationGroup>();

    private String mActiveProfile;
    private Profile mActiveProfile;

    private Context mContext;

@@ -77,7 +77,8 @@ public class ProfileManagerService extends IProfileManager.Stub {
    public void setActiveProfile(String profileName) throws RemoteException {
        if(mProfiles.containsKey(profileName)){
            Log.d(TAG, "Set active profile to: " + profileName);
            mActiveProfile = profileName;
            mActiveProfile = getProfile(profileName);
            mActiveProfile.doSelect(mContext);
        }else{
            Log.e(TAG, "Cannot set active profile to: " + profileName + " - does not exist.");
        }
@@ -106,7 +107,7 @@ public class ProfileManagerService extends IProfileManager.Stub {

    @Override
    public Profile getActiveProfile() throws RemoteException {
        return mProfiles.get(mActiveProfile);
        return mActiveProfile;
    }

    @Override