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

Commit 6386a94e authored by Romain Hunault's avatar Romain Hunault 🚴🏻
Browse files

Merge remote-tracking branch 'origin/lineage-16.0' into v1-pie

parents 96ebb1e4 d1a8aade
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -65,6 +65,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Resources;
import android.database.ContentObserver;
import android.hardware.usb.UsbManager;
import android.net.INetworkPolicyManager;
import android.net.INetworkStatsService;
@@ -123,6 +124,8 @@ import com.android.server.connectivity.tethering.TetheringInterfaceUtils;
import com.android.server.connectivity.tethering.UpstreamNetworkMonitor;
import com.android.server.net.BaseNetworkObserver;

import lineageos.providers.LineageSettings;

import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.net.Inet4Address;
@@ -291,6 +294,18 @@ public class Tethering extends BaseNetworkObserver {
        if (umi != null) {
            umi.addUserRestrictionsListener(new TetheringUserRestrictionListener(this));
        }

        // Listen for allowing tethering upstream via VPN settings changes
        final ContentObserver vpnSettingObserver = new ContentObserver(handler) {
            @Override
            public void onChange(boolean self) {
                // Reconsider tethering upstream
                mTetherMasterSM.sendMessage(TetherMasterSM.CMD_UPSTREAM_CHANGED);
            }
        };
        mContext.getContentResolver().registerContentObserver(LineageSettings.Secure.getUriFor(
                LineageSettings.Secure.TETHERING_ALLOW_VPN_UPSTREAMS), false, vpnSettingObserver,
                UserHandle.USER_ALL);
    }

    private WifiManager getWifiManager() {
+26 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import static android.net.ConnectivityManager.TYPE_NONE;
import static android.net.ConnectivityManager.TYPE_MOBILE_DUN;
import static android.net.ConnectivityManager.TYPE_MOBILE_HIPRI;
import static android.net.NetworkCapabilities.NET_CAPABILITY_DUN;
import static android.net.NetworkCapabilities.NET_CAPABILITY_INTERNET;
import static android.net.NetworkCapabilities.NET_CAPABILITY_NOT_VPN;
import static android.net.NetworkCapabilities.TRANSPORT_CELLULAR;

@@ -28,6 +29,7 @@ import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.os.Process;
import android.os.UserHandle;
import android.net.ConnectivityManager;
import android.net.ConnectivityManager.NetworkCallback;
import android.net.IpPrefix;
@@ -45,6 +47,8 @@ import android.util.Log;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.StateMachine;

import lineageos.providers.LineageSettings;

import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
@@ -103,6 +107,9 @@ public class UpstreamNetworkMonitor {
    // The current upstream network used for tethering.
    private Network mTetheringUpstreamNetwork;

    // Set if the Internet is considered reachable via a VPN network
    private Network mVpnInternetNetwork;

    public UpstreamNetworkMonitor(Context ctx, StateMachine tgt, SharedLog log, int what) {
        mContext = ctx;
        mTarget = tgt;
@@ -145,6 +152,7 @@ public class UpstreamNetworkMonitor {
        releaseCallback(mDefaultNetworkCallback);
        mDefaultNetworkCallback = null;
        mDefaultInternetNetwork = null;
        mVpnInternetNetwork = null;

        releaseCallback(mListenAllCallback);
        mListenAllCallback = null;
@@ -237,6 +245,14 @@ public class UpstreamNetworkMonitor {

    // Returns null if no current upstream available.
    public NetworkState getCurrentPreferredUpstream() {
        // Use VPN upstreams if hotspot settings allow.
        if (mVpnInternetNetwork != null &&
                LineageSettings.Secure.getIntForUser(mContext.getContentResolver(),
                       LineageSettings.Secure.TETHERING_ALLOW_VPN_UPSTREAMS,
                       0, UserHandle.USER_CURRENT) == 1) {
            return mNetworkMap.get(mVpnInternetNetwork);
        }

        final NetworkState dfltState = (mDefaultInternetNetwork != null)
                ? mNetworkMap.get(mDefaultInternetNetwork)
                : null;
@@ -267,6 +283,8 @@ public class UpstreamNetworkMonitor {
    private void handleNetCap(int callbackType, Network network, NetworkCapabilities newNc) {
        if (callbackType == CALLBACK_DEFAULT_INTERNET) mDefaultInternetNetwork = network;

        if (isVpnInternetNetwork(newNc)) mVpnInternetNetwork = network;

        final NetworkState prev = mNetworkMap.get(network);
        if (prev == null || newNc.equals(prev.networkCapabilities)) {
            // Ignore notifications about networks for which we have not yet
@@ -340,6 +358,9 @@ public class UpstreamNetworkMonitor {
            //       callback gets  notified.
            if (callbackType == CALLBACK_DEFAULT_INTERNET) return;
        }
        if (network.equals(mVpnInternetNetwork)) {
            mVpnInternetNetwork = null;
        }

        if (!mNetworkMap.containsKey(network)) {
            // Ignore loss of networks about which we had not previously
@@ -505,6 +526,11 @@ public class UpstreamNetworkMonitor {
               !isCellular(ns.networkCapabilities);
    }

    private static boolean isVpnInternetNetwork(NetworkCapabilities nc) {
        return (nc != null) && !nc.hasCapability(NET_CAPABILITY_NOT_VPN) &&
               nc.hasCapability(NET_CAPABILITY_INTERNET);
    }

    private static NetworkState findFirstDunNetwork(Iterable<NetworkState> netStates) {
        for (NetworkState ns : netStates) {
            if (isCellular(ns) && hasCapability(ns, NET_CAPABILITY_DUN)) return ns;
+7 −1
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import com.android.server.SystemService;

import android.app.ActivityManager;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Handler;
import android.os.Message;
import android.os.Trace;
@@ -201,9 +202,14 @@ public class LightsService extends SystemService {

    private int getVrDisplayMode() {
        int currentUser = ActivityManager.getCurrentUser();

        final PackageManager pm = getContext().getPackageManager();
        boolean lpEnable = pm.hasSystemFeature(PackageManager.FEATURE_VR_MODE_HIGH_PERFORMANCE);

        return Settings.Secure.getIntForUser(getContext().getContentResolver(),
                Settings.Secure.VR_DISPLAY_MODE,
                /*default*/Settings.Secure.VR_DISPLAY_MODE_LOW_PERSISTENCE,
                lpEnable ? Settings.Secure.VR_DISPLAY_MODE_LOW_PERSISTENCE :
                        Settings.Secure.VR_DISPLAY_MODE_OFF,
                currentUser);
    }

+16 −2
Original line number Diff line number Diff line
@@ -808,8 +808,22 @@ public class NotificationManagerService extends SystemService {
        @Override
        public void onNotificationError(int callingUid, int callingPid, String pkg, String tag, int id,
                int uid, int initialPid, String message, int userId) {
            cancelNotification(callingUid, callingPid, pkg, tag, id, 0, 0, false, userId,
                    REASON_ERROR, null);
            final boolean fgService;
            synchronized (mNotificationLock) {
                NotificationRecord r = findNotificationLocked(pkg, tag, id, userId);
                fgService = r != null && (r.getNotification().flags & FLAG_FOREGROUND_SERVICE) != 0;
            }
            cancelNotification(callingUid, callingPid, pkg, tag, id, 0, 0,
                    false, userId, REASON_ERROR, null);
            if (fgService) {
                // Still crash for foreground services, preventing the not-crash behaviour abused
                // by apps to give us a garbage notification and silently start a fg service.
                Binder.withCleanCallingIdentity(
                        () -> mAm.crashApplication(uid, initialPid, pkg, -1,
                            "Bad notification(tag=" + tag + ", id=" + id + ") posted from package "
                                + pkg + ", crashing app(uid=" + uid + ", pid=" + initialPid + "): "
                                + message));
            }
        }

        @Override
+5 −1
Original line number Diff line number Diff line
@@ -121,6 +121,7 @@ final class Notifier {
    @Nullable private final StatusBarManagerInternal mStatusBarManagerInternal;
    private final TrustManager mTrustManager;
    private final Vibrator mVibrator;
    private final AudioManager mAudioManager;

    private final NotifierHandler mHandler;
    private final Intent mScreenOnIntent;
@@ -168,6 +169,7 @@ final class Notifier {
        mStatusBarManagerInternal = LocalServices.getService(StatusBarManagerInternal.class);
        mTrustManager = mContext.getSystemService(TrustManager.class);
        mVibrator = mContext.getSystemService(Vibrator.class);
        mAudioManager = mContext.getSystemService(AudioManager.class);

        mHandler = new NotifierHandler(looper);
        mScreenOnIntent = new Intent(Intent.ACTION_SCREEN_ON);
@@ -806,7 +808,9 @@ final class Notifier {
        final boolean dndOff = Settings.Global.getInt(mContext.getContentResolver(),
                Settings.Global.ZEN_MODE, Settings.Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS)
                == Settings.Global.ZEN_MODE_OFF;
        return enabled && dndOff;
        final boolean silentMode = mAudioManager.getRingerModeInternal()
                == AudioManager.RINGER_MODE_SILENT;
        return enabled && dndOff && !silentMode;
    }

    private final class NotifierHandler extends Handler {