Skip to content

Commit 92933b0

Browse files
gsarricacodenamedroid
authored andcommitted
Adds LTE toggle button to powerwidget. Toggles between NT_MODE_GLOBAL
and NT_MODE_CDMA. Change-Id: Ib98bf8409e6a1481f3196ccd303689e97afd3646
1 parent be0d0c8 commit 92933b0

File tree

11 files changed

+108
-0
lines changed

11 files changed

+108
-0
lines changed

core/java/android/provider/Settings.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2090,6 +2090,13 @@ public static void setShowGTalkServiceStatus(ContentResolver cr, boolean flag) {
20902090
*/
20912091
public static final String EXPANDED_NETWORK_MODE = "expanded_network_mode";
20922092

2093+
/**
2094+
* Notification Power Widget - Custom LTE Toggle
2095+
* 1 - lte on, 0 - lte off
2096+
* @hide
2097+
*/
2098+
public static final String LTE_MODE = "lte_mode";
2099+
20932100
/**
20942101
* Notification Power Widget - Custom Screen Timeout
20952102
* @hide
331 Bytes
Loading
334 Bytes
Loading
460 Bytes
Loading
536 Bytes
Loading
1.05 KB
Loading
1.05 KB
Loading
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
package com.android.systemui.statusbar.powerwidget;
2+
3+
import android.content.ContentResolver;
4+
import android.content.Context;
5+
import android.content.Intent;
6+
import android.net.Uri;
7+
import android.provider.Settings;
8+
import android.provider.Settings.SettingNotFoundException;
9+
import android.telephony.TelephonyManager;
10+
11+
import com.android.internal.telephony.Phone;
12+
import com.android.systemui.R;
13+
14+
import java.util.ArrayList;
15+
import java.util.List;
16+
17+
public class LTEButton extends PowerButton{
18+
19+
private static final List<Uri> OBSERVED_URIS = new ArrayList<Uri>();
20+
static {
21+
OBSERVED_URIS.add(Settings.System.getUriFor(Settings.System.LTE_MODE));
22+
}
23+
24+
public LTEButton() { mType = BUTTON_LTE; }
25+
26+
@Override
27+
protected void updateState() {
28+
ContentResolver resolver = mView.getContext().getContentResolver();
29+
int network = getCurrentPreferredNetworkMode(mView.getContext());
30+
switch(network) {
31+
case Phone.NT_MODE_GLOBAL:
32+
mIcon = R.drawable.stat_lte_on;
33+
mState = STATE_ENABLED;
34+
Settings.System.putInt(resolver, Settings.System.LTE_MODE, 1);
35+
break;
36+
case Phone.NT_MODE_CDMA:
37+
mIcon = R.drawable.stat_lte_off;
38+
mState = STATE_DISABLED;
39+
Settings.System.putInt(resolver, Settings.System.LTE_MODE, 0);
40+
break;
41+
}
42+
}
43+
44+
@Override
45+
protected void toggleState() {
46+
TelephonyManager tm = (TelephonyManager) mView.getContext()
47+
.getSystemService(Context.TELEPHONY_SERVICE);
48+
int network = getCurrentPreferredNetworkMode(mView.getContext());
49+
ContentResolver resolver = mView.getContext().getContentResolver();
50+
if (Phone.NT_MODE_GLOBAL == network) {
51+
tm.toggleLTE(false);
52+
mState = STATE_DISABLED;
53+
Settings.System.putInt(resolver, Settings.System.LTE_MODE, 0);
54+
} else if (Phone.NT_MODE_CDMA == network) {
55+
tm.toggleLTE(true);
56+
mState = STATE_ENABLED;
57+
Settings.System.putInt(resolver, Settings.System.LTE_MODE, 1);
58+
}
59+
}
60+
61+
@Override
62+
protected boolean handleLongClick() {
63+
Intent intent = new Intent(Intent.ACTION_MAIN);
64+
intent.setClassName("com.android.phone", "com.android.phone.Settings");
65+
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
66+
mView.getContext().startActivity(intent);
67+
return true;
68+
}
69+
70+
@Override
71+
protected List<Uri> getObservedUris() {
72+
return OBSERVED_URIS;
73+
}
74+
75+
private static int getCurrentPreferredNetworkMode(Context context) {
76+
int network = -1;
77+
try {
78+
network = Settings.Secure.getInt(context.getContentResolver(),
79+
Settings.Secure.PREFERRED_NETWORK_MODE);
80+
} catch (SettingNotFoundException e) {
81+
e.printStackTrace();
82+
}
83+
return network;
84+
}
85+
}

packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/PowerButton.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public abstract class PowerButton {
5151
public static final String BUTTON_MEDIA_PREVIOUS = "toggleMediaPrevious";
5252
public static final String BUTTON_MEDIA_NEXT = "toggleMediaNext";
5353
public static final String BUTTON_WIMAX = "toggleWimax";
54+
public static final String BUTTON_LTE = "toggleLte";
5455
public static final String BUTTON_UNKNOWN = "unknown";
5556

5657
private static final Mode MASK_MODE = Mode.SCREEN;
@@ -76,6 +77,7 @@ public abstract class PowerButton {
7677
BUTTONS.put(BUTTON_MEDIA_PLAY_PAUSE, MediaPlayPauseButton.class);
7778
BUTTONS.put(BUTTON_MEDIA_PREVIOUS, MediaPreviousButton.class);
7879
BUTTONS.put(BUTTON_MEDIA_NEXT, MediaNextButton.class);
80+
BUTTONS.put(BUTTON_LTE, LTEButton.class);
7981
/* BUTTONS.put(BUTTON_WIMAX, WimaxButton.class); */
8082
}
8183
// this is a list of our currently loaded buttons

telephony/java/android/telephony/TelephonyManager.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,14 @@ public int getNetworkType() {
470470
}
471471
}
472472

473+
public void toggleLTE(boolean on) {
474+
try {
475+
getITelephony().toggleLTE(on);
476+
} catch (RemoteException e) {
477+
//Silently fail
478+
}
479+
}
480+
473481
/** Unknown network class. {@hide} */
474482
public static final int NETWORK_CLASS_UNKNOWN = 0;
475483
/** Class of broadly defined "2G" networks. {@hide} */

0 commit comments

Comments
 (0)