am 7beb70a9: am e5456645: am 840590dd: Merge "Fix issue #7311376: Add API to allow apps to know if they are..." into jb-mr1-dev

* commit '7beb70a94af2ce29b4184fd7927bba93d90cf878':
  Fix issue #7311376: Add API to allow apps to know if they are...
This commit is contained in:
Dianne Hackborn
2012-10-09 17:53:13 -07:00
committed by Android Git Automerger
7 changed files with 83 additions and 13 deletions

View File

@@ -1981,7 +1981,7 @@ public class ActivityManager {
*/
public boolean isUserRunning(int userid) {
try {
return ActivityManagerNative.getDefault().isUserRunning(userid);
return ActivityManagerNative.getDefault().isUserRunning(userid, false);
} catch (RemoteException e) {
return false;
}

View File

@@ -1608,7 +1608,8 @@ public abstract class ActivityManagerNative extends Binder implements IActivityM
case IS_USER_RUNNING_TRANSACTION: {
data.enforceInterface(IActivityManager.descriptor);
int userid = data.readInt();
boolean result = isUserRunning(userid);
boolean orStopping = data.readInt() != 0;
boolean result = isUserRunning(userid, orStopping);
reply.writeNoException();
reply.writeInt(result ? 1 : 0);
return true;
@@ -3865,11 +3866,12 @@ class ActivityManagerProxy implements IActivityManager
return userInfo;
}
public boolean isUserRunning(int userid) throws RemoteException {
public boolean isUserRunning(int userid, boolean orStopping) throws RemoteException {
Parcel data = Parcel.obtain();
Parcel reply = Parcel.obtain();
data.writeInterfaceToken(IActivityManager.descriptor);
data.writeInt(userid);
data.writeInt(orStopping ? 1 : 0);
mRemote.transact(IS_USER_RUNNING_TRANSACTION, data, reply, 0);
reply.readException();
boolean result = reply.readInt() != 0;

View File

@@ -326,7 +326,7 @@ public interface IActivityManager extends IInterface {
public boolean switchUser(int userid) throws RemoteException;
public int stopUser(int userid, IStopUserCallback callback) throws RemoteException;
public UserInfo getCurrentUser() throws RemoteException;
public boolean isUserRunning(int userid) throws RemoteException;
public boolean isUserRunning(int userid, boolean orStopping) throws RemoteException;
public int[] getRunningUserIds() throws RemoteException;
public boolean removeSubTask(int taskId, int subTaskIndex) throws RemoteException;

View File

@@ -16,6 +16,8 @@
package android.os;
import com.android.internal.R;
import android.app.ActivityManagerNative;
import android.content.Context;
import android.content.pm.UserInfo;
import android.graphics.Bitmap;
@@ -81,6 +83,39 @@ public class UserManager {
return false;
}
/**
* Return whether the given user is actively running. This means that
* the user is in the "started" state, not "stopped" -- it is currently
* allowed to run code through scheduled alarms, receiving broadcasts,
* etc. A started user may be either the current foreground user or a
* background user; the result here does not distinguish between the two.
* @param user The user to retrieve the running state for.
*/
public boolean isUserRunning(UserHandle user) {
try {
return ActivityManagerNative.getDefault().isUserRunning(
user.getIdentifier(), false);
} catch (RemoteException e) {
return false;
}
}
/**
* Return whether the given user is actively running <em>or</em> stopping.
* This is like {@link #isUserRunning(UserHandle)}, but will also return
* true if the user had been running but is in the process of being stopped
* (but is not yet fully stopped, and still running some code).
* @param user The user to retrieve the running state for.
*/
public boolean isUserRunningOrStopping(UserHandle user) {
try {
return ActivityManagerNative.getDefault().isUserRunning(
user.getIdentifier(), true);
} catch (RemoteException e) {
return false;
}
}
/**
* Returns the UserInfo object describing a specific user.
* Requires {@link android.Manifest.permission#MANAGE_USERS} permission.