First pass at USB-only tether settings.

bug:2281900
This commit is contained in:
Robert Greenwalt
2010-01-26 10:22:37 -08:00
parent 9dee8a96c5
commit 3901edbdf5
5 changed files with 185 additions and 0 deletions

View File

@@ -168,6 +168,16 @@
</intent-filter>
</activity>
<activity android:name=".TetherSettings"
android:configChanges="orientation|keyboardHidden"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.VOICE_LAUNCH" />
</intent-filter>
</activity>
<activity android:name=".vpn.VpnSettings"
android:configChanges="orientation|keyboardHidden"
android:launchMode="singleTask">

View File

@@ -1256,6 +1256,27 @@
<!-- Main settings screen, Call settings summary for item to go into call settings -->
<string name="call_settings_summary">Set up voicemail, call forwarding, call waiting, caller ID</string>
<!-- Tethering controls, item title to go into the tethering settings -->
<string name="tether_settings_title">Tethering settings</string>
<!-- Tethering controls, the item summary for the user to go into the tethering settings -->
<string name="tether_settings_summary">Set up and manage tethering</string>
<!-- Title of the screen for adjusting tethering settings -->
<string name="tether_screen_title">Tethering settings</string>
<!-- Tethering notification toggle - controls whether a notification will appear when a tetherable connection becomes available -->
<string name="enable_tether_notice_checkbox">Notifications</string>
<!-- Tethering notification summary explains the notification toggle -->
<string name="enable_tether_notice_checkbox_summary">Show a notification when USB tethering is available</string>
<!-- USB Tethering options -->
<string name="usb_tethering_button_text">USB tethering</string>
<!-- USB available subtext - shown when USB is connected but not currently being tethered -->
<string name="usb_tethering_available_subtext">USB connected, select to tether</string>
<!-- USB tethered subtext - shown when USB is connected and being tethered -->
<string name="usb_tethering_active_subtext">Connected, select to disconnect</string>
<!-- USB unavailable subtext - shown when USB is not connected -->
<string name="usb_tethering_unavailable_subtext">USB not connected</string>
<!-- Wireless controls, item title to go into the network settings -->
<string name="network_settings_title">Mobile networks</string>
<!-- Wireless controls, the item summary for the user to go into the network settings -->

35
res/xml/tether_prefs.xml Normal file
View File

@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2008 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:title="@string/tether_screen_title">
<PreferenceScreen
android:key="usb_tether_settings"
android:title="@string/usb_tethering_button_text"
android:widgetLayout="@*android:layout/preference_dialog" >
<intent
android:action="android.intent.action.MAIN"
android:targetPackage="android"
android:targetClass="com.android.internal.app.TetherActivity" />
</PreferenceScreen>
<CheckBoxPreference
android:key="enable_tether_notice"
android:title="@string/enable_tether_notice_checkbox"
android:summary="@string/enable_tether_notice_checkbox_summary"/>
</PreferenceScreen>

View File

@@ -56,6 +56,15 @@
android:targetClass="com.android.settings.bluetooth.BluetoothSettings" />
</PreferenceScreen>
<PreferenceScreen
android:title="@string/tether_settings_title"
android:summary="@string/tether_settings_summary">
<intent
android:action="android.intent.action.MAIN"
android:targetPackage="com.android.settings"
android:targetClass="com.android.settings.TetherSettings" />
</PreferenceScreen>
<PreferenceScreen
android:key="vpn_settings"
android:title="@string/vpn_settings_title"

View File

@@ -0,0 +1,110 @@
/*
* Copyright (C) 2008 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings;
import android.os.Bundle;
import android.os.SystemProperties;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceScreen;
import android.preference.CheckBoxPreference;
import android.provider.Settings;
import android.util.Log;
/*
* Displays preferences for Tethering.
*/
public class TetherSettings extends PreferenceActivity {
private static final String ENABLE_TETHER_NOTICE = "enable_tether_notice";
private static final String USB_TETHER_SETTINGS = "usb_tether_settings";
private CheckBoxPreference mEnableTetherNotice;
private PreferenceScreen mUsbTether;
private BroadcastReceiver mTetherChangeReceiver;
@Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
addPreferencesFromResource(R.xml.tether_prefs);
mEnableTetherNotice = (CheckBoxPreference) findPreference(ENABLE_TETHER_NOTICE);
mUsbTether = (PreferenceScreen) findPreference(USB_TETHER_SETTINGS);
}
private class TetherChangeReceiver extends BroadcastReceiver {
public void onReceive(Context content, Intent intent) {
updateState(intent.getIntExtra(ConnectivityManager.EXTRA_AVAILABLE_TETHER_COUNT,0)>0,
intent.getIntExtra(ConnectivityManager.EXTRA_ACTIVE_TETHER_COUNT,0)>0);
}
}
@Override
protected void onResume() {
super.onResume();
mEnableTetherNotice.setChecked(Settings.Secure.getInt(getContentResolver(),
Settings.Secure.TETHER_NOTIFY, 0) != 0);
IntentFilter filter = new IntentFilter(ConnectivityManager.ACTION_TETHER_STATE_CHANGED);
mTetherChangeReceiver = new TetherChangeReceiver();
registerReceiver(mTetherChangeReceiver, filter);
ConnectivityManager cm =
(ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
updateState(cm.getTetherableIfaces().length>0, cm.getTetheredIfaces().length>0);
}
@Override
protected void onPause() {
super.onPause();
unregisterReceiver(mTetherChangeReceiver);
mTetherChangeReceiver = null;
}
private void updateState(boolean isAvailable, boolean isTethered) {
if (isTethered) {
mUsbTether.setSummary(R.string.usb_tethering_active_subtext);
mUsbTether.setEnabled(true);
} else if (isAvailable) {
mUsbTether.setSummary(R.string.usb_tethering_available_subtext);
mUsbTether.setEnabled(true);
} else {
mUsbTether.setSummary(R.string.usb_tethering_unavailable_subtext);
mUsbTether.setEnabled(false);
}
}
@Override
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
if (preference == mEnableTetherNotice) {
boolean newState = mEnableTetherNotice.isChecked();
Settings.Secure.putInt(getContentResolver(),
Settings.Secure.TETHER_NOTIFY, newState ? 1 : 0);
return true;
}
return false;
}
}