Snap for 4486962 from 91fff3093d to pi-release

Change-Id: I9b73a384d4a493eead40ef374edd80ae186454ac
This commit is contained in:
android-build-team Robot
2017-12-06 08:30:52 +00:00
689 changed files with 3046 additions and 1404 deletions

View File

@@ -2213,16 +2213,13 @@
<activity android:name="Settings$PowerUsageSummaryActivity"
android:label="@string/power_usage_summary_title"
android:icon="@drawable/ic_settings_battery"
android:taskAffinity="">
<intent-filter android:priority="1">
android:enabled="false">
<!-- TODO(b/69867246): add priority for this intent-filter -->
<intent-filter>
<action android:name="android.intent.action.POWER_USAGE_SUMMARY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="com.android.settings.SHORTCUT" />
</intent-filter>
<!-- TODO(b/69867246): add shortcut intent-filter -->
<intent-filter android:priority="8">
<action android:name="com.android.settings.action.SETTINGS" />
</intent-filter>
@@ -2241,6 +2238,27 @@
android:value="com.android.settings.fuelgauge.PowerUsageSummary" />
</activity-alias>
<activity android:name=".Settings$PowerUsageSummaryLegacyActivity"
android:label="@string/power_usage_summary_title"
android:icon="@drawable/ic_settings_battery">
<intent-filter android:priority="1">
<action android:name="android.intent.action.POWER_USAGE_SUMMARY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="com.android.settings.SHORTCUT" />
</intent-filter>
<intent-filter android:priority="8">
<action android:name="com.android.settings.action.SETTINGS" />
</intent-filter>
<meta-data android:name="com.android.settings.category"
android:value="com.android.settings.category.ia.homepage" />
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.fuelgauge.PowerUsageSummaryLegacy" />
</activity>
<activity android:name="Settings$BatterySaverSettingsActivity"
android:label="@string/battery_saver"
android:icon="@drawable/ic_settings_battery"

View File

@@ -139,6 +139,7 @@
style="@style/device_info_dialog_value"
android:id="@+id/icc_id_value"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
android:layout_height="wrap_content"
android:text="@string/device_info_not_available"/>
</LinearLayout>
</ScrollView>

View File

@@ -19,7 +19,6 @@
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:gravity="bottom"
android:paddingTop="4dp"
android:paddingStart="72dp"
android:paddingEnd="72dp"
android:layout_width="match_parent"

View File

@@ -48,4 +48,7 @@
<!--Whether help links are defined. -->
<bool name="config_has_help">false</bool>
<!-- Whether location mode is available or not. -->
<bool name="config_location_mode_available">true</bool>
</resources>

View File

@@ -1486,7 +1486,7 @@
<string name="bluetooth_display_passkey_pin_msg">To pair with:<xliff:g id="bold1">&lt;br>&lt;b></xliff:g><xliff:g id="device_name">%1$s</xliff:g><xliff:g id="end_bold1">&lt;/b>&lt;br>&lt;br></xliff:g>Type on it:<xliff:g id="bold2">&lt;br>&lt;b></xliff:g><xliff:g id="passkey">%2$s</xliff:g><xliff:g id="end_bold2">&lt;/b></xliff:g>, then press Return or Enter.</string>
<!-- Checkbox message in pairing dialogs. [CHAR LIMIT=NONE] -->
<string name="bluetooth_pairing_shares_phonebook">Allow <xliff:g id="device_name">%1$s</xliff:g> to access your contacts and call history</string>
<string name="bluetooth_pairing_shares_phonebook">Allow access to your contacts and call history</string>
<!-- Title for BT error dialogs. -->
<string name="bluetooth_error_title"></string>
@@ -6775,19 +6775,16 @@
<string name="zen_mode_button_turn_off">TURN OFF NOW</string>
<!-- [CHAR LIMIT=110] Zen mode settings footer: Footer showing end time of DND -->
<string name="zen_mode_settings_dnd_manual_end_time_next_day">Do Not Disturb is on until <xliff:g id="formatted_time" example="7:00 AM">%s</xliff:g></string>
<string name="zen_mode_settings_dnd_manual_end_time">Do Not Disturb is on until <xliff:g id="formatted_time" example="7:00 AM">%s</xliff:g></string>
<!-- [CHAR LIMIT=110] Zen mode settings footer: Footer showing length of DND -->
<string name="zen_mode_settings_dnd_manual_indefinite">Do Not Disturb will stay on until you turn it off.</string>
<string name="zen_mode_settings_dnd_manual_indefinite">Do Not Disturb will stay on until you turn it off</string>
<!-- [CHAR LIMIT=110] Zen mode settings footer: Footer showing how DND was triggered by an automatic DND rule -->
<string name="zen_mode_settings_dnd_automatic_rule">Do Not Disturb was automatically turned on by a rule <xliff:g id="rule_name" example="Weeknights">%s</xliff:g></string>
<string name="zen_mode_settings_dnd_automatic_rule">Do Not Disturb was automatically turned on by a rule (<xliff:g id="rule_name" example="Weeknights">%s</xliff:g>)</string>
<!-- [CHAR LIMIT=110] Zen mode settings footer: Footer how DND was triggered by an app -->
<string name="zen_mode_settings_dnd_automatic_rule_app">Do Not Disturb was automatically turned on by an app <xliff:g id="app_name" example="Pixel Services">%s</xliff:g></string>
<!-- [CHAR LIMIT=110] Zen mode settings footer: Footer how DND was triggered by multiple rules and/or apps -->
<string name="zen_mode_settings_dnd_automatic_rule_multiple">Do Not Disturb was automatically turned on by a rule or app</string>
<string name="zen_mode_settings_dnd_automatic_rule_app">Do Not Disturb was automatically turned on by an app (<xliff:g id="app_name" example="Android Services">%s</xliff:g>)</string>
<!-- Work Sounds: Work sound settings section header. [CHAR LIMIT=50] -->
<string name="sound_work_settings">Work profile sounds</string>
@@ -7205,6 +7202,15 @@
<!-- [CHAR LIMIT=40] Zen mode settings: Configure external rule -->
<string name="zen_mode_configure_rule">Configure rule</string>
<!-- [CHAR LIMIT=NONE] Zen mode behavior settings footer: footer describing why the user cannot change the current do not disturb behavior settings -->
<string name="zen_mode_app_set_behavior">These settings can\'t be changed right now. An app (<xliff:g id="app_name" example="Android Services">%1$s</xliff:g>) has automatically turned on Do Not Disturb with custom behavior."</string>
<!-- [CHAR LIMIT=NONE] Zen mode behavior settings footer: footer describing why the user cannot change the current do not disturb behavior settings -->
<string name="zen_mode_unknown_app_set_behavior">These settings can\'t be changed right now. An app has automatically turned on Do Not Disturb with custom behavior."</string>
<!-- [CHAR LIMIT=NONE] Zen mode behavior settings footer: footer describing why the user cannot change the current do not disturb behavior settings -->
<string name="zen_mode_qs_set_behavior">These settings can\'t be changed right now. Do Not Disturb was manually turned on with custom behavior."</string>
<!-- [CHAR LIMIT=40] Zen mode settings: Schedule rule type name -->
<string name="zen_schedule_rule_type_name">Time</string>

View File

@@ -0,0 +1,90 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2009 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.
-->
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:settings="http://schemas.android.com/apk/res-auto"
android:key="power_usage_summary_screen"
android:title="@string/power_usage_summary_title"
settings:keywords="@string/keywords_battery">
<com.android.settings.applications.LayoutPreference
android:key="battery_header"
android:selectable="true"
android:layout="@layout/battery_header"/>
<Preference
android:key="high_usage"
android:icon="@drawable/ic_battery_alert_24dp"
android:title="@string/power_high_usage_title"/>
<PreferenceCategory
android:key="device_usage_list">
<com.android.settings.fuelgauge.PowerGaugePreference
android:key="last_full_charge"
android:title="@string/battery_last_full_charge"
android:selectable="false"/>
<com.android.settings.fuelgauge.PowerGaugePreference
android:key="screen_usage"
android:title="@string/device_screen_usage"
android:selectable="false"/>
</PreferenceCategory>
<PreferenceCategory
android:key="power_management"
android:title="@string/battery_power_management">
<com.android.settings.widget.MasterSwitchPreference
android:fragment="com.android.settings.fuelgauge.BatterySaverSettings"
android:key="battery_saver_summary"
android:title="@string/battery_saver"/>
<SwitchPreference
android:key="battery_percentage"
android:title="@string/battery_percentage"
android:summary="@string/battery_percentage_description"/>
<!-- Cross-listed item, if you change this, also change it in display_settings.xml -->
<SwitchPreference
android:key="auto_brightness_battery"
android:title="@string/auto_brightness_title"
android:summary="@string/auto_brightness_summary"
settings:keywords="@string/keywords_display_auto_brightness"/>
<!-- Cross-listed item, if you change this, also change it in display_settings.xml -->
<com.android.settings.TimeoutListPreference
android:key="screen_timeout_battery"
android:title="@string/screen_timeout"
android:summary="@string/screen_timeout_summary"
android:entries="@array/screen_timeout_entries"
android:entryValues="@array/screen_timeout_values"/>
<!-- Cross-listed item, if you change this, also change it in display_settings.xml -->
<Preference
android:key="ambient_display_battery"
android:title="@string/ambient_display_screen_title"
android:fragment="com.android.settings.display.AmbientDisplaySettings" />
</PreferenceCategory>
<PreferenceCategory
android:key="app_list"
android:title="@string/power_usage_list_summary"/>
</PreferenceScreen>

View File

@@ -75,7 +75,8 @@
<SwitchPreference android:key="zen_mode_screen_off"
android:title="@string/zen_mode_screen_off"
android:summary="@string/zen_mode_screen_off_summary" />
</PreferenceCategory>
<com.android.settingslib.widget.FooterPreference/>
</PreferenceScreen>

View File

@@ -41,4 +41,8 @@
android:layout="@layout/zen_mode_settings_button" />
</PreferenceCategory>
<PreferenceCategory>
<com.android.settingslib.widget.FooterPreference/>
</PreferenceCategory>
</PreferenceScreen>

View File

@@ -16,6 +16,7 @@
package com.android.settings;
import static com.android.settings.core.FeatureFlags.BATTERY_SETTINGS_V2;
import static com.android.settings.core.FeatureFlags.CONNECTED_DEVICE_V2;
import android.os.Bundle;
@@ -72,7 +73,6 @@ public class Settings extends SettingsActivity {
public static class PrivacySettingsActivity extends SettingsActivity { /* empty */ }
public static class FactoryResetActivity extends SettingsActivity { /* empty */ }
public static class RunningServicesActivity extends SettingsActivity { /* empty */ }
public static class PowerUsageSummaryActivity extends SettingsActivity { /* empty */ }
public static class BatterySaverSettingsActivity extends SettingsActivity { /* empty */ }
public static class AccountSyncSettingsActivity extends SettingsActivity { /* empty */ }
public static class AccountSyncSettingsInAddAccountActivity extends SettingsActivity { /* empty */ }
@@ -174,6 +174,8 @@ public class Settings extends SettingsActivity {
}
}
public static class ConnectedDeviceDashboardActivityOld extends SettingsActivity {}
public static class PowerUsageSummaryActivity extends SettingsActivity { /* empty */ }
public static class PowerUsageSummaryLegacyActivity extends SettingsActivity { /* empty */ }
public static class AppAndNotificationDashboardActivity extends SettingsActivity {}
public static class StorageDashboardActivity extends SettingsActivity {}
public static class UserAndAccountDashboardActivity extends SettingsActivity {}

View File

@@ -810,9 +810,17 @@ public class SettingsActivity extends SettingsDrawerActivity
Utils.showSimCardTile(this), isAdmin)
|| somethingChanged;
final boolean isBatterySettingsV2Enabled = FeatureFactory.getFactory(this)
.getPowerUsageFeatureProvider(this)
.isBatteryV2Enabled();
// Enable new battery page if v2 enabled
somethingChanged = setTileEnabled(new ComponentName(packageName,
Settings.PowerUsageSummaryActivity.class.getName()),
mBatteryPresent, isAdmin) || somethingChanged;
mBatteryPresent && isBatterySettingsV2Enabled, isAdmin) || somethingChanged;
// Enable legacy battery page if v2 disabled
somethingChanged = setTileEnabled(new ComponentName(packageName,
Settings.PowerUsageSummaryLegacyActivity.class.getName()),
mBatteryPresent && !isBatterySettingsV2Enabled, isAdmin) || somethingChanged;
somethingChanged = setTileEnabled(new ComponentName(packageName,
Settings.UserSettingsActivity.class.getName()),

View File

@@ -26,6 +26,7 @@ import android.os.SystemClock;
import android.text.format.Formatter;
import android.util.ArrayMap;
import android.util.Log;
import android.util.LongSparseArray;
import android.util.SparseArray;
import com.android.internal.app.ProcessMap;
@@ -270,10 +271,10 @@ public class ProcStatsData {
final ProcessMap<ProcStatsEntry> entriesMap = new ProcessMap<ProcStatsEntry>();
for (int ipkg = 0, N = mStats.mPackages.getMap().size(); ipkg < N; ipkg++) {
final SparseArray<SparseArray<ProcessStats.PackageState>> pkgUids = mStats.mPackages
final SparseArray<LongSparseArray<ProcessStats.PackageState>> pkgUids = mStats.mPackages
.getMap().valueAt(ipkg);
for (int iu = 0; iu < pkgUids.size(); iu++) {
final SparseArray<ProcessStats.PackageState> vpkgs = pkgUids.valueAt(iu);
final LongSparseArray<ProcessStats.PackageState> vpkgs = pkgUids.valueAt(iu);
for (int iv = 0; iv < vpkgs.size(); iv++) {
final ProcessStats.PackageState st = vpkgs.valueAt(iv);
for (int iproc = 0; iproc < st.mProcesses.size(); iproc++) {
@@ -311,10 +312,10 @@ public class ProcStatsData {
// Add in service info.
for (int ip = 0, N = mStats.mPackages.getMap().size(); ip < N; ip++) {
SparseArray<SparseArray<ProcessStats.PackageState>> uids = mStats.mPackages.getMap()
SparseArray<LongSparseArray<ProcessStats.PackageState>> uids = mStats.mPackages.getMap()
.valueAt(ip);
for (int iu = 0; iu < uids.size(); iu++) {
SparseArray<ProcessStats.PackageState> vpkgs = uids.valueAt(iu);
LongSparseArray<ProcessStats.PackageState> vpkgs = uids.valueAt(iu);
for (int iv = 0; iv < vpkgs.size(); iv++) {
ProcessStats.PackageState ps = vpkgs.valueAt(iv);
for (int is = 0, NS = ps.mServices.size(); is < NS; is++) {

View File

@@ -23,7 +23,7 @@ import android.os.Parcelable;
import android.text.TextUtils;
import android.util.ArrayMap;
import android.util.Log;
import android.util.SparseArray;
import android.util.LongSparseArray;
import com.android.internal.app.procstats.ProcessState;
import com.android.internal.app.procstats.ProcessStats;
@@ -142,7 +142,7 @@ public final class ProcStatsEntry implements Parcelable {
// Collect information about each package running in the process.
ArrayList<ProcStatsEntry> subProcs = new ArrayList<>();
for (int ipkg=0; ipkg<mPackages.size(); ipkg++) {
SparseArray<ProcessStats.PackageState> vpkgs
LongSparseArray<ProcessStats.PackageState> vpkgs
= stats.mPackages.get(mPackages.get(ipkg), mUid);
for (int ivers=0; ivers<vpkgs.size(); ivers++) {
ProcessStats.PackageState pkgState = vpkgs.valueAt(ivers);

View File

@@ -25,4 +25,5 @@ public class FeatureFlags {
public static final String SUGGESTIONS_V2 = "new_settings_suggestion";
public static final String APP_INFO_V2 = "settings_app_info_v2";
public static final String CONNECTED_DEVICE_V2 = "settings_connected_device_v2";
public static final String BATTERY_SETTINGS_V2 = "settings_battery_v2";
}

View File

@@ -79,6 +79,7 @@ import com.android.settings.enterprise.EnterprisePrivacySettings;
import com.android.settings.fuelgauge.AdvancedPowerUsageDetail;
import com.android.settings.fuelgauge.BatterySaverSettings;
import com.android.settings.fuelgauge.PowerUsageSummary;
import com.android.settings.fuelgauge.PowerUsageSummaryLegacy;
import com.android.settings.gestures.AssistGestureSettings;
import com.android.settings.gestures.DoubleTapPowerSettings;
import com.android.settings.gestures.DoubleTapScreenSettings;
@@ -181,6 +182,7 @@ public class SettingsGateway {
AndroidBeam.class.getName(),
WifiDisplaySettings.class.getName(),
PowerUsageSummary.class.getName(),
PowerUsageSummaryLegacy.class.getName(),
AccountSyncSettings.class.getName(),
AssistGestureSettings.class.getName(),
SwipeToNotificationSettings.class.getName(),

View File

@@ -161,7 +161,6 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
}
public void setSuggestionsV2(List<Suggestion> data) {
// TODO: Tint icon
final DashboardData prevData = mDashboardData;
mDashboardData = new DashboardData.Builder(prevData)
.setSuggestionsV2(data)

View File

@@ -81,6 +81,9 @@ public class DashboardSummary extends InstrumentedFragment
private boolean isOnCategoriesChangedCalled;
private boolean mOnConditionsChangedCalled;
private DashboardCategory mStagingCategory;
private List<Suggestion> mStagingSuggestions;
@Override
public int getMetricsCategory() {
return MetricsEvent.DASHBOARD_SUMMARY;
@@ -291,7 +294,13 @@ public class DashboardSummary extends InstrumentedFragment
@Override
public void onSuggestionReady(List<Suggestion> suggestions) {
mStagingSuggestions = suggestions;
mAdapter.setSuggestionsV2(suggestions);
if (mStagingCategory != null) {
Log.d(TAG, "Category has loaded, setting category from suggestionReady");
mHandler.removeCallbacksAndMessages(null);
mAdapter.setCategory(mStagingCategory);
}
}
/**
@@ -342,7 +351,19 @@ public class DashboardSummary extends InstrumentedFragment
final DashboardCategory category = mDashboardFeatureProvider.getTilesForCategory(
CategoryKey.CATEGORY_HOMEPAGE);
mSummaryLoader.updateSummaryToCache(category);
ThreadUtils.postOnMainThread(() -> mAdapter.setCategory(category));
mStagingCategory = category;
if (mSuggestionControllerMixin.isSuggestionLoaded()) {
Log.d(TAG, "Suggestion has loaded, setting suggestion/category");
ThreadUtils.postOnMainThread(() -> {
if (mStagingSuggestions != null) {
mAdapter.setSuggestionsV2(mStagingSuggestions);
}
mAdapter.setCategory(mStagingCategory);
});
} else {
Log.d(TAG, "Suggestion NOT loaded, delaying setCategory by " + MAX_WAIT_MILLIS + "ms");
mHandler.postDelayed(() -> mAdapter.setCategory(mStagingCategory), MAX_WAIT_MILLIS);
}
}
/**

View File

@@ -104,6 +104,9 @@ public class SuggestionController {
}
try {
return mRemoteService.getSuggestions();
} catch (NullPointerException e) {
Log.w(TAG, "mRemote service detached before able to query", e);
return null;
} catch (RemoteException e) {
Log.w(TAG, "Error when calling getSuggestion()", e);
return null;

View File

@@ -59,6 +59,8 @@ public class SuggestionControllerMixin implements SuggestionController.ServiceCo
private final SuggestionController mSuggestionController;
private final SuggestionControllerHost mHost;
private boolean mSuggestionLoaded;
public SuggestionControllerMixin(Context context, SuggestionControllerHost host,
Lifecycle lifecycle) {
mContext = context.getApplicationContext();
@@ -106,6 +108,7 @@ public class SuggestionControllerMixin implements SuggestionController.ServiceCo
@Override
public Loader<List<Suggestion>> onCreateLoader(int id, Bundle args) {
if (id == SuggestionLoader.LOADER_ID_SUGGESTIONS) {
mSuggestionLoaded = false;
return new SuggestionLoader(mContext, mSuggestionController);
}
throw new IllegalArgumentException("This loader id is not supported " + id);
@@ -113,12 +116,17 @@ public class SuggestionControllerMixin implements SuggestionController.ServiceCo
@Override
public void onLoadFinished(Loader<List<Suggestion>> loader, List<Suggestion> data) {
mSuggestionLoaded = true;
mHost.onSuggestionReady(data);
}
@Override
public void onLoaderReset(Loader<List<Suggestion>> loader) {
mSuggestionLoaded = false;
}
public boolean isSuggestionLoaded() {
return mSuggestionLoaded;
}
public void dismissSuggestion(Suggestion suggestion) {

View File

@@ -80,9 +80,6 @@ public class ImeiInfoDialogController {
* Sets IMEI/MEID information based on whether the device is CDMA or GSM.
*/
public void populateImeiInfo() {
if (mSubscriptionInfo == null) {
return;
}
if (mTelephonyManager.getPhoneType() == TelephonyManager.PHONE_TYPE_CDMA) {
updateDialogForCdmaPhone();
} else {
@@ -94,7 +91,8 @@ public class ImeiInfoDialogController {
final Resources res = mDialog.getContext().getResources();
mDialog.setText(ID_MEID_NUMBER_VALUE, getMeid());
mDialog.setText(ID_MIN_NUMBER_VALUE,
mTelephonyManager.getCdmaMin(mSubscriptionInfo.getSubscriptionId()));
mSubscriptionInfo != null ? mTelephonyManager.getCdmaMin(
mSubscriptionInfo.getSubscriptionId()) : "");
if (res.getBoolean(R.bool.config_msid_enable)) {
mDialog.setText(ID_MIN_NUMBER_LABEL,
@@ -103,7 +101,7 @@ public class ImeiInfoDialogController {
mDialog.setText(ID_PRL_VERSION_VALUE, getCdmaPrlVersion());
if (isCdmaLteEnabled()) {
if (mSubscriptionInfo != null && isCdmaLteEnabled()) {
// Show IMEI for LTE device
mDialog.setText(ID_IMEI_VALUE,
getTextAsDigits(mTelephonyManager.getImei(mSlotId)));

View File

@@ -115,4 +115,9 @@ public interface PowerUsageFeatureProvider {
* enabled. This string notifies users that the estimate is using enhanced prediction.
*/
String getAdvancedUsageScreenInfoString();
/**
* Checks whether to display the battery v2.
*/
boolean isBatteryV2Enabled();
}

View File

@@ -16,12 +16,15 @@
package com.android.settings.fuelgauge;
import static com.android.settings.core.FeatureFlags.BATTERY_SETTINGS_V2;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.net.Uri;
import android.os.Process;
import android.util.FeatureFlagUtils;
import android.util.SparseIntArray;
import com.android.internal.os.BatterySipper;
@@ -36,9 +39,11 @@ public class PowerUsageFeatureProviderImpl implements PowerUsageFeatureProvider
PACKAGE_CALENDAR_PROVIDER, PACKAGE_SYSTEMUI};
protected PackageManager mPackageManager;
protected Context mContext;
public PowerUsageFeatureProviderImpl(Context context) {
mPackageManager = context.getPackageManager();
mContext = context.getApplicationContext();
}
@Override
@@ -133,4 +138,9 @@ public class PowerUsageFeatureProviderImpl implements PowerUsageFeatureProvider
public String getAdvancedUsageScreenInfoString() {
return null;
}
@Override
public boolean isBatteryV2Enabled() {
return FeatureFlagUtils.isEnabled(mContext, BATTERY_SETTINGS_V2);
}
}

View File

@@ -251,7 +251,7 @@ public class PowerUsageSummary extends PowerUsageBase implements
@Override
public int getMetricsCategory() {
return MetricsEvent.FUELGAUGE_POWER_USAGE_SUMMARY;
return MetricsEvent.FUELGAUGE_POWER_USAGE_SUMMARY_V2;
}
@Override

View File

@@ -0,0 +1,889 @@
/*
* Copyright (C) 2009 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.app.Activity;
import android.app.LoaderManager.LoaderCallbacks;
import android.content.Context;
import android.content.Loader;
import android.graphics.drawable.Drawable;
import android.os.BatteryStats;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.Process;
import android.os.UserHandle;
import android.support.annotation.VisibleForTesting;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceGroup;
import android.text.TextUtils;
import android.text.format.DateUtils;
import android.text.format.Formatter;
import android.util.Log;
import android.util.SparseArray;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.widget.TextView;
import com.android.internal.hardware.AmbientDisplayConfiguration;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.internal.os.BatterySipper;
import com.android.internal.os.BatterySipper.DrainType;
import com.android.internal.os.PowerProfile;
import com.android.settings.R;
import com.android.settings.Settings.HighPowerApplicationsActivity;
import com.android.settings.SettingsActivity;
import com.android.settings.Utils;
import com.android.settings.applications.LayoutPreference;
import com.android.settings.applications.manageapplications.ManageApplications;
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
import com.android.settings.dashboard.SummaryLoader;
import com.android.settings.display.AmbientDisplayPreferenceController;
import com.android.settings.display.AutoBrightnessPreferenceController;
import com.android.settings.display.BatteryPercentagePreferenceController;
import com.android.settings.display.TimeoutPreferenceController;
import com.android.settings.fuelgauge.anomaly.Anomaly;
import com.android.settings.fuelgauge.anomaly.AnomalyDetectionPolicy;
import com.android.settings.fuelgauge.anomaly.AnomalyDialogFragment.AnomalyDialogListener;
import com.android.settings.fuelgauge.anomaly.AnomalyLoader;
import com.android.settings.fuelgauge.anomaly.AnomalySummaryPreferenceController;
import com.android.settings.fuelgauge.anomaly.AnomalyUtils;
import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.core.AbstractPreferenceController;
import java.util.ArrayList;
import java.util.List;
/**
* Displays a list of apps and subsystems that consume power, ordered by how much power was
* consumed since the last time it was unplugged.
*
* This is the battery page used in Android O with the app usage list. It is also used for battery
* debug.
*/
public class PowerUsageSummaryLegacy extends PowerUsageBase implements
AnomalyDialogListener, OnLongClickListener, OnClickListener {
static final String TAG = "PowerUsageSummaryLegacy";
private static final boolean DEBUG = false;
private static final boolean USE_FAKE_DATA = false;
private static final String KEY_APP_LIST = "app_list";
private static final String KEY_BATTERY_HEADER = "battery_header";
private static final String KEY_SHOW_ALL_APPS = "show_all_apps";
private static final int MAX_ITEMS_TO_LIST = USE_FAKE_DATA ? 30 : 10;
private static final int MIN_AVERAGE_POWER_THRESHOLD_MILLI_AMP = 10;
private static final String KEY_SCREEN_USAGE = "screen_usage";
private static final String KEY_TIME_SINCE_LAST_FULL_CHARGE = "last_full_charge";
private static final String KEY_AUTO_BRIGHTNESS = "auto_brightness_battery";
private static final String KEY_SCREEN_TIMEOUT = "screen_timeout_battery";
private static final String KEY_AMBIENT_DISPLAY = "ambient_display_battery";
private static final String KEY_BATTERY_SAVER_SUMMARY = "battery_saver_summary";
private static final String KEY_HIGH_USAGE = "high_usage";
@VisibleForTesting
static final int ANOMALY_LOADER = 1;
@VisibleForTesting
static final int BATTERY_INFO_LOADER = 2;
private static final int MENU_STATS_TYPE = Menu.FIRST;
@VisibleForTesting
static final int MENU_HIGH_POWER_APPS = Menu.FIRST + 3;
@VisibleForTesting
static final int MENU_TOGGLE_APPS = Menu.FIRST + 4;
private static final int MENU_HELP = Menu.FIRST + 5;
public static final int DEBUG_INFO_LOADER = 3;
@VisibleForTesting
boolean mShowAllApps = false;
@VisibleForTesting
PowerGaugePreference mScreenUsagePref;
@VisibleForTesting
PowerGaugePreference mLastFullChargePref;
@VisibleForTesting
PowerUsageFeatureProvider mPowerFeatureProvider;
@VisibleForTesting
BatteryUtils mBatteryUtils;
@VisibleForTesting
LayoutPreference mBatteryLayoutPref;
/**
* SparseArray that maps uid to {@link Anomaly}, so we could find {@link Anomaly} by uid
*/
@VisibleForTesting
SparseArray<List<Anomaly>> mAnomalySparseArray;
@VisibleForTesting
PreferenceGroup mAppListGroup;
@VisibleForTesting
BatteryHeaderPreferenceController mBatteryHeaderPreferenceController;
private AnomalySummaryPreferenceController mAnomalySummaryPreferenceController;
private int mStatsType = BatteryStats.STATS_SINCE_CHARGED;
private LoaderCallbacks<List<Anomaly>> mAnomalyLoaderCallbacks =
new LoaderCallbacks<List<Anomaly>>() {
@Override
public Loader<List<Anomaly>> onCreateLoader(int id, Bundle args) {
return new AnomalyLoader(getContext(), mStatsHelper);
}
@Override
public void onLoadFinished(Loader<List<Anomaly>> loader, List<Anomaly> data) {
final AnomalyUtils anomalyUtils = AnomalyUtils.getInstance(getContext());
anomalyUtils.logAnomalies(mMetricsFeatureProvider, data,
MetricsEvent.FUELGAUGE_POWER_USAGE_SUMMARY);
// show high usage preference if possible
mAnomalySummaryPreferenceController.updateAnomalySummaryPreference(data);
updateAnomalySparseArray(data);
refreshAnomalyIcon();
}
@Override
public void onLoaderReset(Loader<List<Anomaly>> loader) {
}
};
@VisibleForTesting
LoaderCallbacks<BatteryInfo> mBatteryInfoLoaderCallbacks =
new LoaderCallbacks<BatteryInfo>() {
@Override
public Loader<BatteryInfo> onCreateLoader(int i, Bundle bundle) {
return new BatteryInfoLoader(getContext(), mStatsHelper);
}
@Override
public void onLoadFinished(Loader<BatteryInfo> loader, BatteryInfo batteryInfo) {
mBatteryHeaderPreferenceController.updateHeaderPreference(batteryInfo);
}
@Override
public void onLoaderReset(Loader<BatteryInfo> loader) {
// do nothing
}
};
LoaderCallbacks<List<BatteryInfo>> mBatteryInfoDebugLoaderCallbacks =
new LoaderCallbacks<List<BatteryInfo>>() {
@Override
public Loader<List<BatteryInfo>> onCreateLoader(int i, Bundle bundle) {
return new DebugEstimatesLoader(getContext(), mStatsHelper);
}
@Override
public void onLoadFinished(Loader<List<BatteryInfo>> loader,
List<BatteryInfo> batteryInfos) {
final BatteryMeterView batteryView = (BatteryMeterView) mBatteryLayoutPref
.findViewById(R.id.battery_header_icon);
final TextView percentRemaining =
mBatteryLayoutPref.findViewById(R.id.battery_percent);
final TextView summary1 = mBatteryLayoutPref.findViewById(R.id.summary1);
final TextView summary2 = mBatteryLayoutPref.findViewById(R.id.summary2);
BatteryInfo oldInfo = batteryInfos.get(0);
BatteryInfo newInfo = batteryInfos.get(1);
percentRemaining.setText(Utils.formatPercentage(oldInfo.batteryLevel));
// set the text to the old estimate (copied from battery info). Note that this
// can sometimes say 0 time remaining because battery stats requires the phone
// be unplugged for a period of time before being willing ot make an estimate.
summary1.setText(mPowerFeatureProvider.getOldEstimateDebugString(
Formatter.formatShortElapsedTime(getContext(),
BatteryUtils.convertUsToMs(oldInfo.remainingTimeUs))));
// for this one we can just set the string directly
summary2.setText(mPowerFeatureProvider.getEnhancedEstimateDebugString(
Formatter.formatShortElapsedTime(getContext(),
BatteryUtils.convertUsToMs(newInfo.remainingTimeUs))));
batteryView.setBatteryLevel(oldInfo.batteryLevel);
batteryView.setCharging(!oldInfo.discharging);
}
@Override
public void onLoaderReset(Loader<List<BatteryInfo>> loader) {
}
};
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setAnimationAllowed(true);
initFeatureProvider();
mBatteryLayoutPref = (LayoutPreference) findPreference(KEY_BATTERY_HEADER);
mAppListGroup = (PreferenceGroup) findPreference(KEY_APP_LIST);
mScreenUsagePref = (PowerGaugePreference) findPreference(KEY_SCREEN_USAGE);
mLastFullChargePref = (PowerGaugePreference) findPreference(
KEY_TIME_SINCE_LAST_FULL_CHARGE);
mFooterPreferenceMixin.createFooterPreference().setTitle(R.string.battery_footer_summary);
mAnomalySummaryPreferenceController = new AnomalySummaryPreferenceController(
(SettingsActivity) getActivity(), this, MetricsEvent.FUELGAUGE_POWER_USAGE_SUMMARY);
mBatteryUtils = BatteryUtils.getInstance(getContext());
mAnomalySparseArray = new SparseArray<>();
restartBatteryInfoLoader();
restoreSavedInstance(icicle);
}
@Override
public int getMetricsCategory() {
return MetricsEvent.FUELGAUGE_POWER_USAGE_SUMMARY;
}
@Override
public void onPause() {
BatteryEntry.stopRequestQueue();
mHandler.removeMessages(BatteryEntry.MSG_UPDATE_NAME_ICON);
super.onPause();
}
@Override
public void onDestroy() {
super.onDestroy();
if (getActivity().isChangingConfigurations()) {
BatteryEntry.clearUidCache();
}
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putBoolean(KEY_SHOW_ALL_APPS, mShowAllApps);
}
@Override
public boolean onPreferenceTreeClick(Preference preference) {
if (mAnomalySummaryPreferenceController.onPreferenceTreeClick(preference)) {
return true;
}
if (KEY_BATTERY_HEADER.equals(preference.getKey())) {
performBatteryHeaderClick();
return true;
} else if (!(preference instanceof PowerGaugePreference)) {
return super.onPreferenceTreeClick(preference);
}
PowerGaugePreference pgp = (PowerGaugePreference) preference;
BatteryEntry entry = pgp.getInfo();
AdvancedPowerUsageDetail.startBatteryDetailPage((SettingsActivity) getActivity(),
this, mStatsHelper, mStatsType, entry, pgp.getPercent(),
mAnomalySparseArray.get(entry.sipper.getUid()));
return super.onPreferenceTreeClick(preference);
}
@Override
protected String getLogTag() {
return TAG;
}
@Override
protected int getPreferenceScreenResId() {
return R.xml.power_usage_summary_legacy;
}
@Override
protected List<AbstractPreferenceController> getPreferenceControllers(Context context) {
final List<AbstractPreferenceController> controllers = new ArrayList<>();
mBatteryHeaderPreferenceController = new BatteryHeaderPreferenceController(
context, getActivity(), this /* host */, getLifecycle());
controllers.add(mBatteryHeaderPreferenceController);
controllers.add(new AutoBrightnessPreferenceController(context, KEY_AUTO_BRIGHTNESS));
controllers.add(new TimeoutPreferenceController(context, KEY_SCREEN_TIMEOUT));
controllers.add(new BatterySaverController(context, getLifecycle()));
controllers.add(new BatteryPercentagePreferenceController(context));
controllers.add(new AmbientDisplayPreferenceController(
context,
new AmbientDisplayConfiguration(context),
KEY_AMBIENT_DISPLAY));
return controllers;
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
if (DEBUG) {
menu.add(Menu.NONE, MENU_STATS_TYPE, Menu.NONE, R.string.menu_stats_total)
.setIcon(com.android.internal.R.drawable.ic_menu_info_details)
.setAlphabeticShortcut('t');
}
menu.add(Menu.NONE, MENU_HIGH_POWER_APPS, Menu.NONE, R.string.high_power_apps);
if (mPowerFeatureProvider.isPowerAccountingToggleEnabled()) {
menu.add(Menu.NONE, MENU_TOGGLE_APPS, Menu.NONE,
mShowAllApps ? R.string.hide_extra_apps : R.string.show_all_apps);
}
super.onCreateOptionsMenu(menu, inflater);
}
@Override
public int getHelpResource() {
return R.string.help_url_battery;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
final SettingsActivity sa = (SettingsActivity) getActivity();
final Context context = getContext();
final MetricsFeatureProvider metricsFeatureProvider =
FeatureFactory.getFactory(context).getMetricsFeatureProvider();
switch (item.getItemId()) {
case MENU_STATS_TYPE:
if (mStatsType == BatteryStats.STATS_SINCE_CHARGED) {
mStatsType = BatteryStats.STATS_SINCE_UNPLUGGED;
} else {
mStatsType = BatteryStats.STATS_SINCE_CHARGED;
}
refreshUi();
return true;
case MENU_HIGH_POWER_APPS:
Bundle args = new Bundle();
args.putString(ManageApplications.EXTRA_CLASSNAME,
HighPowerApplicationsActivity.class.getName());
sa.startPreferencePanel(this, ManageApplications.class.getName(), args,
R.string.high_power_apps, null, null, 0);
metricsFeatureProvider.action(context,
MetricsEvent.ACTION_SETTINGS_MENU_BATTERY_OPTIMIZATION);
return true;
case MENU_TOGGLE_APPS:
mShowAllApps = !mShowAllApps;
item.setTitle(mShowAllApps ? R.string.hide_extra_apps : R.string.show_all_apps);
metricsFeatureProvider.action(context,
MetricsEvent.ACTION_SETTINGS_MENU_BATTERY_APPS_TOGGLE, mShowAllApps);
restartBatteryStatsLoader(false /* clearHeader */);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
@VisibleForTesting
void restoreSavedInstance(Bundle savedInstance) {
if (savedInstance != null) {
mShowAllApps = savedInstance.getBoolean(KEY_SHOW_ALL_APPS, false);
}
}
private void addNotAvailableMessage() {
final String NOT_AVAILABLE = "not_available";
Preference notAvailable = getCachedPreference(NOT_AVAILABLE);
if (notAvailable == null) {
notAvailable = new Preference(getPrefContext());
notAvailable.setKey(NOT_AVAILABLE);
notAvailable.setTitle(R.string.power_usage_not_available);
mAppListGroup.addPreference(notAvailable);
}
}
private void performBatteryHeaderClick() {
if (mPowerFeatureProvider.isAdvancedUiEnabled()) {
Utils.startWithFragment(getContext(), PowerUsageAdvanced.class.getName(), null,
null, 0, R.string.advanced_battery_title, null, getMetricsCategory());
} else {
mStatsHelper.storeStatsHistoryInFile(BatteryHistoryDetail.BATTERY_HISTORY_FILE);
Bundle args = new Bundle(2);
args.putString(BatteryHistoryDetail.EXTRA_STATS,
BatteryHistoryDetail.BATTERY_HISTORY_FILE);
args.putParcelable(BatteryHistoryDetail.EXTRA_BROADCAST,
mStatsHelper.getBatteryBroadcast());
Utils.startWithFragment(getContext(), BatteryHistoryDetail.class.getName(), args,
null, 0, R.string.history_details_title, null, getMetricsCategory());
}
}
private static boolean isSharedGid(int uid) {
return UserHandle.getAppIdFromSharedAppGid(uid) > 0;
}
private static boolean isSystemUid(int uid) {
final int appUid = UserHandle.getAppId(uid);
return appUid >= Process.SYSTEM_UID && appUid < Process.FIRST_APPLICATION_UID;
}
/**
* We want to coalesce some UIDs. For example, dex2oat runs under a shared gid that
* exists for all users of the same app. We detect this case and merge the power use
* for dex2oat to the device OWNER's use of the app.
*
* @return A sorted list of apps using power.
*/
private List<BatterySipper> getCoalescedUsageList(final List<BatterySipper> sippers) {
final SparseArray<BatterySipper> uidList = new SparseArray<>();
final ArrayList<BatterySipper> results = new ArrayList<>();
final int numSippers = sippers.size();
for (int i = 0; i < numSippers; i++) {
BatterySipper sipper = sippers.get(i);
if (sipper.getUid() > 0) {
int realUid = sipper.getUid();
// Check if this UID is a shared GID. If so, we combine it with the OWNER's
// actual app UID.
if (isSharedGid(sipper.getUid())) {
realUid = UserHandle.getUid(UserHandle.USER_SYSTEM,
UserHandle.getAppIdFromSharedAppGid(sipper.getUid()));
}
// Check if this UID is a system UID (mediaserver, logd, nfc, drm, etc).
if (isSystemUid(realUid)
&& !"mediaserver".equals(sipper.packageWithHighestDrain)) {
// Use the system UID for all UIDs running in their own sandbox that
// are not apps. We exclude mediaserver because we already are expected to
// report that as a separate item.
realUid = Process.SYSTEM_UID;
}
if (realUid != sipper.getUid()) {
// Replace the BatterySipper with a new one with the real UID set.
BatterySipper newSipper = new BatterySipper(sipper.drainType,
new FakeUid(realUid), 0.0);
newSipper.add(sipper);
newSipper.packageWithHighestDrain = sipper.packageWithHighestDrain;
newSipper.mPackages = sipper.mPackages;
sipper = newSipper;
}
int index = uidList.indexOfKey(realUid);
if (index < 0) {
// New entry.
uidList.put(realUid, sipper);
} else {
// Combine BatterySippers if we already have one with this UID.
final BatterySipper existingSipper = uidList.valueAt(index);
existingSipper.add(sipper);
if (existingSipper.packageWithHighestDrain == null
&& sipper.packageWithHighestDrain != null) {
existingSipper.packageWithHighestDrain = sipper.packageWithHighestDrain;
}
final int existingPackageLen = existingSipper.mPackages != null ?
existingSipper.mPackages.length : 0;
final int newPackageLen = sipper.mPackages != null ?
sipper.mPackages.length : 0;
if (newPackageLen > 0) {
String[] newPackages = new String[existingPackageLen + newPackageLen];
if (existingPackageLen > 0) {
System.arraycopy(existingSipper.mPackages, 0, newPackages, 0,
existingPackageLen);
}
System.arraycopy(sipper.mPackages, 0, newPackages, existingPackageLen,
newPackageLen);
existingSipper.mPackages = newPackages;
}
}
} else {
results.add(sipper);
}
}
final int numUidSippers = uidList.size();
for (int i = 0; i < numUidSippers; i++) {
results.add(uidList.valueAt(i));
}
// The sort order must have changed, so re-sort based on total power use.
mBatteryUtils.sortUsageList(results);
return results;
}
protected void refreshUi() {
final Context context = getContext();
if (context == null) {
return;
}
restartAnomalyDetectionIfPossible();
// reload BatteryInfo and updateUI
restartBatteryInfoLoader();
final long lastFullChargeTime = mBatteryUtils.calculateLastFullChargeTime(mStatsHelper,
System.currentTimeMillis());
updateScreenPreference();
updateLastFullChargePreference(lastFullChargeTime);
final CharSequence timeSequence = Utils.formatRelativeTime(context, lastFullChargeTime,
false);
final int resId = mShowAllApps ? R.string.power_usage_list_summary_device
: R.string.power_usage_list_summary;
mAppListGroup.setTitle(TextUtils.expandTemplate(getText(resId), timeSequence));
refreshAppListGroup();
}
private void refreshAppListGroup() {
final PowerProfile powerProfile = mStatsHelper.getPowerProfile();
final BatteryStats stats = mStatsHelper.getStats();
final double averagePower = powerProfile.getAveragePower(PowerProfile.POWER_SCREEN_FULL);
boolean addedSome = false;
final int dischargeAmount = USE_FAKE_DATA ? 5000
: stats != null ? stats.getDischargeAmount(mStatsType) : 0;
cacheRemoveAllPrefs(mAppListGroup);
mAppListGroup.setOrderingAsAdded(false);
if (averagePower >= MIN_AVERAGE_POWER_THRESHOLD_MILLI_AMP || USE_FAKE_DATA) {
final List<BatterySipper> usageList = getCoalescedUsageList(
USE_FAKE_DATA ? getFakeStats() : mStatsHelper.getUsageList());
double hiddenPowerMah = mShowAllApps ? 0 :
mBatteryUtils.removeHiddenBatterySippers(usageList);
mBatteryUtils.sortUsageList(usageList);
final int numSippers = usageList.size();
for (int i = 0; i < numSippers; i++) {
final BatterySipper sipper = usageList.get(i);
double totalPower = USE_FAKE_DATA ? 4000 : mStatsHelper.getTotalPower();
final double percentOfTotal = mBatteryUtils.calculateBatteryPercent(
sipper.totalPowerMah, totalPower, hiddenPowerMah, dischargeAmount);
if (((int) (percentOfTotal + .5)) < 1) {
continue;
}
if (shouldHideSipper(sipper)) {
continue;
}
final UserHandle userHandle = new UserHandle(UserHandle.getUserId(sipper.getUid()));
final BatteryEntry entry = new BatteryEntry(getActivity(), mHandler, mUm, sipper);
final Drawable badgedIcon = mUm.getBadgedIconForUser(entry.getIcon(),
userHandle);
final CharSequence contentDescription = mUm.getBadgedLabelForUser(entry.getLabel(),
userHandle);
final String key = extractKeyFromSipper(sipper);
PowerGaugePreference pref = (PowerGaugePreference) getCachedPreference(key);
if (pref == null) {
pref = new PowerGaugePreference(getPrefContext(), badgedIcon,
contentDescription, entry);
pref.setKey(key);
}
sipper.percent = percentOfTotal;
pref.setTitle(entry.getLabel());
pref.setOrder(i + 1);
pref.setPercent(percentOfTotal);
pref.shouldShowAnomalyIcon(false);
if (sipper.usageTimeMs == 0 && sipper.drainType == DrainType.APP) {
sipper.usageTimeMs = mBatteryUtils.getProcessTimeMs(
BatteryUtils.StatusType.FOREGROUND, sipper.uidObj, mStatsType);
}
setUsageSummary(pref, sipper);
addedSome = true;
mAppListGroup.addPreference(pref);
if (mAppListGroup.getPreferenceCount() - getCachedCount()
> (MAX_ITEMS_TO_LIST + 1)) {
break;
}
}
}
if (!addedSome) {
addNotAvailableMessage();
}
removeCachedPrefs(mAppListGroup);
BatteryEntry.startRequestQueue();
}
@VisibleForTesting
boolean shouldHideSipper(BatterySipper sipper) {
// Don't show over-counted and unaccounted in any condition
return sipper.drainType == DrainType.OVERCOUNTED
|| sipper.drainType == DrainType.UNACCOUNTED;
}
@VisibleForTesting
void refreshAnomalyIcon() {
for (int i = 0, size = mAnomalySparseArray.size(); i < size; i++) {
final String key = extractKeyFromUid(mAnomalySparseArray.keyAt(i));
final PowerGaugePreference pref = (PowerGaugePreference) mAppListGroup.findPreference(
key);
if (pref != null) {
pref.shouldShowAnomalyIcon(true);
}
}
}
@VisibleForTesting
void restartAnomalyDetectionIfPossible() {
if (getAnomalyDetectionPolicy().isAnomalyDetectionEnabled()) {
getLoaderManager().restartLoader(ANOMALY_LOADER, Bundle.EMPTY, mAnomalyLoaderCallbacks);
}
}
@VisibleForTesting
AnomalyDetectionPolicy getAnomalyDetectionPolicy() {
return new AnomalyDetectionPolicy(getContext());
}
@VisibleForTesting
BatterySipper findBatterySipperByType(List<BatterySipper> usageList, DrainType type) {
for (int i = 0, size = usageList.size(); i < size; i++) {
final BatterySipper sipper = usageList.get(i);
if (sipper.drainType == type) {
return sipper;
}
}
return null;
}
@VisibleForTesting
void updateScreenPreference() {
final BatterySipper sipper = findBatterySipperByType(
mStatsHelper.getUsageList(), DrainType.SCREEN);
final long usageTimeMs = sipper != null ? sipper.usageTimeMs : 0;
mScreenUsagePref.setSubtitle(Utils.formatElapsedTime(getContext(), usageTimeMs, false));
}
@VisibleForTesting
void updateLastFullChargePreference(long timeMs) {
final CharSequence timeSequence = Utils.formatRelativeTime(getContext(), timeMs, false);
mLastFullChargePref.setSubtitle(timeSequence);
}
@VisibleForTesting
void showBothEstimates() {
final Context context = getContext();
if (context == null
|| !mPowerFeatureProvider.isEnhancedBatteryPredictionEnabled(context)) {
return;
}
getLoaderManager().restartLoader(DEBUG_INFO_LOADER, Bundle.EMPTY,
mBatteryInfoDebugLoaderCallbacks);
}
@VisibleForTesting
double calculatePercentage(double powerUsage, double dischargeAmount) {
final double totalPower = mStatsHelper.getTotalPower();
return totalPower == 0 ? 0 :
((powerUsage / totalPower) * dischargeAmount);
}
@VisibleForTesting
void setUsageSummary(Preference preference, BatterySipper sipper) {
// Only show summary when usage time is longer than one minute
final long usageTimeMs = sipper.usageTimeMs;
if (usageTimeMs >= DateUtils.MINUTE_IN_MILLIS) {
final CharSequence timeSequence = Utils.formatElapsedTime(getContext(), usageTimeMs,
false);
preference.setSummary(
(sipper.drainType != DrainType.APP || mBatteryUtils.shouldHideSipper(sipper))
? timeSequence
: TextUtils.expandTemplate(getText(R.string.battery_used_for),
timeSequence));
}
}
@VisibleForTesting
String extractKeyFromSipper(BatterySipper sipper) {
if (sipper.uidObj != null) {
return extractKeyFromUid(sipper.getUid());
} else if (sipper.drainType == DrainType.USER) {
return sipper.drainType.toString() + sipper.userId;
} else if (sipper.drainType != DrainType.APP) {
return sipper.drainType.toString();
} else if (sipper.getPackages() != null) {
return TextUtils.concat(sipper.getPackages()).toString();
} else {
Log.w(TAG, "Inappropriate BatterySipper without uid and package names: " + sipper);
return "-1";
}
}
@VisibleForTesting
String extractKeyFromUid(int uid) {
return Integer.toString(uid);
}
@VisibleForTesting
void setBatteryLayoutPreference(LayoutPreference layoutPreference) {
mBatteryLayoutPref = layoutPreference;
}
@VisibleForTesting
void initFeatureProvider() {
final Context context = getContext();
mPowerFeatureProvider = FeatureFactory.getFactory(context)
.getPowerUsageFeatureProvider(context);
}
@VisibleForTesting
void updateAnomalySparseArray(List<Anomaly> anomalies) {
mAnomalySparseArray.clear();
for (int i = 0, size = anomalies.size(); i < size; i++) {
final Anomaly anomaly = anomalies.get(i);
if (mAnomalySparseArray.get(anomaly.uid) == null) {
mAnomalySparseArray.append(anomaly.uid, new ArrayList<>());
}
mAnomalySparseArray.get(anomaly.uid).add(anomaly);
}
}
@VisibleForTesting
void restartBatteryInfoLoader() {
getLoaderManager().restartLoader(BATTERY_INFO_LOADER, Bundle.EMPTY,
mBatteryInfoLoaderCallbacks);
if (mPowerFeatureProvider.isEstimateDebugEnabled()) {
// Unfortunately setting a long click listener on a view means it will no
// longer pass the regular click event to the parent, so we have to register
// a regular click listener as well.
View header = mBatteryLayoutPref.findViewById(R.id.summary1);
header.setOnLongClickListener(this);
header.setOnClickListener(this);
}
}
private static List<BatterySipper> getFakeStats() {
ArrayList<BatterySipper> stats = new ArrayList<>();
float use = 5;
for (DrainType type : DrainType.values()) {
if (type == DrainType.APP) {
continue;
}
stats.add(new BatterySipper(type, null, use));
use += 5;
}
for (int i = 0; i < 100; i++) {
stats.add(new BatterySipper(DrainType.APP,
new FakeUid(Process.FIRST_APPLICATION_UID + i), use));
}
stats.add(new BatterySipper(DrainType.APP,
new FakeUid(0), use));
// Simulate dex2oat process.
BatterySipper sipper = new BatterySipper(DrainType.APP,
new FakeUid(UserHandle.getSharedAppGid(Process.FIRST_APPLICATION_UID)), 10.0f);
sipper.packageWithHighestDrain = "dex2oat";
stats.add(sipper);
sipper = new BatterySipper(DrainType.APP,
new FakeUid(UserHandle.getSharedAppGid(Process.FIRST_APPLICATION_UID + 1)), 10.0f);
sipper.packageWithHighestDrain = "dex2oat";
stats.add(sipper);
sipper = new BatterySipper(DrainType.APP,
new FakeUid(UserHandle.getSharedAppGid(Process.LOG_UID)), 9.0f);
stats.add(sipper);
return stats;
}
Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case BatteryEntry.MSG_UPDATE_NAME_ICON:
BatteryEntry entry = (BatteryEntry) msg.obj;
PowerGaugePreference pgp =
(PowerGaugePreference) findPreference(
Integer.toString(entry.sipper.uidObj.getUid()));
if (pgp != null) {
final int userId = UserHandle.getUserId(entry.sipper.getUid());
final UserHandle userHandle = new UserHandle(userId);
pgp.setIcon(mUm.getBadgedIconForUser(entry.getIcon(), userHandle));
pgp.setTitle(entry.name);
if (entry.sipper.drainType == DrainType.APP) {
pgp.setContentDescription(entry.name);
}
}
break;
case BatteryEntry.MSG_REPORT_FULLY_DRAWN:
Activity activity = getActivity();
if (activity != null) {
activity.reportFullyDrawn();
}
break;
}
super.handleMessage(msg);
}
};
@Override
public void onAnomalyHandled(Anomaly anomaly) {
mAnomalySummaryPreferenceController.hideHighUsagePreference();
}
@Override
public boolean onLongClick(View view) {
showBothEstimates();
view.setOnLongClickListener(null);
return true;
}
@Override
public void onClick(View view) {
performBatteryHeaderClick();
}
@Override
protected void restartBatteryStatsLoader() {
restartBatteryStatsLoader(true /* clearHeader */);
}
void restartBatteryStatsLoader(boolean clearHeader) {
super.restartBatteryStatsLoader();
if (clearHeader) {
mBatteryHeaderPreferenceController.quickUpdateHeaderPreference();
}
}
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;
mBatteryBroadcastReceiver = new BatteryBroadcastReceiver(mContext);
mBatteryBroadcastReceiver.setBatteryChangedListener(() -> {
BatteryInfo.getBatteryInfo(mContext, new BatteryInfo.Callback() {
@Override
public void onBatteryInfoLoaded(BatteryInfo info) {
mLoader.setSummary(PowerUsageSummaryLegacy.SummaryProvider.this, info.chargeLabel);
}
}, true /* shortString */);
});
}
@Override
public void setListening(boolean listening) {
if (listening) {
mBatteryBroadcastReceiver.register();
} else {
mBatteryBroadcastReceiver.unRegister();
}
}
}
public static final SummaryLoader.SummaryProviderFactory SUMMARY_PROVIDER_FACTORY
= new SummaryLoader.SummaryProviderFactory() {
@Override
public SummaryLoader.SummaryProvider createSummaryProvider(Activity activity,
SummaryLoader summaryLoader) {
return new SummaryProvider(activity, summaryLoader);
}
};
}

View File

@@ -40,6 +40,11 @@ public class LocationModePreferenceController extends LocationBasePreferenceCont
return KEY_LOCATION_MODE;
}
@Override
public boolean isAvailable() {
return mContext.getResources().getBoolean(R.bool.config_location_mode_available);
}
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);

View File

@@ -16,6 +16,9 @@
package com.android.settings.notification;
import android.app.ActivityManager;
import android.app.AlarmManager;
import android.app.AlarmManager.AlarmClockInfo;
import android.app.NotificationManager;
import android.content.ContentResolver;
import android.content.Context;
@@ -24,8 +27,11 @@ import android.net.Uri;
import android.os.Handler;
import android.os.UserHandle;
import android.provider.Settings;
import android.service.notification.ScheduleCalendar;
import android.service.notification.ZenModeConfig;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
import android.util.Slog;
import com.android.internal.annotations.VisibleForTesting;
import com.android.settings.core.PreferenceControllerMixin;
@@ -41,12 +47,15 @@ abstract public class AbstractZenModePreferenceController extends
@VisibleForTesting
protected SettingObserver mSettingObserver;
private final String KEY;
final private NotificationManager mNotificationManager;
protected static ZenModeConfigWrapper mZenModeConfigWrapper;
public AbstractZenModePreferenceController(Context context, String key,
Lifecycle lifecycle) {
super(context);
mZenModeConfigWrapper = new ZenModeConfigWrapper(context);
if (lifecycle != null) {
lifecycle.addObserver(this);
}
@@ -79,6 +88,10 @@ abstract public class AbstractZenModePreferenceController extends
return mNotificationManager.getNotificationPolicy();
}
protected ZenModeConfig getZenModeConfig() {
return mNotificationManager.getZenModeConfig();
}
protected int getZenMode() {
return Settings.Global.getInt(mContext.getContentResolver(),
Settings.Global.ZEN_MODE, 0);
@@ -117,4 +130,69 @@ abstract public class AbstractZenModePreferenceController extends
}
}
}
/**
* Wrapper for testing compatibility
*/
@VisibleForTesting
static class ZenModeConfigWrapper {
private final Context mContext;
public ZenModeConfigWrapper(Context context) {
mContext = context;
}
protected String getOwnerCaption(String owner) {
return ZenModeConfig.getOwnerCaption(mContext, owner);
}
protected boolean isTimeRule(Uri id) {
return ZenModeConfig.isValidEventConditionId(id) ||
ZenModeConfig.isValidScheduleConditionId(id);
}
protected CharSequence getFormattedTime(long time, int userHandle) {
return ZenModeConfig.getFormattedTime(mContext, time, isToday(time), userHandle);
}
private boolean isToday(long time) {
return ZenModeConfig.isToday(time);
}
protected long parseManualRuleTime(Uri id) {
return ZenModeConfig.tryParseCountdownConditionId(id);
}
protected long parseAutomaticRuleEndTime(Uri id) {
if (ZenModeConfig.isValidEventConditionId(id)) {
// cannot look up end times for events
return Long.MAX_VALUE;
}
if (ZenModeConfig.isValidScheduleConditionId(id)) {
ScheduleCalendar schedule = ZenModeConfig.toScheduleCalendar(id);
long endTimeMs = schedule.getNextChangeTime(System.currentTimeMillis());
// check if automatic rule will end on next alarm
if (schedule.exitAtAlarm()) {
long nextAlarm = getNextAlarm(mContext);
schedule.maybeSetNextAlarm(System.currentTimeMillis(), nextAlarm);
if (schedule.shouldExitForAlarm(endTimeMs)) {
return nextAlarm;
}
}
return endTimeMs;
}
return -1;
}
}
private static long getNextAlarm(Context context) {
final AlarmManager alarms = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
final AlarmClockInfo info = alarms.getNextAlarmClock(ActivityManager.getCurrentUser());
return info != null ? info.getTriggerTime() : 0;
}
}

View File

@@ -0,0 +1,101 @@
/*
* 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.notification;
import android.content.Context;
import android.content.ComponentName;
import android.net.Uri;
import android.provider.Settings;
import android.service.notification.ZenModeConfig;
import android.support.v7.preference.Preference;
import android.util.Slog;
import com.android.settings.R;
import com.android.settingslib.core.lifecycle.Lifecycle;
public class ZenModeBehaviorFooterPreferenceController extends AbstractZenModePreferenceController {
protected static final String KEY = "footer_preference";
public ZenModeBehaviorFooterPreferenceController(Context context, Lifecycle lifecycle) {
super(context, KEY, lifecycle);
}
@Override
public boolean isAvailable() {
return isDeprecatedZenMode(getZenMode());
}
@Override
public String getPreferenceKey() {
return KEY;
}
@Override
public void updateState(Preference preference) {
super.updateState(preference);
boolean isAvailable = isAvailable();
preference.setVisible(isAvailable);
if (isAvailable) {
preference.setTitle(getFooterText());
}
}
protected String getFooterText() {
ZenModeConfig config = getZenModeConfig();
// DND turned on by manual rule with deprecated zen mode
if (config.manualRule != null &&
isDeprecatedZenMode(config.manualRule.zenMode)) {
final Uri id = config.manualRule.conditionId;
if (config.manualRule.enabler != null) {
// app triggered manual rule
String appOwner = mZenModeConfigWrapper.getOwnerCaption(config.manualRule.enabler);
if (!appOwner.isEmpty()) {
return mContext.getString(R.string.zen_mode_app_set_behavior, appOwner);
}
} else {
return mContext.getString(R.string.zen_mode_qs_set_behavior);
}
}
// DND turned on by an automatic rule with deprecated zen mode
for (ZenModeConfig.ZenRule automaticRule : config.automaticRules.values()) {
if (automaticRule.isAutomaticActive() && isDeprecatedZenMode(automaticRule.zenMode)) {
ComponentName component = automaticRule.component;
if (component != null) {
return mContext.getString(R.string.zen_mode_app_set_behavior,
component.getPackageName());
}
}
}
return mContext.getString(R.string.zen_mode_unknown_app_set_behavior);
}
private boolean isDeprecatedZenMode(int zenMode) {
switch (zenMode) {
case Settings.Global.ZEN_MODE_NO_INTERRUPTIONS:
case Settings.Global.ZEN_MODE_ALARMS:
return true;
default:
return false;
}
}
}

View File

@@ -48,6 +48,7 @@ public class ZenModeBehaviorSettings extends ZenModeSettingsBase implements Inde
controllers.add(new ZenModeRepeatCallersPreferenceController(context, lifecycle));
controllers.add(new ZenModeScreenOnPreferenceController(context, lifecycle));
controllers.add(new ZenModeScreenOffPreferenceController(context, lifecycle));
controllers.add(new ZenModeBehaviorFooterPreferenceController(context, lifecycle));
return controllers;
}

View File

@@ -64,6 +64,7 @@ public class ZenModeSettings extends ZenModeSettingsBase {
controllers.add(new ZenModeBehaviorPreferenceController(context, lifecycle));
controllers.add(new ZenModeAutomationPreferenceController(context));
controllers.add(new ZenModeButtonPreferenceController(context, lifecycle));
controllers.add(new ZenModeSettingsFooterPreferenceController(context, lifecycle));
return controllers;
}

View File

@@ -0,0 +1,118 @@
/*
* 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.notification;
import android.content.Context;
import android.net.Uri;
import android.provider.Settings;
import android.service.notification.ZenModeConfig;
import android.support.v7.preference.Preference;
import com.android.settings.R;
import com.android.settingslib.core.lifecycle.Lifecycle;
public class ZenModeSettingsFooterPreferenceController extends AbstractZenModePreferenceController {
protected static final String KEY = "footer_preference";
public ZenModeSettingsFooterPreferenceController(Context context, Lifecycle lifecycle) {
super(context, KEY, lifecycle);
}
@Override
public boolean isAvailable() {
switch(getZenMode()) {
case Settings.Global.ZEN_MODE_ALARMS:
case Settings.Global.ZEN_MODE_NO_INTERRUPTIONS:
case Settings.Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS:
return true;
case Settings.Global.ZEN_MODE_OFF:
default:
return false;
}
}
@Override
public String getPreferenceKey() {
return KEY;
}
@Override
public void updateState(Preference preference) {
super.updateState(preference);
boolean isAvailable = isAvailable();
preference.setVisible(isAvailable);
if (isAvailable) {
preference.setTitle(getFooterText());
}
}
protected String getFooterText() {
ZenModeConfig config = getZenModeConfig();
String footerText = "";
long latestEndTime = -1;
// DND turned on by manual rule
if (config.manualRule != null) {
final Uri id = config.manualRule.conditionId;
if (config.manualRule.enabler != null) {
// app triggered manual rule
String appOwner = mZenModeConfigWrapper.getOwnerCaption(config.manualRule.enabler);
if (!appOwner.isEmpty()) {
footerText = mContext.getString(
R.string.zen_mode_settings_dnd_automatic_rule_app, appOwner);
}
} else {
if (id == null) {
return mContext.getString(
R.string.zen_mode_settings_dnd_manual_indefinite);
} else {
latestEndTime = mZenModeConfigWrapper.parseManualRuleTime(id);
if (latestEndTime > 0) {
final CharSequence formattedTime = mZenModeConfigWrapper.getFormattedTime(
latestEndTime, mContext.getUserId());
footerText = mContext.getString(
R.string.zen_mode_settings_dnd_manual_end_time,
formattedTime);
}
}
}
}
// DND turned on by an automatic rule
for (ZenModeConfig.ZenRule automaticRule : config.automaticRules.values()) {
if (automaticRule.isAutomaticActive()) {
// set footer if 3rd party rule
if (!mZenModeConfigWrapper.isTimeRule(automaticRule.conditionId)) {
return mContext.getString(R.string.zen_mode_settings_dnd_automatic_rule,
automaticRule.name);
} else {
// set footer if automatic rule end time is the latest active rule end time
long endTime = mZenModeConfigWrapper.parseAutomaticRuleEndTime(
automaticRule.conditionId);
if (endTime > latestEndTime) {
latestEndTime = endTime;
footerText = mContext.getString(
R.string.zen_mode_settings_dnd_automatic_rule, automaticRule.name);
}
}
}
}
return footerText;
}
}

View File

@@ -46,7 +46,7 @@ public class ScreenLockSettings extends DashboardFragment
@Override
public int getMetricsCategory() {
return MetricsProto.MetricsEvent.SECURITY;
return MetricsProto.MetricsEvent.SCREEN_LOCK_SETTINGS;
}
@Override

View File

@@ -4,6 +4,7 @@ com.android.settings.bluetooth.BluetoothDeviceDetailsFragment
com.android.settings.bluetooth.BluetoothPairingDetail
com.android.settings.accounts.AccountDetailDashboardFragment
com.android.settings.fuelgauge.PowerUsageAnomalyDetails
com.android.settings.fuelgauge.PowerUsageSummaryLegacy
com.android.settings.fuelgauge.AdvancedPowerUsageDetail
com.android.settings.development.featureflags.FeatureFlagsDashboard
com.android.settings.development.qstile.DevelopmentTileConfigFragment

View File

@@ -20,4 +20,5 @@
<bool name="config_show_camera_laser_sensor">false</bool>
<bool name="config_show_connectivity_monitor">false</bool>
<bool name="config_display_recent_apps">false</bool>
<bool name="config_location_mode_available">false</bool>
</resources>

View File

@@ -1,44 +0,0 @@
/*
* 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.ims;
import android.content.Context;
/**
* Fake test class to com.android.ims.ImsManager
*/
public class ImsManager {
public static boolean wfcEnabledByPlatform;
public static boolean wfcProvisioned;
public static boolean isWfcEnabledByPlatform(Context context) {
return wfcEnabledByPlatform;
}
public static boolean isWfcProvisionedOnDevice(Context context) {
return wfcProvisioned;
}
public static int getWfcMode(Context context, boolean roaming) {
return 0;
}
public static boolean isWfcEnabledByUser(Context context) {
return false;
}
}

View File

@@ -16,6 +16,10 @@
package com.android.settings;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.verify;
import android.content.Context;
import com.android.internal.logging.nano.MetricsProto;
@@ -25,30 +29,22 @@ import com.android.settings.testutils.SettingsRobolectricTestRunner;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.Robolectric;
import org.robolectric.annotation.Config;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.verify;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class DeviceAdminAddTest {
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private Context mContext;
private FakeFeatureFactory mFeatureFactory;
private DeviceAdminAdd mDeviceAdminAdd;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
FakeFeatureFactory.setupForTest(mContext);
mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
mFeatureFactory = FakeFeatureFactory.setupForTest();
mDeviceAdminAdd = Robolectric.buildActivity(DeviceAdminAdd.class).get();
}

View File

@@ -58,7 +58,7 @@ import java.util.List;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(
manifest = TestConfig.MANIFEST_PATH,
sdk = TestConfig.SDK_VERSION_O,
sdk = TestConfig.SDK_VERSION,
shadows = {ShadowUtils.class, ShadowConnectivityManager.class, ShadowUserManager.class}
)
public class DeviceInfoSettingsTest {

View File

@@ -15,13 +15,12 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.util.ReflectionHelpers;
import java.util.ArrayList;
import java.util.List;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class DisplaySettingsTest {
@Test

View File

@@ -34,7 +34,7 @@ import static com.google.common.truth.Truth.assertThat;
import static org.robolectric.Shadows.shadowOf;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O,
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
shadows = {
ShadowHelpUtils.class
})

View File

@@ -29,7 +29,7 @@ import java.util.List;
import static com.google.common.truth.Truth.assertThat;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class LegalSettingsTest {
@Test

View File

@@ -34,7 +34,7 @@ import org.robolectric.annotation.Config;
import org.xmlpull.v1.XmlPullParserException;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class LicenseHtmlGeneratorFromXmlTest {
private static final String VAILD_XML_STRING =
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +

View File

@@ -39,7 +39,7 @@ import org.mockito.MockitoAnnotations;
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class LicenseHtmlLoaderTest {
@Mock
private Context mContext;

View File

@@ -51,7 +51,7 @@ import org.robolectric.shadows.ShadowActivity;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(
manifest = TestConfig.MANIFEST_PATH,
sdk = TestConfig.SDK_VERSION_O,
sdk = TestConfig.SDK_VERSION,
shadows = {ShadowUtils.class}
)
public class MasterClearTest {

View File

@@ -33,7 +33,7 @@ import static org.mockito.Mockito.when;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class PrivacySettingsTest {
@Mock

View File

@@ -45,7 +45,7 @@ import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class SettingsActivityTest {
@Mock(answer = Answers.RETURNS_DEEP_STUBS)

View File

@@ -33,7 +33,7 @@ import static org.mockito.Mockito.when;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class SettingsDialogFragmentTest {
private static final int DIALOG_ID = 15;

View File

@@ -37,7 +37,7 @@ import static org.mockito.Mockito.when;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class SettingsDumpServiceTest {
private static final String PACKAGE_BROWSER = "com.android.test.browser";
private static final String PACKAGE_NULL = "android";

View File

@@ -43,7 +43,7 @@ import org.robolectric.android.controller.ActivityController;
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class SettingsLicenseActivityTest {
private ActivityController<SettingsLicenseActivity> mActivityController;
private SettingsLicenseActivity mActivity;

View File

@@ -47,7 +47,7 @@ import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.shadow.SettingsShadowResources;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class SettingsPreferenceFragmentTest {
private static final int ITEM_COUNT = 5;

View File

@@ -45,7 +45,7 @@ import org.robolectric.shadows.ShadowPackageManager.ComponentState;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(
manifest = TestConfig.MANIFEST_PATH,
sdk = TestConfig.SDK_VERSION_O,
sdk = TestConfig.SDK_VERSION,
shadows = {
SettingsShadowResources.class,
SettingsShadowResourcesImpl.class,

View File

@@ -34,7 +34,7 @@ import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(
manifest = TestConfig.MANIFEST_PATH,
sdk = TestConfig.SDK_VERSION_O,
sdk = TestConfig.SDK_VERSION,
shadows = {
SettingsShadowSystemProperties.class
})

View File

@@ -35,7 +35,7 @@ import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.shadow.SettingsShadowResources;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O,
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
shadows = {
SettingsShadowResources.class,
SettingsShadowResources.SettingsShadowTheme.class

View File

@@ -23,11 +23,6 @@ import android.os.Build;
*/
public class TestConfig {
/**
* @deprecated New tests should use {@link #SDK_VERSION_O}
*/
@Deprecated
public static final int SDK_VERSION = 23;
public static final int SDK_VERSION_O = Build.VERSION_CODES.O;
public static final int SDK_VERSION = Build.VERSION_CODES.O;
public static final String MANIFEST_PATH = "packages/apps/Settings/AndroidManifest.xml";
}

View File

@@ -37,7 +37,7 @@ import org.robolectric.shadows.ShadowApplication;
import org.robolectric.util.ReflectionHelpers;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class TetherServiceTest {
@Mock

View File

@@ -44,7 +44,7 @@ import java.util.ArrayList;
import java.util.List;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class UtilsTest {
private static final String PACKAGE_NAME = "com.android.app";

View File

@@ -39,7 +39,7 @@ import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(
manifest = TestConfig.MANIFEST_PATH,
sdk = TestConfig.SDK_VERSION_O,
sdk = TestConfig.SDK_VERSION,
shadows = {
ShadowLibcoreTimeZoneNames.class,
ShadowLibcoreTimeZoneNames.ShadowZoneStringsCache.class,

View File

@@ -33,7 +33,7 @@ import java.util.List;
import static com.google.common.truth.Truth.assertThat;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class AccessibilitySettingsTest {
@Test

View File

@@ -17,7 +17,6 @@
package com.android.settings.accessibility;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
@@ -29,7 +28,6 @@ import android.os.UserManager;
import com.android.settings.TestConfig;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settingslib.wrapper.PackageManagerWrapper;
import org.junit.Before;
import org.junit.Test;
@@ -41,7 +39,7 @@ import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class ShortcutServicePickerFragmentTest {
private static final String TEST_SERVICE_KEY_1 = "abc/123";
@@ -54,15 +52,13 @@ public class ShortcutServicePickerFragmentTest {
private Activity mActivity;
@Mock
private UserManager mUserManager;
@Mock
private PackageManagerWrapper mPackageManager;
private ShortcutServicePickerFragment mFragment;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
FakeFeatureFactory.setupForTest(mActivity);
FakeFeatureFactory.setupForTest();
when(mActivity.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
mFragment = spy(new ShortcutServicePickerFragment());

View File

@@ -38,7 +38,7 @@ import org.robolectric.annotation.Config;
import org.robolectric.util.FragmentTestUtil;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O,
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
shadows = {
SettingsShadowResources.class,
SettingsShadowResources.SettingsShadowTheme.class,

View File

@@ -15,6 +15,15 @@
*/
package com.android.settings.accounts;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Answers.RETURNS_DEEP_STUBS;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import static org.robolectric.Shadows.shadowOf;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.app.Activity;
@@ -30,7 +39,6 @@ import android.support.v7.preference.PreferenceScreen;
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.TestConfig;
import com.android.settings.dashboard.DashboardFeatureProviderImpl;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settingslib.drawer.CategoryKey;
import com.android.settingslib.drawer.Tile;
@@ -45,17 +53,8 @@ import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowApplication;
import org.robolectric.util.ReflectionHelpers;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Answers.RETURNS_DEEP_STUBS;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import static org.robolectric.Shadows.shadowOf;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class AccountDetailDashboardFragmentTest {
private static final String METADATA_CATEGORY = "com.android.settings.category";
@@ -127,9 +126,6 @@ public class AccountDetailDashboardFragmentTest {
@Test
public void refreshDashboardTiles_HasAccountType_shouldAddAccountNameToIntent() {
FakeFeatureFactory.setupForTest(mContext);
final FakeFeatureFactory featureFactory =
(FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
final DashboardFeatureProviderImpl dashboardFeatureProvider =
new DashboardFeatureProviderImpl(mContext);
final PackageManager packageManager = mock(PackageManager.class);

View File

@@ -56,7 +56,7 @@ import org.robolectric.annotation.Implements;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(
manifest = TestConfig.MANIFEST_PATH,
sdk = TestConfig.SDK_VERSION_O,
sdk = TestConfig.SDK_VERSION,
shadows = AccountHeaderPreferenceControllerTest.ShadowAuthenticatorHelper.class
)
public class AccountHeaderPreferenceControllerTest {
@@ -80,7 +80,7 @@ public class AccountHeaderPreferenceControllerTest {
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
FakeFeatureFactory.setupForTest(mContext);
FakeFeatureFactory.setupForTest();
mHeaderPreference = new LayoutPreference(
RuntimeEnvironment.application, R.layout.settings_entity_header);
doReturn(mContext).when(mActivity).getApplicationContext();

View File

@@ -68,7 +68,7 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O,
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
shadows = {ShadowAccountManager.class, ShadowContentResolver.class})
public class AccountPreferenceControllerTest {

View File

@@ -35,7 +35,7 @@ import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class AccountPreferenceTest {
private Context mContext;

View File

@@ -47,7 +47,7 @@ import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowApplication;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O,
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
shadows = {ShadowAccountManager.class, ShadowContentResolver.class})
public class AccountSyncPreferenceControllerTest {

View File

@@ -50,7 +50,7 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class AccountTypePreferenceLoaderTest {
@Mock(answer = RETURNS_DEEP_STUBS)

View File

@@ -41,7 +41,7 @@ import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowApplication;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class AddUserWhenLockedPreferenceControllerTest {
@Mock(answer = RETURNS_DEEP_STUBS)

View File

@@ -44,7 +44,7 @@ import java.util.ArrayList;
import java.util.List;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class AutoSyncDataPreferenceControllerTest {
@Mock(answer = RETURNS_DEEP_STUBS)

View File

@@ -42,7 +42,7 @@ import java.util.ArrayList;
import java.util.List;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class AutoSyncPersonalDataPreferenceControllerTest {
@Mock(answer = RETURNS_DEEP_STUBS)

View File

@@ -42,7 +42,7 @@ import java.util.ArrayList;
import java.util.List;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class AutoSyncWorkDataPreferenceControllerTest {
private static int MANAGED_PROFILE_ID = 10;

View File

@@ -52,7 +52,7 @@ import java.util.ArrayList;
import java.util.List;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class EmergencyInfoPreferenceControllerTest {
@Mock(answer = RETURNS_DEEP_STUBS)

View File

@@ -32,7 +32,7 @@ import org.robolectric.annotation.Config;
import org.robolectric.util.ReflectionHelpers;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class ProviderPreferenceTest {
private Context mContext;

View File

@@ -61,7 +61,7 @@ import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowApplication;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class RemoveAccountPreferenceControllerTest {
private static final String KEY_REMOVE_ACCOUNT = "remove_account";

View File

@@ -28,7 +28,7 @@ import java.lang.reflect.Modifier;
import static com.google.common.truth.Truth.assertThat;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class RemoveUserFragmentTest {
@Test

View File

@@ -43,7 +43,7 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@RunWith(RobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class UserAndAccountDashboardFragmentTest {
private static final String METADATA_CATEGORY = "com.android.settings.category";

View File

@@ -40,7 +40,7 @@ import org.robolectric.annotation.Implements;
import java.util.List;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class AppAndNotificationDashboardFragmentTest {
@Test

View File

@@ -73,7 +73,7 @@ import java.util.HashSet;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(
manifest = TestConfig.MANIFEST_PATH,
sdk = TestConfig.SDK_VERSION_O
sdk = TestConfig.SDK_VERSION
)
public final class AppInfoDashboardFragmentTest {
@@ -100,7 +100,7 @@ public final class AppInfoDashboardFragmentTest {
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mFeatureFactory = FakeFeatureFactory.setupForTest(mContext);
mFeatureFactory = FakeFeatureFactory.setupForTest();
mShadowContext = RuntimeEnvironment.application;
mAppDetail = spy(new AppInfoDashboardFragment());
doReturn(mActivity).when(mAppDetail).getActivity();

View File

@@ -17,7 +17,6 @@
package com.android.settings.applications;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@@ -57,11 +56,9 @@ import org.robolectric.shadows.ShadowApplication;
import org.robolectric.util.ReflectionHelpers;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O,
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
shadows = ShadowEntityHeaderController.class)
public class AppInfoWithHeaderTest {
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private Context mContext;
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private EntityHeaderController mHeaderController;
@@ -71,9 +68,7 @@ public class AppInfoWithHeaderTest {
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
FakeFeatureFactory.setupForTest(mContext);
mFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
mFactory = FakeFeatureFactory.setupForTest();
when(mFactory.metricsFeatureProvider.getMetricsCategory(any(Object.class)))
.thenReturn(MetricsProto.MetricsEvent.SETTINGS_APP_NOTIF_CATEGORY);
mAppInfoWithHeader = new TestFragment();

View File

@@ -46,7 +46,7 @@ import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class AppPermissionsPreferenceControllerTest {
private static final String PERM_LOCATION = "android.permission-group.LOCATION";

View File

@@ -37,7 +37,7 @@ import org.mockito.MockitoAnnotations;
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public final class AppStateAppOpsBridgeTest {
@Mock private Context mContext;

View File

@@ -28,7 +28,7 @@ import org.junit.runner.RunWith;
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class AppStateInstallAppsBridgeTest {
@Test

View File

@@ -45,7 +45,7 @@ import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class AppStorageSettingsTest {
@Mock

View File

@@ -21,7 +21,7 @@ import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class AppStorageSizesControllerTest {
private static final String COMPUTING = "Computing…";
private static final String INVALID_SIZE = "Couldnt compute package size.";

View File

@@ -56,7 +56,7 @@ import static org.mockito.Mockito.when;
* Tests for {@link InstalledAppCounter}.
*/
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public final class AppWithAdminGrantedPermissionsCounterTest {
private final String APP_1 = "app1";

View File

@@ -55,7 +55,7 @@ import static org.mockito.Mockito.when;
* Tests for {@link AppWithAdminGrantedPermissionsLister}.
*/
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public final class AppWithAdminGrantedPermissionsListerTest {
private final String APP_1 = "app1";

View File

@@ -55,7 +55,7 @@ import static org.mockito.Mockito.when;
* Tests for {@link ApplicationFeatureProviderImpl}.
*/
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O,
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
shadows = {ShadowUserManager.class})
public final class ApplicationFeatureProviderImplTest {

View File

@@ -52,7 +52,7 @@ import org.robolectric.util.ReflectionHelpers;
import java.util.List;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class DefaultAppSettingsTest {
private Context mContext;

View File

@@ -46,7 +46,7 @@ import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowApplication;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class DrawOverlayDetailsTest {
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
@@ -63,8 +63,8 @@ public class DrawOverlayDetailsTest {
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
FakeFeatureFactory.setupForTest(mActivity);
mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mActivity);
mFeatureFactory = FakeFeatureFactory.setupForTest();
}
@Test

View File

@@ -27,7 +27,7 @@ import org.robolectric.annotation.Config;
import static junit.framework.Assert.assertTrue;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class EnterpriseDefaultAppsTest {
@Test
public void testNumberOfIntentsCorrelateWithUI() throws Exception {

View File

@@ -44,7 +44,7 @@ import org.robolectric.annotation.Config;
import java.io.IOException;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class FetchPackageStorageAsyncLoaderTest {
private static final String PACKAGE_NAME = "com.test.package";
@Mock(answer = Answers.RETURNS_DEEP_STUBS)

View File

@@ -61,7 +61,7 @@ import java.util.Set;
* Tests for {@link InstalledAppCounter}.
*/
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O,
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
shadows = {ShadowUserManager.class})
public final class InstalledAppCounterTest {

View File

@@ -85,7 +85,7 @@ import java.util.List;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(
manifest = TestConfig.MANIFEST_PATH,
sdk = TestConfig.SDK_VERSION_O,
sdk = TestConfig.SDK_VERSION,
shadows = InstalledAppDetailsTest.ShadowUtils.class
)
public final class InstalledAppDetailsTest {
@@ -130,7 +130,7 @@ public final class InstalledAppDetailsTest {
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mFeatureFactory = FakeFeatureFactory.setupForTest(mContext);
mFeatureFactory = FakeFeatureFactory.setupForTest();
mShadowContext = RuntimeEnvironment.application;
mAppDetail = spy(new InstalledAppDetails());
mAppDetail.mBatteryUtils = mBatteryUtils;

View File

@@ -57,7 +57,7 @@ import static org.mockito.Mockito.when;
* Tests for {@link InstalledAppLister}.
*/
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public final class InstalledAppListerTest {
private final String APP_1 = "app1";

View File

@@ -36,7 +36,7 @@ import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class LayoutPreferenceTest {
private Context mContext;

View File

@@ -36,7 +36,7 @@ import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class ManageDomainUrlsTest {
@Mock

View File

@@ -49,7 +49,7 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class NotificationAppsTest {
@Mock

View File

@@ -17,7 +17,6 @@
package com.android.settings.applications;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.verify;
@@ -25,34 +24,28 @@ import static org.mockito.Mockito.verify;
import android.content.Context;
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.wrapper.ActivityInfoWrapper;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class PictureInPictureDetailsTest {
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private Context mContext;
private FakeFeatureFactory mFeatureFactory;
private PictureInPictureDetails mFragment;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
FakeFeatureFactory.setupForTest(mContext);
mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
mFeatureFactory = FakeFeatureFactory.setupForTest();
mFragment = new PictureInPictureDetails();
}

View File

@@ -18,21 +18,16 @@ package com.android.settings.applications;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.nullable;
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.content.Context;
import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.UserInfo;
import android.util.Pair;
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.TestConfig;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
@@ -42,7 +37,6 @@ import com.android.settingslib.wrapper.PackageManagerWrapper;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.annotation.Config;
@@ -51,15 +45,12 @@ import java.util.ArrayList;
import java.util.Collections;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class PictureInPictureSettingsTest {
private static final int PRIMARY_USER_ID = 0;
private static final int PROFILE_USER_ID = 10;
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private Context mContext;
private FakeFeatureFactory mFeatureFactory;
private PictureInPictureSettings mFragment;
@Mock
@@ -73,8 +64,7 @@ public class PictureInPictureSettingsTest {
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
FakeFeatureFactory.setupForTest(mContext);
mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
mFeatureFactory = FakeFeatureFactory.setupForTest();
mFragment = new PictureInPictureSettings(mPackageManager, mUserManager);
mPrimaryUserPackages = new ArrayList<>();
mProfileUserPackages = new ArrayList<>();

View File

@@ -38,20 +38,16 @@ import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowApplication;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class PremiumSmsAccessTest {
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private Context mContext;
private FakeFeatureFactory mFeatureFactory;
private PremiumSmsAccess mFragment;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
FakeFeatureFactory.setupForTest(mContext);
mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
mFeatureFactory = FakeFeatureFactory.setupForTest();
mFragment = new PremiumSmsAccess();
mFragment.onAttach(ShadowApplication.getInstance().getApplicationContext());
}

View File

@@ -65,7 +65,7 @@ import java.util.ArrayList;
import java.util.List;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class RecentAppsPreferenceControllerTest {
@Mock

View File

@@ -36,7 +36,7 @@ import org.robolectric.annotation.Config;
import org.robolectric.util.ReflectionHelpers;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class SpecialAppAccessPreferenceControllerTest {
private Context mContext;
@Mock

View File

@@ -34,27 +34,21 @@ import com.android.settingslib.applications.ApplicationsState;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowApplication;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class UsageAccessDetailsTest {
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private Context mContext;
private FakeFeatureFactory mFeatureFactory;
private UsageAccessDetails mFragment;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
FakeFeatureFactory.setupForTest(mContext);
mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
mFeatureFactory = FakeFeatureFactory.setupForTest();
mFragment = new UsageAccessDetails();
mFragment.onAttach(ShadowApplication.getInstance().getApplicationContext());
}

View File

@@ -23,33 +23,27 @@ import static org.mockito.Mockito.verify;
import android.content.Context;
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class VrListenerSettingsTest {
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private Context mContext;
private FakeFeatureFactory mFeatureFactory;
private VrListenerSettings mFragment;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
FakeFeatureFactory.setupForTest(mContext);
mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
mFeatureFactory = FakeFeatureFactory.setupForTest();
mFragment = new VrListenerSettings();
}

Some files were not shown because too many files have changed in this diff Show More