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

Commit f9e526df authored by Michael Wright's avatar Michael Wright Committed by Android (Google) Code Review
Browse files

Merge "Create Java interface to SensorService." into sc-dev

parents 32df2b14 e3912446
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -38,7 +38,7 @@ import java.util.concurrent.TimeUnit;
/**
 * Thread pool used during initialization of system server.
 *
 * <p>System services can {@link #submit(Runnable)} tasks for execution during boot.
 * <p>System services can {@link #submit(Runnable, String)} tasks for execution during boot.
 * The pool will be shut down after {@link SystemService#PHASE_BOOT_COMPLETED}.
 *
 * <p>New tasks <em>should not</em> be submitted afterwards.
+9 −1
Original line number Diff line number Diff line
@@ -70,11 +70,19 @@ public abstract class SystemService {
    /** @hide */
    protected static final boolean DEBUG_USER = false;

    /*
    /**
     * The earliest boot phase the system send to system services on boot.
     */
    public static final int PHASE_WAIT_FOR_DEFAULT_DISPLAY = 100;

    /**
     * Boot phase that blocks on SensorService availability. The service gets started
     * asynchronously since it may take awhile to actually finish initializing.
     *
     * @hide
     */
    public static final int PHASE_WAIT_FOR_SENSOR_SERVICE = 200;

    /**
     * After receiving this boot phase, services can obtain lock settings data.
     */
+64 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 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 com.android.server.sensors;

import android.content.Context;

import com.android.internal.annotations.GuardedBy;
import com.android.internal.util.ConcurrentUtils;
import com.android.server.SystemServerInitThreadPool;
import com.android.server.SystemService;
import com.android.server.utils.TimingsTraceAndSlog;

import java.util.concurrent.Future;

public class SensorService extends SystemService {
    private static final String START_NATIVE_SENSOR_SERVICE = "StartNativeSensorService";
    private final Object mLock = new Object();
    @GuardedBy("mLock")
    private Future<?> mSensorServiceStart;


    /** Start the sensor service. This is a blocking call and can take time. */
    private static native void startNativeSensorService();

    public SensorService(Context ctx) {
        super(ctx);
        synchronized (mLock) {
            mSensorServiceStart = SystemServerInitThreadPool.submit(() -> {
                TimingsTraceAndSlog traceLog = TimingsTraceAndSlog.newAsyncLog();
                traceLog.traceBegin(START_NATIVE_SENSOR_SERVICE);
                startNativeSensorService();
                traceLog.traceEnd();
            }, START_NATIVE_SENSOR_SERVICE);
        }
    }

    @Override
    public void onStart() { }

    @Override
    public void onBootPhase(int phase) {
        if (phase == SystemService.PHASE_WAIT_FOR_SENSOR_SERVICE) {
            ConcurrentUtils.waitForFutureNoInterrupt(mSensorServiceStart,
                    START_NATIVE_SENSOR_SERVICE);
            synchronized (mLock) {
                mSensorServiceStart = null;
            }
        }
    }
}
+1 −0
Original line number Diff line number Diff line
@@ -70,6 +70,7 @@ cc_library_static {
        "com_android_server_PersistentDataBlockService.cpp",
        "com_android_server_am_LowMemDetector.cpp",
        "com_android_server_pm_PackageManagerShellCommandDataLoader.cpp",
        "com_android_server_sensor_SensorService.cpp",
        "onload.cpp",
        ":lib_cachedAppOptimizer_native",
        ":lib_networkStatsFactory_native",
+0 −13
Original line number Diff line number Diff line
@@ -32,7 +32,6 @@

#include <memtrackproxy/MemtrackProxy.h>
#include <schedulerservice/SchedulingPolicyService.h>
#include <sensorservice/SensorService.h>
#include <sensorservicehidl/SensorManager.h>
#include <stats/StatsAidl.h>
#include <stats/StatsHal.h>
@@ -41,12 +40,10 @@
#include <bionic/reserved_signals.h>

#include <android-base/properties.h>
#include <cutils/properties.h>
#include <utils/Log.h>
#include <utils/misc.h>
#include <utils/AndroidThreads.h>

using android::base::GetIntProperty;
using namespace std::chrono_literals;

namespace {
@@ -81,15 +78,6 @@ static void android_server_SystemServer_startIStatsService(JNIEnv* /* env */, jo
    startStatsAidlService();
}

static void android_server_SystemServer_startSensorService(JNIEnv* /* env */, jobject /* clazz */) {
    char propBuf[PROPERTY_VALUE_MAX];
    property_get("system_init.startsensorservice", propBuf, "1");
    if (strcmp(propBuf, "1") == 0) {
        SensorService::publish(false /* allowIsolated */,
                               IServiceManager::DUMP_FLAG_PRIORITY_CRITICAL);
    }
}

static void android_server_SystemServer_startMemtrackProxyService(JNIEnv* env,
                                                                  jobject /* clazz */) {
    using aidl::android::hardware::memtrack::MemtrackProxy;
@@ -163,7 +151,6 @@ static void android_server_SystemServer_setIncrementalServiceSystemReady(JNIEnv*
static const JNINativeMethod gMethods[] = {
        /* name, signature, funcPtr */
        {"startIStatsService", "()V", (void*)android_server_SystemServer_startIStatsService},
        {"startSensorService", "()V", (void*)android_server_SystemServer_startSensorService},
        {"startMemtrackProxyService", "()V",
         (void*)android_server_SystemServer_startMemtrackProxyService},
        {"startHidlServices", "()V", (void*)android_server_SystemServer_startHidlServices},
Loading