summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoey <joey@lineageos.org>2018-01-25 11:54:44 +0100
committerJoey <joey@lineageos.org>2018-01-25 12:08:19 +0100
commit6a9bb229476471c417f7fe1e8166a09d28e0b7ca (patch)
tree4920cab99f9b81c2e2d59eef950d40bb774e26f7
parent5f17c8acae846aec407cb9894b7a838b3217dd03 (diff)
downloadandroid_packages_apps_Recorder-6a9bb229476471c417f7fe1e8166a09d28e0b7ca.tar.gz
android_packages_apps_Recorder-6a9bb229476471c417f7fe1e8166a09d28e0b7ca.tar.bz2
android_packages_apps_Recorder-6a9bb229476471c417f7fe1e8166a09d28e0b7ca.zip
Recorder: use foreground service for screen recordstaging/lineage-15.1
Since we're targeting api27, we must use a foreground service if we don't want it to be murdered by android while we're recording Change-Id: I474a1c90c2f635a9c23575546924967db6dddaae Signed-off-by: Joey <joey@lineageos.org>
-rw-r--r--app/src/main/java/org/lineageos/recorder/screen/ScreencastService.java101
1 files changed, 60 insertions, 41 deletions
diff --git a/app/src/main/java/org/lineageos/recorder/screen/ScreencastService.java b/app/src/main/java/org/lineageos/recorder/screen/ScreencastService.java
index 112a995..fcc729b 100644
--- a/app/src/main/java/org/lineageos/recorder/screen/ScreencastService.java
+++ b/app/src/main/java/org/lineageos/recorder/screen/ScreencastService.java
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2013 The CyanogenMod Project
- * Copyright (C) 2017 The LineageOS Project
+ * Copyright (C) 2017-2018 The LineageOS Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -32,7 +32,6 @@ import android.os.IBinder;
import android.os.StatFs;
import android.os.SystemClock;
import android.support.v4.app.NotificationCompat;
-import android.text.TextUtils;
import android.text.format.DateUtils;
import android.util.Log;
import android.view.Display;
@@ -57,6 +56,10 @@ public class ScreencastService extends Service {
"org.lineageos.recorder.screen.ACTION_START_SCREENCAST";
public static final String ACTION_STOP_SCREENCAST =
"org.lineageos.recorder.screen.ACTION_STOP_SCREENCAST";
+ private static final String ACTION_SCAN =
+ "org.lineageos.recorder.server.display.SCAN";
+ private static final String ACTION_STOP_SCAN =
+ "org.lineageos.recorder.server.display.STOP_SCAN";
static final String SCREENCASTER_NAME = "hidden:screen-recording";
public static final int NOTIFICATION_ID = 61;
private static final String LOGTAG = "ScreencastService";
@@ -82,6 +85,31 @@ public class ScreencastService extends Service {
}
@Override
+ public int onStartCommand(Intent intent, int flags, int startId) {
+ if (intent == null) {
+ return START_NOT_STICKY;
+ }
+
+ final String action = intent.getAction();
+ if (action == null) {
+ return START_NOT_STICKY;
+ }
+
+ switch (action) {
+ case ACTION_SCAN:
+ case ACTION_STOP_SCAN:
+ return START_STICKY;
+ case ACTION_START_SCREENCAST:
+ return startScreencasting(intent);
+ case ACTION_STOP_SCREENCAST:
+ stopCasting();
+ return START_STICKY;
+ default:
+ return START_NOT_STICKY;
+ }
+ }
+
+ @Override
public void onCreate() {
super.onCreate();
@@ -107,6 +135,36 @@ public class ScreencastService extends Service {
super.onDestroy();
}
+ private int startScreencasting(Intent intent) {
+ try {
+ if (hasNoAvailableSpace()) {
+ Toast.makeText(this, R.string.screen_insufficient_storage,
+ Toast.LENGTH_LONG).show();
+ return START_NOT_STICKY;
+ }
+
+ mStartTime = SystemClock.elapsedRealtime();
+ registerScreencaster(intent.getBooleanExtra(EXTRA_WITHAUDIO, false));
+ mBuilder = createNotificationBuilder();
+ mTimer = new Timer();
+ mTimer.scheduleAtFixedRate(new TimerTask() {
+ @Override
+ public void run() {
+ updateNotification();
+ }
+ }, 100, 1000);
+
+ Utils.setStatus(getApplicationContext(), Utils.PREF_RECORDING_SCREEN);
+
+ startForeground(NOTIFICATION_ID, mBuilder.build());
+ return START_STICKY;
+ } catch (Exception e) {
+ Log.e(LOGTAG, e.getMessage());
+ }
+
+ return START_NOT_STICKY;
+ }
+
private boolean hasNoAvailableSpace() {
StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath());
long bytesAvailable = stat.getBlockSizeLong() * stat.getBlockCountLong();
@@ -177,45 +235,6 @@ public class ScreencastService extends Service {
}
}
- @Override
- public int onStartCommand(Intent intent, int flags, int startId) {
- if (intent == null) {
- return START_NOT_STICKY;
- }
- final String action = intent.getAction();
- if ("org.lineageos.recorder.server.display.SCAN".equals(action)
- || "org.lineageos.recorder.server.display.STOP_SCAN".equals(action)) {
- return START_STICKY;
- } else if (ACTION_START_SCREENCAST.equals(action)
- || "com.cyanogenmod.ACTION_START_SCREENCAST".equals(action)) {
- try {
- if (hasNoAvailableSpace()) {
- Toast.makeText(this, R.string.screen_insufficient_storage, Toast.LENGTH_LONG).show();
- return START_NOT_STICKY;
- }
- mStartTime = SystemClock.elapsedRealtime();
- registerScreencaster(intent.getBooleanExtra(EXTRA_WITHAUDIO, true));
- mBuilder = createNotificationBuilder();
-
- mTimer = new Timer();
- mTimer.scheduleAtFixedRate(new TimerTask() {
- @Override
- public void run() {
- updateNotification();
- }
- }, 100, 1000);
-
- Utils.setStatus(getApplicationContext(), Utils.PREF_RECORDING_SCREEN);
- return START_STICKY;
- } catch (Exception e) {
- Log.e(LOGTAG, e.getMessage());
- }
- } else if (TextUtils.equals(intent.getAction(), ACTION_STOP_SCREENCAST)) {
- stopCasting();
- }
- return START_NOT_STICKY;
- }
-
private NotificationCompat.Builder createNotificationBuilder() {
Intent intent = new Intent(this, RecorderActivity.class);
Intent stopRecordingIntent = new Intent(ACTION_STOP_SCREENCAST);