diff options
Diffstat (limited to 'guest/monitoring/cuttlefish_service/java/com/android/google/gce/gceservice/GceService.java')
-rw-r--r-- | guest/monitoring/cuttlefish_service/java/com/android/google/gce/gceservice/GceService.java | 71 |
1 files changed, 10 insertions, 61 deletions
diff --git a/guest/monitoring/cuttlefish_service/java/com/android/google/gce/gceservice/GceService.java b/guest/monitoring/cuttlefish_service/java/com/android/google/gce/gceservice/GceService.java index 80d497a10..8e7bcc55d 100644 --- a/guest/monitoring/cuttlefish_service/java/com/android/google/gce/gceservice/GceService.java +++ b/guest/monitoring/cuttlefish_service/java/com/android/google/gce/gceservice/GceService.java @@ -23,20 +23,16 @@ import android.bluetooth.BluetoothAdapter; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; -import android.content.res.Configuration; -import android.graphics.Point; import android.net.ConnectivityManager; import android.util.Log; import android.os.IBinder; -import android.view.Display; -import android.view.WindowManager; import java.io.FileDescriptor; import java.io.PrintWriter; import java.util.List; /** * Service is started by the BootCompletedReceiver at the end of Android Boot process. - * Responsible for emitting final BOOT_COMPLETED message and continued configuration changes. + * Responsible for final configuration changes and emitting final BOOT_COMPLETED message. */ public class GceService extends Service { private static final String LOG_TAG = "GceService"; @@ -49,19 +45,13 @@ public class GceService extends Service { private static final int NOTIFICATION_ID = 1; private final JobExecutor mExecutor = new JobExecutor(); - private final EventReporter mEventReporter = new EventReporter(); + private final BootReporter mBootReporter = new BootReporter(); private final GceBroadcastReceiver mBroadcastReceiver = new GceBroadcastReceiver(); private final BluetoothChecker mBluetoothChecker = new BluetoothChecker(); private ConnectivityChecker mConnChecker; private GceWifiManager mWifiManager = null; private String mMostRecentAction = null; - private WindowManager mWindowManager; - - private int mPreviousRotation; - private Point mPreviousScreenBounds; - private int mPreviousDpi; - public GceService() {} @@ -70,22 +60,17 @@ public class GceService extends Service { public void onCreate() { try { super.onCreate(); - mEventReporter.reportBootStarted(); + mBootReporter.reportBootStarted(); registerBroadcastReceivers(); - mWindowManager = getSystemService(WindowManager.class); - mConnChecker = new ConnectivityChecker(this, mEventReporter); - mWifiManager = new GceWifiManager(this, mEventReporter, mExecutor); - - mPreviousRotation = getRotation(); - mPreviousScreenBounds = getScreenBounds(); - mPreviousDpi = getResources().getConfiguration().densityDpi; + mConnChecker = new ConnectivityChecker(this, mBootReporter); + mWifiManager = new GceWifiManager(this, mBootReporter, mExecutor); mExecutor.schedule(mWifiManager); mExecutor.schedule(mBluetoothChecker); mExecutor.schedule(mConnChecker); - mExecutor.schedule(mEventReporter, mBluetoothChecker.getEnabled()); + mExecutor.schedule(mBootReporter, mBluetoothChecker.getEnabled()); NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); @@ -120,42 +105,6 @@ public class GceService extends Service { this.registerReceiver(mBroadcastReceiver, filter); } - private Point getScreenBounds() { - Display display = mWindowManager.getDefaultDisplay(); - Point screenBounds = new Point(); - display.getRealSize(screenBounds); - return screenBounds; - } - - private int getRotation() { - return mWindowManager.getDefaultDisplay().getRotation(); - } - - @Override - public void onConfigurationChanged(Configuration config) { - super.onConfigurationChanged(config); - - int rotation = getRotation(); - Point screenBounds = getScreenBounds(); - int dpi = config.densityDpi; - // NOTE: We cannot rely on config.diff(previous config) here because - // diff shows CONFIG_SCREEN_SIZE changes when changing between 3-button - // and gesture navigation. We only care about the display bounds. - if (rotation == mPreviousRotation && - screenBounds.equals(mPreviousScreenBounds) && - dpi == mPreviousDpi) { - return; - } - - int width = screenBounds.x; - int height = screenBounds.y; - mEventReporter.reportScreenChanged(width, height, dpi, rotation); - - mPreviousRotation = rotation; - mPreviousScreenBounds = screenBounds; - mPreviousDpi = dpi; - } - /** StartService entry point. */ @@ -178,8 +127,6 @@ public class GceService extends Service { .setSmallIcon(android.R.drawable.ic_dialog_info) .setTimeoutAfter(10000) .build(); - // Start in the Foreground (and do not stop) so that this service - // continues running and reporting events without being killed. startForeground(NOTIFICATION_ID, notification); if (INTENT_ACTION_CONFIGURE.equals(mMostRecentAction)) { @@ -190,6 +137,8 @@ public class GceService extends Service { mExecutor.schedule(mBluetoothChecker); } + stopForeground(Service.STOP_FOREGROUND_DETACH); + /* If anything goes wrong, make sure we receive intent again. */ return Service.START_STICKY; } @@ -203,8 +152,8 @@ public class GceService extends Service { */ @Override protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { - pw.println("Virtual Device reporter:"); - List<String> messageList = mEventReporter.getMessageList(); + pw.println("Boot reporter:"); + List<String> messageList = mBootReporter.getMessageList(); for (int i = 0; i < messageList.size(); i++) { pw.println(" " + messageList.get(i)); } |