summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDianne Hackborn <hackbod@google.com>2015-06-15 13:35:16 -0700
committerDianne Hackborn <hackbod@google.com>2015-06-15 17:05:04 -0700
commitb8004ff3d4be75f2d57ac757cd0b983eed4ae9c0 (patch)
treeffde2923733fa16f9f7cc808a6eb239778963861
parent285cb414eaab8543f6c857357849bfcf24b5974f (diff)
downloadframeworks_base-b8004ff3d4be75f2d57ac757cd0b983eed4ae9c0.zip
frameworks_base-b8004ff3d4be75f2d57ac757cd0b983eed4ae9c0.tar.gz
frameworks_base-b8004ff3d4be75f2d57ac757cd0b983eed4ae9c0.tar.bz2
Fix issue #21816660 (app standby), work on issue #20882522 (voice interact)
Issue #21816660: More app standby abuse prevention We now apply the same rules for deciding when an app has counted as active when the screen is on as when the screen is off; the only change this really means is that we don't immediately count foreground services as making an app active both screen on as well as the existing behavior for screen off. Also small fix to how we switch into voice interaction mode that guarantees we immediately switch to the screen on state. Issue #20882522 VI: voice interactor service not restarted This fixes some problems in the framework, allowing it to be correctly restarted (and rolled by to the default voice interactor if appropriate). There are still some problems in system UI that leave things broken in some cases. Also small fix to how we switch into voice interaction mode that guarantees we immediately switch to the screen on state. Change-Id: Ie4fd098a2f5174a2c94f36d30427fb2a9db3d835
-rw-r--r--services/core/java/com/android/server/am/ActivityManagerService.java41
-rw-r--r--services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java109
2 files changed, 89 insertions, 61 deletions
diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java
index 421ba86..acb36d1 100644
--- a/services/core/java/com/android/server/am/ActivityManagerService.java
+++ b/services/core/java/com/android/server/am/ActivityManagerService.java
@@ -31,7 +31,6 @@ import static com.android.server.am.ActivityManagerDebugConfig.*;
import static com.android.server.am.ActivityStackSupervisor.HOME_STACK_ID;
import static com.android.server.am.TaskRecord.INVALID_TASK_ID;
import static com.android.server.am.TaskRecord.LOCK_TASK_AUTH_DONT_LOCK;
-import static com.android.server.am.TaskRecord.LOCK_TASK_AUTH_LAUNCHABLE;
import static com.android.server.am.TaskRecord.LOCK_TASK_AUTH_LAUNCHABLE_PRIV;
import static com.android.server.am.TaskRecord.LOCK_TASK_AUTH_PINNABLE;
import static org.xmlpull.v1.XmlPullParser.END_DOCUMENT;
@@ -10338,11 +10337,12 @@ public final class ActivityManagerService extends ActivityManagerNative
void startRunningVoiceLocked(IVoiceInteractionSession session, int targetUid) {
mVoiceWakeLock.setWorkSource(new WorkSource(targetUid));
if (mRunningVoice == null || mRunningVoice.asBinder() != session.asBinder()) {
- if (mRunningVoice == null) {
+ boolean wasRunningVoice = mRunningVoice != null;
+ mRunningVoice = session;
+ if (!wasRunningVoice) {
mVoiceWakeLock.acquire();
updateSleepIfNeededLocked();
}
- mRunningVoice = session;
}
}
@@ -18595,29 +18595,24 @@ public final class ActivityManagerService extends ActivityManagerNative
return;
}
boolean isInteraction;
- if (!mSleeping) {
- isInteraction = app.curProcState <= ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND;
+ // To avoid some abuse patterns, we are going to be careful about what we consider
+ // to be an app interaction. Being the top activity doesn't count while the display
+ // is sleeping, nor do short foreground services.
+ if (app.curProcState <= ActivityManager.PROCESS_STATE_BOUND_FOREGROUND_SERVICE) {
+ isInteraction = true;
app.fgInteractionTime = 0;
- } else {
- // If the display is off, we are going to be more restrictive about what we consider
- // to be an app interaction. Being the top activity doesn't count, nor do generally
- // foreground services.
- if (app.curProcState <= ActivityManager.PROCESS_STATE_BOUND_FOREGROUND_SERVICE) {
- isInteraction = true;
- app.fgInteractionTime = 0;
- } else if (app.curProcState <= ActivityManager.PROCESS_STATE_TOP_SLEEPING) {
- final long now = SystemClock.elapsedRealtime();
- if (app.fgInteractionTime == 0) {
- app.fgInteractionTime = now;
- isInteraction = false;
- } else {
- isInteraction = now > app.fgInteractionTime + SERVICE_USAGE_INTERACTION_TIME;
- }
+ } else if (app.curProcState <= ActivityManager.PROCESS_STATE_TOP_SLEEPING) {
+ final long now = SystemClock.elapsedRealtime();
+ if (app.fgInteractionTime == 0) {
+ app.fgInteractionTime = now;
+ isInteraction = false;
} else {
- isInteraction = app.curProcState
- <= ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND;
- app.fgInteractionTime = 0;
+ isInteraction = now > app.fgInteractionTime + SERVICE_USAGE_INTERACTION_TIME;
}
+ } else {
+ isInteraction = app.curProcState
+ <= ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND;
+ app.fgInteractionTime = 0;
}
if (isInteraction && !app.reportedInteraction) {
String[] packages = app.getPackageList();
diff --git a/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java
index b0fca95..fafe44a 100644
--- a/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java
+++ b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java
@@ -853,7 +853,38 @@ public class VoiceInteractionManagerService extends SystemService {
PackageMonitor mPackageMonitor = new PackageMonitor() {
@Override
public boolean onHandleForceStop(Intent intent, String[] packages, int uid, boolean doit) {
- return super.onHandleForceStop(intent, packages, uid, doit);
+ if (DEBUG) Slog.d(TAG, "onHandleForceStop uid=" + uid + " doit=" + doit);
+
+ int userHandle = UserHandle.getUserId(uid);
+ ComponentName curInteractor = getCurInteractor(userHandle);
+ ComponentName curRecognizer = getCurRecognizer(userHandle);
+ boolean hit = false;
+ for (String pkg : packages) {
+ if (curInteractor != null && pkg.equals(curInteractor.getPackageName())) {
+ hit = true;
+ break;
+ } else if (curRecognizer != null
+ && pkg.equals(curRecognizer.getPackageName())) {
+ hit = true;
+ break;
+ }
+ }
+ if (hit && doit) {
+ // The user is force stopping our current interactor/recognizer.
+ // Clear the current settings and restore default state.
+ synchronized (VoiceInteractionManagerService.this) {
+ mSoundTriggerHelper.stopAllRecognitions();
+ if (mImpl != null) {
+ mImpl.shutdownLocked();
+ mImpl = null;
+ }
+ setCurInteractor(null, userHandle);
+ setCurRecognizer(null, userHandle);
+ initForUser(userHandle);
+ switchImplementationIfNeededLocked(true);
+ }
+ }
+ return hit;
}
@Override
@@ -865,51 +896,53 @@ public class VoiceInteractionManagerService extends SystemService {
int userHandle = getChangingUserId();
if (DEBUG) Slog.d(TAG, "onSomePackagesChanged user=" + userHandle);
- ComponentName curInteractor = getCurInteractor(userHandle);
- ComponentName curRecognizer = getCurRecognizer(userHandle);
- if (curRecognizer == null) {
- // Could a new recognizer appear when we don't have one pre-installed?
- if (anyPackagesAppearing()) {
- curRecognizer = findAvailRecognizer(null, userHandle);
- if (curRecognizer != null) {
- setCurRecognizer(curRecognizer, userHandle);
+ synchronized (VoiceInteractionManagerService.this) {
+ ComponentName curInteractor = getCurInteractor(userHandle);
+ ComponentName curRecognizer = getCurRecognizer(userHandle);
+ if (curRecognizer == null) {
+ // Could a new recognizer appear when we don't have one pre-installed?
+ if (anyPackagesAppearing()) {
+ curRecognizer = findAvailRecognizer(null, userHandle);
+ if (curRecognizer != null) {
+ setCurRecognizer(curRecognizer, userHandle);
+ }
}
- }
- return;
- }
-
- if (curInteractor != null) {
- int change = isPackageDisappearing(curInteractor.getPackageName());
- if (change == PACKAGE_PERMANENT_CHANGE) {
- // The currently set interactor is permanently gone; fall back to
- // the default config.
- setCurInteractor(null, userHandle);
- setCurRecognizer(null, userHandle);
- initForUser(userHandle);
return;
}
- change = isPackageAppearing(curInteractor.getPackageName());
- if (change != PACKAGE_UNCHANGED) {
- // If current interactor is now appearing, for any reason, then
- // restart our connection with it.
- if (mImpl != null && curInteractor.getPackageName().equals(
- mImpl.mComponent.getPackageName())) {
- switchImplementationIfNeededLocked(true);
+ if (curInteractor != null) {
+ int change = isPackageDisappearing(curInteractor.getPackageName());
+ if (change == PACKAGE_PERMANENT_CHANGE) {
+ // The currently set interactor is permanently gone; fall back to
+ // the default config.
+ setCurInteractor(null, userHandle);
+ setCurRecognizer(null, userHandle);
+ initForUser(userHandle);
+ return;
+ }
+
+ change = isPackageAppearing(curInteractor.getPackageName());
+ if (change != PACKAGE_UNCHANGED) {
+ // If current interactor is now appearing, for any reason, then
+ // restart our connection with it.
+ if (mImpl != null && curInteractor.getPackageName().equals(
+ mImpl.mComponent.getPackageName())) {
+ switchImplementationIfNeededLocked(true);
+ }
}
+ return;
}
- return;
- }
- // There is no interactor, so just deal with a simple recognizer.
- int change = isPackageDisappearing(curRecognizer.getPackageName());
- if (change == PACKAGE_PERMANENT_CHANGE
- || change == PACKAGE_TEMPORARY_CHANGE) {
- setCurRecognizer(findAvailRecognizer(null, userHandle), userHandle);
+ // There is no interactor, so just deal with a simple recognizer.
+ int change = isPackageDisappearing(curRecognizer.getPackageName());
+ if (change == PACKAGE_PERMANENT_CHANGE
+ || change == PACKAGE_TEMPORARY_CHANGE) {
+ setCurRecognizer(findAvailRecognizer(null, userHandle), userHandle);
- } else if (isPackageModified(curRecognizer.getPackageName())) {
- setCurRecognizer(findAvailRecognizer(curRecognizer.getPackageName(),
- userHandle), userHandle);
+ } else if (isPackageModified(curRecognizer.getPackageName())) {
+ setCurRecognizer(findAvailRecognizer(curRecognizer.getPackageName(),
+ userHandle), userHandle);
+ }
}
}
};