Skip to content

Commit

Permalink
Merge new-version
Browse files Browse the repository at this point in the history
  • Loading branch information
jscott1989 committed May 24, 2019
2 parents 6540da2 + c00e76f commit b21e807
Show file tree
Hide file tree
Showing 75 changed files with 691 additions and 593 deletions.
5 changes: 3 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ext {
// 1 or more digits
versionMajor = 6
// exactly 1 digit
versionMinor = 0
versionMinor = 1
// exactly 2 digits
versionBuild = 00
}
Expand All @@ -17,7 +17,7 @@ android {
defaultConfig {
applicationId "com.afwsamples.testdpc"
minSdkVersion 21
targetSdkVersion 'Q'
targetSdkVersion 29
versionCode versionMajor * 1000 + versionMinor * 100 + versionBuild
versionName "${versionMajor}.${versionMinor}.${versionBuild}"
multiDexEnabled true
Expand Down Expand Up @@ -120,6 +120,7 @@ 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-alpha1'
implementation 'com.android.support:recyclerview-v7:28.0.0-alpha1'
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,12 @@
</intent-filter>
</service>

<service android:name=".feedback.AppStatesService">
<intent-filter>
<action android:name="androidx.enterprise.feedback.action.APP_STATES" />
</intent-filter>
</service>

</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,16 @@
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.os.Build.VERSION_CODES;
import android.os.Bundle;
import android.os.UserManager;
import android.support.v4.os.BuildCompat;
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 com.afwsamples.testdpc.common.Util;
import com.android.setupwizardlib.GlifLayout;
import java.io.IOException;

Expand Down Expand Up @@ -122,7 +123,7 @@ private void addAccount(String accountName) {
}

private void disableUserRestrictions() {
if (BuildCompat.isAtLeastN()) {
if (Util.SDK_INT >= VERSION_CODES.N) {
// DPC is allowed to bypass DISALLOW_MODIFY_ACCOUNTS on N or above.
Log.v(TAG, "skip disabling user restriction on N or above");
return;
Expand All @@ -135,7 +136,7 @@ private void disableUserRestrictions() {
}

private void restoreUserRestrictions() {
if (BuildCompat.isAtLeastN()) {
if (Util.SDK_INT >= VERSION_CODES.N) {
// DPC is allowed to bypass DISALLOW_MODIFY_ACCOUNTS on N or above.
Log.v(TAG, "skip restoring user restrictions on N or above");
return;
Expand Down
1 change: 0 additions & 1 deletion app/src/main/java/com/afwsamples/testdpc/BootReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import android.content.Intent;
import android.os.Process;
import android.os.UserHandle;

import com.afwsamples.testdpc.common.Util;
import com.afwsamples.testdpc.comp.BindDeviceAdminServiceHelper;
import com.afwsamples.testdpc.comp.DeviceOwnerService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,22 @@

package com.afwsamples.testdpc;

import static com.afwsamples.testdpc.policy.PolicyManagementFragment.OVERRIDE_KEY_SELECTION_KEY;

import android.annotation.TargetApi;
import android.app.admin.DevicePolicyManager;
import android.app.admin.NetworkEvent;
import android.content.ComponentName;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Build.VERSION_CODES;
import android.os.Process;
import android.preference.PreferenceManager;
import android.support.v4.os.BuildCompat;
import android.text.TextUtils;
import android.util.Log;
import android.widget.Toast;

import com.afwsamples.testdpc.common.Util;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
Expand All @@ -38,8 +40,6 @@
import java.util.Date;
import java.util.List;

import static com.afwsamples.testdpc.policy.PolicyManagementFragment.OVERRIDE_KEY_SELECTION_KEY;

/**
* A class that implements common logic to handle direct and delegated admin callbacks
* from DeviceAdminReceiver and DelegatedAdminReceiver.
Expand All @@ -65,7 +65,7 @@ public static String onChoosePrivateKeyAlias(Context context, int uid) {
}
}

@TargetApi(Build.VERSION_CODES.O)
@TargetApi(VERSION_CODES.O)
public static void onNetworkLogsAvailable(Context context, ComponentName admin, long batchToken,
int networkLogsCount) {
Log.i(TAG, "onNetworkLogsAvailable(), batchToken: " + batchToken
Expand Down Expand Up @@ -93,7 +93,7 @@ public static void onNetworkLogsAvailable(Context context, ComponentName admin,
context.getString(R.string.on_network_logs_available_success, batchToken));

ArrayList<String> loggedEvents = new ArrayList<>();
if (BuildCompat.isAtLeastP()) {
if (Util.SDK_INT >= VERSION_CODES.P) {
for (NetworkEvent event : events) {
loggedEvents.add(event.toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.app.Fragment;
import android.content.ComponentName;
import android.content.pm.CrossProfileApps;
import android.os.Build.VERSION_CODES;
import android.os.Bundle;
import android.os.UserHandle;
import android.view.LayoutInflater;
Expand All @@ -13,8 +14,7 @@
import android.widget.TextView;
import java.util.List;

// TODO: Replace it with P.
@TargetApi(28)
@TargetApi(VERSION_CODES.P)
public class CrossProfileAppsFragment extends Fragment {
private static final String TAG = "CrossProfileAppsFragmen";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Build.VERSION_CODES;

@TargetApi(Build.VERSION_CODES.Q)
@TargetApi(VERSION_CODES.Q)
public class DelegatedAdminReceiver extends android.app.admin.DelegatedAdminReceiver {

@Override
Expand Down
46 changes: 22 additions & 24 deletions app/src/main/java/com/afwsamples/testdpc/DeviceAdminReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,17 @@
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Binder;
import android.os.Build;
import android.os.Build.VERSION_CODES;
import android.os.ParcelFileDescriptor;
import android.os.PersistableBundle;
import android.os.Process;
import android.os.UserHandle;
import android.os.UserManager;
import android.support.v4.app.NotificationCompat;
import android.support.v4.os.BuildCompat;
import android.util.Log;
import android.widget.Toast;
import com.afwsamples.testdpc.common.NotificationUtil;
import com.afwsamples.testdpc.common.Util;
import com.afwsamples.testdpc.policy.UserRestriction;
import com.afwsamples.testdpc.provision.PostProvisioningTask;
import java.io.BufferedReader;
import java.io.BufferedWriter;
Expand Down Expand Up @@ -92,7 +90,7 @@ public void onReceive(Context context, Intent intent) {
}
}

@TargetApi(Build.VERSION_CODES.N)
@TargetApi(VERSION_CODES.N)
@Override
public void onSecurityLogsAvailable(Context context, Intent intent) {
Log.i(TAG, "onSecurityLogsAvailable() called");
Expand All @@ -107,7 +105,7 @@ public void onSecurityLogsAvailable(Context context, Intent intent) {
* TODO: reconsider how to store and present the logs in the future, e.g. save the file into
* internal memory and show the content in a ListView
*/
@TargetApi(Build.VERSION_CODES.O)
@TargetApi(VERSION_CODES.O)
@Override
public void onNetworkLogsAvailable(Context context, Intent intent, long batchToken,
int networkLogsCount) {
Expand All @@ -133,7 +131,7 @@ public void onProfileProvisioningComplete(Context context, Intent intent) {
}
}

@TargetApi(Build.VERSION_CODES.N)
@TargetApi(VERSION_CODES.N)
@Override
public void onBugreportSharingDeclined(Context context, Intent intent) {
Log.i(TAG, "Bugreport sharing declined");
Expand All @@ -142,7 +140,7 @@ public void onBugreportSharingDeclined(Context context, Intent intent) {
NotificationUtil.BUGREPORT_NOTIFICATION_ID);
}

@TargetApi(Build.VERSION_CODES.N)
@TargetApi(VERSION_CODES.N)
@Override
public void onBugreportShared(final Context context, Intent intent,
final String bugreportFileHash) {
Expand Down Expand Up @@ -190,7 +188,7 @@ protected void onPostExecute(String message) {
}.execute();
}

@TargetApi(Build.VERSION_CODES.N)
@TargetApi(VERSION_CODES.N)
@Override
public void onBugreportFailed(Context context, Intent intent, int failureCode) {
String failureReason;
Expand All @@ -212,42 +210,42 @@ public void onBugreportFailed(Context context, Intent intent, int failureCode) {
}


@TargetApi(Build.VERSION_CODES.O)
@TargetApi(VERSION_CODES.O)
@Override
public void onUserAdded(Context context, Intent intent, UserHandle newUser) {
handleUserAction(context, newUser, R.string.on_user_added_title,
R.string.on_user_added_message, NotificationUtil.USER_ADDED_NOTIFICATION_ID);
}

@TargetApi(Build.VERSION_CODES.O)
@TargetApi(VERSION_CODES.O)
@Override
public void onUserRemoved(Context context, Intent intent, UserHandle removedUser) {
handleUserAction(context, removedUser, R.string.on_user_removed_title,
R.string.on_user_removed_message, NotificationUtil.USER_REMOVED_NOTIFICATION_ID);
}

@TargetApi(Build.VERSION_CODES.P)
@TargetApi(VERSION_CODES.P)
@Override
public void onUserStarted(Context context, Intent intent, UserHandle startedUser) {
handleUserAction(context, startedUser, R.string.on_user_started_title,
R.string.on_user_started_message, NotificationUtil.USER_STARTED_NOTIFICATION_ID);
}

@TargetApi(Build.VERSION_CODES.P)
@TargetApi(VERSION_CODES.P)
@Override
public void onUserStopped(Context context, Intent intent, UserHandle stoppedUser) {
handleUserAction(context, stoppedUser, R.string.on_user_stopped_title,
R.string.on_user_stopped_message, NotificationUtil.USER_STOPPED_NOTIFICATION_ID);
}

@TargetApi(Build.VERSION_CODES.P)
@TargetApi(VERSION_CODES.P)
@Override
public void onUserSwitched(Context context, Intent intent, UserHandle switchedUser) {
handleUserAction(context, switchedUser, R.string.on_user_switched_title,
R.string.on_user_switched_message, NotificationUtil.USER_SWITCHED_NOTIFICATION_ID);
}

@TargetApi(Build.VERSION_CODES.M)
@TargetApi(VERSION_CODES.M)
@Override
public void onSystemUpdatePending(Context context, Intent intent, long receivedTime) {
if (receivedTime != -1) {
Expand All @@ -260,7 +258,7 @@ public void onSystemUpdatePending(Context context, Intent intent, long receivedT
}
}

@TargetApi(Build.VERSION_CODES.M)
@TargetApi(VERSION_CODES.M)
@Override
public String onChoosePrivateKeyAlias(Context context, Intent intent, int uid, Uri uri,
String alias) {
Expand All @@ -281,7 +279,7 @@ public void onPasswordExpiring(Context context, Intent intent) {
onPasswordExpiring(context, intent, Process.myUserHandle());
}

@TargetApi(Build.VERSION_CODES.O)
@TargetApi(VERSION_CODES.O)
// @Override
public void onPasswordExpiring(Context context, Intent intent, UserHandle user) {
if (!Process.myUserHandle().equals(user)) {
Expand Down Expand Up @@ -309,7 +307,7 @@ public void onPasswordFailed(Context context, Intent intent) {
onPasswordFailed(context, intent, Process.myUserHandle());
}

@TargetApi(Build.VERSION_CODES.O)
@TargetApi(VERSION_CODES.O)
// @Override
public void onPasswordFailed(Context context, Intent intent, UserHandle user) {
if (!Process.myUserHandle().equals(user)) {
Expand Down Expand Up @@ -372,7 +370,7 @@ public void onPasswordSucceeded(Context context, Intent intent) {
onPasswordSucceeded(context, intent, Process.myUserHandle());
}

@TargetApi(Build.VERSION_CODES.O)
@TargetApi(VERSION_CODES.O)
// @Override
public void onPasswordSucceeded(Context context, Intent intent, UserHandle user) {
if (Process.myUserHandle().equals(user)) {
Expand All @@ -386,7 +384,7 @@ public void onPasswordChanged(Context context, Intent intent) {
onPasswordChanged(context, intent, Process.myUserHandle());
}

@TargetApi(Build.VERSION_CODES.O)
@TargetApi(VERSION_CODES.O)
// @Override
public void onPasswordChanged(Context context, Intent intent, UserHandle user) {
if (Process.myUserHandle().equals(user)) {
Expand Down Expand Up @@ -478,7 +476,7 @@ private static void updatePasswordConstraintNotification(Context context) {
problems.add(context.getText(R.string.password_not_compliant_title));
}

if (um.hasUserRestriction(UserRestriction.DISALLOW_UNIFIED_PASSWORD)
if (um.hasUserRestriction(UserManager.DISALLOW_UNIFIED_PASSWORD)
&& Util.isManagedProfileOwner(context)
&& isUsingUnifiedPassword(context)) {
problems.add(context.getText(R.string.separate_challenge_required_title));
Expand All @@ -504,9 +502,9 @@ && isUsingUnifiedPassword(context)) {
}
}

@TargetApi(28)
@TargetApi(VERSION_CODES.P)
private static Boolean isUsingUnifiedPassword(Context context) {
if (!BuildCompat.isAtLeastP()) {
if (Util.SDK_INT < VERSION_CODES.P) {
return false;
}
final DevicePolicyManager dpm = context.getSystemService(DevicePolicyManager.class);
Expand Down Expand Up @@ -546,7 +544,7 @@ private void onDeviceOwnerChanged(Context context) {
NotificationUtil.DEVICE_OWNER_CHANGED_ID);
}

@TargetApi(Build.VERSION_CODES.P)
@TargetApi(VERSION_CODES.P)
public void onTransferOwnershipComplete(Context context, PersistableBundle bundle) {
Log.i(TAG, "onTransferOwnershipComplete");
NotificationUtil.showNotification(context,
Expand All @@ -556,7 +554,7 @@ public void onTransferOwnershipComplete(Context context, PersistableBundle bundl
NotificationUtil.TRANSFER_OWNERSHIP_COMPLETE_ID);
}

@TargetApi(Build.VERSION_CODES.P)
@TargetApi(VERSION_CODES.P)
public void onTransferAffiliatedProfileOwnershipComplete(Context context, UserHandle user) {
Log.i(TAG, "onTransferAffiliatedProfileOwnershipComplete");
NotificationUtil.showNotification(context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
import android.content.BroadcastReceiver;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Build;
import android.os.Build.VERSION_CODES;
import android.support.annotation.RequiresApi;

/**
* To allow DPC process to be persistent and foreground.
*
* @see {@link android.app.admin.DeviceAdminService}
*/
@RequiresApi(api = Build.VERSION_CODES.O)
@RequiresApi(api = VERSION_CODES.O)
public class DeviceAdminService extends android.app.admin.DeviceAdminService {

private BroadcastReceiver mPackageChangedReceiver;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package com.afwsamples.testdpc;

import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE;
import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME;

import android.accounts.Account;
import android.accounts.AccountManager;
Expand All @@ -30,7 +29,6 @@
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.afwsamples.testdpc.common.LaunchIntentUtil;
import com.afwsamples.testdpc.common.Util;
import com.afwsamples.testdpc.provision.ProvisioningUtil;
Expand Down
Loading

0 comments on commit b21e807

Please sign in to comment.