Skip to content

Commit

Permalink
Merge S changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jscott1989 committed Jun 16, 2021
2 parents 1589a02 + d61cc29 commit cf9374b
Show file tree
Hide file tree
Showing 40 changed files with 1,959 additions and 640 deletions.
8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ apply plugin: 'com.android.application'
ext {
/* Version code for *next* release, bump *after* a release is created. */
// 1 or more digits
versionMajor = 7
// exactly 1 digit
versionMajor = 8
// exactly 1 digiT
versionMinor = 0
// exactly 2 digits
versionBuild = 03
versionBuild = 00
}

android {
compileSdkVersion 'android-30'
compileSdkVersion 'android-S'
buildToolsVersion "28.0.0"

defaultConfig {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
</intent-filter>
</activity>

<activity android:name=".provision.DpcLoginActivity"
<activity android:name=".provision.GetProvisioningModeActivity"
android:exported="true"
android:permission="android.permission.BIND_DEVICE_ADMIN"
android:theme="@style/DpcLoginTheme">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import java.util.Set;

/**
* This fragment provides the ability to whitelist cross profile packages
* This fragment provides the ability to allow-list cross profile packages
*
* <p>APIs exercised:
* <ul>
Expand All @@ -40,7 +40,7 @@
* </ul>
*/
@TargetApi(VERSION_CODES.R)
public class CrossProfileAppsWhitelistFragment extends Fragment {
public class CrossProfileAppsAllowlistFragment extends Fragment {
private static final String DELIMITER = "\n";

private View mInflatedView;
Expand All @@ -59,12 +59,12 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
mDevicePolicyManager = getActivity().getSystemService(DevicePolicyManager.class);
mAdminComponent = DeviceAdminReceiver.getComponentName(getActivity());
mInflatedView = inflater.inflate(
R.layout.cross_profile_apps_whitelist, container, false);
R.layout.cross_profile_apps_allowlist, container, false);

mAppNameEditText = mInflatedView.findViewById(R.id.cross_profile_app_whitelist_input);
mResetButton = mInflatedView.findViewById(R.id.cross_profile_app_whitelist_reset_button);
mAddButton = mInflatedView.findViewById(R.id.cross_profile_app_whitelist_add_button);
mRemoveButton = mInflatedView.findViewById(R.id.cross_profile_app_whitelist_remove_button);
mAppNameEditText = mInflatedView.findViewById(R.id.cross_profile_app_allowlist_input);
mResetButton = mInflatedView.findViewById(R.id.cross_profile_app_allowlist_reset_button);
mAddButton = mInflatedView.findViewById(R.id.cross_profile_app_allowlist_add_button);
mRemoveButton = mInflatedView.findViewById(R.id.cross_profile_app_allowlist_remove_button);
mAppsList = mInflatedView.findViewById(R.id.cross_profile_app_list);

setOnClickListeners();
Expand Down Expand Up @@ -103,7 +103,7 @@ private void removeApp(String app) {
private void updateCrossProfileAppsList(){
Set<String> currentApps = mDevicePolicyManager.getCrossProfilePackages(mAdminComponent);
if (currentApps.isEmpty()) {
mAppsList.setText(R.string.cross_profile_apps_no_whitelisted_apps);
mAppsList.setText(R.string.cross_profile_apps_no_allowlisted_apps);
} else {
mAppsList.setText(String.join(DELIMITER, currentApps));
}
Expand Down
52 changes: 42 additions & 10 deletions app/src/main/java/com/afwsamples/testdpc/DeviceAdminReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,33 @@ public void onReceive(Context context, Intent intent) {
}
}

// TODO(b/179160578): uncomment when available in the SDK
// @Override
@TargetApi(VERSION_CODES.S)
public void onOperationSafetyStateChanged(Context context, int reasonType, boolean safe) {
Log.d(TAG, "onOperationSafetyStateChanged(): " + reasonType + " = " + safe);
String status = safe ? context.getString(R.string.safe)
: context.getString(R.string.unsafe);
String reason;
switch (reasonType) {
case 1: // TODO: use DPM constant once SDK is available
reason = context.getString(R.string.unsafe_operation_reason_driving_distraction);
break;
default:
reason = context.getString(R.string.unsafe_operation_reason_driving_undefined);
}
String message = context.getString(R.string.safety_operations_change_message, reason,
status);
showToast(context, message);
}

@TargetApi(VERSION_CODES.N)
@Override
public void onSecurityLogsAvailable(Context context, Intent intent) {
Log.i(TAG, "onSecurityLogsAvailable() called");
Toast.makeText(context,
context.getString(R.string.on_security_logs_available),
Toast.LENGTH_LONG)
.show();
showToast(context, R.string.on_security_logs_available);
}


/*
* 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
Expand All @@ -115,6 +131,10 @@ public void onNetworkLogsAvailable(Context context, Intent intent, long batchTok

@Override
public void onProfileProvisioningComplete(Context context, Intent intent) {
if (Util.SDK_INT >= VERSION_CODES.O) {
// See http://b/177617306.
return;
}
PostProvisioningTask task = new PostProvisioningTask(context);
if (!task.performPostProvisioningOperations(intent)) {
return;
Expand All @@ -126,8 +146,7 @@ public void onProfileProvisioningComplete(Context context, Intent intent) {
} else {
Log.e(TAG, "DeviceAdminReceiver.onProvisioningComplete() invoked, but ownership "
+ "not assigned");
Toast.makeText(context, R.string.device_admin_receiver_failure, Toast.LENGTH_LONG)
.show();
showToast(context, R.string.device_admin_receiver_failure);
}
}

Expand All @@ -146,6 +165,7 @@ public void onBugreportShared(final Context context, Intent intent,
final String bugreportFileHash) {
Log.i(TAG, "Bugreport shared, hash: " + bugreportFileHash);
final Uri bugreportUri = intent.getData();
Log.i(TAG, "Bugreport URI: " + bugreportUri);

final PendingResult result = goAsync();
new AsyncTask<Void, Void, String>() {
Expand All @@ -161,16 +181,20 @@ protected String doInBackground(Void... params) {
in = new FileInputStream(mInputPfd.getFileDescriptor());
outputBugreportFile = new File(context.getExternalFilesDir(null),
bugreportUri.getLastPathSegment());
Log.i(TAG, "Writing bugreport to " + outputBugreportFile);
out = new FileOutputStream(outputBugreportFile);
byte[] buffer = new byte[1024];
int read;
long totalRead = 0;
while ((read = in.read(buffer)) != -1) {
totalRead += read;
out.write(buffer, 0, read);
}
in.close();
out.close();
message = context.getString(R.string.received_bugreport,
outputBugreportFile.getPath(), bugreportFileHash);
outputBugreportFile.getPath(), bugreportFileHash, totalRead);
Log.i(TAG, message);
} catch (IOException e) {
Log.e(TAG, e.getMessage());
message = context.getString(R.string.received_bugreport_failed_retrieval);
Expand Down Expand Up @@ -251,8 +275,7 @@ public void onSystemUpdatePending(Context context, Intent intent, long receivedT
if (receivedTime != -1) {
DateFormat sdf = new SimpleDateFormat("hh:mm:ss dd/MM/yyyy");
String timeString = sdf.format(new Date(receivedTime));
Toast.makeText(context, "System update received at: " + timeString,
Toast.LENGTH_LONG).show();
showToast(context, "System update received at: " + timeString);
} else {
// No system update is currently available on this device.
}
Expand Down Expand Up @@ -571,4 +594,13 @@ private void handleUserAction(Context context, UserHandle userHandle, int titleR
Log.i(TAG, message);
NotificationUtil.showNotification(context, titleResId, message, notificationId);
}

private void showToast(Context context, int resId) {
showToast(context, context.getString(resId));
}

private void showToast(Context context, String message) {
Log.v(TAG, "showToast():" + message);
Toast.makeText(context, message, Toast.LENGTH_LONG).show();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

import android.app.admin.DevicePolicyManager;
import android.content.ComponentName;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.graphics.Bitmap;
import android.os.Bundle;
Expand Down Expand Up @@ -66,6 +68,21 @@ public interface DevicePolicyManagerGateway {
*/
boolean isOrganizationOwnedDeviceWithManagedProfile();

/**
* See {@link android.os.UserManager#isHeadlessSystemUserMode()}.
*/
boolean isHeadlessSystemUserMode();

/**
* See {@link android.os.UserManager#isUserForeground()}.
*/
boolean isUserForeground();

/**
* See {@link android.app.admin.DevicePolicyManager#listForegroundAffiliatedUsers()}.
*/
List<UserHandle> listForegroundAffiliatedUsers();

/**
* See {@link android.app.admin.DevicePolicyManager#createAndManageUser(android.content.ComponentName, String, android.content.ComponentName, android.os.PersistableBundle, int)}.
*/
Expand Down Expand Up @@ -208,6 +225,19 @@ void wipeData(int flags, @NonNull Consumer<Void> onSuccess,
*/
@NonNull List<String> getUserControlDisabledPackages();

/**
* See {@link android.app.admin.DevicePolicyManager#setPermittedInputMethods(
* android.content.ComponentName, List)}.
*/
boolean setPermittedInputMethods(List<String> packageNames, @NonNull Consumer<Void> onSuccess,
@NonNull Consumer<Exception> onError);

/**
* See {@link android.app.admin.DevicePolicyManager#setPermittedInputMethods(
* android.content.ComponentName, List)}.
*/
boolean setPermittedInputMethods(List<String> packageNames);

/**
* See {@link android.app.admin.DevicePolicyManager#removeActiveAdmin(android.content.ComponentName)}.
*/
Expand Down Expand Up @@ -240,6 +270,30 @@ void setPasswordQuality(int quality, @NonNull Consumer<Void> onSuccess,
void transferOwnership(@NonNull ComponentName target, @Nullable PersistableBundle bundle,
@NonNull Consumer<Void> onSuccess, @NonNull Consumer<Exception> onError);

/**
* See android.app.admin.DevicePolicyManager#setUsbDataSignalingEnabled(
* android.content.ComponentName, boolean)
*/
void setUsbDataSignalingEnabled(boolean enabled, @NonNull Consumer<Void> onSuccess,
@NonNull Consumer<Exception> onError);

/**
* Same as {@link #setUsbDataSignalingEnabled(boolean, Consumer, Consumer)}, but ignoring
* callbacks.
*/
void setUsbDataSignalingEnabled(boolean enabled);

/**
* See {@link android.app.admin.DevicePolicyManager#setPreferentialNetworkServiceEnabled(ComponentName, boolean)}.
*/
void setPreferentialNetworkServiceEnabled(boolean enabled,
@NonNull Consumer<Void> onSuccess, @NonNull Consumer<Exception> onError);

/**
* See {@link android.app.admin.DevicePolicyManager#isPreferentialNetworkServiceEnabled(ComponentName)}.
*/
boolean isPreferentialNetworkServiceEnabled();

/**
* See {@link android.app.admin.DevicePolicyManager#setPackagesSuspended(ComponentName, String[], boolean)}.
*/
Expand Down Expand Up @@ -267,11 +321,31 @@ void setApplicationHidden(String packageName, boolean suspended, @NonNull Consum
*/
void setPersonalAppsSuspended(boolean suspended, @NonNull Consumer<Void> onSuccess,
@NonNull Consumer<Exception> onError);

/**
* See {@link android.app.admin.DevicePolicyManager#getPersonalAppsSuspendedReasons(ComponentName)}.
*/
int getPersonalAppsSuspendedReasons();

// TODO(b/171350084): use on CosuConfig
/**
* See {@link android.app.admin.DevicePolicyManager#enableSystemApp(ComponentName, String)}.
*/
void enableSystemApp(String packageName, @NonNull Consumer<Void> onSuccess,
@NonNull Consumer<Exception> onError);

/**
* See {@link android.app.admin.DevicePolicyManager#enableSystemApp(ComponentName, Intent)}.
*/
void enableSystemApp(Intent intent, @NonNull Consumer<Integer> onSuccess,
@NonNull Consumer<Exception> onError);

/**
* Queries {@link PackageManager} to get the list of apps that are disabled for the user.
*/
@NonNull
List<String> getDisabledSystemApps();

// TODO(b/171350084): use in other places
/**
* See {@link android.app.admin.DevicePolicyManager#setLockTaskPackages(ComponentName, String[])}.
Expand Down Expand Up @@ -320,7 +394,7 @@ void setApplicationRestrictions(String packageName, Bundle settings,
* See {@link android.app.admin.DevicePolicyManager#setPermissionGrantState(ComponentName, String, String, int)}.
*/
void setPermissionGrantState(String packageName, String permission, int grantState,
@NonNull Consumer<Boolean> onSuccess, @NonNull Consumer<Exception> onError);
@NonNull Consumer<Void> onSuccess, @NonNull Consumer<Exception> onError);

/**
* See {@link android.app.admin.DevicePolicyManager#getPermissionGrantState(ComponentName, String, String)}.
Expand Down Expand Up @@ -349,6 +423,23 @@ void setDeviceOwnerLockScreenInfo(CharSequence info, @NonNull Consumer<Void> onS
*/
CharSequence getDeviceOwnerLockScreenInfo();

/**
* See {@link android.app.admin.DevicePolicyManager#setKeyguardDisabled(ComponentName, boolean)}.
*/
void setKeyguardDisabled(boolean disabled, @NonNull Consumer<Void> onSuccess,
@NonNull Consumer<Exception> onError);

/**
* See {@link android.app.admin.DevicePolicyManager#setKeyguardDisabledFeatures(ComponentName, int)}.
*/
void setKeyguardDisabledFeatures(int which, @NonNull Consumer<Void> onSuccess,
@NonNull Consumer<Exception> onError);

/**
* See {@link android.app.admin.DevicePolicyManager#getKeyguardDisabledFeatures(ComponentName)}.
*/
int getKeyguardDisabledFeatures();

/**
* Used on error callbacks to indicate a {@link android.app.admin.DevicePolicyManager} method
* call failed.
Expand Down
Loading

0 comments on commit cf9374b

Please sign in to comment.