Skip to content

Commit d5714bb

Browse files
author
android-build-team Robot
committed
Snap for 5404204 from 732fa9cbee4a82864f74e322b189f6e7094546ac to ub-testdpc-qt-release
Change-Id: I0a2f94f4aabad6d4384379ba462a7b5119963196
2 parents 358d453 + 13d31da commit d5714bb

File tree

8 files changed

+62
-59
lines changed

8 files changed

+62
-59
lines changed

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ apply from: '../dist.gradle'
55
ext {
66
/* Version code for *next* release, bump *after* a release is created. */
77
// 1 or more digits
8-
versionMajor = 5
8+
versionMajor = 6
99
// exactly 1 digit
1010
versionMinor = 0
1111
// exactly 2 digits
12-
versionBuild = 04
12+
versionBuild = 00
1313
}
1414

1515
android {

app/src/main/AndroidManifest.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@
7272
<activity
7373
android:name=".FinalizeActivity"
7474
android:label="@string/app_name"
75-
android:theme="@style/SuwThemeGlifV3.Light">
75+
android:theme="@style/SuwThemeGlifV3.Light"
76+
android:permission="android.permission.BIND_DEVICE_ADMIN">
7677
<intent-filter>
7778
<action android:name="android.app.action.ADMIN_POLICY_COMPLIANCE" />
7879
<category android:name="android.intent.category.DEFAULT"/>
@@ -97,7 +98,8 @@
9798
</activity>
9899

99100
<activity android:name=".provision.DpcLoginActivity"
100-
android:exported="true">
101+
android:exported="true"
102+
android:permission="android.permission.BIND_DEVICE_ADMIN">
101103
<intent-filter>
102104
<action android:name="android.app.action.GET_PROVISIONING_MODE" />
103105
<category android:name="android.intent.category.DEFAULT"/>

app/src/main/java/com/afwsamples/testdpc/policy/PolicyManagementFragment.java

Lines changed: 21 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717
package com.afwsamples.testdpc.policy;
1818

1919
import static android.os.UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES;
20-
import static com.afwsamples.testdpc.common.ReflectionUtil.intConstant;
21-
import static com.afwsamples.testdpc.common.ReflectionUtil.invoke;
22-
import static com.afwsamples.testdpc.common.ReflectionUtil.stringConstant;
2320
import static com.afwsamples.testdpc.common.Util.isAtLeastQ;
2421
import static com.afwsamples.testdpc.common.preference.DpcPreferenceHelper.NO_CUSTOM_CONSTRIANT;
2522

@@ -99,7 +96,6 @@
9996
import com.afwsamples.testdpc.common.CertificateUtil;
10097
import com.afwsamples.testdpc.common.MediaDisplayFragment;
10198
import com.afwsamples.testdpc.common.PackageInstallationUtils;
102-
import com.afwsamples.testdpc.common.ReflectionUtil.ReflectionIsTemporaryException;
10399
import com.afwsamples.testdpc.common.UserArrayAdapter;
104100
import com.afwsamples.testdpc.common.Util;
105101
import com.afwsamples.testdpc.common.preference.CustomConstraint;
@@ -401,26 +397,22 @@ public class PolicyManagementFragment extends BaseSearchablePolicyPreferenceFrag
401397
private static final SparseIntArray PASSWORD_COMPLEXITY = new SparseIntArray(4);
402398
static {
403399
if (isAtLeastQ()) {
404-
try {
405-
final int[] complexityIds = new int[]{
406-
intConstant(DevicePolicyManager.class, "PASSWORD_COMPLEXITY_NONE"),
407-
intConstant(DevicePolicyManager.class, "PASSWORD_COMPLEXITY_LOW"),
408-
intConstant(DevicePolicyManager.class, "PASSWORD_COMPLEXITY_MEDIUM"),
409-
intConstant(DevicePolicyManager.class, "PASSWORD_COMPLEXITY_HIGH")
410-
};
411-
412-
// Strings to show for each password complexity setting.
413-
final int[] complexityNames = new int[]{
414-
R.string.password_complexity_none,
415-
R.string.password_complexity_low,
416-
R.string.password_complexity_medium,
417-
R.string.password_complexity_high
418-
};
419-
for (int i = 0; i < complexityIds.length; i++) {
420-
PASSWORD_COMPLEXITY.put(complexityIds[i], complexityNames[i]);
421-
}
422-
} catch (ReflectionIsTemporaryException e) {
423-
Log.e(TAG, "Cannot get password complexity constants.", e);
400+
final int[] complexityIds = new int[]{
401+
DevicePolicyManager.PASSWORD_COMPLEXITY_NONE,
402+
DevicePolicyManager.PASSWORD_COMPLEXITY_LOW,
403+
DevicePolicyManager.PASSWORD_COMPLEXITY_MEDIUM,
404+
DevicePolicyManager.PASSWORD_COMPLEXITY_HIGH
405+
};
406+
407+
// Strings to show for each password complexity setting.
408+
final int[] complexityNames = new int[]{
409+
R.string.password_complexity_none,
410+
R.string.password_complexity_low,
411+
R.string.password_complexity_medium,
412+
R.string.password_complexity_high
413+
};
414+
for (int i = 0; i < complexityIds.length; i++) {
415+
PASSWORD_COMPLEXITY.put(complexityIds[i], complexityNames[i]);
424416
}
425417
}
426418
}
@@ -1329,13 +1321,9 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
13291321
return true;
13301322
case SET_NEW_PASSWORD_WITH_COMPLEXITY:
13311323
Intent intent = new Intent(DevicePolicyManager.ACTION_SET_NEW_PASSWORD);
1332-
try {
1333-
intent.putExtra(
1334-
stringConstant(DevicePolicyManager.class, "EXTRA_PASSWORD_COMPLEXITY"),
1335-
Integer.parseInt((String) newValue));
1336-
} catch (ReflectionIsTemporaryException e) {
1337-
Log.e(TAG, "Cannot get EXTRA_PASSWORD_COMPLEXITY.", e);
1338-
}
1324+
intent.putExtra(
1325+
DevicePolicyManager.EXTRA_PASSWORD_COMPLEXITY,
1326+
Integer.parseInt((String) newValue));
13391327
startActivity(intent);
13401328
return true;
13411329
}
@@ -2145,13 +2133,8 @@ private void loadPasswordComplexity() {
21452133
return;
21462134
}
21472135

2148-
try {
2149-
int complexity =
2150-
(int) invoke(mDevicePolicyManager, "getPasswordComplexity");
2151-
passwordComplexityPreference.setSummary(PASSWORD_COMPLEXITY.get(complexity));
2152-
} catch (ReflectionIsTemporaryException e) {
2153-
Log.e(TAG, "Cannot get password complexity.", e);
2154-
}
2136+
int complexity = mDevicePolicyManager.getPasswordComplexity();
2137+
passwordComplexityPreference.setSummary(PASSWORD_COMPLEXITY.get(complexity));
21552138
}
21562139

21572140
@TargetApi(Build.VERSION_CODES.N)

app/src/main/java/com/afwsamples/testdpc/policy/locktask/SetLockTaskFeaturesFragment.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import com.afwsamples.testdpc.DeviceAdminReceiver;
3636
import com.afwsamples.testdpc.R;
3737
import com.afwsamples.testdpc.common.BaseSearchablePolicyPreferenceFragment;
38-
import com.afwsamples.testdpc.common.ReflectionUtil;
3938
import com.afwsamples.testdpc.common.preference.DpcSwitchPreference;
4039
import java.util.Map;
4140

app/src/main/java/com/afwsamples/testdpc/policy/networking/AlwaysOnVpnFragment.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,10 @@ protected void reloadSelectedPackage() {
120120
}
121121
}
122122

123-
@TargetApi(Build.VERSION_CODES.Q)
123+
@TargetApi(29)
124124
private void updateLockdown() {
125125
mLockdown.setChecked(mDpm.isAlwaysOnVpnLockdownEnabled(mWho));
126-
final List<String> exemptedPackages = mDpm.getAlwaysOnVpnLockdownWhitelist(mWho);
126+
final Set<String> exemptedPackages = mDpm.getAlwaysOnVpnLockdownWhitelist(mWho);
127127
mExemptedPackages.setText(
128128
exemptedPackages != null ? String.join(",", exemptedPackages) : "");
129129
}
@@ -147,15 +147,15 @@ protected void setSelectedPackage(String pkg) {
147147
}
148148
}
149149

150-
@TargetApi(Build.VERSION_CODES.Q)
150+
@TargetApi(29)
151151
private void setAlwaysOnVpnPackageQPlus(String pkg)
152152
throws PackageManager.NameNotFoundException {
153153
final boolean lockdown = mLockdown.isChecked();
154-
final List<String> packages = lockdown ?
154+
final Set<String> packages = lockdown ?
155155
Arrays.stream(mExemptedPackages.getText().toString().split(","))
156156
.map(String::trim)
157157
.filter(s -> !s.isEmpty())
158-
.collect(Collectors.toList())
158+
.collect(Collectors.toSet())
159159
: null;
160160
mDpm.setAlwaysOnVpnPackage(mWho, pkg, lockdown, packages);
161161
}

app/src/main/java/com/afwsamples/testdpc/policy/networking/PrivateDnsModeFragment.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,16 +105,20 @@ private void updateSelectedMode(int checkedId) {
105105
switch (checkedId) {
106106
case R.id.private_dns_mode_off:
107107
mSelectedMode = PRIVATE_DNS_MODE_OFF;
108+
mSetButton.setEnabled(false);
108109
break;
109110
case R.id.private_dns_mode_automatic:
110111
mSelectedMode = PRIVATE_DNS_MODE_OPPORTUNISTIC;
112+
mSetButton.setEnabled(true);
111113
break;
112114
case R.id.private_dns_mode_specific_host:
113115
mSelectedMode = PRIVATE_DNS_MODE_PROVIDER_HOSTNAME;
116+
mSetButton.setEnabled(true);
114117
break;
115118
case R.id.private_dns_mode_unknown:
116119
default:
117120
mSelectedMode = PRIVATE_DNS_MODE_UNKNOWN;
121+
mSetButton.setEnabled(false);
118122
break;
119123
}
120124
}

app/src/main/java/com/afwsamples/testdpc/policy/networking/SetPrivateDnsTask.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,27 @@ public SetPrivateDnsTask(
4747
@Override
4848
protected String doInBackground(Void... params) {
4949
try {
50-
mDpm.setGlobalPrivateDns(mComponent, mMode, mResolver);
51-
return null;
50+
final int result;
51+
switch (mMode) {
52+
case DevicePolicyManager.PRIVATE_DNS_MODE_PROVIDER_HOSTNAME:
53+
result = mDpm.setGlobalPrivateDnsModeSpecifiedHost(mComponent, mResolver);
54+
break;
55+
case DevicePolicyManager.PRIVATE_DNS_MODE_OPPORTUNISTIC:
56+
result = mDpm.setGlobalPrivateDnsModeOpportunistic(mComponent);
57+
break;
58+
default:
59+
throw new IllegalArgumentException("Invalid private dns mode: " + mMode);
60+
}
61+
switch (result) {
62+
case DevicePolicyManager.PRIVATE_DNS_SET_NO_ERROR:
63+
return null;
64+
case DevicePolicyManager.PRIVATE_DNS_SET_ERROR_FAILURE_SETTING:
65+
return "General failure to set the Private DNS mode";
66+
case DevicePolicyManager.PRIVATE_DNS_SET_ERROR_HOST_NOT_SERVING:
67+
return "Provided host doesn't serve DNS-over-TLS";
68+
default:
69+
return "Unexpected error setting private dns: " + result;
70+
}
5271
} catch (SecurityException | IllegalArgumentException e) {
5372
Log.w(TAG, "Failed to invoke, cause", e);
5473
return e.getMessage();

app/src/main/java/com/afwsamples/testdpc/provision/DpcLoginActivity.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818

1919
import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE;
2020
import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE;
21+
import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_MODE;
22+
import static android.app.admin.DevicePolicyManager.PROVISIONING_MODE_FULLY_MANAGED_DEVICE;
23+
import static android.app.admin.DevicePolicyManager.PROVISIONING_MODE_MANAGED_PROFILE;
2124

2225
import android.accounts.Account;
2326
import android.app.Activity;
@@ -38,13 +41,6 @@
3841
*/
3942
public class DpcLoginActivity extends Activity {
4043

41-
// TODO: clean up these hard coded constants once the new SDK is available.
42-
private static final String EXTRA_PROVISIONING_MODE =
43-
"android.app.extra.PROVISIONING_MODE";
44-
public static final int PROVISIONING_MODE_DO = 1;
45-
public static final int PROVISIONING_MODE_PO = 2;
46-
public static final int PROVISIONING_MODE_MANAGED_PROFILE_ON_FULLY_MANAGED_DEVICE = 3;
47-
4844
private static final String LOG_TAG = "DpcLoginActivity";
4945
private static final int ADD_ACCOUNT_REQUEST_CODE = 1;
5046

@@ -76,7 +72,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
7672

7773
private Intent createResultIntentFromData(Intent data) {
7874
final Intent resultIntent = new Intent();
79-
resultIntent.putExtra(EXTRA_PROVISIONING_MODE, PROVISIONING_MODE_PO);
75+
resultIntent.putExtra(EXTRA_PROVISIONING_MODE, PROVISIONING_MODE_MANAGED_PROFILE);
8076
if (data != null && data.hasExtra(EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE)) {
8177
final Account accountToMigrate = data.getParcelableExtra(
8278
EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE);
@@ -93,7 +89,7 @@ private void onNavigateNext(View nextButton) {
9389
RadioGroup dpcLoginOptions = findViewById(R.id.dpc_login_options);
9490
switch (dpcLoginOptions.getCheckedRadioButtonId()) {
9591
case R.id.dpc_login_do:
96-
intent.putExtra(EXTRA_PROVISIONING_MODE, PROVISIONING_MODE_DO);
92+
intent.putExtra(EXTRA_PROVISIONING_MODE, PROVISIONING_MODE_FULLY_MANAGED_DEVICE);
9793
finishWithIntent(intent);
9894
return;
9995
case R.id.dpc_login_po:

0 commit comments

Comments
 (0)