OSDN Git Service

Merge "Aligned buttons on the Wi-Fi Assistant Card." into lmp-dev
authorPauloftheWest <paulofthewest@google.com>
Thu, 4 Sep 2014 12:50:03 +0000 (12:50 +0000)
committerAndroid (Google) Code Review <android-gerrit@google.com>
Thu, 4 Sep 2014 12:50:04 +0000 (12:50 +0000)
13 files changed:
AndroidManifest.xml
res/xml/wireless_settings.xml
src/com/android/settings/DataUsageSummary.java
src/com/android/settings/Utils.java
src/com/android/settings/accessibility/AccessibilitySettings.java
src/com/android/settings/accounts/AccountSettings.java
src/com/android/settings/applications/InstalledAppDetails.java
src/com/android/settings/notification/NotificationAppList.java
src/com/android/settings/search/Index.java
src/com/android/settings/sim/SimSettings.java
src/com/android/settings/users/UserSettings.java
src/com/android/settings/wifi/WifiSettings.java
src/com/android/settings/wifi/WpsDialog.java

index 58e7f70..1e5a14f 100644 (file)
                 android:value="com.android.settings.vpn2.VpnSettings" />
             <meta-data android:name="com.android.settings.TOP_LEVEL_HEADER_ID"
                 android:resource="@id/wireless_settings" />
+            <meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
+                android:value="true" />
         </activity>
 
         <activity android:name="Settings$DateTimeSettingsActivity"
index f30e393..7db1ed7 100644 (file)
@@ -16,8 +16,7 @@
 
 <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
                   xmlns:settings="http://schemas.android.com/apk/res/com.android.settings"
-        android:title="wireless_settings"
-        android:key="@string/radio_controls_title">
+        android:title="@string/radio_controls_title">
 
     <SwitchPreference
         android:key="toggle_airplane"
index 009c758..17c6d88 100644 (file)
@@ -402,7 +402,6 @@ public class DataUsageSummary extends HighlightingFragment implements Indexable
             mAppSwitches = (LinearLayout) mAppDetail.findViewById(R.id.app_switches);
 
             mAppSettings = (Button) mAppDetail.findViewById(R.id.app_settings);
-            mAppSettings.setOnClickListener(mAppSettingsListener);
 
             mAppRestrict = new Switch(inflater.getContext());
             mAppRestrict.setClickable(false);
@@ -860,11 +859,24 @@ public class DataUsageSummary extends HighlightingFragment implements Indexable
                 }
             }
 
+            mAppSettings.setOnClickListener(new OnClickListener() {
+                @Override
+                public void onClick(View v) {
+                    if (!isAdded()) {
+                        return;
+                    }
+
+                    // TODO: target towards entire UID instead of just first package
+                    getActivity().startActivityAsUser(mAppSettingsIntent,
+                            new UserHandle(UserHandle.getUserId(uid)));
+                }
+            });
             mAppSettings.setEnabled(matchFound);
             mAppSettings.setVisibility(View.VISIBLE);
 
         } else {
             mAppSettingsIntent = null;
+            mAppSettings.setOnClickListener(null);
             mAppSettings.setVisibility(View.GONE);
         }
 
@@ -1117,16 +1129,6 @@ public class DataUsageSummary extends HighlightingFragment implements Indexable
         }
     };
 
-    private OnClickListener mAppSettingsListener = new OnClickListener() {
-        @Override
-        public void onClick(View v) {
-            if (!isAdded()) return;
-
-            // TODO: target torwards entire UID instead of just first package
-            startActivity(mAppSettingsIntent);
-        }
-    };
-
     private OnItemClickListener mListListener = new OnItemClickListener() {
         @Override
         public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
index 4fb166a..47ff6af 100644 (file)
@@ -30,9 +30,11 @@ import android.content.Context;
 import android.content.DialogInterface;
 import android.content.Intent;
 import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageInfo;
 import android.content.pm.PackageManager;
 import android.content.pm.PackageManager.NameNotFoundException;
 import android.content.pm.ResolveInfo;
+import android.content.pm.Signature;
 import android.content.pm.UserInfo;
 import android.content.res.Resources;
 import android.content.res.Resources.NotFoundException;
@@ -839,4 +841,34 @@ public final class Utils {
 
         return tm.getSimCount() > 0;
     }
+
+    /**
+     * Determine whether a package is a "system package", in which case certain things (like
+     * disabling notifications or disabling the package altogether) should be disallowed.
+     */
+    public static boolean isSystemPackage(PackageManager pm, PackageInfo pkg) {
+        if (sSystemSignature == null) {
+            sSystemSignature = new Signature[]{ getSystemSignature(pm) };
+        }
+        return sSystemSignature[0] != null && sSystemSignature[0].equals(getFirstSignature(pkg));
+    }
+
+    private static Signature[] sSystemSignature;
+
+    private static Signature getFirstSignature(PackageInfo pkg) {
+        if (pkg != null && pkg.signatures != null && pkg.signatures.length > 0) {
+            return pkg.signatures[0];
+        }
+        return null;
+    }
+
+    private static Signature getSystemSignature(PackageManager pm) {
+        try {
+            final PackageInfo sys = pm.getPackageInfo("android", PackageManager.GET_SIGNATURES);
+            return getFirstSignature(sys);
+        } catch (NameNotFoundException e) {
+        }
+        return null;
+    }
+
 }
index eff5fb6..92c478e 100644 (file)
@@ -513,19 +513,13 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
 
         if (mServicesCategory.getPreferenceCount() == 0) {
             if (mNoServicesMessagePreference == null) {
-                mNoServicesMessagePreference = new Preference(getActivity()) {
-                        @Override
-                    protected void onBindView(View view) {
-                        super.onBindView(view);
-                        TextView summaryView = (TextView) view.findViewById(R.id.summary);
-                        String title = getString(R.string.accessibility_no_services_installed);
-                        summaryView.setText(title);
-                    }
-                };
+                mNoServicesMessagePreference = new Preference(getActivity());
                 mNoServicesMessagePreference.setPersistent(false);
                 mNoServicesMessagePreference.setLayoutResource(
                         R.layout.text_description_preference);
                 mNoServicesMessagePreference.setSelectable(false);
+                mNoServicesMessagePreference.setSummary(
+                        getString(R.string.accessibility_no_services_installed));
             }
             mServicesCategory.addPreference(mNoServicesMessagePreference);
         }
index 891fdbb..9bcef13 100644 (file)
@@ -31,9 +31,6 @@ import android.content.Intent;
 import android.content.IntentFilter;
 import android.content.pm.UserInfo;
 import android.graphics.drawable.Drawable;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-import android.graphics.drawable.BitmapDrawable;
 import android.os.Bundle;
 import android.os.UserHandle;
 import android.os.UserManager;
@@ -117,6 +114,7 @@ public class AccountSettings extends SettingsPreferenceFragment
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         mUm = (UserManager) getSystemService(Context.USER_SERVICE);
+        mProfileNotAvailablePreference = new Preference(getActivity());
         setHasOptionsMenu(true);
     }
 
@@ -335,16 +333,11 @@ public class AccountSettings extends SettingsPreferenceFragment
             }
         } else {
             // Put a label instead of the accounts list
-            synchronized (this) {
-                if (mProfileNotAvailablePreference == null) {
-                    mProfileNotAvailablePreference = new Preference(getActivity());
-                    mProfileNotAvailablePreference.setEnabled(false);
-                    mProfileNotAvailablePreference.setIcon(R.drawable.empty_icon);
-                    mProfileNotAvailablePreference.setTitle(null);
-                    mProfileNotAvailablePreference.setSummary(
-                            R.string.managed_profile_not_available_label);
-                }
-            }
+            mProfileNotAvailablePreference.setEnabled(false);
+            mProfileNotAvailablePreference.setIcon(R.drawable.empty_icon);
+            mProfileNotAvailablePreference.setTitle(null);
+            mProfileNotAvailablePreference.setSummary(
+                    R.string.managed_profile_not_available_label);
             profileData.preferenceGroup.addPreference(mProfileNotAvailablePreference);
         }
         if (profileData.removeWorkProfilePreference != null) {
index adec63a..4b1bc10 100755 (executable)
@@ -316,22 +316,13 @@ public class InstalledAppDetails extends Fragment
         }
     }
 
-    private boolean isThisASystemPackage() {
-        try {
-            PackageInfo sys = mPm.getPackageInfo("android", PackageManager.GET_SIGNATURES);
-            return (mPackageInfo != null && mPackageInfo.signatures != null &&
-                    sys.signatures[0].equals(mPackageInfo.signatures[0]));
-        } catch (PackageManager.NameNotFoundException e) {
-            return false;
-        }
-    }
-
     private boolean handleDisableable(Button button) {
         boolean disableable = false;
         // Try to prevent the user from bricking their phone
         // by not allowing disabling of apps signed with the
         // system cert and any launcher app in the system.
-        if (mHomePackages.contains(mAppEntry.info.packageName) || isThisASystemPackage()) {
+        if (mHomePackages.contains(mAppEntry.info.packageName)
+                || Utils.isSystemPackage(mPm, mPackageInfo)) {
             // Disable button for core system applications.
             button.setText(R.string.disable_text);
         } else if (mAppEntry.info.enabled) {
@@ -427,7 +418,7 @@ public class InstalledAppDetails extends Fragment
             // this does not bode well
         }
         mNotificationSwitch.setChecked(enabled);
-        if (isThisASystemPackage()) {
+        if (Utils.isSystemPackage(mPm, mPackageInfo)) {
             mNotificationSwitch.setEnabled(false);
         } else {
             mNotificationSwitch.setEnabled(true);
index 3879bef..7ca4b18 100644 (file)
@@ -193,30 +193,6 @@ public class NotificationAppList extends PinnedHeaderListFragment
                 parent.getPaddingEnd() - eat, parent.getPaddingBottom());
     }
 
-    private boolean isSystemApp(PackageInfo pkg) {
-        if (mSystemSignature == null) {
-            mSystemSignature = new Signature[]{ getSystemSignature() };
-        }
-        return mSystemSignature[0] != null && mSystemSignature[0].equals(getFirstSignature(pkg));
-    }
-
-    private static Signature getFirstSignature(PackageInfo pkg) {
-        if (pkg != null && pkg.signatures != null && pkg.signatures.length > 0) {
-            return pkg.signatures[0];
-        }
-        return null;
-    }
-
-    private Signature getSystemSignature() {
-        final PackageManager pm = mContext.getPackageManager();
-        try {
-            final PackageInfo sys = pm.getPackageInfo("android", PackageManager.GET_SIGNATURES);
-            return getFirstSignature(sys);
-        } catch (NameNotFoundException e) {
-        }
-        return null;
-    }
-
     private static class ViewHolder {
         ViewGroup row;
         ImageView icon;
@@ -375,6 +351,7 @@ public class NotificationAppList extends PinnedHeaderListFragment
         public boolean priority;
         public boolean sensitive;
         public boolean first;  // first app in section
+        public boolean isSystem;
     }
 
     private static final Comparator<AppRow> mRowComparator = new Comparator<AppRow>() {
@@ -385,6 +362,7 @@ public class NotificationAppList extends PinnedHeaderListFragment
         }
     };
 
+
     public static AppRow loadAppRow(PackageManager pm, PackageInfo pkg, Backend backend) {
         final AppRow row = new AppRow();
         row.pkg = pkg.packageName;
@@ -399,16 +377,28 @@ public class NotificationAppList extends PinnedHeaderListFragment
         row.banned = backend.getNotificationsBanned(row.pkg, row.uid);
         row.priority = backend.getHighPriority(row.pkg, row.uid);
         row.sensitive = backend.getSensitive(row.pkg, row.uid);
+        row.isSystem = Utils.isSystemPackage(pm, pkg);
         return row;
     }
 
-    public static void collectConfigActivities(PackageManager pm, ArrayMap<String, AppRow> rows) {
+    public static List<ResolveInfo> queryNotificationConfigActivities(PackageManager pm) {
         if (DEBUG) Log.d(TAG, "APP_NOTIFICATION_PREFS_CATEGORY_INTENT is "
                 + APP_NOTIFICATION_PREFS_CATEGORY_INTENT);
         final List<ResolveInfo> resolveInfos = pm.queryIntentActivities(
                 APP_NOTIFICATION_PREFS_CATEGORY_INTENT,
-                PackageManager.MATCH_DEFAULT_ONLY);
-        if (DEBUG) Log.d(TAG, "Found " + resolveInfos.size() + " preference activities");
+                0 //PackageManager.MATCH_DEFAULT_ONLY
+        );
+        return resolveInfos;
+    }
+    public static void collectConfigActivities(PackageManager pm, ArrayMap<String, AppRow> rows) {
+        final List<ResolveInfo> resolveInfos = queryNotificationConfigActivities(pm);
+        applyConfigActivities(pm, rows, resolveInfos);
+    }
+
+    public static void applyConfigActivities(PackageManager pm, ArrayMap<String, AppRow> rows,
+            List<ResolveInfo> resolveInfos) {
+        if (DEBUG) Log.d(TAG, "Found " + resolveInfos.size() + " preference activities"
+                + (resolveInfos.size() == 0 ? " ;_;" : ""));
         for (ResolveInfo ri : resolveInfos) {
             final ActivityInfo activityInfo = ri.activityInfo;
             final ApplicationInfo appInfo = activityInfo.applicationInfo;
@@ -425,7 +415,7 @@ public class NotificationAppList extends PinnedHeaderListFragment
                         + activityInfo.packageName);
                 continue;
             }
-            row.settingsIntent = new Intent(Intent.ACTION_MAIN)
+            row.settingsIntent = new Intent(APP_NOTIFICATION_PREFS_CATEGORY_INTENT)
                     .setClassName(activityInfo.packageName, activityInfo.name);
         }
     }
@@ -439,18 +429,41 @@ public class NotificationAppList extends PinnedHeaderListFragment
                 mRows.clear();
                 mSortedRows.clear();
 
-                // collect all non-system apps
+                // collect all launchable apps, plus any packages that have notification settings
                 final PackageManager pm = mContext.getPackageManager();
-                for (PackageInfo pkg : pm.getInstalledPackages(PackageManager.GET_SIGNATURES)) {
-                    if (pkg.applicationInfo == null || isSystemApp(pkg)) {
-                        if (DEBUG) Log.d(TAG, "Skipping " + pkg.packageName);
+                final List<ResolveInfo> resolvedApps = pm.queryIntentActivities(
+                        new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER),
+                        PackageManager.MATCH_DEFAULT_ONLY
+                );
+                final List<ResolveInfo> resolvedConfigActivities
+                        = queryNotificationConfigActivities(pm);
+                resolvedApps.addAll(resolvedConfigActivities);
+
+                for (ResolveInfo info : resolvedApps) {
+                    String pkgName = info.activityInfo.packageName;
+                    if (mRows.containsKey(pkgName)) {
+                        // we already have this app, thanks
+                        continue;
+                    }
+
+                    PackageInfo pkg = null;
+                    try {
+                        pkg = pm.getPackageInfo(pkgName,
+                                PackageManager.GET_SIGNATURES);
+                    } catch (NameNotFoundException e) {
+                        if (DEBUG) Log.d(TAG, "Skipping (NNFE): " + pkg.packageName);
+                        continue;
+                    }
+                    if (info.activityInfo.applicationInfo == null) {
+                        if (DEBUG) Log.d(TAG, "Skipping (no applicationInfo): " + pkg.packageName);
                         continue;
                     }
                     final AppRow row = loadAppRow(pm, pkg, mBackend);
-                    mRows.put(row.pkg, row);
+                    mRows.put(pkgName, row);
                 }
-                // collect config activities
-                collectConfigActivities(pm, mRows);
+
+                // add config activities to the list
+                applyConfigActivities(pm, mRows, resolvedConfigActivities);
                 // sort rows
                 mSortedRows.addAll(mRows.values());
                 Collections.sort(mSortedRows, mRowComparator);
index f5a2fa9..db60dfe 100644 (file)
@@ -1025,8 +1025,14 @@ public class Index {
             return;
         }
 
+        // The DocID should contains more than the title string itself (you may have two settings
+        // with the same title). So we need to use a combination of the title and the screenTitle.
+        StringBuilder sb = new StringBuilder(updatedTitle);
+        sb.append(screenTitle);
+        int docId = sb.toString().hashCode();
+
         ContentValues values = new ContentValues();
-        values.put(IndexColumns.DOCID, updatedTitle.hashCode());
+        values.put(IndexColumns.DOCID, docId);
         values.put(IndexColumns.LOCALE, locale);
         values.put(IndexColumns.DATA_RANK, rank);
         values.put(IndexColumns.DATA_TITLE, updatedTitle);
index 6526996..abfeccb 100644 (file)
@@ -99,7 +99,7 @@ public class SimSettings extends RestrictedSettingsFragment implements Indexable
         super.onCreate(bundle);
 
         if (mSubInfoList == null) {
-            mSubInfoList = SubscriptionManager.getActivatedSubInfoList(getActivity());
+            mSubInfoList = SubscriptionManager.getActiveSubInfoList();
         }
 
         createPreferences();
@@ -135,7 +135,7 @@ public class SimSettings extends RestrictedSettingsFragment implements Indexable
     }
 
     private void updateSimSlotValues() {
-        SubscriptionManager.getAllSubInfoList(getActivity());
+        SubscriptionManager.getAllSubInfoList();
         final PreferenceCategory simCards = (PreferenceCategory)findPreference(SIM_CARD_CATEGORY);
         final PreferenceScreen prefScreen = getPreferenceScreen();
 
@@ -197,7 +197,7 @@ public class SimSettings extends RestrictedSettingsFragment implements Indexable
 
     private void updateSmsValues() {
         final DropDownPreference simPref = (DropDownPreference) findPreference(KEY_SMS);
-        final SubInfoRecord sir = findRecordBySubId(SubscriptionManager.getPreferredSmsSubId());
+        final SubInfoRecord sir = findRecordBySubId(SubscriptionManager.getDefaultSmsSubId());
         if (sir != null) {
             simPref.setSelectedItem(sir.mSlotId + 1);
         }
@@ -344,13 +344,13 @@ public class SimSettings extends RestrictedSettingsFragment implements Indexable
                     final Spinner displayNumbers =
                         (Spinner)dialogLayout.findViewById(R.id.display_numbers);
 
-                    SubscriptionManager.setDisplayNumberFormat(getActivity(),
+                    SubscriptionManager.setDisplayNumberFormat(
                         displayNumbers.getSelectedItemPosition() == 0
                             ? SubscriptionManager.DISPLAY_NUMBER_LAST
                             : SubscriptionManager.DISPLAY_NUMBER_FIRST, mSubInfoRecord.mSubId);
 
                     mSubInfoRecord.mDisplayName = nameText.getText().toString();
-                    SubscriptionManager.setDisplayName(getActivity(), mSubInfoRecord.mDisplayName,
+                    SubscriptionManager.setDisplayName(mSubInfoRecord.mDisplayName,
                         mSubInfoRecord.mSubId);
 
                     updateAllOptions();
index c0ffca5..f5ea6aa 100644 (file)
@@ -418,9 +418,11 @@ public class UserSettings extends SettingsPreferenceFragment
         int userId = newUserInfo.id;
         UserHandle user = new UserHandle(userId);
         mUserManager.setUserRestriction(UserManager.DISALLOW_MODIFY_ACCOUNTS, true, user);
-        mUserManager.setUserRestriction(UserManager.DISALLOW_SHARE_LOCATION, true, user);
+        // Change the setting before applying the DISALLOW_SHARE_LOCATION restriction, otherwise
+        // the putIntForUser() will fail.
         Secure.putIntForUser(getContentResolver(),
                 Secure.LOCATION_MODE, Secure.LOCATION_MODE_OFF, userId);
+        mUserManager.setUserRestriction(UserManager.DISALLOW_SHARE_LOCATION, true, user);
         Bitmap bitmap = createBitmapFromDrawable(
                 USER_DRAWABLES[userId % UserSettings.USER_DRAWABLES.length]);
         mUserManager.setUserIcon(userId, bitmap);
index abf4de8..50789b8 100644 (file)
@@ -813,7 +813,13 @@ public class WifiSettings extends RestrictedSettingsFragment
 
         final List<WifiConfiguration> configs = wifiManager.getConfiguredNetworks();
         if (configs != null) {
-            savedNetworksExist = (configs.size() > 0);
+            // Update "Saved Networks" menu option.
+            if (savedNetworksExist != (configs.size() > 0)) {
+                savedNetworksExist = !savedNetworksExist;
+                if (context instanceof Activity) {
+                    ((Activity) context).invalidateOptionsMenu();
+                }
+            }
             for (WifiConfiguration config : configs) {
                 AccessPoint accessPoint = new AccessPoint(context, config);
                 if (lastInfo != null && lastState != null) {
index 662d477..d0b116b 100644 (file)
@@ -57,7 +57,7 @@ public class WpsDialog extends AlertDialog {
     private static final int WPS_TIMEOUT_S = 120;
 
     private WifiManager mWifiManager;
-    private WifiManager.WpsListener mWpsListener;
+    private WifiManager.WpsCallback mWpsListener;
     private int mWpsSetup;
 
     private final IntentFilter mFilter;
@@ -81,8 +81,9 @@ public class WpsDialog extends AlertDialog {
         mContext = context;
         mWpsSetup = wpsSetup;
 
-        class WpsListener implements WifiManager.WpsListener {
-            public void onStartSuccess(String pin) {
+        class WpsListener extends WifiManager.WpsCallback {
+
+            public void onStarted(String pin) {
                 if (pin != null) {
                     updateDialog(DialogState.WPS_START, String.format(
                             mContext.getString(R.string.wifi_wps_onstart_pin), pin));
@@ -91,12 +92,13 @@ public class WpsDialog extends AlertDialog {
                             R.string.wifi_wps_onstart_pbc));
                 }
             }
-            public void onCompletion() {
+
+            public void onSucceeded() {
                 updateDialog(DialogState.WPS_COMPLETE,
                         mContext.getString(R.string.wifi_wps_complete));
             }
 
-            public void onFailure(int reason) {
+            public void onFailed(int reason) {
                 String msg;
                 switch (reason) {
                     case WifiManager.WPS_OVERLAP_ERROR: