Skip to content

Commit 5983fdb

Browse files
committed
Added commands to set / get lock screen info
Test: adb shell dumpsys activity service --user 0 com.afwsamples.testdpc get-device-owner-lockscreen-info Test: adb shell dumpsys activity service --user 0 com.afwsamples.testdpc set-device-owner-lockscreen-info DOH Bug: 171350084 Bug: 185285562 Change-Id: I25b6a855891974eab8d5f2b341a2c0d65e85ed79
1 parent 9370510 commit 5983fdb

File tree

4 files changed

+59
-3
lines changed

4 files changed

+59
-3
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,17 @@ void setLocationEnabled(boolean enabled, @NonNull Consumer<Void> onSuccess,
413413
*/
414414
boolean isLocationEnabled();
415415

416+
/**
417+
* See {@link android.app.admin.DevicePolicyManager#setDeviceOwnerLockScreenInfo(ComponentName, CharSequence)}.
418+
*/
419+
void setDeviceOwnerLockScreenInfo(CharSequence info, @NonNull Consumer<Void> onSuccess,
420+
@NonNull Consumer<Exception> onError);
421+
422+
/**
423+
* See {@link android.app.admin.DevicePolicyManager#getDeviceOwnerLockScreenInfo()}.
424+
*/
425+
CharSequence getDeviceOwnerLockScreenInfo();
426+
416427
/**
417428
* Used on error callbacks to indicate a {@link android.app.admin.DevicePolicyManager} method
418429
* call failed.

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,23 @@ public boolean isLocationEnabled() {
814814
return mLocationManager.isLocationEnabled();
815815
}
816816

817+
@Override
818+
public void setDeviceOwnerLockScreenInfo(CharSequence info, Consumer<Void> onSuccess,
819+
Consumer<Exception> onError) {
820+
Log.d(TAG, "setDeviceOwnerLockScreenInfo(" + info + ")");
821+
try {
822+
mDevicePolicyManager.setDeviceOwnerLockScreenInfo(mAdminComponentName, info);
823+
onSuccess.accept(null);
824+
} catch (Exception e) {
825+
onError.accept(e);
826+
}
827+
}
828+
829+
@Override
830+
public CharSequence getDeviceOwnerLockScreenInfo() {
831+
return mDevicePolicyManager.getDeviceOwnerLockScreenInfo();
832+
}
833+
817834
@Override
818835
public String toString() {
819836
return "DevicePolicyManagerGatewayImpl[" + mAdminComponentName + "]";

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ final class ShellCommand {
9999
private static final String CMD_GET_PERMISSION_GRANT_STATE = "get-permission-grant-state";
100100
private static final String CMD_SET_LOCATION_ENABLED = "set-location-enabled";
101101
private static final String CMD_IS_LOCATION_ENABLED = "is-location-enabled";
102+
private static final String CMD_SET_DEVICE_OWNER_LOCKSCREEN_INFO
103+
= "set-device-owner-lockscreen-info";
104+
private static final String CMD_GET_DEVICE_OWNER_LOCKSCREEN_INFO
105+
= "get-device-owner-lockscreen-info";
102106

103107
// Commands for APIs added on Android S
104108
private static final String CMD_SET_PERMITTED_INPUT_METHODS_PARENT =
@@ -285,6 +289,12 @@ public void run() {
285289
case CMD_IS_LOCATION_ENABLED:
286290
execute(() -> isLocationEnabled());
287291
break;
292+
case CMD_SET_DEVICE_OWNER_LOCKSCREEN_INFO:
293+
execute(() -> setDeviceOwnerLockScreenInfo());
294+
break;
295+
case CMD_GET_DEVICE_OWNER_LOCKSCREEN_INFO:
296+
execute(() -> getDeviceOwnerLockScreenInfo());
297+
break;
288298
default:
289299
mWriter.printf("Invalid command: %s\n\n", cmd);
290300
showUsage();
@@ -394,6 +404,11 @@ private void showUsage() {
394404
CMD_SET_LOCATION_ENABLED);
395405
mWriter.printf("\t%s - get whether location is enabled for the user\n",
396406
CMD_IS_LOCATION_ENABLED);
407+
mWriter.printf("\t%s [INFO] - set the device owner lock screen info (or reset when no INFO "
408+
+ "is passed)\n",
409+
CMD_SET_DEVICE_OWNER_LOCKSCREEN_INFO);
410+
mWriter.printf("\t%s - get the device owner lock screen info",
411+
CMD_GET_DEVICE_OWNER_LOCKSCREEN_INFO);
397412

398413
// Separator for S / pre-S commands - do NOT remove line to avoid cherry-pick conflicts
399414

@@ -917,6 +932,18 @@ private void isLocationEnabled() {
917932
mWriter.printf("Location enabled: %b\n", enabled);
918933
}
919934

935+
private void setDeviceOwnerLockScreenInfo() {
936+
final CharSequence info = mArgs.length > 0 ? mArgs[1] : "";
937+
mDevicePolicyManagerGateway.setDeviceOwnerLockScreenInfo(info,
938+
(v) -> onSuccess("Set lock screen info to '%s'", info),
939+
(e) -> onError(e, "Error setting lock screen info to '%s'", info));
940+
}
941+
942+
private void getDeviceOwnerLockScreenInfo() {
943+
CharSequence info = mDevicePolicyManagerGateway.getDeviceOwnerLockScreenInfo();
944+
mWriter.printf("Lock screen info: %s\n", info);
945+
}
946+
920947
private static String permittedToString(boolean permitted) {
921948
return permitted ? "PERMITTED" : "NOT PERMITTED";
922949
}

app/src/main/java/com/afwsamples/testdpc/policy/keyguard/LockScreenPolicyFragment.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,9 @@ private void showSetTrustAgentFragment() {
223223

224224
@TargetApi(VERSION_CODES.N)
225225
private void setLockScreenMessage(Preference preference, String newValue) {
226-
getDpm().setDeviceOwnerLockScreenInfo(getAdmin(), newValue);
227-
preference.setSummary(newValue);
226+
getDpmGateway().setDeviceOwnerLockScreenInfo(newValue,
227+
(v) -> preference.setSummary(newValue),
228+
(e) -> onErrorLog("setDeviceOwnerLockScreenInfo", e));
228229
}
229230

230231
private boolean updateKeyguardFeatures(int flag, boolean newValue) {
@@ -259,7 +260,7 @@ private void updateAggregates() {
259260
private void setupAll() {
260261
setup(Keys.LOCK_SCREEN_MESSAGE,
261262
Util.SDK_INT >= VERSION_CODES.N && isDeviceOwner()
262-
? getDpm().getDeviceOwnerLockScreenInfo() : null);
263+
? getDpmGateway().getDeviceOwnerLockScreenInfo() : null);
263264
setup(Keys.MAX_FAILS_BEFORE_WIPE, getDpm().getMaximumFailedPasswordsForWipe(getAdmin()));
264265
setup(Keys.MAX_TIME_SCREEN_LOCK,
265266
TimeUnit.MILLISECONDS.toSeconds(getDpm().getMaximumTimeToLock(getAdmin())));

0 commit comments

Comments
 (0)