Merge "Move trust agent toggles to developer options"
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 285fc56..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" />
@@ -1825,7 +1826,7 @@
<activity
android:name="Settings$PrintSettingsActivity"
android:label="@string/print_settings"
- android:icon="@*android:drawable/ic_settings_print"
+ android:icon="@drawable/ic_settings_print"
android:parentActivityName="Settings">
<intent-filter android:priority="1">
<action android:name="android.settings.ACTION_PRINT_SETTINGS" />
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/drawable/ic_settings_print.xml b/res/drawable/ic_settings_print.xml
new file mode 100644
index 0000000..dc92de0
--- /dev/null
+++ b/res/drawable/ic_settings_print.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2019 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.
+ -->
+
+<!-- Pass through drawable to framework ic_settings_print. This is necessary because this drawable
+ is used in AndroidManifest.xml and aapt cannot find drawable reference from outside of Settings
+ apk. -->
+<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
+ android:src="@*android:drawable/ic_settings_print"/>
\ No newline at end of file
diff --git a/res/layout/dialog_mobile_network_rename.xml b/res/layout/dialog_mobile_network_rename.xml
new file mode 100644
index 0000000..d67f0dc
--- /dev/null
+++ b/res/layout/dialog_mobile_network_rename.xml
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2019 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.
+-->
+<ScrollView
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content">
+
+ <LinearLayout
+ android:orientation="vertical"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:padding="@dimen/sim_content_padding">
+
+ <EditText
+ android:id="@+id/edittext"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:inputType="text"
+ android:maxLength="50"
+ android:singleLine="true">
+ <requestFocus/>
+ </EditText>
+
+ <TextView
+ style="@style/device_info_dialog_label"
+ android:id="@+id/operator_name_label"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/status_operator"/>
+ <TextView
+ style="@style/device_info_dialog_value"
+ android:id="@+id/operator_name_value"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/device_info_not_available"/>
+
+ <TextView
+ style="@style/device_info_dialog_label"
+ android:id="@+id/number_label"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/status_number_sim_status"/>
+ <TextView
+ style="@style/device_info_dialog_value"
+ android:id="@+id/number_value"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/device_info_not_available"/>
+
+ </LinearLayout>
+</ScrollView>
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/ids.xml b/res/values/ids.xml
index 66af163..ba14e85 100644
--- a/res/values/ids.xml
+++ b/res/values/ids.xml
@@ -31,4 +31,7 @@
<item type="id" name="action_drag_move_top" />
<item type="id" name="action_drag_move_bottom" />
<item type="id" name="action_drag_remove" />
+
+ <!-- For a menu item allowing users to edit a SIM display name -->
+ <item type="id" name="edit_sim_name" />
</resources>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 57cd5c4..8c5e1e1 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -7056,7 +7056,9 @@
<string name="keywords_sim_status">network, mobile network state, service state, signal strength, mobile network type, roaming, iccid</string>
<string name="keywords_model_and_hardware">serial number, hardware version</string>
<string name="keywords_android_version">android security patch level, baseband version, kernel version</string>
- <!--Search keywords for financial apps sms access settings -->
+ <!-- Search keywords for dark mode settings [CHAR LIMIT=NONE] -->
+ <string name="keywords_dark_ui_mode">theme, light, dark, mode</string>
+ <!-- Search keywords for financial apps sms access settings [CHAR LIMIT=NONE] -->
<string name="keywords_financial_apps_sms_access">financial app, sms, permission</string>
<!-- Search keyword for Device Theme Settings [CHAR LIMIT=NONE] -->
@@ -10268,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>
@@ -10456,6 +10458,14 @@
<!-- Summary for an item in the page listing multiple mobile service subscriptions, indicating
that service is inactive and is tied to an eSIM profile [CHAR LIMIT=40] -->
<string name="mobile_network_inactive_esim">Inactive eSIM</string>
+ <!-- Title of a dialog that lets a user modify the display name used for a mobile network
+ subscription in various places in the Settings app. The default name is typically just the
+ carrier name, but especially in multi-SIM configurations users may want to use a different
+ name. [CHAR LIMIT=40] -->
+ <string name="mobile_network_sim_name">SIM name</string>
+ <!-- Label on the confirmation button of a dialog that lets a user set the display name of a
+ mobile network subscription [CHAR LIMIT=20] -->
+ <string name="mobile_network_sim_name_rename">Rename</string>
<!-- Title for preferred network type [CHAR LIMIT=NONE] -->
<string name="preferred_network_mode_title">Preferred network type</string>
diff --git a/res/xml/display_settings.xml b/res/xml/display_settings.xml
index b110b46..0f4c1d3 100644
--- a/res/xml/display_settings.xml
+++ b/res/xml/display_settings.xml
@@ -141,6 +141,7 @@
android:dialogTitle="@string/dark_ui_mode_title"
android:entries="@array/dark_ui_mode_entries"
android:entryValues="@array/dark_ui_mode_values"
+ settings:keywords="@string/keywords_dark_ui_mode"
settings:controller="com.android.settings.display.DarkUIPreferenceController" />
<ListPreference
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/src/com/android/settings/accounts/AccountDetailDashboardFragment.java b/src/com/android/settings/accounts/AccountDetailDashboardFragment.java
index 4b61238..ad6ecaf 100644
--- a/src/com/android/settings/accounts/AccountDetailDashboardFragment.java
+++ b/src/com/android/settings/accounts/AccountDetailDashboardFragment.java
@@ -15,11 +15,14 @@
*/
package com.android.settings.accounts;
+import static android.content.Intent.EXTRA_USER;
+
import android.accounts.Account;
import android.accounts.AccountManager;
import android.app.Activity;
import android.app.settings.SettingsEnums;
import android.content.Context;
+import android.content.Intent;
import android.os.Bundle;
import android.os.UserHandle;
import android.os.UserManager;
@@ -56,6 +59,8 @@
String mAccountType;
private AccountSyncPreferenceController mAccountSynController;
private RemoveAccountPreferenceController mRemoveAccountController;
+ @VisibleForTesting
+ UserHandle mUserHandle;
@Override
public void onCreate(Bundle icicle) {
@@ -63,7 +68,7 @@
getPreferenceManager().setPreferenceComparisonCallback(null);
Bundle args = getArguments();
final Activity activity = getActivity();
- UserHandle userHandle = Utils.getSecureTargetUser(activity.getActivityToken(),
+ mUserHandle = Utils.getSecureTargetUser(activity.getActivityToken(),
(UserManager) getSystemService(Context.USER_SERVICE), args,
activity.getIntent().getExtras());
if (args != null) {
@@ -77,8 +82,8 @@
mAccountType = args.getString(KEY_ACCOUNT_TYPE);
}
}
- mAccountSynController.init(mAccount, userHandle);
- mRemoveAccountController.init(mAccount, userHandle);
+ mAccountSynController.init(mAccount, mUserHandle);
+ mRemoveAccountController.init(mAccount, mUserHandle);
}
@Override
@@ -154,7 +159,9 @@
}
final boolean display = mAccountType.equals(metadata.getString(METADATA_IA_ACCOUNT));
if (display) {
- tile.getIntent().putExtra(EXTRA_ACCOUNT_NAME, mAccount.name);
+ final Intent intent = tile.getIntent();
+ intent.putExtra(EXTRA_ACCOUNT_NAME, mAccount.name);
+ intent.putExtra(EXTRA_USER, mUserHandle);
}
return display;
}
diff --git a/src/com/android/settings/accounts/AvatarViewMixin.java b/src/com/android/settings/accounts/AvatarViewMixin.java
index 43531b3..3ce8c0a 100644
--- a/src/com/android/settings/accounts/AvatarViewMixin.java
+++ b/src/com/android/settings/accounts/AvatarViewMixin.java
@@ -17,6 +17,7 @@
package com.android.settings.accounts;
import android.accounts.Account;
+import android.app.settings.SettingsEnums;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
@@ -38,6 +39,7 @@
import com.android.settings.R;
import com.android.settings.homepage.SettingsHomepageActivity;
import com.android.settings.overlay.FeatureFactory;
+import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
import com.android.settingslib.utils.ThreadUtils;
import java.net.URISyntaxException;
@@ -91,6 +93,12 @@
return;
}
+ final MetricsFeatureProvider metricsFeatureProvider = FeatureFactory.getFactory(
+ mContext).getMetricsFeatureProvider();
+ metricsFeatureProvider.action(SettingsEnums.PAGE_UNKNOWN,
+ SettingsEnums.CLICK_ACCOUNT_AVATAR, SettingsEnums.SETTINGS_HOMEPAGE,
+ null /* key */, Integer.MIN_VALUE /* value */);
+
// Here may have two different UI while start the activity.
// It will display adding account UI when device has no any account.
// It will display account information page when intent added the specified account.
diff --git a/src/com/android/settings/dashboard/DashboardFeatureProviderImpl.java b/src/com/android/settings/dashboard/DashboardFeatureProviderImpl.java
index f79cf5b..69e86cd 100644
--- a/src/com/android/settings/dashboard/DashboardFeatureProviderImpl.java
+++ b/src/com/android/settings/dashboard/DashboardFeatureProviderImpl.java
@@ -16,6 +16,8 @@
package com.android.settings.dashboard;
+import static android.content.Intent.EXTRA_USER;
+
import static com.android.settingslib.drawer.TileUtils.META_DATA_PREFERENCE_ICON_URI;
import static com.android.settingslib.drawer.TileUtils.META_DATA_PREFERENCE_SUMMARY;
import static com.android.settingslib.drawer.TileUtils.META_DATA_PREFERENCE_SUMMARY_URI;
@@ -29,6 +31,7 @@
import android.graphics.drawable.Drawable;
import android.graphics.drawable.Icon;
import android.os.Bundle;
+import android.os.UserHandle;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.ArrayMap;
@@ -239,7 +242,14 @@
mMetricsFeatureProvider.logDashboardStartIntent(mContext, intent, sourceMetricCategory);
activity.startActivityForResultAsUser(intent, 0, tile.userHandle.get(0));
} else {
- ProfileSelectDialog.show(activity.getSupportFragmentManager(), tile);
+ final UserHandle userHandle = intent.getParcelableExtra(EXTRA_USER);
+ if (userHandle != null && tile.userHandle.contains(userHandle)) {
+ mMetricsFeatureProvider.logDashboardStartIntent(
+ mContext, intent, sourceMetricCategory);
+ activity.startActivityForResultAsUser(intent, 0, userHandle);
+ } else {
+ ProfileSelectDialog.show(activity.getSupportFragmentManager(), tile);
+ }
}
}
diff --git a/src/com/android/settings/development/gamedriver/GameDriverEnableForAllAppsPreferenceController.java b/src/com/android/settings/development/gamedriver/GameDriverEnableForAllAppsPreferenceController.java
index 68be526..dd48f69 100644
--- a/src/com/android/settings/development/gamedriver/GameDriverEnableForAllAppsPreferenceController.java
+++ b/src/com/android/settings/development/gamedriver/GameDriverEnableForAllAppsPreferenceController.java
@@ -74,6 +74,7 @@
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
mPreference = screen.findPreference(getPreferenceKey());
+ mPreference.setOnPreferenceChangeListener(this);
}
@Override
@@ -98,8 +99,20 @@
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
+ final boolean isChecked = (boolean) newValue;
+ final int gameDriver = Settings.Global.getInt(
+ mContentResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT);
+
+ if (isChecked && gameDriver == GAME_DRIVER_ALL_APPS) {
+ return true;
+ }
+
+ if (!isChecked && (gameDriver == GAME_DRIVER_DEFAULT || gameDriver == GAME_DRIVER_OFF)) {
+ return true;
+ }
+
Settings.Global.putInt(mContentResolver, Settings.Global.GAME_DRIVER_ALL_APPS,
- (boolean) newValue ? GAME_DRIVER_ALL_APPS : GAME_DRIVER_DEFAULT);
+ isChecked ? GAME_DRIVER_ALL_APPS : GAME_DRIVER_DEFAULT);
return true;
}
diff --git a/src/com/android/settings/development/gamedriver/GameDriverGlobalSwitchBarController.java b/src/com/android/settings/development/gamedriver/GameDriverGlobalSwitchBarController.java
index 125d95b..d84c28f 100644
--- a/src/com/android/settings/development/gamedriver/GameDriverGlobalSwitchBarController.java
+++ b/src/com/android/settings/development/gamedriver/GameDriverGlobalSwitchBarController.java
@@ -79,19 +79,21 @@
@Override
public boolean onSwitchToggled(boolean isChecked) {
- if (!isChecked) {
- Settings.Global.putInt(
- mContentResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_OFF);
+ final int gameDriver = Settings.Global.getInt(
+ mContentResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT);
+
+ if (isChecked
+ && (gameDriver == GAME_DRIVER_DEFAULT || gameDriver == GAME_DRIVER_ALL_APPS)) {
return true;
}
- if (Settings.Global.getInt(
- mContentResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT)
- != GAME_DRIVER_ALL_APPS) {
- Settings.Global.putInt(
- mContentResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT);
+ if (!isChecked && gameDriver == GAME_DRIVER_OFF) {
+ return true;
}
+ Settings.Global.putInt(mContentResolver, Settings.Global.GAME_DRIVER_ALL_APPS,
+ isChecked ? GAME_DRIVER_DEFAULT : GAME_DRIVER_OFF);
+
return true;
}
diff --git a/src/com/android/settings/display/AdaptiveSleepPreferenceController.java b/src/com/android/settings/display/AdaptiveSleepPreferenceController.java
index 97bdb9e..bd9d386 100644
--- a/src/com/android/settings/display/AdaptiveSleepPreferenceController.java
+++ b/src/com/android/settings/display/AdaptiveSleepPreferenceController.java
@@ -17,7 +17,6 @@
import android.content.Context;
import android.provider.Settings;
-import android.text.TextUtils;
import com.android.settings.R;
import com.android.settings.core.TogglePreferenceController;
diff --git a/src/com/android/settings/homepage/contextualcards/legacysuggestion/LegacySuggestionContextualCardController.java b/src/com/android/settings/homepage/contextualcards/legacysuggestion/LegacySuggestionContextualCardController.java
index bbcebbe..3b0b46d 100644
--- a/src/com/android/settings/homepage/contextualcards/legacysuggestion/LegacySuggestionContextualCardController.java
+++ b/src/com/android/settings/homepage/contextualcards/legacysuggestion/LegacySuggestionContextualCardController.java
@@ -128,8 +128,10 @@
return;
}
final List<Suggestion> suggestions = mSuggestionController.getSuggestions();
- Log.d(TAG, "Loaded suggests: "
- + suggestions == null ? "null" : String.valueOf(suggestions.size()));
+ final String suggestionCount = suggestions == null
+ ? "null"
+ : String.valueOf(suggestions.size());
+ Log.d(TAG, "Loaded suggests: " + suggestionCount);
final List<ContextualCard> cards = new ArrayList<>();
if (suggestions != null) {
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/AppLocationPermissionPreferenceController.java b/src/com/android/settings/location/AppLocationPermissionPreferenceController.java
index 1fd1986..43a6a9b 100644
--- a/src/com/android/settings/location/AppLocationPermissionPreferenceController.java
+++ b/src/com/android/settings/location/AppLocationPermissionPreferenceController.java
@@ -76,7 +76,7 @@
PermissionControllerManager permController =
mContext.getSystemService(PermissionControllerManager.class);
permController.countPermissionApps(
- Arrays.asList(ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION), false, false,
+ Arrays.asList(ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION), 0,
(numApps) -> {
mNumTotal = numApps;
if (loadingInProgress.decrementAndGet() == 0) {
@@ -85,7 +85,8 @@
}, null);
permController.countPermissionApps(
- Collections.singletonList(ACCESS_BACKGROUND_LOCATION), true, false,
+ Collections.singletonList(ACCESS_BACKGROUND_LOCATION),
+ PermissionControllerManager.COUNT_ONLY_WHEN_GRANTED,
(numApps) -> {
mNumBackground = numApps;
if (loadingInProgress.decrementAndGet() == 0) {
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/location/TopLevelLocationPreferenceController.java b/src/com/android/settings/location/TopLevelLocationPreferenceController.java
index 6d7789f..2a7a3d7 100644
--- a/src/com/android/settings/location/TopLevelLocationPreferenceController.java
+++ b/src/com/android/settings/location/TopLevelLocationPreferenceController.java
@@ -71,7 +71,7 @@
return;
}
mContext.getSystemService(PermissionControllerManager.class).countPermissionApps(
- Arrays.asList(ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION), false, false,
+ Arrays.asList(ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION), 0,
(numApps) -> {
setLocationAppCount(numApps);
}, null);
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/network/telephony/MobileNetworkActivity.java b/src/com/android/settings/network/telephony/MobileNetworkActivity.java
index a5f011c..821b1e1e 100644
--- a/src/com/android/settings/network/telephony/MobileNetworkActivity.java
+++ b/src/com/android/settings/network/telephony/MobileNetworkActivity.java
@@ -97,13 +97,6 @@
actionBar.setDisplayHomeAsUpEnabled(true);
}
- // Set the title to the name of the subscription. If we don't have subscription info, the
- // title will just default to the label for this activity that's already specified in
- // AndroidManifest.xml.
- final SubscriptionInfo subscription = getSubscription();
- if (subscription != null) {
- setTitle(subscription.getDisplayName());
- }
updateSubscriptions(savedInstanceState);
}
@@ -136,6 +129,14 @@
@VisibleForTesting
void updateSubscriptions(Bundle savedInstanceState) {
+ // Set the title to the name of the subscription. If we don't have subscription info, the
+ // title will just default to the label for this activity that's already specified in
+ // AndroidManifest.xml.
+ final SubscriptionInfo subscription = getSubscription();
+ if (subscription != null) {
+ setTitle(subscription.getDisplayName());
+ }
+
mSubscriptionInfos = mSubscriptionManager.getActiveSubscriptionInfoList(true);
if (!FeatureFlagPersistent.isEnabled(this, FeatureFlags.NETWORK_INTERNET_V2)) {
diff --git a/src/com/android/settings/network/telephony/MobileNetworkSettings.java b/src/com/android/settings/network/telephony/MobileNetworkSettings.java
index 5201586..a4156f5 100644
--- a/src/com/android/settings/network/telephony/MobileNetworkSettings.java
+++ b/src/com/android/settings/network/telephony/MobileNetworkSettings.java
@@ -28,9 +28,9 @@
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Log;
-
-import androidx.annotation.VisibleForTesting;
-import androidx.preference.Preference;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
import com.android.internal.telephony.TelephonyIntents;
import com.android.settings.R;
@@ -52,6 +52,9 @@
import java.util.Arrays;
import java.util.List;
+import androidx.annotation.VisibleForTesting;
+import androidx.preference.Preference;
+
@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
public class MobileNetworkSettings extends RestrictedDashboardFragment {
@@ -219,6 +222,31 @@
}
}
+ @Override
+ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
+ if (FeatureFlagPersistent.isEnabled(getContext(), FeatureFlags.NETWORK_INTERNET_V2) &&
+ mSubId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
+ final MenuItem item = menu.add(Menu.NONE, R.id.edit_sim_name, Menu.NONE,
+ R.string.mobile_network_sim_name);
+ item.setIcon(com.android.internal.R.drawable.ic_mode_edit);
+ item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
+ }
+ super.onCreateOptionsMenu(menu, inflater);
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem menuItem) {
+ if (FeatureFlagPersistent.isEnabled(getContext(), FeatureFlags.NETWORK_INTERNET_V2) &&
+ mSubId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
+ if (menuItem.getItemId() == R.id.edit_sim_name) {
+ RenameMobileNetworkDialogFragment.newInstance(mSubId).show(
+ getFragmentManager(), RenameMobileNetworkDialogFragment.TAG);
+ return true;
+ }
+ }
+ return super.onOptionsItemSelected(menuItem);
+ }
+
public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider() {
@Override
diff --git a/src/com/android/settings/network/telephony/RenameMobileNetworkDialogFragment.java b/src/com/android/settings/network/telephony/RenameMobileNetworkDialogFragment.java
new file mode 100644
index 0000000..488f930
--- /dev/null
+++ b/src/com/android/settings/network/telephony/RenameMobileNetworkDialogFragment.java
@@ -0,0 +1,137 @@
+/*
+ * Copyright (C) 2019 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.network.telephony;
+
+import android.app.Dialog;
+import android.app.settings.SettingsEnums;
+import android.content.Context;
+import android.os.Bundle;
+import android.telephony.ServiceState;
+import android.telephony.SubscriptionInfo;
+import android.telephony.SubscriptionManager;
+import android.telephony.TelephonyManager;
+import android.text.BidiFormatter;
+import android.text.TextDirectionHeuristics;
+import android.text.TextUtils;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.EditText;
+import android.widget.TextView;
+
+import com.android.settings.R;
+import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
+import com.android.settingslib.DeviceInfoUtils;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.annotation.VisibleForTesting;
+import androidx.appcompat.app.AlertDialog;
+
+/** A dialog allowing the display name of a mobile network subscription to be changed */
+public class RenameMobileNetworkDialogFragment extends InstrumentedDialogFragment {
+ public static final String TAG ="RenameMobileNetwork";
+
+ private static final String KEY_SUBSCRIPTION_ID = "subscription_id";
+
+ private TelephonyManager mTelephonyManager;
+ private SubscriptionManager mSubscriptionManager;
+ private int mSubId;
+ private EditText mNameView;
+
+ public static RenameMobileNetworkDialogFragment newInstance(int subscriptionId) {
+ final Bundle args = new Bundle(1);
+ args.putInt(KEY_SUBSCRIPTION_ID, subscriptionId);
+ final RenameMobileNetworkDialogFragment fragment = new RenameMobileNetworkDialogFragment();
+ fragment.setArguments(args);
+ return fragment;
+ }
+
+ @VisibleForTesting
+ protected TelephonyManager getTelephonyManager(Context context) {
+ return context.getSystemService(TelephonyManager.class);
+ }
+
+ @VisibleForTesting
+ protected SubscriptionManager getSubscriptionManager(Context context) {
+ return context.getSystemService(SubscriptionManager.class);
+ }
+
+ @VisibleForTesting
+ protected EditText getNameView() {
+ return mNameView;
+ }
+
+ @Override
+ public void onAttach(Context context) {
+ super.onAttach(context);
+ mTelephonyManager = getTelephonyManager(context);
+ mSubscriptionManager = getSubscriptionManager(context);
+ mSubId = getArguments().getInt(KEY_SUBSCRIPTION_ID);
+ }
+
+ @NonNull
+ @Override
+ public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
+ final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
+ final LayoutInflater layoutInflater = builder.getContext().getSystemService(
+ LayoutInflater.class);
+ final View view = layoutInflater.inflate(R.layout.dialog_mobile_network_rename, null);
+ populateView(view);
+ builder.setTitle(R.string.mobile_network_sim_name)
+ .setView(view)
+ .setPositiveButton(R.string.mobile_network_sim_name_rename, (dialog, which) -> {
+ SubscriptionInfo currentInfo = mSubscriptionManager.getActiveSubscriptionInfo(
+ mSubId);
+ String newName = mNameView.getText().toString();
+ if (currentInfo != null && !currentInfo.getDisplayName().equals(newName)) {
+ mSubscriptionManager.setDisplayName(newName, mSubId);
+ }
+ })
+ .setNegativeButton(android.R.string.cancel, null);
+ return builder.create();
+ }
+
+ @VisibleForTesting
+ protected void populateView(View view) {
+ mNameView = (EditText) view.findViewById(R.id.edittext);
+ final SubscriptionInfo info = mSubscriptionManager.getActiveSubscriptionInfo(mSubId);
+ if (info == null) {
+ Log.w(TAG, "got null SubscriptionInfo for mSubId:" + mSubId);
+ return;
+ }
+ final CharSequence displayName = info.getDisplayName();
+ mNameView.setText(displayName);
+ if (!TextUtils.isEmpty(displayName)) {
+ mNameView.setSelection(displayName.length());
+ }
+
+ final TextView operatorName = view.findViewById(R.id.operator_name_value);
+ final ServiceState serviceState = mTelephonyManager.getServiceStateForSubscriber(mSubId);
+ operatorName.setText(serviceState.getOperatorAlphaLong());
+
+ final TextView phoneNumber = view.findViewById(R.id.number_value);
+ final String formattedNumber = DeviceInfoUtils.getFormattedPhoneNumber(getContext(), info);
+ phoneNumber.setText(BidiFormatter.getInstance().unicodeWrap(formattedNumber,
+ TextDirectionHeuristics.LTR));
+ }
+
+ @Override
+ public int getMetricsCategory() {
+ return SettingsEnums.MOBILE_NETWORK_RENAME_DIALOG;
+ }
+}
diff --git a/src/com/android/settings/notification/SilentStatusBarPreferenceController.java b/src/com/android/settings/notification/SilentStatusBarPreferenceController.java
index 4721f5c..5bf943a 100644
--- a/src/com/android/settings/notification/SilentStatusBarPreferenceController.java
+++ b/src/com/android/settings/notification/SilentStatusBarPreferenceController.java
@@ -24,17 +24,24 @@
import com.android.settings.core.TogglePreferenceController;
+import com.google.common.annotations.VisibleForTesting;
+
public class SilentStatusBarPreferenceController extends TogglePreferenceController {
private static final String KEY = "hide_silent_icons";
private static final int MY_USER_ID = UserHandle.myUserId();
- private final NotificationBackend mBackend;
+ private NotificationBackend mBackend;
public SilentStatusBarPreferenceController(Context context) {
super(context, KEY);
mBackend = new NotificationBackend();
}
+ @VisibleForTesting
+ void setBackend(NotificationBackend backend) {
+ mBackend = backend;
+ }
+
@Override
public boolean isChecked() {
return mBackend.shouldHideSilentStatusBarIcons(mContext);
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/widget/EntityHeaderController.java b/src/com/android/settings/widget/EntityHeaderController.java
index 5672178..8e31290 100644
--- a/src/com/android/settings/widget/EntityHeaderController.java
+++ b/src/com/android/settings/widget/EntityHeaderController.java
@@ -322,7 +322,7 @@
Utils.getColorAttrDefaultColor(activity, android.R.attr.colorPrimaryDark)));
actionBar.setElevation(0);
if (mRecyclerView != null && mLifecycle != null) {
- ActionBarShadowController.attachToRecyclerView(mActivity, mLifecycle, mRecyclerView);
+ ActionBarShadowController.attachToView(mActivity, mLifecycle, mRecyclerView);
}
return this;
diff --git a/src/com/android/settings/wifi/WifiConfigController.java b/src/com/android/settings/wifi/WifiConfigController.java
index 739ddd7..1d78485 100644
--- a/src/com/android/settings/wifi/WifiConfigController.java
+++ b/src/com/android/settings/wifi/WifiConfigController.java
@@ -366,9 +366,8 @@
suggestionOrSpecifierPackageName = config.creatorName;
}
String summary = AccessPoint.getSummary(
- mConfigUi.getContext(), state, isEphemeral,
- suggestionOrSpecifierPackageName,
- providerFriendlyName);
+ mConfigUi.getContext(), /* ssid */ null, state, isEphemeral,
+ suggestionOrSpecifierPackageName);
addRow(group, R.string.wifi_status, summary);
}
diff --git a/src/com/android/settings/wifi/WifiStatusTest.java b/src/com/android/settings/wifi/WifiStatusTest.java
index b063433..ca7f5f7 100644
--- a/src/com/android/settings/wifi/WifiStatusTest.java
+++ b/src/com/android/settings/wifi/WifiStatusTest.java
@@ -299,7 +299,8 @@
WifiInfo info = mWifiManager.getConnectionInfo();
String summary = AccessPoint.getSummary(this, info.getSSID(),
networkInfo.getDetailedState(),
- info.getNetworkId() == WifiConfiguration.INVALID_NETWORK_ID, null, null);
+ info.getNetworkId() == WifiConfiguration.INVALID_NETWORK_ID,
+ /* suggestionOrSpecifierPackageName */ null);
mNetworkState.setText(summary);
}
}
diff --git a/tests/robotests/src/com/android/settings/accounts/AccountDetailDashboardFragmentTest.java b/tests/robotests/src/com/android/settings/accounts/AccountDetailDashboardFragmentTest.java
index 0be51c3..dffa968 100644
--- a/tests/robotests/src/com/android/settings/accounts/AccountDetailDashboardFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/accounts/AccountDetailDashboardFragmentTest.java
@@ -15,6 +15,8 @@
*/
package com.android.settings.accounts;
+import static android.content.Intent.EXTRA_USER;
+
import static com.android.settingslib.drawer.TileUtils.META_DATA_PREFERENCE_KEYHINT;
import static com.android.settingslib.drawer.TileUtils.META_DATA_PREFERENCE_TITLE;
@@ -161,6 +163,20 @@
}
@Test
+ public void displayTile_shouldAddUserHandleToTileIntent() {
+ mFragment.mUserHandle = new UserHandle(1);
+
+ final Tile tile = new Tile(mActivityInfo, CategoryKey.CATEGORY_ACCOUNT_DETAIL);
+ mActivityInfo.metaData.putString(METADATA_CATEGORY, CategoryKey.CATEGORY_ACCOUNT);
+ mActivityInfo.metaData.putString(METADATA_ACCOUNT_TYPE, "com.abc");
+
+ mFragment.displayTile(tile);
+
+ final UserHandle userHandle = tile.getIntent().getParcelableExtra(EXTRA_USER);
+ assertThat(userHandle.getIdentifier()).isEqualTo(1);
+ }
+
+ @Test
public void onResume_accountMissing_shouldFinish() {
ShadowUserManager userManager =
Shadow.extract(mContext.getSystemService(UserManager.class));
diff --git a/tests/robotests/src/com/android/settings/dashboard/DashboardFeatureProviderImplTest.java b/tests/robotests/src/com/android/settings/dashboard/DashboardFeatureProviderImplTest.java
index 2aa6ae2..1c51b81 100644
--- a/tests/robotests/src/com/android/settings/dashboard/DashboardFeatureProviderImplTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/DashboardFeatureProviderImplTest.java
@@ -16,6 +16,8 @@
package com.android.settings.dashboard;
+import static android.content.Intent.EXTRA_USER;
+
import static com.android.settingslib.drawer.TileUtils.META_DATA_KEY_ORDER;
import static com.android.settingslib.drawer.TileUtils.META_DATA_KEY_PROFILE;
import static com.android.settingslib.drawer.TileUtils.META_DATA_PREFERENCE_KEYHINT;
@@ -67,6 +69,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Answers;
+import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.Robolectric;
@@ -412,4 +415,44 @@
.startActivityForResult(any(Intent.class), eq(0));
verify(mActivity, never()).getSupportFragmentManager();
}
+
+ @Test
+ public void openTileIntent_profileSelectionDialog_validUserHandleShouldNotShow() {
+ final int userId = 10;
+ ShadowUserManager.getShadow().addUser(userId, "Someone", 0);
+
+ final UserHandle userHandle = new UserHandle(userId);
+ final Tile tile = new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
+ tile.getIntent().putExtra(EXTRA_USER, userHandle);
+ final ArrayList<UserHandle> handles = new ArrayList<>();
+ handles.add(new UserHandle(0));
+ handles.add(userHandle);
+ tile.userHandle = handles;
+
+ mImpl.openTileIntent(mActivity, tile);
+
+ final ArgumentCaptor<UserHandle> argument = ArgumentCaptor.forClass(UserHandle.class);
+ verify(mActivity)
+ .startActivityForResultAsUser(any(Intent.class), anyInt(), argument.capture());
+ assertThat(argument.getValue().getIdentifier()).isEqualTo(userId);
+ verify(mActivity, never()).getSupportFragmentManager();
+ }
+
+ @Test
+ public void openTileIntent_profileSelectionDialog_invalidUserHandleShouldShow() {
+ ShadowUserManager.getShadow().addUser(10, "Someone", 0);
+
+ final Tile tile = new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
+ tile.getIntent().putExtra(EXTRA_USER, new UserHandle(30));
+ final ArrayList<UserHandle> handles = new ArrayList<>();
+ handles.add(new UserHandle(0));
+ handles.add(new UserHandle(10));
+ tile.userHandle = handles;
+
+ mImpl.openTileIntent(mActivity, tile);
+
+ verify(mActivity, never())
+ .startActivityForResultAsUser(any(Intent.class), anyInt(), any(UserHandle.class));
+ verify(mActivity).getSupportFragmentManager();
+ }
}
diff --git a/tests/robotests/src/com/android/settings/development/gamedriver/GameDriverEnableForAllAppsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/gamedriver/GameDriverEnableForAllAppsPreferenceControllerTest.java
index 094cd21..3d418d9 100644
--- a/tests/robotests/src/com/android/settings/development/gamedriver/GameDriverEnableForAllAppsPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/development/gamedriver/GameDriverEnableForAllAppsPreferenceControllerTest.java
@@ -21,6 +21,7 @@
import static com.android.settings.development.gamedriver.GameDriverEnableForAllAppsPreferenceController.GAME_DRIVER_ALL_APPS;
import static com.android.settings.development.gamedriver.GameDriverEnableForAllAppsPreferenceController.GAME_DRIVER_DEFAULT;
import static com.android.settings.development.gamedriver.GameDriverEnableForAllAppsPreferenceController.GAME_DRIVER_OFF;
+
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.atLeastOnce;
@@ -61,11 +62,14 @@
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
mResolver = mContext.getContentResolver();
+
+ Settings.Global.putInt(mResolver, Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
+ Settings.Global.putInt(
+ mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT);
+
mController = new GameDriverEnableForAllAppsPreferenceController(mContext, "testKey");
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
mController.displayPreference(mScreen);
-
- Settings.Global.putInt(mResolver, Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
}
@Test
@@ -151,7 +155,7 @@
mController.onPreferenceChange(mPreference, true);
assertThat(Settings.Global.getInt(
- mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT))
+ mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT))
.isEqualTo(GAME_DRIVER_ALL_APPS);
}
@@ -162,7 +166,7 @@
mController.onPreferenceChange(mPreference, false);
assertThat(Settings.Global.getInt(
- mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT))
+ mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT))
.isEqualTo(GAME_DRIVER_DEFAULT);
}
}
diff --git a/tests/robotests/src/com/android/settings/homepage/contextualcards/legacysuggestion/LegacySuggestionContextualCardControllerTest.java b/tests/robotests/src/com/android/settings/homepage/contextualcards/legacysuggestion/LegacySuggestionContextualCardControllerTest.java
index ebc2154..a2d4d09 100644
--- a/tests/robotests/src/com/android/settings/homepage/contextualcards/legacysuggestion/LegacySuggestionContextualCardControllerTest.java
+++ b/tests/robotests/src/com/android/settings/homepage/contextualcards/legacysuggestion/LegacySuggestionContextualCardControllerTest.java
@@ -19,6 +19,7 @@
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
import android.content.Context;
@@ -84,8 +85,10 @@
@Test
public void onServiceConnected_shouldLoadSuggestion() {
+ when(mSuggestionController.getSuggestions()).thenReturn(null);
mController.mSuggestionController = mSuggestionController;
mController.setCardUpdateListener(mCardUpdateListener);
+
mController.onServiceConnected();
verify(mSuggestionController).getSuggestions();
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/network/telephony/RenameMobileNetworkDialogFragmentTest.java b/tests/robotests/src/com/android/settings/network/telephony/RenameMobileNetworkDialogFragmentTest.java
new file mode 100644
index 0000000..df52302
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/network/telephony/RenameMobileNetworkDialogFragmentTest.java
@@ -0,0 +1,130 @@
+/*
+ * Copyright (C) 2019 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.network.telephony;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.content.DialogInterface;
+import android.telephony.ServiceState;
+import android.telephony.SubscriptionInfo;
+import android.telephony.SubscriptionManager;
+import android.telephony.TelephonyManager;
+import android.widget.Button;
+import android.widget.EditText;
+
+import com.android.settings.testutils.shadow.ShadowAlertDialogCompat;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.Robolectric;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.annotation.Config;
+
+import androidx.appcompat.app.AlertDialog;
+import androidx.fragment.app.FragmentActivity;
+
+@RunWith(RobolectricTestRunner.class)
+@Config(shadows = ShadowAlertDialogCompat.class)
+public class RenameMobileNetworkDialogFragmentTest {
+ @Mock
+ private TelephonyManager mTelephonyMgr;
+ @Mock
+ private SubscriptionManager mSubscriptionMgr;
+ @Mock
+ private SubscriptionInfo mSubscriptionInfo;
+
+ private FragmentActivity mActivity;
+ private RenameMobileNetworkDialogFragment mFragment;
+ private int mSubscriptionId = 1234;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mActivity = spy(Robolectric.buildActivity(FragmentActivity.class).setup().get());
+
+ when(mSubscriptionInfo.getSubscriptionId()).thenReturn(mSubscriptionId);
+ when(mSubscriptionInfo.getDisplayName()).thenReturn("test");
+
+ mFragment = spy(RenameMobileNetworkDialogFragment.newInstance(mSubscriptionId));
+ doReturn(mTelephonyMgr).when(mFragment).getTelephonyManager(any());
+ doReturn(mSubscriptionMgr).when(mFragment).getSubscriptionManager(any());
+
+ final ServiceState serviceState = mock(ServiceState.class);
+ when(serviceState.getOperatorAlphaLong()).thenReturn("fake carrier name");
+ when(mTelephonyMgr.getServiceStateForSubscriber(mSubscriptionId)).thenReturn(serviceState);
+ }
+
+ @Test
+ public void dialog_subscriptionMissing_noCrash() {
+ final AlertDialog dialog = startDialog();
+ final Button negativeButton = dialog.getButton(DialogInterface.BUTTON_NEGATIVE);
+ assertThat(negativeButton).isNotNull();
+ negativeButton.performClick();
+ }
+
+ @Test
+ public void dialog_cancelButtonClicked_setDisplayNameNotCalled() {
+ when(mSubscriptionMgr.getActiveSubscriptionInfo(mSubscriptionId)).thenReturn(
+ mSubscriptionInfo);
+ final AlertDialog dialog = startDialog();
+ final EditText nameView = mFragment.getNameView();
+ nameView.setText("test2");
+
+ final Button negativeButton = dialog.getButton(DialogInterface.BUTTON_NEGATIVE);
+ negativeButton.performClick();
+
+ verify(mSubscriptionMgr, never()).setDisplayName(anyString(), anyInt());
+ }
+
+ @Test
+ public void dialog_renameButtonClicked_setDisplayNameCalled() {
+ when(mSubscriptionMgr.getActiveSubscriptionInfo(mSubscriptionId)).thenReturn(
+ mSubscriptionInfo);
+
+ final AlertDialog dialog = startDialog();
+ final EditText nameView = mFragment.getNameView();
+ nameView.setText("test2");
+
+ final Button positiveButton = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
+ positiveButton.performClick();
+
+ final ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
+ verify(mSubscriptionMgr).setDisplayName(captor.capture(), eq(mSubscriptionId));
+ assertThat(captor.getValue()).isEqualTo("test2");
+ }
+
+ /** Helper method to start the dialog */
+ private AlertDialog startDialog() {
+ mFragment.show(mActivity.getSupportFragmentManager(), null);
+ return ShadowAlertDialogCompat.getLatestAlertDialog();
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/notification/SilentStatusBarPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/SilentStatusBarPreferenceControllerTest.java
index 8a43a1e..9dd8ff9 100644
--- a/tests/robotests/src/com/android/settings/notification/SilentStatusBarPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/SilentStatusBarPreferenceControllerTest.java
@@ -48,7 +48,6 @@
@Mock
private PreferenceScreen mScreen;
- private FakeFeatureFactory mFeatureFactory;
private Context mContext;
private SilentStatusBarPreferenceController mController;
private Preference mPreference;
@@ -57,8 +56,8 @@
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
- mFeatureFactory = FakeFeatureFactory.setupForTest();
mController = new SilentStatusBarPreferenceController(mContext);
+ mController.setBackend(mBackend);
mPreference = new Preference(mContext);
mPreference.setKey(mController.getPreferenceKey());
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
@@ -83,7 +82,7 @@
when(mBackend.shouldHideSilentStatusBarIcons(any())).thenReturn(false);
assertThat(mController.isChecked()).isFalse();
}
-/**
+
@Test
public void isChecked_settingIsOn_true() {
when(mBackend.shouldHideSilentStatusBarIcons(any())).thenReturn(true);
@@ -93,18 +92,13 @@
@Test
public void onPreferenceChange_on() {
mController.onPreferenceChange(mPreference, true);
-
- assertThat(mController.isChecked()).isTrue();
verify(mBackend).setHideSilentStatusIcons(true);
}
@Test
public void onPreferenceChange_off() {
mController.onPreferenceChange(mPreference, false);
-
- assertThat(mController.isChecked()).isFalse();
verify(mBackend).setHideSilentStatusIcons(false);
}
- **/
}
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);
+ }
}