Merge "Use adaptive icon shapes for settings homeepage"
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index b457977..dccd1d0 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -57,6 +57,7 @@
<uses-permission android:name="android.permission.READ_SYNC_STATS" />
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />
+ <uses-permission android:name="android.permission.READ_DEVICE_CONFIG" />
<uses-permission android:name="android.permission.STATUS_BAR" />
<uses-permission android:name="android.permission.MANAGE_USB" />
<uses-permission android:name="android.permission.MANAGE_DEBUGGING" />
diff --git a/res/drawable/ic_menu_add_white.xml b/res/drawable/ic_menu_add_white.xml
deleted file mode 100644
index 25a8ff0..0000000
--- a/res/drawable/ic_menu_add_white.xml
+++ /dev/null
@@ -1,28 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- Copyright (C) 2016 The Android Open Source Project
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
--->
-
-<vector
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:width="24dp"
- android:height="24dp"
- android:viewportWidth="24.0"
- android:viewportHeight="24.0"
- android:tint="?android:attr/colorControlNormal">
- <path
- android:fillColor="#FFFFFFFF"
- android:pathData="M19,13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"/>
-</vector>
diff --git a/res/menu/vpn.xml b/res/menu/vpn.xml
index 7b35c70..a3b8090 100644
--- a/res/menu/vpn.xml
+++ b/res/menu/vpn.xml
@@ -18,6 +18,6 @@
<item
android:id="@+id/vpn_create"
android:title="@string/vpn_create"
- android:icon="@drawable/ic_menu_add_white"
+ android:icon="@drawable/ic_menu_add"
android:showAsAction="always" />
</menu>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 039fb13..1b1a7f3 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -820,9 +820,9 @@
<string name="lockdown_settings_summary">Display power button option that turns off Smart Lock, fingerprint unlocking, and notifications on the lock screen</string>
<!-- Text shown for the title of the extend unlock mode option for trust agents [CHAR LIMIT=40] -->
- <string name="trust_agents_extend_unlock_title">SmartLock only extends unlock</string>
+ <string name="trust_agents_extend_unlock_title">Trust agents only extend unlock</string>
<!-- Text shown for the description of the extend unlock mode option [CHAR LIMIT=NONE] -->
- <string name="trust_agents_extend_unlock_summary">If enabled, SmartLock will keep your device unlocked for longer, but can no longer unlock a locked device.</string>
+ <string name="trust_agents_extend_unlock_summary">If enabled, trust agents will keep your device unlocked for longer, but can no longer unlock a locked device.</string>
<!-- Text shown for the title of the lock when trust lost option [CHAR LIMIT=40] -->
<string name="trust_lost_locks_screen_title">Lock screen when trust is lost</string>
@@ -4771,13 +4771,13 @@
<!-- Summary for the accessibility preference for hearing aid when not connected. [CHAR LIMIT=50] -->
<string name="accessibility_hearingaid_not_connected_summary">No hearing aids connected</string>
<!-- Summary for the accessibility preference for hearing aid when adding new devices. [CHAR LIMIT=50] -->
- <string name="accessibility_hearingaid_adding_summary">Add hearing aid</string>
+ <string name="accessibility_hearingaid_adding_summary">Add hearing aids</string>
<!-- Message to ask the user that if they want to pair the hearing aid, then they should find and tap the hearing aid device from the list on the next screen. [CHAR LIMIT=NONE] -->
<string name="accessibility_hearingaid_pair_instructions_first_message">To pair your hearing aids, find and tap your device on the next screen.</string>
<!-- Message to ask the user to make sure that their hearing aid devices are in pairing mode. [CHAR LIMIT=NONE] -->
<string name="accessibility_hearingaid_pair_instructions_second_message">Make sure your hearing aids are in pairing mode.</string>
<!-- Summary for the accessibility preference for hearing aid when there is an active device. [CHAR LIMIT=50] -->
- <string name="accessibility_hearingaid_active_device_summary"><xliff:g id="device_name">%1$s</xliff:g> currently active</string>
+ <string name="accessibility_hearingaid_active_device_summary"><xliff:g id="device_name">%1$s</xliff:g> active</string>
<!-- Summary for the accessibility preference for hearing aid when there are saved devices. [CHAR LIMIT=50] -->
<plurals name="show_number_hearingaid_count">
<item quantity="one"><xliff:g id="number_device_count">%1$d</xliff:g> saved hearing aid</item>
@@ -10270,11 +10270,11 @@
<!-- Summary for battery Suggestion. [CHAR LIMIT=55] -->
<string name="battery_suggestion_summary"></string>
- <!-- Title for prevent ringing gesture screen -->
+ <!-- Title for prevent ringing gesture screen [CHAR LIMIT=60]-->
<string name="gesture_prevent_ringing_screen_title">Prevent ringing</string>
- <!-- Title for prevent ringing setting -->
+ <!-- Title for prevent ringing setting [CHAR LIMIT=60]-->
<string name="gesture_prevent_ringing_title">Press Power & Volume Up together to</string>
- <!-- Title for prevent ringing setting -->
+ <!-- Title for prevent ringing setting [CHAR LIMIT=60]-->
<string name="gesture_prevent_ringing_sound_title">Shortcut to prevent ringing</string>
<!-- Option for prevent ringing setting -->
<string name="prevent_ringing_option_vibrate">Vibrate</string>
diff --git a/res/xml/development_settings.xml b/res/xml/development_settings.xml
index d7fcaec..b9e809c 100644
--- a/res/xml/development_settings.xml
+++ b/res/xml/development_settings.xml
@@ -114,6 +114,17 @@
android:key="quick_settings_tiles"
android:title="@string/quick_settings_developer_tiles"
android:fragment="com.android.settings.development.qstile.DevelopmentTileConfigFragment" />
+
+ <!-- Configure trust agent behavior -->
+ <SwitchPreference
+ android:key="security_setting_trust_agents_extend_unlock"
+ android:title="@string/trust_agents_extend_unlock_title"
+ android:summary="@string/trust_agents_extend_unlock_summary" />
+
+ <SwitchPreference
+ android:key="security_setting_trust_lost_locks_screen"
+ android:title="@string/trust_lost_locks_screen_title"
+ android:summary="@string/trust_lost_locks_screen_summary" />
</PreferenceCategory>
<PreferenceCategory
diff --git a/res/xml/location_settings.xml b/res/xml/location_settings.xml
index 72ea312..29d4048 100644
--- a/res/xml/location_settings.xml
+++ b/res/xml/location_settings.xml
@@ -28,7 +28,7 @@
<PreferenceCategory
android:key="location_advanced_settings"
- settings:initialExpandedChildrenCount="0">
+ settings:initialExpandedChildrenCount="2">
<!-- This preference category gets removed if new_recent_location_ui is disabled -->
<Preference
diff --git a/res/xml/screen_lock_settings.xml b/res/xml/screen_lock_settings.xml
index 29c8de9..dd4ac34 100644
--- a/res/xml/screen_lock_settings.xml
+++ b/res/xml/screen_lock_settings.xml
@@ -40,17 +40,4 @@
android:key="power_button_instantly_locks"
android:title="@string/lockpattern_settings_enable_power_button_instantly_locks" />
- <!-- Temporarily available to evaluate extend unlock mode for SmartLock -->
- <SwitchPreference
- android:key="security_setting_trust_agents_extend_unlock"
- android:title="@string/trust_agents_extend_unlock_title"
- android:summary="@string/trust_agents_extend_unlock_summary"
- settings:controller="com.android.settings.security.trustagent.TrustAgentsExtendUnlockPreferenceController" />
-
- <SwitchPreference
- android:key="security_setting_trust_lost_locks_screen"
- android:title="@string/trust_lost_locks_screen_title"
- android:summary="@string/trust_lost_locks_screen_summary"
- settings:controller="com.android.settings.security.trustagent.TrustLostLocksScreenPreferenceController" />
-
</PreferenceScreen>
diff --git a/src/com/android/settings/applications/appinfo/AppDataUsagePreferenceController.java b/src/com/android/settings/applications/appinfo/AppDataUsagePreferenceController.java
index 1bfcd7d..7d9fdcf 100644
--- a/src/com/android/settings/applications/appinfo/AppDataUsagePreferenceController.java
+++ b/src/com/android/settings/applications/appinfo/AppDataUsagePreferenceController.java
@@ -89,7 +89,7 @@
public Loader<List<NetworkCycleDataForUid>> onCreateLoader(int id, Bundle args) {
final NetworkTemplate template = getTemplate(mContext);
return NetworkCycleDataForUidLoader.builder(mContext)
- .setUid(mParent.getAppEntry().info.uid)
+ .addUid(mParent.getAppEntry().info.uid)
.setRetrieveDetail(false)
.setNetworkTemplate(template)
.setSubscriberId(template.getSubscriberId())
diff --git a/src/com/android/settings/datausage/AppDataUsage.java b/src/com/android/settings/datausage/AppDataUsage.java
index 329bf68..4f38843 100644
--- a/src/com/android/settings/datausage/AppDataUsage.java
+++ b/src/com/android/settings/datausage/AppDataUsage.java
@@ -94,10 +94,12 @@
private SpinnerPreference mCycle;
private RestrictedSwitchPreference mUnrestrictedData;
private DataSaverBackend mDataSaverBackend;
+ private Context mContext;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
+ mContext = getContext();
mPackageManager = getPackageManager();
final Bundle args = getArguments();
@@ -105,9 +107,8 @@
mTemplate = (args != null) ? (NetworkTemplate) args.getParcelable(ARG_NETWORK_TEMPLATE)
: null;
if (mTemplate == null) {
- Context context = getContext();
- mTemplate = DataUsageUtils.getDefaultTemplate(context,
- DataUsageUtils.getDefaultSubscriptionId(context));
+ mTemplate = DataUsageUtils.getDefaultTemplate(mContext,
+ DataUsageUtils.getDefaultSubscriptionId(mContext));
}
if (mAppItem == null) {
int uid = (args != null) ? args.getInt(AppInfoBase.ARG_PACKAGE_UID, -1)
@@ -131,7 +132,7 @@
mBackgroundUsage = findPreference(KEY_BACKGROUND_USAGE);
mCycle = (SpinnerPreference) findPreference(KEY_CYCLE);
- mCycleAdapter = new CycleAdapter(getContext(), mCycle, mCycleListener);
+ mCycleAdapter = new CycleAdapter(mContext, mCycle, mCycleListener);
if (mAppItem.key > 0) {
if (mPackages.size() != 0) {
@@ -155,7 +156,7 @@
KEY_UNRESTRICTED_DATA);
mUnrestrictedData.setOnPreferenceChangeListener(this);
}
- mDataSaverBackend = new DataSaverBackend(getContext());
+ mDataSaverBackend = new DataSaverBackend(mContext);
mAppSettings = findPreference(KEY_APP_SETTINGS);
mAppSettingsIntent = new Intent(Intent.ACTION_MANAGE_NETWORK_USAGE);
@@ -256,7 +257,7 @@
private void updatePrefs(boolean restrictBackground, boolean unrestrictData) {
final EnforcedAdmin admin = RestrictedLockUtilsInternal.checkIfMeteredDataRestricted(
- getContext(), mPackageName, UserHandle.getUserId(mAppItem.key));
+ mContext, mPackageName, UserHandle.getUserId(mAppItem.key));
if (mRestrictBackground != null) {
mRestrictBackground.setChecked(!restrictBackground);
mRestrictBackground.setDisabledByAdmin(admin);
@@ -294,11 +295,10 @@
foregroundBytes = data.getForegroudUsage();
}
final long totalBytes = backgroundBytes + foregroundBytes;
- final Context context = getContext();
- mTotalUsage.setSummary(DataUsageUtils.formatDataUsage(context, totalBytes));
- mForegroundUsage.setSummary(DataUsageUtils.formatDataUsage(context, foregroundBytes));
- mBackgroundUsage.setSummary(DataUsageUtils.formatDataUsage(context, backgroundBytes));
+ mTotalUsage.setSummary(DataUsageUtils.formatDataUsage(mContext, totalBytes));
+ mForegroundUsage.setSummary(DataUsageUtils.formatDataUsage(mContext, foregroundBytes));
+ mBackgroundUsage.setSummary(DataUsageUtils.formatDataUsage(mContext, backgroundBytes));
}
private boolean getAppRestrictBackground() {
@@ -364,16 +364,24 @@
}
};
- private final LoaderManager.LoaderCallbacks<List<NetworkCycleDataForUid>> mUidDataCallbacks =
+ @VisibleForTesting
+ final LoaderManager.LoaderCallbacks<List<NetworkCycleDataForUid>> mUidDataCallbacks =
new LoaderManager.LoaderCallbacks<List<NetworkCycleDataForUid>>() {
@Override
public Loader<List<NetworkCycleDataForUid>> onCreateLoader(int id, Bundle args) {
- return NetworkCycleDataForUidLoader.builder(getContext())
- .setUid(mAppItem.key)
- .setRetrieveDetail(true)
+ final NetworkCycleDataForUidLoader.Builder builder
+ = NetworkCycleDataForUidLoader.builder(mContext);
+ builder.setRetrieveDetail(true)
.setNetworkTemplate(mTemplate)
- .setSubscriberId(mTemplate.getSubscriberId())
- .build();
+ .setSubscriberId(mTemplate.getSubscriberId());
+ if (mAppItem.category == AppItem.CATEGORY_USER) {
+ for (int i = 0; i < mAppItem.uids.size(); i++) {
+ builder.addUid(mAppItem.uids.keyAt(i));
+ }
+ } else {
+ builder.addUid(mAppItem.key);
+ }
+ return builder.build();
}
@Override
diff --git a/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java b/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java
index 5135fbf..48597c6 100644
--- a/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java
+++ b/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java
@@ -497,6 +497,8 @@
"android.theme.customization.font"));
controllers.add(new OverlayCategoryPreferenceController(context,
"android.theme.customization.adaptive_icon_shape"));
+ controllers.add(new TrustAgentsExtendUnlockPreferenceController(context));
+ controllers.add(new TrustLostLocksScreenPreferenceController(context));
return controllers;
}
diff --git a/src/com/android/settings/development/TrustAgentsExtendUnlockPreferenceController.java b/src/com/android/settings/development/TrustAgentsExtendUnlockPreferenceController.java
new file mode 100644
index 0000000..0834f9b
--- /dev/null
+++ b/src/com/android/settings/development/TrustAgentsExtendUnlockPreferenceController.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.development;
+
+import android.content.Context;
+import android.provider.Settings;
+
+import androidx.preference.Preference;
+import androidx.preference.SwitchPreference;
+
+import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settingslib.development.DeveloperOptionsPreferenceController;
+
+public class TrustAgentsExtendUnlockPreferenceController extends
+ DeveloperOptionsPreferenceController implements
+ Preference.OnPreferenceChangeListener, PreferenceControllerMixin {
+
+ private static final String KEY_TRUST_AGENTS_EXTEND_UNLOCK =
+ "security_setting_trust_agents_extend_unlock";
+
+ public TrustAgentsExtendUnlockPreferenceController(Context context) {
+ super(context);
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return KEY_TRUST_AGENTS_EXTEND_UNLOCK;
+ }
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ final boolean isEnabled = (Boolean) newValue;
+ Settings.Secure.putInt(mContext.getContentResolver(),
+ Settings.Secure.TRUST_AGENTS_EXTEND_UNLOCK, isEnabled ? 1 : 0);
+ return true;
+ }
+
+ @Override
+ public void updateState(Preference preference) {
+ int trustAgentsExtendUnlock = Settings.Secure.getInt(mContext.getContentResolver(),
+ Settings.Secure.TRUST_AGENTS_EXTEND_UNLOCK, 0);
+ ((SwitchPreference) mPreference).setChecked(trustAgentsExtendUnlock != 0);
+ }
+}
diff --git a/src/com/android/settings/development/TrustLostLocksScreenPreferenceController.java b/src/com/android/settings/development/TrustLostLocksScreenPreferenceController.java
new file mode 100644
index 0000000..3800fd6
--- /dev/null
+++ b/src/com/android/settings/development/TrustLostLocksScreenPreferenceController.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.development;
+
+import android.content.Context;
+import android.provider.Settings;
+
+import androidx.preference.Preference;
+import androidx.preference.SwitchPreference;
+
+import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settingslib.development.DeveloperOptionsPreferenceController;
+
+public class TrustLostLocksScreenPreferenceController
+ extends DeveloperOptionsPreferenceController implements
+ Preference.OnPreferenceChangeListener, PreferenceControllerMixin {
+
+ private static final String KEY_TRUST_LOST_LOCKS_SCREEN =
+ "security_setting_trust_lost_locks_screen";
+
+ public TrustLostLocksScreenPreferenceController(Context context) {
+ super(context);
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return KEY_TRUST_LOST_LOCKS_SCREEN;
+ }
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ final boolean isEnabled = (Boolean) newValue;
+ Settings.Secure.putInt(mContext.getContentResolver(),
+ Settings.Secure.LOCK_SCREEN_WHEN_TRUST_LOST, isEnabled ? 1 : 0);
+ return true;
+ }
+
+ @Override
+ public void updateState(Preference preference) {
+ int lockOnTrustLost = Settings.Secure.getInt(mContext.getContentResolver(),
+ Settings.Secure.LOCK_SCREEN_WHEN_TRUST_LOST, 0);
+ ((SwitchPreference) mPreference).setChecked(lockOnTrustLost != 0);
+ }
+}
diff --git a/src/com/android/settings/inputmethod/UserDictionarySettings.java b/src/com/android/settings/inputmethod/UserDictionarySettings.java
index eccfb3c..c8fb625 100644
--- a/src/com/android/settings/inputmethod/UserDictionarySettings.java
+++ b/src/com/android/settings/inputmethod/UserDictionarySettings.java
@@ -154,7 +154,7 @@
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
MenuItem actionItem =
menu.add(0, OPTIONS_MENU_ADD, 0, R.string.user_dict_settings_add_menu_title)
- .setIcon(R.drawable.ic_menu_add_white);
+ .setIcon(R.drawable.ic_menu_add);
actionItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM |
MenuItem.SHOW_AS_ACTION_WITH_TEXT);
}
diff --git a/src/com/android/settings/location/RecentLocationAccessPreferenceController.java b/src/com/android/settings/location/RecentLocationAccessPreferenceController.java
index 3adc489..214dcd5 100644
--- a/src/com/android/settings/location/RecentLocationAccessPreferenceController.java
+++ b/src/com/android/settings/location/RecentLocationAccessPreferenceController.java
@@ -18,6 +18,7 @@
import android.Manifest;
import android.content.Context;
import android.content.Intent;
+import android.provider.DeviceConfig;
import android.view.View;
import androidx.annotation.VisibleForTesting;
@@ -60,7 +61,9 @@
@Override
public boolean isAvailable() {
- return true;
+ return Boolean.parseBoolean(
+ DeviceConfig.getProperty(DeviceConfig.Privacy.NAMESPACE,
+ DeviceConfig.Privacy.PROPERTY_PERMISSIONS_HUB_ENABLED));
}
@Override
diff --git a/src/com/android/settings/network/ApnSettings.java b/src/com/android/settings/network/ApnSettings.java
index 174257b..c397600 100755
--- a/src/com/android/settings/network/ApnSettings.java
+++ b/src/com/android/settings/network/ApnSettings.java
@@ -351,7 +351,7 @@
if (mAllowAddingApns) {
menu.add(0, MENU_NEW, 0,
getResources().getString(R.string.menu_new))
- .setIcon(R.drawable.ic_menu_add_white)
+ .setIcon(R.drawable.ic_menu_add)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
}
menu.add(0, MENU_RESTORE, 0,
diff --git a/src/com/android/settings/privacy/PermissionBarChartPreferenceController.java b/src/com/android/settings/privacy/PermissionBarChartPreferenceController.java
index e43140f..8b9b595 100644
--- a/src/com/android/settings/privacy/PermissionBarChartPreferenceController.java
+++ b/src/com/android/settings/privacy/PermissionBarChartPreferenceController.java
@@ -26,6 +26,7 @@
import android.graphics.drawable.Drawable;
import android.permission.PermissionControllerManager;
import android.permission.RuntimePermissionUsageInfo;
+import android.provider.DeviceConfig;
import android.util.Log;
import android.view.View;
@@ -38,6 +39,7 @@
import com.android.settingslib.widget.BarChartInfo;
import com.android.settingslib.widget.BarChartPreference;
import com.android.settingslib.widget.BarViewInfo;
+import com.android.settingslib.Utils;
import java.util.ArrayList;
import java.util.Comparator;
@@ -62,7 +64,10 @@
@Override
public int getAvailabilityStatus() {
- return AVAILABLE_UNSEARCHABLE;
+ return Boolean.parseBoolean(
+ DeviceConfig.getProperty(DeviceConfig.Privacy.NAMESPACE,
+ DeviceConfig.Privacy.PROPERTY_PERMISSIONS_HUB_ENABLED)) ?
+ AVAILABLE_UNSEARCHABLE : UNSUPPORTED_ON_DEVICE;
}
@Override
@@ -143,6 +148,7 @@
try {
icon = mPackageManager.getPermissionGroupInfo(permissionGroup.toString(), 0)
.loadIcon(mPackageManager);
+ icon.setTintList(Utils.getColorAttr(mContext, android.R.attr.textColorSecondary));
} catch (PackageManager.NameNotFoundException e) {
Log.w(TAG, "Cannot find group icon for " + permissionGroup, e);
}
diff --git a/src/com/android/settings/security/trustagent/TrustAgentsExtendUnlockPreferenceController.java b/src/com/android/settings/security/trustagent/TrustAgentsExtendUnlockPreferenceController.java
deleted file mode 100644
index 036e07f..0000000
--- a/src/com/android/settings/security/trustagent/TrustAgentsExtendUnlockPreferenceController.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright (C) 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.security.trustagent;
-
-import android.content.Context;
-import android.provider.Settings;
-
-import com.android.settings.core.TogglePreferenceController;
-
-public class TrustAgentsExtendUnlockPreferenceController extends TogglePreferenceController {
-
- public TrustAgentsExtendUnlockPreferenceController(Context context, String key) {
- super(context, key);
- }
-
- @Override
- public int getAvailabilityStatus() {
- return AVAILABLE;
- }
-
- @Override
- public boolean isChecked() {
- return Settings.Secure.getInt(mContext.getContentResolver(),
- Settings.Secure.TRUST_AGENTS_EXTEND_UNLOCK, 1) == 1;
- }
-
- @Override
- public boolean setChecked(boolean isChecked) {
- Settings.Secure.putInt(mContext.getContentResolver(),
- Settings.Secure.TRUST_AGENTS_EXTEND_UNLOCK, isChecked ? 1 : 0);
- return true;
- }
-}
diff --git a/src/com/android/settings/security/trustagent/TrustLostLocksScreenPreferenceController.java b/src/com/android/settings/security/trustagent/TrustLostLocksScreenPreferenceController.java
deleted file mode 100644
index e0c5168..0000000
--- a/src/com/android/settings/security/trustagent/TrustLostLocksScreenPreferenceController.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright (C) 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.security.trustagent;
-
-import android.content.Context;
-import android.provider.Settings;
-
-import com.android.settings.core.TogglePreferenceController;
-
-public class TrustLostLocksScreenPreferenceController extends TogglePreferenceController {
-
- public TrustLostLocksScreenPreferenceController(Context context, String key) {
- super(context, key);
- }
-
- @Override
- public int getAvailabilityStatus() {
- return AVAILABLE;
- }
-
- @Override
- public boolean isChecked() {
- return Settings.Secure.getInt(mContext.getContentResolver(),
- Settings.Secure.LOCK_SCREEN_WHEN_TRUST_LOST, 1) == 1;
- }
-
- @Override
- public boolean setChecked(boolean isChecked) {
- Settings.Secure.putInt(mContext.getContentResolver(),
- Settings.Secure.LOCK_SCREEN_WHEN_TRUST_LOST, isChecked ? 1 : 0);
- return true;
- }
-}
diff --git a/src/com/android/settings/slices/SlicesDatabaseAccessor.java b/src/com/android/settings/slices/SlicesDatabaseAccessor.java
index ae77dd2..fcc42e4 100644
--- a/src/com/android/settings/slices/SlicesDatabaseAccessor.java
+++ b/src/com/android/settings/slices/SlicesDatabaseAccessor.java
@@ -75,8 +75,9 @@
if (pathData == null) {
throw new IllegalStateException("Invalid Slices uri: " + uri);
}
- Cursor cursor = getIndexedSliceData(pathData.second /* key */);
- return buildSliceData(cursor, uri, pathData.first /* isIntentOnly */);
+ try (Cursor cursor = getIndexedSliceData(pathData.second /* key */)) {
+ return buildSliceData(cursor, uri, pathData.first /* isIntentOnly */);
+ }
}
/**
@@ -85,8 +86,9 @@
* Used when handling the action of the {@link Slice}.
*/
public SliceData getSliceDataFromKey(String key) {
- Cursor cursor = getIndexedSliceData(key);
- return buildSliceData(cursor, null /* uri */, false /* isIntentOnly */);
+ try (Cursor cursor = getIndexedSliceData(key)) {
+ return buildSliceData(cursor, null /* uri */, false /* isIntentOnly */);
+ }
}
/**
diff --git a/tests/robotests/src/com/android/settings/datausage/AppDataUsageTest.java b/tests/robotests/src/com/android/settings/datausage/AppDataUsageTest.java
index 37bb3cd..12559f4 100644
--- a/tests/robotests/src/com/android/settings/datausage/AppDataUsageTest.java
+++ b/tests/robotests/src/com/android/settings/datausage/AppDataUsageTest.java
@@ -16,6 +16,8 @@
package com.android.settings.datausage;
+import static com.google.common.truth.Truth.assertThat;
+
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
@@ -31,7 +33,9 @@
import android.content.Context;
import android.content.pm.PackageManager;
import android.net.NetworkPolicyManager;
+import android.net.NetworkTemplate;
import android.os.Bundle;
+import android.text.format.DateUtils;
import android.util.ArraySet;
import android.view.View;
@@ -47,6 +51,7 @@
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
import com.android.settingslib.RestrictedSwitchPreference;
import com.android.settingslib.net.NetworkCycleDataForUid;
+import com.android.settingslib.net.NetworkCycleDataForUidLoader;
import org.junit.After;
import org.junit.Before;
@@ -188,7 +193,7 @@
ReflectionHelpers.setField(mFragment, "mBackgroundUsage", preference);
ReflectionHelpers.setField(mFragment, "mForegroundUsage", preference);
ReflectionHelpers.setField(mFragment, "mTotalUsage", preference);
- doReturn(RuntimeEnvironment.application).when(mFragment).getContext();
+ ReflectionHelpers.setField(mFragment, "mContext", RuntimeEnvironment.application);
mFragment.bindData(0 /* position */);
@@ -199,7 +204,7 @@
public void bindData_hasAppUsageData_shouldShowCycleSpinnerAndUpdateUsageSummary() {
mFragment = spy(new AppDataUsage());
final Context context = RuntimeEnvironment.application;
- doReturn(context).when(mFragment).getContext();
+ ReflectionHelpers.setField(mFragment, "mContext", context);
final long backgroundBytes = 1234L;
final long foregroundBytes = 5678L;
final List<NetworkCycleDataForUid> appUsage = new ArrayList<>();
@@ -223,4 +228,53 @@
verify(backgroundPref).setSummary(DataUsageUtils.formatDataUsage(context, backgroundBytes));
verify(foregroundPref).setSummary(DataUsageUtils.formatDataUsage(context, foregroundBytes));
}
+
+ @Test
+ public void onCreateLoader_categoryApp_shouldQueryDataUsageUsingAppKey() {
+ mFragment = new AppDataUsage();
+ final Context context = RuntimeEnvironment.application;
+ final int testUid = 123123;
+ final AppItem appItem = new AppItem(testUid);
+ appItem.category = AppItem.CATEGORY_APP;
+ ReflectionHelpers.setField(mFragment, "mContext", context);
+ ReflectionHelpers.setField(mFragment, "mAppItem", appItem);
+ ReflectionHelpers.setField(mFragment, "mTemplate",
+ NetworkTemplate.buildTemplateWifiWildcard());
+ final long end = System.currentTimeMillis();
+ final long start = end - (DateUtils.WEEK_IN_MILLIS * 4);
+
+ final NetworkCycleDataForUidLoader loader = (NetworkCycleDataForUidLoader)
+ mFragment.mUidDataCallbacks.onCreateLoader(0, Bundle.EMPTY);
+
+ final List<Integer> uids = loader.getUids();
+ assertThat(uids).hasSize(1);
+ assertThat(uids.get(0)).isEqualTo(testUid);
+ }
+
+ @Test
+ public void onCreateLoader_categoryUser_shouldQueryDataUsageUsingAssociatedUids() {
+ mFragment = new AppDataUsage();
+ final Context context = RuntimeEnvironment.application;
+ final int testUserId = 11;
+ final AppItem appItem = new AppItem(testUserId);
+ appItem.category = AppItem.CATEGORY_USER;
+ appItem.addUid(123);
+ appItem.addUid(456);
+ appItem.addUid(789);
+ ReflectionHelpers.setField(mFragment, "mContext", context);
+ ReflectionHelpers.setField(mFragment, "mAppItem", appItem);
+ ReflectionHelpers.setField(mFragment, "mTemplate",
+ NetworkTemplate.buildTemplateWifiWildcard());
+ final long end = System.currentTimeMillis();
+ final long start = end - (DateUtils.WEEK_IN_MILLIS * 4);
+
+ final NetworkCycleDataForUidLoader loader = (NetworkCycleDataForUidLoader)
+ mFragment.mUidDataCallbacks.onCreateLoader(0, Bundle.EMPTY);
+
+ final List<Integer> uids = loader.getUids();
+ assertThat(uids).hasSize(3);
+ assertThat(uids.get(0)).isEqualTo(123);
+ assertThat(uids.get(1)).isEqualTo(456);
+ assertThat(uids.get(2)).isEqualTo(789);
+ }
}
diff --git a/tests/robotests/src/com/android/settings/location/RecentLocationAccessPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/location/RecentLocationAccessPreferenceControllerTest.java
index 8cba1de..2d3cb0c 100644
--- a/tests/robotests/src/com/android/settings/location/RecentLocationAccessPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/location/RecentLocationAccessPreferenceControllerTest.java
@@ -24,6 +24,7 @@
import android.content.Context;
import android.graphics.drawable.Drawable;
+import android.provider.DeviceConfig;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
@@ -32,9 +33,11 @@
import androidx.preference.PreferenceScreen;
import com.android.settings.R;
+import com.android.settings.testutils.shadow.ShadowDeviceConfig;
import com.android.settingslib.location.RecentLocationAccesses;
import com.android.settingslib.widget.LayoutPreference;
+import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
@@ -43,11 +46,13 @@
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
import java.util.ArrayList;
import java.util.List;
@RunWith(RobolectricTestRunner.class)
+@Config(shadows = {ShadowDeviceConfig.class})
public class RecentLocationAccessPreferenceControllerTest {
@Mock
private LayoutPreference mLayoutPreference;
@@ -76,6 +81,25 @@
mAppEntitiesHeaderView);
}
+ @After
+ public void tearDown() {
+ ShadowDeviceConfig.reset();
+ }
+
+ @Test
+ public void isAvailable_permissionHubNotSet_shouldReturnFalse() {
+ // We have not yet set the property to show the Permissions Hub.
+ assertThat(mController.isAvailable()).isEqualTo(false);
+ }
+
+ @Test
+ public void isAvailable_permissionHubEnabled_shouldReturnTrue() {
+ DeviceConfig.setProperty(DeviceConfig.Privacy.NAMESPACE,
+ DeviceConfig.Privacy.PROPERTY_PERMISSIONS_HUB_ENABLED, "true", true);
+
+ assertThat(mController.isAvailable()).isEqualTo(true);
+ }
+
/** Verifies the title text, details text are correct, and the click listener is set. */
@Test
@Ignore
diff --git a/tests/robotests/src/com/android/settings/privacy/PermissionBarChartPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/privacy/PermissionBarChartPreferenceControllerTest.java
index 119ac7d..b947630 100644
--- a/tests/robotests/src/com/android/settings/privacy/PermissionBarChartPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/privacy/PermissionBarChartPreferenceControllerTest.java
@@ -17,6 +17,7 @@
package com.android.settings.privacy;
import static com.android.settings.core.BasePreferenceController.AVAILABLE_UNSEARCHABLE;
+import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
import static com.google.common.truth.Truth.assertThat;
@@ -28,13 +29,16 @@
import android.content.Context;
import android.permission.RuntimePermissionUsageInfo;
+import android.provider.DeviceConfig;
import androidx.preference.PreferenceScreen;
+import com.android.settings.testutils.shadow.ShadowDeviceConfig;
import com.android.settingslib.widget.BarChartInfo;
import com.android.settingslib.widget.BarChartPreference;
import com.android.settingslib.widget.BarViewInfo;
+import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -42,11 +46,13 @@
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
import java.util.ArrayList;
import java.util.List;
@RunWith(RobolectricTestRunner.class)
+@Config(shadows = {ShadowDeviceConfig.class})
public class PermissionBarChartPreferenceControllerTest {
@Mock
@@ -65,8 +71,22 @@
.thenReturn((BarChartPreference) mPreference);
}
+ @After
+ public void tearDown() {
+ ShadowDeviceConfig.reset();
+ }
+
@Test
- public void getAvailabilityStatus_shouldReturnAvailableUnsearchable() {
+ public void getAvailabilityStatus_permissionHubNotSet_shouldReturnUnsupported() {
+ // We have not yet set the property to show the Permissions Hub.
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
+ }
+
+ @Test
+ public void getAvailabilityStatus_permissionHubEnabled_shouldReturnAvailableUnsearchable() {
+ DeviceConfig.setProperty(DeviceConfig.Privacy.NAMESPACE,
+ DeviceConfig.Privacy.PROPERTY_PERMISSIONS_HUB_ENABLED, "true", true);
+
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE_UNSEARCHABLE);
}
diff --git a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowDeviceConfig.java b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowDeviceConfig.java
index d46e755..dfd0988 100644
--- a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowDeviceConfig.java
+++ b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowDeviceConfig.java
@@ -19,21 +19,32 @@
import org.robolectric.annotation.Config;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
+import org.robolectric.annotation.Resetter;
+
+import java.util.HashMap;
+import java.util.Map;
@Implements(android.provider.DeviceConfig.class)
public class ShadowDeviceConfig {
- private static String configValue;
+ private static Map<String, String> sPropertyMaps = new HashMap<>();
+
+ @Resetter
+ public static void reset() {
+ sPropertyMaps.clear();
+ }
@Implementation
- protected static boolean setProperty(
- String namespace, String name, String value, boolean makeDefault) {
- configValue = value;
+ public static boolean setProperty(
+ String namespace, String name, String value, boolean makeDefault) {
+ sPropertyMaps.put(name, value);
return true;
}
@Implementation
- protected static String getProperty(String ns, String key) { return configValue; }
+ public static String getProperty(String namespace, String name) {
+ return sPropertyMaps.get(name);
+ }
}