Skip to content

Commit 79eeae4

Browse files
Amith YamasaniAndroid (Google) Code Review
authored andcommitted
Merge "Show the current user in power menu"
2 parents 6b36792 + 52f1d75 commit 79eeae4

File tree

4 files changed

+57
-11
lines changed

4 files changed

+57
-11
lines changed

core/java/android/app/ActivityManagerNative.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import android.content.pm.ApplicationInfo;
2626
import android.content.pm.ConfigurationInfo;
2727
import android.content.pm.IPackageDataObserver;
28+
import android.content.pm.UserInfo;
2829
import android.content.res.Configuration;
2930
import android.graphics.Bitmap;
3031
import android.net.Uri;
@@ -1494,7 +1495,15 @@ public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
14941495
reply.writeInt(result ? 1 : 0);
14951496
return true;
14961497
}
1497-
1498+
1499+
case GET_CURRENT_USER_TRANSACTION: {
1500+
data.enforceInterface(IActivityManager.descriptor);
1501+
UserInfo userInfo = getCurrentUser();
1502+
reply.writeNoException();
1503+
userInfo.writeToParcel(reply, 0);
1504+
return true;
1505+
}
1506+
14981507
case REMOVE_SUB_TASK_TRANSACTION:
14991508
{
15001509
data.enforceInterface(IActivityManager.descriptor);
@@ -3530,7 +3539,19 @@ public boolean switchUser(int userid) throws RemoteException {
35303539
data.recycle();
35313540
return result;
35323541
}
3533-
3542+
3543+
public UserInfo getCurrentUser() throws RemoteException {
3544+
Parcel data = Parcel.obtain();
3545+
Parcel reply = Parcel.obtain();
3546+
data.writeInterfaceToken(IActivityManager.descriptor);
3547+
mRemote.transact(SWITCH_USER_TRANSACTION, data, reply, 0);
3548+
reply.readException();
3549+
UserInfo userInfo = UserInfo.CREATOR.createFromParcel(reply);
3550+
reply.recycle();
3551+
data.recycle();
3552+
return userInfo;
3553+
}
3554+
35343555
public boolean removeSubTask(int taskId, int subTaskIndex) throws RemoteException {
35353556
Parcel data = Parcel.obtain();
35363557
Parcel reply = Parcel.obtain();

core/java/android/app/IActivityManager.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import android.content.pm.ConfigurationInfo;
2929
import android.content.pm.IPackageDataObserver;
3030
import android.content.pm.ProviderInfo;
31+
import android.content.pm.UserInfo;
3132
import android.content.res.Configuration;
3233
import android.graphics.Bitmap;
3334
import android.net.Uri;
@@ -318,10 +319,11 @@ public void setPackageScreenCompatMode(String packageName, int mode)
318319
public boolean getPackageAskScreenCompat(String packageName) throws RemoteException;
319320
public void setPackageAskScreenCompat(String packageName, boolean ask)
320321
throws RemoteException;
321-
322+
322323
// Multi-user APIs
323324
public boolean switchUser(int userid) throws RemoteException;
324-
325+
public UserInfo getCurrentUser() throws RemoteException;
326+
325327
public boolean removeSubTask(int taskId, int subTaskIndex) throws RemoteException;
326328

327329
public boolean removeTask(int taskId, int flags) throws RemoteException;
@@ -575,4 +577,5 @@ private WaitResult(Parcel source) {
575577
int REMOVE_CONTENT_PROVIDER_EXTERNAL_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+141;
576578
int GET_MY_MEMORY_STATE_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+142;
577579
int KILL_PROCESSES_BELOW_FOREGROUND_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+143;
580+
int GET_CURRENT_USER_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+144;
578581
}

policy/src/com/android/internal/policy/impl/GlobalActions.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,19 @@ public boolean showBeforeProvisioning() {
200200

201201
List<UserInfo> users = mContext.getPackageManager().getUsers();
202202
if (users.size() > 1) {
203+
UserInfo currentUser;
204+
try {
205+
currentUser = ActivityManagerNative.getDefault().getCurrentUser();
206+
} catch (RemoteException re) {
207+
currentUser = null;
208+
}
203209
for (final UserInfo user : users) {
210+
boolean isCurrentUser = currentUser == null
211+
? user.id == 0 : (currentUser.id == user.id);
204212
SinglePressAction switchToUser = new SinglePressAction(
205213
com.android.internal.R.drawable.ic_menu_cc,
206-
user.name != null ? user.name : "Primary") {
214+
(user.name != null ? user.name : "Primary")
215+
+ (isCurrentUser ? " \u2714" : "")) {
207216
public void onPress() {
208217
try {
209218
ActivityManagerNative.getDefault().switchUser(user.id);

services/java/com/android/server/am/ActivityManagerService.java

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1795,12 +1795,15 @@ final void updateLruProcessLocked(ProcessRecord app,
17951795
final ProcessRecord getProcessRecordLocked(
17961796
String processName, int uid) {
17971797
if (uid == Process.SYSTEM_UID) {
1798-
// The system gets to run in any process. If there are multiple
1799-
// processes with the same uid, just pick the first (this
1800-
// should never happen).
1801-
SparseArray<ProcessRecord> procs = mProcessNames.getMap().get(
1802-
processName);
1803-
return procs != null ? procs.valueAt(0) : null;
1798+
SparseArray<ProcessRecord> procs = mProcessNames.getMap().get(processName);
1799+
if (procs == null) return null;
1800+
int N = procs.size();
1801+
for (int i = 0; i < N; i++) {
1802+
if (UserId.isSameUser(procs.keyAt(i), uid)) {
1803+
return procs.valueAt(i);
1804+
}
1805+
}
1806+
return null;
18041807
}
18051808
// uid = applyUserId(uid);
18061809
ProcessRecord proc = mProcessNames.get(processName, uid);
@@ -14645,6 +14648,16 @@ public boolean switchUser(int userId) {
1464514648
return true;
1464614649
}
1464714650

14651+
@Override
14652+
public UserInfo getCurrentUser() throws RemoteException {
14653+
final int callingUid = Binder.getCallingUid();
14654+
if (callingUid != 0 && callingUid != Process.myUid()) {
14655+
Slog.e(TAG, "Trying to get user from unauthorized app");
14656+
return null;
14657+
}
14658+
return AppGlobals.getPackageManager().getUser(mCurrentUserId);
14659+
}
14660+
1464814661
private void onUserRemoved(Intent intent) {
1464914662
int extraUserId = intent.getIntExtra(Intent.EXTRA_USERID, -1);
1465014663
if (extraUserId < 1) return;

0 commit comments

Comments
 (0)