Convert more pages to use ActionButtonPreference
- text to speech page - blue tooth detail page - installed app page Change-Id: Ib743a144cc6025055cd496ec077f13fce4db0c69 Bug: 63991885 Test: robotests
This commit is contained in:
@@ -1,48 +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.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:gravity="bottom"
|
|
||||||
android:paddingTop="4dp"
|
|
||||||
android:paddingStart="68dp"
|
|
||||||
android:paddingEnd="8dp"
|
|
||||||
android:orientation="horizontal">
|
|
||||||
|
|
||||||
<Button
|
|
||||||
android:id="@+id/tts_play_button"
|
|
||||||
style="@style/android:Widget.Material.Button.Colored"
|
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_gravity="center"
|
|
||||||
android:paddingEnd="8dp"
|
|
||||||
android:text="@string/tts_play"/>
|
|
||||||
|
|
||||||
<Button
|
|
||||||
android:id="@+id/tts_reset_button"
|
|
||||||
style="@style/android:Widget.Material.Button"
|
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_gravity="center"
|
|
||||||
android:paddingStart="8dp"
|
|
||||||
android:text="@string/tts_reset"/>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
@@ -19,8 +19,8 @@
|
|||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:gravity="bottom"
|
android:gravity="center"
|
||||||
android:paddingTop="4dp"
|
android:paddingTop="8dp"
|
||||||
android:paddingStart="68dp"
|
android:paddingStart="68dp"
|
||||||
android:paddingEnd="8dp"
|
android:paddingEnd="8dp"
|
||||||
android:orientation="horizontal">
|
android:orientation="horizontal">
|
||||||
@@ -34,15 +34,13 @@
|
|||||||
style="@style/AppActionPrimaryButton"
|
style="@style/AppActionPrimaryButton"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center"
|
android:layout_marginBottom="4dp" />
|
||||||
android:paddingEnd="8dp" />
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/button1_negative"
|
android:id="@+id/button1_negative"
|
||||||
style="@style/ActionSecondaryButton"
|
style="@style/ActionSecondaryButton"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center"
|
android:layout_marginBottom="4dp" />
|
||||||
android:paddingStart="8dp" />
|
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
<FrameLayout
|
<FrameLayout
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
@@ -53,14 +51,12 @@
|
|||||||
style="@style/AppActionPrimaryButton"
|
style="@style/AppActionPrimaryButton"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center"
|
android:layout_marginBottom="4dp" />
|
||||||
android:paddingStart="8dp" />
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/button2_negative"
|
android:id="@+id/button2_negative"
|
||||||
style="@style/ActionSecondaryButton"
|
style="@style/ActionSecondaryButton"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center"
|
android:layout_marginBottom="4dp" />
|
||||||
android:paddingStart="8dp" />
|
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
@@ -23,10 +23,8 @@
|
|||||||
android:layout="@layout/settings_entity_header"
|
android:layout="@layout/settings_entity_header"
|
||||||
android:selectable="false"/>
|
android:selectable="false"/>
|
||||||
|
|
||||||
<com.android.settings.applications.LayoutPreference
|
<com.android.settings.widget.ActionButtonPreference
|
||||||
android:key="action_buttons"
|
android:key="action_buttons" />
|
||||||
android:layout="@layout/app_action_buttons"
|
|
||||||
android:selectable="false"/>
|
|
||||||
|
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
android:key="bluetooth_profiles"/>
|
android:key="bluetooth_profiles"/>
|
||||||
|
@@ -31,11 +31,9 @@
|
|||||||
android:selectable="false"
|
android:selectable="false"
|
||||||
android:order="-9999"/>
|
android:order="-9999"/>
|
||||||
|
|
||||||
<com.android.settings.applications.LayoutPreference
|
<com.android.settings.widget.ActionButtonPreference
|
||||||
android:key="action_buttons"
|
android:key="action_buttons"
|
||||||
android:layout="@layout/app_action_buttons"
|
android:order="-9998" />
|
||||||
android:selectable="false"
|
|
||||||
android:order="-9998"/>
|
|
||||||
|
|
||||||
<Preference
|
<Preference
|
||||||
android:key="notification_settings"
|
android:key="notification_settings"
|
||||||
|
@@ -51,10 +51,8 @@
|
|||||||
android:defaultValue="100"
|
android:defaultValue="100"
|
||||||
android:max="400"/>
|
android:max="400"/>
|
||||||
|
|
||||||
<com.android.settings.applications.LayoutPreference
|
<com.android.settings.widget.ActionButtonPreference
|
||||||
android:key="action_buttons"
|
android:key="action_buttons" />
|
||||||
android:layout="@layout/tts_action_buttons"
|
|
||||||
android:selectable="false"/>
|
|
||||||
|
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
|
@@ -67,7 +67,6 @@ import android.view.MenuInflater;
|
|||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.webkit.IWebViewUpdateService;
|
import android.webkit.IWebViewUpdateService;
|
||||||
import android.widget.Button;
|
|
||||||
|
|
||||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||||
import com.android.internal.os.BatterySipper;
|
import com.android.internal.os.BatterySipper;
|
||||||
@@ -94,6 +93,7 @@ import com.android.settings.fuelgauge.BatteryUtils;
|
|||||||
import com.android.settings.notification.AppNotificationSettings;
|
import com.android.settings.notification.AppNotificationSettings;
|
||||||
import com.android.settings.notification.NotificationBackend;
|
import com.android.settings.notification.NotificationBackend;
|
||||||
import com.android.settings.notification.NotificationBackend.AppRow;
|
import com.android.settings.notification.NotificationBackend.AppRow;
|
||||||
|
import com.android.settings.widget.ActionButtonPreference;
|
||||||
import com.android.settings.widget.EntityHeaderController;
|
import com.android.settings.widget.EntityHeaderController;
|
||||||
import com.android.settingslib.AppItem;
|
import com.android.settingslib.AppItem;
|
||||||
import com.android.settingslib.RestrictedLockUtils;
|
import com.android.settingslib.RestrictedLockUtils;
|
||||||
@@ -123,8 +123,7 @@ import java.util.Set;
|
|||||||
* uninstall the application.
|
* uninstall the application.
|
||||||
*/
|
*/
|
||||||
public class InstalledAppDetails extends AppInfoBase
|
public class InstalledAppDetails extends AppInfoBase
|
||||||
implements View.OnClickListener, OnPreferenceClickListener,
|
implements OnPreferenceClickListener, LoaderManager.LoaderCallbacks<AppStorageStats> {
|
||||||
LoaderManager.LoaderCallbacks<AppStorageStats> {
|
|
||||||
|
|
||||||
private static final String LOG_TAG = "InstalledAppDetails";
|
private static final String LOG_TAG = "InstalledAppDetails";
|
||||||
|
|
||||||
@@ -166,10 +165,7 @@ public class InstalledAppDetails extends AppInfoBase
|
|||||||
private boolean mInitialized;
|
private boolean mInitialized;
|
||||||
private boolean mShowUninstalled;
|
private boolean mShowUninstalled;
|
||||||
private LayoutPreference mHeader;
|
private LayoutPreference mHeader;
|
||||||
private LayoutPreference mActionButtons;
|
|
||||||
private Button mUninstallButton;
|
|
||||||
private boolean mUpdatedSysApp = false;
|
private boolean mUpdatedSysApp = false;
|
||||||
private Button mForceStopButton;
|
|
||||||
private Preference mNotificationPreference;
|
private Preference mNotificationPreference;
|
||||||
private Preference mStoragePreference;
|
private Preference mStoragePreference;
|
||||||
private Preference mPermissionsPreference;
|
private Preference mPermissionsPreference;
|
||||||
@@ -187,6 +183,8 @@ public class InstalledAppDetails extends AppInfoBase
|
|||||||
private ChartData mChartData;
|
private ChartData mChartData;
|
||||||
private INetworkStatsSession mStatsSession;
|
private INetworkStatsSession mStatsSession;
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
ActionButtonPreference mActionButtons;
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
Preference mBatteryPreference;
|
Preference mBatteryPreference;
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
@@ -231,7 +229,7 @@ public class InstalledAppDetails extends AppInfoBase
|
|||||||
};
|
};
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
boolean handleDisableable(Button button) {
|
boolean handleDisableable() {
|
||||||
boolean disableable = false;
|
boolean disableable = false;
|
||||||
// Try to prevent the user from bricking their phone
|
// Try to prevent the user from bricking their phone
|
||||||
// by not allowing disabling of apps signed with the
|
// by not allowing disabling of apps signed with the
|
||||||
@@ -239,13 +237,19 @@ public class InstalledAppDetails extends AppInfoBase
|
|||||||
if (mHomePackages.contains(mAppEntry.info.packageName)
|
if (mHomePackages.contains(mAppEntry.info.packageName)
|
||||||
|| Utils.isSystemPackage(getContext().getResources(), mPm, mPackageInfo)) {
|
|| Utils.isSystemPackage(getContext().getResources(), mPm, mPackageInfo)) {
|
||||||
// Disable button for core system applications.
|
// Disable button for core system applications.
|
||||||
button.setText(R.string.disable_text);
|
mActionButtons
|
||||||
|
.setButton1Text(R.string.disable_text)
|
||||||
|
.setButton1Positive(false);
|
||||||
} else if (mAppEntry.info.enabled && !isDisabledUntilUsed()) {
|
} else if (mAppEntry.info.enabled && !isDisabledUntilUsed()) {
|
||||||
button.setText(R.string.disable_text);
|
mActionButtons
|
||||||
|
.setButton1Text(R.string.disable_text)
|
||||||
|
.setButton1Positive(false);
|
||||||
disableable = !mApplicationFeatureProvider.getKeepEnabledPackages()
|
disableable = !mApplicationFeatureProvider.getKeepEnabledPackages()
|
||||||
.contains(mAppEntry.info.packageName);
|
.contains(mAppEntry.info.packageName);
|
||||||
} else {
|
} else {
|
||||||
button.setText(R.string.enable_text);
|
mActionButtons
|
||||||
|
.setButton1Text(R.string.enable_text)
|
||||||
|
.setButton1Positive(true);
|
||||||
disableable = true;
|
disableable = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -259,11 +263,11 @@ public class InstalledAppDetails extends AppInfoBase
|
|||||||
|
|
||||||
private void initUninstallButtons() {
|
private void initUninstallButtons() {
|
||||||
final boolean isBundled = (mAppEntry.info.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
|
final boolean isBundled = (mAppEntry.info.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
|
||||||
boolean enabled = true;
|
boolean enabled;
|
||||||
if (isBundled) {
|
if (isBundled) {
|
||||||
enabled = handleDisableable(mUninstallButton);
|
enabled = handleDisableable();
|
||||||
} else {
|
} else {
|
||||||
enabled = initUnintsallButtonForUserApp();
|
enabled = initUninstallButtonForUserApp();
|
||||||
}
|
}
|
||||||
// If this is a device admin, it can't be uninstalled or disabled.
|
// If this is a device admin, it can't be uninstalled or disabled.
|
||||||
// We do this here so the text of the button is still set correctly.
|
// We do this here so the text of the button is still set correctly.
|
||||||
@@ -326,15 +330,15 @@ public class InstalledAppDetails extends AppInfoBase
|
|||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
mUninstallButton.setEnabled(enabled);
|
mActionButtons.setButton1Enabled(enabled);
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
// Register listener
|
// Register listener
|
||||||
mUninstallButton.setOnClickListener(this);
|
mActionButtons.setButton1OnClickListener(v -> handleUninstallButtonClick());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
boolean initUnintsallButtonForUserApp() {
|
boolean initUninstallButtonForUserApp() {
|
||||||
boolean enabled = true;
|
boolean enabled = true;
|
||||||
if ((mPackageInfo.applicationInfo.flags & ApplicationInfo.FLAG_INSTALLED) == 0
|
if ((mPackageInfo.applicationInfo.flags & ApplicationInfo.FLAG_INSTALLED) == 0
|
||||||
&& mUserManager.getUsers().size() >= 2) {
|
&& mUserManager.getUsers().size() >= 2) {
|
||||||
@@ -343,9 +347,9 @@ public class InstalledAppDetails extends AppInfoBase
|
|||||||
enabled = false;
|
enabled = false;
|
||||||
} else if (AppUtils.isInstant(mPackageInfo.applicationInfo)) {
|
} else if (AppUtils.isInstant(mPackageInfo.applicationInfo)) {
|
||||||
enabled = false;
|
enabled = false;
|
||||||
mUninstallButton.setVisibility(View.GONE);
|
mActionButtons.setButton1Visible(false);
|
||||||
}
|
}
|
||||||
mUninstallButton.setText(R.string.uninstall_text);
|
mActionButtons.setButton1Text(R.string.uninstall_text);
|
||||||
return enabled;
|
return enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -447,7 +451,10 @@ public class InstalledAppDetails extends AppInfoBase
|
|||||||
}
|
}
|
||||||
final Activity activity = getActivity();
|
final Activity activity = getActivity();
|
||||||
mHeader = (LayoutPreference) findPreference(KEY_HEADER);
|
mHeader = (LayoutPreference) findPreference(KEY_HEADER);
|
||||||
mActionButtons = (LayoutPreference) findPreference(KEY_ACTION_BUTTONS);
|
mActionButtons = ((ActionButtonPreference) findPreference(KEY_ACTION_BUTTONS))
|
||||||
|
.setButton2Text(R.string.force_stop)
|
||||||
|
.setButton2Positive(false)
|
||||||
|
.setButton2Enabled(false);
|
||||||
EntityHeaderController.newInstance(activity, this, mHeader.findViewById(R.id.entity_header))
|
EntityHeaderController.newInstance(activity, this, mHeader.findViewById(R.id.entity_header))
|
||||||
.setRecyclerView(getListView(), getLifecycle())
|
.setRecyclerView(getListView(), getLifecycle())
|
||||||
.setPackageName(mPackageName)
|
.setPackageName(mPackageName)
|
||||||
@@ -456,7 +463,6 @@ public class InstalledAppDetails extends AppInfoBase
|
|||||||
EntityHeaderController.ActionType.ACTION_NONE)
|
EntityHeaderController.ActionType.ACTION_NONE)
|
||||||
.styleActionBar(activity)
|
.styleActionBar(activity)
|
||||||
.bindHeaderButtons();
|
.bindHeaderButtons();
|
||||||
prepareUninstallAndStop();
|
|
||||||
|
|
||||||
mNotificationPreference = findPreference(KEY_NOTIFICATION);
|
mNotificationPreference = findPreference(KEY_NOTIFICATION);
|
||||||
mNotificationPreference.setOnPreferenceClickListener(this);
|
mNotificationPreference.setOnPreferenceClickListener(this);
|
||||||
@@ -516,13 +522,6 @@ public class InstalledAppDetails extends AppInfoBase
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void prepareUninstallAndStop() {
|
|
||||||
mForceStopButton = (Button) mActionButtons.findViewById(R.id.right_button);
|
|
||||||
mForceStopButton.setText(R.string.force_stop);
|
|
||||||
mUninstallButton = (Button) mActionButtons.findViewById(R.id.left_button);
|
|
||||||
mForceStopButton.setEnabled(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||||
menu.add(0, UNINSTALL_UPDATES, 0, R.string.app_factory_reset)
|
menu.add(0, UNINSTALL_UPDATES, 0, R.string.app_factory_reset)
|
||||||
@@ -905,12 +904,10 @@ public class InstalledAppDetails extends AppInfoBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updateForceStopButton(boolean enabled) {
|
private void updateForceStopButton(boolean enabled) {
|
||||||
if (mAppsControlDisallowedBySystem) {
|
mActionButtons
|
||||||
mForceStopButton.setEnabled(false);
|
.setButton2Enabled(mAppsControlDisallowedBySystem ? false : enabled)
|
||||||
} else {
|
.setButton2OnClickListener(mAppsControlDisallowedBySystem
|
||||||
mForceStopButton.setEnabled(enabled);
|
? null : v -> handleForceStopButtonClick());
|
||||||
mForceStopButton.setOnClickListener(this);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
@@ -921,7 +918,7 @@ public class InstalledAppDetails extends AppInfoBase
|
|||||||
updateForceStopButton(false);
|
updateForceStopButton(false);
|
||||||
} else if (AppUtils.isInstant(mPackageInfo.applicationInfo)) {
|
} else if (AppUtils.isInstant(mPackageInfo.applicationInfo)) {
|
||||||
updateForceStopButton(false);
|
updateForceStopButton(false);
|
||||||
mForceStopButton.setVisibility(View.GONE);
|
mActionButtons.setButton2Visible(false);
|
||||||
} else if ((mAppEntry.info.flags & ApplicationInfo.FLAG_STOPPED) == 0) {
|
} else if ((mAppEntry.info.flags & ApplicationInfo.FLAG_STOPPED) == 0) {
|
||||||
// If the app isn't explicitly stopped, then always show the
|
// If the app isn't explicitly stopped, then always show the
|
||||||
// force stop button.
|
// force stop button.
|
||||||
@@ -968,67 +965,67 @@ public class InstalledAppDetails extends AppInfoBase
|
|||||||
SUB_INFO_FRAGMENT);
|
SUB_INFO_FRAGMENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
private void handleUninstallButtonClick() {
|
||||||
* Method implementing functionality of buttons clicked
|
|
||||||
* @see android.view.View.OnClickListener#onClick(android.view.View)
|
|
||||||
*/
|
|
||||||
public void onClick(View v) {
|
|
||||||
if (mAppEntry == null) {
|
if (mAppEntry == null) {
|
||||||
setIntentAndFinish(true, true);
|
setIntentAndFinish(true, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String packageName = mAppEntry.info.packageName;
|
final String packageName = mAppEntry.info.packageName;
|
||||||
if (v == mUninstallButton) {
|
if (mDpm.packageHasActiveAdmins(mPackageInfo.packageName)) {
|
||||||
if (mDpm.packageHasActiveAdmins(mPackageInfo.packageName)) {
|
stopListeningToPackageRemove();
|
||||||
stopListeningToPackageRemove();
|
Activity activity = getActivity();
|
||||||
Activity activity = getActivity();
|
Intent uninstallDAIntent = new Intent(activity, DeviceAdminAdd.class);
|
||||||
Intent uninstallDAIntent = new Intent(activity, DeviceAdminAdd.class);
|
uninstallDAIntent.putExtra(DeviceAdminAdd.EXTRA_DEVICE_ADMIN_PACKAGE_NAME,
|
||||||
uninstallDAIntent.putExtra(DeviceAdminAdd.EXTRA_DEVICE_ADMIN_PACKAGE_NAME,
|
mPackageName);
|
||||||
mPackageName);
|
mMetricsFeatureProvider.action(
|
||||||
mMetricsFeatureProvider.action(
|
activity, MetricsEvent.ACTION_SETTINGS_UNINSTALL_DEVICE_ADMIN);
|
||||||
activity, MetricsEvent.ACTION_SETTINGS_UNINSTALL_DEVICE_ADMIN);
|
activity.startActivityForResult(uninstallDAIntent, REQUEST_REMOVE_DEVICE_ADMIN);
|
||||||
activity.startActivityForResult(uninstallDAIntent, REQUEST_REMOVE_DEVICE_ADMIN);
|
return;
|
||||||
return;
|
}
|
||||||
}
|
EnforcedAdmin admin = RestrictedLockUtils.checkIfUninstallBlocked(getActivity(),
|
||||||
EnforcedAdmin admin = RestrictedLockUtils.checkIfUninstallBlocked(getActivity(),
|
packageName, mUserId);
|
||||||
packageName, mUserId);
|
boolean uninstallBlockedBySystem = mAppsControlDisallowedBySystem ||
|
||||||
boolean uninstallBlockedBySystem = mAppsControlDisallowedBySystem ||
|
RestrictedLockUtils.hasBaseUserRestriction(getActivity(), packageName, mUserId);
|
||||||
RestrictedLockUtils.hasBaseUserRestriction(getActivity(), packageName, mUserId);
|
if (admin != null && !uninstallBlockedBySystem) {
|
||||||
if (admin != null && !uninstallBlockedBySystem) {
|
RestrictedLockUtils.sendShowAdminSupportDetailsIntent(getActivity(), admin);
|
||||||
RestrictedLockUtils.sendShowAdminSupportDetailsIntent(getActivity(), admin);
|
} else if ((mAppEntry.info.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
|
||||||
} else if ((mAppEntry.info.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
|
if (mAppEntry.info.enabled && !isDisabledUntilUsed()) {
|
||||||
if (mAppEntry.info.enabled && !isDisabledUntilUsed()) {
|
// If the system app has an update and this is the only user on the device,
|
||||||
// If the system app has an update and this is the only user on the device,
|
// then offer to downgrade the app, otherwise only offer to disable the
|
||||||
// then offer to downgrade the app, otherwise only offer to disable the
|
// app for this user.
|
||||||
// app for this user.
|
if (mUpdatedSysApp && isSingleUser()) {
|
||||||
if (mUpdatedSysApp && isSingleUser()) {
|
showDialogInner(DLG_SPECIAL_DISABLE, 0);
|
||||||
showDialogInner(DLG_SPECIAL_DISABLE, 0);
|
|
||||||
} else {
|
|
||||||
showDialogInner(DLG_DISABLE, 0);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
mMetricsFeatureProvider.action(
|
showDialogInner(DLG_DISABLE, 0);
|
||||||
getActivity(),
|
|
||||||
mAppEntry.info.enabled
|
|
||||||
? MetricsEvent.ACTION_SETTINGS_DISABLE_APP
|
|
||||||
: MetricsEvent.ACTION_SETTINGS_ENABLE_APP);
|
|
||||||
new DisableChanger(this, mAppEntry.info,
|
|
||||||
PackageManager.COMPONENT_ENABLED_STATE_DEFAULT)
|
|
||||||
.execute((Object) null);
|
|
||||||
}
|
}
|
||||||
} else if ((mAppEntry.info.flags & ApplicationInfo.FLAG_INSTALLED) == 0) {
|
|
||||||
uninstallPkg(packageName, true, false);
|
|
||||||
} else {
|
} else {
|
||||||
uninstallPkg(packageName, false, false);
|
mMetricsFeatureProvider.action(
|
||||||
}
|
getActivity(),
|
||||||
} else if (v == mForceStopButton) {
|
mAppEntry.info.enabled
|
||||||
if (mAppsControlDisallowedAdmin != null && !mAppsControlDisallowedBySystem) {
|
? MetricsEvent.ACTION_SETTINGS_DISABLE_APP
|
||||||
RestrictedLockUtils.sendShowAdminSupportDetailsIntent(
|
: MetricsEvent.ACTION_SETTINGS_ENABLE_APP);
|
||||||
getActivity(), mAppsControlDisallowedAdmin);
|
new DisableChanger(this, mAppEntry.info,
|
||||||
} else {
|
PackageManager.COMPONENT_ENABLED_STATE_DEFAULT)
|
||||||
showDialogInner(DLG_FORCE_STOP, 0);
|
.execute((Object) null);
|
||||||
//forceStopPackage(mAppInfo.packageName);
|
|
||||||
}
|
}
|
||||||
|
} else if ((mAppEntry.info.flags & ApplicationInfo.FLAG_INSTALLED) == 0) {
|
||||||
|
uninstallPkg(packageName, true, false);
|
||||||
|
} else {
|
||||||
|
uninstallPkg(packageName, false, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleForceStopButtonClick() {
|
||||||
|
if (mAppEntry == null) {
|
||||||
|
setIntentAndFinish(true, true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (mAppsControlDisallowedAdmin != null && !mAppsControlDisallowedBySystem) {
|
||||||
|
RestrictedLockUtils.sendShowAdminSupportDetailsIntent(
|
||||||
|
getActivity(), mAppsControlDisallowedAdmin);
|
||||||
|
} else {
|
||||||
|
showDialogInner(DLG_FORCE_STOP, 0);
|
||||||
|
//forceStopPackage(mAppInfo.packageName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -19,11 +19,9 @@ package com.android.settings.bluetooth;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.support.v14.preference.PreferenceFragment;
|
import android.support.v14.preference.PreferenceFragment;
|
||||||
import android.support.v7.preference.PreferenceScreen;
|
import android.support.v7.preference.PreferenceScreen;
|
||||||
import android.text.TextUtils;
|
|
||||||
import android.widget.Button;
|
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.applications.LayoutPreference;
|
import com.android.settings.widget.ActionButtonPreference;
|
||||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||||
|
|
||||||
@@ -35,7 +33,8 @@ public class BluetoothDetailsButtonsController extends BluetoothDetailsControlle
|
|||||||
private static final String KEY_ACTION_BUTTONS = "action_buttons";
|
private static final String KEY_ACTION_BUTTONS = "action_buttons";
|
||||||
private boolean mIsConnected;
|
private boolean mIsConnected;
|
||||||
|
|
||||||
private LayoutPreference mActionButtons;
|
private boolean mButton1Initialized;
|
||||||
|
private ActionButtonPreference mActionButtons;
|
||||||
|
|
||||||
public BluetoothDetailsButtonsController(Context context, PreferenceFragment fragment,
|
public BluetoothDetailsButtonsController(Context context, PreferenceFragment fragment,
|
||||||
CachedBluetoothDevice device, Lifecycle lifecycle) {
|
CachedBluetoothDevice device, Lifecycle lifecycle) {
|
||||||
@@ -51,35 +50,35 @@ public class BluetoothDetailsButtonsController extends BluetoothDetailsControlle
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void init(PreferenceScreen screen) {
|
protected void init(PreferenceScreen screen) {
|
||||||
mActionButtons = (LayoutPreference) screen.findPreference(getPreferenceKey());
|
mActionButtons = ((ActionButtonPreference) screen.findPreference(getPreferenceKey()))
|
||||||
Button rightButton = (Button) mActionButtons.findViewById(R.id.right_button);
|
.setButton2Text(R.string.forget)
|
||||||
rightButton.setText(R.string.forget);
|
.setButton2OnClickListener((view) -> onForgetButtonPressed())
|
||||||
rightButton.setOnClickListener((view) -> {
|
.setButton2Positive(false)
|
||||||
onForgetButtonPressed();
|
.setButton2Enabled(true);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void refresh() {
|
protected void refresh() {
|
||||||
Button leftButton = (Button) mActionButtons.findViewById(R.id.left_button);
|
mActionButtons.setButton1Enabled(!mCachedDevice.isBusy());
|
||||||
leftButton.setEnabled(!mCachedDevice.isBusy());
|
|
||||||
boolean notInitialized = TextUtils.isEmpty(leftButton.getText());
|
|
||||||
|
|
||||||
boolean previouslyConnected = mIsConnected;
|
boolean previouslyConnected = mIsConnected;
|
||||||
mIsConnected = mCachedDevice.isConnected();
|
mIsConnected = mCachedDevice.isConnected();
|
||||||
if (mIsConnected) {
|
if (mIsConnected) {
|
||||||
if (notInitialized || !previouslyConnected) {
|
if (!mButton1Initialized || !previouslyConnected) {
|
||||||
leftButton.setText(R.string.bluetooth_device_context_disconnect);
|
mActionButtons
|
||||||
leftButton.setOnClickListener((view) -> {
|
.setButton1Text(R.string.bluetooth_device_context_disconnect)
|
||||||
mCachedDevice.disconnect();
|
.setButton1OnClickListener(view -> mCachedDevice.disconnect())
|
||||||
});
|
.setButton1Positive(false);
|
||||||
|
mButton1Initialized = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (notInitialized || previouslyConnected) {
|
if (!mButton1Initialized || previouslyConnected) {
|
||||||
leftButton.setText(R.string.bluetooth_device_context_connect);
|
mActionButtons
|
||||||
leftButton.setOnClickListener((view) -> {
|
.setButton1Text(R.string.bluetooth_device_context_connect)
|
||||||
mCachedDevice.connect(true);
|
.setButton1OnClickListener(
|
||||||
});
|
view -> mCachedDevice.connect(true /* connectAllProfiles */))
|
||||||
|
.setButton1Positive(true);
|
||||||
|
mButton1Initialized = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -88,4 +87,5 @@ public class BluetoothDetailsButtonsController extends BluetoothDetailsControlle
|
|||||||
public String getPreferenceKey() {
|
public String getPreferenceKey() {
|
||||||
return KEY_ACTION_BUTTONS;
|
return KEY_ACTION_BUTTONS;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -16,7 +16,10 @@
|
|||||||
|
|
||||||
package com.android.settings.tts;
|
package com.android.settings.tts;
|
||||||
|
|
||||||
import android.support.v7.preference.ListPreference;
|
import static android.provider.Settings.Secure.TTS_DEFAULT_PITCH;
|
||||||
|
import static android.provider.Settings.Secure.TTS_DEFAULT_RATE;
|
||||||
|
import static android.provider.Settings.Secure.TTS_DEFAULT_SYNTH;
|
||||||
|
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.content.ActivityNotFoundException;
|
import android.content.ActivityNotFoundException;
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
@@ -26,24 +29,23 @@ import android.speech.tts.TextToSpeech;
|
|||||||
import android.speech.tts.TextToSpeech.EngineInfo;
|
import android.speech.tts.TextToSpeech.EngineInfo;
|
||||||
import android.speech.tts.TtsEngines;
|
import android.speech.tts.TtsEngines;
|
||||||
import android.speech.tts.UtteranceProgressListener;
|
import android.speech.tts.UtteranceProgressListener;
|
||||||
|
import android.support.v7.preference.ListPreference;
|
||||||
import android.support.v7.preference.Preference;
|
import android.support.v7.preference.Preference;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.Pair;
|
import android.util.Pair;
|
||||||
import android.view.View;
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.Collections;
|
|
||||||
import com.android.settings.applications.LayoutPreference;
|
|
||||||
|
|
||||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||||
import com.android.settings.widget.SeekBarPreference;
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.SettingsActivity;
|
import com.android.settings.SettingsActivity;
|
||||||
import com.android.settings.SettingsPreferenceFragment;
|
import com.android.settings.SettingsPreferenceFragment;
|
||||||
|
import com.android.settings.widget.ActionButtonPreference;
|
||||||
import com.android.settings.widget.GearPreference;
|
import com.android.settings.widget.GearPreference;
|
||||||
import android.widget.Button;
|
import com.android.settings.widget.SeekBarPreference;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
@@ -51,13 +53,8 @@ import java.util.MissingResourceException;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import static android.provider.Settings.Secure.TTS_DEFAULT_PITCH;
|
|
||||||
import static android.provider.Settings.Secure.TTS_DEFAULT_RATE;
|
|
||||||
import static android.provider.Settings.Secure.TTS_DEFAULT_SYNTH;
|
|
||||||
|
|
||||||
public class TextToSpeechSettings extends SettingsPreferenceFragment
|
public class TextToSpeechSettings extends SettingsPreferenceFragment
|
||||||
implements Preference.OnPreferenceChangeListener,
|
implements Preference.OnPreferenceChangeListener,
|
||||||
View.OnClickListener,
|
|
||||||
GearPreference.OnGearClickListener {
|
GearPreference.OnGearClickListener {
|
||||||
|
|
||||||
private static final String STATE_KEY_LOCALE_ENTRIES = "locale_entries";
|
private static final String STATE_KEY_LOCALE_ENTRIES = "locale_entries";
|
||||||
@@ -108,9 +105,7 @@ public class TextToSpeechSettings extends SettingsPreferenceFragment
|
|||||||
|
|
||||||
private SeekBarPreference mDefaultPitchPref;
|
private SeekBarPreference mDefaultPitchPref;
|
||||||
private SeekBarPreference mDefaultRatePref;
|
private SeekBarPreference mDefaultRatePref;
|
||||||
private Button mResetButton;
|
private ActionButtonPreference mActionButtons;
|
||||||
private Button mPlayButton;
|
|
||||||
private LayoutPreference mActionButtons;
|
|
||||||
|
|
||||||
private int mDefaultPitch = TextToSpeech.Engine.DEFAULT_PITCH;
|
private int mDefaultPitch = TextToSpeech.Engine.DEFAULT_PITCH;
|
||||||
private int mDefaultRate = TextToSpeech.Engine.DEFAULT_RATE;
|
private int mDefaultRate = TextToSpeech.Engine.DEFAULT_RATE;
|
||||||
@@ -126,7 +121,6 @@ public class TextToSpeechSettings extends SettingsPreferenceFragment
|
|||||||
private String mSampleText = null;
|
private String mSampleText = null;
|
||||||
|
|
||||||
private ListPreference mLocalePreference;
|
private ListPreference mLocalePreference;
|
||||||
private Preference mInstallVoicesPreference;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default locale used by selected TTS engine, null if not connected to any engine.
|
* Default locale used by selected TTS engine, null if not connected to any engine.
|
||||||
@@ -172,12 +166,15 @@ public class TextToSpeechSettings extends SettingsPreferenceFragment
|
|||||||
mDefaultPitchPref = (SeekBarPreference) findPreference(KEY_DEFAULT_PITCH);
|
mDefaultPitchPref = (SeekBarPreference) findPreference(KEY_DEFAULT_PITCH);
|
||||||
mDefaultRatePref = (SeekBarPreference) findPreference(KEY_DEFAULT_RATE);
|
mDefaultRatePref = (SeekBarPreference) findPreference(KEY_DEFAULT_RATE);
|
||||||
|
|
||||||
mActionButtons = (LayoutPreference) findPreference(KEY_ACTION_BUTTONS);
|
mActionButtons = ((ActionButtonPreference) findPreference(KEY_ACTION_BUTTONS))
|
||||||
mPlayButton = (Button) mActionButtons.findViewById(R.id.tts_play_button);
|
.setButton1Text(R.string.tts_play)
|
||||||
mPlayButton.setOnClickListener(this);
|
.setButton1Positive(true)
|
||||||
mPlayButton.setEnabled(false);
|
.setButton1OnClickListener(v -> speakSampleText())
|
||||||
mResetButton = (Button) mActionButtons.findViewById(R.id.tts_reset_button);
|
.setButton1Enabled(false)
|
||||||
mResetButton.setOnClickListener(this);
|
.setButton2Text(R.string.tts_reset)
|
||||||
|
.setButton2Positive(false)
|
||||||
|
.setButton2OnClickListener(v -> resetTts())
|
||||||
|
.setButton1Enabled(true);
|
||||||
|
|
||||||
if (savedInstanceState == null) {
|
if (savedInstanceState == null) {
|
||||||
mLocalePreference.setEnabled(false);
|
mLocalePreference.setEnabled(false);
|
||||||
@@ -656,32 +653,18 @@ public class TextToSpeechSettings extends SettingsPreferenceFragment
|
|||||||
mTts.setLanguage((locale != null) ? locale : Locale.getDefault());
|
mTts.setLanguage((locale != null) ? locale : Locale.getDefault());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Called when mPlayButton, mResetButton is clicked. */
|
private void resetTts() {
|
||||||
@Override
|
// Reset button.
|
||||||
public void onClick(View v) {
|
int speechRateSeekbarProgress =
|
||||||
switch (v.getId()) {
|
getSeekBarProgressFromValue(
|
||||||
case R.id.tts_play_button:
|
KEY_DEFAULT_RATE, TextToSpeech.Engine.DEFAULT_RATE);
|
||||||
// Play button.
|
mDefaultRatePref.setProgress(speechRateSeekbarProgress);
|
||||||
// Get the sample text from the TTS engine; onActivityResult will do
|
updateSpeechRate(speechRateSeekbarProgress);
|
||||||
// the actual speaking
|
int pitchSeekbarProgress =
|
||||||
speakSampleText();
|
getSeekBarProgressFromValue(
|
||||||
break;
|
KEY_DEFAULT_PITCH, TextToSpeech.Engine.DEFAULT_PITCH);
|
||||||
case R.id.tts_reset_button:
|
mDefaultPitchPref.setProgress(pitchSeekbarProgress);
|
||||||
// Reset button.
|
updateSpeechPitchValue(pitchSeekbarProgress);
|
||||||
int speechRateSeekbarProgress =
|
|
||||||
getSeekBarProgressFromValue(
|
|
||||||
KEY_DEFAULT_RATE, TextToSpeech.Engine.DEFAULT_RATE);
|
|
||||||
mDefaultRatePref.setProgress(speechRateSeekbarProgress);
|
|
||||||
updateSpeechRate(speechRateSeekbarProgress);
|
|
||||||
int pitchSeekbarProgress =
|
|
||||||
getSeekBarProgressFromValue(
|
|
||||||
KEY_DEFAULT_PITCH, TextToSpeech.Engine.DEFAULT_PITCH);
|
|
||||||
mDefaultPitchPref.setProgress(pitchSeekbarProgress);
|
|
||||||
updateSpeechPitchValue(pitchSeekbarProgress);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateSpeechRate(int speechRateSeekBarProgress) {
|
private void updateSpeechRate(int speechRateSeekBarProgress) {
|
||||||
@@ -715,7 +698,7 @@ public class TextToSpeechSettings extends SettingsPreferenceFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updateWidgetState(boolean enable) {
|
private void updateWidgetState(boolean enable) {
|
||||||
mPlayButton.setEnabled(enable);
|
mActionButtons.setButton1Enabled(enable);
|
||||||
mDefaultRatePref.setEnabled(enable);
|
mDefaultRatePref.setEnabled(enable);
|
||||||
mDefaultPitchPref.setEnabled(enable);
|
mDefaultPitchPref.setEnabled(enable);
|
||||||
}
|
}
|
||||||
|
@@ -17,6 +17,18 @@
|
|||||||
package com.android.settings.applications;
|
package com.android.settings.applications;
|
||||||
|
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
import static org.mockito.ArgumentMatchers.nullable;
|
||||||
|
import static org.mockito.Matchers.anyDouble;
|
||||||
|
import static org.mockito.Matchers.anyInt;
|
||||||
|
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.times;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.AppOpsManager;
|
import android.app.AppOpsManager;
|
||||||
import android.app.Fragment;
|
import android.app.Fragment;
|
||||||
@@ -35,18 +47,18 @@ import android.support.v7.preference.Preference;
|
|||||||
import android.support.v7.preference.PreferenceManager;
|
import android.support.v7.preference.PreferenceManager;
|
||||||
import android.support.v7.preference.PreferenceScreen;
|
import android.support.v7.preference.PreferenceScreen;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Button;
|
|
||||||
|
|
||||||
import com.android.internal.os.BatterySipper;
|
import com.android.internal.os.BatterySipper;
|
||||||
import com.android.internal.os.BatteryStatsHelper;
|
import com.android.internal.os.BatteryStatsHelper;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.SettingsActivity;
|
import com.android.settings.SettingsActivity;
|
||||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
|
||||||
import com.android.settings.TestConfig;
|
import com.android.settings.TestConfig;
|
||||||
import com.android.settings.applications.instantapps.InstantAppButtonsController;
|
import com.android.settings.applications.instantapps.InstantAppButtonsController;
|
||||||
import com.android.settings.applications.instantapps.InstantAppButtonsController.ShowDialogDelegate;
|
import com.android.settings.applications.instantapps.InstantAppButtonsController.ShowDialogDelegate;
|
||||||
import com.android.settings.fuelgauge.BatteryUtils;
|
import com.android.settings.fuelgauge.BatteryUtils;
|
||||||
import com.android.settings.testutils.FakeFeatureFactory;
|
import com.android.settings.testutils.FakeFeatureFactory;
|
||||||
|
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||||
|
import com.android.settings.widget.ActionButtonPreferenceTest;
|
||||||
import com.android.settingslib.Utils;
|
import com.android.settingslib.Utils;
|
||||||
import com.android.settingslib.applications.AppUtils;
|
import com.android.settingslib.applications.AppUtils;
|
||||||
import com.android.settingslib.applications.ApplicationsState.AppEntry;
|
import com.android.settingslib.applications.ApplicationsState.AppEntry;
|
||||||
@@ -69,18 +81,6 @@ import java.util.ArrayList;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
|
||||||
import static org.mockito.ArgumentMatchers.nullable;
|
|
||||||
import static org.mockito.Matchers.anyDouble;
|
|
||||||
import static org.mockito.Matchers.anyInt;
|
|
||||||
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.times;
|
|
||||||
import static org.mockito.Mockito.verify;
|
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
|
|
||||||
@RunWith(SettingsRobolectricTestRunner.class)
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||||
@@ -133,6 +133,7 @@ public final class InstalledAppDetailsTest {
|
|||||||
|
|
||||||
mBatteryPreference = new Preference(mShadowContext);
|
mBatteryPreference = new Preference(mShadowContext);
|
||||||
mAppDetail.mBatteryPreference = mBatteryPreference;
|
mAppDetail.mBatteryPreference = mBatteryPreference;
|
||||||
|
mAppDetail.mActionButtons = ActionButtonPreferenceTest.createMock();
|
||||||
|
|
||||||
mBatterySipper.drainType = BatterySipper.DrainType.IDLE;
|
mBatterySipper.drainType = BatterySipper.DrainType.IDLE;
|
||||||
mBatterySipper.uidObj = mUid;
|
mBatterySipper.uidObj = mUid;
|
||||||
@@ -281,15 +282,13 @@ public final class InstalledAppDetailsTest {
|
|||||||
appEntry.info = info;
|
appEntry.info = info;
|
||||||
final PackageInfo packageInfo = mock(PackageInfo.class);
|
final PackageInfo packageInfo = mock(PackageInfo.class);
|
||||||
packageInfo.applicationInfo = info;
|
packageInfo.applicationInfo = info;
|
||||||
final Button uninstallButton = mock(Button.class);
|
|
||||||
|
|
||||||
ReflectionHelpers.setField(mAppDetail, "mUserManager", mUserManager);
|
ReflectionHelpers.setField(mAppDetail, "mUserManager", mUserManager);
|
||||||
ReflectionHelpers.setField(mAppDetail, "mAppEntry", appEntry);
|
ReflectionHelpers.setField(mAppDetail, "mAppEntry", appEntry);
|
||||||
ReflectionHelpers.setField(mAppDetail, "mPackageInfo", packageInfo);
|
ReflectionHelpers.setField(mAppDetail, "mPackageInfo", packageInfo);
|
||||||
ReflectionHelpers.setField(mAppDetail, "mUninstallButton", uninstallButton);
|
|
||||||
|
|
||||||
mAppDetail.initUnintsallButtonForUserApp();
|
mAppDetail.initUninstallButtonForUserApp();
|
||||||
verify(uninstallButton).setVisibility(View.GONE);
|
verify(mAppDetail.mActionButtons).setButton1Visible(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tests that we don't show the force stop button for instant apps (they aren't allowed to run
|
// Tests that we don't show the force stop button for instant apps (they aren't allowed to run
|
||||||
@@ -303,15 +302,13 @@ public final class InstalledAppDetailsTest {
|
|||||||
final AppEntry appEntry = mock(AppEntry.class);
|
final AppEntry appEntry = mock(AppEntry.class);
|
||||||
final ApplicationInfo info = new ApplicationInfo();
|
final ApplicationInfo info = new ApplicationInfo();
|
||||||
appEntry.info = info;
|
appEntry.info = info;
|
||||||
final Button forceStopButton = mock(Button.class);
|
|
||||||
|
|
||||||
ReflectionHelpers.setField(mAppDetail, "mDpm", mDevicePolicyManager);
|
ReflectionHelpers.setField(mAppDetail, "mDpm", mDevicePolicyManager);
|
||||||
ReflectionHelpers.setField(mAppDetail, "mPackageInfo", packageInfo);
|
ReflectionHelpers.setField(mAppDetail, "mPackageInfo", packageInfo);
|
||||||
ReflectionHelpers.setField(mAppDetail, "mAppEntry", appEntry);
|
ReflectionHelpers.setField(mAppDetail, "mAppEntry", appEntry);
|
||||||
ReflectionHelpers.setField(mAppDetail, "mForceStopButton", forceStopButton);
|
|
||||||
|
|
||||||
mAppDetail.checkForceStop();
|
mAppDetail.checkForceStop();
|
||||||
verify(forceStopButton).setVisibility(View.GONE);
|
verify(mAppDetail.mActionButtons).setButton2Visible(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -484,10 +481,9 @@ public final class InstalledAppDetailsTest {
|
|||||||
|
|
||||||
ReflectionHelpers.setField(mAppDetail, "mHomePackages", homePackages);
|
ReflectionHelpers.setField(mAppDetail, "mHomePackages", homePackages);
|
||||||
ReflectionHelpers.setField(mAppDetail, "mAppEntry", appEntry);
|
ReflectionHelpers.setField(mAppDetail, "mAppEntry", appEntry);
|
||||||
final Button button = mock(Button.class);
|
|
||||||
|
|
||||||
assertThat(mAppDetail.handleDisableable(button)).isFalse();
|
assertThat(mAppDetail.handleDisableable()).isFalse();
|
||||||
verify(button).setText(R.string.disable_text);
|
verify(mAppDetail.mActionButtons).setButton1Text(R.string.disable_text);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -506,10 +502,31 @@ public final class InstalledAppDetailsTest {
|
|||||||
ReflectionHelpers.setField(mAppDetail, "mApplicationFeatureProvider",
|
ReflectionHelpers.setField(mAppDetail, "mApplicationFeatureProvider",
|
||||||
mFeatureFactory.applicationFeatureProvider);
|
mFeatureFactory.applicationFeatureProvider);
|
||||||
ReflectionHelpers.setField(mAppDetail, "mAppEntry", appEntry);
|
ReflectionHelpers.setField(mAppDetail, "mAppEntry", appEntry);
|
||||||
final Button button = mock(Button.class);
|
|
||||||
|
|
||||||
assertThat(mAppDetail.handleDisableable(button)).isTrue();
|
assertThat(mAppDetail.handleDisableable()).isTrue();
|
||||||
verify(button).setText(R.string.disable_text);
|
verify(mAppDetail.mActionButtons).setButton1Text(R.string.disable_text);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Config(shadows = ShadowUtils.class)
|
||||||
|
public void handleDisableable_appIsDisabled_buttonShouldShowEnable() {
|
||||||
|
final ApplicationInfo info = new ApplicationInfo();
|
||||||
|
info.packageName = "pkg";
|
||||||
|
info.enabled = false;
|
||||||
|
info.enabledSetting = PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
|
||||||
|
|
||||||
|
final AppEntry appEntry = mock(AppEntry.class);
|
||||||
|
appEntry.info = info;
|
||||||
|
when(mFeatureFactory.applicationFeatureProvider.getKeepEnabledPackages()).thenReturn(
|
||||||
|
new HashSet<>());
|
||||||
|
|
||||||
|
ReflectionHelpers.setField(mAppDetail, "mApplicationFeatureProvider",
|
||||||
|
mFeatureFactory.applicationFeatureProvider);
|
||||||
|
ReflectionHelpers.setField(mAppDetail, "mAppEntry", appEntry);
|
||||||
|
|
||||||
|
assertThat(mAppDetail.handleDisableable()).isTrue();
|
||||||
|
verify(mAppDetail.mActionButtons).setButton1Text(R.string.enable_text);
|
||||||
|
verify(mAppDetail.mActionButtons).setButton1Positive(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -532,10 +549,8 @@ public final class InstalledAppDetailsTest {
|
|||||||
mFeatureFactory.applicationFeatureProvider);
|
mFeatureFactory.applicationFeatureProvider);
|
||||||
ReflectionHelpers.setField(mAppDetail, "mAppEntry", appEntry);
|
ReflectionHelpers.setField(mAppDetail, "mAppEntry", appEntry);
|
||||||
|
|
||||||
final Button button = mock(Button.class);
|
assertThat(mAppDetail.handleDisableable()).isFalse();
|
||||||
|
verify(mAppDetail.mActionButtons).setButton1Text(R.string.disable_text);
|
||||||
assertThat(mAppDetail.handleDisableable(button)).isFalse();
|
|
||||||
verify(button).setText(R.string.disable_text);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@@ -48,7 +48,7 @@ public class LayoutPreferenceTest {
|
|||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
mContext = RuntimeEnvironment.application;
|
mContext = RuntimeEnvironment.application;
|
||||||
mPreference = new LayoutPreference(mContext, R.layout.app_action_buttons);
|
mPreference = new LayoutPreference(mContext, R.layout.two_action_buttons);
|
||||||
mRootView = mPreference.mRootView;
|
mRootView = mPreference.mRootView;
|
||||||
mHolder = PreferenceViewHolder.createInstanceForTests(LayoutInflater.from(mContext)
|
mHolder = PreferenceViewHolder.createInstanceForTests(LayoutInflater.from(mContext)
|
||||||
.inflate(R.layout.layout_preference_frame, null, false));
|
.inflate(R.layout.layout_preference_frame, null, false));
|
||||||
@@ -79,12 +79,12 @@ public class LayoutPreferenceTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void disableSomeView_shouldMaintainStateAfterBind() {
|
public void disableSomeView_shouldMaintainStateAfterBind() {
|
||||||
mPreference.findViewById(R.id.left_button).setEnabled(false);
|
mPreference.findViewById(R.id.button1_positive).setEnabled(false);
|
||||||
mPreference.findViewById(R.id.right_button).setEnabled(true);
|
mPreference.findViewById(R.id.button2_positive).setEnabled(true);
|
||||||
|
|
||||||
mPreference.onBindViewHolder(mHolder);
|
mPreference.onBindViewHolder(mHolder);
|
||||||
|
|
||||||
assertThat(mPreference.findViewById(R.id.left_button).isEnabled()).isFalse();
|
assertThat(mPreference.findViewById(R.id.button1_positive).isEnabled()).isFalse();
|
||||||
assertThat(mPreference.findViewById(R.id.right_button).isEnabled()).isTrue();
|
assertThat(mPreference.findViewById(R.id.button2_positive).isEnabled()).isTrue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -17,7 +17,7 @@
|
|||||||
package com.android.settings.bluetooth;
|
package com.android.settings.bluetooth;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
import static org.mockito.Matchers.any;
|
||||||
import static org.mockito.Matchers.anyString;
|
import static org.mockito.Matchers.anyString;
|
||||||
import static org.mockito.Matchers.eq;
|
import static org.mockito.Matchers.eq;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
@@ -26,17 +26,20 @@ import static org.mockito.Mockito.when;
|
|||||||
|
|
||||||
import android.app.FragmentManager;
|
import android.app.FragmentManager;
|
||||||
import android.app.FragmentTransaction;
|
import android.app.FragmentTransaction;
|
||||||
|
import android.view.View;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.TestConfig;
|
import com.android.settings.TestConfig;
|
||||||
import com.android.settings.applications.LayoutPreference;
|
|
||||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||||
import com.android.settings.testutils.shadow.SettingsShadowBluetoothDevice;
|
import com.android.settings.testutils.shadow.SettingsShadowBluetoothDevice;
|
||||||
|
import com.android.settings.widget.ActionButtonPreference;
|
||||||
|
import com.android.settings.widget.ActionButtonPreferenceTest;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
|
import org.robolectric.RuntimeEnvironment;
|
||||||
import org.robolectric.annotation.Config;
|
import org.robolectric.annotation.Config;
|
||||||
|
|
||||||
@RunWith(SettingsRobolectricTestRunner.class)
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
@@ -44,22 +47,34 @@ import org.robolectric.annotation.Config;
|
|||||||
shadows = SettingsShadowBluetoothDevice.class)
|
shadows = SettingsShadowBluetoothDevice.class)
|
||||||
public class BluetoothDetailsButtonsControllerTest extends BluetoothDetailsControllerTestBase {
|
public class BluetoothDetailsButtonsControllerTest extends BluetoothDetailsControllerTestBase {
|
||||||
private BluetoothDetailsButtonsController mController;
|
private BluetoothDetailsButtonsController mController;
|
||||||
private LayoutPreference mLayoutPreference;
|
private ActionButtonPreference mButtonsPref;
|
||||||
private Button mLeftButton;
|
private Button mLeftButton;
|
||||||
private Button mRightButton;
|
private Button mRightButton;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
|
final View buttons = View.inflate(
|
||||||
|
RuntimeEnvironment.application, R.layout.two_action_buttons, null /* parent */);
|
||||||
|
mLeftButton = buttons.findViewById(R.id.button1_positive);
|
||||||
|
mRightButton = buttons.findViewById(R.id.button2_positive);
|
||||||
mController = new BluetoothDetailsButtonsController(mContext, mFragment, mCachedDevice,
|
mController = new BluetoothDetailsButtonsController(mContext, mFragment, mCachedDevice,
|
||||||
mLifecycle);
|
mLifecycle);
|
||||||
mLeftButton = new Button(mContext);
|
mButtonsPref = ActionButtonPreferenceTest.createMock();
|
||||||
mRightButton = new Button(mContext);
|
when(mButtonsPref.getKey()).thenReturn(mController.getPreferenceKey());
|
||||||
mLayoutPreference = new LayoutPreference(mContext, R.layout.app_action_buttons);
|
when(mButtonsPref.setButton1OnClickListener(any(View.OnClickListener.class)))
|
||||||
mLayoutPreference.setKey(mController.getPreferenceKey());
|
.thenAnswer(invocation -> {
|
||||||
mScreen.addPreference(mLayoutPreference);
|
final Object[] args = invocation.getArguments();
|
||||||
mLeftButton = (Button) mLayoutPreference.findViewById(R.id.left_button);
|
mLeftButton.setOnClickListener((View.OnClickListener) args[0]);
|
||||||
mRightButton = (Button) mLayoutPreference.findViewById(R.id.right_button);
|
return mButtonsPref;
|
||||||
|
});
|
||||||
|
when(mButtonsPref.setButton2OnClickListener(any(View.OnClickListener.class)))
|
||||||
|
.thenAnswer(invocation -> {
|
||||||
|
final Object[] args = invocation.getArguments();
|
||||||
|
mRightButton.setOnClickListener((View.OnClickListener) args[0]);
|
||||||
|
return mButtonsPref;
|
||||||
|
});
|
||||||
|
mScreen.addPreference(mButtonsPref);
|
||||||
setupDevice(mDeviceConfig);
|
setupDevice(mDeviceConfig);
|
||||||
when(mCachedDevice.isBusy()).thenReturn(false);
|
when(mCachedDevice.isBusy()).thenReturn(false);
|
||||||
}
|
}
|
||||||
@@ -67,15 +82,16 @@ public class BluetoothDetailsButtonsControllerTest extends BluetoothDetailsContr
|
|||||||
@Test
|
@Test
|
||||||
public void connected() {
|
public void connected() {
|
||||||
showScreen(mController);
|
showScreen(mController);
|
||||||
assertThat(mLeftButton.getText()).isEqualTo(
|
|
||||||
mContext.getString(R.string.bluetooth_device_context_disconnect));
|
verify(mButtonsPref).setButton1Text(R.string.bluetooth_device_context_disconnect);
|
||||||
assertThat(mRightButton.getText()).isEqualTo(mContext.getString(R.string.forget));
|
verify(mButtonsPref).setButton2Text(R.string.forget);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void clickOnDisconnect() {
|
public void clickOnDisconnect() {
|
||||||
showScreen(mController);
|
showScreen(mController);
|
||||||
mLeftButton.callOnClick();
|
mLeftButton.callOnClick();
|
||||||
|
|
||||||
verify(mCachedDevice).disconnect();
|
verify(mCachedDevice).disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,8 +100,7 @@ public class BluetoothDetailsButtonsControllerTest extends BluetoothDetailsContr
|
|||||||
when(mCachedDevice.isConnected()).thenReturn(false);
|
when(mCachedDevice.isConnected()).thenReturn(false);
|
||||||
showScreen(mController);
|
showScreen(mController);
|
||||||
|
|
||||||
assertThat(mLeftButton.getText()).isEqualTo(
|
verify(mButtonsPref).setButton1Text(R.string.bluetooth_device_context_connect);
|
||||||
mContext.getString(R.string.bluetooth_device_context_connect));
|
|
||||||
|
|
||||||
mLeftButton.callOnClick();
|
mLeftButton.callOnClick();
|
||||||
verify(mCachedDevice).connect(eq(true));
|
verify(mCachedDevice).connect(eq(true));
|
||||||
@@ -95,14 +110,12 @@ public class BluetoothDetailsButtonsControllerTest extends BluetoothDetailsContr
|
|||||||
public void becomeDisconnected() {
|
public void becomeDisconnected() {
|
||||||
showScreen(mController);
|
showScreen(mController);
|
||||||
// By default we start out with the device connected.
|
// By default we start out with the device connected.
|
||||||
assertThat(mLeftButton.getText()).isEqualTo(
|
verify(mButtonsPref).setButton1Text(R.string.bluetooth_device_context_disconnect);
|
||||||
mContext.getString(R.string.bluetooth_device_context_disconnect));
|
|
||||||
|
|
||||||
// Now make the device appear to have changed to disconnected.
|
// Now make the device appear to have changed to disconnected.
|
||||||
when(mCachedDevice.isConnected()).thenReturn(false);
|
when(mCachedDevice.isConnected()).thenReturn(false);
|
||||||
mController.onDeviceAttributesChanged();
|
mController.onDeviceAttributesChanged();
|
||||||
assertThat(mLeftButton.getText()).isEqualTo(
|
verify(mButtonsPref).setButton1Text(R.string.bluetooth_device_context_connect);
|
||||||
mContext.getString(R.string.bluetooth_device_context_connect));
|
|
||||||
|
|
||||||
// Click the button and make sure that connect (not disconnect) gets called.
|
// Click the button and make sure that connect (not disconnect) gets called.
|
||||||
mLeftButton.callOnClick();
|
mLeftButton.callOnClick();
|
||||||
@@ -115,14 +128,13 @@ public class BluetoothDetailsButtonsControllerTest extends BluetoothDetailsContr
|
|||||||
when(mCachedDevice.isConnected()).thenReturn(false);
|
when(mCachedDevice.isConnected()).thenReturn(false);
|
||||||
showScreen(mController);
|
showScreen(mController);
|
||||||
|
|
||||||
assertThat(mLeftButton.getText()).isEqualTo(
|
verify(mButtonsPref).setButton1Text(R.string.bluetooth_device_context_connect);
|
||||||
mContext.getString(R.string.bluetooth_device_context_connect));
|
|
||||||
|
|
||||||
// Now make the device appear to have changed to connected.
|
// Now make the device appear to have changed to connected.
|
||||||
when(mCachedDevice.isConnected()).thenReturn(true);
|
when(mCachedDevice.isConnected()).thenReturn(true);
|
||||||
mController.onDeviceAttributesChanged();
|
mController.onDeviceAttributesChanged();
|
||||||
assertThat(mLeftButton.getText()).isEqualTo(
|
verify(mButtonsPref).setButton1Text(R.string.bluetooth_device_context_disconnect);
|
||||||
mContext.getString(R.string.bluetooth_device_context_disconnect));
|
|
||||||
|
|
||||||
// Click the button and make sure that disconnnect (not connect) gets called.
|
// Click the button and make sure that disconnnect (not connect) gets called.
|
||||||
mLeftButton.callOnClick();
|
mLeftButton.callOnClick();
|
||||||
@@ -150,24 +162,27 @@ public class BluetoothDetailsButtonsControllerTest extends BluetoothDetailsContr
|
|||||||
public void startsOutBusy() {
|
public void startsOutBusy() {
|
||||||
when(mCachedDevice.isBusy()).thenReturn(true);
|
when(mCachedDevice.isBusy()).thenReturn(true);
|
||||||
showScreen(mController);
|
showScreen(mController);
|
||||||
assertThat(mLeftButton.getText()).isEqualTo(
|
|
||||||
mContext.getString(R.string.bluetooth_device_context_disconnect));
|
verify(mButtonsPref).setButton1Text(R.string.bluetooth_device_context_disconnect);
|
||||||
assertThat(mRightButton.getText()).isEqualTo(mContext.getString(R.string.forget));
|
verify(mButtonsPref).setButton1Enabled(false);
|
||||||
assertThat(mLeftButton.isEnabled()).isFalse();
|
verify(mButtonsPref).setButton2Text(R.string.forget);
|
||||||
|
|
||||||
// Now pretend the device became non-busy.
|
// Now pretend the device became non-busy.
|
||||||
when(mCachedDevice.isBusy()).thenReturn(false);
|
when(mCachedDevice.isBusy()).thenReturn(false);
|
||||||
mController.onDeviceAttributesChanged();
|
mController.onDeviceAttributesChanged();
|
||||||
assertThat(mLeftButton.isEnabled()).isTrue();
|
|
||||||
|
verify(mButtonsPref).setButton1Enabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void becomesBusy() {
|
public void becomesBusy() {
|
||||||
showScreen(mController);
|
showScreen(mController);
|
||||||
assertThat(mLeftButton.isEnabled()).isTrue();
|
verify(mButtonsPref).setButton1Enabled(true);
|
||||||
|
|
||||||
|
// Now pretend the device became busy.
|
||||||
when(mCachedDevice.isBusy()).thenReturn(true);
|
when(mCachedDevice.isBusy()).thenReturn(true);
|
||||||
mController.onDeviceAttributesChanged();
|
mController.onDeviceAttributesChanged();
|
||||||
assertThat(mLeftButton.isEnabled()).isFalse();
|
|
||||||
|
verify(mButtonsPref).setButton1Enabled(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user