Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1fed0c6a authored by Jeremy Joslin's avatar Jeremy Joslin Committed by android-build-merger
Browse files

Merge "New pref toggle for network recommendations." am: a5249906 am: 2b03ffb2

am: 6061ca1b

Change-Id: I05753f7a5d54cd7707531c0a6cd9491c081454b3
parents e6c84091 6061ca1b
Loading
Loading
Loading
Loading
+0 −10
Original line number Diff line number Diff line
@@ -2556,16 +2556,6 @@
            </intent-filter>
        </activity>

        <activity android:name=".ActiveNetworkScorerDialog"
                  android:label="@string/wifi_assistant_title"
                  android:excludeFromRecents="true"
                  android:theme="@android:style/Theme.DeviceDefault.Light.Dialog.Alert">
            <intent-filter android:priority="1">
                <action android:name="android.net.scoring.CHANGE_ACTIVE" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>

        <activity android:name="Settings$NotificationAccessSettingsActivity"
                  android:label="@string/manage_notification_access_title"
                  android:taskAffinity="">
+6 −9
Original line number Diff line number Diff line
@@ -1460,9 +1460,6 @@
    <!-- Bluetooth settings.  Dock Setting Dialog - Remember setting and don't ask user again -->
    <string name="bluetooth_dock_settings_remember">Remember settings</string>
    <!-- Wifi Assistant title.  [CHAR LIMIT=40] -->
    <string name="wifi_assistant_title">Wi\u2011Fi Assistant</string>
    <!-- Wifi Display settings. The title of the screen. [CHAR LIMIT=40] -->
    <string name="wifi_display_settings_title">Cast</string>
    <!-- Wifi Display settings. The title of a menu item to enable wireless display [CHAR LIMIT=40] -->
@@ -1581,12 +1578,12 @@
    <string name="wifi_poor_network_detection_summary">Don\u2019t use a Wi\u2011Fi network unless it has a good Internet connection</string>
    <!-- Checkbox summary for option to toggle poor network detection [CHAR LIMIT=60] -->
    <string name="wifi_avoid_poor_network_detection_summary">Only use networks that have a good Internet connection</string>
    <!-- Checkbox title for option to connect to open Wi-Fi automatically [CHAR LIMIT=40] -->
    <string name="wifi_automatically_connect_title">Use open Wi\u2011Fi automatically</string>
    <!-- Checkbox summary for option to connect to open Wi-Fi automatically  [CHAR LIMIT=100] -->
    <string name="wifi_automatically_connect_summary">Let a Wi\u2011Fi assistant automatically connect to open networks determined to be high quality</string>
    <!-- Dialog title for option to select an app which connects to open Wi-Fi automatically [CHAR LIMIT=40] -->
    <string name="wifi_select_assistant_dialog_title">Choose assistant</string>
    <!-- Network recommendations toggle -->
    <!--TODO(jjoslin): Provide final strings and mark for translation. BUG: 32913919 -->
    <string translatable="false" name="networking_allow_recommendations_title">Use network recommendations</string>
    <string translatable="false" name="networking_allow_recommendations_summary">When enabled, use network recommendations when selecting the Wi\u2011Fi network to connect to</string>
    <!-- Preference title for option to install certificates -->
    <string name="wifi_install_credentials">Install certificates</string>
    <!-- Message to describe "Wi-Fi scan always available feature" when Wi-Fi is off. The
+4 −5
Original line number Diff line number Diff line
@@ -35,11 +35,10 @@
        android:entries="@array/wifi_sleep_policy_entries"
        android:entryValues="@array/wifi_sleep_policy_values" />

    <com.android.settings.AppListSwitchPreference
        android:key="wifi_assistant"
        android:title="@string/wifi_automatically_connect_title"
        android:summary="@string/wifi_automatically_connect_summary"
        android:dialogTitle="@string/wifi_select_assistant_dialog_title" />
    <SwitchPreference
      android:key="allow_recommendations"
      android:title="@string/networking_allow_recommendations_title"
      android:summary="@string/networking_allow_recommendations_summary"/>

    <SwitchPreference
        android:key="wifi_cellular_data_fallback"
+0 −112
Original line number Diff line number Diff line
/*
 * Copyright (C) 2014 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License
 */

package com.android.settings;

import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.NetworkScoreManager;
import android.net.NetworkScorerAppManager;
import android.net.NetworkScorerAppManager.NetworkScorerAppData;
import android.os.Bundle;
import android.os.UserHandle;
import android.text.TextUtils;
import android.util.Log;

import com.android.internal.app.AlertActivity;
import com.android.internal.app.AlertController;

/**
 * Dialog to allow a user to select a new network scorer.
 *
 * <p>Finishes with {@link #RESULT_CANCELED} in all circumstances unless the scorer is successfully
 * changed or was already set to the new value (in which case it finishes with {@link #RESULT_OK}).
 */
public final class ActiveNetworkScorerDialog extends AlertActivity implements
        DialogInterface.OnClickListener {
    private static final String TAG = "ActiveNetScorerDlg";

    private String mNewPackageName;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Intent intent = getIntent();
        mNewPackageName = intent.getStringExtra(NetworkScoreManager.EXTRA_PACKAGE_NAME);

        if (!buildDialog()) {
            finish();
        }
    }

    @Override
    public void onClick(DialogInterface dialog, int which) {
        switch (which) {
            case BUTTON_POSITIVE:
                NetworkScoreManager nsm =
                    (NetworkScoreManager) getSystemService(Context.NETWORK_SCORE_SERVICE);
                if (nsm.setActiveScorer(mNewPackageName)) {
                    setResult(RESULT_OK);
                }
                break;
            case BUTTON_NEGATIVE:
                break;
        }
    }

    private boolean buildDialog() {
        // TOOD: http://b/23422763
        if (UserHandle.myUserId() != UserHandle.USER_SYSTEM) {
            Log.i(TAG, "Can only set scorer for owner/system user.");
            return false;
        }
        NetworkScorerAppManager networkScorerAppManager = new NetworkScorerAppManager(this);
        NetworkScorerAppData newScorer = networkScorerAppManager.getScorer(mNewPackageName);
        if (newScorer == null) {
            Log.e(TAG, "New package " + mNewPackageName + " is not a valid scorer.");
            return false;
        }

        NetworkScorerAppData oldScorer = networkScorerAppManager.getActiveScorer();
        if (oldScorer != null && TextUtils.equals(oldScorer.mPackageName, mNewPackageName)) {
            Log.i(TAG, "New package " + mNewPackageName + " is already the active scorer.");
            // Set RESULT_OK to indicate to the caller that the "switch" was successful.
            setResult(RESULT_OK);
            return false;
        }

        // Compose dialog.
        CharSequence newName = newScorer.mScorerName;
        final AlertController.AlertParams p = mAlertParams;
        p.mTitle = getString(R.string.network_scorer_change_active_dialog_title);
        if (oldScorer != null) {
            p.mMessage = getString(R.string.network_scorer_change_active_dialog_text, newName,
                    oldScorer.mScorerName);
        } else {
            p.mMessage = getString(R.string.network_scorer_change_active_no_previous_dialog_text,
                    newName);
        }
        p.mPositiveButtonText = getString(R.string.yes);
        p.mNegativeButtonText = getString(R.string.no);
        p.mPositiveButtonListener = this;
        p.mNegativeButtonListener = this;
        setupAlert();

        return true;
    }
}
+9 −63
Original line number Diff line number Diff line
@@ -19,14 +19,10 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Resources;
import android.net.NetworkScoreManager;
import android.net.NetworkScorerAppManager;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.os.UserManager;
import android.provider.Settings;
import android.support.v14.preference.SwitchPreference;
import android.support.v7.preference.ListPreference;
@@ -35,12 +31,9 @@ import android.text.TextUtils;
import android.util.Log;
import android.widget.Toast;
import com.android.internal.logging.MetricsProto.MetricsEvent;
import com.android.settings.AppListSwitchPreference;
import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.Utils;

import java.util.Collection;
import java.util.List;

public class ConfigureWifiSettings extends SettingsPreferenceFragment
@@ -53,12 +46,9 @@ public class ConfigureWifiSettings extends SettingsPreferenceFragment
    private static final String KEY_NOTIFY_OPEN_NETWORKS = "notify_open_networks";
    private static final String KEY_SLEEP_POLICY = "sleep_policy";
    private static final String KEY_CELLULAR_FALLBACK = "wifi_cellular_data_fallback";
    private static final String KEY_WIFI_ASSISTANT = "wifi_assistant";
    private static final String KEY_ALLOW_RECOMMENDATIONS = "allow_recommendations";

    private WifiManager mWifiManager;
    private NetworkScoreManager mNetworkScoreManager;
    private AppListSwitchPreference mWifiAssistantPreference;

    private IntentFilter mFilter;

    @Override
@@ -74,8 +64,6 @@ public class ConfigureWifiSettings extends SettingsPreferenceFragment
        mFilter = new IntentFilter();
        mFilter.addAction(WifiManager.LINK_CONFIGURATION_CHANGED_ACTION);
        mFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
        mNetworkScoreManager =
                (NetworkScoreManager) getSystemService(Context.NETWORK_SCORE_SERVICE);
    }

    @Override
@@ -119,15 +107,10 @@ public class ConfigureWifiSettings extends SettingsPreferenceFragment
            }
        }

        mWifiAssistantPreference = (AppListSwitchPreference) findPreference(KEY_WIFI_ASSISTANT);
        Collection<NetworkScorerAppManager.NetworkScorerAppData> scorers =
                new NetworkScorerAppManager(context).getAllValidScorers();
        if (UserManager.get(context).isAdminUser() && !scorers.isEmpty()) {
            mWifiAssistantPreference.setOnPreferenceChangeListener(this);
            initWifiAssistantPreference(scorers);
        } else if (mWifiAssistantPreference != null) {
            getPreferenceScreen().removePreference(mWifiAssistantPreference);
        }
        SwitchPreference allowRecommendations =
            (SwitchPreference) findPreference(KEY_ALLOW_RECOMMENDATIONS);
        allowRecommendations.setChecked(Settings.Global.getInt(getContentResolver(),
            Settings.Global.NETWORK_RECOMMENDATIONS_ENABLED, 0) == 1);

        ListPreference sleepPolicyPref = (ListPreference) findPreference(KEY_SLEEP_POLICY);
        if (sleepPolicyPref != null) {
@@ -187,6 +170,10 @@ public class ConfigureWifiSettings extends SettingsPreferenceFragment
            String settingName = Settings.Global.NETWORK_AVOID_BAD_WIFI;
            Settings.Global.putString(getContentResolver(), settingName,
                    ((SwitchPreference) preference).isChecked() ? "1" : null);
        } else if (KEY_ALLOW_RECOMMENDATIONS.equals(key)) {
            Settings.Global.putInt(getActivity().getContentResolver(),
                Settings.Global.NETWORK_RECOMMENDATIONS_ENABLED,
                ((SwitchPreference) preference).isChecked() ? 1 : 0);
        } else {
            return super.onPreferenceTreeClick(preference);
        }
@@ -198,34 +185,6 @@ public class ConfigureWifiSettings extends SettingsPreferenceFragment
        final Context context = getActivity();
        String key = preference.getKey();

        if (KEY_WIFI_ASSISTANT.equals(key)) {
            NetworkScorerAppManager.NetworkScorerAppData wifiAssistant =
                    new NetworkScorerAppManager(context).getScorer((String) newValue);
            if (wifiAssistant == null) {
                mNetworkScoreManager.setActiveScorer(null);
                return true;
            }

            Intent intent = new Intent();
            if (wifiAssistant.mConfigurationActivityClassName != null) {
                // App has a custom configuration activity; launch that.
                // This custom activity will be responsible for launching the system
                // dialog.
                intent.setClassName(wifiAssistant.mPackageName,
                        wifiAssistant.mConfigurationActivityClassName);
            } else {
                // Fall back on the system dialog.
                intent.setAction(NetworkScoreManager.ACTION_CHANGE_ACTIVE);
                intent.putExtra(NetworkScoreManager.EXTRA_PACKAGE_NAME,
                        wifiAssistant.mPackageName);
            }

            startActivity(intent);
            // Don't update the preference widget state until the child activity returns.
            // It will be updated in onResume after the activity finishes.
            return false;
        }

        if (KEY_SLEEP_POLICY.equals(key)) {
            try {
                String stringValue = (String) newValue;
@@ -259,19 +218,6 @@ public class ConfigureWifiSettings extends SettingsPreferenceFragment
        wifiIpAddressPref.setSelectable(false);
    }

    private void initWifiAssistantPreference(
            Collection<NetworkScorerAppManager.NetworkScorerAppData> scorers) {
        int count = scorers.size();
        String[] packageNames = new String[count];
        int i = 0;
        for (NetworkScorerAppManager.NetworkScorerAppData scorer : scorers) {
            packageNames[i] = scorer.mPackageName;
            i++;
        }
        mWifiAssistantPreference.setPackageNames(packageNames,
                mNetworkScoreManager.getActiveScorerPackage());
    }

    @Override
    protected int getMetricsCategory() {
        return MetricsEvent.CONFIGURE_WIFI;