Move default app preferences to one screen
- Move emergency and SMS app preferences to default apps - Fix search on default apps - Make all default app prefs use AppListPreference - Some approximate UI work on AppListPreference Bug: 20210110 Change-Id: Id04086163c7e87c92a03af421a27018fb380b45d
This commit is contained in:
@@ -24,18 +24,29 @@
|
||||
android:id="@+id/app_image"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:adjustViewBounds="true"
|
||||
android:padding="6dip"
|
||||
/>
|
||||
<CheckedTextView
|
||||
<TextView
|
||||
android:id="@+id/app_label"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="?android:attr/listPreferredItemHeight"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:textColor="?android:attr/textColorAlertDialogListItem"
|
||||
android:gravity="center_vertical"
|
||||
android:paddingEnd="7dip"
|
||||
android:checkMark="?android:attr/listChoiceIndicatorSingle"
|
||||
android:ellipsize="marquee"
|
||||
/>
|
||||
<TextView
|
||||
android:id="@+id/default_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="?android:attr/listPreferredItemHeight"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:gravity="center_vertical"
|
||||
android:text="@string/default_app"
|
||||
android:visibility="gone"
|
||||
android:paddingEnd="7dip"
|
||||
/>
|
||||
</LinearLayout>
|
||||
|
@@ -2658,7 +2658,7 @@
|
||||
<string name="manage_mobile_plan_title" translatable="true">Mobile plan</string>
|
||||
|
||||
<!-- SMS Application [CHAR LIMIT=35]-->
|
||||
<string name="sms_application_title" translatable="true">Default SMS app</string>
|
||||
<string name="sms_application_title" translatable="true">SMS app</string>
|
||||
<string name="sms_change_default_dialog_title" translatable="true">Change SMS app?</string>
|
||||
<string name="sms_change_default_dialog_text" translatable="true">Use <xliff:g id="new_app">%1$s</xliff:g> instead of <xliff:g id="current_app">%2$s</xliff:g> as your SMS app?</string>
|
||||
<string name="sms_change_default_no_previous_dialog_text" translatable="true">Use <xliff:g id="new_app">%s</xliff:g> as your SMS app?</string>
|
||||
@@ -3019,7 +3019,7 @@
|
||||
<!-- [CHAR LIMIT=25] Manage applications screen, menu item. Show background cached processes. -->
|
||||
<string name="show_background_processes">Show cached processes</string>
|
||||
<!-- [CHAR LIMIT=NONE] Advanced applications screen, preference title. Choose the emergency application. -->
|
||||
<string name="default_emergency_app">Default emergency app</string>
|
||||
<string name="default_emergency_app">Emergency app</string>
|
||||
<!-- [CHAR LIMIT=NONE] Manage applications screen, menu item. Reset all of user's app preferences. -->
|
||||
<string name="reset_app_preferences">Reset app preferences</string>
|
||||
<!-- [CHAR LIMIT=NONE] Manage applications screen, menu item. Title of dialog to confirm resetting user's app preferences. -->
|
||||
@@ -6407,9 +6407,12 @@
|
||||
<string name="default_apps_title">Default Apps</string>
|
||||
|
||||
<!-- Title for Default Browser settings [CHAR LIMIT=30] -->
|
||||
<string name="default_browser_title">Default Browser</string>
|
||||
<string name="default_browser_title">Browser app</string>
|
||||
|
||||
<!-- Summary for No Default Browser settings [CHAR LIMIT=45] -->
|
||||
<string name="default_browser_title_none">No default Browser</string>
|
||||
|
||||
<!-- Label of default app for current setting [CHAR LIMIT=40] -->
|
||||
<string name="default_app">(Default)</string>
|
||||
|
||||
</resources>
|
||||
|
@@ -40,9 +40,4 @@
|
||||
android:value="com.android.settings.Settings$DomainsURLsAppListActivity" />
|
||||
</PreferenceScreen>
|
||||
|
||||
<com.android.settings.applications.DefaultEmergencyPreference
|
||||
android:key="default_emergency_app"
|
||||
android:title="@string/default_emergency_app"
|
||||
settings:keywords="@string/keywords_emergency_app" />
|
||||
|
||||
</PreferenceScreen>
|
||||
|
@@ -25,4 +25,16 @@
|
||||
android:summary="@string/default_browser_title_none"
|
||||
/>
|
||||
|
||||
<com.android.settings.applications.DefaultEmergencyPreference
|
||||
android:key="default_emergency_app"
|
||||
android:title="@string/default_emergency_app"
|
||||
settings:keywords="@string/keywords_emergency_app"
|
||||
/>
|
||||
|
||||
<com.android.settings.applications.DefaultSmsPreference
|
||||
android:key="default_sms_app"
|
||||
android:title="@string/sms_application_title"
|
||||
settings:keywords="@string/keywords_more_default_sms_app"
|
||||
/>
|
||||
|
||||
</PreferenceScreen>
|
||||
|
@@ -24,13 +24,6 @@
|
||||
android:persistent="false"
|
||||
android:disableDependentsState="true" />
|
||||
|
||||
<com.android.settings.AppListPreference
|
||||
android:key="sms_application"
|
||||
android:title="@string/sms_application_title"
|
||||
settings:keywords="@string/keywords_more_default_sms_app"
|
||||
android:summary="%s"
|
||||
android:persistent="false" />
|
||||
|
||||
<SwitchPreference
|
||||
android:key="toggle_nfc"
|
||||
android:title="@string/nfc_quick_toggle_title"
|
||||
|
@@ -23,15 +23,17 @@ import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.preference.ListPreference;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.CheckedTextView;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ListAdapter;
|
||||
import android.widget.TextView;
|
||||
|
||||
/**
|
||||
* Extends ListPreference to allow us to show the icons for a given list of applications. We do this
|
||||
@@ -56,10 +58,10 @@ public class AppListPreference extends ListPreference {
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
LayoutInflater inflater = ((Activity)getContext()).getLayoutInflater();
|
||||
View view = inflater.inflate(R.layout.app_preference_item, parent, false);
|
||||
CheckedTextView checkedTextView = (CheckedTextView)view.findViewById(R.id.app_label);
|
||||
checkedTextView.setText(getItem(position));
|
||||
TextView textView = (TextView) view.findViewById(R.id.app_label);
|
||||
textView.setText(getItem(position));
|
||||
if (position == mSelectedIndex) {
|
||||
checkedTextView.setChecked(true);
|
||||
view.findViewById(R.id.default_label).setVisibility(View.VISIBLE);
|
||||
}
|
||||
ImageView imageView = (ImageView)view.findViewById(R.id.app_image);
|
||||
imageView.setImageDrawable(mImageDrawables[position]);
|
||||
@@ -76,14 +78,14 @@ public class AppListPreference extends ListPreference {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public void setPackageNames(String[] packageNames, String defaultPackageName) {
|
||||
public void setPackageNames(CharSequence[] packageNames, CharSequence defaultPackageName) {
|
||||
// Look up all package names in PackageManager. Skip ones we can't find.
|
||||
int foundPackages = 0;
|
||||
PackageManager pm = getContext().getPackageManager();
|
||||
ApplicationInfo[] appInfos = new ApplicationInfo[packageNames.length];
|
||||
for (int i = 0; i < packageNames.length; i++) {
|
||||
try {
|
||||
appInfos[i] = pm.getApplicationInfo(packageNames[i], 0);
|
||||
appInfos[i] = pm.getApplicationInfo(packageNames[i].toString(), 0);
|
||||
foundPackages++;
|
||||
} catch (NameNotFoundException e) {
|
||||
// Leave appInfos[i] uninitialized; it will be skipped in the list.
|
||||
@@ -123,4 +125,61 @@ public class AppListPreference extends ListPreference {
|
||||
builder.setAdapter(adapter, this);
|
||||
super.onPrepareDialogBuilder(builder);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Parcelable onSaveInstanceState() {
|
||||
Parcelable superState = super.onSaveInstanceState();
|
||||
return new SavedState(getEntryValues(), getValue(), superState);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onRestoreInstanceState(Parcelable state) {
|
||||
if (state instanceof SavedState) {
|
||||
SavedState savedState = (SavedState) state;
|
||||
setPackageNames(savedState.entryValues, savedState.value);
|
||||
super.onRestoreInstanceState(savedState.superState);
|
||||
} else {
|
||||
super.onRestoreInstanceState(state);
|
||||
}
|
||||
}
|
||||
|
||||
private static class SavedState implements Parcelable {
|
||||
|
||||
public final CharSequence[] entryValues;
|
||||
public final CharSequence value;
|
||||
public final Parcelable superState;
|
||||
|
||||
public SavedState(CharSequence[] entryValues, CharSequence value, Parcelable superState) {
|
||||
this.entryValues = entryValues;
|
||||
this.value = value;
|
||||
this.superState = superState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeCharSequenceArray(entryValues);
|
||||
dest.writeCharSequence(value);
|
||||
dest.writeParcelable(superState, flags);
|
||||
}
|
||||
|
||||
public static Creator<SavedState> CREATOR = new Creator<SavedState>() {
|
||||
@Override
|
||||
public SavedState createFromParcel(Parcel source) {
|
||||
CharSequence[] entryValues = source.readCharSequenceArray();
|
||||
CharSequence value = source.readCharSequence();
|
||||
Parcelable superState = source.readParcelable(getClass().getClassLoader());
|
||||
return new SavedState(entryValues, value, superState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SavedState[] newArray(int size) {
|
||||
return new SavedState[size];
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@@ -22,7 +22,6 @@ import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
@@ -38,7 +37,6 @@ import android.os.SystemProperties;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.preference.Preference;
|
||||
import android.preference.Preference.OnPreferenceChangeListener;
|
||||
import android.preference.PreferenceScreen;
|
||||
import android.preference.SwitchPreference;
|
||||
import android.provider.SearchIndexableResource;
|
||||
@@ -49,20 +47,17 @@ import android.util.Log;
|
||||
|
||||
import com.android.ims.ImsManager;
|
||||
import com.android.internal.logging.MetricsLogger;
|
||||
import com.android.internal.telephony.SmsApplication;
|
||||
import com.android.internal.telephony.SmsApplication.SmsApplicationData;
|
||||
import com.android.internal.telephony.TelephonyIntents;
|
||||
import com.android.internal.telephony.TelephonyProperties;
|
||||
import com.android.settings.nfc.NfcEnabler;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settings.search.Indexable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class WirelessSettings extends SettingsPreferenceFragment
|
||||
implements OnPreferenceChangeListener, Indexable {
|
||||
public class WirelessSettings extends SettingsPreferenceFragment implements Indexable {
|
||||
private static final String TAG = "WirelessSettings";
|
||||
|
||||
private static final String KEY_TOGGLE_AIRPLANE = "toggle_airplane";
|
||||
@@ -74,7 +69,6 @@ public class WirelessSettings extends SettingsPreferenceFragment
|
||||
private static final String KEY_PROXY_SETTINGS = "proxy_settings";
|
||||
private static final String KEY_MOBILE_NETWORK_SETTINGS = "mobile_network_settings";
|
||||
private static final String KEY_MANAGE_MOBILE_PLAN = "manage_mobile_plan";
|
||||
private static final String KEY_SMS_APPLICATION = "sms_application";
|
||||
private static final String KEY_TOGGLE_NSD = "toggle_nsd"; //network service discovery
|
||||
private static final String KEY_CELL_BROADCAST_SETTINGS = "cell_broadcast_settings";
|
||||
private static final String KEY_WFC_SETTINGS = "wifi_calling_settings";
|
||||
@@ -96,7 +90,6 @@ public class WirelessSettings extends SettingsPreferenceFragment
|
||||
private static final int MANAGE_MOBILE_PLAN_DIALOG_ID = 1;
|
||||
private static final String SAVED_MANAGE_MOBILE_PLAN_MSG = "mManageMobilePlanMessage";
|
||||
|
||||
private AppListPreference mSmsApplicationPreference;
|
||||
private PreferenceScreen mButtonWfc;
|
||||
|
||||
/**
|
||||
@@ -187,27 +180,6 @@ public class WirelessSettings extends SettingsPreferenceFragment
|
||||
}
|
||||
}
|
||||
|
||||
private void initSmsApplicationSetting() {
|
||||
log("initSmsApplicationSetting:");
|
||||
Collection<SmsApplicationData> smsApplications =
|
||||
SmsApplication.getApplicationCollection(getActivity());
|
||||
|
||||
// If the list is empty the dialog will be empty, but we will not crash.
|
||||
int count = smsApplications.size();
|
||||
String[] packageNames = new String[count];
|
||||
int i = 0;
|
||||
for (SmsApplicationData smsApplicationData : smsApplications) {
|
||||
packageNames[i] = smsApplicationData.mPackageName;
|
||||
i++;
|
||||
}
|
||||
String defaultPackageName = null;
|
||||
ComponentName appName = SmsApplication.getDefaultSmsApplication(getActivity(), true);
|
||||
if (appName != null) {
|
||||
defaultPackageName = appName.getPackageName();
|
||||
}
|
||||
mSmsApplicationPreference.setPackageNames(packageNames, defaultPackageName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog(int dialogId) {
|
||||
log("onCreateDialog: dialogId=" + dialogId);
|
||||
@@ -233,11 +205,6 @@ public class WirelessSettings extends SettingsPreferenceFragment
|
||||
Log.d(TAG, s);
|
||||
}
|
||||
|
||||
private boolean isSmsSupported() {
|
||||
// Some tablet has sim card but could not do telephony operations. Skip those.
|
||||
return mTm.isSmsCapable();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getMetricsCategory() {
|
||||
return MetricsLogger.WIRELESS;
|
||||
@@ -260,7 +227,6 @@ public class WirelessSettings extends SettingsPreferenceFragment
|
||||
|
||||
final int myUserId = UserHandle.myUserId();
|
||||
final boolean isSecondaryUser = myUserId != UserHandle.USER_OWNER;
|
||||
final boolean isRestrictedUser = mUm.getUserInfo(myUserId).isRestricted();
|
||||
|
||||
final Activity activity = getActivity();
|
||||
mAirplaneModePreference = (SwitchPreference) findPreference(KEY_TOGGLE_AIRPLANE);
|
||||
@@ -271,15 +237,6 @@ public class WirelessSettings extends SettingsPreferenceFragment
|
||||
mAirplaneModeEnabler = new AirplaneModeEnabler(activity, mAirplaneModePreference);
|
||||
mNfcEnabler = new NfcEnabler(activity, nfc, androidBeam);
|
||||
|
||||
mSmsApplicationPreference = (AppListPreference) findPreference(KEY_SMS_APPLICATION);
|
||||
// Restricted users cannot currently read/write SMS.
|
||||
if (isRestrictedUser) {
|
||||
removePreference(KEY_SMS_APPLICATION);
|
||||
} else {
|
||||
mSmsApplicationPreference.setOnPreferenceChangeListener(this);
|
||||
initSmsApplicationSetting();
|
||||
}
|
||||
|
||||
if (ImsManager.isWfcEnabledByPlatform(activity)) {
|
||||
mButtonWfc = (PreferenceScreen) findPreference(KEY_WFC_SETTINGS);
|
||||
} else {
|
||||
@@ -355,11 +312,6 @@ public class WirelessSettings extends SettingsPreferenceFragment
|
||||
}
|
||||
}
|
||||
|
||||
// Remove SMS Application if the device does not support SMS
|
||||
if (!isSmsSupported()) {
|
||||
removePreference(KEY_SMS_APPLICATION);
|
||||
}
|
||||
|
||||
// Remove Airplane Mode settings if it's a stationary device such as a TV.
|
||||
if (mPm.hasSystemFeature(PackageManager.FEATURE_TELEVISION)) {
|
||||
removePreference(KEY_TOGGLE_AIRPLANE);
|
||||
@@ -409,13 +361,6 @@ public class WirelessSettings extends SettingsPreferenceFragment
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
|
||||
initSmsApplicationSetting();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
@@ -473,15 +418,6 @@ public class WirelessSettings extends SettingsPreferenceFragment
|
||||
return R.string.help_url_more_networks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
if (preference == mSmsApplicationPreference && newValue != null) {
|
||||
SmsApplication.setDefaultApplication(newValue.toString(), getActivity());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* For Search.
|
||||
*/
|
||||
@@ -504,7 +440,6 @@ public class WirelessSettings extends SettingsPreferenceFragment
|
||||
final UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
|
||||
final int myUserId = UserHandle.myUserId();
|
||||
final boolean isSecondaryUser = myUserId != UserHandle.USER_OWNER;
|
||||
final boolean isRestrictedUser = um.getUserInfo(myUserId).isRestricted();
|
||||
final boolean isWimaxEnabled = !isSecondaryUser
|
||||
&& context.getResources().getBoolean(
|
||||
com.android.internal.R.bool.config_wimaxEnabled);
|
||||
@@ -542,13 +477,6 @@ public class WirelessSettings extends SettingsPreferenceFragment
|
||||
result.add(KEY_MANAGE_MOBILE_PLAN);
|
||||
}
|
||||
|
||||
// Remove SMS Application if the device does not support SMS
|
||||
TelephonyManager tm =
|
||||
(TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
|
||||
if (!tm.isSmsCapable() || isRestrictedUser) {
|
||||
result.add(KEY_SMS_APPLICATION);
|
||||
}
|
||||
|
||||
final PackageManager pm = context.getPackageManager();
|
||||
|
||||
// Remove Airplane Mode settings if it's a stationary device such as a TV.
|
||||
|
@@ -16,35 +16,27 @@
|
||||
package com.android.settings.applications;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.os.Bundle;
|
||||
import android.preference.Preference;
|
||||
import android.provider.SearchIndexableResource;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.internal.logging.MetricsLogger;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settings.applications.ApplicationsState.AppEntry;
|
||||
import com.android.settings.applications.ApplicationsState.Callbacks;
|
||||
import com.android.settings.applications.ApplicationsState.Session;
|
||||
import com.android.settings.applications.PermissionsInfo.Callback;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settings.search.Indexable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class AdvancedAppSettings extends SettingsPreferenceFragment implements Callbacks, Callback,
|
||||
Indexable {
|
||||
public class AdvancedAppSettings extends SettingsPreferenceFragment implements
|
||||
ApplicationsState.Callbacks, PermissionsInfo.Callback {
|
||||
|
||||
static final String TAG = "AdvancedAppSettings";
|
||||
static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
|
||||
|
||||
private static final String KEY_APP_PERM = "manage_perms";
|
||||
private static final String KEY_APP_DOMAIN_URLS = "domain_urls";
|
||||
private static final String KEY_DEFAULT_EMERGENCY_APP = "default_emergency_app";
|
||||
|
||||
private ApplicationsState mApplicationsState;
|
||||
private Session mSession;
|
||||
@@ -63,10 +55,6 @@ public class AdvancedAppSettings extends SettingsPreferenceFragment implements C
|
||||
mAppPermsPreference = findPreference(KEY_APP_PERM);
|
||||
mAppDomainURLsPreference = findPreference(KEY_APP_DOMAIN_URLS);
|
||||
updateUI();
|
||||
|
||||
if (!DefaultEmergencyPreference.isAvailable(getActivity())) {
|
||||
removePreference(KEY_DEFAULT_EMERGENCY_APP);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateUI() {
|
||||
@@ -142,26 +130,4 @@ public class AdvancedAppSettings extends SettingsPreferenceFragment implements C
|
||||
mPermissionsInfo.getRuntimePermAppsGrantedCount(),
|
||||
mPermissionsInfo.getRuntimePermAppsCount()));
|
||||
}
|
||||
|
||||
public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider() {
|
||||
@Override
|
||||
public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
|
||||
boolean enabled) {
|
||||
ArrayList<SearchIndexableResource> result = new ArrayList<>(1);
|
||||
SearchIndexableResource sir = new SearchIndexableResource(context);
|
||||
sir.xmlResId = R.xml.advanced_apps;
|
||||
result.add(sir);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getNonIndexableKeys(Context context) {
|
||||
ArrayList<String> result = new ArrayList<>(1);
|
||||
if (!DefaultEmergencyPreference.isAvailable(context)) {
|
||||
result.add(KEY_DEFAULT_EMERGENCY_APP);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@@ -22,15 +22,14 @@ import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.net.Uri;
|
||||
import android.os.UserHandle;
|
||||
import android.preference.ListPreference;
|
||||
import android.util.ArrayMap;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.AppListPreference;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DefaultBrowserPreference extends ListPreference {
|
||||
public class DefaultBrowserPreference extends AppListPreference {
|
||||
|
||||
final private PackageManager mPm;
|
||||
|
||||
@@ -42,14 +41,13 @@ public class DefaultBrowserPreference extends ListPreference {
|
||||
}
|
||||
|
||||
private void loadBrowserApps() {
|
||||
ArrayMap<String, CharSequence> browsers = resolveBrowserApps();
|
||||
List<String> browsers = resolveBrowserApps();
|
||||
|
||||
setEntries(browsers.values().toArray(new CharSequence[browsers.size()]));
|
||||
setEntryValues(browsers.keySet().toArray(new String[browsers.size()]));
|
||||
setPackageNames(browsers.toArray(new String[browsers.size()]), null);
|
||||
}
|
||||
|
||||
private ArrayMap<String, CharSequence> resolveBrowserApps() {
|
||||
ArrayMap<String, CharSequence> result = new ArrayMap<>();
|
||||
private List<String> resolveBrowserApps() {
|
||||
List<String> result = new ArrayList<>();
|
||||
|
||||
// Create an Intent that will match ALL Browser Apps
|
||||
Intent intent = new Intent();
|
||||
@@ -58,22 +56,17 @@ public class DefaultBrowserPreference extends ListPreference {
|
||||
intent.setData(Uri.parse("http:"));
|
||||
|
||||
// Resolve that intent and check that the handleAllWebDataURI boolean is set
|
||||
PackageManager packageManager = getContext().getPackageManager();
|
||||
List<ResolveInfo> list = packageManager.queryIntentActivitiesAsUser(intent, 0,
|
||||
UserHandle.myUserId());
|
||||
List<ResolveInfo> list = mPm.queryIntentActivitiesAsUser(intent, 0, UserHandle.myUserId());
|
||||
|
||||
final int count = list.size();
|
||||
for (int i=0; i<count; i++) {
|
||||
ResolveInfo info = list.get(i);
|
||||
if (info.activityInfo == null || result.containsKey(info.activityInfo.packageName)
|
||||
if (info.activityInfo == null || result.contains(info.activityInfo.packageName)
|
||||
|| !info.handleAllWebDataURI) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String packageName = info.activityInfo.packageName;
|
||||
CharSequence label = info.activityInfo.applicationInfo.loadLabel(packageManager);
|
||||
|
||||
result.put(packageName, label);
|
||||
result.add(info.activityInfo.packageName);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@@ -24,22 +24,22 @@ import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.preference.ListPreference;
|
||||
import android.provider.Settings;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.text.TextUtils;
|
||||
import android.util.ArrayMap;
|
||||
import android.util.ArraySet;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import com.android.settings.AppListPreference;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* A preference for choosing the default emergency app
|
||||
*/
|
||||
public class DefaultEmergencyPreference extends ListPreference {
|
||||
public class DefaultEmergencyPreference extends AppListPreference {
|
||||
|
||||
private final ContentResolver mContentResolver;
|
||||
|
||||
@@ -52,25 +52,6 @@ public class DefaultEmergencyPreference extends ListPreference {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Parcelable onSaveInstanceState() {
|
||||
Parcelable superState = super.onSaveInstanceState();
|
||||
return new SavedState(getEntries(), getEntryValues(), getSummary(), superState);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onRestoreInstanceState(Parcelable state) {
|
||||
if (state instanceof SavedState) {
|
||||
SavedState savedState = (SavedState) state;
|
||||
setEntries(savedState.entries);
|
||||
setEntryValues(savedState.entryValues);
|
||||
setSummary(savedState.summary);
|
||||
super.onRestoreInstanceState(savedState.superState);
|
||||
} else {
|
||||
super.onRestoreInstanceState(state);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean persistString(String value) {
|
||||
String previousValue = Settings.Secure.getString(mContentResolver,
|
||||
@@ -86,25 +67,23 @@ public class DefaultEmergencyPreference extends ListPreference {
|
||||
}
|
||||
|
||||
private void load() {
|
||||
new AsyncTask<Void, Void, ArrayMap<String, CharSequence>>() {
|
||||
new AsyncTask<Void, Void, Set<String>>() {
|
||||
@Override
|
||||
protected ArrayMap<String, CharSequence> doInBackground(Void[] params) {
|
||||
protected Set<String> doInBackground(Void[] params) {
|
||||
return resolveAssistPackageAndQueryApps();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(ArrayMap<String, CharSequence> entries) {
|
||||
setEntries(entries.values().toArray(new CharSequence[entries.size()]));
|
||||
setEntryValues(entries.keySet().toArray(new String[entries.size()]));
|
||||
|
||||
setValue(Settings.Secure.getString(mContentResolver,
|
||||
Settings.Secure.EMERGENCY_ASSISTANCE_APPLICATION));
|
||||
protected void onPostExecute(Set<String> entries) {
|
||||
String currentPkg = Settings.Secure.getString(mContentResolver,
|
||||
Settings.Secure.EMERGENCY_ASSISTANCE_APPLICATION);
|
||||
setPackageNames(entries.toArray(new String[entries.size()]), currentPkg);
|
||||
}
|
||||
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
|
||||
private ArrayMap<String, CharSequence> resolveAssistPackageAndQueryApps() {
|
||||
ArrayMap<String, CharSequence> packages = new ArrayMap<>();
|
||||
private Set<String> resolveAssistPackageAndQueryApps() {
|
||||
Set<String> packages = new ArraySet<>();
|
||||
|
||||
Intent queryIntent = new Intent(TelephonyManager.ACTION_EMERGENCY_ASSISTANCE);
|
||||
PackageManager packageManager = getContext().getPackageManager();
|
||||
@@ -113,15 +92,13 @@ public class DefaultEmergencyPreference extends ListPreference {
|
||||
PackageInfo bestMatch = null;
|
||||
for (int i = 0; i < infos.size(); i++) {
|
||||
if (infos.get(i) == null || infos.get(i).activityInfo == null
|
||||
|| packages.containsKey(infos.get(i).activityInfo.packageName)) {
|
||||
|| packages.contains(infos.get(i).activityInfo.packageName)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String packageName = infos.get(i).activityInfo.packageName;
|
||||
CharSequence label = infos.get(i).activityInfo.applicationInfo
|
||||
.loadLabel(packageManager);
|
||||
|
||||
packages.put(packageName, label);
|
||||
packages.add(packageName);
|
||||
|
||||
PackageInfo packageInfo;
|
||||
try {
|
||||
@@ -142,7 +119,7 @@ public class DefaultEmergencyPreference extends ListPreference {
|
||||
String defaultPackage = Settings.Secure.getString(mContentResolver,
|
||||
Settings.Secure.EMERGENCY_ASSISTANCE_APPLICATION);
|
||||
boolean defaultMissing = TextUtils.isEmpty(defaultPackage)
|
||||
|| !packages.containsKey(defaultPackage);
|
||||
|| !packages.contains(defaultPackage);
|
||||
if (bestMatch != null && defaultMissing) {
|
||||
Settings.Secure.putString(mContentResolver,
|
||||
Settings.Secure.EMERGENCY_ASSISTANCE_APPLICATION,
|
||||
@@ -161,49 +138,4 @@ public class DefaultEmergencyPreference extends ListPreference {
|
||||
return info.applicationInfo != null
|
||||
&& (info.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
|
||||
}
|
||||
|
||||
private static class SavedState implements Parcelable {
|
||||
|
||||
public final CharSequence[] entries;
|
||||
public final CharSequence[] entryValues;
|
||||
public final CharSequence summary;
|
||||
public final Parcelable superState;
|
||||
|
||||
public SavedState(CharSequence[] entries, CharSequence[] entryValues,
|
||||
CharSequence summary, Parcelable superState) {
|
||||
this.entries = entries;
|
||||
this.entryValues = entryValues;
|
||||
this.summary = summary;
|
||||
this.superState = superState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeCharSequenceArray(entries);
|
||||
dest.writeCharSequenceArray(entryValues);
|
||||
dest.writeCharSequence(summary);
|
||||
dest.writeParcelable(superState, flags);
|
||||
}
|
||||
|
||||
public Creator<SavedState> CREATOR = new Creator<SavedState>() {
|
||||
@Override
|
||||
public SavedState createFromParcel(Parcel source) {
|
||||
CharSequence[] entries = source.readCharSequenceArray();
|
||||
CharSequence[] entryValues = source.readCharSequenceArray();
|
||||
CharSequence summary = source.readCharSequence();
|
||||
Parcelable superState = source.readParcelable(getClass().getClassLoader());
|
||||
return new SavedState(entries, entryValues, summary, superState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SavedState[] newArray(int size) {
|
||||
return new SavedState[size];
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright (C) 2015 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.applications;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.text.TextUtils;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import com.android.internal.telephony.SmsApplication;
|
||||
import com.android.internal.telephony.SmsApplication.SmsApplicationData;
|
||||
import com.android.settings.AppListPreference;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Objects;
|
||||
|
||||
public class DefaultSmsPreference extends AppListPreference {
|
||||
|
||||
public DefaultSmsPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
|
||||
loadSmsApps();
|
||||
}
|
||||
|
||||
private void loadSmsApps() {
|
||||
Collection<SmsApplicationData> smsApplications =
|
||||
SmsApplication.getApplicationCollection(getContext());
|
||||
|
||||
int count = smsApplications.size();
|
||||
String[] packageNames = new String[count];
|
||||
int i = 0;
|
||||
for (SmsApplicationData smsApplicationData : smsApplications) {
|
||||
packageNames[i++] = smsApplicationData.mPackageName;
|
||||
}
|
||||
setPackageNames(packageNames, getDefaultPackage());
|
||||
}
|
||||
|
||||
private String getDefaultPackage() {
|
||||
ComponentName appName = SmsApplication.getDefaultSmsApplication(getContext(), true);
|
||||
if (appName != null) {
|
||||
return appName.getPackageName();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean persistString(String value) {
|
||||
if (!TextUtils.isEmpty(value) && !Objects.equals(value, getDefaultPackage())) {
|
||||
SmsApplication.setDefaultApplication(value, getContext());
|
||||
}
|
||||
setSummary(getEntry());
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean isAvailable(Context context) {
|
||||
TelephonyManager tm =
|
||||
(TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
|
||||
return tm.isSmsCapable();
|
||||
}
|
||||
|
||||
}
|
@@ -17,26 +17,37 @@
|
||||
package com.android.settings.applications;
|
||||
|
||||
import android.annotation.Nullable;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.preference.Preference;
|
||||
import android.provider.SearchIndexableResource;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import com.android.settings.InstrumentedFragment;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
|
||||
import com.android.settings.InstrumentedFragment;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settings.search.Indexable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class ManageDefaultApps extends SettingsPreferenceFragment
|
||||
implements Preference.OnPreferenceClickListener {
|
||||
implements Preference.OnPreferenceClickListener, Indexable {
|
||||
|
||||
private static final String TAG = ManageDefaultApps.class.getSimpleName();
|
||||
|
||||
private static final String KEY_DEFAULT_BROWSER = "default_browser";
|
||||
private static final String KEY_SMS_APPLICATION = "default_sms_app";
|
||||
private static final String KEY_DEFAULT_EMERGENCY_APP = "default_emergency_app";
|
||||
|
||||
private DefaultBrowserPreference mDefaultBrowserPreference;
|
||||
private PackageManager mPm;
|
||||
@@ -63,6 +74,18 @@ public class ManageDefaultApps extends SettingsPreferenceFragment
|
||||
return mPm.setDefaultBrowserPackageName(packageName.toString(), myUserId);
|
||||
}
|
||||
});
|
||||
final boolean isRestrictedUser = UserManager.get(getActivity())
|
||||
.getUserInfo(myUserId).isRestricted();
|
||||
|
||||
// Restricted users cannot currently read/write SMS.
|
||||
// Remove SMS Application if the device does not support SMS
|
||||
if (isRestrictedUser || !DefaultSmsPreference.isAvailable(getActivity())) {
|
||||
removePreference(KEY_SMS_APPLICATION);
|
||||
}
|
||||
|
||||
if (!DefaultEmergencyPreference.isAvailable(getActivity())) {
|
||||
removePreference(KEY_DEFAULT_EMERGENCY_APP);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -96,4 +119,33 @@ public class ManageDefaultApps extends SettingsPreferenceFragment
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider() {
|
||||
@Override
|
||||
public List<SearchIndexableResource> getXmlResourcesToIndex(
|
||||
Context context, boolean enabled) {
|
||||
SearchIndexableResource sir = new SearchIndexableResource(context);
|
||||
sir.xmlResId = R.xml.default_apps;
|
||||
return Arrays.asList(sir);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getNonIndexableKeys(Context context) {
|
||||
final ArrayList<String> result = new ArrayList<String>();
|
||||
|
||||
// Remove SMS Application if the device does not support SMS
|
||||
final boolean isRestrictedUser = UserManager.get(context)
|
||||
.getUserInfo(UserHandle.myUserId()).isRestricted();
|
||||
if (!DefaultSmsPreference.isAvailable(context) || isRestrictedUser) {
|
||||
result.add(KEY_SMS_APPLICATION);
|
||||
}
|
||||
|
||||
if (!DefaultEmergencyPreference.isAvailable(context)) {
|
||||
result.add(KEY_DEFAULT_EMERGENCY_APP);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@@ -31,6 +31,7 @@ import com.android.settings.WifiCallingSettings;
|
||||
import com.android.settings.WirelessSettings;
|
||||
import com.android.settings.accessibility.AccessibilitySettings;
|
||||
import com.android.settings.applications.AdvancedAppSettings;
|
||||
import com.android.settings.applications.ManageDefaultApps;
|
||||
import com.android.settings.bluetooth.BluetoothSettings;
|
||||
import com.android.settings.deviceinfo.StorageSettings;
|
||||
import com.android.settings.deviceinfo.UsbSettings;
|
||||
@@ -138,6 +139,7 @@ public final class Ranking {
|
||||
|
||||
// Advanced app settings
|
||||
sRankMap.put(AdvancedAppSettings.class.getName(), RANK_APPS);
|
||||
sRankMap.put(ManageDefaultApps.class.getName(), RANK_APPS);
|
||||
|
||||
// Users
|
||||
sRankMap.put(UserSettings.class.getName(), RANK_USERS);
|
||||
|
@@ -33,6 +33,7 @@ import com.android.settings.WifiCallingSettings;
|
||||
import com.android.settings.WirelessSettings;
|
||||
import com.android.settings.accessibility.AccessibilitySettings;
|
||||
import com.android.settings.applications.AdvancedAppSettings;
|
||||
import com.android.settings.applications.ManageDefaultApps;
|
||||
import com.android.settings.bluetooth.BluetoothSettings;
|
||||
import com.android.settings.deviceinfo.StorageSettings;
|
||||
import com.android.settings.deviceinfo.UsbSettings;
|
||||
@@ -201,10 +202,17 @@ public final class SearchIndexableResources {
|
||||
sResMap.put(AdvancedAppSettings.class.getName(),
|
||||
new SearchIndexableResource(
|
||||
Ranking.getRankForClassName(AdvancedAppSettings.class.getName()),
|
||||
NO_DATA_RES_ID,
|
||||
R.xml.advanced_apps,
|
||||
AdvancedAppSettings.class.getName(),
|
||||
R.drawable.ic_settings_applications));
|
||||
|
||||
sResMap.put(ManageDefaultApps.class.getName(),
|
||||
new SearchIndexableResource(
|
||||
Ranking.getRankForClassName(ManageDefaultApps.class.getName()),
|
||||
NO_DATA_RES_ID,
|
||||
ManageDefaultApps.class.getName(),
|
||||
R.drawable.ic_settings_applications));
|
||||
|
||||
sResMap.put(UserSettings.class.getName(),
|
||||
new SearchIndexableResource(
|
||||
Ranking.getRankForClassName(UserSettings.class.getName()),
|
||||
|
Reference in New Issue
Block a user