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

Commit 4329c0d2 authored by Jeffrey Huang's avatar Jeffrey Huang Committed by Android (Google) Code Review
Browse files

Merge changes I9ea3677d,I0a59dce8

* changes:
  Migrate away from using ServiceManager
  Migrate StatsManager to apex
parents 75b5b13c f58800b6
Loading
Loading
Loading
Loading
+8 −3
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@ java_library {
    name: "framework-statsd",
    installable: true,
    // TODO(b/146209659): Use system_current instead.
    sdk_version: "core_current",
    sdk_version: "core_platform",
    srcs: [
        ":framework-statsd-sources",
    ],
@@ -35,7 +35,9 @@ java_library {
    libs: [
        "framework-annotations-lib",
        // TODO(b/146230220): Use framework-system-stubs instead.
        "android_system_stubs_current",
        //"android_system_stubs_current",
        //"framework_module_lib_stubs_current",
        "framework-all",
    ],
    hostdex: true, // for hiddenapi check
    visibility: [
@@ -52,12 +54,14 @@ java_library {
droidstubs {
    name: "framework-statsd-stubs-docs",
    defaults: [
        "framework-module-stubs-defaults-publicapi"
        "framework-module-stubs-defaults-systemapi"
    ],
    srcs: [
        ":framework-annotations",
        ":framework-statsd-sources",
    ],
    libs: [
        // TODO(b/148218250): Change to android_system_stubs_current
        "framework-all",
    ],
    sdk_version: "core_platform",
@@ -70,6 +74,7 @@ java_library {
        ":framework-statsd-stubs-docs",
    ],
    libs: [
        // TODO(b/148218250): Change to android_system_stubs_current
        "framework-all",
    ],
    sdk_version: "core_platform",
+5 −2
Original line number Diff line number Diff line
@@ -30,7 +30,7 @@ import android.os.IPullAtomResultReceiver;
import android.os.IStatsManagerService;
import android.os.IStatsd;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.StatsFrameworkInitializer;
import android.util.AndroidException;
import android.util.Slog;
import android.util.StatsEvent;
@@ -702,7 +702,10 @@ public final class StatsManager {
            return mStatsManagerService;
        }
        mStatsManagerService = IStatsManagerService.Stub.asInterface(
                ServiceManager.getService(Context.STATS_MANAGER_SERVICE));
                StatsFrameworkInitializer
                .getStatsServiceManager()
                .getStatsManagerServiceRegisterer()
                .get());
        return mStatsManagerService;
    }

+77 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 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.
 */
package android.os;

import android.annotation.NonNull;
import android.annotation.SystemApi;
import android.app.StatsManager;
import android.app.SystemServiceRegistry;
import android.content.Context;

/**
 * Class for performing registration for all stats services
 *
 * TODO(b/148225705) Change to @SystemApi(client=MODULE_LIBRARIES) when the build system is ready.
 * @hide
 */
@SystemApi
public class StatsFrameworkInitializer {
    private StatsFrameworkInitializer() {
    }

    private static volatile StatsServiceManager sStatsServiceManager;

    /**
     * Sets an instance of {@link StatsServiceManager} that allows
     * the statsd mainline module to register/obtain stats binder services. This is called
     * by the platform during the system initialization.
     *
     * @param statsServiceManager instance of {@link StatsServiceManager} that allows
     * the statsd mainline module to register/obtain statsd binder services.
     */
    public static void setStatsServiceManager(
            @NonNull StatsServiceManager statsServiceManager) {
        if (sStatsServiceManager != null) {
            throw new IllegalStateException("setStatsServiceManager called twice!");
        }

        if (statsServiceManager == null) {
            throw new NullPointerException("statsServiceManager is null");
        }

        sStatsServiceManager = statsServiceManager;
    }

    /** @hide */
    public static StatsServiceManager getStatsServiceManager() {
        return sStatsServiceManager;
    }

    /**
     * Called by {@link SystemServiceRegistry}'s static initializer and registers all statsd
     * services to {@link Context}, so that {@link Context#getSystemService} can return them.
     *
     * @throws IllegalStateException if this is called from anywhere besides
     * {@link SystemServiceRegistry}
     */
    public static void registerServiceWrappers() {
        SystemServiceRegistry.registerContextAwareService(
                Context.STATS_MANAGER,
                StatsManager.class,
                context -> new StatsManager(context)
        );
    }
}
+5 −1
Original line number Diff line number Diff line
@@ -85,6 +85,7 @@ import android.os.ParcelFileDescriptor;
import android.os.Parcelable;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.StatsFrameworkInitializer;
import android.os.StatFs;
import android.os.StatsLogEventWrapper;
import android.os.SynchronousResultReceiver;
@@ -750,7 +751,10 @@ public class StatsCompanionService extends IStatsCompanionService.Stub {
     * sStatsd with a null check.
     */
    private static IStatsd fetchStatsdService() {
        return IStatsd.Stub.asInterface(ServiceManager.getService("stats"));
        return IStatsd.Stub.asInterface(StatsFrameworkInitializer
            .getStatsServiceManager()
            .getStatsdServiceRegisterer()
            .get());
    }

    /**
+20 −0
Original line number Diff line number Diff line
@@ -8770,6 +8770,26 @@ package android.os {
    field public static final int TUPLE_VALUE_TYPE = 7; // 0x7
  }
  public class StatsFrameworkInitializer {
    method public static void registerServiceWrappers();
    method public static void setStatsServiceManager(@NonNull android.os.StatsServiceManager);
  }
  public class StatsServiceManager {
    method @NonNull public android.os.StatsServiceManager.ServiceRegisterer getStatsCompanionServiceRegisterer();
    method @NonNull public android.os.StatsServiceManager.ServiceRegisterer getStatsManagerServiceRegisterer();
    method @NonNull public android.os.StatsServiceManager.ServiceRegisterer getStatsdServiceRegisterer();
  }
  public static class StatsServiceManager.ServiceNotFoundException extends java.lang.Exception {
    ctor public StatsServiceManager.ServiceNotFoundException(@NonNull String);
  }
  public static final class StatsServiceManager.ServiceRegisterer {
    method @Nullable public android.os.IBinder get();
    method @Nullable public android.os.IBinder getOrThrow() throws android.os.StatsServiceManager.ServiceNotFoundException;
  }
  public class SystemConfigManager {
    method @NonNull @RequiresPermission(android.Manifest.permission.READ_CARRIER_APP_INFO) public java.util.Set<java.lang.String> getDisabledUntilUsedPreinstalledCarrierApps();
    method @NonNull @RequiresPermission(android.Manifest.permission.READ_CARRIER_APP_INFO) public java.util.Map<java.lang.String,java.util.List<java.lang.String>> getDisabledUntilUsedPreinstalledCarrierAssociatedApps();
Loading