From e5b3977cfdfa46452cb99c4873a44f28274a809c Mon Sep 17 00:00:00 2001 From: Jonathan Scott Date: Thu, 30 May 2019 11:48:36 +0100 Subject: [PATCH 1/7] Migrate to Androidx Fixes: 134040941 Test: Confirmed build succeeds. Manually tested provisioning flow. Change-Id: I0e8c9615e2603bfef43e932e2d6fdfac53b0e832 --- app/build.gradle | 10 +++++----- app/src/main/AndroidManifest.xml | 2 +- .../afwsamples/testdpc/DeviceAdminReceiver.java | 2 +- .../afwsamples/testdpc/DeviceAdminService.java | 2 +- .../testdpc/PackageMonitorReceiver.java | 2 +- .../BaseSearchablePolicyPreferenceFragment.java | 16 ++++++++-------- .../testdpc/common/NotificationUtil.java | 7 +++---- .../testdpc/common/ProfileOrParentFragment.java | 5 ++--- .../common/StringArrayTypeInputAdapter.java | 2 +- .../java/com/afwsamples/testdpc/common/Util.java | 3 +-- .../keyvaluepair/KeyValuePairDialogFragment.java | 6 +++--- .../common/preference/CustomConstraint.java | 2 +- .../common/preference/DpcEditTextPreference.java | 10 +++++----- .../common/preference/DpcListPreference.java | 10 +++++----- .../testdpc/common/preference/DpcPreference.java | 10 +++++----- .../common/preference/DpcPreferenceBase.java | 2 +- .../common/preference/DpcPreferenceHelper.java | 9 ++++----- .../common/preference/DpcSwitchPreference.java | 10 +++++----- .../testdpc/comp/BindDeviceAdminFragment.java | 6 +++--- .../testdpc/comp/OnServiceConnectedListener.java | 2 +- .../testdpc/comp/ProfileOwnerService.java | 2 +- .../testdpc/feedback/AppStatesService.java | 7 +++---- .../testdpc/policy/BaseStringItemsFragment.java | 2 +- .../policy/CrossProfileCalendarFragment.java | 2 +- .../policy/ManageAffiliationIdsFragment.java | 2 +- .../testdpc/policy/OverrideApnFragment.java | 4 ++-- .../testdpc/policy/PolicyManagementFragment.java | 16 ++++++++-------- .../policy/UserRestrictionsDisplayFragment.java | 4 ++-- .../keyguard/LockScreenPolicyFragment.java | 7 +++---- .../keyguard/PasswordConstraintsFragment.java | 6 +++--- .../locktask/SetLockTaskFeaturesFragment.java | 2 +- .../resetpassword/ResetPasswordService.java | 2 +- .../SystemUpdatePolicyFragment.java | 2 +- .../testdpc/policy/utils/Attestation.java | 2 +- .../policy/utils/AttestationApplicationId.java | 2 +- .../testdpc/policy/utils/AuthorizationList.java | 2 +- .../ProfilePolicyManagementFragment.java | 4 ++-- .../delegation/DelegationScopesArrayAdapter.java | 2 +- .../testdpc/provision/CheckInState.java | 2 +- .../testdpc/search/PolicySearchFragment.java | 6 +++--- .../testdpc/search/SearchItemAdapter.java | 2 +- .../testdpc/search/XmlIndexableFragment.java | 2 +- .../PickTransferComponentFragment.java | 2 +- app/src/main/res/layout/basic_key_value_pair.xml | 2 +- app/src/main/res/layout/cross_profile_apps.xml | 4 ++-- app/src/main/res/layout/search_result.xml | 2 +- app/src/replica/AndroidManifest.xml | 2 +- 47 files changed, 103 insertions(+), 109 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index ceb8a06c..14edb482 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -126,11 +126,11 @@ private void stripTestOnlyForBuild(flavor, buildType) { dependencies { implementation 'androidx.enterprise:enterprise-feedback:1.0.0-alpha01' - implementation 'com.android.support:multidex:1.0.1' - implementation 'com.android.support:preference-v14:28.0.0-SNAPSHOT' - implementation 'com.android.support:recyclerview-v7:28.0.0-SNAPSHOT' - implementation 'com.android.support:support-v13:28.0.0-SNAPSHOT' - implementation 'com.android.support.constraint:constraint-layout:1.0.2' + implementation 'androidx.multidex:multidex:2.0.0' + implementation 'androidx.legacy:legacy-preference-v14:1.0.0' + implementation 'androidx.recyclerview:recyclerview:1.0.0' + implementation 'androidx.legacy:legacy-support-v13:1.0.0' + implementation 'androidx.constraintlayout:constraintlayout:1.1.3' implementation(name: 'setup-wizard-lib-platform-release', ext: 'aar') implementation 'org.bouncycastle:bcpkix-jdk15on:1.56' implementation 'org.bouncycastle:bcprov-jdk15on:1.56' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 3cba5493..498dfb0a 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -163,7 +163,7 @@ { @UiThread diff --git a/app/src/main/java/com/afwsamples/testdpc/comp/ProfileOwnerService.java b/app/src/main/java/com/afwsamples/testdpc/comp/ProfileOwnerService.java index a75eb6d7..a1357985 100644 --- a/app/src/main/java/com/afwsamples/testdpc/comp/ProfileOwnerService.java +++ b/app/src/main/java/com/afwsamples/testdpc/comp/ProfileOwnerService.java @@ -28,7 +28,7 @@ import android.os.IBinder; import android.os.RemoteException; import android.os.UserHandle; -import android.support.annotation.Nullable; +import androidx.annotation.Nullable; import android.util.Log; import com.afwsamples.testdpc.DeviceAdminReceiver; diff --git a/app/src/main/java/com/afwsamples/testdpc/feedback/AppStatesService.java b/app/src/main/java/com/afwsamples/testdpc/feedback/AppStatesService.java index c7f42835..9c7aa6fe 100644 --- a/app/src/main/java/com/afwsamples/testdpc/feedback/AppStatesService.java +++ b/app/src/main/java/com/afwsamples/testdpc/feedback/AppStatesService.java @@ -2,11 +2,10 @@ import android.app.NotificationChannel; import android.app.NotificationManager; -import android.os.Build; import android.os.Build.VERSION_CODES; -import android.support.v4.app.NotificationCompat; -import android.support.v4.app.NotificationManagerCompat; -import android.support.v7.preference.PreferenceManager; +import androidx.core.app.NotificationCompat; +import androidx.core.app.NotificationManagerCompat; +import androidx.preference.PreferenceManager; import android.util.Log; import androidx.enterprise.feedback.KeyedAppState; import androidx.enterprise.feedback.KeyedAppStatesService; diff --git a/app/src/main/java/com/afwsamples/testdpc/policy/BaseStringItemsFragment.java b/app/src/main/java/com/afwsamples/testdpc/policy/BaseStringItemsFragment.java index d69cde1b..98053b9a 100644 --- a/app/src/main/java/com/afwsamples/testdpc/policy/BaseStringItemsFragment.java +++ b/app/src/main/java/com/afwsamples/testdpc/policy/BaseStringItemsFragment.java @@ -21,7 +21,7 @@ import android.content.Context; import android.os.Build.VERSION_CODES; import android.os.Bundle; -import android.support.annotation.StringRes; +import androidx.annotation.StringRes; import android.text.TextUtils; import android.view.LayoutInflater; import android.view.View; diff --git a/app/src/main/java/com/afwsamples/testdpc/policy/CrossProfileCalendarFragment.java b/app/src/main/java/com/afwsamples/testdpc/policy/CrossProfileCalendarFragment.java index 80df44ad..b63c9ddd 100644 --- a/app/src/main/java/com/afwsamples/testdpc/policy/CrossProfileCalendarFragment.java +++ b/app/src/main/java/com/afwsamples/testdpc/policy/CrossProfileCalendarFragment.java @@ -23,7 +23,7 @@ import android.content.Context; import android.os.Build.VERSION_CODES; import android.os.Bundle; -import android.support.v7.preference.Preference; +import androidx.preference.Preference; import android.util.ArraySet; import android.view.View; import android.widget.EditText; diff --git a/app/src/main/java/com/afwsamples/testdpc/policy/ManageAffiliationIdsFragment.java b/app/src/main/java/com/afwsamples/testdpc/policy/ManageAffiliationIdsFragment.java index 4b66980a..81be335f 100644 --- a/app/src/main/java/com/afwsamples/testdpc/policy/ManageAffiliationIdsFragment.java +++ b/app/src/main/java/com/afwsamples/testdpc/policy/ManageAffiliationIdsFragment.java @@ -22,7 +22,7 @@ import android.content.Context; import android.os.Build.VERSION_CODES; import android.os.Bundle; -import android.support.v4.util.ArraySet; +import androidx.collection.ArraySet; import com.afwsamples.testdpc.DeviceAdminReceiver; import com.afwsamples.testdpc.R; import java.util.Collection; diff --git a/app/src/main/java/com/afwsamples/testdpc/policy/OverrideApnFragment.java b/app/src/main/java/com/afwsamples/testdpc/policy/OverrideApnFragment.java index 4970e055..922ec4b8 100644 --- a/app/src/main/java/com/afwsamples/testdpc/policy/OverrideApnFragment.java +++ b/app/src/main/java/com/afwsamples/testdpc/policy/OverrideApnFragment.java @@ -26,8 +26,8 @@ import android.net.Uri; import android.os.Build.VERSION_CODES; import android.os.Bundle; -import android.support.v14.preference.SwitchPreference; -import android.support.v7.preference.Preference; +import androidx.preference.SwitchPreference; +import androidx.preference.Preference; import android.telephony.data.ApnSetting; import android.text.TextUtils; import android.util.Log; diff --git a/app/src/main/java/com/afwsamples/testdpc/policy/PolicyManagementFragment.java b/app/src/main/java/com/afwsamples/testdpc/policy/PolicyManagementFragment.java index f47817d7..0c26436e 100644 --- a/app/src/main/java/com/afwsamples/testdpc/policy/PolicyManagementFragment.java +++ b/app/src/main/java/com/afwsamples/testdpc/policy/PolicyManagementFragment.java @@ -58,14 +58,14 @@ import android.security.KeyChain; import android.security.KeyChainAliasCallback; import android.service.notification.NotificationListenerService; -import android.support.annotation.RequiresApi; -import android.support.annotation.StringRes; -import android.support.v14.preference.SwitchPreference; -import android.support.v4.content.FileProvider; -import android.support.v7.preference.EditTextPreference; -import android.support.v7.preference.ListPreference; -import android.support.v7.preference.Preference; -import android.support.v7.preference.PreferenceManager; +import androidx.annotation.RequiresApi; +import androidx.annotation.StringRes; +import androidx.preference.SwitchPreference; +import androidx.core.content.FileProvider; +import androidx.preference.EditTextPreference; +import androidx.preference.ListPreference; +import androidx.preference.Preference; +import androidx.preference.PreferenceManager; import android.telephony.TelephonyManager; import android.text.InputType; import android.text.TextUtils; diff --git a/app/src/main/java/com/afwsamples/testdpc/policy/UserRestrictionsDisplayFragment.java b/app/src/main/java/com/afwsamples/testdpc/policy/UserRestrictionsDisplayFragment.java index 356cab4b..b4ac36e7 100644 --- a/app/src/main/java/com/afwsamples/testdpc/policy/UserRestrictionsDisplayFragment.java +++ b/app/src/main/java/com/afwsamples/testdpc/policy/UserRestrictionsDisplayFragment.java @@ -25,8 +25,8 @@ import android.os.Build.VERSION_CODES; import android.os.Bundle; import android.os.UserManager; -import android.support.v7.preference.Preference; -import android.support.v7.preference.PreferenceScreen; +import androidx.preference.Preference; +import androidx.preference.PreferenceScreen; import android.util.Log; import android.widget.Toast; import com.afwsamples.testdpc.DeviceAdminReceiver; diff --git a/app/src/main/java/com/afwsamples/testdpc/policy/keyguard/LockScreenPolicyFragment.java b/app/src/main/java/com/afwsamples/testdpc/policy/keyguard/LockScreenPolicyFragment.java index 946e3cda..25fb7568 100644 --- a/app/src/main/java/com/afwsamples/testdpc/policy/keyguard/LockScreenPolicyFragment.java +++ b/app/src/main/java/com/afwsamples/testdpc/policy/keyguard/LockScreenPolicyFragment.java @@ -23,12 +23,11 @@ import android.app.Fragment; import android.app.admin.DevicePolicyManager; import android.content.Context; -import android.os.Build; import android.os.Build.VERSION_CODES; import android.os.Bundle; -import android.support.v7.preference.EditTextPreference; -import android.support.v7.preference.Preference; -import android.support.v7.preference.TwoStatePreference; +import androidx.preference.EditTextPreference; +import androidx.preference.Preference; +import androidx.preference.TwoStatePreference; import android.util.ArrayMap; import android.widget.Toast; import com.afwsamples.testdpc.R; diff --git a/app/src/main/java/com/afwsamples/testdpc/policy/keyguard/PasswordConstraintsFragment.java b/app/src/main/java/com/afwsamples/testdpc/policy/keyguard/PasswordConstraintsFragment.java index 96ec8292..0ae636a3 100644 --- a/app/src/main/java/com/afwsamples/testdpc/policy/keyguard/PasswordConstraintsFragment.java +++ b/app/src/main/java/com/afwsamples/testdpc/policy/keyguard/PasswordConstraintsFragment.java @@ -30,9 +30,9 @@ import android.content.ComponentName; import android.content.Context; import android.os.Bundle; -import android.support.v7.preference.EditTextPreference; -import android.support.v7.preference.ListPreference; -import android.support.v7.preference.Preference; +import androidx.preference.EditTextPreference; +import androidx.preference.ListPreference; +import androidx.preference.Preference; import android.widget.Toast; import com.afwsamples.testdpc.DeviceAdminReceiver; diff --git a/app/src/main/java/com/afwsamples/testdpc/policy/locktask/SetLockTaskFeaturesFragment.java b/app/src/main/java/com/afwsamples/testdpc/policy/locktask/SetLockTaskFeaturesFragment.java index 005059dd..7ac6c258 100644 --- a/app/src/main/java/com/afwsamples/testdpc/policy/locktask/SetLockTaskFeaturesFragment.java +++ b/app/src/main/java/com/afwsamples/testdpc/policy/locktask/SetLockTaskFeaturesFragment.java @@ -29,7 +29,7 @@ import android.content.Context; import android.os.Build.VERSION_CODES; import android.os.Bundle; -import android.support.v7.preference.Preference; +import androidx.preference.Preference; import android.util.ArrayMap; import android.util.Log; import android.widget.Toast; diff --git a/app/src/main/java/com/afwsamples/testdpc/policy/resetpassword/ResetPasswordService.java b/app/src/main/java/com/afwsamples/testdpc/policy/resetpassword/ResetPasswordService.java index c6680198..97bf1909 100644 --- a/app/src/main/java/com/afwsamples/testdpc/policy/resetpassword/ResetPasswordService.java +++ b/app/src/main/java/com/afwsamples/testdpc/policy/resetpassword/ResetPasswordService.java @@ -32,7 +32,7 @@ import android.os.Build.VERSION_CODES; import android.os.IBinder; import android.os.UserManager; -import android.support.annotation.Nullable; +import androidx.annotation.Nullable; import android.util.Log; import com.afwsamples.testdpc.DeviceAdminReceiver; import com.afwsamples.testdpc.R; diff --git a/app/src/main/java/com/afwsamples/testdpc/policy/systemupdatepolicy/SystemUpdatePolicyFragment.java b/app/src/main/java/com/afwsamples/testdpc/policy/systemupdatepolicy/SystemUpdatePolicyFragment.java index f24be6e1..3660300e 100644 --- a/app/src/main/java/com/afwsamples/testdpc/policy/systemupdatepolicy/SystemUpdatePolicyFragment.java +++ b/app/src/main/java/com/afwsamples/testdpc/policy/systemupdatepolicy/SystemUpdatePolicyFragment.java @@ -26,7 +26,7 @@ import android.content.Context; import android.os.Build.VERSION_CODES; import android.os.Bundle; -import android.support.annotation.RequiresApi; +import androidx.annotation.RequiresApi; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; diff --git a/app/src/main/java/com/afwsamples/testdpc/policy/utils/Attestation.java b/app/src/main/java/com/afwsamples/testdpc/policy/utils/Attestation.java index f82aaf3c..e50ca4a6 100644 --- a/app/src/main/java/com/afwsamples/testdpc/policy/utils/Attestation.java +++ b/app/src/main/java/com/afwsamples/testdpc/policy/utils/Attestation.java @@ -17,7 +17,7 @@ package com.afwsamples.testdpc.policy.utils; import android.os.Build.VERSION_CODES; -import android.support.annotation.RequiresApi; +import androidx.annotation.RequiresApi; import com.google.common.base.CharMatcher; import com.google.common.io.BaseEncoding; import java.security.cert.CertificateParsingException; diff --git a/app/src/main/java/com/afwsamples/testdpc/policy/utils/AttestationApplicationId.java b/app/src/main/java/com/afwsamples/testdpc/policy/utils/AttestationApplicationId.java index 1935fed5..f41389ff 100644 --- a/app/src/main/java/com/afwsamples/testdpc/policy/utils/AttestationApplicationId.java +++ b/app/src/main/java/com/afwsamples/testdpc/policy/utils/AttestationApplicationId.java @@ -20,7 +20,7 @@ import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.Signature; import android.os.Build.VERSION_CODES; -import android.support.annotation.RequiresApi; +import androidx.annotation.RequiresApi; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.security.cert.CertificateParsingException; diff --git a/app/src/main/java/com/afwsamples/testdpc/policy/utils/AuthorizationList.java b/app/src/main/java/com/afwsamples/testdpc/policy/utils/AuthorizationList.java index 3ea70184..47dfce21 100644 --- a/app/src/main/java/com/afwsamples/testdpc/policy/utils/AuthorizationList.java +++ b/app/src/main/java/com/afwsamples/testdpc/policy/utils/AuthorizationList.java @@ -21,7 +21,7 @@ import android.os.Build.VERSION_CODES; import android.security.keystore.KeyProperties; -import android.support.annotation.RequiresApi; +import androidx.annotation.RequiresApi; import android.util.Log; import com.google.common.base.Joiner; import com.google.common.collect.ImmutableMap; diff --git a/app/src/main/java/com/afwsamples/testdpc/profilepolicy/ProfilePolicyManagementFragment.java b/app/src/main/java/com/afwsamples/testdpc/profilepolicy/ProfilePolicyManagementFragment.java index 8ab784d2..44f0e4f1 100644 --- a/app/src/main/java/com/afwsamples/testdpc/profilepolicy/ProfilePolicyManagementFragment.java +++ b/app/src/main/java/com/afwsamples/testdpc/profilepolicy/ProfilePolicyManagementFragment.java @@ -28,8 +28,8 @@ import android.graphics.Color; import android.os.Build.VERSION_CODES; import android.os.Bundle; -import android.support.v14.preference.SwitchPreference; -import android.support.v7.preference.Preference; +import androidx.preference.SwitchPreference; +import androidx.preference.Preference; import android.widget.Toast; import com.afwsamples.testdpc.DeviceAdminReceiver; import com.afwsamples.testdpc.R; diff --git a/app/src/main/java/com/afwsamples/testdpc/profilepolicy/delegation/DelegationScopesArrayAdapter.java b/app/src/main/java/com/afwsamples/testdpc/profilepolicy/delegation/DelegationScopesArrayAdapter.java index b1c4707f..adc2a241 100644 --- a/app/src/main/java/com/afwsamples/testdpc/profilepolicy/delegation/DelegationScopesArrayAdapter.java +++ b/app/src/main/java/com/afwsamples/testdpc/profilepolicy/delegation/DelegationScopesArrayAdapter.java @@ -2,7 +2,7 @@ import android.app.admin.DevicePolicyManager; import android.content.Context; -import android.support.annotation.NonNull; +import androidx.annotation.NonNull; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; diff --git a/app/src/main/java/com/afwsamples/testdpc/provision/CheckInState.java b/app/src/main/java/com/afwsamples/testdpc/provision/CheckInState.java index 7ab43d2d..631dcaf6 100644 --- a/app/src/main/java/com/afwsamples/testdpc/provision/CheckInState.java +++ b/app/src/main/java/com/afwsamples/testdpc/provision/CheckInState.java @@ -20,7 +20,7 @@ import android.content.Intent; import android.content.SharedPreferences; import android.preference.PreferenceManager; -import android.support.v4.content.LocalBroadcastManager; +import androidx.localbroadcastmanager.content.LocalBroadcastManager; public class CheckInState { private SharedPreferences mSharedPreferences; diff --git a/app/src/main/java/com/afwsamples/testdpc/search/PolicySearchFragment.java b/app/src/main/java/com/afwsamples/testdpc/search/PolicySearchFragment.java index a79a7831..e04e33f0 100644 --- a/app/src/main/java/com/afwsamples/testdpc/search/PolicySearchFragment.java +++ b/app/src/main/java/com/afwsamples/testdpc/search/PolicySearchFragment.java @@ -3,9 +3,9 @@ import android.app.Fragment; import android.os.AsyncTask; import android.os.Bundle; -import android.support.annotation.Nullable; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; +import androidx.annotation.Nullable; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; import android.util.Log; import android.view.LayoutInflater; import android.view.Menu; diff --git a/app/src/main/java/com/afwsamples/testdpc/search/SearchItemAdapter.java b/app/src/main/java/com/afwsamples/testdpc/search/SearchItemAdapter.java index befdf4c2..7d0271d6 100644 --- a/app/src/main/java/com/afwsamples/testdpc/search/SearchItemAdapter.java +++ b/app/src/main/java/com/afwsamples/testdpc/search/SearchItemAdapter.java @@ -1,6 +1,6 @@ package com.afwsamples.testdpc.search; -import android.support.v7.widget.RecyclerView; +import androidx.recyclerview.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; diff --git a/app/src/main/java/com/afwsamples/testdpc/search/XmlIndexableFragment.java b/app/src/main/java/com/afwsamples/testdpc/search/XmlIndexableFragment.java index 11d184a1..ca0dbc66 100644 --- a/app/src/main/java/com/afwsamples/testdpc/search/XmlIndexableFragment.java +++ b/app/src/main/java/com/afwsamples/testdpc/search/XmlIndexableFragment.java @@ -1,7 +1,7 @@ package com.afwsamples.testdpc.search; import android.content.Context; -import android.support.annotation.XmlRes; +import androidx.annotation.XmlRes; import android.text.TextUtils; import android.util.AttributeSet; import android.util.Log; diff --git a/app/src/main/java/com/afwsamples/testdpc/transferownership/PickTransferComponentFragment.java b/app/src/main/java/com/afwsamples/testdpc/transferownership/PickTransferComponentFragment.java index 155761b0..0425dfad 100644 --- a/app/src/main/java/com/afwsamples/testdpc/transferownership/PickTransferComponentFragment.java +++ b/app/src/main/java/com/afwsamples/testdpc/transferownership/PickTransferComponentFragment.java @@ -29,7 +29,7 @@ import android.os.Build.VERSION_CODES; import android.os.Bundle; import android.os.PersistableBundle; -import android.support.annotation.Nullable; +import androidx.annotation.Nullable; import android.util.Log; import android.view.LayoutInflater; import android.view.View; diff --git a/app/src/main/res/layout/basic_key_value_pair.xml b/app/src/main/res/layout/basic_key_value_pair.xml index 6e7870ba..b1b51053 100644 --- a/app/src/main/res/layout/basic_key_value_pair.xml +++ b/app/src/main/res/layout/basic_key_value_pair.xml @@ -123,7 +123,7 @@ android:orientation="vertical" android:visibility="gone"> - - - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/search_result.xml b/app/src/main/res/layout/search_result.xml index fa5d4e0b..bc56c01d 100644 --- a/app/src/main/res/layout/search_result.xml +++ b/app/src/main/res/layout/search_result.xml @@ -1,5 +1,5 @@ - Date: Thu, 30 May 2019 13:16:16 +0100 Subject: [PATCH 2/7] Wait for app to be in foreground before completing add account. Test: Manual Fixes: 124286399 Change-Id: If11239474b16857f40a313b58853e048a836b962 --- app/build.gradle | 4 ++ .../testdpc/AddAccountActivity.java | 65 +++++++++++++------ 2 files changed, 49 insertions(+), 20 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 14edb482..65180e3f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -125,6 +125,8 @@ private void stripTestOnlyForBuild(flavor, buildType) { } dependencies { + def lifecycle_version = "2.0.0" + implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version" implementation 'androidx.enterprise:enterprise-feedback:1.0.0-alpha01' implementation 'androidx.multidex:multidex:2.0.0' implementation 'androidx.legacy:legacy-preference-v14:1.0.0' @@ -135,4 +137,6 @@ dependencies { implementation 'org.bouncycastle:bcpkix-jdk15on:1.56' implementation 'org.bouncycastle:bcprov-jdk15on:1.56' implementation 'com.google.guava:guava:23.6-android' + + annotationProcessor "androidx.lifecycle:lifecycle-compiler:$lifecycle_version" } diff --git a/app/src/main/java/com/afwsamples/testdpc/AddAccountActivity.java b/app/src/main/java/com/afwsamples/testdpc/AddAccountActivity.java index 3c4b9023..d1df8be7 100644 --- a/app/src/main/java/com/afwsamples/testdpc/AddAccountActivity.java +++ b/app/src/main/java/com/afwsamples/testdpc/AddAccountActivity.java @@ -17,6 +17,7 @@ package com.afwsamples.testdpc; import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE; +import static androidx.lifecycle.Lifecycle.State.STARTED; import android.accounts.Account; import android.accounts.AccountManager; @@ -30,6 +31,7 @@ import android.content.Intent; import android.os.Build.VERSION_CODES; import android.os.Bundle; +import android.os.Handler; import android.os.UserManager; import android.text.TextUtils; import android.util.Log; @@ -37,6 +39,7 @@ import android.widget.EditText; import android.widget.RadioGroup; import android.widget.Toast; +import androidx.lifecycle.ProcessLifecycleOwner; import com.afwsamples.testdpc.common.Util; import com.android.setupwizardlib.GlifLayout; import java.io.IOException; @@ -50,6 +53,7 @@ public class AddAccountActivity extends Activity { private static final String TAG = "AddAccountActivity"; private static final String GOOGLE_ACCOUNT_TYPE = "com.google"; + private static final long WAIT_FOR_FOREGROUND_DELAY_MS = 10; public static final String EXTRA_NEXT_ACTIVITY_INTENT = "nextActivityIntent"; @@ -100,26 +104,47 @@ private void addAccount(String accountName) { } accountManager.addAccount(GOOGLE_ACCOUNT_TYPE, null, null, bundle, this, - accountManagerFuture -> { - try { - Bundle result = accountManagerFuture.getResult(); - String accountNameAdded = result.getString(AccountManager.KEY_ACCOUNT_NAME); - Log.d(TAG, "addAccount - accountNameAdded: " + accountNameAdded); - if (mNextActivityIntent != null) { - startActivity(mNextActivityIntent); - } - final Intent resultIntent = new Intent(); - resultIntent.putExtra(EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE, - new Account(accountNameAdded, GOOGLE_ACCOUNT_TYPE)); - setResult(RESULT_OK, resultIntent); - finish(); - } catch (OperationCanceledException | AuthenticatorException - | IOException e) { - Log.e(TAG, "addAccount - failed", e); - Toast.makeText(AddAccountActivity.this, - R.string.fail_to_add_account, Toast.LENGTH_LONG).show(); - } - }, null); + accountManagerFuture -> { + try { + Bundle result = accountManagerFuture.getResult(); + // This callback executes slightly before the app is back in the foreground + // so we need to wait. + waitForForeground(() -> accountCreated(result), 1000); + } catch (OperationCanceledException | AuthenticatorException | IOException e) { + Log.e(TAG, "addAccount - failed", e); + Toast.makeText(AddAccountActivity.this, + R.string.fail_to_add_account, Toast.LENGTH_LONG).show(); + } + }, null); + } + + private void waitForForeground(Runnable r, long timeout) { + if (timeout <= 0) { + throw new RuntimeException("Timed out waiting for foreground."); + } + boolean isAppInForeground = + ProcessLifecycleOwner.get().getLifecycle().getCurrentState().isAtLeast(STARTED); + if (isAppInForeground) { + r.run(); + } else { + new Handler().postDelayed( + () -> waitForForeground(r, timeout - WAIT_FOR_FOREGROUND_DELAY_MS), + WAIT_FOR_FOREGROUND_DELAY_MS); + } + } + + private void accountCreated(Bundle result) { + String accountNameAdded = result.getString(AccountManager.KEY_ACCOUNT_NAME); + Log.d(TAG, "addAccount - accountNameAdded: " + accountNameAdded); + if (mNextActivityIntent != null) { + startActivity(mNextActivityIntent); + } + final Intent resultIntent = new Intent(); + resultIntent.putExtra(EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE, + new Account(accountNameAdded, GOOGLE_ACCOUNT_TYPE)); + setResult(RESULT_OK, resultIntent); + finish(); + } private void disableUserRestrictions() { From 4bc685290debbc7ba78106668328fd8192f3c551 Mon Sep 17 00:00:00 2001 From: Jonathan Scott Date: Fri, 24 May 2019 13:43:03 +0100 Subject: [PATCH 3/7] Use SDK R03. Bug: 130713895 Change-Id: I4f849273c5298164b661bd2785f3d020d9a2ead7 (cherry picked from commit 8f9f6adf2c6380078c3f167e72015a32abb9f4ee) --- app/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index 65180e3f..a43a42f6 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -13,7 +13,7 @@ ext { } android { - compileSdkVersion 'android-29' + compileSdkVersion 'android-Q' buildToolsVersion "28.0.0" defaultConfig { From c158cb2f6f6e46bc47ba225506364cc007ac8191 Mon Sep 17 00:00:00 2001 From: Jonathan Scott Date: Mon, 3 Jun 2019 11:14:00 +0100 Subject: [PATCH 4/7] Bump version. Test: N/A Bug: 130713895 Change-Id: I5b7c124469579ea4e6b70b554821de662f8a4ff4 (cherry picked from commit cfe08118c6b282aede912396a1c48d209ff122fd) --- app/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index a43a42f6..771fc64b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,7 +9,7 @@ ext { // exactly 1 digit versionMinor = 1 // exactly 2 digits - versionBuild = 00 + versionBuild = 01 } android { From 969f58c72cedd284bd1b0cccd36d446aa5f01f91 Mon Sep 17 00:00:00 2001 From: Jonathan Scott Date: Mon, 3 Jun 2019 13:47:26 +0100 Subject: [PATCH 5/7] Fix Q version for test. Bug: 130713895 Change-Id: Ic019d38264f176a9bd42e8e12853de26a70dc04a (cherry picked from commit c889434aeefc4b939d90fde9e0153d95c3761b12) --- .../afwsamples/testdpc/DelegatedAdminReceiver.java | 4 +++- .../java/com/afwsamples/testdpc/common/Util.java | 4 +++- .../testdpc/policy/CrossProfileCalendarFragment.java | 6 ++++-- .../testdpc/policy/PolicyManagementFragment.java | 7 ++++--- .../policy/UserRestrictionsDisplayFragment.java | 3 ++- .../policy/networking/AlwaysOnVpnFragment.java | 12 +++++++----- .../policy/networking/PrivateDnsModeFragment.java | 4 +++- .../testdpc/policy/networking/SetPrivateDnsTask.java | 4 +++- 8 files changed, 29 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/com/afwsamples/testdpc/DelegatedAdminReceiver.java b/app/src/main/java/com/afwsamples/testdpc/DelegatedAdminReceiver.java index 3d71df37..abb8d184 100644 --- a/app/src/main/java/com/afwsamples/testdpc/DelegatedAdminReceiver.java +++ b/app/src/main/java/com/afwsamples/testdpc/DelegatedAdminReceiver.java @@ -16,13 +16,15 @@ package com.afwsamples.testdpc; +import static com.afwsamples.testdpc.common.Util.Q_VERSION_CODE; + import android.annotation.TargetApi; import android.content.Context; import android.content.Intent; import android.net.Uri; import android.os.Build.VERSION_CODES; -@TargetApi(VERSION_CODES.Q) +@TargetApi(Q_VERSION_CODE) public class DelegatedAdminReceiver extends android.app.admin.DelegatedAdminReceiver { @Override diff --git a/app/src/main/java/com/afwsamples/testdpc/common/Util.java b/app/src/main/java/com/afwsamples/testdpc/common/Util.java index 241dcdbe..b3f65805 100644 --- a/app/src/main/java/com/afwsamples/testdpc/common/Util.java +++ b/app/src/main/java/com/afwsamples/testdpc/common/Util.java @@ -61,13 +61,15 @@ public class Util { private static final boolean IS_RUNNING_Q = VERSION.CODENAME.length() == 1 && VERSION.CODENAME.charAt(0) == 'Q'; + public static final int Q_VERSION_CODE = 29; + /** * A replacement for {@link VERSION.SDK_INT} that is compatible with pre-release SDKs * *

This will be set to the version SDK, or {@link VERSION_CODES.CUR_DEVELOPMENT} if the SDK * int is not yet assigned. **/ - public static final int SDK_INT = IS_RUNNING_Q ? VERSION_CODES.Q : VERSION.SDK_INT; + public static final int SDK_INT = IS_RUNNING_Q ? Q_VERSION_CODE : VERSION.SDK_INT; /** * Format a friendly datetime for the current locale according to device policy documentation. diff --git a/app/src/main/java/com/afwsamples/testdpc/policy/CrossProfileCalendarFragment.java b/app/src/main/java/com/afwsamples/testdpc/policy/CrossProfileCalendarFragment.java index b63c9ddd..c82e6ad1 100644 --- a/app/src/main/java/com/afwsamples/testdpc/policy/CrossProfileCalendarFragment.java +++ b/app/src/main/java/com/afwsamples/testdpc/policy/CrossProfileCalendarFragment.java @@ -16,6 +16,8 @@ package com.afwsamples.testdpc.policy; +import static com.afwsamples.testdpc.common.Util.Q_VERSION_CODE; + import android.annotation.TargetApi; import android.app.AlertDialog.Builder; import android.app.admin.DevicePolicyManager; @@ -36,7 +38,7 @@ import java.util.Collections; import java.util.Set; -@TargetApi(VERSION_CODES.Q) +@TargetApi(Q_VERSION_CODE) public class CrossProfileCalendarFragment extends BaseSearchablePolicyPreferenceFragment implements Preference.OnPreferenceClickListener, Preference.OnPreferenceChangeListener { @@ -102,7 +104,7 @@ public boolean onPreferenceChange(Preference preference, Object newValue) { return false; } - @TargetApi(VERSION_CODES.Q) + @TargetApi(Q_VERSION_CODE) private void reloadAllowAllPackagesUi() { final Set packages = mDevicePolicyManager.getCrossProfileCalendarPackages(mAdminComponentName); diff --git a/app/src/main/java/com/afwsamples/testdpc/policy/PolicyManagementFragment.java b/app/src/main/java/com/afwsamples/testdpc/policy/PolicyManagementFragment.java index 0c26436e..73c88aba 100644 --- a/app/src/main/java/com/afwsamples/testdpc/policy/PolicyManagementFragment.java +++ b/app/src/main/java/com/afwsamples/testdpc/policy/PolicyManagementFragment.java @@ -17,6 +17,7 @@ package com.afwsamples.testdpc.policy; import static android.os.UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES; +import static com.afwsamples.testdpc.common.Util.Q_VERSION_CODE; import static com.afwsamples.testdpc.common.preference.DpcPreferenceHelper.NO_CUSTOM_CONSTRIANT; import android.accessibilityservice.AccessibilityServiceInfo; @@ -398,7 +399,7 @@ public class PolicyManagementFragment extends BaseSearchablePolicyPreferenceFrag private static final SparseIntArray PASSWORD_COMPLEXITY = new SparseIntArray(4); static { - if (Util.SDK_INT >= VERSION_CODES.Q) { + if (Util.SDK_INT >= Q_VERSION_CODE) { final int[] complexityIds = new int[]{ DevicePolicyManager.PASSWORD_COMPLEXITY_NONE, DevicePolicyManager.PASSWORD_COMPLEXITY_LOW, @@ -1141,7 +1142,7 @@ public void onPositiveButtonClicked(String[] lockTaskArray) { return false; } - @TargetApi(VERSION_CODES.Q) + @TargetApi(Q_VERSION_CODE) private void promptInstallUpdate() { new AlertDialog.Builder(getActivity()) .setMessage(R.string.install_update_prompt) @@ -1154,7 +1155,7 @@ private void promptInstallUpdate() { .show(); } - @TargetApi(VERSION_CODES.Q) + @TargetApi(Q_VERSION_CODE) private void installUpdate() { File file = new File(getContext().getFilesDir(), "ota.zip"); Uri uri = FileProvider.getUriForFile( diff --git a/app/src/main/java/com/afwsamples/testdpc/policy/UserRestrictionsDisplayFragment.java b/app/src/main/java/com/afwsamples/testdpc/policy/UserRestrictionsDisplayFragment.java index b4ac36e7..ac1a3385 100644 --- a/app/src/main/java/com/afwsamples/testdpc/policy/UserRestrictionsDisplayFragment.java +++ b/app/src/main/java/com/afwsamples/testdpc/policy/UserRestrictionsDisplayFragment.java @@ -17,6 +17,7 @@ package com.afwsamples.testdpc.policy; import static android.os.UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES; +import static com.afwsamples.testdpc.common.Util.Q_VERSION_CODE; import android.app.AlertDialog; import android.app.admin.DevicePolicyManager; @@ -150,7 +151,7 @@ private void constrainPreferences() { } for (String restriction: UserRestriction.QT_PLUS_RESTRICTIONS) { DpcPreferenceBase pref = (DpcPreferenceBase) findPreference(restriction); - pref.setMinSdkVersion(VERSION_CODES.Q); + pref.setMinSdkVersion(Q_VERSION_CODE); } for (String restriction : UserRestriction.PRIMARY_USER_ONLY_RESTRICTIONS) { DpcPreferenceBase pref = (DpcPreferenceBase) findPreference(restriction); diff --git a/app/src/main/java/com/afwsamples/testdpc/policy/networking/AlwaysOnVpnFragment.java b/app/src/main/java/com/afwsamples/testdpc/policy/networking/AlwaysOnVpnFragment.java index 7b50a80e..2eee4a06 100644 --- a/app/src/main/java/com/afwsamples/testdpc/policy/networking/AlwaysOnVpnFragment.java +++ b/app/src/main/java/com/afwsamples/testdpc/policy/networking/AlwaysOnVpnFragment.java @@ -16,6 +16,8 @@ package com.afwsamples.testdpc.policy.networking; +import static com.afwsamples.testdpc.common.Util.Q_VERSION_CODE; + import android.annotation.TargetApi; import android.app.admin.DevicePolicyManager; import android.content.ComponentName; @@ -83,7 +85,7 @@ public View onCreateView(LayoutInflater layoutInflater, ViewGroup container, Bundle savedInstanceState) { final View view = super.onCreateView(layoutInflater, container, savedInstanceState); - if (Util.SDK_INT >= VERSION_CODES.Q) { + if (Util.SDK_INT >= Q_VERSION_CODE) { final ViewGroup extension = getExtensionLayout(view); extension.setVisibility(View.VISIBLE); layoutInflater.inflate(R.layout.lockdown_settings, extension); @@ -112,12 +114,12 @@ protected List createAppList() { @Override protected void reloadSelectedPackage() { super.reloadSelectedPackage(); - if (Util.SDK_INT >= VERSION_CODES.Q) { + if (Util.SDK_INT >= Q_VERSION_CODE) { updateLockdown(); } } - @TargetApi(VERSION_CODES.Q) + @TargetApi(Q_VERSION_CODE) private void updateLockdown() { mLockdown.setChecked(mDpm.isAlwaysOnVpnLockdownEnabled(mWho)); final Set exemptedPackages = mDpm.getAlwaysOnVpnLockdownWhitelist(mWho); @@ -128,7 +130,7 @@ private void updateLockdown() { @Override protected void setSelectedPackage(String pkg) { try { - if (Util.SDK_INT >= VERSION_CODES.Q) { + if (Util.SDK_INT >= Q_VERSION_CODE) { setAlwaysOnVpnPackageQPlus(pkg); } else { mDpm.setAlwaysOnVpnPackage(mWho, pkg, /* lockdownEnabled */ true); @@ -144,7 +146,7 @@ protected void setSelectedPackage(String pkg) { } } - @TargetApi(VERSION_CODES.Q) + @TargetApi(Q_VERSION_CODE) private void setAlwaysOnVpnPackageQPlus(String pkg) throws PackageManager.NameNotFoundException { final boolean lockdown = mLockdown.isChecked(); diff --git a/app/src/main/java/com/afwsamples/testdpc/policy/networking/PrivateDnsModeFragment.java b/app/src/main/java/com/afwsamples/testdpc/policy/networking/PrivateDnsModeFragment.java index 4b761a3f..f6f4c8f6 100644 --- a/app/src/main/java/com/afwsamples/testdpc/policy/networking/PrivateDnsModeFragment.java +++ b/app/src/main/java/com/afwsamples/testdpc/policy/networking/PrivateDnsModeFragment.java @@ -16,6 +16,8 @@ package com.afwsamples.testdpc.policy.networking; +import static com.afwsamples.testdpc.common.Util.Q_VERSION_CODE; + import android.annotation.TargetApi; import android.app.Fragment; import android.app.admin.DevicePolicyManager; @@ -35,7 +37,7 @@ import com.afwsamples.testdpc.DeviceAdminReceiver; import com.afwsamples.testdpc.R; -@TargetApi(VERSION_CODES.Q) +@TargetApi(Q_VERSION_CODE) public class PrivateDnsModeFragment extends Fragment implements View.OnClickListener, RadioGroup.OnCheckedChangeListener { private static final String TAG = "PDNS_FRAG"; diff --git a/app/src/main/java/com/afwsamples/testdpc/policy/networking/SetPrivateDnsTask.java b/app/src/main/java/com/afwsamples/testdpc/policy/networking/SetPrivateDnsTask.java index 332a2a06..2bb77bde 100644 --- a/app/src/main/java/com/afwsamples/testdpc/policy/networking/SetPrivateDnsTask.java +++ b/app/src/main/java/com/afwsamples/testdpc/policy/networking/SetPrivateDnsTask.java @@ -16,6 +16,8 @@ package com.afwsamples.testdpc.policy.networking; +import static com.afwsamples.testdpc.common.Util.Q_VERSION_CODE; + import android.annotation.TargetApi; import android.app.admin.DevicePolicyManager; import android.content.ComponentName; @@ -25,7 +27,7 @@ import com.afwsamples.testdpc.R; import com.afwsamples.testdpc.policy.keymanagement.ShowToastCallback; -@TargetApi(VERSION_CODES.Q) +@TargetApi(Q_VERSION_CODE) final class SetPrivateDnsTask extends AsyncTask { public static final String TAG = "Networking"; private final ShowToastCallback mCallback; From 1e2b3f4abd19c3fb3aad59c588141e6d7304fa17 Mon Sep 17 00:00:00 2001 From: Jonathan Scott Date: Fri, 24 May 2019 13:43:03 +0100 Subject: [PATCH 6/7] Use SDK R03. Bug: 130713895 Change-Id: I4f849273c5298164b661bd2785f3d020d9a2ead7 (cherry picked from commit 8f9f6adf2c6380078c3f167e72015a32abb9f4ee) --- app/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index 65180e3f..a43a42f6 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -13,7 +13,7 @@ ext { } android { - compileSdkVersion 'android-29' + compileSdkVersion 'android-Q' buildToolsVersion "28.0.0" defaultConfig { From ff624945a89152af248bd9329493d9e91820ad1a Mon Sep 17 00:00:00 2001 From: Jonathan Scott Date: Mon, 3 Jun 2019 13:47:26 +0100 Subject: [PATCH 7/7] Fix Q version for test. Bug: 130713895 Change-Id: Ic019d38264f176a9bd42e8e12853de26a70dc04a (cherry picked from commit 4f6db0f7336a5bff77c0504a9cf372eeab0c95ed) --- app/build.gradle | 2 +- .../afwsamples/testdpc/DelegatedAdminReceiver.java | 4 +++- .../java/com/afwsamples/testdpc/common/Util.java | 4 +++- .../testdpc/policy/CrossProfileCalendarFragment.java | 6 ++++-- .../testdpc/policy/PolicyManagementFragment.java | 7 ++++--- .../policy/UserRestrictionsDisplayFragment.java | 3 ++- .../policy/networking/AlwaysOnVpnFragment.java | 12 +++++++----- .../policy/networking/PrivateDnsModeFragment.java | 4 +++- .../testdpc/policy/networking/SetPrivateDnsTask.java | 4 +++- 9 files changed, 30 insertions(+), 16 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index a43a42f6..f9f2206b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,7 +9,7 @@ ext { // exactly 1 digit versionMinor = 1 // exactly 2 digits - versionBuild = 00 + versionBuild = 02 } android { diff --git a/app/src/main/java/com/afwsamples/testdpc/DelegatedAdminReceiver.java b/app/src/main/java/com/afwsamples/testdpc/DelegatedAdminReceiver.java index 3d71df37..abb8d184 100644 --- a/app/src/main/java/com/afwsamples/testdpc/DelegatedAdminReceiver.java +++ b/app/src/main/java/com/afwsamples/testdpc/DelegatedAdminReceiver.java @@ -16,13 +16,15 @@ package com.afwsamples.testdpc; +import static com.afwsamples.testdpc.common.Util.Q_VERSION_CODE; + import android.annotation.TargetApi; import android.content.Context; import android.content.Intent; import android.net.Uri; import android.os.Build.VERSION_CODES; -@TargetApi(VERSION_CODES.Q) +@TargetApi(Q_VERSION_CODE) public class DelegatedAdminReceiver extends android.app.admin.DelegatedAdminReceiver { @Override diff --git a/app/src/main/java/com/afwsamples/testdpc/common/Util.java b/app/src/main/java/com/afwsamples/testdpc/common/Util.java index 241dcdbe..b3f65805 100644 --- a/app/src/main/java/com/afwsamples/testdpc/common/Util.java +++ b/app/src/main/java/com/afwsamples/testdpc/common/Util.java @@ -61,13 +61,15 @@ public class Util { private static final boolean IS_RUNNING_Q = VERSION.CODENAME.length() == 1 && VERSION.CODENAME.charAt(0) == 'Q'; + public static final int Q_VERSION_CODE = 29; + /** * A replacement for {@link VERSION.SDK_INT} that is compatible with pre-release SDKs * *

This will be set to the version SDK, or {@link VERSION_CODES.CUR_DEVELOPMENT} if the SDK * int is not yet assigned. **/ - public static final int SDK_INT = IS_RUNNING_Q ? VERSION_CODES.Q : VERSION.SDK_INT; + public static final int SDK_INT = IS_RUNNING_Q ? Q_VERSION_CODE : VERSION.SDK_INT; /** * Format a friendly datetime for the current locale according to device policy documentation. diff --git a/app/src/main/java/com/afwsamples/testdpc/policy/CrossProfileCalendarFragment.java b/app/src/main/java/com/afwsamples/testdpc/policy/CrossProfileCalendarFragment.java index b63c9ddd..c82e6ad1 100644 --- a/app/src/main/java/com/afwsamples/testdpc/policy/CrossProfileCalendarFragment.java +++ b/app/src/main/java/com/afwsamples/testdpc/policy/CrossProfileCalendarFragment.java @@ -16,6 +16,8 @@ package com.afwsamples.testdpc.policy; +import static com.afwsamples.testdpc.common.Util.Q_VERSION_CODE; + import android.annotation.TargetApi; import android.app.AlertDialog.Builder; import android.app.admin.DevicePolicyManager; @@ -36,7 +38,7 @@ import java.util.Collections; import java.util.Set; -@TargetApi(VERSION_CODES.Q) +@TargetApi(Q_VERSION_CODE) public class CrossProfileCalendarFragment extends BaseSearchablePolicyPreferenceFragment implements Preference.OnPreferenceClickListener, Preference.OnPreferenceChangeListener { @@ -102,7 +104,7 @@ public boolean onPreferenceChange(Preference preference, Object newValue) { return false; } - @TargetApi(VERSION_CODES.Q) + @TargetApi(Q_VERSION_CODE) private void reloadAllowAllPackagesUi() { final Set packages = mDevicePolicyManager.getCrossProfileCalendarPackages(mAdminComponentName); diff --git a/app/src/main/java/com/afwsamples/testdpc/policy/PolicyManagementFragment.java b/app/src/main/java/com/afwsamples/testdpc/policy/PolicyManagementFragment.java index 0c26436e..73c88aba 100644 --- a/app/src/main/java/com/afwsamples/testdpc/policy/PolicyManagementFragment.java +++ b/app/src/main/java/com/afwsamples/testdpc/policy/PolicyManagementFragment.java @@ -17,6 +17,7 @@ package com.afwsamples.testdpc.policy; import static android.os.UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES; +import static com.afwsamples.testdpc.common.Util.Q_VERSION_CODE; import static com.afwsamples.testdpc.common.preference.DpcPreferenceHelper.NO_CUSTOM_CONSTRIANT; import android.accessibilityservice.AccessibilityServiceInfo; @@ -398,7 +399,7 @@ public class PolicyManagementFragment extends BaseSearchablePolicyPreferenceFrag private static final SparseIntArray PASSWORD_COMPLEXITY = new SparseIntArray(4); static { - if (Util.SDK_INT >= VERSION_CODES.Q) { + if (Util.SDK_INT >= Q_VERSION_CODE) { final int[] complexityIds = new int[]{ DevicePolicyManager.PASSWORD_COMPLEXITY_NONE, DevicePolicyManager.PASSWORD_COMPLEXITY_LOW, @@ -1141,7 +1142,7 @@ public void onPositiveButtonClicked(String[] lockTaskArray) { return false; } - @TargetApi(VERSION_CODES.Q) + @TargetApi(Q_VERSION_CODE) private void promptInstallUpdate() { new AlertDialog.Builder(getActivity()) .setMessage(R.string.install_update_prompt) @@ -1154,7 +1155,7 @@ private void promptInstallUpdate() { .show(); } - @TargetApi(VERSION_CODES.Q) + @TargetApi(Q_VERSION_CODE) private void installUpdate() { File file = new File(getContext().getFilesDir(), "ota.zip"); Uri uri = FileProvider.getUriForFile( diff --git a/app/src/main/java/com/afwsamples/testdpc/policy/UserRestrictionsDisplayFragment.java b/app/src/main/java/com/afwsamples/testdpc/policy/UserRestrictionsDisplayFragment.java index b4ac36e7..ac1a3385 100644 --- a/app/src/main/java/com/afwsamples/testdpc/policy/UserRestrictionsDisplayFragment.java +++ b/app/src/main/java/com/afwsamples/testdpc/policy/UserRestrictionsDisplayFragment.java @@ -17,6 +17,7 @@ package com.afwsamples.testdpc.policy; import static android.os.UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES; +import static com.afwsamples.testdpc.common.Util.Q_VERSION_CODE; import android.app.AlertDialog; import android.app.admin.DevicePolicyManager; @@ -150,7 +151,7 @@ private void constrainPreferences() { } for (String restriction: UserRestriction.QT_PLUS_RESTRICTIONS) { DpcPreferenceBase pref = (DpcPreferenceBase) findPreference(restriction); - pref.setMinSdkVersion(VERSION_CODES.Q); + pref.setMinSdkVersion(Q_VERSION_CODE); } for (String restriction : UserRestriction.PRIMARY_USER_ONLY_RESTRICTIONS) { DpcPreferenceBase pref = (DpcPreferenceBase) findPreference(restriction); diff --git a/app/src/main/java/com/afwsamples/testdpc/policy/networking/AlwaysOnVpnFragment.java b/app/src/main/java/com/afwsamples/testdpc/policy/networking/AlwaysOnVpnFragment.java index 7b50a80e..2eee4a06 100644 --- a/app/src/main/java/com/afwsamples/testdpc/policy/networking/AlwaysOnVpnFragment.java +++ b/app/src/main/java/com/afwsamples/testdpc/policy/networking/AlwaysOnVpnFragment.java @@ -16,6 +16,8 @@ package com.afwsamples.testdpc.policy.networking; +import static com.afwsamples.testdpc.common.Util.Q_VERSION_CODE; + import android.annotation.TargetApi; import android.app.admin.DevicePolicyManager; import android.content.ComponentName; @@ -83,7 +85,7 @@ public View onCreateView(LayoutInflater layoutInflater, ViewGroup container, Bundle savedInstanceState) { final View view = super.onCreateView(layoutInflater, container, savedInstanceState); - if (Util.SDK_INT >= VERSION_CODES.Q) { + if (Util.SDK_INT >= Q_VERSION_CODE) { final ViewGroup extension = getExtensionLayout(view); extension.setVisibility(View.VISIBLE); layoutInflater.inflate(R.layout.lockdown_settings, extension); @@ -112,12 +114,12 @@ protected List createAppList() { @Override protected void reloadSelectedPackage() { super.reloadSelectedPackage(); - if (Util.SDK_INT >= VERSION_CODES.Q) { + if (Util.SDK_INT >= Q_VERSION_CODE) { updateLockdown(); } } - @TargetApi(VERSION_CODES.Q) + @TargetApi(Q_VERSION_CODE) private void updateLockdown() { mLockdown.setChecked(mDpm.isAlwaysOnVpnLockdownEnabled(mWho)); final Set exemptedPackages = mDpm.getAlwaysOnVpnLockdownWhitelist(mWho); @@ -128,7 +130,7 @@ private void updateLockdown() { @Override protected void setSelectedPackage(String pkg) { try { - if (Util.SDK_INT >= VERSION_CODES.Q) { + if (Util.SDK_INT >= Q_VERSION_CODE) { setAlwaysOnVpnPackageQPlus(pkg); } else { mDpm.setAlwaysOnVpnPackage(mWho, pkg, /* lockdownEnabled */ true); @@ -144,7 +146,7 @@ protected void setSelectedPackage(String pkg) { } } - @TargetApi(VERSION_CODES.Q) + @TargetApi(Q_VERSION_CODE) private void setAlwaysOnVpnPackageQPlus(String pkg) throws PackageManager.NameNotFoundException { final boolean lockdown = mLockdown.isChecked(); diff --git a/app/src/main/java/com/afwsamples/testdpc/policy/networking/PrivateDnsModeFragment.java b/app/src/main/java/com/afwsamples/testdpc/policy/networking/PrivateDnsModeFragment.java index 4b761a3f..f6f4c8f6 100644 --- a/app/src/main/java/com/afwsamples/testdpc/policy/networking/PrivateDnsModeFragment.java +++ b/app/src/main/java/com/afwsamples/testdpc/policy/networking/PrivateDnsModeFragment.java @@ -16,6 +16,8 @@ package com.afwsamples.testdpc.policy.networking; +import static com.afwsamples.testdpc.common.Util.Q_VERSION_CODE; + import android.annotation.TargetApi; import android.app.Fragment; import android.app.admin.DevicePolicyManager; @@ -35,7 +37,7 @@ import com.afwsamples.testdpc.DeviceAdminReceiver; import com.afwsamples.testdpc.R; -@TargetApi(VERSION_CODES.Q) +@TargetApi(Q_VERSION_CODE) public class PrivateDnsModeFragment extends Fragment implements View.OnClickListener, RadioGroup.OnCheckedChangeListener { private static final String TAG = "PDNS_FRAG"; diff --git a/app/src/main/java/com/afwsamples/testdpc/policy/networking/SetPrivateDnsTask.java b/app/src/main/java/com/afwsamples/testdpc/policy/networking/SetPrivateDnsTask.java index 332a2a06..2bb77bde 100644 --- a/app/src/main/java/com/afwsamples/testdpc/policy/networking/SetPrivateDnsTask.java +++ b/app/src/main/java/com/afwsamples/testdpc/policy/networking/SetPrivateDnsTask.java @@ -16,6 +16,8 @@ package com.afwsamples.testdpc.policy.networking; +import static com.afwsamples.testdpc.common.Util.Q_VERSION_CODE; + import android.annotation.TargetApi; import android.app.admin.DevicePolicyManager; import android.content.ComponentName; @@ -25,7 +27,7 @@ import com.afwsamples.testdpc.R; import com.afwsamples.testdpc.policy.keymanagement.ShowToastCallback; -@TargetApi(VERSION_CODES.Q) +@TargetApi(Q_VERSION_CODE) final class SetPrivateDnsTask extends AsyncTask { public static final String TAG = "Networking"; private final ShowToastCallback mCallback;