Snap for 8581479 from a6533a7f1e to tm-qpr1-release

Change-Id: I871629a3cdb3f5a51e5ee1c6cb3f9358f76f5387
This commit is contained in:
Android Build Coastguard Worker
2022-05-13 03:08:38 +00:00
21 changed files with 139 additions and 256 deletions

View File

@@ -1,28 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
/**
* Copyright (C) 2022 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.
*/
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:pathData="M11,15h2v2h-2v-2zM11,7h2v6h-2L11,7zM11.99,2C6.47,2 2,6.48 2,12s4.47,10 9.99,10C17.52,22 22,17.52 22,12S17.52,2 11.99,2zM12,20c-4.42,0 -8,-3.58 -8,-8s3.58,-8 8,-8 8,3.58 8,8 -3.58,8 -8,8z"
android:fillColor="?android:attr/colorError"
android:fillType="evenOdd"/>
</vector>

View File

@@ -500,15 +500,6 @@
<!-- Title for the App's locale picker activity. [CHAR LIMIT=50]-->
<string name="app_locale_picker_title">App Language</string>
<!-- Title for the warning message of the locale picker activity. [CHAR LIMIT=50]-->
<string name="warnings_title">Update the app</string>
<!-- Summary for the warning message of the locale picker activity. [CHAR LIMIT=70]-->
<string name="warnings_summary">You need to update the app for the latest available languages</string>
<!-- Button text on warning message [CHAR LIMIT=20]-->
<string name="warnings_button_update">Update now</string>
<!-- Category for the suggested app's locales. [CHAR LIMIT=50]-->
<string name="suggested_app_locales_title">Suggested languages</string>
@@ -4751,7 +4742,7 @@
<!-- [CHAR LIMIT=NONE] Manage applications screen, menu item. Title of dialog to confirm resetting user's app preferences. -->
<string name="reset_app_preferences_title">Reset app preferences?</string>
<!-- [CHAR LIMIT=NONE] Manage applications screen, menu item. Body of dialog to confirm resetting user's app preferences. -->
<string name="reset_app_preferences_desc">This will reset all preferences for:\n\n<li>Disabled apps</li>\n<li>Disabled app notifications</li>\n<li>Default applications for actions</li>\n<li>Background data restrictions for apps</li>\n<li>Any permission restrictions</li>\n\nYou will not lose any app data.</string>
<string name="reset_app_preferences_desc">This will reset all preferences for:\n\n<li>Disabled apps</li>\n<li>Disabled app notifications</li>\n<li>Default applications for actions</li>\n<li>Background data restrictions for apps</li>\n<li>Any permission restrictions</li>\n<li>Battery usage settings</li>\n\nYou will not lose any app data.</string>
<!-- [CHAR LIMIT=25] Manage applications screen, menu item. Confirmation button of dialog to confirm resetting user's app preferences. -->
<string name="reset_app_preferences_button">Reset apps</string>
<!-- Manage applications screen, individual app screen, button label when the user wants to manage the space taken up by an app. -->
@@ -7860,7 +7851,11 @@
<string name="help_label">Help &amp; feedback</string>
<!-- Summary text for support setting tile [CHAR LIMIT=None] -->
<string name="support_summary">Help articles, phone &amp; chat</string>
<string name="support_summary" product="default">Help articles, phone &amp; chat</string>
<!-- Summary text for support setting tile [CHAR LIMIT=None] -->
<string name="support_summary" product="tablet">Help articles, tablet &amp; chat</string>
<!-- Summary text for support setting tile [CHAR LIMIT=None] -->
<string name="support_summary" product="device">Help articles, device &amp; chat</string>
<!-- Help URI, Default [DO NOT TRANSLATE] -->
<string name="help_uri_default" translatable="false"></string>

View File

@@ -24,13 +24,6 @@
android:title="@string/desc_app_locale_disclaimer"
android:order="1"/>
<com.android.settingslib.widget.BannerMessagePreference
android:key="key_warnings"
android:order="20"
android:icon="@drawable/ic_error_outline"
android:title="@string/warnings_title"
android:summary="@string/warnings_summary"/>
<com.android.settingslib.widget.LayoutPreference
android:key="app_locale_description"
android:order="30"

View File

@@ -22,9 +22,7 @@ import android.widget.SeekBar;
import androidx.annotation.NonNull;
import androidx.preference.PreferenceScreen;
import com.android.settings.accessibility.TextReadingPreferenceFragment.EntryPoint;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.core.instrumentation.SettingsStatsLog;
import com.android.settings.widget.LabeledSeekBarPreference;
/**
@@ -38,9 +36,6 @@ class PreviewSizeSeekBarController extends BasePreferenceController implements
private ProgressInteractionListener mInteractionListener;
private LabeledSeekBarPreference mSeekBarPreference;
@EntryPoint
private int mEntryPoint;
private final SeekBar.OnSeekBarChangeListener mSeekBarChangeListener =
new SeekBar.OnSeekBarChangeListener() {
@Override
@@ -51,11 +46,6 @@ class PreviewSizeSeekBarController extends BasePreferenceController implements
mInteractionListener.onProgressChanged();
}
SettingsStatsLog.write(
SettingsStatsLog.ACCESSIBILITY_TEXT_READING_OPTIONS_CHANGED,
AccessibilityStatsLogUtils.convertToItemKeyName(getPreferenceKey()),
progress,
AccessibilityStatsLogUtils.convertToEntryPoint(mEntryPoint));
}
@Override
@@ -107,14 +97,6 @@ class PreviewSizeSeekBarController extends BasePreferenceController implements
mSeekBarPreference.setProgress(defaultProgress);
}
/**
* The entry point is used for logging.
*
* @param entryPoint from which settings page
*/
void setEntryPoint(@EntryPoint int entryPoint) {
mEntryPoint = entryPoint;
}
/**
* Interface for callbacks when users interact with the seek bar.

View File

@@ -129,18 +129,17 @@ public class TextReadingPreferenceFragment extends DashboardFragment {
final TextReadingPreviewController previewController = new TextReadingPreviewController(
context, PREVIEW_KEY, fontSizeData, displaySizeData);
previewController.setEntryPoint(mEntryPoint);
controllers.add(previewController);
final PreviewSizeSeekBarController fontSizeController = new PreviewSizeSeekBarController(
context, FONT_SIZE_KEY, fontSizeData);
fontSizeController.setInteractionListener(previewController);
fontSizeController.setEntryPoint(mEntryPoint);
controllers.add(fontSizeController);
final PreviewSizeSeekBarController displaySizeController = new PreviewSizeSeekBarController(
context, DISPLAY_SIZE_KEY, displaySizeData);
displaySizeController.setInteractionListener(previewController);
displaySizeController.setEntryPoint(mEntryPoint);
controllers.add(displaySizeController);
mFontWeightAdjustmentController =

View File

@@ -19,6 +19,7 @@ package com.android.settings.accessibility;
import android.content.Context;
import android.content.res.Configuration;
import android.os.SystemClock;
import android.util.Log;
import android.view.Choreographer;
import android.view.View;
@@ -26,7 +27,9 @@ import androidx.annotation.NonNull;
import androidx.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settings.accessibility.TextReadingPreferenceFragment.EntryPoint;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.core.instrumentation.SettingsStatsLog;
import com.android.settings.display.PreviewPagerAdapter;
import com.android.settings.widget.LabeledSeekBarPreference;
@@ -38,6 +41,7 @@ import java.util.Objects;
*/
class TextReadingPreviewController extends BasePreferenceController implements
PreviewSizeSeekBarController.ProgressInteractionListener {
private static final String TAG = "TextReadingPreviewCtrl";
static final int[] PREVIEW_SAMPLE_RES_IDS = new int[]{
R.layout.accessibility_text_reading_preview_app_grid,
R.layout.screen_zoom_preview_1,
@@ -58,6 +62,9 @@ class TextReadingPreviewController extends BasePreferenceController implements
private LabeledSeekBarPreference mFontSizePreference;
private LabeledSeekBarPreference mDisplaySizePreference;
@EntryPoint
private int mEntryPoint;
private final Choreographer.FrameCallback mCommit = f -> {
tryCommitFontSizeConfig();
tryCommitDisplaySizeConfig();
@@ -92,8 +99,8 @@ class TextReadingPreviewController extends BasePreferenceController implements
/* message= */ "Display size preference is null, the preview controller"
+ " couldn't get the info");
mLastFontProgress = mFontSizePreference.getProgress();
mLastDisplayProgress = mDisplaySizePreference.getProgress();
mLastFontProgress = mFontSizeData.getInitialIndex();
mLastDisplayProgress = mDisplaySizeData.getInitialIndex();
final Configuration origConfig = mContext.getResources().getConfiguration();
final boolean isLayoutRtl =
@@ -131,6 +138,15 @@ class TextReadingPreviewController extends BasePreferenceController implements
postCommitDelayed(CHANGE_BY_SEEKBAR_DELAY_MS);
}
/**
* The entry point is used for logging.
*
* @param entryPoint from which settings page
*/
void setEntryPoint(@EntryPoint int entryPoint) {
mEntryPoint = entryPoint;
}
/**
* Avoids the flicker when switching to the previous or next level.
*
@@ -162,6 +178,16 @@ class TextReadingPreviewController extends BasePreferenceController implements
if (fontProgress != mLastFontProgress) {
mFontSizeData.commit(fontProgress);
mLastFontProgress = fontProgress;
if (Log.isLoggable(TAG, Log.DEBUG)) {
Log.d(TAG, "Font size: " + fontProgress);
}
SettingsStatsLog.write(
SettingsStatsLog.ACCESSIBILITY_TEXT_READING_OPTIONS_CHANGED,
AccessibilityStatsLogUtils.convertToItemKeyName(mFontSizePreference.getKey()),
fontProgress,
AccessibilityStatsLogUtils.convertToEntryPoint(mEntryPoint));
}
}
@@ -170,6 +196,17 @@ class TextReadingPreviewController extends BasePreferenceController implements
if (displayProgress != mLastDisplayProgress) {
mDisplaySizeData.commit(displayProgress);
mLastDisplayProgress = displayProgress;
if (Log.isLoggable(TAG, Log.DEBUG)) {
Log.d(TAG, "Display size: " + displayProgress);
}
SettingsStatsLog.write(
SettingsStatsLog.ACCESSIBILITY_TEXT_READING_OPTIONS_CHANGED,
AccessibilityStatsLogUtils.convertToItemKeyName(
mDisplaySizePreference.getKey()),
displayProgress,
AccessibilityStatsLogUtils.convertToEntryPoint(mEntryPoint));
}
}

View File

@@ -147,8 +147,7 @@ public class ToggleScreenMagnificationPreferenceFragment extends
return AccessibilityGestureNavigationTutorial
.showAccessibilityGestureTutorialDialog(getPrefContext());
case DialogEnums.MAGNIFICATION_EDIT_SHORTCUT:
final CharSequence dialogTitle = getPrefContext().getString(
R.string.accessibility_shortcut_title, mPackageName);
final CharSequence dialogTitle = getShortcutTitle();
final int dialogType = WizardManagerHelper.isAnySetupWizard(getIntent())
? DialogType.EDIT_SHORTCUT_MAGNIFICATION_SUW
: DialogType.EDIT_SHORTCUT_MAGNIFICATION;

View File

@@ -99,7 +99,8 @@ public class AppLocaleUtil {
* Check the function of per app language is supported by current application.
*/
public static boolean isAppLocaleSupported(Context context, String packageName) {
if (getPackageLocales(context, packageName) != null) {
LocaleList localeList = getPackageLocales(context, packageName);
if (localeList != null && localeList.size() > 0) {
return true;
}

View File

@@ -21,12 +21,8 @@ import android.app.Activity;
import android.app.LocaleManager;
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.InstallSourceInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.net.Uri;
import android.os.Bundle;
import android.os.LocaleList;
import android.os.UserHandle;
@@ -34,7 +30,6 @@ import android.util.FeatureFlagUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.TextView;
@@ -48,8 +43,6 @@ import com.android.settings.applications.AppLocaleUtil;
import com.android.settings.widget.EntityHeaderController;
import com.android.settingslib.applications.AppUtils;
import com.android.settingslib.applications.ApplicationsState.AppEntry;
import com.android.settingslib.widget.BannerMessagePreference;
import com.android.settingslib.widget.BannerMessagePreference.AttentionLevel;
import com.android.settingslib.widget.LayoutPreference;
import java.util.Locale;
@@ -62,7 +55,6 @@ public class AppLocaleDetails extends SettingsPreferenceFragment {
private static final String TAG = "AppLocaleDetails";
private static final String KEY_APP_DESCRIPTION = "app_locale_description";
private static final String KEY_WARNINGS = "key_warnings";
private static final String KEY_APP_DISCLAIMER = "app_locale_disclaimer";
private boolean mCreated = false;
@@ -96,7 +88,6 @@ public class AppLocaleDetails extends SettingsPreferenceFragment {
mPrefOfDescription = getPreferenceScreen().findPreference(KEY_APP_DESCRIPTION);
mPrefOfDisclaimer = getPreferenceScreen().findPreference(KEY_APP_DISCLAIMER);
mApplicationInfo = getApplicationInfo(mPackageName, getContext().getUserId());
setWarningMessage();
setDisclaimerPreference();
}
@@ -119,7 +110,6 @@ public class AppLocaleDetails extends SettingsPreferenceFragment {
}
private void refreshUi() {
setWarningMessage();
setDescription();
}
@@ -156,26 +146,6 @@ public class AppLocaleDetails extends SettingsPreferenceFragment {
getPreferenceScreen().addPreference(pref);
}
private void setWarningMessage() {
BannerMessagePreference warningPreference =
(BannerMessagePreference) getPreferenceScreen().findPreference(KEY_WARNINGS);
try {
InstallSourceInfo installSourceInfo =
getContext().getPackageManager().getInstallSourceInfo(mPackageName);
if (mApplicationInfo.isSystemApp()
&& installSourceInfo.getInstallingPackageName() == null) {
warningPreference.setAttentionLevel(AttentionLevel.MEDIUM);
warningPreference.setPositiveButtonOnClickListener(mBannerButtonClickListener);
warningPreference.setPositiveButtonText(R.string.warnings_button_update);
warningPreference.setVisible(true);
} else {
warningPreference.setVisible(false);
}
} catch (NameNotFoundException e) {
Log.e(TAG, "Exception while retrieving the package installer of " + mPackageName, e);
}
}
private void setDisclaimerPreference() {
if (FeatureFlagUtils.isEnabled(
getContext(), FeatureFlagUtils.SETTINGS_APP_LOCALE_OPT_IN_ENABLED)) {
@@ -192,19 +162,6 @@ public class AppLocaleDetails extends SettingsPreferenceFragment {
}
}
private OnClickListener mBannerButtonClickListener = new OnClickListener() {
@Override
public void onClick(View v) {
startActivity(getAppSearchIntent(mPackageName));
}
};
private static Intent getAppSearchIntent(String pkg) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("market://details?id=" + pkg));
return intent;
}
private ApplicationInfo getApplicationInfo(String packageName, int userId) {
ApplicationInfo applicationInfo;
try {

View File

@@ -90,6 +90,12 @@ public class ButtonActionDialogFragment extends InstrumentedDialogFragment imple
@Override
public void onClick(DialogInterface dialog, int which) {
// When it's in a multi-window mode, force stopping an app will lead to an activity
// recreate, and the dialog fragment will also be recreated. So dismiss the dialog before
// stopping the app.
if (mId == ButtonActionDialogFragment.DialogType.FORCE_STOP) {
dialog.dismiss();
}
final AppButtonsDialogListener lsn =
(AppButtonsDialogListener) getTargetFragment();
lsn.handleDialogClick(mId);

View File

@@ -111,6 +111,11 @@ public class FingerprintEnrollFindSensor extends BiometricEnrollBase implements
lottieAnimationView.setVisibility(View.GONE);
lottieAnimationViewPortrait.setVisibility(View.VISIBLE);
break;
case Surface.ROTATION_180:
lottieAnimationView.setVisibility(View.VISIBLE);
lottieAnimationView.setRotation(180);
lottieAnimationViewPortrait.setVisibility(View.GONE);
break;
case Surface.ROTATION_270:
lottieAnimationView.setVisibility(View.GONE);
lottieAnimationViewPortrait.setVisibility(View.VISIBLE);
@@ -353,10 +358,7 @@ public class FingerprintEnrollFindSensor extends BiometricEnrollBase implements
@Override
public void onOrientationChanged(int orientation) {
final int currentRotation = getDisplay().getRotation();
if ((mPreviousRotation == Surface.ROTATION_90
&& currentRotation == Surface.ROTATION_270) || (
mPreviousRotation == Surface.ROTATION_270
&& currentRotation == Surface.ROTATION_90)) {
if ((currentRotation + 2) % 4 == mPreviousRotation) {
mPreviousRotation = currentRotation;
recreate();
}

View File

@@ -132,7 +132,6 @@ public class VolumeOptionMenuController implements LifecycleObserver, OnCreateOp
if (mStorageEntry.isPrivate()) {
if (!mStorageEntry.isDefaultInternalStorage()) {
mRename.setVisible(true);
mUnmount.setVisible(true);
mFormatAsPortable.setVisible(true);
}

View File

@@ -31,9 +31,9 @@ public class TopLevelLocationPreferenceController extends BasePreferenceControll
private static final IntentFilter INTENT_FILTER_LOCATION_MODE_CHANGED =
new IntentFilter(LocationManager.MODE_CHANGED_ACTION);
private final LocationManager mLocationManager;
/** Total number of apps that has location permission. */
private int mNumTotal = -1;
private int mNumTotalLoading = 0;
/** Summary text. */
private static String sSummary = null;
private BroadcastReceiver mReceiver;
private Preference mPreference;
private AtomicInteger loadingInProgress = new AtomicInteger(0);
@@ -51,12 +51,11 @@ public class TopLevelLocationPreferenceController extends BasePreferenceControll
@Override
public CharSequence getSummary() {
if (mLocationManager.isLocationEnabled()) {
if (mNumTotal == -1) {
return mContext.getString(R.string.location_settings_loading_app_permission_stats);
if (sSummary == null) {
sSummary = mContext.getString(
R.string.location_settings_loading_app_permission_stats);
}
return mContext.getResources().getQuantityString(
R.plurals.location_settings_summary_location_on,
mNumTotal, mNumTotal);
return sSummary;
} else {
return mContext.getString(R.string.location_settings_summary_location_off);
}
@@ -64,7 +63,8 @@ public class TopLevelLocationPreferenceController extends BasePreferenceControll
@VisibleForTesting
void setLocationAppCount(int numApps) {
mNumTotal = numApps;
sSummary = mContext.getResources().getQuantityString(
R.plurals.location_settings_summary_location_on, numApps, numApps);
refreshSummary(mPreference);
}

View File

@@ -106,29 +106,20 @@ public class NotificationBackend {
return row;
}
public AppRow loadAppRow(Context context, PackageManager pm,
RoleManager roleManager, PackageInfo app) {
public AppRow loadAppRow(Context context, PackageManager pm, PackageInfo app) {
final AppRow row = loadAppRow(context, pm, app.applicationInfo);
recordCanBeBlocked(context, pm, roleManager, app, row);
recordCanBeBlocked(app, row);
return row;
}
void recordCanBeBlocked(Context context, PackageManager pm, RoleManager rm, PackageInfo app,
AppRow row) {
void recordCanBeBlocked(PackageInfo app, AppRow row) {
try {
row.systemApp = row.lockedImportance =
sINM.isPermissionFixed(app.packageName, row.userId);
sINM.isImportanceLocked(app.packageName, app.applicationInfo.uid);
} catch (RemoteException e) {
Log.w(TAG, "Error calling NMS", e);
}
// The permission system cannot make role permissions 'fixed', so check for these
// roles explicitly
List<String> roles = rm.getHeldRolesFromController(app.packageName);
if (roles.contains(RoleManager.ROLE_DIALER)
|| roles.contains(RoleManager.ROLE_EMERGENCY)) {
row.systemApp = row.lockedImportance = true;
}
// if the app targets T but has not requested the permission, we cannot change the
// permission state
if (app.applicationInfo.targetSdkVersion > Build.VERSION_CODES.S_V2) {
@@ -139,24 +130,6 @@ public class NotificationBackend {
}
}
@VisibleForTesting static void markAppRowWithBlockables(String[] nonBlockablePkgs, AppRow row,
String packageName) {
if (nonBlockablePkgs != null) {
int N = nonBlockablePkgs.length;
for (int i = 0; i < N; i++) {
String pkg = nonBlockablePkgs[i];
if (pkg == null) {
continue;
} else if (pkg.contains(":")) {
// handled by NotificationChannel.isImportanceLockedByOEM()
continue;
} else if (packageName.equals(nonBlockablePkgs[i])) {
row.systemApp = row.lockedImportance = true;
}
}
}
}
static public CharSequence getDeviceList(ICompanionDeviceManager cdm, LocalBluetoothManager lbm,
String pkg, int userId) {
boolean multiple = false;
@@ -191,10 +164,9 @@ public class NotificationBackend {
public boolean enableSwitch(Context context, ApplicationInfo app) {
try {
PackageInfo info = context.getPackageManager().getPackageInfo(
app.packageName, PackageManager.GET_SIGNATURES);
RoleManager rm = context.getSystemService(RoleManager.class);
app.packageName, PackageManager.GET_PERMISSIONS);
final AppRow row = new AppRow();
recordCanBeBlocked(context, context.getPackageManager(), rm, info, row);
recordCanBeBlocked(info, row);
boolean systemBlockable = !row.systemApp || (row.systemApp && row.banned);
return systemBlockable && !row.lockedImportance;
} catch (PackageManager.NameNotFoundException e) {

View File

@@ -24,6 +24,7 @@ import android.app.NotificationChannel;
import android.app.NotificationChannelGroup;
import android.app.NotificationManager;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.ShortcutInfo;
import android.graphics.drawable.Drawable;
@@ -171,7 +172,8 @@ public abstract class NotificationPreferenceController extends AbstractPreferenc
return overrideCanConfigureValue;
}
if (mAppRow != null) {
return !mAppRow.systemApp && !mAppRow.lockedImportance;
boolean systemBlockable = !mAppRow.systemApp || (mAppRow.systemApp && mAppRow.banned);
return systemBlockable && !mAppRow.lockedImportance;
}
return true;
}

View File

@@ -25,7 +25,6 @@ import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationChannelGroup;
import android.app.NotificationManager;
import android.app.role.RoleManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
@@ -69,7 +68,6 @@ abstract public class NotificationSettings extends DashboardFragment {
protected PackageManager mPm;
protected NotificationBackend mBackend = new NotificationBackend();
protected NotificationManager mNm;
protected RoleManager mRm;
protected Context mContext;
protected int mUid;
@@ -116,7 +114,6 @@ abstract public class NotificationSettings extends DashboardFragment {
mPm = getPackageManager();
mNm = NotificationManager.from(mContext);
mRm = mContext.getSystemService(RoleManager.class);
mPkg = mArgs != null && mArgs.containsKey(AppInfoBase.ARG_PACKAGE_NAME)
? mArgs.getString(AppInfoBase.ARG_PACKAGE_NAME)
@@ -290,7 +287,7 @@ abstract public class NotificationSettings extends DashboardFragment {
}
private void loadAppRow() {
mAppRow = mBackend.loadAppRow(mContext, mPm, mRm, mPkgInfo);
mAppRow = mBackend.loadAppRow(mContext, mPm, mPkgInfo);
}
private void loadChannelGroup() {

View File

@@ -18,7 +18,9 @@ package com.android.settings.applications.appinfo;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
@@ -72,6 +74,21 @@ public class ButtonActionDialogFragmentTest {
verify(mTargetFragment).handleDialogClick(anyInt());
}
@Test
public void testOnClick_forceStop_dismissDialog() {
ButtonActionDialogFragment fragment =
spy(ButtonActionDialogFragment.newInstance(FORCE_STOP_ID));
FragmentController.setupFragment(fragment, FragmentActivity.class, 0 /* containerViewId */,
null /* bundle */);
doReturn(mTargetFragment).when(fragment).getTargetFragment();
doNothing().when(mTargetFragment).handleDialogClick(anyInt());
final AlertDialog dialog = mock(AlertDialog.class);
fragment.onClick(dialog, 0);
verify(dialog).dismiss();
}
@Test
public void testOnCreateDialog_forceStopDialog() {
ButtonActionDialogFragment fragment = ButtonActionDialogFragment.newInstance(FORCE_STOP_ID);

View File

@@ -56,31 +56,41 @@ public class TopLevelLocationPreferenceControllerTest {
}
@Test
public void getSummary_whenLocationIsOn_shouldShowLoadingString() {
public void getSummary_whenLocationIsOn_shouldPreservePreviousText() {
final int locationAppCount = 5;
// Retrieve summary text once.
mLocationManager.setLocationEnabledForUser(true, android.os.Process.myUserHandle());
mController.setLocationAppCount(locationAppCount);
mController.getSummary();
// Turn off location.
mLocationManager.setLocationEnabledForUser(false, android.os.Process.myUserHandle());
// Turn on location again and check if the previous summary text is still cached.
mLocationManager.setLocationEnabledForUser(true, android.os.Process.myUserHandle());
assertThat(mController.getSummary()).isEqualTo(
mContext.getString(R.string.location_settings_loading_app_permission_stats));
mContext.getResources().getQuantityString(
R.plurals.location_settings_summary_location_on, locationAppCount,
locationAppCount));
}
@Test
public void getSummary_whenLocationAppCountIsOne_shouldShowSingularString() {
final int LOCATION_APP_COUNT = 1;
final int locationAppCount = 1;
mLocationManager.setLocationEnabledForUser(true, android.os.Process.myUserHandle());
mController.setLocationAppCount(LOCATION_APP_COUNT);
mController.setLocationAppCount(locationAppCount);
assertThat(mController.getSummary()).isEqualTo(
mContext.getResources().getQuantityString(
R.plurals.location_settings_summary_location_on,
LOCATION_APP_COUNT, LOCATION_APP_COUNT));
locationAppCount, locationAppCount));
}
@Test
public void getSummary_whenLocationAppCountIsGreaterThanOne_shouldShowPluralString() {
final int LOCATION_APP_COUNT = 5;
final int locationAppCount = 5;
mLocationManager.setLocationEnabledForUser(true, android.os.Process.myUserHandle());
mController.setLocationAppCount(LOCATION_APP_COUNT);
mController.setLocationAppCount(locationAppCount);
assertThat(mController.getSummary()).isEqualTo(
mContext.getResources().getQuantityString(
R.plurals.location_settings_summary_location_on,
LOCATION_APP_COUNT, LOCATION_APP_COUNT));
locationAppCount, locationAppCount));
}
}

View File

@@ -20,6 +20,7 @@ import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -80,69 +81,17 @@ public class NotificationBackendTest {
}
@Test
public void testMarkAppRow_unblockablePackage() {
AppRow appRow = new AppRow();
String packageName = "foo.bar.unblockable";
appRow.pkg = packageName;
String[] nonBlockablePkgs = new String[2];
nonBlockablePkgs[0] = packageName;
nonBlockablePkgs[1] = "some.other.package";
NotificationBackend.markAppRowWithBlockables(nonBlockablePkgs, appRow, packageName);
// This package has a package lock but no locked channels
assertTrue(appRow.lockedImportance);
}
@Test
public void testMarkAppRow_defaultPackage() {
PackageInfo pi = new PackageInfo();
pi.packageName = "test";
pi.applicationInfo = new ApplicationInfo();
pi.applicationInfo.packageName = "test";
List<String> roles = new ArrayList<>();
roles.add(RoleManager.ROLE_DIALER);
RoleManager rm = mock(RoleManager.class);
when(rm.getHeldRolesFromController(anyString())).thenReturn(roles);
AppRow appRow = new NotificationBackend().loadAppRow(RuntimeEnvironment.application,
mock(PackageManager.class), rm, pi);
assertTrue(appRow.systemApp);
}
@Test
public void testMarkAppRow_fixedPermission_withRole() throws Exception {
public void testMarkAppRow_fixedImportance() throws Exception {
PackageInfo pi = new PackageInfo();
pi.packageName = "test";
pi.applicationInfo = new ApplicationInfo();
pi.applicationInfo.packageName = "test";
pi.applicationInfo.uid = 123;
List<String> roles = new ArrayList<>();
roles.add(RoleManager.ROLE_DIALER);
RoleManager rm = mock(RoleManager.class);
when(rm.getHeldRolesFromController(anyString())).thenReturn(roles);
when(mInm.isPermissionFixed(pi.packageName, 0)).thenReturn(false);
when(mInm.isImportanceLocked(pi.packageName, 123)).thenReturn(true);
AppRow appRow = new NotificationBackend().loadAppRow(RuntimeEnvironment.application,
mock(PackageManager.class), rm, pi);
assertTrue(appRow.systemApp);
assertTrue(appRow.lockedImportance);
}
@Test
public void testMarkAppRow_fixedPermission() throws Exception {
PackageInfo pi = new PackageInfo();
pi.packageName = "test";
pi.applicationInfo = new ApplicationInfo();
pi.applicationInfo.packageName = "test";
pi.applicationInfo.uid = 123;
when(mInm.isPermissionFixed(pi.packageName, 0)).thenReturn(true);
AppRow appRow = new NotificationBackend().loadAppRow(RuntimeEnvironment.application,
mock(PackageManager.class), mock(RoleManager.class), pi);
mock(PackageManager.class), pi);
assertTrue(appRow.systemApp);
assertTrue(appRow.lockedImportance);
@@ -156,10 +105,10 @@ public class NotificationBackendTest {
pi.applicationInfo.packageName = "test";
pi.applicationInfo.uid = 123;
when(mInm.isPermissionFixed(pi.packageName, 0)).thenReturn(false);
when(mInm.isImportanceLocked(anyString(), anyInt())).thenReturn(false);
AppRow appRow = new NotificationBackend().loadAppRow(RuntimeEnvironment.application,
mock(PackageManager.class), mock(RoleManager.class), pi);
mock(PackageManager.class), pi);
assertFalse(appRow.systemApp);
assertFalse(appRow.lockedImportance);
@@ -178,7 +127,7 @@ public class NotificationBackendTest {
when(mInm.isPermissionFixed(pi.packageName, 0)).thenReturn(false);
AppRow appRow = new NotificationBackend().loadAppRow(RuntimeEnvironment.application,
mock(PackageManager.class), mock(RoleManager.class), pi);
mock(PackageManager.class), pi);
assertFalse(appRow.systemApp);
assertTrue(appRow.lockedImportance);
@@ -198,29 +147,12 @@ public class NotificationBackendTest {
when(mInm.isPermissionFixed(pi.packageName, 0)).thenReturn(false);
AppRow appRow = new NotificationBackend().loadAppRow(RuntimeEnvironment.application,
mock(PackageManager.class), mock(RoleManager.class), pi);
mock(PackageManager.class), pi);
assertFalse(appRow.systemApp);
assertFalse(appRow.lockedImportance);
}
@Test
public void testMarkAppRow_notDefaultPackage() {
PackageInfo pi = new PackageInfo();
pi.packageName = "test";
pi.applicationInfo = new ApplicationInfo();
pi.applicationInfo.packageName = "test";
List<String> roles = new ArrayList<>();
roles.add(RoleManager.ROLE_HOME);
RoleManager rm = mock(RoleManager.class);
when(rm.getHeldRolesFromController(anyString())).thenReturn(roles);
AppRow appRow = new NotificationBackend().loadAppRow(RuntimeEnvironment.application,
mock(PackageManager.class), rm, pi);
assertFalse(appRow.systemApp);
}
@Test
public void testGetAggregatedUsageEvents_multipleEventsAgg() {
List<UsageEvents.Event> events = new ArrayList<>();

View File

@@ -284,24 +284,36 @@ public class NotificationPreferenceControllerTest {
}
@Test
public void testIsAppBlockable_postMigration_locked() {
public void testIsAppBlockable_fixedPermission() {
mController = new TestPreferenceController(mContext, mBackend);
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.lockedImportance = true;
appRow.systemApp = true;
appRow.banned = false;
mController.onResume(appRow, null, null, null, null, null, null);
assertFalse(mController.isAppBlockable());
}
@Test
public void testIsAppBlockable_postMigration_locked_butAppOff() {
public void testIsAppBlockable_fixedPermission_butAppOff() {
mController = new TestPreferenceController(mContext, mBackend);
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.lockedImportance = true;
appRow.systemApp = true;
appRow.banned = true;
mController.onResume(appRow, null, null, null, null, null, null);
assertTrue(mController.isAppBlockable());
}
@Test
public void testIsAppBlockable_notFixedButAppInBadState() {
mController = new TestPreferenceController(mContext, mBackend);
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.systemApp = false;
appRow.banned = true;
appRow.lockedImportance = true;
mController.onResume(appRow, null, null, null, null, null, null);
assertFalse(mController.isAppBlockable());
}

View File

@@ -142,7 +142,6 @@ public class VolumeOptionMenuControllerTest {
mController.onPrepareOptionsMenu(mMenu);
verify(mController.mRename, atLeastOnce()).setVisible(true);
verify(mController.mUnmount, atLeastOnce()).setVisible(true);
verify(mController.mFormatAsPortable, atLeastOnce()).setVisible(true);
verify(mController.mMount, never()).setVisible(true);
verify(mController.mFormat, never()).setVisible(true);