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

Commit c94b6373 authored by phweiss's avatar phweiss
Browse files

DO NOT MERGE Add network logging icon to Quicksettings when enabled

Add the network logging icon in Quick Settings' footer if
network logging is enabled, possible next to the VPN icon.
Quicksettings has to be able to tell that network logging
is enabled, so this CL changes DPM.isNetworkLoggingEnabled() to be
callable from the device owner or from any app with the MANAGE_USERS
permission.

The icon is only a placeholder until the official icon is finished.

CTS Verifier tests will be added when all Network logging UX changes are
done.

Cherry-picked from master, and then modified to work in N:
I had to remove the QSFooterTest change because the testing infrastructure
is not there in N. Also, I had to add DPMS.enforceDeviceOwnerOrManageUsers()
to which did not exist in N before.

BUG: 33126618
BUG: 29748723
Test: Manual, CTS-Verifier tests will be added in a follow-up

(cherry picked from commit a4e169ed)

Change-Id: Ib35d323605ab11f883a4b6199d1db79b9e53c49b
parent 2bfb3155
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -6637,13 +6637,15 @@ public class DevicePolicyManager {
    /**
     * Return whether network logging is enabled by a device owner.
     *
     * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
     * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Can only
     * be {@code null} if the caller has MANAGE_USERS permission.
     * @return {@code true} if network logging is enabled by device owner, {@code false} otherwise.
     * @throws {@link SecurityException} if {@code admin} is not a device owner.
     * @throws {@link SecurityException} if {@code admin} is not a device owner and caller has
     * no MANAGE_USERS permission
     *
     * @hide
     */
    public boolean isNetworkLoggingEnabled(@NonNull ComponentName admin) {
    public boolean isNetworkLoggingEnabled(@Nullable ComponentName admin) {
        throwIfParentInstance("isNetworkLoggingEnabled");
        try {
            return mService.isNetworkLoggingEnabled(admin);
+29 −0
Original line number Diff line number Diff line
<!--
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.
-->

<!-- Placeholder icon for network logging until the real icon is finalized-->

<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="12.0dp"
        android:height="12.0dp"
        android:viewportWidth="24.0"
        android:viewportHeight="24.0"
        android:tint="#4DFFFFFF" >
    <path
        android:fillColor="#FFFFFFFF"
        android:pathData="M7,18v-2h6v2H7z M7,14v-2h10v2H7z M8.5,9 12,5.5 15.5,9 13,9 13,13 11,13 11,9z"/>

</vector>
+13 −1
Original line number Diff line number Diff line
@@ -39,4 +39,16 @@
        android:src="@drawable/ic_qs_vpn"
        android:visibility="invisible" />

    <!-- Only shown if both images are visible -->
    <ImageView
        android:id="@+id/footer_icon2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_marginEnd="8dp"
        android:layout_toStartOf="@id/footer_icon"
        android:contentDescription="@null"
        android:src="@drawable/ic_qs_network_logging"
        android:visibility="invisible" />

</RelativeLayout>
+21 −2
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ public class QSFooter implements OnClickListener, DialogInterface.OnClickListene
    private final View mRootView;
    private final TextView mFooterText;
    private final ImageView mFooterIcon;
    private final ImageView mFooterIcon2;
    private final Context mContext;
    private final Callback mCallback = new Callback();

@@ -57,8 +58,10 @@ public class QSFooter implements OnClickListener, DialogInterface.OnClickListene

    private boolean mIsVisible;
    private boolean mIsIconVisible;
    private boolean mIsIcon2Visible;
    private int mFooterTextId;
    private int mFooterIconId;
    private int mFooterIcon2Id;

    public QSFooter(QSPanel qsPanel, Context context) {
        mRootView = LayoutInflater.from(context)
@@ -66,7 +69,9 @@ public class QSFooter implements OnClickListener, DialogInterface.OnClickListene
        mRootView.setOnClickListener(this);
        mFooterText = (TextView) mRootView.findViewById(R.id.footer_text);
        mFooterIcon = (ImageView) mRootView.findViewById(R.id.footer_icon);
        mFooterIcon2 = (ImageView) mRootView.findViewById(R.id.footer_icon2);
        mFooterIconId = R.drawable.ic_qs_vpn;
        mFooterIcon2Id = R.drawable.ic_qs_network_logging;
        mContext = context;
        mMainHandler = new Handler();
    }
@@ -113,17 +118,29 @@ public class QSFooter implements OnClickListener, DialogInterface.OnClickListene
    }

    private void handleRefreshState() {
        mIsIconVisible = mSecurityController.isVpnEnabled();
        // If the device has device owner, show "Device may be monitored", but --
        // TODO See b/25779452 -- device owner doesn't actually have monitoring power.
        boolean isVpnEnabled = mSecurityController.isVpnEnabled();
        boolean isNetworkLoggingEnabled = mSecurityController.isNetworkLoggingEnabled();
        mIsIconVisible = isVpnEnabled || isNetworkLoggingEnabled;
        mIsIcon2Visible = isVpnEnabled && isNetworkLoggingEnabled;
        if (mSecurityController.isDeviceManaged()) {
            mFooterTextId = R.string.device_owned_footer;
            mIsVisible = true;
            int footerIconId = isVpnEnabled
                    ? R.drawable.ic_qs_vpn
                    : R.drawable.ic_qs_network_logging;
            if (mFooterIconId != footerIconId) {
                mFooterIconId = footerIconId;
                mMainHandler.post(mUpdateIcon);
            }
        } else {
            boolean isBranded = mSecurityController.isVpnBranded();
            mFooterTextId = isBranded ? R.string.branded_vpn_footer : R.string.vpn_footer;
            // Update the VPN footer icon, if needed.
            int footerIconId = isBranded ? R.drawable.ic_qs_branded_vpn : R.drawable.ic_qs_vpn;
            int footerIconId = isVpnEnabled
                    ? (isBranded ? R.drawable.ic_qs_branded_vpn : R.drawable.ic_qs_vpn)
                    : R.drawable.ic_qs_network_logging;
            if (mFooterIconId != footerIconId) {
                mFooterIconId = footerIconId;
                mMainHandler.post(mUpdateIcon);
@@ -219,6 +236,7 @@ public class QSFooter implements OnClickListener, DialogInterface.OnClickListene
        @Override
        public void run() {
            mFooterIcon.setImageResource(mFooterIconId);
            mFooterIcon2.setImageResource(mFooterIcon2Id);
        }
    };

@@ -230,6 +248,7 @@ public class QSFooter implements OnClickListener, DialogInterface.OnClickListene
            }
            mRootView.setVisibility(mIsVisible ? View.VISIBLE : View.GONE);
            mFooterIcon.setVisibility(mIsIconVisible ? View.VISIBLE : View.INVISIBLE);
            mFooterIcon2.setVisibility(mIsIcon2Visible ? View.VISIBLE : View.INVISIBLE);
        }
    };

+1 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ public interface SecurityController {
    boolean hasProfileOwner();
    String getDeviceOwnerName();
    String getProfileOwnerName();
    boolean isNetworkLoggingEnabled();
    boolean isVpnEnabled();
    boolean isVpnRestricted();
    /** Whether the VPN app should use branded VPN iconography.  */
Loading