Merge "Fix startup jank in the Wifi Picker." into oc-dev
diff --git a/res/drawable/action_bar_dropshadow.xml b/res/drawable/action_bar_dropshadow.xml
new file mode 100644
index 0000000..dd85877
--- /dev/null
+++ b/res/drawable/action_bar_dropshadow.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2017 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ 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.
+ -->
+
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+ android:shape="rectangle">
+ <gradient
+ android:angle="270"
+ android:startColor="#4D000000"
+ android:endColor="@android:color/transparent"
+ android:type="linear" />
+ <size android:height="8dp" />
+</shape>
\ No newline at end of file
diff --git a/res/layout/app_details.xml b/res/layout/app_details.xml
index 5ffeec5..8cfa8b9 100644
--- a/res/layout/app_details.xml
+++ b/res/layout/app_details.xml
@@ -17,30 +17,24 @@
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/app_snippet"
- style="@style/EntityHeader"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:layout_gravity="center_horizontal|top"
- android:orientation="vertical"
- android:paddingStart="?android:attr/listPreferredItemPaddingStart"
- android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
- android:paddingTop="24dp"
- android:paddingBottom="24dp"
- android:clipChildren="false"
- android:clipToPadding="false">
+ android:orientation="vertical">
<!-- App snippet with buttons -->
<RelativeLayout
+ android:id="@+id/app_snippet"
+ style="@style/EntityHeader"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:paddingStart="8dp"
- android:clipChildren="false"
- android:clipToPadding="false">
+ android:paddingStart="?android:attr/listPreferredItemPaddingStart"
+ android:paddingEnd="0dp"
+ android:paddingTop="24dp"
+ android:paddingBottom="24dp">
<FrameLayout android:id="@+id/app_icon_frame"
- android:layout_width="80dp"
- android:layout_height="80dp"
+ android:layout_width="56dp"
+ android:layout_height="56dp"
android:clipChildren="false"
android:clipToPadding="false">
<ImageView
@@ -54,8 +48,7 @@
android:layout_width="22dp"
android:layout_height="22dp"
android:layout_gravity="end|bottom"
- android:layout_margin="8dp"
- android:visibility="gone"
+ android:layout_margin="4dp"
android:elevation="20dp"
android:background="@drawable/ic_instant_apps_badge_bg"
android:src="@drawable/ic_instant_apps_badge" />
@@ -70,19 +63,22 @@
<ImageButton
android:id="@+id/right_button"
- style="@android:style/Widget.Material.Button.Borderless"
+ style="?android:attr/actionOverflowButtonStyle"
android:layout_width="wrap_content"
android:layout_weight="1"
android:layout_height="0dp"
+ android:minWidth="@dimen/min_tap_target_size"
android:src="@drawable/ic_settings_24dp"
android:tint="?android:attr/colorAccent"/>
<ImageButton
android:id="@+id/left_button"
- style="@android:style/Widget.Material.Button.Borderless"
+ style="?android:attr/actionOverflowButtonStyle"
android:layout_width="wrap_content"
android:layout_weight="1"
android:layout_height="0dp"
+ android:minWidth="@dimen/min_tap_target_size"
+ android:src="@null"
android:tint="?android:attr/colorAccent"/>
</LinearLayout>
@@ -131,4 +127,9 @@
</RelativeLayout>
+ <!-- Drop shadow -->
+ <View android:layout_width="match_parent"
+ android:layout_height="5dp"
+ android:background="@drawable/action_bar_dropshadow"/>
+
</LinearLayout>
\ No newline at end of file
diff --git a/res/layout/preference_wallpaper_type.xml b/res/layout/preference_wallpaper_type.xml
deleted file mode 100644
index a35a24e..0000000
--- a/res/layout/preference_wallpaper_type.xml
+++ /dev/null
@@ -1,43 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2015 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.
--->
-
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:minHeight="?android:attr/listPreferredItemHeight"
- android:gravity="center_vertical"
- android:paddingStart="?android:attr/listPreferredItemPaddingStart"
- android:paddingEnd="?android:attr/listPreferredItemPaddingEnd" >
-
- <ImageView
- android:id="@android:id/icon"
- android:layout_width="40dp"
- android:layout_height="40dp"
- android:layout_gravity="center"
- android:scaleType="fitXY"
- android:layout_marginEnd="16dip"
- android:contentDescription="@null" />
-
- <TextView android:id="@android:id/title"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:singleLine="true"
- android:textAppearance="@android:style/TextAppearance.Material.Subhead"
- android:ellipsize="marquee"
- android:fadingEdge="horizontal"
- android:layout_weight="1" />
-
-</LinearLayout>
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index 09f7cda..8173d8a 100755
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -22,6 +22,7 @@
<dimen name="action_bar_switch_padding">16dip</dimen>
<dimen name="app_icon_size">40dip</dimen>
+ <dimen name="min_tap_target_size">48dp</dimen>
<dimen name="screen_margin_sides">64dip</dimen>
<dimen name="screen_margin_top">72dip</dimen>
<dimen name="screen_margin_bottom">48dip</dimen>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 36643d3..863d27f 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -1628,6 +1628,8 @@
<string name="wifi_wakeup">Turn on Wi\u2011Fi automatically</string>
<!-- Checkbox summary for option to enable Wi-Fi when high quality saved networks are nearby-->
<string name="wifi_wakeup_summary">Wi\u2011Fi will turn back on near high\u2011quality saved networks, like your home network</string>
+ <!-- Checkbox summary for Wi-Fi wakeup option to explain that Wi-Fi wakeup is disabled because Wi-Fi scanning is turned off -->
+ <string name="wifi_wakeup_summary_scanning_disabled">Unavailable because Wi\u2011Fi scanning is turned off</string>
<!-- Checkbox title for option to toggle poor network detection -->
<string name="wifi_poor_network_detection">Avoid poor connections</string>
<!-- Checkbox summary for option to toggle poor network detection -->
diff --git a/res/values/styles.xml b/res/values/styles.xml
index e9d25ff..bae36b3 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -416,7 +416,7 @@
<style name="TextAppearance.EntityHeaderTitle"
parent="@android:style/TextAppearance.Material.Subhead">
<item name="android:textColor">?android:attr/textColorPrimary</item>
- <item name="android:textSize">24sp</item>
+ <item name="android:textSize">16sp</item>
</style>
<style name="AppActionPrimaryButton" parent="android:Widget.Material.Button.Colored"/>
diff --git a/src/com/android/settings/SettingsPreferenceFragment.java b/src/com/android/settings/SettingsPreferenceFragment.java
index 70743e2..761e8cf 100644
--- a/src/com/android/settings/SettingsPreferenceFragment.java
+++ b/src/com/android/settings/SettingsPreferenceFragment.java
@@ -440,6 +440,7 @@
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
+ super.onCreateOptionsMenu(menu, inflater);
if (mHelpUri != null && getActivity() != null) {
HelpUtils.prepareHelpMenuItem(getActivity(), menu, mHelpUri, getClass().getName());
}
diff --git a/src/com/android/settings/SetupChooseLockGeneric.java b/src/com/android/settings/SetupChooseLockGeneric.java
index 61545a6..2c8195d 100644
--- a/src/com/android/settings/SetupChooseLockGeneric.java
+++ b/src/com/android/settings/SetupChooseLockGeneric.java
@@ -17,10 +17,8 @@
package com.android.settings;
import android.app.admin.DevicePolicyManager;
-import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
-import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.os.Bundle;
import android.os.UserHandle;
@@ -120,12 +118,6 @@
data.putExtra(EXTRA_PASSWORD_QUALITY,
lockPatternUtils.getKeyguardStoredPasswordQuality(UserHandle.myUserId()));
- PackageManager packageManager = getPackageManager();
- ComponentName componentName = new ComponentName("com.android.settings",
- "com.android.settings.SetupRedactionInterstitial");
- packageManager.setComponentEnabledSetting(componentName,
- PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
- PackageManager.DONT_KILL_APP);
super.onActivityResult(requestCode, resultCode, data);
}
// If the started activity was cancelled (e.g. the user presses back), then this
diff --git a/src/com/android/settings/SetupChooseLockPassword.java b/src/com/android/settings/SetupChooseLockPassword.java
index f0a9a26..f2c24d0 100644
--- a/src/com/android/settings/SetupChooseLockPassword.java
+++ b/src/com/android/settings/SetupChooseLockPassword.java
@@ -87,6 +87,9 @@
@Override
protected Intent getRedactionInterstitialIntent(Context context) {
+ // Setup wizard's redaction interstitial is deferred to optional step. Enable that
+ // optional step if the lock screen was set up.
+ SetupRedactionInterstitial.setEnabled(context, true);
return null;
}
}
diff --git a/src/com/android/settings/SetupChooseLockPattern.java b/src/com/android/settings/SetupChooseLockPattern.java
index 09b951e..30a3c7c 100644
--- a/src/com/android/settings/SetupChooseLockPattern.java
+++ b/src/com/android/settings/SetupChooseLockPattern.java
@@ -73,6 +73,9 @@
@Override
protected Intent getRedactionInterstitialIntent(Context context) {
+ // Setup wizard's redaction interstitial is deferred to optional step. Enable that
+ // optional step if the lock screen was set up.
+ SetupRedactionInterstitial.setEnabled(context, false);
return null;
}
}
diff --git a/src/com/android/settings/SetupRedactionInterstitial.java b/src/com/android/settings/SetupRedactionInterstitial.java
index d527585..321040e 100644
--- a/src/com/android/settings/SetupRedactionInterstitial.java
+++ b/src/com/android/settings/SetupRedactionInterstitial.java
@@ -16,11 +16,11 @@
package com.android.settings;
+import android.content.ComponentName;
+import android.content.Context;
import android.content.Intent;
+import android.content.pm.PackageManager;
import android.content.res.Resources;
-import android.os.Bundle;
-import android.view.View;
-import android.widget.Button;
import com.android.settings.notification.RedactionInterstitial;
@@ -33,6 +33,20 @@
*/
public class SetupRedactionInterstitial extends RedactionInterstitial {
+ /**
+ * Set the enabled state of SetupRedactionInterstitial activity to configure whether it is shown
+ * as part of setup wizard's optional steps.
+ */
+ public static void setEnabled(Context context, boolean enabled) {
+ PackageManager packageManager = context.getPackageManager();
+ ComponentName componentName = new ComponentName(context, SetupRedactionInterstitial.class);
+ packageManager.setComponentEnabledSetting(
+ componentName,
+ enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
+ : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
+ PackageManager.DONT_KILL_APP);
+ }
+
@Override
public Intent getIntent() {
Intent modIntent = new Intent(super.getIntent());
diff --git a/src/com/android/settings/applications/AppAndNotificationDashboardFragment.java b/src/com/android/settings/applications/AppAndNotificationDashboardFragment.java
index 9018d9b..51225aa 100644
--- a/src/com/android/settings/applications/AppAndNotificationDashboardFragment.java
+++ b/src/com/android/settings/applications/AppAndNotificationDashboardFragment.java
@@ -25,6 +25,7 @@
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.search.BaseSearchIndexProvider;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -55,7 +56,13 @@
@Override
protected List<PreferenceController> getPreferenceControllers(Context context) {
- return null;
+ return buildPreferenceControllers(context);
+ }
+
+ private static List<PreferenceController> buildPreferenceControllers(Context context) {
+ final List<PreferenceController> controllers = new ArrayList<>();
+ controllers.add(new SpecialAppAccessPreferenceController(context));
+ return controllers;
}
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
@@ -67,5 +74,10 @@
sir.xmlResId = R.xml.app_and_notification;
return Arrays.asList(sir);
}
+
+ @Override
+ public List<PreferenceController> getPreferenceControllers(Context context) {
+ return buildPreferenceControllers(context);
+ }
};
}
diff --git a/src/com/android/settings/applications/AppHeaderController.java b/src/com/android/settings/applications/AppHeaderController.java
index f3a086b..29acaa4 100644
--- a/src/com/android/settings/applications/AppHeaderController.java
+++ b/src/com/android/settings/applications/AppHeaderController.java
@@ -18,25 +18,25 @@
import android.annotation.IdRes;
import android.annotation.UserIdInt;
+import android.app.ActionBar;
+import android.app.Activity;
import android.app.Fragment;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.ResolveInfo;
-import android.content.res.Resources;
-import android.graphics.Outline;
-import android.graphics.drawable.AdaptiveIconDrawable;
import android.graphics.drawable.Drawable;
import android.os.UserHandle;
import android.support.annotation.IntDef;
+import android.support.annotation.VisibleForTesting;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
-import android.view.ViewOutlineProvider;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
+
import com.android.settings.AppHeader;
import com.android.settings.R;
import com.android.settings.Utils;
@@ -69,7 +69,6 @@
private final Fragment mFragment;
private final int mMetricsCategory;
private final View mAppHeader;
- private final int mIconElevation;
private Drawable mIcon;
private CharSequence mLabel;
@@ -96,8 +95,6 @@
mAppHeader = LayoutInflater.from(fragment.getContext())
.inflate(R.layout.app_details, null /* root */);
}
- mIconElevation = mContext.getResources()
- .getDimensionPixelSize(R.dimen.launcher_icon_elevation);
}
public AppHeaderController setIcon(Drawable icon) {
@@ -164,39 +161,10 @@
}
/**
- * Binds app header view and data from {@code PackageInfo} and {@code AppEntry}.
- */
- public void bindAppHeader(PackageInfo packageInfo, ApplicationsState.AppEntry appEntry) {
- final String versionName = packageInfo == null ? null : packageInfo.versionName;
- final Resources res = mAppHeader.getResources();
-
- // Set Icon
- final ImageView iconView = (ImageView) mAppHeader.findViewById(R.id.app_detail_icon);
- if (appEntry.icon != null) {
- iconView.setImageDrawable(appEntry.icon.getConstantState().newDrawable(res));
- }
-
- // Set application name.
- final TextView labelView = (TextView) mAppHeader.findViewById(R.id.app_detail_title);
- labelView.setText(appEntry.label);
-
- // Version number of application
- final TextView appVersion = (TextView) mAppHeader.findViewById(R.id.app_detail_summary);
-
- if (!TextUtils.isEmpty(versionName)) {
- appVersion.setSelected(true);
- appVersion.setVisibility(View.VISIBLE);
- appVersion.setText(res.getString(R.string.version_text, String.valueOf(versionName)));
- } else {
- appVersion.setVisibility(View.INVISIBLE);
- }
- }
-
- /**
* Done mutating appheader, rebinds everything and return a new {@link LayoutPreference}.
*/
- public LayoutPreference done(Context context) {
- final LayoutPreference pref = new LayoutPreference(context, done());
+ public LayoutPreference done(Activity activity, Context uiContext) {
+ final LayoutPreference pref = new LayoutPreference(uiContext, done(activity));
// Makes sure it's the first preference onscreen.
pref.setOrder(-1000);
pref.setKey(PREF_KEY_APP_HEADER);
@@ -204,17 +172,11 @@
}
/**
- * Done mutating appheader, rebinds everything.
- */
- public View done() {
- return done(true);
- }
-
- /**
* Done mutating appheader, rebinds everything (optionally skip rebinding buttons).
*/
- public View done(boolean rebindActions) {
- ImageView iconView = (ImageView) mAppHeader.findViewById(R.id.app_detail_icon);
+ public View done(Activity activity, boolean rebindActions) {
+ styleActionBar(activity);
+ ImageView iconView = mAppHeader.findViewById(R.id.app_detail_icon);
if (iconView != null) {
iconView.setImageDrawable(mIcon);
ImageView badgeView = mAppHeader.findViewById(R.id.app_icon_instant_apps_badge);
@@ -239,12 +201,39 @@
/**
* Only binds app header with button actions.
*/
- public void bindAppHeaderButtons() {
- ImageButton leftButton = (ImageButton) mAppHeader.findViewById(R.id.left_button);
- ImageButton rightButton = (ImageButton) mAppHeader.findViewById(R.id.right_button);
+ public AppHeaderController bindAppHeaderButtons() {
+ ImageButton leftButton = mAppHeader.findViewById(R.id.left_button);
+ ImageButton rightButton = mAppHeader.findViewById(R.id.right_button);
bindButton(leftButton, mLeftAction);
bindButton(rightButton, mRightAction);
+ return this;
+ }
+
+ public AppHeaderController styleActionBar(Activity activity) {
+ if (activity == null) {
+ Log.w(TAG, "No activity, cannot style actionbar.");
+ return this;
+ }
+ final ActionBar actionBar = activity.getActionBar();
+ if (actionBar == null) {
+ Log.w(TAG, "No actionbar, cannot style actionbar.");
+ return this;
+ }
+ final Drawable appHeaderBackground =
+ mAppHeader.findViewById(R.id.app_snippet).getBackground();
+ actionBar.setBackgroundDrawable(appHeaderBackground);
+ actionBar.setElevation(0);
+
+ return this;
+ }
+
+ /**
+ * Done mutating appheader, rebinds everything.
+ */
+ @VisibleForTesting
+ View done(Activity activity) {
+ return done(activity, true /* rebindActions */);
}
private void bindButton(ImageButton button, @ActionType int action) {
@@ -328,7 +317,7 @@
}
private void setText(@IdRes int id, CharSequence text) {
- TextView textView = (TextView) mAppHeader.findViewById(id);
+ TextView textView = mAppHeader.findViewById(id);
if (textView != null) {
textView.setText(text);
textView.setVisibility(TextUtils.isEmpty(text) ? View.GONE : View.VISIBLE);
diff --git a/src/com/android/settings/applications/AppInfoWithHeader.java b/src/com/android/settings/applications/AppInfoWithHeader.java
index 768a726..2c9599b 100644
--- a/src/com/android/settings/applications/AppInfoWithHeader.java
+++ b/src/com/android/settings/applications/AppInfoWithHeader.java
@@ -16,6 +16,8 @@
package com.android.settings.applications;
+import static com.android.settings.applications.AppHeaderController.ActionType;
+
import android.app.Activity;
import android.os.Bundle;
import android.support.v7.preference.Preference;
@@ -24,8 +26,6 @@
import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.applications.AppUtils;
-import static com.android.settings.applications.AppHeaderController.ActionType;
-
public abstract class AppInfoWithHeader extends AppInfoBase {
private boolean mCreated;
@@ -41,16 +41,16 @@
if (mPackageInfo == null) return;
final Activity activity = getActivity();
final Preference pref = FeatureFactory.getFactory(activity)
- .getApplicationFeatureProvider(activity)
- .newAppHeaderController(this, null /* appHeader */)
- .setIcon(mPackageInfo.applicationInfo.loadIcon(mPm))
- .setLabel(mPackageInfo.applicationInfo.loadLabel(mPm))
- .setSummary(mPackageInfo)
- .setIsInstantApp(AppUtils.isInstant(mPackageInfo.applicationInfo))
- .setPackageName(mPackageName)
- .setUid(mPackageInfo.applicationInfo.uid)
- .setButtonActions(ActionType.ACTION_APP_INFO, ActionType.ACTION_NONE)
- .done(getPrefContext());
+ .getApplicationFeatureProvider(activity)
+ .newAppHeaderController(this, null /* appHeader */)
+ .setIcon(mPackageInfo.applicationInfo.loadIcon(mPm))
+ .setLabel(mPackageInfo.applicationInfo.loadLabel(mPm))
+ .setSummary(mPackageInfo)
+ .setIsInstantApp(AppUtils.isInstant(mPackageInfo.applicationInfo))
+ .setPackageName(mPackageName)
+ .setUid(mPackageInfo.applicationInfo.uid)
+ .setButtonActions(ActionType.ACTION_APP_INFO, ActionType.ACTION_NONE)
+ .done(activity, getPrefContext());
getPreferenceScreen().addPreference(pref);
}
}
diff --git a/src/com/android/settings/applications/FetchPackageStorageAsyncLoader.java b/src/com/android/settings/applications/FetchPackageStorageAsyncLoader.java
index 97e5b7b..b39ec3b 100644
--- a/src/com/android/settings/applications/FetchPackageStorageAsyncLoader.java
+++ b/src/com/android/settings/applications/FetchPackageStorageAsyncLoader.java
@@ -19,6 +19,7 @@
import android.annotation.NonNull;
import android.content.Context;
import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageManager.NameNotFoundException;
import android.os.UserHandle;
import android.util.Log;
@@ -27,6 +28,8 @@
import com.android.settingslib.applications.StorageStatsSource;
import com.android.settingslib.applications.StorageStatsSource.AppStorageStats;
+import java.io.IOException;
+
/**
* Fetches the storage stats using the StorageStatsManager for a given package and user tuple.
*/
@@ -49,7 +52,7 @@
AppStorageStats result = null;
try {
result = mSource.getStatsForPackage(mInfo.volumeUuid, mInfo.packageName, mUser);
- } catch (IllegalStateException e) {
+ } catch (NameNotFoundException | IOException e) {
Log.w(TAG, "Package may have been removed during query, failing gracefully", e);
}
return result;
diff --git a/src/com/android/settings/applications/InstalledAppDetails.java b/src/com/android/settings/applications/InstalledAppDetails.java
index 7510146..09771f2 100755
--- a/src/com/android/settings/applications/InstalledAppDetails.java
+++ b/src/com/android/settings/applications/InstalledAppDetails.java
@@ -16,8 +16,9 @@
package com.android.settings.applications;
+import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
+
import android.Manifest.permission;
-import android.annotation.IdRes;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.AlertDialog;
@@ -115,8 +116,6 @@
import java.util.List;
import java.util.Set;
-import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
-
/**
* Activity to display application information from Settings. This activity presents
* extended information associated with a package like code, data, total size, permissions
@@ -413,12 +412,13 @@
mHeader = (LayoutPreference) findPreference(KEY_HEADER);
mActionButtons = (LayoutPreference) findPreference(KEY_ACTION_BUTTONS);
FeatureFactory.getFactory(activity)
- .getApplicationFeatureProvider(activity)
- .newAppHeaderController(this, mHeader.findViewById(R.id.app_snippet))
- .setPackageName(mPackageName)
- .setButtonActions(AppHeaderController.ActionType.ACTION_STORE_DEEP_LINK,
- AppHeaderController.ActionType.ACTION_APP_PREFERENCE)
- .bindAppHeaderButtons();
+ .getApplicationFeatureProvider(activity)
+ .newAppHeaderController(this, mHeader.findViewById(R.id.app_snippet))
+ .setPackageName(mPackageName)
+ .setButtonActions(AppHeaderController.ActionType.ACTION_STORE_DEEP_LINK,
+ AppHeaderController.ActionType.ACTION_APP_PREFERENCE)
+ .styleActionBar(activity)
+ .bindAppHeaderButtons();
prepareUninstallAndStop();
mNotificationPreference = findPreference(KEY_NOTIFICATION);
@@ -590,7 +590,7 @@
.setIcon(mAppEntry)
.setSummary(summary)
.setIsInstantApp(isInstantApp)
- .done(false /* rebindActions */);
+ .done(activity, false /* rebindActions */);
mVersionPreference.setSummary(getString(R.string.version_text, pkgInfo.versionName));
}
diff --git a/src/com/android/settings/applications/MusicViewHolderController.java b/src/com/android/settings/applications/MusicViewHolderController.java
index 69f8958..1bca26a 100644
--- a/src/com/android/settings/applications/MusicViewHolderController.java
+++ b/src/com/android/settings/applications/MusicViewHolderController.java
@@ -23,15 +23,20 @@
import android.provider.DocumentsContract;
import android.support.annotation.WorkerThread;
import android.text.format.Formatter;
+import android.util.Log;
import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settingslib.applications.StorageStatsSource;
+import java.io.IOException;
+
/**
* MusicViewHolderController controls an Audio/Music file view in the ManageApplications view.
*/
public class MusicViewHolderController implements FileViewHolderController {
+ private static final String TAG = "MusicViewHolderController";
+
private static final String AUTHORITY_MEDIA = "com.android.providers.media.documents";
private Context mContext;
@@ -51,7 +56,12 @@
@Override
@WorkerThread
public void queryStats() {
- mMusicSize = mSource.getExternalStorageStats(mVolumeUuid, mUser).audioBytes;
+ try {
+ mMusicSize = mSource.getExternalStorageStats(mVolumeUuid, mUser).audioBytes;
+ } catch (IOException e) {
+ mMusicSize = 0;
+ Log.w(TAG, e);
+ }
}
@Override
diff --git a/src/com/android/settings/applications/ProcessStatsDetail.java b/src/com/android/settings/applications/ProcessStatsDetail.java
index 9b6f41e..c23da04 100644
--- a/src/com/android/settings/applications/ProcessStatsDetail.java
+++ b/src/com/android/settings/applications/ProcessStatsDetail.java
@@ -16,6 +16,8 @@
package com.android.settings.applications;
+import static com.android.settings.applications.AppHeaderController.ActionType;
+
import android.app.Activity;
import android.app.ActivityManager;
import android.app.ActivityManager.RunningServiceInfo;
@@ -58,8 +60,6 @@
import java.util.HashMap;
import java.util.List;
-import static com.android.settings.applications.AppHeaderController.ActionType;
-
public class ProcessStatsDetail extends SettingsPreferenceFragment {
private static final String TAG = "ProcessStatsDetail";
@@ -137,7 +137,7 @@
? mApp.mUiTargetApp.uid
: UserHandle.USER_NULL)
.setButtonActions(ActionType.ACTION_APP_INFO, ActionType.ACTION_NONE)
- .done(getPrefContext());
+ .done(activity, getPrefContext());
getPreferenceScreen().addPreference(pref);
}
diff --git a/src/com/android/settings/applications/SpecialAppAccessPreferenceController.java b/src/com/android/settings/applications/SpecialAppAccessPreferenceController.java
new file mode 100644
index 0000000..5b05602
--- /dev/null
+++ b/src/com/android/settings/applications/SpecialAppAccessPreferenceController.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. 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.applications;
+
+import android.content.Context;
+import android.support.v7.preference.Preference;
+import com.android.settings.R;
+import com.android.settings.core.PreferenceController;
+import com.android.settings.datausage.DataSaverBackend;
+
+public class SpecialAppAccessPreferenceController extends PreferenceController {
+
+ private static final String KEY_SPECIAL_ACCESS = "special_access";
+
+ private DataSaverBackend mDataSaverBackend;
+
+ public SpecialAppAccessPreferenceController(Context context) {
+ super(context);
+ mDataSaverBackend = new DataSaverBackend(context);
+ }
+
+ @Override
+ public boolean isAvailable() {
+ return true;
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return KEY_SPECIAL_ACCESS;
+ }
+
+ @Override
+ public void updateState(Preference preference) {
+ final int count = mDataSaverBackend.getWhitelistedCount();
+ preference.setSummary(mContext.getResources().getQuantityString(
+ R.plurals.special_access_summary, count, count));
+ }
+}
diff --git a/src/com/android/settings/datausage/AppDataUsage.java b/src/com/android/settings/datausage/AppDataUsage.java
index 0431ce5..e98ca20 100644
--- a/src/com/android/settings/datausage/AppDataUsage.java
+++ b/src/com/android/settings/datausage/AppDataUsage.java
@@ -14,6 +14,8 @@
package com.android.settings.datausage;
+import static android.net.NetworkPolicyManager.POLICY_REJECT_METERED_BACKGROUND;
+
import android.app.Activity;
import android.app.LoaderManager;
import android.content.Context;
@@ -57,8 +59,6 @@
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
-import static android.net.NetworkPolicyManager.POLICY_REJECT_METERED_BACKGROUND;
-
public class AppDataUsage extends DataUsageBase implements Preference.OnPreferenceChangeListener,
DataSaverBackend.Listener {
@@ -362,7 +362,7 @@
.setUid(uid)
.setButtonActions(AppHeaderController.ActionType.ACTION_APP_INFO,
AppHeaderController.ActionType.ACTION_NONE)
- .done(getPrefContext());
+ .done(activity, getPrefContext());
getPreferenceScreen().addPreference(pref);
}
diff --git a/src/com/android/settings/deviceinfo/PrivateVolumeSettings.java b/src/com/android/settings/deviceinfo/PrivateVolumeSettings.java
index b5d7ddf..10df004 100644
--- a/src/com/android/settings/deviceinfo/PrivateVolumeSettings.java
+++ b/src/com/android/settings/deviceinfo/PrivateVolumeSettings.java
@@ -59,7 +59,6 @@
import com.android.settings.Utils;
import com.android.settings.applications.ManageApplications;
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
-import com.android.settings.deletionhelper.AutomaticStorageManagerSettings;
import com.android.settings.deviceinfo.StorageSettings.MountTask;
import com.android.settingslib.deviceinfo.StorageMeasurement;
import com.android.settingslib.deviceinfo.StorageMeasurement.MeasurementDetails;
@@ -126,7 +125,6 @@
private int mItemPoolIndex;
private Preference mExplore;
- private Preference mAutomaticStorageManagement;
private boolean mNeedsUpdate;
@@ -185,7 +183,6 @@
mCurrentUser = mUserManager.getUserInfo(UserHandle.myUserId());
mExplore = buildAction(R.string.storage_menu_explore);
- mAutomaticStorageManagement = buildAction(R.string.storage_menu_manage);
mNeedsUpdate = true;
@@ -212,9 +209,6 @@
screen.removeAll();
- if (getResources().getBoolean(R.bool.config_storage_manager_settings_enabled)) {
- addPreference(screen, mAutomaticStorageManagement);
- }
addPreference(screen, mSummary);
List<UserInfo> allUsers = mUserManager.getUsers();
@@ -331,6 +325,7 @@
private StorageItemPreference buildItem() {
final StorageItemPreference item = new StorageItemPreference(getPrefContext());
+ item.setIcon(R.drawable.empty_icon);
return item;
}
@@ -511,11 +506,6 @@
case R.string.storage_menu_explore: {
intent = mSharedVolume.buildBrowseIntent();
} break;
- case R.string.storage_menu_manage: {
- startFragment(this, AutomaticStorageManagerSettings.class.getCanonicalName(),
- R.string.automatic_storage_manager_settings, 0, null);
- return true;
- }
case 0: {
UserInfoFragment.show(this, pref.getTitle(), pref.getSummary());
return true;
diff --git a/src/com/android/settings/deviceinfo/StorageDashboardFragment.java b/src/com/android/settings/deviceinfo/StorageDashboardFragment.java
index bc64ffa..f7bb95d 100644
--- a/src/com/android/settings/deviceinfo/StorageDashboardFragment.java
+++ b/src/com/android/settings/deviceinfo/StorageDashboardFragment.java
@@ -16,6 +16,7 @@
package com.android.settings.deviceinfo;
+import android.app.Activity;
import android.app.LoaderManager;
import android.content.Context;
import android.content.Intent;
@@ -78,16 +79,15 @@
super.onCreate(icicle);
// Initialize the storage sizes that we can quickly calc.
- final Context context = getActivity();
- StorageManager sm = context.getSystemService(StorageManager.class);
+ final Activity activity = getActivity();
+ StorageManager sm = activity.getSystemService(StorageManager.class);
mVolume = Utils.maybeInitializeVolume(sm, getArguments());
if (mVolume == null) {
- getActivity().finish();
+ activity.finish();
return;
}
- mOptionMenuController = new PrivateVolumeOptionMenuController(
- context, mVolume, new PackageManagerWrapperImpl(context.getPackageManager()));
+ initializeOptionsMenu(activity);
final long sharedDataSize = mVolume.getPath().getTotalSpace();
long totalSize = sm.getPrimaryStorageSize();
@@ -114,6 +114,15 @@
}
}
+ @VisibleForTesting
+ void initializeOptionsMenu(Activity activity) {
+ mOptionMenuController = new PrivateVolumeOptionMenuController(
+ activity, mVolume, new PackageManagerWrapperImpl(activity.getPackageManager()));
+ getLifecycle().addObserver(mOptionMenuController);
+ setHasOptionsMenu(true);
+ activity.invalidateOptionsMenu();
+ }
+
@Override
public void onResume() {
super.onResume();
@@ -156,7 +165,6 @@
new AutomaticStorageManagementSwitchPreferenceController(
context, mMetricsFeatureProvider, getFragmentManager());
getLifecycle().addObserver(asmController);
- getLifecycle().addObserver(mOptionMenuController);
controllers.add(asmController);
return controllers;
}
diff --git a/src/com/android/settings/deviceinfo/storage/StorageAsyncLoader.java b/src/com/android/settings/deviceinfo/storage/StorageAsyncLoader.java
index cf0239d..8652804 100644
--- a/src/com/android/settings/deviceinfo/storage/StorageAsyncLoader.java
+++ b/src/com/android/settings/deviceinfo/storage/StorageAsyncLoader.java
@@ -23,6 +23,7 @@
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.UserInfo;
+import android.content.pm.PackageManager.NameNotFoundException;
import android.os.UserHandle;
import android.util.Log;
import android.util.SparseArray;
@@ -32,6 +33,7 @@
import com.android.settings.utils.AsyncLoader;
import com.android.settingslib.applications.StorageStatsSource;
+import java.io.IOException;
import java.util.List;
/**
@@ -83,7 +85,7 @@
StorageStatsSource.AppStorageStats stats;
try {
stats = mStatsManager.getStatsForPackage(mUuid, app.packageName, myUser);
- } catch (IllegalStateException e) {
+ } catch (NameNotFoundException | IOException e) {
// This may happen if the package was removed during our calculation.
Log.w("App unexpectedly not found", e);
continue;
@@ -122,7 +124,11 @@
}
Log.d(TAG, "Loading external stats");
- result.externalStats = mStatsManager.getExternalStorageStats(mUuid, UserHandle.of(userId));
+ try {
+ result.externalStats = mStatsManager.getExternalStorageStats(mUuid, UserHandle.of(userId));
+ } catch (IOException e) {
+ Log.w(TAG, e);
+ }
Log.d(TAG, "Obtaining result completed");
return result;
}
diff --git a/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetail.java b/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetail.java
index 2f8e28e..0c798a6 100644
--- a/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetail.java
+++ b/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetail.java
@@ -17,16 +17,12 @@
package com.android.settings.fuelgauge;
import android.app.Activity;
-import android.app.AlertDialog;
-import android.app.Dialog;
import android.app.admin.DevicePolicyManager;
import android.content.Context;
-import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.BatteryStats;
import android.os.Bundle;
-import android.os.SystemClock;
import android.os.UserHandle;
import android.os.UserManager;
import android.support.annotation.VisibleForTesting;
@@ -179,7 +175,7 @@
@VisibleForTesting
void initHeader() {
final View appSnippet = mHeaderPreference.findViewById(R.id.app_snippet);
- final Context context = getContext();
+ final Activity context = getActivity();
final Bundle bundle = getArguments();
AppHeaderController controller = FeatureFactory.getFactory(context)
.getApplicationFeatureProvider(context)
@@ -203,7 +199,7 @@
controller.setSummary(getString(Utils.getInstallationStatus(mAppEntry.info)));
}
- controller.done(true /* rebindActions */);
+ controller.done(context, true /* rebindActions */);
}
@Override
diff --git a/src/com/android/settings/fuelgauge/BatteryBroadcastReceiver.java b/src/com/android/settings/fuelgauge/BatteryBroadcastReceiver.java
new file mode 100644
index 0000000..9d37333
--- /dev/null
+++ b/src/com/android/settings/fuelgauge/BatteryBroadcastReceiver.java
@@ -0,0 +1,87 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * 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.fuelgauge;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.support.annotation.VisibleForTesting;
+
+import com.android.settings.Utils;
+
+/**
+ * Use this broadcastReceiver to listen to the battery change, and it will invoke
+ * {@link OnBatteryChangedListener} if any of the following happens:
+ *
+ * 1. Battery level has been changed
+ * 2. Battery status has been changed
+ */
+public class BatteryBroadcastReceiver extends BroadcastReceiver {
+
+ interface OnBatteryChangedListener {
+ void onBatteryChanged();
+ }
+
+ @VisibleForTesting
+ String mBatteryLevel;
+ @VisibleForTesting
+ String mBatteryStatus;
+ private OnBatteryChangedListener mBatteryListener;
+ private Context mContext;
+
+ public BatteryBroadcastReceiver(Context context) {
+ mContext = context;
+ }
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ String action = intent.getAction();
+ if (mBatteryListener != null && Intent.ACTION_BATTERY_CHANGED.equals(action)
+ && updateBatteryStatus(intent)) {
+ mBatteryListener.onBatteryChanged();
+ }
+ }
+
+ public void setBatteryChangedListener(OnBatteryChangedListener lsn) {
+ mBatteryListener = lsn;
+ }
+
+ public void register() {
+ mContext.registerReceiver(this,
+ new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
+ }
+
+ public void unRegister() {
+ mContext.unregisterReceiver(this);
+ }
+
+ private boolean updateBatteryStatus(Intent intent) {
+ if (intent != null) {
+ String batteryLevel = Utils.getBatteryPercentage(intent);
+ String batteryStatus = Utils.getBatteryStatus(
+ mContext.getResources(), intent);
+ if (!batteryLevel.equals(mBatteryLevel) || !batteryStatus.equals(mBatteryStatus)) {
+ mBatteryLevel = batteryLevel;
+ mBatteryStatus = batteryStatus;
+ return true;
+ }
+ }
+ return false;
+ }
+
+}
\ No newline at end of file
diff --git a/src/com/android/settings/fuelgauge/PowerUsageBase.java b/src/com/android/settings/fuelgauge/PowerUsageBase.java
index 0236a30..1d9a228 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageBase.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageBase.java
@@ -45,9 +45,7 @@
protected BatteryStatsHelper mStatsHelper;
protected UserManager mUm;
-
- private String mBatteryLevel;
- private String mBatteryStatus;
+ private BatteryBroadcastReceiver mBatteryBroadcastReceiver;
@Override
public void onAttach(Activity activity) {
@@ -61,6 +59,13 @@
super.onCreate(icicle);
mStatsHelper.create(icicle);
setHasOptionsMenu(true);
+
+ mBatteryBroadcastReceiver = new BatteryBroadcastReceiver(getContext());
+ mBatteryBroadcastReceiver.setBatteryChangedListener(() -> {
+ if (!mHandler.hasMessages(MSG_REFRESH_STATS)) {
+ mHandler.sendEmptyMessageDelayed(MSG_REFRESH_STATS, 500);
+ }
+ });
}
@Override
@@ -73,8 +78,7 @@
public void onResume() {
super.onResume();
BatteryStatsHelper.dropFile(getActivity(), BatteryHistoryDetail.BATTERY_HISTORY_FILE);
- updateBatteryStatus(getActivity().registerReceiver(mBatteryInfoReceiver,
- new IntentFilter(Intent.ACTION_BATTERY_CHANGED)));
+ mBatteryBroadcastReceiver.register();
if (mHandler.hasMessages(MSG_REFRESH_STATS)) {
mHandler.removeMessages(MSG_REFRESH_STATS);
mStatsHelper.clearStats();
@@ -84,7 +88,7 @@
@Override
public void onPause() {
super.onPause();
- getActivity().unregisterReceiver(mBatteryInfoReceiver);
+ mBatteryBroadcastReceiver.unRegister();
}
@Override
@@ -109,20 +113,6 @@
historyPref.setStats(mStatsHelper);
}
- private boolean updateBatteryStatus(Intent intent) {
- if (intent != null) {
- String batteryLevel = com.android.settings.Utils.getBatteryPercentage(intent);
- String batteryStatus = com.android.settings.Utils.getBatteryStatus(getResources(),
- intent);
- if (!batteryLevel.equals(mBatteryLevel) || !batteryStatus.equals(mBatteryStatus)) {
- mBatteryLevel = batteryLevel;
- mBatteryStatus = batteryStatus;
- return true;
- }
- }
- return false;
- }
-
static final int MSG_REFRESH_STATS = 100;
private final Handler mHandler = new Handler() {
@@ -137,17 +127,4 @@
}
};
- private BroadcastReceiver mBatteryInfoReceiver = new BroadcastReceiver() {
- @Override
- public void onReceive(Context context, Intent intent) {
- String action = intent.getAction();
- if (Intent.ACTION_BATTERY_CHANGED.equals(action)
- && updateBatteryStatus(intent)) {
- if (!mHandler.hasMessages(MSG_REFRESH_STATS)) {
- mHandler.sendEmptyMessageDelayed(MSG_REFRESH_STATS, 500);
- }
- }
- }
- };
-
}
diff --git a/src/com/android/settings/fuelgauge/PowerUsageSummary.java b/src/com/android/settings/fuelgauge/PowerUsageSummary.java
index ac041b8..5f12d7c 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageSummary.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageSummary.java
@@ -683,22 +683,28 @@
private static class SummaryProvider implements SummaryLoader.SummaryProvider {
private final Context mContext;
private final SummaryLoader mLoader;
+ private final BatteryBroadcastReceiver mBatteryBroadcastReceiver;
private SummaryProvider(Context context, SummaryLoader loader) {
mContext = context;
mLoader = loader;
- }
-
- @Override
- public void setListening(boolean listening) {
- if (listening) {
- // TODO: Listen.
+ mBatteryBroadcastReceiver = new BatteryBroadcastReceiver(mContext);
+ mBatteryBroadcastReceiver.setBatteryChangedListener(() -> {
BatteryInfo.getBatteryInfo(mContext, new BatteryInfo.Callback() {
@Override
public void onBatteryInfoLoaded(BatteryInfo info) {
mLoader.setSummary(SummaryProvider.this, info.chargeLabelString);
}
});
+ });
+ }
+
+ @Override
+ public void setListening(boolean listening) {
+ if (listening) {
+ mBatteryBroadcastReceiver.register();
+ } else {
+ mBatteryBroadcastReceiver.unRegister();
}
}
}
diff --git a/src/com/android/settings/notification/AppNotificationSettings.java b/src/com/android/settings/notification/AppNotificationSettings.java
index e359da6..8f7f2c5 100644
--- a/src/com/android/settings/notification/AppNotificationSettings.java
+++ b/src/com/android/settings/notification/AppNotificationSettings.java
@@ -49,7 +49,6 @@
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
-import java.util.Objects;
/** These settings are per app, so should not be returned in global search results. */
public class AppNotificationSettings extends NotificationSettingsBase {
@@ -109,8 +108,9 @@
}
}.execute();
- final Preference pref = FeatureFactory.getFactory(getActivity())
- .getApplicationFeatureProvider(getActivity())
+ final Activity activity = getActivity();
+ final Preference pref = FeatureFactory.getFactory(activity)
+ .getApplicationFeatureProvider(activity)
.newAppHeaderController(this /* fragment */, null /* appHeader */)
.setIcon(mAppRow.icon)
.setLabel(mAppRow.label)
@@ -118,7 +118,7 @@
.setUid(mAppRow.uid)
.setButtonActions(AppHeaderController.ActionType.ACTION_APP_INFO,
AppHeaderController.ActionType.ACTION_NOTIF_PREFERENCE)
- .done(getPrefContext());
+ .done(activity, getPrefContext());
getPreferenceScreen().addPreference(pref);
if (mUid < 0 || TextUtils.isEmpty(mPkg) || mPkgInfo == null) {
diff --git a/src/com/android/settings/notification/ChannelNotificationSettings.java b/src/com/android/settings/notification/ChannelNotificationSettings.java
index bec4845..c115672 100644
--- a/src/com/android/settings/notification/ChannelNotificationSettings.java
+++ b/src/com/android/settings/notification/ChannelNotificationSettings.java
@@ -21,6 +21,7 @@
import static android.app.NotificationManager.IMPORTANCE_MIN;
import static android.app.NotificationManager.IMPORTANCE_NONE;
+import android.app.Activity;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
@@ -111,8 +112,9 @@
setupBlockAndImportance();
updateDependents();
}
- final Preference pref = FeatureFactory.getFactory(getActivity())
- .getApplicationFeatureProvider(getActivity())
+ final Activity activity = getActivity();
+ final Preference pref = FeatureFactory.getFactory(activity)
+ .getApplicationFeatureProvider(activity)
.newAppHeaderController(this /* fragment */, null /* appHeader */)
.setIcon(mAppRow.icon)
.setLabel(mChannel.getName())
@@ -121,7 +123,7 @@
.setUid(mAppRow.uid)
.setButtonActions(AppHeaderController.ActionType.ACTION_APP_INFO,
AppHeaderController.ActionType.ACTION_NOTIF_PREFERENCE)
- .done(getPrefContext());
+ .done(activity, getPrefContext());
getPreferenceScreen().addPreference(pref);
if (mAppRow.settingsIntent != null) {
diff --git a/src/com/android/settings/notification/RedactionInterstitial.java b/src/com/android/settings/notification/RedactionInterstitial.java
index 08474a0..b269062 100644
--- a/src/com/android/settings/notification/RedactionInterstitial.java
+++ b/src/com/android/settings/notification/RedactionInterstitial.java
@@ -16,7 +16,11 @@
package com.android.settings.notification;
-import android.app.admin.DevicePolicyManager;
+import static android.app.admin.DevicePolicyManager.KEYGUARD_DISABLE_SECURE_NOTIFICATIONS;
+import static android.app.admin.DevicePolicyManager.KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS;
+
+import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
+
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
@@ -26,7 +30,6 @@
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
-import android.widget.CompoundButton;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
@@ -34,18 +37,13 @@
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
-import com.android.settings.RestrictedCheckBox;
import com.android.settings.RestrictedRadioButton;
import com.android.settings.SettingsActivity;
import com.android.settings.SettingsPreferenceFragment;
+import com.android.settings.SetupRedactionInterstitial;
import com.android.settings.Utils;
import com.android.settingslib.RestrictedLockUtils;
-import static android.app.admin.DevicePolicyManager.KEYGUARD_DISABLE_SECURE_NOTIFICATIONS;
-import static android.app.admin.DevicePolicyManager.KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS;
-
-import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
-
public class RedactionInterstitial extends SettingsActivity {
@Override
@@ -128,6 +126,7 @@
@Override
public void onClick(View v) {
if (v.getId() == R.id.redaction_done_button) {
+ SetupRedactionInterstitial.setEnabled(getContext(), false);
final RedactionInterstitial activity = (RedactionInterstitial) getActivity();
if (activity != null) {
activity.setResult(RESULT_OK, null);
diff --git a/src/com/android/settings/wallpaper/WallpaperTypeSettings.java b/src/com/android/settings/wallpaper/WallpaperTypeSettings.java
index 6efdcf72..bef4777 100644
--- a/src/com/android/settings/wallpaper/WallpaperTypeSettings.java
+++ b/src/com/android/settings/wallpaper/WallpaperTypeSettings.java
@@ -67,7 +67,6 @@
// Add Preference items for each of the matching activities
for (ResolveInfo info : rList) {
Preference pref = new Preference(getPrefContext());
- pref.setLayoutResource(R.layout.preference_wallpaper_type);
Intent prefIntent = new Intent(intent);
prefIntent.setComponent(new ComponentName(
info.activityInfo.packageName, info.activityInfo.name));
diff --git a/src/com/android/settings/wifi/WifiWakeupPreferenceController.java b/src/com/android/settings/wifi/WifiWakeupPreferenceController.java
index 122e524..2c33fc5 100644
--- a/src/com/android/settings/wifi/WifiWakeupPreferenceController.java
+++ b/src/com/android/settings/wifi/WifiWakeupPreferenceController.java
@@ -26,6 +26,7 @@
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
import android.text.TextUtils;
+import com.android.settings.R;
import com.android.settings.core.PreferenceController;
import com.android.settings.core.lifecycle.Lifecycle;
@@ -97,10 +98,20 @@
return;
}
final SwitchPreference enableWifiWakeup = (SwitchPreference) preference;
+
enableWifiWakeup.setChecked(Settings.Global.getInt(mContext.getContentResolver(),
Settings.Global.WIFI_WAKEUP_ENABLED, 0) == 1);
- enableWifiWakeup.setEnabled(Settings.Global.getInt(mContext.getContentResolver(),
- Settings.Global.NETWORK_RECOMMENDATIONS_ENABLED, 0) == 1);
+
+ boolean wifiScanningEnabled = Settings.Global.getInt(mContext.getContentResolver(),
+ Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 0) == 1;
+ boolean networkRecommendationsEnabled = Settings.Global.getInt(
+ mContext.getContentResolver(),
+ Settings.Global.NETWORK_RECOMMENDATIONS_ENABLED, 0) == 1;
+ enableWifiWakeup.setEnabled(networkRecommendationsEnabled && wifiScanningEnabled);
+
+ enableWifiWakeup.setSummary(wifiScanningEnabled ?
+ R.string.wifi_wakeup_summary :
+ R.string.wifi_wakeup_summary_scanning_disabled);
}
class SettingObserver extends ContentObserver {
diff --git a/tests/robotests/src/com/android/settings/applications/AppHeaderControllerTest.java b/tests/robotests/src/com/android/settings/applications/AppHeaderControllerTest.java
index 0d878ed..030978f 100644
--- a/tests/robotests/src/com/android/settings/applications/AppHeaderControllerTest.java
+++ b/tests/robotests/src/com/android/settings/applications/AppHeaderControllerTest.java
@@ -17,6 +17,15 @@
package com.android.settings.applications;
+import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyInt;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.app.ActionBar;
import android.app.Activity;
import android.app.Fragment;
import android.content.Context;
@@ -24,6 +33,7 @@
import android.content.pm.ActivityInfo;
import android.content.pm.PackageInfo;
import android.content.pm.ResolveInfo;
+import android.graphics.drawable.Drawable;
import android.os.UserHandle;
import android.support.v7.preference.Preference;
import android.view.LayoutInflater;
@@ -34,7 +44,6 @@
import com.android.settings.R;
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
-import com.android.settingslib.applications.ApplicationsState;
import org.junit.Before;
import org.junit.Test;
@@ -45,14 +54,6 @@
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
-import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyInt;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class AppHeaderControllerTest {
@@ -60,11 +61,9 @@
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private Context mContext;
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
- private ApplicationsState.AppEntry mAppEntry;
+ private Activity mActivity;
@Mock
private Fragment mFragment;
- @Mock
- private View mAppHeader;
private Context mShadowContext;
private LayoutInflater mLayoutInflater;
@@ -85,7 +84,7 @@
@Test
public void testBuildView_constructedWithoutView_shouldCreateNewView() {
mController = new AppHeaderController(mShadowContext, mFragment, null);
- View view = mController.done();
+ View view = mController.done(mActivity);
assertThat(view).isNotNull();
}
@@ -93,7 +92,7 @@
@Test
public void testBuildView_withContext_shouldBuildPreference() {
mController = new AppHeaderController(mShadowContext, mFragment, null);
- Preference preference = mController.done(mShadowContext);
+ Preference preference = mController.done(mActivity, mShadowContext);
assertThat(preference instanceof LayoutPreference).isTrue();
}
@@ -102,7 +101,7 @@
public void testBuildView_constructedWithView_shouldReturnSameView() {
View inputView = mLayoutInflater.inflate(R.layout.app_details, null /* root */);
mController = new AppHeaderController(mShadowContext, mFragment, inputView);
- View view = mController.done();
+ View view = mController.done(mActivity);
assertThat(view).isSameAs(inputView);
}
@@ -111,14 +110,14 @@
public void bindViews_shouldBindAllData() {
final String testString = "test";
final View appHeader = mLayoutInflater.inflate(R.layout.app_details, null /* root */);
- final TextView label = (TextView) appHeader.findViewById(R.id.app_detail_title);
- final TextView version = (TextView) appHeader.findViewById(R.id.app_detail_summary);
+ final TextView label = appHeader.findViewById(R.id.app_detail_title);
+ final TextView version = appHeader.findViewById(R.id.app_detail_summary);
mController = new AppHeaderController(mShadowContext, mFragment, appHeader);
mController.setLabel(testString);
mController.setSummary(testString);
mController.setIcon(mShadowContext.getDrawable(R.drawable.ic_add));
- mController.done();
+ mController.done(mActivity);
assertThat(label.getText()).isEqualTo(testString);
assertThat(version.getText()).isEqualTo(testString);
@@ -139,7 +138,7 @@
mController.setButtonActions(
AppHeaderController.ActionType.ACTION_APP_PREFERENCE,
AppHeaderController.ActionType.ACTION_NONE);
- mController.done();
+ mController.done(mActivity);
assertThat(appLinks.findViewById(R.id.left_button).getVisibility())
.isEqualTo(View.VISIBLE);
@@ -164,7 +163,7 @@
mController.setButtonActions(
AppHeaderController.ActionType.ACTION_APP_PREFERENCE,
AppHeaderController.ActionType.ACTION_NONE);
- mController.done();
+ mController.done(mActivity);
assertThat(appLinks.findViewById(R.id.left_button).getVisibility())
.isEqualTo(View.GONE);
@@ -183,7 +182,7 @@
mController.setButtonActions(
AppHeaderController.ActionType.ACTION_STORE_DEEP_LINK,
AppHeaderController.ActionType.ACTION_NONE);
- mController.done();
+ mController.done(mActivity);
assertThat(appLinks.findViewById(R.id.left_button).getVisibility())
.isEqualTo(View.GONE);
@@ -201,7 +200,7 @@
.setButtonActions(
AppHeaderController.ActionType.ACTION_APP_INFO,
AppHeaderController.ActionType.ACTION_NONE);
- mController.done();
+ mController.done(mActivity);
assertThat(appLinks.findViewById(R.id.left_button).getVisibility())
.isEqualTo(View.GONE);
@@ -221,7 +220,7 @@
.setButtonActions(
AppHeaderController.ActionType.ACTION_APP_INFO,
AppHeaderController.ActionType.ACTION_NOTIF_PREFERENCE);
- mController.done();
+ mController.done(mActivity);
assertThat(appLinks.findViewById(R.id.left_button).getVisibility())
.isEqualTo(View.VISIBLE);
@@ -242,7 +241,7 @@
.setButtonActions(
AppHeaderController.ActionType.ACTION_APP_INFO,
AppHeaderController.ActionType.ACTION_NOTIF_PREFERENCE);
- mController.done();
+ mController.done(mActivity);
assertThat(appLinks.findViewById(R.id.left_button).getContentDescription())
.isEqualTo("App Info");
@@ -258,7 +257,7 @@
.setButtonActions(
AppHeaderController.ActionType.ACTION_NOTIF_PREFERENCE,
AppHeaderController.ActionType.ACTION_NONE);
- mController.done();
+ mController.done(mActivity);
assertThat(appLinks.findViewById(R.id.left_button).getVisibility())
.isEqualTo(View.VISIBLE);
@@ -272,7 +271,7 @@
public void instantApps_normalAppsDontGetLabel() {
final View appHeader = mLayoutInflater.inflate(R.layout.app_details, null /* root */);
mController = new AppHeaderController(mContext, mFragment, appHeader);
- mController.done();
+ mController.done(mActivity);
assertThat(appHeader.findViewById(R.id.install_type).getVisibility())
.isEqualTo(View.GONE);
}
@@ -283,7 +282,7 @@
public void instantApps_normalAppsDontGetInstantAppsBadge() {
final View appHeader = mLayoutInflater.inflate(R.layout.app_details, null /* root */);
mController = new AppHeaderController(mContext, mFragment, appHeader);
- mController.done();
+ mController.done(mActivity);
assertThat(appHeader.findViewById(R.id.app_icon_instant_apps_badge).getVisibility())
.isEqualTo(View.GONE);
}
@@ -294,8 +293,8 @@
final View appHeader = mLayoutInflater.inflate(R.layout.app_details, null /* root */);
mController = new AppHeaderController(mContext, mFragment, appHeader);
mController.setIsInstantApp(true);
- mController.done();
- TextView label = (TextView)appHeader.findViewById(R.id.install_type);
+ mController.done(mActivity);
+ TextView label = appHeader.findViewById(R.id.install_type);
ImageView badgeView = appHeader.findViewById(R.id.app_icon_instant_apps_badge);
assertThat(badgeView.getVisibility()).isEqualTo(View.VISIBLE);
assertThat(label.getVisibility()).isEqualTo(View.VISIBLE);
@@ -306,6 +305,29 @@
}
@Test
+ public void styleActionBar_invalidObjects_shouldNotCrash() {
+ mController = new AppHeaderController(mShadowContext, mFragment, null);
+ mController.styleActionBar(null);
+
+ when(mActivity.getActionBar()).thenReturn(null);
+ mController.styleActionBar(mActivity);
+
+ verify(mActivity).getActionBar();
+ }
+
+ @Test
+ public void styleActionBar_setElevationAndBackground() {
+ final ActionBar actionBar = mActivity.getActionBar();
+
+ mController = new AppHeaderController(mShadowContext, mFragment, null);
+ mController.styleActionBar(mActivity);
+
+ verify(actionBar).setElevation(0);
+ verify(actionBar).setBackgroundDrawable(any(Drawable.class));
+ }
+
+
+ @Test
public void initAppHeaderController_appHeaderNull_useFragmentContext() {
mController = new AppHeaderController(mContext, mFragment, null);
diff --git a/tests/robotests/src/com/android/settings/applications/FetchPackageStorageAsyncLoaderTest.java b/tests/robotests/src/com/android/settings/applications/FetchPackageStorageAsyncLoaderTest.java
index 04eeb02..36116c0 100644
--- a/tests/robotests/src/com/android/settings/applications/FetchPackageStorageAsyncLoaderTest.java
+++ b/tests/robotests/src/com/android/settings/applications/FetchPackageStorageAsyncLoaderTest.java
@@ -40,6 +40,8 @@
import org.mockito.MockitoAnnotations;
import org.robolectric.annotation.Config;
+import java.io.IOException;
+
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class FetchPackageStorageAsyncLoaderTest {
@@ -56,7 +58,7 @@
}
@Test
- public void worksForValidPackageNameAndUid() {
+ public void worksForValidPackageNameAndUid() throws Exception {
AppStorageStats stats = mock(AppStorageStats.class);
when(stats.getCodeBytes()).thenReturn(1L);
when(stats.getDataBytes()).thenReturn(2L);
@@ -72,9 +74,9 @@
}
@Test
- public void installerExceptionHandledCleanly() {
+ public void installerExceptionHandledCleanly() throws Exception {
when(mSource.getStatsForPackage(anyString(), anyString(), any(UserHandle.class))).
- thenThrow(new IllegalStateException("intentional failure"));
+ thenThrow(new IOException("intentional failure"));
ApplicationInfo info = new ApplicationInfo();
info.packageName = PACKAGE_NAME;
FetchPackageStorageAsyncLoader task = new FetchPackageStorageAsyncLoader(
diff --git a/tests/robotests/src/com/android/settings/applications/MusicViewHolderControllerTest.java b/tests/robotests/src/com/android/settings/applications/MusicViewHolderControllerTest.java
index 9bc7482..6440141 100644
--- a/tests/robotests/src/com/android/settings/applications/MusicViewHolderControllerTest.java
+++ b/tests/robotests/src/com/android/settings/applications/MusicViewHolderControllerTest.java
@@ -81,7 +81,7 @@
}
@Test
- public void storageShouldRepresentStorageStatsQuery() {
+ public void storageShouldRepresentStorageStatsQuery() throws Exception {
when(mSource.getExternalStorageStats(any(String.class), any(UserHandle.class))).thenReturn(
new StorageStatsSource.ExternalStorageStats(1, 1, 0, 0));
diff --git a/tests/robotests/src/com/android/settings/applications/SpecialAppAccessPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/applications/SpecialAppAccessPreferenceControllerTest.java
new file mode 100644
index 0000000..44ca9f7
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/applications/SpecialAppAccessPreferenceControllerTest.java
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * 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.applications;
+
+import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.support.v7.preference.Preference;
+import com.android.settings.R;
+import com.android.settings.SettingsRobolectricTestRunner;
+import com.android.settings.TestConfig;
+import com.android.settings.datausage.DataSaverBackend;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+import org.robolectric.util.ReflectionHelpers;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class SpecialAppAccessPreferenceControllerTest {
+ private Context mContext;
+ @Mock
+ private DataSaverBackend mBackend;
+ @Mock
+ private Preference mPreference;
+
+ private SpecialAppAccessPreferenceController mController;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = RuntimeEnvironment.application;
+ mController = new SpecialAppAccessPreferenceController(mContext);
+ ReflectionHelpers.setField(mController, "mDataSaverBackend", mBackend);
+ }
+
+ @Test
+ public void isAvailable_shouldAlwaysReturnTrue() {
+ assertThat(mController.isAvailable()).isTrue();
+ }
+
+ @Test
+ public void updateState_shouldSetSummary() {
+ when(mBackend.getWhitelistedCount()).thenReturn(0);
+
+ mController.updateState(mPreference);
+
+ verify(mPreference).setSummary(mContext.getResources().getQuantityString(
+ R.plurals.special_access_summary, 0, 0));
+
+ when(mBackend.getWhitelistedCount()).thenReturn(1);
+
+ mController.updateState(mPreference);
+
+ verify(mPreference).setSummary(mContext.getResources().getQuantityString(
+ R.plurals.special_access_summary, 1, 1));
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/StorageDashboardFragmentTest.java b/tests/robotests/src/com/android/settings/deviceinfo/StorageDashboardFragmentTest.java
index b3253f9..0c9988b 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/StorageDashboardFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/StorageDashboardFragmentTest.java
@@ -18,6 +18,10 @@
import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+import android.app.Activity;
import android.os.storage.StorageManager;
import android.provider.SearchIndexableResource;
@@ -56,6 +60,15 @@
}
@Test
+ public void test_initializeOptionsMenuInvalidatesExistingMenu() {
+ Activity activity = mock(Activity.class);
+
+ mFragment.initializeOptionsMenu(activity);
+
+ verify(activity).invalidateOptionsMenu();
+ }
+
+ @Test
public void testSearchIndexProvider_shouldIndexResource() {
final List<SearchIndexableResource> indexRes =
StorageDashboardFragment.SEARCH_INDEX_DATA_PROVIDER.getXmlResourcesToIndex(
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/StorageSettingsTest.java b/tests/robotests/src/com/android/settings/deviceinfo/StorageSettingsTest.java
index 95f9fbe..17abab1 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/StorageSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/StorageSettingsTest.java
@@ -70,7 +70,7 @@
}
@Test
- public void updateSummary_shouldDisplayUsedPercentAndFreeSpace() {
+ public void updateSummary_shouldDisplayUsedPercentAndFreeSpace() throws Exception {
final SummaryLoader loader = mock(SummaryLoader.class);
final SummaryLoader.SummaryProvider provider =
StorageSettings.SUMMARY_PROVIDER_FACTORY.createSummaryProvider(mActivity, loader);
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetailTest.java b/tests/robotests/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetailTest.java
index 03892a3..801034c 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetailTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetailTest.java
@@ -17,7 +17,18 @@
package com.android.settings.fuelgauge;
import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Matchers.any;
+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.Mockito.doAnswer;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import android.app.Activity;
import android.app.Fragment;
import android.content.Context;
import android.content.pm.ApplicationInfo;
@@ -25,12 +36,12 @@
import android.graphics.drawable.Drawable;
import android.os.BatteryStats;
import android.os.Bundle;
-import android.os.UserHandle;
import android.view.View;
import com.android.internal.os.BatterySipper;
import com.android.internal.os.BatteryStatsHelper;
import com.android.settings.SettingsActivity;
+import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
import com.android.settings.applications.AppHeaderController;
import com.android.settings.applications.LayoutPreference;
@@ -46,22 +57,10 @@
import org.mockito.MockitoAnnotations;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
-import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import org.robolectric.util.ReflectionHelpers;
-import static org.mockito.Matchers.anyLong;
-import static org.mockito.Matchers.anyInt;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.doAnswer;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.verify;
-
-@RunWith(RobolectricTestRunner.class)
+@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class AdvancedPowerUsageDetailTest {
private static final String APP_LABEL = "app label";
@@ -77,6 +76,8 @@
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private Context mContext;
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ private Activity mActivity;
@Mock
private AppHeaderController mAppHeaderController;
@Mock
@@ -86,8 +87,6 @@
@Mock
private ApplicationsState.AppEntry mAppEntry;
@Mock
- private Drawable mIconDrawable;
- @Mock
private Bundle mBundle;
@Mock
private BatteryEntry mBatteryEntry;
@@ -111,6 +110,7 @@
mFragment = spy(new AdvancedPowerUsageDetail());
doReturn(mContext).when(mFragment).getContext();
+ doReturn(mActivity).when(mFragment).getActivity();
doReturn(SUMMARY).when(mFragment).getString(anyInt());
doReturn(APP_LABEL).when(mBundle).getString(anyString());
doReturn(mBundle).when(mFragment).getArguments();
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryBroadcastReceiverTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryBroadcastReceiverTest.java
new file mode 100644
index 0000000..799dab9
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryBroadcastReceiverTest.java
@@ -0,0 +1,95 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * 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.fuelgauge;
+
+import android.content.Context;
+import android.content.Intent;
+import android.os.BatteryManager;
+
+import com.android.settings.SettingsRobolectricTestRunner;
+import com.android.settings.TestConfig;
+import com.android.settings.Utils;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class BatteryBroadcastReceiverTest {
+ private static final String BATTERY_INIT_LEVEL = "100%";
+ private static final String BATTERY_INIT_STATUS = "Not charging";
+ private static final int BATTERY_INTENT_LEVEL = 80;
+ private static final int BATTERY_INTENT_SCALE = 100;
+
+ @Mock
+ private BatteryBroadcastReceiver.OnBatteryChangedListener mBatteryListener;
+ private BatteryBroadcastReceiver mBatteryBroadcastReceiver;
+ private Context mContext;
+ private Intent mChargingIntent;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = RuntimeEnvironment.application;
+
+ mBatteryBroadcastReceiver = new BatteryBroadcastReceiver(mContext);
+ mBatteryBroadcastReceiver.mBatteryLevel = BATTERY_INIT_LEVEL;
+ mBatteryBroadcastReceiver.mBatteryStatus = BATTERY_INIT_STATUS;
+ mBatteryBroadcastReceiver.setBatteryChangedListener(mBatteryListener);
+
+ mChargingIntent = new Intent(Intent.ACTION_BATTERY_CHANGED);
+ mChargingIntent.putExtra(BatteryManager.EXTRA_LEVEL, BATTERY_INTENT_LEVEL);
+ mChargingIntent.putExtra(BatteryManager.EXTRA_SCALE, BATTERY_INTENT_SCALE);
+ mChargingIntent.putExtra(BatteryManager.EXTRA_STATUS,
+ BatteryManager.BATTERY_STATUS_CHARGING);
+ }
+
+ @Test
+ public void testOnReceive_batteryDataChanged_dataUpdated() {
+ mBatteryBroadcastReceiver.onReceive(mContext, mChargingIntent);
+
+ assertThat(mBatteryBroadcastReceiver.mBatteryLevel).isEqualTo(
+ Utils.getBatteryPercentage(mChargingIntent));
+ assertThat(mBatteryBroadcastReceiver.mBatteryStatus).isEqualTo(
+ Utils.getBatteryStatus(mContext.getResources(), mChargingIntent));
+ verify(mBatteryListener).onBatteryChanged();
+ }
+
+ @Test
+ public void testOnReceive_batteryDataNotChanged_listenerNotInvoked() {
+ final String batteryLevel = Utils.getBatteryPercentage(mChargingIntent);
+ final String batteryStatus = Utils.getBatteryStatus(mContext.getResources(),
+ mChargingIntent);
+ mBatteryBroadcastReceiver.mBatteryLevel = batteryLevel;
+ mBatteryBroadcastReceiver.mBatteryStatus = batteryStatus;
+
+ mBatteryBroadcastReceiver.onReceive(mContext, mChargingIntent);
+
+ assertThat(mBatteryBroadcastReceiver.mBatteryLevel).isEqualTo(batteryLevel);
+ assertThat(mBatteryBroadcastReceiver.mBatteryStatus).isEqualTo(batteryStatus);
+ verify(mBatteryListener, never()).onBatteryChanged();
+ }
+
+}
diff --git a/tests/robotests/src/com/android/settings/wifi/WifiWakeupPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/WifiWakeupPreferenceControllerTest.java
index d6243ac..7df5c9a 100644
--- a/tests/robotests/src/com/android/settings/wifi/WifiWakeupPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/WifiWakeupPreferenceControllerTest.java
@@ -17,6 +17,7 @@
package com.android.settings.wifi;
import static android.provider.Settings.Global.NETWORK_RECOMMENDATIONS_ENABLED;
+import static android.provider.Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE;
import static android.provider.Settings.Global.WIFI_WAKEUP_ENABLED;
import static com.google.common.truth.Truth.assertThat;
@@ -29,6 +30,7 @@
import android.support.v14.preference.SwitchPreference;
import android.support.v7.preference.Preference;
+import com.android.settings.R;
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
import com.android.settings.core.lifecycle.Lifecycle;
@@ -52,6 +54,7 @@
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
mController = new WifiWakeupPreferenceController(mContext, mock(Lifecycle.class));
+ Settings.System.putInt(mContext.getContentResolver(), WIFI_SCAN_ALWAYS_AVAILABLE, 1);
}
@Test
@@ -95,6 +98,7 @@
verify(preference).setChecked(true);
verify(preference).setEnabled(true);
+ verify(preference).setSummary(R.string.wifi_wakeup_summary);
}
@Test
@@ -107,5 +111,20 @@
verify(preference).setChecked(false);
verify(preference).setEnabled(false);
+ verify(preference).setSummary(R.string.wifi_wakeup_summary);
+ }
+
+ @Test
+ public void updateState_preferenceSetUncheckedAndSetDisabledWhenWifiScanningDisabled() {
+ final SwitchPreference preference = mock(SwitchPreference.class);
+ Settings.System.putInt(mContext.getContentResolver(), NETWORK_RECOMMENDATIONS_ENABLED, 1);
+ Settings.System.putInt(mContext.getContentResolver(), WIFI_WAKEUP_ENABLED, 1);
+ Settings.System.putInt(mContext.getContentResolver(), WIFI_SCAN_ALWAYS_AVAILABLE, 0);
+
+ mController.updateState(preference);
+
+ verify(preference).setChecked(true);
+ verify(preference).setEnabled(false);
+ verify(preference).setSummary(R.string.wifi_wakeup_summary_scanning_disabled);
}
}
diff --git a/tests/unit/src/com/android/settings/WallpaperPreferenceLayoutTest.java b/tests/unit/src/com/android/settings/WallpaperPreferenceLayoutTest.java
deleted file mode 100644
index 4448307..0000000
--- a/tests/unit/src/com/android/settings/WallpaperPreferenceLayoutTest.java
+++ /dev/null
@@ -1,34 +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;
-
-import android.support.test.InstrumentationRegistry;
-import android.support.test.filters.SmallTest;
-import android.support.test.runner.AndroidJUnit4;
-import android.view.LayoutInflater;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-@SmallTest
-@RunWith(AndroidJUnit4.class)
-public class WallpaperPreferenceLayoutTest {
- @Test
- public void testInflateWallpaperPreferenceLayout_doesNotCrash() {
- LayoutInflater.from(InstrumentationRegistry.getTargetContext())
- .inflate(R.layout.preference_wallpaper_type, null, false);
- }
-}
diff --git a/tests/unit/src/com/android/settings/deviceinfo/storage/StorageAsyncLoaderTest.java b/tests/unit/src/com/android/settings/deviceinfo/storage/StorageAsyncLoaderTest.java
index f7131b3..546ea4b 100644
--- a/tests/unit/src/com/android/settings/deviceinfo/storage/StorageAsyncLoaderTest.java
+++ b/tests/unit/src/com/android/settings/deviceinfo/storage/StorageAsyncLoaderTest.java
@@ -194,8 +194,8 @@
// Should not crash.
}
- private ApplicationInfo addPackage(
- String packageName, long cacheSize, long codeSize, long dataSize, int category) {
+ private ApplicationInfo addPackage(String packageName, long cacheSize, long codeSize,
+ long dataSize, int category) throws Exception {
StorageStatsSource.AppStorageStats storageStats =
mock(StorageStatsSource.AppStorageStats.class);
when(storageStats.getCodeBytes()).thenReturn(codeSize);
diff --git a/tests/unit/src/com/android/settings/display/NightDisplaySettingsActivityTest.java b/tests/unit/src/com/android/settings/display/NightDisplaySettingsActivityTest.java
new file mode 100644
index 0000000..4011d9a
--- /dev/null
+++ b/tests/unit/src/com/android/settings/display/NightDisplaySettingsActivityTest.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * 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.display;
+
+import android.app.Instrumentation;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+import android.provider.Settings;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
+
+import com.android.settings.Settings.NightDisplaySettingsActivity;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(AndroidJUnit4.class)
+@SmallTest
+public class NightDisplaySettingsActivityTest {
+
+ private Context mTargetContext;
+
+ @Before
+ public void setUp() throws Exception {
+ Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
+ mTargetContext = instrumentation.getTargetContext();
+ }
+
+ @Test
+ public void nightDisplaySettingsIntent_resolvesCorrectly() {
+ final boolean nightDisplayAvailable = mTargetContext.getResources().getBoolean(
+ com.android.internal.R.bool.config_nightDisplayAvailable);
+ final PackageManager pm = mTargetContext.getPackageManager();
+ final Intent intent = new Intent(Settings.ACTION_NIGHT_DISPLAY_SETTINGS);
+ final ResolveInfo ri = pm.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
+
+ if (nightDisplayAvailable) {
+ Assert.assertNotNull("No activity for " + Settings.ACTION_NIGHT_DISPLAY_SETTINGS, ri);
+ Assert.assertEquals(mTargetContext.getPackageName(), ri.activityInfo.packageName);
+ Assert.assertEquals(NightDisplaySettingsActivity.class.getName(),
+ ri.activityInfo.name);
+ } else {
+ Assert.assertNull("Should have no activity for "
+ + Settings.ACTION_NIGHT_DISPLAY_SETTINGS, ri);
+ }
+ }
+
+}