Skip to content

Commit

Permalink
Merge /ssd/testdpc-qt-release/vendor/unbundled_google/packages/TestDP…
Browse files Browse the repository at this point in the history
…C into new-version
  • Loading branch information
jscott1989 committed Jun 4, 2019
2 parents b21e807 + 06371c0 commit 8fc45ed
Show file tree
Hide file tree
Showing 52 changed files with 182 additions and 145 deletions.
16 changes: 10 additions & 6 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ext {
// exactly 1 digit
versionMinor = 1
// exactly 2 digits
versionBuild = 00
versionBuild = 02
}

android {
Expand Down Expand Up @@ -120,14 +120,18 @@ 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 'com.android.support:multidex:1.0.1'
implementation 'com.android.support:preference-v14:28.0.0-alpha1'
implementation 'com.android.support:recyclerview-v7:28.0.0-alpha1'
implementation 'com.android.support:support-v13:28.0.0-alpha1'
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'
implementation 'com.google.guava:guava:23.6-android'

annotationProcessor "androidx.lifecycle:lifecycle-compiler:$lifecycle_version"
}
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@

<provider
android:authorities="com.afwsamples.testdpc.fileprovider"
android:name="android.support.v4.content.FileProvider"
android:name="androidx.core.content.FileProvider"
android:grantUriPermissions="true"
android:exported="false">
<meta-data
Expand Down
65 changes: 45 additions & 20 deletions app/src/main/java/com/afwsamples/testdpc/AddAccountActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -30,13 +31,15 @@
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;
import android.view.View;
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;
Expand All @@ -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";

Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import android.os.Process;
import android.os.UserHandle;
import android.os.UserManager;
import android.support.v4.app.NotificationCompat;
import androidx.core.app.NotificationCompat;
import android.util.Log;
import android.widget.Toast;
import com.afwsamples.testdpc.common.NotificationUtil;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Build.VERSION_CODES;
import android.support.annotation.RequiresApi;
import androidx.annotation.RequiresApi;

/**
* To allow DPC process to be persistent and foreground.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.NotificationCompat;
import androidx.core.app.NotificationCompat;
import android.text.TextUtils;
import com.afwsamples.testdpc.common.NotificationUtil;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

import android.content.Context;
import android.os.Bundle;
import android.support.v14.preference.PreferenceFragment;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceGroup;
import android.support.v7.preference.PreferenceGroupAdapter;
import android.support.v7.preference.PreferenceScreen;
import android.support.v7.preference.PreferenceViewHolder;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import androidx.preference.PreferenceFragment;
import androidx.preference.Preference;
import androidx.preference.PreferenceGroup;
import androidx.preference.PreferenceGroupAdapter;
import androidx.preference.PreferenceScreen;
import androidx.preference.PreferenceViewHolder;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.text.TextUtils;
import android.view.Menu;
import android.view.MenuInflater;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Context;
import android.os.Build;
import android.os.Build.VERSION_CODES;
import android.support.annotation.RequiresApi;
import android.support.annotation.StringRes;
import android.support.v4.app.NotificationCompat;
import androidx.annotation.RequiresApi;
import androidx.annotation.StringRes;
import androidx.core.app.NotificationCompat;
import com.afwsamples.testdpc.R;

public class NotificationUtil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@
import android.app.admin.DevicePolicyManager;
import android.content.ComponentName;
import android.content.Context;
import android.os.Build;
import android.os.Build.VERSION_CODES;
import android.os.Bundle;
import android.support.v13.app.FragmentTabHost;
import android.support.v7.preference.PreferenceManager;
import androidx.legacy.app.FragmentTabHost;
import androidx.preference.PreferenceManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package com.afwsamples.testdpc.common;

import android.support.v7.widget.RecyclerView;
import androidx.recyclerview.widget.RecyclerView;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
Expand Down
7 changes: 4 additions & 3 deletions app/src/main/java/com/afwsamples/testdpc/common/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@
import android.content.IntentFilter;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Build;
import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;
import android.os.Bundle;
import android.os.UserHandle;
import android.os.UserManager;
import android.support.v14.preference.PreferenceFragment;
import androidx.preference.PreferenceFragment;
import android.text.format.DateUtils;
import android.util.Log;
import android.widget.ImageView;
Expand Down Expand Up @@ -62,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
*
* <p>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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
import android.graphics.Color;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.annotation.StringRes;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import androidx.annotation.StringRes;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package com.afwsamples.testdpc.common.preference;

import android.support.annotation.StringRes;
import androidx.annotation.StringRes;

public interface CustomConstraint {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
package com.afwsamples.testdpc.common.preference;

import android.content.Context;
import android.support.annotation.Nullable;
import android.support.v7.preference.EditTextPreference;
import android.support.v7.preference.PreferenceManager;
import android.support.v7.preference.PreferenceViewHolder;
import androidx.annotation.Nullable;
import androidx.preference.EditTextPreference;
import androidx.preference.PreferenceManager;
import androidx.preference.PreferenceViewHolder;
import android.util.AttributeSet;

/**
Expand All @@ -41,7 +41,7 @@ public DpcEditTextPreference(Context context, AttributeSet attrs, int defStyleAt
}

public DpcEditTextPreference(Context context, AttributeSet attrs) {
this(context, attrs, android.support.v7.preference.R.attr.editTextPreferenceStyle);
this(context, attrs, androidx.preference.R.attr.editTextPreferenceStyle);
}

public DpcEditTextPreference(Context context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
package com.afwsamples.testdpc.common.preference;

import android.content.Context;
import android.support.annotation.Nullable;
import android.support.v7.preference.ListPreference;
import android.support.v7.preference.PreferenceManager;
import android.support.v7.preference.PreferenceViewHolder;
import androidx.annotation.Nullable;
import androidx.preference.ListPreference;
import androidx.preference.PreferenceManager;
import androidx.preference.PreferenceViewHolder;
import android.util.AttributeSet;

/**
Expand All @@ -41,7 +41,7 @@ public DpcListPreference(Context context, AttributeSet attrs, int defStyleAttr)
}

public DpcListPreference(Context context, AttributeSet attrs) {
this(context, attrs, android.support.v7.preference.R.attr.dialogPreferenceStyle);
this(context, attrs, androidx.preference.R.attr.dialogPreferenceStyle);
}

public DpcListPreference(Context context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
package com.afwsamples.testdpc.common.preference;

import android.content.Context;
import android.support.annotation.Nullable;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceManager;
import android.support.v7.preference.PreferenceViewHolder;
import androidx.annotation.Nullable;
import androidx.preference.Preference;
import androidx.preference.PreferenceManager;
import androidx.preference.PreferenceViewHolder;
import android.util.AttributeSet;

/**
Expand All @@ -41,7 +41,7 @@ public DpcPreference(Context context, AttributeSet attrs, int defStyleAttr) {
}

public DpcPreference(Context context, AttributeSet attrs) {
this(context, attrs, android.support.v7.preference.R.attr.preferenceStyle);
this(context, attrs, androidx.preference.R.attr.preferenceStyle);
}

public DpcPreference(Context context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package com.afwsamples.testdpc.common.preference;

import android.support.annotation.Nullable;
import androidx.annotation.Nullable;

/**
* Common base class for the DpcPreference family of classes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@
import android.app.admin.DevicePolicyManager;
import android.content.Context;
import android.content.res.TypedArray;
import android.os.Build;
import android.os.Build.VERSION_CODES;
import android.support.annotation.IntDef;
import android.support.annotation.StringRes;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceViewHolder;
import androidx.annotation.IntDef;
import androidx.annotation.StringRes;
import androidx.preference.Preference;
import androidx.preference.PreferenceViewHolder;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
Expand Down
Loading

0 comments on commit 8fc45ed

Please sign in to comment.