Skip to content

Commit 8264408

Browse files
Amith YamasaniAndroid (Google) Code Review
authored andcommitted
Start the correct settings from the status bar.
Added a new method to Context: startActivityAsUser() requiring the INTERACT_ACROSS_USERS_FULL permission. Show the correct Recents list, based on current user. Added a getRecentTasksForUser() in ActivityManager. Hidden and requires the INTERACT_ACROSS_USERS_FULL permission. Change-Id: If5b56465efdd3ead36601a3b51ed4af157bbf35c
1 parent fb11ffa commit 8264408

File tree

12 files changed

+211
-29
lines changed

12 files changed

+211
-29
lines changed

core/java/android/app/ActivityManager.java

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,36 @@ public List<RecentTaskInfo> getRecentTasks(int maxNum, int flags)
529529
throws SecurityException {
530530
try {
531531
return ActivityManagerNative.getDefault().getRecentTasks(maxNum,
532-
flags);
532+
flags, UserId.myUserId());
533+
} catch (RemoteException e) {
534+
// System dead, we will be dead too soon!
535+
return null;
536+
}
537+
}
538+
539+
/**
540+
* Same as {@link #getRecentTasks(int, int)} but returns the recent tasks for a
541+
* specific user. It requires holding
542+
* the {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL} permission.
543+
* @param maxNum The maximum number of entries to return in the list. The
544+
* actual number returned may be smaller, depending on how many tasks the
545+
* user has started and the maximum number the system can remember.
546+
* @param flags Information about what to return. May be any combination
547+
* of {@link #RECENT_WITH_EXCLUDED} and {@link #RECENT_IGNORE_UNAVAILABLE}.
548+
*
549+
* @return Returns a list of RecentTaskInfo records describing each of
550+
* the recent tasks.
551+
*
552+
* @throws SecurityException Throws SecurityException if the caller does
553+
* not hold the {@link android.Manifest.permission#GET_TASKS} or the
554+
* {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL} permissions.
555+
* @hide
556+
*/
557+
public List<RecentTaskInfo> getRecentTasksForUser(int maxNum, int flags, int userId)
558+
throws SecurityException {
559+
try {
560+
return ActivityManagerNative.getDefault().getRecentTasks(maxNum,
561+
flags, userId);
533562
} catch (RemoteException e) {
534563
// System dead, we will be dead too soon!
535564
return null;

core/java/android/app/ActivityManagerNative.java

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import android.os.RemoteException;
4040
import android.os.ServiceManager;
4141
import android.os.StrictMode;
42+
import android.os.UserId;
4243
import android.text.TextUtils;
4344
import android.util.Log;
4445
import android.util.Singleton;
@@ -135,6 +136,31 @@ public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
135136
return true;
136137
}
137138

139+
case START_ACTIVITY_AS_USER_TRANSACTION:
140+
{
141+
data.enforceInterface(IActivityManager.descriptor);
142+
IBinder b = data.readStrongBinder();
143+
IApplicationThread app = ApplicationThreadNative.asInterface(b);
144+
Intent intent = Intent.CREATOR.createFromParcel(data);
145+
String resolvedType = data.readString();
146+
IBinder resultTo = data.readStrongBinder();
147+
String resultWho = data.readString();
148+
int requestCode = data.readInt();
149+
int startFlags = data.readInt();
150+
String profileFile = data.readString();
151+
ParcelFileDescriptor profileFd = data.readInt() != 0
152+
? data.readFileDescriptor() : null;
153+
Bundle options = data.readInt() != 0
154+
? Bundle.CREATOR.createFromParcel(data) : null;
155+
int userId = data.readInt();
156+
int result = startActivityAsUser(app, intent, resolvedType,
157+
resultTo, resultWho, requestCode, startFlags,
158+
profileFile, profileFd, options, userId);
159+
reply.writeNoException();
160+
reply.writeInt(result);
161+
return true;
162+
}
163+
138164
case START_ACTIVITY_AND_WAIT_TRANSACTION:
139165
{
140166
data.enforceInterface(IActivityManager.descriptor);
@@ -454,8 +480,9 @@ public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
454480
data.enforceInterface(IActivityManager.descriptor);
455481
int maxNum = data.readInt();
456482
int fl = data.readInt();
483+
int userId = data.readInt();
457484
List<ActivityManager.RecentTaskInfo> list = getRecentTasks(maxNum,
458-
fl);
485+
fl, userId);
459486
reply.writeNoException();
460487
reply.writeTypedList(list);
461488
return true;
@@ -1764,6 +1791,42 @@ public int startActivity(IApplicationThread caller, Intent intent,
17641791
data.recycle();
17651792
return result;
17661793
}
1794+
1795+
public int startActivityAsUser(IApplicationThread caller, Intent intent,
1796+
String resolvedType, IBinder resultTo, String resultWho, int requestCode,
1797+
int startFlags, String profileFile,
1798+
ParcelFileDescriptor profileFd, Bundle options, int userId) throws RemoteException {
1799+
Parcel data = Parcel.obtain();
1800+
Parcel reply = Parcel.obtain();
1801+
data.writeInterfaceToken(IActivityManager.descriptor);
1802+
data.writeStrongBinder(caller != null ? caller.asBinder() : null);
1803+
intent.writeToParcel(data, 0);
1804+
data.writeString(resolvedType);
1805+
data.writeStrongBinder(resultTo);
1806+
data.writeString(resultWho);
1807+
data.writeInt(requestCode);
1808+
data.writeInt(startFlags);
1809+
data.writeString(profileFile);
1810+
if (profileFd != null) {
1811+
data.writeInt(1);
1812+
profileFd.writeToParcel(data, Parcelable.PARCELABLE_WRITE_RETURN_VALUE);
1813+
} else {
1814+
data.writeInt(0);
1815+
}
1816+
if (options != null) {
1817+
data.writeInt(1);
1818+
options.writeToParcel(data, 0);
1819+
} else {
1820+
data.writeInt(0);
1821+
}
1822+
data.writeInt(userId);
1823+
mRemote.transact(START_ACTIVITY_AS_USER_TRANSACTION, data, reply, 0);
1824+
reply.readException();
1825+
int result = reply.readInt();
1826+
reply.recycle();
1827+
data.recycle();
1828+
return result;
1829+
}
17671830
public WaitResult startActivityAndWait(IApplicationThread caller, Intent intent,
17681831
String resolvedType, IBinder resultTo, String resultWho,
17691832
int requestCode, int startFlags, String profileFile,
@@ -2163,12 +2226,13 @@ public List getTasks(int maxNum, int flags,
21632226
return list;
21642227
}
21652228
public List<ActivityManager.RecentTaskInfo> getRecentTasks(int maxNum,
2166-
int flags) throws RemoteException {
2229+
int flags, int userId) throws RemoteException {
21672230
Parcel data = Parcel.obtain();
21682231
Parcel reply = Parcel.obtain();
21692232
data.writeInterfaceToken(IActivityManager.descriptor);
21702233
data.writeInt(maxNum);
21712234
data.writeInt(flags);
2235+
data.writeInt(userId);
21722236
mRemote.transact(GET_RECENT_TASKS_TRANSACTION, data, reply, 0);
21732237
reply.readException();
21742238
ArrayList<ActivityManager.RecentTaskInfo> list

core/java/android/app/ContextImpl.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,18 @@ public void startActivity(Intent intent) {
893893
startActivity(intent, null);
894894
}
895895

896+
/** @hide */
897+
@Override
898+
public void startActivityAsUser(Intent intent, int userId) {
899+
try {
900+
ActivityManagerNative.getDefault().startActivityAsUser(
901+
mMainThread.getApplicationThread(), intent,
902+
intent.resolveTypeIfNeeded(getContentResolver()),
903+
null, null, 0, Intent.FLAG_ACTIVITY_NEW_TASK, null, null, null, userId);
904+
} catch (RemoteException re) {
905+
}
906+
}
907+
896908
@Override
897909
public void startActivity(Intent intent, Bundle options) {
898910
if ((intent.getFlags()&Intent.FLAG_ACTIVITY_NEW_TASK) == 0) {

core/java/android/app/IActivityManager.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ public int startActivity(IApplicationThread caller,
5555
Intent intent, String resolvedType, IBinder resultTo, String resultWho,
5656
int requestCode, int flags, String profileFile,
5757
ParcelFileDescriptor profileFd, Bundle options) throws RemoteException;
58+
public int startActivityAsUser(IApplicationThread caller,
59+
Intent intent, String resolvedType, IBinder resultTo, String resultWho,
60+
int requestCode, int flags, String profileFile,
61+
ParcelFileDescriptor profileFd, Bundle options, int userId) throws RemoteException;
5862
public WaitResult startActivityAndWait(IApplicationThread caller,
5963
Intent intent, String resolvedType, IBinder resultTo, String resultWho,
6064
int requestCode, int flags, String profileFile,
@@ -102,7 +106,7 @@ public void activityStopped(IBinder token, Bundle state,
102106
public List getTasks(int maxNum, int flags,
103107
IThumbnailReceiver receiver) throws RemoteException;
104108
public List<ActivityManager.RecentTaskInfo> getRecentTasks(int maxNum,
105-
int flags) throws RemoteException;
109+
int flags, int userId) throws RemoteException;
106110
public ActivityManager.TaskThumbnails getTaskThumbnails(int taskId) throws RemoteException;
107111
public List getServices(int maxNum, int flags) throws RemoteException;
108112
public List<ActivityManager.ProcessErrorStateInfo> getProcessesInErrorState()
@@ -606,4 +610,5 @@ private WaitResult(Parcel source) {
606610
int GET_LAUNCHED_FROM_UID_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+149;
607611
int UNSTABLE_PROVIDER_DIED_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+150;
608612
int IS_INTENT_SENDER_AN_ACTIVITY_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+151;
613+
int START_ACTIVITY_AS_USER_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+152;
609614
}

core/java/android/content/Context.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,18 @@ public abstract SQLiteDatabase openOrCreateDatabase(String name,
850850
*/
851851
public abstract void startActivity(Intent intent);
852852

853+
/**
854+
* Same as {@link #startActivity(Intent)}, but for a specific user. It requires holding
855+
* the {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL} permission.
856+
* @param intent The description of the activity to start.
857+
* @param userId The user id of the user to start this activity for.
858+
* @throws ActivityNotFoundException
859+
* @hide
860+
*/
861+
public void startActivityAsUser(Intent intent, int userId) {
862+
throw new RuntimeException("Not implemented. Must override in a subclass.");
863+
}
864+
853865
/**
854866
* Launch a new activity. You will not receive any information about when
855867
* the activity exits.

core/java/android/content/ContextWrapper.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,12 @@ public void startActivity(Intent intent) {
276276
mBase.startActivity(intent);
277277
}
278278

279+
/** @hide */
280+
@Override
281+
public void startActivityAsUser(Intent intent, int userId) {
282+
mBase.startActivityAsUser(intent, userId);
283+
}
284+
279285
@Override
280286
public void startActivity(Intent intent, Bundle options) {
281287
mBase.startActivity(intent, options);

core/java/android/os/UserId.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,13 @@ public final class UserId {
2727
*/
2828
public static final int PER_USER_RANGE = 100000;
2929

30+
/** A user id to indicate all users on the device */
3031
public static final int USER_ALL = -1;
3132

33+
/** A user id to indicate the currently active user */
34+
public static final int USER_CURRENT = -2;
35+
36+
3237
/**
3338
* Enable multi-user related side effects. Set this to false if there are problems with single
3439
* user usecases.

packages/SystemUI/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
<uses-permission android:name="android.permission.STOP_APP_SWITCHES" />
4141
<uses-permission android:name="android.permission.SET_SCREEN_COMPATIBILITY" />
4242
<uses-permission android:name="android.permission.START_ANY_ACTIVITY" />
43+
<uses-permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL" />
4344

4445
<!-- WindowManager -->
4546
<uses-permission android:name="android.permission.INTERNAL_SYSTEM_WINDOW" />

packages/SystemUI/src/com/android/systemui/recent/RecentTasksLoader.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import android.os.AsyncTask;
3131
import android.os.Handler;
3232
import android.os.Process;
33+
import android.os.UserId;
3334
import android.util.Log;
3435

3536
import com.android.systemui.R;
@@ -243,7 +244,8 @@ protected Void doInBackground(Void... params) {
243244
mContext.getSystemService(Context.ACTIVITY_SERVICE);
244245

245246
final List<ActivityManager.RecentTaskInfo> recentTasks =
246-
am.getRecentTasks(MAX_TASKS, ActivityManager.RECENT_IGNORE_UNAVAILABLE);
247+
am.getRecentTasksForUser(MAX_TASKS,
248+
ActivityManager.RECENT_IGNORE_UNAVAILABLE, UserId.USER_CURRENT);
247249
int numTasks = recentTasks.size();
248250
ActivityInfo homeInfo = new Intent(Intent.ACTION_MAIN)
249251
.addCategory(Intent.CATEGORY_HOME).resolveActivityInfo(pm, 0);

packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import android.os.RemoteException;
4747
import android.os.ServiceManager;
4848
import android.os.SystemClock;
49+
import android.os.UserId;
4950
import android.provider.Settings;
5051
import android.util.DisplayMetrics;
5152
import android.util.Log;
@@ -2222,8 +2223,8 @@ public void onClick(View v) {
22222223
ActivityManagerNative.getDefault().dismissKeyguardOnNextActivity();
22232224
} catch (RemoteException e) {
22242225
}
2225-
v.getContext().startActivity(new Intent(Settings.ACTION_SETTINGS)
2226-
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
2226+
v.getContext().startActivityAsUser(new Intent(Settings.ACTION_SETTINGS)
2227+
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK), UserId.USER_CURRENT);
22272228
animateCollapse();
22282229
}
22292230
};

0 commit comments

Comments
 (0)