Snap for 4900871 from 1d7ee9b997 to qt-release
Change-Id: Ifb6c4788553ff3030316afb84a5f86994073e8e5
This commit is contained in:
@@ -307,7 +307,7 @@
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
|
||||
android:value="com.android.settings.wifi.SavedAccessPointsWifiSettings" />
|
||||
android:value="com.android.settings.wifi.savedaccesspoints.SavedAccessPointsWifiSettings" />
|
||||
<meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
|
||||
android:value="true" />
|
||||
</activity>
|
||||
@@ -574,6 +574,12 @@
|
||||
android:value="true" />
|
||||
</activity>
|
||||
|
||||
<activity android:name=".localepicker.LocalePickerWithRegionActivity"
|
||||
android:excludeFromRecents="true"
|
||||
android:configChanges="orientation|keyboardHidden|screenSize"
|
||||
android:exported="false">
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".Settings$LanguageAndInputSettingsActivity"
|
||||
android:label="@string/language_settings"
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
<!--
|
||||
Copyright (C) 2016 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.
|
||||
-->
|
||||
<inset
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:insetLeft="5dp">
|
||||
<vector
|
||||
android:width="24.0dp"
|
||||
android:height="24.0dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0"
|
||||
android:tint="?android:attr/colorAccent">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M19.0,13.0l-6.0,0.0l0.0,6.0l-2.0,0.0l0.0,-6.0L5.0,13.0l0.0,-2.0l6.0,0.0L11.0,5.0l2.0,0.0l0.0,6.0l6.0,0.0l0.0,2.0z"/>
|
||||
</vector>
|
||||
</inset>
|
||||
@@ -6897,6 +6897,8 @@
|
||||
<string name="app_and_notification_dashboard_title">Apps & notifications</string>
|
||||
<!-- Summary for Apps & Notification settings, explaining a few important settings under it [CHAR LIMIT=NONE]-->
|
||||
<string name="app_and_notification_dashboard_summary">Permissions, default apps</string>
|
||||
<!-- Toast text for notification settings in the work profile. This is shown when an app in the work profile attempts to open notification settings. [CHAR LIMIT=NONE] -->
|
||||
<string name="notification_settings_work_profile">Notification access is not available for apps in the work profile.</string>
|
||||
<!-- Title for setting tile leading to account settings [CHAR LIMIT=40]-->
|
||||
<string name="account_dashboard_title">Accounts</string>
|
||||
<!-- Summary for account settings tiles when there is no accounts on device [CHAR LIMIT=NONE]-->
|
||||
|
||||
@@ -39,6 +39,6 @@
|
||||
<Preference
|
||||
android:key="saved_networks"
|
||||
android:title="@string/wifi_saved_access_points_label"
|
||||
android:fragment="com.android.settings.wifi.SavedAccessPointsWifiSettings" />
|
||||
android:fragment="com.android.settings.wifi.savedaccesspoints.SavedAccessPointsWifiSettings" />
|
||||
</PreferenceCategory>
|
||||
</PreferenceScreen>
|
||||
|
||||
@@ -633,8 +633,14 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
|
||||
mCategoryToPrefCategoryMap.get(CATEGORY_DISPLAY);
|
||||
experimentalCategory.removePreference(mToggleInversionPreference);
|
||||
experimentalCategory.removePreference(mDisplayDaltonizerPreferenceScreen);
|
||||
mToggleInversionPreference.setOrder(mToggleLargePointerIconPreference.getOrder());
|
||||
mDisplayDaltonizerPreferenceScreen.setOrder(mToggleInversionPreference.getOrder());
|
||||
mDisplayDaltonizerPreferenceScreen.setOrder(
|
||||
mDisplayMagnificationPreferenceScreen.getOrder() + 1);
|
||||
mToggleInversionPreference.setOrder(
|
||||
mDisplayDaltonizerPreferenceScreen.getOrder() + 1);
|
||||
mToggleLargePointerIconPreference.setOrder(
|
||||
mToggleInversionPreference.getOrder() + 1);
|
||||
mToggleDisableAnimationsPreference.setOrder(
|
||||
mToggleLargePointerIconPreference.getOrder() + 1);
|
||||
mToggleInversionPreference.setSummary(R.string.summary_empty);
|
||||
displayCategory.addPreference(mToggleInversionPreference);
|
||||
displayCategory.addPreference(mDisplayDaltonizerPreferenceScreen);
|
||||
|
||||
@@ -28,6 +28,7 @@ import android.util.Pair;
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
|
||||
import com.android.settings.fuelgauge.BatteryUtils;
|
||||
import com.android.settings.widget.RadioButtonPickerFragment;
|
||||
import com.android.settings.widget.RadioButtonPreference;
|
||||
import com.android.settingslib.applications.DefaultAppInfo;
|
||||
@@ -43,11 +44,13 @@ import androidx.fragment.app.FragmentActivity;
|
||||
public abstract class DefaultAppPickerFragment extends RadioButtonPickerFragment {
|
||||
|
||||
protected PackageManager mPm;
|
||||
protected BatteryUtils mBatteryUtils;
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
mPm = context.getPackageManager();
|
||||
mBatteryUtils = BatteryUtils.getInstance(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -80,6 +80,7 @@ public class DefaultPhonePicker extends DefaultAppPickerFragment {
|
||||
@Override
|
||||
protected boolean setDefaultKey(String key) {
|
||||
if (!TextUtils.isEmpty(key) && !TextUtils.equals(key, getDefaultKey())) {
|
||||
mBatteryUtils.clearForceAppStandby(key);
|
||||
return mDefaultKeyUpdater.setDefaultDialerApplication(getContext(), key, mUserId);
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.android.settings.applications.defaultapps;
|
||||
|
||||
import android.app.AppOpsManager;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
@@ -25,6 +26,7 @@ import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.internal.telephony.SmsApplication;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.fuelgauge.BatteryUtils;
|
||||
import com.android.settingslib.applications.DefaultAppInfo;
|
||||
import com.android.settingslib.widget.CandidateInfo;
|
||||
|
||||
@@ -74,6 +76,7 @@ public class DefaultSmsPicker extends DefaultAppPickerFragment {
|
||||
protected boolean setDefaultKey(String key) {
|
||||
if (!TextUtils.isEmpty(key) && !TextUtils.equals(key, getDefaultKey())) {
|
||||
mDefaultKeyUpdater.setDefaultApplication(getContext(), key);
|
||||
mBatteryUtils.clearForceAppStandby(key);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -455,10 +455,7 @@ public class DeviceAdminAdd extends Activity {
|
||||
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);
|
||||
}
|
||||
batteryUtils.clearForceAppStandby(packageName);
|
||||
}
|
||||
|
||||
void continueRemoveAction(CharSequence msg) {
|
||||
|
||||
@@ -38,7 +38,6 @@ import com.android.settings.applications.DirectoryAccessDetails;
|
||||
import com.android.settings.applications.ProcessStatsSummary;
|
||||
import com.android.settings.applications.ProcessStatsUi;
|
||||
import com.android.settings.applications.UsageAccessDetails;
|
||||
import com.android.settings.applications.specialaccess.vrlistener.VrListenerSettings;
|
||||
import com.android.settings.applications.appinfo.AppInfoDashboardFragment;
|
||||
import com.android.settings.applications.appinfo.DrawOverlayDetails;
|
||||
import com.android.settings.applications.appinfo.ExternalSourcesDetails;
|
||||
@@ -50,6 +49,7 @@ import com.android.settings.applications.managedomainurls.ManageDomainUrls;
|
||||
import com.android.settings.applications.specialaccess.deviceadmin.DeviceAdminSettings;
|
||||
import com.android.settings.applications.specialaccess.pictureinpicture.PictureInPictureDetails;
|
||||
import com.android.settings.applications.specialaccess.pictureinpicture.PictureInPictureSettings;
|
||||
import com.android.settings.applications.specialaccess.vrlistener.VrListenerSettings;
|
||||
import com.android.settings.backup.PrivacySettings;
|
||||
import com.android.settings.backup.ToggleBackupSettingFragment;
|
||||
import com.android.settings.bluetooth.BluetoothDeviceDetailsFragment;
|
||||
@@ -127,12 +127,12 @@ import com.android.settings.wallpaper.WallpaperTypeSettings;
|
||||
import com.android.settings.webview.WebViewAppPicker;
|
||||
import com.android.settings.wfd.WifiDisplaySettings;
|
||||
import com.android.settings.wifi.ConfigureWifiSettings;
|
||||
import com.android.settings.wifi.SavedAccessPointsWifiSettings;
|
||||
import com.android.settings.wifi.WifiAPITest;
|
||||
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.savedaccesspoints.SavedAccessPointsWifiSettings;
|
||||
import com.android.settings.wifi.tether.WifiTetherSettings;
|
||||
|
||||
public class SettingsGateway {
|
||||
|
||||
@@ -407,6 +407,16 @@ public class BatteryUtils {
|
||||
packageName) == AppOpsManager.MODE_IGNORED;
|
||||
}
|
||||
|
||||
public boolean clearForceAppStandby(String packageName) {
|
||||
final int uid = getPackageUid(packageName);
|
||||
if (uid != UID_NULL && isForceAppStandbyEnabled(uid, packageName)) {
|
||||
setForceAppStandby(uid, packageName, AppOpsManager.MODE_ALLOWED);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void initBatteryStatsHelper(BatteryStatsHelper statsHelper, Bundle bundle,
|
||||
UserManager userManager) {
|
||||
statsHelper.create(bundle);
|
||||
|
||||
@@ -18,8 +18,10 @@ package com.android.settings.localepicker;
|
||||
|
||||
import static android.os.UserManager.DISALLOW_CONFIG_LOCALE;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.LocaleList;
|
||||
import android.view.LayoutInflater;
|
||||
@@ -40,18 +42,18 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
/**
|
||||
* Drag-and-drop editor for the user-ordered locale lists.
|
||||
*/
|
||||
public class LocaleListEditor extends RestrictedSettingsFragment
|
||||
implements LocalePickerWithRegion.LocaleSelectedListener {
|
||||
public class LocaleListEditor extends RestrictedSettingsFragment {
|
||||
|
||||
protected static final String INTENT_LOCALE_KEY = "localeInfo";
|
||||
private static final String CFGKEY_REMOVE_MODE = "localeRemoveMode";
|
||||
private static final String CFGKEY_REMOVE_DIALOG = "showingLocaleRemoveDialog";
|
||||
private static final int MENU_ID_REMOVE = Menu.FIRST + 1;
|
||||
private static final int REQUEST_LOCALE_PICKER = 0;
|
||||
|
||||
private LocaleDragAndDropAdapter mAdapter;
|
||||
private Menu mMenu;
|
||||
@@ -150,6 +152,19 @@ public class LocaleListEditor extends RestrictedSettingsFragment
|
||||
return super.onOptionsItemSelected(menuItem);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if (requestCode == REQUEST_LOCALE_PICKER && resultCode == Activity.RESULT_OK
|
||||
&& data != null) {
|
||||
final LocaleStore.LocaleInfo locale =
|
||||
(LocaleStore.LocaleInfo) data.getSerializableExtra(
|
||||
INTENT_LOCALE_KEY);
|
||||
mAdapter.addLocale(locale);
|
||||
updateVisibilityOfRemoveMenu();
|
||||
}
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
|
||||
private void setRemoveMode(boolean mRemoveMode) {
|
||||
this.mRemoveMode = mRemoveMode;
|
||||
mAdapter.setRemoveMode(mRemoveMode);
|
||||
@@ -267,24 +282,13 @@ public class LocaleListEditor extends RestrictedSettingsFragment
|
||||
mAddLanguage.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
final LocalePickerWithRegion selector = LocalePickerWithRegion.createLanguagePicker(
|
||||
getContext(), LocaleListEditor.this, false /* translate only */);
|
||||
getFragmentManager()
|
||||
.beginTransaction()
|
||||
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
|
||||
.replace(getId(), selector)
|
||||
.addToBackStack("localeListEditor")
|
||||
.commit();
|
||||
final Intent intent = new Intent(getActivity(),
|
||||
LocalePickerWithRegionActivity.class);
|
||||
startActivityForResult(intent, REQUEST_LOCALE_PICKER);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLocaleSelected(LocaleStore.LocaleInfo locale) {
|
||||
mAdapter.addLocale(locale);
|
||||
updateVisibilityOfRemoveMenu();
|
||||
}
|
||||
|
||||
// Hide the "Remove" menu if there is only one locale in the list, show it otherwise
|
||||
// This is called when the menu is first created, and then one add / remove locale
|
||||
private void updateVisibilityOfRemoveMenu() {
|
||||
|
||||
@@ -1,278 +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.localepicker;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.os.LocaleList;
|
||||
import android.text.TextUtils;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.ListView;
|
||||
import android.widget.SearchView;
|
||||
|
||||
import com.android.internal.R;
|
||||
import com.android.internal.app.LocaleHelper;
|
||||
import com.android.internal.app.LocalePicker;
|
||||
import com.android.internal.app.LocaleStore;
|
||||
import com.android.internal.app.SuggestedLocaleAdapter;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
import androidx.fragment.app.ListFragment;
|
||||
|
||||
/**
|
||||
* A two-step locale picker. It shows a language, then a country.
|
||||
*
|
||||
* <p>It shows suggestions at the top, then the rest of the locales.
|
||||
* Allows the user to search for locales using both their native name and their name in the
|
||||
* default locale.</p>
|
||||
*/
|
||||
public class LocalePickerWithRegion extends ListFragment implements SearchView.OnQueryTextListener {
|
||||
private static final String PARENT_FRAGMENT_NAME = "localeListEditor";
|
||||
|
||||
private SuggestedLocaleAdapter mAdapter;
|
||||
private LocaleSelectedListener mListener;
|
||||
private Set<LocaleStore.LocaleInfo> mLocaleList;
|
||||
private LocaleStore.LocaleInfo mParentLocale;
|
||||
private boolean mTranslatedOnly = false;
|
||||
private SearchView mSearchView = null;
|
||||
private CharSequence mPreviousSearch = null;
|
||||
private boolean mPreviousSearchHadFocus = false;
|
||||
private int mFirstVisiblePosition = 0;
|
||||
private int mTopDistance = 0;
|
||||
|
||||
/**
|
||||
* Other classes can register to be notified when a locale was selected.
|
||||
*
|
||||
* <p>This is the mechanism to "return" the result of the selection.</p>
|
||||
*/
|
||||
public interface LocaleSelectedListener {
|
||||
/**
|
||||
* The classes that want to retrieve the locale picked should implement this method.
|
||||
* @param locale the locale picked.
|
||||
*/
|
||||
void onLocaleSelected(LocaleStore.LocaleInfo locale);
|
||||
}
|
||||
|
||||
private static LocalePickerWithRegion createCountryPicker(Context context,
|
||||
LocaleSelectedListener listener, LocaleStore.LocaleInfo parent,
|
||||
boolean translatedOnly) {
|
||||
LocalePickerWithRegion
|
||||
localePicker = new LocalePickerWithRegion();
|
||||
boolean shouldShowTheList = localePicker.setListener(context, listener, parent,
|
||||
translatedOnly);
|
||||
return shouldShowTheList ? localePicker : null;
|
||||
}
|
||||
|
||||
public static LocalePickerWithRegion createLanguagePicker(Context context,
|
||||
LocaleSelectedListener listener, boolean translatedOnly) {
|
||||
LocalePickerWithRegion
|
||||
localePicker = new LocalePickerWithRegion();
|
||||
localePicker.setListener(context, listener, /* parent */ null, translatedOnly);
|
||||
return localePicker;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the listener and initializes the locale list.
|
||||
*
|
||||
* <p>Returns true if we need to show the list, false if not.</p>
|
||||
*
|
||||
* <p>Can return false because of an error, trying to show a list of countries,
|
||||
* but no parent locale was provided.</p>
|
||||
*
|
||||
* <p>It can also return false if the caller tries to show the list in country mode and
|
||||
* there is only one country available (i.e. Japanese => Japan).
|
||||
* In this case we don't even show the list, we call the listener with that locale,
|
||||
* "pretending" it was selected, and return false.</p>
|
||||
*/
|
||||
private boolean setListener(Context context, LocaleSelectedListener listener,
|
||||
LocaleStore.LocaleInfo parent, boolean translatedOnly) {
|
||||
this.mParentLocale = parent;
|
||||
this.mListener = listener;
|
||||
this.mTranslatedOnly = translatedOnly;
|
||||
setRetainInstance(true);
|
||||
|
||||
final HashSet<String> langTagsToIgnore = new HashSet<>();
|
||||
if (!translatedOnly) {
|
||||
final LocaleList userLocales = LocalePicker.getLocales();
|
||||
final String[] langTags = userLocales.toLanguageTags().split(",");
|
||||
Collections.addAll(langTagsToIgnore, langTags);
|
||||
}
|
||||
|
||||
if (parent != null) {
|
||||
mLocaleList = LocaleStore.getLevelLocales(context,
|
||||
langTagsToIgnore, parent, translatedOnly);
|
||||
if (mLocaleList.size() <= 1) {
|
||||
if (listener != null && (mLocaleList.size() == 1)) {
|
||||
listener.onLocaleSelected(mLocaleList.iterator().next());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
mLocaleList = LocaleStore.getLevelLocales(context, langTagsToIgnore,
|
||||
null /* no parent */, translatedOnly);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void returnToParentFrame() {
|
||||
getFragmentManager().popBackStack(PARENT_FRAGMENT_NAME,
|
||||
FragmentManager.POP_BACK_STACK_INCLUSIVE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setHasOptionsMenu(true);
|
||||
|
||||
if (mLocaleList == null) {
|
||||
// The fragment was killed and restored by the FragmentManager.
|
||||
// At this point we have no data, no listener. Just return, to prevend a NPE.
|
||||
// Fixes b/28748150. Created b/29400003 for a cleaner solution.
|
||||
returnToParentFrame();
|
||||
return;
|
||||
}
|
||||
|
||||
final boolean countryMode = mParentLocale != null;
|
||||
final Locale sortingLocale = countryMode ? mParentLocale.getLocale() : Locale.getDefault();
|
||||
mAdapter = new SuggestedLocaleAdapter(mLocaleList, countryMode);
|
||||
final LocaleHelper.LocaleInfoComparator comp =
|
||||
new LocaleHelper.LocaleInfoComparator(sortingLocale, countryMode);
|
||||
mAdapter.sort(comp);
|
||||
setListAdapter(mAdapter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem menuItem) {
|
||||
int id = menuItem.getItemId();
|
||||
switch (id) {
|
||||
case android.R.id.home:
|
||||
getFragmentManager().popBackStack();
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(menuItem);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
||||
if (mParentLocale != null) {
|
||||
getActivity().setTitle(mParentLocale.getFullNameNative());
|
||||
} else {
|
||||
getActivity().setTitle(R.string.language_selection_title);
|
||||
}
|
||||
|
||||
getListView().requestFocus();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
|
||||
// Save search status
|
||||
if (mSearchView != null) {
|
||||
mPreviousSearchHadFocus = mSearchView.hasFocus();
|
||||
mPreviousSearch = mSearchView.getQuery();
|
||||
} else {
|
||||
mPreviousSearchHadFocus = false;
|
||||
mPreviousSearch = null;
|
||||
}
|
||||
|
||||
// Save scroll position
|
||||
final ListView list = getListView();
|
||||
final View firstChild = list.getChildAt(0);
|
||||
mFirstVisiblePosition = list.getFirstVisiblePosition();
|
||||
mTopDistance = (firstChild == null) ? 0 : (firstChild.getTop() - list.getPaddingTop());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onListItemClick(ListView l, View v, int position, long id) {
|
||||
final LocaleStore.LocaleInfo locale =
|
||||
(LocaleStore.LocaleInfo) getListAdapter().getItem(position);
|
||||
|
||||
if (locale.getParent() != null) {
|
||||
if (mListener != null) {
|
||||
mListener.onLocaleSelected(locale);
|
||||
}
|
||||
returnToParentFrame();
|
||||
} else {
|
||||
LocalePickerWithRegion
|
||||
selector = LocalePickerWithRegion.createCountryPicker(
|
||||
getContext(), mListener, locale, mTranslatedOnly /* translate only */);
|
||||
if (selector != null) {
|
||||
getFragmentManager().beginTransaction()
|
||||
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
|
||||
.replace(getId(), selector).addToBackStack(null)
|
||||
.commit();
|
||||
} else {
|
||||
returnToParentFrame();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
if (mParentLocale == null) {
|
||||
inflater.inflate(R.menu.language_selection_list, menu);
|
||||
|
||||
final MenuItem searchMenuItem = menu.findItem(R.id.locale_search_menu);
|
||||
mSearchView = (SearchView) searchMenuItem.getActionView();
|
||||
|
||||
mSearchView.setQueryHint(getText(R.string.search_language_hint));
|
||||
mSearchView.setOnQueryTextListener(this);
|
||||
|
||||
// Restore previous search status
|
||||
if (!TextUtils.isEmpty(mPreviousSearch)) {
|
||||
searchMenuItem.expandActionView();
|
||||
mSearchView.setIconified(false);
|
||||
mSearchView.setActivated(true);
|
||||
if (mPreviousSearchHadFocus) {
|
||||
mSearchView.requestFocus();
|
||||
}
|
||||
mSearchView.setQuery(mPreviousSearch, true /* submit */);
|
||||
} else {
|
||||
mSearchView.setQuery(null, false /* submit */);
|
||||
}
|
||||
|
||||
// Restore previous scroll position
|
||||
getListView().setSelectionFromTop(mFirstVisiblePosition, mTopDistance);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onQueryTextSubmit(String query) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onQueryTextChange(String newText) {
|
||||
if (mAdapter != null) {
|
||||
mAdapter.getFilter().filter(newText);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* 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.localepicker;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.FragmentTransaction;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.MenuItem;
|
||||
|
||||
import com.android.internal.app.LocalePickerWithRegion;
|
||||
import com.android.internal.app.LocaleStore;
|
||||
|
||||
public class LocalePickerWithRegionActivity extends Activity
|
||||
implements LocalePickerWithRegion.LocaleSelectedListener {
|
||||
|
||||
private static final String PARENT_FRAGMENT_NAME = "localeListEditor";
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
getActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
final LocalePickerWithRegion selector = LocalePickerWithRegion.createLanguagePicker(
|
||||
this, LocalePickerWithRegionActivity.this, false /* translate only */);
|
||||
getFragmentManager()
|
||||
.beginTransaction()
|
||||
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
|
||||
.replace(android.R.id.content, selector)
|
||||
.addToBackStack(PARENT_FRAGMENT_NAME)
|
||||
.commit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if (item.getItemId() == android.R.id.home) {
|
||||
handleBackPressed();
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLocaleSelected(LocaleStore.LocaleInfo locale) {
|
||||
final Intent intent = new Intent();
|
||||
intent.putExtra(LocaleListEditor.INTENT_LOCALE_KEY, locale);
|
||||
setResult(RESULT_OK, intent);
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
handleBackPressed();
|
||||
}
|
||||
|
||||
private void handleBackPressed() {
|
||||
if (getFragmentManager().getBackStackEntryCount() > 1) {
|
||||
super.onBackPressed();
|
||||
} else {
|
||||
setResult(RESULT_CANCELED);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,10 +23,12 @@ import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserManager;
|
||||
import android.provider.SearchIndexableResource;
|
||||
import android.provider.Settings;
|
||||
import android.service.notification.NotificationListenerService;
|
||||
|
||||
import android.widget.Toast;
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
|
||||
@@ -61,6 +63,18 @@ public class NotificationAccessSettings extends ManagedServiceSettings {
|
||||
|
||||
private NotificationManager mNm;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
final Context ctx = getContext();
|
||||
if (UserManager.get(ctx).isManagedProfile()) {
|
||||
// Apps in the work profile do not support notification listeners.
|
||||
Toast.makeText(ctx, R.string.notification_settings_work_profile, Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsEvent.NOTIFICATION_ACCESS;
|
||||
|
||||
@@ -27,12 +27,6 @@ public class LongPressAccessPointPreference extends AccessPointPreference {
|
||||
|
||||
private final Fragment mFragment;
|
||||
|
||||
public LongPressAccessPointPreference(AccessPoint accessPoint, Context context,
|
||||
UserBadgeCache cache, boolean forSavedNetworks, Fragment fragment) {
|
||||
super(accessPoint, context, cache, forSavedNetworks);
|
||||
mFragment = fragment;
|
||||
}
|
||||
|
||||
public LongPressAccessPointPreference(AccessPoint accessPoint, Context context,
|
||||
UserBadgeCache cache, boolean forSavedNetworks, int iconResId, Fragment fragment) {
|
||||
super(accessPoint, context, cache, iconResId, forSavedNetworks);
|
||||
|
||||
@@ -21,6 +21,7 @@ import com.android.settings.ButtonBarHandler;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.wifi.p2p.WifiP2pSettings;
|
||||
import com.android.settings.wifi.savedaccesspoints.SavedAccessPointsWifiSettings;
|
||||
|
||||
import androidx.preference.PreferenceFragmentCompat;
|
||||
|
||||
|
||||
@@ -231,7 +231,7 @@ public class WifiSettings extends RestrictedSettingsFragment
|
||||
|
||||
Context prefContext = getPrefContext();
|
||||
mAddPreference = new Preference(prefContext);
|
||||
mAddPreference.setIcon(R.drawable.ic_menu_add_inset);
|
||||
mAddPreference.setIcon(R.drawable.ic_menu_add);
|
||||
mAddPreference.setTitle(R.string.wifi_add_network);
|
||||
mStatusMessagePreference = new LinkablePreference(prefContext);
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.wifi;
|
||||
package com.android.settings.wifi.savedaccesspoints;
|
||||
|
||||
import android.annotation.Nullable;
|
||||
import android.app.Activity;
|
||||
@@ -26,30 +26,29 @@ import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settings.search.Indexable;
|
||||
import com.android.settings.wifi.WifiConfigUiBase;
|
||||
import com.android.settings.wifi.WifiDialog;
|
||||
import com.android.settings.wifi.WifiSettings;
|
||||
import com.android.settingslib.wifi.AccessPoint;
|
||||
import com.android.settingslib.wifi.AccessPointPreference;
|
||||
import com.android.settingslib.wifi.WifiSavedConfigUtils;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
/**
|
||||
* UI to manage saved networks/access points.
|
||||
* TODO(b/64806699): convert to {@link DashboardFragment} with {@link PreferenceController}s
|
||||
*/
|
||||
public class SavedAccessPointsWifiSettings extends SettingsPreferenceFragment
|
||||
implements Indexable, WifiDialog.WifiDialogListener {
|
||||
implements WifiDialog.WifiDialogListener {
|
||||
private static final String TAG = "SavedAccessPoints";
|
||||
@VisibleForTesting
|
||||
static final int MSG_UPDATE_PREFERENCES = 1;
|
||||
@@ -111,7 +110,6 @@ public class SavedAccessPointsWifiSettings extends SettingsPreferenceFragment
|
||||
private AccessPoint mDlgAccessPoint;
|
||||
private Bundle mAccessPointSavedState;
|
||||
private AccessPoint mSelectedAccessPoint;
|
||||
private Preference mAddNetworkPreference;
|
||||
|
||||
private AccessPointPreference.UserBadgeCache mUserBadgeCache;
|
||||
|
||||
@@ -139,7 +137,8 @@ public class SavedAccessPointsWifiSettings extends SettingsPreferenceFragment
|
||||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
|
||||
mWifiManager = (WifiManager) getContext()
|
||||
.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
if (savedInstanceState.containsKey(SAVE_DIALOG_ACCESS_POINT_STATE)) {
|
||||
@@ -162,11 +161,10 @@ public class SavedAccessPointsWifiSettings extends SettingsPreferenceFragment
|
||||
for (int i = 0; i < accessPointsSize; ++i) {
|
||||
AccessPoint ap = accessPoints.get(i);
|
||||
String key = ap.getKey();
|
||||
LongPressAccessPointPreference preference =
|
||||
(LongPressAccessPointPreference) getCachedPreference(key);
|
||||
AccessPointPreference preference =
|
||||
(AccessPointPreference) getCachedPreference(key);
|
||||
if (preference == null) {
|
||||
preference = new LongPressAccessPointPreference(
|
||||
ap, context, mUserBadgeCache, true, this);
|
||||
preference = new AccessPointPreference(ap, context, mUserBadgeCache, true);
|
||||
preference.setKey(key);
|
||||
preference.setIcon(null);
|
||||
preferenceScreen.addPreference(preference);
|
||||
@@ -176,14 +174,6 @@ public class SavedAccessPointsWifiSettings extends SettingsPreferenceFragment
|
||||
|
||||
removeCachedPrefs(preferenceScreen);
|
||||
|
||||
if (mAddNetworkPreference == null) {
|
||||
mAddNetworkPreference = new Preference(getPrefContext());
|
||||
mAddNetworkPreference.setIcon(R.drawable.ic_menu_add_inset);
|
||||
mAddNetworkPreference.setTitle(R.string.wifi_add_network);
|
||||
}
|
||||
mAddNetworkPreference.setOrder(accessPointsSize);
|
||||
preferenceScreen.addPreference(mAddNetworkPreference);
|
||||
|
||||
if(getPreferenceScreen().getPreferenceCount() < 1) {
|
||||
Log.w(TAG, "Saved networks activity loaded, but there are no saved networks!");
|
||||
}
|
||||
@@ -195,7 +185,7 @@ public class SavedAccessPointsWifiSettings extends SettingsPreferenceFragment
|
||||
}
|
||||
}
|
||||
|
||||
private void showWifiDialog(@Nullable LongPressAccessPointPreference accessPoint) {
|
||||
private void showWifiDialog(@Nullable AccessPointPreference accessPoint) {
|
||||
if (mDialog != null) {
|
||||
removeDialog(WifiSettings.WIFI_DIALOG_ID);
|
||||
mDialog = null;
|
||||
@@ -290,11 +280,8 @@ public class SavedAccessPointsWifiSettings extends SettingsPreferenceFragment
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceTreeClick(Preference preference) {
|
||||
if (preference instanceof LongPressAccessPointPreference) {
|
||||
showWifiDialog((LongPressAccessPointPreference) preference);
|
||||
return true;
|
||||
} else if (preference == mAddNetworkPreference) {
|
||||
showWifiDialog(null);
|
||||
if (preference instanceof AccessPointPreference) {
|
||||
showWifiDialog((AccessPointPreference) preference);
|
||||
return true;
|
||||
} else {
|
||||
return super.onPreferenceTreeClick(preference);
|
||||
@@ -73,5 +73,5 @@ com.android.settings.wifi.calling.WifiCallingSettingsForSub
|
||||
com.android.settings.wifi.ChangeWifiStateDetails
|
||||
com.android.settings.wifi.details.WifiNetworkDetailsFragment
|
||||
com.android.settings.wifi.p2p.WifiP2pSettings
|
||||
com.android.settings.wifi.SavedAccessPointsWifiSettings
|
||||
com.android.settings.wifi.savedaccesspoints.SavedAccessPointsWifiSettings
|
||||
com.android.settings.wifi.WifiInfo
|
||||
|
||||
@@ -5,5 +5,4 @@ com.android.settings.password.ChooseLockPassword$SaveAndFinishWorker
|
||||
com.android.settings.password.ChooseLockPattern$SaveAndFinishWorker
|
||||
com.android.settings.RestrictedListPreference$RestrictedListPreferenceDialogFragment
|
||||
com.android.settings.password.ConfirmDeviceCredentialBaseFragment$LastTryDialog
|
||||
com.android.settings.password.CredentialCheckResultTracker
|
||||
com.android.settings.localepicker.LocalePickerWithRegion
|
||||
com.android.settings.password.CredentialCheckResultTracker
|
||||
@@ -1,5 +1,8 @@
|
||||
<resources>
|
||||
<style name="Theme.Settings" parent="@android:style/Theme.DeviceDefault.Settings" />
|
||||
<style name="Theme.Settings" parent="@android:style/Theme.DeviceDefault.Settings">
|
||||
<!-- For AndroidX AlertDialogs -->
|
||||
<item name="alertDialogTheme">@style/Theme.AppCompat.DayNight.Dialog.Alert</item>
|
||||
</style>
|
||||
|
||||
<!-- Override the main app's style for ActionPrimaryButton to get around lack of new style
|
||||
support in robolectric -->
|
||||
|
||||
@@ -29,6 +29,7 @@ import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.UserManager;
|
||||
|
||||
import com.android.settings.fuelgauge.BatteryUtils;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -53,6 +54,8 @@ public class DefaultPhonePickerTest {
|
||||
private DefaultPhonePicker.DefaultKeyUpdater mDefaultKeyUpdater;
|
||||
@Mock
|
||||
private PackageManager mPackageManager;
|
||||
@Mock
|
||||
private BatteryUtils mBatteryUtils;
|
||||
|
||||
private DefaultPhonePicker mPicker;
|
||||
|
||||
@@ -66,6 +69,7 @@ public class DefaultPhonePickerTest {
|
||||
|
||||
ReflectionHelpers.setField(mPicker, "mPm", mPackageManager);
|
||||
ReflectionHelpers.setField(mPicker, "mDefaultKeyUpdater", mDefaultKeyUpdater);
|
||||
ReflectionHelpers.setField(mPicker, "mBatteryUtils", mBatteryUtils);
|
||||
doReturn(RuntimeEnvironment.application).when(mPicker).getContext();
|
||||
}
|
||||
|
||||
@@ -87,6 +91,14 @@ public class DefaultPhonePickerTest {
|
||||
@Test
|
||||
public void getDefaultAppKey_shouldReturnDefault() {
|
||||
mPicker.getDefaultKey();
|
||||
|
||||
verify(mDefaultKeyUpdater).getDefaultDialerApplication(any(Context.class), anyInt());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setDefaultKey_shouldUnrestrictApp() {
|
||||
mPicker.setDefaultKey(TEST_APP_KEY);
|
||||
|
||||
verify(mBatteryUtils).clearForceAppStandby(TEST_APP_KEY);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.UserManager;
|
||||
|
||||
import com.android.settings.fuelgauge.BatteryUtils;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -52,6 +53,8 @@ public class DefaultSmsPickerTest {
|
||||
private DefaultSmsPicker.DefaultKeyUpdater mDefaultKeyUpdater;
|
||||
@Mock
|
||||
private PackageManager mPackageManager;
|
||||
@Mock
|
||||
private BatteryUtils mBatteryUtils;
|
||||
|
||||
private DefaultSmsPicker mPicker;
|
||||
|
||||
@@ -64,6 +67,7 @@ public class DefaultSmsPickerTest {
|
||||
|
||||
ReflectionHelpers.setField(mPicker, "mPm", mPackageManager);
|
||||
ReflectionHelpers.setField(mPicker, "mDefaultKeyUpdater", mDefaultKeyUpdater);
|
||||
ReflectionHelpers.setField(mPicker, "mBatteryUtils", mBatteryUtils);
|
||||
doReturn(RuntimeEnvironment.application).when(mPicker).getContext();
|
||||
}
|
||||
|
||||
@@ -80,4 +84,11 @@ public class DefaultSmsPickerTest {
|
||||
|
||||
verify(mDefaultKeyUpdater).getDefaultApplication(any(Context.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setDefaultKey_shouldUnrestrictApp() {
|
||||
mPicker.setDefaultKey(TEST_APP_KEY);
|
||||
|
||||
verify(mBatteryUtils).clearForceAppStandby(TEST_APP_KEY);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,9 +17,13 @@
|
||||
package com.android.settings.applications.specialaccess.deviceadmin;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@@ -39,6 +43,7 @@ import org.mockito.Answers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.Robolectric;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class DeviceAdminAddTest {
|
||||
@@ -47,7 +52,6 @@ public class DeviceAdminAddTest {
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private DeviceAdminInfo mDeviceAdmin;
|
||||
@Mock
|
||||
private BatteryUtils mBatteryUtils;
|
||||
private FakeFeatureFactory mFeatureFactory;
|
||||
private DeviceAdminAdd mDeviceAdminAdd;
|
||||
@@ -56,6 +60,8 @@ public class DeviceAdminAddTest {
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
mBatteryUtils = spy(BatteryUtils.getInstance(RuntimeEnvironment.application));
|
||||
doNothing().when(mBatteryUtils).setForceAppStandby(anyInt(), anyString(), anyInt());
|
||||
mFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||
mDeviceAdminAdd = Robolectric.buildActivity(DeviceAdminAdd.class).get();
|
||||
|
||||
|
||||
@@ -653,4 +653,35 @@ public class BatteryUtilsTest {
|
||||
assertThat(mBatteryUtils.shouldHideAnomaly(mPowerWhitelistBackend, UID,
|
||||
mAnomalyInfo)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clearForceAppStandby_appRestricted_clearAndReturnTrue() {
|
||||
when(mBatteryUtils.getPackageUid(HIGH_SDK_PACKAGE)).thenReturn(UID);
|
||||
when(mAppOpsManager.checkOpNoThrow(AppOpsManager.OP_RUN_ANY_IN_BACKGROUND, UID,
|
||||
HIGH_SDK_PACKAGE)).thenReturn(AppOpsManager.MODE_IGNORED);
|
||||
|
||||
assertThat(mBatteryUtils.clearForceAppStandby(HIGH_SDK_PACKAGE)).isTrue();
|
||||
verify(mAppOpsManager).setMode(AppOpsManager.OP_RUN_ANY_IN_BACKGROUND, UID,
|
||||
HIGH_SDK_PACKAGE, AppOpsManager.MODE_ALLOWED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clearForceAppStandby_appInvalid_returnFalse() {
|
||||
when(mBatteryUtils.getPackageUid(PACKAGE_NAME)).thenReturn(BatteryUtils.UID_NULL);
|
||||
|
||||
assertThat(mBatteryUtils.clearForceAppStandby(PACKAGE_NAME)).isFalse();
|
||||
verify(mAppOpsManager, never()).setMode(AppOpsManager.OP_RUN_ANY_IN_BACKGROUND, UID,
|
||||
PACKAGE_NAME, AppOpsManager.MODE_ALLOWED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clearForceAppStandby_appUnrestricted_returnFalse() {
|
||||
when(mBatteryUtils.getPackageUid(PACKAGE_NAME)).thenReturn(UID);
|
||||
when(mAppOpsManager.checkOpNoThrow(AppOpsManager.OP_RUN_ANY_IN_BACKGROUND, UID,
|
||||
PACKAGE_NAME)).thenReturn(AppOpsManager.MODE_ALLOWED);
|
||||
|
||||
assertThat(mBatteryUtils.clearForceAppStandby(PACKAGE_NAME)).isFalse();
|
||||
verify(mAppOpsManager, never()).setMode(AppOpsManager.OP_RUN_ANY_IN_BACKGROUND, UID,
|
||||
PACKAGE_NAME, AppOpsManager.MODE_ALLOWED);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.android.settings.localepicker;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
|
||||
import android.app.Activity;
|
||||
|
||||
import com.android.internal.app.LocaleStore;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.Robolectric;
|
||||
import org.robolectric.Shadows;
|
||||
import org.robolectric.android.controller.ActivityController;
|
||||
import org.robolectric.shadows.ShadowActivity;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class LocalePickerWithRegionActivityTest {
|
||||
|
||||
private LocalePickerWithRegionActivity mActivity;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
final ActivityController<LocalePickerWithRegionActivity> mActivityController =
|
||||
Robolectric.buildActivity(LocalePickerWithRegionActivity.class);
|
||||
mActivity = spy(mActivityController.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onLocaleSelected_resultShouldBeOK() {
|
||||
final ShadowActivity shadowActivity = Shadows.shadowOf(mActivity);
|
||||
mActivity.onLocaleSelected(mock(LocaleStore.LocaleInfo.class));
|
||||
|
||||
assertEquals(Activity.RESULT_OK, shadowActivity.getResultCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onLocaleSelected_localeInfoShouldBeSentBack() {
|
||||
final ShadowActivity shadowActivity = Shadows.shadowOf(mActivity);
|
||||
mActivity.onLocaleSelected(mock(LocaleStore.LocaleInfo.class));
|
||||
|
||||
assertNotNull(shadowActivity.getResultIntent().getSerializableExtra(
|
||||
LocaleListEditor.INTENT_LOCALE_KEY));
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Google Inc.
|
||||
* Copyright (C) 2017 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.
|
||||
@@ -16,38 +16,33 @@
|
||||
|
||||
package com.android.settings.password;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.password.ChooseLockTypeDialogFragment.OnLockTypeSelectedListener;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.ShadowUserManager;
|
||||
import com.android.settings.testutils.shadow.ShadowUtils;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowResourcesImpl;
|
||||
import com.android.settings.testutils.shadow.ShadowAlertDialogCompat;
|
||||
import com.android.settingslib.testutils.FragmentTestUtils;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.Shadows;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowAlertDialog;
|
||||
import org.robolectric.shadows.ShadowDialog;
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(shadows = {ShadowUserManager.class, ShadowUtils.class})
|
||||
@Config(shadows = {SettingsShadowResourcesImpl.class, ShadowAlertDialogCompat.class})
|
||||
public class ChooseLockTypeDialogFragmentTest {
|
||||
|
||||
private Context mContext;
|
||||
@@ -61,32 +56,36 @@ public class ChooseLockTypeDialogFragmentTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("b/111247403")
|
||||
public void testThatDialog_IsShown() {
|
||||
AlertDialog latestDialog = startLockFragment();
|
||||
assertNotNull(latestDialog);
|
||||
ShadowDialog shadowDialog = Shadows.shadowOf(latestDialog);
|
||||
ShadowAlertDialogCompat shadowAlertDialog = ShadowAlertDialogCompat.shadowOf(
|
||||
latestDialog);
|
||||
|
||||
assertThat(latestDialog).isNotNull();
|
||||
assertThat(latestDialog.isShowing()).isTrue();
|
||||
// verify that we are looking at the expected dialog.
|
||||
assertEquals(shadowDialog.getTitle(),
|
||||
assertThat(shadowAlertDialog.getTitle()).isEqualTo(
|
||||
mContext.getString(R.string.setup_lock_settings_options_dialog_title));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("b/111247403")
|
||||
public void testThat_OnClickListener_IsCalled() {
|
||||
mFragment.mDelegate = mock(OnLockTypeSelectedListener.class);
|
||||
AlertDialog lockDialog = startLockFragment();
|
||||
ShadowAlertDialog shadowAlertDialog = Shadows.shadowOf(lockDialog);
|
||||
ShadowAlertDialogCompat shadowAlertDialog = ShadowAlertDialogCompat.shadowOf(lockDialog);
|
||||
|
||||
shadowAlertDialog.clickOnItem(0);
|
||||
|
||||
verify(mFragment.mDelegate, times(1)).onLockTypeSelected(any(ScreenLockType.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("b/111247403")
|
||||
public void testThat_OnClickListener_IsNotCalledWhenCancelled() {
|
||||
mFragment.mDelegate = mock(OnLockTypeSelectedListener.class);
|
||||
AlertDialog lockDialog = startLockFragment();
|
||||
|
||||
lockDialog.dismiss();
|
||||
|
||||
verify(mFragment.mDelegate, never()).onLockTypeSelected(any(ScreenLockType.class));
|
||||
}
|
||||
|
||||
@@ -94,7 +93,7 @@ public class ChooseLockTypeDialogFragmentTest {
|
||||
ChooseLockTypeDialogFragment chooseLockTypeDialogFragment =
|
||||
ChooseLockTypeDialogFragment.newInstance(1234);
|
||||
chooseLockTypeDialogFragment.show(mFragment.getChildFragmentManager(), null);
|
||||
return ShadowAlertDialog.getLatestAlertDialog();
|
||||
return ShadowAlertDialogCompat.getLatestAlertDialog();
|
||||
}
|
||||
|
||||
public static class TestFragment extends Fragment implements OnLockTypeSelectedListener {
|
||||
|
||||
@@ -43,7 +43,8 @@ public class SettingsShadowResourcesImpl extends ShadowResourcesImpl {
|
||||
// that Robolectric isn't yet aware of.
|
||||
// TODO: Remove this once Robolectric is updated.
|
||||
if (id == R.drawable.switchbar_background
|
||||
|| id == R.color.ripple_material_light) {
|
||||
|| id == R.color.ripple_material_light
|
||||
|| id == R.color.ripple_material_dark) {
|
||||
return new ColorDrawable();
|
||||
} else if (id == R.drawable.ic_launcher_settings) {
|
||||
// ic_launcher_settings uses adaptive-icon, which is not supported by robolectric,
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* 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.testutils.shadow;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.view.View;
|
||||
|
||||
import org.robolectric.Shadows;
|
||||
import org.robolectric.annotation.Implementation;
|
||||
import org.robolectric.annotation.Implements;
|
||||
import org.robolectric.annotation.RealObject;
|
||||
import org.robolectric.annotation.Resetter;
|
||||
import org.robolectric.shadow.api.Shadow;
|
||||
import org.robolectric.shadows.ShadowDialog;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
|
||||
/* Robolectric shadow for the androidx alert dialog. */
|
||||
@Implements(AlertDialog.class)
|
||||
public class ShadowAlertDialogCompat extends ShadowDialog {
|
||||
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
@Nullable
|
||||
private static ShadowAlertDialogCompat latestSupportAlertDialog;
|
||||
@RealObject
|
||||
private AlertDialog realAlertDialog;
|
||||
|
||||
@Implementation
|
||||
public void show() {
|
||||
super.show();
|
||||
latestSupportAlertDialog = this;
|
||||
}
|
||||
|
||||
public CharSequence getMessage() {
|
||||
final Object alertController = ReflectionHelpers.getField(realAlertDialog, "mAlert");
|
||||
return ReflectionHelpers.getField(alertController, "mMessage");
|
||||
}
|
||||
|
||||
public CharSequence getTitle() {
|
||||
final Object alertController = ReflectionHelpers.getField(realAlertDialog, "mAlert");
|
||||
return ReflectionHelpers.getField(alertController, "mTitle");
|
||||
}
|
||||
|
||||
public View getView() {
|
||||
final Object alertController = ReflectionHelpers.getField(realAlertDialog, "mAlert");
|
||||
return ReflectionHelpers.getField(alertController, "mView");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static AlertDialog getLatestAlertDialog() {
|
||||
return latestSupportAlertDialog == null ? null : latestSupportAlertDialog.realAlertDialog;
|
||||
}
|
||||
|
||||
@Resetter
|
||||
public static void reset() {
|
||||
latestSupportAlertDialog = null;
|
||||
}
|
||||
|
||||
public static ShadowAlertDialogCompat shadowOf(AlertDialog alertDialog) {
|
||||
return (ShadowAlertDialogCompat) Shadow.extract(alertDialog);
|
||||
}
|
||||
|
||||
public void clickOnItem(int index) {
|
||||
Shadows.shadowOf(realAlertDialog.getListView()).performItemClick(index);
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.wifi;
|
||||
package com.android.settings.wifi.savedaccesspoints;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
@@ -28,6 +28,8 @@ import android.net.wifi.WifiManager.ActionListener;
|
||||
import android.os.Handler;
|
||||
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.wifi.WifiConfigController;
|
||||
import com.android.settings.wifi.WifiDialog;
|
||||
import com.android.settingslib.wifi.AccessPoint;
|
||||
|
||||
import org.junit.Before;
|
||||
Reference in New Issue
Block a user