Skip to content

Commit e28642f

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 (cherry picked from commit 76a80e91563a4b74b82d3de6b3ec053df0893a0c)
1 parent dca27e6 commit e28642f

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
@@ -338,6 +338,17 @@ void setLocationEnabled(boolean enabled, @NonNull Consumer<Void> onSuccess,
338338
*/
339339
boolean isLocationEnabled();
340340

341+
/**
342+
* See {@link android.app.admin.DevicePolicyManager#setDeviceOwnerLockScreenInfo(ComponentName, CharSequence)}.
343+
*/
344+
void setDeviceOwnerLockScreenInfo(CharSequence info, @NonNull Consumer<Void> onSuccess,
345+
@NonNull Consumer<Exception> onError);
346+
347+
/**
348+
* See {@link android.app.admin.DevicePolicyManager#getDeviceOwnerLockScreenInfo()}.
349+
*/
350+
CharSequence getDeviceOwnerLockScreenInfo();
351+
341352
/**
342353
* Used on error callbacks to indicate a {@link android.app.admin.DevicePolicyManager} method
343354
* 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
@@ -621,6 +621,23 @@ public boolean isLocationEnabled() {
621621
return mLocationManager.isLocationEnabled();
622622
}
623623

624+
@Override
625+
public void setDeviceOwnerLockScreenInfo(CharSequence info, Consumer<Void> onSuccess,
626+
Consumer<Exception> onError) {
627+
Log.d(TAG, "setDeviceOwnerLockScreenInfo(" + info + ")");
628+
try {
629+
mDevicePolicyManager.setDeviceOwnerLockScreenInfo(mAdminComponentName, info);
630+
onSuccess.accept(null);
631+
} catch (Exception e) {
632+
onError.accept(e);
633+
}
634+
}
635+
636+
@Override
637+
public CharSequence getDeviceOwnerLockScreenInfo() {
638+
return mDevicePolicyManager.getDeviceOwnerLockScreenInfo();
639+
}
640+
624641
@Override
625642
public String toString() {
626643
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
@@ -97,6 +97,10 @@ final class ShellCommand {
9797
private static final String CMD_GET_PERMISSION_GRANT_STATE = "get-permission-grant-state";
9898
private static final String CMD_SET_LOCATION_ENABLED = "set-location-enabled";
9999
private static final String CMD_IS_LOCATION_ENABLED = "is-location-enabled";
100+
private static final String CMD_SET_DEVICE_OWNER_LOCKSCREEN_INFO
101+
= "set-device-owner-lockscreen-info";
102+
private static final String CMD_GET_DEVICE_OWNER_LOCKSCREEN_INFO
103+
= "get-device-owner-lockscreen-info";
100104

101105
private static final String ARG_FLAGS = "--flags";
102106

@@ -257,6 +261,12 @@ public void run() {
257261
case CMD_IS_LOCATION_ENABLED:
258262
execute(() -> isLocationEnabled());
259263
break;
264+
case CMD_SET_DEVICE_OWNER_LOCKSCREEN_INFO:
265+
execute(() -> setDeviceOwnerLockScreenInfo());
266+
break;
267+
case CMD_GET_DEVICE_OWNER_LOCKSCREEN_INFO:
268+
execute(() -> getDeviceOwnerLockScreenInfo());
269+
break;
260270
default:
261271
mWriter.printf("Invalid command: %s\n\n", cmd);
262272
showUsage();
@@ -358,6 +368,11 @@ private void showUsage() {
358368
CMD_SET_LOCATION_ENABLED);
359369
mWriter.printf("\t%s - get whether location is enabled for the user\n",
360370
CMD_IS_LOCATION_ENABLED);
371+
mWriter.printf("\t%s [INFO] - set the device owner lock screen info (or reset when no INFO "
372+
+ "is passed)\n",
373+
CMD_SET_DEVICE_OWNER_LOCKSCREEN_INFO);
374+
mWriter.printf("\t%s - get the device owner lock screen info",
375+
CMD_GET_DEVICE_OWNER_LOCKSCREEN_INFO);
361376

362377
// Separator for S / pre-S commands - do NOT remove line to avoid cherry-pick conflicts
363378
}
@@ -817,6 +832,18 @@ private void isLocationEnabled() {
817832
mWriter.printf("Location enabled: %b\n", enabled);
818833
}
819834

835+
private void setDeviceOwnerLockScreenInfo() {
836+
final CharSequence info = mArgs.length > 0 ? mArgs[1] : "";
837+
mDevicePolicyManagerGateway.setDeviceOwnerLockScreenInfo(info,
838+
(v) -> onSuccess("Set lock screen info to '%s'", info),
839+
(e) -> onError(e, "Error setting lock screen info to '%s'", info));
840+
}
841+
842+
private void getDeviceOwnerLockScreenInfo() {
843+
CharSequence info = mDevicePolicyManagerGateway.getDeviceOwnerLockScreenInfo();
844+
mWriter.printf("Lock screen info: %s\n", info);
845+
}
846+
820847
private static String permittedToString(boolean permitted) {
821848
return permitted ? "PERMITTED" : "NOT PERMITTED";
822849
}

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)