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

Commit 4d25f52a authored by Daniel Estrada Alva's avatar Daniel Estrada Alva Committed by Android (Google) Code Review
Browse files

Merge "Clean up Gps/Flp Hardware on shut-down."

parents e171a1cd b9026986
Loading
Loading
Loading
Loading
+25 −0
Original line number Diff line number Diff line
@@ -307,6 +307,7 @@ public class LocationManagerService extends ILocationManager.Stub {
        intentFilter.addAction(Intent.ACTION_USER_SWITCHED);
        intentFilter.addAction(Intent.ACTION_MANAGED_PROFILE_ADDED);
        intentFilter.addAction(Intent.ACTION_MANAGED_PROFILE_REMOVED);
        intentFilter.addAction(Intent.ACTION_SHUTDOWN);

        mContext.registerReceiverAsUser(new BroadcastReceiver() {
            @Override
@@ -317,11 +318,35 @@ public class LocationManagerService extends ILocationManager.Stub {
                } else if (Intent.ACTION_MANAGED_PROFILE_ADDED.equals(action)
                        || Intent.ACTION_MANAGED_PROFILE_REMOVED.equals(action)) {
                    updateUserProfiles(mCurrentUserId);
                } else if (Intent.ACTION_SHUTDOWN.equals(action)) {
                    shutdownComponents();
                }
            }
        }, UserHandle.ALL, intentFilter, null, mLocationHandler);
    }

    /**
     * Provides a way for components held by the {@link LocationManagerService} to clean-up
     * gracefully on system's shutdown.
     *
     * NOTES:
     * 1) Only provides a chance to clean-up on an opt-in basis. This guarantees back-compat
     * support for components that do not wish to handle such event.
     */
    private void shutdownComponents() {
        if(D) Log.d(TAG, "Shutting down components...");

        LocationProviderInterface gpsProvider = mProvidersByName.get(LocationManager.GPS_PROVIDER);
        if (gpsProvider != null && gpsProvider.isEnabled()) {
            gpsProvider.disable();
        }

        FlpHardwareProvider flpHardwareProvider = FlpHardwareProvider.getInstance(mContext);
        if (FlpHardwareProvider.isSupported() && flpHardwareProvider != null) {
            flpHardwareProvider.cleanup();
        }
    }

    /**
     * Makes a list of userids that are related to the current user. This is
     * relevant when using managed profiles. Otherwise the list only contains
+7 −4
Original line number Diff line number Diff line
@@ -16,19 +16,18 @@

package com.android.server.location;

import android.content.Context;
import android.hardware.location.GeofenceHardware;
import android.hardware.location.GeofenceHardwareImpl;
import android.hardware.location.GeofenceHardwareRequestParcelable;
import android.hardware.location.IFusedLocationHardware;
import android.hardware.location.IFusedLocationHardwareSink;
import android.location.IFusedGeofenceHardware;
import android.location.FusedBatchOptions;
import android.location.IFusedGeofenceHardware;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.location.LocationRequest;

import android.content.Context;
import android.os.Bundle;
import android.os.Looper;
import android.os.RemoteException;
@@ -301,7 +300,6 @@ public class FlpHardwareProvider {
    private native void nativeRequestBatchedLocation(int lastNLocations);
    private native void nativeFlushBatchedLocations();
    private native void nativeInjectLocation(Location location);
    // TODO [Fix] sort out the lifetime of the instance
    private native void nativeCleanup();

    // FlpDiagnosticsInterface members
@@ -341,6 +339,11 @@ public class FlpHardwareProvider {
        return mGeofenceHardwareService;
    }

    public void cleanup() {
        Log.i(TAG, "Calling nativeCleanup()");
        nativeCleanup();
    }

    private final IFusedLocationHardware mLocationHardware = new IFusedLocationHardware.Stub() {
        @Override
        public void registerSink(IFusedLocationHardwareSink eventSink) {
+0 −10
Original line number Diff line number Diff line
@@ -840,16 +840,6 @@ static void Cleanup(JNIEnv* env, jobject /* object */) {
    env->DeleteGlobalRef(sCallbacksObj);
    sCallbacksObj = NULL;
  }

  sFlpInterface = NULL;
  sFlpDiagnosticInterface = NULL;
  sFlpDeviceContextInterface = NULL;
  sFlpGeofencingInterface = NULL;

  if(sHardwareDevice != NULL) {
    sHardwareDevice->close(sHardwareDevice);
    sHardwareDevice = NULL;
  }
}

static void GetBatchedLocation(JNIEnv* env, jobject /* object */, jint lastNLocations) {