cmsdk: send connection value when changing network modes

Ref: CYNGNOS-1463

Change-Id: I2ef1feb0d1f135f360dc553e3426bdd7610087bd
Signed-off-by: Roman Birg <roman@cyngn.com>
This commit is contained in:
Roman Birg 2016-02-10 18:59:16 -08:00 committed by Gerrit Code Review
parent 80f56517fd
commit c46e0ffb69
4 changed files with 141 additions and 26 deletions

View File

@ -219,6 +219,7 @@ package cyanogenmod.app {
method public int describeContents(); method public int describeContents();
method public cyanogenmod.profiles.AirplaneModeSettings getAirplaneMode(); method public cyanogenmod.profiles.AirplaneModeSettings getAirplaneMode();
method public cyanogenmod.profiles.BrightnessSettings getBrightness(); method public cyanogenmod.profiles.BrightnessSettings getBrightness();
method public cyanogenmod.profiles.ConnectionSettings getConnectionSettingWithSubId(int);
method public java.util.Collection<cyanogenmod.profiles.ConnectionSettings> getConnectionSettings(); method public java.util.Collection<cyanogenmod.profiles.ConnectionSettings> getConnectionSettings();
method public int getDozeMode(); method public int getDozeMode();
method public int getExpandedDesktopMode(); method public int getExpandedDesktopMode();
@ -673,9 +674,11 @@ package cyanogenmod.profiles {
ctor public ConnectionSettings(int, int, boolean); ctor public ConnectionSettings(int, int, boolean);
method public int describeContents(); method public int describeContents();
method public int getConnectionId(); method public int getConnectionId();
method public int getSubId();
method public int getValue(); method public int getValue();
method public boolean isOverride(); method public boolean isOverride();
method public void setOverride(boolean); method public void setOverride(boolean);
method public void setSubId(int);
method public void setValue(int); method public void setValue(int);
method public void writeToParcel(android.os.Parcel, int); method public void writeToParcel(android.os.Parcel, int);
field public static final int PROFILE_CONNECTION_2G3G4G = 9; // 0x9 field public static final int PROFILE_CONNECTION_2G3G4G = 9; // 0x9

View File

@ -41,6 +41,7 @@ import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -82,6 +83,8 @@ public final class Profile implements Parcelable, Comparable {
private Map<Integer, ConnectionSettings> connections = new HashMap<Integer, ConnectionSettings>(); private Map<Integer, ConnectionSettings> connections = new HashMap<Integer, ConnectionSettings>();
private Map<Integer, ConnectionSettings> networkConnectionSubIds = new HashMap<>();
private RingModeSettings mRingMode = new RingModeSettings(); private RingModeSettings mRingMode = new RingModeSettings();
private AirplaneModeSettings mAirplaneMode = new AirplaneModeSettings(); private AirplaneModeSettings mAirplaneMode = new AirplaneModeSettings();
@ -638,6 +641,15 @@ public final class Profile implements Parcelable, Comparable {
// === ELDERBERRY === // === ELDERBERRY ===
dest.writeInt(mNotificationLightMode); dest.writeInt(mNotificationLightMode);
if (networkConnectionSubIds != null && !networkConnectionSubIds.isEmpty()) {
dest.writeInt(1);
dest.writeTypedArray(networkConnectionSubIds.values().toArray(
new ConnectionSettings[0]), flags);
} else {
dest.writeInt(0);
}
// Go back and write size // Go back and write size
int parcelableSize = dest.dataPosition() - startPosition; int parcelableSize = dest.dataPosition() - startPosition;
dest.setDataPosition(sizePosition); dest.setDataPosition(sizePosition);
@ -714,6 +726,13 @@ public final class Profile implements Parcelable, Comparable {
} }
if (parcelableVersion >= Build.CM_VERSION_CODES.ELDERBERRY) { if (parcelableVersion >= Build.CM_VERSION_CODES.ELDERBERRY) {
mNotificationLightMode = in.readInt(); mNotificationLightMode = in.readInt();
if (in.readInt() != 0) {
for (ConnectionSettings connection :
in.createTypedArray(ConnectionSettings.CREATOR)) {
// elderberry can do msim connections
networkConnectionSubIds.put(connection.getSubId(), connection);
}
}
} }
in.setDataPosition(startPosition + parcelableSize); in.setDataPosition(startPosition + parcelableSize);
@ -979,6 +998,11 @@ public final class Profile implements Parcelable, Comparable {
return true; return true;
} }
} }
for (ConnectionSettings conn : networkConnectionSubIds.values()) {
if (conn.isDirty()) {
return true;
}
}
if (mRingMode.isDirty()) { if (mRingMode.isDirty()) {
return true; return true;
} }
@ -1054,6 +1078,9 @@ public final class Profile implements Parcelable, Comparable {
for (ConnectionSettings cs : connections.values()) { for (ConnectionSettings cs : connections.values()) {
cs.getXmlString(builder, context); cs.getXmlString(builder, context);
} }
for (ConnectionSettings cs : networkConnectionSubIds.values()) {
cs.getXmlString(builder, context);
}
if (!mTriggers.isEmpty()) { if (!mTriggers.isEmpty()) {
builder.append("<triggers>\n"); builder.append("<triggers>\n");
for (ProfileTrigger trigger : mTriggers.values()) { for (ProfileTrigger trigger : mTriggers.values()) {
@ -1200,7 +1227,12 @@ public final class Profile implements Parcelable, Comparable {
} }
if (name.equals("connectionDescriptor")) { if (name.equals("connectionDescriptor")) {
ConnectionSettings cs = ConnectionSettings.fromXml(xpp, context); ConnectionSettings cs = ConnectionSettings.fromXml(xpp, context);
profile.connections.put(cs.getConnectionId(), cs); if (Build.CM_VERSION.SDK_INT >= Build.CM_VERSION_CODES.ELDERBERRY
&& cs.getConnectionId() == ConnectionSettings.PROFILE_CONNECTION_2G3G4G) {
profile.networkConnectionSubIds.put(cs.getSubId(), cs);
} else {
profile.connections.put(cs.getConnectionId(), cs);
}
} }
if (name.equals("triggers")) { if (name.equals("triggers")) {
readTriggersFromXml(xpp, context, profile); readTriggersFromXml(xpp, context, profile);
@ -1232,6 +1264,12 @@ public final class Profile implements Parcelable, Comparable {
cs.processOverride(context); cs.processOverride(context);
} }
} }
for (ConnectionSettings cs : networkConnectionSubIds.values()) {
if (cs.isOverride()) {
cs.processOverride(context);
}
}
// Set ring mode // Set ring mode
mRingMode.processOverride(context); mRingMode.processOverride(context);
// Set airplane mode // Set airplane mode
@ -1302,15 +1340,37 @@ public final class Profile implements Parcelable, Comparable {
* @return {@link ConnectionSettings} * @return {@link ConnectionSettings}
*/ */
public ConnectionSettings getSettingsForConnection(int connectionId){ public ConnectionSettings getSettingsForConnection(int connectionId){
if (connectionId == ConnectionSettings.PROFILE_CONNECTION_2G3G4G) {
if (networkConnectionSubIds.size() > 1) {
throw new UnsupportedOperationException("Use getConnectionSettingsWithSubId for MSIM devices!");
} else {
return networkConnectionSubIds.values().iterator().next();
}
}
return connections.get(connectionId); return connections.get(connectionId);
} }
/**
* Get the settings for a {@link ConnectionSettings#PROFILE_CONNECTION_2G3G4G} by sub id.
*
* @param subId the sub id to lookup. Can be {@link android.telephony.SubscriptionManager#INVALID_SUBSCRIPTION_ID}
* @return {@link ConnectionSettings}
*/
public ConnectionSettings getConnectionSettingWithSubId(int subId) {
return networkConnectionSubIds.get(subId);
}
/** /**
* Set the {@link ConnectionSettings} for the {@link Profile} * Set the {@link ConnectionSettings} for the {@link Profile}
* @param descriptor * @param descriptor
*/ */
public void setConnectionSettings(ConnectionSettings descriptor){ public void setConnectionSettings(ConnectionSettings descriptor) {
connections.put(descriptor.getConnectionId(), descriptor); if (descriptor.getConnectionId() == ConnectionSettings.PROFILE_CONNECTION_2G3G4G) {
networkConnectionSubIds.put(descriptor.getSubId(), descriptor);
} else {
connections.put(descriptor.getConnectionId(), descriptor);
}
mDirty = true;
} }
/** /**
@ -1318,6 +1378,9 @@ public final class Profile implements Parcelable, Comparable {
* @return {@link Collection<ConnectionSettings>} * @return {@link Collection<ConnectionSettings>}
*/ */
public Collection<ConnectionSettings> getConnectionSettings(){ public Collection<ConnectionSettings> getConnectionSettings(){
return connections.values(); List<ConnectionSettings> combinedList = new ArrayList<>();
combinedList.addAll(connections.values());
combinedList.addAll(networkConnectionSubIds.values());
return combinedList;
} }
} }

View File

@ -58,6 +58,11 @@ public final class ConnectionSettings implements Parcelable {
private boolean mOverride; private boolean mOverride;
private boolean mDirty; private boolean mDirty;
/**
* For use with {@link #PROFILE_CONNECTION_2G3G4G} to determine what subscription to control.
*/
private int mSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
/** /**
* The {@link #PROFILE_CONNECTION_MOBILEDATA} allows for enabling and disabling the mobile * The {@link #PROFILE_CONNECTION_MOBILEDATA} allows for enabling and disabling the mobile
* data connection. Boolean connection settings {@link BooleanState} * data connection. Boolean connection settings {@link BooleanState}
@ -116,6 +121,7 @@ public final class ConnectionSettings implements Parcelable {
private static final String ACTION_MODIFY_NETWORK_MODE = private static final String ACTION_MODIFY_NETWORK_MODE =
"com.android.internal.telephony.MODIFY_NETWORK_MODE"; "com.android.internal.telephony.MODIFY_NETWORK_MODE";
private static final String EXTRA_NETWORK_MODE = "networkMode"; private static final String EXTRA_NETWORK_MODE = "networkMode";
private static final String EXTRA_SUB_ID = "subId";
/** /**
* BooleanStates for specific {@link ConnectionSettings} * BooleanStates for specific {@link ConnectionSettings}
@ -210,6 +216,11 @@ public final class ConnectionSettings implements Parcelable {
mDirty = true; mDirty = true;
} }
public void setSubId(int subId) {
mSubId = subId;
mDirty = true;
}
/** /**
* Check whether or not the {@link ConnectionSettings} overrides user settings. * Check whether or not the {@link ConnectionSettings} overrides user settings.
* @return true if override * @return true if override
@ -218,6 +229,14 @@ public final class ConnectionSettings implements Parcelable {
return mOverride; return mOverride;
} }
/**
* Get the subscription id which this {@link ConnectionSettings} should apply to.
* @return
*/
public int getSubId() {
return mSubId;
}
/** @hide */ /** @hide */
public boolean isDirty() { public boolean isDirty() {
return mDirty; return mDirty;
@ -254,28 +273,35 @@ public final class ConnectionSettings implements Parcelable {
} }
break; break;
case PROFILE_CONNECTION_2G3G4G: case PROFILE_CONNECTION_2G3G4G:
Intent intent = new Intent(ACTION_MODIFY_NETWORK_MODE); if (Build.CM_VERSION.SDK_INT >= Build.CM_VERSION_CODES.ELDERBERRY) {
switch(getValue()) { Intent intent = new Intent(ACTION_MODIFY_NETWORK_MODE);
case CM_MODE_2G: intent.putExtra(EXTRA_NETWORK_MODE, getValue());
intent.putExtra(EXTRA_NETWORK_MODE, RILConstants.NETWORK_MODE_GSM_ONLY); intent.putExtra(EXTRA_SUB_ID, getSubId());
break; context.sendBroadcast(intent, "com.android.phone.CHANGE_NETWORK_MODE");
case CM_MODE_3G: } else {
intent.putExtra(EXTRA_NETWORK_MODE, RILConstants.NETWORK_MODE_WCDMA_ONLY); Intent intent = new Intent(ACTION_MODIFY_NETWORK_MODE);
break; switch(getValue()) {
case CM_MODE_4G: case CM_MODE_2G:
intent.putExtra(EXTRA_NETWORK_MODE, RILConstants.NETWORK_MODE_LTE_ONLY); intent.putExtra(EXTRA_NETWORK_MODE, RILConstants.NETWORK_MODE_GSM_ONLY);
break; break;
case CM_MODE_2G3G: case CM_MODE_3G:
intent.putExtra(EXTRA_NETWORK_MODE, RILConstants.NETWORK_MODE_WCDMA_PREF); intent.putExtra(EXTRA_NETWORK_MODE, RILConstants.NETWORK_MODE_WCDMA_ONLY);
break; break;
case CM_MODE_ALL: case CM_MODE_4G:
intent.putExtra(EXTRA_NETWORK_MODE, intent.putExtra(EXTRA_NETWORK_MODE, RILConstants.NETWORK_MODE_LTE_ONLY);
RILConstants.NETWORK_MODE_LTE_GSM_WCDMA); break;
break; case CM_MODE_2G3G:
default: intent.putExtra(EXTRA_NETWORK_MODE, RILConstants.NETWORK_MODE_WCDMA_PREF);
return; break;
case CM_MODE_ALL:
intent.putExtra(EXTRA_NETWORK_MODE,
RILConstants.NETWORK_MODE_LTE_GSM_WCDMA);
break;
default:
return;
}
context.sendBroadcast(intent);
} }
context.sendBroadcast(intent);
break; break;
case PROFILE_CONNECTION_BLUETOOTH: case PROFILE_CONNECTION_BLUETOOTH:
int btstate = bta.getState(); int btstate = bta.getState();
@ -363,6 +389,8 @@ public final class ConnectionSettings implements Parcelable {
connectionDescriptor.mValue = Integer.parseInt(xpp.nextText()); connectionDescriptor.mValue = Integer.parseInt(xpp.nextText());
} else if (name.equals("override")) { } else if (name.equals("override")) {
connectionDescriptor.mOverride = Boolean.parseBoolean(xpp.nextText()); connectionDescriptor.mOverride = Boolean.parseBoolean(xpp.nextText());
} else if (name.equals("subId")) {
connectionDescriptor.mSubId = Integer.parseInt(xpp.nextText());
} }
} else if (event == XmlPullParser.END_DOCUMENT) { } else if (event == XmlPullParser.END_DOCUMENT) {
throw new IOException("Premature end of file while parsing connection settings"); throw new IOException("Premature end of file while parsing connection settings");
@ -380,7 +408,14 @@ public final class ConnectionSettings implements Parcelable {
builder.append(mValue); builder.append(mValue);
builder.append("</value>\n<override>"); builder.append("</value>\n<override>");
builder.append(mOverride); builder.append(mOverride);
builder.append("</override>\n</connectionDescriptor>\n"); builder.append("</override>\n");
if (Build.CM_VERSION.SDK_INT >= Build.CM_VERSION_CODES.ELDERBERRY) {
if (mConnectionId == PROFILE_CONNECTION_2G3G4G
&& mSubId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
builder.append("<subId>").append(mSubId).append("</subId>\n");
}
}
builder.append("</connectionDescriptor>\n");
} }
@Override @Override
@ -407,6 +442,11 @@ public final class ConnectionSettings implements Parcelable {
dest.writeInt(mValue); dest.writeInt(mValue);
dest.writeInt(mDirty ? 1 : 0); dest.writeInt(mDirty ? 1 : 0);
// === ELDERBERRY ===
if (mConnectionId == PROFILE_CONNECTION_2G3G4G) {
dest.writeInt(mSubId);
}
// Go back and write size // Go back and write size
int parcelableSize = dest.dataPosition() - startPosition; int parcelableSize = dest.dataPosition() - startPosition;
dest.setDataPosition(sizePosition); dest.setDataPosition(sizePosition);
@ -432,6 +472,12 @@ public final class ConnectionSettings implements Parcelable {
mDirty = in.readInt() != 0; mDirty = in.readInt() != 0;
} }
if (parcelableVersion >= Build.CM_VERSION_CODES.ELDERBERRY) {
if (mConnectionId == PROFILE_CONNECTION_2G3G4G) {
mSubId = in.readInt();
}
}
in.setDataPosition(startPosition + parcelableSize); in.setDataPosition(startPosition + parcelableSize);
} }
} }

View File

@ -219,6 +219,7 @@ package cyanogenmod.app {
method public int describeContents(); method public int describeContents();
method public cyanogenmod.profiles.AirplaneModeSettings getAirplaneMode(); method public cyanogenmod.profiles.AirplaneModeSettings getAirplaneMode();
method public cyanogenmod.profiles.BrightnessSettings getBrightness(); method public cyanogenmod.profiles.BrightnessSettings getBrightness();
method public cyanogenmod.profiles.ConnectionSettings getConnectionSettingWithSubId(int);
method public java.util.Collection<cyanogenmod.profiles.ConnectionSettings> getConnectionSettings(); method public java.util.Collection<cyanogenmod.profiles.ConnectionSettings> getConnectionSettings();
method public int getDozeMode(); method public int getDozeMode();
method public int getExpandedDesktopMode(); method public int getExpandedDesktopMode();
@ -673,9 +674,11 @@ package cyanogenmod.profiles {
ctor public ConnectionSettings(int, int, boolean); ctor public ConnectionSettings(int, int, boolean);
method public int describeContents(); method public int describeContents();
method public int getConnectionId(); method public int getConnectionId();
method public int getSubId();
method public int getValue(); method public int getValue();
method public boolean isOverride(); method public boolean isOverride();
method public void setOverride(boolean); method public void setOverride(boolean);
method public void setSubId(int);
method public void setValue(int); method public void setValue(int);
method public void writeToParcel(android.os.Parcel, int); method public void writeToParcel(android.os.Parcel, int);
field public static final int PROFILE_CONNECTION_2G3G4G = 9; // 0x9 field public static final int PROFILE_CONNECTION_2G3G4G = 9; // 0x9