Loading core/java/android/app/Profile.java +52 −11 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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) { Loading Loading @@ -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 */ Loading @@ -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() { Loading @@ -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; } Loading @@ -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"); } Loading @@ -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(); Loading @@ -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(); } } core/java/android/app/StreamSettings.java 0 → 100644 +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(); } } services/java/com/android/server/ProfileManagerService.java +4 −3 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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."); } Loading Loading @@ -106,7 +107,7 @@ public class ProfileManagerService extends IProfileManager.Stub { @Override public Profile getActiveProfile() throws RemoteException { return mProfiles.get(mActiveProfile); return mActiveProfile; } @Override Loading Loading
core/java/android/app/Profile.java +52 −11 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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) { Loading Loading @@ -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 */ Loading @@ -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() { Loading @@ -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; } Loading @@ -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"); } Loading @@ -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(); Loading @@ -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(); } }
core/java/android/app/StreamSettings.java 0 → 100644 +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(); } }
services/java/com/android/server/ProfileManagerService.java +4 −3 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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."); } Loading Loading @@ -106,7 +107,7 @@ public class ProfileManagerService extends IProfileManager.Stub { @Override public Profile getActiveProfile() throws RemoteException { return mProfiles.get(mActiveProfile); return mActiveProfile; } @Override Loading