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:
parent
80f56517fd
commit
c46e0ffb69
@ -219,6 +219,7 @@ package cyanogenmod.app {
|
||||
method public int describeContents();
|
||||
method public cyanogenmod.profiles.AirplaneModeSettings getAirplaneMode();
|
||||
method public cyanogenmod.profiles.BrightnessSettings getBrightness();
|
||||
method public cyanogenmod.profiles.ConnectionSettings getConnectionSettingWithSubId(int);
|
||||
method public java.util.Collection<cyanogenmod.profiles.ConnectionSettings> getConnectionSettings();
|
||||
method public int getDozeMode();
|
||||
method public int getExpandedDesktopMode();
|
||||
@ -673,9 +674,11 @@ package cyanogenmod.profiles {
|
||||
ctor public ConnectionSettings(int, int, boolean);
|
||||
method public int describeContents();
|
||||
method public int getConnectionId();
|
||||
method public int getSubId();
|
||||
method public int getValue();
|
||||
method public boolean isOverride();
|
||||
method public void setOverride(boolean);
|
||||
method public void setSubId(int);
|
||||
method public void setValue(int);
|
||||
method public void writeToParcel(android.os.Parcel, int);
|
||||
field public static final int PROFILE_CONNECTION_2G3G4G = 9; // 0x9
|
||||
|
@ -41,6 +41,7 @@ import org.xmlpull.v1.XmlPullParserException;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
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> networkConnectionSubIds = new HashMap<>();
|
||||
|
||||
private RingModeSettings mRingMode = new RingModeSettings();
|
||||
|
||||
private AirplaneModeSettings mAirplaneMode = new AirplaneModeSettings();
|
||||
@ -638,6 +641,15 @@ public final class Profile implements Parcelable, Comparable {
|
||||
// === ELDERBERRY ===
|
||||
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
|
||||
int parcelableSize = dest.dataPosition() - startPosition;
|
||||
dest.setDataPosition(sizePosition);
|
||||
@ -714,6 +726,13 @@ public final class Profile implements Parcelable, Comparable {
|
||||
}
|
||||
if (parcelableVersion >= Build.CM_VERSION_CODES.ELDERBERRY) {
|
||||
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);
|
||||
@ -979,6 +998,11 @@ public final class Profile implements Parcelable, Comparable {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
for (ConnectionSettings conn : networkConnectionSubIds.values()) {
|
||||
if (conn.isDirty()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (mRingMode.isDirty()) {
|
||||
return true;
|
||||
}
|
||||
@ -1054,6 +1078,9 @@ public final class Profile implements Parcelable, Comparable {
|
||||
for (ConnectionSettings cs : connections.values()) {
|
||||
cs.getXmlString(builder, context);
|
||||
}
|
||||
for (ConnectionSettings cs : networkConnectionSubIds.values()) {
|
||||
cs.getXmlString(builder, context);
|
||||
}
|
||||
if (!mTriggers.isEmpty()) {
|
||||
builder.append("<triggers>\n");
|
||||
for (ProfileTrigger trigger : mTriggers.values()) {
|
||||
@ -1200,7 +1227,12 @@ public final class Profile implements Parcelable, Comparable {
|
||||
}
|
||||
if (name.equals("connectionDescriptor")) {
|
||||
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")) {
|
||||
readTriggersFromXml(xpp, context, profile);
|
||||
@ -1232,6 +1264,12 @@ public final class Profile implements Parcelable, Comparable {
|
||||
cs.processOverride(context);
|
||||
}
|
||||
}
|
||||
for (ConnectionSettings cs : networkConnectionSubIds.values()) {
|
||||
if (cs.isOverride()) {
|
||||
cs.processOverride(context);
|
||||
}
|
||||
}
|
||||
|
||||
// Set ring mode
|
||||
mRingMode.processOverride(context);
|
||||
// Set airplane mode
|
||||
@ -1302,15 +1340,37 @@ public final class Profile implements Parcelable, Comparable {
|
||||
* @return {@link ConnectionSettings}
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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}
|
||||
* @param descriptor
|
||||
*/
|
||||
public void setConnectionSettings(ConnectionSettings descriptor){
|
||||
connections.put(descriptor.getConnectionId(), descriptor);
|
||||
public void setConnectionSettings(ConnectionSettings 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>}
|
||||
*/
|
||||
public Collection<ConnectionSettings> getConnectionSettings(){
|
||||
return connections.values();
|
||||
List<ConnectionSettings> combinedList = new ArrayList<>();
|
||||
combinedList.addAll(connections.values());
|
||||
combinedList.addAll(networkConnectionSubIds.values());
|
||||
return combinedList;
|
||||
}
|
||||
}
|
||||
|
@ -58,6 +58,11 @@ public final class ConnectionSettings implements Parcelable {
|
||||
private boolean mOverride;
|
||||
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
|
||||
* 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 =
|
||||
"com.android.internal.telephony.MODIFY_NETWORK_MODE";
|
||||
private static final String EXTRA_NETWORK_MODE = "networkMode";
|
||||
private static final String EXTRA_SUB_ID = "subId";
|
||||
|
||||
/**
|
||||
* BooleanStates for specific {@link ConnectionSettings}
|
||||
@ -210,6 +216,11 @@ public final class ConnectionSettings implements Parcelable {
|
||||
mDirty = true;
|
||||
}
|
||||
|
||||
public void setSubId(int subId) {
|
||||
mSubId = subId;
|
||||
mDirty = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether or not the {@link ConnectionSettings} overrides user settings.
|
||||
* @return true if override
|
||||
@ -218,6 +229,14 @@ public final class ConnectionSettings implements Parcelable {
|
||||
return mOverride;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the subscription id which this {@link ConnectionSettings} should apply to.
|
||||
* @return
|
||||
*/
|
||||
public int getSubId() {
|
||||
return mSubId;
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
public boolean isDirty() {
|
||||
return mDirty;
|
||||
@ -254,28 +273,35 @@ public final class ConnectionSettings implements Parcelable {
|
||||
}
|
||||
break;
|
||||
case PROFILE_CONNECTION_2G3G4G:
|
||||
Intent intent = new Intent(ACTION_MODIFY_NETWORK_MODE);
|
||||
switch(getValue()) {
|
||||
case CM_MODE_2G:
|
||||
intent.putExtra(EXTRA_NETWORK_MODE, RILConstants.NETWORK_MODE_GSM_ONLY);
|
||||
break;
|
||||
case CM_MODE_3G:
|
||||
intent.putExtra(EXTRA_NETWORK_MODE, RILConstants.NETWORK_MODE_WCDMA_ONLY);
|
||||
break;
|
||||
case CM_MODE_4G:
|
||||
intent.putExtra(EXTRA_NETWORK_MODE, RILConstants.NETWORK_MODE_LTE_ONLY);
|
||||
break;
|
||||
case CM_MODE_2G3G:
|
||||
intent.putExtra(EXTRA_NETWORK_MODE, RILConstants.NETWORK_MODE_WCDMA_PREF);
|
||||
break;
|
||||
case CM_MODE_ALL:
|
||||
intent.putExtra(EXTRA_NETWORK_MODE,
|
||||
RILConstants.NETWORK_MODE_LTE_GSM_WCDMA);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
if (Build.CM_VERSION.SDK_INT >= Build.CM_VERSION_CODES.ELDERBERRY) {
|
||||
Intent intent = new Intent(ACTION_MODIFY_NETWORK_MODE);
|
||||
intent.putExtra(EXTRA_NETWORK_MODE, getValue());
|
||||
intent.putExtra(EXTRA_SUB_ID, getSubId());
|
||||
context.sendBroadcast(intent, "com.android.phone.CHANGE_NETWORK_MODE");
|
||||
} else {
|
||||
Intent intent = new Intent(ACTION_MODIFY_NETWORK_MODE);
|
||||
switch(getValue()) {
|
||||
case CM_MODE_2G:
|
||||
intent.putExtra(EXTRA_NETWORK_MODE, RILConstants.NETWORK_MODE_GSM_ONLY);
|
||||
break;
|
||||
case CM_MODE_3G:
|
||||
intent.putExtra(EXTRA_NETWORK_MODE, RILConstants.NETWORK_MODE_WCDMA_ONLY);
|
||||
break;
|
||||
case CM_MODE_4G:
|
||||
intent.putExtra(EXTRA_NETWORK_MODE, RILConstants.NETWORK_MODE_LTE_ONLY);
|
||||
break;
|
||||
case CM_MODE_2G3G:
|
||||
intent.putExtra(EXTRA_NETWORK_MODE, RILConstants.NETWORK_MODE_WCDMA_PREF);
|
||||
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;
|
||||
case PROFILE_CONNECTION_BLUETOOTH:
|
||||
int btstate = bta.getState();
|
||||
@ -363,6 +389,8 @@ public final class ConnectionSettings implements Parcelable {
|
||||
connectionDescriptor.mValue = Integer.parseInt(xpp.nextText());
|
||||
} else if (name.equals("override")) {
|
||||
connectionDescriptor.mOverride = Boolean.parseBoolean(xpp.nextText());
|
||||
} else if (name.equals("subId")) {
|
||||
connectionDescriptor.mSubId = Integer.parseInt(xpp.nextText());
|
||||
}
|
||||
} else if (event == XmlPullParser.END_DOCUMENT) {
|
||||
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("</value>\n<override>");
|
||||
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
|
||||
@ -407,6 +442,11 @@ public final class ConnectionSettings implements Parcelable {
|
||||
dest.writeInt(mValue);
|
||||
dest.writeInt(mDirty ? 1 : 0);
|
||||
|
||||
// === ELDERBERRY ===
|
||||
if (mConnectionId == PROFILE_CONNECTION_2G3G4G) {
|
||||
dest.writeInt(mSubId);
|
||||
}
|
||||
|
||||
// Go back and write size
|
||||
int parcelableSize = dest.dataPosition() - startPosition;
|
||||
dest.setDataPosition(sizePosition);
|
||||
@ -432,6 +472,12 @@ public final class ConnectionSettings implements Parcelable {
|
||||
mDirty = in.readInt() != 0;
|
||||
}
|
||||
|
||||
if (parcelableVersion >= Build.CM_VERSION_CODES.ELDERBERRY) {
|
||||
if (mConnectionId == PROFILE_CONNECTION_2G3G4G) {
|
||||
mSubId = in.readInt();
|
||||
}
|
||||
}
|
||||
|
||||
in.setDataPosition(startPosition + parcelableSize);
|
||||
}
|
||||
}
|
||||
|
@ -219,6 +219,7 @@ package cyanogenmod.app {
|
||||
method public int describeContents();
|
||||
method public cyanogenmod.profiles.AirplaneModeSettings getAirplaneMode();
|
||||
method public cyanogenmod.profiles.BrightnessSettings getBrightness();
|
||||
method public cyanogenmod.profiles.ConnectionSettings getConnectionSettingWithSubId(int);
|
||||
method public java.util.Collection<cyanogenmod.profiles.ConnectionSettings> getConnectionSettings();
|
||||
method public int getDozeMode();
|
||||
method public int getExpandedDesktopMode();
|
||||
@ -673,9 +674,11 @@ package cyanogenmod.profiles {
|
||||
ctor public ConnectionSettings(int, int, boolean);
|
||||
method public int describeContents();
|
||||
method public int getConnectionId();
|
||||
method public int getSubId();
|
||||
method public int getValue();
|
||||
method public boolean isOverride();
|
||||
method public void setOverride(boolean);
|
||||
method public void setSubId(int);
|
||||
method public void setValue(int);
|
||||
method public void writeToParcel(android.os.Parcel, int);
|
||||
field public static final int PROFILE_CONNECTION_2G3G4G = 9; // 0x9
|
||||
|
Loading…
Reference in New Issue
Block a user