summaryrefslogtreecommitdiffstats
path: root/services/print
diff options
context:
space:
mode:
authorSvetoslav <svetoslavganov@google.com>2014-08-21 14:22:53 -0700
committerSvetoslav <svetoslavganov@google.com>2014-08-26 18:19:13 -0700
commit86b1df234397802895771fe14cd8f2813fa43415 (patch)
tree62152dc66e9c90420240b17d851e0a202751a1b1 /services/print
parent105f6ceb0f123d365e1ff5837f0442b3e377a056 (diff)
downloadframeworks_base-86b1df234397802895771fe14cd8f2813fa43415.zip
frameworks_base-86b1df234397802895771fe14cd8f2813fa43415.tar.gz
frameworks_base-86b1df234397802895771fe14cd8f2813fa43415.tar.bz2
Print services setting changes not handled for managed profiles.
We keep per user settings for enabled print services which are observed to update the print manager service state. We were listening to all user changes but the handling code was not updating the state of the user whose settings changed, rather the current user. Added hidden APIs in content observer to know which user changed and now the print manager serivce handles content changes for the correct user. bug:16977006 Change-Id: I71ec88c8f3f38cb405844c13ab83695c2029eb79
Diffstat (limited to 'services/print')
-rw-r--r--services/print/java/com/android/server/print/PrintManagerService.java161
1 files changed, 58 insertions, 103 deletions
diff --git a/services/print/java/com/android/server/print/PrintManagerService.java b/services/print/java/com/android/server/print/PrintManagerService.java
index 6a56de0..ce91f3d 100644
--- a/services/print/java/com/android/server/print/PrintManagerService.java
+++ b/services/print/java/com/android/server/print/PrintManagerService.java
@@ -17,14 +17,14 @@
package com.android.server.print;
import android.Manifest;
+import android.app.ActivityManager;
+import android.app.ActivityManagerNative;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
-import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
-import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo;
@@ -81,10 +81,13 @@ public final class PrintManagerService extends SystemService {
}
@Override
- public void onBootPhase(int phase) {
- if (phase == PHASE_THIRD_PARTY_APPS_CAN_START) {
- mPrintManagerImpl.systemRunning();
- }
+ public void onStartUser(int userHandle) {
+ mPrintManagerImpl.handleUserStarted(userHandle);
+ }
+
+ @Override
+ public void onStopUser(int userHandle) {
+ mPrintManagerImpl.handleUserStopped(userHandle);
}
class PrintManagerImpl extends IPrintManager.Stub {
@@ -101,9 +104,7 @@ public final class PrintManagerService extends SystemService {
private final UserManager mUserManager;
- private final SparseArray<UserState> mUserStates = new SparseArray<UserState>();
-
- private int mCurrentUserId = UserHandle.USER_OWNER;
+ private final SparseArray<UserState> mUserStates = new SparseArray<>();
PrintManagerImpl(Context context) {
mContext = context;
@@ -112,22 +113,6 @@ public final class PrintManagerService extends SystemService {
registerBroadcastReceivers();
}
- public void systemRunning() {
- BackgroundThread.getHandler().post(new Runnable() {
- @Override
- public void run() {
- final UserState userState;
- synchronized (mLock) {
- userState = getCurrentUserStateLocked();
- }
- // This is the first time we switch to this user after boot, so
- // now is the time to remove obsolete print jobs since they
- // are from the last boot and no application would query them.
- userState.removeObsoletePrintJobs();
- }
- });
- }
-
@Override
public Bundle print(String printJobName, IPrintDocumentAdapter adapter,
PrintAttributes attributes, String packageName, int appId, int userId) {
@@ -137,7 +122,7 @@ public final class PrintManagerService extends SystemService {
final String resolvedPackageName;
synchronized (mLock) {
// Only the current group members can start new print jobs.
- if (resolveCallingProfileParentLocked(resolvedUserId) != mCurrentUserId) {
+ if (resolveCallingProfileParentLocked(resolvedUserId) != getCurrentUserId()) {
return null;
}
resolvedAppId = resolveCallingAppEnforcingPermissions(appId);
@@ -160,7 +145,7 @@ public final class PrintManagerService extends SystemService {
final UserState userState;
synchronized (mLock) {
// Only the current group members can query for state of print jobs.
- if (resolveCallingProfileParentLocked(resolvedUserId) != mCurrentUserId) {
+ if (resolveCallingProfileParentLocked(resolvedUserId) != getCurrentUserId()) {
return null;
}
resolvedAppId = resolveCallingAppEnforcingPermissions(appId);
@@ -181,7 +166,7 @@ public final class PrintManagerService extends SystemService {
final UserState userState;
synchronized (mLock) {
// Only the current group members can query for state of a print job.
- if (resolveCallingProfileParentLocked(resolvedUserId) != mCurrentUserId) {
+ if (resolveCallingProfileParentLocked(resolvedUserId) != getCurrentUserId()) {
return null;
}
resolvedAppId = resolveCallingAppEnforcingPermissions(appId);
@@ -202,7 +187,7 @@ public final class PrintManagerService extends SystemService {
final UserState userState;
synchronized (mLock) {
// Only the current group members can cancel a print job.
- if (resolveCallingProfileParentLocked(resolvedUserId) != mCurrentUserId) {
+ if (resolveCallingProfileParentLocked(resolvedUserId) != getCurrentUserId()) {
return;
}
resolvedAppId = resolveCallingAppEnforcingPermissions(appId);
@@ -223,7 +208,7 @@ public final class PrintManagerService extends SystemService {
final UserState userState;
synchronized (mLock) {
// Only the current group members can restart a print job.
- if (resolveCallingProfileParentLocked(resolvedUserId) != mCurrentUserId) {
+ if (resolveCallingProfileParentLocked(resolvedUserId) != getCurrentUserId()) {
return;
}
resolvedAppId = resolveCallingAppEnforcingPermissions(appId);
@@ -243,7 +228,7 @@ public final class PrintManagerService extends SystemService {
final UserState userState;
synchronized (mLock) {
// Only the current group members can get enabled services.
- if (resolveCallingProfileParentLocked(resolvedUserId) != mCurrentUserId) {
+ if (resolveCallingProfileParentLocked(resolvedUserId) != getCurrentUserId()) {
return null;
}
userState = getOrCreateUserStateLocked(resolvedUserId);
@@ -262,7 +247,7 @@ public final class PrintManagerService extends SystemService {
final UserState userState;
synchronized (mLock) {
// Only the current group members can get installed services.
- if (resolveCallingProfileParentLocked(resolvedUserId) != mCurrentUserId) {
+ if (resolveCallingProfileParentLocked(resolvedUserId) != getCurrentUserId()) {
return null;
}
userState = getOrCreateUserStateLocked(resolvedUserId);
@@ -282,7 +267,7 @@ public final class PrintManagerService extends SystemService {
final UserState userState;
synchronized (mLock) {
// Only the current group members can create a discovery session.
- if (resolveCallingProfileParentLocked(resolvedUserId) != mCurrentUserId) {
+ if (resolveCallingProfileParentLocked(resolvedUserId) != getCurrentUserId()) {
return;
}
userState = getOrCreateUserStateLocked(resolvedUserId);
@@ -302,7 +287,7 @@ public final class PrintManagerService extends SystemService {
final UserState userState;
synchronized (mLock) {
// Only the current group members can destroy a discovery session.
- if (resolveCallingProfileParentLocked(resolvedUserId) != mCurrentUserId) {
+ if (resolveCallingProfileParentLocked(resolvedUserId) != getCurrentUserId()) {
return;
}
userState = getOrCreateUserStateLocked(resolvedUserId);
@@ -322,7 +307,7 @@ public final class PrintManagerService extends SystemService {
final UserState userState;
synchronized (mLock) {
// Only the current group members can start discovery.
- if (resolveCallingProfileParentLocked(resolvedUserId) != mCurrentUserId) {
+ if (resolveCallingProfileParentLocked(resolvedUserId) != getCurrentUserId()) {
return;
}
userState = getOrCreateUserStateLocked(resolvedUserId);
@@ -341,7 +326,7 @@ public final class PrintManagerService extends SystemService {
final UserState userState;
synchronized (mLock) {
// Only the current group members can stop discovery.
- if (resolveCallingProfileParentLocked(resolvedUserId) != mCurrentUserId) {
+ if (resolveCallingProfileParentLocked(resolvedUserId) != getCurrentUserId()) {
return;
}
userState = getOrCreateUserStateLocked(resolvedUserId);
@@ -360,7 +345,7 @@ public final class PrintManagerService extends SystemService {
final UserState userState;
synchronized (mLock) {
// Only the current group members can validate printers.
- if (resolveCallingProfileParentLocked(resolvedUserId) != mCurrentUserId) {
+ if (resolveCallingProfileParentLocked(resolvedUserId) != getCurrentUserId()) {
return;
}
userState = getOrCreateUserStateLocked(resolvedUserId);
@@ -379,7 +364,7 @@ public final class PrintManagerService extends SystemService {
final UserState userState;
synchronized (mLock) {
// Only the current group members can start printer tracking.
- if (resolveCallingProfileParentLocked(resolvedUserId) != mCurrentUserId) {
+ if (resolveCallingProfileParentLocked(resolvedUserId) != getCurrentUserId()) {
return;
}
userState = getOrCreateUserStateLocked(resolvedUserId);
@@ -398,7 +383,7 @@ public final class PrintManagerService extends SystemService {
final UserState userState;
synchronized (mLock) {
// Only the current group members can stop printer tracking.
- if (resolveCallingProfileParentLocked(resolvedUserId) != mCurrentUserId) {
+ if (resolveCallingProfileParentLocked(resolvedUserId) != getCurrentUserId()) {
return;
}
userState = getOrCreateUserStateLocked(resolvedUserId);
@@ -419,7 +404,7 @@ public final class PrintManagerService extends SystemService {
final UserState userState;
synchronized (mLock) {
// Only the current group members can add a print job listener.
- if (resolveCallingProfileParentLocked(resolvedUserId) != mCurrentUserId) {
+ if (resolveCallingProfileParentLocked(resolvedUserId) != getCurrentUserId()) {
return;
}
resolvedAppId = resolveCallingAppEnforcingPermissions(appId);
@@ -440,7 +425,7 @@ public final class PrintManagerService extends SystemService {
final UserState userState;
synchronized (mLock) {
// Only the current group members can remove a print job listener.
- if (resolveCallingProfileParentLocked(resolvedUserId) != mCurrentUserId) {
+ if (resolveCallingProfileParentLocked(resolvedUserId) != getCurrentUserId()) {
return;
}
userState = getOrCreateUserStateLocked(resolvedUserId);
@@ -484,11 +469,19 @@ public final class PrintManagerService extends SystemService {
Settings.Secure.ENABLED_PRINT_SERVICES);
ContentObserver observer = new ContentObserver(BackgroundThread.getHandler()) {
@Override
- public void onChange(boolean selfChange, Uri uri) {
+ public void onChange(boolean selfChange, Uri uri, int userId) {
if (enabledPrintServicesUri.equals(uri)) {
synchronized (mLock) {
- UserState userState = getCurrentUserStateLocked();
- userState.updateIfNeededLocked();
+ if (userId != UserHandle.USER_ALL) {
+ UserState userState = getOrCreateUserStateLocked(userId);
+ userState.updateIfNeededLocked();
+ } else {
+ final int userCount = mUserStates.size();
+ for (int i = 0; i < userCount; i++) {
+ UserState userState = mUserStates.valueAt(i);
+ userState.updateIfNeededLocked();
+ }
+ }
}
}
}
@@ -622,27 +615,6 @@ public final class PrintManagerService extends SystemService {
// package changes
monitor.register(mContext, BackgroundThread.getHandler().getLooper(),
UserHandle.ALL, true);
-
- // user changes
- IntentFilter intentFilter = new IntentFilter();
- intentFilter.addAction(Intent.ACTION_USER_SWITCHED);
- intentFilter.addAction(Intent.ACTION_USER_REMOVED);
-
- mContext.registerReceiverAsUser(new BroadcastReceiver() {
- @Override
- public void onReceive(Context context, Intent intent) {
- String action = intent.getAction();
- if (Intent.ACTION_USER_SWITCHED.equals(action)) {
- switchUser(intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0));
- } else if (Intent.ACTION_USER_REMOVED.equals(action)) {
- removeUser(intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0));
- }
- }
- }, UserHandle.ALL, intentFilter, null, BackgroundThread.getHandler());
- }
-
- private UserState getCurrentUserStateLocked() {
- return getOrCreateUserStateLocked(mCurrentUserId);
}
private UserState getOrCreateUserStateLocked(int userId) {
@@ -654,20 +626,11 @@ public final class PrintManagerService extends SystemService {
return userState;
}
- private void switchUser(int newUserId) {
+ private void handleUserStarted(int userId) {
UserState userState;
synchronized (mLock) {
- if (newUserId == mCurrentUserId) {
- return;
- }
- mCurrentUserId = newUserId;
- userState = mUserStates.get(mCurrentUserId);
- if (userState == null) {
- userState = getCurrentUserStateLocked();
- userState.updateIfNeededLocked();
- } else {
- userState.updateIfNeededLocked();
- }
+ userState = getOrCreateUserStateLocked(userId);
+ userState.updateIfNeededLocked();
}
// This is the first time we switch to this user after boot, so
// now is the time to remove obsolete print jobs since they
@@ -675,18 +638,18 @@ public final class PrintManagerService extends SystemService {
userState.removeObsoletePrintJobs();
}
- private void removeUser(int removedUserId) {
+ private void handleUserStopped(int userId) {
synchronized (mLock) {
- UserState userState = mUserStates.get(removedUserId);
+ UserState userState = mUserStates.get(userId);
if (userState != null) {
userState.destroyLocked();
- mUserStates.remove(removedUserId);
+ mUserStates.remove(userId);
}
}
}
private int resolveCallingProfileParentLocked(int userId) {
- if (userId != mCurrentUserId) {
+ if (userId != getCurrentUserId()) {
final long identity = Binder.clearCallingIdentity();
try {
UserInfo parent = mUserManager.getProfileParent(userId);
@@ -723,28 +686,11 @@ public final class PrintManagerService extends SystemService {
}
private int resolveCallingUserEnforcingPermissions(int userId) {
- final int callingUid = Binder.getCallingUid();
- if (callingUid == 0 || callingUid == Process.SYSTEM_UID
- || callingUid == Process.SHELL_UID) {
- return userId;
- }
- final int callingUserId = UserHandle.getUserId(callingUid);
- if (callingUserId == userId) {
- return userId;
- }
- if (mContext.checkCallingPermission(Manifest.permission.INTERACT_ACROSS_USERS_FULL)
- != PackageManager.PERMISSION_GRANTED
- && mContext.checkCallingPermission(Manifest.permission.INTERACT_ACROSS_USERS)
- != PackageManager.PERMISSION_GRANTED) {
- if (userId == UserHandle.USER_CURRENT_OR_SELF) {
- return callingUserId;
- }
- throw new SecurityException("Call from user " + callingUserId + " as user "
- + userId + " without permission INTERACT_ACROSS_USERS or "
- + "INTERACT_ACROSS_USERS_FULL not allowed.");
- }
- if (userId == UserHandle.USER_CURRENT || userId == UserHandle.USER_CURRENT_OR_SELF) {
- return mCurrentUserId;
+ try {
+ return ActivityManagerNative.getDefault().handleIncomingUser(Binder.getCallingPid(),
+ Binder.getCallingUid(), userId, true, true, "", null);
+ } catch (RemoteException re) {
+ // Shouldn't happen, local.
}
return userId;
}
@@ -764,6 +710,15 @@ public final class PrintManagerService extends SystemService {
return null;
}
+ private int getCurrentUserId () {
+ final long identity = Binder.clearCallingIdentity();
+ try {
+ return ActivityManager.getCurrentUser();
+ } finally {
+ Binder.restoreCallingIdentity(identity);
+ }
+ }
+
private void showEnableInstalledPrintServiceNotification(ComponentName component,
String label, int userId) {
UserHandle userHandle = new UserHandle(userId);