Merge branch 'master' into honeycomb-release

This commit is contained in:
The Android Automerger
2010-11-02 08:24:18 -07:00
12 changed files with 368 additions and 305 deletions

View File

@@ -457,7 +457,7 @@
<!-- Provide direct entry into manage apps showing running services. -->
<activity-alias android:name=".RunningServices"
android:label="@string/runningservices_settings_title"
android:targetActivity=".applications.ManageApplications">
android:targetActivity="Settings">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
@@ -470,7 +470,7 @@
<!-- Provide direct entry into manage apps showing running services. -->
<activity-alias android:name=".applications.StorageUse"
android:label="@string/storageuse_settings_title"
android:targetActivity=".applications.ManageApplications">
android:targetActivity="Settings">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
@@ -480,11 +480,6 @@
</intent-filter>
</activity-alias>
<activity android:name=".applications.RunningServiceDetails"
android:theme="@android:style/Theme.NoTitleBar"
android:label="@string/runningservicedetails_settings_title">
</activity>
<activity-alias android:name="SecuritySettings"
android:label="@string/location_security_settings_title"
android:configChanges="orientation|keyboardHidden"
@@ -686,15 +681,17 @@
</intent-filter>
</activity>
<activity android:name="DevelopmentSettings"
android:label="@string/development_settings_title">
<activity-alias android:name="DevelopmentSettings"
android:label="@string/development_settings_title"
android:targetActivity="Settings"
android:clearTaskOnLaunch="true"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="com.android.settings.APPLICATION_DEVELOPMENT_SETTINGS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</activity-alias>

View File

@@ -999,14 +999,6 @@
<!-- Wi-Fi Advanced Settings --> <skip />
<!-- Wi-Fi settings screen, advanced, settings section. This is a header shown above advanced wifi settings. -->
<string name="wifi_advanced_titlebar">Advanced</string>
<!-- Wi-Fi settings screen, setting title for choosing the number of channels to be used -->
<string name="wifi_setting_num_channels_title">Regulatory domain</string>
<!-- Wi-Fi settings screen, setting summary for choosing the number of channels to be used -->
<string name="wifi_setting_num_channels_summary">Set the number of channels to use</string>
<!-- Wi-Fi settings screen, generic error message when the regulatory domain could not be set. -->
<string name="wifi_setting_num_channels_error">There was a problem setting the regulatory domain.</string>
<!-- Wi-Fi settings screen, label to be appended to the count in displaying the list of valid channel counts -->
<string name="wifi_setting_num_channels_channel_phrase"><xliff:g id="num_channels">%1$d</xliff:g> channels</string>
<!-- Wi-Fi settings screen, setting title for setting the wifi sleep policy -->
<string name="wifi_setting_sleep_policy_title">Wi-Fi sleep policy</string>
<!-- Wi-Fi settings screen, setting summary for setting the wifi sleep policy -->

View File

@@ -44,25 +44,24 @@
</PreferenceScreen>
<PreferenceScreen
android:fragment="com.android.settings.applications.ManageApplications"
android:title="@string/manageapplications_settings_title"
android:summary="@string/manageapplications_settings_summary">
android:fragment="com.android.settings.applications.ManageApplications"
android:title="@string/manageapplications_settings_title"
android:summary="@string/manageapplications_settings_summary">
</PreferenceScreen>
<PreferenceScreen
android:fragment="com.android.settings.applications.ManageApplications"
android:title="@string/runningservices_settings_title"
android:summary="@string/runningservices_settings_summary">
<intent android:action="android.intent.action.MAIN"
android:targetPackage="com.android.settings"
android:targetClass="com.android.settings.RunningServices" />
<extra android:name="classname" android:value="com.android.settings.RunningServices" />
</PreferenceScreen>
<PreferenceScreen
android:fragment="com.android.settings.applications.ManageApplications"
android:title="@string/storageuse_settings_title"
android:summary="@string/storageuse_settings_summary">
<intent android:action="android.intent.action.MAIN"
android:targetPackage="com.android.settings"
android:targetClass="com.android.settings.applications.StorageUse" />
<extra android:name="classname"
android:value="com.android.settings.applications.StorageUse" />
</PreferenceScreen>
<PreferenceScreen

View File

@@ -17,13 +17,6 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:title="@string/wifi_advanced_titlebar">
<ListPreference
android:key="num_channels"
android:title="@string/wifi_setting_num_channels_title"
android:summary="@string/wifi_setting_num_channels_summary"
android:persistent="false"
/>
<ListPreference
android:key="sleep_policy"
android:title="@string/wifi_setting_sleep_policy_title"

View File

@@ -18,21 +18,20 @@ package com.android.settings;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.ContentResolver;
import android.content.DialogInterface;
import android.os.BatteryManager;
import android.os.Bundle;
import android.os.SystemProperties;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceFragment;
import android.preference.PreferenceScreen;
import android.preference.CheckBoxPreference;
import android.provider.Settings;
import android.text.TextUtils;
/*
* Displays preferences for application developers.
*/
public class DevelopmentSettings extends PreferenceActivity
public class DevelopmentSettings extends PreferenceFragment
implements DialogInterface.OnClickListener, DialogInterface.OnDismissListener {
private static final String ENABLE_ADB = "enable_adb";
@@ -49,7 +48,7 @@ public class DevelopmentSettings extends PreferenceActivity
private Dialog mOkDialog;
@Override
protected void onCreate(Bundle icicle) {
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
addPreferencesFromResource(R.xml.development_prefs);
@@ -60,14 +59,15 @@ public class DevelopmentSettings extends PreferenceActivity
}
@Override
protected void onResume() {
public void onResume() {
super.onResume();
mEnableAdb.setChecked(Settings.Secure.getInt(getContentResolver(),
final ContentResolver cr = getActivity().getContentResolver();
mEnableAdb.setChecked(Settings.Secure.getInt(cr,
Settings.Secure.ADB_ENABLED, 0) != 0);
mKeepScreenOn.setChecked(Settings.System.getInt(getContentResolver(),
mKeepScreenOn.setChecked(Settings.System.getInt(cr,
Settings.System.STAY_ON_WHILE_PLUGGED_IN, 0) != 0);
mAllowMockLocation.setChecked(Settings.Secure.getInt(getContentResolver(),
mAllowMockLocation.setChecked(Settings.Secure.getInt(cr,
Settings.Secure.ALLOW_MOCK_LOCATION, 0) != 0);
}
@@ -82,8 +82,8 @@ public class DevelopmentSettings extends PreferenceActivity
if (mEnableAdb.isChecked()) {
mOkClicked = false;
if (mOkDialog != null) dismissDialog();
mOkDialog = new AlertDialog.Builder(this).setMessage(
getResources().getString(R.string.adb_warning_message))
mOkDialog = new AlertDialog.Builder(getActivity()).setMessage(
getActivity().getResources().getString(R.string.adb_warning_message))
.setTitle(R.string.adb_warning_title)
.setIcon(android.R.drawable.ic_dialog_alert)
.setPositiveButton(android.R.string.yes, this)
@@ -91,14 +91,17 @@ public class DevelopmentSettings extends PreferenceActivity
.show();
mOkDialog.setOnDismissListener(this);
} else {
Settings.Secure.putInt(getContentResolver(), Settings.Secure.ADB_ENABLED, 0);
Settings.Secure.putInt(getActivity().getContentResolver(),
Settings.Secure.ADB_ENABLED, 0);
}
} else if (preference == mKeepScreenOn) {
Settings.System.putInt(getContentResolver(), Settings.System.STAY_ON_WHILE_PLUGGED_IN,
Settings.System.putInt(getActivity().getContentResolver(),
Settings.System.STAY_ON_WHILE_PLUGGED_IN,
mKeepScreenOn.isChecked() ?
(BatteryManager.BATTERY_PLUGGED_AC | BatteryManager.BATTERY_PLUGGED_USB) : 0);
} else if (preference == mAllowMockLocation) {
Settings.Secure.putInt(getContentResolver(), Settings.Secure.ALLOW_MOCK_LOCATION,
Settings.Secure.putInt(getActivity().getContentResolver(),
Settings.Secure.ALLOW_MOCK_LOCATION,
mAllowMockLocation.isChecked() ? 1 : 0);
}
@@ -114,7 +117,8 @@ public class DevelopmentSettings extends PreferenceActivity
public void onClick(DialogInterface dialog, int which) {
if (which == DialogInterface.BUTTON_POSITIVE) {
mOkClicked = true;
Settings.Secure.putInt(getContentResolver(), Settings.Secure.ADB_ENABLED, 1);
Settings.Secure.putInt(getActivity().getContentResolver(),
Settings.Secure.ADB_ENABLED, 1);
} else {
// Reset the toggle
mEnableAdb.setChecked(false);

View File

@@ -56,7 +56,9 @@ public class Settings extends PreferenceActivity {
String intentClass = intent.getComponent().getClassName();
if (intentClass.equals(getClass().getName())) return null;
if ("com.android.settings.ManageApplications".equals(intentClass)) {
if ("com.android.settings.ManageApplications".equals(intentClass)
|| "com.android.settings.RunningServices".equals(intentClass)
|| "com.android.settings.applications.StorageUse".equals(intentClass)) {
// Old name of manage apps.
intentClass = com.android.settings.applications.ManageApplications.class.getName();
}

View File

@@ -40,9 +40,11 @@ import android.content.pm.PackageManager.NameNotFoundException;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.os.RemoteException;
import android.preference.PreferenceActivity;
import android.text.format.Formatter;
import android.util.Log;
@@ -222,6 +224,10 @@ public class InstalledAppDetails extends Fragment
}
private void initMoveButton() {
if (Environment.isExternalStorageEmulated()) {
mMoveAppButton.setVisibility(View.INVISIBLE);
return;
}
boolean dataOnly = false;
dataOnly = (mPackageInfo == null) && (mAppEntry != null);
boolean moveDisable = true;
@@ -470,13 +476,8 @@ public class InstalledAppDetails extends Fragment
if(localLOGV) Log.i(TAG, "appChanged="+appChanged);
Intent intent = new Intent();
intent.putExtra(ManageApplications.APP_CHG, appChanged);
Fragment target = getTargetFragment();
if (target != null) {
target.onActivityResult(getTargetRequestCode(), Activity.RESULT_OK, intent);
}
if (finish) {
getActivity().onBackPressed();
}
PreferenceActivity pa = (PreferenceActivity)getActivity();
pa.finishPreferencePanel(this, Activity.RESULT_OK, intent);
}
private void refreshSizeInfo() {

View File

@@ -21,14 +21,11 @@ import com.android.settings.R;
import com.android.settings.applications.ApplicationsState.AppEntry;
import android.app.Fragment;
import android.app.TabActivity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.IPackageManager;
import android.content.pm.PackageInfo;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.os.RemoteException;
@@ -38,14 +35,12 @@ import android.preference.PreferenceActivity;
import android.provider.Settings;
import android.text.format.Formatter;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.animation.AnimationUtils;
import android.view.inputmethod.InputMethodManager;
import android.widget.AbsListView;
@@ -57,7 +52,6 @@ import android.widget.Filterable;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TabHost;
import android.widget.TabWidget;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
@@ -167,6 +161,8 @@ public class ManageApplications extends Fragment implements
TextView mUsedStorageText;
TextView mFreeStorageText;
private Menu mOptionsMenu;
// These are for keeping track of activity and tab switch state.
private int mCurView;
private boolean mCreatedRunning;
@@ -518,11 +514,14 @@ public class ManageApplications extends Fragment implements
Intent intent = getActivity().getIntent();
String action = intent.getAction();
String defaultTabTag = TAB_DOWNLOADED;
if (intent.getComponent().getClassName().equals(
"com.android.settings.RunningServices")) {
String className = getArguments() != null
? getArguments().getString("classname") : null;
if (className == null) {
className = intent.getComponent().getClassName();
}
if (className.equals("com.android.settings.RunningServices")) {
defaultTabTag = TAB_RUNNING;
} else if (intent.getComponent().getClassName().equals(
"com.android.settings.applications.StorageUse")
} else if (className.equals("com.android.settings.applications.StorageUse")
|| action.equals(Intent.ACTION_MANAGE_PACKAGE_STORAGE)) {
mSortOrder = SORT_ORDER_SIZE;
mFilterApps = FILTER_APPS_ALL;
@@ -577,6 +576,8 @@ public class ManageApplications extends Fragment implements
mRunningProcessesView = (RunningProcessesView)mRootView.findViewById(
R.id.running_processes);
mCreatedRunning = mResumedRunning = false;
View tabRoot = mInflater.inflate(com.android.internal.R.layout.tab_content, null);
mTabHost = (TabHost)tabRoot.findViewById(com.android.internal.R.id.tabhost);
mTabHost.setup();
@@ -589,10 +590,12 @@ public class ManageApplications extends Fragment implements
.setIndicator(getActivity().getString(R.string.filter_apps_all),
getActivity().getResources().getDrawable(R.drawable.ic_tab_all))
.setContent(this));
tabHost.addTab(tabHost.newTabSpec(TAB_SDCARD)
.setIndicator(getActivity().getString(R.string.filter_apps_onsdcard),
getActivity().getResources().getDrawable(R.drawable.ic_tab_sdcard))
.setContent(this));
if (!Environment.isExternalStorageEmulated()) {
tabHost.addTab(tabHost.newTabSpec(TAB_SDCARD)
.setIndicator(getActivity().getString(R.string.filter_apps_onsdcard),
getActivity().getResources().getDrawable(R.drawable.ic_tab_sdcard))
.setContent(this));
}
tabHost.addTab(tabHost.newTabSpec(TAB_RUNNING)
.setIndicator(getActivity().getString(R.string.filter_apps_running),
getActivity().getResources().getDrawable(R.drawable.ic_tab_running))
@@ -613,6 +616,7 @@ public class ManageApplications extends Fragment implements
super.onResume();
mActivityResumed = true;
showCurrentTab();
updateOptionsMenu();
}
@Override
@@ -620,8 +624,8 @@ public class ManageApplications extends Fragment implements
super.onSaveInstanceState(outState);
outState.putInt("sortOrder", mSortOrder);
outState.putInt("filterApps", mFilterApps);
if (mTabHost != null) {
outState.putString("defautTabTag", mTabHost.getCurrentTabTag());
if (mDefaultTab != null) {
outState.putString("defautTabTag", mDefaultTab);
}
}
@@ -645,52 +649,63 @@ public class ManageApplications extends Fragment implements
// utility method used to start sub activity
private void startApplicationDetailsActivity() {
// Create intent to start new activity
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
Uri.fromParts("package", mCurrentPkgName, null));
// start new fragment to display extended information
Bundle args = new Bundle();
args.putString(InstalledAppDetails.ARG_PACKAGE_NAME, mCurrentPkgName);
PreferenceActivity pa = (PreferenceActivity)getActivity();
if (pa.isMultiPane()) {
Fragment frag = new InstalledAppDetails();
frag.setTargetFragment(this, INSTALLED_APP_DETAILS);
frag.setArguments(args);
frag.setTargetFragment(this, INSTALLED_APP_DETAILS);
pa.startPreferenceFragment(frag, true);
} else {
pa.startWithFragment(InstalledAppDetails.class.getName(), args);
}
pa.startPreferencePanel(InstalledAppDetails.class.getName(), args,
R.string.application_info_label, null, this, INSTALLED_APP_DETAILS);
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
Log.i(TAG, "onCreateOptionsMenu in " + this + ": " + menu);
mOptionsMenu = menu;
menu.add(0, SORT_ORDER_ALPHA, 1, R.string.sort_order_alpha)
.setIcon(android.R.drawable.ic_menu_sort_alphabetically);
.setIcon(android.R.drawable.ic_menu_sort_alphabetically)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
menu.add(0, SORT_ORDER_SIZE, 2, R.string.sort_order_size)
.setIcon(android.R.drawable.ic_menu_sort_by_size);
menu.add(0, SHOW_RUNNING_SERVICES, 3, R.string.show_running_services);
menu.add(0, SHOW_BACKGROUND_PROCESSES, 3, R.string.show_background_processes);
.setIcon(android.R.drawable.ic_menu_sort_by_size)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
menu.add(0, SHOW_RUNNING_SERVICES, 3, R.string.show_running_services)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
menu.add(0, SHOW_BACKGROUND_PROCESSES, 3, R.string.show_background_processes)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
updateOptionsMenu();
}
@Override
public void onPrepareOptionsMenu(Menu menu) {
updateOptionsMenu();
}
@Override
public void onDestroyOptionsMenu() {
mOptionsMenu = null;
}
void updateOptionsMenu() {
if (mOptionsMenu == null) {
return;
}
/*
* The running processes screen doesn't use the mApplicationsAdapter
* so bringing up this menu in that case doesn't make any sense.
*/
if (mCurView == VIEW_RUNNING) {
boolean showingBackground = mRunningProcessesView.mAdapter.getShowBackground();
menu.findItem(SORT_ORDER_ALPHA).setVisible(false);
menu.findItem(SORT_ORDER_SIZE).setVisible(false);
menu.findItem(SHOW_RUNNING_SERVICES).setVisible(showingBackground);
menu.findItem(SHOW_BACKGROUND_PROCESSES).setVisible(!showingBackground);
boolean showingBackground = mRunningProcessesView != null
? mRunningProcessesView.mAdapter.getShowBackground() : false;
mOptionsMenu.findItem(SORT_ORDER_ALPHA).setVisible(false);
mOptionsMenu.findItem(SORT_ORDER_SIZE).setVisible(false);
mOptionsMenu.findItem(SHOW_RUNNING_SERVICES).setVisible(showingBackground);
mOptionsMenu.findItem(SHOW_BACKGROUND_PROCESSES).setVisible(!showingBackground);
} else {
menu.findItem(SORT_ORDER_ALPHA).setVisible(mSortOrder != SORT_ORDER_ALPHA);
menu.findItem(SORT_ORDER_SIZE).setVisible(mSortOrder != SORT_ORDER_SIZE);
menu.findItem(SHOW_RUNNING_SERVICES).setVisible(false);
menu.findItem(SHOW_BACKGROUND_PROCESSES).setVisible(false);
mOptionsMenu.findItem(SORT_ORDER_ALPHA).setVisible(mSortOrder != SORT_ORDER_ALPHA);
mOptionsMenu.findItem(SORT_ORDER_SIZE).setVisible(mSortOrder != SORT_ORDER_SIZE);
mOptionsMenu.findItem(SHOW_RUNNING_SERVICES).setVisible(false);
mOptionsMenu.findItem(SHOW_BACKGROUND_PROCESSES).setVisible(false);
}
}
@@ -707,6 +722,7 @@ public class ManageApplications extends Fragment implements
} else if (menuId == SHOW_BACKGROUND_PROCESSES) {
mRunningProcessesView.mAdapter.setShowBackground(true);
}
updateOptionsMenu();
return true;
}
@@ -822,7 +838,7 @@ public class ManageApplications extends Fragment implements
}
boolean haveData = true;
if (mActivityResumed && !mResumedRunning) {
haveData = mRunningProcessesView.doResume(mRunningProcessesAvail);
haveData = mRunningProcessesView.doResume(this, mRunningProcessesAvail);
mResumedRunning = true;
}
mApplicationsAdapter.pause();
@@ -850,7 +866,7 @@ public class ManageApplications extends Fragment implements
}
public void showCurrentTab() {
String tabId = mTabHost.getCurrentTabTag();
String tabId = mDefaultTab = mTabHost.getCurrentTabTag();
int newOption;
if (TAB_DOWNLOADED.equalsIgnoreCase(tabId)) {
newOption = FILTER_APPS_THIRD_PARTY;
@@ -872,6 +888,7 @@ public class ManageApplications extends Fragment implements
mFilterApps = newOption;
selectView(VIEW_LIST);
updateStorageUsage();
updateOptionsMenu();
}
public void onTabChanged(String tabId) {

View File

@@ -20,16 +20,16 @@ import com.android.settings.R;
import android.app.ActivityManager;
import android.app.Dialog;
import android.app.Fragment;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.SystemClock;
import android.os.SystemProperties;
import android.preference.PreferenceActivity;
import android.text.format.DateUtils;
import android.text.format.Formatter;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -61,6 +61,8 @@ public class RunningProcessesView extends FrameLayout
RunningState mState;
Fragment mOwner;
Runnable mDataAvail;
StringBuilder mBuilder = new StringBuilder(128);
@@ -417,14 +419,22 @@ public class RunningProcessesView extends FrameLayout
ListView l = (ListView)parent;
RunningState.MergedItem mi = (RunningState.MergedItem)l.getAdapter().getItem(position);
mCurSelected = mi;
Intent intent = new Intent();
intent.putExtra(RunningServiceDetails.KEY_UID, mi.mProcess.mUid);
intent.putExtra(RunningServiceDetails.KEY_PROCESS, mi.mProcess.mProcessName);
intent.putExtra(RunningServiceDetails.KEY_BACKGROUND, mAdapter.mShowBackground);
intent.setClass(getContext(), RunningServiceDetails.class);
getContext().startActivity(intent);
startServiceDetailsActivity(mi);
}
// utility method used to start sub activity
private void startServiceDetailsActivity(RunningState.MergedItem mi) {
// start new fragment to display extended information
Bundle args = new Bundle();
args.putInt(RunningServiceDetails.KEY_UID, mi.mProcess.mUid);
args.putString(RunningServiceDetails.KEY_PROCESS, mi.mProcess.mProcessName);
args.putBoolean(RunningServiceDetails.KEY_BACKGROUND, mAdapter.mShowBackground);
PreferenceActivity pa = (PreferenceActivity)mOwner.getActivity();
pa.startPreferencePanel(RunningServiceDetails.class.getName(), args,
R.string.runningservicedetails_settings_title, null, null, 0);
}
public void onMovedToScrapHeap(View view) {
mActiveItems.remove(view);
}
@@ -472,9 +482,11 @@ public class RunningProcessesView extends FrameLayout
public void doPause() {
mState.pause();
mDataAvail = null;
mOwner = null;
}
public boolean doResume(Runnable dataAvail) {
public boolean doResume(Fragment owner, Runnable dataAvail) {
mOwner = owner;
mState.resume(this);
if (mState.hasData()) {
// If the state already has its data, then let's populate our

View File

@@ -2,11 +2,12 @@ package com.android.settings.applications;
import com.android.settings.R;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.AlertDialog;
import android.app.ApplicationErrorReport;
import android.app.Dialog;
import android.app.DialogFragment;
import android.app.Fragment;
import android.app.PendingIntent;
import android.content.ActivityNotFoundException;
import android.content.ComponentName;
@@ -37,7 +38,7 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
public class RunningServiceDetails extends Activity
public class RunningServiceDetails extends Fragment
implements RunningState.OnRefreshUiListener {
static final String TAG = "RunningServicesDetails";
@@ -59,6 +60,7 @@ public class RunningServiceDetails extends Activity
RunningState.MergedItem mMergedItem;
View mRootView;
ViewGroup mAllDetails;
ViewGroup mSnippet;
RunningProcessesView.ActiveItem mSnippetActiveItem;
@@ -84,14 +86,11 @@ public class RunningServiceDetails extends Activity
RunningState.ServiceItem si = mServiceItem;
if (!confirmed) {
if ((si.mServiceInfo.applicationInfo.flags&ApplicationInfo.FLAG_SYSTEM) != 0) {
Bundle args = new Bundle();
args.putParcelable("comp", si.mRunningService.service);
removeDialog(DIALOG_CONFIRM_STOP);
showDialog(DIALOG_CONFIRM_STOP, args);
showConfirmStopDialog(si.mRunningService.service);
return;
}
}
stopService(new Intent().setComponent(si.mRunningService.service));
getActivity().stopService(new Intent().setComponent(si.mRunningService.service));
if (mMergedItem == null) {
// If this is gone, we are gone.
mState.updateNow();
@@ -125,7 +124,7 @@ public class RunningServiceDetails extends Activity
}
ComponentName comp = new ComponentName(mServiceItem.mServiceInfo.packageName,
mServiceItem.mServiceInfo.name);
File filename = getFileStreamPath("service_dump.txt");
File filename = getActivity().getFileStreamPath("service_dump.txt");
FileOutputStream output = null;
try {
output = new FileOutputStream(filename);
@@ -160,7 +159,7 @@ public class RunningServiceDetails extends Activity
if (mManageIntent != null) {
try {
startIntentSender(mManageIntent.getIntentSender(), null,
getActivity().startIntentSender(mManageIntent.getIntentSender(), null,
Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET,
Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET, 0);
@@ -236,7 +235,7 @@ public class RunningServiceDetails extends Activity
TextView description = (TextView)root.findViewById(R.id.comp_description);
if (si != null && si.mServiceInfo.descriptionRes != 0) {
description.setText(getPackageManager().getText(
description.setText(getActivity().getPackageManager().getText(
si.mServiceInfo.packageName, si.mServiceInfo.descriptionRes,
si.mServiceInfo.applicationInfo));
} else {
@@ -244,15 +243,15 @@ public class RunningServiceDetails extends Activity
description.setText(R.string.background_process_stop_description);
} else if (detail.mManageIntent != null) {
try {
Resources clientr = getPackageManager().getResourcesForApplication(
Resources clientr = getActivity().getPackageManager().getResourcesForApplication(
si.mRunningService.clientPackage);
String label = clientr.getString(si.mRunningService.clientLabel);
description.setText(getString(R.string.service_manage_description,
description.setText(getActivity().getString(R.string.service_manage_description,
label));
} catch (PackageManager.NameNotFoundException e) {
}
} else {
description.setText(getText(si != null
description.setText(getActivity().getText(si != null
? R.string.service_stop_description
: R.string.heavy_weight_stop_description));
}
@@ -260,18 +259,19 @@ public class RunningServiceDetails extends Activity
detail.mStopButton = (Button)root.findViewById(R.id.left_button);
detail.mStopButton.setOnClickListener(detail);
detail.mStopButton.setText(getText(detail.mManageIntent != null
detail.mStopButton.setText(getActivity().getText(detail.mManageIntent != null
? R.string.service_manage : R.string.service_stop));
detail.mReportButton = (Button)root.findViewById(R.id.right_button);
detail.mReportButton.setOnClickListener(detail);
detail.mReportButton.setText(com.android.internal.R.string.report);
// check if error reporting is enabled in secure settings
int enabled = Settings.Secure.getInt(getContentResolver(),
int enabled = Settings.Secure.getInt(getActivity().getContentResolver(),
Settings.Secure.SEND_ACTION_APP_ERROR, 0);
if (enabled != 0 && si != null) {
detail.mInstaller = ApplicationErrorReport.getErrorReportReceiver(
this, si.mServiceInfo.packageName, si.mServiceInfo.applicationInfo.flags);
getActivity(), si.mServiceInfo.packageName,
si.mServiceInfo.applicationInfo.flags);
detail.mReportButton.setEnabled(detail.mInstaller != null);
} else {
detail.mReportButton.setEnabled(false);
@@ -312,9 +312,9 @@ public class RunningServiceDetails extends Activity
textid = R.string.process_provider_in_use_description;
if (rpi.importanceReasonComponent != null) {
try {
ProviderInfo prov = getPackageManager().getProviderInfo(
ProviderInfo prov = getActivity().getPackageManager().getProviderInfo(
rpi.importanceReasonComponent, 0);
label = RunningState.makeLabel(getPackageManager(),
label = RunningState.makeLabel(getActivity().getPackageManager(),
prov.name, prov);
} catch (NameNotFoundException e) {
}
@@ -324,9 +324,9 @@ public class RunningServiceDetails extends Activity
textid = R.string.process_service_in_use_description;
if (rpi.importanceReasonComponent != null) {
try {
ServiceInfo serv = getPackageManager().getServiceInfo(
ServiceInfo serv = getActivity().getPackageManager().getServiceInfo(
rpi.importanceReasonComponent, 0);
label = RunningState.makeLabel(getPackageManager(),
label = RunningState.makeLabel(getActivity().getPackageManager(),
serv.name, serv);
} catch (NameNotFoundException e) {
}
@@ -334,7 +334,7 @@ public class RunningServiceDetails extends Activity
break;
}
if (textid != 0 && label != null) {
description.setText(getString(textid, label));
description.setText(getActivity().getString(textid, label));
}
}
@@ -405,23 +405,30 @@ public class RunningServiceDetails extends Activity
}
}
private void finish() {
getActivity().onBackPressed();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mUid = getIntent().getIntExtra(KEY_UID, 0);
mProcessName = getIntent().getStringExtra(KEY_PROCESS);
mShowBackground = getIntent().getBooleanExtra(KEY_BACKGROUND, false);
mUid = getArguments().getInt(KEY_UID, 0);
mProcessName = getArguments().getString(KEY_PROCESS);
mShowBackground = getArguments().getBoolean(KEY_BACKGROUND, false);
mAm = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
mInflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mAm = (ActivityManager)getActivity().getSystemService(Context.ACTIVITY_SERVICE);
mInflater = (LayoutInflater)getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mState = RunningState.getInstance(this);
mState = RunningState.getInstance(getActivity());
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = mRootView = inflater.inflate(R.layout.running_service_details, null);
setContentView(R.layout.running_service_details);
mAllDetails = (ViewGroup)findViewById(R.id.all_details);
mSnippet = (ViewGroup)findViewById(R.id.snippet);
mAllDetails = (ViewGroup)view.findViewById(R.id.all_details);
mSnippet = (ViewGroup)view.findViewById(R.id.snippet);
mSnippet.setBackgroundResource(com.android.internal.R.drawable.title_bar_medium);
mSnippet.setPadding(0, mSnippet.getPaddingTop(), 0, mSnippet.getPaddingBottom());
mSnippetViewHolder = new RunningProcessesView.ViewHolder(mSnippet);
@@ -429,26 +436,23 @@ public class RunningServiceDetails extends Activity
// We want to retrieve the data right now, so any active managed
// dialog that gets created can find it.
ensureData();
return view;
}
@Override
protected void onPause() {
public void onPause() {
super.onPause();
mHaveData = false;
mState.pause();
}
@Override
protected void onResume() {
public void onResume() {
super.onResume();
ensureData();
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
}
ActiveDetail activeDetailForService(ComponentName comp) {
for (int i=0; i<mActiveDetails.size(); i++) {
ActiveDetail ad = mActiveDetails.get(i);
@@ -460,34 +464,56 @@ public class RunningServiceDetails extends Activity
return null;
}
@Override
protected Dialog onCreateDialog(int id, Bundle args) {
switch (id) {
case DIALOG_CONFIRM_STOP: {
final ComponentName comp = (ComponentName)args.getParcelable("comp");
if (activeDetailForService(comp) == null) {
return null;
}
return new AlertDialog.Builder(this)
.setTitle(getString(R.string.runningservicedetails_stop_dlg_title))
.setIcon(android.R.drawable.ic_dialog_alert)
.setMessage(getString(R.string.runningservicedetails_stop_dlg_text))
.setPositiveButton(R.string.dlg_ok,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
ActiveDetail ad = activeDetailForService(comp);
if (ad != null) {
ad.stopActiveService(true);
private void showConfirmStopDialog(ComponentName comp) {
DialogFragment newFragment = MyAlertDialogFragment.newConfirmStop(
DIALOG_CONFIRM_STOP, comp);
newFragment.setTargetFragment(this, 0);
newFragment.show(getFragmentManager(), "confirmstop");
}
public static class MyAlertDialogFragment extends DialogFragment {
public static MyAlertDialogFragment newConfirmStop(int id, ComponentName comp) {
MyAlertDialogFragment frag = new MyAlertDialogFragment();
Bundle args = new Bundle();
args.putInt("id", id);
args.putParcelable("comp", comp);
frag.setArguments(args);
return frag;
}
RunningServiceDetails getOwner() {
return (RunningServiceDetails)getTargetFragment();
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
int id = getArguments().getInt("id");
switch (id) {
case DIALOG_CONFIRM_STOP: {
final ComponentName comp = (ComponentName)getArguments().getParcelable("comp");
if (getOwner().activeDetailForService(comp) == null) {
return null;
}
return new AlertDialog.Builder(getActivity())
.setTitle(getActivity().getString(R.string.runningservicedetails_stop_dlg_title))
.setIcon(android.R.drawable.ic_dialog_alert)
.setMessage(getActivity().getString(R.string.runningservicedetails_stop_dlg_text))
.setPositiveButton(R.string.dlg_ok,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
ActiveDetail ad = getOwner().activeDetailForService(comp);
if (ad != null) {
ad.stopActiveService(true);
}
}
}
})
.setNegativeButton(R.string.dlg_cancel, null)
.create();
})
.setNegativeButton(R.string.dlg_cancel, null)
.create();
}
}
default:
return super.onCreateDialog(id, args);
throw new IllegalArgumentException("unknown id " + id);
}
}
@@ -509,11 +535,10 @@ public class RunningServiceDetails extends Activity
void updateTimes() {
if (mSnippetActiveItem != null) {
mSnippetActiveItem.updateTime(RunningServiceDetails.this, mBuilder);
mSnippetActiveItem.updateTime(getActivity(), mBuilder);
}
for (int i=0; i<mActiveDetails.size(); i++) {
mActiveDetails.get(i).mActiveItem.updateTime(
RunningServiceDetails.this, mBuilder);
mActiveDetails.get(i).mActiveItem.updateTime(getActivity(), mBuilder);
}
}

View File

@@ -23,97 +23,173 @@ import android.content.pm.ApplicationInfo;
import android.preference.CheckBoxPreference;
import android.preference.PreferenceScreen;
import android.provider.Settings;
import android.provider.Settings.SettingNotFoundException;
import android.text.TextUtils;
import android.util.Log;
import android.view.inputmethod.InputMethodInfo;
import android.view.inputmethod.InputMethodSubtype;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
public class InputMethodAndSubtypeUtil {
private static final TextUtils.SimpleStringSplitter sStringColonSplitter
= new TextUtils.SimpleStringSplitter(':');
private static final boolean DEBUG = false;
static final String TAG = "InputMethdAndSubtypeUtil";
private static final char INPUT_METHOD_SEPARATER = ':';
private static final char INPUT_METHOD_SUBTYPE_SEPARATER = ';';
private static final int NOT_A_SUBTYPE_ID = -1;
private static final TextUtils.SimpleStringSplitter sStringInputMethodSplitter
= new TextUtils.SimpleStringSplitter(INPUT_METHOD_SEPARATER);
private static final TextUtils.SimpleStringSplitter sStringInputMethodSubtypeSplitter
= new TextUtils.SimpleStringSplitter(INPUT_METHOD_SUBTYPE_SEPARATER);
private static boolean isInputMethodSubtypeSelected(ContentResolver resolver) {
try {
return Settings.Secure.getInt(resolver,
Settings.Secure.SELECTED_INPUT_METHOD_SUBTYPE) != NOT_A_SUBTYPE_ID;
} catch (SettingNotFoundException e) {
return false;
}
}
private static void putSelectedInputMethodSubtype(ContentResolver resolver, int hashCode) {
Settings.Secure.putInt(resolver, Settings.Secure.SELECTED_INPUT_METHOD_SUBTYPE, hashCode);
}
// Needs to modify InputMethodManageService if you want to change the format of saved string.
private static HashMap<String, HashSet<String>> getEnabledInputMethodsAndSubtypeList(
ContentResolver resolver) {
final String enabledInputMethodsStr = Settings.Secure.getString(
resolver, Settings.Secure.ENABLED_INPUT_METHODS);
HashMap<String, HashSet<String>> imsList
= new HashMap<String, HashSet<String>>();
if (DEBUG) {
Log.d(TAG, "--- Load enabled input methods: " + enabledInputMethodsStr);
}
if (TextUtils.isEmpty(enabledInputMethodsStr)) {
return imsList;
}
sStringInputMethodSplitter.setString(enabledInputMethodsStr);
while (sStringInputMethodSplitter.hasNext()) {
String nextImsStr = sStringInputMethodSplitter.next();
sStringInputMethodSubtypeSplitter.setString(nextImsStr);
if (sStringInputMethodSubtypeSplitter.hasNext()) {
HashSet<String> subtypeHashes = new HashSet<String>();
// The first element is ime id.
String imeId = sStringInputMethodSubtypeSplitter.next();
while (sStringInputMethodSubtypeSplitter.hasNext()) {
subtypeHashes.add(sStringInputMethodSubtypeSplitter.next());
}
imsList.put(imeId, subtypeHashes);
}
}
return imsList;
}
public static void saveInputMethodSubtypeList(
SettingsPreferenceFragment context, ContentResolver resolver,
List<InputMethodInfo> inputMethodProperties,
boolean hasHardKeyboard, String lastTickedInputMethodId) {
String lastInputMethodId = Settings.Secure.getString(resolver,
String currentInputMethodId = Settings.Secure.getString(resolver,
Settings.Secure.DEFAULT_INPUT_METHOD);
StringBuilder builder = new StringBuilder();
StringBuilder disabledSysImes = new StringBuilder();
InputMethodInfo firstEnabledIMI = null;
int firstSubtypeHashCode = NOT_A_SUBTYPE_ID;
int firstEnabled = -1;
int N = inputMethodProperties.size();
for (int i = 0; i < N; ++i) {
final InputMethodInfo property = inputMethodProperties.get(i);
final boolean onlyOneIME = inputMethodProperties.size() == 1;
for (InputMethodInfo property : inputMethodProperties) {
final String id = property.getId();
CheckBoxPreference pref = (CheckBoxPreference) context.findPreference(id);
boolean currentInputMethod = id.equals(lastInputMethodId);
boolean isCurrentInputMethod = id.equals(currentInputMethodId);
boolean systemIme = isSystemIme(property);
// TODO: Append subtypes by using the separator ";"
if (((N == 1 || systemIme) && !hasHardKeyboard)
if (((onlyOneIME || systemIme) && !hasHardKeyboard)
|| (pref != null && pref.isChecked())) {
if (builder.length() > 0) builder.append(':');
if (builder.length() > 0) builder.append(INPUT_METHOD_SEPARATER);
builder.append(id);
if (firstEnabled < 0) {
firstEnabled = i;
if (firstEnabledIMI == null) {
firstEnabledIMI = property;
}
} else if (currentInputMethod) {
lastInputMethodId = lastTickedInputMethodId;
for (InputMethodSubtype subtype : property.getSubtypes()) {
CheckBoxPreference subtypePref = (CheckBoxPreference) context.findPreference(
id + subtype.hashCode());
if (subtypePref != null && subtypePref.isChecked()) {
builder.append(INPUT_METHOD_SUBTYPE_SEPARATER).append(subtype.hashCode());
if (firstSubtypeHashCode == NOT_A_SUBTYPE_ID) {
firstSubtypeHashCode = subtype.hashCode();
}
}
}
} else if (isCurrentInputMethod) {
// We are processing the current input method, but found that it's not enabled.
// This means that the current input method has been uninstalled.
// If currentInputMethod is already uninstalled, selects last ticked IME
currentInputMethodId = lastTickedInputMethodId;
}
// If it's a disabled system ime, add it to the disabled list so that it
// doesn't get enabled automatically on any changes to the package list
if (pref != null && !pref.isChecked() && systemIme && hasHardKeyboard) {
if (disabledSysImes.length() > 0) disabledSysImes.append(":");
if (disabledSysImes.length() > 0) disabledSysImes.append(INPUT_METHOD_SEPARATER);
disabledSysImes.append(id);
}
}
// If the last input method is unset, set it as the first enabled one.
if (TextUtils.isEmpty(lastInputMethodId)) {
if (firstEnabled >= 0) {
lastInputMethodId = inputMethodProperties.get(firstEnabled).getId();
if (TextUtils.isEmpty(currentInputMethodId)) {
if (firstEnabledIMI != null) {
currentInputMethodId = firstEnabledIMI.getId();
} else {
lastInputMethodId = null;
currentInputMethodId = null;
}
}
if (DEBUG) {
Log.d(TAG, "--- Save enabled inputmethod settings. :" + builder.toString());
Log.d(TAG, "--- Save disable system inputmethod settings. :"
+ disabledSysImes.toString());
Log.d(TAG, "--- Save default inputmethod settings. :" + currentInputMethodId);
}
// redefines SelectedSubtype when all subtypes are unchecked or there is no subtype
// selected.
if (firstSubtypeHashCode == NOT_A_SUBTYPE_ID || !isInputMethodSubtypeSelected(resolver)) {
if (DEBUG) {
Log.d(TAG, "--- Set inputmethod subtype because it's not defined."
+ firstSubtypeHashCode);
}
putSelectedInputMethodSubtype(resolver, firstSubtypeHashCode);
}
Settings.Secure.putString(resolver,
Settings.Secure.ENABLED_INPUT_METHODS, builder.toString());
Settings.Secure.putString(resolver,
Settings.Secure.DISABLED_SYSTEM_INPUT_METHODS, disabledSysImes.toString());
Settings.Secure.putString(resolver, Settings.Secure.DEFAULT_INPUT_METHOD,
lastInputMethodId != null ? lastInputMethodId : "");
currentInputMethodId != null ? currentInputMethodId : "");
}
public static void loadInputMethodSubtypeList(
SettingsPreferenceFragment context, ContentResolver resolver,
List<InputMethodInfo> inputMethodProperties) {
final HashSet<String> enabled = new HashSet<String>();
String enabledStr = Settings.Secure.getString(resolver,
Settings.Secure.ENABLED_INPUT_METHODS);
if (enabledStr != null) {
final TextUtils.SimpleStringSplitter splitter = sStringColonSplitter;
splitter.setString(enabledStr);
while (splitter.hasNext()) {
enabled.add(splitter.next());
}
}
HashMap<String, HashSet<String>> enabledSubtypes =
getEnabledInputMethodsAndSubtypeList(resolver);
// Update the statuses of the Check Boxes.
int N = inputMethodProperties.size();
// TODO: Use iterator.
for (int i = 0; i < N; ++i) {
final String id = inputMethodProperties.get(i).getId();
CheckBoxPreference pref = (CheckBoxPreference) context.findPreference(
inputMethodProperties.get(i).getId());
for (InputMethodInfo property : inputMethodProperties) {
final String id = property.getId();
CheckBoxPreference pref = (CheckBoxPreference) context.findPreference(id);
if (pref != null) {
boolean isEnabled = enabled.contains(id);
boolean isEnabled = enabledSubtypes.containsKey(id);
pref.setChecked(isEnabled);
setSubtypesPreferenceEnabled(context, inputMethodProperties, id, isEnabled);
updateSubtypesPreferenceChecked(context, inputMethodProperties, enabledSubtypes);
}
}
}
@@ -121,17 +197,41 @@ public class InputMethodAndSubtypeUtil {
public static void setSubtypesPreferenceEnabled(SettingsPreferenceFragment context,
List<InputMethodInfo> inputMethodProperties, String id, boolean enabled) {
PreferenceScreen preferenceScreen = context.getPreferenceScreen();
final int N = inputMethodProperties.size();
// TODO: Use iterator.
for (int i = 0; i < N; i++) {
InputMethodInfo imi = inputMethodProperties.get(i);
for (InputMethodInfo imi : inputMethodProperties) {
if (id.equals(imi.getId())) {
for (InputMethodSubtype subtype: imi.getSubtypes()) {
preferenceScreen.findPreference(id + subtype.hashCode()).setEnabled(enabled);
for (InputMethodSubtype subtype : imi.getSubtypes()) {
CheckBoxPreference pref = (CheckBoxPreference) preferenceScreen.findPreference(
id + subtype.hashCode());
if (pref != null) {
pref.setEnabled(enabled);
}
}
}
}
}
public static void updateSubtypesPreferenceChecked(SettingsPreferenceFragment context,
List<InputMethodInfo> inputMethodProperties,
HashMap<String, HashSet<String>> enabledSubtypes) {
PreferenceScreen preferenceScreen = context.getPreferenceScreen();
for (InputMethodInfo imi : inputMethodProperties) {
String id = imi.getId();
HashSet<String> enabledSubtypesSet = enabledSubtypes.get(id);
for (InputMethodSubtype subtype : imi.getSubtypes()) {
String hashCode = String.valueOf(subtype.hashCode());
if (DEBUG) {
Log.d(TAG, "--- Set checked state: " + "id" + ", " + hashCode + ", "
+ enabledSubtypesSet.contains(hashCode));
}
CheckBoxPreference pref = (CheckBoxPreference) preferenceScreen.findPreference(
id + hashCode);
if (pref != null) {
pref.setChecked(enabledSubtypesSet.contains(hashCode));
}
}
}
}
public static boolean isSystemIme(InputMethodInfo property) {
return (property.getServiceInfo().applicationInfo.flags
& ApplicationInfo.FLAG_SYSTEM) != 0;

View File

@@ -35,12 +35,8 @@ public class AdvancedSettings extends SettingsPreferenceFragment
private static final String KEY_MAC_ADDRESS = "mac_address";
private static final String KEY_CURRENT_IP_ADDRESS = "current_ip_address";
private static final String KEY_NUM_CHANNELS = "num_channels";
private static final String KEY_SLEEP_POLICY = "sleep_policy";
//Tracks ro.debuggable (1 on userdebug builds)
private static int DEBUGGABLE;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -50,77 +46,16 @@ public class AdvancedSettings extends SettingsPreferenceFragment
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
DEBUGGABLE = SystemProperties.getInt("ro.debuggable", 0);
/**
* Remove user control of regulatory domain
* channel count settings in non userdebug builds
*/
if (DEBUGGABLE == 1) {
/*
* Fix the Run-time IllegalStateException that ListPreference requires an entries
* array and an entryValues array, this exception occurs when user open/close the
* slider in the Regulatory domain dialog.
*/
initNumChannelsPreference();
} else {
Preference chanPref = findPreference(KEY_NUM_CHANNELS);
if (chanPref != null) {
getPreferenceScreen().removePreference(chanPref);
}
}
}
@Override
public void onResume() {
super.onResume();
/**
* Remove user control of regulatory domain
* channel count settings in non userdebug builds
*/
if (DEBUGGABLE == 1) {
initNumChannelsPreference();
}
initSleepPolicyPreference();
refreshWifiInfo();
}
private void initNumChannelsPreference() {
ListPreference pref = (ListPreference) findPreference(KEY_NUM_CHANNELS);
pref.setOnPreferenceChangeListener(this);
WifiManager wifiManager = (WifiManager) getSystemService(Activity.WIFI_SERVICE);
/*
* Generate the list of valid channel counts to show in the ListPreference.
* The values are numerical, so the only text to be localized is the
* "channel_word" resource.
*/
int[] validChannelCounts = wifiManager.getValidChannelCounts();
if (validChannelCounts == null) {
Toast.makeText(getActivity(), R.string.wifi_setting_num_channels_error,
Toast.LENGTH_SHORT).show();
pref.setEnabled(false);
return;
}
String[] entries = new String[validChannelCounts.length];
String[] entryValues = new String[validChannelCounts.length];
for (int i = 0; i < validChannelCounts.length; i++) {
entryValues[i] = String.valueOf(validChannelCounts[i]);
entries[i] = getActivity().getString(R.string.wifi_setting_num_channels_channel_phrase,
validChannelCounts[i]);
}
pref.setEntries(entries);
pref.setEntryValues(entryValues);
pref.setEnabled(true);
int numChannels = wifiManager.getNumAllowedChannels();
if (numChannels >= 0) {
pref.setValue(String.valueOf(numChannels));
}
}
private void initSleepPolicyPreference() {
ListPreference pref = (ListPreference) findPreference(KEY_SLEEP_POLICY);
pref.setOnPreferenceChangeListener(this);
@@ -133,21 +68,7 @@ public class AdvancedSettings extends SettingsPreferenceFragment
String key = preference.getKey();
if (key == null) return true;
if (key.equals(KEY_NUM_CHANNELS)) {
try {
int numChannels = Integer.parseInt((String) newValue);
WifiManager wifiManager = (WifiManager) getSystemService(Activity.WIFI_SERVICE);
if (!wifiManager.setNumAllowedChannels(numChannels, true)) {
Toast.makeText(getActivity(), R.string.wifi_setting_num_channels_error,
Toast.LENGTH_SHORT).show();
}
} catch (NumberFormatException e) {
Toast.makeText(getActivity(), R.string.wifi_setting_num_channels_error,
Toast.LENGTH_SHORT).show();
return false;
}
} else if (key.equals(KEY_SLEEP_POLICY)) {
if (key.equals(KEY_SLEEP_POLICY)) {
try {
Settings.System.putInt(getContentResolver(),
Settings.System.WIFI_SLEEP_POLICY, Integer.parseInt(((String) newValue)));
@@ -157,7 +78,7 @@ public class AdvancedSettings extends SettingsPreferenceFragment
return false;
}
}
return true;
}
@@ -167,7 +88,7 @@ public class AdvancedSettings extends SettingsPreferenceFragment
Preference wifiMacAddressPref = findPreference(KEY_MAC_ADDRESS);
String macAddress = wifiInfo == null ? null : wifiInfo.getMacAddress();
wifiMacAddressPref.setSummary(!TextUtils.isEmpty(macAddress) ? macAddress
wifiMacAddressPref.setSummary(!TextUtils.isEmpty(macAddress) ? macAddress
: getActivity().getString(R.string.status_unavailable));
Preference wifiIpAddressPref = findPreference(KEY_CURRENT_IP_ADDRESS);