Merge "Modify testNetworkSetupWizardPermission let it fit Factory Ota use case." into qt-dev
This commit is contained in:
@@ -40,6 +40,7 @@ import android.platform.test.annotations.AppModeFull;
|
|||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.support.test.uiautomator.UiDevice;
|
import android.support.test.uiautomator.UiDevice;
|
||||||
import android.test.AndroidTestCase;
|
import android.test.AndroidTestCase;
|
||||||
|
import android.text.TextUtils;
|
||||||
import android.util.ArraySet;
|
import android.util.ArraySet;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
@@ -798,6 +799,8 @@ public class WifiManagerTest extends AndroidTestCase {
|
|||||||
* functionality. The permission is intended to be granted to only the device setup wizard.
|
* functionality. The permission is intended to be granted to only the device setup wizard.
|
||||||
*/
|
*/
|
||||||
public void testNetworkSetupWizardPermission() {
|
public void testNetworkSetupWizardPermission() {
|
||||||
|
final ArraySet<String> allowedPackages = new ArraySet();
|
||||||
|
|
||||||
final PackageManager pm = getContext().getPackageManager();
|
final PackageManager pm = getContext().getPackageManager();
|
||||||
|
|
||||||
final Intent intent = new Intent(Intent.ACTION_MAIN);
|
final Intent intent = new Intent(Intent.ACTION_MAIN);
|
||||||
@@ -805,16 +808,39 @@ public class WifiManagerTest extends AndroidTestCase {
|
|||||||
final ResolveInfo ri = pm.resolveActivity(intent, PackageManager.MATCH_DISABLED_COMPONENTS);
|
final ResolveInfo ri = pm.resolveActivity(intent, PackageManager.MATCH_DISABLED_COMPONENTS);
|
||||||
String validPkg = "";
|
String validPkg = "";
|
||||||
if (ri != null) {
|
if (ri != null) {
|
||||||
|
allowedPackages.add(ri.activityInfo.packageName);
|
||||||
validPkg = ri.activityInfo.packageName;
|
validPkg = ri.activityInfo.packageName;
|
||||||
}
|
}
|
||||||
|
|
||||||
final List<PackageInfo> holding = pm.getPackagesHoldingPermissions(new String[] {
|
final Intent preIntent = new Intent("com.android.setupwizard.OEM_PRE_SETUP");
|
||||||
android.Manifest.permission.NETWORK_SETUP_WIZARD
|
preIntent.addCategory(Intent.CATEGORY_DEFAULT);
|
||||||
|
final ResolveInfo preRi = pm
|
||||||
|
.resolveActivity(preIntent, PackageManager.MATCH_DISABLED_COMPONENTS);
|
||||||
|
String prePackageName = "";
|
||||||
|
if (null != preRi) {
|
||||||
|
prePackageName = preRi.activityInfo.packageName;
|
||||||
|
}
|
||||||
|
|
||||||
|
final Intent postIntent = new Intent("com.android.setupwizard.OEM_POST_SETUP");
|
||||||
|
postIntent.addCategory(Intent.CATEGORY_DEFAULT);
|
||||||
|
final ResolveInfo postRi = pm
|
||||||
|
.resolveActivity(postIntent, PackageManager.MATCH_DISABLED_COMPONENTS);
|
||||||
|
String postPackageName = "";
|
||||||
|
if (null != postRi) {
|
||||||
|
postPackageName = postRi.activityInfo.packageName;
|
||||||
|
}
|
||||||
|
if (!TextUtils.isEmpty(prePackageName) && !TextUtils.isEmpty(postPackageName)
|
||||||
|
&& prePackageName.equals(postPackageName)) {
|
||||||
|
allowedPackages.add(prePackageName);
|
||||||
|
}
|
||||||
|
|
||||||
|
final List<PackageInfo> holding = pm.getPackagesHoldingPermissions(new String[]{
|
||||||
|
android.Manifest.permission.NETWORK_SETUP_WIZARD
|
||||||
}, PackageManager.MATCH_UNINSTALLED_PACKAGES);
|
}, PackageManager.MATCH_UNINSTALLED_PACKAGES);
|
||||||
for (PackageInfo pi : holding) {
|
for (PackageInfo pi : holding) {
|
||||||
if (!Objects.equals(pi.packageName, validPkg)) {
|
if (!allowedPackages.contains(pi.packageName)) {
|
||||||
fail("The NETWORK_SETUP_WIZARD permission must not be held by " + pi.packageName
|
fail("The NETWORK_SETUP_WIZARD permission must not be held by " + pi.packageName
|
||||||
+ " and must be revoked for security reasons [" + validPkg +"]");
|
+ " and must be revoked for security reasons [" + validPkg + "]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user