Merge pi-dev-plus-aosp-without-vendor into stage-dr1-aosp-master
Bug: 111615259 Change-Id: I0bbc44c97afd0ed6ff7799e866d4b36beee6c3be
This commit is contained in:
@@ -467,6 +467,20 @@
|
||||
android:value="com.android.settings.TetherSettings" />
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name="Settings$WifiTetherSettingsActivity"
|
||||
android:label="@string/wifi_hotspot_checkbox_text"
|
||||
android:icon="@drawable/ic_wifi_tethering"
|
||||
android:parentActivityName="Settings">
|
||||
<intent-filter>
|
||||
<action android:name="com.android.settings.WIFI_TETHER_SETTINGS" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
|
||||
android:value="com.android.settings.wifi.tether.WifiTetherSettings" />
|
||||
</activity>
|
||||
|
||||
|
||||
<!-- Keep compatibility with old shortcuts. -->
|
||||
<activity-alias android:name=".TetherSettings"
|
||||
android:label="@string/tether_settings_title_all"
|
||||
|
@@ -284,17 +284,27 @@
|
||||
|
||||
<!-- Wi-Fi AP band settings. Either Auto, 2.4GHz or 5GHz. -->
|
||||
<!-- Note that adding/removing/moving the items will need wifi settings code change. -->
|
||||
<string-array name="wifi_ap_band_config_full">
|
||||
<string-array translatable="false" name="wifi_ap_band_config_full">
|
||||
<item>0</item>
|
||||
<item>1</item>
|
||||
</string-array>
|
||||
|
||||
<string-array translatable="false" name="wifi_ap_band_summary_full">
|
||||
<item>@string/wifi_ap_choose_2G</item>
|
||||
<item>@string/wifi_ap_choose_5G</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="wifi_ap_band_summary_full">
|
||||
<item>@string/wifi_ap_2G</item>
|
||||
<item>@string/wifi_ap_5G</item>
|
||||
<string-array translatable="false" name="wifi_ap_band_dual_mode">
|
||||
<item>0</item>
|
||||
<item>-1</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="wifi_ap_band_config_2G_only">
|
||||
<string-array translatable="false" name="wifi_ap_band_dual_mode_summary">
|
||||
<item>@string/wifi_ap_choose_2G</item>
|
||||
<item>@string/wifi_ap_prefer_5G</item>
|
||||
</string-array>
|
||||
|
||||
<string-array translatable="false" name="wifi_ap_band_config_2G_only">
|
||||
<item>@string/wifi_ap_choose_auto</item>
|
||||
<item>@string/wifi_ap_choose_2G</item>
|
||||
</string-array>
|
||||
|
@@ -1986,8 +1986,10 @@
|
||||
<string name="wifi_ap_choose_auto">Auto</string>
|
||||
<!-- Label for the radio button to choose wifi ap 2.4 GHz band -->
|
||||
<string name="wifi_ap_choose_2G">2.4 GHz Band</string>
|
||||
<!-- Label for the radio button to choose wifi ap 5GHz band -->
|
||||
<!-- Label for the radio button to only choose wifi ap 5GHz band -->
|
||||
<string name="wifi_ap_choose_5G">5.0 GHz Band</string>
|
||||
<!-- Label for the radio button to prefer 5GHz wifi ap band [CHAR LIMIT=80]-->
|
||||
<string name="wifi_ap_prefer_5G">5.0 GHz Band preferred</string>
|
||||
<!-- Label for adding to the list of selected bands when 2.4 GHz is selected -->
|
||||
<string name="wifi_ap_2G">2.4 GHz</string>
|
||||
<!-- Label for adding to the list of selected bands when 5.0 GHz is selected -->
|
||||
@@ -2491,11 +2493,11 @@
|
||||
<string name="color_mode_option_boosted">Boosted</string>
|
||||
<!-- Display settings screen, Color mode option for "Saturated color" [CHAR LIMIT=45] -->
|
||||
<string name="color_mode_option_saturated">Saturated</string>
|
||||
<!-- Display settings screen, Color mode option for "Automatic color" [CHAR LIMIT=45] -->
|
||||
<string name="color_mode_option_automatic">Automatic</string>
|
||||
<!-- Display settings screen, Color mode option for "Adaptive color" [CHAR LIMIT=45] -->
|
||||
<string name="color_mode_option_automatic">Adaptive</string>
|
||||
<!-- Display settings screen, "natural(sRGB) color" setting option summary [CHAR LIMIT=NONE] -->
|
||||
<string name="color_mode_summary_natural">Use accurate colors only</string>
|
||||
<!-- Display settings screen, "Automatic color" setting option summary [CHAR LIMIT=NONE] -->
|
||||
<!-- Display settings screen, "Adaptive color" setting option summary [CHAR LIMIT=NONE] -->
|
||||
<string name="color_mode_summary_automatic">Adjust between vivid and accurate colors</string>
|
||||
|
||||
<!-- Sound & display settings screen, accelerometer-based rotation summary text when check box is selected -->
|
||||
@@ -7417,7 +7419,7 @@
|
||||
<!-- Do not disturb settings, messages, events and reminders title [CHAR LIMIT=100]-->
|
||||
<string name="zen_msg_event_reminder_title">Messages, events & reminders</string>
|
||||
<!-- Do not disturb settings, messages, events and reminders footer [CHAR LIMIT=NONE]-->
|
||||
<string name="zen_msg_event_reminder_footer">When Do Not Disturb is on, messages, reminders, and events will muted, except for the items you allow above. You can adjust messages settings to allow your friends, family, or other contacts to reach you.</string>
|
||||
<string name="zen_msg_event_reminder_footer">When Do Not Disturb is on, messages, reminders, and events will be muted, except for the items you allow above. You can adjust messages settings to allow your friends, family, or other contacts to reach you.</string>
|
||||
|
||||
<!-- Do not disturb onboarding dialog, accept new settings [CHAR LIMIT=30]-->
|
||||
<string name="zen_onboarding_ok">Done</string>
|
||||
@@ -9922,6 +9924,9 @@
|
||||
<!-- Help URI, smart battery page [DO NOT TRANSLATE] -->
|
||||
<string name="help_uri_smart_battery_settings" translatable="false"></string>
|
||||
|
||||
<!-- Help URI, prevent ringing gesture [DO NOT TRANSLATE] -->
|
||||
<string name="help_uri_prevent_ringing_gesture" translatable="false"></string>
|
||||
|
||||
<!-- Title label for dnd suggestion, which is displayed in Settings homepage [CHAR LIMIT=100] -->
|
||||
<string name="zen_suggestion_title">Update Do Not Disturb</string>
|
||||
|
||||
|
@@ -43,11 +43,7 @@
|
||||
android:title="@string/wifi_hotspot_auto_off_title"
|
||||
android:summary="@string/wifi_hotspot_auto_off_summary" />
|
||||
|
||||
<com.android.settings.widget.HotspotApBandSelectionPreference
|
||||
<ListPreference
|
||||
android:key="wifi_tether_network_ap_band"
|
||||
android:title="@string/wifi_hotspot_ap_band_title"
|
||||
android:dialogLayout="@layout/hotspot_ap_band_selection_dialog"
|
||||
android:dialogTitle="@string/wifi_hotspot_ap_band_title"
|
||||
android:negativeButtonText="@string/cancel"
|
||||
android:positiveButtonText="@string/apply" />
|
||||
android:title="@string/wifi_hotspot_ap_band_title" />
|
||||
</PreferenceScreen>
|
@@ -59,6 +59,7 @@ import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.fuelgauge.BatteryUtils;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.users.UserDialogs;
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
@@ -425,6 +426,9 @@ public class DeviceAdminAdd extends Activity {
|
||||
mDPM.setActiveAdmin(mDeviceAdmin.getComponent(), mRefreshing);
|
||||
EventLog.writeEvent(EventLogTags.EXP_DET_DEVICE_ADMIN_ACTIVATED_BY_USER,
|
||||
mDeviceAdmin.getActivityInfo().applicationInfo.uid);
|
||||
|
||||
unrestrictAppIfPossible(BatteryUtils.getInstance(this));
|
||||
|
||||
setResult(Activity.RESULT_OK);
|
||||
} catch (RuntimeException e) {
|
||||
// Something bad happened... could be that it was
|
||||
@@ -446,6 +450,15 @@ public class DeviceAdminAdd extends Activity {
|
||||
finish();
|
||||
}
|
||||
|
||||
void unrestrictAppIfPossible(BatteryUtils batteryUtils) {
|
||||
// Unrestrict admin app if it is already been restricted
|
||||
final String packageName = mDeviceAdmin.getComponent().getPackageName();
|
||||
final int uid = batteryUtils.getPackageUid(packageName);
|
||||
if (batteryUtils.isForceAppStandbyEnabled(uid, packageName)) {
|
||||
batteryUtils.setForceAppStandby(uid, packageName, AppOpsManager.MODE_ALLOWED);
|
||||
}
|
||||
}
|
||||
|
||||
void continueRemoveAction(CharSequence msg) {
|
||||
if (!mWaitingForRemoveMsg) {
|
||||
return;
|
||||
|
@@ -32,6 +32,7 @@ public class Settings extends SettingsActivity {
|
||||
public static class BluetoothSettingsActivity extends SettingsActivity { /* empty */ }
|
||||
public static class SimSettingsActivity extends SettingsActivity { /* empty */ }
|
||||
public static class TetherSettingsActivity extends SettingsActivity { /* empty */ }
|
||||
public static class WifiTetherSettingsActivity extends SettingsActivity { /* empty */ }
|
||||
public static class VpnSettingsActivity extends SettingsActivity { /* empty */ }
|
||||
public static class DateTimeSettingsActivity extends SettingsActivity { /* empty */ }
|
||||
public static class PrivateVolumeForgetActivity extends SettingsActivity { /* empty */ }
|
||||
|
@@ -21,26 +21,29 @@ import android.support.annotation.VisibleForTesting;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
import android.util.Log;
|
||||
import com.android.settings.bluetooth.BluetoothDeviceUpdater;
|
||||
import com.android.settings.bluetooth.SavedBluetoothDeviceUpdater;
|
||||
import com.android.settings.connecteddevice.dock.DockUpdater;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStart;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStop;
|
||||
import com.android.settingslib.utils.ThreadUtils;
|
||||
|
||||
public class PreviouslyConnectedDevicePreferenceController extends BasePreferenceController
|
||||
implements LifecycleObserver, OnStart, OnStop, DevicePreferenceCallback {
|
||||
|
||||
private Preference mPreference;
|
||||
private BluetoothDeviceUpdater mBluetoothDeviceUpdater;
|
||||
private DockUpdater mSavedDockUpdater;
|
||||
private int mPreferenceSize;
|
||||
|
||||
public PreviouslyConnectedDevicePreferenceController(Context context, String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
|
||||
mSavedDockUpdater = FeatureFactory.getFactory(
|
||||
context).getDockUpdaterFeatureProvider().getSavedDockUpdater(context, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -62,12 +65,14 @@ public class PreviouslyConnectedDevicePreferenceController extends BasePreferenc
|
||||
@Override
|
||||
public void onStart() {
|
||||
mBluetoothDeviceUpdater.registerCallback();
|
||||
mSavedDockUpdater.registerCallback();
|
||||
updatePreferenceOnSizeChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
mBluetoothDeviceUpdater.unregisterCallback();
|
||||
mSavedDockUpdater.unregisterCallback();
|
||||
}
|
||||
|
||||
public void init(DashboardFragment fragment) {
|
||||
@@ -92,6 +97,11 @@ public class PreviouslyConnectedDevicePreferenceController extends BasePreferenc
|
||||
mBluetoothDeviceUpdater = bluetoothDeviceUpdater;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void setSavedDockUpdater(DockUpdater savedDockUpdater) {
|
||||
mSavedDockUpdater = savedDockUpdater;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void setPreferenceSize(int size) {
|
||||
mPreferenceSize = size;
|
||||
|
@@ -136,6 +136,7 @@ import com.android.settings.wifi.WifiInfo;
|
||||
import com.android.settings.wifi.WifiSettings;
|
||||
import com.android.settings.wifi.calling.WifiCallingSettings;
|
||||
import com.android.settings.wifi.p2p.WifiP2pSettings;
|
||||
import com.android.settings.wifi.tether.WifiTetherSettings;
|
||||
|
||||
public class SettingsGateway {
|
||||
|
||||
@@ -151,6 +152,7 @@ public class SettingsGateway {
|
||||
SimSettings.class.getName(),
|
||||
TetherSettings.class.getName(),
|
||||
WifiP2pSettings.class.getName(),
|
||||
WifiTetherSettings.class.getName(),
|
||||
BackgroundCheckSummary.class.getName(),
|
||||
VpnSettings.class.getName(),
|
||||
DateTimeSettings.class.getName(),
|
||||
|
@@ -20,6 +20,7 @@ import android.provider.Settings;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v14.preference.SwitchPreference;
|
||||
|
||||
import com.android.internal.R;
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
|
||||
@@ -40,7 +41,8 @@ public class BatteryPercentagePreferenceController extends AbstractPreferenceCon
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
return true;
|
||||
return mContext.getResources()
|
||||
.getBoolean(R.bool.config_battery_percentage_setting_available);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -472,6 +472,12 @@ public class PowerUsageSummary extends PowerUsageBase implements OnLongClickList
|
||||
@Override
|
||||
public List<String> getNonIndexableKeys(Context context) {
|
||||
List<String> niks = super.getNonIndexableKeys(context);
|
||||
|
||||
final BatteryPercentagePreferenceController controller =
|
||||
new BatteryPercentagePreferenceController(context);
|
||||
if (!controller.isAvailable()) {
|
||||
niks.add(controller.getPreferenceKey());
|
||||
}
|
||||
niks.add(KEY_BATTERY_SAVER_SUMMARY);
|
||||
return niks;
|
||||
}
|
||||
|
@@ -58,7 +58,7 @@ public class PreventRingingGestureSettings extends DashboardFragment {
|
||||
|
||||
@Override
|
||||
public int getHelpResource() {
|
||||
return 0;
|
||||
return R.string.help_uri_prevent_ringing_gesture;
|
||||
}
|
||||
|
||||
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
|
@@ -147,8 +147,10 @@ public class VisibilityPreferenceController extends NotificationPreferenceContro
|
||||
}
|
||||
|
||||
private boolean getLockscreenNotificationsEnabled() {
|
||||
return Settings.Secure.getInt(mContext.getContentResolver(),
|
||||
Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 0) != 0;
|
||||
final UserInfo parentUser = mUm.getProfileParent(UserHandle.myUserId());
|
||||
final int primaryUserId = parentUser != null ? parentUser.id : UserHandle.myUserId();
|
||||
return Settings.Secure.getIntForUser(mContext.getContentResolver(),
|
||||
Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 0, primaryUserId) != 0;
|
||||
}
|
||||
|
||||
private boolean getLockscreenAllowPrivateNotifications() {
|
||||
|
@@ -21,7 +21,10 @@ import android.app.job.JobInfo;
|
||||
import android.app.job.JobScheduler;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ServiceInfo;
|
||||
import android.net.Uri;
|
||||
import android.os.Binder;
|
||||
import android.os.Build;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
@@ -36,7 +39,6 @@ import java.util.Locale;
|
||||
|
||||
public interface DeviceIndexFeatureProvider {
|
||||
|
||||
|
||||
String TAG = "DeviceIndex";
|
||||
|
||||
String INDEX_VERSION = "settings:index_version";
|
||||
@@ -57,7 +59,7 @@ public interface DeviceIndexFeatureProvider {
|
||||
|
||||
default void updateIndex(Context context, boolean force) {
|
||||
if (!isIndexingEnabled()) {
|
||||
Log.w(TAG, "Skipping: device index is not enabled");
|
||||
Log.i(TAG, "Skipping: device index is not enabled");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -66,7 +68,29 @@ public interface DeviceIndexFeatureProvider {
|
||||
return;
|
||||
}
|
||||
|
||||
final ComponentName jobComponent = new ComponentName(context.getPackageName(),
|
||||
DeviceIndexUpdateJobService.class.getName());
|
||||
|
||||
try {
|
||||
final int callerUid = Binder.getCallingUid();
|
||||
final ServiceInfo si = context.getPackageManager().getServiceInfo(jobComponent,
|
||||
PackageManager.MATCH_DIRECT_BOOT_AWARE
|
||||
| PackageManager.MATCH_DIRECT_BOOT_UNAWARE);
|
||||
if (si == null) {
|
||||
Log.w(TAG, "Skipping: No such service " + jobComponent);
|
||||
return;
|
||||
}
|
||||
if (si.applicationInfo.uid != callerUid) {
|
||||
Log.w(TAG, "Skipping: Uid cannot schedule DeviceIndexUpdate: " + callerUid);
|
||||
return;
|
||||
}
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
Log.w(TAG, "Skipping: error finding DeviceIndexUpdateJobService from packageManager");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!force && skipIndex(context)) {
|
||||
Log.i(TAG, "Skipping: already indexed.");
|
||||
// No need to update.
|
||||
return;
|
||||
}
|
||||
@@ -74,8 +98,6 @@ public interface DeviceIndexFeatureProvider {
|
||||
// Prevent scheduling multiple jobs
|
||||
setIndexState(context);
|
||||
|
||||
final ComponentName jobComponent = new ComponentName(context.getPackageName(),
|
||||
DeviceIndexUpdateJobService.class.getName());
|
||||
final int jobId = context.getResources().getInteger(R.integer.device_index_update);
|
||||
// Schedule a job so that we know it'll be able to complete, but try to run as
|
||||
// soon as possible.
|
||||
|
@@ -170,12 +170,20 @@ public abstract class AudioSwitchPreferenceController extends BasePreferenceCont
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
if (mLocalBluetoothManager == null) {
|
||||
Log.e(TAG, "Bluetooth is not supported on this device");
|
||||
return;
|
||||
}
|
||||
mLocalBluetoothManager.setForegroundActivity(mContext);
|
||||
register();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
if (mLocalBluetoothManager == null) {
|
||||
Log.e(TAG, "Bluetooth is not supported on this device");
|
||||
return;
|
||||
}
|
||||
mLocalBluetoothManager.setForegroundActivity(null);
|
||||
unregister();
|
||||
}
|
||||
|
@@ -1,258 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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.widget;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settingslib.CustomDialogPreference;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class HotspotApBandSelectionPreference extends CustomDialogPreference implements
|
||||
CompoundButton.OnCheckedChangeListener, DialogInterface.OnShowListener {
|
||||
private static final int UNSET = Integer.MIN_VALUE;
|
||||
|
||||
@VisibleForTesting
|
||||
static final String KEY_CHECKED_BANDS = "checked_bands";
|
||||
@VisibleForTesting
|
||||
static final String KEY_HOTSPOT_SUPER_STATE = "hotspot_super_state";
|
||||
|
||||
@VisibleForTesting
|
||||
CheckBox mBox2G;
|
||||
@VisibleForTesting
|
||||
CheckBox mBox5G;
|
||||
@VisibleForTesting
|
||||
ArrayList<Integer> mRestoredBands;
|
||||
@VisibleForTesting
|
||||
boolean mShouldRestore;
|
||||
|
||||
private String[] mBandEntries;
|
||||
private int mExistingConfigValue = UNSET;
|
||||
|
||||
public HotspotApBandSelectionPreference(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public HotspotApBandSelectionPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public HotspotApBandSelectionPreference(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
}
|
||||
|
||||
public HotspotApBandSelectionPreference(Context context, AttributeSet attrs, int defStyleAttr,
|
||||
int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onRestoreInstanceState(Parcelable state) {
|
||||
SavedState myState = (SavedState) state;
|
||||
|
||||
super.onRestoreInstanceState(myState.getSuperState());
|
||||
|
||||
mShouldRestore = myState.shouldRestore;
|
||||
if (mShouldRestore) {
|
||||
mRestoredBands = new ArrayList<>();
|
||||
if (myState.enabled2G) {
|
||||
mRestoredBands.add(WifiConfiguration.AP_BAND_2GHZ);
|
||||
}
|
||||
if (myState.enabled5G) {
|
||||
mRestoredBands.add(WifiConfiguration.AP_BAND_5GHZ);
|
||||
}
|
||||
} else {
|
||||
mRestoredBands = null;
|
||||
}
|
||||
updatePositiveButton();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onBindDialogView(View view) {
|
||||
super.onBindDialogView(view);
|
||||
final Context context = getContext();
|
||||
|
||||
// Register so we can adjust the buttons if needed once the dialog is available.
|
||||
setOnShowListener(this);
|
||||
|
||||
mBandEntries = context.getResources().getStringArray(R.array.wifi_ap_band_config_full);
|
||||
// add a checkbox for every band entry.
|
||||
addApBandViews((LinearLayout) view);
|
||||
// try to update the button just in case we already missed the onShow call.
|
||||
updatePositiveButton();
|
||||
// clear any saved state so it doesn't leak across multiple rotations/dialog closings
|
||||
mRestoredBands = null;
|
||||
mShouldRestore = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Parcelable onSaveInstanceState() {
|
||||
final Parcelable superState = super.onSaveInstanceState();
|
||||
|
||||
SavedState myState = new SavedState(superState);
|
||||
myState.shouldRestore = getDialog() != null;
|
||||
myState.enabled2G = mBox2G != null && mBox2G.isChecked();
|
||||
myState.enabled5G = mBox5G != null && mBox5G.isChecked();
|
||||
return myState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
if (!(buttonView instanceof CheckBox)) {
|
||||
return;
|
||||
}
|
||||
updatePositiveButton();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onClick(DialogInterface dialog, int which) {
|
||||
// we only want to persist our enabled bands if apply is clicked
|
||||
if (which == DialogInterface.BUTTON_POSITIVE) {
|
||||
if (mBox2G.isChecked() || mBox5G.isChecked()) {
|
||||
int wifiBand = getWifiBand();
|
||||
mExistingConfigValue = wifiBand;
|
||||
callChangeListener(wifiBand);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to set the band selection for the preference if one already exists
|
||||
* @param band the band to set it to from {@link WifiConfiguration}
|
||||
*/
|
||||
public void setExistingConfigValue(int band) {
|
||||
mExistingConfigValue = band;
|
||||
}
|
||||
|
||||
private void addApBandViews(LinearLayout view) {
|
||||
mBox2G = view.findViewById(R.id.box_2g);
|
||||
mBox2G.setText(mBandEntries[WifiConfiguration.AP_BAND_2GHZ]);
|
||||
mBox2G.setChecked(restoreBandIfNeeded(WifiConfiguration.AP_BAND_2GHZ));
|
||||
mBox2G.setOnCheckedChangeListener(this);
|
||||
|
||||
mBox5G = view.findViewById(R.id.box_5g);
|
||||
mBox5G.setText(mBandEntries[WifiConfiguration.AP_BAND_5GHZ]);
|
||||
mBox5G.setChecked(restoreBandIfNeeded(WifiConfiguration.AP_BAND_5GHZ));
|
||||
mBox5G.setOnCheckedChangeListener(this);
|
||||
}
|
||||
|
||||
private boolean restoreBandIfNeeded(int band) {
|
||||
// Only use the provided config if we aren't restoring, restore if state available
|
||||
return (isBandPreviouslySelected(band) && !mShouldRestore)
|
||||
|| (mShouldRestore && mRestoredBands.contains(band));
|
||||
}
|
||||
|
||||
private void updatePositiveButton() {
|
||||
AlertDialog dialog = (AlertDialog) getDialog();
|
||||
Button button = dialog == null ? null : dialog.getButton(DialogInterface.BUTTON_POSITIVE);
|
||||
if (button != null && mBox5G != null && mBox2G != null) {
|
||||
button.setEnabled(mBox2G.isChecked() || mBox5G.isChecked());
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
int getWifiBand() {
|
||||
final boolean checked_2g = mBox2G.isChecked();
|
||||
final boolean checked_5g = mBox5G.isChecked();
|
||||
if (checked_2g && checked_5g) {
|
||||
return WifiConfiguration.AP_BAND_ANY;
|
||||
} else if (checked_2g && !checked_5g) {
|
||||
return WifiConfiguration.AP_BAND_2GHZ;
|
||||
} else if (checked_5g && !checked_2g) {
|
||||
return WifiConfiguration.AP_BAND_5GHZ;
|
||||
} else {
|
||||
throw new IllegalStateException("Wifi Config only supports selecting one or all bands");
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isBandPreviouslySelected(int bandIndex) {
|
||||
switch(mExistingConfigValue) {
|
||||
case WifiConfiguration.AP_BAND_ANY:
|
||||
return true;
|
||||
case WifiConfiguration.AP_BAND_2GHZ:
|
||||
return bandIndex == 0;
|
||||
case WifiConfiguration.AP_BAND_5GHZ:
|
||||
return bandIndex == 1;
|
||||
case UNSET:
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onShow(DialogInterface dialog) {
|
||||
updatePositiveButton();
|
||||
}
|
||||
|
||||
private static class SavedState extends BaseSavedState {
|
||||
boolean shouldRestore;
|
||||
boolean enabled2G;
|
||||
boolean enabled5G;
|
||||
|
||||
public SavedState(Parcelable source) {
|
||||
super(source);
|
||||
}
|
||||
|
||||
private SavedState(Parcel in) {
|
||||
super(in);
|
||||
shouldRestore = in.readByte() == 1;
|
||||
enabled2G = in.readByte() == 1;
|
||||
enabled5G = in.readByte() == 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
super.writeToParcel(dest, flags);
|
||||
dest.writeByte((byte) (shouldRestore ? 1 : 0));
|
||||
dest.writeByte((byte) (enabled2G ? 1: 0));
|
||||
dest.writeByte((byte) (enabled5G ? 1 : 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "HotspotApBandSelectionPreference.SavedState{"
|
||||
+ Integer.toHexString(System.identityHashCode(this))
|
||||
+ " shouldRestore=" + shouldRestore
|
||||
+ " enabled2G=" + enabled2G
|
||||
+ " enabled5G=" + enabled5G + "}";
|
||||
}
|
||||
|
||||
public static final Parcelable.Creator<SavedState> CREATOR
|
||||
= new Parcelable.Creator<SavedState>() {
|
||||
public SavedState createFromParcel(Parcel in) {
|
||||
return new SavedState(in);
|
||||
}
|
||||
|
||||
public SavedState[] newArray(int size) {
|
||||
return new SavedState[size];
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
@@ -16,36 +16,31 @@
|
||||
|
||||
package com.android.settings.wifi.tether;
|
||||
|
||||
import static android.net.wifi.WifiConfiguration.AP_BAND_2GHZ;
|
||||
import static android.net.wifi.WifiConfiguration.AP_BAND_5GHZ;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.icu.text.ListFormatter;
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.support.v7.preference.ListPreference;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.widget.HotspotApBandSelectionPreference;
|
||||
|
||||
public class WifiTetherApBandPreferenceController extends WifiTetherBasePreferenceController {
|
||||
|
||||
private static final String TAG = "WifiTetherApBandPref";
|
||||
private static final String PREF_KEY = "wifi_tether_network_ap_band";
|
||||
public static final String[] BAND_VALUES =
|
||||
{String.valueOf(AP_BAND_2GHZ), String.valueOf(AP_BAND_5GHZ)};
|
||||
|
||||
private final String[] mBandEntries;
|
||||
private final String[] mBandSummaries;
|
||||
private String[] mBandEntries;
|
||||
private String[] mBandSummaries;
|
||||
private int mBandIndex;
|
||||
private boolean isDualMode;
|
||||
|
||||
public WifiTetherApBandPreferenceController(Context context,
|
||||
OnTetherConfigUpdateListener listener) {
|
||||
super(context, listener);
|
||||
Resources res = mContext.getResources();
|
||||
mBandEntries = res.getStringArray(R.array.wifi_ap_band_config_full);
|
||||
mBandSummaries = res.getStringArray(R.array.wifi_ap_band_summary_full);
|
||||
isDualMode = mWifiManager.isDualModeSupported();
|
||||
updatePreferenceEntries();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -55,7 +50,7 @@ public class WifiTetherApBandPreferenceController extends WifiTetherBasePreferen
|
||||
mBandIndex = 0;
|
||||
Log.d(TAG, "Updating band index to 0 because no config");
|
||||
} else if (is5GhzBandSupported()) {
|
||||
mBandIndex = config.apBand;
|
||||
mBandIndex = validateSelection(config.apBand);
|
||||
Log.d(TAG, "Updating band index to " + mBandIndex);
|
||||
} else {
|
||||
config.apBand = 0;
|
||||
@@ -63,21 +58,23 @@ public class WifiTetherApBandPreferenceController extends WifiTetherBasePreferen
|
||||
mBandIndex = config.apBand;
|
||||
Log.d(TAG, "5Ghz not supported, updating band index to " + mBandIndex);
|
||||
}
|
||||
HotspotApBandSelectionPreference preference =
|
||||
(HotspotApBandSelectionPreference) mPreference;
|
||||
ListPreference preference =
|
||||
(ListPreference) mPreference;
|
||||
preference.setEntries(mBandSummaries);
|
||||
preference.setEntryValues(mBandEntries);
|
||||
|
||||
if (!is5GhzBandSupported()) {
|
||||
preference.setEnabled(false);
|
||||
preference.setSummary(R.string.wifi_ap_choose_2G);
|
||||
} else {
|
||||
preference.setExistingConfigValue(config.apBand);
|
||||
preference.setValue(Integer.toString(config.apBand));
|
||||
preference.setSummary(getConfigSummary());
|
||||
}
|
||||
}
|
||||
|
||||
String getConfigSummary() {
|
||||
if (mBandIndex == WifiConfiguration.AP_BAND_ANY) {
|
||||
return ListFormatter.getInstance().format((Object[]) mBandSummaries);
|
||||
return mContext.getString(R.string.wifi_ap_prefer_5G);
|
||||
}
|
||||
return mBandSummaries[mBandIndex];
|
||||
}
|
||||
@@ -89,13 +86,46 @@ public class WifiTetherApBandPreferenceController extends WifiTetherBasePreferen
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
mBandIndex = (Integer) newValue;
|
||||
mBandIndex = validateSelection(Integer.parseInt((String) newValue));
|
||||
Log.d(TAG, "Band preference changed, updating band index to " + mBandIndex);
|
||||
preference.setSummary(getConfigSummary());
|
||||
mListener.onTetherConfigUpdated();
|
||||
return true;
|
||||
}
|
||||
|
||||
private int validateSelection(int band) {
|
||||
// Reset the band to 2.4 GHz if we get a weird config back to avoid a crash.
|
||||
final boolean isDualMode = mWifiManager.isDualModeSupported();
|
||||
|
||||
// unsupported states:
|
||||
// 1: no dual mode means we can't have AP_BAND_ANY - default to 5GHZ
|
||||
// 2: no 5 GHZ support means we can't have AP_BAND_5GHZ - default to 2GHZ
|
||||
// 3: With Dual mode support we can't have AP_BAND_5GHZ - default to ANY
|
||||
if (!isDualMode && WifiConfiguration.AP_BAND_ANY == band) {
|
||||
return WifiConfiguration.AP_BAND_5GHZ;
|
||||
} else if (!is5GhzBandSupported() && WifiConfiguration.AP_BAND_5GHZ == band) {
|
||||
return WifiConfiguration.AP_BAND_2GHZ;
|
||||
} else if (isDualMode && WifiConfiguration.AP_BAND_5GHZ == band) {
|
||||
return WifiConfiguration.AP_BAND_ANY;
|
||||
}
|
||||
|
||||
return band;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void updatePreferenceEntries() {
|
||||
Resources res = mContext.getResources();
|
||||
int entriesRes = R.array.wifi_ap_band_config_full;
|
||||
int summariesRes = R.array.wifi_ap_band_summary_full;
|
||||
// change the list options if this is a dual mode device
|
||||
if (isDualMode) {
|
||||
entriesRes = R.array.wifi_ap_band_dual_mode;
|
||||
summariesRes = R.array.wifi_ap_band_dual_mode_summary;
|
||||
}
|
||||
mBandEntries = res.getStringArray(entriesRes);
|
||||
mBandSummaries = res.getStringArray(summariesRes);
|
||||
}
|
||||
|
||||
private boolean is5GhzBandSupported() {
|
||||
final String countryCode = mWifiManager.getCountryCode();
|
||||
if (!mWifiManager.isDualBandSupported() || countryCode == null) {
|
||||
|
@@ -18,23 +18,37 @@ package com.android.settings;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.AppOpsManager;
|
||||
import android.app.admin.DeviceAdminInfo;
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.fuelgauge.BatteryUtils;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.Robolectric;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class DeviceAdminAddTest {
|
||||
private static final int UID = 12345;
|
||||
private static final String PACKAGE_NAME = "com.android.test.device.admin";
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private DeviceAdminInfo mDeviceAdmin;
|
||||
@Mock
|
||||
private BatteryUtils mBatteryUtils;
|
||||
private FakeFeatureFactory mFeatureFactory;
|
||||
private DeviceAdminAdd mDeviceAdminAdd;
|
||||
|
||||
@@ -44,6 +58,10 @@ public class DeviceAdminAddTest {
|
||||
|
||||
mFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||
mDeviceAdminAdd = Robolectric.buildActivity(DeviceAdminAdd.class).get();
|
||||
|
||||
doReturn(UID).when(mBatteryUtils).getPackageUid(PACKAGE_NAME);
|
||||
when(mDeviceAdmin.getComponent().getPackageName()).thenReturn(PACKAGE_NAME);
|
||||
mDeviceAdminAdd.mDeviceAdmin = mDeviceAdmin;
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -56,4 +74,23 @@ public class DeviceAdminAddTest {
|
||||
verify(mFeatureFactory.metricsFeatureProvider).action(any(Context.class),
|
||||
eq(MetricsProto.MetricsEvent.APP_SPECIAL_PERMISSION_ADMIN_DENY), eq("app"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unrestrictAppIfPossible_appRestricted_unrestrictApp() {
|
||||
doReturn(true).when(mBatteryUtils).isForceAppStandbyEnabled(UID, PACKAGE_NAME);
|
||||
|
||||
mDeviceAdminAdd.unrestrictAppIfPossible(mBatteryUtils);
|
||||
|
||||
verify(mBatteryUtils).setForceAppStandby(UID, PACKAGE_NAME, AppOpsManager.MODE_ALLOWED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unrestrictAppIfPossible_appUnrestricted_doNothing() {
|
||||
doReturn(false).when(mBatteryUtils).isForceAppStandbyEnabled(UID, PACKAGE_NAME);
|
||||
|
||||
mDeviceAdminAdd.unrestrictAppIfPossible(mBatteryUtils);
|
||||
|
||||
verify(mBatteryUtils, never()).setForceAppStandby(UID, PACKAGE_NAME,
|
||||
AppOpsManager.MODE_ALLOWED);
|
||||
}
|
||||
}
|
||||
|
@@ -21,6 +21,7 @@ import android.content.pm.PackageManager;
|
||||
import android.support.v7.preference.Preference;
|
||||
|
||||
import com.android.settings.bluetooth.BluetoothDeviceUpdater;
|
||||
import com.android.settings.connecteddevice.dock.DockUpdater;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
@@ -46,6 +47,8 @@ public class PreviouslyConnectedDevicePreferenceControllerTest {
|
||||
@Mock
|
||||
private BluetoothDeviceUpdater mBluetoothDeviceUpdater;
|
||||
@Mock
|
||||
private DockUpdater mDockUpdater;
|
||||
@Mock
|
||||
private PackageManager mPackageManager;
|
||||
|
||||
private Context mContext;
|
||||
@@ -61,6 +64,7 @@ public class PreviouslyConnectedDevicePreferenceControllerTest {
|
||||
mPreConnectedDeviceController =
|
||||
new PreviouslyConnectedDevicePreferenceController(mContext, KEY);
|
||||
mPreConnectedDeviceController.setBluetoothDeviceUpdater(mBluetoothDeviceUpdater);
|
||||
mPreConnectedDeviceController.setSavedDockUpdater(mDockUpdater);
|
||||
|
||||
mPreference = new Preference(mContext);
|
||||
mPreConnectedDeviceController.setPreference(mPreference);
|
||||
@@ -71,10 +75,12 @@ public class PreviouslyConnectedDevicePreferenceControllerTest {
|
||||
// register the callback in onStart()
|
||||
mPreConnectedDeviceController.onStart();
|
||||
verify(mBluetoothDeviceUpdater).registerCallback();
|
||||
verify(mDockUpdater).registerCallback();
|
||||
|
||||
// unregister the callback in onStop()
|
||||
mPreConnectedDeviceController.onStop();
|
||||
verify(mBluetoothDeviceUpdater).unregisterCallback();
|
||||
verify(mDockUpdater).unregisterCallback();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -35,6 +35,7 @@ import static org.mockito.Mockito.when;
|
||||
import android.app.LoaderManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Bundle;
|
||||
import android.util.SparseArray;
|
||||
import android.view.Menu;
|
||||
@@ -49,6 +50,7 @@ import com.android.settings.R;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.applications.LayoutPreference;
|
||||
import com.android.settings.dashboard.SummaryLoader;
|
||||
import com.android.settings.display.BatteryPercentagePreferenceController;
|
||||
import com.android.settings.fuelgauge.anomaly.Anomaly;
|
||||
import com.android.settings.fuelgauge.batterytip.BatteryTipPreferenceController;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
@@ -390,6 +392,34 @@ public class PowerUsageSummaryTest {
|
||||
.isEqualTo("3% - Phone will shut down soon");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void percentageSettingAvailable_shouldNotBeHiddenInSearch() {
|
||||
final Resources resources = spy(mRealContext.getResources());
|
||||
doReturn(true).when(resources).getBoolean(anyInt());
|
||||
doReturn(resources).when(mRealContext).getResources();
|
||||
final String prefKey = new BatteryPercentagePreferenceController(mRealContext)
|
||||
.getPreferenceKey();
|
||||
|
||||
final List<String> nonIndexableKeys =
|
||||
PowerUsageSummary.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(mRealContext);
|
||||
|
||||
assertThat(nonIndexableKeys).doesNotContain(prefKey);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void percentageSettingNotAvailable_shouldBeHiddenInSearch() {
|
||||
final Resources resources = spy(mRealContext.getResources());
|
||||
doReturn(false).when(resources).getBoolean(anyInt());
|
||||
doReturn(resources).when(mRealContext).getResources();
|
||||
final String prefKey = new BatteryPercentagePreferenceController(mRealContext)
|
||||
.getPreferenceKey();
|
||||
|
||||
final List<String> nonIndexableKeys =
|
||||
PowerUsageSummary.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(mRealContext);
|
||||
|
||||
assertThat(nonIndexableKeys).contains(prefKey);
|
||||
}
|
||||
|
||||
public static class TestFragment extends PowerUsageSummary {
|
||||
private Context mContext;
|
||||
|
||||
|
@@ -208,6 +208,31 @@ public class VisibilityPreferenceControllerTest {
|
||||
.contains(String.valueOf(VISIBILITY_PRIVATE)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateState_noLockScreenNotificationsGloballyInProfile() {
|
||||
final int primaryUserId = 2;
|
||||
final UserInfo primaryUserInfo = new UserInfo(primaryUserId, "user 2", 0);
|
||||
when(mUm.getProfileParent(anyInt())).thenReturn(primaryUserInfo);
|
||||
|
||||
Settings.Secure.putIntForUser(mContext.getContentResolver(),
|
||||
Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 0, primaryUserId);
|
||||
|
||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||
NotificationChannel channel = mock(NotificationChannel.class);
|
||||
mController.onResume(appRow, channel, null, null);
|
||||
|
||||
RestrictedListPreference pref = mock(RestrictedListPreference.class);
|
||||
mController.updateState(pref);
|
||||
|
||||
ArgumentCaptor<CharSequence[]> argumentCaptor =
|
||||
ArgumentCaptor.forClass(CharSequence[].class);
|
||||
verify(pref, times(1)).setEntryValues(argumentCaptor.capture());
|
||||
assertFalse(toStringList(argumentCaptor.getValue())
|
||||
.contains(String.valueOf(VISIBILITY_NO_OVERRIDE)));
|
||||
assertFalse(toStringList(argumentCaptor.getValue())
|
||||
.contains(String.valueOf(VISIBILITY_PRIVATE)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateState_noPrivateLockScreenNotificationsGlobally() {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||
|
@@ -15,7 +15,6 @@
|
||||
package com.android.settings.search;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -23,27 +22,42 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.job.JobScheduler;
|
||||
import android.os.Binder;
|
||||
import android.provider.Settings;
|
||||
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.Robolectric;
|
||||
import org.robolectric.shadows.ShadowBinder;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class DeviceIndexFeatureProviderTest {
|
||||
|
||||
@Mock
|
||||
private JobScheduler mJobScheduler;
|
||||
private DeviceIndexFeatureProvider mProvider;
|
||||
private Activity mActivity;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
ShadowBinder.reset();
|
||||
FakeFeatureFactory.setupForTest();
|
||||
mActivity = spy(Robolectric.buildActivity(Activity.class).create().visible().get());
|
||||
mProvider = spy(new DeviceIndexFeatureProviderImpl());
|
||||
when(mActivity.getSystemService(JobScheduler.class)).thenReturn(mJobScheduler);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
ShadowBinder.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -51,7 +65,7 @@ public class DeviceIndexFeatureProviderTest {
|
||||
when(mProvider.isIndexingEnabled()).thenReturn(false);
|
||||
|
||||
mProvider.updateIndex(mActivity, false);
|
||||
verify(mProvider, never()).index(any(), any(), any(), any(), any());
|
||||
verify(mJobScheduler, never()).schedule(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -62,19 +76,17 @@ public class DeviceIndexFeatureProviderTest {
|
||||
|
||||
mProvider.updateIndex(mActivity, false);
|
||||
|
||||
verify(mProvider, never()).index(any(), any(), any(), any(), any());
|
||||
verify(mJobScheduler, never()).schedule(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateIndex_enabled_provisioned_shouldIndex() {
|
||||
Settings.Global.putInt(mActivity.getContentResolver(),
|
||||
Settings.Global.DEVICE_PROVISIONED, 1);
|
||||
JobScheduler jobScheduler = mock(JobScheduler.class);
|
||||
when(mProvider.isIndexingEnabled()).thenReturn(true);
|
||||
when(mActivity.getSystemService(JobScheduler.class)).thenReturn(jobScheduler);
|
||||
|
||||
mProvider.updateIndex(mActivity, false);
|
||||
verify(jobScheduler).schedule(any());
|
||||
verify(mJobScheduler).schedule(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -87,12 +99,22 @@ public class DeviceIndexFeatureProviderTest {
|
||||
Settings.Global.putString(mActivity.getContentResolver(),
|
||||
DeviceIndexFeatureProvider.LANGUAGE.toString(),
|
||||
DeviceIndexFeatureProvider.INDEX_LANGUAGE);
|
||||
JobScheduler jobScheduler = mock(JobScheduler.class);
|
||||
when(mProvider.isIndexingEnabled()).thenReturn(true);
|
||||
when(mActivity.getSystemService(JobScheduler.class)).thenReturn(jobScheduler);
|
||||
|
||||
mProvider.updateIndex(mActivity, false);
|
||||
verify(jobScheduler).schedule(any());
|
||||
verify(mJobScheduler).schedule(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateIndex_enabled_provisioned_differentUid_shouldNotIndex() {
|
||||
Settings.Global.putInt(mActivity.getContentResolver(),
|
||||
Settings.Global.DEVICE_PROVISIONED, 1);
|
||||
when(mProvider.isIndexingEnabled()).thenReturn(true);
|
||||
|
||||
ShadowBinder.setCallingUid(Binder.getCallingUid() + 2000);
|
||||
|
||||
mProvider.updateIndex(mActivity, false);
|
||||
verify(mJobScheduler, never()).schedule(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -102,12 +124,11 @@ public class DeviceIndexFeatureProviderTest {
|
||||
DeviceIndexFeatureProvider.setIndexState(mActivity);
|
||||
Settings.Global.putString(mActivity.getContentResolver(),
|
||||
DeviceIndexFeatureProvider.INDEX_LANGUAGE, "new language");
|
||||
JobScheduler jobScheduler = mock(JobScheduler.class);
|
||||
|
||||
when(mProvider.isIndexingEnabled()).thenReturn(true);
|
||||
when(mActivity.getSystemService(JobScheduler.class)).thenReturn(jobScheduler);
|
||||
|
||||
mProvider.updateIndex(mActivity, false);
|
||||
verify(jobScheduler).schedule(any());
|
||||
verify(mJobScheduler).schedule(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -120,11 +141,8 @@ public class DeviceIndexFeatureProviderTest {
|
||||
// Same build and same language
|
||||
DeviceIndexFeatureProvider.setIndexState(mActivity);
|
||||
|
||||
final JobScheduler jobScheduler = mock(JobScheduler.class);
|
||||
when(mActivity.getSystemService(JobScheduler.class)).thenReturn(jobScheduler);
|
||||
|
||||
mProvider.updateIndex(mActivity, false);
|
||||
|
||||
verify(jobScheduler, never()).schedule(any());
|
||||
verify(mJobScheduler, never()).schedule(any());
|
||||
}
|
||||
}
|
||||
|
@@ -186,6 +186,8 @@ public class AudioOutputSwitchPreferenceControllerTest {
|
||||
|
||||
AudioSwitchPreferenceController controller = new AudioSwitchPreferenceControllerTestable(
|
||||
mContext, TEST_KEY);
|
||||
controller.onStart();
|
||||
controller.onStop();
|
||||
|
||||
assertThat(mLocalBluetoothManager).isNull();
|
||||
}
|
||||
|
@@ -1,158 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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.widget;
|
||||
|
||||
import static com.android.settingslib.CustomDialogPreference.CustomPreferenceDialogFragment;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcelable;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class HotspotApBandSelectionPreferenceTest {
|
||||
private HotspotApBandSelectionPreference mPreference;
|
||||
private Context mContext;
|
||||
private Button mSaveButton;
|
||||
private View mLayout;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mSaveButton = spy(new Button(mContext));
|
||||
|
||||
final CustomPreferenceDialogFragment fragment = mock(CustomPreferenceDialogFragment.class);
|
||||
final AlertDialog dialog = mock(AlertDialog.class);
|
||||
when(fragment.getDialog()).thenReturn(dialog);
|
||||
when(dialog.getButton(anyInt())).thenReturn(mSaveButton);
|
||||
|
||||
mPreference = new HotspotApBandSelectionPreference(mContext);
|
||||
ReflectionHelpers.setField(mPreference, "mFragment", fragment);
|
||||
|
||||
final LayoutInflater inflater = LayoutInflater.from(mContext);
|
||||
mLayout = inflater.inflate(R.layout.hotspot_ap_band_selection_dialog,
|
||||
new LinearLayout(mContext), false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getWifiBand_updatesBandPresetConfigProvided() {
|
||||
mPreference.setExistingConfigValue(WifiConfiguration.AP_BAND_ANY);
|
||||
mPreference.onBindDialogView(mLayout);
|
||||
|
||||
// check that the boxes are set correctly when a pre-existing config is set
|
||||
assertThat(mPreference.getWifiBand()).isEqualTo(WifiConfiguration.AP_BAND_ANY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getWifiBand_updatesBandWhenBoxesToggled() {
|
||||
mPreference.setExistingConfigValue(WifiConfiguration.AP_BAND_ANY);
|
||||
mPreference.onBindDialogView(mLayout);
|
||||
|
||||
assertThat(mPreference.getWifiBand()).isEqualTo(WifiConfiguration.AP_BAND_ANY);
|
||||
|
||||
// make sure we have the expected box then toggle it
|
||||
mPreference.mBox2G.setChecked(false);
|
||||
|
||||
// check that band is updated
|
||||
assertThat(mPreference.getWifiBand()).isEqualTo(WifiConfiguration.AP_BAND_5GHZ);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onSaveInstanceState_skipWhenDialogGone() {
|
||||
mPreference.setExistingConfigValue(WifiConfiguration.AP_BAND_2GHZ);
|
||||
mPreference.onBindDialogView(mLayout);
|
||||
// remove the fragment to make the dialog unavailable
|
||||
ReflectionHelpers.setField(mPreference, "mFragment", null);
|
||||
|
||||
mPreference.setExistingConfigValue(WifiConfiguration.AP_BAND_ANY);
|
||||
mPreference.onBindDialogView(mLayout);
|
||||
|
||||
// state should only be saved when the dialog is available
|
||||
Parcelable parcelable = mPreference.onSaveInstanceState();
|
||||
mPreference.onRestoreInstanceState(parcelable);
|
||||
assertThat(mPreference.mShouldRestore).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onSaveInstanceState_doesNotCrashWhenViewGone() {
|
||||
mPreference.setExistingConfigValue(WifiConfiguration.AP_BAND_2GHZ);
|
||||
mPreference.onBindDialogView(mLayout);
|
||||
// When the device dozes the view and dialog can become null
|
||||
mPreference.mBox5G = null;
|
||||
mPreference.mBox2G = null;
|
||||
ReflectionHelpers.setField(mPreference, "mFragment", null);
|
||||
|
||||
// make sure it does not crash and state is not restored
|
||||
Parcelable parcelable = mPreference.onSaveInstanceState();
|
||||
mPreference.onRestoreInstanceState(parcelable);
|
||||
assertThat(mPreference.mShouldRestore).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onSaveInstanceState_presentWhenDialogPresent() {
|
||||
mPreference.setExistingConfigValue(WifiConfiguration.AP_BAND_2GHZ);
|
||||
mPreference.onBindDialogView(mLayout);
|
||||
|
||||
Parcelable parcelable = mPreference.onSaveInstanceState();
|
||||
mPreference.onRestoreInstanceState(parcelable);
|
||||
assertThat(mPreference.mShouldRestore).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void positiveButton_updatedCorrectly() {
|
||||
mPreference.setExistingConfigValue(WifiConfiguration.AP_BAND_ANY);
|
||||
mPreference.onBindDialogView(mLayout);
|
||||
|
||||
// button is enabled whole time so far since we have a pre-existing selection
|
||||
verify(mSaveButton, never()).setEnabled(false);
|
||||
|
||||
// clear all boxes and make sure it stays enabled until empty
|
||||
mPreference.mBox2G.setChecked(false);
|
||||
mPreference.mBox5G.setChecked(false);
|
||||
|
||||
// button should be disabled now
|
||||
verify(mSaveButton, times(1)).setEnabled(false);
|
||||
}
|
||||
}
|
@@ -18,6 +18,7 @@ package com.android.settings.wifi.tether;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -26,16 +27,15 @@ import android.content.Context;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.support.v7.preference.ListPreference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.widget.HotspotApBandSelectionPreference;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
@@ -43,8 +43,9 @@ import org.robolectric.RuntimeEnvironment;
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class WifiTetherApBandPreferenceControllerTest {
|
||||
|
||||
private static final String ALL_BANDS = "2.4 GHz and 5.0 GHz";
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private static final String ALL_BANDS = "5.0 GHz Band preferred";
|
||||
private static final String TWO_GHZ_STRING = "2.4 GHz Band";
|
||||
private static final String FIVE_GHZ_STRING = "5.0 GHz Band";
|
||||
private Context mContext;
|
||||
@Mock
|
||||
private ConnectivityManager mConnectivityManager;
|
||||
@@ -56,12 +57,13 @@ public class WifiTetherApBandPreferenceControllerTest {
|
||||
private PreferenceScreen mScreen;
|
||||
|
||||
private WifiTetherApBandPreferenceController mController;
|
||||
private HotspotApBandSelectionPreference mPreference;
|
||||
private ListPreference mPreference;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mPreference = new HotspotApBandSelectionPreference(RuntimeEnvironment.application);
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
mPreference = new ListPreference(RuntimeEnvironment.application);
|
||||
when(mContext.getSystemService(Context.WIFI_SERVICE)).thenReturn(mWifiManager);
|
||||
when(mContext.getSystemService(Context.CONNECTIVITY_SERVICE))
|
||||
.thenReturn(mConnectivityManager);
|
||||
@@ -71,6 +73,7 @@ public class WifiTetherApBandPreferenceControllerTest {
|
||||
WifiConfiguration config = new WifiConfiguration();
|
||||
config.apBand = WifiConfiguration.AP_BAND_ANY;
|
||||
when(mWifiManager.getWifiApConfiguration()).thenReturn(new WifiConfiguration());
|
||||
when(mWifiManager.isDualModeSupported()).thenReturn(false);
|
||||
|
||||
mController = new WifiTetherApBandPreferenceController(mContext, mListener);
|
||||
}
|
||||
@@ -79,9 +82,10 @@ public class WifiTetherApBandPreferenceControllerTest {
|
||||
public void display_5GhzSupported_shouldDisplayFullList() {
|
||||
when(mWifiManager.getCountryCode()).thenReturn("US");
|
||||
when(mWifiManager.isDualBandSupported()).thenReturn(true);
|
||||
when(mWifiManager.isDualModeSupported()).thenReturn(true);
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
mController.onPreferenceChange(mPreference, -1);
|
||||
mController.onPreferenceChange(mPreference, "-1");
|
||||
|
||||
assertThat(mPreference.getSummary()).isEqualTo(ALL_BANDS);
|
||||
}
|
||||
@@ -100,6 +104,7 @@ public class WifiTetherApBandPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void display_5GhzNotSupported_shouldDisable() {
|
||||
when(mWifiManager.getCountryCode()).thenReturn("US");
|
||||
when(mWifiManager.isDualBandSupported()).thenReturn(false);
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
@@ -110,37 +115,71 @@ public class WifiTetherApBandPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void changePreference_shouldUpdateValue() {
|
||||
when(mWifiManager.is5GHzBandSupported()).thenReturn(true);
|
||||
public void changePreference_noDualModeWith5G_shouldUpdateValue() {
|
||||
when(mWifiManager.getCountryCode()).thenReturn("US");
|
||||
when(mWifiManager.isDualBandSupported()).thenReturn(true);
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
// -1 is WifiConfiguration.AP_BAND_ANY, for 'Auto' option. This should be prevented from
|
||||
// being set since it is invalid for this configuration
|
||||
mController.onPreferenceChange(mPreference, "-1");
|
||||
assertThat(mController.getBandIndex()).isEqualTo(1);
|
||||
assertThat(mPreference.getSummary()).isEqualTo(FIVE_GHZ_STRING);
|
||||
verify(mListener, times(1)).onTetherConfigUpdated();
|
||||
|
||||
// set to 5 Ghz
|
||||
mController.onPreferenceChange(mPreference, "1");
|
||||
assertThat(mController.getBandIndex()).isEqualTo(1);
|
||||
assertThat(mPreference.getSummary()).isEqualTo(FIVE_GHZ_STRING);
|
||||
verify(mListener, times(2)).onTetherConfigUpdated();
|
||||
|
||||
// set to 2 Ghz
|
||||
mController.onPreferenceChange(mPreference, "0");
|
||||
assertThat(mController.getBandIndex()).isEqualTo(0);
|
||||
assertThat(mPreference.getSummary()).isEqualTo(TWO_GHZ_STRING);
|
||||
verify(mListener, times(3)).onTetherConfigUpdated();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void changePreference_dualModeWith5G_shouldUpdateValue() {
|
||||
when(mWifiManager.getCountryCode()).thenReturn("US");
|
||||
when(mWifiManager.isDualBandSupported()).thenReturn(true);
|
||||
when(mWifiManager.isDualModeSupported()).thenReturn(true);
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
// -1 is WifiConfiguration.AP_BAND_ANY, for 'Auto' option.
|
||||
mController.onPreferenceChange(mPreference, -1);
|
||||
mController.onPreferenceChange(mPreference, "-1");
|
||||
assertThat(mController.getBandIndex()).isEqualTo(-1);
|
||||
assertThat(mPreference.getSummary()).isEqualTo(ALL_BANDS);
|
||||
verify(mListener, times(1)).onTetherConfigUpdated();
|
||||
|
||||
mController.onPreferenceChange(mPreference, 1);
|
||||
assertThat(mController.getBandIndex()).isEqualTo(1);
|
||||
assertThat(mPreference.getSummary()).isEqualTo("5.0 GHz");
|
||||
// should revert to the default for 5 Ghz only since this is not supported with this config
|
||||
mController.onPreferenceChange(mPreference, "1");
|
||||
assertThat(mController.getBandIndex()).isEqualTo(-1);
|
||||
assertThat(mPreference.getSummary()).isEqualTo(ALL_BANDS);
|
||||
verify(mListener, times(2)).onTetherConfigUpdated();
|
||||
|
||||
mController.onPreferenceChange(mPreference, 0);
|
||||
// set to 2 Ghz
|
||||
mController.onPreferenceChange(mPreference, "0");
|
||||
assertThat(mController.getBandIndex()).isEqualTo(0);
|
||||
assertThat(mPreference.getSummary()).isEqualTo("2.4 GHz");
|
||||
|
||||
assertThat(mPreference.getSummary()).isEqualTo(TWO_GHZ_STRING);
|
||||
verify(mListener, times(3)).onTetherConfigUpdated();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateDisplay_shouldUpdateValue() {
|
||||
when(mWifiManager.getCountryCode()).thenReturn("US");
|
||||
when(mWifiManager.isDualBandSupported()).thenReturn(true);
|
||||
|
||||
// Set controller band index to 1 and verify is set.
|
||||
when(mWifiManager.is5GHzBandSupported()).thenReturn(true);
|
||||
mController.displayPreference(mScreen);
|
||||
mController.onPreferenceChange(mPreference, 1);
|
||||
mController.onPreferenceChange(mPreference, "1");
|
||||
assertThat(mController.getBandIndex()).isEqualTo(1);
|
||||
|
||||
// Disable 5Ghz band
|
||||
when(mWifiManager.is5GHzBandSupported()).thenReturn(false);
|
||||
when(mWifiManager.isDualBandSupported()).thenReturn(false);
|
||||
|
||||
// Call updateDisplay and verify it's changed.
|
||||
mController.updateDisplay();
|
||||
|
Reference in New Issue
Block a user