Merge "If the print spooler gets started onUserUnlock use less of a priority to have less impact on the system." into nyc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
59d1c9430a
@@ -129,7 +129,7 @@ public final class PrintManagerService extends SystemService {
|
||||
}
|
||||
resolvedAppId = resolveCallingAppEnforcingPermissions(appId);
|
||||
resolvedPackageName = resolveCallingPackageNameEnforcingSecurity(packageName);
|
||||
userState = getOrCreateUserStateLocked(resolvedUserId);
|
||||
userState = getOrCreateUserStateLocked(resolvedUserId, false);
|
||||
}
|
||||
final long identity = Binder.clearCallingIdentity();
|
||||
try {
|
||||
@@ -151,7 +151,7 @@ public final class PrintManagerService extends SystemService {
|
||||
return null;
|
||||
}
|
||||
resolvedAppId = resolveCallingAppEnforcingPermissions(appId);
|
||||
userState = getOrCreateUserStateLocked(resolvedUserId);
|
||||
userState = getOrCreateUserStateLocked(resolvedUserId, false);
|
||||
}
|
||||
final long identity = Binder.clearCallingIdentity();
|
||||
try {
|
||||
@@ -176,7 +176,7 @@ public final class PrintManagerService extends SystemService {
|
||||
return null;
|
||||
}
|
||||
resolvedAppId = resolveCallingAppEnforcingPermissions(appId);
|
||||
userState = getOrCreateUserStateLocked(resolvedUserId);
|
||||
userState = getOrCreateUserStateLocked(resolvedUserId, false);
|
||||
}
|
||||
final long identity = Binder.clearCallingIdentity();
|
||||
try {
|
||||
@@ -197,7 +197,7 @@ public final class PrintManagerService extends SystemService {
|
||||
if (resolveCallingProfileParentLocked(resolvedUserId) != getCurrentUserId()) {
|
||||
return null;
|
||||
}
|
||||
userState = getOrCreateUserStateLocked(resolvedUserId);
|
||||
userState = getOrCreateUserStateLocked(resolvedUserId, false);
|
||||
}
|
||||
final long identity = Binder.clearCallingIdentity();
|
||||
try {
|
||||
@@ -222,7 +222,7 @@ public final class PrintManagerService extends SystemService {
|
||||
return;
|
||||
}
|
||||
resolvedAppId = resolveCallingAppEnforcingPermissions(appId);
|
||||
userState = getOrCreateUserStateLocked(resolvedUserId);
|
||||
userState = getOrCreateUserStateLocked(resolvedUserId, false);
|
||||
}
|
||||
final long identity = Binder.clearCallingIdentity();
|
||||
try {
|
||||
@@ -247,7 +247,7 @@ public final class PrintManagerService extends SystemService {
|
||||
return;
|
||||
}
|
||||
resolvedAppId = resolveCallingAppEnforcingPermissions(appId);
|
||||
userState = getOrCreateUserStateLocked(resolvedUserId);
|
||||
userState = getOrCreateUserStateLocked(resolvedUserId, false);
|
||||
}
|
||||
final long identity = Binder.clearCallingIdentity();
|
||||
try {
|
||||
@@ -269,7 +269,7 @@ public final class PrintManagerService extends SystemService {
|
||||
if (resolveCallingProfileParentLocked(resolvedUserId) != getCurrentUserId()) {
|
||||
return null;
|
||||
}
|
||||
userState = getOrCreateUserStateLocked(resolvedUserId);
|
||||
userState = getOrCreateUserStateLocked(resolvedUserId, false);
|
||||
}
|
||||
final long identity = Binder.clearCallingIdentity();
|
||||
try {
|
||||
@@ -303,7 +303,7 @@ public final class PrintManagerService extends SystemService {
|
||||
if (resolveCallingProfileParentLocked(resolvedUserId) != getCurrentUserId()) {
|
||||
return;
|
||||
}
|
||||
userState = getOrCreateUserStateLocked(resolvedUserId);
|
||||
userState = getOrCreateUserStateLocked(resolvedUserId, false);
|
||||
}
|
||||
final long identity = Binder.clearCallingIdentity();
|
||||
try {
|
||||
@@ -325,7 +325,7 @@ public final class PrintManagerService extends SystemService {
|
||||
if (resolveCallingProfileParentLocked(resolvedUserId) != getCurrentUserId()) {
|
||||
return;
|
||||
}
|
||||
userState = getOrCreateUserStateLocked(resolvedUserId);
|
||||
userState = getOrCreateUserStateLocked(resolvedUserId, false);
|
||||
}
|
||||
final long identity = Binder.clearCallingIdentity();
|
||||
try {
|
||||
@@ -347,7 +347,7 @@ public final class PrintManagerService extends SystemService {
|
||||
if (resolveCallingProfileParentLocked(resolvedUserId) != getCurrentUserId()) {
|
||||
return;
|
||||
}
|
||||
userState = getOrCreateUserStateLocked(resolvedUserId);
|
||||
userState = getOrCreateUserStateLocked(resolvedUserId, false);
|
||||
}
|
||||
final long identity = Binder.clearCallingIdentity();
|
||||
try {
|
||||
@@ -373,7 +373,7 @@ public final class PrintManagerService extends SystemService {
|
||||
if (resolveCallingProfileParentLocked(resolvedUserId) != getCurrentUserId()) {
|
||||
return;
|
||||
}
|
||||
userState = getOrCreateUserStateLocked(resolvedUserId);
|
||||
userState = getOrCreateUserStateLocked(resolvedUserId, false);
|
||||
}
|
||||
final long identity = Binder.clearCallingIdentity();
|
||||
try {
|
||||
@@ -394,7 +394,7 @@ public final class PrintManagerService extends SystemService {
|
||||
if (resolveCallingProfileParentLocked(resolvedUserId) != getCurrentUserId()) {
|
||||
return;
|
||||
}
|
||||
userState = getOrCreateUserStateLocked(resolvedUserId);
|
||||
userState = getOrCreateUserStateLocked(resolvedUserId, false);
|
||||
}
|
||||
final long identity = Binder.clearCallingIdentity();
|
||||
try {
|
||||
@@ -415,7 +415,7 @@ public final class PrintManagerService extends SystemService {
|
||||
if (resolveCallingProfileParentLocked(resolvedUserId) != getCurrentUserId()) {
|
||||
return;
|
||||
}
|
||||
userState = getOrCreateUserStateLocked(resolvedUserId);
|
||||
userState = getOrCreateUserStateLocked(resolvedUserId, false);
|
||||
}
|
||||
final long identity = Binder.clearCallingIdentity();
|
||||
try {
|
||||
@@ -436,7 +436,7 @@ public final class PrintManagerService extends SystemService {
|
||||
if (resolveCallingProfileParentLocked(resolvedUserId) != getCurrentUserId()) {
|
||||
return;
|
||||
}
|
||||
userState = getOrCreateUserStateLocked(resolvedUserId);
|
||||
userState = getOrCreateUserStateLocked(resolvedUserId, false);
|
||||
}
|
||||
final long identity = Binder.clearCallingIdentity();
|
||||
try {
|
||||
@@ -457,7 +457,7 @@ public final class PrintManagerService extends SystemService {
|
||||
if (resolveCallingProfileParentLocked(resolvedUserId) != getCurrentUserId()) {
|
||||
return;
|
||||
}
|
||||
userState = getOrCreateUserStateLocked(resolvedUserId);
|
||||
userState = getOrCreateUserStateLocked(resolvedUserId, false);
|
||||
}
|
||||
final long identity = Binder.clearCallingIdentity();
|
||||
try {
|
||||
@@ -481,7 +481,7 @@ public final class PrintManagerService extends SystemService {
|
||||
return;
|
||||
}
|
||||
resolvedAppId = resolveCallingAppEnforcingPermissions(appId);
|
||||
userState = getOrCreateUserStateLocked(resolvedUserId);
|
||||
userState = getOrCreateUserStateLocked(resolvedUserId, false);
|
||||
}
|
||||
final long identity = Binder.clearCallingIdentity();
|
||||
try {
|
||||
@@ -503,7 +503,7 @@ public final class PrintManagerService extends SystemService {
|
||||
if (resolveCallingProfileParentLocked(resolvedUserId) != getCurrentUserId()) {
|
||||
return;
|
||||
}
|
||||
userState = getOrCreateUserStateLocked(resolvedUserId);
|
||||
userState = getOrCreateUserStateLocked(resolvedUserId, false);
|
||||
}
|
||||
final long identity = Binder.clearCallingIdentity();
|
||||
try {
|
||||
@@ -525,7 +525,7 @@ public final class PrintManagerService extends SystemService {
|
||||
if (resolveCallingProfileParentLocked(resolvedUserId) != getCurrentUserId()) {
|
||||
return;
|
||||
}
|
||||
userState = getOrCreateUserStateLocked(resolvedUserId);
|
||||
userState = getOrCreateUserStateLocked(resolvedUserId, false);
|
||||
}
|
||||
final long identity = Binder.clearCallingIdentity();
|
||||
try {
|
||||
@@ -547,7 +547,7 @@ public final class PrintManagerService extends SystemService {
|
||||
if (resolveCallingProfileParentLocked(resolvedUserId) != getCurrentUserId()) {
|
||||
return;
|
||||
}
|
||||
userState = getOrCreateUserStateLocked(resolvedUserId);
|
||||
userState = getOrCreateUserStateLocked(resolvedUserId, false);
|
||||
}
|
||||
final long identity = Binder.clearCallingIdentity();
|
||||
try {
|
||||
@@ -661,7 +661,7 @@ public final class PrintManagerService extends SystemService {
|
||||
@Override
|
||||
public void onPackageModified(String packageName) {
|
||||
if (!mUserManager.isUserUnlocked(getChangingUserId())) return;
|
||||
UserState userState = getOrCreateUserStateLocked(getChangingUserId());
|
||||
UserState userState = getOrCreateUserStateLocked(getChangingUserId(), false);
|
||||
|
||||
synchronized (mLock) {
|
||||
if (hadPrintService(userState, packageName)
|
||||
@@ -676,7 +676,7 @@ public final class PrintManagerService extends SystemService {
|
||||
@Override
|
||||
public void onPackageRemoved(String packageName, int uid) {
|
||||
if (!mUserManager.isUserUnlocked(getChangingUserId())) return;
|
||||
UserState userState = getOrCreateUserStateLocked(getChangingUserId());
|
||||
UserState userState = getOrCreateUserStateLocked(getChangingUserId(), false);
|
||||
|
||||
synchronized (mLock) {
|
||||
if (hadPrintService(userState, packageName)) {
|
||||
@@ -695,7 +695,8 @@ public final class PrintManagerService extends SystemService {
|
||||
// A background user/profile's print jobs are running but there is
|
||||
// no UI shown. Hence, if the packages of such a user change we need
|
||||
// to handle it as the change may affect ongoing print jobs.
|
||||
UserState userState = getOrCreateUserStateLocked(getChangingUserId());
|
||||
UserState userState = getOrCreateUserStateLocked(getChangingUserId(),
|
||||
false);
|
||||
boolean stoppedSomePackages = false;
|
||||
|
||||
List<PrintServiceInfo> enabledServices = userState
|
||||
@@ -730,7 +731,8 @@ public final class PrintManagerService extends SystemService {
|
||||
if (!mUserManager.isUserUnlocked(getChangingUserId())) return;
|
||||
synchronized (mLock) {
|
||||
if (hasPrintService(packageName)) {
|
||||
UserState userState = getOrCreateUserStateLocked(getChangingUserId());
|
||||
UserState userState = getOrCreateUserStateLocked(getChangingUserId(),
|
||||
false);
|
||||
userState.updateIfNeededLocked();
|
||||
}
|
||||
}
|
||||
@@ -742,7 +744,7 @@ public final class PrintManagerService extends SystemService {
|
||||
UserHandle.ALL, true);
|
||||
}
|
||||
|
||||
private UserState getOrCreateUserStateLocked(int userId) {
|
||||
private UserState getOrCreateUserStateLocked(int userId, boolean lowPriority) {
|
||||
if (!mUserManager.isUserUnlocked(userId)) {
|
||||
throw new IllegalStateException(
|
||||
"User " + userId + " must be unlocked for printing to be available");
|
||||
@@ -750,9 +752,14 @@ public final class PrintManagerService extends SystemService {
|
||||
|
||||
UserState userState = mUserStates.get(userId);
|
||||
if (userState == null) {
|
||||
userState = new UserState(mContext, userId, mLock);
|
||||
userState = new UserState(mContext, userId, mLock, lowPriority);
|
||||
mUserStates.put(userId, userState);
|
||||
}
|
||||
|
||||
if (!lowPriority) {
|
||||
userState.increasePriority();
|
||||
}
|
||||
|
||||
return userState;
|
||||
}
|
||||
|
||||
@@ -764,7 +771,7 @@ public final class PrintManagerService extends SystemService {
|
||||
public void run() {
|
||||
UserState userState;
|
||||
synchronized (mLock) {
|
||||
userState = getOrCreateUserStateLocked(userId);
|
||||
userState = getOrCreateUserStateLocked(userId, true);
|
||||
userState.updateIfNeededLocked();
|
||||
}
|
||||
// This is the first time we switch to this user after boot, so
|
||||
|
||||
@@ -98,6 +98,8 @@ final class RemotePrintSpooler {
|
||||
|
||||
private final PrintSpoolerCallbacks mCallbacks;
|
||||
|
||||
private boolean mIsLowPriority;
|
||||
|
||||
private IPrintSpooler mRemoteInstance;
|
||||
|
||||
private boolean mDestroyed;
|
||||
@@ -110,17 +112,42 @@ final class RemotePrintSpooler {
|
||||
public void onPrintJobStateChanged(PrintJobInfo printJob);
|
||||
}
|
||||
|
||||
public RemotePrintSpooler(Context context, int userId,
|
||||
public RemotePrintSpooler(Context context, int userId, boolean lowPriority,
|
||||
PrintSpoolerCallbacks callbacks) {
|
||||
mContext = context;
|
||||
mUserHandle = new UserHandle(userId);
|
||||
mCallbacks = callbacks;
|
||||
mIsLowPriority = lowPriority;
|
||||
mClient = new PrintSpoolerClient(this);
|
||||
mIntent = new Intent();
|
||||
mIntent.setComponent(new ComponentName(PrintManager.PRINT_SPOOLER_PACKAGE_NAME,
|
||||
PrintManager.PRINT_SPOOLER_PACKAGE_NAME + ".model.PrintSpoolerService"));
|
||||
}
|
||||
|
||||
public void increasePriority() {
|
||||
if (mIsLowPriority) {
|
||||
mIsLowPriority = false;
|
||||
|
||||
synchronized (mLock) {
|
||||
throwIfDestroyedLocked();
|
||||
|
||||
while (!mCanUnbind) {
|
||||
try {
|
||||
mLock.wait();
|
||||
} catch (InterruptedException e) {
|
||||
Slog.e(LOG_TAG, "Interrupted while waiting for operation to complete");
|
||||
}
|
||||
}
|
||||
|
||||
if (DEBUG) {
|
||||
Slog.i(LOG_TAG, "Unbinding as previous binding was low priority");
|
||||
}
|
||||
|
||||
unbindLocked();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public final List<PrintJobInfo> getPrintJobInfos(ComponentName componentName, int state,
|
||||
int appId) {
|
||||
throwIfCalledOnMainThread();
|
||||
@@ -579,11 +606,18 @@ final class RemotePrintSpooler {
|
||||
return;
|
||||
}
|
||||
if (DEBUG) {
|
||||
Slog.i(LOG_TAG, "[user: " + mUserHandle.getIdentifier() + "] bindLocked()");
|
||||
Slog.i(LOG_TAG, "[user: " + mUserHandle.getIdentifier() + "] bindLocked() " +
|
||||
(mIsLowPriority ? "low priority" : ""));
|
||||
}
|
||||
|
||||
mContext.bindServiceAsUser(mIntent, mServiceConnection,
|
||||
Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE, mUserHandle);
|
||||
int flags;
|
||||
if (mIsLowPriority) {
|
||||
flags = Context.BIND_AUTO_CREATE;
|
||||
} else {
|
||||
flags = Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE;
|
||||
}
|
||||
|
||||
mContext.bindServiceAsUser(mIntent, mServiceConnection, flags, mUserHandle);
|
||||
|
||||
final long startMillis = SystemClock.uptimeMillis();
|
||||
while (true) {
|
||||
|
||||
@@ -126,11 +126,11 @@ final class UserState implements PrintSpoolerCallbacks, PrintServiceCallbacks {
|
||||
|
||||
private boolean mDestroyed;
|
||||
|
||||
public UserState(Context context, int userId, Object lock) {
|
||||
public UserState(Context context, int userId, Object lock, boolean lowPriority) {
|
||||
mContext = context;
|
||||
mUserId = userId;
|
||||
mLock = lock;
|
||||
mSpooler = new RemotePrintSpooler(context, userId, this);
|
||||
mSpooler = new RemotePrintSpooler(context, userId, lowPriority, this);
|
||||
mHandler = new UserStateHandler(context.getMainLooper());
|
||||
|
||||
synchronized (mLock) {
|
||||
@@ -145,6 +145,10 @@ final class UserState implements PrintSpoolerCallbacks, PrintServiceCallbacks {
|
||||
}
|
||||
}
|
||||
|
||||
public void increasePriority() {
|
||||
mSpooler.increasePriority();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPrintJobQueued(PrintJobInfo printJob) {
|
||||
final RemotePrintService service;
|
||||
|
||||
Reference in New Issue
Block a user