Merge "Fix CarrierSettings preference"
diff --git a/color-check-baseline.xml b/color-check-baseline.xml
index cbfae2e..0ae001d 100644
--- a/color-check-baseline.xml
+++ b/color-check-baseline.xml
@@ -2,18 +2,6 @@
<issues format="4">
<issue
- id="LintError"
- severity="Error"
- message="No `.class` files were found in project ".", so none of the classfile based checks could be run. Does the project need to be built first?"
- category="Lint"
- priority="10"
- summary="Lint Failure"
- explanation="This issue type represents a problem running lint itself. Examples include failure to find bytecode for source files (which means certain detectors could not be run), parsing errors in lint configuration files, etc.
These errors are not errors in your own code, but they are shown to make it clear that some checks were not completed.">
- <location
- file="."/>
- </issue>
-
- <issue
id="HardCodedColor"
severity="Error"
message="Avoid using hardcoded color"
@@ -2553,7 +2541,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~">
<location
file="res/values-en-rXC/strings.xml"
- line="2530"
+ line="2533"
column="168"/>
</issue>
@@ -2569,7 +2557,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~">
<location
file="res/values-en-rAU/strings.xml"
- line="2531"
+ line="2534"
column="64"/>
</issue>
@@ -2585,7 +2573,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~">
<location
file="res/values-en-rCA/strings.xml"
- line="2531"
+ line="2534"
column="64"/>
</issue>
@@ -2601,7 +2589,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~">
<location
file="res/values-en-rGB/strings.xml"
- line="2531"
+ line="2534"
column="64"/>
</issue>
@@ -2617,7 +2605,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~">
<location
file="res/values-en-rIN/strings.xml"
- line="2531"
+ line="2534"
column="64"/>
</issue>
@@ -2633,7 +2621,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~">
<location
file="res/values/strings.xml"
- line="5886"
+ line="5902"
column="36"/>
</issue>
@@ -2665,7 +2653,7 @@
errorLine2=" ^">
<location
file="res/values/styles.xml"
- line="443"
+ line="448"
column="44"/>
</issue>
@@ -2681,7 +2669,7 @@
errorLine2=" ^">
<location
file="res/values/styles.xml"
- line="449"
+ line="454"
column="44"/>
</issue>
@@ -2697,7 +2685,7 @@
errorLine2=" ^">
<location
file="res/values/styles.xml"
- line="450"
+ line="455"
column="44"/>
</issue>
@@ -2761,7 +2749,7 @@
errorLine2=" ^">
<location
file="res/values/themes.xml"
- line="91"
+ line="90"
column="47"/>
</issue>
@@ -2777,7 +2765,7 @@
errorLine2=" ^">
<location
file="res/values/themes.xml"
- line="91"
+ line="90"
column="47"/>
</issue>
@@ -2793,7 +2781,7 @@
errorLine2=" ^">
<location
file="res/values/themes.xml"
- line="97"
+ line="96"
column="40"/>
</issue>
@@ -2809,7 +2797,7 @@
errorLine2=" ^">
<location
file="res/values/themes.xml"
- line="97"
+ line="96"
column="40"/>
</issue>
@@ -2825,7 +2813,7 @@
errorLine2=" ^">
<location
file="res/values/themes.xml"
- line="160"
+ line="159"
column="45"/>
</issue>
@@ -2841,7 +2829,7 @@
errorLine2=" ^">
<location
file="res/values/themes.xml"
- line="161"
+ line="160"
column="49"/>
</issue>
@@ -2857,7 +2845,7 @@
errorLine2=" ^">
<location
file="res/values/themes.xml"
- line="169"
+ line="168"
column="45"/>
</issue>
@@ -2873,7 +2861,7 @@
errorLine2=" ^">
<location
file="res/values/themes.xml"
- line="170"
+ line="169"
column="49"/>
</issue>
@@ -2885,6 +2873,54 @@
priority="4"
summary="Using hardcoded color"
explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.
This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
+ errorLine1=" <item name="batteryGoodColor">@color/battery_good_color_light</item>"
+ errorLine2=" ^">
+ <location
+ file="res/values/themes.xml"
+ line="185"
+ column="39"/>
+ </issue>
+
+ <issue
+ id="HardCodedColor"
+ severity="Error"
+ message="Avoid using hardcoded color"
+ category="Correctness"
+ priority="4"
+ summary="Using hardcoded color"
+ explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.
This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
+ errorLine1=" <item name="batteryMaybeColor">@color/battery_maybe_color_light</item>"
+ errorLine2=" ^">
+ <location
+ file="res/values/themes.xml"
+ line="186"
+ column="40"/>
+ </issue>
+
+ <issue
+ id="HardCodedColor"
+ severity="Error"
+ message="Avoid using hardcoded color"
+ category="Correctness"
+ priority="4"
+ summary="Using hardcoded color"
+ explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.
This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
+ errorLine1=" <item name="batteryBadColor">@color/battery_bad_color_light</item>"
+ errorLine2=" ^">
+ <location
+ file="res/values/themes.xml"
+ line="187"
+ column="38"/>
+ </issue>
+
+ <issue
+ id="HardCodedColor"
+ severity="Error"
+ message="Avoid using hardcoded color"
+ category="Correctness"
+ priority="4"
+ summary="Using hardcoded color"
+ explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.
This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
errorLine1=" <item name="wifi_signal_color">@color/setup_wizard_wifi_color_dark</item>"
errorLine2=" ^">
<location
diff --git a/res/drawable/ic_settings_backup.xml b/res/drawable/ic_settings_backup.xml
index 231eadd..715a2e8 100644
--- a/res/drawable/ic_settings_backup.xml
+++ b/res/drawable/ic_settings_backup.xml
@@ -21,5 +21,5 @@
android:tint="?android:attr/colorControlNormal">
<path
android:fillColor="#FFFFFFFF"
- android:pathData="M17.92,10.02C17.45,7.18 14.97,5 12,5C9.82,5 7.83,6.18 6.78,8.06C4.09,8.41 2,10.74 2,13.5C2,16.53 4.47,19 7.5,19h10c2.48,0 4.5,-2.02 4.5,-4.5C22,12.16 20.21,10.23 17.92,10.02zM17.5,17h-10C5.57,17 4,15.43 4,13.5c0,-1.89 1.54,-3.46 3.44,-3.49L8.08,10l0.26,-0.59C8.97,7.94 10.41,7 12,7c2.21,0 4,1.79 4,4v1h1.5c1.38,0 2.5,1.12 2.5,2.5S18.88,17 17.5,17zM14.09,11.09l1.41,1.41l-2.79,2.79L12,16l-0.71,-0.71L8.5,12.5l1.41,-1.41L11,12.17V9.5h2v2.67L14.09,11.09z"/>
+ android:pathData="M17.92,10.02C17.45,7.18 14.97,5 12,5C9.82,5 7.83,6.18 6.78,8.06C4.09,8.41 2,10.74 2,13.5C2,16.53 4.47,19 7.5,19h10c2.48,0 4.5,-2.02 4.5,-4.5C22,12.16 20.21,10.23 17.92,10.02zM17.5,17h-10C5.57,17 4,15.43 4,13.5c0,-1.89 1.54,-3.46 3.44,-3.49L8.08,10l0.26,-0.59C8.97,7.94 10.41,7 12,7c2.21,0 4,1.79 4,4v1h1.5c1.38,0 2.5,1.12 2.5,2.5S18.88,17 17.5,17zM9.91,14.41L8.5,13l2.79,-2.79L12,9.5l0.71,0.71L15.5,13l-1.41,1.41L13,13.33V16h-2v-2.67L9.91,14.41z"/>
</vector>
diff --git a/res/layout/homepage_condition_footer.xml b/res/layout/homepage_condition_footer.xml
new file mode 100644
index 0000000..0ff7ac6
--- /dev/null
+++ b/res/layout/homepage_condition_footer.xml
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ 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.
+ -->
+
+<androidx.cardview.widget.CardView
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ style="@style/ContextualCardStyle">
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="@dimen/homepage_condition_footer_height"
+ android:contentDescription="@string/homepage_condition_footer_content_description"
+ android:gravity="end"
+ android:orientation="horizontal"
+ android:paddingTop="@dimen/homepage_condition_footer_padding_top"
+ android:paddingEnd="@dimen/homepage_condition_footer_padding_end">
+
+ <ImageView
+ android:id="@+id/collapse_button"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:src="@drawable/ic_expand_less" />
+
+ </LinearLayout>
+</androidx.cardview.widget.CardView>
\ No newline at end of file
diff --git a/res/layout/homepage_condition_header.xml b/res/layout/homepage_condition_header.xml
new file mode 100644
index 0000000..a440d7f
--- /dev/null
+++ b/res/layout/homepage_condition_header.xml
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ 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.
+ -->
+
+<androidx.cardview.widget.CardView
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ style="@style/ContextualCardStyle">
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:paddingTop="@dimen/homepage_condition_header_padding_top"
+ android:paddingBottom="@dimen/homepage_condition_header_padding_bottom"
+ android:orientation="horizontal"
+ android:gravity="center_vertical">
+
+ <LinearLayout
+ android:id="@+id/header_icons_container"
+ android:layout_width="0dp"
+ android:layout_height="match_parent"
+ android:layout_weight="1"
+ android:layout_marginStart="@dimen/homepage_condition_header_icons_margin_start"
+ android:orientation="horizontal"
+ android:gravity="center_vertical"/>
+
+ <ImageView
+ android:id="@+id/expand_indicator"
+ android:layout_width="wrap_content"
+ android:layout_height="match_parent"
+ android:paddingTop="@dimen/homepage_condition_header_indicator_padding_top"
+ android:paddingStart="@dimen/homepage_condition_header_indicator_padding_start"
+ android:paddingEnd="@dimen/homepage_condition_header_indicator_padding_end"
+ android:src="@drawable/ic_expand_more"/>
+
+ </LinearLayout>
+
+</androidx.cardview.widget.CardView>
\ No newline at end of file
diff --git a/res/layout/homepage_condition_header_icon.xml b/res/layout/homepage_condition_header_icon.xml
new file mode 100644
index 0000000..ae75140
--- /dev/null
+++ b/res/layout/homepage_condition_header_icon.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ 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.
+ -->
+
+<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@android:id/icon"
+ android:layout_width="@dimen/homepage_condition_header_icon_width_height"
+ android:layout_height="@dimen/homepage_condition_header_icon_width_height"
+ android:layout_marginEnd="@dimen/homepage_condition_header_icon_margin_end"
+ android:tint="?android:attr/colorAccent"/>
\ No newline at end of file
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index aa464a0..8f44c69 100755
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -198,6 +198,12 @@
+ (fingerprint_enrolling_content_margin_vertical x 2) -->
<dimen name="fingerprint_finish_max_size">288dp</dimen>
+ <!-- Face -->
+ <dimen name="face_preview_translate_y">0dp</dimen>
+ <dimen name="face_preview_translate_x">0dp</dimen>
+ <item name="face_preview_scale" format="float" type="dimen">1.0</item>
+
+ <!-- Confirm device credentials -->
<dimen name="confirm_credentials_security_method_margin">48dp</dimen>
<dimen name="confirm_credentials_layout_width">@dimen/match_parent</dimen>
<dimen name="confirm_credentials_top_padding">0dp</dimen>
@@ -349,5 +355,16 @@
<dimen name="homepage_condition_full_card_padding_end">24dp</dimen>
<dimen name="homepage_condition_full_card_padding_top">12dp</dimen>
<dimen name="homepage_condition_full_card_padding_bottom">12dp</dimen>
+ <dimen name="homepage_condition_header_padding_top">10dp</dimen>
+ <dimen name="homepage_condition_header_padding_bottom">10dp</dimen>
+ <dimen name="homepage_condition_header_icons_margin_start">24dp</dimen>
+ <dimen name="homepage_condition_header_indicator_padding_top">4dp</dimen>
+ <dimen name="homepage_condition_header_indicator_padding_start">16dp</dimen>
+ <dimen name="homepage_condition_header_indicator_padding_end">16dp</dimen>
+ <dimen name="homepage_condition_footer_height">44dp</dimen>
+ <dimen name="homepage_condition_footer_padding_top">10dp</dimen>
+ <dimen name="homepage_condition_footer_padding_end">10dp</dimen>
+ <dimen name="homepage_condition_header_icon_width_height">24dp</dimen>
+ <dimen name="homepage_condition_header_icon_margin_end">24dp</dimen>
</resources>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index bc35005..151ea14 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -9105,6 +9105,9 @@
<!-- Summary for the condition section on the dashboard, representing number of conditions. [CHAR LIMIT=10] -->
<string name="condition_summary" translatable="false"><xliff:g name="count" example="3">%1$d</xliff:g></string>
+ <!-- Content description for condition footer button. In talkback mode, double tapping will cause condition list to collapse [CHAR LIMIT=NONE]-->
+ <string name="homepage_condition_footer_content_description">Collapse</string>
+
<!-- Title for the suggestions section on the dashboard [CHAR LIMIT=30] -->
<string name="suggestions_title_v2">Suggested for You</string>
diff --git a/res/values/themes.xml b/res/values/themes.xml
index 4f44a36..b280482 100644
--- a/res/values/themes.xml
+++ b/res/values/themes.xml
@@ -180,6 +180,11 @@
<!-- action bar, needed for search bar icon tinting -->
<item name="android:actionBarTheme">@*android:style/ThemeOverlay.DeviceDefault.ActionBar.Accent</item>
+
+ <!-- For battery status icons in -->
+ <item name="batteryGoodColor">@color/battery_good_color_light</item>
+ <item name="batteryMaybeColor">@color/battery_maybe_color_light</item>
+ <item name="batteryBadColor">@color/battery_bad_color_light</item>
</style>
<style name="Theme.Settings.Home" parent="Theme.Settings.HomeBase">
diff --git a/src/com/android/settings/accounts/AccountDetailDashboardFragment.java b/src/com/android/settings/accounts/AccountDetailDashboardFragment.java
index 78a8614..e13d3eb 100644
--- a/src/com/android/settings/accounts/AccountDetailDashboardFragment.java
+++ b/src/com/android/settings/accounts/AccountDetailDashboardFragment.java
@@ -94,8 +94,7 @@
void finishIfAccountMissing() {
final Context context = getContext();
final UserManager um = context.getSystemService(UserManager.class);
- final AccountManager accountManager = (AccountManager) context.getSystemService(
- AccountManager.class);
+ final AccountManager accountManager = context.getSystemService(AccountManager.class);
for (UserHandle userHandle : um.getUserProfiles()) {
for (Account account : accountManager.getAccountsAsUser(userHandle.getIdentifier())) {
if (account.equals(mAccount)) {
diff --git a/src/com/android/settings/applications/LayoutPreference.java b/src/com/android/settings/applications/LayoutPreference.java
index cc077cc..9c3cfaf 100644
--- a/src/com/android/settings/applications/LayoutPreference.java
+++ b/src/com/android/settings/applications/LayoutPreference.java
@@ -24,7 +24,6 @@
import android.view.ViewGroup;
import android.widget.FrameLayout;
-import androidx.annotation.VisibleForTesting;
import androidx.core.content.res.TypedArrayUtils;
import androidx.preference.Preference;
import androidx.preference.PreferenceViewHolder;
@@ -37,9 +36,7 @@
private final View.OnClickListener mClickListener = v -> performClick(v);
private boolean mAllowDividerAbove;
private boolean mAllowDividerBelow;
-
- @VisibleForTesting
- View mRootView;
+ private View mRootView;
public LayoutPreference(Context context, AttributeSet attrs) {
super(context, attrs);
@@ -116,4 +113,11 @@
return mRootView.findViewById(id);
}
+ public void setAllowDividerBelow(boolean allowed) {
+ mAllowDividerBelow = allowed;
+ }
+
+ public boolean isAllowDividerBelow() {
+ return mAllowDividerBelow;
+ }
}
\ No newline at end of file
diff --git a/src/com/android/settings/biometrics/face/FaceEnrollPreviewFragment.java b/src/com/android/settings/biometrics/face/FaceEnrollPreviewFragment.java
index 1861e10..a543584 100644
--- a/src/com/android/settings/biometrics/face/FaceEnrollPreviewFragment.java
+++ b/src/com/android/settings/biometrics/face/FaceEnrollPreviewFragment.java
@@ -17,7 +17,6 @@
package com.android.settings.biometrics.face;
import android.content.Context;
-import android.graphics.Matrix;
import android.graphics.SurfaceTexture;
import android.hardware.camera2.CameraAccessException;
import android.hardware.camera2.CameraCaptureSession;
@@ -31,6 +30,7 @@
import android.os.Looper;
import android.util.Log;
import android.util.Size;
+import android.util.TypedValue;
import android.view.Surface;
import android.view.TextureView;
import android.view.View;
@@ -41,11 +41,7 @@
import com.android.settings.biometrics.BiometricEnrollSidecar;
import com.android.settings.core.InstrumentedPreferenceFragment;
-import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.List;
/**
* Fragment that contains the logic for showing and controlling the camera preview, circular
@@ -120,7 +116,6 @@
@Override
public void onOpened(CameraDevice cameraDevice) {
mCameraDevice = cameraDevice;
-
try {
// Configure the size of default buffer
SurfaceTexture texture = mTextureView.getSurfaceTexture();
@@ -245,11 +240,8 @@
/**
* Sets up member variables related to camera.
- *
- * @param width The width of available size for camera preview
- * @param height The height of available size for camera preview
*/
- private void setUpCameraOutputs(int width, int height) {
+ private void setUpCameraOutputs() {
try {
for (String cameraId : mCameraManager.getCameraIdList()) {
CameraCharacteristics characteristics =
@@ -265,8 +257,7 @@
// Get the stream configurations
StreamConfigurationMap map = characteristics.get(
CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
- mPreviewSize = chooseOptimalSize(map.getOutputSizes(SurfaceTexture.class),
- width, height, MAX_PREVIEW_WIDTH, MAX_PREVIEW_HEIGHT);
+ mPreviewSize = chooseOptimalSize(map.getOutputSizes(SurfaceTexture.class));
break;
}
} catch (CameraAccessException e) {
@@ -281,7 +272,7 @@
*/
private void openCamera(int width, int height) {
try {
- setUpCameraOutputs(width, height);
+ setUpCameraOutputs();
mCameraManager.openCamera(mCameraId, mCameraStateCallback, mHandler);
configureTransform(width, height);
} catch (CameraAccessException e) {
@@ -292,35 +283,15 @@
/**
* Chooses the optimal resolution for the camera to open.
*/
- private Size chooseOptimalSize(Size[] choices, int textureViewWidth, int textureViewHeight,
- int maxWidth, int maxHeight) {
- // Collect the supported resolutions that are at least as big as the preview Surface
- List<Size> bigEnough = new ArrayList<>();
- // Collect the supported resolutions that are smaller than the preview Surface
- List<Size> notBigEnough = new ArrayList<>();
-
- for (Size option : choices) {
- if (option.getWidth() <= maxWidth && option.getHeight() <= maxHeight &&
- option.getHeight() == option.getWidth()) {
- if (option.getWidth() >= textureViewWidth &&
- option.getHeight() >= textureViewHeight) {
- bigEnough.add(option);
- } else {
- notBigEnough.add(option);
- }
+ private Size chooseOptimalSize(Size[] choices) {
+ for (int i = 0; i < choices.length; i++) {
+ if (choices[i].getHeight() == MAX_PREVIEW_HEIGHT
+ && choices[i].getWidth() == MAX_PREVIEW_WIDTH) {
+ return choices[i];
}
}
-
- // Pick the smallest of those big enough. If there is no one big enough, pick the
- // largest of those not big enough.
- if (bigEnough.size() > 0) {
- return Collections.min(bigEnough, new CompareSizesByArea());
- } else if (notBigEnough.size() > 0) {
- return Collections.max(notBigEnough, new CompareSizesByArea());
- } else {
- Log.e(TAG, "Couldn't find any suitable preview size");
- return choices[0];
- }
+ Log.w(TAG, "Unable to find a good resolution");
+ return choices[0];
}
/**
@@ -337,19 +308,22 @@
}
// Fix the aspect ratio
- Matrix matrix = new Matrix();
float scaleX = (float) viewWidth / mPreviewSize.getWidth();
float scaleY = (float) viewHeight / mPreviewSize.getHeight();
- // Now divide by smaller one so it fills up the original space
+ // Now divide by smaller one so it fills up the original space.
float smaller = Math.min(scaleX, scaleY);
scaleX = scaleX / smaller;
scaleY = scaleY / smaller;
- // Apply the scale
- matrix.setScale(scaleX, scaleY);
+ // Apply the transformation/scale
+ mTextureView.setTranslationX(getResources().getDimension(R.dimen.face_preview_translate_x));
+ mTextureView.setTranslationY(getResources().getDimension(R.dimen.face_preview_translate_y));
- mTextureView.setTransform(matrix);
+ final TypedValue scale = new TypedValue();
+ getResources().getValue(R.dimen.face_preview_scale, scale, true /* resolveRefs */);
+ mTextureView.setScaleX(scaleX * scale.getFloat());
+ mTextureView.setScaleY(scaleY * scale.getFloat());
}
private void closeCamera() {
@@ -362,18 +336,4 @@
mCameraDevice = null;
}
}
-
- /**
- * Compares two {@code Size}s based on their areas.
- */
- private static class CompareSizesByArea implements Comparator<Size> {
- @Override
- public int compare(Size lhs, Size rhs) {
- // We cast here to ensure the multiplications won't overflow
- return Long.signum((long) lhs.getWidth() * lhs.getHeight() -
- (long) rhs.getWidth() * rhs.getHeight());
- }
-
- }
-
}
diff --git a/src/com/android/settings/deviceinfo/imei/ImeiInfoDialogController.java b/src/com/android/settings/deviceinfo/imei/ImeiInfoDialogController.java
index 577b478..3584849 100644
--- a/src/com/android/settings/deviceinfo/imei/ImeiInfoDialogController.java
+++ b/src/com/android/settings/deviceinfo/imei/ImeiInfoDialogController.java
@@ -128,7 +128,7 @@
private SubscriptionInfo getSubscriptionInfo(Context context, int slotId) {
final List<SubscriptionInfo> subscriptionInfoList = SubscriptionManager.from(context)
.getActiveSubscriptionInfoList();
- if (subscriptionInfoList == null) {
+ if (subscriptionInfoList == null || subscriptionInfoList.isEmpty()) {
return null;
}
diff --git a/src/com/android/settings/fuelgauge/BatteryBroadcastReceiver.java b/src/com/android/settings/fuelgauge/BatteryBroadcastReceiver.java
index b5c39a1..0266689 100644
--- a/src/com/android/settings/fuelgauge/BatteryBroadcastReceiver.java
+++ b/src/com/android/settings/fuelgauge/BatteryBroadcastReceiver.java
@@ -26,6 +26,7 @@
import androidx.annotation.VisibleForTesting;
import com.android.settings.Utils;
+import com.android.settings.homepage.contextualcards.slices.BatteryFixSlice;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -115,6 +116,6 @@
mBatteryListener.onBatteryChanged(BatteryUpdateType.BATTERY_SAVER);
}
}
+ BatteryFixSlice.updateBatteryTipAvailabilityCache(mContext);
}
-
}
\ No newline at end of file
diff --git a/src/com/android/settings/homepage/contextualcards/CardContentProvider.java b/src/com/android/settings/homepage/contextualcards/CardContentProvider.java
index 8088143..e7ede14 100644
--- a/src/com/android/settings/homepage/contextualcards/CardContentProvider.java
+++ b/src/com/android/settings/homepage/contextualcards/CardContentProvider.java
@@ -17,6 +17,7 @@
package com.android.settings.homepage.contextualcards;
import android.content.ContentProvider;
+import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.UriMatcher;
import android.database.Cursor;
@@ -36,10 +37,15 @@
*/
public class CardContentProvider extends ContentProvider {
- private static final String TAG = "CardContentProvider";
-
public static final String CARD_AUTHORITY = "com.android.settings.homepage.CardContentProvider";
+ public static final Uri URI = new Uri.Builder()
+ .scheme(ContentResolver.SCHEME_CONTENT)
+ .authority(CardContentProvider.CARD_AUTHORITY)
+ .appendPath(CardDatabaseHelper.CARD_TABLE)
+ .build();
+
+ private static final String TAG = "CardContentProvider";
/** URI matcher for ContentProvider queries. */
private static final UriMatcher URI_MATCHER = new UriMatcher(UriMatcher.NO_MATCH);
/** URI matcher type for cards table */
diff --git a/src/com/android/settings/homepage/contextualcards/CardDatabaseHelper.java b/src/com/android/settings/homepage/contextualcards/CardDatabaseHelper.java
index b5cdf87..164afdd 100644
--- a/src/com/android/settings/homepage/contextualcards/CardDatabaseHelper.java
+++ b/src/com/android/settings/homepage/contextualcards/CardDatabaseHelper.java
@@ -209,16 +209,19 @@
* Mark a specific ContextualCard with dismissal flag in the database to indicate that the
* card has been dismissed.
*
- * @param cardName the card name of the ContextualCard which is dismissed by user.
- * @return updated row number
+ * @param context Context
+ * @param cardName The card name of the ContextualCard which is dismissed by user.
+ * @return The number of rows updated
*/
- public int markContextualCardAsDismissed(String cardName) {
- final SQLiteDatabase database = this.getWritableDatabase();
+ public int markContextualCardAsDismissed(Context context, String cardName) {
+ final SQLiteDatabase database = getWritableDatabase();
final ContentValues values = new ContentValues();
values.put(CardColumns.CARD_DISMISSED, 1);
final String selection = CardColumns.NAME + "=?";
final String[] selectionArgs = {cardName};
final int rowsUpdated = database.update(CARD_TABLE, values, selection, selectionArgs);
+ database.close();
+ context.getContentResolver().notifyChange(CardContentProvider.URI, null);
return rowsUpdated;
}
}
diff --git a/src/com/android/settings/homepage/contextualcards/ContextualCardLoader.java b/src/com/android/settings/homepage/contextualcards/ContextualCardLoader.java
index adfaf20..c723cfd 100644
--- a/src/com/android/settings/homepage/contextualcards/ContextualCardLoader.java
+++ b/src/com/android/settings/homepage/contextualcards/ContextualCardLoader.java
@@ -24,8 +24,11 @@
import android.content.ContentResolver;
import android.content.Context;
import android.content.pm.PackageManager;
+import android.database.ContentObserver;
import android.database.Cursor;
import android.net.Uri;
+import android.os.Handler;
+import android.os.Looper;
import android.util.Log;
import androidx.annotation.NonNull;
@@ -61,6 +64,19 @@
}
@Override
+ protected void onStartLoading() {
+ super.onStartLoading();
+ mContext.getContentResolver().registerContentObserver(CardContentProvider.URI,
+ false /*notifyForDescendants*/, mObserver);
+ }
+
+ @Override
+ protected void onStopLoading() {
+ super.onStopLoading();
+ mContext.getContentResolver().unregisterContentObserver(mObserver);
+ }
+
+ @Override
protected void onDiscardResult(List<ContextualCard> result) {
}
@@ -184,4 +200,14 @@
}
return -1L;
}
+
+ private final ContentObserver mObserver = new ContentObserver(
+ new Handler(Looper.getMainLooper())) {
+ @Override
+ public void onChange(boolean selfChange) {
+ if (isStarted()) {
+ forceLoad();
+ }
+ }
+ };
}
diff --git a/src/com/android/settings/homepage/contextualcards/ControllerRendererPool.java b/src/com/android/settings/homepage/contextualcards/ControllerRendererPool.java
index 723b344..931bfb7 100644
--- a/src/com/android/settings/homepage/contextualcards/ControllerRendererPool.java
+++ b/src/com/android/settings/homepage/contextualcards/ControllerRendererPool.java
@@ -114,7 +114,7 @@
if (ConditionContextualCardController.class == clz) {
return new ConditionContextualCardController(context);
} else if (SliceContextualCardController.class == clz) {
- return new SliceContextualCardController();
+ return new SliceContextualCardController(context);
} else if (LegacySuggestionContextualCardController.class == clz) {
return new LegacySuggestionContextualCardController(context);
}
diff --git a/src/com/android/settings/homepage/contextualcards/SettingsContextualCardProvider.java b/src/com/android/settings/homepage/contextualcards/SettingsContextualCardProvider.java
index f58ec74..db3fddc 100644
--- a/src/com/android/settings/homepage/contextualcards/SettingsContextualCardProvider.java
+++ b/src/com/android/settings/homepage/contextualcards/SettingsContextualCardProvider.java
@@ -21,6 +21,7 @@
import android.annotation.Nullable;
import com.android.settings.homepage.contextualcards.deviceinfo.BatterySlice;
+import com.android.settings.homepage.contextualcards.slices.BatteryFixSlice;
import com.android.settings.homepage.contextualcards.slices.ConnectedDeviceSlice;
import com.android.settings.homepage.contextualcards.slices.LowStorageSlice;
import com.android.settings.intelligence.ContextualCardProto.ContextualCard;
@@ -61,11 +62,18 @@
.setCardName(LowStorageSlice.PATH_LOW_STORAGE)
.setCardCategory(ContextualCard.Category.IMPORTANT)
.build();
+ final ContextualCard batteryFixCard =
+ ContextualCard.newBuilder()
+ .setSliceUri(BatteryFixSlice.BATTERY_FIX_URI.toString())
+ .setCardName(BatteryFixSlice.PATH_BATTERY_FIX)
+ .setCardCategory(ContextualCard.Category.IMPORTANT)
+ .build();
final ContextualCardList cards = ContextualCardList.newBuilder()
.addCard(wifiCard)
.addCard(batteryInfoCard)
.addCard(connectedDeviceCard)
.addCard(lowStorageCard)
+ .addCard(batteryFixCard)
.build();
return cards;
diff --git a/src/com/android/settings/homepage/contextualcards/conditional/ConditionContextualCardController.java b/src/com/android/settings/homepage/contextualcards/conditional/ConditionContextualCardController.java
index 84ceabd..6fcc636 100644
--- a/src/com/android/settings/homepage/contextualcards/conditional/ConditionContextualCardController.java
+++ b/src/com/android/settings/homepage/contextualcards/conditional/ConditionContextualCardController.java
@@ -77,13 +77,13 @@
@Override
public void onActionClick(ContextualCard contextualCard) {
-
+ final ConditionalContextualCard card = (ConditionalContextualCard) contextualCard;
+ mConditionManager.onActionClick(card.getConditionId());
}
@Override
public void onDismissed(ContextualCard contextualCard) {
- final ConditionalContextualCard card = (ConditionalContextualCard) contextualCard;
- mConditionManager.onActionClick(card.getConditionId());
+
}
@Override
@@ -93,8 +93,8 @@
final boolean isOddNumber = conditionCards.size() % 2 == 1;
if (isOddNumber) {
final int lastIndex = conditionCards.size() - 1;
- final ConditionalContextualCard card = (ConditionalContextualCard) conditionCards.get(
- lastIndex);
+ final ConditionalContextualCard card = (ConditionalContextualCard) conditionCards
+ .get(lastIndex);
conditionCards.set(lastIndex, card.mutate().setIsHalfWidth(false).build());
}
diff --git a/src/com/android/settings/homepage/contextualcards/conditional/ConditionContextualCardRenderer.java b/src/com/android/settings/homepage/contextualcards/conditional/ConditionContextualCardRenderer.java
index 3405dd2..34f442c 100644
--- a/src/com/android/settings/homepage/contextualcards/conditional/ConditionContextualCardRenderer.java
+++ b/src/com/android/settings/homepage/contextualcards/conditional/ConditionContextualCardRenderer.java
@@ -113,7 +113,7 @@
viewContext, MetricsProto.MetricsEvent.ACTION_SETTINGS_CONDITION_BUTTON,
card.getMetricsConstant());
mControllerRendererPool.getController(mContext, card.getCardType())
- .onDismissed(card);
+ .onActionClick(card);
});
} else {
button.setVisibility(View.GONE);
diff --git a/src/com/android/settings/homepage/contextualcards/deviceinfo/DeviceInfoSlice.java b/src/com/android/settings/homepage/contextualcards/deviceinfo/DeviceInfoSlice.java
index d6fdfd5..b8751f8 100644
--- a/src/com/android/settings/homepage/contextualcards/deviceinfo/DeviceInfoSlice.java
+++ b/src/com/android/settings/homepage/contextualcards/deviceinfo/DeviceInfoSlice.java
@@ -131,7 +131,7 @@
SubscriptionInfo getFirstSubscriptionInfo() {
final List<SubscriptionInfo> subscriptionInfoList =
mSubscriptionManager.getActiveSubscriptionInfoList();
- if (subscriptionInfoList == null) {
+ if (subscriptionInfoList == null || subscriptionInfoList.isEmpty()) {
return null;
}
return subscriptionInfoList.get(0);
diff --git a/src/com/android/settings/homepage/contextualcards/slices/BatteryFixSlice.java b/src/com/android/settings/homepage/contextualcards/slices/BatteryFixSlice.java
new file mode 100644
index 0000000..23ff172
--- /dev/null
+++ b/src/com/android/settings/homepage/contextualcards/slices/BatteryFixSlice.java
@@ -0,0 +1,224 @@
+/*
+ * 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.homepage.contextualcards.slices;
+
+import static android.content.Context.MODE_PRIVATE;
+
+import android.app.PendingIntent;
+import android.content.ContentResolver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.net.Uri;
+
+import androidx.annotation.VisibleForTesting;
+import androidx.annotation.WorkerThread;
+import androidx.core.graphics.drawable.IconCompat;
+import androidx.slice.Slice;
+import androidx.slice.builders.ListBuilder;
+import androidx.slice.builders.ListBuilder.RowBuilder;
+import androidx.slice.builders.SliceAction;
+
+import com.android.internal.logging.nano.MetricsProto;
+import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
+import com.android.internal.os.BatteryStatsHelper;
+import com.android.settings.R;
+import com.android.settings.SubSettings;
+import com.android.settings.Utils;
+import com.android.settings.fuelgauge.BatteryStatsHelperLoader;
+import com.android.settings.fuelgauge.PowerUsageSummary;
+import com.android.settings.fuelgauge.batterytip.BatteryTipLoader;
+import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
+import com.android.settings.slices.CustomSliceable;
+import com.android.settings.slices.SettingsSliceProvider;
+import com.android.settings.slices.SliceBackgroundWorker;
+import com.android.settings.slices.SliceBuilderUtils;
+import com.android.settingslib.utils.ThreadUtils;
+
+import java.util.List;
+
+public class BatteryFixSlice implements CustomSliceable {
+
+ /**
+ * Unique name of Battery Fix Slice.
+ */
+ public static final String PATH_BATTERY_FIX = "battery_fix";
+
+ /**
+ * Uri for Battery Fix Slice.
+ */
+ public static final Uri BATTERY_FIX_URI = new Uri.Builder()
+ .scheme(ContentResolver.SCHEME_CONTENT)
+ .authority(SettingsSliceProvider.SLICE_AUTHORITY)
+ .appendPath(PATH_BATTERY_FIX)
+ .build();
+
+ @VisibleForTesting
+ static final String PREFS = "battery_fix_prefs";
+ @VisibleForTesting
+ static final String KEY_CURRENT_TIPS_TYPE = "current_tip_type";
+
+ private static final String TAG = "BatteryFixSlice";
+
+ private final Context mContext;
+
+ public BatteryFixSlice(Context context) {
+ mContext = context;
+ }
+
+ @Override
+ public Uri getUri() {
+ return BATTERY_FIX_URI;
+ }
+
+ /**
+ * Return a Slice bound to {@link #BATTERY_FIX_URI}.
+ */
+ @Override
+ public Slice getSlice() {
+ IconCompat icon;
+ SliceAction primaryAction;
+ Slice slice = null;
+
+ // TipType.SUMMARY is battery good
+ if (readBatteryTipAvailabilityCache(mContext) == BatteryTip.TipType.SUMMARY) {
+ return null;
+ }
+
+ final List<BatteryTip> batteryTips = SliceBackgroundWorker.getInstance(mContext,
+ this).getResults();
+
+ if (batteryTips != null) {
+ for (BatteryTip batteryTip : batteryTips) {
+ if (batteryTip.getState() != BatteryTip.StateType.INVISIBLE) {
+ icon = IconCompat.createWithResource(mContext, batteryTip.getIconId());
+ primaryAction = new SliceAction(getPrimaryAction(),
+ icon,
+ batteryTip.getTitle(mContext));
+ slice = new ListBuilder(mContext, BATTERY_FIX_URI, ListBuilder.INFINITY)
+ .setAccentColor(Utils.getColorAccentDefaultColor(mContext))
+ .addRow(new RowBuilder()
+ .setTitle(batteryTip.getTitle(mContext))
+ .setSubtitle(batteryTip.getSummary(mContext))
+ .setPrimaryAction(primaryAction)
+ .addEndItem(icon, ListBuilder.ICON_IMAGE))
+ .build();
+ break;
+ }
+ }
+ } else {
+ icon = IconCompat.createWithResource(mContext,
+ R.drawable.ic_battery_status_good_24dp);
+ final String title = mContext.getString(R.string.power_usage_summary_title);
+ primaryAction = new SliceAction(getPrimaryAction(), icon, title);
+ slice = new ListBuilder(mContext, BATTERY_FIX_URI, ListBuilder.INFINITY)
+ .setAccentColor(Utils.getColorAccentDefaultColor(mContext))
+ .addRow(new RowBuilder()
+ .setTitle(title)
+ .setPrimaryAction(primaryAction)
+ .addEndItem(icon, ListBuilder.ICON_IMAGE))
+ .build();
+ }
+ return slice;
+ }
+
+ @Override
+ public Intent getIntent() {
+ final String screenTitle = mContext.getText(R.string.power_usage_summary_title)
+ .toString();
+ final Uri contentUri = new Uri.Builder().appendPath(PATH_BATTERY_FIX).build();
+
+ return SliceBuilderUtils.buildSearchResultPageIntent(mContext,
+ PowerUsageSummary.class.getName(), PATH_BATTERY_FIX,
+ screenTitle,
+ MetricsProto.MetricsEvent.SLICE)
+ .setClassName(mContext.getPackageName(), SubSettings.class.getName())
+ .setData(contentUri);
+ }
+
+ @Override
+ public void onNotifyChange(Intent intent) {
+ }
+
+ @Override
+ public Class getBackgroundWorkerClass() {
+ return BatteryTipWorker.class;
+ }
+
+ private PendingIntent getPrimaryAction() {
+ final Intent intent = getIntent();
+ return PendingIntent.getActivity(mContext, 0 /* requestCode */, intent, 0 /* flags */);
+ }
+
+ // TODO(b/114807643): we should find a better way to get current battery tip type quickly
+ // Now we save battery tip type to shared preference when battery level changes
+ public static void updateBatteryTipAvailabilityCache(Context context) {
+ ThreadUtils.postOnBackgroundThread(() -> {
+ refreshBatteryTips(context);
+ });
+ }
+
+ @VisibleForTesting
+ static int readBatteryTipAvailabilityCache(Context context) {
+ final SharedPreferences prefs = context.getSharedPreferences(PREFS, MODE_PRIVATE);
+ return prefs.getInt(KEY_CURRENT_TIPS_TYPE, BatteryTip.TipType.SUMMARY);
+ }
+
+ @WorkerThread
+ private static List<BatteryTip> refreshBatteryTips(Context context) {
+ final BatteryStatsHelperLoader statsLoader = new BatteryStatsHelperLoader(context);
+ final BatteryStatsHelper statsHelper = statsLoader.loadInBackground();
+ final BatteryTipLoader loader = new BatteryTipLoader(context, statsHelper);
+ final List<BatteryTip> batteryTips = loader.loadInBackground();
+ for (BatteryTip batteryTip : batteryTips) {
+ if (batteryTip.getState() != BatteryTip.StateType.INVISIBLE) {
+ SharedPreferences.Editor editor = context.getSharedPreferences(PREFS,
+ MODE_PRIVATE).edit();
+ editor.putInt(KEY_CURRENT_TIPS_TYPE, batteryTip.getType());
+ editor.apply();
+ break;
+ }
+ }
+ return batteryTips;
+ }
+
+ public static class BatteryTipWorker extends SliceBackgroundWorker<BatteryTip> {
+
+ private final Context mContext;
+
+ public BatteryTipWorker(Context context, Uri uri) {
+ super(context, uri);
+ mContext = context;
+ }
+
+ @Override
+ protected void onSlicePinned() {
+ ThreadUtils.postOnBackgroundThread(() -> {
+ final List<BatteryTip> batteryTips = refreshBatteryTips(mContext);
+ updateResults(batteryTips);
+ });
+ }
+
+ @Override
+ protected void onSliceUnpinned() {
+ }
+
+ @Override
+ public void close() {
+ }
+ }
+}
diff --git a/src/com/android/settings/homepage/contextualcards/slices/SliceContextualCardController.java b/src/com/android/settings/homepage/contextualcards/slices/SliceContextualCardController.java
index 6ab8f40..f1fbc9c 100644
--- a/src/com/android/settings/homepage/contextualcards/slices/SliceContextualCardController.java
+++ b/src/com/android/settings/homepage/contextualcards/slices/SliceContextualCardController.java
@@ -16,9 +16,14 @@
package com.android.settings.homepage.contextualcards.slices;
+import android.content.Context;
+
+import com.android.settings.homepage.contextualcards.CardContentProvider;
+import com.android.settings.homepage.contextualcards.CardDatabaseHelper;
import com.android.settings.homepage.contextualcards.ContextualCard;
import com.android.settings.homepage.contextualcards.ContextualCardController;
import com.android.settings.homepage.contextualcards.ContextualCardUpdateListener;
+import com.android.settingslib.utils.ThreadUtils;
/**
* Card controller for {@link ContextualCard} built as slices.
@@ -27,8 +32,13 @@
private static final String TAG = "SliceCardController";
+ private Context mContext;
private ContextualCardUpdateListener mCardUpdateListener;
+ public SliceContextualCardController(Context context) {
+ mContext = context;
+ }
+
@Override
public int getCardType() {
return ContextualCard.CardType.SLICE;
@@ -46,11 +56,14 @@
@Override
public void onDismissed(ContextualCard card) {
- //TODO(b/113783548): Mark this card as dismissed in db and reload loader.
+ ThreadUtils.postOnBackgroundThread(() -> {
+ final CardDatabaseHelper dbHelper = CardDatabaseHelper.getInstance(mContext);
+ dbHelper.markContextualCardAsDismissed(mContext, card.getName());
+ });
}
@Override
public void setCardUpdateListener(ContextualCardUpdateListener listener) {
- mCardUpdateListener = listener;
+ mCardUpdateListener = listener;
}
}
diff --git a/src/com/android/settings/slices/CustomSliceManager.java b/src/com/android/settings/slices/CustomSliceManager.java
index 5b25498..99e22a1 100644
--- a/src/com/android/settings/slices/CustomSliceManager.java
+++ b/src/com/android/settings/slices/CustomSliceManager.java
@@ -20,10 +20,13 @@
import android.net.Uri;
import android.util.ArrayMap;
+import androidx.annotation.VisibleForTesting;
+
import com.android.settings.homepage.contextualcards.deviceinfo.BatterySlice;
import com.android.settings.homepage.contextualcards.deviceinfo.DataUsageSlice;
import com.android.settings.homepage.contextualcards.deviceinfo.DeviceInfoSlice;
import com.android.settings.homepage.contextualcards.deviceinfo.StorageSlice;
+import com.android.settings.homepage.contextualcards.slices.BatteryFixSlice;
import com.android.settings.homepage.contextualcards.slices.ConnectedDeviceSlice;
import com.android.settings.homepage.contextualcards.slices.LowStorageSlice;
import com.android.settings.wifi.WifiSlice;
@@ -34,13 +37,11 @@
/**
* Manages custom {@link androidx.slice.Slice Slices}, which are all Slices not backed by
* preferences.
- * <p>
- * By default, all Slices in Settings should be built by a
- * </p>
*/
public class CustomSliceManager {
- protected final Map<Uri, Class<? extends CustomSliceable>> mUriMap;
+ @VisibleForTesting
+ final Map<Uri, Class<? extends CustomSliceable>> mUriMap;
private final Context mContext;
private final Map<Uri, CustomSliceable> mSliceableCache;
@@ -107,5 +108,6 @@
mUriMap.put(BatterySlice.BATTERY_CARD_URI, BatterySlice.class);
mUriMap.put(ConnectedDeviceSlice.CONNECTED_DEVICE_URI, ConnectedDeviceSlice.class);
mUriMap.put(LowStorageSlice.LOW_STORAGE_URI, LowStorageSlice.class);
+ mUriMap.put(BatteryFixSlice.BATTERY_FIX_URI, BatteryFixSlice.class);
}
}
diff --git a/src/com/android/settings/widget/EntityHeaderController.java b/src/com/android/settings/widget/EntityHeaderController.java
index 5e83819..853313f 100644
--- a/src/com/android/settings/widget/EntityHeaderController.java
+++ b/src/com/android/settings/widget/EntityHeaderController.java
@@ -238,6 +238,7 @@
pref.setOrder(-1000);
pref.setSelectable(false);
pref.setKey(PREF_KEY_APP_HEADER);
+ pref.setAllowDividerBelow(true);
return pref;
}
diff --git a/src/com/android/settings/wifi/qrcode/QrCamera.java b/src/com/android/settings/wifi/qrcode/QrCamera.java
index 3230035..c29236c 100644
--- a/src/com/android/settings/wifi/qrcode/QrCamera.java
+++ b/src/com/android/settings/wifi/qrcode/QrCamera.java
@@ -298,18 +298,30 @@
}
}
+ /** Get best preview size from the list of camera supported preview sizes. Compares the
+ * preview size and aspect ratio to choose the best one. */
private Size getBestPreviewSize(Camera.Parameters parameters) {
+ final double minRatioDiffPercent = 0.1;
final Size windowSize = mScannerCallback.getViewSize();
+ final double winRatio = getRatio(windowSize.getWidth(), windowSize.getHeight());
+ double bestChoiceRatio = 0;
Size bestChoice = new Size(0, 0);
for (Camera.Size size : parameters.getSupportedPreviewSizes()) {
- if (size.width <= windowSize.getWidth() && size.height <= windowSize.getHeight()) {
+ double ratio = getRatio(size.width, size.height);
+ if (size.height * size.width > bestChoice.getWidth() * bestChoice.getHeight()
+ && (Math.abs(bestChoiceRatio - winRatio) / winRatio > minRatioDiffPercent
+ || Math.abs(ratio - winRatio) / winRatio <= minRatioDiffPercent)) {
bestChoice = new Size(size.width, size.height);
- break;
+ bestChoiceRatio = getRatio(size.width, size.height);
}
}
return bestChoice;
}
+ private double getRatio(double x, double y) {
+ return (x < y) ? x / y : y / x;
+ }
+
@VisibleForTesting
protected void decodeImage(BinaryBitmap image) {
Result qrCode = null;
diff --git a/src/com/android/settings/wifi/qrcode/QrCodeGenerator.java b/src/com/android/settings/wifi/qrcode/QrCodeGenerator.java
new file mode 100644
index 0000000..08fcb10
--- /dev/null
+++ b/src/com/android/settings/wifi/qrcode/QrCodeGenerator.java
@@ -0,0 +1,47 @@
+/*
+ * 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.wifi.qrcode;
+
+import android.graphics.Bitmap;
+import android.graphics.Color;
+
+import com.google.zxing.BarcodeFormat;
+import com.google.zxing.MultiFormatWriter;
+import com.google.zxing.WriterException;
+import com.google.zxing.common.BitMatrix;
+
+public final class QrCodeGenerator {
+ /**
+ * Generates a barcode image with {@code contents}.
+ *
+ * @param contents The contents to encode in the barcode
+ * @param size The preferred image size in pixels
+ * @return Barcode bitmap
+ */
+ public static Bitmap encodeQrCode(String contents, int size)
+ throws WriterException, IllegalArgumentException {
+ final BitMatrix qrBits = new MultiFormatWriter().encode(contents, BarcodeFormat.QR_CODE,
+ size, size);
+ final Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.RGB_565);
+ for (int x = 0; x < size; x++) {
+ for (int y = 0; y < size; y++) {
+ bitmap.setPixel(x, y, qrBits.get(x, y) ? Color.BLACK : Color.WHITE);
+ }
+ }
+ return bitmap;
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/accessibility/AccessibilityHearingAidPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/accessibility/AccessibilityHearingAidPreferenceControllerTest.java
index 06fd1fc..0209267 100644
--- a/tests/robotests/src/com/android/settings/accessibility/AccessibilityHearingAidPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/accessibility/AccessibilityHearingAidPreferenceControllerTest.java
@@ -166,11 +166,11 @@
mPreferenceController.setPreference(mHearingAidPreference);
//not call registerReceiver()
mPreferenceController.onResume();
- verify(mContext, never()).registerReceiver((BroadcastReceiver) any(), (IntentFilter) any());
+ verify(mContext, never()).registerReceiver(any(), any());
//not call unregisterReceiver()
mPreferenceController.onPause();
- verify(mContext, never()).unregisterReceiver((BroadcastReceiver) any());
+ verify(mContext, never()).unregisterReceiver(any());
}
private void setupBluetoothEnvironment() {
@@ -185,9 +185,9 @@
private void setupHearingAidEnvironment() {
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
- mShadowBluetoothAdapter = Shadow.extract(BluetoothAdapter.getDefaultAdapter());
+ mShadowBluetoothAdapter = Shadow.extract(mBluetoothAdapter);
mBluetoothDevice = mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS);
- mShadowBluetoothAdapter.enable();
+ mBluetoothAdapter.enable();
mShadowBluetoothAdapter.addSupportedProfiles(BluetoothProfile.HEARING_AID);
when(mCachedDeviceManager.findDevice(mBluetoothDevice)).thenReturn(mCachedBluetoothDevice);
when(mCachedBluetoothDevice.getName()).thenReturn(TEST_DEVICE_NAME);
diff --git a/tests/robotests/src/com/android/settings/accounts/AccountDetailDashboardFragmentTest.java b/tests/robotests/src/com/android/settings/accounts/AccountDetailDashboardFragmentTest.java
index 2648916..f18496c 100644
--- a/tests/robotests/src/com/android/settings/accounts/AccountDetailDashboardFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/accounts/AccountDetailDashboardFragmentTest.java
@@ -166,11 +166,11 @@
public void onResume_accountMissing_shouldFinish() {
ShadowUserManager userManager = Shadow.extract(
mContext.getSystemService(UserManager.class));
- ShadowAccountManager acctMgr = Shadow.extract(
+ ShadowAccountManager accountManager = Shadow.extract(
mContext.getSystemService(AccountManager.class));
- userManager.addProfile(new UserInfo(1, null, 0));
- acctMgr.addAccountForUser(1, new Account("test@test.com", "com.test"));
+ userManager.addUserProfile(new UserHandle(1));
+ accountManager.addAccountForUser(1, new Account("test@test.com", "com.test"));
mFragment.finishIfAccountMissing();
verify(mFragment).finish();
@@ -180,11 +180,11 @@
public void onResume_accountPresentOneProfile_shouldNotFinish() {
ShadowUserManager userManager = Shadow.extract(
mContext.getSystemService(UserManager.class));
- ShadowAccountManager acctMgr = Shadow.extract(
+ ShadowAccountManager accountManager = Shadow.extract(
mContext.getSystemService(AccountManager.class));
- userManager.addProfile(new UserInfo(1, null, 0));
- acctMgr.addAccountForUser(1, mFragment.mAccount);
+ userManager.addUserProfile(new UserHandle(1));
+ accountManager.addAccountForUser(1, mFragment.mAccount);
mFragment.finishIfAccountMissing();
verify(mFragment, never()).finish();
@@ -194,13 +194,13 @@
public void onResume_accountPresentTwoProfiles_shouldNotFinish() {
ShadowUserManager userManager = Shadow.extract(
mContext.getSystemService(UserManager.class));
- ShadowAccountManager acctMgr = Shadow.extract(
+ ShadowAccountManager accountManager = Shadow.extract(
mContext.getSystemService(AccountManager.class));
- userManager.addProfile(new UserInfo(1, null, 0));
- userManager.addProfile(new UserInfo(2, null, 0));
- acctMgr.addAccountForUser(1, new Account("test@test.com", "com.test"));
- acctMgr.addAccountForUser(2, mFragment.mAccount);
+ userManager.addUserProfile(new UserHandle(1));
+ userManager.addUserProfile(new UserHandle(2));
+ accountManager.addAccountForUser(1, new Account("test@test.com", "com.test"));
+ accountManager.addAccountForUser(2, mFragment.mAccount);
mFragment.finishIfAccountMissing();
verify(mFragment, never()).finish();
diff --git a/tests/robotests/src/com/android/settings/accounts/AvatarViewMixinTest.java b/tests/robotests/src/com/android/settings/accounts/AvatarViewMixinTest.java
index e074440..f08306d 100644
--- a/tests/robotests/src/com/android/settings/accounts/AvatarViewMixinTest.java
+++ b/tests/robotests/src/com/android/settings/accounts/AvatarViewMixinTest.java
@@ -40,6 +40,7 @@
import android.widget.ImageView;
import com.android.settings.homepage.SettingsHomepageActivity;
+import com.android.settings.homepage.contextualcards.slices.BatteryFixSliceTest;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import org.junit.Before;
@@ -99,7 +100,11 @@
}
@Test
- @Config(qualifiers = "mcc999")
+ @Config(qualifiers = "mcc999",
+ shadows = {
+ BatteryFixSliceTest.ShadowBatteryStatsHelperLoader.class,
+ BatteryFixSliceTest.ShadowBatteryTipLoader.class
+ })
public void onStart_useMockAvatarViewMixin_shouldBeExecuted() {
final AvatarViewMixin mockAvatar = spy(new AvatarViewMixin(mActivity, mImageView));
@@ -141,8 +146,7 @@
@Test
public void callWithGetAccountAvatarMethod_useDummyData_shouldReturnAccountNameAndAvatar() {
- final ShadowContentResolver shadowContentResolver = Shadow.extract(
- mContext.getContentResolver());
+ final ContentResolver contentResolver = mContext.getContentResolver();
final Uri uri = new Uri.Builder().scheme(ContentResolver.SCHEME_CONTENT).authority(
DUMMY_AUTHORITY).build();
final ContentProvider mockContentProvider = mock(ContentProvider.class);
@@ -156,8 +160,7 @@
doReturn(bundle).when(mockContentProvider).call(anyString(), anyString(),
any(Bundle.class));
- final Bundle expectBundle = shadowContentResolver.call(uri, METHOD_GET_ACCOUNT_AVATAR,
- null /* arg */, null /* extras */);
+ contentResolver.call(uri, METHOD_GET_ACCOUNT_AVATAR, null /* arg */, null /* extras */);
final Object object = bundle.getParcelable("account_avatar");
assertThat(object instanceof Bitmap).isTrue();
diff --git a/tests/robotests/src/com/android/settings/applications/LayoutPreferenceTest.java b/tests/robotests/src/com/android/settings/applications/LayoutPreferenceTest.java
index 1d2bb3a..899d4cb 100644
--- a/tests/robotests/src/com/android/settings/applications/LayoutPreferenceTest.java
+++ b/tests/robotests/src/com/android/settings/applications/LayoutPreferenceTest.java
@@ -83,4 +83,11 @@
assertThat(mPreference.findViewById(R.id.button1).isEnabled()).isFalse();
assertThat(mPreference.findViewById(R.id.button2).isEnabled()).isTrue();
}
+
+ @Test
+ public void allowDividerBelow_shouldSaveCorrectDividerStatus() {
+ mPreference.setAllowDividerBelow(true);
+
+ assertThat(mPreference.isAllowDividerBelow()).isTrue();
+ }
}
diff --git a/tests/robotests/src/com/android/settings/applications/appinfo/AppMemoryPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/applications/appinfo/AppMemoryPreferenceControllerTest.java
index 733e22e..8fbc27c 100644
--- a/tests/robotests/src/com/android/settings/applications/appinfo/AppMemoryPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/applications/appinfo/AppMemoryPreferenceControllerTest.java
@@ -37,7 +37,6 @@
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.shadow.ShadowUserManager;
-import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -77,11 +76,6 @@
when(mFragment.getActivity()).thenReturn(mActivity);
}
- @After
- public void tearDown() {
- ShadowUserManager.getShadow().reset();
- }
-
@Test
@Config(qualifiers = "mcc999")
public void getAvailabilityStatus_developmentSettingsEnabled_shouldReturnAvailable() {
diff --git a/tests/robotests/src/com/android/settings/biometrics/fingerprint/FingerprintSuggestionActivityTest.java b/tests/robotests/src/com/android/settings/biometrics/fingerprint/FingerprintSuggestionActivityTest.java
index 393d86e..b4823c0 100644
--- a/tests/robotests/src/com/android/settings/biometrics/fingerprint/FingerprintSuggestionActivityTest.java
+++ b/tests/robotests/src/com/android/settings/biometrics/fingerprint/FingerprintSuggestionActivityTest.java
@@ -23,7 +23,6 @@
import android.app.Activity;
import android.app.KeyguardManager;
import android.content.Intent;
-import android.content.pm.UserInfo;
import android.view.View;
import android.widget.Button;
@@ -36,8 +35,6 @@
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;
import org.robolectric.android.controller.ActivityController;
@@ -49,20 +46,14 @@
@Config(shadows = {ShadowLockPatternUtils.class, ShadowUserManager.class})
public class FingerprintSuggestionActivityTest {
- @Mock
- private UserInfo mUserInfo;
-
private ActivityController<FingerprintSuggestionActivity> mController;
@Before
public void setUp() {
- MockitoAnnotations.initMocks(this);
FakeFeatureFactory.setupForTest();
final Intent intent = new Intent();
mController = Robolectric.buildActivity(FingerprintSuggestionActivity.class, intent);
-
- ShadowUserManager.getShadow().setUserInfo(0, mUserInfo);
}
@Test
diff --git a/tests/robotests/src/com/android/settings/biometrics/fingerprint/SetupFingerprintEnrollIntroductionTest.java b/tests/robotests/src/com/android/settings/biometrics/fingerprint/SetupFingerprintEnrollIntroductionTest.java
index aed1ea9..a06c48d 100644
--- a/tests/robotests/src/com/android/settings/biometrics/fingerprint/SetupFingerprintEnrollIntroductionTest.java
+++ b/tests/robotests/src/com/android/settings/biometrics/fingerprint/SetupFingerprintEnrollIntroductionTest.java
@@ -23,7 +23,6 @@
import android.app.KeyguardManager;
import android.content.Intent;
import android.content.pm.PackageManager;
-import android.content.pm.UserInfo;
import android.view.View;
import android.widget.Button;
@@ -43,8 +42,6 @@
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;
import org.robolectric.android.controller.ActivityController;
@@ -62,15 +59,10 @@
})
public class SetupFingerprintEnrollIntroductionTest {
- @Mock
- private UserInfo mUserInfo;
-
private ActivityController<SetupFingerprintEnrollIntroduction> mController;
@Before
public void setUp() {
- MockitoAnnotations.initMocks(this);
-
Shadows.shadowOf(application.getPackageManager())
.setSystemFeature(PackageManager.FEATURE_FINGERPRINT, true);
@@ -78,8 +70,6 @@
final Intent intent = new Intent();
mController = Robolectric.buildActivity(SetupFingerprintEnrollIntroduction.class, intent);
-
- ShadowUserManager.getShadow().setUserInfo(0, mUserInfo);
}
@After
diff --git a/tests/robotests/src/com/android/settings/bluetooth/AvailableMediaBluetoothDeviceUpdaterTest.java b/tests/robotests/src/com/android/settings/bluetooth/AvailableMediaBluetoothDeviceUpdaterTest.java
index 0b7853c..06ce13f 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/AvailableMediaBluetoothDeviceUpdaterTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/AvailableMediaBluetoothDeviceUpdaterTest.java
@@ -15,7 +15,7 @@
*/
package com.android.settings.bluetooth;
-import static org.mockito.Matchers.any;
+import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
@@ -64,7 +64,7 @@
private Context mContext;
private AvailableMediaBluetoothDeviceUpdater mBluetoothDeviceUpdater;
private Collection<CachedBluetoothDevice> mCachedDevices;
- private ShadowAudioManager mShadowAudioManager;
+ private AudioManager mAudioManager;
private BluetoothDevicePreference mPreference;
private ShadowBluetoothAdapter mShadowBluetoothAdapter;
private ShadowCachedBluetoothDeviceManager mShadowCachedBluetoothDeviceManager;
@@ -73,14 +73,13 @@
public void setUp() {
MockitoAnnotations.initMocks(this);
- mShadowAudioManager = ShadowAudioManager.getShadow();
+ mContext = RuntimeEnvironment.application;
+ mAudioManager = mContext.getSystemService(AudioManager.class);
mShadowBluetoothAdapter = Shadow.extract(BluetoothAdapter.getDefaultAdapter());
mShadowBluetoothAdapter.setEnabled(true);
- mContext = RuntimeEnvironment.application;
mShadowCachedBluetoothDeviceManager = Shadow.extract(
Utils.getLocalBtManager(mContext).getCachedDeviceManager());
- mCachedDevices =
- new ArrayList<CachedBluetoothDevice>(new ArrayList<CachedBluetoothDevice>());
+ mCachedDevices = new ArrayList<>();
mShadowCachedBluetoothDeviceManager.setCachedDevicesCopy(mCachedDevices);
doReturn(mContext).when(mDashboardFragment).getContext();
@@ -96,7 +95,7 @@
@Test
public void onAudioModeChanged_hfpDeviceConnected_inCall_addPreference() {
- mShadowAudioManager.setMode(AudioManager.MODE_IN_CALL);
+ mAudioManager.setMode(AudioManager.MODE_IN_CALL);
when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true);
@@ -109,7 +108,7 @@
@Test
public void onAudioModeChanged_hfpDeviceConnected_notInCall_removePreference() {
- mShadowAudioManager.setMode(AudioManager.MODE_NORMAL);
+ mAudioManager.setMode(AudioManager.MODE_NORMAL);
when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true);
@@ -122,7 +121,7 @@
@Test
public void onAudioModeChanged_a2dpDeviceConnected_inCall_removePreference() {
- mShadowAudioManager.setMode(AudioManager.MODE_IN_CALL);
+ mAudioManager.setMode(AudioManager.MODE_IN_CALL);
when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true);
@@ -135,7 +134,7 @@
@Test
public void onAudioModeChanged_a2dpDeviceConnected_notInCall_addPreference() {
- mShadowAudioManager.setMode(AudioManager.MODE_NORMAL);
+ mAudioManager.setMode(AudioManager.MODE_NORMAL);
when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true);
@@ -148,7 +147,7 @@
@Test
public void onProfileConnectionStateChanged_a2dpDeviceConnected_notInCall_addPreference() {
- mShadowAudioManager.setMode(AudioManager.MODE_NORMAL);
+ mAudioManager.setMode(AudioManager.MODE_NORMAL);
when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true);
@@ -161,7 +160,7 @@
@Test
public void onProfileConnectionStateChanged_a2dpDeviceConnected_inCall_removePreference() {
- mShadowAudioManager.setMode(AudioManager.MODE_IN_CALL);
+ mAudioManager.setMode(AudioManager.MODE_IN_CALL);
when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true);
@@ -174,7 +173,7 @@
@Test
public void onProfileConnectionStateChanged_hfpDeviceConnected_notInCall_removePreference() {
- mShadowAudioManager.setMode(AudioManager.MODE_NORMAL);
+ mAudioManager.setMode(AudioManager.MODE_NORMAL);
when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true);
@@ -187,7 +186,7 @@
@Test
public void onProfileConnectionStateChanged_hfpDeviceConnected_inCall_addPreference() {
- mShadowAudioManager.setMode(AudioManager.MODE_IN_CALL);
+ mAudioManager.setMode(AudioManager.MODE_IN_CALL);
when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true);
@@ -201,7 +200,7 @@
@Test
public void onProfileConnectionStateChanged_hearingAidDeviceConnected_notInCall_addPreference()
{
- mShadowAudioManager.setMode(AudioManager.MODE_NORMAL);
+ mAudioManager.setMode(AudioManager.MODE_NORMAL);
when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isConnectedHearingAidDevice()).thenReturn(true);
@@ -214,7 +213,7 @@
@Test
public void onProfileConnectionStateChanged_hearingAidDeviceConnected_inCall_addPreference() {
- mShadowAudioManager.setMode(AudioManager.MODE_IN_CALL);
+ mAudioManager.setMode(AudioManager.MODE_IN_CALL);
when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isConnectedHearingAidDevice()).thenReturn(true);
diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDeviceRenamePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDeviceRenamePreferenceControllerTest.java
index 9de46dd..34b2d09 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDeviceRenamePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDeviceRenamePreferenceControllerTest.java
@@ -18,8 +18,8 @@
import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyString;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
@@ -72,8 +72,8 @@
mContext = spy(RuntimeEnvironment.application);
mPreference = new Preference(mContext);
mPreference.setKey(PREF_KEY);
- mBluetoothAdapter = ShadowBluetoothAdapter.getDefaultAdapter();
- mShadowBluetoothAdapter = Shadow.extract(BluetoothAdapter.getDefaultAdapter());
+ mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
+ mShadowBluetoothAdapter = Shadow.extract(mBluetoothAdapter);
mController = spy(new BluetoothDeviceRenamePreferenceController(mContext, PREF_KEY));
mController.setFragment(mFragment);
diff --git a/tests/robotests/src/com/android/settings/bluetooth/ConnectedBluetoothDeviceUpdaterTest.java b/tests/robotests/src/com/android/settings/bluetooth/ConnectedBluetoothDeviceUpdaterTest.java
index f4364b7..cbded4d 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/ConnectedBluetoothDeviceUpdaterTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/ConnectedBluetoothDeviceUpdaterTest.java
@@ -66,7 +66,7 @@
private Context mContext;
private ConnectedBluetoothDeviceUpdater mBluetoothDeviceUpdater;
private Collection<CachedBluetoothDevice> mCachedDevices;
- private ShadowAudioManager mShadowAudioManager;
+ private AudioManager mAudioManager;
private ShadowBluetoothAdapter mShadowBluetoothAdapter;
private ShadowCachedBluetoothDeviceManager mShadowCachedBluetoothDeviceManager;
@@ -74,15 +74,14 @@
public void setUp() {
MockitoAnnotations.initMocks(this);
- mShadowAudioManager = ShadowAudioManager.getShadow();
+ mContext = RuntimeEnvironment.application;
+ mAudioManager = mContext.getSystemService(AudioManager.class);
mShadowBluetoothAdapter = Shadow.extract(BluetoothAdapter.getDefaultAdapter());
mShadowBluetoothAdapter.setEnabled(true);
- mContext = RuntimeEnvironment.application;
mShadowCachedBluetoothDeviceManager = Shadow.extract(
Utils.getLocalBtManager(mContext).getCachedDeviceManager());
doReturn(mContext).when(mDashboardFragment).getContext();
- mCachedDevices =
- new ArrayList<CachedBluetoothDevice>(new ArrayList<CachedBluetoothDevice>());
+ mCachedDevices = new ArrayList<>();
when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice);
mShadowCachedBluetoothDeviceManager.setCachedDevicesCopy(mCachedDevices);
@@ -95,7 +94,7 @@
@Test
public void onAudioModeChanged_hfpDeviceConnected_notInCall_addPreference() {
- mShadowAudioManager.setMode(AudioManager.MODE_NORMAL);
+ mAudioManager.setMode(AudioManager.MODE_NORMAL);
when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true);
@@ -108,7 +107,7 @@
@Test
public void onAudioModeChanged_hfpDeviceConnected_inCall_removePreference() {
- mShadowAudioManager.setMode(AudioManager.MODE_IN_CALL);
+ mAudioManager.setMode(AudioManager.MODE_IN_CALL);
when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true);
@@ -121,7 +120,7 @@
@Test
public void onAudioModeChanged_a2dpDeviceConnected_notInCall_removePreference() {
- mShadowAudioManager.setMode(AudioManager.MODE_NORMAL);
+ mAudioManager.setMode(AudioManager.MODE_NORMAL);
when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true);
@@ -134,7 +133,7 @@
@Test
public void onAudioModeChanged_a2dpDeviceConnected_inCall_addPreference() {
- mShadowAudioManager.setMode(AudioManager.MODE_IN_CALL);
+ mAudioManager.setMode(AudioManager.MODE_IN_CALL);
when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true);
@@ -147,7 +146,7 @@
@Test
public void onProfileConnectionStateChanged_a2dpDeviceConnected_inCall_addPreference() {
- mShadowAudioManager.setMode(AudioManager.MODE_IN_CALL);
+ mAudioManager.setMode(AudioManager.MODE_IN_CALL);
when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true);
@@ -160,7 +159,7 @@
@Test
public void onProfileConnectionStateChanged_a2dpDeviceConnected_notInCall_removePreference() {
- mShadowAudioManager.setMode(AudioManager.MODE_NORMAL);
+ mAudioManager.setMode(AudioManager.MODE_NORMAL);
when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true);
@@ -173,7 +172,7 @@
@Test
public void onProfileConnectionStateChanged_hfpDeviceConnected_inCall_removePreference() {
- mShadowAudioManager.setMode(AudioManager.MODE_IN_CALL);
+ mAudioManager.setMode(AudioManager.MODE_IN_CALL);
when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true);
@@ -186,7 +185,7 @@
@Test
public void onProfileConnectionStateChanged_hfpDeviceConnected_notInCall_addPreference() {
- mShadowAudioManager.setMode(AudioManager.MODE_NORMAL);
+ mAudioManager.setMode(AudioManager.MODE_NORMAL);
when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true);
@@ -200,7 +199,7 @@
@Test
public void onProfileConnectionStateChanged_hearingAidDeviceConnected_inCall_removePreference()
{
- mShadowAudioManager.setMode(AudioManager.MODE_IN_CALL);
+ mAudioManager.setMode(AudioManager.MODE_IN_CALL);
when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isConnectedHearingAidDevice()).thenReturn(true);
@@ -214,7 +213,7 @@
@Test
public void onProfileConnectionStateChanged_hearingAidDeviceConnected_notInCall_removePreference
() {
- mShadowAudioManager.setMode(AudioManager.MODE_NORMAL);
+ mAudioManager.setMode(AudioManager.MODE_NORMAL);
when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isConnectedHearingAidDevice()).thenReturn(true);
diff --git a/tests/robotests/src/com/android/settings/connecteddevice/AdvancedConnectedDeviceControllerTest.java b/tests/robotests/src/com/android/settings/connecteddevice/AdvancedConnectedDeviceControllerTest.java
index f0be229..7190874 100644
--- a/tests/robotests/src/com/android/settings/connecteddevice/AdvancedConnectedDeviceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/connecteddevice/AdvancedConnectedDeviceControllerTest.java
@@ -23,6 +23,7 @@
import android.content.ContentResolver;
import android.content.Context;
+import android.nfc.NfcAdapter;
import android.provider.Settings;
import com.android.settings.R;
@@ -60,7 +61,7 @@
mContentResolver = mContext.getContentResolver();
mNfcController = new NfcPreferenceController(mContext,
NfcPreferenceController.KEY_TOGGLE_NFC);
- mShadowNfcAdapter = Shadows.shadowOf(ShadowNfcAdapter.getNfcAdapter(mContext));
+ mShadowNfcAdapter = Shadows.shadowOf(NfcAdapter.getNfcAdapter(mContext));
}
@Test
@@ -68,8 +69,7 @@
AdvancedConnectedDeviceController controller =
new AdvancedConnectedDeviceController(mContext, KEY);
- assertThat(controller.getAvailabilityStatus()).isEqualTo(
- AVAILABLE);
+ assertThat(controller.getAvailabilityStatus()).isEqualTo(AVAILABLE);
}
@Test
diff --git a/tests/robotests/src/com/android/settings/connecteddevice/AvailableMediaDeviceGroupControllerTest.java b/tests/robotests/src/com/android/settings/connecteddevice/AvailableMediaDeviceGroupControllerTest.java
index 7d99550..dc2459b 100644
--- a/tests/robotests/src/com/android/settings/connecteddevice/AvailableMediaDeviceGroupControllerTest.java
+++ b/tests/robotests/src/com/android/settings/connecteddevice/AvailableMediaDeviceGroupControllerTest.java
@@ -56,10 +56,7 @@
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(shadows = {
- ShadowAudioManager.class,
- ShadowBluetoothUtils.class}
-)
+@Config(shadows = {ShadowAudioManager.class, ShadowBluetoothUtils.class})
public class AvailableMediaDeviceGroupControllerTest {
private static final String PREFERENCE_KEY_1 = "pref_key_1";
@@ -84,7 +81,7 @@
private Preference mPreference;
private AvailableMediaDeviceGroupController mAvailableMediaDeviceGroupController;
private LocalBluetoothManager mLocalBluetoothManager;
- private ShadowAudioManager mShadowAudioManager;
+ private AudioManager mAudioManager;
@Before
public void setUp() {
@@ -101,7 +98,7 @@
ShadowBluetoothUtils.sLocalBluetoothManager = mLocalManager;
mLocalBluetoothManager = ShadowBluetoothUtils.getLocalBtManager(mContext);
- mShadowAudioManager = ShadowAudioManager.getShadow();
+ mAudioManager = mContext.getSystemService(AudioManager.class);
doReturn(mEventManager).when(mLocalBluetoothManager).getEventManager();
mAvailableMediaDeviceGroupController = new AvailableMediaDeviceGroupController(mContext);
@@ -184,7 +181,7 @@
@Test
public void setTitle_inCallState_showCallStateTitle() {
- mShadowAudioManager.setMode(AudioManager.MODE_IN_CALL);
+ mAudioManager.setMode(AudioManager.MODE_IN_CALL);
mAvailableMediaDeviceGroupController.onAudioModeChanged();
assertThat(mPreferenceGroup.getTitle()).isEqualTo(
@@ -193,7 +190,7 @@
@Test
public void setTitle_notInCallState_showMediaStateTitle() {
- mShadowAudioManager.setMode(AudioManager.MODE_NORMAL);
+ mAudioManager.setMode(AudioManager.MODE_NORMAL);
mAvailableMediaDeviceGroupController.onAudioModeChanged();
assertThat(mPreferenceGroup.getTitle()).isEqualTo(
diff --git a/tests/robotests/src/com/android/settings/dashboard/DashboardFeatureProviderImplTest.java b/tests/robotests/src/com/android/settings/dashboard/DashboardFeatureProviderImplTest.java
index d083a38..3ada961 100644
--- a/tests/robotests/src/com/android/settings/dashboard/DashboardFeatureProviderImplTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/DashboardFeatureProviderImplTest.java
@@ -365,6 +365,8 @@
@Test
public void openTileIntent_profileSelectionDialog_shouldShow() {
+ ShadowUserManager.getShadow().addUser(10, "Someone", 0);
+
final Tile tile = new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
final ArrayList<UserHandle> handles = new ArrayList<>();
handles.add(new UserHandle(0));
@@ -379,6 +381,8 @@
@Test
public void openTileIntent_profileSelectionDialog_explicitMetadataShouldShow() {
+ ShadowUserManager.getShadow().addUser(10, "Someone", 0);
+
mActivityInfo.metaData.putString(META_DATA_KEY_PROFILE, PROFILE_ALL);
final Tile tile = new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
final ArrayList<UserHandle> handles = new ArrayList<>();
@@ -394,6 +398,8 @@
@Test
public void openTileIntent_profileSelectionDialog_shouldNotShow() {
+ ShadowUserManager.getShadow().addUser(10, "Someone", 0);
+
mActivityInfo.metaData.putString(META_DATA_KEY_PROFILE, PROFILE_PRIMARY);
final Tile tile = new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
final ArrayList<UserHandle> handles = new ArrayList<>();
diff --git a/tests/robotests/src/com/android/settings/datausage/DataUsageSummaryTest.java b/tests/robotests/src/com/android/settings/datausage/DataUsageSummaryTest.java
index 9fee9f0..d52793e 100644
--- a/tests/robotests/src/com/android/settings/datausage/DataUsageSummaryTest.java
+++ b/tests/robotests/src/com/android/settings/datausage/DataUsageSummaryTest.java
@@ -95,11 +95,6 @@
.createSummaryProvider(mActivity, mSummaryLoader);
}
- @After
- public void tearDown() {
- ShadowUserManager.getShadow().reset();
- }
-
@Test
public void formatUsage_shouldLookLikeFormatFileSize() {
SettingsShadowResources.overrideResource(com.android.internal.R.string.fileSizeSuffix,
diff --git a/tests/robotests/src/com/android/settings/development/CbrsDataSwitchPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/CbrsDataSwitchPreferenceControllerTest.java
index 0f22390..af929fd 100644
--- a/tests/robotests/src/com/android/settings/development/CbrsDataSwitchPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/development/CbrsDataSwitchPreferenceControllerTest.java
@@ -16,7 +16,6 @@
package com.android.settings.development;
-import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static com.google.common.truth.Truth.assertThat;
@@ -34,7 +33,6 @@
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
-import org.robolectric.Shadows;
@RunWith(SettingsRobolectricTestRunner.class)
public final class CbrsDataSwitchPreferenceControllerTest {
diff --git a/tests/robotests/src/com/android/settings/development/DevelopmentSettingsDashboardFragmentTest.java b/tests/robotests/src/com/android/settings/development/DevelopmentSettingsDashboardFragmentTest.java
index a3abb07..d2c9b65 100644
--- a/tests/robotests/src/com/android/settings/development/DevelopmentSettingsDashboardFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/development/DevelopmentSettingsDashboardFragmentTest.java
@@ -75,7 +75,6 @@
@After
public void tearDown() {
ShadowEnableDevelopmentSettingWarningDialog.reset();
- mShadowUserManager.reset();
}
@Test
diff --git a/tests/robotests/src/com/android/settings/development/DevelopmentSwitchBarControllerTest.java b/tests/robotests/src/com/android/settings/development/DevelopmentSwitchBarControllerTest.java
index 688db76..da0dcaf 100644
--- a/tests/robotests/src/com/android/settings/development/DevelopmentSwitchBarControllerTest.java
+++ b/tests/robotests/src/com/android/settings/development/DevelopmentSwitchBarControllerTest.java
@@ -70,7 +70,6 @@
@After
public void tearDown() {
ShadowUtils.reset();
- ShadowUserManager.getShadow().reset();
}
@Test
diff --git a/tests/robotests/src/com/android/settings/development/qstile/DevelopmentTilePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/qstile/DevelopmentTilePreferenceControllerTest.java
index a6ff088..c3ef73b 100644
--- a/tests/robotests/src/com/android/settings/development/qstile/DevelopmentTilePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/development/qstile/DevelopmentTilePreferenceControllerTest.java
@@ -41,6 +41,7 @@
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
@@ -82,6 +83,7 @@
}
@Test
+ @Ignore("b/119829673")
public void display_hasTileService_shouldDisplay() {
final Intent tileProbe = new Intent(TileService.ACTION_QS_TILE)
.setPackage(mContext.getPackageName());
diff --git a/tests/robotests/src/com/android/settings/enterprise/ActionDisabledByAdminDialogHelperTest.java b/tests/robotests/src/com/android/settings/enterprise/ActionDisabledByAdminDialogHelperTest.java
index 0a661b4..8ab3b63 100644
--- a/tests/robotests/src/com/android/settings/enterprise/ActionDisabledByAdminDialogHelperTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/ActionDisabledByAdminDialogHelperTest.java
@@ -155,6 +155,7 @@
dpmShadow.setShortSupportMessageForUser(component, 123, "some message");
dpmShadow.setIsAdminActiveAsUser(true);
userManagerShadow.addProfile(new UserInfo(123, null, 0));
+ userManagerShadow.addUserProfile(new UserHandle(123));
ShadowProcess.setMyUid(Process.SYSTEM_UID);
mHelper.setAdminSupportDetails(mActivity, view, admin);
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryBroadcastReceiverTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryBroadcastReceiverTest.java
index fb34640..02a6761 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryBroadcastReceiverTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryBroadcastReceiverTest.java
@@ -33,6 +33,7 @@
import android.os.PowerManager;
import com.android.settings.Utils;
+import com.android.settings.homepage.contextualcards.slices.BatteryFixSliceTest;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import org.junit.Before;
@@ -42,6 +43,11 @@
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+import org.robolectric.annotation.Implementation;
+import org.robolectric.annotation.Implements;
+import org.robolectric.annotation.Resetter;
+
@RunWith(SettingsRobolectricTestRunner.class)
public class BatteryBroadcastReceiverTest {
@@ -74,6 +80,10 @@
}
@Test
+ @Config(shadows = {
+ BatteryFixSliceTest.ShadowBatteryStatsHelperLoader.class,
+ BatteryFixSliceTest.ShadowBatteryTipLoader.class
+ })
public void testOnReceive_batteryLevelChanged_dataUpdated() {
mBatteryBroadcastReceiver.onReceive(mContext, mChargingIntent);
@@ -85,6 +95,10 @@
}
@Test
+ @Config(shadows = {
+ BatteryFixSliceTest.ShadowBatteryStatsHelperLoader.class,
+ BatteryFixSliceTest.ShadowBatteryTipLoader.class
+ })
public void testOnReceive_powerSaveModeChanged_listenerInvoked() {
mBatteryBroadcastReceiver.onReceive(mContext,
new Intent(PowerManager.ACTION_POWER_SAVE_MODE_CHANGED));
@@ -93,6 +107,10 @@
}
@Test
+ @Config(shadows = {
+ BatteryFixSliceTest.ShadowBatteryStatsHelperLoader.class,
+ BatteryFixSliceTest.ShadowBatteryTipLoader.class
+ })
public void testOnReceive_batteryDataNotChanged_listenerNotInvoked() {
final String batteryLevel = Utils.getBatteryPercentage(mChargingIntent);
final String batteryStatus =
@@ -108,6 +126,10 @@
}
@Test
+ @Config(shadows = {
+ BatteryFixSliceTest.ShadowBatteryStatsHelperLoader.class,
+ BatteryFixSliceTest.ShadowBatteryTipLoader.class
+ })
public void testRegister_updateBatteryStatus() {
doReturn(mChargingIntent).when(mContext).registerReceiver(any(), any());
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/AnomalyCleanupJobServiceTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/AnomalyCleanupJobServiceTest.java
index f600d41..7bcfd36 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/AnomalyCleanupJobServiceTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/AnomalyCleanupJobServiceTest.java
@@ -19,8 +19,8 @@
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertEquals;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyBoolean;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
@@ -45,9 +45,7 @@
import org.mockito.MockitoAnnotations;
import org.robolectric.Robolectric;
import org.robolectric.RuntimeEnvironment;
-import org.robolectric.Shadows;
import org.robolectric.annotation.Config;
-import org.robolectric.shadows.ShadowJobScheduler;
import java.util.List;
import java.util.concurrent.TimeUnit;
@@ -85,9 +83,8 @@
public void scheduleCleanUp() {
AnomalyCleanupJobService.scheduleCleanUp(mContext);
- ShadowJobScheduler shadowJobScheduler =
- Shadows.shadowOf(mContext.getSystemService(JobScheduler.class));
- List<JobInfo> pendingJobs = shadowJobScheduler.getAllPendingJobs();
+ JobScheduler jobScheduler = mContext.getSystemService(JobScheduler.class);
+ List<JobInfo> pendingJobs = jobScheduler.getAllPendingJobs();
assertEquals(1, pendingJobs.size());
JobInfo pendingJob = pendingJobs.get(0);
assertThat(pendingJob.getId()).isEqualTo(R.integer.job_anomaly_clean_up);
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/AnomalyConfigJobServiceTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/AnomalyConfigJobServiceTest.java
index 8e7590b..13be366 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/AnomalyConfigJobServiceTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/AnomalyConfigJobServiceTest.java
@@ -45,8 +45,6 @@
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
-import org.robolectric.Shadows;
-import org.robolectric.shadows.ShadowJobScheduler;
import java.util.List;
import java.util.concurrent.TimeUnit;
@@ -82,9 +80,8 @@
public void testScheduleConfigUpdate() {
AnomalyConfigJobService.scheduleConfigUpdate(mContext);
- ShadowJobScheduler shadowJobScheduler =
- Shadows.shadowOf(mContext.getSystemService(JobScheduler.class));
- List<JobInfo> pendingJobs = shadowJobScheduler.getAllPendingJobs();
+ JobScheduler jobScheduler = mContext.getSystemService(JobScheduler.class);
+ List<JobInfo> pendingJobs = jobScheduler.getAllPendingJobs();
assertEquals(1, pendingJobs.size());
JobInfo pendingJob = pendingJobs.get(0);
assertThat(pendingJob.getId()).isEqualTo(R.integer.job_anomaly_config_update);
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/AnomalyDetectionJobServiceTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/AnomalyDetectionJobServiceTest.java
index 11b22dd..5f32c0b 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/AnomalyDetectionJobServiceTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/AnomalyDetectionJobServiceTest.java
@@ -22,12 +22,12 @@
import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyBoolean;
-import static org.mockito.Matchers.anyInt;
-import static org.mockito.Matchers.anyLong;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Matchers.eq;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyBoolean;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.anyLong;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doThrow;
@@ -67,10 +67,8 @@
import org.mockito.MockitoAnnotations;
import org.robolectric.Robolectric;
import org.robolectric.RuntimeEnvironment;
-import org.robolectric.Shadows;
import org.robolectric.android.controller.ServiceController;
import org.robolectric.annotation.Config;
-import org.robolectric.shadows.ShadowJobScheduler;
import java.util.ArrayList;
import java.util.List;
@@ -129,9 +127,8 @@
public void scheduleCleanUp() {
AnomalyDetectionJobService.scheduleAnomalyDetection(application, new Intent());
- ShadowJobScheduler shadowJobScheduler =
- Shadows.shadowOf(application.getSystemService(JobScheduler.class));
- List<JobInfo> pendingJobs = shadowJobScheduler.getAllPendingJobs();
+ JobScheduler jobScheduler = application.getSystemService(JobScheduler.class);
+ List<JobInfo> pendingJobs = jobScheduler.getAllPendingJobs();
assertThat(pendingJobs).hasSize(1);
JobInfo pendingJob = pendingJobs.get(0);
diff --git a/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/BatteryFixSliceTest.java b/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/BatteryFixSliceTest.java
new file mode 100644
index 0000000..1df5277
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/BatteryFixSliceTest.java
@@ -0,0 +1,130 @@
+/*
+ * 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.homepage.contextualcards.slices;
+
+import static android.content.Context.MODE_PRIVATE;
+
+import static com.android.settings.homepage.contextualcards.slices.BatteryFixSlice.KEY_CURRENT_TIPS_TYPE;
+import static com.android.settings.homepage.contextualcards.slices.BatteryFixSlice.PREFS;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.content.Context;
+import android.content.SharedPreferences;
+
+import androidx.slice.SliceProvider;
+import androidx.slice.widget.SliceLiveData;
+
+import com.android.internal.os.BatteryStatsHelper;
+import com.android.settings.fuelgauge.BatteryStatsHelperLoader;
+import com.android.settings.fuelgauge.batterytip.BatteryTipLoader;
+import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
+import com.android.settings.fuelgauge.batterytip.tips.EarlyWarningTip;
+import com.android.settings.fuelgauge.batterytip.tips.LowBatteryTip;
+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.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+import org.robolectric.annotation.Implementation;
+import org.robolectric.annotation.Implements;
+import org.robolectric.annotation.Resetter;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+public class BatteryFixSliceTest {
+
+ private Context mContext;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = RuntimeEnvironment.application;
+
+ // Set-up specs for SliceMetadata.
+ SliceProvider.setSpecs(SliceLiveData.SUPPORTED_SPECS);
+ }
+
+ @After
+ public void tearDown() {
+ ShadowBatteryTipLoader.reset();
+ }
+
+ @Test
+ public void readBatteryTipfromPref_readCorrectValue() {
+ int target = 111;
+ final SharedPreferences.Editor editor = mContext.getSharedPreferences(PREFS,
+ MODE_PRIVATE).edit();
+ editor.putInt(KEY_CURRENT_TIPS_TYPE, target);
+
+ editor.commit();
+
+ assertThat(BatteryFixSlice.readBatteryTipAvailabilityCache(mContext)).isEqualTo(target);
+ }
+
+ @Test
+ @Config(shadows = {
+ ShadowBatteryStatsHelperLoader.class,
+ ShadowBatteryTipLoader.class
+ })
+ public void updateBatteryTipAvailabilityCache_writeCorrectValue() {
+ final List<BatteryTip> tips = new ArrayList<>();
+ tips.add(new LowBatteryTip(BatteryTip.StateType.INVISIBLE, false, ""));
+ tips.add(new EarlyWarningTip(BatteryTip.StateType.HANDLED, false));
+ ShadowBatteryTipLoader.setBatteryTips(tips);
+
+ BatteryFixSlice.updateBatteryTipAvailabilityCache(mContext);
+
+ assertThat(BatteryFixSlice.readBatteryTipAvailabilityCache(mContext)).isEqualTo(
+ BatteryTip.TipType.BATTERY_SAVER);
+ }
+
+ @Implements(BatteryStatsHelperLoader.class)
+ public static class ShadowBatteryStatsHelperLoader {
+
+ @Implementation
+ protected BatteryStatsHelper loadInBackground() {
+ return null;
+ }
+ }
+
+ @Implements(BatteryTipLoader.class)
+ public static class ShadowBatteryTipLoader {
+
+ private static List<BatteryTip> sBatteryTips = new ArrayList<>();
+
+ @Resetter
+ public static void reset() {
+ sBatteryTips = new ArrayList<>();
+ }
+
+ @Implementation
+ protected List<BatteryTip> loadInBackground() {
+ return sBatteryTips;
+ }
+
+ public static void setBatteryTips(List<BatteryTip> tips) {
+ sBatteryTips = tips;
+ }
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/SliceContextualCardControllerTest.java b/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/SliceContextualCardControllerTest.java
new file mode 100644
index 0000000..362e1f5
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/SliceContextualCardControllerTest.java
@@ -0,0 +1,96 @@
+/*
+ * 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.homepage.contextualcards.slices;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.content.ContentResolver;
+import android.content.ContentValues;
+import android.content.Context;
+import android.database.Cursor;
+import android.net.Uri;
+
+import com.android.settings.homepage.contextualcards.CardContentProvider;
+import com.android.settings.homepage.contextualcards.CardDatabaseHelper;
+import com.android.settings.homepage.contextualcards.ContextualCard;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.Robolectric;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.shadows.ShadowContentResolver;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+public class SliceContextualCardControllerTest {
+
+ private static final String TEST_SLICE_URI = "content://test/test";
+ private static final String TEST_CARD_NAME = "test_card_name";
+
+ private Context mContext;
+ private CardContentProvider mProvider;
+ private ContentResolver mResolver;
+ private SliceContextualCardController mController;
+
+ @Before
+ public void setUp() {
+ mContext = RuntimeEnvironment.application;
+ mProvider = Robolectric.setupContentProvider(CardContentProvider.class);
+ ShadowContentResolver.registerProviderInternal(CardContentProvider.CARD_AUTHORITY,
+ mProvider);
+ mResolver = mContext.getContentResolver();
+ mController = new SliceContextualCardController(mContext);
+ }
+
+ @Test
+ public void onDismissed_cardShouldBeMarkedAsDismissed() {
+ final Uri providerUri = CardContentProvider.URI;
+ final ContextualCard card = new ContextualCard.Builder()
+ .setName(TEST_CARD_NAME)
+ .setCardType(ContextualCard.CardType.SLICE)
+ .setSliceUri(Uri.parse(TEST_SLICE_URI))
+ .build();
+ mResolver.insert(providerUri, generateOneRow());
+
+ mController.onDismissed(card);
+
+ final String[] columns = {CardDatabaseHelper.CardColumns.CARD_DISMISSED};
+ final String selection = CardDatabaseHelper.CardColumns.NAME + "=?";
+ final String[] selectionArgs = {TEST_CARD_NAME};
+ final Cursor cr = mResolver.query(providerUri, columns, selection, selectionArgs, null);
+ cr.moveToFirst();
+ final int qryDismissed = cr.getInt(0);
+ cr.close();
+
+ assertThat(qryDismissed).isEqualTo(1);
+ }
+
+ private ContentValues generateOneRow() {
+ final ContentValues values = new ContentValues();
+ values.put(CardDatabaseHelper.CardColumns.NAME, TEST_CARD_NAME);
+ values.put(CardDatabaseHelper.CardColumns.TYPE, 1);
+ values.put(CardDatabaseHelper.CardColumns.SCORE, 0.9);
+ values.put(CardDatabaseHelper.CardColumns.SLICE_URI, TEST_SLICE_URI);
+ values.put(CardDatabaseHelper.CardColumns.CATEGORY, 2);
+ values.put(CardDatabaseHelper.CardColumns.PACKAGE_NAME, "com.android.settings");
+ values.put(CardDatabaseHelper.CardColumns.APP_VERSION, 10001);
+ values.put(CardDatabaseHelper.CardColumns.CARD_DISMISSED, 0);
+
+ return values;
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/network/telephony/Enhanced4gLtePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/telephony/Enhanced4gLtePreferenceControllerTest.java
index dee4c5e..1d80da7 100644
--- a/tests/robotests/src/com/android/settings/network/telephony/Enhanced4gLtePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/network/telephony/Enhanced4gLtePreferenceControllerTest.java
@@ -79,8 +79,8 @@
mPreference = new RestrictedSwitchPreference(mContext);
mController = new Enhanced4gLtePreferenceController(mContext, "roaming");
- mController.mImsManager = mImsManager;
mController.init(SUB_ID);
+ mController.mImsManager = mImsManager;
mPreference.setKey(mController.getPreferenceKey());
}
diff --git a/tests/robotests/src/com/android/settings/notification/RedactionInterstitialTest.java b/tests/robotests/src/com/android/settings/notification/RedactionInterstitialTest.java
index b62495c..2f273ae 100644
--- a/tests/robotests/src/com/android/settings/notification/RedactionInterstitialTest.java
+++ b/tests/robotests/src/com/android/settings/notification/RedactionInterstitialTest.java
@@ -48,7 +48,6 @@
@After
public void tearDown() {
- ShadowUserManager.getShadow().reset();
ShadowRestrictedLockUtilsInternal.reset();
}
diff --git a/tests/robotests/src/com/android/settings/security/EncryptionStatusPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/security/EncryptionStatusPreferenceControllerTest.java
index 8221b15..c7fdeae 100644
--- a/tests/robotests/src/com/android/settings/security/EncryptionStatusPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/security/EncryptionStatusPreferenceControllerTest.java
@@ -57,11 +57,6 @@
mPreference = new Preference(mContext);
}
- @After
- public void tearDown() {
- mShadowUserManager.reset();
- }
-
@Test
public void isAvailable_admin_true() {
mShadowUserManager.setIsAdminUser(true);
diff --git a/tests/robotests/src/com/android/settings/security/RestrictedEncryptionPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/security/RestrictedEncryptionPreferenceControllerTest.java
index 6bd5e1f..8c7eaa5 100644
--- a/tests/robotests/src/com/android/settings/security/RestrictedEncryptionPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/security/RestrictedEncryptionPreferenceControllerTest.java
@@ -63,11 +63,6 @@
mUserManager = ShadowUserManager.getShadow();
}
- @After
- public void tearDown() {
- mUserManager.reset();
- }
-
@Test
public void isAvailable_noRestriction_shouldReturnTrue() {
assertThat(mCredentialStoragePreferenceController.isAvailable()).isTrue();
diff --git a/tests/robotests/src/com/android/settings/slices/SlicesDatabaseAccessorTest.java b/tests/robotests/src/com/android/settings/slices/SlicesDatabaseAccessorTest.java
index bebf797..f628c87 100644
--- a/tests/robotests/src/com/android/settings/slices/SlicesDatabaseAccessorTest.java
+++ b/tests/robotests/src/com/android/settings/slices/SlicesDatabaseAccessorTest.java
@@ -90,7 +90,6 @@
@After
public void cleanUp() {
- ShadowUserManager.getShadow().reset();
DatabaseTestUtils.clearDb(mContext);
}
diff --git a/tests/robotests/src/com/android/settings/sound/AudioOutputSwitchPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/sound/AudioOutputSwitchPreferenceControllerTest.java
index 2ed1907..3ce2105 100644
--- a/tests/robotests/src/com/android/settings/sound/AudioOutputSwitchPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/sound/AudioOutputSwitchPreferenceControllerTest.java
@@ -38,6 +38,7 @@
import android.content.Context;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
+import android.media.AudioManager;
import android.util.FeatureFlagUtils;
import androidx.preference.ListPreference;
@@ -107,8 +108,8 @@
private Context mContext;
private PreferenceScreen mScreen;
private ListPreference mPreference;
+ private AudioManager mAudioManager;
private ShadowAudioManager mShadowAudioManager;
- private ShadowMediaRouter mShadowMediaRouter;
private BluetoothManager mBluetoothManager;
private BluetoothAdapter mBluetoothAdapter;
private BluetoothDevice mBluetoothDevice;
@@ -126,8 +127,8 @@
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
+ mAudioManager = mContext.getSystemService(AudioManager.class);
mShadowAudioManager = ShadowAudioManager.getShadow();
- mShadowMediaRouter = ShadowMediaRouter.getShadow();
ShadowBluetoothUtils.sLocalBluetoothManager = mLocalManager;
mLocalBluetoothManager = ShadowBluetoothUtils.getLocalBtManager(mContext);
@@ -168,7 +169,6 @@
@After
public void tearDown() {
- mShadowAudioManager.reset();
ShadowBluetoothUtils.reset();
}
diff --git a/tests/robotests/src/com/android/settings/sound/HandsFreeProfileOutputPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/sound/HandsFreeProfileOutputPreferenceControllerTest.java
index e3014b7..5745efd 100644
--- a/tests/robotests/src/com/android/settings/sound/HandsFreeProfileOutputPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/sound/HandsFreeProfileOutputPreferenceControllerTest.java
@@ -99,8 +99,8 @@
private Context mContext;
private PreferenceScreen mScreen;
private ListPreference mPreference;
+ private AudioManager mAudioManager;
private ShadowAudioManager mShadowAudioManager;
- private ShadowMediaRouter mShadowMediaRouter;
private BluetoothManager mBluetoothManager;
private BluetoothAdapter mBluetoothAdapter;
private BluetoothDevice mBluetoothDevice;
@@ -117,8 +117,8 @@
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
+ mAudioManager = mContext.getSystemService(AudioManager.class);
mShadowAudioManager = ShadowAudioManager.getShadow();
- mShadowMediaRouter = ShadowMediaRouter.getShadow();
ShadowBluetoothUtils.sLocalBluetoothManager = mLocalManager;
mLocalBluetoothManager = ShadowBluetoothUtils.getLocalBtManager(mContext);
@@ -163,7 +163,6 @@
@After
public void tearDown() {
- mShadowAudioManager.reset();
ShadowBluetoothUtils.reset();
}
@@ -173,7 +172,7 @@
*/
@Test
public void setActiveBluetoothDevice_btDeviceWithHisyncId_shouldSetBtDeviceActive() {
- mShadowAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
+ mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
when(mHearingAidProfile.getHiSyncId(mLeftBluetoothHapDevice)).thenReturn(HISYNCID1);
mController.setActiveBluetoothDevice(mLeftBluetoothHapDevice);
@@ -188,7 +187,7 @@
*/
@Test
public void setActiveBluetoothDevice_btDeviceWithoutHisyncId_shouldSetBtDeviceActive() {
- mShadowAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
+ mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
mController.setActiveBluetoothDevice(mBluetoothDevice);
@@ -203,7 +202,7 @@
*/
@Test
public void setActiveBluetoothDevice_setNull_shouldSetNullToBothProfiles() {
- mShadowAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
+ mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
mController.setActiveBluetoothDevice(null);
@@ -217,7 +216,7 @@
*/
@Test
public void setActiveBluetoothDevice_inNormalMode_shouldNotSetActiveDeviceToHeadsetProfile() {
- mShadowAudioManager.setMode(AudioManager.MODE_NORMAL);
+ mAudioManager.setMode(AudioManager.MODE_NORMAL);
mController.setActiveBluetoothDevice(mBluetoothDevice);
@@ -245,7 +244,7 @@
*/
@Test
public void updateState_oneHeadsetsAvailableAndActivated_shouldSetDeviceName() {
- mShadowAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
+ mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
mShadowAudioManager.setOutputDevice(DEVICE_OUT_BLUETOOTH_SCO);
mProfileConnectedDevices.clear();
mProfileConnectedDevices.add(mBluetoothDevice);
@@ -266,7 +265,7 @@
*/
@Test
public void updateState_moreThanOneHfpBtDevicesAreAvailable_shouldSetActivatedDeviceName() {
- mShadowAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
+ mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
mShadowAudioManager.setOutputDevice(DEVICE_OUT_BLUETOOTH_SCO);
List<BluetoothDevice> connectedDevices = new ArrayList<>(2);
connectedDevices.add(mBluetoothDevice);
@@ -288,7 +287,7 @@
*/
@Test
public void updateState_withAvailableDevicesWiredHeadsetActivated_shouldSetDefaultSummary() {
- mShadowAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
+ mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
mProfileConnectedDevices.clear();
mProfileConnectedDevices.add(mBluetoothDevice);
when(mHeadsetProfile.getConnectedDevices()).thenReturn(mProfileConnectedDevices);
@@ -308,7 +307,7 @@
*/
@Test
public void updateState_noAvailableHeadsetBtDevices_shouldSetDefaultSummary() {
- mShadowAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
+ mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
List<BluetoothDevice> emptyDeviceList = new ArrayList<>();
when(mHeadsetProfile.getConnectedDevices()).thenReturn(emptyDeviceList);
@@ -326,7 +325,7 @@
*/
@Test
public void updateState_oneHapBtDeviceAreAvailable_shouldSetActivatedDeviceName() {
- mShadowAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
+ mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
mShadowAudioManager.setOutputDevice(DEVICE_OUT_HEARING_AID);
mProfileConnectedDevices.clear();
mProfileConnectedDevices.add(mLeftBluetoothHapDevice);
@@ -350,7 +349,7 @@
*/
@Test
public void updateState_moreThanOneHapBtDevicesAreAvailable_shouldSetActivatedDeviceName() {
- mShadowAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
+ mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
mShadowAudioManager.setOutputDevice(DEVICE_OUT_HEARING_AID);
mProfileConnectedDevices.clear();
mProfileConnectedDevices.add(mLeftBluetoothHapDevice);
@@ -378,7 +377,7 @@
*/
@Test
public void updateState_hapBtDeviceWithSameId_shouldSetActivatedDeviceName() {
- mShadowAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
+ mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
mShadowAudioManager.setOutputDevice(DEVICE_OUT_HEARING_AID);
mProfileConnectedDevices.clear();
mProfileConnectedDevices.add(mBluetoothDevice);
@@ -411,7 +410,7 @@
*/
@Test
public void updateState_hapBtDeviceWithSameIdButDifferentOrder_shouldSetActivatedDeviceName() {
- mShadowAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
+ mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
mShadowAudioManager.setOutputDevice(DEVICE_OUT_HEARING_AID);
mProfileConnectedDevices.clear();
mProfileConnectedDevices.add(mBluetoothDevice);
@@ -443,7 +442,7 @@
*/
@Test
public void updateState_hapBtDeviceWithDifferentId_shouldSetActivatedDeviceName() {
- mShadowAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
+ mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
mShadowAudioManager.setOutputDevice(DEVICE_OUT_HEARING_AID);
mProfileConnectedDevices.clear();
mProfileConnectedDevices.add(mBluetoothDevice);
diff --git a/tests/robotests/src/com/android/settings/sound/MediaOutputPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/sound/MediaOutputPreferenceControllerTest.java
index cdee894..9a0c2ee 100644
--- a/tests/robotests/src/com/android/settings/sound/MediaOutputPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/sound/MediaOutputPreferenceControllerTest.java
@@ -100,8 +100,8 @@
private Context mContext;
private PreferenceScreen mScreen;
private ListPreference mPreference;
+ private AudioManager mAudioManager;
private ShadowAudioManager mShadowAudioManager;
- private ShadowMediaRouter mShadowMediaRouter;
private BluetoothManager mBluetoothManager;
private BluetoothAdapter mBluetoothAdapter;
private BluetoothDevice mBluetoothDevice;
@@ -118,8 +118,8 @@
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
+ mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
mShadowAudioManager = ShadowAudioManager.getShadow();
- mShadowMediaRouter = ShadowMediaRouter.getShadow();
ShadowBluetoothUtils.sLocalBluetoothManager = mLocalManager;
mLocalBluetoothManager = ShadowBluetoothUtils.getLocalBtManager(mContext);
@@ -164,7 +164,6 @@
@After
public void tearDown() {
- mShadowAudioManager.reset();
ShadowBluetoothUtils.reset();
}
@@ -174,7 +173,7 @@
*/
@Test
public void setActiveBluetoothDevice_btDeviceWithHisyncId_shouldSetBtDeviceActive() {
- mShadowAudioManager.setMode(AudioManager.MODE_NORMAL);
+ mAudioManager.setMode(AudioManager.MODE_NORMAL);
when(mHearingAidProfile.getHiSyncId(mLeftBluetoothHapDevice)).thenReturn(HISYNCID1);
mController.setActiveBluetoothDevice(mLeftBluetoothHapDevice);
@@ -189,7 +188,7 @@
*/
@Test
public void setActiveBluetoothDevice_btDeviceWithoutHisyncId_shouldSetBtDeviceActive() {
- mShadowAudioManager.setMode(AudioManager.MODE_NORMAL);
+ mAudioManager.setMode(AudioManager.MODE_NORMAL);
mController.setActiveBluetoothDevice(mBluetoothDevice);
@@ -204,7 +203,7 @@
*/
@Test
public void setActiveBluetoothDevice_setNull_shouldSetNullToBothProfiles() {
- mShadowAudioManager.setMode(AudioManager.MODE_NORMAL);
+ mAudioManager.setMode(AudioManager.MODE_NORMAL);
mController.setActiveBluetoothDevice(null);
@@ -218,7 +217,7 @@
*/
@Test
public void setActiveBluetoothDevice_duringACall_shouldNotSetActiveDeviceToA2dpProfile() {
- mShadowAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
+ mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
mController.setActiveBluetoothDevice(mBluetoothDevice);
@@ -246,7 +245,7 @@
*/
@Test
public void updateState_duringACall_shouldSetDefaultSummary() {
- mShadowAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
+ mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
mController.updateState(mPreference);
@@ -262,7 +261,7 @@
*/
@Test
public void updateState_noAvailableA2dpBtDevices_shouldDisableAndSetDefaultSummary() {
- mShadowAudioManager.setMode(AudioManager.MODE_NORMAL);
+ mAudioManager.setMode(AudioManager.MODE_NORMAL);
List<BluetoothDevice> emptyDeviceList = new ArrayList<>();
when(mA2dpProfile.getConnectedDevices()).thenReturn(emptyDeviceList);
@@ -296,7 +295,7 @@
*/
@Test
public void updateState_oneA2dpBtDeviceAreAvailable_shouldSetActivatedDeviceName() {
- mShadowAudioManager.setMode(AudioManager.MODE_NORMAL);
+ mAudioManager.setMode(AudioManager.MODE_NORMAL);
mShadowAudioManager.setOutputDevice(DEVICE_OUT_BLUETOOTH_A2DP);
mProfileConnectedDevices.clear();
mProfileConnectedDevices.add(mBluetoothDevice);
@@ -316,7 +315,7 @@
*/
@Test
public void updateState_moreThanOneA2DpBtDevicesAreAvailable_shouldSetActivatedDeviceName() {
- mShadowAudioManager.setMode(AudioManager.MODE_NORMAL);
+ mAudioManager.setMode(AudioManager.MODE_NORMAL);
mShadowAudioManager.setOutputDevice(DEVICE_OUT_BLUETOOTH_A2DP);
mProfileConnectedDevices.clear();
mProfileConnectedDevices.add(mBluetoothDevice);
@@ -337,7 +336,7 @@
*/
@Test
public void updateState_a2dpDevicesAvailableWiredHeadsetIsActivated_shouldSetDefaultSummary() {
- mShadowAudioManager.setMode(AudioManager.MODE_NORMAL);
+ mAudioManager.setMode(AudioManager.MODE_NORMAL);
mProfileConnectedDevices.clear();
mProfileConnectedDevices.add(mBluetoothDevice);
when(mLocalBluetoothProfileManager.getHearingAidProfile()).thenReturn(null);
@@ -359,7 +358,7 @@
*/
@Test
public void updateState_a2dpDevicesAvailableCurrentDeviceActivated_shouldSetDefaultSummary() {
- mShadowAudioManager.setMode(AudioManager.MODE_NORMAL);
+ mAudioManager.setMode(AudioManager.MODE_NORMAL);
mProfileConnectedDevices.clear();
mProfileConnectedDevices.add(mBluetoothDevice);
when(mA2dpProfile.getConnectedDevices()).thenReturn(mProfileConnectedDevices);
@@ -379,7 +378,7 @@
*/
@Test
public void updateState_oneHapBtDeviceAreAvailable_shouldSetActivatedDeviceName() {
- mShadowAudioManager.setMode(AudioManager.MODE_NORMAL);
+ mAudioManager.setMode(AudioManager.MODE_NORMAL);
mShadowAudioManager.setOutputDevice(DEVICE_OUT_HEARING_AID);
mProfileConnectedDevices.clear();
mProfileConnectedDevices.add(mLeftBluetoothHapDevice);
@@ -403,7 +402,7 @@
*/
@Test
public void updateState_moreThanOneHapBtDevicesAreAvailable_shouldSetActivatedDeviceName() {
- mShadowAudioManager.setMode(AudioManager.MODE_NORMAL);
+ mAudioManager.setMode(AudioManager.MODE_NORMAL);
mShadowAudioManager.setOutputDevice(DEVICE_OUT_HEARING_AID);
mProfileConnectedDevices.clear();
mProfileConnectedDevices.add(mLeftBluetoothHapDevice);
@@ -431,7 +430,7 @@
*/
@Test
public void updateState_hapBtDeviceWithSameId_shouldSetActivatedDeviceName() {
- mShadowAudioManager.setMode(AudioManager.MODE_NORMAL);
+ mAudioManager.setMode(AudioManager.MODE_NORMAL);
mShadowAudioManager.setOutputDevice(DEVICE_OUT_HEARING_AID);
mProfileConnectedDevices.clear();
mProfileConnectedDevices.add(mBluetoothDevice);
@@ -464,7 +463,7 @@
*/
@Test
public void updateState_hapBtDeviceWithSameIdButDifferentOrder_shouldSetActivatedDeviceName() {
- mShadowAudioManager.setMode(AudioManager.MODE_NORMAL);
+ mAudioManager.setMode(AudioManager.MODE_NORMAL);
mShadowAudioManager.setOutputDevice(DEVICE_OUT_HEARING_AID);
mProfileConnectedDevices.clear();
mProfileConnectedDevices.add(mBluetoothDevice);
@@ -496,7 +495,7 @@
*/
@Test
public void updateState_hapBtDeviceWithDifferentId_shouldSetActivatedDeviceName() {
- mShadowAudioManager.setMode(AudioManager.MODE_NORMAL);
+ mAudioManager.setMode(AudioManager.MODE_NORMAL);
mShadowAudioManager.setOutputDevice(DEVICE_OUT_HEARING_AID);
mProfileConnectedDevices.clear();
mProfileConnectedDevices.add(mBluetoothDevice);
diff --git a/tests/robotests/src/com/android/settings/system/SystemDashboardFragmentTest.java b/tests/robotests/src/com/android/settings/system/SystemDashboardFragmentTest.java
index 5f787a9..2785c66 100644
--- a/tests/robotests/src/com/android/settings/system/SystemDashboardFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/system/SystemDashboardFragmentTest.java
@@ -48,7 +48,6 @@
@After
public void tearDown() {
SettingsShadowResources.reset();
- ShadowUserManager.getShadow().reset();
}
@Test
diff --git a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowAccountManager.java b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowAccountManager.java
index 4401926..bf54d2f 100644
--- a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowAccountManager.java
+++ b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowAccountManager.java
@@ -30,7 +30,7 @@
import java.util.Map;
@Implements(AccountManager.class)
-public class ShadowAccountManager{
+public class ShadowAccountManager {
private static final Map<String, AuthenticatorDescription> sAuthenticators = new HashMap<>();
private static final Map<Integer, List<Account>> sAccountsByUserId = new HashMap<>();
diff --git a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowAudioManager.java b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowAudioManager.java
index cea50f3..6636a6c 100644
--- a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowAudioManager.java
+++ b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowAudioManager.java
@@ -101,11 +101,6 @@
}
}
- @Resetter
- public void reset() {
- mDeviceCallbacks.clear();
- }
-
public void setBluetoothScoOn(boolean bluetoothScoOn) {
mBluetoothScoOn = bluetoothScoOn;
}
diff --git a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowLibcoreTimeZoneNames.java b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowLibcoreTimeZoneNames.java
deleted file mode 100644
index 7292234..0000000
--- a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowLibcoreTimeZoneNames.java
+++ /dev/null
@@ -1,60 +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.
- */
-
-package com.android.settings.testutils.shadow;
-
-import libcore.icu.TimeZoneNames;
-
-import org.robolectric.annotation.Implementation;
-import org.robolectric.annotation.Implements;
-import org.robolectric.annotation.RealObject;
-import org.robolectric.util.ReflectionHelpers;
-
-import java.util.Locale;
-import java.util.TimeZone;
-
-/**
- * System.logI used by ZoneStringsCache.create is a method new in API 24 and not available in
- * Robolectric's 6.0 jar. Create a shadow which removes that log call.
- */
-@Implements(value = TimeZoneNames.class, isInAndroidSdk = false)
-public class ShadowLibcoreTimeZoneNames {
-
- private static final String[] availableTimeZoneIds = TimeZone.getAvailableIDs();
-
- @Implements(value = TimeZoneNames.ZoneStringsCache.class, isInAndroidSdk = false)
- public static class ShadowZoneStringsCache {
-
- @RealObject
- private TimeZoneNames.ZoneStringsCache mRealObject;
-
- @Implementation
- public String[][] create(Locale locale) {
- // Set up the 2D array used to hold the names. The first column contains the Olson ids.
- String[][] result = new String[availableTimeZoneIds.length][5];
- for (int i = 0; i < availableTimeZoneIds.length; ++i) {
- result[i][0] = availableTimeZoneIds[i];
- }
-
- ReflectionHelpers.callInstanceMethod(TimeZoneNames.class,
- mRealObject, "fillZoneStrings",
- ReflectionHelpers.ClassParameter.from(String.class, locale.toLanguageTag()),
- ReflectionHelpers.ClassParameter.from(String[][].class, result));
-
- return result;
- }
- }
-}
diff --git a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowUserManager.java b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowUserManager.java
index 61278f3..d8703be 100644
--- a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowUserManager.java
+++ b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowUserManager.java
@@ -21,12 +21,10 @@
import android.os.UserHandle;
import android.os.UserManager;
import android.os.UserManager.EnforcingUser;
-import android.util.SparseArray;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
-import org.robolectric.annotation.Resetter;
import org.robolectric.shadow.api.Shadow;
import java.util.ArrayList;
@@ -40,7 +38,6 @@
@Implements(value = UserManager.class)
public class ShadowUserManager extends org.robolectric.shadows.ShadowUserManager {
- private SparseArray<UserInfo> mUserInfos = new SparseArray<>();
private final List<String> mRestrictions = new ArrayList<>();
private final Map<String, List<EnforcingUser>> mRestrictionSources = new HashMap<>();
private final List<UserInfo> mUserProfileInfos = new ArrayList<>();
@@ -49,28 +46,6 @@
private int[] profileIdsForUser = new int[0];
private boolean mUserSwitchEnabled;
-
- @Resetter
- public void reset() {
- mUserInfos.clear();
- mRestrictions.clear();
- mUserProfileInfos.clear();
- mRestrictionSources.clear();
- mManagedProfiles.clear();
- mIsQuietModeEnabled = false;
- mUserSwitchEnabled = false;
- profileIdsForUser = new int[0];
- }
-
- public void setUserInfo(int userHandle, UserInfo userInfo) {
- mUserInfos.put(userHandle, userInfo);
- }
-
- @Implementation
- protected UserInfo getUserInfo(int userHandle) {
- return mUserInfos.get(userHandle);
- }
-
public void addProfile(UserInfo userInfo) {
mUserProfileInfos.add(userInfo);
}
@@ -90,16 +65,6 @@
}
@Implementation
- public List<UserHandle> getUserProfiles(){
- int[] userIds = getProfileIds(UserHandle.myUserId(), true /* enabledOnly */);
- List<UserHandle> result = new ArrayList<>(userIds.length);
- for (int userId : userIds) {
- result.add(UserHandle.of(userId));
- }
- return result;
- }
-
- @Implementation
protected int getCredentialOwnerProfile(@UserIdInt int userHandle) {
return userHandle;
}
diff --git a/tests/robotests/src/com/android/settings/users/AddUserWhenLockedPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/users/AddUserWhenLockedPreferenceControllerTest.java
index 2bd12c3..8093af5 100644
--- a/tests/robotests/src/com/android/settings/users/AddUserWhenLockedPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/users/AddUserWhenLockedPreferenceControllerTest.java
@@ -23,7 +23,6 @@
import static org.mockito.Mockito.when;
import android.content.Context;
-import android.content.pm.UserInfo;
import android.provider.Settings.Global;
import androidx.preference.PreferenceScreen;
@@ -32,7 +31,6 @@
import com.android.settings.testutils.shadow.ShadowUserManager;
import com.android.settingslib.RestrictedSwitchPreference;
-import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -40,7 +38,6 @@
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
-import org.robolectric.shadows.ShadowApplication;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(shadows = {ShadowUserManager.class})
@@ -49,7 +46,6 @@
@Mock(answer = RETURNS_DEEP_STUBS)
private PreferenceScreen mScreen;
@Mock(answer = RETURNS_DEEP_STUBS)
- private UserInfo mUserInfo;
private Context mContext;
private ShadowUserManager mUserManager;
@@ -63,15 +59,9 @@
mController = new AddUserWhenLockedPreferenceController(mContext, "fake_key");
}
- @After
- public void tearDown() {
- mUserManager.reset();
- }
-
@Test
public void displayPref_NotAdmin_shouldNotDisplay() {
- mUserManager.setUserInfo(0, mUserInfo);
- when(mUserInfo.isAdmin()).thenReturn(false);
+ mUserManager.setIsAdminUser(false);
final RestrictedSwitchPreference preference = mock(RestrictedSwitchPreference.class);
when(preference.getKey()).thenReturn(mController.getPreferenceKey());
when(mScreen.findPreference(preference.getKey())).thenReturn(preference);
diff --git a/tests/robotests/src/com/android/settings/users/EditUserInfoControllerTest.java b/tests/robotests/src/com/android/settings/users/EditUserInfoControllerTest.java
index 97b3e69..cd33b39 100644
--- a/tests/robotests/src/com/android/settings/users/EditUserInfoControllerTest.java
+++ b/tests/robotests/src/com/android/settings/users/EditUserInfoControllerTest.java
@@ -28,7 +28,6 @@
import android.content.Context;
import android.content.Intent;
-import android.content.pm.UserInfo;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
@@ -40,9 +39,7 @@
import com.android.settings.R;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
-import com.android.settings.testutils.shadow.ShadowUserManager;
-import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -50,18 +47,14 @@
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.android.controller.ActivityController;
-import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(shadows = {ShadowUserManager.class})
public class EditUserInfoControllerTest {
@Mock
private Fragment mFragment;
@Mock
private LayoutInflater mInflater;
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
- private UserInfo mUserInfo;
- @Mock(answer = Answers.RETURNS_DEEP_STUBS)
private View mDialogContent;
@Mock
private EditText mUserName;
@@ -70,7 +63,6 @@
@Mock
private Drawable mCurrentIcon;
- private ShadowUserManager mUserManager;
private FragmentActivity mActivity;
private TestEditUserInfoController mController;
@@ -92,8 +84,6 @@
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
- mUserManager = ShadowUserManager.getShadow();
- mUserManager.setUserInfo(0, mUserInfo);
mActivity = spy(ActivityController.of(new FragmentActivity()).get());
when(mFragment.getActivity()).thenReturn(mActivity);
when(mActivity.getLayoutInflater()).thenReturn(mInflater);
@@ -105,11 +95,6 @@
mController = new TestEditUserInfoController();
}
- @After
- public void tearDown() {
- mUserManager.reset();
- }
-
@Test
public void photoControllerOnActivityResult_whenWaiting_isCalled() {
mController.createDialog(mFragment, mCurrentIcon, "test user",
diff --git a/tests/robotests/src/com/android/settings/users/UserCapabilitiesTest.java b/tests/robotests/src/com/android/settings/users/UserCapabilitiesTest.java
index c8d3685..894def7 100644
--- a/tests/robotests/src/com/android/settings/users/UserCapabilitiesTest.java
+++ b/tests/robotests/src/com/android/settings/users/UserCapabilitiesTest.java
@@ -45,11 +45,6 @@
mUserManager = ShadowUserManager.getShadow();
}
- @After
- public void tearDown() {
- mUserManager.reset();
- }
-
@Test
public void disallowUserSwitch_restrictionIsSet_true() {
mUserManager.setUserRestriction(UserHandle.of(UserHandle.myUserId()),
diff --git a/tests/robotests/src/com/android/settings/widget/EntityHeaderControllerTest.java b/tests/robotests/src/com/android/settings/widget/EntityHeaderControllerTest.java
index cc9bee0..5d60810 100644
--- a/tests/robotests/src/com/android/settings/widget/EntityHeaderControllerTest.java
+++ b/tests/robotests/src/com/android/settings/widget/EntityHeaderControllerTest.java
@@ -96,11 +96,12 @@
}
@Test
- public void testBuildView_withContext_shouldBuildPreference() {
+ public void testBuildView_withContext_shouldBuildPreferenceAllowedBelowDivider() {
mController = EntityHeaderController.newInstance(mActivity, mFragment, null);
Preference preference = mController.done(mActivity, mShadowContext);
assertThat(preference instanceof LayoutPreference).isTrue();
+ assertThat(((LayoutPreference)preference).isAllowDividerBelow()).isTrue();
}
@Test
diff --git a/tests/robotests/src/com/android/settings/wifi/qrcode/QrCameraTest.java b/tests/robotests/src/com/android/settings/wifi/qrcode/QrCameraTest.java
index ca74c19..2595bb6 100644
--- a/tests/robotests/src/com/android/settings/wifi/qrcode/QrCameraTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/qrcode/QrCameraTest.java
@@ -30,13 +30,10 @@
import com.android.settings.R;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
-import com.google.zxing.BarcodeFormat;
import com.google.zxing.BinaryBitmap;
import com.google.zxing.LuminanceSource;
import com.google.zxing.RGBLuminanceSource;
-import com.google.zxing.MultiFormatWriter;
import com.google.zxing.WriterException;
-import com.google.zxing.common.BitMatrix;
import com.google.zxing.common.HybridBinarizer;
import java.util.concurrent.CountDownLatch;
@@ -111,36 +108,17 @@
final String googleUrl = "http://www.google.com";
try {
- Bitmap bmp = encodeQrCode(googleUrl, 320);
- int[] intArray = new int[bmp.getWidth() * bmp.getHeight()];
+ final Bitmap bmp = QrCodeGenerator.encodeQrCode(googleUrl, 320);
+ final int[] intArray = new int[bmp.getWidth() * bmp.getHeight()];
bmp.getPixels(intArray, 0, bmp.getWidth(), 0, 0, bmp.getWidth(), bmp.getHeight());
LuminanceSource source = new RGBLuminanceSource(bmp.getWidth(), bmp.getHeight(),
intArray);
-
- BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
+ final BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
mCamera.decodeImage(bitmap);
+ bmp.recycle();
} catch (WriterException e) {
}
assertThat(mQrCode).isEqualTo(googleUrl);
}
-
- private Bitmap encodeQrCode(String qrCode, int size) throws WriterException {
- BitMatrix qrBits = null;
- try {
- qrBits =
- new MultiFormatWriter().encode(qrCode, BarcodeFormat.QR_CODE, size, size, null);
- } catch (IllegalArgumentException iae) {
- // Should never reach here.
- }
- assertThat(qrBits).isNotNull();
-
- Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.RGB_565);
- for (int x = 0; x < size; ++x) {
- for (int y = 0; y < size; ++y) {
- bitmap.setPixel(x, y, qrBits.get(x, y) ? Color.BLACK : Color.WHITE);
- }
- }
- return bitmap;
- }
}
diff --git a/tests/robotests/src/com/android/settings/wifi/savedaccesspoints/SavedAccessPointsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/savedaccesspoints/SavedAccessPointsPreferenceControllerTest.java
index 790739a..6d609b8 100644
--- a/tests/robotests/src/com/android/settings/wifi/savedaccesspoints/SavedAccessPointsPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/savedaccesspoints/SavedAccessPointsPreferenceControllerTest.java
@@ -28,6 +28,7 @@
import android.content.Context;
import android.net.wifi.WifiConfiguration;
+import android.net.wifi.WifiManager;
import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceScreen;
@@ -56,14 +57,14 @@
private PreferenceCategory mPreferenceCategory;
private Context mContext;
- private ShadowWifiManager mWifiManager;
+ private WifiManager mWifiManager;
private SavedAccessPointsPreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
- mWifiManager = ShadowWifiManager.get();
+ mWifiManager = mContext.getSystemService(WifiManager.class);
mController = spy(new SavedAccessPointsPreferenceController(mContext, "test_key"));
when(mPreferenceScreen.findPreference(mController.getPreferenceKey()))