-
Notifications
You must be signed in to change notification settings - Fork 551
/
Copy pathTetheringEnabler.java
65 lines (53 loc) · 1.97 KB
/
TetheringEnabler.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package com.android.settings;
import android.content.Context;
import android.os.SystemProperties;
import android.os.SystemService;
import android.preference.CheckBoxPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.util.Log;
/**
* @author shade
*
* TODO: Actually check if tethering started/stopped
*
*/
public class TetheringEnabler implements OnPreferenceChangeListener {
private final Context mContext;
private final CheckBoxPreference mCheckBoxPref;
private static final String TETHER_ON = "tether_on";
private static final String TETHER_OFF = "tether_off";
private static final String TETHER_PROP = "tethering.enabled";
public TetheringEnabler(Context context, CheckBoxPreference pref) {
this.mContext = context;
this.mCheckBoxPref = pref;
}
/* (non-Javadoc)
* @see android.preference.Preference.OnPreferenceChangeListener#onPreferenceChange(android.preference.Preference, java.lang.Object)
*/
// @Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
final Boolean v = (Boolean)newValue;
setTetheringEnabled(v);
mCheckBoxPref.setSummary(v ? R.string.internet_tethering_summary_on : R.string.internet_tethering_summary_off);
return true;
}
private synchronized void setTetheringEnabled(boolean enabled) {
if (enabled) {
Log.i("tether", "Enabling tethering..");
SystemService.start(TETHER_ON);
} else {
Log.i("tether", "Disabling tethering..");
SystemService.start(TETHER_OFF);
}
}
public void pause() {
mCheckBoxPref.setOnPreferenceChangeListener(null);
}
public void resume() {
mCheckBoxPref.setOnPreferenceChangeListener(this);
final boolean isEnabled = SystemProperties.getBoolean(TETHER_PROP, false);
mCheckBoxPref.setChecked(isEnabled);
mCheckBoxPref.setSummary(isEnabled ? R.string.internet_tethering_summary_on : R.string.internet_tethering_summary_off);
}
}