Skip to content

Commit 8fc45ed

Browse files
committed
Merge /ssd/testdpc-qt-release/vendor/unbundled_google/packages/TestDPC into new-version
2 parents b21e807 + 06371c0 commit 8fc45ed

File tree

52 files changed

+182
-145
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+182
-145
lines changed

app/build.gradle

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ ext {
77
// exactly 1 digit
88
versionMinor = 1
99
// exactly 2 digits
10-
versionBuild = 00
10+
versionBuild = 02
1111
}
1212

1313
android {
@@ -120,14 +120,18 @@ private void stripTestOnlyForBuild(flavor, buildType) {
120120
}
121121

122122
dependencies {
123+
def lifecycle_version = "2.0.0"
124+
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
123125
implementation 'androidx.enterprise:enterprise-feedback:1.0.0-alpha01'
124-
implementation 'com.android.support:multidex:1.0.1'
125-
implementation 'com.android.support:preference-v14:28.0.0-alpha1'
126-
implementation 'com.android.support:recyclerview-v7:28.0.0-alpha1'
127-
implementation 'com.android.support:support-v13:28.0.0-alpha1'
128-
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
126+
implementation 'androidx.multidex:multidex:2.0.0'
127+
implementation 'androidx.legacy:legacy-preference-v14:1.0.0'
128+
implementation 'androidx.recyclerview:recyclerview:1.0.0'
129+
implementation 'androidx.legacy:legacy-support-v13:1.0.0'
130+
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
129131
implementation(name: 'setup-wizard-lib-platform-release', ext: 'aar')
130132
implementation 'org.bouncycastle:bcpkix-jdk15on:1.56'
131133
implementation 'org.bouncycastle:bcprov-jdk15on:1.56'
132134
implementation 'com.google.guava:guava:23.6-android'
135+
136+
annotationProcessor "androidx.lifecycle:lifecycle-compiler:$lifecycle_version"
133137
}

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@
163163

164164
<provider
165165
android:authorities="com.afwsamples.testdpc.fileprovider"
166-
android:name="android.support.v4.content.FileProvider"
166+
android:name="androidx.core.content.FileProvider"
167167
android:grantUriPermissions="true"
168168
android:exported="false">
169169
<meta-data

app/src/main/java/com/afwsamples/testdpc/AddAccountActivity.java

Lines changed: 45 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.afwsamples.testdpc;
1818

1919
import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE;
20+
import static androidx.lifecycle.Lifecycle.State.STARTED;
2021

2122
import android.accounts.Account;
2223
import android.accounts.AccountManager;
@@ -30,13 +31,15 @@
3031
import android.content.Intent;
3132
import android.os.Build.VERSION_CODES;
3233
import android.os.Bundle;
34+
import android.os.Handler;
3335
import android.os.UserManager;
3436
import android.text.TextUtils;
3537
import android.util.Log;
3638
import android.view.View;
3739
import android.widget.EditText;
3840
import android.widget.RadioGroup;
3941
import android.widget.Toast;
42+
import androidx.lifecycle.ProcessLifecycleOwner;
4043
import com.afwsamples.testdpc.common.Util;
4144
import com.android.setupwizardlib.GlifLayout;
4245
import java.io.IOException;
@@ -50,6 +53,7 @@ public class AddAccountActivity extends Activity {
5053

5154
private static final String TAG = "AddAccountActivity";
5255
private static final String GOOGLE_ACCOUNT_TYPE = "com.google";
56+
private static final long WAIT_FOR_FOREGROUND_DELAY_MS = 10;
5357

5458
public static final String EXTRA_NEXT_ACTIVITY_INTENT = "nextActivityIntent";
5559

@@ -100,26 +104,47 @@ private void addAccount(String accountName) {
100104
}
101105

102106
accountManager.addAccount(GOOGLE_ACCOUNT_TYPE, null, null, bundle, this,
103-
accountManagerFuture -> {
104-
try {
105-
Bundle result = accountManagerFuture.getResult();
106-
String accountNameAdded = result.getString(AccountManager.KEY_ACCOUNT_NAME);
107-
Log.d(TAG, "addAccount - accountNameAdded: " + accountNameAdded);
108-
if (mNextActivityIntent != null) {
109-
startActivity(mNextActivityIntent);
110-
}
111-
final Intent resultIntent = new Intent();
112-
resultIntent.putExtra(EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE,
113-
new Account(accountNameAdded, GOOGLE_ACCOUNT_TYPE));
114-
setResult(RESULT_OK, resultIntent);
115-
finish();
116-
} catch (OperationCanceledException | AuthenticatorException
117-
| IOException e) {
118-
Log.e(TAG, "addAccount - failed", e);
119-
Toast.makeText(AddAccountActivity.this,
120-
R.string.fail_to_add_account, Toast.LENGTH_LONG).show();
121-
}
122-
}, null);
107+
accountManagerFuture -> {
108+
try {
109+
Bundle result = accountManagerFuture.getResult();
110+
// This callback executes slightly before the app is back in the foreground
111+
// so we need to wait.
112+
waitForForeground(() -> accountCreated(result), 1000);
113+
} catch (OperationCanceledException | AuthenticatorException | IOException e) {
114+
Log.e(TAG, "addAccount - failed", e);
115+
Toast.makeText(AddAccountActivity.this,
116+
R.string.fail_to_add_account, Toast.LENGTH_LONG).show();
117+
}
118+
}, null);
119+
}
120+
121+
private void waitForForeground(Runnable r, long timeout) {
122+
if (timeout <= 0) {
123+
throw new RuntimeException("Timed out waiting for foreground.");
124+
}
125+
boolean isAppInForeground =
126+
ProcessLifecycleOwner.get().getLifecycle().getCurrentState().isAtLeast(STARTED);
127+
if (isAppInForeground) {
128+
r.run();
129+
} else {
130+
new Handler().postDelayed(
131+
() -> waitForForeground(r, timeout - WAIT_FOR_FOREGROUND_DELAY_MS),
132+
WAIT_FOR_FOREGROUND_DELAY_MS);
133+
}
134+
}
135+
136+
private void accountCreated(Bundle result) {
137+
String accountNameAdded = result.getString(AccountManager.KEY_ACCOUNT_NAME);
138+
Log.d(TAG, "addAccount - accountNameAdded: " + accountNameAdded);
139+
if (mNextActivityIntent != null) {
140+
startActivity(mNextActivityIntent);
141+
}
142+
final Intent resultIntent = new Intent();
143+
resultIntent.putExtra(EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE,
144+
new Account(accountNameAdded, GOOGLE_ACCOUNT_TYPE));
145+
setResult(RESULT_OK, resultIntent);
146+
finish();
147+
123148
}
124149

125150
private void disableUserRestrictions() {

app/src/main/java/com/afwsamples/testdpc/DelegatedAdminReceiver.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@
1616

1717
package com.afwsamples.testdpc;
1818

19+
import static com.afwsamples.testdpc.common.Util.Q_VERSION_CODE;
20+
1921
import android.annotation.TargetApi;
2022
import android.content.Context;
2123
import android.content.Intent;
2224
import android.net.Uri;
2325
import android.os.Build.VERSION_CODES;
2426

25-
@TargetApi(VERSION_CODES.Q)
27+
@TargetApi(Q_VERSION_CODE)
2628
public class DelegatedAdminReceiver extends android.app.admin.DelegatedAdminReceiver {
2729

2830
@Override

app/src/main/java/com/afwsamples/testdpc/DeviceAdminReceiver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
import android.os.Process;
3333
import android.os.UserHandle;
3434
import android.os.UserManager;
35-
import android.support.v4.app.NotificationCompat;
35+
import androidx.core.app.NotificationCompat;
3636
import android.util.Log;
3737
import android.widget.Toast;
3838
import com.afwsamples.testdpc.common.NotificationUtil;

app/src/main/java/com/afwsamples/testdpc/DeviceAdminService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import android.content.Intent;
55
import android.content.IntentFilter;
66
import android.os.Build.VERSION_CODES;
7-
import android.support.annotation.RequiresApi;
7+
import androidx.annotation.RequiresApi;
88

99
/**
1010
* To allow DPC process to be persistent and foreground.

app/src/main/java/com/afwsamples/testdpc/PackageMonitorReceiver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import android.content.BroadcastReceiver;
66
import android.content.Context;
77
import android.content.Intent;
8-
import android.support.v4.app.NotificationCompat;
8+
import androidx.core.app.NotificationCompat;
99
import android.text.TextUtils;
1010
import com.afwsamples.testdpc.common.NotificationUtil;
1111

app/src/main/java/com/afwsamples/testdpc/common/BaseSearchablePolicyPreferenceFragment.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
import android.content.Context;
44
import android.os.Bundle;
5-
import android.support.v14.preference.PreferenceFragment;
6-
import android.support.v7.preference.Preference;
7-
import android.support.v7.preference.PreferenceGroup;
8-
import android.support.v7.preference.PreferenceGroupAdapter;
9-
import android.support.v7.preference.PreferenceScreen;
10-
import android.support.v7.preference.PreferenceViewHolder;
11-
import android.support.v7.widget.LinearLayoutManager;
12-
import android.support.v7.widget.RecyclerView;
5+
import androidx.preference.PreferenceFragment;
6+
import androidx.preference.Preference;
7+
import androidx.preference.PreferenceGroup;
8+
import androidx.preference.PreferenceGroupAdapter;
9+
import androidx.preference.PreferenceScreen;
10+
import androidx.preference.PreferenceViewHolder;
11+
import androidx.recyclerview.widget.LinearLayoutManager;
12+
import androidx.recyclerview.widget.RecyclerView;
1313
import android.text.TextUtils;
1414
import android.view.Menu;
1515
import android.view.MenuInflater;

app/src/main/java/com/afwsamples/testdpc/common/NotificationUtil.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44
import android.app.NotificationChannel;
55
import android.app.NotificationManager;
66
import android.content.Context;
7-
import android.os.Build;
87
import android.os.Build.VERSION_CODES;
9-
import android.support.annotation.RequiresApi;
10-
import android.support.annotation.StringRes;
11-
import android.support.v4.app.NotificationCompat;
8+
import androidx.annotation.RequiresApi;
9+
import androidx.annotation.StringRes;
10+
import androidx.core.app.NotificationCompat;
1211
import com.afwsamples.testdpc.R;
1312

1413
public class NotificationUtil {

app/src/main/java/com/afwsamples/testdpc/common/ProfileOrParentFragment.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@
2121
import android.app.admin.DevicePolicyManager;
2222
import android.content.ComponentName;
2323
import android.content.Context;
24-
import android.os.Build;
2524
import android.os.Build.VERSION_CODES;
2625
import android.os.Bundle;
27-
import android.support.v13.app.FragmentTabHost;
28-
import android.support.v7.preference.PreferenceManager;
26+
import androidx.legacy.app.FragmentTabHost;
27+
import androidx.preference.PreferenceManager;
2928
import android.view.LayoutInflater;
3029
import android.view.View;
3130
import android.view.ViewGroup;

0 commit comments

Comments
 (0)