Skip to content

Commit cf9374b

Browse files
committed
Merge S changes
2 parents 1589a02 + d61cc29 commit cf9374b

40 files changed

+1959
-640
lines changed

app/build.gradle

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ apply plugin: 'com.android.application'
33
ext {
44
/* Version code for *next* release, bump *after* a release is created. */
55
// 1 or more digits
6-
versionMajor = 7
7-
// exactly 1 digit
6+
versionMajor = 8
7+
// exactly 1 digiT
88
versionMinor = 0
99
// exactly 2 digits
10-
versionBuild = 03
10+
versionBuild = 00
1111
}
1212

1313
android {
14-
compileSdkVersion 'android-30'
14+
compileSdkVersion 'android-S'
1515
buildToolsVersion "28.0.0"
1616

1717
defaultConfig {

app/src/main/AndroidManifest.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111
</intent-filter>
112112
</activity>
113113

114-
<activity android:name=".provision.DpcLoginActivity"
114+
<activity android:name=".provision.GetProvisioningModeActivity"
115115
android:exported="true"
116116
android:permission="android.permission.BIND_DEVICE_ADMIN"
117117
android:theme="@style/DpcLoginTheme">

app/src/main/java/com/afwsamples/testdpc/CrossProfileAppsWhitelistFragment.java app/src/main/java/com/afwsamples/testdpc/CrossProfileAppsAllowlistFragment.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import java.util.Set;
3232

3333
/**
34-
* This fragment provides the ability to whitelist cross profile packages
34+
* This fragment provides the ability to allow-list cross profile packages
3535
*
3636
* <p>APIs exercised:
3737
* <ul>
@@ -40,7 +40,7 @@
4040
* </ul>
4141
*/
4242
@TargetApi(VERSION_CODES.R)
43-
public class CrossProfileAppsWhitelistFragment extends Fragment {
43+
public class CrossProfileAppsAllowlistFragment extends Fragment {
4444
private static final String DELIMITER = "\n";
4545

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

64-
mAppNameEditText = mInflatedView.findViewById(R.id.cross_profile_app_whitelist_input);
65-
mResetButton = mInflatedView.findViewById(R.id.cross_profile_app_whitelist_reset_button);
66-
mAddButton = mInflatedView.findViewById(R.id.cross_profile_app_whitelist_add_button);
67-
mRemoveButton = mInflatedView.findViewById(R.id.cross_profile_app_whitelist_remove_button);
64+
mAppNameEditText = mInflatedView.findViewById(R.id.cross_profile_app_allowlist_input);
65+
mResetButton = mInflatedView.findViewById(R.id.cross_profile_app_allowlist_reset_button);
66+
mAddButton = mInflatedView.findViewById(R.id.cross_profile_app_allowlist_add_button);
67+
mRemoveButton = mInflatedView.findViewById(R.id.cross_profile_app_allowlist_remove_button);
6868
mAppsList = mInflatedView.findViewById(R.id.cross_profile_app_list);
6969

7070
setOnClickListeners();
@@ -103,7 +103,7 @@ private void removeApp(String app) {
103103
private void updateCrossProfileAppsList(){
104104
Set<String> currentApps = mDevicePolicyManager.getCrossProfilePackages(mAdminComponent);
105105
if (currentApps.isEmpty()) {
106-
mAppsList.setText(R.string.cross_profile_apps_no_whitelisted_apps);
106+
mAppsList.setText(R.string.cross_profile_apps_no_allowlisted_apps);
107107
} else {
108108
mAppsList.setText(String.join(DELIMITER, currentApps));
109109
}

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

+42-10
Original file line numberDiff line numberDiff line change
@@ -90,17 +90,33 @@ public void onReceive(Context context, Intent intent) {
9090
}
9191
}
9292

93+
// TODO(b/179160578): uncomment when available in the SDK
94+
// @Override
95+
@TargetApi(VERSION_CODES.S)
96+
public void onOperationSafetyStateChanged(Context context, int reasonType, boolean safe) {
97+
Log.d(TAG, "onOperationSafetyStateChanged(): " + reasonType + " = " + safe);
98+
String status = safe ? context.getString(R.string.safe)
99+
: context.getString(R.string.unsafe);
100+
String reason;
101+
switch (reasonType) {
102+
case 1: // TODO: use DPM constant once SDK is available
103+
reason = context.getString(R.string.unsafe_operation_reason_driving_distraction);
104+
break;
105+
default:
106+
reason = context.getString(R.string.unsafe_operation_reason_driving_undefined);
107+
}
108+
String message = context.getString(R.string.safety_operations_change_message, reason,
109+
status);
110+
showToast(context, message);
111+
}
112+
93113
@TargetApi(VERSION_CODES.N)
94114
@Override
95115
public void onSecurityLogsAvailable(Context context, Intent intent) {
96116
Log.i(TAG, "onSecurityLogsAvailable() called");
97-
Toast.makeText(context,
98-
context.getString(R.string.on_security_logs_available),
99-
Toast.LENGTH_LONG)
100-
.show();
117+
showToast(context, R.string.on_security_logs_available);
101118
}
102119

103-
104120
/*
105121
* TODO: reconsider how to store and present the logs in the future, e.g. save the file into
106122
* internal memory and show the content in a ListView
@@ -115,6 +131,10 @@ public void onNetworkLogsAvailable(Context context, Intent intent, long batchTok
115131

116132
@Override
117133
public void onProfileProvisioningComplete(Context context, Intent intent) {
134+
if (Util.SDK_INT >= VERSION_CODES.O) {
135+
// See http://b/177617306.
136+
return;
137+
}
118138
PostProvisioningTask task = new PostProvisioningTask(context);
119139
if (!task.performPostProvisioningOperations(intent)) {
120140
return;
@@ -126,8 +146,7 @@ public void onProfileProvisioningComplete(Context context, Intent intent) {
126146
} else {
127147
Log.e(TAG, "DeviceAdminReceiver.onProvisioningComplete() invoked, but ownership "
128148
+ "not assigned");
129-
Toast.makeText(context, R.string.device_admin_receiver_failure, Toast.LENGTH_LONG)
130-
.show();
149+
showToast(context, R.string.device_admin_receiver_failure);
131150
}
132151
}
133152

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

150170
final PendingResult result = goAsync();
151171
new AsyncTask<Void, Void, String>() {
@@ -161,16 +181,20 @@ protected String doInBackground(Void... params) {
161181
in = new FileInputStream(mInputPfd.getFileDescriptor());
162182
outputBugreportFile = new File(context.getExternalFilesDir(null),
163183
bugreportUri.getLastPathSegment());
184+
Log.i(TAG, "Writing bugreport to " + outputBugreportFile);
164185
out = new FileOutputStream(outputBugreportFile);
165186
byte[] buffer = new byte[1024];
166187
int read;
188+
long totalRead = 0;
167189
while ((read = in.read(buffer)) != -1) {
190+
totalRead += read;
168191
out.write(buffer, 0, read);
169192
}
170193
in.close();
171194
out.close();
172195
message = context.getString(R.string.received_bugreport,
173-
outputBugreportFile.getPath(), bugreportFileHash);
196+
outputBugreportFile.getPath(), bugreportFileHash, totalRead);
197+
Log.i(TAG, message);
174198
} catch (IOException e) {
175199
Log.e(TAG, e.getMessage());
176200
message = context.getString(R.string.received_bugreport_failed_retrieval);
@@ -251,8 +275,7 @@ public void onSystemUpdatePending(Context context, Intent intent, long receivedT
251275
if (receivedTime != -1) {
252276
DateFormat sdf = new SimpleDateFormat("hh:mm:ss dd/MM/yyyy");
253277
String timeString = sdf.format(new Date(receivedTime));
254-
Toast.makeText(context, "System update received at: " + timeString,
255-
Toast.LENGTH_LONG).show();
278+
showToast(context, "System update received at: " + timeString);
256279
} else {
257280
// No system update is currently available on this device.
258281
}
@@ -571,4 +594,13 @@ private void handleUserAction(Context context, UserHandle userHandle, int titleR
571594
Log.i(TAG, message);
572595
NotificationUtil.showNotification(context, titleResId, message, notificationId);
573596
}
597+
598+
private void showToast(Context context, int resId) {
599+
showToast(context, context.getString(resId));
600+
}
601+
602+
private void showToast(Context context, String message) {
603+
Log.v(TAG, "showToast():" + message);
604+
Toast.makeText(context, message, Toast.LENGTH_LONG).show();
605+
}
574606
}

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

+92-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
import android.app.admin.DevicePolicyManager;
1919
import android.content.ComponentName;
20+
import android.content.Intent;
21+
import android.content.pm.PackageManager;
2022
import android.content.pm.PackageManager.NameNotFoundException;
2123
import android.graphics.Bitmap;
2224
import android.os.Bundle;
@@ -66,6 +68,21 @@ public interface DevicePolicyManagerGateway {
6668
*/
6769
boolean isOrganizationOwnedDeviceWithManagedProfile();
6870

71+
/**
72+
* See {@link android.os.UserManager#isHeadlessSystemUserMode()}.
73+
*/
74+
boolean isHeadlessSystemUserMode();
75+
76+
/**
77+
* See {@link android.os.UserManager#isUserForeground()}.
78+
*/
79+
boolean isUserForeground();
80+
81+
/**
82+
* See {@link android.app.admin.DevicePolicyManager#listForegroundAffiliatedUsers()}.
83+
*/
84+
List<UserHandle> listForegroundAffiliatedUsers();
85+
6986
/**
7087
* See {@link android.app.admin.DevicePolicyManager#createAndManageUser(android.content.ComponentName, String, android.content.ComponentName, android.os.PersistableBundle, int)}.
7188
*/
@@ -208,6 +225,19 @@ void wipeData(int flags, @NonNull Consumer<Void> onSuccess,
208225
*/
209226
@NonNull List<String> getUserControlDisabledPackages();
210227

228+
/**
229+
* See {@link android.app.admin.DevicePolicyManager#setPermittedInputMethods(
230+
* android.content.ComponentName, List)}.
231+
*/
232+
boolean setPermittedInputMethods(List<String> packageNames, @NonNull Consumer<Void> onSuccess,
233+
@NonNull Consumer<Exception> onError);
234+
235+
/**
236+
* See {@link android.app.admin.DevicePolicyManager#setPermittedInputMethods(
237+
* android.content.ComponentName, List)}.
238+
*/
239+
boolean setPermittedInputMethods(List<String> packageNames);
240+
211241
/**
212242
* See {@link android.app.admin.DevicePolicyManager#removeActiveAdmin(android.content.ComponentName)}.
213243
*/
@@ -240,6 +270,30 @@ void setPasswordQuality(int quality, @NonNull Consumer<Void> onSuccess,
240270
void transferOwnership(@NonNull ComponentName target, @Nullable PersistableBundle bundle,
241271
@NonNull Consumer<Void> onSuccess, @NonNull Consumer<Exception> onError);
242272

273+
/**
274+
* See android.app.admin.DevicePolicyManager#setUsbDataSignalingEnabled(
275+
* android.content.ComponentName, boolean)
276+
*/
277+
void setUsbDataSignalingEnabled(boolean enabled, @NonNull Consumer<Void> onSuccess,
278+
@NonNull Consumer<Exception> onError);
279+
280+
/**
281+
* Same as {@link #setUsbDataSignalingEnabled(boolean, Consumer, Consumer)}, but ignoring
282+
* callbacks.
283+
*/
284+
void setUsbDataSignalingEnabled(boolean enabled);
285+
286+
/**
287+
* See {@link android.app.admin.DevicePolicyManager#setPreferentialNetworkServiceEnabled(ComponentName, boolean)}.
288+
*/
289+
void setPreferentialNetworkServiceEnabled(boolean enabled,
290+
@NonNull Consumer<Void> onSuccess, @NonNull Consumer<Exception> onError);
291+
292+
/**
293+
* See {@link android.app.admin.DevicePolicyManager#isPreferentialNetworkServiceEnabled(ComponentName)}.
294+
*/
295+
boolean isPreferentialNetworkServiceEnabled();
296+
243297
/**
244298
* See {@link android.app.admin.DevicePolicyManager#setPackagesSuspended(ComponentName, String[], boolean)}.
245299
*/
@@ -267,11 +321,31 @@ void setApplicationHidden(String packageName, boolean suspended, @NonNull Consum
267321
*/
268322
void setPersonalAppsSuspended(boolean suspended, @NonNull Consumer<Void> onSuccess,
269323
@NonNull Consumer<Exception> onError);
324+
270325
/**
271326
* See {@link android.app.admin.DevicePolicyManager#getPersonalAppsSuspendedReasons(ComponentName)}.
272327
*/
273328
int getPersonalAppsSuspendedReasons();
274329

330+
// TODO(b/171350084): use on CosuConfig
331+
/**
332+
* See {@link android.app.admin.DevicePolicyManager#enableSystemApp(ComponentName, String)}.
333+
*/
334+
void enableSystemApp(String packageName, @NonNull Consumer<Void> onSuccess,
335+
@NonNull Consumer<Exception> onError);
336+
337+
/**
338+
* See {@link android.app.admin.DevicePolicyManager#enableSystemApp(ComponentName, Intent)}.
339+
*/
340+
void enableSystemApp(Intent intent, @NonNull Consumer<Integer> onSuccess,
341+
@NonNull Consumer<Exception> onError);
342+
343+
/**
344+
* Queries {@link PackageManager} to get the list of apps that are disabled for the user.
345+
*/
346+
@NonNull
347+
List<String> getDisabledSystemApps();
348+
275349
// TODO(b/171350084): use in other places
276350
/**
277351
* See {@link android.app.admin.DevicePolicyManager#setLockTaskPackages(ComponentName, String[])}.
@@ -320,7 +394,7 @@ void setApplicationRestrictions(String packageName, Bundle settings,
320394
* See {@link android.app.admin.DevicePolicyManager#setPermissionGrantState(ComponentName, String, String, int)}.
321395
*/
322396
void setPermissionGrantState(String packageName, String permission, int grantState,
323-
@NonNull Consumer<Boolean> onSuccess, @NonNull Consumer<Exception> onError);
397+
@NonNull Consumer<Void> onSuccess, @NonNull Consumer<Exception> onError);
324398

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

426+
/**
427+
* See {@link android.app.admin.DevicePolicyManager#setKeyguardDisabled(ComponentName, boolean)}.
428+
*/
429+
void setKeyguardDisabled(boolean disabled, @NonNull Consumer<Void> onSuccess,
430+
@NonNull Consumer<Exception> onError);
431+
432+
/**
433+
* See {@link android.app.admin.DevicePolicyManager#setKeyguardDisabledFeatures(ComponentName, int)}.
434+
*/
435+
void setKeyguardDisabledFeatures(int which, @NonNull Consumer<Void> onSuccess,
436+
@NonNull Consumer<Exception> onError);
437+
438+
/**
439+
* See {@link android.app.admin.DevicePolicyManager#getKeyguardDisabledFeatures(ComponentName)}.
440+
*/
441+
int getKeyguardDisabledFeatures();
442+
352443
/**
353444
* Used on error callbacks to indicate a {@link android.app.admin.DevicePolicyManager} method
354445
* call failed.

0 commit comments

Comments
 (0)