Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3902516a authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Unify action buttons to a common widget (part 1)"

parents d3feec2c 2d28a4ce
Loading
Loading
Loading
Loading
+66 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
  Copyright (C) 2017 The Android Open Source Project

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
  -->

<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">

    <FrameLayout
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="wrap_content">
        <Button
            android:id="@+id/button1_positive"
            style="@style/AppActionPrimaryButton"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:paddingEnd="8dp" />
        <Button
            android:id="@+id/button1_negative"
            style="@style/ActionSecondaryButton"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:paddingStart="8dp" />
    </FrameLayout>
    <FrameLayout
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="wrap_content">
        <Button
            android:id="@+id/button2_positive"
            style="@style/AppActionPrimaryButton"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:paddingStart="8dp" />
        <Button
            android:id="@+id/button2_negative"
            style="@style/ActionSecondaryButton"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:paddingStart="8dp" />
    </FrameLayout>
</LinearLayout>
 No newline at end of file
+2 −0
Original line number Diff line number Diff line
@@ -423,6 +423,8 @@

    <style name="AppActionPrimaryButton" parent="android:Widget.Material.Button.Colored"/>

    <style name="ActionSecondaryButton" parent="android:Widget.Material.Button"/>

    <style name="DreamStartButton" parent="android:Widget.Material.Button" />

    <style name="LockPatternStyle">
+1 −3
Original line number Diff line number Diff line
@@ -23,10 +23,8 @@
        android:selectable="false"
        android:order="-10000"/>

    <com.android.settings.applications.LayoutPreference
    <com.android.settings.widget.ActionButtonPreference
        android:key="action_buttons"
        android:layout="@layout/app_action_buttons"
        android:selectable="false"
        android:order="-9999"/>

    <Preference
+1 −2
Original line number Diff line number Diff line
@@ -26,9 +26,8 @@
    <PreferenceCategory
            android:key="general_details_category" >
        <!-- Buttons -->
        <com.android.settings.applications.LayoutPreference
        <com.android.settings.widget.ActionButtonPreference
            android:key="buttons"
            android:layout="@layout/wifi_network_details_two_buttons_panel"
            android:selectable="false" />

        <com.android.settings.wifi.WifiDetailPreference
+39 −38
Original line number Diff line number Diff line
@@ -37,23 +37,22 @@ import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.UserHandle;
import android.os.UserManager;
import android.support.annotation.VisibleForTesting;
import android.support.v7.preference.PreferenceScreen;
import android.util.Log;
import android.view.View;
import android.webkit.IWebViewUpdateService;
import android.widget.Button;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.DeviceAdminAdd;
import com.android.settings.R;
import com.android.settings.SettingsActivity;
import com.android.settings.Utils;
import com.android.settings.applications.LayoutPreference;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
import com.android.settings.enterprise.DevicePolicyManagerWrapper;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.widget.ActionButtonPreference;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.applications.AppUtils;
import com.android.settingslib.applications.ApplicationsState;
@@ -79,7 +78,7 @@ import java.util.List;
//TODO(b/35810915): Make InstalledAppDetails use this controller
public class AppButtonsPreferenceController extends AbstractPreferenceController implements
        PreferenceControllerMixin, LifecycleObserver, OnResume, OnPause, OnDestroy,
        View.OnClickListener, ApplicationsState.Callbacks {
        ApplicationsState.Callbacks {
    public static final String APP_CHG = "chg";

    private static final String TAG = "AppButtonsPrefCtl";
@@ -95,13 +94,11 @@ public class AppButtonsPreferenceController extends AbstractPreferenceController
    @VisibleForTesting
    PackageInfo mPackageInfo;
    @VisibleForTesting
    Button mForceStopButton;
    @VisibleForTesting
    Button mUninstallButton;
    @VisibleForTesting
    String mPackageName;
    @VisibleForTesting
    boolean mDisableAfterUninstall = false;
    @VisibleForTesting
    ActionButtonPreference mButtonsPref;

    private final int mRequestUninstall;
    private final int mRequestRemoveDeviceAdmin;
@@ -115,7 +112,6 @@ public class AppButtonsPreferenceController extends AbstractPreferenceController
    private RestrictedLockUtils.EnforcedAdmin mAppsControlDisallowedAdmin;
    private MetricsFeatureProvider mMetricsFeatureProvider;

    private LayoutPreference mButtonsPref;
    private int mUserId;
    private boolean mUpdatedSysApp = false;
    private boolean mListeningToPackageRemove = false;
@@ -165,14 +161,14 @@ public class AppButtonsPreferenceController extends AbstractPreferenceController
    public void displayPreference(PreferenceScreen screen) {
        super.displayPreference(screen);
        if (isAvailable()) {
            mButtonsPref = (LayoutPreference) screen.findPreference(KEY_ACTION_BUTTONS);

            mUninstallButton = (Button) mButtonsPref.findViewById(R.id.left_button);
            mUninstallButton.setText(R.string.uninstall_text);

            mForceStopButton = (Button) mButtonsPref.findViewById(R.id.right_button);
            mForceStopButton.setText(R.string.force_stop);
            mForceStopButton.setEnabled(false);
            mButtonsPref = ((ActionButtonPreference) screen.findPreference(KEY_ACTION_BUTTONS))
                    .setButton1Text(R.string.uninstall_text)
                    .setButton2Text(R.string.force_stop)
                    .setButton1OnClickListener(new UninstallAndDisableButtonListener())
                    .setButton2OnClickListener(new ForceStopButtonListener())
                    .setButton1Positive(false)
                    .setButton2Positive(false)
                    .setButton2Enabled(false);
        }
    }

@@ -207,11 +203,11 @@ public class AppButtonsPreferenceController extends AbstractPreferenceController
        mSession.release();
    }

    private class UninstallAndDisableButtonListener implements View.OnClickListener {

        @Override
        public void onClick(View v) {
            final String packageName = mAppEntry.info.packageName;
        final int id = v.getId();
        if (id == R.id.left_button) {
            // Uninstall
            if (mDpm.packageHasActiveAdmins(mPackageInfo.packageName)) {
                stopListeningToPackageRemove();
@@ -254,7 +250,13 @@ public class AppButtonsPreferenceController extends AbstractPreferenceController
            } else {
                uninstallPkg(packageName, false, false);
            }
        } else if (id == R.id.right_button) {
        }
    }

    private class ForceStopButtonListener implements View.OnClickListener {

        @Override
        public void onClick(View v) {
            // force stop
            if (mAppsControlDisallowedAdmin != null && !mAppsControlDisallowedBySystem) {
                RestrictedLockUtils.sendShowAdminSupportDetailsIntent(
@@ -363,7 +365,7 @@ public class AppButtonsPreferenceController extends AbstractPreferenceController
        final boolean isBundled = (mAppEntry.info.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
        boolean enabled = true;
        if (isBundled) {
            enabled = handleDisableable(mUninstallButton);
            enabled = handleDisableable();
        } else {
            if ((mPackageInfo.applicationInfo.flags & ApplicationInfo.FLAG_INSTALLED) == 0
                    && mUserManager.getUsers().size() >= 2) {
@@ -428,11 +430,7 @@ public class AppButtonsPreferenceController extends AbstractPreferenceController
            enabled = false;
        }

        mUninstallButton.setEnabled(enabled);
        if (enabled) {
            // Register listener
            mUninstallButton.setOnClickListener(this);
        }
        mButtonsPref.setButton1Enabled(enabled);
    }

    /**
@@ -477,12 +475,12 @@ public class AppButtonsPreferenceController extends AbstractPreferenceController
        if (mDpm.packageHasActiveAdmins(mPackageInfo.packageName)) {
            // User can't force stop device admin.
            Log.w(TAG, "User can't force stop device admin");
            updateForceStopButtonInner(false);
            updateForceStopButtonInner(false /* enabled */);
        } else if ((mAppEntry.info.flags & ApplicationInfo.FLAG_STOPPED) == 0) {
            // If the app isn't explicitly stopped, then always show the
            // force stop button.
            Log.w(TAG, "App is not explicitly stopped");
            updateForceStopButtonInner(true);
            updateForceStopButtonInner(true /* enabled */);
        } else {
            Intent intent = new Intent(Intent.ACTION_QUERY_PACKAGE_RESTART,
                    Uri.fromParts("package", mAppEntry.info.packageName, null));
@@ -499,10 +497,9 @@ public class AppButtonsPreferenceController extends AbstractPreferenceController
    @VisibleForTesting
    void updateForceStopButtonInner(boolean enabled) {
        if (mAppsControlDisallowedBySystem) {
            mForceStopButton.setEnabled(false);
            mButtonsPref.setButton2Enabled(false);
        } else {
            mForceStopButton.setEnabled(enabled);
            mForceStopButton.setOnClickListener(this);
            mButtonsPref.setButton2Enabled(enabled);
        }
    }

@@ -538,7 +535,7 @@ public class AppButtonsPreferenceController extends AbstractPreferenceController
    }

    @VisibleForTesting
    boolean handleDisableable(Button button) {
    boolean handleDisableable() {
        boolean disableable = false;
        // Try to prevent the user from bricking their phone
        // by not allowing disabling of apps signed with the
@@ -546,12 +543,16 @@ public class AppButtonsPreferenceController extends AbstractPreferenceController
        if (mHomePackages.contains(mAppEntry.info.packageName)
                || isSystemPackage(mActivity.getResources(), mPm, mPackageInfo)) {
            // Disable button for core system applications.
            button.setText(R.string.disable_text);
            mButtonsPref.setButton1Text(R.string.disable_text)
                    .setButton1Positive(false);

        } else if (mAppEntry.info.enabled && !isDisabledUntilUsed()) {
            button.setText(R.string.disable_text);
            mButtonsPref.setButton1Text(R.string.disable_text)
                    .setButton1Positive(false);
            disableable = true;
        } else {
            button.setText(R.string.enable_text);
            mButtonsPref.setButton1Text(R.string.enable_text)
                    .setButton1Positive(true);
            disableable = true;
        }

Loading