am 5925e191: Merge "Added a check if a custom activity can be started" into lmp-mr1-dev

automerge: 4a0d6f3

* commit '4a0d6f3e1196a545d56337e2934b273d7d0655a6':
  Added a check if a custom activity can be started
This commit is contained in:
Fyodor Kupolov
2014-11-20 21:06:20 +00:00
committed by android-build-merger

View File

@@ -23,6 +23,7 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.content.RestrictionEntry; import android.content.RestrictionEntry;
import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo; import android.content.pm.ApplicationInfo;
import android.content.pm.IPackageManager; import android.content.pm.IPackageManager;
import android.content.pm.PackageInfo; import android.content.pm.PackageInfo;
@@ -905,6 +906,7 @@ public class AppRestrictionsFragment extends SettingsPreferenceFragment implemen
} else if (restrictionsIntent != null) { } else if (restrictionsIntent != null) {
preference.setRestrictions(restrictions); preference.setRestrictions(restrictions);
if (invokeIfCustom && AppRestrictionsFragment.this.isResumed()) { if (invokeIfCustom && AppRestrictionsFragment.this.isResumed()) {
assertSafeToStartCustomActivity(restrictionsIntent);
int requestCode = generateCustomActivityRequestCode( int requestCode = generateCustomActivityRequestCode(
RestrictionsResultReceiver.this.preference); RestrictionsResultReceiver.this.preference);
AppRestrictionsFragment.this.startActivityForResult( AppRestrictionsFragment.this.startActivityForResult(
@@ -912,6 +914,25 @@ public class AppRestrictionsFragment extends SettingsPreferenceFragment implemen
} }
} }
} }
private void assertSafeToStartCustomActivity(Intent intent) {
// Activity can be started if it belongs to the same app
if (intent.getPackage() != null && intent.getPackage().equals(packageName)) {
return;
}
// Activity can be started if intent resolves to multiple activities
List<ResolveInfo> resolveInfos = AppRestrictionsFragment.this.mPackageManager
.queryIntentActivities(intent, 0 /* no flags */);
if (resolveInfos.size() != 1) {
return;
}
// Prevent potential privilege escalation
ActivityInfo activityInfo = resolveInfos.get(0).activityInfo;
if (!packageName.equals(activityInfo.packageName)) {
throw new SecurityException("Application " + packageName
+ " is not allowed to start activity " + intent);
};
}
} }
private void onRestrictionsReceived(AppRestrictionsPreference preference, String packageName, private void onRestrictionsReceived(AppRestrictionsPreference preference, String packageName,