Merge "Save preferred activity info with user id." into jb-mr1-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
7fdaa3976d
@@ -1106,7 +1106,17 @@ final class ApplicationPackageManager extends PackageManager {
|
|||||||
public void addPreferredActivity(IntentFilter filter,
|
public void addPreferredActivity(IntentFilter filter,
|
||||||
int match, ComponentName[] set, ComponentName activity) {
|
int match, ComponentName[] set, ComponentName activity) {
|
||||||
try {
|
try {
|
||||||
mPM.addPreferredActivity(filter, match, set, activity);
|
mPM.addPreferredActivity(filter, match, set, activity, UserHandle.myUserId());
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
// Should never happen!
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addPreferredActivity(IntentFilter filter, int match,
|
||||||
|
ComponentName[] set, ComponentName activity, int userId) {
|
||||||
|
try {
|
||||||
|
mPM.addPreferredActivity(filter, match, set, activity, userId);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
// Should never happen!
|
// Should never happen!
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -200,7 +200,7 @@ interface IPackageManager {
|
|||||||
List<PackageInfo> getPreferredPackages(int flags);
|
List<PackageInfo> getPreferredPackages(int flags);
|
||||||
|
|
||||||
void addPreferredActivity(in IntentFilter filter, int match,
|
void addPreferredActivity(in IntentFilter filter, int match,
|
||||||
in ComponentName[] set, in ComponentName activity);
|
in ComponentName[] set, in ComponentName activity, int userId);
|
||||||
|
|
||||||
void replacePreferredActivity(in IntentFilter filter, int match,
|
void replacePreferredActivity(in IntentFilter filter, int match,
|
||||||
in ComponentName[] set, in ComponentName activity);
|
in ComponentName[] set, in ComponentName activity);
|
||||||
|
|||||||
@@ -2459,6 +2459,17 @@ public abstract class PackageManager {
|
|||||||
public abstract void addPreferredActivity(IntentFilter filter, int match,
|
public abstract void addPreferredActivity(IntentFilter filter, int match,
|
||||||
ComponentName[] set, ComponentName activity);
|
ComponentName[] set, ComponentName activity);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Same as {@link #addPreferredActivity(IntentFilter, int,
|
||||||
|
ComponentName[], ComponentName)}, but with a specific userId to apply the preference
|
||||||
|
to.
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public void addPreferredActivity(IntentFilter filter, int match,
|
||||||
|
ComponentName[] set, ComponentName activity, int userId) {
|
||||||
|
throw new RuntimeException("Not implemented. Must override in a subclass.");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated This is a protected API that should not have been available
|
* @deprecated This is a protected API that should not have been available
|
||||||
* to third party applications. It is the platform's responsibility for
|
* to third party applications. It is the platform's responsibility for
|
||||||
|
|||||||
@@ -150,7 +150,8 @@ public class ResolverActivity extends AlertActivity implements AdapterView.OnIte
|
|||||||
|
|
||||||
resizeGrid();
|
resizeGrid();
|
||||||
} else if (count == 1) {
|
} else if (count == 1) {
|
||||||
startActivity(mAdapter.intentForPosition(0));
|
startActivityAsUser(mAdapter.intentForPosition(0),
|
||||||
|
UserHandle.getUserId(mLaunchedFromUid));
|
||||||
mPackageMonitor.unregister();
|
mPackageMonitor.unregister();
|
||||||
mRegistered = false;
|
mRegistered = false;
|
||||||
finish();
|
finish();
|
||||||
@@ -363,12 +364,12 @@ public class ResolverActivity extends AlertActivity implements AdapterView.OnIte
|
|||||||
if (r.match > bestMatch) bestMatch = r.match;
|
if (r.match > bestMatch) bestMatch = r.match;
|
||||||
}
|
}
|
||||||
getPackageManager().addPreferredActivity(filter, bestMatch, set,
|
getPackageManager().addPreferredActivity(filter, bestMatch, set,
|
||||||
intent.getComponent());
|
intent.getComponent(), UserHandle.getUserId(mLaunchedFromUid));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (intent != null) {
|
if (intent != null) {
|
||||||
startActivity(intent);
|
startActivityAsUser(intent, UserHandle.getUserId(mLaunchedFromUid));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -376,7 +377,7 @@ public class ResolverActivity extends AlertActivity implements AdapterView.OnIte
|
|||||||
Intent in = new Intent().setAction("android.settings.APPLICATION_DETAILS_SETTINGS")
|
Intent in = new Intent().setAction("android.settings.APPLICATION_DETAILS_SETTINGS")
|
||||||
.setData(Uri.fromParts("package", ri.activityInfo.packageName, null))
|
.setData(Uri.fromParts("package", ri.activityInfo.packageName, null))
|
||||||
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
|
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
|
||||||
startActivity(in);
|
startActivityAsUser(in, UserHandle.getUserId(mLaunchedFromUid));
|
||||||
}
|
}
|
||||||
|
|
||||||
private final class DisplayResolveInfo {
|
private final class DisplayResolveInfo {
|
||||||
|
|||||||
@@ -2422,6 +2422,9 @@ public class PackageManagerService extends IPackageManager.Stub {
|
|||||||
final int M = prefs.size();
|
final int M = prefs.size();
|
||||||
for (int i=0; i<M; i++) {
|
for (int i=0; i<M; i++) {
|
||||||
final PreferredActivity pa = prefs.get(i);
|
final PreferredActivity pa = prefs.get(i);
|
||||||
|
if (pa.mUserId != userId) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (pa.mPref.mMatch != match) {
|
if (pa.mPref.mMatch != match) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -7645,7 +7648,7 @@ public class PackageManagerService extends IPackageManager.Stub {
|
|||||||
mSettings.updateSharedUserPermsLPw(deletedPs, mGlobalGids);
|
mSettings.updateSharedUserPermsLPw(deletedPs, mGlobalGids);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
clearPackagePreferredActivitiesLPw(deletedPs.name);
|
clearPackagePreferredActivitiesLPw(deletedPs.name, UserHandle.USER_ALL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// can downgrade to reader
|
// can downgrade to reader
|
||||||
@@ -8112,26 +8115,28 @@ public class PackageManagerService extends IPackageManager.Stub {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void addPreferredActivity(IntentFilter filter, int match,
|
public void addPreferredActivity(IntentFilter filter, int match,
|
||||||
ComponentName[] set, ComponentName activity) {
|
ComponentName[] set, ComponentName activity, int userId) {
|
||||||
// writer
|
// writer
|
||||||
|
int callingUid = Binder.getCallingUid();
|
||||||
|
checkValidCaller(callingUid, userId);
|
||||||
synchronized (mPackages) {
|
synchronized (mPackages) {
|
||||||
if (mContext.checkCallingOrSelfPermission(
|
if (mContext.checkCallingOrSelfPermission(
|
||||||
android.Manifest.permission.SET_PREFERRED_APPLICATIONS)
|
android.Manifest.permission.SET_PREFERRED_APPLICATIONS)
|
||||||
!= PackageManager.PERMISSION_GRANTED) {
|
!= PackageManager.PERMISSION_GRANTED) {
|
||||||
if (getUidTargetSdkVersionLockedLPr(Binder.getCallingUid())
|
if (getUidTargetSdkVersionLockedLPr(callingUid)
|
||||||
< Build.VERSION_CODES.FROYO) {
|
< Build.VERSION_CODES.FROYO) {
|
||||||
Slog.w(TAG, "Ignoring addPreferredActivity() from uid "
|
Slog.w(TAG, "Ignoring addPreferredActivity() from uid "
|
||||||
+ Binder.getCallingUid());
|
+ callingUid);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mContext.enforceCallingOrSelfPermission(
|
mContext.enforceCallingOrSelfPermission(
|
||||||
android.Manifest.permission.SET_PREFERRED_APPLICATIONS, null);
|
android.Manifest.permission.SET_PREFERRED_APPLICATIONS, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
Slog.i(TAG, "Adding preferred activity " + activity + ":");
|
Slog.i(TAG, "Adding preferred activity " + activity + " for user " + userId + " :");
|
||||||
filter.dump(new LogPrinter(Log.INFO, TAG), " ");
|
filter.dump(new LogPrinter(Log.INFO, TAG), " ");
|
||||||
mSettings.mPreferredActivities.addFilter(
|
mSettings.mPreferredActivities.addFilter(
|
||||||
new PreferredActivity(filter, match, set, activity));
|
new PreferredActivity(filter, match, set, activity, userId));
|
||||||
scheduleWriteSettingsLocked();
|
scheduleWriteSettingsLocked();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8167,13 +8172,15 @@ public class PackageManagerService extends IPackageManager.Stub {
|
|||||||
mContext.enforceCallingOrSelfPermission(
|
mContext.enforceCallingOrSelfPermission(
|
||||||
android.Manifest.permission.SET_PREFERRED_APPLICATIONS, null);
|
android.Manifest.permission.SET_PREFERRED_APPLICATIONS, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final int callingUserId = UserHandle.getCallingUserId();
|
||||||
ArrayList<PreferredActivity> removed = null;
|
ArrayList<PreferredActivity> removed = null;
|
||||||
Iterator<PreferredActivity> it = mSettings.mPreferredActivities.filterIterator();
|
Iterator<PreferredActivity> it = mSettings.mPreferredActivities.filterIterator();
|
||||||
String action = filter.getAction(0);
|
String action = filter.getAction(0);
|
||||||
String category = filter.getCategory(0);
|
String category = filter.getCategory(0);
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
PreferredActivity pa = it.next();
|
PreferredActivity pa = it.next();
|
||||||
|
if (pa.mUserId != callingUserId) continue;
|
||||||
if (pa.getAction(0).equals(action) && pa.getCategory(0).equals(category)) {
|
if (pa.getAction(0).equals(action) && pa.getCategory(0).equals(category)) {
|
||||||
if (removed == null) {
|
if (removed == null) {
|
||||||
removed = new ArrayList<PreferredActivity>();
|
removed = new ArrayList<PreferredActivity>();
|
||||||
@@ -8189,7 +8196,7 @@ public class PackageManagerService extends IPackageManager.Stub {
|
|||||||
mSettings.mPreferredActivities.removeFilter(pa);
|
mSettings.mPreferredActivities.removeFilter(pa);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
addPreferredActivity(filter, match, set, activity);
|
addPreferredActivity(filter, match, set, activity, callingUserId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -8213,17 +8220,21 @@ public class PackageManagerService extends IPackageManager.Stub {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (clearPackagePreferredActivitiesLPw(packageName)) {
|
if (clearPackagePreferredActivitiesLPw(packageName, UserHandle.getCallingUserId())) {
|
||||||
scheduleWriteSettingsLocked();
|
scheduleWriteSettingsLocked();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean clearPackagePreferredActivitiesLPw(String packageName) {
|
/** This method takes a specific user id as well as UserHandle.USER_ALL. */
|
||||||
|
boolean clearPackagePreferredActivitiesLPw(String packageName, int userId) {
|
||||||
ArrayList<PreferredActivity> removed = null;
|
ArrayList<PreferredActivity> removed = null;
|
||||||
Iterator<PreferredActivity> it = mSettings.mPreferredActivities.filterIterator();
|
Iterator<PreferredActivity> it = mSettings.mPreferredActivities.filterIterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
PreferredActivity pa = it.next();
|
PreferredActivity pa = it.next();
|
||||||
|
if (userId != UserHandle.USER_ALL && pa.mUserId != userId) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (pa.mPref.mComponent.getPackageName().equals(packageName)) {
|
if (pa.mPref.mComponent.getPackageName().equals(packageName)) {
|
||||||
if (removed == null) {
|
if (removed == null) {
|
||||||
removed = new ArrayList<PreferredActivity>();
|
removed = new ArrayList<PreferredActivity>();
|
||||||
@@ -8245,11 +8256,15 @@ public class PackageManagerService extends IPackageManager.Stub {
|
|||||||
List<ComponentName> outActivities, String packageName) {
|
List<ComponentName> outActivities, String packageName) {
|
||||||
|
|
||||||
int num = 0;
|
int num = 0;
|
||||||
|
final int userId = UserHandle.getCallingUserId();
|
||||||
// reader
|
// reader
|
||||||
synchronized (mPackages) {
|
synchronized (mPackages) {
|
||||||
final Iterator<PreferredActivity> it = mSettings.mPreferredActivities.filterIterator();
|
final Iterator<PreferredActivity> it = mSettings.mPreferredActivities.filterIterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
final PreferredActivity pa = it.next();
|
final PreferredActivity pa = it.next();
|
||||||
|
if (pa.mUserId != userId) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (packageName == null
|
if (packageName == null
|
||||||
|| pa.mPref.mComponent.getPackageName().equals(packageName)) {
|
|| pa.mPref.mComponent.getPackageName().equals(packageName)) {
|
||||||
if (outFilters != null) {
|
if (outFilters != null) {
|
||||||
|
|||||||
@@ -33,22 +33,38 @@ class PreferredActivity extends IntentFilter implements PreferredComponent.Callb
|
|||||||
private static final String TAG = "PreferredActivity";
|
private static final String TAG = "PreferredActivity";
|
||||||
|
|
||||||
private static final boolean DEBUG_FILTERS = false;
|
private static final boolean DEBUG_FILTERS = false;
|
||||||
|
static final String ATTR_USER_ID = "userId";
|
||||||
|
|
||||||
final PreferredComponent mPref;
|
final PreferredComponent mPref;
|
||||||
|
final int mUserId;
|
||||||
|
|
||||||
PreferredActivity(IntentFilter filter, int match, ComponentName[] set, ComponentName activity) {
|
PreferredActivity(IntentFilter filter, int match, ComponentName[] set, ComponentName activity) {
|
||||||
|
this(filter, match, set, activity, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
PreferredActivity(IntentFilter filter, int match, ComponentName[] set, ComponentName activity,
|
||||||
|
int userId) {
|
||||||
super(filter);
|
super(filter);
|
||||||
|
mUserId = userId;
|
||||||
mPref = new PreferredComponent(this, match, set, activity);
|
mPref = new PreferredComponent(this, match, set, activity);
|
||||||
}
|
}
|
||||||
|
|
||||||
PreferredActivity(XmlPullParser parser) throws XmlPullParserException, IOException {
|
PreferredActivity(XmlPullParser parser) throws XmlPullParserException, IOException {
|
||||||
|
String userIdString = parser.getAttributeValue(null, ATTR_USER_ID);
|
||||||
|
if (userIdString != null && userIdString.length() > 0) {
|
||||||
|
mUserId = Integer.parseInt(userIdString);
|
||||||
|
} else {
|
||||||
|
// Old format with no userId specified - assume primary user
|
||||||
|
mUserId = 0;
|
||||||
|
}
|
||||||
mPref = new PreferredComponent(this, parser);
|
mPref = new PreferredComponent(this, parser);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeToXml(XmlSerializer serializer) throws IOException {
|
public void writeToXml(XmlSerializer serializer) throws IOException {
|
||||||
|
serializer.attribute(null, ATTR_USER_ID, Integer.toString(mUserId));
|
||||||
mPref.writeToXml(serializer);
|
mPref.writeToXml(serializer);
|
||||||
serializer.startTag(null, "filter");
|
serializer.startTag(null, "filter");
|
||||||
super.writeToXml(serializer);
|
super.writeToXml(serializer);
|
||||||
serializer.endTag(null, "filter");
|
serializer.endTag(null, "filter");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -506,6 +506,7 @@ public class UserManagerService extends IUserManager.Stub {
|
|||||||
Intent addedIntent = new Intent(Intent.ACTION_USER_ADDED);
|
Intent addedIntent = new Intent(Intent.ACTION_USER_ADDED);
|
||||||
addedIntent.putExtra(Intent.EXTRA_USER_HANDLE, userInfo.id);
|
addedIntent.putExtra(Intent.EXTRA_USER_HANDLE, userInfo.id);
|
||||||
mContext.sendBroadcast(addedIntent, android.Manifest.permission.MANAGE_USERS);
|
mContext.sendBroadcast(addedIntent, android.Manifest.permission.MANAGE_USERS);
|
||||||
|
mContext.sendBroadcastToUser(new Intent(Intent.ACTION_BOOT_COMPLETED), userInfo.id);
|
||||||
}
|
}
|
||||||
return userInfo;
|
return userInfo;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user