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

Commit 901db250 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "[MS30] Remove ServiceManager#getService dependency" am: eb03a3b8 am:...

Merge "[MS30] Remove ServiceManager#getService dependency" am: eb03a3b8 am: 069ce4f2 am: 577f32c7

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1934470

Change-Id: Ib9caca1691a86b2dd1823a4d1a07988f49896c8d
parents 84043479 577f32c7
Loading
Loading
Loading
Loading
+20 −3
Original line number Original line Diff line number Diff line
@@ -17,6 +17,7 @@
package android.net;
package android.net;


import android.annotation.NonNull;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SuppressLint;
import android.annotation.SuppressLint;
import android.annotation.SystemApi;
import android.annotation.SystemApi;
import android.annotation.TestApi;
import android.annotation.TestApi;
@@ -27,8 +28,8 @@ import android.compat.annotation.UnsupportedAppUsage;
import android.content.Context;
import android.content.Context;
import android.media.MediaPlayer;
import android.media.MediaPlayer;
import android.os.Build;
import android.os.Build;
import android.os.IBinder;
import android.os.RemoteException;
import android.os.RemoteException;
import android.os.ServiceManager;


import com.android.server.NetworkManagementSocketTagger;
import com.android.server.NetworkManagementSocketTagger;


@@ -36,6 +37,8 @@ import dalvik.system.SocketTagger;


import java.io.FileDescriptor;
import java.io.FileDescriptor;
import java.io.IOException;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.DatagramSocket;
import java.net.DatagramSocket;
import java.net.Socket;
import java.net.Socket;
import java.net.SocketException;
import java.net.SocketException;
@@ -53,6 +56,7 @@ import java.net.SocketException;
 * use {@link NetworkStatsManager} instead.
 * use {@link NetworkStatsManager} instead.
 */
 */
public class TrafficStats {
public class TrafficStats {
    private static final String TAG = TrafficStats.class.getSimpleName();
    /**
    /**
     * The return value to indicate that the device does not support the statistic.
     * The return value to indicate that the device does not support the statistic.
     */
     */
@@ -173,12 +177,25 @@ public class TrafficStats {
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 130143562)
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 130143562)
    private synchronized static INetworkStatsService getStatsService() {
    private synchronized static INetworkStatsService getStatsService() {
        if (sStatsService == null) {
        if (sStatsService == null) {
            sStatsService = INetworkStatsService.Stub.asInterface(
            sStatsService = getStatsBinder();
                    ServiceManager.getService(Context.NETWORK_STATS_SERVICE));
        }
        }
        return sStatsService;
        return sStatsService;
    }
    }


    @Nullable
    private static INetworkStatsService getStatsBinder() {
        try {
            final Method getServiceMethod = Class.forName("android.os.ServiceManager")
                    .getDeclaredMethod("getService", new Class[]{String.class});
            final IBinder binder = (IBinder) getServiceMethod.invoke(
                    null, Context.NETWORK_STATS_SERVICE);
            return INetworkStatsService.Stub.asInterface(binder);
        } catch (NoSuchMethodException | ClassNotFoundException | IllegalAccessException
                | InvocationTargetException e) {
            throw new NullPointerException("Cannot get INetworkStatsService: " + e);
        }
    }

    /**
    /**
     * Snapshot of {@link NetworkStats} when the currently active profiling
     * Snapshot of {@link NetworkStats} when the currently active profiling
     * session started, or {@code null} if no session active.
     * session started, or {@code null} if no session active.
+1 −0
Original line number Original line Diff line number Diff line
@@ -26,6 +26,7 @@ import java.net.SocketException;


/**
/**
 * Assigns tags to sockets for traffic stats.
 * Assigns tags to sockets for traffic stats.
 * @hide
 */
 */
public final class NetworkManagementSocketTagger extends SocketTagger {
public final class NetworkManagementSocketTagger extends SocketTagger {
    private static final String TAG = "NetworkManagementSocketTagger";
    private static final String TAG = "NetworkManagementSocketTagger";